Skip to content

Commit

Permalink
fix: make searching more accurate and performant
Browse files Browse the repository at this point in the history
Filter by geometry before adding layer to the map. Prior to this change the layer was loading all of it's features when added to the map and then filtering by geometry.

#537
  • Loading branch information
stdavis committed Sep 8, 2023
1 parent 7ec832d commit bb0a992
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/components/Map.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,18 @@ export default function MapComponent() {
}
}

// this essentially applies a geometry filter to the layer before it's added to the map
// this is done to prevent the map from requesting ALL of the features from the layer
const ids = await featureLayer.queryObjectIds({
where,
geometry: filter.geometry,
});
if (ids?.length) {
featureLayer.definitionExpression = `${
featureLayer.objectIdField
} IN (${ids.join(',')})`;
}

map.current.add(
featureLayer,
featureLayer.geometryType === 'polygon' ? 0 : null,
Expand All @@ -348,6 +360,8 @@ export default function MapComponent() {
};

await whenOnce(() => layerView.updating === false);

// client side queries
const { count, extent } = await layerView.queryExtent();
const featureSet = await layerView.queryFeatures();

Expand Down

0 comments on commit bb0a992

Please sign in to comment.