Skip to content

Commit

Permalink
fix: use mapstate-sharemap with draw control (origo-map#1745)
Browse files Browse the repository at this point in the history
* fix: use sharemap with draw control

* Update viewer.js
  • Loading branch information
jokd committed Apr 24, 2023
1 parent 3002196 commit 2b6baaf
Showing 1 changed file with 21 additions and 20 deletions.
41 changes: 21 additions & 20 deletions src/viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -537,12 +537,31 @@ const Viewer = function Viewer(targetOption, options = {}) {
mapId: this.getId()
});

if (urlParams.pin) {
featureinfoOptions.savedPin = urlParams.pin;
} else if (urlParams.selection) {
// This needs further development for proper handling in permalink
featureinfoOptions.savedSelection = new Feature({
geometry: new geom[urlParams.selection.geometryType](urlParams.selection.coordinates)
});
}

featureinfoOptions.viewer = this;

selectionmanager = Selectionmanager(featureinfoOptions);
featureinfo = Featureinfo(featureinfoOptions);
this.addComponent(selectionmanager);
this.addComponent(featureinfo);
this.addComponent(centerMarker);

this.addControls();

if (urlParams.feature) {
const featureId = urlParams.feature;
const layerName = featureId.split('.')[0];
const layer = getLayer(layerName);
const layerType = layer.get('type');
if (layer && layerType !== 'GROUP') {
if (layer && layer.get('type') !== 'GROUP') {
const layerType = layer.get('type');
// FIXME: postrender event is only emitted if any features from a layer is actually drawn, which means there is no feature in the default extent,
// it will not be triggered until map is panned or zoomed where a feature exists.
layer.once('postrender', () => {
Expand Down Expand Up @@ -590,28 +609,10 @@ const Viewer = function Viewer(targetOption, options = {}) {
}
}

if (urlParams.pin) {
featureinfoOptions.savedPin = urlParams.pin;
} else if (urlParams.selection) {
// This needs further development for proper handling in permalink
featureinfoOptions.savedSelection = new Feature({
geometry: new geom[urlParams.selection.geometryType](urlParams.selection.coordinates)
});
}

if (!urlParams.zoom && !urlParams.mapStateId && startExtent) {
map.getView().fit(startExtent, { size: map.getSize() });
}

featureinfoOptions.viewer = this;

selectionmanager = Selectionmanager(featureinfoOptions);
featureinfo = Featureinfo(featureinfoOptions);
this.addComponent(selectionmanager);
this.addComponent(featureinfo);
this.addComponent(centerMarker);

this.addControls();
this.dispatch('loaded');
});
},
Expand Down

0 comments on commit 2b6baaf

Please sign in to comment.