react-three-map 0.8.1 → 1.0.0-next.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 +19 -0
- package/README.md +41 -24
- package/dist/cjs/main.js +1283 -44
- package/dist/es/main.mjs +2 -1
- package/dist/es/main10.mjs +71 -10
- package/dist/es/main10.mjs.map +1 -1
- package/dist/es/main11.mjs +12 -35
- package/dist/es/main11.mjs.map +1 -1
- package/dist/es/main12.mjs +12 -13
- package/dist/es/main12.mjs.map +1 -1
- package/dist/es/main13.mjs +42 -24
- package/dist/es/main13.mjs.map +1 -1
- package/dist/es/main14.mjs +13 -4
- package/dist/es/main14.mjs.map +1 -1
- package/dist/es/main15.mjs +22 -31
- package/dist/es/main15.mjs.map +1 -1
- package/dist/es/main16.mjs +87 -22
- package/dist/es/main16.mjs.map +1 -1
- package/dist/es/main17.mjs +14 -94
- package/dist/es/main17.mjs.map +1 -1
- package/dist/es/main18.mjs +22 -62
- package/dist/es/main18.mjs.map +1 -1
- package/dist/es/main19.mjs +27 -20
- package/dist/es/main19.mjs.map +1 -1
- package/dist/es/main20.mjs +8 -23
- package/dist/es/main20.mjs.map +1 -1
- package/dist/es/main21.mjs +34 -16
- package/dist/es/main21.mjs.map +1 -1
- package/dist/es/main22.mjs +12 -80
- package/dist/es/main22.mjs.map +1 -1
- package/dist/es/main23.mjs +26 -0
- package/dist/es/main23.mjs.map +1 -0
- package/dist/es/main24.mjs +5 -0
- package/dist/es/main24.mjs.map +1 -0
- package/dist/es/main25.mjs +33 -0
- package/dist/es/main25.mjs.map +1 -0
- package/dist/es/main26.mjs +27 -0
- package/dist/es/main26.mjs.map +1 -0
- package/dist/es/main27.mjs +98 -0
- package/dist/es/main27.mjs.map +1 -0
- package/dist/es/main28.mjs +66 -0
- package/dist/es/main28.mjs.map +1 -0
- package/dist/es/main29.mjs +23 -0
- package/dist/es/main29.mjs.map +1 -0
- package/dist/es/main3.mjs +13 -4
- package/dist/es/main3.mjs.map +1 -1
- package/dist/es/main30.mjs +27 -0
- package/dist/es/main30.mjs.map +1 -0
- package/dist/es/main31.mjs +19 -0
- package/dist/es/main31.mjs.map +1 -0
- package/dist/es/main32.mjs +83 -0
- package/dist/es/main32.mjs.map +1 -0
- package/dist/es/main33.mjs +501 -0
- package/dist/es/main33.mjs.map +1 -0
- package/dist/es/main34.mjs +90 -0
- package/dist/es/main34.mjs.map +1 -0
- package/dist/es/main35.mjs +6 -0
- package/dist/es/main35.mjs.map +1 -0
- package/dist/es/main36.mjs +26 -0
- package/dist/es/main36.mjs.map +1 -0
- package/dist/es/main37.mjs +19 -0
- package/dist/es/main37.mjs.map +1 -0
- package/dist/es/main38.mjs +50 -0
- package/dist/es/main38.mjs.map +1 -0
- package/dist/es/main39.mjs +31 -0
- package/dist/es/main39.mjs.map +1 -0
- package/dist/es/main4.mjs +3 -3
- package/dist/es/main40.mjs +9 -0
- package/dist/es/main40.mjs.map +1 -0
- package/dist/es/main41.mjs +62 -0
- package/dist/es/main41.mjs.map +1 -0
- package/dist/es/main42.mjs +42 -0
- package/dist/es/main42.mjs.map +1 -0
- package/dist/es/main5.mjs +22 -2
- package/dist/es/main5.mjs.map +1 -1
- package/dist/es/main6.mjs +1 -1
- package/dist/es/main7.mjs +1 -1
- package/dist/es/main8.mjs +87 -20
- package/dist/es/main8.mjs.map +1 -1
- package/dist/es/main9.mjs +80 -24
- package/dist/es/main9.mjs.map +1 -1
- package/dist/maplibre/cjs/main.js +30 -9
- package/dist/maplibre/es/main.mjs +2 -1
- package/dist/maplibre/es/main.mjs.map +1 -1
- package/dist/maplibre/es/main14.mjs +1 -1
- package/dist/maplibre/es/main14.mjs.map +1 -1
- package/dist/maplibre/es/main16.mjs +2 -1
- package/dist/maplibre/es/main16.mjs.map +1 -1
- package/dist/maplibre/es/main3.mjs +2 -2
- package/dist/maplibre/es/main3.mjs.map +1 -1
- package/dist/maplibre/es/main5.mjs +21 -1
- package/dist/maplibre/es/main5.mjs.map +1 -1
- package/dist/maplibre/types/api/coords-to-vector-3.d.ts +1 -0
- package/dist/maplibre/types/core/canvas-in-layer/use-canvas-in-layer.d.ts +5 -1
- package/dist/maplibre/types/core/canvas-in-layer/use-render.d.ts +5 -1
- package/dist/maplibre/types/core/earth-radius.d.ts +1 -1
- package/dist/maplibre/types/core/generic-map.d.ts +2 -2
- package/dist/maplibre/types/{mapbox → maplibre}/canvas.d.ts +1 -1
- package/dist/maplibre/types/maplibre.index.d.ts +1 -1
- package/dist/types/api/coords-to-vector-3.d.ts +1 -0
- package/dist/types/core/canvas-in-layer/use-canvas-in-layer.d.ts +5 -1
- package/dist/types/core/canvas-in-layer/use-render.d.ts +5 -1
- package/dist/types/core/earth-radius.d.ts +1 -1
- package/dist/types/core/generic-map.d.ts +2 -2
- package/dist/types/mapbox/canvas.d.ts +1 -1
- package/made-with/studio-carto-urban-project.webp +0 -0
- package/package.json +7 -7
- package/stories/package.json +4 -4
- package/stories/yarn.lock +175 -98
package/dist/es/main9.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"main9.mjs","sources":["../../
|
|
1
|
+
{"version":3,"file":"main9.mjs","sources":["../../node_modules/@vis.gl/react-mapbox/dist/components/marker.js"],"sourcesContent":["/* global document */\nimport * as React from 'react';\nimport { createPortal } from 'react-dom';\nimport { useImperativeHandle, useEffect, useMemo, useRef, useContext, forwardRef, memo } from 'react';\nimport { applyReactStyle } from \"../utils/apply-react-style.js\";\nimport { MapContext } from \"./map.js\";\nimport { arePointsEqual } from \"../utils/deep-equal.js\";\n/* eslint-disable complexity,max-statements */\nexport const Marker = memo(forwardRef((props, ref) => {\n const { map, mapLib } = useContext(MapContext);\n const thisRef = useRef({ props });\n thisRef.current.props = props;\n const marker = useMemo(() => {\n let hasChildren = false;\n React.Children.forEach(props.children, el => {\n if (el) {\n hasChildren = true;\n }\n });\n const options = {\n ...props,\n element: hasChildren ? document.createElement('div') : null\n };\n const mk = new mapLib.Marker(options);\n mk.setLngLat([props.longitude, props.latitude]);\n mk.getElement().addEventListener('click', (e) => {\n thisRef.current.props.onClick?.({\n type: 'click',\n target: mk,\n originalEvent: e\n });\n });\n mk.on('dragstart', e => {\n const evt = e;\n evt.lngLat = marker.getLngLat();\n thisRef.current.props.onDragStart?.(evt);\n });\n mk.on('drag', e => {\n const evt = e;\n evt.lngLat = marker.getLngLat();\n thisRef.current.props.onDrag?.(evt);\n });\n mk.on('dragend', e => {\n const evt = e;\n evt.lngLat = marker.getLngLat();\n thisRef.current.props.onDragEnd?.(evt);\n });\n return mk;\n }, []);\n useEffect(() => {\n marker.addTo(map.getMap());\n return () => {\n marker.remove();\n };\n }, []);\n const { longitude, latitude, offset, style, draggable = false, popup = null, rotation = 0, rotationAlignment = 'auto', pitchAlignment = 'auto' } = props;\n useEffect(() => {\n applyReactStyle(marker.getElement(), style);\n }, [style]);\n useImperativeHandle(ref, () => marker, []);\n if (marker.getLngLat().lng !== longitude || marker.getLngLat().lat !== latitude) {\n marker.setLngLat([longitude, latitude]);\n }\n if (offset && !arePointsEqual(marker.getOffset(), offset)) {\n marker.setOffset(offset);\n }\n if (marker.isDraggable() !== draggable) {\n marker.setDraggable(draggable);\n }\n if (marker.getRotation() !== rotation) {\n marker.setRotation(rotation);\n }\n if (marker.getRotationAlignment() !== rotationAlignment) {\n marker.setRotationAlignment(rotationAlignment);\n }\n if (marker.getPitchAlignment() !== pitchAlignment) {\n marker.setPitchAlignment(pitchAlignment);\n }\n if (marker.getPopup() !== popup) {\n marker.setPopup(popup);\n }\n return createPortal(props.children, marker.getElement());\n}));\n//# sourceMappingURL=marker.js.map"],"names":[],"mappings":";;;;;;AAQsB,KAAK,WAAW,CAAC,OAAO,QAAQ;AAClD,QAAM,EAAE,KAAK,OAAQ,IAAG,WAAW,UAAU;AAC7C,QAAM,UAAU,OAAO,EAAE,MAAO,CAAA;AAChC,UAAQ,QAAQ,QAAQ;AACxB,QAAM,SAAS,QAAQ,MAAM;AACzB,QAAI,cAAc;AAClB,UAAM,SAAS,QAAQ,MAAM,UAAU,QAAM;AACzC,UAAI,IAAI;AACJ,sBAAc;AAAA,MACjB;AAAA,IACb,CAAS;AACD,UAAM,UAAU;AAAA,MACZ,GAAG;AAAA,MACH,SAAS,cAAc,SAAS,cAAc,KAAK,IAAI;AAAA,IACnE;AACQ,UAAM,KAAK,IAAI,OAAO,OAAO,OAAO;AACpC,OAAG,UAAU,CAAC,MAAM,WAAW,MAAM,QAAQ,CAAC;AAC9C,OAAG,WAAY,EAAC,iBAAiB,SAAS,CAAC,MAAM;;AAC7C,0BAAQ,QAAQ,OAAM,YAAtB,4BAAgC;AAAA,QAC5B,MAAM;AAAA,QACN,QAAQ;AAAA,QACR,eAAe;AAAA,MAC/B;AAAA,IACA,CAAS;AACD,OAAG,GAAG,aAAa,OAAK;;AACpB,YAAM,MAAM;AACZ,UAAI,SAAS,OAAO;AACpB,0BAAQ,QAAQ,OAAM,gBAAtB,4BAAoC;AAAA,IAChD,CAAS;AACD,OAAG,GAAG,QAAQ,OAAK;;AACf,YAAM,MAAM;AACZ,UAAI,SAAS,OAAO;AACpB,0BAAQ,QAAQ,OAAM,WAAtB,4BAA+B;AAAA,IAC3C,CAAS;AACD,OAAG,GAAG,WAAW,OAAK;;AAClB,YAAM,MAAM;AACZ,UAAI,SAAS,OAAO;AACpB,0BAAQ,QAAQ,OAAM,cAAtB,4BAAkC;AAAA,IAC9C,CAAS;AACD,WAAO;AAAA,EACV,GAAE,CAAE,CAAA;AACL,YAAU,MAAM;AACZ,WAAO,MAAM,IAAI,OAAQ,CAAA;AACzB,WAAO,MAAM;AACT,aAAO,OAAM;AAAA,IACzB;AAAA,EACK,GAAE,CAAE,CAAA;AACL,QAAM,EAAE,WAAW,UAAU,QAAQ,OAAO,YAAY,OAAO,QAAQ,MAAM,WAAW,GAAG,oBAAoB,QAAQ,iBAAiB,OAAQ,IAAG;AACnJ,YAAU,MAAM;AACZ,oBAAgB,OAAO,WAAY,GAAE,KAAK;AAAA,EAClD,GAAO,CAAC,KAAK,CAAC;AACV,sBAAoB,KAAK,MAAM,QAAQ,CAAE,CAAA;AACzC,MAAI,OAAO,UAAW,EAAC,QAAQ,aAAa,OAAO,UAAS,EAAG,QAAQ,UAAU;AAC7E,WAAO,UAAU,CAAC,WAAW,QAAQ,CAAC;AAAA,EACzC;AACD,MAAI,UAAU,CAAC,eAAe,OAAO,UAAS,GAAI,MAAM,GAAG;AACvD,WAAO,UAAU,MAAM;AAAA,EAC1B;AACD,MAAI,OAAO,YAAa,MAAK,WAAW;AACpC,WAAO,aAAa,SAAS;AAAA,EAChC;AACD,MAAI,OAAO,YAAa,MAAK,UAAU;AACnC,WAAO,YAAY,QAAQ;AAAA,EAC9B;AACD,MAAI,OAAO,qBAAsB,MAAK,mBAAmB;AACrD,WAAO,qBAAqB,iBAAiB;AAAA,EAChD;AACD,MAAI,OAAO,kBAAmB,MAAK,gBAAgB;AAC/C,WAAO,kBAAkB,cAAc;AAAA,EAC1C;AACD,MAAI,OAAO,SAAU,MAAK,OAAO;AAC7B,WAAO,SAAS,KAAK;AAAA,EACxB;AACD,SAAO,aAAa,MAAM,UAAU,OAAO,WAAY,CAAA;AAC3D,CAAC,CAAC;","x_google_ignoreList":[0]}
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
3
|
const fiber = require("@react-three/fiber");
|
|
4
4
|
const jsxRuntime = require("react/jsx-runtime");
|
|
5
|
-
const
|
|
5
|
+
const maplibreGl = require("maplibre-gl");
|
|
6
6
|
const react = require("react");
|
|
7
|
-
const
|
|
7
|
+
const maplibre = require("react-map-gl/maplibre");
|
|
8
8
|
const THREE = require("three");
|
|
9
9
|
const reactDom = require("react-dom");
|
|
10
10
|
function _interopNamespaceDefault(e) {
|
|
@@ -147,14 +147,33 @@ function RenderAtCoords({ r3m, origin }) {
|
|
|
147
147
|
}, [set, r3m]);
|
|
148
148
|
return /* @__PURE__ */ jsxRuntime.jsx("perspectiveCamera", { ref: cameraRef });
|
|
149
149
|
}
|
|
150
|
-
const earthRadius =
|
|
150
|
+
const earthRadius = 63710088e-1;
|
|
151
|
+
const mercatorScaleLookup = {};
|
|
152
|
+
function getMercatorScale(lat) {
|
|
153
|
+
const index = Math.round(lat * 1e3);
|
|
154
|
+
if (mercatorScaleLookup[index] === void 0) {
|
|
155
|
+
mercatorScaleLookup[index] = 1 / Math.cos(lat * THREE.MathUtils.DEG2RAD);
|
|
156
|
+
}
|
|
157
|
+
return mercatorScaleLookup[index];
|
|
158
|
+
}
|
|
159
|
+
function averageMercatorScale(originLat, pointLat, steps = 10) {
|
|
160
|
+
let totalScale = 0;
|
|
161
|
+
const latStep = (pointLat - originLat) / steps;
|
|
162
|
+
for (let i = 0; i <= steps; i++) {
|
|
163
|
+
const lat = originLat + latStep * i;
|
|
164
|
+
totalScale += getMercatorScale(lat);
|
|
165
|
+
}
|
|
166
|
+
return totalScale / (steps + 1);
|
|
167
|
+
}
|
|
151
168
|
function coordsToVector3(point, origin) {
|
|
152
169
|
const latitudeDiff = (point.latitude - origin.latitude) * THREE.MathUtils.DEG2RAD;
|
|
153
170
|
const longitudeDiff = (point.longitude - origin.longitude) * THREE.MathUtils.DEG2RAD;
|
|
154
171
|
const altitudeDiff = (point.altitude || 0) - (origin.altitude || 0);
|
|
155
172
|
const x = longitudeDiff * earthRadius * Math.cos(origin.latitude * THREE.MathUtils.DEG2RAD);
|
|
156
173
|
const y = altitudeDiff;
|
|
157
|
-
const
|
|
174
|
+
const steps = Math.ceil(Math.abs(point.latitude - origin.latitude)) * 100 + 1;
|
|
175
|
+
const avgScale = averageMercatorScale(origin.latitude, point.latitude, steps);
|
|
176
|
+
const z = -latitudeDiff * earthRadius / getMercatorScale(origin.latitude) * avgScale;
|
|
158
177
|
return [x, y, z];
|
|
159
178
|
}
|
|
160
179
|
function useCoords() {
|
|
@@ -218,7 +237,8 @@ function useRender({
|
|
|
218
237
|
r3m
|
|
219
238
|
}) {
|
|
220
239
|
const render = useFunction((_gl, projViewMx) => {
|
|
221
|
-
|
|
240
|
+
const pVMx = "defaultProjectionData" in projViewMx ? Object.values(projViewMx.defaultProjectionData.mainMatrix) : projViewMx;
|
|
241
|
+
r3m.viewProjMx.splice(0, 16, ...pVMx);
|
|
222
242
|
const state = useThree.getState();
|
|
223
243
|
const camera = state.camera;
|
|
224
244
|
const { gl, advance } = state;
|
|
@@ -518,9 +538,9 @@ const InitCanvasFC = react.memo((props) => {
|
|
|
518
538
|
});
|
|
519
539
|
InitCanvasFC.displayName = "InitCanvasFC";
|
|
520
540
|
fiber.extend(THREE__namespace);
|
|
521
|
-
const fromLngLat =
|
|
541
|
+
const fromLngLat = maplibreGl.MercatorCoordinate.fromLngLat;
|
|
522
542
|
const Canvas = react.memo(({ overlay, ...props }) => {
|
|
523
|
-
const map =
|
|
543
|
+
const map = maplibre.useMap().current.getMap();
|
|
524
544
|
return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
525
545
|
overlay && /* @__PURE__ */ jsxRuntime.jsx(CanvasOverlay, { map, ...props }),
|
|
526
546
|
!overlay && /* @__PURE__ */ jsxRuntime.jsx(CanvasInLayer, { map, ...props })
|
|
@@ -529,7 +549,7 @@ const Canvas = react.memo(({ overlay, ...props }) => {
|
|
|
529
549
|
Canvas.displayName = "Canvas";
|
|
530
550
|
const CanvasInLayer = react.memo(({ map, ...props }) => {
|
|
531
551
|
const layerProps = useCanvasInLayer(props, fromLngLat, map);
|
|
532
|
-
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
552
|
+
return /* @__PURE__ */ jsxRuntime.jsx(maplibre.Layer, { ...layerProps });
|
|
533
553
|
});
|
|
534
554
|
CanvasInLayer.displayName = "CanvasInLayer";
|
|
535
555
|
const CanvasOverlay = react.memo(({ map, id, beforeId, ...props }) => {
|
|
@@ -540,7 +560,7 @@ const CanvasOverlay = react.memo(({ map, id, beforeId, ...props }) => {
|
|
|
540
560
|
onRender(mx);
|
|
541
561
|
});
|
|
542
562
|
return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
543
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
563
|
+
/* @__PURE__ */ jsxRuntime.jsx(maplibre.Layer, { id, beforeId, type: "custom", render }),
|
|
544
564
|
/* @__PURE__ */ jsxRuntime.jsx(
|
|
545
565
|
InitCanvasFC,
|
|
546
566
|
{
|
|
@@ -557,6 +577,7 @@ const useMap = useMap$1;
|
|
|
557
577
|
exports.Canvas = Canvas;
|
|
558
578
|
exports.Coordinates = Coordinates;
|
|
559
579
|
exports.NearCoordinates = NearCoordinates;
|
|
580
|
+
exports.averageMercatorScale = averageMercatorScale;
|
|
560
581
|
exports.coordsToVector3 = coordsToVector3;
|
|
561
582
|
exports.useMap = useMap;
|
|
562
583
|
exports.vector3ToCoords = vector3ToCoords;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { useMap as useMap$1 } from "./main2.mjs";
|
|
2
2
|
import { Canvas } from "./main3.mjs";
|
|
3
3
|
import { Coordinates } from "./main4.mjs";
|
|
4
|
-
import { coordsToVector3 } from "./main5.mjs";
|
|
4
|
+
import { averageMercatorScale, coordsToVector3 } from "./main5.mjs";
|
|
5
5
|
import { NearCoordinates } from "./main6.mjs";
|
|
6
6
|
import { vector3ToCoords } from "./main7.mjs";
|
|
7
7
|
const useMap = useMap$1;
|
|
@@ -9,6 +9,7 @@ export {
|
|
|
9
9
|
Canvas,
|
|
10
10
|
Coordinates,
|
|
11
11
|
NearCoordinates,
|
|
12
|
+
averageMercatorScale,
|
|
12
13
|
coordsToVector3,
|
|
13
14
|
useMap,
|
|
14
15
|
vector3ToCoords
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"main.mjs","sources":["../../../src/maplibre.index.ts"],"sourcesContent":["import type { Map } from 'maplibre-gl';\nimport { useMap as useMapGeneric } from './api/use-map';\n\nexport * from './api';\nexport * from './
|
|
1
|
+
{"version":3,"file":"main.mjs","sources":["../../../src/maplibre.index.ts"],"sourcesContent":["import type { Map } from 'maplibre-gl';\nimport { useMap as useMapGeneric } from './api/use-map';\n\nexport * from './api';\nexport * from './maplibre/canvas';\n\nexport const useMap = useMapGeneric<Map>;\n"],"names":["useMapGeneric"],"mappings":";;;;;;AAMO,MAAM,SAASA;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"main14.mjs","sources":["../../../src/core/earth-radius.ts"],"sourcesContent":["export const earthRadius =
|
|
1
|
+
{"version":3,"file":"main14.mjs","sources":["../../../src/core/earth-radius.ts"],"sourcesContent":["export const earthRadius = 6371008.8;\n"],"names":[],"mappings":"AAAO,MAAM,cAAc;"}
|
|
@@ -8,7 +8,8 @@ function useRender({
|
|
|
8
8
|
r3m
|
|
9
9
|
}) {
|
|
10
10
|
const render = useFunction((_gl, projViewMx) => {
|
|
11
|
-
|
|
11
|
+
const pVMx = "defaultProjectionData" in projViewMx ? Object.values(projViewMx.defaultProjectionData.mainMatrix) : projViewMx;
|
|
12
|
+
r3m.viewProjMx.splice(0, 16, ...pVMx);
|
|
12
13
|
const state = useThree.getState();
|
|
13
14
|
const camera = state.camera;
|
|
14
15
|
const { gl, advance } = state;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"main16.mjs","sources":["../../../src/core/canvas-in-layer/use-render.ts"],"sourcesContent":["import { RootState } from \"@react-three/fiber\";\nimport { Matrix4Tuple, PerspectiveCamera } from \"three\";\nimport { UseBoundStore } from \"zustand\";\nimport { MapInstance } from \"../generic-map\";\nimport { syncCamera } from \"../sync-camera\";\nimport { useFunction } from \"../use-function\";\nimport { R3M } from \"../use-r3m\";\n\nexport function useRender({\n map, origin, useThree, frameloop, r3m,\n} :{\n map: MapInstance,\n origin: Matrix4Tuple,\n useThree: UseBoundStore<RootState>,\n frameloop?: 'always' | 'demand',\n r3m: R3M\n}) {\n const render = useFunction((_gl: WebGL2RenderingContext, projViewMx: number[]) => {\n r3m.viewProjMx.splice(0, 16, ...
|
|
1
|
+
{"version":3,"file":"main16.mjs","sources":["../../../src/core/canvas-in-layer/use-render.ts"],"sourcesContent":["import { RootState } from \"@react-three/fiber\";\nimport { Matrix4Tuple, PerspectiveCamera } from \"three\";\nimport { UseBoundStore } from \"zustand\";\nimport { MapInstance } from \"../generic-map\";\nimport { syncCamera } from \"../sync-camera\";\nimport { useFunction } from \"../use-function\";\nimport { R3M } from \"../use-r3m\";\n\nexport function useRender({\n map, origin, useThree, frameloop, r3m,\n} :{\n map: MapInstance,\n origin: Matrix4Tuple,\n useThree: UseBoundStore<RootState>,\n frameloop?: 'always' | 'demand',\n r3m: R3M\n}) {\n const render = useFunction((_gl: WebGL2RenderingContext, projViewMx: number[] | {defaultProjectionData: {mainMatrix: Record<string, number>}}) => {\n const pVMx = 'defaultProjectionData' in projViewMx ? Object.values(projViewMx.defaultProjectionData.mainMatrix) : projViewMx;\n r3m.viewProjMx.splice(0, 16, ...pVMx)\n const state = useThree.getState();\n const camera = state.camera as PerspectiveCamera;\n const {gl, advance} = state;\n syncCamera(camera as PerspectiveCamera, origin, projViewMx as Matrix4Tuple);\n gl.resetState();\n advance(Date.now() * 0.001, true);\n if (!frameloop || frameloop === 'always') map.triggerRepaint();\n })\n return render;\n}"],"names":[],"mappings":";;AAQO,SAAS,UAAU;AAAA,EACxB;AAAA,EAAK;AAAA,EAAQ;AAAA,EAAU;AAAA,EAAW;AACpC,GAMG;AACD,QAAM,SAAS,YAAY,CAAC,KAA6B,eAAyF;AAC1I,UAAA,OAAO,2BAA2B,aAAa,OAAO,OAAO,WAAW,sBAAsB,UAAU,IAAI;AAClH,QAAI,WAAW,OAAO,GAAG,IAAI,GAAG,IAAI;AAC9B,UAAA,QAAQ,SAAS;AACvB,UAAM,SAAS,MAAM;AACf,UAAA,EAAC,IAAI,QAAW,IAAA;AACX,eAAA,QAA6B,QAAQ,UAA0B;AAC1E,OAAG,WAAW;AACd,YAAQ,KAAK,IAAQ,IAAA,MAAO,IAAI;AAC5B,QAAA,CAAC,aAAa,cAAc;AAAU,UAAI,eAAe;AAAA,EAAA,CAC9D;AACM,SAAA;AACT;"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { jsxs, Fragment, jsx } from "react/jsx-runtime";
|
|
2
2
|
import { extend } from "@react-three/fiber";
|
|
3
|
-
import { MercatorCoordinate } from "
|
|
3
|
+
import { MercatorCoordinate } from "maplibre-gl";
|
|
4
4
|
import { memo, useState } from "react";
|
|
5
|
-
import { useMap, Layer } from "react-map-gl";
|
|
5
|
+
import { useMap, Layer } from "react-map-gl/maplibre";
|
|
6
6
|
import * as THREE from "three";
|
|
7
7
|
import { useCanvasInLayer } from "./main8.mjs";
|
|
8
8
|
import { InitCanvasFC } from "./main9.mjs";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"main3.mjs","sources":["../../../src/
|
|
1
|
+
{"version":3,"file":"main3.mjs","sources":["../../../src/maplibre/canvas.tsx"],"sourcesContent":["/* eslint-disable @typescript-eslint/ban-ts-comment */\nimport { extend } from \"@react-three/fiber\";\nimport { MercatorCoordinate } from \"maplibre-gl\";\nimport { memo, useState } from \"react\";\nimport { Layer, useMap } from \"react-map-gl/maplibre\";\nimport * as THREE from \"three\";\nimport { Matrix4Tuple } from \"three\";\nimport { CanvasProps } from \"../api/canvas-props\";\nimport { useCanvasInLayer } from \"../core/canvas-in-layer/use-canvas-in-layer\";\nimport { InitCanvasFC } from \"../core/canvas-overlay/init-canvas-fc\";\nimport { Render } from \"../core/canvas-overlay/render\";\nimport { MapInstance } from \"../core/generic-map\";\nimport { useFunction } from \"../core/use-function\";\n\nextend(THREE);\n\nconst fromLngLat = MercatorCoordinate.fromLngLat\n\n/** `react-three-fiber` canvas inside `MapLibre` */\nexport const Canvas = memo<CanvasProps>(({ overlay, ...props }) => {\n\n const map = useMap().current!.getMap(); // eslint-disable-line @typescript-eslint/no-non-null-assertion\n\n return <>\n {overlay && <CanvasOverlay map={map} {...props} />}\n {!overlay && <CanvasInLayer map={map} {...props} />}\n </>\n})\nCanvas.displayName = 'Canvas'\n\ninterface CanvasPropsAndMap extends CanvasProps {\n map: MapInstance;\n}\n\nconst CanvasInLayer = memo<CanvasPropsAndMap>(({ map, ...props }) => {\n const layerProps = useCanvasInLayer(props, fromLngLat, map);\n /* @ts-ignore */ // eslint-disable-line @typescript-eslint/ban-ts-comment\n return <Layer {...layerProps} />\n})\nCanvasInLayer.displayName = 'CanvasInLayer';\n\nconst CanvasOverlay = memo<CanvasPropsAndMap>(({ map, id, beforeId, ...props }) => {\n const [onRender, setOnRender] = useState<(mx: Matrix4Tuple) => void>();\n\n const render = useFunction<Render>((_gl, mx) => {\n if (!onRender) return;\n onRender(mx as Matrix4Tuple);\n })\n\n return <>\n {/* @ts-ignore */}\n <Layer id={id} beforeId={beforeId} type=\"custom\" render={render} />\n <InitCanvasFC {...props}\n setOnRender={setOnRender}\n map={map}\n fromLngLat={fromLngLat}\n />\n </>\n})\nCanvasInLayer.displayName = 'CanvasInLayer';"],"names":[],"mappings":";;;;;;;;;AAcA,OAAO,KAAK;AAEZ,MAAM,aAAa,mBAAmB;AAG/B,MAAM,SAAS,KAAkB,CAAC,EAAE,SAAS,GAAG,YAAY;AAEjE,QAAM,MAAM,OAAA,EAAS,QAAS,OAAO;AAErC,SACG,qBAAA,UAAA,EAAA,UAAA;AAAA,IAAA,WAAY,oBAAA,eAAA,EAAc,KAAW,GAAG,MAAO,CAAA;AAAA,IAC/C,CAAC,WAAW,oBAAC,eAAc,EAAA,KAAW,GAAG,OAAO;AAAA,EACnD,EAAA,CAAA;AACF,CAAC;AACD,OAAO,cAAc;AAMrB,MAAM,gBAAgB,KAAwB,CAAC,EAAE,KAAK,GAAG,YAAY;AACnE,QAAM,aAAa,iBAAiB,OAAO,YAAY,GAAG;AAEnD,SAAA,oBAAC,OAAO,EAAA,GAAG,WAAY,CAAA;AAChC,CAAC;AACD,cAAc,cAAc;AAE5B,MAAM,gBAAgB,KAAwB,CAAC,EAAE,KAAK,IAAI,UAAU,GAAG,YAAY;AACjF,QAAM,CAAC,UAAU,WAAW,IAAI,SAAqC;AAErE,QAAM,SAAS,YAAoB,CAAC,KAAK,OAAO;AAC9C,QAAI,CAAC;AAAU;AACf,aAAS,EAAkB;AAAA,EAAA,CAC5B;AAED,SAEE,qBAAA,UAAA,EAAA,UAAA;AAAA,IAAA,oBAAC,OAAM,EAAA,IAAQ,UAAoB,MAAK,UAAS,QAAgB;AAAA,IACjE;AAAA,MAAC;AAAA,MAAA;AAAA,QAAc,GAAG;AAAA,QAChB;AAAA,QACA;AAAA,QACA;AAAA,MAAA;AAAA,IACF;AAAA,EACF,EAAA,CAAA;AACF,CAAC;AACD,cAAc,cAAc;"}
|
|
@@ -1,15 +1,35 @@
|
|
|
1
1
|
import { MathUtils } from "three";
|
|
2
2
|
import { earthRadius } from "./main14.mjs";
|
|
3
|
+
const mercatorScaleLookup = {};
|
|
4
|
+
function getMercatorScale(lat) {
|
|
5
|
+
const index = Math.round(lat * 1e3);
|
|
6
|
+
if (mercatorScaleLookup[index] === void 0) {
|
|
7
|
+
mercatorScaleLookup[index] = 1 / Math.cos(lat * MathUtils.DEG2RAD);
|
|
8
|
+
}
|
|
9
|
+
return mercatorScaleLookup[index];
|
|
10
|
+
}
|
|
11
|
+
function averageMercatorScale(originLat, pointLat, steps = 10) {
|
|
12
|
+
let totalScale = 0;
|
|
13
|
+
const latStep = (pointLat - originLat) / steps;
|
|
14
|
+
for (let i = 0; i <= steps; i++) {
|
|
15
|
+
const lat = originLat + latStep * i;
|
|
16
|
+
totalScale += getMercatorScale(lat);
|
|
17
|
+
}
|
|
18
|
+
return totalScale / (steps + 1);
|
|
19
|
+
}
|
|
3
20
|
function coordsToVector3(point, origin) {
|
|
4
21
|
const latitudeDiff = (point.latitude - origin.latitude) * MathUtils.DEG2RAD;
|
|
5
22
|
const longitudeDiff = (point.longitude - origin.longitude) * MathUtils.DEG2RAD;
|
|
6
23
|
const altitudeDiff = (point.altitude || 0) - (origin.altitude || 0);
|
|
7
24
|
const x = longitudeDiff * earthRadius * Math.cos(origin.latitude * MathUtils.DEG2RAD);
|
|
8
25
|
const y = altitudeDiff;
|
|
9
|
-
const
|
|
26
|
+
const steps = Math.ceil(Math.abs(point.latitude - origin.latitude)) * 100 + 1;
|
|
27
|
+
const avgScale = averageMercatorScale(origin.latitude, point.latitude, steps);
|
|
28
|
+
const z = -latitudeDiff * earthRadius / getMercatorScale(origin.latitude) * avgScale;
|
|
10
29
|
return [x, y, z];
|
|
11
30
|
}
|
|
12
31
|
export {
|
|
32
|
+
averageMercatorScale,
|
|
13
33
|
coordsToVector3
|
|
14
34
|
};
|
|
15
35
|
//# sourceMappingURL=main5.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"main5.mjs","sources":["../../../src/api/coords-to-vector-3.ts"],"sourcesContent":["import { MathUtils, Vector3Tuple } from 'three';\nimport { Coords } from './coords';\nimport { earthRadius } from \"../core/earth-radius\";\n\nexport function coordsToVector3(point: Coords, origin: Coords): Vector3Tuple {\n const latitudeDiff = (point.latitude - origin.latitude) * MathUtils.DEG2RAD;\n const longitudeDiff = (point.longitude - origin.longitude) * MathUtils.DEG2RAD;\n const altitudeDiff = (point.altitude || 0) - (origin.altitude || 0);\n\n const x = longitudeDiff * earthRadius * Math.cos(origin.latitude * MathUtils.DEG2RAD);\n const y = altitudeDiff;\n const z = -latitudeDiff * earthRadius;\n
|
|
1
|
+
{"version":3,"file":"main5.mjs","sources":["../../../src/api/coords-to-vector-3.ts"],"sourcesContent":["import { MathUtils, Vector3Tuple } from 'three';\nimport { Coords } from './coords';\nimport { earthRadius } from \"../core/earth-radius\";\n\n\nconst mercatorScaleLookup: { [key: number]: number } = {};\n\nfunction getMercatorScale(lat: number): number {\n const index = Math.round(lat * 1000);\n if (mercatorScaleLookup[index] === undefined) {\n mercatorScaleLookup[index] = 1 / Math.cos(lat * MathUtils.DEG2RAD);\n }\n return mercatorScaleLookup[index];\n}\n\nexport function averageMercatorScale(originLat: number, pointLat: number, steps = 10): number {\n let totalScale = 0;\n const latStep = (pointLat - originLat) / steps;\n for (let i = 0; i <= steps; i++) {\n const lat = originLat + latStep * i;\n totalScale += getMercatorScale(lat);\n }\n return totalScale / (steps + 1);\n}\n\nexport function coordsToVector3(point: Coords, origin: Coords): Vector3Tuple {\n const latitudeDiff = (point.latitude - origin.latitude) * MathUtils.DEG2RAD;\n const longitudeDiff = (point.longitude - origin.longitude) * MathUtils.DEG2RAD;\n const altitudeDiff = (point.altitude || 0) - (origin.altitude || 0);\n\n const x = longitudeDiff * earthRadius * Math.cos(origin.latitude * MathUtils.DEG2RAD);\n const y = altitudeDiff;\n\n // dynamic step size based on latitude difference. calculate the mercator unit scale at origin\n // and the scale average along the line to the point for better accuracy far from origin\n const steps = Math.ceil(Math.abs(point.latitude - origin.latitude)) * 100 + 1;\n const avgScale = averageMercatorScale(origin.latitude, point.latitude, steps);\n\n const z = ((-latitudeDiff * earthRadius) / getMercatorScale(origin.latitude)) * avgScale;\n return [x, y, z] as Vector3Tuple;\n}"],"names":[],"mappings":";;AAKA,MAAM,sBAAiD,CAAA;AAEvD,SAAS,iBAAiB,KAAqB;AAC7C,QAAM,QAAQ,KAAK,MAAM,MAAM,GAAI;AAC/B,MAAA,oBAAoB,KAAK,MAAM,QAAW;AAC5C,wBAAoB,KAAK,IAAI,IAAI,KAAK,IAAI,MAAM,UAAU,OAAO;AAAA,EACnE;AACA,SAAO,oBAAoB,KAAK;AAClC;AAEO,SAAS,qBAAqB,WAAmB,UAAkB,QAAQ,IAAY;AAC5F,MAAI,aAAa;AACX,QAAA,WAAW,WAAW,aAAa;AACzC,WAAS,IAAI,GAAG,KAAK,OAAO,KAAK;AACzB,UAAA,MAAM,YAAY,UAAU;AAClC,kBAAc,iBAAiB,GAAG;AAAA,EACpC;AACA,SAAO,cAAc,QAAQ;AAC/B;AAEgB,SAAA,gBAAgB,OAAe,QAA8B;AAC3E,QAAM,gBAAgB,MAAM,WAAW,OAAO,YAAY,UAAU;AACpE,QAAM,iBAAiB,MAAM,YAAY,OAAO,aAAa,UAAU;AACvE,QAAM,gBAAgB,MAAM,YAAY,MAAM,OAAO,YAAY;AAE3D,QAAA,IAAI,gBAAgB,cAAc,KAAK,IAAI,OAAO,WAAW,UAAU,OAAO;AACpF,QAAM,IAAI;AAIJ,QAAA,QAAQ,KAAK,KAAK,KAAK,IAAI,MAAM,WAAW,OAAO,QAAQ,CAAC,IAAI,MAAM;AAC5E,QAAM,WAAW,qBAAqB,OAAO,UAAU,MAAM,UAAU,KAAK;AAE5E,QAAM,IAAM,CAAC,eAAe,cAAe,iBAAiB,OAAO,QAAQ,IAAK;AACzE,SAAA,CAAC,GAAG,GAAG,CAAC;AACjB;"}
|
|
@@ -5,7 +5,11 @@ export declare function useCanvasInLayer(props: CanvasProps, fromLngLat: FromLng
|
|
|
5
5
|
readonly id: string | undefined;
|
|
6
6
|
readonly beforeId: string | undefined;
|
|
7
7
|
readonly onRemove: () => void;
|
|
8
|
-
readonly render: (_gl: WebGL2RenderingContext, projViewMx: number[]
|
|
8
|
+
readonly render: (_gl: WebGL2RenderingContext, projViewMx: number[] | {
|
|
9
|
+
defaultProjectionData: {
|
|
10
|
+
mainMatrix: Record<string, number>;
|
|
11
|
+
};
|
|
12
|
+
}) => void;
|
|
9
13
|
readonly type: "custom";
|
|
10
14
|
readonly renderingMode: "3d";
|
|
11
15
|
};
|
|
@@ -9,4 +9,8 @@ export declare function useRender({ map, origin, useThree, frameloop, r3m, }: {
|
|
|
9
9
|
useThree: UseBoundStore<RootState>;
|
|
10
10
|
frameloop?: 'always' | 'demand';
|
|
11
11
|
r3m: R3M;
|
|
12
|
-
}): (_gl: WebGL2RenderingContext, projViewMx: number[]
|
|
12
|
+
}): (_gl: WebGL2RenderingContext, projViewMx: number[] | {
|
|
13
|
+
defaultProjectionData: {
|
|
14
|
+
mainMatrix: Record<string, number>;
|
|
15
|
+
};
|
|
16
|
+
}) => void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const earthRadius =
|
|
1
|
+
export declare const earthRadius = 6371008.8;
|
|
@@ -34,8 +34,8 @@ export interface MapInstance {
|
|
|
34
34
|
/** MapLibre only */
|
|
35
35
|
getPixelRatio?: () => number;
|
|
36
36
|
triggerRepaint(): void;
|
|
37
|
-
on<T extends keyof MapEventType>(type: T, listener: (ev: MapEventType[T] & Object) => void):
|
|
38
|
-
off<T extends keyof MapEventType>(type: T, listener: (ev: MapEventType[T] & Object) => void):
|
|
37
|
+
on<T extends keyof MapEventType>(type: T, listener: (ev: MapEventType[T] & Object) => void): void;
|
|
38
|
+
off<T extends keyof MapEventType>(type: T, listener: (ev: MapEventType[T] & Object) => void): void;
|
|
39
39
|
}
|
|
40
40
|
/** Generic interface of Mapbox/Maplibre `MapEventType` */
|
|
41
41
|
export type MapEventType = {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { CanvasProps } from "../api/canvas-props";
|
|
3
|
-
/** react
|
|
3
|
+
/** `react-three-fiber` canvas inside `MapLibre` */
|
|
4
4
|
export declare const Canvas: import("react").NamedExoticComponent<CanvasProps>;
|
|
@@ -5,7 +5,11 @@ export declare function useCanvasInLayer(props: CanvasProps, fromLngLat: FromLng
|
|
|
5
5
|
readonly id: string | undefined;
|
|
6
6
|
readonly beforeId: string | undefined;
|
|
7
7
|
readonly onRemove: () => void;
|
|
8
|
-
readonly render: (_gl: WebGL2RenderingContext, projViewMx: number[]
|
|
8
|
+
readonly render: (_gl: WebGL2RenderingContext, projViewMx: number[] | {
|
|
9
|
+
defaultProjectionData: {
|
|
10
|
+
mainMatrix: Record<string, number>;
|
|
11
|
+
};
|
|
12
|
+
}) => void;
|
|
9
13
|
readonly type: "custom";
|
|
10
14
|
readonly renderingMode: "3d";
|
|
11
15
|
};
|
|
@@ -9,4 +9,8 @@ export declare function useRender({ map, origin, useThree, frameloop, r3m, }: {
|
|
|
9
9
|
useThree: UseBoundStore<RootState>;
|
|
10
10
|
frameloop?: 'always' | 'demand';
|
|
11
11
|
r3m: R3M;
|
|
12
|
-
}): (_gl: WebGL2RenderingContext, projViewMx: number[]
|
|
12
|
+
}): (_gl: WebGL2RenderingContext, projViewMx: number[] | {
|
|
13
|
+
defaultProjectionData: {
|
|
14
|
+
mainMatrix: Record<string, number>;
|
|
15
|
+
};
|
|
16
|
+
}) => void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const earthRadius =
|
|
1
|
+
export declare const earthRadius = 6371008.8;
|
|
@@ -34,8 +34,8 @@ export interface MapInstance {
|
|
|
34
34
|
/** MapLibre only */
|
|
35
35
|
getPixelRatio?: () => number;
|
|
36
36
|
triggerRepaint(): void;
|
|
37
|
-
on<T extends keyof MapEventType>(type: T, listener: (ev: MapEventType[T] & Object) => void):
|
|
38
|
-
off<T extends keyof MapEventType>(type: T, listener: (ev: MapEventType[T] & Object) => void):
|
|
37
|
+
on<T extends keyof MapEventType>(type: T, listener: (ev: MapEventType[T] & Object) => void): void;
|
|
38
|
+
off<T extends keyof MapEventType>(type: T, listener: (ev: MapEventType[T] & Object) => void): void;
|
|
39
39
|
}
|
|
40
40
|
/** Generic interface of Mapbox/Maplibre `MapEventType` */
|
|
41
41
|
export type MapEventType = {
|
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-three-map",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.0-next.0",
|
|
4
4
|
"description": "Use react-three-fiber inside MapLibre and Mapbox",
|
|
5
5
|
"main": "dist/cjs/main.js",
|
|
6
6
|
"module": "dist/es/main.mjs",
|
|
@@ -53,11 +53,11 @@
|
|
|
53
53
|
"happy-dom": "^10.5.2",
|
|
54
54
|
"leva": "^0.9.35",
|
|
55
55
|
"luxon": "^3.3.0",
|
|
56
|
-
"mapbox-gl": "^3.
|
|
57
|
-
"maplibre-gl": "
|
|
56
|
+
"mapbox-gl": "^3.9.4",
|
|
57
|
+
"maplibre-gl": "4.7.1",
|
|
58
58
|
"react": "^18.2.0",
|
|
59
59
|
"react-dom": "^18.2.0",
|
|
60
|
-
"react-map-gl": "^
|
|
60
|
+
"react-map-gl": "^8.0.1",
|
|
61
61
|
"suncalc": "^1.9.0",
|
|
62
62
|
"suspend-react": "^0.1.3",
|
|
63
63
|
"three": "^0.159.0",
|
|
@@ -70,10 +70,10 @@
|
|
|
70
70
|
},
|
|
71
71
|
"peerDependencies": {
|
|
72
72
|
"@react-three/fiber": ">=8.13",
|
|
73
|
-
"mapbox-gl": ">=
|
|
74
|
-
"maplibre-gl": ">=
|
|
73
|
+
"mapbox-gl": ">=3.5.0",
|
|
74
|
+
"maplibre-gl": ">=4.0.0",
|
|
75
75
|
"react": ">=18.0",
|
|
76
|
-
"react-map-gl": ">=
|
|
76
|
+
"react-map-gl": ">=8.0.0",
|
|
77
77
|
"three": ">=0.133"
|
|
78
78
|
},
|
|
79
79
|
"peerDependenciesMeta": {
|
package/stories/package.json
CHANGED
|
@@ -15,12 +15,12 @@
|
|
|
15
15
|
"@types/tz-lookup": "^6.1.2",
|
|
16
16
|
"leva": "^0.9.35",
|
|
17
17
|
"luxon": "^3.4.4",
|
|
18
|
-
"mapbox-gl": "^3.
|
|
19
|
-
"maplibre-gl": "^
|
|
18
|
+
"mapbox-gl": "^3.9.4",
|
|
19
|
+
"maplibre-gl": "^5.1.0",
|
|
20
20
|
"react": "^18.2.0",
|
|
21
21
|
"react-dom": "^18.2.0",
|
|
22
|
-
"react-map-gl": "^
|
|
23
|
-
"react-three-map": "^0.
|
|
22
|
+
"react-map-gl": "^8.0.1",
|
|
23
|
+
"react-three-map": "^0.8.1",
|
|
24
24
|
"suncalc": "^1.9.0",
|
|
25
25
|
"three": "^0.159.0",
|
|
26
26
|
"three-stdlib": "^2.28.7",
|