@treasuryspatial/map-react 0.1.9 → 0.1.11
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,oGAyc1B,CAAC"}
|
package/dist/MapModeViewport.js
CHANGED
|
@@ -23,8 +23,10 @@ export const MapModeViewport = forwardRef(function MapModeViewport({ active, geo
|
|
|
23
23
|
const onCandidateClearRef = useRef(onCandidateClear);
|
|
24
24
|
const lastGeocodeLabelRef = useRef(null);
|
|
25
25
|
const reverseGeocodeRequestRef = useRef(0);
|
|
26
|
+
const resizeObserverRef = useRef(null);
|
|
26
27
|
const [mapReady, setMapReady] = useState(false);
|
|
27
28
|
const [mapError, setMapError] = useState('');
|
|
29
|
+
const [threeLayerReady, setThreeLayerReady] = useState(false);
|
|
28
30
|
const debug = useMemo(() => {
|
|
29
31
|
if (typeof window === 'undefined')
|
|
30
32
|
return false;
|
|
@@ -150,6 +152,24 @@ export const MapModeViewport = forwardRef(function MapModeViewport({ active, geo
|
|
|
150
152
|
canvas.removeEventListener('webglcontextlost', onContextLost);
|
|
151
153
|
canvas.removeEventListener('webglcontextrestored', onContextRestored);
|
|
152
154
|
};
|
|
155
|
+
const container = containerRef.current;
|
|
156
|
+
if (container && typeof ResizeObserver !== 'undefined') {
|
|
157
|
+
const observer = new ResizeObserver(() => {
|
|
158
|
+
if (!mapRef.current)
|
|
159
|
+
return;
|
|
160
|
+
mapRef.current.resize();
|
|
161
|
+
if (debug) {
|
|
162
|
+
const mapCanvas = mapRef.current.getCanvas();
|
|
163
|
+
log('map resize', {
|
|
164
|
+
canvasSize: { width: mapCanvas.width, height: mapCanvas.height },
|
|
165
|
+
canvasRect: mapCanvas.getBoundingClientRect(),
|
|
166
|
+
containerRect: container.getBoundingClientRect(),
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
});
|
|
170
|
+
observer.observe(container);
|
|
171
|
+
resizeObserverRef.current = observer;
|
|
172
|
+
}
|
|
153
173
|
map.on('style.load', () => {
|
|
154
174
|
if (!map.isStyleLoaded())
|
|
155
175
|
return;
|
|
@@ -169,6 +189,17 @@ export const MapModeViewport = forwardRef(function MapModeViewport({ active, geo
|
|
|
169
189
|
applyMapVisibility(map, mapVisibility, opacityCacheRef);
|
|
170
190
|
setMapReady(true);
|
|
171
191
|
bindFootprintHandlers(map);
|
|
192
|
+
requestAnimationFrame(() => {
|
|
193
|
+
map.resize();
|
|
194
|
+
if (debug) {
|
|
195
|
+
const mapCanvas = map.getCanvas();
|
|
196
|
+
log('map load', {
|
|
197
|
+
canvasSize: { width: mapCanvas.width, height: mapCanvas.height },
|
|
198
|
+
canvasRect: mapCanvas.getBoundingClientRect(),
|
|
199
|
+
containerRect: map.getContainer().getBoundingClientRect(),
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
});
|
|
172
203
|
});
|
|
173
204
|
geocoder.on('result', (event) => {
|
|
174
205
|
const center = event?.result?.center;
|
|
@@ -197,6 +228,8 @@ export const MapModeViewport = forwardRef(function MapModeViewport({ active, geo
|
|
|
197
228
|
threeLayerRef.current = null;
|
|
198
229
|
setMapReady(false);
|
|
199
230
|
handlersBoundRef.current = false;
|
|
231
|
+
resizeObserverRef.current?.disconnect();
|
|
232
|
+
resizeObserverRef.current = null;
|
|
200
233
|
cleanupCanvasEvents?.();
|
|
201
234
|
cleanupMapEvents?.();
|
|
202
235
|
};
|
|
@@ -232,7 +265,7 @@ export const MapModeViewport = forwardRef(function MapModeViewport({ active, geo
|
|
|
232
265
|
return;
|
|
233
266
|
}
|
|
234
267
|
threeLayerRef.current.setOrigin(confirmedSelection.origin);
|
|
235
|
-
}, [mapReady, confirmedSelection]);
|
|
268
|
+
}, [mapReady, confirmedSelection, threeLayerReady]);
|
|
236
269
|
useEffect(() => {
|
|
237
270
|
if (!mapReady)
|
|
238
271
|
return;
|
|
@@ -278,11 +311,16 @@ export const MapModeViewport = forwardRef(function MapModeViewport({ active, geo
|
|
|
278
311
|
(applyLightingPreset ?? defaultApplyLightingPreset)(scene, renderer, lightingPresetRef.current);
|
|
279
312
|
},
|
|
280
313
|
});
|
|
314
|
+
setThreeLayerReady(true);
|
|
281
315
|
}
|
|
282
316
|
const layer = threeLayerRef.current.layer;
|
|
283
317
|
if (!map.getLayer(layer.id)) {
|
|
284
318
|
map.addLayer(layer);
|
|
285
319
|
}
|
|
320
|
+
const selection = confirmedSelectionRef.current;
|
|
321
|
+
if (selection) {
|
|
322
|
+
threeLayerRef.current?.setOrigin(selection.origin);
|
|
323
|
+
}
|
|
286
324
|
};
|
|
287
325
|
const bindFootprintHandlers = (map) => {
|
|
288
326
|
if (handlersBoundRef.current)
|
|
@@ -386,6 +424,8 @@ const ensureGeometryUvs = (geometry) => {
|
|
|
386
424
|
geometry.setAttribute('uv', new THREE.BufferAttribute(uvs, 2));
|
|
387
425
|
};
|
|
388
426
|
function applyMaterialOverrides(group, settings) {
|
|
427
|
+
if (!group || typeof group.traverse !== 'function')
|
|
428
|
+
return;
|
|
389
429
|
const color = new THREE.Color(settings?.color ?? '#ffffff');
|
|
390
430
|
const textureUrl = settings?.textureUrl;
|
|
391
431
|
const repeat = settings?.textureRepeat ?? 2;
|