From c2d477c97af1d6083a8dfb29fb7c2a40c2082b5c Mon Sep 17 00:00:00 2001 From: pietervdvn Date: Wed, 29 Sep 2021 01:12:38 +0200 Subject: [PATCH] More refactoring --- InitUiElements.ts | 5 +- Logic/Actors/TitleHandler.ts | 2 +- Logic/ElementStorage.ts | 7 +- Logic/FeatureSource/FeaturePipeline.ts | 64 ++++++++++--------- .../Sources/FilteringFeatureSource.ts | 20 +----- Logic/MetaTagging.ts | 2 +- Logic/Osm/Changes.ts | 15 ++--- Logic/Tags/RegexTag.ts | 3 + Models/Constants.ts | 2 +- .../layers/cluster_style/cluster_style.json | 36 +++++++++++ .../toerisme_vlaanderen.json | 6 +- langs/themes/nl.json | 2 +- 12 files changed, 91 insertions(+), 73 deletions(-) create mode 100644 assets/layers/cluster_style/cluster_style.json diff --git a/InitUiElements.ts b/InitUiElements.ts index 40932dfd2..d0eb8b0d4 100644 --- a/InitUiElements.ts +++ b/InitUiElements.ts @@ -25,20 +25,18 @@ import ScrollableFullScreen from "./UI/Base/ScrollableFullScreen"; import Translations from "./UI/i18n/Translations"; import MapControlButton from "./UI/MapControlButton"; import LZString from "lz-string"; -import AllKnownLayers from "./Customizations/AllKnownLayers"; import AvailableBaseLayers from "./Logic/Actors/AvailableBaseLayers"; import LeftControls from "./UI/BigComponents/LeftControls"; import RightControls from "./UI/BigComponents/RightControls"; import {LayoutConfigJson} from "./Models/ThemeConfig/Json/LayoutConfigJson"; import LayoutConfig from "./Models/ThemeConfig/LayoutConfig"; -import LayerConfig from "./Models/ThemeConfig/LayerConfig"; import Minimap from "./UI/Base/Minimap"; import SelectedFeatureHandler from "./Logic/Actors/SelectedFeatureHandler"; import Combine from "./UI/Base/Combine"; import {SubtleButton} from "./UI/Base/SubtleButton"; import ShowTileInfo from "./UI/ShowDataLayer/ShowTileInfo"; import {Tiles} from "./Models/TileRange"; -import {TileHierarchyAggregator} from "./UI/ShowDataLayer/PerTileCountAggregator"; +import {TileHierarchyAggregator} from "./UI/ShowDataLayer/TileHierarchyAggregator"; import FilterConfig from "./Models/ThemeConfig/FilterConfig"; import FilteredLayer from "./Models/FilteredLayer"; import {BBox} from "./Logic/BBox"; @@ -435,6 +433,7 @@ export class InitUiElements { features: clusterCounter.getCountsForZoom(State.state.locationControl, State.state.layoutToUse.clustering.minNeededElements), leafletMap: State.state.leafletMap, layerToShow: ShowTileInfo.styling, + enablePopups: false }) State.state.featurePipeline = new FeaturePipeline( diff --git a/Logic/Actors/TitleHandler.ts b/Logic/Actors/TitleHandler.ts index 699a33aa8..91ec89b0c 100644 --- a/Logic/Actors/TitleHandler.ts +++ b/Logic/Actors/TitleHandler.ts @@ -29,7 +29,7 @@ export default class TitleHandler { if (layer.source.osmTags.matchesProperties(tags)) { const tagsSource = state.allElements.getEventSourceById(tags.id) const title = new TagRenderingAnswer(tagsSource, layer.title) - return new Combine([defaultTitle, " | ", title]).ConstructElement().innerText; + return new Combine([defaultTitle, " | ", title]).ConstructElement()?.innerText ?? defaultTitle; } } return defaultTitle diff --git a/Logic/ElementStorage.ts b/Logic/ElementStorage.ts index 91193ea6d..ae51094ae 100644 --- a/Logic/ElementStorage.ts +++ b/Logic/ElementStorage.ts @@ -39,11 +39,10 @@ export class ElementStorage { } getEventSourceById(elementId): UIEventSource { - if (this._elements.has(elementId)) { - return this._elements.get(elementId); + if(elementId === undefined){ + return undefined; } - console.error("Can not find eventsource with id ", elementId); - return undefined; + return this._elements.get(elementId); } has(id) { diff --git a/Logic/FeatureSource/FeaturePipeline.ts b/Logic/FeatureSource/FeaturePipeline.ts index d65771da2..e8d270f0b 100644 --- a/Logic/FeatureSource/FeaturePipeline.ts +++ b/Logic/FeatureSource/FeaturePipeline.ts @@ -62,11 +62,35 @@ export default class FeaturePipeline { /** * Maps tileid onto last download moment */ - const tileFreshnesses = new Map() + const tileFreshnesses = new UIEventSource>(new Map()) const osmSourceZoomLevel = 14 const useOsmApi = state.locationControl.map(l => l.zoom > (state.overpassMaxZoom.data ?? 12)) this.relationTracker = new RelationsTracker() + console.log("Tilefreshnesses are", tileFreshnesses.data) + const oldestAllowedDate = new Date(new Date().getTime() - (60 * 60 * 24 * 30 * 1000)); + const neededTilesFromOsm = state.currentBounds.map(bbox => { + if (bbox === undefined) { + return + } + const range = bbox.containingTileRange(osmSourceZoomLevel) + const tileIndexes = [] + if (range.total > 100) { + // Too much tiles! + return [] + } + Tiles.MapRange(range, (x, y) => { + const i = Tiles.tile_index(osmSourceZoomLevel, x, y); + if (tileFreshnesses.data.get(i) > oldestAllowedDate) { + console.debug("Skipping tile", osmSourceZoomLevel, x, y, "as a decently fresh one is available") + // The cached tiles contain decently fresh data + return; + } + tileIndexes.push(i) + }) + return tileIndexes + }, [tileFreshnesses]) + const updater = new OverpassFeatureSource(state, { relationTracker: this.relationTracker, @@ -75,8 +99,9 @@ export default class FeaturePipeline { // This callback contains metadata of the overpass call const range = bbox.containingTileRange(osmSourceZoomLevel) Tiles.MapRange(range, (x, y) => { - tileFreshnesses.set(Tiles.tile_index(osmSourceZoomLevel, x, y), freshness) + tileFreshnesses.data.set(Tiles.tile_index(osmSourceZoomLevel, x, y), freshness) }) + tileFreshnesses.ping(); } }); @@ -137,17 +162,17 @@ export default class FeaturePipeline { }, state) localStorage.tileFreshness.forEach((value, key) => { - if (tileFreshnesses.has(key)) { - const previous = tileFreshnesses.get(key) + if (tileFreshnesses.data.has(key)) { + const previous = tileFreshnesses.data.get(key) if (value < previous) { - tileFreshnesses.set(key, value) + tileFreshnesses.data.set(key, value) } } else { - tileFreshnesses.set(key, value) + tileFreshnesses.data.set(key, value) } + tileFreshnesses.ping() }) - continue } @@ -178,30 +203,7 @@ export default class FeaturePipeline { } } - console.log("Tilefreshnesses are", tileFreshnesses) - const oldestAllowedDate = new Date(new Date().getTime() - (60 * 60 * 24 * 30 * 1000)); - - const neededTilesFromOsm = state.currentBounds.map(bbox => { - if (bbox === undefined) { - return - } - const range = bbox.containingTileRange(osmSourceZoomLevel) - const tileIndexes = [] - if (range.total > 100) { - // Too much tiles! - return [] - } - Tiles.MapRange(range, (x, y) => { - const i = Tiles.tile_index(osmSourceZoomLevel, x, y); - if (tileFreshnesses.get(i) > oldestAllowedDate) { - console.debug("Skipping tile", osmSourceZoomLevel, x, y, "as a decently fresh one is available") - // The cached tiles contain decently fresh data - return; - } - tileIndexes.push(i) - }) - return tileIndexes - }) + const osmFeatureSource = new OsmFeatureSource({ isActive: useOsmApi, diff --git a/Logic/FeatureSource/Sources/FilteringFeatureSource.ts b/Logic/FeatureSource/Sources/FilteringFeatureSource.ts index 6b433f88d..0c2c9d92a 100644 --- a/Logic/FeatureSource/Sources/FilteringFeatureSource.ts +++ b/Logic/FeatureSource/Sources/FilteringFeatureSource.ts @@ -28,8 +28,9 @@ export default class FilteringFeatureSource implements FeatureSourceForLayer, Ti this.layer = upstream.layer; const layer = upstream.layer; - + function update() { + const features: { feature: any; freshness: Date }[] = upstream.features.data; const newFeatures = features.filter((f) => { if ( @@ -60,11 +61,6 @@ export default class FilteringFeatureSource implements FeatureSourceForLayer, Ti } - if (!layer.isDisplayed) { - // The layer itself is either disabled or hidden due to zoom constraints - // We should return true, but it might still match some other layer - return false; - } return true; }); @@ -75,20 +71,8 @@ export default class FilteringFeatureSource implements FeatureSourceForLayer, Ti update(); }); - layer.isDisplayed.addCallback(isShown => { - if (isShown) { - update(); - } else { - self.features.setData([]) - } - }); layer.appliedFilters.addCallback(_ => { - if (!layer.isDisplayed.data) { - // Currently not shown. - // Note that a change in 'isSHown' will trigger an update as well, so we don't have to watch it another time - return; - } update() }) diff --git a/Logic/MetaTagging.ts b/Logic/MetaTagging.ts index 2a85e6292..ee4209f4a 100644 --- a/Logic/MetaTagging.ts +++ b/Logic/MetaTagging.ts @@ -63,7 +63,7 @@ export default class MetaTagging { } somethingChanged = somethingChanged || metatag.applyMetaTagsOnFeature(feature, freshness) } catch (e) { - console.error("Could not calculate metatag for ", metatag.keys.join(","), ":", e) + console.error("Could not calculate metatag for ", metatag.keys.join(","), ":", e, e.stack) } } diff --git a/Logic/Osm/Changes.ts b/Logic/Osm/Changes.ts index b4bf3b4ec..570bf553b 100644 --- a/Logic/Osm/Changes.ts +++ b/Logic/Osm/Changes.ts @@ -149,14 +149,13 @@ export class Changes { } - public applyAction(action: OsmChangeAction) { - action.Perform(this).then(changes => { - console.log("Received changes:", changes) - this.pendingChanges.data.push(...changes); - this.pendingChanges.ping(); - this.allChanges.data.push(...changes) - this.allChanges.ping() - }) + public async applyAction(action: OsmChangeAction): Promise { + const changes = await action.Perform(this) + console.log("Received changes:", changes) + this.pendingChanges.data.push(...changes); + this.pendingChanges.ping(); + this.allChanges.data.push(...changes) + this.allChanges.ping() } private CreateChangesetObjects(changes: ChangeDescription[], downloadedOsmObjects: OsmObject[]): { diff --git a/Logic/Tags/RegexTag.ts b/Logic/Tags/RegexTag.ts index 20fbbbcbf..fae2fd70b 100644 --- a/Logic/Tags/RegexTag.ts +++ b/Logic/Tags/RegexTag.ts @@ -19,6 +19,9 @@ export class RegexTag extends TagsFilter { if (fromTag === undefined) { return; } + if(typeof fromTag === "number"){ + fromTag = "" + fromTag; + } if (typeof possibleRegex === "string") { return fromTag === possibleRegex; } diff --git a/Models/Constants.ts b/Models/Constants.ts index 91c9e0015..a7f79bf39 100644 --- a/Models/Constants.ts +++ b/Models/Constants.ts @@ -2,7 +2,7 @@ import {Utils} from "../Utils"; export default class Constants { - public static vNumber = "0.10.0-alpha-3"; + public static vNumber = "0.10.0-alpha-4"; public static ImgurApiKey = '7070e7167f0a25a' // The user journey states thresholds when a new feature gets unlocked diff --git a/assets/layers/cluster_style/cluster_style.json b/assets/layers/cluster_style/cluster_style.json new file mode 100644 index 000000000..ea6760612 --- /dev/null +++ b/assets/layers/cluster_style/cluster_style.json @@ -0,0 +1,36 @@ +{ + "id": "cluster_style", + "description": "The style for the clustering in all themes.", + "source": { + "osmTags": "tileId~*" + }, + "color": { + "render": "#3c3", + "mappings": [ + { + "if": "count>200", + "then": "#f33" + }, + { + "if": "count>100", + "then": "#c93" + }, + { + "if": "count>50", + "then": "#cc3" + } + ] + }, + "width": { + "render": "1" + }, + "label": { + "render": "
{count}
", + "mappings": [ + { + "if": "count>99", + "then": "
>99
" + } + ] + } +} \ No newline at end of file diff --git a/assets/themes/toerisme_vlaanderen/toerisme_vlaanderen.json b/assets/themes/toerisme_vlaanderen/toerisme_vlaanderen.json index aeea7f806..2b303ea14 100644 --- a/assets/themes/toerisme_vlaanderen/toerisme_vlaanderen.json +++ b/assets/themes/toerisme_vlaanderen/toerisme_vlaanderen.json @@ -14,7 +14,7 @@ "nl": "Een kaart om toeristisch relevante info op aan te duiden" }, "description": { - "nl": "Op deze kaart kan je info zien voor toeristen en zelf aanpasingen maken, zichtbaar voor iedereen" + "nl": "Op deze kaart kan je info zien die relevant is voor toerisme, zoals:
  • Eetgelegenheden
  • Cafés en bars
  • (Fiets)oplaadpunten
  • Fietspompen, fietserverhuur en fietswinkels
  • Uitkijktorens
  • ...
Zie je fouten op de kaart? Dan kan je zelf makkelijk aanpasingen maken, die zichtbaar zijn voor iedereen. Hiervoor dien je een gratis OpenStreetMap account voor te maken.

Met de steun van Toerisme Vlaanderen" }, "icon": "./assets/svg/star.svg", "startZoom": 8, @@ -39,9 +39,5 @@ "binocular", "observation_tower" ], - "overiddeAll": { - "minZoomVisible": 0 - }, - "hideFromOverview": true } \ No newline at end of file diff --git a/langs/themes/nl.json b/langs/themes/nl.json index a1e3dee82..e3220df4d 100644 --- a/langs/themes/nl.json +++ b/langs/themes/nl.json @@ -1008,7 +1008,7 @@ "title": "Surveillance under Surveillance" }, "toerisme_vlaanderen": { - "description": "Op deze kaart kan je info zien voor toeristen en zelf aanpasingen maken, zichtbaar voor iedereen", + "description": "Op deze kaart kan je info zien die relevant is voor toerisme, zoals:
  • Eetgelegenheden
  • Cafés en bars
  • (Fiets)oplaadpunten
  • Fietspompen, fietserverhuur en fietswinkels
  • Uitkijktorens
  • ...
Zie je fouten op de kaart? Dan kan je zelf makkelijk aanpasingen maken, die zichtbaar zijn voor iedereen. Hiervoor dien je een gratis OpenStreetMap account voor te maken.

Met de steun van Toerisme Vlaanderen", "shortDescription": "Een kaart om toeristisch relevante info op aan te duiden", "title": "Toeristisch relevante info" },