From 79facef79d4b83cb0f8d43dd35f854f7409428f7 Mon Sep 17 00:00:00 2001 From: Johann Levesque Date: Thu, 12 Dec 2024 10:03:24 -0500 Subject: [PATCH] fix some condition on panel --- .../map-event-processor.ts | 16 +++++++++++++++- .../src/core/components/crosshair/crosshair.tsx | 5 +---- .../core/components/details/details-panel.tsx | 7 +++++-- .../components/details/feature-info-table.tsx | 15 ++++++--------- .../map-state.ts | 6 +++--- packages/geoview-core/src/geo/map/map-viewer.ts | 8 ++++---- 6 files changed, 34 insertions(+), 23 deletions(-) diff --git a/packages/geoview-core/src/api/event-processors/event-processor-children/map-event-processor.ts b/packages/geoview-core/src/api/event-processors/event-processor-children/map-event-processor.ts index a0b89902274..8a754694dfd 100644 --- a/packages/geoview-core/src/api/event-processors/event-processor-children/map-event-processor.ts +++ b/packages/geoview-core/src/api/event-processors/event-processor-children/map-event-processor.ts @@ -48,7 +48,7 @@ import { UIEventProcessor } from './ui-event-processor'; import { TypeMapFeaturesConfig } from '@/core/types/global-types'; import { TypeClickMarker } from '@/core/components'; import { IMapState, TypeOrderedLayerInfo, TypeScaleInfo } from '@/core/stores/store-interface-and-intial-values/map-state'; -import { TypeFeatureInfoResultSet, TypeHoverFeatureInfo } from '@/core/stores/store-interface-and-intial-values/feature-info-state'; +import { TypeHoverFeatureInfo } from '@/core/stores/store-interface-and-intial-values/feature-info-state'; import { TypeBasemapProps } from '@/geo/layer/basemap/basemap-types'; import { LegendEventProcessor } from './legend-event-processor'; import { TypeLegendLayer } from '@/core/components/layers/types'; @@ -109,6 +109,20 @@ export class MapEventProcessor extends AbstractEventProcessor { (removedFeatures[i].geometry as TypeGeometry).ol_uid ); } + }, + { + equalityFn: (prev, curr) => { + // Quick length checks first (prevents re-render) and calls to to removeHighlight + if (prev === curr) return true; + if (prev.length !== curr.length) return false; + if (prev.length === 0) return true; + + // Use Set for O(1) lookup instead of array operations + const prevUids = new Set(prev.map((feature) => (feature.geometry as TypeGeometry).ol_uid)); + + // Single pass through current features + return curr.every((feature) => prevUids.has((feature.geometry as TypeGeometry).ol_uid)); + }, } ); diff --git a/packages/geoview-core/src/core/components/crosshair/crosshair.tsx b/packages/geoview-core/src/core/components/crosshair/crosshair.tsx index 3e1dadc872b..45c250b3457 100644 --- a/packages/geoview-core/src/core/components/crosshair/crosshair.tsx +++ b/packages/geoview-core/src/core/components/crosshair/crosshair.tsx @@ -47,10 +47,7 @@ export const Crosshair = memo(function Crosshair({ mapTargetElement }: Crosshair logger.logTraceUseCallback('CROSSHAIR - simulateClick', pointerPosition); if (event.key === 'Enter' && pointerPosition) { // Update the store - setClickCoordinates(pointerPosition).catch((error) => { - // Log - logger.logPromiseFailed('Failed to setClickCoordinates in crosshair.simulateClick', error); - }); + setClickCoordinates(pointerPosition); } }, [pointerPosition, setClickCoordinates] diff --git a/packages/geoview-core/src/core/components/details/details-panel.tsx b/packages/geoview-core/src/core/components/details/details-panel.tsx index d2264680370..cdbc462d711 100644 --- a/packages/geoview-core/src/core/components/details/details-panel.tsx +++ b/packages/geoview-core/src/core/components/details/details-panel.tsx @@ -426,9 +426,12 @@ export function DetailsPanel({ fullWidth = false }: DetailsPanelType): JSX.Eleme * NOTE: Here we return null, so that in responsive grid layout, it can be used as flag to render the guide for details. * @returns {JSX.Element | null} JSX.Element | null */ - logger.logMarkerStart('DETAILS-MARKER'); const renderContent = (): JSX.Element | null => { - if (!memoIsAllLayersQueryStatusProcessed()) { + // If there is no layer, return null for the guide to show + if (memoLayersList && memoLayersList.length === 0) return null; + + // Until process, return skeleton + if (!memoIsAllLayersQueryStatusProcessed() || !(memoSelectedLayerDataFeatures && memoSelectedLayerDataFeatures.length > 0)) { return ; } diff --git a/packages/geoview-core/src/core/components/details/feature-info-table.tsx b/packages/geoview-core/src/core/components/details/feature-info-table.tsx index dc40ba95853..d4ffbdadeb7 100644 --- a/packages/geoview-core/src/core/components/details/feature-info-table.tsx +++ b/packages/geoview-core/src/core/components/details/feature-info-table.tsx @@ -86,7 +86,7 @@ export const FeatureItem = memo(function FeatureItem({ return ( - + ); }); @@ -97,18 +97,15 @@ export const FeatureRow = memo(function FeatureRow({ featureInfoItem, index, onI const { alias, value } = featureInfoItem; // Convert value to string, handling arrays and other types - const stringValue = useMemo((): string => { + const stringValue = useMemo((): string[] => { if (Array.isArray(value)) { - return value.map((item) => stringify(item)).join(';'); + return [value.map((item) => stringify(item)).join(';')] as string[]; } - return stringify(value) as string; + return [stringify(value)] as string[]; }, [value]); - // Split text but leave html intact - const valueArray = alias !== 'html' ? stringValue.split(';') : [stringValue]; - // Generate stable IDs for each item when component mounts - const itemIds = useMemo(() => valueArray.map(() => generateId()), [valueArray]); + const itemIds = useMemo(() => stringValue.map(() => generateId()), [stringValue]); return ( - {valueArray.map((item: string, idx: number) => ( + {stringValue.map((item: string, idx: number) => ( Promise; zoomToMyLocation: (position: GeolocationPosition) => Promise; transformPoints: (coords: Coordinate[], outputProjection: number) => Coordinate[]; - setClickCoordinates: (pointerPosition: TypeMapMouseInfo) => Promise; + setClickCoordinates: (pointerPosition: TypeMapMouseInfo) => void; setCurrentBasemapOptions: (basemapOptions: TypeBasemapOptions) => void; setFixNorth: (ifFix: boolean) => void; setOverlayClickMarkerRef: (htmlRef: HTMLElement) => void; @@ -459,7 +459,7 @@ export function initializeMapState(set: TypeSetStore, get: TypeGetStore): IMapSt * @param {TypeMapMouseInfo} pointerPosition - The pointer position. * @returns {Promise} */ - setClickCoordinates: (pointerPosition: TypeMapMouseInfo): Promise => { + setClickCoordinates: (pointerPosition: TypeMapMouseInfo): void => { // Redirect to processor return MapEventProcessor.setClickCoordinates(get().mapId, pointerPosition); }, diff --git a/packages/geoview-core/src/geo/map/map-viewer.ts b/packages/geoview-core/src/geo/map/map-viewer.ts index 12365f032ac..b5459648cac 100644 --- a/packages/geoview-core/src/geo/map/map-viewer.ts +++ b/packages/geoview-core/src/geo/map/map-viewer.ts @@ -547,7 +547,7 @@ export class MapViewer { }); } } - }, 250); + }, 1000); } /** @@ -692,7 +692,7 @@ export class MapViewer { this.#checkMapLayersLoaded(); } } - }, 250); + }, 1000); } /** @@ -726,7 +726,7 @@ export class MapViewer { this.#emitMapLayersLoaded(); } } - }, 250); + }, 1000); } /** @@ -761,7 +761,7 @@ export class MapViewer { resolve(); } } - }, 250); + }, 1000); }); }