react-bkoi-gl 1.0.7 → 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.
Files changed (167) hide show
  1. package/README.md +163 -18
  2. package/dist/components/attribution-control.d.ts +4 -6
  3. package/dist/components/attribution-control.js +6 -5
  4. package/dist/components/attribution-control.js.map +1 -1
  5. package/dist/components/fullscreen-control.d.ts +4 -6
  6. package/dist/components/fullscreen-control.js +4 -4
  7. package/dist/components/fullscreen-control.js.map +1 -1
  8. package/dist/components/geolocate-control.d.ts +10 -26
  9. package/dist/components/geolocate-control.js +11 -11
  10. package/dist/components/geolocate-control.js.map +1 -1
  11. package/dist/components/layer.d.ts +7 -6
  12. package/dist/components/layer.js +8 -9
  13. package/dist/components/layer.js.map +1 -1
  14. package/dist/components/logo-control.d.ts +9 -0
  15. package/dist/components/logo-control.js +28 -0
  16. package/dist/components/logo-control.js.map +1 -0
  17. package/dist/components/map.d.ts +20 -16
  18. package/dist/components/map.js +38 -32
  19. package/dist/components/map.js.map +1 -1
  20. package/dist/components/marker.d.ts +10 -33
  21. package/dist/components/marker.js +22 -15
  22. package/dist/components/marker.js.map +1 -1
  23. package/dist/components/navigation-control.d.ts +4 -6
  24. package/dist/components/navigation-control.js +4 -4
  25. package/dist/components/navigation-control.js.map +1 -1
  26. package/dist/components/popup.d.ts +7 -25
  27. package/dist/components/popup.js +17 -28
  28. package/dist/components/popup.js.map +1 -1
  29. package/dist/components/scale-control.d.ts +4 -6
  30. package/dist/components/scale-control.js +4 -4
  31. package/dist/components/scale-control.js.map +1 -1
  32. package/dist/components/source.d.ts +3 -4
  33. package/dist/components/source.js +20 -22
  34. package/dist/components/source.js.map +1 -1
  35. package/dist/components/terrain-control.d.ts +10 -0
  36. package/dist/components/terrain-control.js +19 -0
  37. package/dist/components/terrain-control.js.map +1 -0
  38. package/dist/components/use-control.d.ts +6 -6
  39. package/dist/components/use-control.js +4 -5
  40. package/dist/components/use-control.js.map +1 -1
  41. package/dist/components/use-map.d.ts +8 -9
  42. package/dist/components/use-map.js +5 -5
  43. package/dist/components/use-map.js.map +1 -1
  44. package/dist/exports-maplibre-gl.d.ts +33 -0
  45. package/dist/exports-maplibre-gl.js +21 -0
  46. package/dist/exports-maplibre-gl.js.map +1 -0
  47. package/dist/index.cjs +590 -681
  48. package/dist/index.d.ts +2 -2
  49. package/dist/index.js +2 -2
  50. package/dist/index.js.map +1 -1
  51. package/dist/{mapbox → maplibre}/create-ref.d.ts +6 -6
  52. package/dist/maplibre/create-ref.js +30 -0
  53. package/dist/maplibre/create-ref.js.map +1 -0
  54. package/dist/maplibre/maplibre.d.ts +81 -0
  55. package/dist/maplibre/maplibre.js +387 -0
  56. package/dist/maplibre/maplibre.js.map +1 -0
  57. package/dist/styles/index.d.ts +4 -0
  58. package/dist/styles/react-bkoi-gl.css +1 -1
  59. package/dist/styles.d.js +2 -0
  60. package/dist/styles.d.js.map +1 -0
  61. package/dist/tsconfig.build.tsbuildinfo +1 -0
  62. package/dist/types/common.d.ts +2 -60
  63. package/dist/types/common.js.map +1 -1
  64. package/dist/types/events.d.ts +64 -23
  65. package/dist/types/events.js.map +1 -1
  66. package/dist/types/internal.d.ts +14 -0
  67. package/dist/types/internal.js +2 -0
  68. package/dist/types/internal.js.map +1 -0
  69. package/dist/types/lib.d.ts +16 -200
  70. package/dist/types/lib.js.map +1 -1
  71. package/dist/types/style-spec.d.ts +1 -0
  72. package/dist/types/style-spec.js +2 -0
  73. package/dist/types/style-spec.js.map +1 -0
  74. package/dist/utils/apply-react-style.d.ts +1 -1
  75. package/dist/utils/apply-react-style.js.map +1 -1
  76. package/dist/utils/compare-class-names.d.ts +2 -0
  77. package/dist/utils/compare-class-names.js +23 -0
  78. package/dist/utils/compare-class-names.js.map +1 -0
  79. package/dist/utils/deep-equal.d.ts +1 -1
  80. package/dist/utils/deep-equal.js +1 -1
  81. package/dist/utils/deep-equal.js.map +1 -1
  82. package/dist/utils/set-globals.d.ts +6 -8
  83. package/dist/utils/set-globals.js +22 -10
  84. package/dist/utils/set-globals.js.map +1 -1
  85. package/dist/utils/style-utils.d.ts +3 -2
  86. package/dist/utils/style-utils.js +4 -4
  87. package/dist/utils/style-utils.js.map +1 -1
  88. package/dist/utils/transform.d.ts +11 -19
  89. package/dist/utils/transform.js +13 -36
  90. package/dist/utils/transform.js.map +1 -1
  91. package/dist/utils/use-isomorphic-layout-effect.d.ts +1 -1
  92. package/dist/utils/use-isomorphic-layout-effect.js +2 -2
  93. package/dist/utils/use-isomorphic-layout-effect.js.map +1 -1
  94. package/package.json +42 -26
  95. package/src/components/attribution-control.ts +40 -16
  96. package/src/components/fullscreen-control.ts +40 -0
  97. package/src/components/geolocate-control.ts +45 -39
  98. package/src/components/layer.ts +37 -29
  99. package/src/components/logo-control.ts +44 -0
  100. package/src/components/map.tsx +86 -75
  101. package/src/components/marker.ts +141 -123
  102. package/src/components/navigation-control.ts +11 -12
  103. package/src/components/popup.ts +94 -97
  104. package/src/components/scale-control.ts +12 -14
  105. package/src/components/source.ts +58 -57
  106. package/src/components/terrain-control.ts +29 -0
  107. package/src/components/use-control.ts +21 -17
  108. package/src/components/use-map.tsx +26 -24
  109. package/src/exports-maplibre-gl.ts +37 -0
  110. package/src/index.ts +3 -2
  111. package/src/maplibre/create-ref.ts +70 -0
  112. package/src/maplibre/maplibre.ts +624 -0
  113. package/src/styles.d.ts +4 -0
  114. package/src/types/common.ts +12 -72
  115. package/src/types/events.ts +102 -42
  116. package/src/types/internal.ts +26 -0
  117. package/src/types/lib.ts +65 -260
  118. package/src/types/style-spec.ts +34 -0
  119. package/src/utils/apply-react-style.ts +7 -3
  120. package/src/utils/compare-class-names.ts +29 -0
  121. package/src/utils/deep-equal.ts +2 -2
  122. package/src/utils/set-globals.ts +22 -28
  123. package/src/utils/style-utils.ts +18 -9
  124. package/src/utils/transform.ts +32 -60
  125. package/src/utils/use-isomorphic-layout-effect.ts +3 -2
  126. package/bkoi-gl/package.json +0 -6
  127. package/dist/exports-bkoi-gl.cjs +0 -1512
  128. package/dist/exports-bkoi-gl.d.ts +0 -89
  129. package/dist/exports-bkoi-gl.js +0 -36
  130. package/dist/exports-bkoi-gl.js.map +0 -1
  131. package/dist/exports-mapbox.d.ts +0 -139
  132. package/dist/exports-mapbox.js +0 -36
  133. package/dist/exports-mapbox.js.map +0 -1
  134. package/dist/mapbox/create-ref.js +0 -64
  135. package/dist/mapbox/create-ref.js.map +0 -1
  136. package/dist/mapbox/mapbox.d.ts +0 -81
  137. package/dist/mapbox/mapbox.js +0 -476
  138. package/dist/mapbox/mapbox.js.map +0 -1
  139. package/dist/types/events-bkoi-gl.d.ts +0 -49
  140. package/dist/types/events-bkoi-gl.js +0 -2
  141. package/dist/types/events-bkoi-gl.js.map +0 -1
  142. package/dist/types/events-mapbox.d.ts +0 -49
  143. package/dist/types/events-mapbox.js +0 -2
  144. package/dist/types/events-mapbox.js.map +0 -1
  145. package/dist/types/index.d.ts +0 -70
  146. package/dist/types/index.js +0 -5
  147. package/dist/types/index.js.map +0 -1
  148. package/dist/types/public.d.ts +0 -2
  149. package/dist/types/public.js +0 -2
  150. package/dist/types/public.js.map +0 -1
  151. package/dist/types/style-spec-bkoi-gl.d.ts +0 -9
  152. package/dist/types/style-spec-bkoi-gl.js +0 -2
  153. package/dist/types/style-spec-bkoi-gl.js.map +0 -1
  154. package/dist/types/style-spec-mapbox.d.ts +0 -7
  155. package/dist/types/style-spec-mapbox.js +0 -2
  156. package/dist/types/style-spec-mapbox.js.map +0 -1
  157. package/src/components/fullscreen-control.tsx +0 -37
  158. package/src/exports-bkoi-gl.ts +0 -156
  159. package/src/exports-mapbox.ts +0 -159
  160. package/src/mapbox/create-ref.ts +0 -118
  161. package/src/mapbox/mapbox.ts +0 -742
  162. package/src/types/events-bkoi-gl.ts +0 -78
  163. package/src/types/events-mapbox.ts +0 -76
  164. package/src/types/index.ts +0 -93
  165. package/src/types/public.ts +0 -9
  166. package/src/types/style-spec-bkoi-gl.ts +0 -81
  167. 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: () => AttributionControl2,
