Skip to content

Commit

Permalink
chore(web): fix some bugs around feature selection functionality (#736)
Browse files Browse the repository at this point in the history
  • Loading branch information
keiya01 authored Oct 12, 2023
1 parent d4127b7 commit 2476c3b
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
8 changes: 5 additions & 3 deletions web/src/beta/lib/core/engines/Cesium/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -317,8 +317,6 @@ export default ({
const prevSelectedEntity = useRef<Entity | Cesium3DTileset | InternalCesium3DTileFeature>();
// manage layer selection
useEffect(() => {
if (!(featureFlags & FEATURE_FLAGS.SINGLE_SELECTION)) return;

const viewer = cesium.current?.cesiumElement;
if (!viewer || viewer.isDestroyed()) return;

Expand All @@ -337,10 +335,12 @@ export default ({
const entity =
findEntity(viewer, undefined, selectedLayerId?.featureId) ||
findEntity(viewer, selectedLayerId?.layerId);

if (prevSelectedEntity.current === entity) return;

if (!entity || entity instanceof Entity) {
viewer.selectedEntity = entity;
}
if (prevSelectedEntity.current === entity) return;
prevSelectedEntity.current = entity;

// TODO: Support layers.selectFeature API for MVT
Expand Down Expand Up @@ -512,6 +512,8 @@ export default ({
const viewer = cesium.current?.cesiumElement;
if (!viewer || viewer.isDestroyed()) return;

viewer.selectedEntity = undefined;

if (target && "id" in target && target.id instanceof Entity && isSelectable(target.id)) {
const tag = getTag(target.id);
const layer = tag?.layerId
Expand Down
2 changes: 1 addition & 1 deletion web/src/beta/lib/core/engines/Cesium/pickMany.ts
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ export const pickManyFromViewportAsFeature = (
for (const obj of objs) {
const [layerId, f] = convertObjToComputedFeature(viewer, obj) ?? [];
const pickedFeature = f ? { ...f, layerId } : undefined;
if (!pickedFeature || !condition?.(pickedFeature)) {
if (!pickedFeature || (condition && !condition(pickedFeature))) {
continue;
}
result.push(pickedFeature);
Expand Down
7 changes: 4 additions & 3 deletions web/src/beta/lib/core/engines/Cesium/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -368,14 +368,15 @@ export const convertObjToComputedFeature = (
];
}

if (obj instanceof Entity) {
const tag = getTag(obj);
if (obj instanceof Entity || ("id" in obj && obj.id instanceof Entity)) {
const entity = (obj instanceof Entity ? obj : obj.id) as Entity;
const tag = getTag(entity);
return [
tag?.layerId,
tag?.computedFeature ?? {
type: "computedFeature",
id: tag?.featureId ?? "",
properties: convertEntityProperties(viewer, obj),
properties: convertEntityProperties(viewer, entity),
},
];
}
Expand Down

0 comments on commit 2476c3b

Please sign in to comment.