Fix duplicate buildings for grb layer; add default flag for filters, performance improvement

This commit is contained in:
Pieter Vander Vennet 2022-02-11 03:57:39 +01:00
parent 31205f3430
commit 695a0867c7
13 changed files with 157 additions and 111 deletions

View file

@ -204,7 +204,7 @@ export default class FeaturePipeline {
TiledFeatureSource.createHierarchy(src, {
layer: src.layer,
minZoomLevel: this.osmSourceZoomLevel,
dontEnforceMinZoom: true,
noDuplicates: true,
registerTile: (tile) => {
new RegisteringAllFromFeatureSourceActor(tile, state.allElements)
perLayerHierarchy.get(id).registerTile(tile)
@ -276,7 +276,7 @@ export default class FeaturePipeline {
(source) => TiledFeatureSource.createHierarchy(source, {
layer: source.layer,
minZoomLevel: source.layer.layerDef.minzoom,
dontEnforceMinZoom: true,
noDuplicates: true,
maxFeatureCount: state.layoutToUse.clustering.minNeededElements,
maxZoomLevel: state.layoutToUse.clustering.maxZoom,
registerTile: (tile) => {

View file

@ -18,19 +18,13 @@ export default class GeoJsonSource implements FeatureSourceForLayer, Tiled {
public readonly layer: FilteredLayer;
public readonly tileIndex
public readonly bbox;
private readonly seenids: Set<string> = new Set<string>()
/**
* 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<Set<string>>
private readonly seenids: Set<string>;
private readonly idKey ?: string;
public constructor(flayer: FilteredLayer,
zxy?: [number, number, number] | BBox,
options?: {
featureIdBlacklist?: UIEventSource<Set<string>>
featureIdBlacklist?: Set<string>
}) {
if (flayer.layerDef.source.geojsonZoomLevel !== undefined && zxy === undefined) {
@ -38,7 +32,8 @@ export default class GeoJsonSource implements FeatureSourceForLayer, Tiled {
}
this.layer = flayer;
this.featureIdBlacklist = options?.featureIdBlacklist
this.idKey = flayer.layerDef.source.idKey
this.seenids = options?.featureIdBlacklist ?? new Set<string>()
let url = flayer.layerDef.source.geojsonSource.replace("{layer}", flayer.layerDef.id);
if (zxy !== undefined) {
let tile_bbox: BBox;
@ -106,6 +101,10 @@ export default class GeoJsonSource implements FeatureSourceForLayer, Tiled {
}
}
if(self.idKey !== undefined){
props.id = props[self.idKey]
}
if (props.id === undefined) {
props.id = url + "/" + i;
feature.id = url + "/" + i;
@ -117,10 +116,6 @@ export default class GeoJsonSource implements FeatureSourceForLayer, Tiled {
}
self.seenids.add(props.id)
if (self.featureIdBlacklist?.data?.has(props.id)) {
continue;
}
let freshness: Date = time;
if (feature.properties["_last_edit:timestamp"] !== undefined) {
freshness = new Date(props["_last_edit:timestamp"])

View file

@ -20,7 +20,7 @@ export class NewGeometryFromChangesFeatureSource implements FeatureSource {
const features = this.features.data;
const self = this;
changes.pendingChanges.addCallbackAndRunD(changes => {
changes.pendingChanges.stabilized(100).addCallbackAndRunD(changes => {
if (changes.length === 0) {
return;
}

View file

@ -55,8 +55,7 @@ export default class DynamicGeoJsonTileSource extends DynamicTileSource {
}
}
const seenIds = new Set<string>();
const blackList = new UIEventSource(seenIds)
const blackList = (new Set<string>())
super(
layer,
source.geojsonZoomLevel,
@ -76,10 +75,7 @@ export default class DynamicGeoJsonTileSource extends DynamicTileSource {
featureIdBlacklist: blackList
}
)
src.features.addCallbackAndRunD(feats => {
feats.forEach(feat => seenIds.add(feat.feature.properties.id))
blackList.ping();
})
registerLayer(src)
return src
},

View file

@ -21,7 +21,6 @@ export class TileHierarchyMerger implements TileHierarchy<FeatureSourceForLayer
* Add another feature source for the given tile.
* Entries for this tile will be merged
* @param src
* @param index
*/
public registerTile(src: FeatureSource & Tiled) {

View file

@ -146,7 +146,10 @@ export default class TiledFeatureSource implements Tiled, IndexedFeatureSource,
for (const feature of features) {
const bbox = BBox.get(feature.feature)
if (this.options.dontEnforceMinZoom) {
// There are a few strategies to deal with features that cross tile boundaries
if (this.options.noDuplicates) {
// Strategy 1: We put the feature into a somewhat matching tile
if (bbox.overlapsWith(this.upper_left.bbox)) {
ulf.push(feature)
} else if (bbox.overlapsWith(this.upper_right.bbox)) {
@ -159,6 +162,7 @@ export default class TiledFeatureSource implements Tiled, IndexedFeatureSource,
overlapsboundary.push(feature)
}
} else if (this.options.minZoomLevel === undefined) {
// Strategy 2: put it into a strictly matching tile (or in this tile, which is slightly too big)
if (bbox.isContainedIn(this.upper_left.bbox)) {
ulf.push(feature)
} else if (bbox.isContainedIn(this.upper_right.bbox)) {
@ -171,7 +175,7 @@ export default class TiledFeatureSource implements Tiled, IndexedFeatureSource,
overlapsboundary.push(feature)
}
} else {
// We duplicate a feature on a boundary into every tile as we need to get to the minZoomLevel
// Strategy 3: We duplicate a feature on a boundary into every tile as we need to get to the minZoomLevel
if (bbox.overlapsWith(this.upper_left.bbox)) {
ulf.push(feature)
}
@ -201,10 +205,9 @@ export interface TiledFeatureSourceOptions {
readonly minZoomLevel?: number,
/**
* IF minZoomLevel is set, and if a feature runs through a tile boundary, it would normally be duplicated.
* Setting 'dontEnforceMinZoomLevel' will still allow bigger zoom levels for those features.
* If 'pick_first' is set, the feature will not be duplicated but set to some tile
* Setting 'dontEnforceMinZoomLevel' will assign to feature to some matching subtile.
*/
readonly dontEnforceMinZoom?: boolean | "pick_first",
readonly noDuplicates?: boolean,
readonly registerTile?: (tile: TiledFeatureSource & FeatureSourceForLayer & Tiled) => void,
readonly layer?: FilteredLayer
}