react-three-map 0.4.0 → 0.4.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 +6 -0
- package/README.md +2 -2
- package/dist/cjs/main.js +337 -1
- package/dist/es/main.mjs +4 -4
- package/dist/es/main10.mjs +14 -6
- package/dist/es/main10.mjs.map +1 -1
- package/dist/es/main11.mjs +48 -34
- package/dist/es/main11.mjs.map +1 -1
- package/dist/es/main12.mjs +8 -5
- package/dist/es/main12.mjs.map +1 -1
- package/dist/es/main13.mjs +64 -37
- package/dist/es/main13.mjs.map +1 -1
- package/dist/es/main2.mjs +18 -17
- package/dist/es/main2.mjs.map +1 -1
- package/dist/es/main3.mjs +46 -32
- package/dist/es/main3.mjs.map +1 -1
- package/dist/es/main4.mjs +20 -18
- package/dist/es/main4.mjs.map +1 -1
- package/dist/es/main5.mjs +3 -3
- package/dist/es/main5.mjs.map +1 -1
- package/dist/es/main6.mjs +33 -5
- package/dist/es/main6.mjs.map +1 -1
- package/dist/es/main7.mjs +11 -10
- package/dist/es/main7.mjs.map +1 -1
- package/dist/es/main8.mjs +19 -13
- package/dist/es/main8.mjs.map +1 -1
- package/dist/es/main9.mjs +17 -9
- package/dist/es/main9.mjs.map +1 -1
- package/dist/maplibre/cjs/main.js +337 -1
- package/dist/maplibre/es/main.mjs +4 -4
- package/dist/maplibre/es/main10.mjs +14 -6
- package/dist/maplibre/es/main10.mjs.map +1 -1
- package/dist/maplibre/es/main11.mjs +48 -34
- package/dist/maplibre/es/main11.mjs.map +1 -1
- package/dist/maplibre/es/main12.mjs +8 -5
- package/dist/maplibre/es/main12.mjs.map +1 -1
- package/dist/maplibre/es/main13.mjs +64 -37
- package/dist/maplibre/es/main13.mjs.map +1 -1
- package/dist/maplibre/es/main2.mjs +18 -17
- package/dist/maplibre/es/main2.mjs.map +1 -1
- package/dist/maplibre/es/main3.mjs +46 -32
- package/dist/maplibre/es/main3.mjs.map +1 -1
- package/dist/maplibre/es/main4.mjs +20 -18
- package/dist/maplibre/es/main4.mjs.map +1 -1
- package/dist/maplibre/es/main5.mjs +3 -3
- package/dist/maplibre/es/main5.mjs.map +1 -1
- package/dist/maplibre/es/main6.mjs +33 -5
- package/dist/maplibre/es/main6.mjs.map +1 -1
- package/dist/maplibre/es/main7.mjs +11 -10
- package/dist/maplibre/es/main7.mjs.map +1 -1
- package/dist/maplibre/es/main8.mjs +19 -13
- package/dist/maplibre/es/main8.mjs.map +1 -1
- package/dist/maplibre/es/main9.mjs +17 -9
- package/dist/maplibre/es/main9.mjs.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -140,7 +140,7 @@ Therefore, the following `<Canvas>` props are ignored:
|
|
|
140
140
|
|
|
141
141
|
### Coordinates
|
|
142
142
|
|
|
143
|
-
[](https://rodrigohamuy.github.io/react-three-map/?story=multi-coordinates--default
|
|
143
|
+
[](https://rodrigohamuy.github.io/react-three-map/?story=multi-coordinates--default)
|
|
144
144
|
|
|
145
145
|
This component allows you to have 3D objects at different coordinates.
|
|
146
146
|
|
|
@@ -162,4 +162,4 @@ import { Canvas, Coordinates } from 'react-three-map'
|
|
|
162
162
|
| --------- | ------------------------------------------------ | ---------- |
|
|
163
163
|
| latitude | The latitude coordinate where to add the scene. | |
|
|
164
164
|
| longitude | The longitude coordinate where to add the scene. | |
|
|
165
|
-
| altitude | The altitude coordinate where to add the scene. | `0` |
|
|
165
|
+
| altitude | The altitude coordinate where to add the scene. | `0` |
|
package/dist/cjs/main.js
CHANGED
|
@@ -1 +1,337 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const jsxRuntime = require("react/jsx-runtime");
|
|
4
|
+
const fiber = require("@react-three/fiber");
|
|
5
|
+
const mapboxGl = require("mapbox-gl");
|
|
6
|
+
const react = require("react");
|
|
7
|
+
const reactMapGl = require("react-map-gl");
|
|
8
|
+
const THREE = require("three");
|
|
9
|
+
function _interopNamespaceDefault(e) {
|
|
10
|
+
const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
|
|
11
|
+
if (e) {
|
|
12
|
+
for (const k in e) {
|
|
13
|
+
if (k !== "default") {
|
|
14
|
+
const d = Object.getOwnPropertyDescriptor(e, k);
|
|
15
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
16
|
+
enumerable: true,
|
|
17
|
+
get: () => e[k]
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
n.default = e;
|
|
23
|
+
return Object.freeze(n);
|
|
24
|
+
}
|
|
25
|
+
const THREE__namespace = /* @__PURE__ */ _interopNamespaceDefault(THREE);
|
|
26
|
+
const quat = new THREE.Quaternion();
|
|
27
|
+
const euler = new THREE.Euler();
|
|
28
|
+
const pos = new THREE.Vector3();
|
|
29
|
+
const scale = new THREE.Vector3();
|
|
30
|
+
const m4 = new THREE.Matrix4();
|
|
31
|
+
function coordsToMatrix({ longitude, latitude, altitude, fromLngLat: fromLngLat2 }) {
|
|
32
|
+
const center = fromLngLat2([longitude, latitude], altitude);
|
|
33
|
+
const scaleUnit = center.meterInMercatorCoordinateUnits();
|
|
34
|
+
pos.set(center.x, center.y, center.z || 0);
|
|
35
|
+
scale.set(scaleUnit, -scaleUnit, scaleUnit);
|
|
36
|
+
quat.setFromEuler(euler.set(-Math.PI * 0.5, 0, 0));
|
|
37
|
+
return m4.compose(pos, quat, scale).toArray();
|
|
38
|
+
}
|
|
39
|
+
function useCoords({ latitude, longitude, altitude, fromLngLat: fromLngLat2 }) {
|
|
40
|
+
const m42 = react.useMemo(() => coordsToMatrix({
|
|
41
|
+
latitude,
|
|
42
|
+
longitude,
|
|
43
|
+
altitude,
|
|
44
|
+
fromLngLat: fromLngLat2
|
|
45
|
+
}), [latitude, longitude, altitude, fromLngLat2]);
|
|
46
|
+
return m42;
|
|
47
|
+
}
|
|
48
|
+
const DOM_EVENTS = {
|
|
49
|
+
onClick: ["click", false],
|
|
50
|
+
onContextMenu: ["contextmenu", false],
|
|
51
|
+
onDoubleClick: ["dblclick", false],
|
|
52
|
+
onWheel: ["wheel", true],
|
|
53
|
+
onPointerDown: ["pointerdown", true],
|
|
54
|
+
onPointerUp: ["pointerup", true],
|
|
55
|
+
onPointerLeave: ["pointerleave", true],
|
|
56
|
+
onPointerMove: ["pointermove", true],
|
|
57
|
+
onPointerCancel: ["pointercancel", true],
|
|
58
|
+
onLostPointerCapture: ["lostpointercapture", true]
|
|
59
|
+
};
|
|
60
|
+
const identity = [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];
|
|
61
|
+
function createEvents() {
|
|
62
|
+
return (store) => {
|
|
63
|
+
const { handlePointer } = fiber.createEvents(store);
|
|
64
|
+
const rayCamera = new THREE.PerspectiveCamera();
|
|
65
|
+
rayCamera.position.z = 5;
|
|
66
|
+
rayCamera.matrixAutoUpdate = false;
|
|
67
|
+
rayCamera.matrixWorldAutoUpdate = false;
|
|
68
|
+
rayCamera.lookAt(0, 0, 0);
|
|
69
|
+
return {
|
|
70
|
+
priority: 1,
|
|
71
|
+
enabled: true,
|
|
72
|
+
compute(event, state) {
|
|
73
|
+
state.size.width = state.gl.domElement.width / window.devicePixelRatio;
|
|
74
|
+
state.size.height = state.gl.domElement.height / window.devicePixelRatio;
|
|
75
|
+
state.pointer.x = event.offsetX / state.size.width * 2 - 1;
|
|
76
|
+
state.pointer.y = 1 - event.offsetY / state.size.height * 2;
|
|
77
|
+
rayCamera.copy(state.camera);
|
|
78
|
+
const projByViewInv2 = rayCamera.userData.projByViewInv || identity;
|
|
79
|
+
rayCamera.matrix.identity();
|
|
80
|
+
rayCamera.matrixWorld.identity();
|
|
81
|
+
rayCamera.matrixWorldInverse.copy(rayCamera.matrixWorld).invert();
|
|
82
|
+
rayCamera.projectionMatrixInverse.fromArray(projByViewInv2);
|
|
83
|
+
rayCamera.projectionMatrix.fromArray(rayCamera.userData.projByView);
|
|
84
|
+
state.raycaster.camera = state.camera;
|
|
85
|
+
state.raycaster.ray.origin.setScalar(0).applyMatrix4(rayCamera.projectionMatrixInverse);
|
|
86
|
+
state.raycaster.ray.direction.set(state.pointer.x, state.pointer.y, 1).applyMatrix4(rayCamera.projectionMatrixInverse).sub(state.raycaster.ray.origin).normalize();
|
|
87
|
+
},
|
|
88
|
+
connected: void 0,
|
|
89
|
+
handlers: Object.keys(DOM_EVENTS).reduce(
|
|
90
|
+
(acc, key) => ({ ...acc, [key]: handlePointer(key) }),
|
|
91
|
+
{}
|
|
92
|
+
),
|
|
93
|
+
update: () => {
|
|
94
|
+
var _a;
|
|
95
|
+
const { events, internal } = store.getState();
|
|
96
|
+
if (((_a = internal.lastEvent) == null ? void 0 : _a.current) && events.handlers) {
|
|
97
|
+
events.handlers.onPointerMove(internal.lastEvent.current);
|
|
98
|
+
}
|
|
99
|
+
},
|
|
100
|
+
connect: (target) => {
|
|
101
|
+
var _a;
|
|
102
|
+
const { set, events } = store.getState();
|
|
103
|
+
(_a = events.disconnect) == null ? void 0 : _a.call(events);
|
|
104
|
+
set((state) => ({ events: { ...state.events, connected: target.parentNode } }));
|
|
105
|
+
Object.entries(events.handlers ?? []).forEach(([name, event]) => {
|
|
106
|
+
const [eventName, passive] = DOM_EVENTS[name];
|
|
107
|
+
target.addEventListener(eventName, event, { passive });
|
|
108
|
+
});
|
|
109
|
+
},
|
|
110
|
+
disconnect: () => {
|
|
111
|
+
const { set, events } = store.getState();
|
|
112
|
+
if (events.connected) {
|
|
113
|
+
Object.entries(events.handlers ?? []).forEach(([name, event]) => {
|
|
114
|
+
if (events && events.connected instanceof HTMLElement) {
|
|
115
|
+
const [eventName] = DOM_EVENTS[name];
|
|
116
|
+
events.connected.removeEventListener(eventName, event);
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
set((state) => ({ events: { ...state.events, connected: void 0 } }));
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
const useFunction = (callback) => {
|
|
126
|
+
const callbackRef = react.useRef(callback);
|
|
127
|
+
callbackRef.current = callback;
|
|
128
|
+
return react.useCallback((...args) => {
|
|
129
|
+
return callbackRef.current(...args);
|
|
130
|
+
}, []);
|
|
131
|
+
};
|
|
132
|
+
function useOnAdd(fromLngLat2, { frameloop, ...renderProps }) {
|
|
133
|
+
const [mounted, setMounted] = react.useState(false);
|
|
134
|
+
const r3mRef = react.useRef({ fromLngLat: fromLngLat2 });
|
|
135
|
+
const onAdd = useFunction((map, gl) => {
|
|
136
|
+
const canvas = map.getCanvas();
|
|
137
|
+
const root = fiber.createRoot(canvas);
|
|
138
|
+
root.configure({
|
|
139
|
+
dpr: window.devicePixelRatio,
|
|
140
|
+
events: createEvents(),
|
|
141
|
+
...renderProps,
|
|
142
|
+
frameloop: "never",
|
|
143
|
+
gl: {
|
|
144
|
+
context: gl,
|
|
145
|
+
depth: true,
|
|
146
|
+
autoClear: false,
|
|
147
|
+
antialias: true,
|
|
148
|
+
...renderProps == null ? void 0 : renderProps.gl
|
|
149
|
+
},
|
|
150
|
+
onCreated: (state) => {
|
|
151
|
+
state.gl.forceContextLoss = () => {
|
|
152
|
+
};
|
|
153
|
+
},
|
|
154
|
+
camera: {
|
|
155
|
+
matrixAutoUpdate: false,
|
|
156
|
+
near: 0
|
|
157
|
+
},
|
|
158
|
+
size: {
|
|
159
|
+
width: canvas.clientWidth,
|
|
160
|
+
height: canvas.clientHeight,
|
|
161
|
+
top: 0,
|
|
162
|
+
left: 0,
|
|
163
|
+
...renderProps == null ? void 0 : renderProps.size
|
|
164
|
+
}
|
|
165
|
+
});
|
|
166
|
+
const store = fiber._roots.get(canvas).store;
|
|
167
|
+
r3mRef.current.map = map;
|
|
168
|
+
r3mRef.current.root = root;
|
|
169
|
+
r3mRef.current.state = store.getState();
|
|
170
|
+
store.setState({ r3m: r3mRef.current });
|
|
171
|
+
if (frameloop === "demand") {
|
|
172
|
+
store.setState({
|
|
173
|
+
frameloop,
|
|
174
|
+
invalidate: () => {
|
|
175
|
+
map.triggerRepaint();
|
|
176
|
+
}
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
setTimeout(() => setMounted(true));
|
|
180
|
+
});
|
|
181
|
+
const onRemove = useFunction(() => {
|
|
182
|
+
if (!r3mRef.current.root)
|
|
183
|
+
return;
|
|
184
|
+
r3mRef.current.root.unmount();
|
|
185
|
+
r3mRef.current.root = void 0;
|
|
186
|
+
});
|
|
187
|
+
react.useEffect(() => () => onRemove(), [onRemove]);
|
|
188
|
+
return { onAdd, onRemove, mounted, r3mRef };
|
|
189
|
+
}
|
|
190
|
+
const useCreateRoot = ({
|
|
191
|
+
children,
|
|
192
|
+
frameloop,
|
|
193
|
+
fromLngLat: fromLngLat2,
|
|
194
|
+
...renderProps
|
|
195
|
+
}) => {
|
|
196
|
+
const id = react.useId();
|
|
197
|
+
const { onAdd, onRemove, mounted, r3mRef } = useOnAdd(fromLngLat2, { frameloop, ...renderProps });
|
|
198
|
+
react.useEffect(() => {
|
|
199
|
+
if (!mounted)
|
|
200
|
+
return;
|
|
201
|
+
if (!r3mRef.current.root)
|
|
202
|
+
return;
|
|
203
|
+
r3mRef.current.root.render(/* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children }));
|
|
204
|
+
}, [r3mRef, mounted, children]);
|
|
205
|
+
return { id, onAdd, onRemove, r3mRef };
|
|
206
|
+
};
|
|
207
|
+
const originMx = new THREE.Matrix4();
|
|
208
|
+
const projByView = new THREE.Matrix4();
|
|
209
|
+
const projByViewInv = new THREE.Matrix4();
|
|
210
|
+
const fwd = new THREE.Vector3();
|
|
211
|
+
function syncCamera(camera, origin, mapCamMx) {
|
|
212
|
+
projByView.fromArray(mapCamMx).multiply(originMx.fromArray(origin));
|
|
213
|
+
projByViewInv.copy(projByView).invert();
|
|
214
|
+
updateCamera(camera, projByViewInv);
|
|
215
|
+
camera.updateMatrix();
|
|
216
|
+
camera.updateMatrixWorld(true);
|
|
217
|
+
camera.projectionMatrix.copy(camera.matrix).premultiply(projByView);
|
|
218
|
+
camera.projectionMatrixInverse.copy(camera.projectionMatrix).invert();
|
|
219
|
+
camera.far = calculateFar(
|
|
220
|
+
camera.matrix.elements[10],
|
|
221
|
+
camera.matrix.elements[14],
|
|
222
|
+
camera.near
|
|
223
|
+
);
|
|
224
|
+
camera.userData.projByView = projByView.toArray();
|
|
225
|
+
camera.userData.projByViewInv = projByViewInv.toArray();
|
|
226
|
+
}
|
|
227
|
+
const updateCamera = (target, projByViewInv2) => {
|
|
228
|
+
target.position.setScalar(0).applyMatrix4(projByViewInv2);
|
|
229
|
+
target.up.set(0, -1, 0).applyMatrix4(projByViewInv2).negate().add(target.position).normalize();
|
|
230
|
+
fwd.set(0, 0, 1).applyMatrix4(projByViewInv2);
|
|
231
|
+
target.lookAt(fwd);
|
|
232
|
+
};
|
|
233
|
+
function calculateFar(c, d, near) {
|
|
234
|
+
const numerator = d * (c - 1);
|
|
235
|
+
const denominator = c * near + near;
|
|
236
|
+
const far = numerator / denominator;
|
|
237
|
+
return far;
|
|
238
|
+
}
|
|
239
|
+
function useRender(origin, r3mRef, frameloop) {
|
|
240
|
+
const render = useFunction((_gl, mapCamMx) => {
|
|
241
|
+
const r3m = r3mRef.current;
|
|
242
|
+
if (!r3m.state || !r3m.map)
|
|
243
|
+
return;
|
|
244
|
+
const camera = r3m.state.camera;
|
|
245
|
+
const gl = r3m.state.gl;
|
|
246
|
+
const advance = r3m.state.advance;
|
|
247
|
+
r3m.mapCamMx = mapCamMx;
|
|
248
|
+
syncCamera(camera, origin, mapCamMx);
|
|
249
|
+
gl.resetState();
|
|
250
|
+
advance(Date.now() * 1e-3, true);
|
|
251
|
+
if (frameloop === "always")
|
|
252
|
+
r3m.map.triggerRepaint();
|
|
253
|
+
});
|
|
254
|
+
return render;
|
|
255
|
+
}
|
|
256
|
+
function useCanvas({
|
|
257
|
+
longitude,
|
|
258
|
+
latitude,
|
|
259
|
+
altitude = 0,
|
|
260
|
+
frameloop = "always",
|
|
261
|
+
fromLngLat: fromLngLat2,
|
|
262
|
+
...renderProps
|
|
263
|
+
}) {
|
|
264
|
+
const m42 = useCoords({
|
|
265
|
+
latitude,
|
|
266
|
+
longitude,
|
|
267
|
+
altitude,
|
|
268
|
+
fromLngLat: fromLngLat2
|
|
269
|
+
});
|
|
270
|
+
const { id, onAdd, onRemove, r3mRef } = useCreateRoot({ frameloop, fromLngLat: fromLngLat2, ...renderProps });
|
|
271
|
+
const render = useRender(m42, r3mRef, frameloop);
|
|
272
|
+
return { id, onAdd, onRemove, render };
|
|
273
|
+
}
|
|
274
|
+
fiber.extend(THREE__namespace);
|
|
275
|
+
const fromLngLat = mapboxGl.MercatorCoordinate.fromLngLat;
|
|
276
|
+
const Canvas = react.memo((props) => {
|
|
277
|
+
const { id, onAdd, onRemove, render } = useCanvas({ ...props, fromLngLat });
|
|
278
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
279
|
+
reactMapGl.Layer,
|
|
280
|
+
{
|
|
281
|
+
id,
|
|
282
|
+
type: "custom",
|
|
283
|
+
renderingMode: "3d",
|
|
284
|
+
onAdd,
|
|
285
|
+
onRemove,
|
|
286
|
+
render
|
|
287
|
+
}
|
|
288
|
+
);
|
|
289
|
+
});
|
|
290
|
+
const useR3M = () => fiber.useThree((s) => s.r3m);
|
|
291
|
+
const Coordinates = react.memo(({
|
|
292
|
+
latitude,
|
|
293
|
+
longitude,
|
|
294
|
+
altitude = 0,
|
|
295
|
+
children
|
|
296
|
+
}) => {
|
|
297
|
+
const [scene] = react.useState(() => new THREE.Scene());
|
|
298
|
+
const r3m = useR3M();
|
|
299
|
+
const origin = useCoords({
|
|
300
|
+
latitude,
|
|
301
|
+
longitude,
|
|
302
|
+
altitude,
|
|
303
|
+
fromLngLat: r3m.fromLngLat
|
|
304
|
+
});
|
|
305
|
+
return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: fiber.createPortal(/* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
306
|
+
/* @__PURE__ */ jsxRuntime.jsx(RenderAtCoords, { r3m, origin }),
|
|
307
|
+
children
|
|
308
|
+
] }), scene, { events: { priority: 2 } }) });
|
|
309
|
+
});
|
|
310
|
+
Coordinates.displayName = "Coordinates";
|
|
311
|
+
function RenderAtCoords({ r3m, origin }) {
|
|
312
|
+
const { gl, scene, set } = fiber.useThree();
|
|
313
|
+
const cameraRef = react.useRef(null);
|
|
314
|
+
fiber.useFrame(() => {
|
|
315
|
+
if (!r3m.mapCamMx)
|
|
316
|
+
return;
|
|
317
|
+
if (!cameraRef.current)
|
|
318
|
+
return;
|
|
319
|
+
syncCamera(cameraRef.current, origin, r3m.mapCamMx);
|
|
320
|
+
gl.render(scene, cameraRef.current);
|
|
321
|
+
});
|
|
322
|
+
react.useLayoutEffect(() => {
|
|
323
|
+
if (!cameraRef.current)
|
|
324
|
+
return;
|
|
325
|
+
set({
|
|
326
|
+
invalidate: () => {
|
|
327
|
+
if (!r3m.map)
|
|
328
|
+
return;
|
|
329
|
+
r3m.map.triggerRepaint();
|
|
330
|
+
},
|
|
331
|
+
camera: cameraRef.current
|
|
332
|
+
});
|
|
333
|
+
}, [set, r3m]);
|
|
334
|
+
return /* @__PURE__ */ jsxRuntime.jsx("perspectiveCamera", { ref: cameraRef });
|
|
335
|
+
}
|
|
336
|
+
exports.Canvas = Canvas;
|
|
337
|
+
exports.Coordinates = Coordinates;
|
package/dist/es/main.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { Canvas
|
|
2
|
-
import { Coordinates
|
|
1
|
+
import { Canvas } from "./main2.mjs";
|
|
2
|
+
import { Coordinates } from "./main3.mjs";
|
|
3
3
|
export {
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
Canvas,
|
|
5
|
+
Coordinates
|
|
6
6
|
};
|
|
7
7
|
//# sourceMappingURL=main.mjs.map
|
package/dist/es/main10.mjs
CHANGED
|
@@ -1,10 +1,18 @@
|
|
|
1
|
-
import { Quaternion
|
|
2
|
-
const
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import { Quaternion, Euler, Vector3, Matrix4 } from "three";
|
|
2
|
+
const quat = new Quaternion();
|
|
3
|
+
const euler = new Euler();
|
|
4
|
+
const pos = new Vector3();
|
|
5
|
+
const scale = new Vector3();
|
|
6
|
+
const m4 = new Matrix4();
|
|
7
|
+
function coordsToMatrix({ longitude, latitude, altitude, fromLngLat }) {
|
|
8
|
+
const center = fromLngLat([longitude, latitude], altitude);
|
|
9
|
+
const scaleUnit = center.meterInMercatorCoordinateUnits();
|
|
10
|
+
pos.set(center.x, center.y, center.z || 0);
|
|
11
|
+
scale.set(scaleUnit, -scaleUnit, scaleUnit);
|
|
12
|
+
quat.setFromEuler(euler.set(-Math.PI * 0.5, 0, 0));
|
|
13
|
+
return m4.compose(pos, quat, scale).toArray();
|
|
6
14
|
}
|
|
7
15
|
export {
|
|
8
|
-
|
|
16
|
+
coordsToMatrix
|
|
9
17
|
};
|
|
10
18
|
//# sourceMappingURL=main10.mjs.map
|
package/dist/es/main10.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"main10.mjs","sources":["../../src/core/coords-to-matrix.ts"],"sourcesContent":["import { Euler, Matrix4, Quaternion, Vector3 } from \"three\";\nimport { FromLngLat } from \"./generic-map\";\n\nconst quat = new Quaternion();\nconst euler = new Euler();\nconst pos = new Vector3();\nconst scale = new Vector3();\nconst m4 = new Matrix4();\n\n/** calculate Matrix4 from coordinates */\nexport function coordsToMatrix({ longitude, latitude, altitude, fromLngLat }: {\n longitude: number, latitude: number, altitude: number, fromLngLat: FromLngLat\n}) {\n const center = fromLngLat([longitude, latitude], altitude);\n const scaleUnit = center.meterInMercatorCoordinateUnits();\n pos.set(center.x, center.y, center.z || 0);\n scale.set(scaleUnit, -scaleUnit, scaleUnit);\n quat.setFromEuler(euler.set(-Math.PI * .5, 0, 0));\n return m4.compose(pos, quat, scale).toArray();\n}\n"],"names":[
|
|
1
|
+
{"version":3,"file":"main10.mjs","sources":["../../src/core/coords-to-matrix.ts"],"sourcesContent":["import { Euler, Matrix4, Quaternion, Vector3 } from \"three\";\nimport { FromLngLat } from \"./generic-map\";\n\nconst quat = new Quaternion();\nconst euler = new Euler();\nconst pos = new Vector3();\nconst scale = new Vector3();\nconst m4 = new Matrix4();\n\n/** calculate Matrix4 from coordinates */\nexport function coordsToMatrix({ longitude, latitude, altitude, fromLngLat }: {\n longitude: number, latitude: number, altitude: number, fromLngLat: FromLngLat\n}) {\n const center = fromLngLat([longitude, latitude], altitude);\n const scaleUnit = center.meterInMercatorCoordinateUnits();\n pos.set(center.x, center.y, center.z || 0);\n scale.set(scaleUnit, -scaleUnit, scaleUnit);\n quat.setFromEuler(euler.set(-Math.PI * .5, 0, 0));\n return m4.compose(pos, quat, scale).toArray();\n}\n"],"names":[],"mappings":";AAGA,MAAM,OAAO,IAAI;AACjB,MAAM,QAAQ,IAAI;AAClB,MAAM,MAAM,IAAI;AAChB,MAAM,QAAQ,IAAI;AAClB,MAAM,KAAK,IAAI;AAGR,SAAS,eAAe,EAAE,WAAW,UAAU,UAAU,cAE7D;AACD,QAAM,SAAS,WAAW,CAAC,WAAW,QAAQ,GAAG,QAAQ;AACnD,QAAA,YAAY,OAAO;AACzB,MAAI,IAAI,OAAO,GAAG,OAAO,GAAG,OAAO,KAAK,CAAC;AACzC,QAAM,IAAI,WAAW,CAAC,WAAW,SAAS;AACrC,OAAA,aAAa,MAAM,IAAI,CAAC,KAAK,KAAK,KAAI,GAAG,CAAC,CAAC;AAChD,SAAO,GAAG,QAAQ,KAAK,MAAM,KAAK,EAAE;AACtC;"}
|
package/dist/es/main11.mjs
CHANGED
|
@@ -1,52 +1,66 @@
|
|
|
1
|
-
import { createRoot
|
|
2
|
-
import { useState
|
|
3
|
-
import { createEvents
|
|
4
|
-
import { useFunction
|
|
5
|
-
function
|
|
6
|
-
const [
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
import { createRoot, _roots } from "@react-three/fiber";
|
|
2
|
+
import { useState, useRef, useEffect } from "react";
|
|
3
|
+
import { createEvents } from "./main13.mjs";
|
|
4
|
+
import { useFunction } from "./main12.mjs";
|
|
5
|
+
function useOnAdd(fromLngLat, { frameloop, ...renderProps }) {
|
|
6
|
+
const [mounted, setMounted] = useState(false);
|
|
7
|
+
const r3mRef = useRef({ fromLngLat });
|
|
8
|
+
const onAdd = useFunction((map, gl) => {
|
|
9
|
+
const canvas = map.getCanvas();
|
|
10
|
+
const root = createRoot(canvas);
|
|
11
|
+
root.configure({
|
|
9
12
|
dpr: window.devicePixelRatio,
|
|
10
|
-
events:
|
|
11
|
-
...
|
|
13
|
+
events: createEvents(),
|
|
14
|
+
...renderProps,
|
|
12
15
|
frameloop: "never",
|
|
13
16
|
gl: {
|
|
14
|
-
context:
|
|
15
|
-
depth:
|
|
16
|
-
autoClear:
|
|
17
|
-
antialias:
|
|
18
|
-
...
|
|
17
|
+
context: gl,
|
|
18
|
+
depth: true,
|
|
19
|
+
autoClear: false,
|
|
20
|
+
antialias: true,
|
|
21
|
+
...renderProps == null ? void 0 : renderProps.gl
|
|
19
22
|
},
|
|
20
|
-
onCreated: (
|
|
21
|
-
|
|
23
|
+
onCreated: (state) => {
|
|
24
|
+
state.gl.forceContextLoss = () => {
|
|
22
25
|
};
|
|
23
26
|
},
|
|
24
27
|
camera: {
|
|
25
|
-
matrixAutoUpdate:
|
|
28
|
+
matrixAutoUpdate: false,
|
|
29
|
+
near: 0
|
|
26
30
|
},
|
|
27
31
|
size: {
|
|
28
|
-
width:
|
|
29
|
-
height:
|
|
32
|
+
width: canvas.clientWidth,
|
|
33
|
+
height: canvas.clientHeight,
|
|
30
34
|
top: 0,
|
|
31
35
|
left: 0,
|
|
32
|
-
...
|
|
36
|
+
...renderProps == null ? void 0 : renderProps.size
|
|
33
37
|
}
|
|
34
38
|
});
|
|
35
|
-
const
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
39
|
+
const store = _roots.get(canvas).store;
|
|
40
|
+
r3mRef.current.map = map;
|
|
41
|
+
r3mRef.current.root = root;
|
|
42
|
+
r3mRef.current.state = store.getState();
|
|
43
|
+
store.setState({ r3m: r3mRef.current });
|
|
44
|
+
if (frameloop === "demand") {
|
|
45
|
+
store.setState({
|
|
46
|
+
frameloop,
|
|
47
|
+
invalidate: () => {
|
|
48
|
+
map.triggerRepaint();
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
setTimeout(() => setMounted(true));
|
|
53
|
+
});
|
|
54
|
+
const onRemove = useFunction(() => {
|
|
55
|
+
if (!r3mRef.current.root)
|
|
56
|
+
return;
|
|
57
|
+
r3mRef.current.root.unmount();
|
|
58
|
+
r3mRef.current.root = void 0;
|
|
46
59
|
});
|
|
47
|
-
|
|
60
|
+
useEffect(() => () => onRemove(), [onRemove]);
|
|
61
|
+
return { onAdd, onRemove, mounted, r3mRef };
|
|
48
62
|
}
|
|
49
63
|
export {
|
|
50
|
-
|
|
64
|
+
useOnAdd
|
|
51
65
|
};
|
|
52
66
|
//# sourceMappingURL=main11.mjs.map
|
package/dist/es/main11.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"main11.mjs","sources":["../../src/core/use-on-add.ts"],"sourcesContent":["import { RenderProps, _roots, createRoot } from \"@react-three/fiber\";\nimport { useRef, useState } from \"react\";\nimport { createEvents } from \"./create-events\";\nimport { FromLngLat, MapInstance } from \"./generic-map\";\nimport { R3mStore } from \"./store\";\nimport { useFunction } from \"./use-function\";\n\nexport function useOnAdd(\n fromLngLat: FromLngLat,\n { frameloop, ...renderProps }: RenderProps<HTMLCanvasElement>\n) {\n\n const [mounted, setMounted] = useState(false);\n\n const r3mRef = useRef<R3mStore>({ fromLngLat });\n\n const onAdd = useFunction((map: MapInstance, gl: WebGLRenderingContext) => {\n\n const canvas = map.getCanvas();\n const root = createRoot(canvas);\n root.configure({\n dpr: window.devicePixelRatio,\n events: createEvents(),\n ...renderProps,\n frameloop: 'never',\n gl: {\n context: gl,\n depth: true,\n autoClear: false,\n antialias: true,\n ...renderProps?.gl,\n },\n onCreated: (state) => {\n // eslint-disable-next-line @typescript-eslint/no-empty-function\n state.gl.forceContextLoss = () => { };\n },\n camera: {\n matrixAutoUpdate: false,\n },\n size: {\n width: canvas.clientWidth,\n height: canvas.clientHeight,\n top: 0,\n left: 0,\n ...renderProps?.size,\n },\n });\n\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const store = _roots.get(canvas)!.store;\n\n r3mRef.current.map = map;\n r3mRef.current.root = root;\n r3mRef.current.state = store.getState();\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n store.setState({ r3m: r3mRef.current } as any);\n\n if (frameloop === 'demand') {\n store.setState({\n frameloop,\n invalidate: () => {\n map.triggerRepaint();\n },\n })\n }\n\n setTimeout(() => setMounted(true));\n\n })\n\n const onRemove = useFunction(() => {\n
|
|
1
|
+
{"version":3,"file":"main11.mjs","sources":["../../src/core/use-on-add.ts"],"sourcesContent":["import { RenderProps, _roots, createRoot } from \"@react-three/fiber\";\nimport { useEffect, useRef, useState } from \"react\";\nimport { createEvents } from \"./create-events\";\nimport { FromLngLat, MapInstance } from \"./generic-map\";\nimport { R3mStore } from \"./store\";\nimport { useFunction } from \"./use-function\";\n\nexport function useOnAdd(\n fromLngLat: FromLngLat,\n { frameloop, ...renderProps }: RenderProps<HTMLCanvasElement>\n) {\n\n const [mounted, setMounted] = useState(false);\n\n const r3mRef = useRef<R3mStore>({ fromLngLat });\n\n const onAdd = useFunction((map: MapInstance, gl: WebGLRenderingContext) => {\n\n const canvas = map.getCanvas();\n const root = createRoot(canvas);\n root.configure({\n dpr: window.devicePixelRatio,\n events: createEvents(),\n ...renderProps,\n frameloop: 'never',\n gl: {\n context: gl,\n depth: true,\n autoClear: false,\n antialias: true,\n ...renderProps?.gl,\n },\n onCreated: (state) => {\n // eslint-disable-next-line @typescript-eslint/no-empty-function\n state.gl.forceContextLoss = () => { };\n },\n camera: {\n matrixAutoUpdate: false,\n near: 0,\n },\n size: {\n width: canvas.clientWidth,\n height: canvas.clientHeight,\n top: 0,\n left: 0,\n ...renderProps?.size,\n },\n });\n\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const store = _roots.get(canvas)!.store;\n\n r3mRef.current.map = map;\n r3mRef.current.root = root;\n r3mRef.current.state = store.getState();\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n store.setState({ r3m: r3mRef.current } as any);\n\n if (frameloop === 'demand') {\n store.setState({\n frameloop,\n invalidate: () => {\n map.triggerRepaint();\n },\n })\n }\n\n setTimeout(() => setMounted(true));\n\n })\n\n const onRemove = useFunction(() => {\n if (!r3mRef.current.root) return;\n r3mRef.current.root.unmount();\n r3mRef.current.root = undefined;\n })\n\n // on unmount\n useEffect(() => () => onRemove(), [onRemove])\n\n return { onAdd, onRemove, mounted, r3mRef };\n}"],"names":[],"mappings":";;;;AAOO,SAAS,SACd,YACA,EAAE,WAAW,GAAG,eAChB;AAEA,QAAM,CAAC,SAAS,UAAU,IAAI,SAAS,KAAK;AAE5C,QAAM,SAAS,OAAiB,EAAE,WAAY,CAAA;AAE9C,QAAM,QAAQ,YAAY,CAAC,KAAkB,OAA8B;AAEnE,UAAA,SAAS,IAAI;AACb,UAAA,OAAO,WAAW,MAAM;AAC9B,SAAK,UAAU;AAAA,MACb,KAAK,OAAO;AAAA,MACZ,QAAQ,aAAa;AAAA,MACrB,GAAG;AAAA,MACH,WAAW;AAAA,MACX,IAAI;AAAA,QACF,SAAS;AAAA,QACT,OAAO;AAAA,QACP,WAAW;AAAA,QACX,WAAW;AAAA,QACX,GAAG,2CAAa;AAAA,MAClB;AAAA,MACA,WAAW,CAAC,UAAU;AAEd,cAAA,GAAG,mBAAmB,MAAM;AAAA,QAAA;AAAA,MACpC;AAAA,MACA,QAAQ;AAAA,QACN,kBAAkB;AAAA,QAClB,MAAM;AAAA,MACR;AAAA,MACA,MAAM;AAAA,QACJ,OAAO,OAAO;AAAA,QACd,QAAQ,OAAO;AAAA,QACf,KAAK;AAAA,QACL,MAAM;AAAA,QACN,GAAG,2CAAa;AAAA,MAClB;AAAA,IAAA,CACD;AAGD,UAAM,QAAQ,OAAO,IAAI,MAAM,EAAG;AAElC,WAAO,QAAQ,MAAM;AACrB,WAAO,QAAQ,OAAO;AACf,WAAA,QAAQ,QAAQ,MAAM,SAAS;AAGtC,UAAM,SAAS,EAAE,KAAK,OAAO,QAAgB,CAAA;AAE7C,QAAI,cAAc,UAAU;AAC1B,YAAM,SAAS;AAAA,QACb;AAAA,QACA,YAAY,MAAM;AAChB,cAAI,eAAe;AAAA,QACrB;AAAA,MAAA,CACD;AAAA,IACH;AAEW,eAAA,MAAM,WAAW,IAAI,CAAC;AAAA,EAAA,CAElC;AAEK,QAAA,WAAW,YAAY,MAAM;AAC7B,QAAA,CAAC,OAAO,QAAQ;AAAM;AACnB,WAAA,QAAQ,KAAK;AACpB,WAAO,QAAQ,OAAO;AAAA,EAAA,CACvB;AAGD,YAAU,MAAM,MAAM,SAAY,GAAA,CAAC,QAAQ,CAAC;AAE5C,SAAO,EAAE,OAAO,UAAU,SAAS,OAAO;AAC5C;"}
|
package/dist/es/main12.mjs
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
|
-
import { useRef
|
|
2
|
-
const
|
|
3
|
-
const
|
|
4
|
-
|
|
1
|
+
import { useRef, useCallback } from "react";
|
|
2
|
+
const useFunction = (callback) => {
|
|
3
|
+
const callbackRef = useRef(callback);
|
|
4
|
+
callbackRef.current = callback;
|
|
5
|
+
return useCallback((...args) => {
|
|
6
|
+
return callbackRef.current(...args);
|
|
7
|
+
}, []);
|
|
5
8
|
};
|
|
6
9
|
export {
|
|
7
|
-
|
|
10
|
+
useFunction
|
|
8
11
|
};
|
|
9
12
|
//# sourceMappingURL=main12.mjs.map
|
package/dist/es/main12.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"main12.mjs","sources":["../../src/core/use-function.ts"],"sourcesContent":["import { useCallback, useRef } from 'react';\n\n/* eslint-disable @typescript-eslint/no-explicit-any */\nexport const useFunction = <T extends (...args: any[]) => any>(callback: T): T => {\n const callbackRef = useRef(callback);\n callbackRef.current = callback;\n return useCallback((...args: any[]) => {\n return callbackRef.current(...args);\n }, []) as T;\n};\n"],"names":[
|
|
1
|
+
{"version":3,"file":"main12.mjs","sources":["../../src/core/use-function.ts"],"sourcesContent":["import { useCallback, useRef } from 'react';\n\n/* eslint-disable @typescript-eslint/no-explicit-any */\nexport const useFunction = <T extends (...args: any[]) => any>(callback: T): T => {\n const callbackRef = useRef(callback);\n callbackRef.current = callback;\n return useCallback((...args: any[]) => {\n return callbackRef.current(...args);\n }, []) as T;\n};\n"],"names":[],"mappings":";AAGa,MAAA,cAAc,CAAoC,aAAmB;AAC1E,QAAA,cAAc,OAAO,QAAQ;AACnC,cAAY,UAAU;AACf,SAAA,YAAY,IAAI,SAAgB;AAC9B,WAAA,YAAY,QAAQ,GAAG,IAAI;AAAA,EACpC,GAAG,CAAE,CAAA;AACP;"}
|