react-bkoi-gl 2.0.0 → 2.1.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/LICENSE +21 -0
- package/README.md +1429 -176
- package/dist/index.cjs +1299 -266
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +870 -0
- package/dist/index.d.ts +870 -2
- package/dist/index.js +2420 -2
- package/dist/index.js.map +1 -1
- package/dist/styles/react-bkoi-gl.css +95 -1
- package/package.json +83 -31
- package/dist/components/attribution-control.d.ts +0 -9
- package/dist/components/attribution-control.js +0 -20
- package/dist/components/attribution-control.js.map +0 -1
- package/dist/components/fullscreen-control.d.ts +0 -12
- package/dist/components/fullscreen-control.js +0 -21
- package/dist/components/fullscreen-control.js.map +0 -1
- package/dist/components/geolocate-control.d.ts +0 -21
- package/dist/components/geolocate-control.js +0 -46
- package/dist/components/geolocate-control.js.map +0 -1
- package/dist/components/layer.d.ts +0 -18
- package/dist/components/layer.js +0 -98
- package/dist/components/layer.js.map +0 -1
- package/dist/components/logo-control.d.ts +0 -9
- package/dist/components/logo-control.js +0 -28
- package/dist/components/logo-control.js.map +0 -1
- package/dist/components/map.d.ts +0 -27
- package/dist/components/map.js +0 -108
- package/dist/components/map.js.map +0 -1
- package/dist/components/marker.d.ts +0 -18
- package/dist/components/marker.js +0 -105
- package/dist/components/marker.js.map +0 -1
- package/dist/components/navigation-control.d.ts +0 -9
- package/dist/components/navigation-control.js +0 -19
- package/dist/components/navigation-control.js.map +0 -1
- package/dist/components/popup.d.ts +0 -15
- package/dist/components/popup.js +0 -68
- package/dist/components/popup.js.map +0 -1
- package/dist/components/scale-control.d.ts +0 -11
- package/dist/components/scale-control.js +0 -31
- package/dist/components/scale-control.js.map +0 -1
- package/dist/components/source.d.ts +0 -6
- package/dist/components/source.js +0 -95
- package/dist/components/source.js.map +0 -1
- package/dist/components/terrain-control.d.ts +0 -10
- package/dist/components/terrain-control.js +0 -19
- package/dist/components/terrain-control.js.map +0 -1
- package/dist/components/use-control.d.ts +0 -9
- package/dist/components/use-control.js +0 -30
- package/dist/components/use-control.js.map +0 -1
- package/dist/components/use-map.d.ts +0 -19
- package/dist/components/use-map.js +0 -54
- package/dist/components/use-map.js.map +0 -1
- package/dist/exports-maplibre-gl.d.ts +0 -33
- package/dist/exports-maplibre-gl.js +0 -21
- package/dist/exports-maplibre-gl.js.map +0 -1
- package/dist/maplibre/create-ref.d.ts +0 -9
- package/dist/maplibre/create-ref.js +0 -30
- package/dist/maplibre/create-ref.js.map +0 -1
- package/dist/maplibre/maplibre.d.ts +0 -81
- package/dist/maplibre/maplibre.js +0 -387
- package/dist/maplibre/maplibre.js.map +0 -1
- package/dist/styles.d.js +0 -2
- package/dist/styles.d.js.map +0 -1
- package/dist/tsconfig.build.tsbuildinfo +0 -1
- package/dist/types/common.d.ts +0 -20
- package/dist/types/common.js +0 -2
- package/dist/types/common.js.map +0 -1
- package/dist/types/events.d.ts +0 -80
- package/dist/types/events.js +0 -2
- package/dist/types/events.js.map +0 -1
- package/dist/types/internal.d.ts +0 -14
- package/dist/types/internal.js +0 -2
- package/dist/types/internal.js.map +0 -1
- package/dist/types/lib.d.ts +0 -40
- package/dist/types/lib.js +0 -2
- package/dist/types/lib.js.map +0 -1
- package/dist/types/style-spec.d.ts +0 -1
- package/dist/types/style-spec.js +0 -2
- package/dist/types/style-spec.js.map +0 -1
- package/dist/utils/apply-react-style.d.ts +0 -2
- package/dist/utils/apply-react-style.js +0 -16
- package/dist/utils/apply-react-style.js.map +0 -1
- package/dist/utils/assert.d.ts +0 -1
- package/dist/utils/assert.js +0 -6
- package/dist/utils/assert.js.map +0 -1
- package/dist/utils/compare-class-names.d.ts +0 -2
- package/dist/utils/compare-class-names.js +0 -23
- package/dist/utils/compare-class-names.js.map +0 -1
- package/dist/utils/deep-equal.d.ts +0 -15
- package/dist/utils/deep-equal.js +0 -46
- package/dist/utils/deep-equal.js.map +0 -1
- package/dist/utils/set-globals.d.ts +0 -20
- package/dist/utils/set-globals.js +0 -31
- package/dist/utils/set-globals.js.map +0 -1
- package/dist/utils/style-utils.d.ts +0 -3
- package/dist/utils/style-utils.js +0 -42
- package/dist/utils/style-utils.js.map +0 -1
- package/dist/utils/transform.d.ts +0 -18
- package/dist/utils/transform.js +0 -33
- package/dist/utils/transform.js.map +0 -1
- package/dist/utils/use-isomorphic-layout-effect.d.ts +0 -3
- package/dist/utils/use-isomorphic-layout-effect.js +0 -4
- package/dist/utils/use-isomorphic-layout-effect.js.map +0 -1
- package/src/components/attribution-control.ts +0 -56
- package/src/components/fullscreen-control.ts +0 -40
- package/src/components/geolocate-control.ts +0 -96
- package/src/components/layer.ts +0 -141
- package/src/components/logo-control.ts +0 -44
- package/src/components/map.tsx +0 -166
- package/src/components/marker.ts +0 -155
- package/src/components/navigation-control.ts +0 -28
- package/src/components/popup.ts +0 -113
- package/src/components/scale-control.ts +0 -44
- package/src/components/source.ts +0 -159
- package/src/components/terrain-control.ts +0 -29
- package/src/components/use-control.ts +0 -68
- package/src/components/use-map.tsx +0 -71
- package/src/exports-maplibre-gl.ts +0 -37
- package/src/index.ts +0 -3
- package/src/maplibre/create-ref.ts +0 -70
- package/src/maplibre/maplibre.ts +0 -624
- package/src/styles.d.ts +0 -4
- package/src/types/common.ts +0 -34
- package/src/types/events.ts +0 -133
- package/src/types/internal.ts +0 -26
- package/src/types/lib.ts +0 -84
- package/src/types/style-spec.ts +0 -34
- package/src/utils/apply-react-style.ts +0 -24
- package/src/utils/assert.ts +0 -5
- package/src/utils/compare-class-names.ts +0 -29
- package/src/utils/deep-equal.ts +0 -61
- package/src/utils/set-globals.ts +0 -51
- package/src/utils/style-utils.ts +0 -68
- package/src/utils/transform.ts +0 -58
- package/src/utils/use-isomorphic-layout-effect.ts +0 -8
package/dist/index.cjs
CHANGED
|
@@ -1,26 +1,9 @@
|
|
|
1
1
|
var __create = Object.create;
|
|
2
2
|
var __defProp = Object.defineProperty;
|
|
3
|
-
var __defProps = Object.defineProperties;
|
|
4
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
6
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
8
5
|
var __getProtoOf = Object.getPrototypeOf;
|
|
9
6
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
10
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
11
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
12
|
-
var __spreadValues = (a, b) => {
|
|
13
|
-
for (var prop in b || (b = {}))
|
|
14
|
-
if (__hasOwnProp.call(b, prop))
|
|
15
|
-
__defNormalProp(a, prop, b[prop]);
|
|
16
|
-
if (__getOwnPropSymbols)
|
|
17
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
18
|
-
if (__propIsEnum.call(b, prop))
|
|
19
|
-
__defNormalProp(a, prop, b[prop]);
|
|
20
|
-
}
|
|
21
|
-
return a;
|
|
22
|
-
};
|
|
23
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
24
7
|
var __export = (target, all) => {
|
|
25
8
|
for (var name in all)
|
|
26
9
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -44,16 +27,21 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
44
27
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
45
28
|
|
|
46
29
|
// src/index.ts
|
|
47
|
-
var
|
|
48
|
-
__export(
|
|
30
|
+
var index_exports = {};
|
|
31
|
+
__export(index_exports, {
|
|
49
32
|
AttributionControl: () => AttributionControl,
|
|
33
|
+
CanvasSource: () => CanvasSource,
|
|
34
|
+
DrawControl: () => DrawControl,
|
|
50
35
|
FullscreenControl: () => FullscreenControl,
|
|
51
36
|
GeolocateControl: () => GeolocateControl,
|
|
37
|
+
GlobeControl: () => GlobeControl,
|
|
52
38
|
Layer: () => Layer,
|
|
53
39
|
LogoControl: () => LogoControl,
|
|
54
40
|
Map: () => Map,
|
|
55
41
|
MapProvider: () => MapProvider,
|
|
56
42
|
Marker: () => Marker,
|
|
43
|
+
Minimap: () => Minimap,
|
|
44
|
+
MinimapControl: () => MinimapControl,
|
|
57
45
|
NavigationControl: () => NavigationControl,
|
|
58
46
|
Popup: () => Popup,
|
|
59
47
|
ScaleControl: () => ScaleControl,
|
|
@@ -63,7 +51,7 @@ __export(src_exports, {
|
|
|
63
51
|
useControl: () => useControl,
|
|
64
52
|
useMap: () => useMap
|
|
65
53
|
});
|
|
66
|
-
module.exports = __toCommonJS(
|
|
54
|
+
module.exports = __toCommonJS(index_exports);
|
|
67
55
|
|
|
68
56
|
// src/components/map.tsx
|
|
69
57
|
var React2 = __toESM(require("react"), 1);
|
|
@@ -83,13 +71,13 @@ var MapProvider = (props) => {
|
|
|
83
71
|
if (currMaps[id]) {
|
|
84
72
|
throw new Error(`Multiple maps with the same id: ${id}`);
|
|
85
73
|
}
|
|
86
|
-
return
|
|
74
|
+
return { ...currMaps, [id]: map };
|
|
87
75
|
});
|
|
88
76
|
}, []);
|
|
89
77
|
const onMapUnmount = (0, import_react.useCallback)((id = "default") => {
|
|
90
78
|
setMaps((currMaps) => {
|
|
91
79
|
if (currMaps[id]) {
|
|
92
|
-
const nextMaps =
|
|
80
|
+
const nextMaps = { ...currMaps };
|
|
93
81
|
delete nextMaps[id];
|
|
94
82
|
return nextMaps;
|
|
95
83
|
}
|
|
@@ -109,11 +97,11 @@ var MapProvider = (props) => {
|
|
|
109
97
|
);
|
|
110
98
|
};
|
|
111
99
|
function useMap() {
|
|
112
|
-
|
|
113
|
-
const maps = (_a = (0, import_react.useContext)(MountedMapsContext)) == null ? void 0 : _a.maps;
|
|
100
|
+
const maps = (0, import_react.useContext)(MountedMapsContext)?.maps;
|
|
114
101
|
const currentMap = (0, import_react.useContext)(MapContext);
|
|
115
102
|
const mapsWithCurrent = (0, import_react.useMemo)(() => {
|
|
116
|
-
|
|
103
|
+
const current = currentMap?.map || (maps ? Object.values(maps)[0] : void 0);
|
|
104
|
+
return { ...maps, current };
|
|
117
105
|
}, [maps, currentMap]);
|
|
118
106
|
return mapsWithCurrent;
|
|
119
107
|
}
|
|
@@ -153,7 +141,7 @@ function deepEqual(a, b) {
|
|
|
153
141
|
return false;
|
|
154
142
|
}
|
|
155
143
|
for (const key of aKeys) {
|
|
156
|
-
if (!
|
|
144
|
+
if (!Object.prototype.hasOwnProperty.call(b, key)) {
|
|
157
145
|
return false;
|
|
158
146
|
}
|
|
159
147
|
if (!deepEqual(a[key], b[key])) {
|
|
@@ -199,15 +187,7 @@ function applyViewStateToTransform(tr, props) {
|
|
|
199
187
|
}
|
|
200
188
|
|
|
201
189
|
// src/utils/style-utils.ts
|
|
202
|
-
var refProps = [
|
|
203
|
-
"type",
|
|
204
|
-
"source",
|
|
205
|
-
"source-layer",
|
|
206
|
-
"minzoom",
|
|
207
|
-
"maxzoom",
|
|
208
|
-
"filter",
|
|
209
|
-
"layout"
|
|
210
|
-
];
|
|
190
|
+
var refProps = ["type", "source", "source-layer", "minzoom", "maxzoom", "filter", "layout"];
|
|
211
191
|
function normalizeStyle(style) {
|
|
212
192
|
if (!style) {
|
|
213
193
|
return null;
|
|
@@ -226,14 +206,15 @@ function normalizeStyle(style) {
|
|
|
226
206
|
layerIndex[layer.id] = layer;
|
|
227
207
|
}
|
|
228
208
|
const layers = style.layers.map((layer) => {
|
|
209
|
+
const legacyLayer = layer;
|
|
229
210
|
let normalizedLayer = null;
|
|
230
|
-
if ("interactive" in
|
|
231
|
-
normalizedLayer = Object.assign({},
|
|
211
|
+
if ("interactive" in legacyLayer) {
|
|
212
|
+
normalizedLayer = Object.assign({}, legacyLayer);
|
|
232
213
|
delete normalizedLayer.interactive;
|
|
233
214
|
}
|
|
234
|
-
const layerRef = layerIndex[
|
|
215
|
+
const layerRef = layerIndex[legacyLayer.ref];
|
|
235
216
|
if (layerRef) {
|
|
236
|
-
normalizedLayer = normalizedLayer || Object.assign({},
|
|
217
|
+
normalizedLayer = normalizedLayer || Object.assign({}, legacyLayer);
|
|
237
218
|
delete normalizedLayer.ref;
|
|
238
219
|
for (const propName of refProps) {
|
|
239
220
|
if (propName in layerRef) {
|
|
@@ -243,7 +224,7 @@ function normalizeStyle(style) {
|
|
|
243
224
|
}
|
|
244
225
|
return normalizedLayer || layer;
|
|
245
226
|
});
|
|
246
|
-
return
|
|
227
|
+
return { ...style, layers };
|
|
247
228
|
}
|
|
248
229
|
|
|
249
230
|
// src/maplibre/maplibre.ts
|
|
@@ -319,7 +300,7 @@ var handlerNames = [
|
|
|
319
300
|
"touchZoomRotate",
|
|
320
301
|
"touchPitch"
|
|
321
302
|
];
|
|
322
|
-
var
|
|
303
|
+
var Maplibre = class _Maplibre {
|
|
323
304
|
constructor(MapClass, props, container) {
|
|
324
305
|
// mapboxgl.Map instance
|
|
325
306
|
this._map = null;
|
|
@@ -329,7 +310,8 @@ var _Maplibre = class {
|
|
|
329
310
|
this._propsedCameraUpdate = null;
|
|
330
311
|
this._styleComponents = {};
|
|
331
312
|
this._onEvent = (e) => {
|
|
332
|
-
const
|
|
313
|
+
const handlerName = otherEvents[e.type];
|
|
314
|
+
const cb = this.props[handlerName];
|
|
333
315
|
if (cb) {
|
|
334
316
|
cb(e);
|
|
335
317
|
} else if (e.type === "error") {
|
|
@@ -341,7 +323,8 @@ var _Maplibre = class {
|
|
|
341
323
|
return;
|
|
342
324
|
}
|
|
343
325
|
e.viewState = this._propsedCameraUpdate || transformToViewState(this._map.transform);
|
|
344
|
-
const
|
|
326
|
+
const handlerName = cameraEvents[e.type];
|
|
327
|
+
const cb = this.props[handlerName];
|
|
345
328
|
if (cb) {
|
|
346
329
|
cb(e);
|
|
347
330
|
}
|
|
@@ -357,7 +340,8 @@ var _Maplibre = class {
|
|
|
357
340
|
if (e.type === "mousemove" || e.type === "mouseout") {
|
|
358
341
|
this._updateHover(e);
|
|
359
342
|
}
|
|
360
|
-
const
|
|
343
|
+
const handlerName = pointerEvents[e.type];
|
|
344
|
+
const cb = this.props[handlerName];
|
|
361
345
|
if (cb) {
|
|
362
346
|
if (this.props.interactiveLayerIds && e.type !== "mouseover" && e.type !== "mouseout") {
|
|
363
347
|
e.features = this._hoveredFeatures || this._queryRenderedFeatures(e.point);
|
|
@@ -370,6 +354,9 @@ var _Maplibre = class {
|
|
|
370
354
|
this.props = props;
|
|
371
355
|
this._initialize(container);
|
|
372
356
|
}
|
|
357
|
+
static {
|
|
358
|
+
this.savedMaps = [];
|
|
359
|
+
}
|
|
373
360
|
get map() {
|
|
374
361
|
return this._map;
|
|
375
362
|
}
|
|
@@ -397,20 +384,22 @@ var _Maplibre = class {
|
|
|
397
384
|
while (oldContainer.childNodes.length > 0) {
|
|
398
385
|
container.appendChild(oldContainer.childNodes[0]);
|
|
399
386
|
}
|
|
400
|
-
|
|
401
|
-
|
|
387
|
+
const mapInternal = map;
|
|
388
|
+
mapInternal._container = container;
|
|
389
|
+
const resizeObserver = mapInternal._resizeObserver;
|
|
402
390
|
if (resizeObserver) {
|
|
403
391
|
resizeObserver.disconnect();
|
|
404
392
|
resizeObserver.observe(container);
|
|
405
393
|
}
|
|
406
|
-
that.setProps(
|
|
394
|
+
that.setProps({ ...props, styleDiffing: false });
|
|
407
395
|
map.resize();
|
|
408
396
|
const { initialViewState } = props;
|
|
409
397
|
if (initialViewState) {
|
|
410
398
|
if (initialViewState.bounds) {
|
|
411
|
-
map.fitBounds(initialViewState.bounds,
|
|
399
|
+
map.fitBounds(initialViewState.bounds, {
|
|
400
|
+
...initialViewState.fitBoundsOptions,
|
|
412
401
|
duration: 0
|
|
413
|
-
})
|
|
402
|
+
});
|
|
414
403
|
} else {
|
|
415
404
|
that._updateViewState(initialViewState);
|
|
416
405
|
}
|
|
@@ -420,17 +409,19 @@ var _Maplibre = class {
|
|
|
420
409
|
} else {
|
|
421
410
|
map.once("style.load", () => map.fire("load"));
|
|
422
411
|
}
|
|
423
|
-
map
|
|
412
|
+
const mapInternalForUpdate = map;
|
|
413
|
+
mapInternalForUpdate._update();
|
|
424
414
|
return that;
|
|
425
415
|
}
|
|
426
|
-
/* eslint-disable complexity,max-statements */
|
|
427
416
|
_initialize(container) {
|
|
428
417
|
const { props } = this;
|
|
429
418
|
const { mapStyle = DEFAULT_STYLE } = props;
|
|
430
|
-
const mapOptions =
|
|
419
|
+
const mapOptions = {
|
|
420
|
+
...props,
|
|
421
|
+
...props.initialViewState,
|
|
431
422
|
container,
|
|
432
423
|
style: normalizeStyle(mapStyle)
|
|
433
|
-
}
|
|
424
|
+
};
|
|
434
425
|
const viewState = mapOptions.initialViewState || mapOptions.viewState || mapOptions;
|
|
435
426
|
Object.assign(mapOptions, {
|
|
436
427
|
center: [viewState.longitude || 0, viewState.latitude || 0],
|
|
@@ -454,12 +445,11 @@ var _Maplibre = class {
|
|
|
454
445
|
}
|
|
455
446
|
map.transformCameraUpdate = this._onCameraUpdate;
|
|
456
447
|
map.on("style.load", () => {
|
|
457
|
-
|
|
448
|
+
const mapWithProjection = map;
|
|
458
449
|
this._styleComponents = {
|
|
459
450
|
light: map.getLight(),
|
|
460
451
|
sky: map.getSky(),
|
|
461
|
-
|
|
462
|
-
projection: (_a = map.getProjection) == null ? void 0 : _a.call(map),
|
|
452
|
+
projection: mapWithProjection.getProjection?.(),
|
|
463
453
|
terrain: map.getTerrain()
|
|
464
454
|
};
|
|
465
455
|
this._updateStyleComponents(this.props);
|
|
@@ -478,11 +468,10 @@ var _Maplibre = class {
|
|
|
478
468
|
}
|
|
479
469
|
this._map = map;
|
|
480
470
|
}
|
|
481
|
-
/* eslint-enable complexity,max-statements */
|
|
482
471
|
recycle() {
|
|
483
472
|
const container = this.map.getContainer();
|
|
484
473
|
const children = container.querySelector("[mapboxgl-children]");
|
|
485
|
-
children
|
|
474
|
+
children?.remove();
|
|
486
475
|
_Maplibre.savedMaps.push(this);
|
|
487
476
|
}
|
|
488
477
|
destroy() {
|
|
@@ -549,7 +538,7 @@ var _Maplibre = class {
|
|
|
549
538
|
if (propName in nextProps && !deepEqual(nextProps[propName], currProps[propName])) {
|
|
550
539
|
changed = true;
|
|
551
540
|
const setter = map[`set${propName[0].toUpperCase()}${propName.slice(1)}`];
|
|
552
|
-
setter
|
|
541
|
+
setter?.call(map, nextProps[propName]);
|
|
553
542
|
}
|
|
554
543
|
}
|
|
555
544
|
return changed;
|
|
@@ -575,23 +564,18 @@ var _Maplibre = class {
|
|
|
575
564
|
* 1. They can not be applied right away. Certain conditions (style loaded, source loaded, etc.) must be met
|
|
576
565
|
* 2. They can be overwritten by mapStyle
|
|
577
566
|
*/
|
|
578
|
-
_updateStyleComponents({
|
|
579
|
-
light,
|
|
580
|
-
projection,
|
|
581
|
-
sky,
|
|
582
|
-
terrain
|
|
583
|
-
}) {
|
|
584
|
-
var _a, _b;
|
|
567
|
+
_updateStyleComponents({ light, projection, sky, terrain }) {
|
|
585
568
|
const map = this._map;
|
|
586
569
|
const currProps = this._styleComponents;
|
|
570
|
+
const mapWithProjection = map;
|
|
587
571
|
if (map.style._loaded) {
|
|
588
572
|
if (light && !deepEqual(light, currProps.light)) {
|
|
589
573
|
currProps.light = light;
|
|
590
574
|
map.setLight(light);
|
|
591
575
|
}
|
|
592
|
-
if (projection && !deepEqual(projection, currProps.projection) && projection !==
|
|
576
|
+
if (projection && !deepEqual(projection, currProps.projection) && projection !== currProps.projection?.type) {
|
|
593
577
|
currProps.projection = typeof projection === "string" ? { type: projection } : projection;
|
|
594
|
-
|
|
578
|
+
mapWithProjection.setProjection?.(currProps.projection);
|
|
595
579
|
}
|
|
596
580
|
if (sky && !deepEqual(sky, currProps.sky)) {
|
|
597
581
|
currProps.sky = sky;
|
|
@@ -607,11 +591,10 @@ var _Maplibre = class {
|
|
|
607
591
|
}
|
|
608
592
|
/* Update interaction handlers to match props */
|
|
609
593
|
_updateHandlers(nextProps, currProps) {
|
|
610
|
-
var _a, _b;
|
|
611
594
|
const map = this._map;
|
|
612
595
|
for (const propName of handlerNames) {
|
|
613
|
-
const newValue =
|
|
614
|
-
const oldValue =
|
|
596
|
+
const newValue = nextProps[propName] ?? true;
|
|
597
|
+
const oldValue = currProps[propName] ?? true;
|
|
615
598
|
if (!deepEqual(newValue, oldValue)) {
|
|
616
599
|
if (newValue) {
|
|
617
600
|
map[propName].enable(newValue);
|
|
@@ -628,17 +611,16 @@ var _Maplibre = class {
|
|
|
628
611
|
return map.queryRenderedFeatures(point, {
|
|
629
612
|
layers: interactiveLayerIds.filter(map.getLayer.bind(map))
|
|
630
613
|
});
|
|
631
|
-
} catch
|
|
614
|
+
} catch {
|
|
632
615
|
return [];
|
|
633
616
|
}
|
|
634
617
|
}
|
|
635
618
|
_updateHover(e) {
|
|
636
|
-
var _a;
|
|
637
619
|
const { props } = this;
|
|
638
620
|
const shouldTrackHoveredFeatures = props.interactiveLayerIds && (props.onMouseMove || props.onMouseEnter || props.onMouseLeave);
|
|
639
621
|
if (shouldTrackHoveredFeatures) {
|
|
640
622
|
const eventType = e.type;
|
|
641
|
-
const wasHovering =
|
|
623
|
+
const wasHovering = this._hoveredFeatures?.length > 0;
|
|
642
624
|
const features = this._queryRenderedFeatures(e.point);
|
|
643
625
|
const isHovering = features.length > 0;
|
|
644
626
|
if (!isHovering && wasHovering) {
|
|
@@ -656,8 +638,6 @@ var _Maplibre = class {
|
|
|
656
638
|
}
|
|
657
639
|
}
|
|
658
640
|
};
|
|
659
|
-
var Maplibre = _Maplibre;
|
|
660
|
-
Maplibre.savedMaps = [];
|
|
661
641
|
|
|
662
642
|
// src/maplibre/create-ref.ts
|
|
663
643
|
var skipMethods = [
|
|
@@ -717,19 +697,34 @@ var useIsomorphicLayoutEffect = typeof document !== "undefined" ? import_react2.
|
|
|
717
697
|
var use_isomorphic_layout_effect_default = useIsomorphicLayoutEffect;
|
|
718
698
|
|
|
719
699
|
// src/utils/set-globals.ts
|
|
700
|
+
var validateUrl = (url, settingName) => {
|
|
701
|
+
try {
|
|
702
|
+
const parsed = new URL(url);
|
|
703
|
+
if (!["http:", "https:"].includes(parsed.protocol)) {
|
|
704
|
+
console.warn(`${settingName}: Only http/https protocols are allowed, got: ${parsed.protocol}`);
|
|
705
|
+
return false;
|
|
706
|
+
}
|
|
707
|
+
return true;
|
|
708
|
+
} catch {
|
|
709
|
+
console.warn(`${settingName}: Invalid URL format: ${url}`);
|
|
710
|
+
return false;
|
|
711
|
+
}
|
|
712
|
+
};
|
|
720
713
|
function setGlobals(mapLib, props) {
|
|
721
714
|
const { RTLTextPlugin, maxParallelImageRequests, workerCount, workerUrl } = props;
|
|
722
715
|
if (RTLTextPlugin && mapLib.getRTLTextPluginStatus && mapLib.getRTLTextPluginStatus() === "unavailable") {
|
|
723
716
|
const { pluginUrl, lazy = true } = typeof RTLTextPlugin === "string" ? { pluginUrl: RTLTextPlugin } : RTLTextPlugin;
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
717
|
+
if (validateUrl(pluginUrl, "RTLTextPlugin")) {
|
|
718
|
+
mapLib.setRTLTextPlugin(
|
|
719
|
+
pluginUrl,
|
|
720
|
+
(error) => {
|
|
721
|
+
if (error) {
|
|
722
|
+
console.error(error);
|
|
723
|
+
}
|
|
724
|
+
},
|
|
725
|
+
lazy
|
|
726
|
+
);
|
|
727
|
+
}
|
|
733
728
|
}
|
|
734
729
|
if (maxParallelImageRequests !== void 0) {
|
|
735
730
|
mapLib.setMaxParallelImageRequests(maxParallelImageRequests);
|
|
@@ -738,7 +733,9 @@ function setGlobals(mapLib, props) {
|
|
|
738
733
|
mapLib.setWorkerCount(workerCount);
|
|
739
734
|
}
|
|
740
735
|
if (workerUrl !== void 0) {
|
|
741
|
-
|
|
736
|
+
if (validateUrl(workerUrl, "workerUrl")) {
|
|
737
|
+
mapLib.setWorkerUrl(workerUrl);
|
|
738
|
+
}
|
|
742
739
|
}
|
|
743
740
|
}
|
|
744
741
|
|
|
@@ -766,14 +763,18 @@ function applyReactStyle(element, styles) {
|
|
|
766
763
|
var import_react3 = require("react");
|
|
767
764
|
function useControl(onCreate, arg1, arg2, arg3) {
|
|
768
765
|
const context = (0, import_react3.useContext)(MapContext);
|
|
766
|
+
if (!context) {
|
|
767
|
+
throw new Error("useControl must be used within a Map component");
|
|
768
|
+
}
|
|
769
769
|
const ctrl = (0, import_react3.useMemo)(() => onCreate(context), []);
|
|
770
770
|
(0, import_react3.useEffect)(() => {
|
|
771
771
|
const opts = arg3 || arg2 || arg1;
|
|
772
772
|
const onAdd = typeof arg1 === "function" && typeof arg2 === "function" ? arg1 : null;
|
|
773
773
|
const onRemove = typeof arg2 === "function" ? arg2 : typeof arg1 === "function" ? arg1 : null;
|
|
774
774
|
const { map } = context;
|
|
775
|
-
|
|
776
|
-
|
|
775
|
+
const ctrlAsIControl = ctrl;
|
|
776
|
+
if (!map.hasControl(ctrlAsIControl)) {
|
|
777
|
+
map.addControl(ctrlAsIControl, opts?.position);
|
|
777
778
|
if (onAdd) {
|
|
778
779
|
onAdd(context);
|
|
779
780
|
}
|
|
@@ -782,8 +783,8 @@ function useControl(onCreate, arg1, arg2, arg3) {
|
|
|
782
783
|
if (onRemove) {
|
|
783
784
|
onRemove(context);
|
|
784
785
|
}
|
|
785
|
-
if (map.hasControl(
|
|
786
|
-
map.removeControl(
|
|
786
|
+
if (map.hasControl(ctrlAsIControl)) {
|
|
787
|
+
map.removeControl(ctrlAsIControl);
|
|
787
788
|
}
|
|
788
789
|
};
|
|
789
790
|
}, []);
|
|
@@ -792,23 +793,36 @@ function useControl(onCreate, arg1, arg2, arg3) {
|
|
|
792
793
|
|
|
793
794
|
// src/components/logo-control.ts
|
|
794
795
|
function _LogoControl(props) {
|
|
795
|
-
const ctrl = useControl(
|
|
796
|
-
|
|
797
|
-
|
|
796
|
+
const ctrl = useControl(
|
|
797
|
+
() => {
|
|
798
|
+
const control = {
|
|
799
|
+
onAdd: (map) => {
|
|
800
|
+
if (map.getContainer) {
|
|
801
|
+
const existingLogo = map.getContainer().querySelector('a.maplibregl-ctrl-logo[href="https://www.barikoi.com"]');
|
|
802
|
+
if (existingLogo) {
|
|
803
|
+
existingLogo.remove();
|
|
804
|
+
}
|
|
805
|
+
}
|
|
806
|
+
const container = document.createElement("a");
|
|
807
|
+
container.className = "maplibregl-ctrl-logo";
|
|
808
|
+
container.href = "https://www.barikoi.com";
|
|
809
|
+
container.target = "_blank";
|
|
810
|
+
container.setAttribute("alt", "Barikoi");
|
|
811
|
+
container.setAttribute("aria-label", "Barikoi logo");
|
|
812
|
+
container.setAttribute("rel", "noopener nofollow");
|
|
813
|
+
control._container = container;
|
|
814
|
+
return container;
|
|
815
|
+
},
|
|
816
|
+
onRemove: () => {
|
|
817
|
+
delete control._container;
|
|
818
|
+
}
|
|
819
|
+
};
|
|
820
|
+
return control;
|
|
821
|
+
},
|
|
822
|
+
{ position: props.position }
|
|
823
|
+
);
|
|
798
824
|
(0, import_react4.useEffect)(() => {
|
|
799
|
-
var _a;
|
|
800
825
|
applyReactStyle(ctrl._container, props.style);
|
|
801
|
-
const logoElement = (_a = ctrl._container) == null ? void 0 : _a.querySelector(
|
|
802
|
-
".maplibregl-ctrl-logo"
|
|
803
|
-
);
|
|
804
|
-
if (logoElement) {
|
|
805
|
-
logoElement.href = "https://barikoi.com/";
|
|
806
|
-
logoElement.setAttribute("aria-label", "Barikoi logo");
|
|
807
|
-
logoElement.target = "_blank";
|
|
808
|
-
logoElement.rel = "noopener nofollow";
|
|
809
|
-
logoElement.style.cursor = "pointer";
|
|
810
|
-
logoElement.replaceWith(logoElement.cloneNode(true));
|
|
811
|
-
}
|
|
812
826
|
}, [props.style, ctrl._container]);
|
|
813
827
|
return null;
|
|
814
828
|
}
|
|
@@ -817,15 +831,49 @@ var LogoControl = (0, import_react4.memo)(_LogoControl);
|
|
|
817
831
|
// src/components/attribution-control.ts
|
|
818
832
|
var import_react5 = require("react");
|
|
819
833
|
function _AttributionControl(props) {
|
|
834
|
+
const { current: map } = useMap();
|
|
820
835
|
const ctrl = useControl(
|
|
821
|
-
({ mapLib }) => new mapLib.AttributionControl(
|
|
836
|
+
({ mapLib }) => new mapLib.AttributionControl({
|
|
837
|
+
compact: true,
|
|
838
|
+
...props
|
|
839
|
+
}),
|
|
822
840
|
{ position: props.position }
|
|
823
841
|
);
|
|
824
842
|
(0, import_react5.useEffect)(() => {
|
|
825
843
|
applyReactStyle(ctrl._container, props.style);
|
|
826
|
-
if (!ctrl._container)
|
|
827
|
-
|
|
828
|
-
|
|
844
|
+
if (!ctrl._container || !map) return;
|
|
845
|
+
const onLoad = () => {
|
|
846
|
+
setTimeout(() => {
|
|
847
|
+
const inner = ctrl._container.querySelector(".maplibregl-ctrl-attrib-inner");
|
|
848
|
+
if (inner) {
|
|
849
|
+
inner.textContent = "";
|
|
850
|
+
const createLink = (text, href) => {
|
|
851
|
+
const a = document.createElement("a");
|
|
852
|
+
a.href = href;
|
|
853
|
+
a.target = "_blank";
|
|
854
|
+
a.rel = "noopener noreferrer";
|
|
855
|
+
a.textContent = text;
|
|
856
|
+
return a;
|
|
857
|
+
};
|
|
858
|
+
inner.appendChild(createLink("Barikoi", "https://barikoi.com"));
|
|
859
|
+
inner.appendChild(document.createTextNode(" \xA9 "));
|
|
860
|
+
inner.appendChild(createLink("OpenMapTiles", "https://openmaptiles.org"));
|
|
861
|
+
inner.appendChild(document.createTextNode(" \xA9 "));
|
|
862
|
+
inner.appendChild(
|
|
863
|
+
createLink("OpenStreetMap contributors", "https://www.openstreetmap.org/copyright")
|
|
864
|
+
);
|
|
865
|
+
}
|
|
866
|
+
}, 0);
|
|
867
|
+
};
|
|
868
|
+
if (map.loaded()) {
|
|
869
|
+
onLoad();
|
|
870
|
+
} else {
|
|
871
|
+
map.once("load", onLoad);
|
|
872
|
+
}
|
|
873
|
+
return () => {
|
|
874
|
+
map.off("load", onLoad);
|
|
875
|
+
};
|
|
876
|
+
}, [props.style, ctrl._container, map]);
|
|
829
877
|
return null;
|
|
830
878
|
}
|
|
831
879
|
var AttributionControl = (0, import_react5.memo)(_AttributionControl);
|
|
@@ -843,7 +891,7 @@ function _Map(props, ref) {
|
|
|
843
891
|
(0, import_react6.useEffect)(() => {
|
|
844
892
|
const mapLib = props.mapLib;
|
|
845
893
|
let isMounted = true;
|
|
846
|
-
let maplibre;
|
|
894
|
+
let maplibre = null;
|
|
847
895
|
Promise.resolve(mapLib || import("maplibre-gl")).then((module2) => {
|
|
848
896
|
if (!isMounted) {
|
|
849
897
|
return;
|
|
@@ -862,17 +910,19 @@ function _Map(props, ref) {
|
|
|
862
910
|
if (!maplibre) {
|
|
863
911
|
maplibre = new Maplibre(
|
|
864
912
|
mapboxgl.Map,
|
|
865
|
-
|
|
866
|
-
|
|
913
|
+
{
|
|
914
|
+
...props,
|
|
867
915
|
attributionControl: false
|
|
868
|
-
}
|
|
916
|
+
},
|
|
869
917
|
containerRef.current
|
|
870
918
|
);
|
|
871
919
|
}
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
920
|
+
if (maplibre) {
|
|
921
|
+
contextValue.map = createRef(maplibre);
|
|
922
|
+
contextValue.mapLib = mapboxgl;
|
|
923
|
+
setMapInstance(maplibre);
|
|
924
|
+
}
|
|
925
|
+
mountedMapsContext?.onMapMount(contextValue.map, props.id);
|
|
876
926
|
}).catch((error) => {
|
|
877
927
|
const { onError } = props;
|
|
878
928
|
if (onError) {
|
|
@@ -889,7 +939,7 @@ function _Map(props, ref) {
|
|
|
889
939
|
return () => {
|
|
890
940
|
isMounted = false;
|
|
891
941
|
if (maplibre) {
|
|
892
|
-
mountedMapsContext
|
|
942
|
+
mountedMapsContext?.onMapUnmount(props.id);
|
|
893
943
|
if (props.reuseMaps) {
|
|
894
944
|
maplibre.recycle();
|
|
895
945
|
} else {
|
|
@@ -905,17 +955,18 @@ function _Map(props, ref) {
|
|
|
905
955
|
});
|
|
906
956
|
(0, import_react6.useImperativeHandle)(ref, () => contextValue.map, [mapInstance]);
|
|
907
957
|
const style = (0, import_react6.useMemo)(
|
|
908
|
-
() =>
|
|
958
|
+
() => ({
|
|
909
959
|
position: "relative",
|
|
910
960
|
width: "100%",
|
|
911
|
-
height: "100%"
|
|
912
|
-
|
|
961
|
+
height: "100%",
|
|
962
|
+
...props.style
|
|
963
|
+
}),
|
|
913
964
|
[props.style]
|
|
914
965
|
);
|
|
915
966
|
const CHILD_CONTAINER_STYLE = {
|
|
916
967
|
height: "100%"
|
|
917
968
|
};
|
|
918
|
-
return /* @__PURE__ */ React2.createElement("div", { id: props.id, ref: containerRef, style }, mapInstance && /* @__PURE__ */ React2.createElement(MapContext.Provider, { value: contextValue }, /* @__PURE__ */ React2.createElement("div", {
|
|
969
|
+
return /* @__PURE__ */ React2.createElement("div", { id: props.id, ref: containerRef, style }, mapInstance && /* @__PURE__ */ React2.createElement(MapContext.Provider, { value: contextValue }, /* @__PURE__ */ React2.createElement("div", { style: CHILD_CONTAINER_STYLE }, /* @__PURE__ */ React2.createElement(LogoControl, { position: "bottom-left" }), /* @__PURE__ */ React2.createElement(AttributionControl, { position: "bottom-right" }), props.children)));
|
|
919
970
|
}
|
|
920
971
|
var Map = React2.forwardRef(_Map);
|
|
921
972
|
|
|
@@ -952,7 +1003,7 @@ function getClassList(className) {
|
|
|
952
1003
|
var Marker = (0, import_react7.memo)(
|
|
953
1004
|
(0, import_react7.forwardRef)((props, ref) => {
|
|
954
1005
|
const { map, mapLib } = (0, import_react7.useContext)(MapContext);
|
|
955
|
-
const
|
|
1006
|
+
const callbackRef = (0, import_react7.useRef)({});
|
|
956
1007
|
const marker = (0, import_react7.useMemo)(() => {
|
|
957
1008
|
let hasChildren = false;
|
|
958
1009
|
React3.Children.forEach(props.children, (el) => {
|
|
@@ -960,42 +1011,52 @@ var Marker = (0, import_react7.memo)(
|
|
|
960
1011
|
hasChildren = true;
|
|
961
1012
|
}
|
|
962
1013
|
});
|
|
963
|
-
const options =
|
|
1014
|
+
const options = {
|
|
1015
|
+
...props,
|
|
964
1016
|
element: hasChildren ? document.createElement("div") : void 0
|
|
965
|
-
}
|
|
1017
|
+
};
|
|
966
1018
|
const mk = new mapLib.Marker(options);
|
|
967
1019
|
mk.setLngLat([props.longitude, props.latitude]);
|
|
968
|
-
mk.getElement().addEventListener("click", (e) => {
|
|
969
|
-
var _a, _b;
|
|
970
|
-
(_b = (_a = thisRef.current.props).onClick) == null ? void 0 : _b.call(_a, {
|
|
971
|
-
type: "click",
|
|
972
|
-
target: mk,
|
|
973
|
-
originalEvent: e
|
|
974
|
-
});
|
|
975
|
-
});
|
|
976
|
-
mk.on("dragstart", (e) => {
|
|
977
|
-
var _a, _b;
|
|
978
|
-
const evt = e;
|
|
979
|
-
evt.lngLat = marker.getLngLat();
|
|
980
|
-
(_b = (_a = thisRef.current.props).onDragStart) == null ? void 0 : _b.call(_a, evt);
|
|
981
|
-
});
|
|
982
|
-
mk.on("drag", (e) => {
|
|
983
|
-
var _a, _b;
|
|
984
|
-
const evt = e;
|
|
985
|
-
evt.lngLat = marker.getLngLat();
|
|
986
|
-
(_b = (_a = thisRef.current.props).onDrag) == null ? void 0 : _b.call(_a, evt);
|
|
987
|
-
});
|
|
988
|
-
mk.on("dragend", (e) => {
|
|
989
|
-
var _a, _b;
|
|
990
|
-
const evt = e;
|
|
991
|
-
evt.lngLat = marker.getLngLat();
|
|
992
|
-
(_b = (_a = thisRef.current.props).onDragEnd) == null ? void 0 : _b.call(_a, evt);
|
|
993
|
-
});
|
|
994
1020
|
return mk;
|
|
995
1021
|
}, []);
|
|
996
1022
|
(0, import_react7.useEffect)(() => {
|
|
1023
|
+
callbackRef.current = {
|
|
1024
|
+
onClick: props.onClick,
|
|
1025
|
+
onDragStart: props.onDragStart,
|
|
1026
|
+
onDrag: props.onDrag,
|
|
1027
|
+
onDragEnd: props.onDragEnd
|
|
1028
|
+
};
|
|
1029
|
+
});
|
|
1030
|
+
(0, import_react7.useEffect)(() => {
|
|
1031
|
+
const clickHandler = (e) => {
|
|
1032
|
+
callbackRef.current.onClick?.({
|
|
1033
|
+
type: "click",
|
|
1034
|
+
target: marker,
|
|
1035
|
+
originalEvent: e
|
|
1036
|
+
});
|
|
1037
|
+
};
|
|
1038
|
+
marker.getElement().addEventListener("click", clickHandler);
|
|
1039
|
+
const dragStartHandler = (e) => {
|
|
1040
|
+
e.lngLat = marker.getLngLat();
|
|
1041
|
+
callbackRef.current.onDragStart?.(e);
|
|
1042
|
+
};
|
|
1043
|
+
const dragHandler = (e) => {
|
|
1044
|
+
e.lngLat = marker.getLngLat();
|
|
1045
|
+
callbackRef.current.onDrag?.(e);
|
|
1046
|
+
};
|
|
1047
|
+
const dragEndHandler = (e) => {
|
|
1048
|
+
e.lngLat = marker.getLngLat();
|
|
1049
|
+
callbackRef.current.onDragEnd?.(e);
|
|
1050
|
+
};
|
|
1051
|
+
marker.on("dragstart", dragStartHandler);
|
|
1052
|
+
marker.on("drag", dragHandler);
|
|
1053
|
+
marker.on("dragend", dragEndHandler);
|
|
997
1054
|
marker.addTo(map.getMap());
|
|
998
1055
|
return () => {
|
|
1056
|
+
marker.getElement().removeEventListener("click", clickHandler);
|
|
1057
|
+
marker.off("dragstart", dragStartHandler);
|
|
1058
|
+
marker.off("drag", dragHandler);
|
|
1059
|
+
marker.off("dragend", dragEndHandler);
|
|
999
1060
|
marker.remove();
|
|
1000
1061
|
};
|
|
1001
1062
|
}, []);
|
|
@@ -1008,44 +1069,44 @@ var Marker = (0, import_react7.memo)(
|
|
|
1008
1069
|
popup = null,
|
|
1009
1070
|
rotation = 0,
|
|
1010
1071
|
rotationAlignment = "auto",
|
|
1011
|
-
pitchAlignment = "auto"
|
|
1072
|
+
pitchAlignment = "auto",
|
|
1073
|
+
className
|
|
1012
1074
|
} = props;
|
|
1013
1075
|
(0, import_react7.useEffect)(() => {
|
|
1014
1076
|
applyReactStyle(marker.getElement(), style);
|
|
1015
1077
|
}, [style]);
|
|
1016
1078
|
(0, import_react7.useImperativeHandle)(ref, () => marker, []);
|
|
1017
|
-
const
|
|
1018
|
-
|
|
1019
|
-
marker.
|
|
1020
|
-
|
|
1021
|
-
if (offset && !arePointsEqual(marker.getOffset(), offset)) {
|
|
1022
|
-
marker.setOffset(offset);
|
|
1023
|
-
}
|
|
1024
|
-
if (marker.isDraggable() !== draggable) {
|
|
1025
|
-
marker.setDraggable(draggable);
|
|
1026
|
-
}
|
|
1027
|
-
if (marker.getRotation() !== rotation) {
|
|
1028
|
-
marker.setRotation(rotation);
|
|
1029
|
-
}
|
|
1030
|
-
if (marker.getRotationAlignment() !== rotationAlignment) {
|
|
1031
|
-
marker.setRotationAlignment(rotationAlignment);
|
|
1032
|
-
}
|
|
1033
|
-
if (marker.getPitchAlignment() !== pitchAlignment) {
|
|
1034
|
-
marker.setPitchAlignment(pitchAlignment);
|
|
1035
|
-
}
|
|
1036
|
-
if (marker.getPopup() !== popup) {
|
|
1037
|
-
marker.setPopup(popup);
|
|
1038
|
-
}
|
|
1039
|
-
const classNameDiff = compareClassNames(
|
|
1040
|
-
oldProps.className,
|
|
1041
|
-
props.className
|
|
1042
|
-
);
|
|
1043
|
-
if (classNameDiff) {
|
|
1044
|
-
for (const c of classNameDiff) {
|
|
1045
|
-
marker.toggleClassName(c);
|
|
1079
|
+
const prevClassNameRef = (0, import_react7.useRef)(className);
|
|
1080
|
+
(0, import_react7.useEffect)(() => {
|
|
1081
|
+
if (marker.getLngLat().lng !== longitude || marker.getLngLat().lat !== latitude) {
|
|
1082
|
+
marker.setLngLat([longitude, latitude]);
|
|
1046
1083
|
}
|
|
1047
|
-
|
|
1048
|
-
|
|
1084
|
+
if (offset && !arePointsEqual(marker.getOffset(), offset)) {
|
|
1085
|
+
marker.setOffset(offset);
|
|
1086
|
+
}
|
|
1087
|
+
if (marker.isDraggable() !== draggable) {
|
|
1088
|
+
marker.setDraggable(draggable);
|
|
1089
|
+
}
|
|
1090
|
+
if (marker.getRotation() !== rotation) {
|
|
1091
|
+
marker.setRotation(rotation);
|
|
1092
|
+
}
|
|
1093
|
+
if (marker.getRotationAlignment() !== rotationAlignment) {
|
|
1094
|
+
marker.setRotationAlignment(rotationAlignment);
|
|
1095
|
+
}
|
|
1096
|
+
if (marker.getPitchAlignment() !== pitchAlignment) {
|
|
1097
|
+
marker.setPitchAlignment(pitchAlignment);
|
|
1098
|
+
}
|
|
1099
|
+
if (marker.getPopup() !== popup) {
|
|
1100
|
+
marker.setPopup(popup);
|
|
1101
|
+
}
|
|
1102
|
+
const classNameDiff = compareClassNames(prevClassNameRef.current, className);
|
|
1103
|
+
if (classNameDiff) {
|
|
1104
|
+
for (const c of classNameDiff) {
|
|
1105
|
+
marker.toggleClassName(c);
|
|
1106
|
+
}
|
|
1107
|
+
}
|
|
1108
|
+
prevClassNameRef.current = className;
|
|
1109
|
+
});
|
|
1049
1110
|
return (0, import_react_dom.createPortal)(props.children, marker.getElement());
|
|
1050
1111
|
})
|
|
1051
1112
|
);
|
|
@@ -1059,25 +1120,25 @@ var Popup = (0, import_react8.memo)(
|
|
|
1059
1120
|
const container = (0, import_react8.useMemo)(() => {
|
|
1060
1121
|
return document.createElement("div");
|
|
1061
1122
|
}, []);
|
|
1062
|
-
const thisRef = (0, import_react8.useRef)({ props });
|
|
1063
1123
|
const popup = (0, import_react8.useMemo)(() => {
|
|
1064
|
-
const options =
|
|
1124
|
+
const options = { ...props };
|
|
1065
1125
|
const pp = new mapLib.Popup(options);
|
|
1066
1126
|
pp.setLngLat([props.longitude, props.latitude]);
|
|
1067
|
-
pp.once("open", (e) => {
|
|
1068
|
-
var _a, _b;
|
|
1069
|
-
(_b = (_a = thisRef.current.props).onOpen) == null ? void 0 : _b.call(_a, e);
|
|
1070
|
-
});
|
|
1071
1127
|
return pp;
|
|
1072
1128
|
}, []);
|
|
1129
|
+
(0, import_react8.useImperativeHandle)(ref, () => popup, []);
|
|
1073
1130
|
(0, import_react8.useEffect)(() => {
|
|
1131
|
+
const onOpen = (e) => {
|
|
1132
|
+
props.onOpen?.(e);
|
|
1133
|
+
};
|
|
1074
1134
|
const onClose = (e) => {
|
|
1075
|
-
|
|
1076
|
-
(_b = (_a = thisRef.current.props).onClose) == null ? void 0 : _b.call(_a, e);
|
|
1135
|
+
props.onClose?.(e);
|
|
1077
1136
|
};
|
|
1137
|
+
popup.on("open", onOpen);
|
|
1078
1138
|
popup.on("close", onClose);
|
|
1079
1139
|
popup.setDOMContent(container).addTo(map.getMap());
|
|
1080
1140
|
return () => {
|
|
1141
|
+
popup.off("open", onOpen);
|
|
1081
1142
|
popup.off("close", onClose);
|
|
1082
1143
|
if (popup.isOpen()) {
|
|
1083
1144
|
popup.remove();
|
|
@@ -1087,30 +1148,34 @@ var Popup = (0, import_react8.memo)(
|
|
|
1087
1148
|
(0, import_react8.useEffect)(() => {
|
|
1088
1149
|
applyReactStyle(popup.getElement(), props.style);
|
|
1089
1150
|
}, [props.style]);
|
|
1090
|
-
(0, import_react8.
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1151
|
+
(0, import_react8.useEffect)(() => {
|
|
1152
|
+
if (popup.isOpen()) {
|
|
1153
|
+
if (popup.getLngLat().lng !== props.longitude || popup.getLngLat().lat !== props.latitude) {
|
|
1154
|
+
popup.setLngLat([props.longitude, props.latitude]);
|
|
1155
|
+
}
|
|
1095
1156
|
}
|
|
1096
|
-
|
|
1157
|
+
}, [props.longitude, props.latitude]);
|
|
1158
|
+
(0, import_react8.useEffect)(() => {
|
|
1159
|
+
if (popup.isOpen() && props.offset) {
|
|
1097
1160
|
popup.setOffset(props.offset);
|
|
1098
1161
|
}
|
|
1099
|
-
|
|
1100
|
-
|
|
1162
|
+
}, [props.offset]);
|
|
1163
|
+
(0, import_react8.useEffect)(() => {
|
|
1164
|
+
if (popup.isOpen() && props.maxWidth !== void 0) {
|
|
1101
1165
|
popup.setMaxWidth(props.maxWidth);
|
|
1102
1166
|
}
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1167
|
+
}, [props.maxWidth]);
|
|
1168
|
+
(0, import_react8.useEffect)(() => {
|
|
1169
|
+
if (popup.isOpen() && props.className) {
|
|
1170
|
+
const currentClassName = popup.options.className || "";
|
|
1171
|
+
const classNameDiff = compareClassNames(currentClassName, props.className);
|
|
1172
|
+
if (classNameDiff) {
|
|
1173
|
+
for (const c of classNameDiff) {
|
|
1174
|
+
popup.toggleClassName(c);
|
|
1175
|
+
}
|
|
1110
1176
|
}
|
|
1111
1177
|
}
|
|
1112
|
-
|
|
1113
|
-
}
|
|
1178
|
+
}, [props.className]);
|
|
1114
1179
|
return (0, import_react_dom2.createPortal)(props.children, container);
|
|
1115
1180
|
})
|
|
1116
1181
|
);
|
|
@@ -1145,24 +1210,19 @@ function _GeolocateControl(props, ref) {
|
|
|
1145
1210
|
}
|
|
1146
1211
|
};
|
|
1147
1212
|
gc.on("geolocate", (e) => {
|
|
1148
|
-
|
|
1149
|
-
(_b = (_a = thisRef.current.props).onGeolocate) == null ? void 0 : _b.call(_a, e);
|
|
1213
|
+
thisRef.current.props.onGeolocate?.(e);
|
|
1150
1214
|
});
|
|
1151
1215
|
gc.on("error", (e) => {
|
|
1152
|
-
|
|
1153
|
-
(_b = (_a = thisRef.current.props).onError) == null ? void 0 : _b.call(_a, e);
|
|
1216
|
+
thisRef.current.props.onError?.(e);
|
|
1154
1217
|
});
|
|
1155
1218
|
gc.on("outofmaxbounds", (e) => {
|
|
1156
|
-
|
|
1157
|
-
(_b = (_a = thisRef.current.props).onOutOfMaxBounds) == null ? void 0 : _b.call(_a, e);
|
|
1219
|
+
thisRef.current.props.onOutOfMaxBounds?.(e);
|
|
1158
1220
|
});
|
|
1159
1221
|
gc.on("trackuserlocationstart", (e) => {
|
|
1160
|
-
|
|
1161
|
-
(_b = (_a = thisRef.current.props).onTrackUserLocationStart) == null ? void 0 : _b.call(_a, e);
|
|
1222
|
+
thisRef.current.props.onTrackUserLocationStart?.(e);
|
|
1162
1223
|
});
|
|
1163
1224
|
gc.on("trackuserlocationend", (e) => {
|
|
1164
|
-
|
|
1165
|
-
(_b = (_a = thisRef.current.props).onTrackUserLocationEnd) == null ? void 0 : _b.call(_a, e);
|
|
1225
|
+
thisRef.current.props.onTrackUserLocationEnd?.(e);
|
|
1166
1226
|
});
|
|
1167
1227
|
return gc;
|
|
1168
1228
|
},
|
|
@@ -1175,9 +1235,7 @@ function _GeolocateControl(props, ref) {
|
|
|
1175
1235
|
}, [props.style]);
|
|
1176
1236
|
return null;
|
|
1177
1237
|
}
|
|
1178
|
-
var GeolocateControl = (0, import_react10.memo)(
|
|
1179
|
-
(0, import_react10.forwardRef)(_GeolocateControl)
|
|
1180
|
-
);
|
|
1238
|
+
var GeolocateControl = (0, import_react10.memo)((0, import_react10.forwardRef)(_GeolocateControl));
|
|
1181
1239
|
|
|
1182
1240
|
// src/components/navigation-control.ts
|
|
1183
1241
|
var import_react11 = require("react");
|
|
@@ -1201,16 +1259,18 @@ function _ScaleControl(props) {
|
|
|
1201
1259
|
const propsRef = (0, import_react12.useRef)(props);
|
|
1202
1260
|
const prevProps = propsRef.current;
|
|
1203
1261
|
propsRef.current = props;
|
|
1204
|
-
const { style } = props;
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1262
|
+
const { style, maxWidth, unit } = props;
|
|
1263
|
+
(0, import_react12.useEffect)(() => {
|
|
1264
|
+
if (maxWidth !== void 0 && maxWidth !== prevProps.maxWidth) {
|
|
1265
|
+
ctrl.options.maxWidth = maxWidth;
|
|
1266
|
+
}
|
|
1267
|
+
if (unit !== void 0 && unit !== prevProps.unit) {
|
|
1268
|
+
ctrl.setUnit(unit);
|
|
1269
|
+
}
|
|
1270
|
+
}, [ctrl, maxWidth, unit, prevProps.maxWidth, prevProps.unit]);
|
|
1211
1271
|
(0, import_react12.useEffect)(() => {
|
|
1212
1272
|
applyReactStyle(ctrl._container, style);
|
|
1213
|
-
}, [style]);
|
|
1273
|
+
}, [ctrl, style]);
|
|
1214
1274
|
return null;
|
|
1215
1275
|
}
|
|
1216
1276
|
var ScaleControl = (0, import_react12.memo)(_ScaleControl);
|
|
@@ -1240,10 +1300,10 @@ function assert(condition, message) {
|
|
|
1240
1300
|
}
|
|
1241
1301
|
|
|
1242
1302
|
// src/components/source.ts
|
|
1243
|
-
var sourceCounter = 0;
|
|
1244
1303
|
function createSource(map, id, props) {
|
|
1245
|
-
|
|
1246
|
-
|
|
1304
|
+
const mapInternal = map;
|
|
1305
|
+
if (mapInternal.style && mapInternal.style._loaded) {
|
|
1306
|
+
const options = { ...props };
|
|
1247
1307
|
delete options.id;
|
|
1248
1308
|
delete options.children;
|
|
1249
1309
|
map.addSource(id, options);
|
|
@@ -1252,7 +1312,6 @@ function createSource(map, id, props) {
|
|
|
1252
1312
|
return null;
|
|
1253
1313
|
}
|
|
1254
1314
|
function updateSource(source, props, prevProps) {
|
|
1255
|
-
var _a, _b, _c;
|
|
1256
1315
|
assert(props.id === prevProps.id, "source id changed");
|
|
1257
1316
|
assert(props.type === prevProps.type, "source type changed");
|
|
1258
1317
|
let changedKey = "";
|
|
@@ -1268,46 +1327,57 @@ function updateSource(source, props, prevProps) {
|
|
|
1268
1327
|
}
|
|
1269
1328
|
const type = props.type;
|
|
1270
1329
|
if (type === "geojson") {
|
|
1330
|
+
;
|
|
1271
1331
|
source.setData(props.data);
|
|
1272
1332
|
} else if (type === "image") {
|
|
1333
|
+
;
|
|
1273
1334
|
source.updateImage({
|
|
1274
1335
|
url: props.url,
|
|
1275
1336
|
coordinates: props.coordinates
|
|
1276
1337
|
});
|
|
1277
1338
|
} else {
|
|
1339
|
+
const sourceWithMethods = source;
|
|
1340
|
+
const propsWithOptional = props;
|
|
1278
1341
|
switch (changedKey) {
|
|
1279
1342
|
case "coordinates":
|
|
1280
|
-
|
|
1343
|
+
sourceWithMethods.setCoordinates?.(propsWithOptional.coordinates);
|
|
1281
1344
|
break;
|
|
1282
1345
|
case "url":
|
|
1283
|
-
|
|
1346
|
+
sourceWithMethods.setUrl?.(propsWithOptional.url);
|
|
1284
1347
|
break;
|
|
1285
1348
|
case "tiles":
|
|
1286
|
-
|
|
1349
|
+
sourceWithMethods.setTiles?.(propsWithOptional.tiles);
|
|
1287
1350
|
break;
|
|
1288
1351
|
default:
|
|
1289
1352
|
console.warn(`Unable to update <Source> prop: ${changedKey}`);
|
|
1290
1353
|
}
|
|
1291
1354
|
}
|
|
1292
1355
|
}
|
|
1293
|
-
function
|
|
1356
|
+
function _Source(props, ref) {
|
|
1294
1357
|
const map = (0, import_react14.useContext)(MapContext).map.getMap();
|
|
1295
1358
|
const propsRef = (0, import_react14.useRef)(props);
|
|
1359
|
+
const sourceRef = (0, import_react14.useRef)(null);
|
|
1296
1360
|
const [, setStyleLoaded] = (0, import_react14.useState)(0);
|
|
1297
|
-
const
|
|
1361
|
+
const generatedId = (0, import_react14.useId)();
|
|
1362
|
+
const id = (0, import_react14.useMemo)(
|
|
1363
|
+
() => props.id || `jsx-source-${generatedId.replace(/:/g, "-")}`,
|
|
1364
|
+
// Empty deps - id is set once on mount and should not change
|
|
1365
|
+
[]
|
|
1366
|
+
);
|
|
1298
1367
|
(0, import_react14.useEffect)(() => {
|
|
1299
1368
|
if (map) {
|
|
1300
1369
|
const forceUpdate = () => setTimeout(() => setStyleLoaded((version) => version + 1), 0);
|
|
1301
1370
|
map.on("styledata", forceUpdate);
|
|
1302
1371
|
forceUpdate();
|
|
1303
1372
|
return () => {
|
|
1304
|
-
var _a;
|
|
1305
1373
|
map.off("styledata", forceUpdate);
|
|
1306
|
-
|
|
1307
|
-
|
|
1374
|
+
const mapInternal2 = map;
|
|
1375
|
+
if (mapInternal2.style && mapInternal2.style._loaded && map.getSource(id)) {
|
|
1376
|
+
const allLayers = map.getStyle()?.layers;
|
|
1308
1377
|
if (allLayers) {
|
|
1309
1378
|
for (const layer of allLayers) {
|
|
1310
|
-
|
|
1379
|
+
const layerWithSource = layer;
|
|
1380
|
+
if (layerWithSource.source === id) {
|
|
1311
1381
|
map.removeLayer(layer.id);
|
|
1312
1382
|
}
|
|
1313
1383
|
}
|
|
@@ -1318,13 +1388,16 @@ function Source(props) {
|
|
|
1318
1388
|
}
|
|
1319
1389
|
return void 0;
|
|
1320
1390
|
}, [map]);
|
|
1321
|
-
|
|
1391
|
+
const mapInternal = map;
|
|
1392
|
+
let source = map && mapInternal.style && map.getSource(id);
|
|
1322
1393
|
if (source) {
|
|
1323
1394
|
updateSource(source, props, propsRef.current);
|
|
1324
1395
|
} else {
|
|
1325
1396
|
source = createSource(map, id, props);
|
|
1326
1397
|
}
|
|
1398
|
+
sourceRef.current = source;
|
|
1327
1399
|
propsRef.current = props;
|
|
1400
|
+
(0, import_react14.useImperativeHandle)(ref, () => sourceRef.current, [source]);
|
|
1328
1401
|
return source && React4.Children.map(
|
|
1329
1402
|
props.children,
|
|
1330
1403
|
(child) => child && (0, import_react14.cloneElement)(child, {
|
|
@@ -1332,80 +1405,272 @@ function Source(props) {
|
|
|
1332
1405
|
})
|
|
1333
1406
|
) || null;
|
|
1334
1407
|
}
|
|
1408
|
+
var Source = (0, import_react14.memo)(React4.forwardRef(_Source));
|
|
1335
1409
|
|
|
1336
|
-
// src/components/
|
|
1410
|
+
// src/components/canvas-source.ts
|
|
1411
|
+
var React5 = __toESM(require("react"), 1);
|
|
1337
1412
|
var import_react15 = require("react");
|
|
1413
|
+
function _CanvasSource(props) {
|
|
1414
|
+
const map = (0, import_react15.useContext)(MapContext).map.getMap();
|
|
1415
|
+
const propsRef = (0, import_react15.useRef)(props);
|
|
1416
|
+
const id = (0, import_react15.useMemo)(() => props.id || `canvas-source-${Date.now()}`, [props.id]);
|
|
1417
|
+
(0, import_react15.useEffect)(() => {
|
|
1418
|
+
if (!map) return void 0;
|
|
1419
|
+
const mapInternal2 = map;
|
|
1420
|
+
let source = null;
|
|
1421
|
+
const addSource = () => {
|
|
1422
|
+
if (!mapInternal2.style || !mapInternal2.style._loaded) return;
|
|
1423
|
+
if (map.getSource(id)) return;
|
|
1424
|
+
const { coordinates, canvas, animate } = props;
|
|
1425
|
+
map.addSource(id, {
|
|
1426
|
+
type: "canvas",
|
|
1427
|
+
coordinates,
|
|
1428
|
+
canvas,
|
|
1429
|
+
animate: animate || false
|
|
1430
|
+
});
|
|
1431
|
+
source = map.getSource(id);
|
|
1432
|
+
};
|
|
1433
|
+
const updateSource2 = () => {
|
|
1434
|
+
if (!source) return;
|
|
1435
|
+
const { coordinates, canvas } = props;
|
|
1436
|
+
const prevProps = propsRef.current;
|
|
1437
|
+
if (JSON.stringify(coordinates) !== JSON.stringify(prevProps.coordinates)) {
|
|
1438
|
+
const sourceWithMethods = source;
|
|
1439
|
+
sourceWithMethods.setCoordinates?.(coordinates);
|
|
1440
|
+
}
|
|
1441
|
+
};
|
|
1442
|
+
if (mapInternal2.style && mapInternal2.style._loaded) {
|
|
1443
|
+
addSource();
|
|
1444
|
+
} else {
|
|
1445
|
+
map.once("styledata", addSource);
|
|
1446
|
+
}
|
|
1447
|
+
return () => {
|
|
1448
|
+
map.off("styledata", addSource);
|
|
1449
|
+
const mapInternalForCleanup = map;
|
|
1450
|
+
if (mapInternalForCleanup.style && mapInternalForCleanup.style._loaded && map.getSource(id)) {
|
|
1451
|
+
const allLayers = map.getStyle()?.layers;
|
|
1452
|
+
if (allLayers) {
|
|
1453
|
+
for (const layer of allLayers) {
|
|
1454
|
+
if (layer.source === id) {
|
|
1455
|
+
map.removeLayer(layer.id);
|
|
1456
|
+
}
|
|
1457
|
+
}
|
|
1458
|
+
}
|
|
1459
|
+
map.removeSource(id);
|
|
1460
|
+
}
|
|
1461
|
+
};
|
|
1462
|
+
}, [map, id]);
|
|
1463
|
+
(0, import_react15.useEffect)(() => {
|
|
1464
|
+
if (!map) return;
|
|
1465
|
+
const source = map.getSource(id);
|
|
1466
|
+
if (!source) return;
|
|
1467
|
+
const { coordinates } = props;
|
|
1468
|
+
const prevProps = propsRef.current;
|
|
1469
|
+
if (JSON.stringify(coordinates) !== JSON.stringify(prevProps.coordinates)) {
|
|
1470
|
+
const sourceWithMethods = source;
|
|
1471
|
+
sourceWithMethods.setCoordinates?.(coordinates);
|
|
1472
|
+
}
|
|
1473
|
+
propsRef.current = props;
|
|
1474
|
+
}, [map, id, props.coordinates, props.canvas]);
|
|
1475
|
+
if (!map) return null;
|
|
1476
|
+
const mapInternal = map;
|
|
1477
|
+
if (!mapInternal.style || !mapInternal.style._loaded || !map.getSource(id)) {
|
|
1478
|
+
return null;
|
|
1479
|
+
}
|
|
1480
|
+
return props.children && React5.Children.map(
|
|
1481
|
+
props.children,
|
|
1482
|
+
(child) => child && React5.cloneElement(child, {
|
|
1483
|
+
source: id
|
|
1484
|
+
})
|
|
1485
|
+
) || null;
|
|
1486
|
+
}
|
|
1487
|
+
var CanvasSource = (0, import_react15.memo)(_CanvasSource);
|
|
1488
|
+
|
|
1489
|
+
// src/components/layer.ts
|
|
1490
|
+
var import_react16 = require("react");
|
|
1338
1491
|
function updateLayer(map, id, props, prevProps) {
|
|
1339
1492
|
assert(props.id === prevProps.id, "layer id changed");
|
|
1340
1493
|
assert(props.type === prevProps.type, "layer type changed");
|
|
1341
1494
|
if (props.type === "custom" || prevProps.type === "custom") {
|
|
1342
1495
|
return;
|
|
1343
1496
|
}
|
|
1344
|
-
const
|
|
1345
|
-
|
|
1497
|
+
const propsWithFilter = props;
|
|
1498
|
+
const prevPropsWithFilter = prevProps;
|
|
1499
|
+
const { layout = {}, paint = {}, filter, minzoom, maxzoom, beforeId } = propsWithFilter;
|
|
1500
|
+
if (beforeId !== prevPropsWithFilter.beforeId) {
|
|
1346
1501
|
map.moveLayer(id, beforeId);
|
|
1347
1502
|
}
|
|
1348
|
-
if (layout !==
|
|
1349
|
-
const prevLayout =
|
|
1503
|
+
if (layout !== prevPropsWithFilter.layout) {
|
|
1504
|
+
const prevLayout = prevPropsWithFilter.layout || {};
|
|
1350
1505
|
for (const key in layout) {
|
|
1351
1506
|
if (!deepEqual(layout[key], prevLayout[key])) {
|
|
1352
1507
|
map.setLayoutProperty(id, key, layout[key]);
|
|
1353
1508
|
}
|
|
1354
1509
|
}
|
|
1355
1510
|
for (const key in prevLayout) {
|
|
1356
|
-
if (!
|
|
1511
|
+
if (!Object.prototype.hasOwnProperty.call(layout, key)) {
|
|
1357
1512
|
map.setLayoutProperty(id, key, void 0);
|
|
1358
1513
|
}
|
|
1359
1514
|
}
|
|
1360
1515
|
}
|
|
1361
|
-
if (paint !==
|
|
1362
|
-
const prevPaint =
|
|
1516
|
+
if (paint !== prevPropsWithFilter.paint) {
|
|
1517
|
+
const prevPaint = prevPropsWithFilter.paint || {};
|
|
1363
1518
|
for (const key in paint) {
|
|
1364
1519
|
if (!deepEqual(paint[key], prevPaint[key])) {
|
|
1365
1520
|
map.setPaintProperty(id, key, paint[key]);
|
|
1366
1521
|
}
|
|
1367
1522
|
}
|
|
1368
1523
|
for (const key in prevPaint) {
|
|
1369
|
-
if (!
|
|
1524
|
+
if (!Object.prototype.hasOwnProperty.call(paint, key)) {
|
|
1370
1525
|
map.setPaintProperty(id, key, void 0);
|
|
1371
1526
|
}
|
|
1372
1527
|
}
|
|
1373
1528
|
}
|
|
1374
|
-
if (!deepEqual(filter,
|
|
1375
|
-
map.setFilter(id, filter);
|
|
1529
|
+
if (!deepEqual(filter, prevPropsWithFilter.filter)) {
|
|
1530
|
+
map.setFilter(id, filter ?? null);
|
|
1376
1531
|
}
|
|
1377
|
-
if (minzoom !==
|
|
1532
|
+
if (minzoom !== prevPropsWithFilter.minzoom || maxzoom !== prevPropsWithFilter.maxzoom) {
|
|
1378
1533
|
map.setLayerZoomRange(id, minzoom, maxzoom);
|
|
1379
1534
|
}
|
|
1380
1535
|
}
|
|
1381
1536
|
function createLayer(map, id, props) {
|
|
1382
|
-
|
|
1383
|
-
|
|
1537
|
+
const mapInternal = map;
|
|
1538
|
+
if (mapInternal.style && mapInternal.style._loaded && (!("source" in props) || map.getSource(props.source))) {
|
|
1539
|
+
const options = { ...props, id };
|
|
1384
1540
|
delete options.beforeId;
|
|
1385
1541
|
map.addLayer(options, props.beforeId);
|
|
1386
1542
|
}
|
|
1387
1543
|
}
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
const
|
|
1391
|
-
const
|
|
1392
|
-
const
|
|
1393
|
-
const id = (0,
|
|
1394
|
-
|
|
1544
|
+
function _Layer(props) {
|
|
1545
|
+
const map = (0, import_react16.useContext)(MapContext).map.getMap();
|
|
1546
|
+
const propsRef = (0, import_react16.useRef)(props);
|
|
1547
|
+
const [, setStyleLoaded] = (0, import_react16.useState)(0);
|
|
1548
|
+
const generatedId = (0, import_react16.useId)();
|
|
1549
|
+
const id = (0, import_react16.useMemo)(
|
|
1550
|
+
() => props.id || `jsx-layer-${generatedId.replace(/:/g, "-")}`,
|
|
1551
|
+
// Empty deps - id is set once on mount and should not change
|
|
1552
|
+
[]
|
|
1553
|
+
);
|
|
1554
|
+
const {
|
|
1555
|
+
onClick,
|
|
1556
|
+
onMouseEnter,
|
|
1557
|
+
onMouseLeave,
|
|
1558
|
+
onMouseMove,
|
|
1559
|
+
onMouseDown,
|
|
1560
|
+
onMouseUp,
|
|
1561
|
+
onContextMenu,
|
|
1562
|
+
onDoubleClick
|
|
1563
|
+
} = props;
|
|
1564
|
+
const callbacksRef = (0, import_react16.useRef)({
|
|
1565
|
+
onClick,
|
|
1566
|
+
onMouseEnter,
|
|
1567
|
+
onMouseLeave,
|
|
1568
|
+
onMouseMove,
|
|
1569
|
+
onMouseDown,
|
|
1570
|
+
onMouseUp,
|
|
1571
|
+
onContextMenu,
|
|
1572
|
+
onDoubleClick
|
|
1573
|
+
});
|
|
1574
|
+
(0, import_react16.useEffect)(() => {
|
|
1575
|
+
callbacksRef.current = {
|
|
1576
|
+
onClick,
|
|
1577
|
+
onMouseEnter,
|
|
1578
|
+
onMouseLeave,
|
|
1579
|
+
onMouseMove,
|
|
1580
|
+
onMouseDown,
|
|
1581
|
+
onMouseUp,
|
|
1582
|
+
onContextMenu,
|
|
1583
|
+
onDoubleClick
|
|
1584
|
+
};
|
|
1585
|
+
}, [
|
|
1586
|
+
onClick,
|
|
1587
|
+
onMouseEnter,
|
|
1588
|
+
onMouseLeave,
|
|
1589
|
+
onMouseMove,
|
|
1590
|
+
onMouseDown,
|
|
1591
|
+
onMouseUp,
|
|
1592
|
+
onContextMenu,
|
|
1593
|
+
onDoubleClick
|
|
1594
|
+
]);
|
|
1595
|
+
(0, import_react16.useEffect)(() => {
|
|
1395
1596
|
if (map) {
|
|
1396
1597
|
const forceUpdate = () => setStyleLoaded((version) => version + 1);
|
|
1397
1598
|
map.on("styledata", forceUpdate);
|
|
1398
1599
|
forceUpdate();
|
|
1399
1600
|
return () => {
|
|
1400
1601
|
map.off("styledata", forceUpdate);
|
|
1401
|
-
|
|
1602
|
+
const mapInternal2 = map;
|
|
1603
|
+
if (mapInternal2.style && mapInternal2.style._loaded && map.getLayer(id)) {
|
|
1402
1604
|
map.removeLayer(id);
|
|
1403
1605
|
}
|
|
1404
1606
|
};
|
|
1405
1607
|
}
|
|
1406
1608
|
return void 0;
|
|
1407
1609
|
}, [map]);
|
|
1408
|
-
|
|
1610
|
+
(0, import_react16.useEffect)(() => {
|
|
1611
|
+
if (!map) return void 0;
|
|
1612
|
+
const hasEventHandler = onClick || onMouseEnter || onMouseLeave || onMouseMove || onMouseDown || onMouseUp || onContextMenu || onDoubleClick;
|
|
1613
|
+
if (!hasEventHandler) return void 0;
|
|
1614
|
+
const handleClick = (e) => {
|
|
1615
|
+
callbacksRef.current.onClick?.(e);
|
|
1616
|
+
};
|
|
1617
|
+
const handleMouseEnter = (e) => {
|
|
1618
|
+
callbacksRef.current.onMouseEnter?.(e);
|
|
1619
|
+
if (callbacksRef.current.onClick) {
|
|
1620
|
+
map.getCanvas().style.cursor = "pointer";
|
|
1621
|
+
}
|
|
1622
|
+
};
|
|
1623
|
+
const handleMouseLeave = () => {
|
|
1624
|
+
callbacksRef.current.onMouseLeave?.();
|
|
1625
|
+
map.getCanvas().style.cursor = "";
|
|
1626
|
+
};
|
|
1627
|
+
const handleMouseMove = (e) => {
|
|
1628
|
+
callbacksRef.current.onMouseMove?.(e);
|
|
1629
|
+
};
|
|
1630
|
+
const handleMouseDown = (e) => {
|
|
1631
|
+
callbacksRef.current.onMouseDown?.(e);
|
|
1632
|
+
};
|
|
1633
|
+
const handleMouseUp = (e) => {
|
|
1634
|
+
callbacksRef.current.onMouseUp?.(e);
|
|
1635
|
+
};
|
|
1636
|
+
const handleContextMenu = (e) => {
|
|
1637
|
+
callbacksRef.current.onContextMenu?.(e);
|
|
1638
|
+
};
|
|
1639
|
+
const handleDoubleClick = (e) => {
|
|
1640
|
+
callbacksRef.current.onDoubleClick?.(e);
|
|
1641
|
+
};
|
|
1642
|
+
if (onClick) map.on("click", id, handleClick);
|
|
1643
|
+
if (onMouseEnter) map.on("mouseenter", id, handleMouseEnter);
|
|
1644
|
+
if (onMouseLeave) map.on("mouseleave", id, handleMouseLeave);
|
|
1645
|
+
if (onMouseMove) map.on("mousemove", id, handleMouseMove);
|
|
1646
|
+
if (onMouseDown) map.on("mousedown", id, handleMouseDown);
|
|
1647
|
+
if (onMouseUp) map.on("mouseup", id, handleMouseUp);
|
|
1648
|
+
if (onContextMenu) map.on("contextmenu", id, handleContextMenu);
|
|
1649
|
+
if (onDoubleClick) map.on("dblclick", id, handleDoubleClick);
|
|
1650
|
+
return () => {
|
|
1651
|
+
if (onClick) map.off("click", id, handleClick);
|
|
1652
|
+
if (onMouseEnter) map.off("mouseenter", id, handleMouseEnter);
|
|
1653
|
+
if (onMouseLeave) map.off("mouseleave", id, handleMouseLeave);
|
|
1654
|
+
if (onMouseMove) map.off("mousemove", id, handleMouseMove);
|
|
1655
|
+
if (onMouseDown) map.off("mousedown", id, handleMouseDown);
|
|
1656
|
+
if (onMouseUp) map.off("mouseup", id, handleMouseUp);
|
|
1657
|
+
if (onContextMenu) map.off("contextmenu", id, handleContextMenu);
|
|
1658
|
+
if (onDoubleClick) map.off("dblclick", id, handleDoubleClick);
|
|
1659
|
+
};
|
|
1660
|
+
}, [
|
|
1661
|
+
map,
|
|
1662
|
+
id,
|
|
1663
|
+
onClick,
|
|
1664
|
+
onMouseEnter,
|
|
1665
|
+
onMouseLeave,
|
|
1666
|
+
onMouseMove,
|
|
1667
|
+
onMouseDown,
|
|
1668
|
+
onMouseUp,
|
|
1669
|
+
onContextMenu,
|
|
1670
|
+
onDoubleClick
|
|
1671
|
+
]);
|
|
1672
|
+
const mapInternal = map;
|
|
1673
|
+
const layer = map && mapInternal.style && map.getLayer(id);
|
|
1409
1674
|
if (layer) {
|
|
1410
1675
|
try {
|
|
1411
1676
|
updateLayer(map, id, props, propsRef.current);
|
|
@@ -1418,6 +1683,774 @@ function Layer(props) {
|
|
|
1418
1683
|
propsRef.current = props;
|
|
1419
1684
|
return null;
|
|
1420
1685
|
}
|
|
1686
|
+
var Layer = (0, import_react16.memo)(_Layer);
|
|
1687
|
+
|
|
1688
|
+
// src/components/draw-control.ts
|
|
1689
|
+
var import_react17 = require("react");
|
|
1690
|
+
var import_maplibre_gl_draw = __toESM(require("maplibre-gl-draw"), 1);
|
|
1691
|
+
var defaultDrawOptions = {
|
|
1692
|
+
displayControlsDefault: false,
|
|
1693
|
+
controls: {
|
|
1694
|
+
polygon: true,
|
|
1695
|
+
trash: true
|
|
1696
|
+
}
|
|
1697
|
+
};
|
|
1698
|
+
function _DrawControl(props) {
|
|
1699
|
+
const {
|
|
1700
|
+
position,
|
|
1701
|
+
style,
|
|
1702
|
+
onDrawCreate,
|
|
1703
|
+
onDrawDelete,
|
|
1704
|
+
onDrawUpdate,
|
|
1705
|
+
onDrawSelectionChange,
|
|
1706
|
+
onDrawModeChange,
|
|
1707
|
+
onDrawCombine,
|
|
1708
|
+
onDrawUncombine,
|
|
1709
|
+
onDrawRender,
|
|
1710
|
+
...drawOptions
|
|
1711
|
+
} = props;
|
|
1712
|
+
const context = (0, import_react17.useContext)(MapContext);
|
|
1713
|
+
if (!context) {
|
|
1714
|
+
throw new Error("DrawControl must be used within a Map component");
|
|
1715
|
+
}
|
|
1716
|
+
const options = (0, import_react17.useMemo)(
|
|
1717
|
+
() => ({
|
|
1718
|
+
...defaultDrawOptions,
|
|
1719
|
+
...drawOptions,
|
|
1720
|
+
controls: {
|
|
1721
|
+
...defaultDrawOptions.controls,
|
|
1722
|
+
...drawOptions.controls
|
|
1723
|
+
}
|
|
1724
|
+
}),
|
|
1725
|
+
[
|
|
1726
|
+
drawOptions.displayControlsDefault,
|
|
1727
|
+
drawOptions.controls,
|
|
1728
|
+
drawOptions.styles,
|
|
1729
|
+
drawOptions.modes,
|
|
1730
|
+
drawOptions.defaultMode
|
|
1731
|
+
]
|
|
1732
|
+
);
|
|
1733
|
+
const optionsKey = (0, import_react17.useMemo)(() => JSON.stringify(options), [options]);
|
|
1734
|
+
const callbacksRef = (0, import_react17.useRef)({
|
|
1735
|
+
onDrawCreate,
|
|
1736
|
+
onDrawDelete,
|
|
1737
|
+
onDrawUpdate,
|
|
1738
|
+
onDrawSelectionChange,
|
|
1739
|
+
onDrawModeChange,
|
|
1740
|
+
onDrawCombine,
|
|
1741
|
+
onDrawUncombine,
|
|
1742
|
+
onDrawRender
|
|
1743
|
+
});
|
|
1744
|
+
(0, import_react17.useEffect)(() => {
|
|
1745
|
+
callbacksRef.current = {
|
|
1746
|
+
onDrawCreate,
|
|
1747
|
+
onDrawDelete,
|
|
1748
|
+
onDrawUpdate,
|
|
1749
|
+
onDrawSelectionChange,
|
|
1750
|
+
onDrawModeChange,
|
|
1751
|
+
onDrawCombine,
|
|
1752
|
+
onDrawUncombine,
|
|
1753
|
+
onDrawRender
|
|
1754
|
+
};
|
|
1755
|
+
}, [
|
|
1756
|
+
onDrawCreate,
|
|
1757
|
+
onDrawDelete,
|
|
1758
|
+
onDrawUpdate,
|
|
1759
|
+
onDrawSelectionChange,
|
|
1760
|
+
onDrawModeChange,
|
|
1761
|
+
onDrawCombine,
|
|
1762
|
+
onDrawUncombine,
|
|
1763
|
+
onDrawRender
|
|
1764
|
+
]);
|
|
1765
|
+
const ctrlRef = (0, import_react17.useRef)(null);
|
|
1766
|
+
const listenersRef = (0, import_react17.useRef)({});
|
|
1767
|
+
(0, import_react17.useEffect)(() => {
|
|
1768
|
+
const { map } = context;
|
|
1769
|
+
if (!map) return;
|
|
1770
|
+
const mapInstance = map.getMap();
|
|
1771
|
+
if (!mapInstance) return;
|
|
1772
|
+
const DrawClass = import_maplibre_gl_draw.default;
|
|
1773
|
+
const resetCursorIfNeeded = () => {
|
|
1774
|
+
if (ctrlRef.current) {
|
|
1775
|
+
const currentMode = ctrlRef.current.getMode();
|
|
1776
|
+
if (currentMode === "simple_select") {
|
|
1777
|
+
mapInstance.getCanvas().style.cursor = "";
|
|
1778
|
+
}
|
|
1779
|
+
}
|
|
1780
|
+
};
|
|
1781
|
+
const handleCreate = (e) => {
|
|
1782
|
+
resetCursorIfNeeded();
|
|
1783
|
+
callbacksRef.current.onDrawCreate?.(e);
|
|
1784
|
+
};
|
|
1785
|
+
const handleUpdate = (e) => {
|
|
1786
|
+
resetCursorIfNeeded();
|
|
1787
|
+
callbacksRef.current.onDrawUpdate?.(e);
|
|
1788
|
+
};
|
|
1789
|
+
const handleDelete = (e) => {
|
|
1790
|
+
resetCursorIfNeeded();
|
|
1791
|
+
callbacksRef.current.onDrawDelete?.(e);
|
|
1792
|
+
};
|
|
1793
|
+
const handleSelectionChange = (e) => {
|
|
1794
|
+
resetCursorIfNeeded();
|
|
1795
|
+
callbacksRef.current.onDrawSelectionChange?.(e);
|
|
1796
|
+
};
|
|
1797
|
+
const handleModeChange = (e) => {
|
|
1798
|
+
resetCursorIfNeeded();
|
|
1799
|
+
callbacksRef.current.onDrawModeChange?.(e);
|
|
1800
|
+
};
|
|
1801
|
+
const handleCombine = (e) => {
|
|
1802
|
+
callbacksRef.current.onDrawCombine?.(e);
|
|
1803
|
+
};
|
|
1804
|
+
const handleUncombine = (e) => {
|
|
1805
|
+
callbacksRef.current.onDrawUncombine?.(e);
|
|
1806
|
+
};
|
|
1807
|
+
const handleRender = (e) => {
|
|
1808
|
+
callbacksRef.current.onDrawRender?.(e);
|
|
1809
|
+
};
|
|
1810
|
+
const ctrl = new DrawClass(options);
|
|
1811
|
+
ctrlRef.current = ctrl;
|
|
1812
|
+
map.addControl(ctrl, position);
|
|
1813
|
+
listenersRef.current = {
|
|
1814
|
+
handleCreate,
|
|
1815
|
+
handleUpdate,
|
|
1816
|
+
handleDelete,
|
|
1817
|
+
handleSelectionChange,
|
|
1818
|
+
handleModeChange,
|
|
1819
|
+
handleCombine,
|
|
1820
|
+
handleUncombine,
|
|
1821
|
+
handleRender
|
|
1822
|
+
};
|
|
1823
|
+
mapInstance.on("draw.create", handleCreate);
|
|
1824
|
+
mapInstance.on("draw.update", handleUpdate);
|
|
1825
|
+
mapInstance.on("draw.delete", handleDelete);
|
|
1826
|
+
mapInstance.on("draw.selectionchange", handleSelectionChange);
|
|
1827
|
+
mapInstance.on("draw.modechange", handleModeChange);
|
|
1828
|
+
mapInstance.on("draw.combine", handleCombine);
|
|
1829
|
+
mapInstance.on("draw.uncombine", handleUncombine);
|
|
1830
|
+
mapInstance.on("draw.render", handleRender);
|
|
1831
|
+
return () => {
|
|
1832
|
+
if (listenersRef.current.handleCreate) {
|
|
1833
|
+
mapInstance.off("draw.create", listenersRef.current.handleCreate);
|
|
1834
|
+
}
|
|
1835
|
+
if (listenersRef.current.handleUpdate) {
|
|
1836
|
+
mapInstance.off("draw.update", listenersRef.current.handleUpdate);
|
|
1837
|
+
}
|
|
1838
|
+
if (listenersRef.current.handleDelete) {
|
|
1839
|
+
mapInstance.off("draw.delete", listenersRef.current.handleDelete);
|
|
1840
|
+
}
|
|
1841
|
+
if (listenersRef.current.handleSelectionChange) {
|
|
1842
|
+
mapInstance.off("draw.selectionchange", listenersRef.current.handleSelectionChange);
|
|
1843
|
+
}
|
|
1844
|
+
if (listenersRef.current.handleModeChange) {
|
|
1845
|
+
mapInstance.off("draw.modechange", listenersRef.current.handleModeChange);
|
|
1846
|
+
}
|
|
1847
|
+
if (listenersRef.current.handleCombine) {
|
|
1848
|
+
mapInstance.off("draw.combine", listenersRef.current.handleCombine);
|
|
1849
|
+
}
|
|
1850
|
+
if (listenersRef.current.handleUncombine) {
|
|
1851
|
+
mapInstance.off("draw.uncombine", listenersRef.current.handleUncombine);
|
|
1852
|
+
}
|
|
1853
|
+
if (listenersRef.current.handleRender) {
|
|
1854
|
+
mapInstance.off("draw.render", listenersRef.current.handleRender);
|
|
1855
|
+
}
|
|
1856
|
+
if (ctrlRef.current && map.hasControl(ctrlRef.current)) {
|
|
1857
|
+
map.removeControl(ctrlRef.current);
|
|
1858
|
+
}
|
|
1859
|
+
ctrlRef.current = null;
|
|
1860
|
+
};
|
|
1861
|
+
}, [context, optionsKey, position]);
|
|
1862
|
+
return null;
|
|
1863
|
+
}
|
|
1864
|
+
var DrawControl = (0, import_react17.memo)(_DrawControl);
|
|
1865
|
+
|
|
1866
|
+
// src/components/globe-control.ts
|
|
1867
|
+
var import_react18 = require("react");
|
|
1868
|
+
var GLOBE_SVG = `<svg viewBox="0 0 24 24" width="24" height="24" stroke="currentColor" stroke-width="2">
|
|
1869
|
+
<circle cx="12" cy="12" r="9" fill="none"/>
|
|
1870
|
+
<path d="M12 21a9 9-9 0 0-9 9-9 0 0 9h0c2.2a8.2 2.3 5.1 5.8-5.5c-.4-.4-.5-.9-.5-1.5v-1.3c0-2.3 1.8-4.2 4-4.5V5.5c-1.8.5-3.5 2-4.5 2.8 0 5.2 2.3 5.2 5 0z"/>
|
|
1871
|
+
<path d="M12 3c-2.8 0-5.2 2.3-5.2 5h2c0-1.5.1-1.1.5-1.5L5.8 9 2.3 5.1 8.2 2c.4 0 .9-.5 1.5-.5h1.3c2.3 0 4.2-1.8 4.5-4h-2c0 1.5-1.8 3.5-4 4.5V21c2.8 0 5.2-2.3 5.2-5h-2c0 1.5-.1 1.1-.5 1.5L18.2 15 14.8l2.7-5.1c-.4 0-.9.5-1.5.5h-1.3c-2.3 0-4.2 1.8-4.5 4h2c0-1.5 1.8-3.5 4-4.5V3z"/>
|
|
1872
|
+
</svg>`;
|
|
1873
|
+
var MAP_SVG = `<svg viewBox="0 0 24 24" width="24" height="24" stroke="currentColor" stroke-width="2">
|
|
1874
|
+
<rect x="3" y="3" width="18" height="18" rx="2" fill="none"/>
|
|
1875
|
+
<path d="M3 9h18M3 15h18M9 3v18M15 3v18"/>
|
|
1876
|
+
</svg>`;
|
|
1877
|
+
var GlobeControlImpl = class {
|
|
1878
|
+
constructor(options, callbacks) {
|
|
1879
|
+
this._map = null;
|
|
1880
|
+
this._isGlobe = false;
|
|
1881
|
+
this._options = options;
|
|
1882
|
+
this._onProjectionChange = callbacks.onProjectionChange;
|
|
1883
|
+
this._container = document.createElement("div");
|
|
1884
|
+
this._container.className = "maplibregl-ctrl maplibregl-ctrl-group";
|
|
1885
|
+
this._button = this._createButton();
|
|
1886
|
+
this._container.appendChild(this._button);
|
|
1887
|
+
}
|
|
1888
|
+
_createButton() {
|
|
1889
|
+
const button = this._options.buttonElement || document.createElement("button");
|
|
1890
|
+
if (!this._options.buttonElement) {
|
|
1891
|
+
button.className = this._options.buttonClassName || "maplibregl-ctrl-globe";
|
|
1892
|
+
button.type = "button";
|
|
1893
|
+
button.title = this._options.buttonTitle || "Toggle Globe View";
|
|
1894
|
+
button.setAttribute("aria-label", "Toggle Globe View");
|
|
1895
|
+
button.innerHTML = this._isGlobe ? MAP_SVG : GLOBE_SVG;
|
|
1896
|
+
Object.assign(button.style, {
|
|
1897
|
+
padding: "5px",
|
|
1898
|
+
border: "none",
|
|
1899
|
+
background: "white",
|
|
1900
|
+
cursor: "pointer",
|
|
1901
|
+
borderRadius: "4px",
|
|
1902
|
+
display: "flex",
|
|
1903
|
+
alignItems: "center",
|
|
1904
|
+
justifyContent: "center",
|
|
1905
|
+
...this._options.buttonStyle
|
|
1906
|
+
});
|
|
1907
|
+
}
|
|
1908
|
+
button.addEventListener("click", () => this._toggleGlobe());
|
|
1909
|
+
return button;
|
|
1910
|
+
}
|
|
1911
|
+
_toggleGlobe() {
|
|
1912
|
+
if (!this._map) return;
|
|
1913
|
+
this._isGlobe = !this._isGlobe;
|
|
1914
|
+
this._button.innerHTML = this._isGlobe ? MAP_SVG : GLOBE_SVG;
|
|
1915
|
+
this._button.title = this._isGlobe ? "Switch to Map View" : "Switch to Globe View";
|
|
1916
|
+
try {
|
|
1917
|
+
const projection = this._isGlobe ? { type: "globe" } : { type: "mercator" };
|
|
1918
|
+
this._map.setProjection(projection);
|
|
1919
|
+
this._onProjectionChange?.(this._isGlobe);
|
|
1920
|
+
} catch (error) {
|
|
1921
|
+
console.warn("GlobeControl: setProjection not available", error);
|
|
1922
|
+
}
|
|
1923
|
+
}
|
|
1924
|
+
onAdd(map) {
|
|
1925
|
+
this._map = map;
|
|
1926
|
+
try {
|
|
1927
|
+
const currentProjection = map.getProjection?.();
|
|
1928
|
+
this._isGlobe = currentProjection?.type === "globe";
|
|
1929
|
+
this._button.innerHTML = this._isGlobe ? MAP_SVG : GLOBE_SVG;
|
|
1930
|
+
} catch {
|
|
1931
|
+
this._isGlobe = false;
|
|
1932
|
+
}
|
|
1933
|
+
return this._container;
|
|
1934
|
+
}
|
|
1935
|
+
onRemove() {
|
|
1936
|
+
this._container.parentNode?.removeChild(this._container);
|
|
1937
|
+
this._map = null;
|
|
1938
|
+
}
|
|
1939
|
+
/**
|
|
1940
|
+
* Check if currently in globe view
|
|
1941
|
+
*/
|
|
1942
|
+
isGlobe() {
|
|
1943
|
+
return this._isGlobe;
|
|
1944
|
+
}
|
|
1945
|
+
/**
|
|
1946
|
+
* Set the projection programmatically
|
|
1947
|
+
*/
|
|
1948
|
+
setGlobe(isGlobe) {
|
|
1949
|
+
if (this._isGlobe !== isGlobe) {
|
|
1950
|
+
this._toggleGlobe();
|
|
1951
|
+
}
|
|
1952
|
+
}
|
|
1953
|
+
};
|
|
1954
|
+
function _GlobeControl(props) {
|
|
1955
|
+
const { position, onProjectionChange, ...options } = props;
|
|
1956
|
+
const callbacksRef = (0, import_react18.useRef)({ onProjectionChange });
|
|
1957
|
+
(0, import_react18.useEffect)(() => {
|
|
1958
|
+
callbacksRef.current = { onProjectionChange };
|
|
1959
|
+
}, [onProjectionChange]);
|
|
1960
|
+
useControl(
|
|
1961
|
+
() => {
|
|
1962
|
+
return new GlobeControlImpl(options, {
|
|
1963
|
+
onProjectionChange: (isGlobe) => callbacksRef.current.onProjectionChange?.(isGlobe)
|
|
1964
|
+
});
|
|
1965
|
+
},
|
|
1966
|
+
{ position }
|
|
1967
|
+
);
|
|
1968
|
+
return null;
|
|
1969
|
+
}
|
|
1970
|
+
var GlobeControl = (0, import_react18.memo)(_GlobeControl);
|
|
1971
|
+
|
|
1972
|
+
// src/components/minimap-control.ts
|
|
1973
|
+
var import_react19 = require("react");
|
|
1974
|
+
var import_maplibre_gl = require("maplibre-gl");
|
|
1975
|
+
var DEFAULT_ZOOM_ADJUST = -4;
|
|
1976
|
+
var DEFAULT_COLLAPSED_SIZE = "29px";
|
|
1977
|
+
var DEFAULT_BORDER_RADIUS = "3px";
|
|
1978
|
+
var TRANSITION_DURATION_MS = 600;
|
|
1979
|
+
var RESIZE_DEBOUNCE_MS = 100;
|
|
1980
|
+
var DEFAULT_WIDTH = "400px";
|
|
1981
|
+
var DEFAULT_HEIGHT = "300px";
|
|
1982
|
+
var defaultInteractions = {
|
|
1983
|
+
dragPan: true,
|
|
1984
|
+
scrollZoom: false,
|
|
1985
|
+
boxZoom: false,
|
|
1986
|
+
dragRotate: false,
|
|
1987
|
+
keyboard: false,
|
|
1988
|
+
doubleClickZoom: false,
|
|
1989
|
+
touchZoomRotate: false
|
|
1990
|
+
};
|
|
1991
|
+
var DEFAULT_ICON = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M17.6 18L8 8.4V17H6V5h12v2H9.4l9.6 9.6l-1.4 1.4Z" /></svg>`;
|
|
1992
|
+
function getRandomUUID() {
|
|
1993
|
+
if (typeof crypto !== "undefined" && crypto.randomUUID) {
|
|
1994
|
+
return crypto.randomUUID();
|
|
1995
|
+
}
|
|
1996
|
+
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(c) {
|
|
1997
|
+
const array = new Uint8Array(1);
|
|
1998
|
+
crypto.getRandomValues(array);
|
|
1999
|
+
const r = array[0] % 16;
|
|
2000
|
+
const v = c === "x" ? r : r & 3 | 8;
|
|
2001
|
+
return v.toString(16);
|
|
2002
|
+
});
|
|
2003
|
+
}
|
|
2004
|
+
function sanitizeSVG(svgString) {
|
|
2005
|
+
const svgPattern = /^<svg[^>]*>[\s\S]*<\/svg>$/i;
|
|
2006
|
+
if (!svgPattern.test(svgString)) {
|
|
2007
|
+
console.warn("Invalid SVG format, using default icon");
|
|
2008
|
+
return DEFAULT_ICON;
|
|
2009
|
+
}
|
|
2010
|
+
return svgString.replace(/<script[\s\S]*?<\/script>/gi, "").replace(/\s*on\w+\s*=\s*["'][^"']*["']/gi, "").replace(/javascript:/gi, "");
|
|
2011
|
+
}
|
|
2012
|
+
var Minimap = class {
|
|
2013
|
+
constructor(options = {}) {
|
|
2014
|
+
this.differentStyle = false;
|
|
2015
|
+
this.isMinimized = false;
|
|
2016
|
+
this.id = `minimap-${getRandomUUID()}`;
|
|
2017
|
+
if (options.style !== void 0) {
|
|
2018
|
+
this.differentStyle = true;
|
|
2019
|
+
}
|
|
2020
|
+
const interactions = { ...defaultInteractions, ...options.interactions ?? {} };
|
|
2021
|
+
const containerStyle = this.validateContainerStyle(options.containerStyle);
|
|
2022
|
+
this.options = {
|
|
2023
|
+
zoomAdjust: DEFAULT_ZOOM_ADJUST,
|
|
2024
|
+
position: "top-right",
|
|
2025
|
+
pitchAdjust: false,
|
|
2026
|
+
attributionControl: false,
|
|
2027
|
+
logoPosition: "bottom-left",
|
|
2028
|
+
toggleable: true,
|
|
2029
|
+
initialMinimized: false,
|
|
2030
|
+
collapsedWidth: DEFAULT_COLLAPSED_SIZE,
|
|
2031
|
+
collapsedHeight: DEFAULT_COLLAPSED_SIZE,
|
|
2032
|
+
borderRadius: DEFAULT_BORDER_RADIUS,
|
|
2033
|
+
hideText: "Hide minimap",
|
|
2034
|
+
showText: "Show minimap",
|
|
2035
|
+
responsive: true,
|
|
2036
|
+
responsiveWidth: "20vw",
|
|
2037
|
+
responsiveHeight: "20vh",
|
|
2038
|
+
minWidth: "200px",
|
|
2039
|
+
minHeight: "150px",
|
|
2040
|
+
maxWidth: DEFAULT_WIDTH,
|
|
2041
|
+
maxHeight: DEFAULT_HEIGHT,
|
|
2042
|
+
interactions,
|
|
2043
|
+
...options,
|
|
2044
|
+
containerStyle
|
|
2045
|
+
};
|
|
2046
|
+
if (options.lockZoom !== void 0) {
|
|
2047
|
+
this.options.minZoom = options.lockZoom;
|
|
2048
|
+
this.options.maxZoom = options.lockZoom;
|
|
2049
|
+
}
|
|
2050
|
+
this.isMinimized = this.options.initialMinimized ?? false;
|
|
2051
|
+
}
|
|
2052
|
+
onAdd(parentMap) {
|
|
2053
|
+
this.parentMap = parentMap;
|
|
2054
|
+
this.container = this.createContainer();
|
|
2055
|
+
this.options.container = this.container;
|
|
2056
|
+
this.options.zoom = parentMap.getZoom() + (this.options.zoomAdjust ?? DEFAULT_ZOOM_ADJUST);
|
|
2057
|
+
this.options.center ??= parentMap.getCenter().toArray();
|
|
2058
|
+
this.options.bearing = parentMap.getBearing();
|
|
2059
|
+
this.options.pitch = this.options.pitchAdjust ? parentMap.getPitch() : 0;
|
|
2060
|
+
if (!this.differentStyle) {
|
|
2061
|
+
this.options.style = parentMap.getStyle();
|
|
2062
|
+
}
|
|
2063
|
+
this.map = new import_maplibre_gl.Map(this.options);
|
|
2064
|
+
this.map.once("style.load", () => {
|
|
2065
|
+
this.map.resize();
|
|
2066
|
+
});
|
|
2067
|
+
this.map.once("load", () => {
|
|
2068
|
+
this.configureInteractions();
|
|
2069
|
+
this.addParentRect(this.options.parentRect);
|
|
2070
|
+
this.desync = this.syncMaps();
|
|
2071
|
+
this.setupToggleButton();
|
|
2072
|
+
this.setupResponsiveSizing();
|
|
2073
|
+
});
|
|
2074
|
+
return this.container;
|
|
2075
|
+
}
|
|
2076
|
+
onRemove() {
|
|
2077
|
+
if (this.resizeHandler) {
|
|
2078
|
+
window.removeEventListener("resize", this.resizeHandler);
|
|
2079
|
+
this.resizeHandler = void 0;
|
|
2080
|
+
}
|
|
2081
|
+
this.toggleButtonCleanup?.();
|
|
2082
|
+
this.desync?.();
|
|
2083
|
+
this.container.remove();
|
|
2084
|
+
}
|
|
2085
|
+
createContainer() {
|
|
2086
|
+
const container = document.createElement("div");
|
|
2087
|
+
container.id = this.id;
|
|
2088
|
+
container.className = "maplibregl-ctrl maplibregl-ctrl-group maplibregl-ctrl-minimap custom-ctrl-minimap";
|
|
2089
|
+
if (this.isMinimized) {
|
|
2090
|
+
container.classList.add("minimized");
|
|
2091
|
+
}
|
|
2092
|
+
const styleEl = document.createElement("style");
|
|
2093
|
+
styleEl.innerHTML = this.getContainerStyles();
|
|
2094
|
+
container.appendChild(styleEl);
|
|
2095
|
+
if (this.options.containerStyle) {
|
|
2096
|
+
for (const [key, value] of Object.entries(this.options.containerStyle)) {
|
|
2097
|
+
container.style.setProperty(key, value);
|
|
2098
|
+
}
|
|
2099
|
+
}
|
|
2100
|
+
if (this.isMinimized) {
|
|
2101
|
+
container.style.width = this.options.collapsedWidth || DEFAULT_COLLAPSED_SIZE;
|
|
2102
|
+
container.style.height = this.options.collapsedHeight || DEFAULT_COLLAPSED_SIZE;
|
|
2103
|
+
}
|
|
2104
|
+
const preventDefault = (e) => e.preventDefault();
|
|
2105
|
+
container.addEventListener("contextmenu", preventDefault);
|
|
2106
|
+
return container;
|
|
2107
|
+
}
|
|
2108
|
+
getContainerStyles() {
|
|
2109
|
+
const width = this.options.containerStyle?.width || DEFAULT_WIDTH;
|
|
2110
|
+
const height = this.options.containerStyle?.height || DEFAULT_HEIGHT;
|
|
2111
|
+
const collapsedWidth = this.options.collapsedWidth || DEFAULT_COLLAPSED_SIZE;
|
|
2112
|
+
const collapsedHeight = this.options.collapsedHeight || DEFAULT_COLLAPSED_SIZE;
|
|
2113
|
+
const borderRadius = this.options.borderRadius || DEFAULT_BORDER_RADIUS;
|
|
2114
|
+
return `
|
|
2115
|
+
#${this.id}.custom-ctrl-minimap {
|
|
2116
|
+
cursor: default !important;
|
|
2117
|
+
box-shadow: 0 1px 5px rgba(0, 0, 0, 0.65);
|
|
2118
|
+
transition: width 0.6s ease-in, height 0.6s ease-in, border-color 0s ease-in;
|
|
2119
|
+
border-style: solid;
|
|
2120
|
+
border-radius: ${borderRadius};
|
|
2121
|
+
border-width: 4px;
|
|
2122
|
+
border-color: white;
|
|
2123
|
+
width: ${width};
|
|
2124
|
+
height: ${height};
|
|
2125
|
+
overflow: hidden;
|
|
2126
|
+
background: #fff;
|
|
2127
|
+
position: relative;
|
|
2128
|
+
}
|
|
2129
|
+
#${this.id}.minimized {
|
|
2130
|
+
border-radius: 3px !important;
|
|
2131
|
+
width: ${collapsedWidth};
|
|
2132
|
+
height: ${collapsedHeight};
|
|
2133
|
+
}
|
|
2134
|
+
#${this.id} canvas {
|
|
2135
|
+
width: 100% !important;
|
|
2136
|
+
height: 100% !important;
|
|
2137
|
+
display: block;
|
|
2138
|
+
}
|
|
2139
|
+
@media (prefers-color-scheme: dark) {
|
|
2140
|
+
#${this.id}.custom-ctrl-minimap {
|
|
2141
|
+
border-color: hsl(0, 0%, 15.2%);
|
|
2142
|
+
}
|
|
2143
|
+
}
|
|
2144
|
+
`;
|
|
2145
|
+
}
|
|
2146
|
+
validateContainerStyle(style) {
|
|
2147
|
+
const defaults = { border: "1px solid #000", width: DEFAULT_WIDTH, height: DEFAULT_HEIGHT };
|
|
2148
|
+
if (!style) return defaults;
|
|
2149
|
+
const validated = {};
|
|
2150
|
+
if (style.width) {
|
|
2151
|
+
validated.width = CSS.supports("width", style.width) ? style.width : defaults.width;
|
|
2152
|
+
} else {
|
|
2153
|
+
validated.width = defaults.width;
|
|
2154
|
+
}
|
|
2155
|
+
if (style.height) {
|
|
2156
|
+
validated.height = CSS.supports("height", style.height) ? style.height : defaults.height;
|
|
2157
|
+
} else {
|
|
2158
|
+
validated.height = defaults.height;
|
|
2159
|
+
}
|
|
2160
|
+
for (const [key, value] of Object.entries(style)) {
|
|
2161
|
+
if (key !== "width" && key !== "height") {
|
|
2162
|
+
validated[key] = value;
|
|
2163
|
+
}
|
|
2164
|
+
}
|
|
2165
|
+
return validated;
|
|
2166
|
+
}
|
|
2167
|
+
configureInteractions() {
|
|
2168
|
+
const interactions = this.options.interactions || defaultInteractions;
|
|
2169
|
+
for (const [interaction, enabled] of Object.entries(interactions)) {
|
|
2170
|
+
if (!enabled) {
|
|
2171
|
+
const interactionMethod = interaction;
|
|
2172
|
+
const interactionObj = this.map[interactionMethod];
|
|
2173
|
+
interactionObj?.disable();
|
|
2174
|
+
}
|
|
2175
|
+
}
|
|
2176
|
+
}
|
|
2177
|
+
setupToggleButton() {
|
|
2178
|
+
if (!this.options.toggleable) return;
|
|
2179
|
+
const el = document.createElement("button");
|
|
2180
|
+
const elId = "btn-" + getRandomUUID();
|
|
2181
|
+
el.innerHTML = sanitizeSVG(this.options.toggleButton?.icon || DEFAULT_ICON);
|
|
2182
|
+
el.setAttribute("id", elId);
|
|
2183
|
+
el.setAttribute("type", "button");
|
|
2184
|
+
el.setAttribute("aria-label", this.options.hideText || "Hide minimap");
|
|
2185
|
+
el.setAttribute("title", this.options.hideText || "Hide minimap");
|
|
2186
|
+
if (this.options.toggleButton?.className) {
|
|
2187
|
+
const classes = this.options.toggleButton.className.split(" ");
|
|
2188
|
+
classes.forEach((cls) => el.classList.add(cls));
|
|
2189
|
+
}
|
|
2190
|
+
const iconBackgroundColor = this.options.toggleButton?.iconBackgroundColor || "black";
|
|
2191
|
+
const hoverColor = this.options.toggleButton?.hoverColor || "#e5e7e3";
|
|
2192
|
+
const styleEl = document.createElement("style");
|
|
2193
|
+
styleEl.innerHTML = `
|
|
2194
|
+
button#${elId} {
|
|
2195
|
+
border-radius: 0 !important;
|
|
2196
|
+
color: black;
|
|
2197
|
+
background-color: ${iconBackgroundColor};
|
|
2198
|
+
border: none;
|
|
2199
|
+
display: flex;
|
|
2200
|
+
align-items: center;
|
|
2201
|
+
justify-content: center;
|
|
2202
|
+
cursor: pointer;
|
|
2203
|
+
transition: all 0.2s ease-in;
|
|
2204
|
+
position: absolute;
|
|
2205
|
+
width: 24px;
|
|
2206
|
+
height: 24px;
|
|
2207
|
+
z-index: 2;
|
|
2208
|
+
padding: 0;
|
|
2209
|
+
left: 0;
|
|
2210
|
+
top: 0;
|
|
2211
|
+
}
|
|
2212
|
+
button#${elId}:hover {
|
|
2213
|
+
background-color: ${hoverColor} !important;
|
|
2214
|
+
}
|
|
2215
|
+
button#${elId} svg {
|
|
2216
|
+
fill: white;
|
|
2217
|
+
width: 16px;
|
|
2218
|
+
height: 16px;
|
|
2219
|
+
}
|
|
2220
|
+
.minimized > button#${elId} > * {
|
|
2221
|
+
transform: rotate(-180deg);
|
|
2222
|
+
}
|
|
2223
|
+
`;
|
|
2224
|
+
const clickHandler = () => {
|
|
2225
|
+
this.toggle();
|
|
2226
|
+
const minimized = this.container.classList.contains("minimized");
|
|
2227
|
+
const text = minimized ? this.options.showText || "Show minimap" : this.options.hideText || "Hide minimap";
|
|
2228
|
+
el.setAttribute("aria-label", text);
|
|
2229
|
+
el.setAttribute("title", text);
|
|
2230
|
+
};
|
|
2231
|
+
el.addEventListener("click", clickHandler);
|
|
2232
|
+
document.head.appendChild(styleEl);
|
|
2233
|
+
this.container.appendChild(el);
|
|
2234
|
+
this.toggleButtonCleanup = () => {
|
|
2235
|
+
el.removeEventListener("click", clickHandler);
|
|
2236
|
+
styleEl.remove();
|
|
2237
|
+
this.container.removeChild(el);
|
|
2238
|
+
};
|
|
2239
|
+
}
|
|
2240
|
+
setupResponsiveSizing() {
|
|
2241
|
+
if (!this.options.responsive) return;
|
|
2242
|
+
const updateSize = () => {
|
|
2243
|
+
if (this.isMinimized) return;
|
|
2244
|
+
const vw = window.innerWidth / 100;
|
|
2245
|
+
const vh = window.innerHeight / 100;
|
|
2246
|
+
const responsiveWidth = this.options.responsiveWidth || "20vw";
|
|
2247
|
+
const responsiveHeight = this.options.responsiveHeight || "20vh";
|
|
2248
|
+
let width;
|
|
2249
|
+
let height;
|
|
2250
|
+
if (responsiveWidth.endsWith("vw")) {
|
|
2251
|
+
width = parseFloat(responsiveWidth) * vw;
|
|
2252
|
+
} else if (responsiveWidth.endsWith("%")) {
|
|
2253
|
+
width = parseFloat(responsiveWidth) / 100 * window.innerWidth;
|
|
2254
|
+
} else {
|
|
2255
|
+
width = parseFloat(responsiveWidth);
|
|
2256
|
+
}
|
|
2257
|
+
if (responsiveHeight.endsWith("vh")) {
|
|
2258
|
+
height = parseFloat(responsiveHeight) * vh;
|
|
2259
|
+
} else if (responsiveHeight.endsWith("%")) {
|
|
2260
|
+
height = parseFloat(responsiveHeight) / 100 * window.innerHeight;
|
|
2261
|
+
} else {
|
|
2262
|
+
height = parseFloat(responsiveHeight);
|
|
2263
|
+
}
|
|
2264
|
+
const minW = parseFloat(this.options.minWidth || "200px");
|
|
2265
|
+
const minH = parseFloat(this.options.minHeight || "150px");
|
|
2266
|
+
const maxW = parseFloat(this.options.maxWidth || DEFAULT_WIDTH);
|
|
2267
|
+
const maxH = parseFloat(this.options.maxHeight || DEFAULT_HEIGHT);
|
|
2268
|
+
width = Math.max(minW, Math.min(maxW, width));
|
|
2269
|
+
height = Math.max(minH, Math.min(maxH, height));
|
|
2270
|
+
this.container.style.width = `${width}px`;
|
|
2271
|
+
this.container.style.height = `${height}px`;
|
|
2272
|
+
this.map.resize();
|
|
2273
|
+
this.setParentBounds();
|
|
2274
|
+
};
|
|
2275
|
+
updateSize();
|
|
2276
|
+
let resizeTimeout;
|
|
2277
|
+
this.resizeHandler = () => {
|
|
2278
|
+
clearTimeout(resizeTimeout);
|
|
2279
|
+
resizeTimeout = setTimeout(updateSize, RESIZE_DEBOUNCE_MS);
|
|
2280
|
+
};
|
|
2281
|
+
window.addEventListener("resize", this.resizeHandler);
|
|
2282
|
+
}
|
|
2283
|
+
toggle() {
|
|
2284
|
+
this.isMinimized = !this.isMinimized;
|
|
2285
|
+
const collapsedWidth = this.options.collapsedWidth || DEFAULT_COLLAPSED_SIZE;
|
|
2286
|
+
const collapsedHeight = this.options.collapsedHeight || DEFAULT_COLLAPSED_SIZE;
|
|
2287
|
+
if (this.isMinimized) {
|
|
2288
|
+
this.container.classList.add("minimized");
|
|
2289
|
+
this.container.style.width = collapsedWidth;
|
|
2290
|
+
this.container.style.height = collapsedHeight;
|
|
2291
|
+
} else {
|
|
2292
|
+
this.container.classList.remove("minimized");
|
|
2293
|
+
if (this.options.responsive && this.resizeHandler) {
|
|
2294
|
+
this.resizeHandler();
|
|
2295
|
+
} else {
|
|
2296
|
+
const expandedWidth = this.options.containerStyle?.width || DEFAULT_WIDTH;
|
|
2297
|
+
const expandedHeight = this.options.containerStyle?.height || DEFAULT_HEIGHT;
|
|
2298
|
+
this.container.style.width = expandedWidth;
|
|
2299
|
+
this.container.style.height = expandedHeight;
|
|
2300
|
+
}
|
|
2301
|
+
}
|
|
2302
|
+
this.options.onToggle?.(this.isMinimized);
|
|
2303
|
+
setTimeout(() => {
|
|
2304
|
+
this.map.resize();
|
|
2305
|
+
this.setParentBounds();
|
|
2306
|
+
}, TRANSITION_DURATION_MS);
|
|
2307
|
+
}
|
|
2308
|
+
isMinimizedState() {
|
|
2309
|
+
return this.isMinimized;
|
|
2310
|
+
}
|
|
2311
|
+
addParentRect(rect) {
|
|
2312
|
+
if (rect === void 0 || rect.linePaint === void 0 && rect.fillPaint === void 0) {
|
|
2313
|
+
return;
|
|
2314
|
+
}
|
|
2315
|
+
this.parentRect = {
|
|
2316
|
+
type: "Feature",
|
|
2317
|
+
properties: { name: "parentRect" },
|
|
2318
|
+
geometry: {
|
|
2319
|
+
type: "Polygon",
|
|
2320
|
+
coordinates: [[[], [], [], [], []]]
|
|
2321
|
+
}
|
|
2322
|
+
};
|
|
2323
|
+
this.map.addSource("parentRect", {
|
|
2324
|
+
type: "geojson",
|
|
2325
|
+
data: this.parentRect
|
|
2326
|
+
});
|
|
2327
|
+
if (rect.lineLayout !== void 0 || rect.linePaint !== void 0) {
|
|
2328
|
+
this.map.addLayer({
|
|
2329
|
+
id: "parentRectOutline",
|
|
2330
|
+
type: "line",
|
|
2331
|
+
source: "parentRect",
|
|
2332
|
+
layout: { ...rect.lineLayout || {} },
|
|
2333
|
+
paint: {
|
|
2334
|
+
"line-color": "#FFF",
|
|
2335
|
+
"line-width": 1,
|
|
2336
|
+
"line-opacity": 0.85,
|
|
2337
|
+
...rect.linePaint || {}
|
|
2338
|
+
}
|
|
2339
|
+
});
|
|
2340
|
+
}
|
|
2341
|
+
if (rect.fillPaint !== void 0) {
|
|
2342
|
+
this.map.addLayer({
|
|
2343
|
+
id: "parentRectFill",
|
|
2344
|
+
type: "fill",
|
|
2345
|
+
source: "parentRect",
|
|
2346
|
+
layout: {},
|
|
2347
|
+
paint: {
|
|
2348
|
+
"fill-color": "#08F",
|
|
2349
|
+
"fill-opacity": 0.135,
|
|
2350
|
+
...rect.fillPaint || {}
|
|
2351
|
+
}
|
|
2352
|
+
});
|
|
2353
|
+
}
|
|
2354
|
+
this.setParentBounds();
|
|
2355
|
+
}
|
|
2356
|
+
setParentBounds() {
|
|
2357
|
+
if (this.parentRect === void 0 || this.isMinimized) return;
|
|
2358
|
+
const { devicePixelRatio } = window;
|
|
2359
|
+
const canvas = this.parentMap.getCanvas();
|
|
2360
|
+
const width = canvas.width / devicePixelRatio;
|
|
2361
|
+
const height = canvas.height / devicePixelRatio;
|
|
2362
|
+
const unproject = this.parentMap.unproject.bind(this.parentMap);
|
|
2363
|
+
const northWest = unproject([0, 0]);
|
|
2364
|
+
const northEast = unproject([width, 0]);
|
|
2365
|
+
const southWest = unproject([0, height]);
|
|
2366
|
+
const southEast = unproject([width, height]);
|
|
2367
|
+
this.parentRect.geometry.coordinates = [
|
|
2368
|
+
[
|
|
2369
|
+
southWest.toArray(),
|
|
2370
|
+
southEast.toArray(),
|
|
2371
|
+
northEast.toArray(),
|
|
2372
|
+
northWest.toArray(),
|
|
2373
|
+
southWest.toArray()
|
|
2374
|
+
]
|
|
2375
|
+
];
|
|
2376
|
+
const source = this.map.getSource("parentRect");
|
|
2377
|
+
if (source !== void 0) {
|
|
2378
|
+
source.setData(this.parentRect);
|
|
2379
|
+
}
|
|
2380
|
+
}
|
|
2381
|
+
syncMaps() {
|
|
2382
|
+
const { pitchAdjust } = this.options;
|
|
2383
|
+
const parentCallback = () => {
|
|
2384
|
+
if (!this.isMinimized) {
|
|
2385
|
+
sync("parent");
|
|
2386
|
+
}
|
|
2387
|
+
};
|
|
2388
|
+
const minimapCallback = () => {
|
|
2389
|
+
if (!this.isMinimized) {
|
|
2390
|
+
sync("minimap");
|
|
2391
|
+
}
|
|
2392
|
+
};
|
|
2393
|
+
const on = () => {
|
|
2394
|
+
this.parentMap.on("move", parentCallback);
|
|
2395
|
+
this.map.on("move", minimapCallback);
|
|
2396
|
+
};
|
|
2397
|
+
const off = () => {
|
|
2398
|
+
this.parentMap.off("move", parentCallback);
|
|
2399
|
+
this.map.off("move", minimapCallback);
|
|
2400
|
+
};
|
|
2401
|
+
const sync = (which) => {
|
|
2402
|
+
off();
|
|
2403
|
+
const from = which === "parent" ? this.parentMap : this.map;
|
|
2404
|
+
const to = which === "parent" ? this.map : this.parentMap;
|
|
2405
|
+
const center = from.getCenter();
|
|
2406
|
+
const zoom = from.getZoom() + (this.options.zoomAdjust ?? DEFAULT_ZOOM_ADJUST) * (which === "parent" ? 1 : -1);
|
|
2407
|
+
const bearing = from.getBearing();
|
|
2408
|
+
const pitch = from.getPitch();
|
|
2409
|
+
to.jumpTo({
|
|
2410
|
+
center,
|
|
2411
|
+
zoom,
|
|
2412
|
+
bearing,
|
|
2413
|
+
pitch: pitchAdjust ? pitch : 0
|
|
2414
|
+
});
|
|
2415
|
+
this.setParentBounds();
|
|
2416
|
+
on();
|
|
2417
|
+
};
|
|
2418
|
+
on();
|
|
2419
|
+
return () => {
|
|
2420
|
+
off();
|
|
2421
|
+
};
|
|
2422
|
+
}
|
|
2423
|
+
};
|
|
2424
|
+
function _MinimapControl(props) {
|
|
2425
|
+
const { position, ...options } = props;
|
|
2426
|
+
useControl(() => new Minimap(options), { position });
|
|
2427
|
+
return null;
|
|
2428
|
+
}
|
|
2429
|
+
var MinimapControl = (0, import_react19.memo)(_MinimapControl);
|
|
1421
2430
|
|
|
1422
2431
|
// src/exports-maplibre-gl.ts
|
|
1423
2432
|
var exports_maplibre_gl_default = Map;
|
|
2433
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
2434
|
+
0 && (module.exports = {
|
|
2435
|
+
AttributionControl,
|
|
2436
|
+
CanvasSource,
|
|
2437
|
+
DrawControl,
|
|
2438
|
+
FullscreenControl,
|
|
2439
|
+
GeolocateControl,
|
|
2440
|
+
GlobeControl,
|
|
2441
|
+
Layer,
|
|
2442
|
+
LogoControl,
|
|
2443
|
+
Map,
|
|
2444
|
+
MapProvider,
|
|
2445
|
+
Marker,
|
|
2446
|
+
Minimap,
|
|
2447
|
+
MinimapControl,
|
|
2448
|
+
NavigationControl,
|
|
2449
|
+
Popup,
|
|
2450
|
+
ScaleControl,
|
|
2451
|
+
Source,
|
|
2452
|
+
TerrainControl,
|
|
2453
|
+
useControl,
|
|
2454
|
+
useMap
|
|
2455
|
+
});
|
|
2456
|
+
//# sourceMappingURL=index.cjs.map
|