Skip to content

Commit

Permalink
Fix on window DPR changes (#55)
Browse files Browse the repository at this point in the history
  • Loading branch information
RodrigoHamuy authored Jul 31, 2023
1 parent 25dc10b commit 6be61b6
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/honest-stingrays-sell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"react-three-map": patch
---

Fix on window DPR changes (different solutions for Mapbox and Maplibre)
17 changes: 15 additions & 2 deletions src/core/use-on-add.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export function useOnAdd(
height: canvas.clientHeight,
top: 0,
left: 0,
updateStyle: false,
...renderProps?.size,
},
});
Expand Down Expand Up @@ -76,8 +77,20 @@ export function useOnAdd(
if (!r3mRef.current.map) return;
if (!r3mRef.current.state) return;
const canvas = r3mRef.current.map.getCanvas();
r3mRef.current.state.setSize(canvas.width, canvas.height)
r3mRef.current.state.viewport.dpr = window.devicePixelRatio;

if (canvas.classList.contains('mapboxgl-canvas')) {
// if mapbox
r3mRef.current.state.size.width = canvas.clientWidth;
r3mRef.current.state.size.height = canvas.clientHeight;
} else {
// if maplibre
r3mRef.current.state.setSize(
canvas.clientWidth,
canvas.clientHeight,
false
);
}

})

const onRemove = useFunction(() => {
Expand Down

0 comments on commit 6be61b6

Please sign in to comment.