react-three-map 0.2.1 → 0.3.0
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 +6 -0
- package/README.md +14 -13
- package/dist/cjs/main.js.js +1 -1318
- package/dist/es/main.js2.mjs +24 -20
- package/dist/es/main.js2.mjs.map +1 -1
- package/dist/es/main.js3.mjs.map +1 -1
- package/dist/es/main.js4.mjs +12 -24
- package/dist/es/main.js4.mjs.map +1 -1
- package/dist/es/main.js5.mjs +55 -23532
- package/dist/es/main.js5.mjs.map +1 -1
- package/dist/es/main.js6.mjs +13 -2
- package/dist/es/main.js6.mjs.map +1 -1
- package/dist/es/main.js7.mjs +53 -2
- package/dist/es/main.js7.mjs.map +1 -1
- package/dist/es/main.js8.mjs +6 -57
- package/dist/es/main.js8.mjs.map +1 -1
- package/dist/maplibre/cjs/main.js.js +1 -1
- package/dist/maplibre/es/main.js2.mjs +24 -20
- package/dist/maplibre/es/main.js2.mjs.map +1 -1
- package/dist/maplibre/es/main.js3.mjs.map +1 -1
- package/dist/maplibre/es/main.js4.mjs +12 -24
- package/dist/maplibre/es/main.js4.mjs.map +1 -1
- package/dist/maplibre/es/main.js5.mjs.map +1 -1
- package/dist/maplibre/es/main.js6.mjs.map +1 -1
- package/dist/maplibre/es/main.js7.mjs.map +1 -1
- package/dist/maplibre/es/main.js8.mjs.map +1 -1
- package/example-mapbox/package.json +29 -0
- package/example-mapbox/sandbox.config.json +3 -0
- package/example-mapbox/src/canvas.basic.stories.tsx +69 -0
- package/example-mapbox/src/comparison.stories.tsx +24 -0
- package/example-mapbox/src/html-on-top.stories.tsx +24 -0
- package/example-mapbox/src/my-scene.tsx +96 -0
- package/example-mapbox/src/render-on-demand.stories.tsx +32 -0
- package/example-mapbox/src/story-map.tsx +46 -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 +22 -0
- package/example-maplibre/src/html-on-top.stories.tsx +24 -0
- package/example-maplibre/src/my-scene.tsx +97 -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 +1 -1
- package/package.json +9 -6
- 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 +13 -30
- package/src/stories/html-on-top.stories.tsx +11 -16
- package/src/stories/mapbox/story-mapbox.tsx +43 -0
- package/src/stories/mapbox-example.stories.tsx +69 -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 +0 -1
- package/src/stories/render-on-demand.stories.tsx +18 -37
- package/src/stories/story-map.tsx +26 -24
- package/tsconfig.json +5 -0
- package/dist/es/main.js10.mjs +0 -56
- package/dist/es/main.js10.mjs.map +0 -1
- package/dist/es/main.js11.mjs +0 -9
- package/dist/es/main.js11.mjs.map +0 -1
- package/dist/es/main.js9.mjs +0 -16
- package/dist/es/main.js9.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
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { Box, Plane, useHelper } from "@react-three/drei";
|
|
2
|
+
import { MeshProps, useFrame, useThree } from '@react-three/fiber';
|
|
3
|
+
import { useControls } from "leva";
|
|
4
|
+
import { useCallback, useRef, useState } from 'react';
|
|
5
|
+
import { CameraHelper, MathUtils, Mesh, OrthographicCamera } from "three";
|
|
6
|
+
|
|
7
|
+
export function MyScene() {
|
|
8
|
+
return <>
|
|
9
|
+
<Lights />
|
|
10
|
+
<Floor />
|
|
11
|
+
<MyBox position={[-8 * 3, 8 * 1.5, 0]} />
|
|
12
|
+
<MyBox position={[8 * 3, 8 * 1.5, 0]} />
|
|
13
|
+
</>
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
function MyBox(props: MeshProps) {
|
|
18
|
+
const [hovered, hover] = useState(false);
|
|
19
|
+
const mesh = useRef<Mesh>(null)
|
|
20
|
+
const invalidate = useThree(st => st.invalidate);
|
|
21
|
+
|
|
22
|
+
const onOver = useCallback(() => {
|
|
23
|
+
hover(true);
|
|
24
|
+
}, [])
|
|
25
|
+
|
|
26
|
+
const onOut = useCallback(() => {
|
|
27
|
+
hover(false);
|
|
28
|
+
}, [])
|
|
29
|
+
|
|
30
|
+
useFrame((_st, dt) => {
|
|
31
|
+
if (!mesh.current) return;
|
|
32
|
+
mesh.current.rotateY(dt);
|
|
33
|
+
invalidate();
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
return (
|
|
37
|
+
<Box
|
|
38
|
+
{...props}
|
|
39
|
+
ref={mesh}
|
|
40
|
+
args={[16, 16, 16]}
|
|
41
|
+
receiveShadow
|
|
42
|
+
castShadow
|
|
43
|
+
onClick={onOver}
|
|
44
|
+
onPointerOver={onOver}
|
|
45
|
+
onPointerOut={onOut}
|
|
46
|
+
>
|
|
47
|
+
<meshStandardMaterial
|
|
48
|
+
color={hovered ? "red" : "orange"}
|
|
49
|
+
metalness={.75}
|
|
50
|
+
roughness={.5}
|
|
51
|
+
/>
|
|
52
|
+
</Box>
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
function Lights() {
|
|
56
|
+
const cam = useRef<OrthographicCamera>(null);
|
|
57
|
+
const noCam = useRef<OrthographicCamera>(null);
|
|
58
|
+
const { showCamHelper } = useControls({
|
|
59
|
+
showCamHelper: {
|
|
60
|
+
value: false,
|
|
61
|
+
label: 'show camera helper'
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
65
|
+
useHelper((showCamHelper ? cam : noCam) as any, CameraHelper)
|
|
66
|
+
const camSize = 100;
|
|
67
|
+
return <>
|
|
68
|
+
<ambientLight intensity={0.5} />
|
|
69
|
+
<directionalLight
|
|
70
|
+
castShadow
|
|
71
|
+
position={[2.5, 50, 5]}
|
|
72
|
+
intensity={1.5}
|
|
73
|
+
shadow-mapSize={1024}
|
|
74
|
+
>
|
|
75
|
+
<orthographicCamera
|
|
76
|
+
ref={cam}
|
|
77
|
+
attach="shadow-camera"
|
|
78
|
+
args={[-camSize, camSize, -camSize, camSize, 0.1, 100]}
|
|
79
|
+
rotation={[0, 90 * MathUtils.DEG2RAD, 0]}
|
|
80
|
+
/>
|
|
81
|
+
</directionalLight>
|
|
82
|
+
<pointLight position={[-10, 0, -20]} color="white" intensity={1} />
|
|
83
|
+
<pointLight position={[0, -10, 0]} intensity={1} />
|
|
84
|
+
</>
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function Floor() {
|
|
88
|
+
return <Plane
|
|
89
|
+
args={[200, 200]}
|
|
90
|
+
position={[0, 0, 0]}
|
|
91
|
+
rotation={[-90 * MathUtils.DEG2RAD, 0, 0]}
|
|
92
|
+
receiveShadow
|
|
93
|
+
>
|
|
94
|
+
<shadowMaterial opacity={.5} />
|
|
95
|
+
</Plane>
|
|
96
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Box, Stats } from "@react-three/drei";
|
|
2
|
+
import { useRef, useState } from "react";
|
|
3
|
+
import { Canvas } from "react-three-map";
|
|
4
|
+
import { MathUtils } from "three";
|
|
5
|
+
import { StoryMap } from "./story-map";
|
|
6
|
+
|
|
7
|
+
export function Default() {
|
|
8
|
+
|
|
9
|
+
const [hovered, hover] = useState(false);
|
|
10
|
+
|
|
11
|
+
const ref = useRef<HTMLDivElement>(null)
|
|
12
|
+
|
|
13
|
+
return <div style={{ height: '100vh', position: 'relative' }}>
|
|
14
|
+
<style>{`.stats{position:absolute !important}`}</style>
|
|
15
|
+
<StoryMap latitude={51} longitude={0} zoom={13}>
|
|
16
|
+
<Canvas latitude={51} longitude={0} frameloop="demand">
|
|
17
|
+
<Box
|
|
18
|
+
args={[500, 500, 500]}
|
|
19
|
+
position={[0, 250, 0]}
|
|
20
|
+
rotation={[0, 45 * MathUtils.DEG2RAD, 0]}
|
|
21
|
+
onPointerOver={() => hover(true)}
|
|
22
|
+
onPointerOut={() => hover(false)}
|
|
23
|
+
material-color={hovered ? 'purple' : 'orange'}
|
|
24
|
+
/>
|
|
25
|
+
<Stats className="stats" parent={ref} />
|
|
26
|
+
</Canvas>
|
|
27
|
+
</StoryMap>
|
|
28
|
+
<div style={{ position: 'absolute', top: 0, right: 0, left: 80, background: '#ffffffc2', padding: 5 }}>
|
|
29
|
+
Hover over the box, it will only render once to change colour, or when you move the camera. Look at the stats to confirm.
|
|
30
|
+
</div>
|
|
31
|
+
</div>
|
|
32
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
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
|
+
|
|
8
|
+
export interface StoryMapProps extends PropsWithChildren {
|
|
9
|
+
latitude: number,
|
|
10
|
+
longitude: number,
|
|
11
|
+
zoom?: number,
|
|
12
|
+
pitch?: number,
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/** `<Map>` styled for stories */
|
|
16
|
+
export const StoryMap: FC<StoryMapProps> = ({
|
|
17
|
+
latitude, longitude, zoom = 18, pitch = 60, children
|
|
18
|
+
}) => {
|
|
19
|
+
|
|
20
|
+
const { mapboxToken } = useControls({ mapboxToken: import.meta.env.VITE_MAPBOX_TOKEN || '' })
|
|
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 && <>Add a mapbox token to load this component</>}
|
|
32
|
+
{mapboxToken && <Map
|
|
33
|
+
antialias
|
|
34
|
+
initialViewState={{
|
|
35
|
+
latitude,
|
|
36
|
+
longitude,
|
|
37
|
+
zoom,
|
|
38
|
+
pitch,
|
|
39
|
+
}}
|
|
40
|
+
mapStyle={mapStyle}
|
|
41
|
+
mapboxAccessToken={mapboxToken}
|
|
42
|
+
>
|
|
43
|
+
{children}
|
|
44
|
+
</Map>}
|
|
45
|
+
</div>
|
|
46
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
/// <reference types="vite/client" />
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2020",
|
|
4
|
+
"useDefineForClassFields": true,
|
|
5
|
+
"lib": ["ES2020", "DOM", "DOM.Iterable"],
|
|
6
|
+
"module": "ESNext",
|
|
7
|
+
"skipLibCheck": true,
|
|
8
|
+
|
|
9
|
+
/* Bundler mode */
|
|
10
|
+
"moduleResolution": "Node",
|
|
11
|
+
"allowImportingTsExtensions": true,
|
|
12
|
+
"resolveJsonModule": true,
|
|
13
|
+
"isolatedModules": true,
|
|
14
|
+
"noEmit": true,
|
|
15
|
+
"jsx": "react-jsx",
|
|
16
|
+
|
|
17
|
+
/* Linting */
|
|
18
|
+
"strict": true,
|
|
19
|
+
"noUnusedLocals": true,
|
|
20
|
+
"noUnusedParameters": true,
|
|
21
|
+
"noFallthroughCasesInSwitch": true,
|
|
22
|
+
|
|
23
|
+
"allowSyntheticDefaultImports": true
|
|
24
|
+
},
|
|
25
|
+
"include": ["src"],
|
|
26
|
+
"references": [{ "path": "./tsconfig.node.json" }]
|
|
27
|
+
}
|