-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(context): set map zoom level after importing context #1384
Changes from 3 commits
1737905
b09955c
a439f43
0b23af7
d44e420
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import olMap from 'ol/Map'; | ||
import olView from 'ol/View'; | ||
import olView, { ViewOptions } from 'ol/View'; | ||
import olControlAttribution from 'ol/control/Attribution'; | ||
import olControlScaleLine from 'ol/control/ScaleLine'; | ||
import * as olproj from 'ol/proj'; | ||
|
@@ -185,14 +185,16 @@ export class IgoMap implements MapBase { | |
|
||
updateView(options: MapViewOptions) { | ||
const currentView = this.ol.getView(); | ||
const viewOptions = Object.assign( | ||
{ | ||
zoom: currentView.getZoom() | ||
}, | ||
currentView.getProperties() | ||
); | ||
const viewOptions: MapViewOptions = { | ||
...currentView.getProperties(), | ||
...options | ||
}; | ||
|
||
if (options.zoom && options.resolution == null) { | ||
viewOptions.resolution = undefined; | ||
} | ||
|
||
this.setView(Object.assign(viewOptions, options)); | ||
this.setView(viewOptions); | ||
if (options.maxZoomOnExtent) { | ||
this.viewController.maxZoomOnExtent = options.maxZoomOnExtent; | ||
} | ||
|
@@ -208,21 +210,23 @@ export class IgoMap implements MapBase { | |
this.viewController.clearStateHistory(); | ||
} | ||
|
||
options = Object.assign({ constrainResolution: true }, options); | ||
const view = new olView(options); | ||
this.ol.setView(view); | ||
const viewOptions = this.handleMapViewOptions(options); | ||
this.ol.setView(new olView(viewOptions)); | ||
|
||
if (options) { | ||
if (options.maxLayerZoomExtent) { | ||
this.viewController.maxLayerZoomExtent = options.maxLayerZoomExtent; | ||
} | ||
if (options.maxLayerZoomExtent) { | ||
this.viewController.maxLayerZoomExtent = options.maxLayerZoomExtent; | ||
} | ||
} | ||
|
||
if (options.center) { | ||
const projection = view.getProjection().getCode(); | ||
const center = olproj.fromLonLat(options.center, projection); | ||
view.setCenter(center); | ||
} | ||
private handleMapViewOptions(options: MapViewOptions): ViewOptions { | ||
const viewOptions: ViewOptions = { constrainResolution: true, ...options }; | ||
|
||
if (options.center) { | ||
const projection = olproj.createProjection(options.projection, 'EPSG:3857'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P-etre faire attention. Passer par le view controller (ou le get projection) pour définir la projection de la map. Ce n'est pas toujours en 3857 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @alecarn Pourquoi creer une projection? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. En passant par le viewCtrl, j'ai l'impression qu'on fait une conversion pour rien. Parce qu'a ce point ci, le viewCtrl représente la vue précédente |
||
viewOptions.center = olproj.fromLonLat(options.center, projection); | ||
} | ||
|
||
return viewOptions; | ||
} | ||
|
||
updateControls(value: MapControlsOptions) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pourquoi passer le keepCurrentView a false ici?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Si tu veux exporter un contexte, j'imagine que naturellement, tu veux reloader la vue lors de l'importation.