diff --git a/Logic/FeatureSource/Sources/GeoJsonSource.ts b/Logic/FeatureSource/Sources/GeoJsonSource.ts index 301f1bc55..b341a0dd3 100644 --- a/Logic/FeatureSource/Sources/GeoJsonSource.ts +++ b/Logic/FeatureSource/Sources/GeoJsonSource.ts @@ -21,14 +21,26 @@ export default class GeoJsonSource implements FeatureSourceForLayer, Tiled { public readonly tileIndex public readonly bbox; + /** + * Only used if the actual source is a tiled geojson. + * A big feature might be contained in multiple tiles. + * However, we only want to load them once. The blacklist thus contains all ids of all features previously seen + * @private + */ + private readonly featureIdBlacklist?: UIEventSource> + public constructor(flayer: FilteredLayer, - zxy?: [number, number, number]) { + zxy?: [number, number, number], + options?: { + featureIdBlacklist?: UIEventSource> + }) { if (flayer.layerDef.source.geojsonZoomLevel !== undefined && zxy === undefined) { throw "Dynamic layers are not supported. Use 'DynamicGeoJsonTileSource instead" } this.layer = flayer; + this.featureIdBlacklist = options?.featureIdBlacklist let url = flayer.layerDef.source.geojsonSource.replace("{layer}", flayer.layerDef.id); if (zxy !== undefined) { const [z, x, y] = zxy; @@ -68,6 +80,7 @@ export default class GeoJsonSource implements FeatureSourceForLayer, Tiled { const props = feature.properties for (const key in props) { if (typeof props[key] !== "string") { + // Make sure all the values are string, it crashes stuff otherwise props[key] = "" + props[key] } } @@ -82,6 +95,10 @@ export default class GeoJsonSource implements FeatureSourceForLayer, Tiled { continue; } self.seenids.add(props.id) + + if(self.featureIdBlacklist?.data?.has(props.id)){ + continue; + } let freshness: Date = time; if (feature.properties["_last_edit:timestamp"] !== undefined) { diff --git a/Logic/FeatureSource/TiledFeatureSource/DynamicGeoJsonTileSource.ts b/Logic/FeatureSource/TiledFeatureSource/DynamicGeoJsonTileSource.ts index 8843b182a..fcfdbea5a 100644 --- a/Logic/FeatureSource/TiledFeatureSource/DynamicGeoJsonTileSource.ts +++ b/Logic/FeatureSource/TiledFeatureSource/DynamicGeoJsonTileSource.ts @@ -37,6 +37,8 @@ export default class DynamicGeoJsonTileSource extends DynamicTileSource { console.warn("No whitelist found for ", layer.layerDef.id, err) }) + const seenIds = new Set(); + const blackList = new UIEventSource(seenIds) super( layer, source.geojsonZoomLevel, @@ -50,8 +52,15 @@ export default class DynamicGeoJsonTileSource extends DynamicTileSource { const src = new GeoJsonSource( layer, - zxy + zxy, + { + featureIdBlacklist: blackList + } ) + src.features.addCallbackAndRunD(feats => { + feats.forEach(feat => seenIds.add(feat.feature.properties.id)) + blackList.ping(); + }) registerLayer(src) return src },