Skip to content

Commit

Permalink
fix: View resets to default when adding/removing a layer. #1690 (#1691)
Browse files Browse the repository at this point in the history
* fix: View resets to default when adding/removing a layer. #1690
 - for some reason this has gone missing from the code at some point.

* Code comment fixes.

* Lint fix
  • Loading branch information
nilscb authored Oct 13, 2023
1 parent a603666 commit 5ec5d90
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,7 @@ IsRenderedCallback.args = {
viewports: [
{
id: "view_1",
show3D: false,
show3D: true,
},
],
},
Expand Down
11 changes: 11 additions & 0 deletions typescript/packages/subsurface-viewer/src/components/Map.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,10 @@ const Map: React.FC<MapProps> = ({

const bboxInitial: BoundingBox3D = [0, 0, 0, 1, 1, 1];

const isCameraPositionDefined =
typeof cameraPosition !== "undefined" &&
Object.keys(cameraPosition).length !== 0;

// Deck.gl View's and viewStates as input to Deck.gl
const [deckGLViews, setDeckGLViews] = useState<View[]>([]);
const [viewStates, setViewStates] = useState<Record<string, ViewStateType>>(
Expand All @@ -602,6 +606,8 @@ const Map: React.FC<MapProps> = ({

const [deckGLLayers, setDeckGLLayers] = useState<LayersList>([]);

const [viewStateChanged, setViewStateChanged] = useState<boolean>(false);

const [viewPortMargins, setViewPortMargins] = useState<marginsType>({
left: 0,
right: 0,
Expand Down Expand Up @@ -647,6 +653,9 @@ const Map: React.FC<MapProps> = ({
}, [triggerHome]);

useEffect(() => {
if (viewStateChanged && !isCameraPositionDefined) {
return;
}
const [Views, viewStates] = createViewsAndViewStates(
views,
viewPortMargins,
Expand All @@ -658,6 +667,7 @@ const Map: React.FC<MapProps> = ({

setDeckGLViews(Views);
setViewStates(viewStates);
setViewStateChanged(false);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [
bounds,
Expand Down Expand Up @@ -1006,6 +1016,7 @@ const Map: React.FC<MapProps> = ({
if (getCameraPosition) {
getCameraPosition(viewState);
}
setViewStateChanged(true);
},
[getCameraPosition, viewStates, views?.viewports]
);
Expand Down

0 comments on commit 5ec5d90

Please sign in to comment.