Stabilizing popup behaviour

This commit is contained in:
pietervdvn 2021-01-05 16:59:12 +01:00
parent 614158e3c6
commit 52d9b2f452

View file

@ -43,7 +43,7 @@ export default class ShowDataLayer {
const feats = features.data.map(ff => ff.feature); const feats = features.data.map(ff => ff.feature);
let geoLayer = self.CreateGeojsonLayer(feats) let geoLayer = self.CreateGeojsonLayer(feats)
if (layoutToUse.clustering.minNeededElements <= features.data.length) { if (layoutToUse.clustering.minNeededElements <= features.data.length) {
const cl = window["L"]; const cl = window["L"]; // This is a dirty workaround, the clustering plugin binds to the L of the window, not of the namespace or something
const cluster = cl.markerClusterGroup({ disableClusteringAtZoom: layoutToUse.clustering.maxZoom }); const cluster = cl.markerClusterGroup({ disableClusteringAtZoom: layoutToUse.clustering.maxZoom });
cluster.addLayer(geoLayer); cluster.addLayer(geoLayer);
geoLayer = cluster; geoLayer = cluster;
@ -116,7 +116,7 @@ export default class ShowDataLayer {
const tags = State.state.allElements.getEventSourceFor(feature); const tags = State.state.allElements.getEventSourceFor(feature);
const uiElement: LazyElement = new LazyElement(() => new FeatureInfoBox(tags, layer)); const uiElement: LazyElement = new LazyElement(() => new FeatureInfoBox(tags, layer));
popup.setContent(uiElement.Render()); popup.setContent(uiElement.Render());
popup.on('popupclose', () => { popup.on('remove', () => {
State.state.selectedElement.setData(undefined); State.state.selectedElement.setData(undefined);
}); });
leafletLayer.bindPopup(popup); leafletLayer.bindPopup(popup);
@ -126,13 +126,16 @@ export default class ShowDataLayer {
leafletLayer.on("click", (e) => { leafletLayer.on("click", (e) => {
// We set the element as selected... // We set the element as selected...
// uiElement.Activate(); uiElement.Activate();
State.state.selectedElement.setData(feature); State.state.selectedElement.setData(feature);
}); });
const id = feature.properties.id+feature.geometry.type+feature._matching_layer_id; const id = feature.properties.id+feature.geometry.type+feature._matching_layer_id;
this._onSelectedTrigger[id] this._onSelectedTrigger[id]
= () => { = () => {
if(popup.isOpen()){
return;
}
leafletLayer.openPopup(); leafletLayer.openPopup();
uiElement.Activate(); uiElement.Activate();
} }