50
- FullscreenControl: () => FullscreenControl2,
51
- GeolocateControl: () => GeolocateControl2,
52
- Layer: () => Layer2,
53
- Map: () => Map2,
49
+ AttributionControl: () => AttributionControl,
50
+ FullscreenControl: () => FullscreenControl,
51
+ GeolocateControl: () => GeolocateControl,
52
+ Layer: () => Layer,
53
+ LogoControl: () => LogoControl,
54
+ Map: () => Map,
54
55
  MapProvider: () => MapProvider,
55
- Marker: () => Marker2,
56
- NavigationControl: () => NavigationControl2,
57
- Popup: () => Popup2,
58
- ScaleControl: () => ScaleControl2,
59
- Source: () => Source2,
60
- default: () => exports_mapbox_default,
61
- useControl: () => use_control_default,
62
- useMap: () => useMap2
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 import_react3 = require("react");
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
- let changed = false;
198
- if ("zoom" in v) {
199
- const zoom = tr.zoom;
200
- tr.zoom = v.zoom;
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 ("bearing" in v) {
204
- const bearing = tr.bearing;
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 ("pitch" in v) {
209
- const pitch = tr.pitch;
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.padding && !tr.isPaddingEqual(v.padding)) {
214
- changed = true;
215
- tr.padding = v.padding;
192
+ if ("pitch" in v && v.pitch !== tr.pitch) {
193
+ changes.pitch = v.pitch;
216
194
  }
217
- if ("longitude" in v && "latitude" in v) {
218
- const center = tr.center;
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 changed;
198
+ return changes;
223
199
  }
224
200
 
225
201
  // src/utils/style-utils.ts
226
- var refProps = ["type", "source", "source-layer", "minzoom", "maxzoom", "filter", "layout"];
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/mapbox/mapbox.ts
266
- var DEFAULT_STYLE = { version: 8, sources: {}, layers: [] };
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 _Mapbox = class {
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._deferredEvents = {
343
- move: false,
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, true);
381
+ const viewStateChanged = this._updateViewState(props);
399
382
  this._updateStyle(props, oldProps);
400
- this._updateStyleComponents(props, oldProps);
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 = _Mapbox.savedMaps.pop();
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), { duration: 0 }));
411
+ map.fitBounds(initialViewState.bounds, __spreadProps(__spreadValues({}, initialViewState.fitBoundsOptions), {
412
+ duration: 0
413
+ }));
429
414
  } else {
430
- that._updateViewState(initialViewState, false);
415
+ that._updateViewState(initialViewState);
431
416
  }
