react-three-map 0.2.1 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/README.md +18 -15
- package/dist/cjs/main.js +1 -0
- package/dist/es/main.mjs +5 -0
- package/dist/es/main.mjs.map +1 -0
- package/dist/es/main2.mjs +38 -0
- package/dist/es/main2.mjs.map +1 -0
- package/dist/{maplibre/es/main.js3.mjs → es/main3.mjs} +1 -1
- package/dist/es/main3.mjs.map +1 -0
- package/dist/es/main4.mjs +19 -0
- package/dist/es/main4.mjs.map +1 -0
- package/dist/{maplibre/es/main.js5.mjs → es/main5.mjs} +3 -3
- package/dist/es/main5.mjs.map +1 -0
- package/dist/{maplibre/es/main.js6.mjs → es/main6.mjs} +2 -2
- package/dist/es/main6.mjs.map +1 -0
- package/dist/{maplibre/es/main.js7.mjs → es/main7.mjs} +1 -1
- package/dist/es/main7.mjs.map +1 -0
- package/dist/{maplibre/es/main.js8.mjs → es/main8.mjs} +1 -1
- package/dist/es/main8.mjs.map +1 -0
- package/dist/maplibre/cjs/main.js +1 -0
- package/dist/maplibre/es/main.mjs +5 -0
- package/dist/maplibre/es/main.mjs.map +1 -0
- package/dist/maplibre/es/main2.mjs +38 -0
- package/dist/maplibre/es/main2.mjs.map +1 -0
- package/dist/{es/main.js3.mjs → maplibre/es/main3.mjs} +1 -1
- package/dist/maplibre/es/main3.mjs.map +1 -0
- package/dist/maplibre/es/main4.mjs +19 -0
- package/dist/maplibre/es/main4.mjs.map +1 -0
- package/dist/{es/main.js8.mjs → maplibre/es/main5.mjs} +3 -3
- package/dist/maplibre/es/main5.mjs.map +1 -0
- package/dist/{es/main.js9.mjs → maplibre/es/main6.mjs} +2 -2
- package/dist/maplibre/es/main6.mjs.map +1 -0
- package/dist/{es/main.js10.mjs → maplibre/es/main7.mjs} +1 -1
- package/dist/maplibre/es/main7.mjs.map +1 -0
- package/dist/{es/main.js11.mjs → maplibre/es/main8.mjs} +1 -1
- package/dist/maplibre/es/main8.mjs.map +1 -0
- package/example-mapbox/package.json +29 -0
- package/example-mapbox/sandbox.config.json +3 -0
- package/example-mapbox/src/canvas.basic.stories.tsx +84 -0
- package/example-mapbox/src/comparison.stories.tsx +37 -0
- package/example-mapbox/src/html-on-top.stories.tsx +24 -0
- package/example-mapbox/src/my-scene.tsx +89 -0
- package/example-mapbox/src/render-on-demand.stories.tsx +32 -0
- package/example-mapbox/src/story-map.tsx +61 -0
- package/example-mapbox/src/vite-env.d.ts +1 -0
- package/example-mapbox/tsconfig.json +27 -0
- package/example-mapbox/tsconfig.node.json +10 -0
- package/example-mapbox/yarn.lock +4154 -0
- package/example-maplibre/package.json +29 -0
- package/example-maplibre/sandbox.config.json +3 -0
- package/example-maplibre/src/canvas.basic.stories.tsx +61 -0
- package/example-maplibre/src/comparison.stories.tsx +35 -0
- package/example-maplibre/src/html-on-top.stories.tsx +24 -0
- package/example-maplibre/src/my-scene.tsx +89 -0
- package/example-maplibre/src/render-on-demand.stories.tsx +32 -0
- package/example-maplibre/src/story-map.tsx +38 -0
- package/example-maplibre/src/vite-env.d.ts +1 -0
- package/example-maplibre/tsconfig.json +25 -0
- package/example-maplibre/tsconfig.node.json +10 -0
- package/example-maplibre/yarn.lock +4181 -0
- package/maplibre/package.json +2 -2
- package/package.json +22 -7
- package/src/{canvas/core → core}/generic-map.ts +15 -2
- package/src/{canvas/core → core}/state-ref.ts +2 -2
- package/src/{canvas/core/internal-canvas.tsx → core/use-canvas.tsx} +6 -18
- package/src/{canvas/core → core}/use-on-add.ts +3 -3
- package/src/{canvas/canvas-mapbox.tsx → mapbox/canvas.tsx} +15 -9
- package/src/mapbox/index.ts +1 -0
- package/src/{canvas/canvas-maplibre.tsx → maplibre/canvas.tsx} +13 -7
- package/src/maplibre/index.ts +1 -0
- package/src/stories/comparison.stories.tsx +27 -30
- package/src/stories/html-on-top.stories.tsx +11 -16
- package/src/stories/mapbox/story-mapbox.tsx +58 -0
- package/src/stories/mapbox-example.stories.tsx +84 -0
- package/src/stories/maplibre/story-maplibre.tsx +32 -0
- package/src/stories/{canvas.basic.stories.tsx → maplibre-example.stories.tsx} +28 -30
- package/src/stories/my-scene.tsx +3 -12
- package/src/stories/render-on-demand.stories.tsx +23 -37
- package/src/stories/story-map.tsx +23 -28
- package/tsconfig.json +5 -0
- package/dist/cjs/main.js.js +0 -1318
- package/dist/es/main.js.mjs +0 -5
- package/dist/es/main.js.mjs.map +0 -1
- package/dist/es/main.js10.mjs.map +0 -1
- package/dist/es/main.js11.mjs.map +0 -1
- package/dist/es/main.js2.mjs +0 -34
- package/dist/es/main.js2.mjs.map +0 -1
- package/dist/es/main.js3.mjs.map +0 -1
- package/dist/es/main.js4.mjs +0 -31
- package/dist/es/main.js4.mjs.map +0 -1
- package/dist/es/main.js5.mjs +0 -23537
- package/dist/es/main.js5.mjs.map +0 -1
- package/dist/es/main.js6.mjs +0 -5
- package/dist/es/main.js6.mjs.map +0 -1
- package/dist/es/main.js7.mjs +0 -5
- package/dist/es/main.js7.mjs.map +0 -1
- package/dist/es/main.js8.mjs.map +0 -1
- package/dist/es/main.js9.mjs.map +0 -1
- package/dist/maplibre/cjs/main.js.js +0 -1
- package/dist/maplibre/es/main.js.mjs +0 -5
- package/dist/maplibre/es/main.js.mjs.map +0 -1
- package/dist/maplibre/es/main.js2.mjs +0 -34
- package/dist/maplibre/es/main.js2.mjs.map +0 -1
- package/dist/maplibre/es/main.js3.mjs.map +0 -1
- package/dist/maplibre/es/main.js4.mjs +0 -31
- package/dist/maplibre/es/main.js4.mjs.map +0 -1
- package/dist/maplibre/es/main.js5.mjs.map +0 -1
- package/dist/maplibre/es/main.js6.mjs.map +0 -1
- package/dist/maplibre/es/main.js7.mjs.map +0 -1
- package/dist/maplibre/es/main.js8.mjs.map +0 -1
- package/src/main-mapbox.ts +0 -1
- package/src/main-maplibre.ts +0 -1
- /package/src/{canvas/core → core}/coords-to-matrix.ts +0 -0
- /package/src/{canvas/core → core}/create-events.ts +0 -0
- /package/src/{canvas/core → core}/generic-map.test.ts +0 -0
- /package/src/{canvas/core → core}/use-function.ts +0 -0
- /package/src/{canvas/core → core}/use-render.ts +0 -0
package/maplibre/package.json
CHANGED
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-three-map",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"description": "Use react-three-fiber inside MapLibre and Mapbox",
|
|
5
5
|
"main": "dist/cjs/main.js",
|
|
6
|
-
"module": "dist/es/main.
|
|
7
|
-
"types": "src/
|
|
6
|
+
"module": "dist/es/main.mjs",
|
|
7
|
+
"types": "src/mapbox/index.ts",
|
|
8
8
|
"sideEffects": false,
|
|
9
9
|
"repository": "https://github.com/RodrigoHamuy/react-three-map",
|
|
10
10
|
"homepage": "https://github.com/RodrigoHamuy/react-three-map",
|
|
@@ -14,7 +14,6 @@
|
|
|
14
14
|
"license": "MIT",
|
|
15
15
|
"author": "RodrigoHamuy",
|
|
16
16
|
"scripts": {
|
|
17
|
-
"dev": "vite",
|
|
18
17
|
"prebuild": "tsc",
|
|
19
18
|
"build": "yarn build:maplibre && yarn build:mapbox",
|
|
20
19
|
"build:maplibre": "cross-env LIB_MODE=1 MAP_MODE=0 vite build",
|
|
@@ -22,7 +21,7 @@
|
|
|
22
21
|
"build:mapbox": "cross-env LIB_MODE=1 MAP_MODE=1 vite build",
|
|
23
22
|
"postbuild:mapbox": "cross-env LIB_MODE=2 MAP_MODE=1 vite build",
|
|
24
23
|
"release": "yarn build && yarn changeset publish",
|
|
25
|
-
"lint": "eslint src --ext ts,tsx --fix",
|
|
24
|
+
"lint": "eslint src example-maplibre/src example-mapbox/src --ext ts,tsx --fix",
|
|
26
25
|
"preview": "vite preview",
|
|
27
26
|
"ts": "tsc -w",
|
|
28
27
|
"stories": "yarn ladle serve",
|
|
@@ -33,7 +32,7 @@
|
|
|
33
32
|
"@changesets/cli": "^2.26.1",
|
|
34
33
|
"@ladle/react": "^2.13.0",
|
|
35
34
|
"@react-three/drei": "^9.74.5",
|
|
36
|
-
"@react-three/fiber": "^8.13.
|
|
35
|
+
"@react-three/fiber": "^8.13.4",
|
|
37
36
|
"@types/node": "^20.3.1",
|
|
38
37
|
"@types/react": "^18.0.37",
|
|
39
38
|
"@types/react-dom": "^18.0.11",
|
|
@@ -50,10 +49,26 @@
|
|
|
50
49
|
"maplibre-gl": "^3.1.0",
|
|
51
50
|
"react": "^18.2.0",
|
|
52
51
|
"react-dom": "^18.2.0",
|
|
53
|
-
"react-map-gl": "^7.0
|
|
52
|
+
"react-map-gl": "^7.1.0",
|
|
54
53
|
"three": "^0.153.0",
|
|
55
54
|
"three-stdlib": "^2.23.8",
|
|
56
55
|
"typescript": "~5.0.2",
|
|
57
56
|
"vite": "^4.3.9"
|
|
57
|
+
},
|
|
58
|
+
"peerDependencies": {
|
|
59
|
+
"@react-three/fiber": ">=8.13",
|
|
60
|
+
"mapbox-gl": ">=2.15",
|
|
61
|
+
"maplibre-gl": ">=3.1",
|
|
62
|
+
"react-map-gl": ">=7.1",
|
|
63
|
+
"react": ">=18.0",
|
|
64
|
+
"three": ">=0.133"
|
|
65
|
+
},
|
|
66
|
+
"peerDependenciesMeta": {
|
|
67
|
+
"mapbox-gl": {
|
|
68
|
+
"optional": true
|
|
69
|
+
},
|
|
70
|
+
"maplibre-gl": {
|
|
71
|
+
"optional": true
|
|
72
|
+
}
|
|
58
73
|
}
|
|
59
74
|
}
|
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
// mock of functions used by `react-three-map` from `Maplibre` or `Mapbox`
|
|
2
2
|
|
|
3
|
+
/** Generic interface of Mapbox/Maplibre `LayerProps` */
|
|
4
|
+
export interface LayerProps {
|
|
5
|
+
id: string;
|
|
6
|
+
type: 'custom';
|
|
7
|
+
renderingMode: '3d';
|
|
8
|
+
onRemove?(map: MapInstance, gl: WebGLRenderingContext): void;
|
|
9
|
+
onAdd?(map: MapInstance, gl: WebGLRenderingContext): void;
|
|
10
|
+
prerender?(gl: WebGLRenderingContext, matrix: number[]): void;
|
|
11
|
+
render(gl: WebGLRenderingContext, matrix: number[]): void;
|
|
12
|
+
}
|
|
13
|
+
|
|
3
14
|
/** Generic interface of Mapbox/Maplibre `LngLatLike` */
|
|
4
15
|
export type LngLatLike = {
|
|
5
16
|
lng: number;
|
|
@@ -24,10 +35,12 @@ export interface MercatorCoordinate {
|
|
|
24
35
|
}
|
|
25
36
|
|
|
26
37
|
/** Generic interface of Mapbox/Maplibre `Map` */
|
|
27
|
-
export interface
|
|
38
|
+
export interface MapInstance {
|
|
28
39
|
getCanvas(): HTMLCanvasElement;
|
|
29
40
|
triggerRepaint(): void;
|
|
41
|
+
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
30
42
|
on<T extends keyof MapEventType>(type: T, listener: (ev: MapEventType[T] & Object) => void): this;
|
|
43
|
+
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
31
44
|
off<T extends keyof MapEventType>(type: T, listener: (ev: MapEventType[T] & Object) => void): this;
|
|
32
45
|
}
|
|
33
46
|
|
|
@@ -39,6 +52,6 @@ export type MapEventType = {
|
|
|
39
52
|
/** Generic interface of `MapLibreEvent` or `MapBoxEvent` */
|
|
40
53
|
export interface MapEvent<TOrig = unknown> {
|
|
41
54
|
type: string;
|
|
42
|
-
target:
|
|
55
|
+
target: MapInstance;
|
|
43
56
|
originalEvent: TOrig;
|
|
44
57
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { ReconcilerRoot, RootState } from "@react-three/fiber";
|
|
2
2
|
import { MutableRefObject } from "react";
|
|
3
|
-
import {
|
|
3
|
+
import { MapInstance } from "./generic-map";
|
|
4
4
|
|
|
5
5
|
export type StateRef = MutableRefObject<{
|
|
6
|
-
map:
|
|
6
|
+
map: MapInstance;
|
|
7
7
|
root: ReconcilerRoot<HTMLCanvasElement>;
|
|
8
8
|
state?: RootState;
|
|
9
9
|
} | undefined>
|
|
@@ -1,19 +1,18 @@
|
|
|
1
1
|
import { RenderProps } from "@react-three/fiber";
|
|
2
|
-
import { PropsWithChildren,
|
|
3
|
-
import { Layer } from "react-map-gl";
|
|
2
|
+
import { PropsWithChildren, useEffect, useId, useRef } from "react";
|
|
4
3
|
import { Matrix4Tuple } from "three";
|
|
5
4
|
import { StateRef } from "./state-ref";
|
|
6
5
|
import { useOnAdd } from "./use-on-add";
|
|
7
6
|
import { useRender } from "./use-render";
|
|
8
7
|
|
|
9
|
-
export interface
|
|
8
|
+
export interface useCanvasProps extends Omit<RenderProps<HTMLCanvasElement>, 'frameloop'>, PropsWithChildren {
|
|
10
9
|
frameloop: 'always' | 'demand',
|
|
11
10
|
m4: Matrix4Tuple;
|
|
12
11
|
}
|
|
13
12
|
|
|
14
|
-
export const
|
|
13
|
+
export const useCanvas = (({
|
|
15
14
|
m4, children, frameloop, ...renderProps
|
|
16
|
-
}) => {
|
|
15
|
+
}: useCanvasProps) => {
|
|
17
16
|
const id = useId();
|
|
18
17
|
|
|
19
18
|
const stateRef: StateRef = useRef();
|
|
@@ -28,16 +27,5 @@ export const InternalCanvas = memo<InternalCanvasProps>(({
|
|
|
28
27
|
stateRef.current.root.render(<>{children}</>);
|
|
29
28
|
}, [stateRef, mounted, children])
|
|
30
29
|
|
|
31
|
-
return
|
|
32
|
-
|
|
33
|
-
type="custom"
|
|
34
|
-
renderingMode="3d"
|
|
35
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
36
|
-
onAdd={onAdd as any}
|
|
37
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
38
|
-
onRemove={onRemove as any}
|
|
39
|
-
render={render}
|
|
40
|
-
/>
|
|
41
|
-
})
|
|
42
|
-
|
|
43
|
-
InternalCanvas.displayName = 'InternalCanvas';
|
|
30
|
+
return { id, onAdd, onRemove, render }
|
|
31
|
+
})
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { RenderProps, createRoot } from "@react-three/fiber";
|
|
2
|
-
import { Map } from "./generic-map";
|
|
3
2
|
import { useState } from "react";
|
|
4
3
|
import { createEvents } from "./create-events";
|
|
4
|
+
import { MapInstance } from "./generic-map";
|
|
5
5
|
import { StateRef } from "./state-ref";
|
|
6
6
|
import { useFunction } from "./use-function";
|
|
7
7
|
|
|
@@ -9,7 +9,7 @@ export function useOnAdd(ref: StateRef, { frameloop, ...renderProps }: RenderPro
|
|
|
9
9
|
|
|
10
10
|
const [mounted, setMounted] = useState(false);
|
|
11
11
|
|
|
12
|
-
const onAdd = useFunction((map:
|
|
12
|
+
const onAdd = useFunction((map: MapInstance, gl: WebGLRenderingContext) => {
|
|
13
13
|
|
|
14
14
|
const canvas = map.getCanvas();
|
|
15
15
|
const root = createRoot(canvas);
|
|
@@ -78,7 +78,7 @@ export function useOnAdd(ref: StateRef, { frameloop, ...renderProps }: RenderPro
|
|
|
78
78
|
state.setSize(canvas.width, canvas.height);
|
|
79
79
|
})
|
|
80
80
|
|
|
81
|
-
const onRemove = useFunction((map:
|
|
81
|
+
const onRemove = useFunction((map: MapInstance) => {
|
|
82
82
|
setTimeout(() => {
|
|
83
83
|
if (!ref.current) return;
|
|
84
84
|
ref.current.root.unmount();
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { RenderProps, extend } from "@react-three/fiber";
|
|
2
|
+
import { MercatorCoordinate } from "mapbox-gl";
|
|
2
3
|
import { PropsWithChildren, memo, useMemo } from "react";
|
|
4
|
+
import { Layer } from "react-map-gl";
|
|
3
5
|
import * as THREE from "three";
|
|
4
|
-
import { coordsToMatrix } from "
|
|
5
|
-
import {
|
|
6
|
-
import { MercatorCoordinate } from "mapbox-gl";
|
|
6
|
+
import { coordsToMatrix } from "../core/coords-to-matrix";
|
|
7
|
+
import { useCanvas } from "../core/use-canvas";
|
|
7
8
|
|
|
8
9
|
extend(THREE);
|
|
9
10
|
|
|
@@ -14,7 +15,7 @@ export interface CanvasProps extends Omit<RenderProps<HTMLCanvasElement>, 'frame
|
|
|
14
15
|
frameloop?: 'always' | 'demand',
|
|
15
16
|
}
|
|
16
17
|
|
|
17
|
-
/** react`-three-fiber` canvas inside `
|
|
18
|
+
/** react`-three-fiber` canvas inside `MapLibre` */
|
|
18
19
|
export const Canvas = memo<CanvasProps>(({
|
|
19
20
|
longitude, latitude, altitude = 0,
|
|
20
21
|
frameloop = 'always', ...renderProps
|
|
@@ -22,11 +23,16 @@ export const Canvas = memo<CanvasProps>(({
|
|
|
22
23
|
|
|
23
24
|
const m4 = useMemo(() => coordsToMatrix({
|
|
24
25
|
latitude, longitude, altitude, fromLngLat: MercatorCoordinate.fromLngLat,
|
|
25
|
-
}), [latitude, longitude, altitude])
|
|
26
|
+
}), [latitude, longitude, altitude]);
|
|
27
|
+
|
|
28
|
+
const { id, onAdd, onRemove, render } = useCanvas({ m4, frameloop, ...renderProps });
|
|
26
29
|
|
|
27
|
-
return <
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
30
|
+
return <Layer
|
|
31
|
+
id={id}
|
|
32
|
+
type="custom"
|
|
33
|
+
renderingMode="3d"
|
|
34
|
+
onAdd={onAdd}
|
|
35
|
+
onRemove={onRemove}
|
|
36
|
+
render={render}
|
|
31
37
|
/>
|
|
32
38
|
})
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './canvas';
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { RenderProps, extend } from "@react-three/fiber";
|
|
2
2
|
import { MercatorCoordinate } from "maplibre-gl";
|
|
3
3
|
import { PropsWithChildren, memo, useMemo } from "react";
|
|
4
|
+
import { Layer } from "react-map-gl/maplibre";
|
|
4
5
|
import * as THREE from "three";
|
|
5
|
-
import { coordsToMatrix } from "
|
|
6
|
-
import {
|
|
6
|
+
import { coordsToMatrix } from "../core/coords-to-matrix";
|
|
7
|
+
import { useCanvas } from "../core/use-canvas";
|
|
7
8
|
|
|
8
9
|
extend(THREE);
|
|
9
10
|
|
|
@@ -22,11 +23,16 @@ export const Canvas = memo<CanvasProps>(({
|
|
|
22
23
|
|
|
23
24
|
const m4 = useMemo(() => coordsToMatrix({
|
|
24
25
|
latitude, longitude, altitude, fromLngLat: MercatorCoordinate.fromLngLat,
|
|
25
|
-
}), [latitude, longitude, altitude])
|
|
26
|
+
}), [latitude, longitude, altitude]);
|
|
26
27
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
{
|
|
28
|
+
const { id, onAdd, onRemove, render } = useCanvas({ m4, frameloop, ...renderProps });
|
|
29
|
+
|
|
30
|
+
return <Layer
|
|
31
|
+
id={id}
|
|
32
|
+
type="custom"
|
|
33
|
+
renderingMode="3d"
|
|
34
|
+
onAdd={onAdd}
|
|
35
|
+
onRemove={onRemove}
|
|
36
|
+
render={render}
|
|
31
37
|
/>
|
|
32
38
|
})
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './canvas';
|
|
@@ -1,41 +1,38 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import { Canvas } from "../canvas/canvas-maplibre";
|
|
5
|
-
import { Canvas as FiberCanvas } from "@react-three/fiber"
|
|
1
|
+
import { MapControls } from "@react-three/drei";
|
|
2
|
+
import { Canvas as FiberCanvas } from "@react-three/fiber";
|
|
3
|
+
import { useControls } from "leva";
|
|
6
4
|
import { MyScene } from "./my-scene";
|
|
7
|
-
import {
|
|
8
|
-
import MapLibre from "maplibre-gl";
|
|
5
|
+
import { StoryMap } from "./story-map";
|
|
9
6
|
|
|
10
7
|
export function WithMap() {
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
longitude: -0.1276473,
|
|
22
|
-
zoom: 18,
|
|
23
|
-
pitch: 60,
|
|
24
|
-
}}
|
|
25
|
-
mapStyle={mapStyle}
|
|
26
|
-
>
|
|
27
|
-
<Canvas latitude={51.5073218} longitude={-0.1276473} shadows="variance">
|
|
28
|
-
<MyScene />
|
|
29
|
-
</Canvas>
|
|
30
|
-
</Map>
|
|
31
|
-
</div>
|
|
8
|
+
const showCamHelper = useShowCamHelper()
|
|
9
|
+
return <StoryMap
|
|
10
|
+
latitude={51.5073218}
|
|
11
|
+
longitude={-0.1276473}
|
|
12
|
+
zoom={18}
|
|
13
|
+
pitch={60}
|
|
14
|
+
canvas={{ shadows: 'variance' }}
|
|
15
|
+
>
|
|
16
|
+
<MyScene showCamHelper={showCamHelper} />
|
|
17
|
+
</StoryMap>
|
|
32
18
|
}
|
|
33
19
|
|
|
34
20
|
export const WithoutMap = () => {
|
|
21
|
+
const showCamHelper = useShowCamHelper()
|
|
35
22
|
return <div style={{ height: '100vh' }}>
|
|
36
|
-
<FiberCanvas camera={{position: [100,100,100]}} shadows="variance">
|
|
37
|
-
<MyScene />
|
|
23
|
+
<FiberCanvas camera={{ position: [100, 100, 100] }} shadows="variance">
|
|
24
|
+
<MyScene showCamHelper={showCamHelper} />
|
|
38
25
|
<MapControls makeDefault />
|
|
39
26
|
</FiberCanvas>
|
|
40
27
|
</div>
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const useShowCamHelper = () => {
|
|
31
|
+
const { showCamHelper } = useControls({
|
|
32
|
+
showCamHelper: {
|
|
33
|
+
value: false,
|
|
34
|
+
label: 'show camera helper'
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
return showCamHelper
|
|
41
38
|
}
|
|
@@ -1,26 +1,21 @@
|
|
|
1
|
-
import { Box, Html
|
|
2
|
-
import 'maplibre-gl/dist/maplibre-gl.css';
|
|
1
|
+
import { Box, Html } from "@react-three/drei";
|
|
3
2
|
import { useState } from "react";
|
|
4
3
|
import { MathUtils } from "three";
|
|
5
|
-
import { Canvas } from "../canvas/canvas-maplibre";
|
|
6
4
|
import { StoryMap } from "./story-map";
|
|
7
5
|
|
|
8
6
|
export function Default() {
|
|
9
7
|
|
|
10
8
|
const [hovered, hover] = useState(false);
|
|
11
9
|
|
|
12
|
-
return <StoryMap>
|
|
13
|
-
<
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
/>
|
|
23
|
-
<Stats />
|
|
24
|
-
</Canvas>
|
|
10
|
+
return <StoryMap latitude={51} longitude={0} zoom={13} pitch={60}>
|
|
11
|
+
<Html center position={[0, 250, 0]} style={{ textAlign: 'center', fontSize: '2em', width: '10em', lineHeight: '1.5em' }}><i>Some</i> <b>HTML</b><br />content!</Html>
|
|
12
|
+
<Box
|
|
13
|
+
args={[500, 500, 500]}
|
|
14
|
+
position={[0, 250, 0]}
|
|
15
|
+
rotation={[0, 45 * MathUtils.DEG2RAD, 0]}
|
|
16
|
+
onPointerOver={() => hover(true)}
|
|
17
|
+
onPointerOut={() => hover(false)}
|
|
18
|
+
material-color={hovered ? 'purple' : 'orange'}
|
|
19
|
+
/>
|
|
25
20
|
</StoryMap>
|
|
26
21
|
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { ThemeState, useLadleContext } from '@ladle/react';
|
|
2
|
+
import { useControls } from 'leva';
|
|
3
|
+
import Mapbox from "mapbox-gl";
|
|
4
|
+
import 'mapbox-gl/dist/mapbox-gl.css';
|
|
5
|
+
import { FC, PropsWithChildren } from "react";
|
|
6
|
+
import Map from 'react-map-gl';
|
|
7
|
+
import { Canvas } from 'react-three-map';
|
|
8
|
+
import { StoryMapProps } from '../story-map';
|
|
9
|
+
|
|
10
|
+
/** `<Map>` styled for stories */
|
|
11
|
+
export const StoryMapbox: FC<StoryMapProps> = ({
|
|
12
|
+
latitude, longitude, zoom = 18, pitch = 60, canvas, children
|
|
13
|
+
}) => {
|
|
14
|
+
|
|
15
|
+
const { mapboxToken } = useControls({
|
|
16
|
+
mapboxToken: {
|
|
17
|
+
value: import.meta.env.VITE_MAPBOX_TOKEN || '',
|
|
18
|
+
label: 'mapbox token',
|
|
19
|
+
}
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
const theme = useLadleContext().globalState.theme;
|
|
23
|
+
|
|
24
|
+
const mapStyle = theme === ThemeState.Dark
|
|
25
|
+
? "mapbox://styles/mapbox/dark-v11"
|
|
26
|
+
: "mapbox://styles/mapbox/streets-v12";
|
|
27
|
+
|
|
28
|
+
Mapbox.accessToken = mapboxToken;
|
|
29
|
+
|
|
30
|
+
return <div style={{ height: '100vh', position: 'relative' }}>
|
|
31
|
+
{!mapboxToken && <Center>Add a mapbox token to load this component</Center>}
|
|
32
|
+
{!!mapboxToken && <Map
|
|
33
|
+
antialias
|
|
34
|
+
initialViewState={{
|
|
35
|
+
latitude,
|
|
36
|
+
longitude,
|
|
37
|
+
zoom,
|
|
38
|
+
pitch,
|
|
39
|
+
}}
|
|
40
|
+
mapStyle={mapStyle}
|
|
41
|
+
mapboxAccessToken={mapboxToken}
|
|
42
|
+
>
|
|
43
|
+
<Canvas latitude={latitude} longitude={longitude} {...canvas}>
|
|
44
|
+
{children}
|
|
45
|
+
</Canvas>
|
|
46
|
+
</Map>}
|
|
47
|
+
</div>
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const Center = ({ children }: PropsWithChildren) => (
|
|
51
|
+
<div style={{
|
|
52
|
+
display: 'flex',
|
|
53
|
+
height: '100%',
|
|
54
|
+
width: '100%',
|
|
55
|
+
alignItems: 'center',
|
|
56
|
+
justifyContent: 'center',
|
|
57
|
+
}}>{children}</div>
|
|
58
|
+
)
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { useFrame, Vector3 } from "@react-three/fiber";
|
|
2
|
+
import { useControls } from "leva";
|
|
3
|
+
import Mapbox from "mapbox-gl";
|
|
4
|
+
import 'mapbox-gl/dist/mapbox-gl.css';
|
|
5
|
+
import { FC, PropsWithChildren, useRef, useState } from "react";
|
|
6
|
+
import Map from 'react-map-gl';
|
|
7
|
+
import { Canvas } from "react-three-map";
|
|
8
|
+
import { Mesh } from "three";
|
|
9
|
+
|
|
10
|
+
export default { title: 'Canvas' }
|
|
11
|
+
|
|
12
|
+
export function MapboxExample() {
|
|
13
|
+
|
|
14
|
+
const { mapboxToken } = useControls({
|
|
15
|
+
mapboxToken: {
|
|
16
|
+
value: import.meta.env.VITE_MAPBOX_TOKEN || '',
|
|
17
|
+
label: 'mapbox token',
|
|
18
|
+
}
|
|
19
|
+
})
|
|
20
|
+
|
|
21
|
+
Mapbox.accessToken = mapboxToken;
|
|
22
|
+
|
|
23
|
+
return <div style={{ height: '100vh' }}>
|
|
24
|
+
{!mapboxToken && <Center>Add a mapbox token to load this component</Center>}
|
|
25
|
+
{!!mapboxToken && <Map
|
|
26
|
+
antialias
|
|
27
|
+
initialViewState={{
|
|
28
|
+
latitude: 51,
|
|
29
|
+
longitude: 0,
|
|
30
|
+
zoom: 13,
|
|
31
|
+
pitch: 60,
|
|
32
|
+
}}
|
|
33
|
+
mapStyle="mapbox://styles/mapbox/streets-v12"
|
|
34
|
+
>
|
|
35
|
+
<Canvas latitude={51} longitude={0}>
|
|
36
|
+
<hemisphereLight
|
|
37
|
+
args={["#ffffff", "#60666C"]}
|
|
38
|
+
position={[1, 4.5, 3]}
|
|
39
|
+
/>
|
|
40
|
+
<object3D scale={500}>
|
|
41
|
+
<Box position={[-1.2, 1, 0]} />
|
|
42
|
+
<Box position={[1.2, 1, 0]} />
|
|
43
|
+
</object3D>
|
|
44
|
+
</Canvas>
|
|
45
|
+
</Map>}
|
|
46
|
+
</div>
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const Center = ({ children }: PropsWithChildren) => (
|
|
50
|
+
<div style={{
|
|
51
|
+
display: 'flex',
|
|
52
|
+
height: '100%',
|
|
53
|
+
width: '100%',
|
|
54
|
+
alignItems: 'center',
|
|
55
|
+
justifyContent: 'center',
|
|
56
|
+
}}>{children}</div>
|
|
57
|
+
)
|
|
58
|
+
|
|
59
|
+
const Box: FC<{ position: Vector3 }> = (props) => {
|
|
60
|
+
// This reference gives us direct access to the THREE.Mesh object
|
|
61
|
+
const ref = useRef<Mesh>(null)
|
|
62
|
+
// Hold state for hovered and clicked events
|
|
63
|
+
const [hovered, hover] = useState(false)
|
|
64
|
+
const [clicked, click] = useState(false)
|
|
65
|
+
// Subscribe this component to the render-loop, rotate the mesh every frame
|
|
66
|
+
useFrame((_state, delta) => {
|
|
67
|
+
if (!ref.current) return;
|
|
68
|
+
ref.current.rotation.x += delta;
|
|
69
|
+
ref.current.rotation.z -= delta;
|
|
70
|
+
})
|
|
71
|
+
// Return the view, these are regular Threejs elements expressed in JSX
|
|
72
|
+
return (
|
|
73
|
+
<mesh
|
|
74
|
+
{...props}
|
|
75
|
+
ref={ref}
|
|
76
|
+
scale={clicked ? 1.5 : 1}
|
|
77
|
+
onClick={() => click(!clicked)}
|
|
78
|
+
onPointerOver={() => hover(true)}
|
|
79
|
+
onPointerOut={() => hover(false)}>
|
|
80
|
+
<boxGeometry args={[1, 1, 1]} />
|
|
81
|
+
<meshStandardMaterial color={hovered ? 'hotpink' : 'orange'} />
|
|
82
|
+
</mesh>
|
|
83
|
+
)
|
|
84
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { ThemeState, useLadleContext } from '@ladle/react';
|
|
2
|
+
import MapLibre from "maplibre-gl";
|
|
3
|
+
import 'maplibre-gl/dist/maplibre-gl.css';
|
|
4
|
+
import { FC } from "react";
|
|
5
|
+
import Map from 'react-map-gl/maplibre';
|
|
6
|
+
import { StoryMapProps } from '../story-map';
|
|
7
|
+
import { Canvas } from 'react-three-map/maplibre';
|
|
8
|
+
|
|
9
|
+
/** Maplibre `<Map>` styled for stories */
|
|
10
|
+
export const StoryMaplibre: FC<StoryMapProps> = ({
|
|
11
|
+
latitude, longitude, zoom, pitch, canvas, children
|
|
12
|
+
}) => {
|
|
13
|
+
|
|
14
|
+
const theme = useLadleContext().globalState.theme;
|
|
15
|
+
|
|
16
|
+
const mapStyle = theme === ThemeState.Dark
|
|
17
|
+
? "https://basemaps.cartocdn.com/gl/dark-matter-gl-style/style.json"
|
|
18
|
+
: "https://basemaps.cartocdn.com/gl/positron-gl-style/style.json";
|
|
19
|
+
|
|
20
|
+
return <div style={{ height: '100vh', position: 'relative' }}>
|
|
21
|
+
<Map
|
|
22
|
+
mapLib={MapLibre}
|
|
23
|
+
antialias
|
|
24
|
+
initialViewState={{ latitude, longitude, zoom, pitch, }}
|
|
25
|
+
mapStyle={mapStyle}
|
|
26
|
+
>
|
|
27
|
+
<Canvas latitude={latitude} longitude={longitude} {...canvas}>
|
|
28
|
+
{children}
|
|
29
|
+
</Canvas>
|
|
30
|
+
</Map>
|
|
31
|
+
</div>
|
|
32
|
+
}
|
|
@@ -1,13 +1,38 @@
|
|
|
1
1
|
import { useFrame, Vector3 } from "@react-three/fiber";
|
|
2
2
|
import 'maplibre-gl/dist/maplibre-gl.css';
|
|
3
3
|
import { FC, useRef, useState } from "react";
|
|
4
|
-
import Map from 'react-map-gl';
|
|
4
|
+
import Map from 'react-map-gl/maplibre';
|
|
5
5
|
import { Mesh } from "three";
|
|
6
|
-
import { Canvas } from "
|
|
7
|
-
import MapLibre from "maplibre-gl";
|
|
6
|
+
import { Canvas } from "react-three-map/maplibre";
|
|
8
7
|
|
|
9
8
|
export default {title: 'Canvas'}
|
|
10
9
|
|
|
10
|
+
export function AMaplibreExample() {
|
|
11
|
+
return <div style={{ height: '100vh' }}>
|
|
12
|
+
<Map
|
|
13
|
+
antialias
|
|
14
|
+
initialViewState={{
|
|
15
|
+
latitude: 51,
|
|
16
|
+
longitude: 0,
|
|
17
|
+
zoom: 13,
|
|
18
|
+
pitch: 60,
|
|
19
|
+
}}
|
|
20
|
+
mapStyle="https://basemaps.cartocdn.com/gl/positron-gl-style/style.json"
|
|
21
|
+
>
|
|
22
|
+
<Canvas latitude={51} longitude={0}>
|
|
23
|
+
<hemisphereLight
|
|
24
|
+
args={["#ffffff", "#60666C"]}
|
|
25
|
+
position={[1, 4.5, 3]}
|
|
26
|
+
/>
|
|
27
|
+
<object3D scale={500}>
|
|
28
|
+
<Box position={[-1.2, 1, 0]} />
|
|
29
|
+
<Box position={[1.2, 1, 0]} />
|
|
30
|
+
</object3D>
|
|
31
|
+
</Canvas>
|
|
32
|
+
</Map>
|
|
33
|
+
</div>
|
|
34
|
+
}
|
|
35
|
+
|
|
11
36
|
const Box : FC<{position: Vector3}> = (props) => {
|
|
12
37
|
// This reference gives us direct access to the THREE.Mesh object
|
|
13
38
|
const ref = useRef<Mesh>(null)
|
|
@@ -33,31 +58,4 @@ const Box : FC<{position: Vector3}> = (props) => {
|
|
|
33
58
|
<meshStandardMaterial color={hovered ? 'hotpink' : 'orange'} />
|
|
34
59
|
</mesh>
|
|
35
60
|
)
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export function BasicExample() {
|
|
39
|
-
return <div style={{ height: '100vh' }}>
|
|
40
|
-
<Map
|
|
41
|
-
mapLib={MapLibre}
|
|
42
|
-
antialias
|
|
43
|
-
initialViewState={{
|
|
44
|
-
latitude: 51,
|
|
45
|
-
longitude: 0,
|
|
46
|
-
zoom: 13,
|
|
47
|
-
pitch: 60,
|
|
48
|
-
}}
|
|
49
|
-
mapStyle="https://basemaps.cartocdn.com/gl/positron-gl-style/style.json"
|
|
50
|
-
>
|
|
51
|
-
<Canvas latitude={51} longitude={0}>
|
|
52
|
-
<hemisphereLight
|
|
53
|
-
args={["#ffffff", "#60666C"]}
|
|
54
|
-
position={[1, 4.5, 3]}
|
|
55
|
-
/>
|
|
56
|
-
<object3D scale={500}>
|
|
57
|
-
<Box position={[-1.2, 1, 0]} />
|
|
58
|
-
<Box position={[1.2, 1, 0]} />
|
|
59
|
-
</object3D>
|
|
60
|
-
</Canvas>
|
|
61
|
-
</Map>
|
|
62
|
-
</div>
|
|
63
61
|
}
|