diff --git a/src/Logic/FeatureSource/Sources/FilteringFeatureSource.ts b/src/Logic/FeatureSource/Sources/FilteringFeatureSource.ts index cc4980a2a..9e362369c 100644 --- a/src/Logic/FeatureSource/Sources/FilteringFeatureSource.ts +++ b/src/Logic/FeatureSource/Sources/FilteringFeatureSource.ts @@ -1,12 +1,13 @@ import { Store, UIEventSource } from "../../UIEventSource" import FilteredLayer from "../../../Models/FilteredLayer" import { FeatureSource } from "../FeatureSource" -import { Feature } from "geojson" +import { Feature, Geometry } from "geojson" import { GlobalFilter } from "../../../Models/GlobalFilter" +import { OsmTags } from "../../../Models/OsmFeature" -export default class FilteringFeatureSource implements FeatureSource { - public features: UIEventSource = new UIEventSource([]) - private readonly upstream: FeatureSource +export default class FilteringFeatureSource> implements FeatureSource { + public readonly features: UIEventSource = new UIEventSource([]) + private readonly upstream: FeatureSource private readonly _fetchStore?: (id: string) => Store> private readonly _globalFilters?: Store private readonly _alreadyRegistered = new Set>() @@ -18,7 +19,7 @@ export default class FilteringFeatureSource implements FeatureSource { constructor( layer: FilteredLayer, - upstream: FeatureSource, + upstream: FeatureSource, fetchStore?: (id: string) => Store>, globalFilters?: Store, metataggingUpdated?: Store, @@ -40,7 +41,7 @@ export default class FilteringFeatureSource implements FeatureSource { }) layer.appliedFilters.forEach((value) => - value.addCallback((_) => { + value.addCallback(() => { this.update() }) ) @@ -68,7 +69,7 @@ export default class FilteringFeatureSource implements FeatureSource { private update() { const layer = this._layer - const features: Feature[] = this.upstream.features.data ?? [] + const features: T[] = this.upstream.features.data ?? [] const includedFeatureIds = new Set() const globalFilters = this._globalFilters?.data?.map((f) => f) const zoomlevel = this._zoomlevel?.data @@ -121,10 +122,9 @@ export default class FilteringFeatureSource implements FeatureSource { } this._alreadyRegistered.add(src) - const self = this // Add a callback as a changed tag might change the filter - src.addCallbackAndRunD((_) => { - self._is_dirty.setData(true) + src.addCallbackAndRunD(() => { + this._is_dirty.setData(true) }) } } diff --git a/src/Logic/FeatureSource/Sources/IfVisibleFeatureSource.ts b/src/Logic/FeatureSource/Sources/IfVisibleFeatureSource.ts index b52660368..f8b02db71 100644 --- a/src/Logic/FeatureSource/Sources/IfVisibleFeatureSource.ts +++ b/src/Logic/FeatureSource/Sources/IfVisibleFeatureSource.ts @@ -12,8 +12,8 @@ export class IfVisibleFeatureSource implements FeatureSource< let dirty = false upstream.features.addCallbackAndRun(features => { if (!visible.data) { - console.log(">>> not writing data as not visible") dirty = true + this._features.set([]) return } this._features.set(features) diff --git a/src/Logic/FeatureSource/TiledFeatureSource/ClusteringFeatureSource.ts b/src/Logic/FeatureSource/TiledFeatureSource/ClusteringFeatureSource.ts index c5c629600..bd74c183a 100644 --- a/src/Logic/FeatureSource/TiledFeatureSource/ClusteringFeatureSource.ts +++ b/src/Logic/FeatureSource/TiledFeatureSource/ClusteringFeatureSource.ts @@ -140,13 +140,14 @@ export class ClusterGrouping implements FeatureSource[] = [] + const now = new Date().getTime() + "" for (const tileId of countPerTile.keys()) { const coordinates = Tiles.centerPointOf(tileId) features.push({ type: "Feature", properties: { total_metric: "" + countPerTile.get(tileId), - id: "clustered_all_" + tileId + id: "clustered_all_" + tileId + "_" + now // We add the date to force a fresh ID every time, this makes sure values are updated }, geometry: { type: "Point", diff --git a/src/UI/Map/PointRenderingLayer.ts b/src/UI/Map/PointRenderingLayer.ts index f41154301..d79da1dda 100644 --- a/src/UI/Map/PointRenderingLayer.ts +++ b/src/UI/Map/PointRenderingLayer.ts @@ -79,12 +79,12 @@ export class PointRenderingLayer { } allowed_location_codes.forEach((code) => { const marker = this._allMarkers.get(selected.properties.id) - .get(code) + ?.get(code) ?.getElement() if (marker === undefined) { return } - marker?.classList?.add("selected") + marker.classList?.add("selected") this._markedAsSelected.push(marker) }) }) diff --git a/src/UI/Map/ShowDataLayer.ts b/src/UI/Map/ShowDataLayer.ts index 4d1e5c044..67b6a7285 100644 --- a/src/UI/Map/ShowDataLayer.ts +++ b/src/UI/Map/ShowDataLayer.ts @@ -388,20 +388,26 @@ export default class ShowDataLayer { }) } + /** + * Show the data, unless they are clustered. + * This method does _not_ add the clusters themselves to the map, + * this should be done independently. In a themeViewGui, this is done by the 'addSpecialLayers' + * @see ClusterGrouping + * @param mlmap + * @param state + * @param options + */ public static showLayerClustered(mlmap: Store, state: { mapProperties: { zoom: UIEventSource } }, options: ShowDataLayerOptions & { layer: LayerConfig } ) { - options.preprocessPoints = feats => { - const clustering = new ClusteringFeatureSource(feats, state.mapProperties.zoom.map(z => z + 2), + options.preprocessPoints = feats => + new ClusteringFeatureSource(feats, state.mapProperties.zoom.map(z => z + 2), options.layer.id, { cutoff: 7, showSummaryAt: "tilecenter" }) - - return clustering - } new ShowDataLayer(mlmap, options) } @@ -417,8 +423,6 @@ export default class ShowDataLayer { }) } - public destruct() {} - private static zoomToCurrentFeatures(map: MlMap, features: Feature[]) { if (!features || !map || features.length == 0) { return