From b2704d0ab876625c244ee96a28d9bb1769d6334c Mon Sep 17 00:00:00 2001 From: Pieter Vander Vennet Date: Wed, 1 Jul 2020 16:32:17 +0200 Subject: [PATCH] Fix #26 --- LayerDefinition.ts | 4 ++-- Logic/FilteredLayer.ts | 21 ++++++++------------- index.ts | 18 +++++++++++++++--- 3 files changed, 25 insertions(+), 18 deletions(-) diff --git a/LayerDefinition.ts b/LayerDefinition.ts index fb1dae6..4f63b4f 100644 --- a/LayerDefinition.ts +++ b/LayerDefinition.ts @@ -30,8 +30,8 @@ export class LayerDefinition { maxAllowedOverlapPercentage: number = undefined; - asLayer(basemap: Basemap, allElements: ElementStorage, changes: Changes, userDetails: UIEventSource, selectedElement: UIEventSource, - showOnPopup:UIEventSource<(() => UIElement)>): + asLayer(basemap: Basemap, allElements: ElementStorage, changes: Changes, userDetails: UIEventSource, selectedElement: UIEventSource, + showOnPopup: (tags: UIEventSource<(any)>) => UIElement): FilteredLayer { return new FilteredLayer( this.name, diff --git a/Logic/FilteredLayer.ts b/Logic/FilteredLayer.ts index 6af93ff..4b40eb0 100644 --- a/Logic/FilteredLayer.ts +++ b/Logic/FilteredLayer.ts @@ -39,7 +39,7 @@ export class FilteredLayer { */ private _geolayer; private _selectedElement: UIEventSource; - private _showOnPopup: UIEventSource<(() => UIElement)>; + private _showOnPopup: (tags: UIEventSource) => UIElement; constructor( name: string, @@ -49,7 +49,7 @@ export class FilteredLayer { maxAllowedOverlap: number, style: ((properties) => any), selectedElement: UIEventSource, - showOnPopup: UIEventSource<(() => UIElement)> + showOnPopup: ((tags: UIEventSource) => UIElement) ) { this._selectedElement = selectedElement; this._showOnPopup = showOnPopup; @@ -177,7 +177,6 @@ export class FilteredLayer { icon: style.icon }); } - return marker; }, @@ -188,21 +187,17 @@ export class FilteredLayer { }); - layer.on("click", function(e) { + const uiElement = self._showOnPopup(eventSource); + layer.bindPopup(uiElement.Render()); + layer.on("click", function (e) { console.log("Selected ", feature) self._selectedElement.setData(feature.properties); - - L.DomEvent.stop(e); // Marks the event as consumed - const uiElement = self._showOnPopup.data(); - const popup = L.popup(); - popup.setContent(uiElement.Render()); - layer.bindPopup(popup).openPopup(); - popup.onclose(() => { - layer.removePopup(popup) - }); + uiElement.Update(); uiElement.Activate(); + L.DomEvent.stop(e); // Marks the event as consumed + }); } }); diff --git a/index.ts b/index.ts index 4a90c00..e0d443e 100644 --- a/index.ts +++ b/index.ts @@ -26,10 +26,10 @@ let dryRun = false; if (location.hostname === "localhost" || location.hostname === "127.0.0.1") { // Set to true if testing and changes should NOT be saved - // dryRun = true; + // dryRun = true; // If you have a testfile somewhere, enable this to spoof overpass // This should be hosted independantly, e.g. with `cd assets; webfsd -p 8080` + a CORS plugin to disable cors rules - // Overpass.testUrl = "http://127.0.0.1:8080/test.json"; + Overpass.testUrl = null; // "http://127.0.0.1:8080/test.json"; } @@ -115,7 +115,19 @@ const flayers: FilteredLayer[] = [] for (const layer of questSetToRender.layers) { - const flayer = layer.asLayer(bm, allElements, changes, osmConnection.userDetails, selectedElement, leftMessage); + const generateInfo = (tagsES) => { + + return new FeatureInfoBox( + tagsES, + layer.elementsToShow, + layer.questions, + changes, + osmConnection.userDetails + ) + }; + + const flayer = layer.asLayer(bm, allElements, changes, osmConnection.userDetails, selectedElement, + generateInfo); const addButton = { name: layer.name,