432
417
  }
433
418
  if (map.isStyleLoaded()) {
434
419
  map.fire("load");
435
420
  } else {
436
- map.once("styledata", () => map.fire("load"));
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._createShadowTransform(map);
472
- const renderMap = map._render;
473
- map._render = (arg) => {
474
- this._inRender = true;
475
- renderMap.call(map, arg);
476
- this._inRender = false;
477
- };
478
- const runRenderTaskQueue = map._renderTaskQueue.run;
479
- map._renderTaskQueue.run = (arg) => {
480
- runRenderTaskQueue.call(map._renderTaskQueue, arg);
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);
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("styledata", () => {
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
- _Mapbox.savedMaps.push(this);
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 (!this._inRender && map.style) {
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, triggerEvents) {
555
- if (this._internalUpdate) {
556
- return false;
557
- }
525
+ _updateViewState(nextProps) {
558
526
  const map = this._map;
559
- const tr = this._renderTransform;
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(map.transform, nextProps);
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 changed;
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
- @param {object} nextProps
622
- @param {object} currProps
623
- @returns {bool} true if anything is changed
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(nextProps, currProps) {
578
+ _updateStyleComponents({
579
+ light,
580
+ projection,
581
+ sky,
582
+ terrain
583
+ }) {
584
+ var _a, _b;
626
585
  const map = this._map;
627
- let changed = false;
628
- if (map.isStyleLoaded()) {
629
- if ("light" in nextProps && map.setLight && !deepEqual(nextProps.light, currProps.light)) {
630
- changed = true;
631
- map.setLight(nextProps.light);
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 ("fog" in nextProps && map.setFog && !deepEqual(nextProps.fog, currProps.fog)) {
634
- changed = true;
635
- map.setFog(nextProps.fog);
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 ("terrain" in nextProps && map.setTerrain && !deepEqual(nextProps.terrain, currProps.terrain)) {
638
- if (!nextProps.terrain || map.getSource(nextProps.terrain.source)) {
639
- changed = true;
640
- map.setTerrain(nextProps.terrain);
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 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
- }
659
+ var Maplibre = _Maplibre;
660
+ Maplibre.savedMaps = [];
764
661
 
765
- // src/mapbox/create-ref.ts
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
- var globalSettings = [
860
- "baseApiUrl",
861
- "maxParallelImageRequests",
862
- "workerClass",
863
- "workerCount",
864
- "workerUrl"
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
- true
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 Map(props, ref, defaultLib) {
891
- const mountedMapsContext = (0, import_react3.useContext)(MountedMapsContext);
892
- const [mapInstance, setMapInstance] = (0, import_react3.useState)(null);
893
- const containerRef = (0, import_react3.useRef)();
894
- const { current: contextValue } = (0, import_react3.useRef)({ mapLib: null, map: null });
895
- (0, import_react3.useEffect)(() => {
896
- const mapLib2 = props.mapLib;
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 mapbox;
899
- Promise.resolve(mapLib2 || defaultLib).then((module2) => {
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 (!mapboxgl.supported || mapboxgl.supported(props)) {
912
- if (props.reuseMaps) {
913
- mapbox = Mapbox.reuse(props, containerRef.current);
914
- }
915
- if (!mapbox) {
916
- mapbox = new Mapbox(mapboxgl.Map, props, containerRef.current);
917
- }
918
- contextValue.map = createRef(mapbox);
919
- contextValue.mapLib = mapboxgl;
920
- setMapInstance(mapbox);
921
- mountedMapsContext == null ? void 0 : mountedMapsContext.onMapMount(contextValue.map, props.id);
922
- } else {
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 (mapbox) {
891
+ if (maplibre) {
941
892
  mountedMapsContext == null ? void 0 : mountedMapsContext.onMapUnmount(props.id);
942
893
  if (props.reuseMaps) {
943
- mapbox.recycle();
894
+ maplibre.recycle();
944
895
  } else {
945
- mapbox.destroy();
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, import_react3.useImperativeHandle)(ref, () => contextValue.map, [mapInstance]);
956
- const style = (0, import_react3.useMemo)(
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 import_react4 = require("react");
925
+ var import_react7 = require("react");
974
926
 
975
- // src/utils/apply-react-style.ts
976
- var unitlessNumber = /box|flex|grid|column|lineHeight|fontWeight|opacity|order|tabSize|zIndex/;
977
- function applyReactStyle(element, styles) {
978
- if (!element || !styles) {
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 style = element.style;
982
- for (const key in styles) {
983
- const value = styles[key];
984
- if (Number.isFinite(value) && !unitlessNumber.test(key)) {
985
- style[key] = `${value}px`;
986
- } else {
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
- // src/components/marker.ts
993
- function Marker(props, ref) {
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 (0, import_react_dom.createPortal)(props.children, marker.getElement());
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
- function Popup(props, ref) {
1090
- const { map, mapLib: mapLib2 } = (0, import_react5.useContext)(MapContext);
1091
- const container = (0, import_react5.useMemo)(() => {
1092
- return document.createElement("div");
1093
- }, []);
1094
- const thisRef = (0, import_react5.useRef)({ props });
1095
- thisRef.current.props = props;
1096
- const popup = (0, import_react5.useMemo)(() => {
1097
- const options = __spreadValues({}, props);
1098
- const pp = new mapLib2.Popup(options);
1099
- pp.setLngLat([props.longitude, props.latitude]);
1100
- pp.once("open", (e) => {
1101
- var _a, _b;
1102
- (_b = (_a = thisRef.current.props).onOpen) == null ? void 0 : _b.call(_a, e);
1103
- });
1104
- return pp;
1105
- }, []);
1106
- (0, import_react5.useEffect)(() => {
1107
- const onClose = (e) => {
1108
- var _a, _b;
1109
- (_b = (_a = thisRef.current.props).onClose) == null ? void 0 : _b.call(_a, e);
1110
- };
1111
- popup.on("close", onClose);
1112
- popup.setDOMContent(container).addTo(map.getMap());
1113
- return () => {
1114
- popup.off("close", onClose);
1115
- if (popup.isOpen()) {
1116
- popup.remove();
1117
- }
1118
- };
1119
- }, []);
1120
- (0, import_react5.useEffect)(() => {
1121
- applyReactStyle(popup.getElement(), props.style);
1122
- }, [props.style]);
1123
- (0, import_react5.useImperativeHandle)(ref, () => popup, []);
1124
- if (popup.isOpen()) {
1125
- if (popup.getLngLat().lng !== props.longitude || popup.getLngLat().lat !== props.latitude) {
1126
- popup.setLngLat([props.longitude, props.latitude]);
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 (props.offset && !deepEqual(popup.options.offset, props.offset)) {
1129
- popup.setOffset(props.offset);
1021
+ if (offset && !arePointsEqual(marker.getOffset(), offset)) {
1022
+ marker.setOffset(offset);
1130
1023
  }
1131
- if (popup.options.anchor !== props.anchor || popup.options.maxWidth !== props.maxWidth) {
1132
- popup.options.anchor = props.anchor;
1133
- popup.setMaxWidth(props.maxWidth);
1024
+ if (marker.isDraggable() !== draggable) {
1025
+ marker.setDraggable(draggable);
1134
1026
  }
1135
- if (popup.options.className !== props.className) {
1136
- const prevClassList = getClassList(popup.options.className);
1137
- const nextClassList = getClassList(props.className);
1138
- for (const c of prevClassList) {
1139
- if (!nextClassList.has(c)) {
1140
- popup.removeClassName(c);
1141
- }
1142
- }
1143
- for (const c of nextClassList) {
1144
- if (!prevClassList.has(c)) {
1145
- popup.addClassName(c);
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
- return (0, import_react_dom2.createPortal)(props.children, container);
1152
- }
1153
- var popup_default = (0, import_react5.memo)((0, import_react5.forwardRef)(Popup));
1048
+ thisRef.current.props = props;
1049
+ return (0, import_react_dom.createPortal)(props.children, marker.getElement());
1050
+ })
1051
+ );
1154
1052
 
1155
- // src/components/attribution-control.ts
1156
- var import_react7 = require("react");
1157
-
1158
- // src/components/use-control.ts
1159
- var import_react6 = require("react");
1160
- function useControl(onCreate, arg1, arg2, arg3) {
1161
- const context = (0, import_react6.useContext)(MapContext);
1162
- const ctrl = (0, import_react6.useMemo)(() => onCreate(context), []);
1163
- (0, import_react6.useEffect)(() => {
1164
- const opts = arg3 || arg2 || arg1;
1165
- const onAdd = typeof arg1 === "function" && typeof arg2 === "function" ? arg1 : null;
1166
- const onRemove = typeof arg2 === "function" ? arg2 : typeof arg1 === "function" ? arg1 : null;
1167
- const { map } = context;
1168
- if (!map.hasControl(ctrl)) {
1169
- map.addControl(ctrl, opts == null ? void 0 : opts.position);
1170
- if (onAdd) {
1171
- onAdd(context);
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
- return () => {
1175
- if (onRemove) {
1176
- onRemove(context);
1096
+ if (props.offset && !deepEqual(oldProps.offset, props.offset)) {
1097
+ popup.setOffset(props.offset);
1177
1098
  }
1178
- if (map.hasControl(ctrl)) {
1179
- map.removeControl(ctrl);
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
- return ctrl;
1184
- }
1185
- var use_control_default = useControl;
1186
-
1187
- // src/components/attribution-control.ts
1188
- function AttributionControl(props) {
1189
- const ctrl = use_control_default(
1190
- ({ mapLib: mapLib2 }) => new mapLib2.AttributionControl(props),
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
- (0, import_react7.useEffect)(() => {
1196
- applyReactStyle(ctrl._container, props.style);
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.tsx
1203
- var import_react8 = require("react");
1204
- function FullscreenControl(props) {
1205
- const ctrl = use_control_default(
1206
- ({ mapLib: mapLib2 }) => new mapLib2.FullscreenControl({
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, import_react8.useEffect)(() => {
1127
+ (0, import_react9.useEffect)(() => {
1212
1128
  applyReactStyle(ctrl._controlContainer, props.style);
1213
1129
  }, [props.style]);
1214
1130
  return null;
1215
1131
  }
1216
- var fullscreen_control_default = (0, import_react8.memo)(FullscreenControl);
1132
+ var FullscreenControl = (0, import_react9.memo)(_FullscreenControl);
1217
1133
 
1218
1134
  // src/components/geolocate-control.ts
1219
- var import_react9 = require("react");
1220
- function GeolocateControl(props, ref) {
1221
- const thisRef = (0, import_react9.useRef)({ props });
1222
- const ctrl = use_control_default(
1223
- ({ mapLib: mapLib2 }) => {
1224
- const gc = new mapLib2.GeolocateControl(props);
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 = (args) => {
1142
+ gc._setupUI = () => {
1227
1143
  if (!gc._container.hasChildNodes()) {
1228
- setupUI(args);
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, import_react9.useImperativeHandle)(ref, () => ctrl, []);
1257
- (0, import_react9.useEffect)(() => {
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 geolocate_control_default = (0, import_react9.memo)((0, import_react9.forwardRef)(GeolocateControl));
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 import_react10 = require("react");
1266
- function NavigationControl(props) {
1267
- const ctrl = use_control_default(({ mapLib: mapLib2 }) => new mapLib2.NavigationControl(props), {
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, import_react10.useEffect)(() => {
1188
+ (0, import_react11.useEffect)(() => {
1271
1189
  applyReactStyle(ctrl._container, props.style);
1272
1190
  }, [props.style]);
1273
1191
  return null;
1274
1192
  }
1275
- var navigation_control_default = (0, import_react10.memo)(NavigationControl);
1193
+ var NavigationControl = (0, import_react11.memo)(_NavigationControl);
1276
1194
 
1277
1195
  // src/components/scale-control.ts
1278
- var import_react11 = require("react");
1279
- function ScaleControl(props) {
1280
- const ctrl = use_control_default(({ mapLib: mapLib2 }) => new mapLib2.ScaleControl(props), {
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, import_react11.useRef)(props);
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, import_react11.useEffect)(() => {
1211
+ (0, import_react12.useEffect)(() => {
1294
1212
  applyReactStyle(ctrl._container, style);
1295
1213
  }, [style]);
1296
1214
  return null;
1297
1215
  }
1298
- var scale_control_default = (0, import_react11.memo)(ScaleControl);
1216
+ var ScaleControl = (0, import_react12.memo)(_ScaleControl);
1299
1217
 
1300
- // src/components/layer.ts
1301
- var import_react12 = require("react");
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 if ("setCoordinates" in source && changedKeyCount === 1 && changedKey === "coordinates") {
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, import_react13.useContext)(MapContext).map.getMap();
1453
- const propsRef = (0, import_react13.useRef)(props);
1454
- const [, setStyleLoaded] = (0, import_react13.useState)(0);
1455
- const id = (0, import_react13.useMemo)(() => props.id || `jsx-source-${sourceCounter++}`, []);
1456
- (0, import_react13.useEffect)(() => {
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/exports-mapbox.ts
1496
- function useMap2() {
1497
- return useMap();
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
- var mapLib = import("mapbox-gl");
1500
- var Map2 = (() => {
1501
- return React5.forwardRef(function Map3(props, ref) {
1502
- return Map(props, ref, mapLib);
1503
- });
1504
- })();
1505
- var Marker2 = marker_default;
1506
- var Popup2 = popup_default;
1507
- var AttributionControl2 = attribution_control_default;
1508
- var FullscreenControl2 = fullscreen_control_default;
1509
- var NavigationControl2 = navigation_control_default;
1510
- var GeolocateControl2 = geolocate_control_default;
1511
- var ScaleControl2 = scale_control_default;
1512
- var Layer2 = layer_default;
1513
- var Source2 = source_default;
1514
- var exports_mapbox_default = Map2;
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;