react-three-map 0.3.2 → 0.3.3
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/dist/maplibre/types/core/coords-to-matrix.d.ts +8 -0
- package/dist/maplibre/types/core/create-events.d.ts +3 -0
- package/dist/maplibre/types/core/generic-map.d.ts +47 -0
- package/{src/core/state-ref.ts → dist/maplibre/types/core/state-ref.d.ts} +4 -5
- package/dist/maplibre/types/core/use-canvas.d.ts +13 -0
- package/dist/maplibre/types/core/use-function.d.ts +1 -0
- package/dist/maplibre/types/core/use-on-add.d.ts +8 -0
- package/dist/maplibre/types/core/use-render.d.ts +3 -0
- package/dist/maplibre/types/maplibre/canvas.d.ts +10 -0
- package/dist/maplibre/types/maplibre.index.d.ts +1 -0
- package/dist/types/core/coords-to-matrix.d.ts +8 -0
- package/dist/types/core/create-events.d.ts +3 -0
- package/dist/types/core/generic-map.d.ts +47 -0
- package/dist/types/core/state-ref.d.ts +8 -0
- package/dist/types/core/use-canvas.d.ts +13 -0
- package/dist/types/core/use-function.d.ts +1 -0
- package/dist/types/core/use-on-add.d.ts +8 -0
- package/dist/types/core/use-render.d.ts +3 -0
- package/dist/types/mapbox/canvas.d.ts +10 -0
- package/dist/types/mapbox.index.d.ts +1 -0
- package/maplibre/package.json +1 -1
- package/package.json +4 -3
- package/docs/basic-app.gif +0 -0
- package/example-mapbox/package.json +0 -29
- package/example-mapbox/sandbox.config.json +0 -3
- package/example-mapbox/src/canvas.basic.stories.tsx +0 -84
- package/example-mapbox/src/comparison.stories.tsx +0 -37
- package/example-mapbox/src/html-on-top.stories.tsx +0 -24
- package/example-mapbox/src/my-scene.tsx +0 -89
- package/example-mapbox/src/render-on-demand.stories.tsx +0 -32
- package/example-mapbox/src/story-map.tsx +0 -61
- package/example-mapbox/src/vite-env.d.ts +0 -1
- package/example-mapbox/tsconfig.json +0 -27
- package/example-mapbox/tsconfig.node.json +0 -10
- package/example-mapbox/yarn.lock +0 -4154
- package/example-maplibre/package.json +0 -29
- package/example-maplibre/sandbox.config.json +0 -3
- package/example-maplibre/src/canvas.basic.stories.tsx +0 -61
- package/example-maplibre/src/comparison.stories.tsx +0 -35
- package/example-maplibre/src/html-on-top.stories.tsx +0 -24
- package/example-maplibre/src/my-scene.tsx +0 -89
- package/example-maplibre/src/render-on-demand.stories.tsx +0 -32
- package/example-maplibre/src/story-map.tsx +0 -38
- package/example-maplibre/src/vite-env.d.ts +0 -1
- package/example-maplibre/tsconfig.json +0 -25
- package/example-maplibre/tsconfig.node.json +0 -10
- package/example-maplibre/yarn.lock +0 -4181
- package/src/core/coords-to-matrix.ts +0 -20
- package/src/core/create-events.ts +0 -73
- package/src/core/generic-map.test.ts +0 -2
- package/src/core/generic-map.ts +0 -57
- package/src/core/use-canvas.tsx +0 -31
- package/src/core/use-function.ts +0 -10
- package/src/core/use-on-add.ts +0 -90
- package/src/core/use-render.ts +0 -25
- package/src/mapbox/canvas.tsx +0 -38
- package/src/mapbox/index.ts +0 -1
- package/src/maplibre/canvas.tsx +0 -38
- package/src/maplibre/index.ts +0 -1
- package/src/stories/comparison.stories.tsx +0 -38
- package/src/stories/html-on-top.stories.tsx +0 -21
- package/src/stories/mapbox/story-mapbox.tsx +0 -58
- package/src/stories/mapbox-example.stories.tsx +0 -84
- package/src/stories/maplibre/story-maplibre.tsx +0 -32
- package/src/stories/maplibre-example.stories.tsx +0 -61
- package/src/stories/my-scene.tsx +0 -88
- package/src/stories/render-on-demand.stories.tsx +0 -34
- package/src/stories/story-map.tsx +0 -35
- package/src/vite-env.d.ts +0 -1
- package/tsconfig.json +0 -30
- package/tsconfig.node.json +0 -10
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import { useFrame, Vector3 } from "@react-three/fiber";
|
|
2
|
-
import 'maplibre-gl/dist/maplibre-gl.css';
|
|
3
|
-
import { FC, useRef, useState } from "react";
|
|
4
|
-
import Map from 'react-map-gl/maplibre';
|
|
5
|
-
import { Mesh } from "three";
|
|
6
|
-
import { Canvas } from "react-three-map/maplibre";
|
|
7
|
-
|
|
8
|
-
export default {title: 'Canvas'}
|
|
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
|
-
|
|
36
|
-
const Box : FC<{position: Vector3}> = (props) => {
|
|
37
|
-
// This reference gives us direct access to the THREE.Mesh object
|
|
38
|
-
const ref = useRef<Mesh>(null)
|
|
39
|
-
// Hold state for hovered and clicked events
|
|
40
|
-
const [hovered, hover] = useState(false)
|
|
41
|
-
const [clicked, click] = useState(false)
|
|
42
|
-
// Subscribe this component to the render-loop, rotate the mesh every frame
|
|
43
|
-
useFrame((_state, delta) => {
|
|
44
|
-
if(!ref.current) return;
|
|
45
|
-
ref.current.rotation.x += delta;
|
|
46
|
-
ref.current.rotation.z -= delta;
|
|
47
|
-
})
|
|
48
|
-
// Return the view, these are regular Threejs elements expressed in JSX
|
|
49
|
-
return (
|
|
50
|
-
<mesh
|
|
51
|
-
{...props}
|
|
52
|
-
ref={ref}
|
|
53
|
-
scale={clicked ? 1.5 : 1}
|
|
54
|
-
onClick={() => click(!clicked)}
|
|
55
|
-
onPointerOver={() => hover(true)}
|
|
56
|
-
onPointerOut={() => hover(false)}>
|
|
57
|
-
<boxGeometry args={[1, 1, 1]} />
|
|
58
|
-
<meshStandardMaterial color={hovered ? 'hotpink' : 'orange'} />
|
|
59
|
-
</mesh>
|
|
60
|
-
)
|
|
61
|
-
}
|
package/src/stories/my-scene.tsx
DELETED
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
import { Box, Plane, useHelper } from "@react-three/drei";
|
|
2
|
-
import { MeshProps, useFrame, useThree } from '@react-three/fiber';
|
|
3
|
-
import { useCallback, useRef, useState } from 'react';
|
|
4
|
-
import { CameraHelper, MathUtils, Mesh, OrthographicCamera } from "three";
|
|
5
|
-
|
|
6
|
-
export function MyScene({ showCamHelper }: { showCamHelper?: boolean }) {
|
|
7
|
-
return <>
|
|
8
|
-
<Lights showCamHelper={showCamHelper} />
|
|
9
|
-
<Floor />
|
|
10
|
-
<MyBox position={[-8 * 3, 8 * 1.5, 0]} />
|
|
11
|
-
<MyBox position={[8 * 3, 8 * 1.5, 0]} />
|
|
12
|
-
</>
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
function MyBox(props: MeshProps) {
|
|
17
|
-
const [hovered, hover] = useState(false);
|
|
18
|
-
const mesh = useRef<Mesh>(null)
|
|
19
|
-
const invalidate = useThree(st => st.invalidate);
|
|
20
|
-
|
|
21
|
-
const onOver = useCallback(() => {
|
|
22
|
-
hover(true);
|
|
23
|
-
}, [])
|
|
24
|
-
|
|
25
|
-
const onOut = useCallback(() => {
|
|
26
|
-
hover(false);
|
|
27
|
-
}, [])
|
|
28
|
-
|
|
29
|
-
useFrame((_st, dt) => {
|
|
30
|
-
if (!mesh.current) return;
|
|
31
|
-
mesh.current.rotateY(dt);
|
|
32
|
-
invalidate();
|
|
33
|
-
})
|
|
34
|
-
|
|
35
|
-
return (
|
|
36
|
-
<Box
|
|
37
|
-
{...props}
|
|
38
|
-
ref={mesh}
|
|
39
|
-
args={[16, 16, 16]}
|
|
40
|
-
receiveShadow
|
|
41
|
-
castShadow
|
|
42
|
-
onClick={onOver}
|
|
43
|
-
onPointerOver={onOver}
|
|
44
|
-
onPointerOut={onOut}
|
|
45
|
-
>
|
|
46
|
-
<meshStandardMaterial
|
|
47
|
-
color={hovered ? "red" : "orange"}
|
|
48
|
-
metalness={.75}
|
|
49
|
-
roughness={.5}
|
|
50
|
-
/>
|
|
51
|
-
</Box>
|
|
52
|
-
);
|
|
53
|
-
}
|
|
54
|
-
function Lights({ showCamHelper }: { showCamHelper?: boolean }) {
|
|
55
|
-
const cam = useRef<OrthographicCamera>(null);
|
|
56
|
-
const noCam = useRef<OrthographicCamera>(null);
|
|
57
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
58
|
-
useHelper((showCamHelper ? cam : noCam) as any, CameraHelper)
|
|
59
|
-
const camSize = 100;
|
|
60
|
-
return <>
|
|
61
|
-
<ambientLight intensity={0.5} />
|
|
62
|
-
<directionalLight
|
|
63
|
-
castShadow
|
|
64
|
-
position={[2.5, 50, 5]}
|
|
65
|
-
intensity={1.5}
|
|
66
|
-
shadow-mapSize={1024}
|
|
67
|
-
>
|
|
68
|
-
<orthographicCamera
|
|
69
|
-
ref={cam}
|
|
70
|
-
attach="shadow-camera"
|
|
71
|
-
args={[-camSize, camSize, -camSize, camSize, 0.1, 100]}
|
|
72
|
-
/>
|
|
73
|
-
</directionalLight>
|
|
74
|
-
<pointLight position={[-10, 0, -20]} color="white" intensity={1} />
|
|
75
|
-
<pointLight position={[0, -10, 0]} intensity={1} />
|
|
76
|
-
</>
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
function Floor() {
|
|
80
|
-
return <Plane
|
|
81
|
-
args={[200, 200]}
|
|
82
|
-
position={[0, 0, 0]}
|
|
83
|
-
rotation={[-90 * MathUtils.DEG2RAD, 0, 0]}
|
|
84
|
-
receiveShadow
|
|
85
|
-
>
|
|
86
|
-
<shadowMaterial opacity={.5} />
|
|
87
|
-
</Plane>
|
|
88
|
-
}
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { Box, Stats } from "@react-three/drei";
|
|
2
|
-
import { useRef, useState } from "react";
|
|
3
|
-
import { MathUtils } from "three";
|
|
4
|
-
import { StoryMap } from "./story-map";
|
|
5
|
-
|
|
6
|
-
export function Default() {
|
|
7
|
-
|
|
8
|
-
const [hovered, hover] = useState(false);
|
|
9
|
-
|
|
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' }}>
|
|
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.
|
|
32
|
-
</div>
|
|
33
|
-
</div>
|
|
34
|
-
}
|
|
@@ -1,35 +0,0 @@
|
|
|
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
|
-
}
|
|
11
|
-
|
|
12
|
-
export interface StoryMapProps extends PropsWithChildren {
|
|
13
|
-
latitude: number,
|
|
14
|
-
longitude: number,
|
|
15
|
-
zoom?: number,
|
|
16
|
-
pitch?: number,
|
|
17
|
-
canvas?: Partial<CanvasProps>,
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
/** `<Map>` styled for stories */
|
|
21
|
-
export const StoryMap: FC<StoryMapProps> = (props) => {
|
|
22
|
-
|
|
23
|
-
const { mapProvider } = useControls({
|
|
24
|
-
mapProvider: {
|
|
25
|
-
value: MapProvider.maplibre,
|
|
26
|
-
options: MapProvider,
|
|
27
|
-
label: 'map provider'
|
|
28
|
-
},
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
return <div style={{ height: '100vh', position: 'relative' }}>
|
|
32
|
-
{mapProvider === MapProvider.maplibre && <StoryMaplibre {...props} />}
|
|
33
|
-
{mapProvider === MapProvider.mapbox && <StoryMapbox {...props} />}
|
|
34
|
-
</div>
|
|
35
|
-
}
|
package/src/vite-env.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
/// <reference types="vite/client" />
|
package/tsconfig.json
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
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": "bundler",
|
|
11
|
-
"allowImportingTsExtensions": true,
|
|
12
|
-
"resolveJsonModule": true,
|
|
13
|
-
"isolatedModules": true,
|
|
14
|
-
"noEmit": true,
|
|
15
|
-
"jsx": "react-jsx",
|
|
16
|
-
|
|
17
|
-
"paths": {
|
|
18
|
-
"react-three-map": ["./src/mapbox/index.ts"],
|
|
19
|
-
"react-three-map/maplibre": ["./src/maplibre/index.ts"],
|
|
20
|
-
},
|
|
21
|
-
|
|
22
|
-
/* Linting */
|
|
23
|
-
"strict": true,
|
|
24
|
-
"noUnusedLocals": true,
|
|
25
|
-
"noUnusedParameters": true,
|
|
26
|
-
"noFallthroughCasesInSwitch": true
|
|
27
|
-
},
|
|
28
|
-
"include": ["src"],
|
|
29
|
-
"references": [{ "path": "./tsconfig.node.json" }]
|
|
30
|
-
}
|