Skip to content

Commit 1c52c0f

Browse files
authored
allow to set Layer id and beforeId (#76)
1 parent 748d7a7 commit 1c52c0f

File tree

5 files changed

+19
-10
lines changed

5 files changed

+19
-10
lines changed

.changeset/thirty-radios-suffer.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"react-three-map": minor
3+
---
4+
5+
`<Canvas>` props accepts `id?: string` and `beforeId?: string` to set the MapLibre/Mapbox layer.

src/api/canvas-props.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@ import { RenderProps } from "@react-three/fiber";
22
import { PropsWithChildren } from "react";
33

44
export interface CanvasProps extends Omit<RenderProps<HTMLCanvasElement>, 'frameloop'>, PropsWithChildren {
5+
id?: string;
6+
beforeId?: string;
57
longitude: number,
68
latitude: number,
79
altitude?: number,
810
frameloop?: 'always' | 'demand',
9-
}
11+
}

src/core/use-canvas.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { useCoords } from "./use-coords";
44
import { useCreateRoot } from "./use-create-root";
55
import { useRender } from "./use-render";
66

7-
export interface useCanvasProps extends CanvasProps {
7+
export interface useCanvasProps extends Omit<CanvasProps, 'id'|'beforeId'> {
88
fromLngLat: FromLngLat,
99
}
1010

src/mapbox/canvas.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,17 @@ extend(THREE);
1111
const fromLngLat = MercatorCoordinate.fromLngLat
1212

1313
/** react`-three-fiber` canvas inside `Mapbox` */
14-
export const Canvas = memo<CanvasProps>((props) => {
14+
export const Canvas = memo<CanvasProps>(({id, beforeId, ...props}) => {
1515

16-
const { id, onAdd, onRemove, render } = useCanvas({ ...props, fromLngLat });
16+
const { id: reactId, onAdd, onRemove, render } = useCanvas({ ...props, fromLngLat });
1717

1818
return <Layer
19-
id={id}
19+
id={id || reactId}
20+
beforeId={beforeId}
2021
type="custom"
2122
renderingMode="3d"
2223
onAdd={onAdd}
2324
onRemove={onRemove}
2425
render={render}
2526
/>
26-
})
27+
})

src/maplibre/canvas.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,17 @@ extend(THREE);
1111
const fromLngLat = MercatorCoordinate.fromLngLat
1212

1313
/** react`-three-fiber` canvas inside `MapLibre` */
14-
export const Canvas = memo<CanvasProps>((props) => {
14+
export const Canvas = memo<CanvasProps>(({id, beforeId, ...props}) => {
1515

16-
const { id, onAdd, onRemove, render } = useCanvas({ ...props, fromLngLat });
16+
const { id: reactId, onAdd, onRemove, render } = useCanvas({ ...props, fromLngLat });
1717

1818
return <Layer
19-
id={id}
19+
id={id || reactId}
20+
beforeId={beforeId}
2021
type="custom"
2122
renderingMode="3d"
2223
onAdd={onAdd}
2324
onRemove={onRemove}
2425
render={render}
2526
/>
26-
})
27+
})

0 commit comments

Comments
 (0)