react-three-map 0.1.5 → 0.2.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 +15 -0
- package/README.md +105 -48
- package/dist/cjs/main.js.js +1318 -1
- package/dist/es/main.js10.mjs +56 -0
- package/dist/es/main.js10.mjs.map +1 -0
- package/dist/es/main.js11.mjs +9 -0
- package/dist/es/main.js11.mjs.map +1 -0
- package/dist/es/main.js2.mjs +23 -28
- package/dist/es/main.js2.mjs.map +1 -1
- package/dist/es/main.js3.mjs +6 -7
- package/dist/es/main.js3.mjs.map +1 -1
- package/dist/es/main.js4.mjs +28 -56
- package/dist/es/main.js4.mjs.map +1 -1
- package/dist/es/main.js5.mjs +23533 -12
- package/dist/es/main.js5.mjs.map +1 -1
- package/dist/es/main.js6.mjs +2 -53
- package/dist/es/main.js6.mjs.map +1 -1
- package/dist/es/main.js7.mjs +2 -6
- package/dist/es/main.js7.mjs.map +1 -1
- package/dist/es/main.js8.mjs +60 -0
- package/dist/es/main.js8.mjs.map +1 -0
- package/dist/es/main.js9.mjs +16 -0
- package/dist/es/main.js9.mjs.map +1 -0
- package/dist/maplibre/cjs/main.js.js +1 -0
- package/dist/maplibre/es/main.js.mjs +5 -0
- package/dist/maplibre/es/main.js.mjs.map +1 -0
- package/dist/maplibre/es/main.js2.mjs +34 -0
- package/dist/maplibre/es/main.js2.mjs.map +1 -0
- package/dist/maplibre/es/main.js3.mjs +10 -0
- package/dist/maplibre/es/main.js3.mjs.map +1 -0
- package/dist/maplibre/es/main.js4.mjs +31 -0
- package/dist/maplibre/es/main.js4.mjs.map +1 -0
- package/dist/maplibre/es/main.js5.mjs +60 -0
- package/dist/maplibre/es/main.js5.mjs.map +1 -0
- package/dist/maplibre/es/main.js6.mjs +16 -0
- package/dist/maplibre/es/main.js6.mjs.map +1 -0
- package/dist/maplibre/es/main.js7.mjs +56 -0
- package/dist/maplibre/es/main.js7.mjs.map +1 -0
- package/dist/maplibre/es/main.js8.mjs +9 -0
- package/dist/maplibre/es/main.js8.mjs.map +1 -0
- package/docs/basic-app.gif +0 -0
- package/maplibre/package.json +7 -0
- package/package.json +12 -5
- package/src/canvas/canvas-mapbox.tsx +32 -0
- package/src/canvas/canvas-maplibre.tsx +32 -0
- package/src/canvas/core/coords-to-matrix.ts +20 -0
- package/src/canvas/{create-events.ts → core/create-events.ts} +2 -2
- package/src/canvas/core/generic-map.test.ts +2 -0
- package/src/canvas/core/generic-map.ts +44 -0
- package/src/canvas/core/internal-canvas.tsx +43 -0
- package/src/canvas/{state-ref.ts → core/state-ref.ts} +2 -2
- package/src/canvas/{use-on-add.ts → core/use-on-add.ts} +30 -18
- package/src/canvas/core/use-render.ts +25 -0
- package/src/main-mapbox.ts +1 -0
- package/src/main-maplibre.ts +1 -0
- package/src/stories/canvas.basic.stories.tsx +63 -0
- package/src/stories/{canvas.stories.tsx → comparison.stories.tsx} +6 -4
- package/src/stories/html-on-top.stories.tsx +26 -0
- package/src/stories/my-scene.tsx +18 -11
- package/src/stories/render-on-demand.stories.tsx +9 -7
- package/src/stories/story-map.tsx +40 -0
- package/dist/cjs/vite.svg +0 -1
- package/dist/es/vite.svg +0 -1
- package/index.html +0 -13
- package/src/canvas/canvas.tsx +0 -49
- package/src/canvas/coords-to-matrix.ts +0 -19
- package/src/canvas/use-render.ts +0 -29
- package/src/main.ts +0 -1
- /package/src/canvas/{use-function.ts → core/use-function.ts} +0 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# react-three-map
|
|
2
|
+
|
|
3
|
+
## 0.2.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- b210a12: Support to render `react-three-map` on demand via `<Canvas frameloop="ondemand">`
|
|
8
|
+
- 557920a: Add Mapbox support.
|
|
9
|
+
|
|
10
|
+
- If you use **Mapbox** `import { Canvas } from "react-three-map"`
|
|
11
|
+
- If you use **Maplibre** `import { Canvas } from "react-three-map/maplibre"`
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- 83de85c: Fix camera matrix bug where it may have invalid state on start.
|
package/README.md
CHANGED
|
@@ -1,78 +1,135 @@
|
|
|
1
1
|
# React Three Map
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
[](https://npmjs.com/package/@react-three/fiber)
|
|
5
4
|
|
|
6
|
-
React Three Map seamlessly integrates three.js with MapLibre and Mapbox using React, allowing you to bring the power of 3D rendering to your maps in a declarative manner.
|
|
7
5
|
|
|
8
|
-
This
|
|
6
|
+
⚠️ **Alpha Warning: This library is currently in its alpha phase. While functional, it's still under active development and may have bugs. Please use with caution in production and feel free to report any issues you encounter. Thank you for your understanding!**
|
|
9
7
|
|
|
10
|
-
|
|
8
|
+
`react-three-map` is a bridge to use [`react-three-fiber`](https://github.com/pmndrs/react-three-fiber) inside [`react-map-gl`](https://github.com/visgl/react-map-gl).
|
|
11
9
|
|
|
12
|
-
|
|
10
|
+
Until now you had:
|
|
13
11
|
|
|
14
|
-
|
|
12
|
+
| imperative | declarative (react) |
|
|
13
|
+
| --- | --- |
|
|
14
|
+
| Mapbox GL JS | react-map-gl |
|
|
15
|
+
| THREE.js | react-three-fiber |
|
|
15
16
|
|
|
16
|
-
|
|
17
|
+
Now with `react-three-map`, you can use them together :fist_right::fist_left:.
|
|
17
18
|
|
|
18
|
-
```
|
|
19
|
+
```sh
|
|
19
20
|
npm install react-three-map
|
|
20
21
|
```
|
|
21
22
|
|
|
23
|
+
Find use examples in our [Stories :book:](https://rodrigohamuy.github.io/react-three-map).
|
|
24
|
+
|
|
25
|
+
## What does it look like?
|
|
26
|
+
|
|
22
27
|
|
|
23
|
-
|
|
28
|
+
<table>
|
|
29
|
+
<tbody>
|
|
30
|
+
<tr>
|
|
31
|
+
<td>Let's build the same <code>react-three-fiber</code> basic example, but now it can be inside a map. (<a href="https://codesandbox.io/p/sandbox/vigorous-snyder-2n9vpl?file=%2Fsrc%2FApp.tsx%3A48%2C45">live demo</a>).</td>
|
|
32
|
+
<td>
|
|
33
|
+
<a href="https://codesandbox.io/p/sandbox/vigorous-snyder-2n9vpl?file=%2Fsrc%2FApp.tsx%3A48%2C45">
|
|
34
|
+
<img src="docs/basic-app.gif" />
|
|
35
|
+
</a>
|
|
36
|
+
</td>
|
|
37
|
+
</tr>
|
|
38
|
+
</tbody>
|
|
39
|
+
</table>
|
|
24
40
|
|
|
25
|
-
|
|
41
|
+
1. Import `Canvas` from `react-three-map` instead of `@react-three/fiber`.
|
|
42
|
+
2. Give it a latitude and longitude so it knows where to position the scene in the map.
|
|
43
|
+
3. Everything else should work just as usual.
|
|
26
44
|
|
|
27
45
|
```jsx
|
|
28
|
-
import
|
|
29
|
-
import {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
46
|
+
import "maplibre-gl/dist/maplibre-gl.css"
|
|
47
|
+
import { createRoot } from 'react-dom/client'
|
|
48
|
+
import React, { useRef, useState } from 'react'
|
|
49
|
+
import { useFrame } from "@react-three/fiber"
|
|
50
|
+
import { useRef, useState } from "react"
|
|
51
|
+
import Map from "react-map-gl/maplibre"
|
|
52
|
+
import { Canvas } from "react-three-map/maplibre"
|
|
53
|
+
// import { Canvas } from "react-three-map" // if you are using MapBox
|
|
54
|
+
|
|
55
|
+
function BasicExample() {
|
|
56
|
+
return <Map
|
|
57
|
+
antialias
|
|
58
|
+
initialViewState={{
|
|
59
|
+
latitude: 51,
|
|
60
|
+
longitude: 0,
|
|
61
|
+
zoom: 13,
|
|
62
|
+
pitch: 60
|
|
63
|
+
}}
|
|
64
|
+
mapStyle="https://basemaps.cartocdn.com/gl/positron-gl-style/style.json"
|
|
65
|
+
>
|
|
66
|
+
<Canvas latitude={51} longitude={0}>
|
|
67
|
+
<hemisphereLight
|
|
68
|
+
args={["#ffffff", "#60666C"]}
|
|
69
|
+
position={[1, 4.5, 3]}
|
|
70
|
+
/>
|
|
71
|
+
<object3D scale={500}>
|
|
72
|
+
<Box position={[-1.2, 1, 0]} />
|
|
73
|
+
<Box position={[1.2, 1, 0]} />
|
|
74
|
+
</object3D>
|
|
75
|
+
</Canvas>
|
|
76
|
+
</Map>
|
|
77
|
+
}
|
|
43
78
|
```
|
|
44
79
|
|
|
45
|
-
|
|
80
|
+
# Why we build this?
|
|
46
81
|
|
|
47
|
-
|
|
82
|
+
Look [how complex](https://maplibre.org/maplibre-gl-js-docs/example/add-3d-model/) is to add just one ThreeJS object to a map.
|
|
48
83
|
|
|
49
|
-
|
|
84
|
+
Look [how complex](https://docs.pmnd.rs/react-three-fiber/api/canvas#createroot) is to create your custom root for R3F.
|
|
50
85
|
|
|
51
|
-
|
|
86
|
+
You can now replace all that complexity and hundreds of lines of code with the `<Canvas>` component exported by `react-three-map`, which includes a tone of extra features and seamless integration, supporting pointer events, raycasting, and much more, all out of the box.
|
|
52
87
|
|
|
53
|
-
##
|
|
88
|
+
## API
|
|
54
89
|
|
|
55
|
-
|
|
90
|
+
### Canvas
|
|
91
|
+
|
|
92
|
+
Same as in `@react-three/fiber`, the `<Canvas>` object is where you start to define your React Three Fiber Scene.
|
|
93
|
+
|
|
94
|
+
```tsx
|
|
95
|
+
import "maplibre-gl/dist/maplibre-gl.css"
|
|
96
|
+
import Map from "react-map-gl/maplibre"
|
|
97
|
+
import { Canvas } from 'react-three-map/maplibre'
|
|
98
|
+
// import { Canvas } from "react-three-map" // if you are using MapBox
|
|
99
|
+
|
|
100
|
+
const App = () => (
|
|
101
|
+
<Map
|
|
102
|
+
initialViewState={{ latitude: 51, longitude: 0, zoom: 13 }}
|
|
103
|
+
mapStyle="https://basemaps.cartocdn.com/gl/positron-gl-style/style.json" >
|
|
104
|
+
<Canvas latitude={51} longitude={0}>
|
|
105
|
+
<pointLight position={[10, 10, 10]} />
|
|
106
|
+
<mesh>
|
|
107
|
+
<sphereGeometry />
|
|
108
|
+
<meshStandardMaterial color="hotpink" />
|
|
109
|
+
</mesh>
|
|
110
|
+
</Canvas>
|
|
111
|
+
</Map>
|
|
112
|
+
)
|
|
113
|
+
```
|
|
56
114
|
|
|
57
|
-
|
|
115
|
+
It shares most of the props from R3F `<Canvas>`, so you can check them directly in the [`@react-three/fiber` docs](https://docs.pmnd.rs/react-three-fiber/api/canvas). There are a few important exceptions though, which are mentioned bellow.
|
|
58
116
|
|
|
59
|
-
|
|
117
|
+
#### Render Props
|
|
60
118
|
|
|
61
|
-
|
|
119
|
+
| PROP | DESCRIPTION | DEFAULT |
|
|
120
|
+
| --------- | ------------------------------------------------ | -------- |
|
|
121
|
+
| latitude | The latitude coordinate where to add the scene. | |
|
|
122
|
+
| longitude | The longitude coordinate where to add the scene. | |
|
|
123
|
+
| altitude | The altitude coordinate where to add the scene. | `0` |
|
|
124
|
+
| frameloop | Render mode: always, demand. | `always` |
|
|
62
125
|
|
|
63
|
-
|
|
126
|
+
#### Render Props removed from `@react-three/fiber`
|
|
64
127
|
|
|
65
|
-
|
|
128
|
+
Because the scene now lives in a map, we leave a lot of the render and camera control to the map, rather than to R3F.
|
|
66
129
|
|
|
67
|
-
|
|
130
|
+
- gl
|
|
131
|
+
- camera
|
|
132
|
+
- resize
|
|
133
|
+
- orthographic
|
|
134
|
+
- dpr
|
|
68
135
|
|
|
69
|
-
- [x] Use ThreeJS as a Map Layer (Maplibre).
|
|
70
|
-
- [x] Support on demand rendering.
|
|
71
|
-
- [ ] Use ThreeJS as a canvas overlay.
|
|
72
|
-
- [ ] Add stencil buffers to occlude from the map.
|
|
73
|
-
- [ ] Fully decompose the projection matrix into all the Camera properties required.
|
|
74
|
-
- [ ] Support post processing.
|
|
75
|
-
- [ ] Support multiple coordinate transformations using only one ThreeJS renderer.
|
|
76
|
-
- [ ] Support `drei` `<Html>` component.
|
|
77
|
-
- [ ] Support MapBox.
|
|
78
|
-
- [ ] Support Google Maps.
|