@treasuryspatial/map-react 0.1.8 → 0.1.9
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MapModeViewport.d.ts","sourceRoot":"","sources":["../src/MapModeViewport.tsx"],"names":[],"mappings":"AAEA,OAAO,KAA6F,MAAM,OAAO,CAAC;AAElH,OAAO,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAEhD,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EASL,KAAK,cAAc,EACnB,KAAK,qBAAqB,EAC3B,MAAM,0BAA0B,CAAC;AAElC,MAAM,MAAM,gBAAgB,GAAG;IAC7B,SAAS,EAAE,qBAAqB,CAAC;IACjC,OAAO,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC;IAC1B,WAAW,EAAE,MAAM,EAAE,EAAE,CAAC;IACxB,KAAK,EAAE,cAAc,CAAC;IACtB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,MAAM,MAAM,qBAAqB,GAAG;IAClC,iBAAiB,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,IAAI,CAAC;IAC/C,aAAa,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,IAAI,CAAC;IAC1C,iBAAiB,EAAE,MAAM,MAAM,CAAC;CACjC,CAAC;AAIF,MAAM,MAAM,mBAAmB,GAAG,CAAC,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE,QAAQ,EAAE,KAAK,CAAC,aAAa,EAAE,SAAS,EAAE,MAAM,KAAK,IAAI,CAAC;AACjH,MAAM,MAAM,gBAAgB,GAAG,CAAC,WAAW,EAAE,MAAM,KAAK,OAAO,CAAC,KAAK,CAAC,KAAK,GAAG,IAAI,CAAC,CAAC;AAEpF,MAAM,MAAM,oBAAoB,GAAG;IACjC,MAAM,EAAE,OAAO,CAAC;IAChB,WAAW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AAM,IAAI,CAAC;IAC7B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,mBAAmB,CAAC,EAAE,mBAAmB,CAAC;IAC1C,gBAAgB,CAAC,EAAE,gBAAgB,CAAC;CACrC,CAAC;AAMF,eAAO,MAAM,eAAe,oGAma1B,CAAC"}
|
package/dist/MapModeViewport.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
-
import { forwardRef, useEffect, useImperativeHandle, useMemo, useRef, useState } from 'react';
|
|
3
|
+
import { forwardRef, useCallback, useEffect, useImperativeHandle, useMemo, useRef, useState } from 'react';
|
|
4
4
|
import MapboxGeocoder from '@mapbox/mapbox-gl-geocoder';
|
|
5
5
|
import * as THREE from 'three';
|
|
6
6
|
import { buildGeoJsonPolygon, computeCentroid, computeFootprintStats, createMapThreeLayer, ensureFootprintLayers, getOuterRing, toLocalMeters, toPolygonFeature, } from '@treasuryspatial/map-kit';
|
|
@@ -25,6 +25,17 @@ export const MapModeViewport = forwardRef(function MapModeViewport({ active, geo
|
|
|
25
25
|
const reverseGeocodeRequestRef = useRef(0);
|
|
26
26
|
const [mapReady, setMapReady] = useState(false);
|
|
27
27
|
const [mapError, setMapError] = useState('');
|
|
28
|
+
const debug = useMemo(() => {
|
|
29
|
+
if (typeof window === 'undefined')
|
|
30
|
+
return false;
|
|
31
|
+
const params = new URLSearchParams(window.location.search);
|
|
32
|
+
return params.has('mapDebug') || process.env.NODE_ENV !== 'production';
|
|
33
|
+
}, []);
|
|
34
|
+
const log = useCallback((...args) => {
|
|
35
|
+
if (!debug)
|
|
36
|
+
return;
|
|
37
|
+
console.info('[map-react]', ...args);
|
|
38
|
+
}, [debug]);
|
|
28
39
|
useEffect(() => {
|
|
29
40
|
lightingPresetRef.current = lightingPreset;
|
|
30
41
|
}, [lightingPreset]);
|
|
@@ -71,6 +82,8 @@ export const MapModeViewport = forwardRef(function MapModeViewport({ active, geo
|
|
|
71
82
|
return;
|
|
72
83
|
}
|
|
73
84
|
let cancelled = false;
|
|
85
|
+
let cleanupCanvasEvents = null;
|
|
86
|
+
let cleanupMapEvents = null;
|
|
74
87
|
const boot = async () => {
|
|
75
88
|
try {
|
|
76
89
|
const module = await import('mapbox-gl');
|
|
@@ -95,6 +108,13 @@ export const MapModeViewport = forwardRef(function MapModeViewport({ active, geo
|
|
|
95
108
|
preserveDrawingBuffer: true,
|
|
96
109
|
attributionControl: false,
|
|
97
110
|
});
|
|
111
|
+
log('map init', {
|
|
112
|
+
style: mapStyle,
|
|
113
|
+
center: [startCenter.lng, startCenter.lat],
|
|
114
|
+
zoom: startZoom,
|
|
115
|
+
bearing: startBearing,
|
|
116
|
+
pitch: startPitch,
|
|
117
|
+
});
|
|
98
118
|
map.addControl(new mapboxgl.NavigationControl({ visualizePitch: true }), 'bottom-right');
|
|
99
119
|
const geocoder = new MapboxGeocoder({
|
|
100
120
|
accessToken,
|
|
@@ -106,6 +126,30 @@ export const MapModeViewport = forwardRef(function MapModeViewport({ active, geo
|
|
|
106
126
|
});
|
|
107
127
|
map.addControl(geocoder, 'top-left');
|
|
108
128
|
mapRef.current = map;
|
|
129
|
+
const onMapError = (event) => {
|
|
130
|
+
const err = event?.error ?? event;
|
|
131
|
+
console.error('[map-react] Mapbox error', err);
|
|
132
|
+
};
|
|
133
|
+
map.on('error', onMapError);
|
|
134
|
+
cleanupMapEvents = () => {
|
|
135
|
+
map.off('error', onMapError);
|
|
136
|
+
};
|
|
137
|
+
const canvas = map.getCanvas();
|
|
138
|
+
const onContextLost = (event) => {
|
|
139
|
+
event.preventDefault();
|
|
140
|
+
console.error('[map-react] WebGL context lost');
|
|
141
|
+
setMapError('WebGL context lost.');
|
|
142
|
+
};
|
|
143
|
+
const onContextRestored = () => {
|
|
144
|
+
console.info('[map-react] WebGL context restored');
|
|
145
|
+
setMapError('');
|
|
146
|
+
};
|
|
147
|
+
canvas.addEventListener('webglcontextlost', onContextLost, { passive: false });
|
|
148
|
+
canvas.addEventListener('webglcontextrestored', onContextRestored);
|
|
149
|
+
cleanupCanvasEvents = () => {
|
|
150
|
+
canvas.removeEventListener('webglcontextlost', onContextLost);
|
|
151
|
+
canvas.removeEventListener('webglcontextrestored', onContextRestored);
|
|
152
|
+
};
|
|
109
153
|
map.on('style.load', () => {
|
|
110
154
|
if (!map.isStyleLoaded())
|
|
111
155
|
return;
|
|
@@ -153,6 +197,8 @@ export const MapModeViewport = forwardRef(function MapModeViewport({ active, geo
|
|
|
153
197
|
threeLayerRef.current = null;
|
|
154
198
|
setMapReady(false);
|
|
155
199
|
handlersBoundRef.current = false;
|
|
200
|
+
cleanupCanvasEvents?.();
|
|
201
|
+
cleanupMapEvents?.();
|
|
156
202
|
};
|
|
157
203
|
}, [active, accessToken, mapStyle, mapVisibility]);
|
|
158
204
|
useEffect(() => {
|
|
@@ -223,6 +269,7 @@ export const MapModeViewport = forwardRef(function MapModeViewport({ active, geo
|
|
|
223
269
|
threeLayerRef.current = createMapThreeLayer({
|
|
224
270
|
id: 'courtyard-mesh',
|
|
225
271
|
zOffsetMeters: 0.05,
|
|
272
|
+
debug,
|
|
226
273
|
onInit: (scene, renderer) => {
|
|
227
274
|
sceneRef.current = scene;
|
|
228
275
|
rendererRef.current = renderer;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@treasuryspatial/map-react",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.9",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"access": "public"
|
|
19
19
|
},
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@treasuryspatial/map-kit": "^0.1.
|
|
21
|
+
"@treasuryspatial/map-kit": "^0.1.4"
|
|
22
22
|
},
|
|
23
23
|
"peerDependencies": {
|
|
24
24
|
"react": ">=18",
|