react-three-map 0.1.4 → 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.
Files changed (69) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/README.md +105 -48
  3. package/dist/cjs/main.js.js +1318 -1
  4. package/dist/es/main.js10.mjs +56 -0
  5. package/dist/es/main.js10.mjs.map +1 -0
  6. package/dist/es/main.js11.mjs +9 -0
  7. package/dist/es/main.js11.mjs.map +1 -0
  8. package/dist/es/main.js2.mjs +23 -28
  9. package/dist/es/main.js2.mjs.map +1 -1
  10. package/dist/es/main.js3.mjs +6 -7
  11. package/dist/es/main.js3.mjs.map +1 -1
  12. package/dist/es/main.js4.mjs +28 -56
  13. package/dist/es/main.js4.mjs.map +1 -1
  14. package/dist/es/main.js5.mjs +23533 -12
  15. package/dist/es/main.js5.mjs.map +1 -1
  16. package/dist/es/main.js6.mjs +2 -53
  17. package/dist/es/main.js6.mjs.map +1 -1
  18. package/dist/es/main.js7.mjs +2 -6
  19. package/dist/es/main.js7.mjs.map +1 -1
  20. package/dist/es/main.js8.mjs +60 -0
  21. package/dist/es/main.js8.mjs.map +1 -0
  22. package/dist/es/main.js9.mjs +16 -0
  23. package/dist/es/main.js9.mjs.map +1 -0
  24. package/dist/maplibre/cjs/main.js.js +1 -0
  25. package/dist/maplibre/es/main.js.mjs +5 -0
  26. package/dist/maplibre/es/main.js.mjs.map +1 -0
  27. package/dist/maplibre/es/main.js2.mjs +34 -0
  28. package/dist/maplibre/es/main.js2.mjs.map +1 -0
  29. package/dist/maplibre/es/main.js3.mjs +10 -0
  30. package/dist/maplibre/es/main.js3.mjs.map +1 -0
  31. package/dist/maplibre/es/main.js4.mjs +31 -0
  32. package/dist/maplibre/es/main.js4.mjs.map +1 -0
  33. package/dist/maplibre/es/main.js5.mjs +60 -0
  34. package/dist/maplibre/es/main.js5.mjs.map +1 -0
  35. package/dist/maplibre/es/main.js6.mjs +16 -0
  36. package/dist/maplibre/es/main.js6.mjs.map +1 -0
  37. package/dist/maplibre/es/main.js7.mjs +56 -0
  38. package/dist/maplibre/es/main.js7.mjs.map +1 -0
  39. package/dist/maplibre/es/main.js8.mjs +9 -0
  40. package/dist/maplibre/es/main.js8.mjs.map +1 -0
  41. package/docs/basic-app.gif +0 -0
  42. package/maplibre/package.json +7 -0
  43. package/package.json +12 -5
  44. package/src/canvas/canvas-mapbox.tsx +32 -0
  45. package/src/canvas/canvas-maplibre.tsx +32 -0
  46. package/src/canvas/core/coords-to-matrix.ts +20 -0
  47. package/src/canvas/{create-events.ts → core/create-events.ts} +2 -2
  48. package/src/canvas/core/generic-map.test.ts +2 -0
  49. package/src/canvas/core/generic-map.ts +44 -0
  50. package/src/canvas/core/internal-canvas.tsx +43 -0
  51. package/src/canvas/{state-ref.ts → core/state-ref.ts} +2 -2
  52. package/src/canvas/{use-on-add.ts → core/use-on-add.ts} +31 -23
  53. package/src/canvas/core/use-render.ts +25 -0
  54. package/src/main-mapbox.ts +1 -0
  55. package/src/main-maplibre.ts +1 -0
  56. package/src/stories/canvas.basic.stories.tsx +63 -0
  57. package/src/stories/{canvas.stories.tsx → comparison.stories.tsx} +6 -4
  58. package/src/stories/html-on-top.stories.tsx +26 -0
  59. package/src/stories/my-scene.tsx +18 -11
  60. package/src/stories/render-on-demand.stories.tsx +9 -7
  61. package/src/stories/story-map.tsx +40 -0
  62. package/dist/cjs/vite.svg +0 -1
  63. package/dist/es/vite.svg +0 -1
  64. package/index.html +0 -13
  65. package/src/canvas/canvas.tsx +0 -49
  66. package/src/canvas/coords-to-matrix.ts +0 -19
  67. package/src/canvas/use-render.ts +0 -29
  68. package/src/main.ts +0 -1
  69. /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
- ⚠️ **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!**
4
-
3
+ [![Version](https://img.shields.io/npm/v/react-three-map?style=flat&colorA=000000&colorB=000000)](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 package offers a Three layer that allows you to use `@react-three/fiber` within `react-map-gl` and is compatible with both Mapbox and Maplibre.
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
- ## Examples
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
- Check out our [stories](https://rodrigohamuy.github.io/react-three-map) to see it in action.
10
+ Until now you had:
13
11
 
14
- ## Installation
12
+ | imperative | declarative (react) |
13
+ | --- | --- |
14
+ | Mapbox GL JS | react-map-gl |
15
+ | THREE.js | react-three-fiber |
15
16
 
16
- You can install React Three Map via npm:
17
+ Now with `react-three-map`, you can use them together :fist_right::fist_left:.
17
18
 
18
- ```bash
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
- ## Getting Started
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
- Just add `<Canvas>` inside the map and start using R3F as usual. That easy!
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 Map from 'react-map-gl/maplibre';
29
- import { Canvas } from 'react-three-map';
30
-
31
- ...
32
-
33
- <Map initialViewState={{ latitude: 51, longitude: 0, zoom: 22 }}>
34
- <Canvas latitude={51} longitude={0}>
35
- {/* Use react-three-fiber as usual in here */}
36
- <mesh>
37
- <boxBufferGeometry attach="geometry" args={[1, 1, 1]} />
38
- <meshStandardMaterial attach="material" color="orange" />
39
- </mesh>
40
- </Canvas>
41
- </Map>
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
- ## Documentation
80
+ # Why we build this?
46
81
 
47
- For a full API reference, more usage examples, and other information, check out the full React [Three Map Documentation](#todo).
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
- ## Contributing
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
- We encourage you to contribute to React Three Map! Please check out the [Contributing to React Three Map guide](#todo) for guidelines about how to proceed.
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
- ## License
88
+ ## API
54
89
 
55
- React Three Map is [MIT licensed](#todo).
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
- ## Support
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
- f you're having a problem with anything related to this library, we encourage you to reach out to us. We're always happy to help resolve issues and answer any questions you might have. Open an issue on our [Github repo](#todo).
117
+ #### Render Props
60
118
 
61
- Remember to always follow the Code of Conduct when interacting with the community.
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
- ## Enjoy Using React Three Map!
126
+ #### Render Props removed from `@react-three/fiber`
64
127
 
65
- We hope that you enjoy using React Three Map as much as we enjoyed building it. Happy coding!
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
- ## Roadmap
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.