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/src/stories/my-scene.tsx
CHANGED
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
import { Box, Plane, useHelper } from "@react-three/drei";
|
|
2
2
|
import { MeshProps, useFrame, useThree } from '@react-three/fiber';
|
|
3
|
-
import { useControls } from "leva";
|
|
4
|
-
import 'maplibre-gl/dist/maplibre-gl.css';
|
|
5
3
|
import { useCallback, useRef, useState } from 'react';
|
|
6
4
|
import { CameraHelper, MathUtils, Mesh, OrthographicCamera } from "three";
|
|
7
5
|
|
|
8
|
-
export function MyScene() {
|
|
6
|
+
export function MyScene({ showCamHelper }: { showCamHelper?: boolean }) {
|
|
9
7
|
return <>
|
|
10
|
-
<Lights />
|
|
8
|
+
<Lights showCamHelper={showCamHelper} />
|
|
11
9
|
<Floor />
|
|
12
10
|
<MyBox position={[-8 * 3, 8 * 1.5, 0]} />
|
|
13
11
|
<MyBox position={[8 * 3, 8 * 1.5, 0]} />
|
|
@@ -53,15 +51,9 @@ function MyBox(props: MeshProps) {
|
|
|
53
51
|
</Box>
|
|
54
52
|
);
|
|
55
53
|
}
|
|
56
|
-
function Lights() {
|
|
54
|
+
function Lights({ showCamHelper }: { showCamHelper?: boolean }) {
|
|
57
55
|
const cam = useRef<OrthographicCamera>(null);
|
|
58
56
|
const noCam = useRef<OrthographicCamera>(null);
|
|
59
|
-
const { showCamHelper } = useControls({
|
|
60
|
-
showCamHelper: {
|
|
61
|
-
value: false,
|
|
62
|
-
label: 'show camera helper'
|
|
63
|
-
}
|
|
64
|
-
});
|
|
65
57
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
66
58
|
useHelper((showCamHelper ? cam : noCam) as any, CameraHelper)
|
|
67
59
|
const camSize = 100;
|
|
@@ -77,7 +69,6 @@ function Lights() {
|
|
|
77
69
|
ref={cam}
|
|
78
70
|
attach="shadow-camera"
|
|
79
71
|
args={[-camSize, camSize, -camSize, camSize, 0.1, 100]}
|
|
80
|
-
rotation={[0, 90 * MathUtils.DEG2RAD, 0]}
|
|
81
72
|
/>
|
|
82
73
|
</directionalLight>
|
|
83
74
|
<pointLight position={[-10, 0, -20]} color="white" intensity={1} />
|
|
@@ -1,47 +1,33 @@
|
|
|
1
|
-
import { ThemeState, useLadleContext } from "@ladle/react";
|
|
2
1
|
import { Box, Stats } from "@react-three/drei";
|
|
3
|
-
import
|
|
4
|
-
import { useState } from "react";
|
|
5
|
-
import Map from 'react-map-gl';
|
|
2
|
+
import { useRef, useState } from "react";
|
|
6
3
|
import { MathUtils } from "three";
|
|
7
|
-
import {
|
|
8
|
-
import MapLibre from "maplibre-gl";
|
|
4
|
+
import { StoryMap } from "./story-map";
|
|
9
5
|
|
|
10
6
|
export function Default() {
|
|
11
7
|
|
|
12
|
-
const theme = useLadleContext().globalState.theme;
|
|
13
|
-
|
|
14
|
-
const mapStyle = theme === ThemeState.Dark
|
|
15
|
-
? "https://basemaps.cartocdn.com/gl/dark-matter-gl-style/style.json"
|
|
16
|
-
: "https://basemaps.cartocdn.com/gl/positron-gl-style/style.json";
|
|
17
|
-
|
|
18
8
|
const [hovered, hover] = useState(false);
|
|
19
9
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
<Stats />
|
|
42
|
-
</Canvas>
|
|
43
|
-
</Map>
|
|
44
|
-
<div style={{ position: 'absolute', top: 0, right: 0, left: 80, background: '#ffffffc2', padding: 5 }}>
|
|
10
|
+
const ref = useRef<HTMLDivElement>(null)
|
|
11
|
+
|
|
12
|
+
return <div ref={ref} style={{ height: '100vh', position: 'relative' }}>
|
|
13
|
+
<style>{`.stats{position:absolute !important}`}</style>
|
|
14
|
+
<StoryMap
|
|
15
|
+
latitude={51}
|
|
16
|
+
longitude={0}
|
|
17
|
+
zoom={13}
|
|
18
|
+
pitch={60}
|
|
19
|
+
canvas={{ frameloop: 'demand' }}>
|
|
20
|
+
<Box
|
|
21
|
+
args={[500, 500, 500]}
|
|
22
|
+
position={[0, 250, 0]}
|
|
23
|
+
rotation={[0, 45 * MathUtils.DEG2RAD, 0]}
|
|
24
|
+
onPointerOver={() => hover(true)}
|
|
25
|
+
onPointerOut={() => hover(false)}
|
|
26
|
+
material-color={hovered ? 'purple' : 'orange'}
|
|
27
|
+
/>
|
|
28
|
+
<Stats className="stats" parent={ref} />
|
|
29
|
+
</StoryMap>
|
|
30
|
+
<div style={{ position: 'absolute', bottom: 0, right: 0, left: 0, background: '#ffffffc2', padding: '15px 20px 40px' }}>
|
|
45
31
|
Hover over the box, it will only render once to change colour, or when you move the camera. Look at the stats to confirm.
|
|
46
32
|
</div>
|
|
47
33
|
</div>
|
|
@@ -1,40 +1,35 @@
|
|
|
1
|
-
import '
|
|
2
|
-
import { FC, PropsWithChildren } from "react"
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import {
|
|
1
|
+
import { useControls } from 'leva';
|
|
2
|
+
import { FC, PropsWithChildren } from "react";
|
|
3
|
+
import { StoryMapbox } from './mapbox/story-mapbox';
|
|
4
|
+
import { StoryMaplibre } from './maplibre/story-maplibre';
|
|
5
|
+
import { CanvasProps } from '../maplibre/canvas';
|
|
6
|
+
|
|
7
|
+
export enum MapProvider {
|
|
8
|
+
maplibre = "maplibre",
|
|
9
|
+
mapbox = "mapbox",
|
|
10
|
+
}
|
|
6
11
|
|
|
7
12
|
export interface StoryMapProps extends PropsWithChildren {
|
|
8
|
-
latitude
|
|
9
|
-
longitude
|
|
13
|
+
latitude: number,
|
|
14
|
+
longitude: number,
|
|
10
15
|
zoom?: number,
|
|
11
16
|
pitch?: number,
|
|
17
|
+
canvas?: Partial<CanvasProps>,
|
|
12
18
|
}
|
|
13
19
|
|
|
14
20
|
/** `<Map>` styled for stories */
|
|
15
|
-
export const StoryMap: FC<StoryMapProps> = ({
|
|
16
|
-
children
|
|
17
|
-
}) => {
|
|
18
|
-
|
|
19
|
-
const theme = useLadleContext().globalState.theme;
|
|
21
|
+
export const StoryMap: FC<StoryMapProps> = (props) => {
|
|
20
22
|
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
|
|
23
|
+
const { mapProvider } = useControls({
|
|
24
|
+
mapProvider: {
|
|
25
|
+
value: MapProvider.maplibre,
|
|
26
|
+
options: MapProvider,
|
|
27
|
+
label: 'map provider'
|
|
28
|
+
},
|
|
29
|
+
});
|
|
24
30
|
|
|
25
31
|
return <div style={{ height: '100vh', position: 'relative' }}>
|
|
26
|
-
<
|
|
27
|
-
|
|
28
|
-
antialias
|
|
29
|
-
initialViewState={{
|
|
30
|
-
latitude: 51,
|
|
31
|
-
longitude: 0,
|
|
32
|
-
zoom: 13,
|
|
33
|
-
pitch: 60,
|
|
34
|
-
}}
|
|
35
|
-
mapStyle={mapStyle}
|
|
36
|
-
>
|
|
37
|
-
{children}
|
|
38
|
-
</Map>
|
|
32
|
+
{mapProvider === MapProvider.maplibre && <StoryMaplibre {...props} />}
|
|
33
|
+
{mapProvider === MapProvider.mapbox && <StoryMapbox {...props} />}
|
|
39
34
|
</div>
|
|
40
35
|
}
|
package/tsconfig.json
CHANGED