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