Skip to content

Commit

Permalink
Bug fix for bounding undefined (#1385)
Browse files Browse the repository at this point in the history
* temp

* fix bug for views does not get updated if bound is undefined

* resolve duplicate

Co-authored-by: shengwei zhang <[email protected]>
  • Loading branch information
VincentNevermore and shengwei zhang authored Jan 13, 2023
1 parent 7757b44 commit 218ac97
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions react/src/lib/components/DeckGLMap/components/Map.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -335,10 +335,9 @@ const Map: React.FC<MapProps> = ({
);

// 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
Expand All @@ -363,8 +362,9 @@ const Map: React.FC<MapProps> = ({

let tempViewStates: Record<string, ViewStateType> = {};
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(
Expand Down Expand Up @@ -549,13 +549,17 @@ const Map: React.FC<MapProps> = ({
}, [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(() => {
Expand Down Expand Up @@ -892,6 +896,7 @@ const Map: React.FC<MapProps> = ({
},
[viewStates]
);

if (!deckGLViews || isEmpty(deckGLViews) || isEmpty(deckGLLayers))
return null;
return (
Expand Down

0 comments on commit 218ac97

Please sign in to comment.