Skip to content

Commit

Permalink
Filter duplicate features from wrapped tiles based on index in featur…
Browse files Browse the repository at this point in the history
…e_index instead of feature.id (which may be undefined).
  • Loading branch information
ChrisLoer committed May 25, 2017
1 parent bdb217a commit 6131a7b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 22 deletions.
2 changes: 1 addition & 1 deletion src/data/feature_index.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ class FeatureIndex {
if (layerResult === undefined) {
layerResult = result[layerID] = [];
}
layerResult.push(geojsonFeature);
layerResult.push({ featureIndex: index, feature: geojsonFeature });
}
}
}
Expand Down
29 changes: 8 additions & 21 deletions src/source/query_features.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,35 +51,22 @@ function sortTilesIn(a, b) {
}

function mergeRenderedFeatureLayers(tiles) {
// Avoid merge work for common cases
if (!tiles.length) {
return {};
} else if (tiles.length === 1) {
return tiles[0].queryResults;
}

// Merge results from all tiles, but if two tiles share the same
// wrapped ID, don't duplicate features between the two tiles
const result = {};
const wrappedIDFeatureMap = {};
const wrappedIDLayerMap = {};
for (const tile of tiles) {
const queryResults = tile.queryResults;
const wrappedID = tile.wrappedTileID;
const wrappedIDFeatures = wrappedIDFeatureMap[wrappedID] = wrappedIDFeatureMap[wrappedID] || {};
const wrappedIDLayers = wrappedIDLayerMap[wrappedID] = wrappedIDLayerMap[wrappedID] || {};
for (const layerID in queryResults) {
const tileFeatures = queryResults[layerID];
let resultFeatures = result[layerID];
if (resultFeatures === undefined) {
resultFeatures = result[layerID] = tileFeatures;
tileFeatures.forEach((tileFeature) => {
wrappedIDFeatures[tileFeature.id] = true;
});
} else {
for (const tileFeature of tileFeatures) {
if (!tileFeature.id || !wrappedIDFeatures[tileFeature.id]) {
wrappedIDFeatures[tileFeature.id] = true;
resultFeatures.push(tileFeature);
}
const wrappedIDFeatures = wrappedIDLayers[layerID] = wrappedIDLayers[layerID] || {};
const resultFeatures = result[layerID] = result[layerID] || [];
for (const tileFeature of tileFeatures) {
if (!wrappedIDFeatures[tileFeature.featureIndex]) {
wrappedIDFeatures[tileFeature.featureIndex] = true;
resultFeatures.push(tileFeature.feature);
}
}
}
Expand Down

0 comments on commit 6131a7b

Please sign in to comment.