Skip to content

Commit 55c5392

Browse files
authored
Support maplibre@v5 (#150)
1 parent e22aa04 commit 55c5392

File tree

15 files changed

+57
-51
lines changed

15 files changed

+57
-51
lines changed

.changeset/thin-bears-train.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"react-three-map": patch
3+
---
4+
5+
Support maplibre@v5

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,9 @@ import { Canvas } from "react-three-map/maplibre"
7373

7474
function BasicExample() {
7575
return <Map
76-
antialias
76+
canvasContextAttributes={{
77+
antialias: true,
78+
}}
7779
initialViewState={{
7880
latitude: 51,
7981
longitude: 0,

example-mapbox/src/canvas.basic.stories.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { useControls } from "leva";
33
import Mapbox from "mapbox-gl";
44
import 'mapbox-gl/dist/mapbox-gl.css';
55
import { FC, PropsWithChildren, useRef, useState } from "react";
6-
import Map from 'react-map-gl';
6+
import Map from 'react-map-gl/mapbox';
77
import { Canvas } from "react-three-map";
88
import { Mesh } from "three";
99

example-mapbox/src/story-map.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { useControls } from 'leva';
33
import Mapbox from "mapbox-gl";
44
import 'mapbox-gl/dist/mapbox-gl.css';
55
import { FC, PropsWithChildren } from "react";
6-
import Map from 'react-map-gl';
6+
import Map from 'react-map-gl/mapbox';
77

88
export interface StoryMapProps extends PropsWithChildren {
99
latitude: number,

example-maplibre/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"@react-three/drei": "^9.77.10",
1212
"@react-three/fiber": "^8.13.4",
1313
"leva": "^0.9.35",
14-
"maplibre-gl": "^4.7.1",
14+
"maplibre-gl": "^5.4.0",
1515
"react": "^18.2.0",
1616
"react-dom": "^18.2.0",
1717
"react-map-gl": "8.0.1",

example-maplibre/src/canvas.basic.stories.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ export default { title: 'Canvas' }
1010
export function BasicExample() {
1111
return <div style={{ height: '100vh' }}>
1212
<Map
13-
antialias
13+
canvasContextAttributes={{
14+
antialias: true,
15+
}}
1416
initialViewState={{
1517
latitude: 51,
1618
longitude: 0,

example-maplibre/src/story-map.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ export const StoryMap: FC<StoryMapProps> = ({
2323

2424
return <div style={{ height: '100vh', position: 'relative' }}>
2525
<Map
26-
antialias
26+
canvasContextAttributes={{
27+
antialias: true,
28+
}}
2729
initialViewState={{
2830
latitude,
2931
longitude,

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
"leva": "^0.9.35",
5555
"luxon": "^3.3.0",
5656
"mapbox-gl": "^3.9.4",
57-
"maplibre-gl": "4.7.1",
57+
"maplibre-gl": "^5.4.0",
5858
"react": "^18.2.0",
5959
"react-dom": "^18.2.0",
6060
"react-map-gl": "^8.0.1",

src/core/canvas-in-layer/use-render.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export function useRender({
2121
const state = useThree.getState();
2222
const camera = state.camera as PerspectiveCamera;
2323
const {gl, advance} = state;
24-
syncCamera(camera as PerspectiveCamera, origin, projViewMx as Matrix4Tuple);
24+
syncCamera(camera as PerspectiveCamera, origin, pVMx as Matrix4Tuple);
2525
gl.resetState();
2626
advance(Date.now() * 0.001, true);
2727
if (!frameloop || frameloop === 'always') map.triggerRepaint();

src/core/canvas-overlay/sync-camera-fc.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export const SyncCameraFC = memo<SyncCameraFCProps>(({
5757
}
5858
}, -Infinity)
5959

60-
const onRender = useFunction((viewProjMx: Matrix4Tuple) => {
60+
const onRender = useFunction((viewProjMx: Matrix4Tuple | {defaultProjectionData: {mainMatrix: Record<string, number>}}) => {
6161
map.triggerRepaint = triggerRepaintOff;
6262

6363
if (threeCanvas.width !== mapCanvas.width || threeCanvas.height !== mapCanvas.height) {
@@ -70,7 +70,8 @@ export const SyncCameraFC = memo<SyncCameraFCProps>(({
7070
);
7171
}
7272

73-
r3m.viewProjMx = viewProjMx;
73+
const pVMx = 'defaultProjectionData' in viewProjMx ? Object.values(viewProjMx.defaultProjectionData.mainMatrix) : viewProjMx;
74+
r3m.viewProjMx = pVMx as Matrix4Tuple;
7475
if (!ready.current && onReady) {
7576
ready.current = true;
7677
onReady();

0 commit comments

Comments
 (0)