@dynatrace/strato-geo 3.5.2 → 3.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/esm/map/MapView.js +42 -34
- package/esm/map/MapView.js.map +2 -2
- package/esm/map/components/BubbleLayer/BubbleCircleLayer.js +2 -0
- package/esm/map/components/BubbleLayer/BubbleCircleLayer.js.map +2 -2
- package/esm/map/components/BubbleLayer/BubbleLayer.js +14 -3
- package/esm/map/components/BubbleLayer/BubbleLayer.js.map +2 -2
- package/esm/map/components/BubbleLayer/BubbleLayerTooltip.js +9 -3
- package/esm/map/components/BubbleLayer/BubbleLayerTooltip.js.map +2 -2
- package/esm/map/components/BubbleLayer/utils/parse-bubble-data-to-geo-json.js +5 -5
- package/esm/map/components/BubbleLayer/utils/parse-bubble-data-to-geo-json.js.map +2 -2
- package/esm/map/components/ChoroplethLayer/ChoroplethLayer.js +15 -7
- package/esm/map/components/ChoroplethLayer/ChoroplethLayer.js.map +2 -2
- package/esm/map/components/ChoroplethLayer/ChoroplethLayerTooltip.js +9 -3
- package/esm/map/components/ChoroplethLayer/ChoroplethLayerTooltip.js.map +2 -2
- package/esm/map/components/ChoroplethLayer/ChoroplethOutlineLayer.js +3 -1
- package/esm/map/components/ChoroplethLayer/ChoroplethOutlineLayer.js.map +2 -2
- package/esm/map/components/ChoroplethLayer/utils/parse-region-data-to-geo-json.js +6 -5
- package/esm/map/components/ChoroplethLayer/utils/parse-region-data-to-geo-json.js.map +2 -2
- package/esm/map/components/ConnectionLayer/ConnectionLayer.js +11 -6
- package/esm/map/components/ConnectionLayer/ConnectionLayer.js.map +2 -2
- package/esm/map/components/ConnectionLayer/ConnectionLayerLine.js +3 -0
- package/esm/map/components/ConnectionLayer/ConnectionLayerLine.js.map +2 -2
- package/esm/map/components/ConnectionLayer/ConnectionLayerTooltip.js +16 -12
- package/esm/map/components/ConnectionLayer/ConnectionLayerTooltip.js.map +2 -2
- package/esm/map/components/ConnectionLayer/utils/parse-connection-data-to-geo-json.js +20 -18
- package/esm/map/components/ConnectionLayer/utils/parse-connection-data-to-geo-json.js.map +2 -2
- package/esm/map/components/DotLayer/DotLayer.js +12 -3
- package/esm/map/components/DotLayer/DotLayer.js.map +2 -2
- package/esm/map/components/DotLayer/DotLayerTooltip.js +9 -3
- package/esm/map/components/DotLayer/DotLayerTooltip.js.map +2 -2
- package/esm/map/components/DotLayer/utils/parse-dot-data-to-geo-json.js +5 -5
- package/esm/map/components/DotLayer/utils/parse-dot-data-to-geo-json.js.map +2 -2
- package/esm/map/components/MapContent.js +22 -12
- package/esm/map/components/MapContent.js.map +2 -2
- package/esm/map/contexts/geo-data-lookup.context.js +8 -0
- package/esm/map/contexts/geo-data-lookup.context.js.map +7 -0
- package/esm/map/contexts/map-view-provider.context.js +9 -0
- package/esm/map/contexts/map-view-provider.context.js.map +7 -0
- package/esm/map/hooks/use-active-interaction.js +59 -43
- package/esm/map/hooks/use-active-interaction.js.map +2 -2
- package/esm/map/hooks/use-attach-image-from-icon.js +4 -2
- package/esm/map/hooks/use-attach-image-from-icon.js.map +2 -2
- package/esm/map/hooks/use-hover-interaction.js +59 -41
- package/esm/map/hooks/use-hover-interaction.js.map +2 -2
- package/esm/map/hooks/use-layer-before-id.js +24 -0
- package/esm/map/hooks/use-layer-before-id.js.map +7 -0
- package/esm/map/hooks/use-load-map-base-layer.js +13 -3
- package/esm/map/hooks/use-load-map-base-layer.js.map +2 -2
- package/esm/map/hooks/use-map-runtime-error.js +93 -0
- package/esm/map/hooks/use-map-runtime-error.js.map +7 -0
- package/esm/map/hooks/use-map-view-provider-context.js +7 -0
- package/esm/map/hooks/use-map-view-provider-context.js.map +7 -0
- package/esm/map/hooks/use-overlay-events.js +11 -2
- package/esm/map/hooks/use-overlay-events.js.map +2 -2
- package/esm/map/hooks/use-tooltip-template.js +17 -2
- package/esm/map/hooks/use-tooltip-template.js.map +2 -2
- package/esm/map/hooks/use-webgl-context-error.js +2 -1
- package/esm/map/hooks/use-webgl-context-error.js.map +2 -2
- package/esm/map/index.js +2 -0
- package/esm/map/index.js.map +2 -2
- package/esm/map/providers/map-view.provider.js +18 -0
- package/esm/map/providers/map-view.provider.js.map +7 -0
- package/esm/map/slots/Tooltip.js.map +2 -2
- package/esm/map/types/map-view-provider.js +1 -0
- package/esm/map/types/map-view-provider.js.map +7 -0
- package/esm/map/utils/attach-image-from-shape.js +4 -2
- package/esm/map/utils/attach-image-from-shape.js.map +2 -2
- package/esm/map/utils/extract-layers-data.js +24 -15
- package/esm/map/utils/extract-layers-data.js.map +2 -2
- package/esm/map/utils/fetch-base-layer-features.js +1 -1
- package/esm/map/utils/fetch-base-layer-features.js.map +2 -2
- package/esm/map/utils/is-browser-firefox.js +7 -0
- package/esm/map/utils/is-browser-firefox.js.map +7 -0
- package/esm/map/utils/parse-tooltip-data.js +22 -7
- package/esm/map/utils/parse-tooltip-data.js.map +2 -2
- package/map/MapView.js +42 -34
- package/map/components/BubbleLayer/BubbleCircleLayer.d.ts +2 -1
- package/map/components/BubbleLayer/BubbleCircleLayer.js +2 -0
- package/map/components/BubbleLayer/BubbleLayer.js +14 -3
- package/map/components/BubbleLayer/BubbleLayerTooltip.d.ts +2 -0
- package/map/components/BubbleLayer/BubbleLayerTooltip.js +9 -3
- package/map/components/BubbleLayer/utils/parse-bubble-data-to-geo-json.d.ts +3 -1
- package/map/components/BubbleLayer/utils/parse-bubble-data-to-geo-json.js +5 -5
- package/map/components/ChoroplethLayer/ChoroplethLayer.js +15 -7
- package/map/components/ChoroplethLayer/ChoroplethLayerTooltip.d.ts +2 -0
- package/map/components/ChoroplethLayer/ChoroplethLayerTooltip.js +9 -3
- package/map/components/ChoroplethLayer/ChoroplethOutlineLayer.d.ts +1 -0
- package/map/components/ChoroplethLayer/ChoroplethOutlineLayer.js +3 -1
- package/map/components/ChoroplethLayer/utils/parse-region-data-to-geo-json.d.ts +3 -1
- package/map/components/ChoroplethLayer/utils/parse-region-data-to-geo-json.js +6 -5
- package/map/components/ConnectionLayer/ConnectionLayer.js +11 -6
- package/map/components/ConnectionLayer/ConnectionLayerLine.js +3 -0
- package/map/components/ConnectionLayer/ConnectionLayerTooltip.d.ts +2 -0
- package/map/components/ConnectionLayer/ConnectionLayerTooltip.js +16 -12
- package/map/components/ConnectionLayer/utils/parse-connection-data-to-geo-json.d.ts +3 -1
- package/map/components/ConnectionLayer/utils/parse-connection-data-to-geo-json.js +20 -18
- package/map/components/DotLayer/DotLayer.js +12 -3
- package/map/components/DotLayer/DotLayerTooltip.d.ts +2 -0
- package/map/components/DotLayer/DotLayerTooltip.js +9 -3
- package/map/components/DotLayer/utils/parse-dot-data-to-geo-json.d.ts +3 -1
- package/map/components/DotLayer/utils/parse-dot-data-to-geo-json.js +5 -5
- package/map/components/MapContent.js +21 -12
- package/map/contexts/geo-data-lookup.context.d.ts +9 -0
- package/map/contexts/geo-data-lookup.context.js +27 -0
- package/map/contexts/map-view-provider.context.d.ts +2 -0
- package/map/{components/ConnectionLayer/utils/restore-null-props.js → contexts/map-view-provider.context.js} +8 -8
- package/map/hooks/use-active-interaction.d.ts +8 -1
- package/map/hooks/use-active-interaction.js +58 -42
- package/map/hooks/use-attach-image-from-icon.js +4 -2
- package/map/hooks/use-hover-interaction.d.ts +6 -2
- package/map/hooks/use-hover-interaction.js +52 -39
- package/map/hooks/use-layer-before-id.d.ts +13 -0
- package/map/hooks/{use-map-mouse-move.js → use-layer-before-id.js} +20 -15
- package/map/hooks/use-load-map-base-layer.js +13 -3
- package/map/hooks/use-map-runtime-error.d.ts +34 -0
- package/map/hooks/use-map-runtime-error.js +112 -0
- package/map/hooks/use-map-view-provider-context.d.ts +1 -0
- package/map/hooks/use-map-view-provider-context.js +26 -0
- package/map/hooks/use-overlay-events.js +11 -2
- package/map/hooks/use-tooltip-template.d.ts +8 -0
- package/map/hooks/use-tooltip-template.js +17 -2
- package/map/hooks/use-webgl-context-error.js +2 -1
- package/map/index.d.ts +2 -0
- package/map/index.js +2 -0
- package/map/providers/map-view.provider.d.ts +7 -0
- package/map/providers/map-view.provider.js +37 -0
- package/map/slots/Tooltip.d.ts +2 -0
- package/map/types/connection-layer.d.ts +1 -8
- package/map/types/map-view-provider.d.ts +10 -0
- package/map/types/map-view-provider.js +16 -0
- package/map/types/tooltip.d.ts +17 -0
- package/map/utils/attach-image-from-shape.js +4 -2
- package/map/utils/extract-layers-data.d.ts +2 -0
- package/map/utils/extract-layers-data.js +24 -15
- package/map/utils/fetch-base-layer-features.js +1 -1
- package/map/utils/is-browser-firefox.d.ts +5 -0
- package/map/utils/is-browser-firefox.js +26 -0
- package/map/utils/parse-tooltip-data.d.ts +11 -3
- package/map/utils/parse-tooltip-data.js +22 -7
- package/package.json +2 -2
- package/esm/map/components/ConnectionLayer/utils/restore-null-props.js +0 -9
- package/esm/map/components/ConnectionLayer/utils/restore-null-props.js.map +0 -7
- package/esm/map/hooks/use-map-mouse-move.js +0 -19
- package/esm/map/hooks/use-map-mouse-move.js.map +0 -7
- package/map/components/ConnectionLayer/utils/restore-null-props.d.ts +0 -2
- package/map/hooks/use-map-mouse-move.d.ts +0 -2
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/map/components/MapContent.tsx"],
|
|
4
|
-
"sourcesContent": ["import {\n Layer,\n type LayerProps,\n Map,\n Source,\n type ViewStateChangeEvent,\n} from '@vis.gl/react-maplibre';\nimport { isUndefined } from 'lodash-es';\nimport type
|
|
5
|
-
"mappings": "
|
|
4
|
+
"sourcesContent": ["import {\n Layer,\n type LayerProps,\n Map,\n Source,\n type ViewStateChangeEvent,\n} from '@vis.gl/react-maplibre';\nimport { isUndefined } from 'lodash-es';\nimport { type MapLayerMouseEvent } from 'maplibre-gl';\nimport {\n forwardRef,\n type PropsWithChildren,\n useCallback,\n useContext,\n useRef,\n useState,\n} from 'react';\n\nimport { _useGraphSize as useGraphSize } from '@dynatrace/strato-components/charts';\nimport { useMergeRefs } from '@dynatrace/strato-components/core';\n\nimport {\n BASE_LAYER_FILL_ID,\n BASE_LAYER_LINE_ID,\n COUNTRY_BORDER_WIDTH,\n DEFAULT_BOUNDARIES_BORDER_COLOR,\n DEFAULT_COUNTRIES_FILL_COLOR,\n MAX_LATITUDE,\n MAX_LONGITUDE,\n MIN_LATITUDE,\n MIN_LONGITUDE,\n REGION_BORDER_WIDTH,\n} from '../constants.js';\nimport { useMapZoomState, useSetStateZoom } from '../store/store.js';\nimport { MapToolbar } from './toolbar/MapToolbar.js';\nimport { LayerIdsContext } from '../contexts/layer-ids.context.js';\nimport { MapDataBoundingBoxContext } from '../contexts/map-data-bounding-box.context.js';\nimport { useActiveInteraction } from '../hooks/use-active-interaction.js';\nimport { useHoverInteraction } from '../hooks/use-hover-interaction.js';\nimport { useMapBaseLayerFeatures } from '../hooks/use-map-base-layer-features.js';\nimport { useMapConfig } from '../hooks/use-map-config.js';\nimport { useMapLoading } from '../hooks/use-map-loading.js';\nimport { useMapPerformance } from '../hooks/use-map-performance.js';\nimport { useMapRuntimeError } from '../hooks/use-map-runtime-error.js';\nimport { useOverlayEvents } from '../hooks/use-overlay-events.js';\nimport { useTooltipEventListeners } from '../hooks/use-tooltip-event-listeners.js';\nimport { defaultStyle } from '../map-styles/default-style.js';\nimport { MapViewImperativeHandler } from '../providers/imperative-handler.provider.js';\nimport type {\n MapViewProps,\n MapViewRef,\n ViewStateRequired,\n} from '../types/map-view.js';\nimport { getColorFromToken } from '../utils/get-color-from-token.js';\nimport { getDataLayersBoundingBox } from '../utils/get-data-layers-bounding-box.js';\nimport { toMapBoxInitialViewState } from '../utils/to-mapbox-initial-view-state.js';\nimport { useSetMapInitialConfiguration } from '../utils/use-set-map-initial-configuration.js';\nimport { generateNewZoomState } from './toolbar/utils/zoom-state-utils.js';\n\nconst lineLayer: LayerProps = {\n id: BASE_LAYER_LINE_ID,\n type: 'line',\n};\n\nconst fillLayer: LayerProps = {\n id: BASE_LAYER_FILL_ID,\n type: 'fill',\n};\n\nconst MapSource = () => {\n const baseLayerFeatures = useMapBaseLayerFeatures();\n return (\n baseLayerFeatures && (\n <Source id=\"data\" type=\"geojson\" data={baseLayerFeatures}>\n <Layer\n {...fillLayer}\n paint={{\n 'fill-color': getColorFromToken(DEFAULT_COUNTRIES_FILL_COLOR),\n }}\n />\n <Layer\n {...lineLayer}\n type=\"line\"\n filter={[\n 'any',\n ['==', 'region_type', 'COUNTRY'],\n ['==', 'region_type', 'REGION'],\n ]}\n paint={{\n 'line-color': getColorFromToken(DEFAULT_BOUNDARIES_BORDER_COLOR),\n 'line-width': [\n 'case',\n ['==', ['get', 'region_type'], 'REGION'],\n REGION_BORDER_WIDTH,\n COUNTRY_BORDER_WIDTH,\n ],\n }}\n />\n </Source>\n )\n );\n};\n\nconst MapInteractions = ({\n children,\n onContextLostError,\n interactiveLayerIds,\n}: PropsWithChildren<{\n onContextLostError?: () => void;\n interactiveLayerIds: string[];\n}>) => {\n const [runtimeError, setRuntimeError] = useState<Error | null>(null);\n\n const onRuntimeError = useCallback(() => {\n onContextLostError?.();\n setRuntimeError(\n new Error(\n 'The map encountered repeated rendering errors and could not recover. Please reload the page.',\n ),\n );\n }, [onContextLostError]);\n\n useHoverInteraction(interactiveLayerIds);\n useActiveInteraction(interactiveLayerIds);\n useMapRuntimeError({ onError: onRuntimeError });\n\n if (runtimeError) {\n throw runtimeError;\n }\n\n return children;\n};\ntype MapContentProps = MapViewProps & {\n onMapLoad: () => void;\n};\n\nexport const MapContent = forwardRef<\n MapViewRef,\n PropsWithChildren<MapContentProps>\n>((props, forwardedRef) => {\n const {\n initialViewState: initialViewStateProp,\n children,\n style,\n mapStyle = defaultStyle,\n onViewStateChange,\n onMapLoad,\n onContextLostError,\n ...remaining\n } = props;\n\n const loading = useMapLoading();\n const setZoomState = useSetStateZoom();\n const [savedInitialViewState, setSavedInitialViewState] = useState<\n ViewStateRequired | undefined\n >();\n\n const mapContainerRef = useRef<HTMLDivElement>(null);\n\n const mergedRefs = useMergeRefs<MapViewRef | HTMLDivElement>([\n mapContainerRef,\n forwardedRef,\n ]);\n\n const baseFeatureCollection = useMapBaseLayerFeatures();\n\n const dataLayersBBox = getDataLayersBoundingBox(\n children,\n baseFeatureCollection?.features,\n );\n\n useTooltipEventListeners();\n\n const { toolbar: toolbarConfig, interactions: interactionsConfig } =\n useMapConfig();\n const layerIds = useContext(LayerIdsContext);\n\n const shouldRenderToolbar =\n (!isUndefined(toolbarConfig) && !toolbarConfig.hidden) ||\n !isUndefined(interactionsConfig);\n\n const { height: graphHeight, width: graphWidth } = useGraphSize();\n\n const {\n handleMouseEnter,\n handleMouseMove,\n handleMouseLeave,\n handleMouseClick,\n handleZoom,\n handleDrag,\n } = useOverlayEvents();\n\n const initialViewState = initialViewStateProp ?? dataLayersBBox;\n\n const { onLoadHandler, onRenderHandler } = useMapPerformance(mapContainerRef);\n const calculatedInitialViewState = toMapBoxInitialViewState(initialViewState);\n\n const { zoomToFitInProgress } = useMapZoomState();\n\n const handleZoomEnd = (event: ViewStateChangeEvent) => {\n if (savedInitialViewState) {\n const zoomState = generateNewZoomState(\n event,\n savedInitialViewState,\n zoomToFitInProgress,\n );\n\n setZoomState(zoomState);\n }\n };\n\n const handleDragEnd = (event: ViewStateChangeEvent) => {\n if (savedInitialViewState) {\n const zoomState = generateNewZoomState(\n event,\n savedInitialViewState,\n zoomToFitInProgress,\n );\n\n setZoomState(zoomState);\n }\n };\n\n const isZoomEnabled = toolbarConfig?.zoom?.enabled !== false;\n\n return (\n <div\n data-testid=\"map-container\"\n ref={mergedRefs}\n onMouseEnter={handleMouseEnter}\n onMouseLeave={handleMouseLeave}\n >\n <Map\n style={{\n width: graphWidth,\n height: `${graphHeight}px`,\n ...style,\n }}\n onMove={(evt) => {\n onViewStateChange?.(evt.viewState);\n }}\n initialViewState={calculatedInitialViewState}\n mapStyle={mapStyle}\n dragRotate={false}\n fadeDuration={0}\n renderWorldCopies={false}\n interactiveLayerIds={layerIds}\n maxBounds={[\n [MIN_LONGITUDE, MIN_LATITUDE],\n [MAX_LONGITUDE, MAX_LATITUDE],\n ]}\n onMouseMove={(e) => handleMouseMove(e as MapLayerMouseEvent)}\n onClick={(e) => handleMouseClick(e as MapLayerMouseEvent)}\n onZoom={handleZoom}\n onZoomEnd={handleZoomEnd}\n onDrag={handleDrag}\n onDragEnd={handleDragEnd}\n boxZoom={isZoomEnabled}\n keyboard={isZoomEnabled}\n scrollZoom={isZoomEnabled}\n doubleClickZoom={isZoomEnabled}\n attributionControl={false}\n onRender={() => onRenderHandler && onRenderHandler()}\n onLoad={(e) => {\n onMapLoad();\n onLoadHandler && onLoadHandler();\n\n const initialCenter = e.target.getCenter();\n\n setSavedInitialViewState({\n latitude: initialCenter.lat,\n longitude: initialCenter.lng,\n zoom: e.target.getZoom(),\n });\n }}\n ref={useSetMapInitialConfiguration()}\n interactive\n {...remaining}\n >\n <MapDataBoundingBoxContext.Provider value={dataLayersBBox}>\n <MapViewImperativeHandler\n forwardedRef={forwardedRef}\n containerRef={mapContainerRef}\n >\n <MapSource />\n {loading ? null : (\n <>\n <MapInteractions\n onContextLostError={onContextLostError}\n interactiveLayerIds={layerIds}\n >\n {children}\n </MapInteractions>\n {shouldRenderToolbar ? <MapToolbar /> : null}\n </>\n )}\n </MapViewImperativeHandler>\n </MapDataBoundingBoxContext.Provider>\n </Map>\n </div>\n );\n});\n\n(MapContent as typeof MapContent & { displayName: string }).displayName =\n 'MapContent';\n"],
|
|
5
|
+
"mappings": "AAyEM,SAqNQ,UApNN,KADF;AAzEN;AAAA,EACE;AAAA,EAEA;AAAA,EACA;AAAA,OAEK;AACP,SAAS,mBAAmB;AAE5B;AAAA,EACE;AAAA,EAEA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEP,SAAS,iBAAiB,oBAAoB;AAC9C,SAAS,oBAAoB;AAE7B;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;A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AA,UACpB,UAAU,MAAM,mBAAmB,gBAAgB;AAAA,UACnD,QAAQ,CAAC,MAAM;AACb,sBAAU;AACV,6BAAiB,cAAc;AAE/B,kBAAM,gBAAgB,EAAE,OAAO,UAAU;AAEzC,qCAAyB;AAAA,cACvB,UAAU,cAAc;AAAA,cACxB,WAAW,cAAc;AAAA,cACzB,MAAM,EAAE,OAAO,QAAQ;AAAA,YACzB,CAAC;AAAA,UACH;AAAA,UACA,KAAK,8BAA8B;AAAA,UACnC,aAAW;AAAA,UACV,GAAG;AAAA,UAEJ,8BAAC,0BAA0B,UAA1B,EAAmC,OAAO,gBACzC;AAAA,YAAC;AAAA;AAAA,cACC;AAAA,cACA,cAAc;AAAA,cAEd;AAAA,oCAAC,aAAU;AAAA,gBACV,UAAU,OACT,iCACE;AAAA;AAAA,oBAAC;AAAA;AAAA,sBACC;AAAA,sBACA,qBAAqB;AAAA,sBAEpB;AAAA;AAAA,kBACH;AAAA,kBACC,sBAAsB,oBAAC,cAAW,IAAK;AAAA,mBAC1C;AAAA;AAAA;AAAA,UAEJ,GACF;AAAA;AAAA,MACF;AAAA;AAAA,EACF;AAEJ,CAAC;AAEA,WAA2D,cAC1D;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../src/map/contexts/geo-data-lookup.context.ts"],
|
|
4
|
+
"sourcesContent": ["import { createContext } from 'react';\n\n/**\n * @internal\n */\nexport type GeoDataLookup = Map<number, unknown>;\n\n/**\n * @internal\n */\nexport type GeoDataLookupRegistry = Map<string, GeoDataLookup>;\n\nexport const GeoDataLookupContext = createContext<GeoDataLookupRegistry>(\n new Map(),\n);\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,qBAAqB;AAYvB,MAAM,uBAAuB;AAAA,EAClC,oBAAI,IAAI;AACV;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../src/map/contexts/map-view-provider.context.ts"],
|
|
4
|
+
"sourcesContent": ["import { createContext } from 'react';\n\nimport type { MapViewProviderProps } from '../types/map-view-provider.js';\n\nexport const MapViewProviderContext = createContext<MapViewProviderProps>({\n countryCode: undefined,\n displayWorldMap: undefined,\n});\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,qBAAqB;AAIvB,MAAM,yBAAyB,cAAoC;AAAA,EACxE,aAAa;AAAA,EACb,iBAAiB;AACnB,CAAC;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,32 +1,45 @@
|
|
|
1
1
|
import { useMap } from "@vis.gl/react-maplibre";
|
|
2
2
|
import { isNil, isUndefined } from "lodash-es";
|
|
3
|
-
import { useCallback, useEffect } from "react";
|
|
4
|
-
import { BASE_LAYER_IDS } from "../constants.js";
|
|
3
|
+
import { useCallback, useEffect, useRef } from "react";
|
|
5
4
|
import { getMinValueFeature } from "../utils/get-min-value-feature.js";
|
|
6
|
-
const useActiveInteraction = () => {
|
|
5
|
+
const useActiveInteraction = (interactiveLayerIds) => {
|
|
7
6
|
const map = useMap().current;
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
const featureIdRef = useRef(void 0);
|
|
8
|
+
const sourceIdRef = useRef(void 0);
|
|
9
|
+
const interactiveLayerIdsRef = useRef(interactiveLayerIds);
|
|
10
|
+
interactiveLayerIdsRef.current = interactiveLayerIds;
|
|
10
11
|
const handleClick = useCallback(
|
|
11
12
|
({ point }) => {
|
|
12
|
-
|
|
13
|
-
|
|
13
|
+
let features = [];
|
|
14
|
+
try {
|
|
15
|
+
features = map.queryRenderedFeatures(point, {
|
|
16
|
+
layers: interactiveLayerIdsRef.current
|
|
17
|
+
});
|
|
18
|
+
} catch {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
let allFeatures = [];
|
|
22
|
+
try {
|
|
23
|
+
allFeatures = map.queryRenderedFeatures(void 0, {
|
|
24
|
+
layers: interactiveLayerIdsRef.current
|
|
25
|
+
});
|
|
26
|
+
} catch {
|
|
27
|
+
}
|
|
14
28
|
const layerId = features?.[0]?.layer?.id;
|
|
15
29
|
const hasHoveredFeatures = !isNil(features) && features.length > 0 && !isUndefined(layerId);
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
if (!isUndefined(featureId) && !isUndefined(sourceId)) {
|
|
30
|
+
if (hasHoveredFeatures) {
|
|
31
|
+
if (!isUndefined(featureIdRef.current) && !isUndefined(sourceIdRef.current)) {
|
|
19
32
|
map.setFeatureState(
|
|
20
|
-
{ source:
|
|
33
|
+
{ source: sourceIdRef.current, id: featureIdRef.current },
|
|
21
34
|
{ active: false }
|
|
22
35
|
);
|
|
23
36
|
}
|
|
24
37
|
const minFeature = getMinValueFeature(features);
|
|
25
|
-
|
|
26
|
-
|
|
38
|
+
featureIdRef.current = minFeature.id;
|
|
39
|
+
sourceIdRef.current = minFeature.layer.source;
|
|
27
40
|
const activeState = features[0].state.active;
|
|
28
41
|
map.setFeatureState(
|
|
29
|
-
{ source:
|
|
42
|
+
{ source: sourceIdRef.current, id: featureIdRef.current },
|
|
30
43
|
{ active: !activeState }
|
|
31
44
|
);
|
|
32
45
|
allFeatures.forEach((feature) => {
|
|
@@ -37,46 +50,49 @@ const useActiveInteraction = () => {
|
|
|
37
50
|
);
|
|
38
51
|
}
|
|
39
52
|
});
|
|
40
|
-
} else {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
});
|
|
54
|
-
}
|
|
53
|
+
} else if (!isUndefined(featureIdRef.current) && !isUndefined(sourceIdRef.current)) {
|
|
54
|
+
map.setFeatureState(
|
|
55
|
+
{ source: sourceIdRef.current, id: featureIdRef.current },
|
|
56
|
+
{ active: false }
|
|
57
|
+
);
|
|
58
|
+
allFeatures.forEach((feature) => {
|
|
59
|
+
if (feature.id !== void 0 && feature.layer.source !== void 0) {
|
|
60
|
+
map.setFeatureState(
|
|
61
|
+
{ source: feature.layer.source, id: feature.id },
|
|
62
|
+
{ isAnyActive: false }
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
});
|
|
55
66
|
}
|
|
56
67
|
},
|
|
57
|
-
[
|
|
68
|
+
[map]
|
|
58
69
|
);
|
|
59
70
|
const onEscapeKeyPressedHandler = useCallback(
|
|
60
71
|
(event) => {
|
|
61
72
|
if (event.key === "Escape") {
|
|
62
|
-
if (!isUndefined(
|
|
73
|
+
if (!isUndefined(featureIdRef.current) && !isUndefined(sourceIdRef.current)) {
|
|
63
74
|
map.setFeatureState(
|
|
64
|
-
{ source:
|
|
75
|
+
{ source: sourceIdRef.current, id: featureIdRef.current },
|
|
65
76
|
{ active: false }
|
|
66
77
|
);
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
78
|
+
try {
|
|
79
|
+
const allFeatures = map.queryRenderedFeatures(void 0, {
|
|
80
|
+
layers: interactiveLayerIdsRef.current
|
|
81
|
+
});
|
|
82
|
+
allFeatures.forEach((feature) => {
|
|
83
|
+
if (feature.id !== void 0 && feature.layer.source !== void 0) {
|
|
84
|
+
map.setFeatureState(
|
|
85
|
+
{ source: feature.layer.source, id: feature.id },
|
|
86
|
+
{ isAnyActive: false }
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
} catch {
|
|
91
|
+
}
|
|
76
92
|
}
|
|
77
93
|
}
|
|
78
94
|
},
|
|
79
|
-
[
|
|
95
|
+
[map]
|
|
80
96
|
);
|
|
81
97
|
useEffect(() => {
|
|
82
98
|
map.on("click", handleClick);
|
|
@@ -85,7 +101,7 @@ const useActiveInteraction = () => {
|
|
|
85
101
|
map.off("click", handleClick);
|
|
86
102
|
window.removeEventListener("keyup", onEscapeKeyPressedHandler);
|
|
87
103
|
};
|
|
88
|
-
}, []);
|
|
104
|
+
}, [map, handleClick, onEscapeKeyPressedHandler]);
|
|
89
105
|
};
|
|
90
106
|
export {
|
|
91
107
|
useActiveInteraction
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/map/hooks/use-active-interaction.ts"],
|
|
4
|
-
"sourcesContent": ["import { useMap } from '@vis.gl/react-maplibre';\nimport { isNil, isUndefined } from 'lodash-es';\nimport type { MapLayerMouseEvent } from 'maplibre-gl';\nimport { useCallback, useEffect } from 'react';\n\nimport {
|
|
5
|
-
"mappings": "AAAA,SAAS,cAAc;AACvB,SAAS,OAAO,mBAAmB;AAEnC,SAAS,aAAa,
|
|
4
|
+
"sourcesContent": ["import { useMap } from '@vis.gl/react-maplibre';\nimport { isNil, isUndefined } from 'lodash-es';\nimport type { MapLayerMouseEvent } from 'maplibre-gl';\nimport { useCallback, useEffect, useRef } from 'react';\n\nimport { getMinValueFeature } from '../utils/get-min-value-feature.js';\n\n/**\n * Handles click-to-activate interactions on map features.\n *\n * Scopes `queryRenderedFeatures` to `interactiveLayerIds` to prevent accidental\n * activation of base/background layers. Both query calls are try-caught to\n * contain maplibre-gl runtime errors without crashing the component tree.\n */\nexport const useActiveInteraction = (interactiveLayerIds: string[]) => {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const map = useMap().current!;\n\n /** Tracks the ID of the currently active feature across renders. */\n const featureIdRef = useRef<string | number | undefined>(undefined);\n /** Tracks the source of the currently active feature across renders. */\n const sourceIdRef = useRef<string | undefined>(undefined);\n /**\n * Kept in a ref so that stable callbacks always read the latest layer list\n * without needing to be recreated when the array reference changes.\n */\n const interactiveLayerIdsRef = useRef(interactiveLayerIds);\n interactiveLayerIdsRef.current = interactiveLayerIds;\n\n const handleClick = useCallback(\n ({ point }: MapLayerMouseEvent) => {\n let features: ReturnType<typeof map.queryRenderedFeatures> = [];\n\n try {\n features = map.queryRenderedFeatures(point, {\n layers: interactiveLayerIdsRef.current,\n });\n } catch {\n return;\n }\n\n // Keep the broad query for isAnyActive so all interactive features receive the flag.\n let allFeatures: ReturnType<typeof map.queryRenderedFeatures> = [];\n try {\n allFeatures = map.queryRenderedFeatures(undefined, {\n layers: interactiveLayerIdsRef.current,\n });\n } catch {\n // falls through with empty allFeatures\n }\n\n const layerId = features?.[0]?.layer?.id;\n\n const hasHoveredFeatures =\n !isNil(features) && features.length > 0 && !isUndefined(layerId);\n\n if (hasHoveredFeatures) {\n if (\n !isUndefined(featureIdRef.current) &&\n !isUndefined(sourceIdRef.current)\n ) {\n // If there's already an active feature, remove the active state.\n map.setFeatureState(\n { source: sourceIdRef.current, id: featureIdRef.current },\n { active: false },\n );\n }\n\n const minFeature = getMinValueFeature(features);\n\n featureIdRef.current = minFeature.id;\n sourceIdRef.current = minFeature.layer.source;\n const activeState = features[0].state.active;\n\n // Add the active state to the closest feature.\n map.setFeatureState(\n { source: sourceIdRef.current, id: featureIdRef.current },\n { active: !activeState },\n );\n allFeatures.forEach((feature) => {\n if (feature.id !== undefined && feature.layer.source !== undefined) {\n map.setFeatureState(\n { source: feature.layer.source, id: feature.id },\n { isAnyActive: !activeState },\n );\n }\n }); //TODO: change to inactive\n } else if (\n !isUndefined(featureIdRef.current) &&\n !isUndefined(sourceIdRef.current)\n ) {\n // Remove the active state from the last active feature.\n map.setFeatureState(\n { source: sourceIdRef.current, id: featureIdRef.current },\n { active: false },\n );\n allFeatures.forEach((feature) => {\n if (feature.id !== undefined && feature.layer.source !== undefined) {\n map.setFeatureState(\n { source: feature.layer.source, id: feature.id },\n { isAnyActive: false },\n );\n }\n });\n }\n },\n [map],\n );\n\n const onEscapeKeyPressedHandler = useCallback(\n (event: KeyboardEvent) => {\n if (event.key === 'Escape') {\n if (\n !isUndefined(featureIdRef.current) &&\n !isUndefined(sourceIdRef.current)\n ) {\n map.setFeatureState(\n { source: sourceIdRef.current, id: featureIdRef.current },\n { active: false },\n );\n\n try {\n const allFeatures = map.queryRenderedFeatures(undefined, {\n layers: interactiveLayerIdsRef.current,\n });\n allFeatures.forEach((feature) => {\n if (\n feature.id !== undefined &&\n feature.layer.source !== undefined\n ) {\n map.setFeatureState(\n { source: feature.layer.source, id: feature.id },\n { isAnyActive: false },\n );\n }\n });\n } catch {\n // falls through \u2014 active state is already cleared above\n }\n }\n }\n },\n [map],\n );\n\n useEffect(() => {\n map.on('click', handleClick);\n window.addEventListener('keyup', onEscapeKeyPressedHandler);\n return () => {\n map.off('click', handleClick);\n window.removeEventListener('keyup', onEscapeKeyPressedHandler);\n };\n }, [map, handleClick, onEscapeKeyPressedHandler]);\n};\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,cAAc;AACvB,SAAS,OAAO,mBAAmB;AAEnC,SAAS,aAAa,WAAW,cAAc;AAE/C,SAAS,0BAA0B;AAS5B,MAAM,uBAAuB,CAAC,wBAAkC;AAErE,QAAM,MAAM,OAAO,EAAE;AAGrB,QAAM,eAAe,OAAoC,MAAS;AAElE,QAAM,cAAc,OAA2B,MAAS;AAKxD,QAAM,yBAAyB,OAAO,mBAAmB;AACzD,yBAAuB,UAAU;AAEjC,QAAM,cAAc;AAAA,IAClB,CAAC,EAAE,MAAM,MAA0B;AACjC,UAAI,WAAyD,CAAC;AAE9D,UAAI;AACF,mBAAW,IAAI,sBAAsB,OAAO;AAAA,UAC1C,QAAQ,uBAAuB;AAAA,QACjC,CAAC;AAAA,MACH,QAAQ;AACN;AAAA,MACF;AAGA,UAAI,cAA4D,CAAC;AACjE,UAAI;AACF,sBAAc,IAAI,sBAAsB,QAAW;AAAA,UACjD,QAAQ,uBAAuB;AAAA,QACjC,CAAC;AAAA,MACH,QAAQ;AAAA,MAER;AAEA,YAAM,UAAU,WAAW,CAAC,GAAG,OAAO;AAEtC,YAAM,qBACJ,CAAC,MAAM,QAAQ,KAAK,SAA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,4BAA4B;AAAA,IAChC,CAAC,UAAyB;AACxB,UAAI,MAAM,QAAQ,UAAU;AAC1B,YACE,CAAC,YAAY,aAAa,OAAO,KACjC,CAAC,YAAY,YAAY,OAAO,GAChC;AACA,cAAI;AAAA,YACF,EAAE,QAAQ,YAAY,SAAS,IAAI,aAAa,QAAQ;AAAA,YACxD,EAAE,QAAQ,MAAM;AAAA,UAClB;AAEA,cAAI;AACF,kBAAM,cAAc,IAAI,sBAAsB,QAAW;AAAA,cACvD,QAAQ,uBAAuB;AAAA,YACjC,CAAC;AACD,wBAAY,QAAQ,CAAC,YAAY;AAC/B,kBACE,QAAQ,OAAO,UACf,QAAQ,MAAM,WAAW,QACzB;AACA,oBAAI;AAAA,kBACF,EAAE,QAAQ,QAAQ,MAAM,QAAQ,IAAI,QAAQ,GAAG;AAAA,kBAC/C,EAAE,aAAa,MAAM;AAAA,gBACvB;AAAA,cACF;AAAA,YACF,CAAC;AAAA,UACH,QAAQ;AAAA,UAER;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAAA,IACA,CAAC,GAAG;AAAA,EACN;AAEA,YAAU,MAAM;AACd,QAAI,GAAG,SAAS,WAAW;AAC3B,WAAO,iBAAiB,SAAS,yBAAyB;AAC1D,WAAO,MAAM;AACX,UAAI,IAAI,SAAS,WAAW;AAC5B,aAAO,oBAAoB,SAAS,yBAAyB;AAAA,IAC/D;AAAA,EACF,GAAG,CAAC,KAAK,aAAa,yBAAyB,CAAC;AAClD;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -8,6 +8,7 @@ import { attachImageToMap } from "../utils/attach-image-to-map.js";
|
|
|
8
8
|
import { createBitmapConfigOptions } from "../utils/create-bitmap-config-options.js";
|
|
9
9
|
import { getDataUri } from "../utils/get-data-uri.js";
|
|
10
10
|
import { getScaledSymbolSize } from "../utils/get-scaled-symbol-size.js";
|
|
11
|
+
import { isFirefox } from "../utils/is-browser-firefox.js";
|
|
11
12
|
const useAttachImageFromIcon = (icon, suffix, outputSize) => {
|
|
12
13
|
const { elementAsString, ref } = useSafeSvgParser();
|
|
13
14
|
const defaultScaledIconSize = getScaledSymbolSize();
|
|
@@ -25,14 +26,15 @@ const useAttachImageFromIcon = (icon, suffix, outputSize) => {
|
|
|
25
26
|
fakeDomContainer.remove();
|
|
26
27
|
const stringUrl = getDataUri(elementAsString);
|
|
27
28
|
img.addEventListener("load", () => {
|
|
28
|
-
createImageBitmap(
|
|
29
|
+
const bitmapPromise = isFirefox() ? createImageBitmap(img, createBitmapConfigOptions(outputSize)) : createImageBitmap(
|
|
29
30
|
img,
|
|
30
31
|
0,
|
|
31
32
|
0,
|
|
32
33
|
DEFAULT_INPUT_ICON_SIZE,
|
|
33
34
|
DEFAULT_INPUT_ICON_SIZE,
|
|
34
35
|
createBitmapConfigOptions(outputSize)
|
|
35
|
-
)
|
|
36
|
+
);
|
|
37
|
+
bitmapPromise.then((bitmap) => {
|
|
36
38
|
if (!map) {
|
|
37
39
|
return;
|
|
38
40
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/map/hooks/use-attach-image-from-icon.ts"],
|
|
4
|
-
"sourcesContent": ["import { useMap } from '@vis.gl/react-maplibre';\nimport { isString } from 'lodash-es';\nimport { createElement, type ReactNode, useLayoutEffect } from 'react';\nimport { createRoot } from 'react-dom/client';\n\nimport { useSafeSvgParser } from './use-safe-svg-parser.js';\nimport { DEFAULT_INPUT_ICON_SIZE } from '../constants.js';\nimport type { MapShape } from '../types/shapes.js';\nimport { attachImageToMap } from '../utils/attach-image-to-map.js';\nimport { createBitmapConfigOptions } from '../utils/create-bitmap-config-options.js';\nimport { getDataUri } from '../utils/get-data-uri.js';\nimport { getScaledSymbolSize } from '../utils/get-scaled-symbol-size.js';\n\nexport const useAttachImageFromIcon = (\n icon: string | MapShape | ReactNode,\n suffix: string,\n outputSize?: number,\n) => {\n const { elementAsString, ref } = useSafeSvgParser();\n const defaultScaledIconSize = getScaledSymbolSize();\n\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const { current: map } = useMap()!;\n const img = new Image(defaultScaledIconSize, defaultScaledIconSize);\n\n /*\n * As we can only create a reference in a React Node, but we need a virtual\n * 'root' element in the DOM to attach it, we create a 'div'\n * container that lately will hold the React Node. This is done to ensure\n * everything is cached prior any manipulation.\n */\n // Create a div element that acts as a container node in the DOM\n const fakeDomContainer = document.createElement('div');\n useLayoutEffect(() => {\n if (isString(icon)) {\n return;\n }\n // Create a React Node that will have a ref callback to be run when loaded and\n // the input icon as a children\n const reactNodeRefContainer = createElement('div', { ref }, icon);\n // Attach React Node with the ref callback into DOM Node\n const root = createRoot(fakeDomContainer);\n root.render(reactNodeRefContainer);\n }, [icon]);\n\n // Remove cached element to free resources\n fakeDomContainer.remove();\n\n const stringUrl = getDataUri(elementAsString);\n\n img.addEventListener('load', () => {\n createImageBitmap(\n img,\n
|
|
5
|
-
"mappings": "AAAA,SAAS,cAAc;AACvB,SAAS,gBAAgB;AACzB,SAAS,eAA+B,uBAAuB;AAC/D,SAAS,kBAAkB;AAE3B,SAAS,wBAAwB;AACjC,SAAS,+BAA+B;AAExC,SAAS,wBAAwB;AACjC,SAAS,iCAAiC;AAC1C,SAAS,kBAAkB;AAC3B,SAAS,2BAA2B;
|
|
4
|
+
"sourcesContent": ["import { useMap } from '@vis.gl/react-maplibre';\nimport { isString } from 'lodash-es';\nimport { createElement, type ReactNode, useLayoutEffect } from 'react';\nimport { createRoot } from 'react-dom/client';\n\nimport { useSafeSvgParser } from './use-safe-svg-parser.js';\nimport { DEFAULT_INPUT_ICON_SIZE } from '../constants.js';\nimport type { MapShape } from '../types/shapes.js';\nimport { attachImageToMap } from '../utils/attach-image-to-map.js';\nimport { createBitmapConfigOptions } from '../utils/create-bitmap-config-options.js';\nimport { getDataUri } from '../utils/get-data-uri.js';\nimport { getScaledSymbolSize } from '../utils/get-scaled-symbol-size.js';\nimport { isFirefox } from '../utils/is-browser-firefox.js';\n\nexport const useAttachImageFromIcon = (\n icon: string | MapShape | ReactNode,\n suffix: string,\n outputSize?: number,\n) => {\n const { elementAsString, ref } = useSafeSvgParser();\n const defaultScaledIconSize = getScaledSymbolSize();\n\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const { current: map } = useMap()!;\n const img = new Image(defaultScaledIconSize, defaultScaledIconSize);\n\n /*\n * As we can only create a reference in a React Node, but we need a virtual\n * 'root' element in the DOM to attach it, we create a 'div'\n * container that lately will hold the React Node. This is done to ensure\n * everything is cached prior any manipulation.\n */\n // Create a div element that acts as a container node in the DOM\n const fakeDomContainer = document.createElement('div');\n useLayoutEffect(() => {\n if (isString(icon)) {\n return;\n }\n // Create a React Node that will have a ref callback to be run when loaded and\n // the input icon as a children\n const reactNodeRefContainer = createElement('div', { ref }, icon);\n // Attach React Node with the ref callback into DOM Node\n const root = createRoot(fakeDomContainer);\n root.render(reactNodeRefContainer);\n }, [icon]);\n\n // Remove cached element to free resources\n fakeDomContainer.remove();\n\n const stringUrl = getDataUri(elementAsString);\n\n img.addEventListener('load', () => {\n // Firefox rasterizes SVG sources at the Image element's display size, not\n // at the SVG's intrinsic dimensions, so an explicit source rect clips the\n // icon. Drop the rect on Firefox only \u2014 other browsers keep the original\n // path.\n const bitmapPromise = isFirefox()\n ? createImageBitmap(img, createBitmapConfigOptions(outputSize))\n : createImageBitmap(\n img,\n 0,\n 0,\n DEFAULT_INPUT_ICON_SIZE,\n DEFAULT_INPUT_ICON_SIZE,\n createBitmapConfigOptions(outputSize),\n );\n bitmapPromise.then((bitmap) => {\n if (!map) {\n return;\n }\n const iconName = `custom-icon-${suffix}`;\n attachImageToMap(map, bitmap, iconName);\n });\n });\n img.src = stringUrl;\n\n return !isString(icon);\n};\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,cAAc;AACvB,SAAS,gBAAgB;AACzB,SAAS,eAA+B,uBAAuB;AAC/D,SAAS,kBAAkB;AAE3B,SAAS,wBAAwB;AACjC,SAAS,+BAA+B;AAExC,SAAS,wBAAwB;AACjC,SAAS,iCAAiC;AAC1C,SAAS,kBAAkB;AAC3B,SAAS,2BAA2B;AACpC,SAAS,iBAAiB;AAEnB,MAAM,yBAAyB,CACpC,MACA,QACA,eACG;AACH,QAAM,EAAE,iBAAiB,IAAI,IAAI,iBAAiB;AAClD,QAAM,wBAAwB,oBAAoB;AAGlD,QAAM,EAAE,SAAS,IAAI,IAAI,OAAO;AAChC,QAAM,MAAM,IAAI,MAAM,uBAAuB,qBAAqB;AASlE,QAAM,mBAAmB,SAAS,cAAc,KAAK;AACrD,kBAAgB,MAAM;AACpB,QAAI,SAAS,IAAI,GAAG;AAClB;AAAA,IACF;AAGA,UAAM,wBAAwB,cAAc,OAAO,EAAE,IAAI,GAAG,IAAI;AAEhE,UAAM,OAAO,WAAW,gBAAgB;AACxC,SAAK,OAAO,qBAAqB;AAAA,EACnC,GAAG,CAAC,IAAI,CAAC;AAGT,mBAAiB,OAAO;AAExB,QAAM,YAAY,WAAW,eAAe;AAE5C,MAAI,iBAAiB,QAAQ,MAAM;AAKjC,UAAM,gBAAgB,UAAU,IAC5B,kBAAkB,KAAK,0BAA0B,UAAU,CAAC,IAC5D;AAAA,MACE;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA,0BAA0B,UAAU;AAAA,IACtC;AACJ,kBAAc,KAAK,CAAC,WAAW;AAC7B,UAAI,CAAC,KAAK;AACR;AAAA,MACF;AACA,YAAM,WAAW,eAAe,MAAM;AACtC,uBAAiB,KAAK,QAAQ,QAAQ;AAAA,IACxC,CAAC;AAAA,EACH,CAAC;AACD,MAAI,MAAM;AAEV,SAAO,CAAC,SAAS,IAAI;AACvB;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,13 +1,25 @@
|
|
|
1
1
|
import { useMap } from "@vis.gl/react-maplibre";
|
|
2
|
-
import { isNil, isString, isUndefined } from "lodash-es";
|
|
3
|
-
import {
|
|
4
|
-
|
|
2
|
+
import { isNil, isString, isUndefined, throttle } from "lodash-es";
|
|
3
|
+
import {
|
|
4
|
+
useCallback,
|
|
5
|
+
useEffect,
|
|
6
|
+
useMemo,
|
|
7
|
+
useRef
|
|
8
|
+
} from "react";
|
|
5
9
|
import {
|
|
6
10
|
getAssociatedFeatures,
|
|
7
11
|
hasAssociatedFeatures,
|
|
8
12
|
isAssociatedFeature
|
|
9
13
|
} from "../utils/associated-features.js";
|
|
10
14
|
import { getMinValueFeature } from "../utils/get-min-value-feature.js";
|
|
15
|
+
const MOUSEMOVE_THROTTLE_MS = 16;
|
|
16
|
+
const blurTrackedFeature = (map, featureIdRef, sourceIdRef) => {
|
|
17
|
+
if (!isNil(featureIdRef.current) && !isNil(sourceIdRef.current)) {
|
|
18
|
+
blurFeature(map, sourceIdRef.current, featureIdRef.current);
|
|
19
|
+
featureIdRef.current = void 0;
|
|
20
|
+
sourceIdRef.current = void 0;
|
|
21
|
+
}
|
|
22
|
+
};
|
|
11
23
|
const featureExists = (map, source, id) => {
|
|
12
24
|
const isSourcePresent = map.getSource(source) !== void 0;
|
|
13
25
|
return isSourcePresent && map.getFeatureState({
|
|
@@ -49,55 +61,61 @@ const hoverFeature = (map, source, id) => {
|
|
|
49
61
|
}
|
|
50
62
|
}
|
|
51
63
|
};
|
|
52
|
-
const useHoverInteraction = () => {
|
|
64
|
+
const useHoverInteraction = (interactiveLayerIds) => {
|
|
53
65
|
const map = useMap().current;
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
const
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
66
|
+
const featureIdRef = useRef(void 0);
|
|
67
|
+
const sourceIdRef = useRef(void 0);
|
|
68
|
+
const interactiveLayerIdsRef = useRef(interactiveLayerIds);
|
|
69
|
+
interactiveLayerIdsRef.current = interactiveLayerIds;
|
|
70
|
+
const handleMouseOut = useCallback(() => {
|
|
71
|
+
if (!isNil(map)) {
|
|
72
|
+
blurTrackedFeature(map, featureIdRef, sourceIdRef);
|
|
73
|
+
}
|
|
74
|
+
}, [map]);
|
|
75
|
+
const throttledMouseMove = useMemo(
|
|
76
|
+
() => throttle(
|
|
77
|
+
({ point }) => {
|
|
78
|
+
if (isNil(map)) {
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
let features;
|
|
82
|
+
try {
|
|
83
|
+
features = map.queryRenderedFeatures(point, {
|
|
84
|
+
layers: interactiveLayerIdsRef.current
|
|
85
|
+
}).filter((feature) => !isAssociatedFeature(feature.properties.id));
|
|
86
|
+
} catch {
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
69
89
|
const layerId = features?.[0]?.layer?.id;
|
|
70
90
|
const hasHoveredFeatures = !isNil(features) && features.length > 0 && !isUndefined(layerId);
|
|
71
|
-
|
|
72
|
-
if (hasHoveredFeatures && !isBaseLayer) {
|
|
73
|
-
map.getCanvas().style.cursor = "pointer";
|
|
74
|
-
if (!isUndefined(featureId) && !isUndefined(sourceId)) {
|
|
75
|
-
blurFeature(map, sourceId, featureId);
|
|
76
|
-
}
|
|
77
|
-
const minFeature = getMinValueFeature(features);
|
|
78
|
-
featureId = minFeature.id;
|
|
79
|
-
sourceId = minFeature.layer.source;
|
|
80
|
-
if (!isUndefined(featureId)) {
|
|
81
|
-
hoverFeature(map, sourceId, featureId);
|
|
82
|
-
}
|
|
83
|
-
} else {
|
|
91
|
+
if (!hasHoveredFeatures) {
|
|
84
92
|
map.getCanvas().style.cursor = "grab";
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
}
|
|
93
|
+
blurTrackedFeature(map, featureIdRef, sourceIdRef);
|
|
94
|
+
return;
|
|
88
95
|
}
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
96
|
+
map.getCanvas().style.cursor = "pointer";
|
|
97
|
+
blurTrackedFeature(map, featureIdRef, sourceIdRef);
|
|
98
|
+
const minFeature = getMinValueFeature(features);
|
|
99
|
+
featureIdRef.current = minFeature.id;
|
|
100
|
+
sourceIdRef.current = minFeature.layer.source;
|
|
101
|
+
if (!isUndefined(featureIdRef.current)) {
|
|
102
|
+
hoverFeature(map, sourceIdRef.current, featureIdRef.current);
|
|
103
|
+
}
|
|
104
|
+
},
|
|
105
|
+
MOUSEMOVE_THROTTLE_MS,
|
|
106
|
+
{ trailing: true }
|
|
107
|
+
),
|
|
108
|
+
[map]
|
|
92
109
|
);
|
|
93
110
|
useEffect(() => {
|
|
94
|
-
map?.on("mousemove",
|
|
111
|
+
map?.on("mousemove", throttledMouseMove);
|
|
95
112
|
map?.on("mouseout", handleMouseOut);
|
|
96
113
|
return () => {
|
|
97
|
-
|
|
114
|
+
throttledMouseMove.cancel();
|
|
115
|
+
map?.off("mousemove", throttledMouseMove);
|
|
98
116
|
map?.off("mouseout", handleMouseOut);
|
|
99
117
|
};
|
|
100
|
-
}, []);
|
|
118
|
+
}, [map, throttledMouseMove, handleMouseOut]);
|
|
101
119
|
};
|
|
102
120
|
export {
|
|
103
121
|
useHoverInteraction
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/map/hooks/use-hover-interaction.ts"],
|
|
4
|
-
"sourcesContent": ["import type { MapRef } from '@vis.gl/react-maplibre';\nimport { useMap } from '@vis.gl/react-maplibre';\nimport { isNil, isString, isUndefined } from 'lodash-es';\nimport type { MapLayerMouseEvent } from 'maplibre-gl';\nimport { useCallback
|
|
5
|
-
"mappings": "AACA,SAAS,cAAc;AACvB,SAAS,OAAO,UAAU,
|
|
4
|
+
"sourcesContent": ["import type { MapRef } from '@vis.gl/react-maplibre';\nimport { useMap } from '@vis.gl/react-maplibre';\nimport { isNil, isString, isUndefined, throttle } from 'lodash-es';\nimport type { MapLayerMouseEvent } from 'maplibre-gl';\nimport {\n type MutableRefObject,\n useCallback,\n useEffect,\n useMemo,\n useRef,\n} from 'react';\n\nimport {\n getAssociatedFeatures,\n hasAssociatedFeatures,\n isAssociatedFeature,\n} from '../utils/associated-features.js';\nimport { getMinValueFeature } from '../utils/get-min-value-feature.js';\n\n/** Minimum milliseconds between processed mousemove events (~1 frame at 60 fps). */\nconst MOUSEMOVE_THROTTLE_MS = 16;\n\nconst blurTrackedFeature = (\n map: MapRef,\n featureIdRef: MutableRefObject<string | number | undefined>,\n sourceIdRef: MutableRefObject<string | undefined>,\n) => {\n if (!isNil(featureIdRef.current) && !isNil(sourceIdRef.current)) {\n blurFeature(map, sourceIdRef.current, featureIdRef.current);\n featureIdRef.current = undefined;\n sourceIdRef.current = undefined;\n }\n};\n\n/**\n * Checks whether a feature exists from a given source\n *\n * @param map -\n * @param source -\n * @param id -\n */\nconst featureExists = (\n map: MapRef,\n source: string,\n id: string | number,\n): boolean => {\n const isSourcePresent = map.getSource(source) !== undefined;\n\n return (\n isSourcePresent &&\n map.getFeatureState({\n source,\n id,\n }) !== undefined\n );\n};\n\n/**\n * Removes hovered state from a feature and its associated features from a given source\n * @param map -\n * @param source -\n * @param id -\n */\nconst blurFeature = (map: MapRef, source: string, id: string | number) => {\n map.setFeatureState({ source, id }, { hover: false });\n\n if (isString(id) && hasAssociatedFeatures(id)) {\n for (const associatedFeature of getAssociatedFeatures('connection')) {\n const associatedSource = `${source}-direction`;\n const associatedId = `${id}-${associatedFeature}`;\n\n if (featureExists(map, associatedSource, associatedId)) {\n map.setFeatureState(\n { source: associatedSource, id: associatedId },\n {\n hover: false,\n },\n );\n }\n }\n }\n};\n\n/**\n * Sets hovered state to a feature and its associated features from a given source\n * @param map -\n * @param source -\n * @param id -\n */\nconst hoverFeature = (map: MapRef, source: string, id: string | number) => {\n map.setFeatureState({ source, id }, { hover: true });\n\n if (isString(id) && hasAssociatedFeatures(id)) {\n for (const associatedFeature of getAssociatedFeatures('connection')) {\n const associatedSource = `${source}-direction`;\n const associatedId = `${id}-${associatedFeature}`;\n\n if (featureExists(map, associatedSource, associatedId)) {\n map.setFeatureState(\n { source: `${source}-direction`, id: `${id}-${associatedFeature}` },\n {\n hover: true,\n },\n );\n }\n }\n }\n};\n\n/**\n * Sets and removes hovered state to the features depending on mouse position.\n *\n * @param interactiveLayerIds - maplibre-gl layer IDs to scope the feature query.\n * Scoping to data layers prevents touching base-map vector tiles whose internal\n * feature index may be in a transitional state (root cause of APPDEV-17854).\n */\nexport const useHoverInteraction = (interactiveLayerIds: string[]) => {\n const map = useMap().current;\n\n const featureIdRef = useRef<string | number | undefined>(undefined);\n const sourceIdRef = useRef<string | undefined>(undefined);\n\n // Keep a ref so the stable callback always sees the latest layer IDs even\n // if the consumer updates them after the first render.\n const interactiveLayerIdsRef = useRef(interactiveLayerIds);\n interactiveLayerIdsRef.current = interactiveLayerIds;\n\n const handleMouseOut = useCallback(() => {\n if (!isNil(map)) {\n blurTrackedFeature(map, featureIdRef, sourceIdRef);\n }\n }, [map]);\n\n const throttledMouseMove = useMemo(\n () =>\n throttle(\n ({ point }: MapLayerMouseEvent) => {\n if (isNil(map)) {\n return;\n }\n\n let features;\n try {\n features = map\n .queryRenderedFeatures(point, {\n layers: interactiveLayerIdsRef.current,\n })\n .filter((feature) => !isAssociatedFeature(feature.properties.id));\n } catch {\n return;\n }\n\n const layerId = features?.[0]?.layer?.id;\n const hasHoveredFeatures =\n !isNil(features) && features.length > 0 && !isUndefined(layerId);\n\n // No BASE_LAYER_IDS check needed: querying only interactiveLayerIds\n // already excludes base-map layers entirely.\n if (!hasHoveredFeatures) {\n map.getCanvas().style.cursor = 'grab';\n blurTrackedFeature(map, featureIdRef, sourceIdRef);\n return;\n }\n\n map.getCanvas().style.cursor = 'pointer';\n blurTrackedFeature(map, featureIdRef, sourceIdRef);\n\n const minFeature = getMinValueFeature(features);\n featureIdRef.current = minFeature.id;\n sourceIdRef.current = minFeature.layer.source;\n\n if (!isUndefined(featureIdRef.current)) {\n hoverFeature(map, sourceIdRef.current, featureIdRef.current);\n }\n },\n MOUSEMOVE_THROTTLE_MS,\n { trailing: true },\n ),\n [map],\n );\n\n useEffect(() => {\n map?.on('mousemove', throttledMouseMove);\n map?.on('mouseout', handleMouseOut);\n return () => {\n throttledMouseMove.cancel();\n map?.off('mousemove', throttledMouseMove);\n map?.off('mouseout', handleMouseOut);\n };\n }, [map, throttledMouseMove, handleMouseOut]);\n};\n"],
|
|
5
|
+
"mappings": "AACA,SAAS,cAAc;AACvB,SAAS,OAAO,UAAU,aAAa,gBAAgB;AAEvD;AAAA,EAEE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,0BAA0B;AAGnC,MAAM,wBAAwB;AAE9B,MAAM,qBAAqB,CACzB,KACA,cACA,gBACG;AACH,MAAI,CAAC,MAAM,aAAa,OAAO,KAAK,CAAC,MAAM,YAAY,OAAO,GAAG;AAC/D,gBAAY,KAAK,YAAY,SAAS,aAAa,OAAO;AAC1D,iBAAa,UAAU;AACvB,gBAAY,UAAU;AAAA,EACxB;AACF;AASA,MAAM,gBAAgB,CACpB,KACA,QACA,OACY;AACZ,QAAM,kBAAkB,IAAI,UAAU,MAAM,MAAM;AAElD,SACE,mBACA,IAAI,gBAAgB;AAAA,IAClB;AAAA,IACA;AAAA,EACF,CAAC,MAAM;AAEX;AAQA,MAAM,cAAc,CAAC,KAAa,QAAgB,OAAwB;AACxE,MAAI,gBAAgB,EAAE,QAAQ,GAAG,GAAG,EAAE,OAAO,MAAM,CAAC;AAEpD,MAAI,SAAS,EAAE,KAAK,sBAAsB,EAAE,GAAG;AAC7C,eAAW,qBAAqB,sBAAsB,YAAY,GAAG;AACnE,YAAM,mBAAmB,GAAG,MAAM;AAClC,YAAM,eAAe,GAAG,EAAE,IAAI,iBAAiB;AAE/C,UAAI,cAAc,KAAK,kBAAkB,YAAY,GAAG;AACtD,YAAI;AAAA,UACF,EAAE,QAAQ,kBAAkB,IAAI,aAA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Q;AACN;AAAA,QACF;AAEA,cAAM,UAAU,WAAW,CAAC,GAAG,OAAO;AACtC,cAAM,qBACJ,CAAC,MAAM,QAAQ,KAAK,SAAS,SAAS,KAAK,CAAC,YAAY,OAAO;AAIjE,YAAI,CAAC,oBAAoB;AACvB,cAAI,UAAU,EAAE,MAAM,SAAS;AAC/B,6BAAmB,KAAK,cAAc,WAAW;AACjD;AAAA,QACF;AAEA,YAAI,UAAU,EAAE,MAAM,SAAS;AAC/B,2BAAmB,KAAK,cAAc,WAAW;AAEjD,cAAM,aAAa,mBAAmB,QAAQ;AAC9C,qBAAa,UAAU,WAAW;AAClC,oBAAY,UAAU,WAAW,MAAM;AAEvC,YAAI,CAAC,YAAY,aAAa,OAAO,GAAG;AACtC,uBAAa,KAAK,YAAY,SAAS,aAAa,OAAO;AAAA,QAC7D;AAAA,MACF;AAAA,MACA;AAAA,MACA,EAAE,UAAU,KAAK;AAAA,IACnB;AAAA,IACF,CAAC,GAAG;AAAA,EACN;AAEA,YAAU,MAAM;AACd,SAAK,GAAG,aAAa,kBAAkB;AACvC,SAAK,GAAG,YAAY,cAAc;AAClC,WAAO,MAAM;AACX,yBAAmB,OAAO;AAC1B,WAAK,IAAI,aAAa,kBAAkB;AACxC,WAAK,IAAI,YAAY,cAAc;AAAA,IACrC;AAAA,EACF,GAAG,CAAC,KAAK,oBAAoB,cAAc,CAAC;AAC9C;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { useMap } from "@vis.gl/react-maplibre";
|
|
2
|
+
import { useContext } from "react";
|
|
3
|
+
import { LayerIdsContext } from "../contexts/layer-ids.context.js";
|
|
4
|
+
const useLayerBeforeId = (layerId) => {
|
|
5
|
+
const layerIds = useContext(LayerIdsContext);
|
|
6
|
+
const { current: map } = useMap();
|
|
7
|
+
if (!map) {
|
|
8
|
+
return void 0;
|
|
9
|
+
}
|
|
10
|
+
const currentIndex = layerIds.indexOf(layerId);
|
|
11
|
+
if (currentIndex === -1) {
|
|
12
|
+
return void 0;
|
|
13
|
+
}
|
|
14
|
+
for (let i = currentIndex + 1; i < layerIds.length; i++) {
|
|
15
|
+
if (map.getLayer(layerIds[i])) {
|
|
16
|
+
return layerIds[i];
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
return void 0;
|
|
20
|
+
};
|
|
21
|
+
export {
|
|
22
|
+
useLayerBeforeId
|
|
23
|
+
};
|
|
24
|
+
//# sourceMappingURL=use-layer-before-id.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../src/map/hooks/use-layer-before-id.ts"],
|
|
4
|
+
"sourcesContent": ["import { useMap } from '@vis.gl/react-maplibre';\nimport { useContext } from 'react';\n\nimport { LayerIdsContext } from '../contexts/layer-ids.context.js';\n\n/**\n * Returns the maplibre layer id that the current layer should be inserted before,\n * based on the JSX order of `MapView` children.\n *\n * Without this, layers that mount asynchronously (e.g. `{apiData && <ChoroplethLayer>}`)\n * are appended to the top of the maplibre stack and end up visually above siblings\n * that mounted earlier \u2014 even when JSX puts them first. Passing the returned value as\n * `beforeId` to a `<Layer>` keeps the rendered stack aligned with JSX order.\n *\n * Only returns an id that actually exists in the map right now, so the result is\n * always safe to pass to `map.addLayer(opts, beforeId)`.\n */\nexport const useLayerBeforeId = (layerId: string): string | undefined => {\n const layerIds = useContext(LayerIdsContext);\n const { current: map } = useMap();\n\n if (!map) {\n return undefined;\n }\n\n const currentIndex = layerIds.indexOf(layerId);\n if (currentIndex === -1) {\n return undefined;\n }\n\n for (let i = currentIndex + 1; i < layerIds.length; i++) {\n if (map.getLayer(layerIds[i])) {\n return layerIds[i];\n }\n }\n\n return undefined;\n};\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,cAAc;AACvB,SAAS,kBAAkB;AAE3B,SAAS,uBAAuB;AAczB,MAAM,mBAAmB,CAAC,YAAwC;AACvE,QAAM,WAAW,WAAW,eAAe;AAC3C,QAAM,EAAE,SAAS,IAAI,IAAI,OAAO;AAEhC,MAAI,CAAC,KAAK;AACR,WAAO;AAAA,EACT;AAEA,QAAM,eAAe,SAAS,QAAQ,OAAO;AAC7C,MAAI,iBAAiB,IAAI;AACvB,WAAO;AAAA,EACT;AAEA,WAAS,IAAI,eAAe,GAAG,IAAI,SAAS,QAAQ,KAAK;AACvD,QAAI,IAAI,SAAS,SAAS,CAAC,CAAC,GAAG;AAC7B,aAAO,SAAS,CAAC;AAAA,IACnB;AAAA,EACF;AAEA,SAAO;AACT;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { useCallback, useEffect, useState } from "react";
|
|
2
|
+
import { useMapViewProviderContext } from "./use-map-view-provider-context.js";
|
|
2
3
|
import { applyFeatureFilterRules } from "../utils/apply-feature-filter-rules.js";
|
|
3
4
|
import {
|
|
4
5
|
getCountryRegionsRules,
|
|
@@ -18,13 +19,17 @@ const useLoadMapBaseLayer = (baseLayerConfig) => {
|
|
|
18
19
|
const [isMapEnabled, setIsMapEnabled] = useState(false);
|
|
19
20
|
const [baseFeatureCollection, setBaseFeatureCollection] = useState(void 0);
|
|
20
21
|
const [error, setError] = useState(false);
|
|
22
|
+
const {
|
|
23
|
+
countryCode: providerCountryCode,
|
|
24
|
+
displayWorldMap: providerDisplayWorldMap
|
|
25
|
+
} = useMapViewProviderContext();
|
|
21
26
|
const getData = useCallback(async () => {
|
|
22
27
|
setIsFetchingFeatures(true);
|
|
23
|
-
const isMapEnabledResponse = await fetchClientConfigMapEnabled();
|
|
28
|
+
const isMapEnabledResponse = providerDisplayWorldMap ?? await fetchClientConfigMapEnabled();
|
|
24
29
|
setIsMapEnabled(isMapEnabledResponse);
|
|
25
30
|
try {
|
|
26
31
|
if (isMapEnabledResponse) {
|
|
27
|
-
const tenantCountryCode = await getTenantCountryCode();
|
|
32
|
+
const tenantCountryCode = providerCountryCode ?? await getTenantCountryCode();
|
|
28
33
|
const { includeWorldView, countryRegions } = getBaseLayerShapesRequestConfig(baseLayerConfig.include);
|
|
29
34
|
const featuresRequests = [];
|
|
30
35
|
if (includeWorldView) {
|
|
@@ -55,7 +60,12 @@ const useLoadMapBaseLayer = (baseLayerConfig) => {
|
|
|
55
60
|
setError(true);
|
|
56
61
|
}
|
|
57
62
|
setIsFetchingFeatures(false);
|
|
58
|
-
}, [
|
|
63
|
+
}, [
|
|
64
|
+
baseLayerConfig.include,
|
|
65
|
+
baseLayerConfig.exclude,
|
|
66
|
+
providerCountryCode,
|
|
67
|
+
providerDisplayWorldMap
|
|
68
|
+
]);
|
|
59
69
|
useEffect(() => {
|
|
60
70
|
getData();
|
|
61
71
|
}, [getData]);
|