From eec0ce0586d790448bfe7d4924df4c63d2bce0b3 Mon Sep 17 00:00:00 2001 From: Mohamed Marrouchi Date: Wed, 19 Mar 2025 15:03:42 +0100 Subject: [PATCH] fix: nested map projection --- packages/ez-react/src/components/Map.tsx | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/packages/ez-react/src/components/Map.tsx b/packages/ez-react/src/components/Map.tsx index 55e4930..31d5580 100644 --- a/packages/ez-react/src/components/Map.tsx +++ b/packages/ez-react/src/components/Map.tsx @@ -8,7 +8,7 @@ import { GeoJsonData, MapConfig } from 'eazychart-core/src/types'; import { MapPath } from './shapes/MapPath'; import { useColorScale } from './scales/ColorScale'; import { useChart } from '@/lib/use-chart'; -import { MapContext } from '@/lib/use-map'; +import { MapContext, useMap } from '@/lib/use-map'; export interface MapProps extends SVGAttributes { isWrapped?: boolean; @@ -23,6 +23,7 @@ export const Map: React.FC = ({ children, ...rest }) => { + const parentMap = useMap(); // Validate GeoJSON data structure if (geoJson && !('features' in geoJson)) { throw new Error( @@ -39,8 +40,11 @@ export const Map: React.FC = ({ ); const projection = useMemo( - () => computeMapProjection(projectionType, projectionViewport), - [projectionType, projectionViewport] + () => + parentMap.mapData.length > 0 + ? parentMap.projection + : computeMapProjection(projectionType, projectionViewport), + [parentMap, projectionType, projectionViewport] ); const mapData = useMemo(() => {