Skip to content

Commit

Permalink
chore(web): Add hideIndicator On Selecting (#866)
Browse files Browse the repository at this point in the history
  • Loading branch information
m-abe-dev committed Jan 18, 2024
1 parent ace1727 commit 9a1e322
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 16 deletions.
7 changes: 5 additions & 2 deletions web/src/beta/lib/core/engines/Cesium/Feature/Marker/index.tsx
Expand Up @@ -79,6 +79,7 @@ export default function Marker({ property, id, isVisible, geometry, layer, featu
eyeOffset,
pixelOffset,
heightReference: hr,
hideIndicator,
} = property ?? {};

const { useTransition, translate } = layer?.transition ?? {};
Expand Down Expand Up @@ -186,7 +187,8 @@ export default function Marker({ property, id, isVisible, geometry, layer, featu
featureId={feature?.id}
unselectable
properties={feature?.properties}
availability={availability}>
availability={availability}
hideIndicator={hideIndicator}>
<PolylineGraphics
positions={extrudePoints}
material={extrudePointsLineColor}
Expand All @@ -206,7 +208,8 @@ export default function Marker({ property, id, isVisible, geometry, layer, featu
featureId={feature?.id}
draggable
properties={feature?.properties}
availability={availability}>
availability={availability}
hideIndicator={hideIndicator}>
{style === "point" ? (
<PointGraphics
pixelSize={pointSize}
Expand Down
Expand Up @@ -18,7 +18,9 @@ import {
type FeatureProps,
} from "../utils";

export type Props = FeatureProps<Property> & { disableWorkaround?: boolean };
export type Props = FeatureProps<Property> & {
disableWorkaround?: boolean;
};

export type Property = PolygonAppearance & {
polygon?: PolygonValue;
Expand Down Expand Up @@ -56,6 +58,7 @@ export default function Polygon({
shadows,
extrudedHeight,
classificationType: ct,
hideIndicator,
} = property ?? {};

const hierarchy = useCustomCompareMemo(
Expand Down Expand Up @@ -121,7 +124,8 @@ export default function Polygon({
layerId={layer?.id}
featureId={feature?.id}
availability={availability}
properties={feature?.properties}>
properties={feature?.properties}
hideIndicator={hideIndicator}>
<PolygonGraphics
hierarchy={hierarchy}
fill={fill}
Expand Down
Expand Up @@ -18,7 +18,6 @@ import {
} from "../utils";

export type Props = FeatureProps<Property>;

export type Property = PolylineAppearance & {
coordinates?: Coordinates;
};
Expand All @@ -43,6 +42,7 @@ export default function Polyline({ id, isVisible, property, geometry, layer, fea
strokeWidth = 1,
shadows,
classificationType: ct,
hideIndicator,
} = property ?? {};

const positions = useCustomCompareMemo(
Expand All @@ -67,7 +67,8 @@ export default function Polyline({ id, isVisible, property, geometry, layer, fea
layerId={layer?.id}
featureId={feature?.id}
availability={availability}
properties={feature?.properties}>
properties={feature?.properties}
hideIndicator={hideIndicator}>
<PolylineGraphics
positions={positions}
width={strokeWidth}
Expand Down
14 changes: 13 additions & 1 deletion web/src/beta/lib/core/engines/Cesium/Feature/utils.tsx
Expand Up @@ -66,6 +66,7 @@ export type Tag = {
originalProperties?: any;
computedFeature?: ComputedFeature;
isFeatureSelected?: boolean;
hideIndicator?: boolean;
};

export const EntityExt = forwardRef(EntityExtComponent);
Expand All @@ -77,6 +78,7 @@ function EntityExtComponent(
draggable,
unselectable,
legacyLocationPropertyKey,
hideIndicator,
...props
}: ComponentProps<typeof Entity> & Tag,
ref: ForwardedRef<CesiumComponentRef<CesiumEntity>>,
Expand All @@ -90,8 +92,17 @@ function EntityExtComponent(
draggable,
unselectable,
legacyLocationPropertyKey,
hideIndicator,
});
}, [draggable, featureId, layerId, legacyLocationPropertyKey, props.id, unselectable]);
}, [
draggable,
featureId,
layerId,
legacyLocationPropertyKey,
props.id,
unselectable,
hideIndicator,
]);

return <Entity ref={composeRefs(ref, r)} {...props} />;
}
Expand Down Expand Up @@ -201,6 +212,7 @@ const tagObj: { [k in keyof Tag]: 1 } = {
originalProperties: 1,
computedFeature: 1,
isFeatureSelected: 1,
hideIndicator: 1,
};

const tagKeys = Object.keys(tagObj) as (keyof Tag)[];
Expand Down
43 changes: 34 additions & 9 deletions web/src/beta/lib/core/engines/Cesium/hooks.ts
Expand Up @@ -355,9 +355,13 @@ export default ({

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

if (!entity || entity instanceof Entity) {
const tag = getTag(entity);
if (!entity || (entity instanceof Entity && !tag?.hideIndicator)) {
viewer.selectedEntity = entity;
} else {
viewer.selectedEntity = undefined;
}

prevSelectedEntity.current = entity;

// TODO: Support layers.selectFeature API for MVT
Expand Down Expand Up @@ -388,7 +392,6 @@ export default ({
}
}

const tag = getTag(entity);
if (tag?.unselectable) return;

if (entity && entity instanceof Cesium3DTileFeature) {
Expand Down Expand Up @@ -529,7 +532,14 @@ export default ({
const viewer = cesium.current?.cesiumElement;
if (!viewer || viewer.isDestroyed()) return;

viewer.selectedEntity = undefined;
const entity =
findEntity(viewer, undefined, selectedLayerId?.featureId) ||
findEntity(viewer, selectedLayerId?.layerId);

const tag = getTag(entity);
if (!entity || (entity instanceof Entity && !tag?.hideIndicator)) {
viewer.selectedEntity = undefined;
}

if (target && "id" in target && target.id instanceof Entity && isSelectable(target.id)) {
const tag = getTag(target.id);
Expand All @@ -554,7 +564,11 @@ export default ({
: undefined,
);
prevSelectedEntity.current = target.id;
viewer.selectedEntity = target.id;
if (target.id instanceof Entity && !tag?.hideIndicator) {
viewer.selectedEntity = target.id;
} else {
viewer.selectedEntity = undefined;
}
return;
}

Expand Down Expand Up @@ -638,9 +652,11 @@ export default ({
// ref: https://github.com/CesiumGS/cesium/blob/9295450e64c3077d96ad579012068ea05f97842c/packages/widgets/Source/Viewer/Viewer.js#L1843-L1876
// issue: https://github.com/CesiumGS/cesium/issues/7965
requestAnimationFrame(() => {
viewer.selectedEntity = new Entity({
position: Cartographic.toCartesian(pos),
});
if (!tag?.hideIndicator) {
viewer.selectedEntity = new Entity({
position: Cartographic.toCartesian(pos),
});
}
});
}

Expand Down Expand Up @@ -675,10 +691,19 @@ export default ({
}
}

viewer.selectedEntity = undefined;
if (!entity || (entity instanceof Entity && !tag?.hideIndicator)) {
viewer.selectedEntity = undefined;
}
onLayerSelect?.();
},
[onLayerSelect, mouseEventHandles, layersRef, featureFlags],
[
onLayerSelect,
mouseEventHandles,
layersRef,
featureFlags,
selectedLayerId?.featureId,
selectedLayerId?.layerId,
],
);

// E2E test
Expand Down
3 changes: 3 additions & 0 deletions web/src/beta/lib/core/mantle/types/appearance.ts
Expand Up @@ -78,6 +78,7 @@ export type MarkerAppearance = {
far?: number;
pixelOffset?: [number, number];
eyeOffset?: [number, number, number];
hideIndicator?: boolean;
};

export type PolylineAppearance = {
Expand All @@ -89,6 +90,7 @@ export type PolylineAppearance = {
near?: number;
far?: number;
classificationType?: ClassificationType;
hideIndicator?: boolean;
};

export type PolygonAppearance = {
Expand All @@ -105,6 +107,7 @@ export type PolygonAppearance = {
far?: number;
extrudedHeight?: number;
classificationType?: ClassificationType;
hideIndicator?: boolean;
};

export type HeatMapAppearance = {
Expand Down

0 comments on commit 9a1e322

Please sign in to comment.