Skip to content

Commit

Permalink
chore(web): fix feature unselection (#812)
Browse files Browse the repository at this point in the history
  • Loading branch information
keiya01 authored Nov 15, 2023
1 parent b97cd2e commit 3e6b7c6
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions web/src/beta/lib/core/Map/Layers/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -821,7 +821,8 @@ function useSelection({
layerId?: string;
featureId?: string[];
}[],
) => {
): boolean => {
let shouldUpdate = false;
for (const { layerId, featureId } of layers) {
if (!layerId || !featureId) continue;

Expand All @@ -838,13 +839,14 @@ function useSelection({

if (featureId.length) {
engineRef?.current?.selectFeatures(layerId, featureId);
updateStyle(layerId);
selectedFeatureIds.current[selectedFeatureIdsIndex].featureIds =
selectedFeatureIds.current[selectedFeatureIdsIndex].featureIds.concat(featureId);
shouldUpdate = true;
}
}
return shouldUpdate;
},
[engineRef, updateStyle],
[engineRef],
);

const selectFeatures = useCallback(
Expand All @@ -856,16 +858,26 @@ function useSelection({
options?: LayerSelectionReason,
info?: SelectedFeatureInfo,
) => {
let shouldUpdate = false;
selectedFeatureIds.current.forEach(id => {
engineRef?.current?.unselectFeatures(id.layerId, id.featureIds);
updateStyle(id.layerId);
shouldUpdate = true;
});

const prevSelectedFeatureIds = selectedFeatureIds.current;
selectedFeatureIds.current = [];

updateSelectedLayerForFeature(layers, options, info);

updateEngineFeatures(layers);
shouldUpdate = updateEngineFeatures(layers) || shouldUpdate;

if (!shouldUpdate) return;

for (const { layerId } of [...layers, ...prevSelectedFeatureIds]) {
if (!layerId) continue;
// Wait 1 frame for cesium to synchronize the updated value.
requestAnimationFrame(() => updateStyle(layerId));
}
},
[engineRef, updateStyle, updateEngineFeatures, updateSelectedLayerForFeature],
);
Expand Down

0 comments on commit 3e6b7c6

Please sign in to comment.