react-bkoi-gl 1.0.6 → 2.0.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/README.md +163 -18
- package/dist/components/attribution-control.d.ts +4 -6
- package/dist/components/attribution-control.js +6 -5
- package/dist/components/attribution-control.js.map +1 -1
- package/dist/components/fullscreen-control.d.ts +4 -6
- package/dist/components/fullscreen-control.js +4 -4
- package/dist/components/fullscreen-control.js.map +1 -1
- package/dist/components/geolocate-control.d.ts +10 -26
- package/dist/components/geolocate-control.js +11 -11
- package/dist/components/geolocate-control.js.map +1 -1
- package/dist/components/layer.d.ts +7 -6
- package/dist/components/layer.js +8 -9
- package/dist/components/layer.js.map +1 -1
- package/dist/components/logo-control.d.ts +9 -0
- package/dist/components/logo-control.js +28 -0
- package/dist/components/logo-control.js.map +1 -0
- package/dist/components/map.d.ts +20 -16
- package/dist/components/map.js +38 -32
- package/dist/components/map.js.map +1 -1
- package/dist/components/marker.d.ts +10 -33
- package/dist/components/marker.js +22 -15
- package/dist/components/marker.js.map +1 -1
- package/dist/components/navigation-control.d.ts +4 -6
- package/dist/components/navigation-control.js +4 -4
- package/dist/components/navigation-control.js.map +1 -1
- package/dist/components/popup.d.ts +7 -25
- package/dist/components/popup.js +17 -28
- package/dist/components/popup.js.map +1 -1
- package/dist/components/scale-control.d.ts +4 -6
- package/dist/components/scale-control.js +4 -4
- package/dist/components/scale-control.js.map +1 -1
- package/dist/components/source.d.ts +3 -4
- package/dist/components/source.js +20 -22
- package/dist/components/source.js.map +1 -1
- package/dist/components/terrain-control.d.ts +10 -0
- package/dist/components/terrain-control.js +19 -0
- package/dist/components/terrain-control.js.map +1 -0
- package/dist/components/use-control.d.ts +6 -6
- package/dist/components/use-control.js +4 -5
- package/dist/components/use-control.js.map +1 -1
- package/dist/components/use-map.d.ts +8 -9
- package/dist/components/use-map.js +5 -5
- package/dist/components/use-map.js.map +1 -1
- package/dist/exports-maplibre-gl.d.ts +33 -0
- package/dist/exports-maplibre-gl.js +21 -0
- package/dist/exports-maplibre-gl.js.map +1 -0
- package/dist/index.cjs +590 -681
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/{mapbox → maplibre}/create-ref.d.ts +6 -6
- package/dist/maplibre/create-ref.js +30 -0
- package/dist/maplibre/create-ref.js.map +1 -0
- package/dist/maplibre/maplibre.d.ts +81 -0
- package/dist/maplibre/maplibre.js +387 -0
- package/dist/maplibre/maplibre.js.map +1 -0
- package/dist/styles/index.d.ts +4 -0
- package/dist/styles/react-bkoi-gl.css +1 -1
- package/dist/styles.d.js +2 -0
- package/dist/styles.d.js.map +1 -0
- package/dist/tsconfig.build.tsbuildinfo +1 -0
- package/dist/types/common.d.ts +2 -60
- package/dist/types/common.js.map +1 -1
- package/dist/types/events.d.ts +64 -23
- package/dist/types/events.js.map +1 -1
- package/dist/types/internal.d.ts +14 -0
- package/dist/types/internal.js +2 -0
- package/dist/types/internal.js.map +1 -0
- package/dist/types/lib.d.ts +16 -200
- package/dist/types/lib.js.map +1 -1
- package/dist/types/style-spec.d.ts +1 -0
- package/dist/types/style-spec.js +2 -0
- package/dist/types/style-spec.js.map +1 -0
- package/dist/utils/apply-react-style.d.ts +1 -1
- package/dist/utils/apply-react-style.js.map +1 -1
- package/dist/utils/compare-class-names.d.ts +2 -0
- package/dist/utils/compare-class-names.js +23 -0
- package/dist/utils/compare-class-names.js.map +1 -0
- package/dist/utils/deep-equal.d.ts +1 -1
- package/dist/utils/deep-equal.js +1 -1
- package/dist/utils/deep-equal.js.map +1 -1
- package/dist/utils/set-globals.d.ts +6 -8
- package/dist/utils/set-globals.js +22 -10
- package/dist/utils/set-globals.js.map +1 -1
- package/dist/utils/style-utils.d.ts +3 -2
- package/dist/utils/style-utils.js +4 -4
- package/dist/utils/style-utils.js.map +1 -1
- package/dist/utils/transform.d.ts +11 -19
- package/dist/utils/transform.js +13 -36
- package/dist/utils/transform.js.map +1 -1
- package/dist/utils/use-isomorphic-layout-effect.d.ts +1 -1
- package/dist/utils/use-isomorphic-layout-effect.js +2 -2
- package/dist/utils/use-isomorphic-layout-effect.js.map +1 -1
- package/package.json +42 -26
- package/src/components/attribution-control.ts +40 -16
- package/src/components/fullscreen-control.ts +40 -0
- package/src/components/geolocate-control.ts +45 -39
- package/src/components/layer.ts +37 -29
- package/src/components/logo-control.ts +44 -0
- package/src/components/map.tsx +86 -75
- package/src/components/marker.ts +141 -123
- package/src/components/navigation-control.ts +11 -12
- package/src/components/popup.ts +94 -97
- package/src/components/scale-control.ts +12 -14
- package/src/components/source.ts +58 -57
- package/src/components/terrain-control.ts +29 -0
- package/src/components/use-control.ts +21 -17
- package/src/components/use-map.tsx +26 -24
- package/src/exports-maplibre-gl.ts +37 -0
- package/src/index.ts +3 -2
- package/src/maplibre/create-ref.ts +70 -0
- package/src/maplibre/maplibre.ts +624 -0
- package/src/styles.d.ts +4 -0
- package/src/types/common.ts +12 -72
- package/src/types/events.ts +102 -42
- package/src/types/internal.ts +26 -0
- package/src/types/lib.ts +65 -260
- package/src/types/style-spec.ts +34 -0
- package/src/utils/apply-react-style.ts +7 -3
- package/src/utils/compare-class-names.ts +29 -0
- package/src/utils/deep-equal.ts +2 -2
- package/src/utils/set-globals.ts +22 -28
- package/src/utils/style-utils.ts +18 -9
- package/src/utils/transform.ts +32 -60
- package/src/utils/use-isomorphic-layout-effect.ts +3 -2
- package/bkoi-gl/package.json +0 -6
- package/dist/exports-bkoi-gl.cjs +0 -1512
- package/dist/exports-bkoi-gl.d.ts +0 -89
- package/dist/exports-bkoi-gl.js +0 -36
- package/dist/exports-bkoi-gl.js.map +0 -1
- package/dist/exports-mapbox.d.ts +0 -139
- package/dist/exports-mapbox.js +0 -36
- package/dist/exports-mapbox.js.map +0 -1
- package/dist/mapbox/create-ref.js +0 -64
- package/dist/mapbox/create-ref.js.map +0 -1
- package/dist/mapbox/mapbox.d.ts +0 -81
- package/dist/mapbox/mapbox.js +0 -476
- package/dist/mapbox/mapbox.js.map +0 -1
- package/dist/types/events-bkoi-gl.d.ts +0 -49
- package/dist/types/events-bkoi-gl.js +0 -2
- package/dist/types/events-bkoi-gl.js.map +0 -1
- package/dist/types/events-mapbox.d.ts +0 -49
- package/dist/types/events-mapbox.js +0 -2
- package/dist/types/events-mapbox.js.map +0 -1
- package/dist/types/index.d.ts +0 -70
- package/dist/types/index.js +0 -5
- package/dist/types/index.js.map +0 -1
- package/dist/types/public.d.ts +0 -2
- package/dist/types/public.js +0 -2
- package/dist/types/public.js.map +0 -1
- package/dist/types/style-spec-bkoi-gl.d.ts +0 -9
- package/dist/types/style-spec-bkoi-gl.js +0 -2
- package/dist/types/style-spec-bkoi-gl.js.map +0 -1
- package/dist/types/style-spec-mapbox.d.ts +0 -7
- package/dist/types/style-spec-mapbox.js +0 -2
- package/dist/types/style-spec-mapbox.js.map +0 -1
- package/src/components/fullscreen-control.tsx +0 -37
- package/src/exports-bkoi-gl.ts +0 -156
- package/src/exports-mapbox.ts +0 -159
- package/src/mapbox/create-ref.ts +0 -118
- package/src/mapbox/mapbox.ts +0 -742
- package/src/types/events-bkoi-gl.ts +0 -78
- package/src/types/events-mapbox.ts +0 -76
- package/src/types/index.ts +0 -93
- package/src/types/public.ts +0 -9
- package/src/types/style-spec-bkoi-gl.ts +0 -81
- package/src/types/style-spec-mapbox.ts +0 -80
package/dist/index.cjs
CHANGED
|
@@ -46,29 +46,28 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
46
46
|
// src/index.ts
|
|
47
47
|
var src_exports = {};
|
|
48
48
|
__export(src_exports, {
|
|
49
|
-
AttributionControl: () =>
|
|
50
|
-
FullscreenControl: () =>
|
|
51
|
-
GeolocateControl: () =>
|
|
52
|
-
Layer: () =>
|
|
53
|
-
|
|
49
|
+
AttributionControl: () => AttributionControl,
|
|
50
|
+
FullscreenControl: () => FullscreenControl,
|
|
51
|
+
GeolocateControl: () => GeolocateControl,
|
|
52
|
+
Layer: () => Layer,
|
|
53
|
+
LogoControl: () => LogoControl,
|
|
54
|
+
Map: () => Map,
|
|
54
55
|
MapProvider: () => MapProvider,
|
|
55
|
-
Marker: () =>
|
|
56
|
-
NavigationControl: () =>
|
|
57
|
-
Popup: () =>
|
|
58
|
-
ScaleControl: () =>
|
|
59
|
-
Source: () =>
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
56
|
+
Marker: () => Marker,
|
|
57
|
+
NavigationControl: () => NavigationControl,
|
|
58
|
+
Popup: () => Popup,
|
|
59
|
+
ScaleControl: () => ScaleControl,
|
|
60
|
+
Source: () => Source,
|
|
61
|
+
TerrainControl: () => TerrainControl,
|
|
62
|
+
default: () => exports_maplibre_gl_default,
|
|
63
|
+
useControl: () => useControl,
|
|
64
|
+
useMap: () => useMap
|
|
63
65
|
});
|
|
64
66
|
module.exports = __toCommonJS(src_exports);
|
|
65
67
|
|
|
66
|
-
// src/exports-mapbox.ts
|
|
67
|
-
var React5 = __toESM(require("react"), 1);
|
|
68
|
-
|
|
69
68
|
// src/components/map.tsx
|
|
70
69
|
var React2 = __toESM(require("react"), 1);
|
|
71
|
-
var
|
|
70
|
+
var import_react6 = require("react");
|
|
72
71
|
|
|
73
72
|
// src/components/use-map.tsx
|
|
74
73
|
var React = __toESM(require("react"), 1);
|
|
@@ -167,21 +166,6 @@ function deepEqual(a, b) {
|
|
|
167
166
|
}
|
|
168
167
|
|
|
169
168
|
// src/utils/transform.ts
|
|
170
|
-
function cloneTransform(tr) {
|
|
171
|
-
const newTransform = tr.clone();
|
|
172
|
-
newTransform.pixelsToGLUnits = tr.pixelsToGLUnits;
|
|
173
|
-
return newTransform;
|
|
174
|
-
}
|
|
175
|
-
function syncProjection(src, dest) {
|
|
176
|
-
if (!src.getProjection) {
|
|
177
|
-
return;
|
|
178
|
-
}
|
|
179
|
-
const srcProjection = src.getProjection();
|
|
180
|
-
const destProjection = dest.getProjection();
|
|
181
|
-
if (!deepEqual(srcProjection, destProjection)) {
|
|
182
|
-
dest.setProjection(srcProjection);
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
169
|
function transformToViewState(tr) {
|
|
186
170
|
return {
|
|
187
171
|
longitude: tr.center.lng,
|
|
@@ -194,36 +178,36 @@ function transformToViewState(tr) {
|
|
|
194
178
|
}
|
|
195
179
|
function applyViewStateToTransform(tr, props) {
|
|
196
180
|
const v = props.viewState || props;
|
|
197
|
-
|
|
198
|
-
if ("
|
|
199
|
-
const
|
|
200
|
-
|
|
201
|
-
changed = changed || zoom !== tr.zoom;
|
|
181
|
+
const changes = {};
|
|
182
|
+
if ("longitude" in v && "latitude" in v && (v.longitude !== tr.center.lng || v.latitude !== tr.center.lat)) {
|
|
183
|
+
const LngLat = tr.center.constructor;
|
|
184
|
+
changes.center = new LngLat(v.longitude, v.latitude);
|
|
202
185
|
}
|
|
203
|
-
if ("
|
|
204
|
-
|
|
205
|
-
tr.bearing = v.bearing;
|
|
206
|
-
changed = changed || bearing !== tr.bearing;
|
|
186
|
+
if ("zoom" in v && v.zoom !== tr.zoom) {
|
|
187
|
+
changes.zoom = v.zoom;
|
|
207
188
|
}
|
|
208
|
-
if ("
|
|
209
|
-
|
|
210
|
-
tr.pitch = v.pitch;
|
|
211
|
-
changed = changed || pitch !== tr.pitch;
|
|
189
|
+
if ("bearing" in v && v.bearing !== tr.bearing) {
|
|
190
|
+
changes.bearing = v.bearing;
|
|
212
191
|
}
|
|
213
|
-
if (v
|
|
214
|
-
|
|
215
|
-
tr.padding = v.padding;
|
|
192
|
+
if ("pitch" in v && v.pitch !== tr.pitch) {
|
|
193
|
+
changes.pitch = v.pitch;
|
|
216
194
|
}
|
|
217
|
-
if (
|
|
218
|
-
|
|
219
|
-
tr.center = new center.constructor(v.longitude, v.latitude);
|
|
220
|
-
changed = changed || center !== tr.center;
|
|
195
|
+
if (v.padding && tr.padding && !deepEqual(v.padding, tr.padding)) {
|
|
196
|
+
changes.padding = v.padding;
|
|
221
197
|
}
|
|
222
|
-
return
|
|
198
|
+
return changes;
|
|
223
199
|
}
|
|
224
200
|
|
|
225
201
|
// src/utils/style-utils.ts
|
|
226
|
-
var refProps = [
|
|
202
|
+
var refProps = [
|
|
203
|
+
"type",
|
|
204
|
+
"source",
|
|
205
|
+
"source-layer",
|
|
206
|
+
"minzoom",
|
|
207
|
+
"maxzoom",
|
|
208
|
+
"filter",
|
|
209
|
+
"layout"
|
|
210
|
+
];
|
|
227
211
|
function normalizeStyle(style) {
|
|
228
212
|
if (!style) {
|
|
229
213
|
return null;
|
|
@@ -262,8 +246,12 @@ function normalizeStyle(style) {
|
|
|
262
246
|
return __spreadProps(__spreadValues({}, style), { layers });
|
|
263
247
|
}
|
|
264
248
|
|
|
265
|
-
// src/
|
|
266
|
-
var DEFAULT_STYLE = {
|
|
249
|
+
// src/maplibre/maplibre.ts
|
|
250
|
+
var DEFAULT_STYLE = {
|
|
251
|
+
version: 8,
|
|
252
|
+
sources: {},
|
|
253
|
+
layers: []
|
|
254
|
+
};
|
|
267
255
|
var pointerEvents = {
|
|
268
256
|
mousedown: "onMouseDown",
|
|
269
257
|
mouseup: "onMouseUp",
|
|
@@ -331,20 +319,15 @@ var handlerNames = [
|
|
|
331
319
|
"touchZoomRotate",
|
|
332
320
|
"touchPitch"
|
|
333
321
|
];
|
|
334
|
-
var
|
|
322
|
+
var _Maplibre = class {
|
|
335
323
|
constructor(MapClass, props, container) {
|
|
336
324
|
// mapboxgl.Map instance
|
|
337
325
|
this._map = null;
|
|
338
326
|
// Internal states
|
|
339
327
|
this._internalUpdate = false;
|
|
340
|
-
this._inRender = false;
|
|
341
328
|
this._hoveredFeatures = null;
|
|
342
|
-
this.
|
|
343
|
-
|
|
344
|
-
zoom: false,
|
|
345
|
-
pitch: false,
|
|
346
|
-
rotate: false
|
|
347
|
-
};
|
|
329
|
+
this._propsedCameraUpdate = null;
|
|
330
|
+
this._styleComponents = {};
|
|
348
331
|
this._onEvent = (e) => {
|
|
349
332
|
const cb = this.props[otherEvents[e.type]];
|
|
350
333
|
if (cb) {
|
|
@@ -353,6 +336,23 @@ var _Mapbox = class {
|
|
|
353
336
|
console.error(e.error);
|
|
354
337
|
}
|
|
355
338
|
};
|
|
339
|
+
this._onCameraEvent = (e) => {
|
|
340
|
+
if (this._internalUpdate) {
|
|
341
|
+
return;
|
|
342
|
+
}
|
|
343
|
+
e.viewState = this._propsedCameraUpdate || transformToViewState(this._map.transform);
|
|
344
|
+
const cb = this.props[cameraEvents[e.type]];
|
|
345
|
+
if (cb) {
|
|
346
|
+
cb(e);
|
|
347
|
+
}
|
|
348
|
+
};
|
|
349
|
+
this._onCameraUpdate = (tr) => {
|
|
350
|
+
if (this._internalUpdate) {
|
|
351
|
+
return tr;
|
|
352
|
+
}
|
|
353
|
+
this._propsedCameraUpdate = transformToViewState(tr);
|
|
354
|
+
return applyViewStateToTransform(tr, this.props);
|
|
355
|
+
};
|
|
356
356
|
this._onPointerEvent = (e) => {
|
|
357
357
|
if (e.type === "mousemove" || e.type === "mouseout") {
|
|
358
358
|
this._updateHover(e);
|
|
@@ -366,17 +366,6 @@ var _Mapbox = class {
|
|
|
366
366
|
delete e.features;
|
|
367
367
|
}
|
|
368
368
|
};
|
|
369
|
-
this._onCameraEvent = (e) => {
|
|
370
|
-
if (!this._internalUpdate) {
|
|
371
|
-
const cb = this.props[cameraEvents[e.type]];
|
|
372
|
-
if (cb) {
|
|
373
|
-
cb(e);
|
|
374
|
-
}
|
|
375
|
-
}
|
|
376
|
-
if (e.type in this._deferredEvents) {
|
|
377
|
-
this._deferredEvents[e.type] = false;
|
|
378
|
-
}
|
|
379
|
-
};
|
|
380
369
|
this._MapClass = MapClass;
|
|
381
370
|
this.props = props;
|
|
382
371
|
this._initialize(container);
|
|
@@ -384,27 +373,21 @@ var _Mapbox = class {
|
|
|
384
373
|
get map() {
|
|
385
374
|
return this._map;
|
|
386
375
|
}
|
|
387
|
-
get transform() {
|
|
388
|
-
return this._renderTransform;
|
|
389
|
-
}
|
|
390
376
|
setProps(props) {
|
|
391
377
|
const oldProps = this.props;
|
|
392
378
|
this.props = props;
|
|
393
379
|
const settingsChanged = this._updateSettings(props, oldProps);
|
|
394
|
-
if (settingsChanged) {
|
|
395
|
-
this._createShadowTransform(this._map);
|
|
396
|
-
}
|
|
397
380
|
const sizeChanged = this._updateSize(props);
|
|
398
|
-
const viewStateChanged = this._updateViewState(props
|
|
381
|
+
const viewStateChanged = this._updateViewState(props);
|
|
399
382
|
this._updateStyle(props, oldProps);
|
|
400
|
-
this._updateStyleComponents(props
|
|
383
|
+
this._updateStyleComponents(props);
|
|
401
384
|
this._updateHandlers(props, oldProps);
|
|
402
385
|
if (settingsChanged || sizeChanged || viewStateChanged && !this._map.isMoving()) {
|
|
403
386
|
this.redraw();
|
|
404
387
|
}
|
|
405
388
|
}
|
|
406
389
|
static reuse(props, container) {
|
|
407
|
-
const that =
|
|
390
|
+
const that = _Maplibre.savedMaps.pop();
|
|
408
391
|
if (!that) {
|
|
409
392
|
return null;
|
|
410
393
|
}
|
|
@@ -425,15 +408,17 @@ var _Mapbox = class {
|
|
|
425
408
|
const { initialViewState } = props;
|
|
426
409
|
if (initialViewState) {
|
|
427
410
|
if (initialViewState.bounds) {
|
|
428
|
-
map.fitBounds(initialViewState.bounds, __spreadProps(__spreadValues({}, initialViewState.fitBoundsOptions), {
|
|
411
|
+
map.fitBounds(initialViewState.bounds, __spreadProps(__spreadValues({}, initialViewState.fitBoundsOptions), {
|
|
412
|
+
duration: 0
|
|
413
|
+
}));
|
|
429
414
|
} else {
|
|
430
|
-
that._updateViewState(initialViewState
|
|
415
|
+
that._updateViewState(initialViewState);
|
|
431
416
|
}
|
|
432
417
|
}
|
|
433
418
|
if (map.isStyleLoaded()) {
|
|
434
419
|
map.fire("load");
|
|
435
420
|
} else {
|
|
436
|
-
map.once("
|
|
421
|
+
map.once("style.load", () => map.fire("load"));
|
|
437
422
|
}
|
|
438
423
|
map._update();
|
|
439
424
|
return that;
|
|
@@ -443,7 +428,6 @@ var _Mapbox = class {
|
|
|
443
428
|
const { props } = this;
|
|
444
429
|
const { mapStyle = DEFAULT_STYLE } = props;
|
|
445
430
|
const mapOptions = __spreadProps(__spreadValues(__spreadValues({}, props), props.initialViewState), {
|
|
446
|
-
accessToken: props.mapboxAccessToken || getAccessTokenFromEnv() || null,
|
|
447
431
|
container,
|
|
448
432
|
style: normalizeStyle(mapStyle)
|
|
449
433
|
});
|
|
@@ -468,29 +452,21 @@ var _Mapbox = class {
|
|
|
468
452
|
if (props.cursor) {
|
|
469
453
|
map.getCanvas().style.cursor = props.cursor;
|
|
470
454
|
}
|
|
471
|
-
this.
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
this.
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
this.
|
|
482
|
-
};
|
|
483
|
-
map.on("render", () => this._onAfterRepaint());
|
|
484
|
-
const fireEvent = map.fire;
|
|
485
|
-
map.fire = this._fireEvent.bind(this, fireEvent);
|
|
486
|
-
map.on("resize", () => {
|
|
487
|
-
this._renderTransform.resize(map.transform.width, map.transform.height);
|
|
455
|
+
map.transformCameraUpdate = this._onCameraUpdate;
|
|
456
|
+
map.on("style.load", () => {
|
|
457
|
+
var _a;
|
|
458
|
+
this._styleComponents = {
|
|
459
|
+
light: map.getLight(),
|
|
460
|
+
sky: map.getSky(),
|
|
461
|
+
// @ts-ignore getProjection() does not exist in v4
|
|
462
|
+
projection: (_a = map.getProjection) == null ? void 0 : _a.call(map),
|
|
463
|
+
terrain: map.getTerrain()
|
|
464
|
+
};
|
|
465
|
+
this._updateStyleComponents(this.props);
|
|
488
466
|
});
|
|
489
|
-
map.on("
|
|
490
|
-
this._updateStyleComponents(this.props
|
|
491
|
-
syncProjection(map.transform, this._renderTransform);
|
|
467
|
+
map.on("sourcedata", () => {
|
|
468
|
+
this._updateStyleComponents(this.props);
|
|
492
469
|
});
|
|
493
|
-
map.on("sourcedata", () => this._updateStyleComponents(this.props, {}));
|
|
494
470
|
for (const eventName in pointerEvents) {
|
|
495
471
|
map.on(eventName, this._onPointerEvent);
|
|
496
472
|
}
|
|
@@ -507,7 +483,7 @@ var _Mapbox = class {
|
|
|
507
483
|
const container = this.map.getContainer();
|
|
508
484
|
const children = container.querySelector("[mapboxgl-children]");
|
|
509
485
|
children == null ? void 0 : children.remove();
|
|
510
|
-
|
|
486
|
+
_Maplibre.savedMaps.push(this);
|
|
511
487
|
}
|
|
512
488
|
destroy() {
|
|
513
489
|
this._map.remove();
|
|
@@ -517,7 +493,7 @@ var _Mapbox = class {
|
|
|
517
493
|
// This removes the synchronization issue caused by requestAnimationFrame.
|
|
518
494
|
redraw() {
|
|
519
495
|
const map = this._map;
|
|
520
|
-
if (
|
|
496
|
+
if (map.style) {
|
|
521
497
|
if (map._frame) {
|
|
522
498
|
map._frame.cancel();
|
|
523
499
|
map._frame = null;
|
|
@@ -525,11 +501,6 @@ var _Mapbox = class {
|
|
|
525
501
|
map._render();
|
|
526
502
|
}
|
|
527
503
|
}
|
|
528
|
-
_createShadowTransform(map) {
|
|
529
|
-
const renderTransform = cloneTransform(map.transform);
|
|
530
|
-
map.painter.transform = renderTransform;
|
|
531
|
-
this._renderTransform = renderTransform;
|
|
532
|
-
}
|
|
533
504
|
/* Trigger map resize if size is controlled
|
|
534
505
|
@param {object} nextProps
|
|
535
506
|
@returns {bool} true if size has changed
|
|
@@ -551,32 +522,20 @@ var _Mapbox = class {
|
|
|
551
522
|
@param {bool} triggerEvents - should fire camera events
|
|
552
523
|
@returns {bool} true if anything is changed
|
|
553
524
|
*/
|
|
554
|
-
_updateViewState(nextProps
|
|
555
|
-
if (this._internalUpdate) {
|
|
556
|
-
return false;
|
|
557
|
-
}
|
|
525
|
+
_updateViewState(nextProps) {
|
|
558
526
|
const map = this._map;
|
|
559
|
-
const tr =
|
|
560
|
-
const { zoom, pitch, bearing } = tr;
|
|
527
|
+
const tr = map.transform;
|
|
561
528
|
const isMoving = map.isMoving();
|
|
562
|
-
if (isMoving) {
|
|
563
|
-
tr.cameraElevationReference = "sea";
|
|
564
|
-
}
|
|
565
|
-
const changed = applyViewStateToTransform(tr, __spreadValues(__spreadValues({}, transformToViewState(map.transform)), nextProps));
|
|
566
|
-
if (isMoving) {
|
|
567
|
-
tr.cameraElevationReference = "ground";
|
|
568
|
-
}
|
|
569
|
-
if (changed && triggerEvents) {
|
|
570
|
-
const deferredEvents = this._deferredEvents;
|
|
571
|
-
deferredEvents.move = true;
|
|
572
|
-
deferredEvents.zoom || (deferredEvents.zoom = zoom !== tr.zoom);
|
|
573
|
-
deferredEvents.rotate || (deferredEvents.rotate = bearing !== tr.bearing);
|
|
574
|
-
deferredEvents.pitch || (deferredEvents.pitch = pitch !== tr.pitch);
|
|
575
|
-
}
|
|
576
529
|
if (!isMoving) {
|
|
577
|
-
applyViewStateToTransform(
|
|
530
|
+
const changes = applyViewStateToTransform(tr, nextProps);
|
|
531
|
+
if (Object.keys(changes).length > 0) {
|
|
532
|
+
this._internalUpdate = true;
|
|
533
|
+
map.jumpTo(changes);
|
|
534
|
+
this._internalUpdate = false;
|
|
535
|
+
return true;
|
|
536
|
+
}
|
|
578
537
|
}
|
|
579
|
-
return
|
|
538
|
+
return false;
|
|
580
539
|
}
|
|
581
540
|
/* Update camera constraints and projection settings to match props
|
|
582
541
|
@param {object} nextProps
|
|
@@ -595,11 +554,7 @@ var _Mapbox = class {
|
|
|
595
554
|
}
|
|
596
555
|
return changed;
|
|
597
556
|
}
|
|
598
|
-
/* Update map style to match props
|
|
599
|
-
@param {object} nextProps
|
|
600
|
-
@param {object} currProps
|
|
601
|
-
@returns {bool} true if style is changed
|
|
602
|
-
*/
|
|
557
|
+
/* Update map style to match props */
|
|
603
558
|
_updateStyle(nextProps, currProps) {
|
|
604
559
|
if (nextProps.cursor !== currProps.cursor) {
|
|
605
560
|
this._map.getCanvas().style.cursor = nextProps.cursor || "";
|
|
@@ -613,50 +568,51 @@ var _Mapbox = class {
|
|
|
613
568
|
options.localIdeographFontFamily = nextProps.localIdeographFontFamily;
|
|
614
569
|
}
|
|
615
570
|
this._map.setStyle(normalizeStyle(mapStyle), options);
|
|
616
|
-
return true;
|
|
617
571
|
}
|
|
618
|
-
return false;
|
|
619
572
|
}
|
|
620
|
-
/* Update fog, light and terrain to match props
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
573
|
+
/* Update fog, light, projection and terrain to match props
|
|
574
|
+
* These props are special because
|
|
575
|
+
* 1. They can not be applied right away. Certain conditions (style loaded, source loaded, etc.) must be met
|
|
576
|
+
* 2. They can be overwritten by mapStyle
|
|
624
577
|
*/
|
|
625
|
-
_updateStyleComponents(
|
|
578
|
+
_updateStyleComponents({
|
|
579
|
+
light,
|
|
580
|
+
projection,
|
|
581
|
+
sky,
|
|
582
|
+
terrain
|
|
583
|
+
}) {
|
|
584
|
+
var _a, _b;
|
|
626
585
|
const map = this._map;
|
|
627
|
-
|
|
628
|
-
if (map.
|
|
629
|
-
if (
|
|
630
|
-
|
|
631
|
-
map.setLight(
|
|
586
|
+
const currProps = this._styleComponents;
|
|
587
|
+
if (map.style._loaded) {
|
|
588
|
+
if (light && !deepEqual(light, currProps.light)) {
|
|
589
|
+
currProps.light = light;
|
|
590
|
+
map.setLight(light);
|
|
632
591
|
}
|
|
633
|
-
if (
|
|
634
|
-
|
|
635
|
-
map.
|
|
592
|
+
if (projection && !deepEqual(projection, currProps.projection) && projection !== ((_a = currProps.projection) == null ? void 0 : _a.type)) {
|
|
593
|
+
currProps.projection = typeof projection === "string" ? { type: projection } : projection;
|
|
594
|
+
(_b = map.setProjection) == null ? void 0 : _b.call(map, currProps.projection);
|
|
636
595
|
}
|
|
637
|
-
if (
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
596
|
+
if (sky && !deepEqual(sky, currProps.sky)) {
|
|
597
|
+
currProps.sky = sky;
|
|
598
|
+
map.setSky(sky);
|
|
599
|
+
}
|
|
600
|
+
if (terrain !== void 0 && !deepEqual(terrain, currProps.terrain)) {
|
|
601
|
+
if (!terrain || map.getSource(terrain.source)) {
|
|
602
|
+
currProps.terrain = terrain;
|
|
603
|
+
map.setTerrain(terrain);
|
|
641
604
|
}
|
|
642
605
|
}
|
|
643
606
|
}
|
|
644
|
-
return changed;
|
|
645
607
|
}
|
|
646
|
-
/* Update interaction handlers to match props
|
|
647
|
-
@param {object} nextProps
|
|
648
|
-
@param {object} currProps
|
|
649
|
-
@returns {bool} true if anything is changed
|
|
650
|
-
*/
|
|
608
|
+
/* Update interaction handlers to match props */
|
|
651
609
|
_updateHandlers(nextProps, currProps) {
|
|
652
610
|
var _a, _b;
|
|
653
611
|
const map = this._map;
|
|
654
|
-
let changed = false;
|
|
655
612
|
for (const propName of handlerNames) {
|
|
656
613
|
const newValue = (_a = nextProps[propName]) != null ? _a : true;
|
|
657
614
|
const oldValue = (_b = currProps[propName]) != null ? _b : true;
|
|
658
615
|
if (!deepEqual(newValue, oldValue)) {
|
|
659
|
-
changed = true;
|
|
660
616
|
if (newValue) {
|
|
661
617
|
map[propName].enable(newValue);
|
|
662
618
|
} else {
|
|
@@ -664,21 +620,16 @@ var _Mapbox = class {
|
|
|
664
620
|
}
|
|
665
621
|
}
|
|
666
622
|
}
|
|
667
|
-
return changed;
|
|
668
623
|
}
|
|
669
624
|
_queryRenderedFeatures(point) {
|
|
670
625
|
const map = this._map;
|
|
671
|
-
const tr = map.transform;
|
|
672
626
|
const { interactiveLayerIds = [] } = this.props;
|
|
673
627
|
try {
|
|
674
|
-
map.transform = this._renderTransform;
|
|
675
628
|
return map.queryRenderedFeatures(point, {
|
|
676
629
|
layers: interactiveLayerIds.filter(map.getLayer.bind(map))
|
|
677
630
|
});
|
|
678
631
|
} catch (e) {
|
|
679
632
|
return [];
|
|
680
|
-
} finally {
|
|
681
|
-
map.transform = tr;
|
|
682
633
|
}
|
|
683
634
|
}
|
|
684
635
|
_updateHover(e) {
|
|
@@ -704,65 +655,11 @@ var _Mapbox = class {
|
|
|
704
655
|
this._hoveredFeatures = null;
|
|
705
656
|
}
|
|
706
657
|
}
|
|
707
|
-
_fireEvent(baseFire, event, properties) {
|
|
708
|
-
const map = this._map;
|
|
709
|
-
const tr = map.transform;
|
|
710
|
-
const eventType = typeof event === "string" ? event : event.type;
|
|
711
|
-
if (eventType === "move") {
|
|
712
|
-
this._updateViewState(this.props, false);
|
|
713
|
-
}
|
|
714
|
-
if (eventType in cameraEvents) {
|
|
715
|
-
if (typeof event === "object") {
|
|
716
|
-
event.viewState = transformToViewState(tr);
|
|
717
|
-
}
|
|
718
|
-
if (this._map.isMoving()) {
|
|
719
|
-
map.transform = this._renderTransform;
|
|
720
|
-
baseFire.call(map, event, properties);
|
|
721
|
-
map.transform = tr;
|
|
722
|
-
return map;
|
|
723
|
-
}
|
|
724
|
-
}
|
|
725
|
-
baseFire.call(map, event, properties);
|
|
726
|
-
return map;
|
|
727
|
-
}
|
|
728
|
-
// All camera manipulations are complete, ready to repaint
|
|
729
|
-
_onBeforeRepaint() {
|
|
730
|
-
const map = this._map;
|
|
731
|
-
this._internalUpdate = true;
|
|
732
|
-
for (const eventType in this._deferredEvents) {
|
|
733
|
-
if (this._deferredEvents[eventType]) {
|
|
734
|
-
map.fire(eventType);
|
|
735
|
-
}
|
|
736
|
-
}
|
|
737
|
-
this._internalUpdate = false;
|
|
738
|
-
const tr = this._map.transform;
|
|
739
|
-
map.transform = this._renderTransform;
|
|
740
|
-
this._onAfterRepaint = () => {
|
|
741
|
-
syncProjection(this._renderTransform, tr);
|
|
742
|
-
map.transform = tr;
|
|
743
|
-
};
|
|
744
|
-
}
|
|
745
658
|
};
|
|
746
|
-
var
|
|
747
|
-
|
|
748
|
-
function getAccessTokenFromEnv() {
|
|
749
|
-
let accessToken = null;
|
|
750
|
-
if (typeof location !== "undefined") {
|
|
751
|
-
const match = /access_token=([^&\/]*)/.exec(location.search);
|
|
752
|
-
accessToken = match && match[1];
|
|
753
|
-
}
|
|
754
|
-
try {
|
|
755
|
-
accessToken = accessToken || process.env.MapboxAccessToken;
|
|
756
|
-
} catch (e) {
|
|
757
|
-
}
|
|
758
|
-
try {
|
|
759
|
-
accessToken = accessToken || process.env.REACT_APP_MAPBOX_ACCESS_TOKEN;
|
|
760
|
-
} catch (e) {
|
|
761
|
-
}
|
|
762
|
-
return accessToken;
|
|
763
|
-
}
|
|
659
|
+
var Maplibre = _Maplibre;
|
|
660
|
+
Maplibre.savedMaps = [];
|
|
764
661
|
|
|
765
|
-
// src/
|
|
662
|
+
// src/maplibre/create-ref.ts
|
|
766
663
|
var skipMethods = [
|
|
767
664
|
"setMaxBounds",
|
|
768
665
|
"setMinZoom",
|
|
@@ -791,43 +688,7 @@ function createRef(mapInstance) {
|
|
|
791
688
|
}
|
|
792
689
|
const map = mapInstance.map;
|
|
793
690
|
const result = {
|
|
794
|
-
getMap: () => map
|
|
795
|
-
// Overwrite getters to use our shadow transform
|
|
796
|
-
getCenter: () => mapInstance.transform.center,
|
|
797
|
-
getZoom: () => mapInstance.transform.zoom,
|
|
798
|
-
getBearing: () => mapInstance.transform.bearing,
|
|
799
|
-
getPitch: () => mapInstance.transform.pitch,
|
|
800
|
-
getPadding: () => mapInstance.transform.padding,
|
|
801
|
-
getBounds: () => mapInstance.transform.getBounds(),
|
|
802
|
-
project: (lnglat) => {
|
|
803
|
-
const tr = map.transform;
|
|
804
|
-
map.transform = mapInstance.transform;
|
|
805
|
-
const result2 = map.project(lnglat);
|
|
806
|
-
map.transform = tr;
|
|
807
|
-
return result2;
|
|
808
|
-
},
|
|
809
|
-
unproject: (point) => {
|
|
810
|
-
const tr = map.transform;
|
|
811
|
-
map.transform = mapInstance.transform;
|
|
812
|
-
const result2 = map.unproject(point);
|
|
813
|
-
map.transform = tr;
|
|
814
|
-
return result2;
|
|
815
|
-
},
|
|
816
|
-
// options diverge between mapbox and maplibre
|
|
817
|
-
queryTerrainElevation: (lnglat, options) => {
|
|
818
|
-
const tr = map.transform;
|
|
819
|
-
map.transform = mapInstance.transform;
|
|
820
|
-
const result2 = map.queryTerrainElevation(lnglat, options);
|
|
821
|
-
map.transform = tr;
|
|
822
|
-
return result2;
|
|
823
|
-
},
|
|
824
|
-
queryRenderedFeatures: (geometry, options) => {
|
|
825
|
-
const tr = map.transform;
|
|
826
|
-
map.transform = mapInstance.transform;
|
|
827
|
-
const result2 = map.queryRenderedFeatures(geometry, options);
|
|
828
|
-
map.transform = tr;
|
|
829
|
-
return result2;
|
|
830
|
-
}
|
|
691
|
+
getMap: () => map
|
|
831
692
|
};
|
|
832
693
|
for (const key of getMethodNames(map)) {
|
|
833
694
|
if (!(key in result) && !skipMethods.includes(key)) {
|
|
@@ -856,47 +717,134 @@ var useIsomorphicLayoutEffect = typeof document !== "undefined" ? import_react2.
|
|
|
856
717
|
var use_isomorphic_layout_effect_default = useIsomorphicLayoutEffect;
|
|
857
718
|
|
|
858
719
|
// src/utils/set-globals.ts
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
"
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
];
|
|
866
|
-
function setGlobals(mapLib2, props) {
|
|
867
|
-
for (const key of globalSettings) {
|
|
868
|
-
if (key in props) {
|
|
869
|
-
mapLib2[key] = props[key];
|
|
870
|
-
}
|
|
871
|
-
}
|
|
872
|
-
const {
|
|
873
|
-
RTLTextPlugin = "https://api.mapbox.com/mapbox-gl-js/plugins/mapbox-gl-rtl-text/v0.2.3/mapbox-gl-rtl-text.js"
|
|
874
|
-
} = props;
|
|
875
|
-
if (RTLTextPlugin && mapLib2.getRTLTextPluginStatus && mapLib2.getRTLTextPluginStatus() === "unavailable") {
|
|
876
|
-
mapLib2.setRTLTextPlugin(
|
|
877
|
-
RTLTextPlugin,
|
|
720
|
+
function setGlobals(mapLib, props) {
|
|
721
|
+
const { RTLTextPlugin, maxParallelImageRequests, workerCount, workerUrl } = props;
|
|
722
|
+
if (RTLTextPlugin && mapLib.getRTLTextPluginStatus && mapLib.getRTLTextPluginStatus() === "unavailable") {
|
|
723
|
+
const { pluginUrl, lazy = true } = typeof RTLTextPlugin === "string" ? { pluginUrl: RTLTextPlugin } : RTLTextPlugin;
|
|
724
|
+
mapLib.setRTLTextPlugin(
|
|
725
|
+
pluginUrl,
|
|
878
726
|
(error) => {
|
|
879
727
|
if (error) {
|
|
880
728
|
console.error(error);
|
|
881
729
|
}
|
|
882
730
|
},
|
|
883
|
-
|
|
731
|
+
lazy
|
|
884
732
|
);
|
|
885
733
|
}
|
|
734
|
+
if (maxParallelImageRequests !== void 0) {
|
|
735
|
+
mapLib.setMaxParallelImageRequests(maxParallelImageRequests);
|
|
736
|
+
}
|
|
737
|
+
if (workerCount !== void 0) {
|
|
738
|
+
mapLib.setWorkerCount(workerCount);
|
|
739
|
+
}
|
|
740
|
+
if (workerUrl !== void 0) {
|
|
741
|
+
mapLib.setWorkerUrl(workerUrl);
|
|
742
|
+
}
|
|
743
|
+
}
|
|
744
|
+
|
|
745
|
+
// src/components/logo-control.ts
|
|
746
|
+
var import_react4 = require("react");
|
|
747
|
+
|
|
748
|
+
// src/utils/apply-react-style.ts
|
|
749
|
+
var unitlessNumber = /box|flex|grid|column|lineHeight|fontWeight|opacity|order|tabSize|zIndex/;
|
|
750
|
+
function applyReactStyle(element, styles) {
|
|
751
|
+
if (!element || !styles) {
|
|
752
|
+
return;
|
|
753
|
+
}
|
|
754
|
+
const style = element.style;
|
|
755
|
+
for (const key in styles) {
|
|
756
|
+
const value = styles[key];
|
|
757
|
+
if (Number.isFinite(value) && !unitlessNumber.test(key)) {
|
|
758
|
+
style[key] = `${value}px`;
|
|
759
|
+
} else {
|
|
760
|
+
style[key] = value;
|
|
761
|
+
}
|
|
762
|
+
}
|
|
763
|
+
}
|
|
764
|
+
|
|
765
|
+
// src/components/use-control.ts
|
|
766
|
+
var import_react3 = require("react");
|
|
767
|
+
function useControl(onCreate, arg1, arg2, arg3) {
|
|
768
|
+
const context = (0, import_react3.useContext)(MapContext);
|
|
769
|
+
const ctrl = (0, import_react3.useMemo)(() => onCreate(context), []);
|
|
770
|
+
(0, import_react3.useEffect)(() => {
|
|
771
|
+
const opts = arg3 || arg2 || arg1;
|
|
772
|
+
const onAdd = typeof arg1 === "function" && typeof arg2 === "function" ? arg1 : null;
|
|
773
|
+
const onRemove = typeof arg2 === "function" ? arg2 : typeof arg1 === "function" ? arg1 : null;
|
|
774
|
+
const { map } = context;
|
|
775
|
+
if (!map.hasControl(ctrl)) {
|
|
776
|
+
map.addControl(ctrl, opts == null ? void 0 : opts.position);
|
|
777
|
+
if (onAdd) {
|
|
778
|
+
onAdd(context);
|
|
779
|
+
}
|
|
780
|
+
}
|
|
781
|
+
return () => {
|
|
782
|
+
if (onRemove) {
|
|
783
|
+
onRemove(context);
|
|
784
|
+
}
|
|
785
|
+
if (map.hasControl(ctrl)) {
|
|
786
|
+
map.removeControl(ctrl);
|
|
787
|
+
}
|
|
788
|
+
};
|
|
789
|
+
}, []);
|
|
790
|
+
return ctrl;
|
|
791
|
+
}
|
|
792
|
+
|
|
793
|
+
// src/components/logo-control.ts
|
|
794
|
+
function _LogoControl(props) {
|
|
795
|
+
const ctrl = useControl(({ mapLib }) => new mapLib.LogoControl(props), {
|
|
796
|
+
position: props.position
|
|
797
|
+
});
|
|
798
|
+
(0, import_react4.useEffect)(() => {
|
|
799
|
+
var _a;
|
|
800
|
+
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
|
+
}, [props.style, ctrl._container]);
|
|
813
|
+
return null;
|
|
814
|
+
}
|
|
815
|
+
var LogoControl = (0, import_react4.memo)(_LogoControl);
|
|
816
|
+
|
|
817
|
+
// src/components/attribution-control.ts
|
|
818
|
+
var import_react5 = require("react");
|
|
819
|
+
function _AttributionControl(props) {
|
|
820
|
+
const ctrl = useControl(
|
|
821
|
+
({ mapLib }) => new mapLib.AttributionControl(props),
|
|
822
|
+
{ position: props.position }
|
|
823
|
+
);
|
|
824
|
+
(0, import_react5.useEffect)(() => {
|
|
825
|
+
applyReactStyle(ctrl._container, props.style);
|
|
826
|
+
if (!ctrl._container)
|
|
827
|
+
return;
|
|
828
|
+
}, [props.style, ctrl._container]);
|
|
829
|
+
return null;
|
|
886
830
|
}
|
|
831
|
+
var AttributionControl = (0, import_react5.memo)(_AttributionControl);
|
|
887
832
|
|
|
888
833
|
// src/components/map.tsx
|
|
889
834
|
var MapContext = React2.createContext(null);
|
|
890
|
-
function
|
|
891
|
-
const mountedMapsContext = (0,
|
|
892
|
-
const [mapInstance, setMapInstance] = (0,
|
|
893
|
-
const containerRef = (0,
|
|
894
|
-
const { current: contextValue } = (0,
|
|
895
|
-
|
|
896
|
-
|
|
835
|
+
function _Map(props, ref) {
|
|
836
|
+
const mountedMapsContext = (0, import_react6.useContext)(MountedMapsContext);
|
|
837
|
+
const [mapInstance, setMapInstance] = (0, import_react6.useState)(null);
|
|
838
|
+
const containerRef = (0, import_react6.useRef)();
|
|
839
|
+
const { current: contextValue } = (0, import_react6.useRef)({
|
|
840
|
+
mapLib: null,
|
|
841
|
+
map: null
|
|
842
|
+
});
|
|
843
|
+
(0, import_react6.useEffect)(() => {
|
|
844
|
+
const mapLib = props.mapLib;
|
|
897
845
|
let isMounted = true;
|
|
898
|
-
let
|
|
899
|
-
Promise.resolve(
|
|
846
|
+
let maplibre;
|
|
847
|
+
Promise.resolve(mapLib || import("maplibre-gl")).then((module2) => {
|
|
900
848
|
if (!isMounted) {
|
|
901
849
|
return;
|
|
902
850
|
}
|
|
@@ -908,20 +856,23 @@ function Map(props, ref, defaultLib) {
|
|
|
908
856
|
throw new Error("Invalid mapLib");
|
|
909
857
|
}
|
|
910
858
|
setGlobals(mapboxgl, props);
|
|
911
|
-
if (
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
throw new Error("Map is not supported by this browser");
|
|
859
|
+
if (props.reuseMaps) {
|
|
860
|
+
maplibre = Maplibre.reuse(props, containerRef.current);
|
|
861
|
+
}
|
|
862
|
+
if (!maplibre) {
|
|
863
|
+
maplibre = new Maplibre(
|
|
864
|
+
mapboxgl.Map,
|
|
865
|
+
__spreadProps(__spreadValues({}, props), {
|
|
866
|
+
// @ts-ignore
|
|
867
|
+
attributionControl: false
|
|
868
|
+
}),
|
|
869
|
+
containerRef.current
|
|
870
|
+
);
|
|
924
871
|
}
|
|
872
|
+
contextValue.map = createRef(maplibre);
|
|
873
|
+
contextValue.mapLib = mapboxgl;
|
|
874
|
+
setMapInstance(maplibre);
|
|
875
|
+
mountedMapsContext == null ? void 0 : mountedMapsContext.onMapMount(contextValue.map, props.id);
|
|
925
876
|
}).catch((error) => {
|
|
926
877
|
const { onError } = props;
|
|
927
878
|
if (onError) {
|
|
@@ -937,12 +888,12 @@ function Map(props, ref, defaultLib) {
|
|
|
937
888
|
});
|
|
938
889
|
return () => {
|
|
939
890
|
isMounted = false;
|
|
940
|
-
if (
|
|
891
|
+
if (maplibre) {
|
|
941
892
|
mountedMapsContext == null ? void 0 : mountedMapsContext.onMapUnmount(props.id);
|
|
942
893
|
if (props.reuseMaps) {
|
|
943
|
-
|
|
894
|
+
maplibre.recycle();
|
|
944
895
|
} else {
|
|
945
|
-
|
|
896
|
+
maplibre.destroy();
|
|
946
897
|
}
|
|
947
898
|
}
|
|
948
899
|
};
|
|
@@ -952,8 +903,8 @@ function Map(props, ref, defaultLib) {
|
|
|
952
903
|
mapInstance.setProps(props);
|
|
953
904
|
}
|
|
954
905
|
});
|
|
955
|
-
(0,
|
|
956
|
-
const style = (0,
|
|
906
|
+
(0, import_react6.useImperativeHandle)(ref, () => contextValue.map, [mapInstance]);
|
|
907
|
+
const style = (0, import_react6.useMemo)(
|
|
957
908
|
() => __spreadValues({
|
|
958
909
|
position: "relative",
|
|
959
910
|
width: "100%",
|
|
@@ -964,268 +915,233 @@ function Map(props, ref, defaultLib) {
|
|
|
964
915
|
const CHILD_CONTAINER_STYLE = {
|
|
965
916
|
height: "100%"
|
|
966
917
|
};
|
|
967
|
-
return /* @__PURE__ */ React2.createElement("div", { id: props.id, ref: containerRef, style }, mapInstance && /* @__PURE__ */ React2.createElement(MapContext.Provider, { value: contextValue }, /* @__PURE__ */ React2.createElement("div", { "mapboxgl-children": "", style: CHILD_CONTAINER_STYLE }, props.children)));
|
|
918
|
+
return /* @__PURE__ */ React2.createElement("div", { id: props.id, ref: containerRef, style }, mapInstance && /* @__PURE__ */ React2.createElement(MapContext.Provider, { value: contextValue }, /* @__PURE__ */ React2.createElement("div", { "mapboxgl-children": "", style: CHILD_CONTAINER_STYLE }, /* @__PURE__ */ React2.createElement(LogoControl, { position: "bottom-left" }), /* @__PURE__ */ React2.createElement(AttributionControl, { position: "bottom-right" }), props.children)));
|
|
968
919
|
}
|
|
920
|
+
var Map = React2.forwardRef(_Map);
|
|
969
921
|
|
|
970
922
|
// src/components/marker.ts
|
|
971
923
|
var React3 = __toESM(require("react"), 1);
|
|
972
924
|
var import_react_dom = require("react-dom");
|
|
973
|
-
var
|
|
925
|
+
var import_react7 = require("react");
|
|
974
926
|
|
|
975
|
-
// src/utils/
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
return;
|
|
927
|
+
// src/utils/compare-class-names.ts
|
|
928
|
+
function compareClassNames(prevClassName, nextClassName) {
|
|
929
|
+
if (prevClassName === nextClassName) {
|
|
930
|
+
return null;
|
|
980
931
|
}
|
|
981
|
-
const
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
style[key] = value;
|
|
932
|
+
const prevClassList = getClassList(prevClassName);
|
|
933
|
+
const nextClassList = getClassList(nextClassName);
|
|
934
|
+
const diff = [];
|
|
935
|
+
for (const c of nextClassList) {
|
|
936
|
+
if (!prevClassList.has(c)) {
|
|
937
|
+
diff.push(c);
|
|
988
938
|
}
|
|
989
939
|
}
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
const { map, mapLib: mapLib2 } = (0, import_react4.useContext)(MapContext);
|
|
995
|
-
const thisRef = (0, import_react4.useRef)({ props });
|
|
996
|
-
thisRef.current.props = props;
|
|
997
|
-
const marker = (0, import_react4.useMemo)(() => {
|
|
998
|
-
let hasChildren = false;
|
|
999
|
-
React3.Children.forEach(props.children, (el) => {
|
|
1000
|
-
if (el) {
|
|
1001
|
-
hasChildren = true;
|
|
1002
|
-
}
|
|
1003
|
-
});
|
|
1004
|
-
const options = __spreadProps(__spreadValues({}, props), {
|
|
1005
|
-
element: hasChildren ? document.createElement("div") : null
|
|
1006
|
-
});
|
|
1007
|
-
const mk = new mapLib2.Marker(options);
|
|
1008
|
-
mk.setLngLat([props.longitude, props.latitude]);
|
|
1009
|
-
mk.getElement().addEventListener("click", (e) => {
|
|
1010
|
-
var _a, _b;
|
|
1011
|
-
(_b = (_a = thisRef.current.props).onClick) == null ? void 0 : _b.call(_a, {
|
|
1012
|
-
type: "click",
|
|
1013
|
-
target: mk,
|
|
1014
|
-
originalEvent: e
|
|
1015
|
-
});
|
|
1016
|
-
});
|
|
1017
|
-
mk.on("dragstart", (e) => {
|
|
1018
|
-
var _a, _b;
|
|
1019
|
-
const evt = e;
|
|
1020
|
-
evt.lngLat = marker.getLngLat();
|
|
1021
|
-
(_b = (_a = thisRef.current.props).onDragStart) == null ? void 0 : _b.call(_a, evt);
|
|
1022
|
-
});
|
|
1023
|
-
mk.on("drag", (e) => {
|
|
1024
|
-
var _a, _b;
|
|
1025
|
-
const evt = e;
|
|
1026
|
-
evt.lngLat = marker.getLngLat();
|
|
1027
|
-
(_b = (_a = thisRef.current.props).onDrag) == null ? void 0 : _b.call(_a, evt);
|
|
1028
|
-
});
|
|
1029
|
-
mk.on("dragend", (e) => {
|
|
1030
|
-
var _a, _b;
|
|
1031
|
-
const evt = e;
|
|
1032
|
-
evt.lngLat = marker.getLngLat();
|
|
1033
|
-
(_b = (_a = thisRef.current.props).onDragEnd) == null ? void 0 : _b.call(_a, evt);
|
|
1034
|
-
});
|
|
1035
|
-
return mk;
|
|
1036
|
-
}, []);
|
|
1037
|
-
(0, import_react4.useEffect)(() => {
|
|
1038
|
-
marker.addTo(map.getMap());
|
|
1039
|
-
return () => {
|
|
1040
|
-
marker.remove();
|
|
1041
|
-
};
|
|
1042
|
-
}, []);
|
|
1043
|
-
const {
|
|
1044
|
-
longitude,
|
|
1045
|
-
latitude,
|
|
1046
|
-
offset,
|
|
1047
|
-
style,
|
|
1048
|
-
draggable = false,
|
|
1049
|
-
popup = null,
|
|
1050
|
-
rotation = 0,
|
|
1051
|
-
rotationAlignment = "auto",
|
|
1052
|
-
pitchAlignment = "auto"
|
|
1053
|
-
} = props;
|
|
1054
|
-
(0, import_react4.useEffect)(() => {
|
|
1055
|
-
applyReactStyle(marker.getElement(), style);
|
|
1056
|
-
}, [style]);
|
|
1057
|
-
(0, import_react4.useImperativeHandle)(ref, () => marker, []);
|
|
1058
|
-
if (marker.getLngLat().lng !== longitude || marker.getLngLat().lat !== latitude) {
|
|
1059
|
-
marker.setLngLat([longitude, latitude]);
|
|
1060
|
-
}
|
|
1061
|
-
if (offset && !arePointsEqual(marker.getOffset(), offset)) {
|
|
1062
|
-
marker.setOffset(offset);
|
|
1063
|
-
}
|
|
1064
|
-
if (marker.isDraggable() !== draggable) {
|
|
1065
|
-
marker.setDraggable(draggable);
|
|
1066
|
-
}
|
|
1067
|
-
if (marker.getRotation() !== rotation) {
|
|
1068
|
-
marker.setRotation(rotation);
|
|
1069
|
-
}
|
|
1070
|
-
if (marker.getRotationAlignment() !== rotationAlignment) {
|
|
1071
|
-
marker.setRotationAlignment(rotationAlignment);
|
|
1072
|
-
}
|
|
1073
|
-
if (marker.getPitchAlignment() !== pitchAlignment) {
|
|
1074
|
-
marker.setPitchAlignment(pitchAlignment);
|
|
1075
|
-
}
|
|
1076
|
-
if (marker.getPopup() !== popup) {
|
|
1077
|
-
marker.setPopup(popup);
|
|
940
|
+
for (const c of prevClassList) {
|
|
941
|
+
if (!nextClassList.has(c)) {
|
|
942
|
+
diff.push(c);
|
|
943
|
+
}
|
|
1078
944
|
}
|
|
1079
|
-
return
|
|
945
|
+
return diff.length === 0 ? null : diff;
|
|
1080
946
|
}
|
|
1081
|
-
var marker_default = (0, import_react4.memo)((0, import_react4.forwardRef)(Marker));
|
|
1082
|
-
|
|
1083
|
-
// src/components/popup.ts
|
|
1084
|
-
var import_react_dom2 = require("react-dom");
|
|
1085
|
-
var import_react5 = require("react");
|
|
1086
947
|
function getClassList(className) {
|
|
1087
948
|
return new Set(className ? className.trim().split(/\s+/) : []);
|
|
1088
949
|
}
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
950
|
+
|
|
951
|
+
// src/components/marker.ts
|
|
952
|
+
var Marker = (0, import_react7.memo)(
|
|
953
|
+
(0, import_react7.forwardRef)((props, ref) => {
|
|
954
|
+
const { map, mapLib } = (0, import_react7.useContext)(MapContext);
|
|
955
|
+
const thisRef = (0, import_react7.useRef)({ props });
|
|
956
|
+
const marker = (0, import_react7.useMemo)(() => {
|
|
957
|
+
let hasChildren = false;
|
|
958
|
+
React3.Children.forEach(props.children, (el) => {
|
|
959
|
+
if (el) {
|
|
960
|
+
hasChildren = true;
|
|
961
|
+
}
|
|
962
|
+
});
|
|
963
|
+
const options = __spreadProps(__spreadValues({}, props), {
|
|
964
|
+
element: hasChildren ? document.createElement("div") : void 0
|
|
965
|
+
});
|
|
966
|
+
const mk = new mapLib.Marker(options);
|
|
967
|
+
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
|
+
return mk;
|
|
995
|
+
}, []);
|
|
996
|
+
(0, import_react7.useEffect)(() => {
|
|
997
|
+
marker.addTo(map.getMap());
|
|
998
|
+
return () => {
|
|
999
|
+
marker.remove();
|
|
1000
|
+
};
|
|
1001
|
+
}, []);
|
|
1002
|
+
const {
|
|
1003
|
+
longitude,
|
|
1004
|
+
latitude,
|
|
1005
|
+
offset,
|
|
1006
|
+
style,
|
|
1007
|
+
draggable = false,
|
|
1008
|
+
popup = null,
|
|
1009
|
+
rotation = 0,
|
|
1010
|
+
rotationAlignment = "auto",
|
|
1011
|
+
pitchAlignment = "auto"
|
|
1012
|
+
} = props;
|
|
1013
|
+
(0, import_react7.useEffect)(() => {
|
|
1014
|
+
applyReactStyle(marker.getElement(), style);
|
|
1015
|
+
}, [style]);
|
|
1016
|
+
(0, import_react7.useImperativeHandle)(ref, () => marker, []);
|
|
1017
|
+
const oldProps = thisRef.current.props;
|
|
1018
|
+
if (marker.getLngLat().lng !== longitude || marker.getLngLat().lat !== latitude) {
|
|
1019
|
+
marker.setLngLat([longitude, latitude]);
|
|
1127
1020
|
}
|
|
1128
|
-
if (
|
|
1129
|
-
|
|
1021
|
+
if (offset && !arePointsEqual(marker.getOffset(), offset)) {
|
|
1022
|
+
marker.setOffset(offset);
|
|
1130
1023
|
}
|
|
1131
|
-
if (
|
|
1132
|
-
|
|
1133
|
-
popup.setMaxWidth(props.maxWidth);
|
|
1024
|
+
if (marker.isDraggable() !== draggable) {
|
|
1025
|
+
marker.setDraggable(draggable);
|
|
1134
1026
|
}
|
|
1135
|
-
if (
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
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);
|
|
1147
1046
|
}
|
|
1148
|
-
popup.options.className = props.className;
|
|
1149
1047
|
}
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
}
|
|
1153
|
-
|
|
1048
|
+
thisRef.current.props = props;
|
|
1049
|
+
return (0, import_react_dom.createPortal)(props.children, marker.getElement());
|
|
1050
|
+
})
|
|
1051
|
+
);
|
|
1154
1052
|
|
|
1155
|
-
// src/components/
|
|
1156
|
-
var
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
const
|
|
1165
|
-
const
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1053
|
+
// src/components/popup.ts
|
|
1054
|
+
var import_react_dom2 = require("react-dom");
|
|
1055
|
+
var import_react8 = require("react");
|
|
1056
|
+
var Popup = (0, import_react8.memo)(
|
|
1057
|
+
(0, import_react8.forwardRef)((props, ref) => {
|
|
1058
|
+
const { map, mapLib } = (0, import_react8.useContext)(MapContext);
|
|
1059
|
+
const container = (0, import_react8.useMemo)(() => {
|
|
1060
|
+
return document.createElement("div");
|
|
1061
|
+
}, []);
|
|
1062
|
+
const thisRef = (0, import_react8.useRef)({ props });
|
|
1063
|
+
const popup = (0, import_react8.useMemo)(() => {
|
|
1064
|
+
const options = __spreadValues({}, props);
|
|
1065
|
+
const pp = new mapLib.Popup(options);
|
|
1066
|
+
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
|
+
return pp;
|
|
1072
|
+
}, []);
|
|
1073
|
+
(0, import_react8.useEffect)(() => {
|
|
1074
|
+
const onClose = (e) => {
|
|
1075
|
+
var _a, _b;
|
|
1076
|
+
(_b = (_a = thisRef.current.props).onClose) == null ? void 0 : _b.call(_a, e);
|
|
1077
|
+
};
|
|
1078
|
+
popup.on("close", onClose);
|
|
1079
|
+
popup.setDOMContent(container).addTo(map.getMap());
|
|
1080
|
+
return () => {
|
|
1081
|
+
popup.off("close", onClose);
|
|
1082
|
+
if (popup.isOpen()) {
|
|
1083
|
+
popup.remove();
|
|
1084
|
+
}
|
|
1085
|
+
};
|
|
1086
|
+
}, []);
|
|
1087
|
+
(0, import_react8.useEffect)(() => {
|
|
1088
|
+
applyReactStyle(popup.getElement(), props.style);
|
|
1089
|
+
}, [props.style]);
|
|
1090
|
+
(0, import_react8.useImperativeHandle)(ref, () => popup, []);
|
|
1091
|
+
if (popup.isOpen()) {
|
|
1092
|
+
const oldProps = thisRef.current.props;
|
|
1093
|
+
if (popup.getLngLat().lng !== props.longitude || popup.getLngLat().lat !== props.latitude) {
|
|
1094
|
+
popup.setLngLat([props.longitude, props.latitude]);
|
|
1172
1095
|
}
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
if (onRemove) {
|
|
1176
|
-
onRemove(context);
|
|
1096
|
+
if (props.offset && !deepEqual(oldProps.offset, props.offset)) {
|
|
1097
|
+
popup.setOffset(props.offset);
|
|
1177
1098
|
}
|
|
1178
|
-
if (
|
|
1179
|
-
|
|
1099
|
+
if (oldProps.anchor !== props.anchor || oldProps.maxWidth !== props.maxWidth) {
|
|
1100
|
+
popup.options.anchor = props.anchor;
|
|
1101
|
+
popup.setMaxWidth(props.maxWidth);
|
|
1180
1102
|
}
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
{
|
|
1192
|
-
position: props.position
|
|
1103
|
+
const classNameDiff = compareClassNames(
|
|
1104
|
+
oldProps.className,
|
|
1105
|
+
props.className
|
|
1106
|
+
);
|
|
1107
|
+
if (classNameDiff) {
|
|
1108
|
+
for (const c of classNameDiff) {
|
|
1109
|
+
popup.toggleClassName(c);
|
|
1110
|
+
}
|
|
1111
|
+
}
|
|
1112
|
+
thisRef.current.props = props;
|
|
1193
1113
|
}
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
}, [props.style]);
|
|
1198
|
-
return null;
|
|
1199
|
-
}
|
|
1200
|
-
var attribution_control_default = (0, import_react7.memo)(AttributionControl);
|
|
1114
|
+
return (0, import_react_dom2.createPortal)(props.children, container);
|
|
1115
|
+
})
|
|
1116
|
+
);
|
|
1201
1117
|
|
|
1202
|
-
// src/components/fullscreen-control.
|
|
1203
|
-
var
|
|
1204
|
-
function
|
|
1205
|
-
const ctrl =
|
|
1206
|
-
({ mapLib
|
|
1118
|
+
// src/components/fullscreen-control.ts
|
|
1119
|
+
var import_react9 = require("react");
|
|
1120
|
+
function _FullscreenControl(props) {
|
|
1121
|
+
const ctrl = useControl(
|
|
1122
|
+
({ mapLib }) => new mapLib.FullscreenControl({
|
|
1207
1123
|
container: props.containerId && document.getElementById(props.containerId)
|
|
1208
1124
|
}),
|
|
1209
1125
|
{ position: props.position }
|
|
1210
1126
|
);
|
|
1211
|
-
(0,
|
|
1127
|
+
(0, import_react9.useEffect)(() => {
|
|
1212
1128
|
applyReactStyle(ctrl._controlContainer, props.style);
|
|
1213
1129
|
}, [props.style]);
|
|
1214
1130
|
return null;
|
|
1215
1131
|
}
|
|
1216
|
-
var
|
|
1132
|
+
var FullscreenControl = (0, import_react9.memo)(_FullscreenControl);
|
|
1217
1133
|
|
|
1218
1134
|
// src/components/geolocate-control.ts
|
|
1219
|
-
var
|
|
1220
|
-
function
|
|
1221
|
-
const thisRef = (0,
|
|
1222
|
-
const ctrl =
|
|
1223
|
-
({ mapLib
|
|
1224
|
-
const gc = new
|
|
1135
|
+
var import_react10 = require("react");
|
|
1136
|
+
function _GeolocateControl(props, ref) {
|
|
1137
|
+
const thisRef = (0, import_react10.useRef)({ props });
|
|
1138
|
+
const ctrl = useControl(
|
|
1139
|
+
({ mapLib }) => {
|
|
1140
|
+
const gc = new mapLib.GeolocateControl(props);
|
|
1225
1141
|
const setupUI = gc._setupUI;
|
|
1226
|
-
gc._setupUI = (
|
|
1142
|
+
gc._setupUI = () => {
|
|
1227
1143
|
if (!gc._container.hasChildNodes()) {
|
|
1228
|
-
setupUI(
|
|
1144
|
+
setupUI();
|
|
1229
1145
|
}
|
|
1230
1146
|
};
|
|
1231
1147
|
gc.on("geolocate", (e) => {
|
|
@@ -1253,34 +1169,36 @@ function GeolocateControl(props, ref) {
|
|
|
1253
1169
|
{ position: props.position }
|
|
1254
1170
|
);
|
|
1255
1171
|
thisRef.current.props = props;
|
|
1256
|
-
(0,
|
|
1257
|
-
(0,
|
|
1172
|
+
(0, import_react10.useImperativeHandle)(ref, () => ctrl, []);
|
|
1173
|
+
(0, import_react10.useEffect)(() => {
|
|
1258
1174
|
applyReactStyle(ctrl._container, props.style);
|
|
1259
1175
|
}, [props.style]);
|
|
1260
1176
|
return null;
|
|
1261
1177
|
}
|
|
1262
|
-
var
|
|
1178
|
+
var GeolocateControl = (0, import_react10.memo)(
|
|
1179
|
+
(0, import_react10.forwardRef)(_GeolocateControl)
|
|
1180
|
+
);
|
|
1263
1181
|
|
|
1264
1182
|
// src/components/navigation-control.ts
|
|
1265
|
-
var
|
|
1266
|
-
function
|
|
1267
|
-
const ctrl =
|
|
1183
|
+
var import_react11 = require("react");
|
|
1184
|
+
function _NavigationControl(props) {
|
|
1185
|
+
const ctrl = useControl(({ mapLib }) => new mapLib.NavigationControl(props), {
|
|
1268
1186
|
position: props.position
|
|
1269
1187
|
});
|
|
1270
|
-
(0,
|
|
1188
|
+
(0, import_react11.useEffect)(() => {
|
|
1271
1189
|
applyReactStyle(ctrl._container, props.style);
|
|
1272
1190
|
}, [props.style]);
|
|
1273
1191
|
return null;
|
|
1274
1192
|
}
|
|
1275
|
-
var
|
|
1193
|
+
var NavigationControl = (0, import_react11.memo)(_NavigationControl);
|
|
1276
1194
|
|
|
1277
1195
|
// src/components/scale-control.ts
|
|
1278
|
-
var
|
|
1279
|
-
function
|
|
1280
|
-
const ctrl =
|
|
1196
|
+
var import_react12 = require("react");
|
|
1197
|
+
function _ScaleControl(props) {
|
|
1198
|
+
const ctrl = useControl(({ mapLib }) => new mapLib.ScaleControl(props), {
|
|
1281
1199
|
position: props.position
|
|
1282
1200
|
});
|
|
1283
|
-
const propsRef = (0,
|
|
1201
|
+
const propsRef = (0, import_react12.useRef)(props);
|
|
1284
1202
|
const prevProps = propsRef.current;
|
|
1285
1203
|
propsRef.current = props;
|
|
1286
1204
|
const { style } = props;
|
|
@@ -1290,15 +1208,29 @@ function ScaleControl(props) {
|
|
|
1290
1208
|
if (props.unit !== void 0 && props.unit !== prevProps.unit) {
|
|
1291
1209
|
ctrl.setUnit(props.unit);
|
|
1292
1210
|
}
|
|
1293
|
-
(0,
|
|
1211
|
+
(0, import_react12.useEffect)(() => {
|
|
1294
1212
|
applyReactStyle(ctrl._container, style);
|
|
1295
1213
|
}, [style]);
|
|
1296
1214
|
return null;
|
|
1297
1215
|
}
|
|
1298
|
-
var
|
|
1216
|
+
var ScaleControl = (0, import_react12.memo)(_ScaleControl);
|
|
1299
1217
|
|
|
1300
|
-
// src/components/
|
|
1301
|
-
var
|
|
1218
|
+
// src/components/terrain-control.ts
|
|
1219
|
+
var import_react13 = require("react");
|
|
1220
|
+
function _TerrainControl(props) {
|
|
1221
|
+
const ctrl = useControl(({ mapLib }) => new mapLib.TerrainControl(props), {
|
|
1222
|
+
position: props.position
|
|
1223
|
+
});
|
|
1224
|
+
(0, import_react13.useEffect)(() => {
|
|
1225
|
+
applyReactStyle(ctrl._container, props.style);
|
|
1226
|
+
}, [props.style]);
|
|
1227
|
+
return null;
|
|
1228
|
+
}
|
|
1229
|
+
var TerrainControl = (0, import_react13.memo)(_TerrainControl);
|
|
1230
|
+
|
|
1231
|
+
// src/components/source.ts
|
|
1232
|
+
var React4 = __toESM(require("react"), 1);
|
|
1233
|
+
var import_react14 = require("react");
|
|
1302
1234
|
|
|
1303
1235
|
// src/utils/assert.ts
|
|
1304
1236
|
function assert(condition, message) {
|
|
@@ -1307,96 +1239,7 @@ function assert(condition, message) {
|
|
|
1307
1239
|
}
|
|
1308
1240
|
}
|
|
1309
1241
|
|
|
1310
|
-
// src/components/layer.ts
|
|
1311
|
-
function updateLayer(map, id, props, prevProps) {
|
|
1312
|
-
assert(props.id === prevProps.id, "layer id changed");
|
|
1313
|
-
assert(props.type === prevProps.type, "layer type changed");
|
|
1314
|
-
if (props.type === "custom" || prevProps.type === "custom") {
|
|
1315
|
-
return;
|
|
1316
|
-
}
|
|
1317
|
-
const { layout = {}, paint = {}, filter, minzoom, maxzoom, beforeId } = props;
|
|
1318
|
-
if (beforeId !== prevProps.beforeId) {
|
|
1319
|
-
map.moveLayer(id, beforeId);
|
|
1320
|
-
}
|
|
1321
|
-
if (layout !== prevProps.layout) {
|
|
1322
|
-
const prevLayout = prevProps.layout || {};
|
|
1323
|
-
for (const key in layout) {
|
|
1324
|
-
if (!deepEqual(layout[key], prevLayout[key])) {
|
|
1325
|
-
map.setLayoutProperty(id, key, layout[key]);
|
|
1326
|
-
}
|
|
1327
|
-
}
|
|
1328
|
-
for (const key in prevLayout) {
|
|
1329
|
-
if (!layout.hasOwnProperty(key)) {
|
|
1330
|
-
map.setLayoutProperty(id, key, void 0);
|
|
1331
|
-
}
|
|
1332
|
-
}
|
|
1333
|
-
}
|
|
1334
|
-
if (paint !== prevProps.paint) {
|
|
1335
|
-
const prevPaint = prevProps.paint || {};
|
|
1336
|
-
for (const key in paint) {
|
|
1337
|
-
if (!deepEqual(paint[key], prevPaint[key])) {
|
|
1338
|
-
map.setPaintProperty(id, key, paint[key]);
|
|
1339
|
-
}
|
|
1340
|
-
}
|
|
1341
|
-
for (const key in prevPaint) {
|
|
1342
|
-
if (!paint.hasOwnProperty(key)) {
|
|
1343
|
-
map.setPaintProperty(id, key, void 0);
|
|
1344
|
-
}
|
|
1345
|
-
}
|
|
1346
|
-
}
|
|
1347
|
-
if (!deepEqual(filter, prevProps.filter)) {
|
|
1348
|
-
map.setFilter(id, filter);
|
|
1349
|
-
}
|
|
1350
|
-
if (minzoom !== prevProps.minzoom || maxzoom !== prevProps.maxzoom) {
|
|
1351
|
-
map.setLayerZoomRange(id, minzoom, maxzoom);
|
|
1352
|
-
}
|
|
1353
|
-
}
|
|
1354
|
-
function createLayer(map, id, props) {
|
|
1355
|
-
if (map.style && map.style._loaded && (!("source" in props) || map.getSource(props.source))) {
|
|
1356
|
-
const options = __spreadProps(__spreadValues({}, props), { id });
|
|
1357
|
-
delete options.beforeId;
|
|
1358
|
-
map.addLayer(options, props.beforeId);
|
|
1359
|
-
}
|
|
1360
|
-
}
|
|
1361
|
-
var layerCounter = 0;
|
|
1362
|
-
function Layer(props) {
|
|
1363
|
-
const map = (0, import_react12.useContext)(MapContext).map.getMap();
|
|
1364
|
-
const propsRef = (0, import_react12.useRef)(props);
|
|
1365
|
-
const [, setStyleLoaded] = (0, import_react12.useState)(0);
|
|
1366
|
-
const id = (0, import_react12.useMemo)(() => props.id || `jsx-layer-${layerCounter++}`, []);
|
|
1367
|
-
(0, import_react12.useEffect)(() => {
|
|
1368
|
-
if (map) {
|
|
1369
|
-
const forceUpdate = () => setStyleLoaded((version) => version + 1);
|
|
1370
|
-
map.on("styledata", forceUpdate);
|
|
1371
|
-
forceUpdate();
|
|
1372
|
-
return () => {
|
|
1373
|
-
map.off("styledata", forceUpdate);
|
|
1374
|
-
if (map.style && map.style._loaded && map.getLayer(id)) {
|
|
1375
|
-
map.removeLayer(id);
|
|
1376
|
-
}
|
|
1377
|
-
};
|
|
1378
|
-
}
|
|
1379
|
-
return void 0;
|
|
1380
|
-
}, [map]);
|
|
1381
|
-
const layer = map && map.style && map.getLayer(id);
|
|
1382
|
-
if (layer) {
|
|
1383
|
-
try {
|
|
1384
|
-
updateLayer(map, id, props, propsRef.current);
|
|
1385
|
-
} catch (error) {
|
|
1386
|
-
console.warn(error);
|
|
1387
|
-
}
|
|
1388
|
-
} else {
|
|
1389
|
-
createLayer(map, id, props);
|
|
1390
|
-
}
|
|
1391
|
-
propsRef.current = props;
|
|
1392
|
-
return null;
|
|
1393
|
-
}
|
|
1394
|
-
var layer_default = Layer;
|
|
1395
|
-
|
|
1396
1242
|
// src/components/source.ts
|
|
1397
|
-
var React4 = __toESM(require("react"), 1);
|
|
1398
|
-
var import_react13 = require("react");
|
|
1399
|
-
var import_react14 = require("react");
|
|
1400
1243
|
var sourceCounter = 0;
|
|
1401
1244
|
function createSource(map, id, props) {
|
|
1402
1245
|
if (map.style && map.style._loaded) {
|
|
@@ -1409,6 +1252,7 @@ function createSource(map, id, props) {
|
|
|
1409
1252
|
return null;
|
|
1410
1253
|
}
|
|
1411
1254
|
function updateSource(source, props, prevProps) {
|
|
1255
|
+
var _a, _b, _c;
|
|
1412
1256
|
assert(props.id === prevProps.id, "source id changed");
|
|
1413
1257
|
assert(props.type === prevProps.type, "source type changed");
|
|
1414
1258
|
let changedKey = "";
|
|
@@ -1424,36 +1268,34 @@ function updateSource(source, props, prevProps) {
|
|
|
1424
1268
|
}
|
|
1425
1269
|
const type = props.type;
|
|
1426
1270
|
if (type === "geojson") {
|
|
1427
|
-
source.setData(
|
|
1428
|
-
props.data
|
|
1429
|
-
);
|
|
1271
|
+
source.setData(props.data);
|
|
1430
1272
|
} else if (type === "image") {
|
|
1431
1273
|
source.updateImage({
|
|
1432
1274
|
url: props.url,
|
|
1433
1275
|
coordinates: props.coordinates
|
|
1434
1276
|
});
|
|
1435
|
-
} else
|
|
1436
|
-
source.setCoordinates(props.coordinates);
|
|
1437
|
-
} else if ("setUrl" in source) {
|
|
1277
|
+
} else {
|
|
1438
1278
|
switch (changedKey) {
|
|
1279
|
+
case "coordinates":
|
|
1280
|
+
(_a = source.setCoordinates) == null ? void 0 : _a.call(source, props.coordinates);
|
|
1281
|
+
break;
|
|
1439
1282
|
case "url":
|
|
1440
|
-
source.setUrl(props.url);
|
|
1283
|
+
(_b = source.setUrl) == null ? void 0 : _b.call(source, props.url);
|
|
1441
1284
|
break;
|
|
1442
1285
|
case "tiles":
|
|
1443
|
-
source.setTiles(props.tiles);
|
|
1286
|
+
(_c = source.setTiles) == null ? void 0 : _c.call(source, props.tiles);
|
|
1444
1287
|
break;
|
|
1445
1288
|
default:
|
|
1289
|
+
console.warn(`Unable to update <Source> prop: ${changedKey}`);
|
|
1446
1290
|
}
|
|
1447
|
-
} else {
|
|
1448
|
-
console.warn(`Unable to update <Source> prop: ${changedKey}`);
|
|
1449
1291
|
}
|
|
1450
1292
|
}
|
|
1451
1293
|
function Source(props) {
|
|
1452
|
-
const map = (0,
|
|
1453
|
-
const propsRef = (0,
|
|
1454
|
-
const [, setStyleLoaded] = (0,
|
|
1455
|
-
const id = (0,
|
|
1456
|
-
(0,
|
|
1294
|
+
const map = (0, import_react14.useContext)(MapContext).map.getMap();
|
|
1295
|
+
const propsRef = (0, import_react14.useRef)(props);
|
|
1296
|
+
const [, setStyleLoaded] = (0, import_react14.useState)(0);
|
|
1297
|
+
const id = (0, import_react14.useMemo)(() => props.id || `jsx-source-${sourceCounter++}`, []);
|
|
1298
|
+
(0, import_react14.useEffect)(() => {
|
|
1457
1299
|
if (map) {
|
|
1458
1300
|
const forceUpdate = () => setTimeout(() => setStyleLoaded((version) => version + 1), 0);
|
|
1459
1301
|
map.on("styledata", forceUpdate);
|
|
@@ -1490,25 +1332,92 @@ function Source(props) {
|
|
|
1490
1332
|
})
|
|
1491
1333
|
) || null;
|
|
1492
1334
|
}
|
|
1493
|
-
var source_default = Source;
|
|
1494
1335
|
|
|
1495
|
-
// src/
|
|
1496
|
-
|
|
1497
|
-
|
|
1336
|
+
// src/components/layer.ts
|
|
1337
|
+
var import_react15 = require("react");
|
|
1338
|
+
function updateLayer(map, id, props, prevProps) {
|
|
1339
|
+
assert(props.id === prevProps.id, "layer id changed");
|
|
1340
|
+
assert(props.type === prevProps.type, "layer type changed");
|
|
1341
|
+
if (props.type === "custom" || prevProps.type === "custom") {
|
|
1342
|
+
return;
|
|
1343
|
+
}
|
|
1344
|
+
const { layout = {}, paint = {}, filter, minzoom, maxzoom, beforeId } = props;
|
|
1345
|
+
if (beforeId !== prevProps.beforeId) {
|
|
1346
|
+
map.moveLayer(id, beforeId);
|
|
1347
|
+
}
|
|
1348
|
+
if (layout !== prevProps.layout) {
|
|
1349
|
+
const prevLayout = prevProps.layout || {};
|
|
1350
|
+
for (const key in layout) {
|
|
1351
|
+
if (!deepEqual(layout[key], prevLayout[key])) {
|
|
1352
|
+
map.setLayoutProperty(id, key, layout[key]);
|
|
1353
|
+
}
|
|
1354
|
+
}
|
|
1355
|
+
for (const key in prevLayout) {
|
|
1356
|
+
if (!layout.hasOwnProperty(key)) {
|
|
1357
|
+
map.setLayoutProperty(id, key, void 0);
|
|
1358
|
+
}
|
|
1359
|
+
}
|
|
1360
|
+
}
|
|
1361
|
+
if (paint !== prevProps.paint) {
|
|
1362
|
+
const prevPaint = prevProps.paint || {};
|
|
1363
|
+
for (const key in paint) {
|
|
1364
|
+
if (!deepEqual(paint[key], prevPaint[key])) {
|
|
1365
|
+
map.setPaintProperty(id, key, paint[key]);
|
|
1366
|
+
}
|
|
1367
|
+
}
|
|
1368
|
+
for (const key in prevPaint) {
|
|
1369
|
+
if (!paint.hasOwnProperty(key)) {
|
|
1370
|
+
map.setPaintProperty(id, key, void 0);
|
|
1371
|
+
}
|
|
1372
|
+
}
|
|
1373
|
+
}
|
|
1374
|
+
if (!deepEqual(filter, prevProps.filter)) {
|
|
1375
|
+
map.setFilter(id, filter);
|
|
1376
|
+
}
|
|
1377
|
+
if (minzoom !== prevProps.minzoom || maxzoom !== prevProps.maxzoom) {
|
|
1378
|
+
map.setLayerZoomRange(id, minzoom, maxzoom);
|
|
1379
|
+
}
|
|
1498
1380
|
}
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
}
|
|
1505
|
-
|
|
1506
|
-
var
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1381
|
+
function createLayer(map, id, props) {
|
|
1382
|
+
if (map.style && map.style._loaded && (!("source" in props) || map.getSource(props.source))) {
|
|
1383
|
+
const options = __spreadProps(__spreadValues({}, props), { id });
|
|
1384
|
+
delete options.beforeId;
|
|
1385
|
+
map.addLayer(options, props.beforeId);
|
|
1386
|
+
}
|
|
1387
|
+
}
|
|
1388
|
+
var layerCounter = 0;
|
|
1389
|
+
function Layer(props) {
|
|
1390
|
+
const map = (0, import_react15.useContext)(MapContext).map.getMap();
|
|
1391
|
+
const propsRef = (0, import_react15.useRef)(props);
|
|
1392
|
+
const [, setStyleLoaded] = (0, import_react15.useState)(0);
|
|
1393
|
+
const id = (0, import_react15.useMemo)(() => props.id || `jsx-layer-${layerCounter++}`, []);
|
|
1394
|
+
(0, import_react15.useEffect)(() => {
|
|
1395
|
+
if (map) {
|
|
1396
|
+
const forceUpdate = () => setStyleLoaded((version) => version + 1);
|
|
1397
|
+
map.on("styledata", forceUpdate);
|
|
1398
|
+
forceUpdate();
|
|
1399
|
+
return () => {
|
|
1400
|
+
map.off("styledata", forceUpdate);
|
|
1401
|
+
if (map.style && map.style._loaded && map.getLayer(id)) {
|
|
1402
|
+
map.removeLayer(id);
|
|
1403
|
+
}
|
|
1404
|
+
};
|
|
1405
|
+
}
|
|
1406
|
+
return void 0;
|
|
1407
|
+
}, [map]);
|
|
1408
|
+
const layer = map && map.style && map.getLayer(id);
|
|
1409
|
+
if (layer) {
|
|
1410
|
+
try {
|
|
1411
|
+
updateLayer(map, id, props, propsRef.current);
|
|
1412
|
+
} catch (error) {
|
|
1413
|
+
console.warn(error);
|
|
1414
|
+
}
|
|
1415
|
+
} else {
|
|
1416
|
+
createLayer(map, id, props);
|
|
1417
|
+
}
|
|
1418
|
+
propsRef.current = props;
|
|
1419
|
+
return null;
|
|
1420
|
+
}
|
|
1421
|
+
|
|
1422
|
+
// src/exports-maplibre-gl.ts
|
|
1423
|
+
var exports_maplibre_gl_default = Map;
|