diff --git a/react/src/lib/components/DeckGLMap/components/Map.tsx b/react/src/lib/components/DeckGLMap/components/Map.tsx index 9ec16a947..ab3c27aaa 100644 --- a/react/src/lib/components/DeckGLMap/components/Map.tsx +++ b/react/src/lib/components/DeckGLMap/components/Map.tsx @@ -335,10 +335,9 @@ const Map: React.FC = ({ ); // Local help function. - function calcDefaultViewStates() { + function calcDefaultViewStates(input?: ViewportType[]) { // If "bounds" or "cameraPosition" is not defined "viewState" will be // calculated based on the union of the reported bounding boxes from each layer. - const union_of_reported_bboxes = addBoundingBoxes( reportedBoundingBoxAcc, reportedBoundingBox @@ -363,8 +362,9 @@ const Map: React.FC = ({ let tempViewStates: Record = {}; const isBoundsDefined = typeof bounds !== "undefined"; + const updatedViewProps = input ? input : viewsProps; tempViewStates = Object.fromEntries( - viewsProps.map((item, index) => [ + updatedViewProps.map((item, index) => [ item.id, isBoundsDefined ? getViewState( @@ -549,13 +549,17 @@ const Map: React.FC = ({ }, [scaleZDown]); useEffect(() => { - setViewsProps( - getViews( - views, - scaleUpFunction, - scaleDownFunction - ) as ViewportType[] - ); + const viewProps = getViews( + views, + scaleUpFunction, + scaleDownFunction + ) as ViewportType[]; + + setViewsProps(viewProps); + + if (!bounds) { + calcDefaultViewStates(viewProps); + } }, [views]); useEffect(() => { @@ -892,6 +896,7 @@ const Map: React.FC = ({ }, [viewStates] ); + if (!deckGLViews || isEmpty(deckGLViews) || isEmpty(deckGLLayers)) return null; return (