react-bkoi-gl 1.0.6 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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
@@ -1,1512 +0,0 @@
1
- var __create = Object.create;
2
- var __defProp = Object.defineProperty;
3
- var __defProps = Object.defineProperties;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
6
- var __getOwnPropNames = Object.getOwnPropertyNames;
7
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
8
- var __getProtoOf = Object.getPrototypeOf;
9
- 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
- var __export = (target, all) => {
25
- for (var name in all)
26
- __defProp(target, name, { get: all[name], enumerable: true });
27
- };
28
- var __copyProps = (to, from, except, desc) => {
29
- if (from && typeof from === "object" || typeof from === "function") {
30
- for (let key of __getOwnPropNames(from))
31
- if (!__hasOwnProp.call(to, key) && key !== except)
32
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
33
- }
34
- return to;
35
- };
36
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
37
- // If the importer is in node compatibility mode or this is not an ESM
38
- // file that has been converted to a CommonJS file using a Babel-
39
- // compatible transform (i.e. "__esModule" has not been set), then set
40
- // "default" to the CommonJS "module.exports" for node compatibility.
41
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
42
- mod
43
- ));
44
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
45
-
46
- // src/exports-bkoi-gl.ts
47
- var exports_bkoi_gl_exports = {};
48
- __export(exports_bkoi_gl_exports, {
49
- AttributionControl: () => AttributionControl2,
50
- FullscreenControl: () => FullscreenControl2,
51
- GeolocateControl: () => GeolocateControl2,
52
- Layer: () => Layer2,
53
- Map: () => Map2,
54
- MapProvider: () => MapProvider,
55
- Marker: () => Marker2,
56
- NavigationControl: () => NavigationControl2,
57
- Popup: () => Popup2,
58
- ScaleControl: () => ScaleControl2,
59
- Source: () => Source2,
60
- default: () => exports_bkoi_gl_default,
61
- useControl: () => use_control_default,
62
- useMap: () => useMap2
63
- });
64
- module.exports = __toCommonJS(exports_bkoi_gl_exports);
65
- var React5 = __toESM(require("react"), 1);
66
-
67
- // src/components/map.tsx
68
- var React2 = __toESM(require("react"), 1);
69
- var import_react3 = require("react");
70
-
71
- // src/components/use-map.tsx
72
- var React = __toESM(require("react"), 1);
73
- var import_react = require("react");
74
- var MountedMapsContext = React.createContext(null);
75
- var MapProvider = (props) => {
76
- const [maps, setMaps] = (0, import_react.useState)({});
77
- const onMapMount = (0, import_react.useCallback)((map, id = "default") => {
78
- setMaps((currMaps) => {
79
- if (id === "current") {
80
- throw new Error("'current' cannot be used as map id");
81
- }
82
- if (currMaps[id]) {
83
- throw new Error(`Multiple maps with the same id: ${id}`);
84
- }
85
- return __spreadProps(__spreadValues({}, currMaps), { [id]: map });
86
- });
87
- }, []);
88
- const onMapUnmount = (0, import_react.useCallback)((id = "default") => {
89
- setMaps((currMaps) => {
90
- if (currMaps[id]) {
91
- const nextMaps = __spreadValues({}, currMaps);
92
- delete nextMaps[id];
93
- return nextMaps;
94
- }
95
- return currMaps;
96
- });
97
- }, []);
98
- return /* @__PURE__ */ React.createElement(
99
- MountedMapsContext.Provider,
100
- {
101
- value: {
102
- maps,
103
- onMapMount,
104
- onMapUnmount
105
- }
106
- },
107
- props.children
108
- );
109
- };
110
- function useMap() {
111
- var _a;
112
- const maps = (_a = (0, import_react.useContext)(MountedMapsContext)) == null ? void 0 : _a.maps;
113
- const currentMap = (0, import_react.useContext)(MapContext);
114
- const mapsWithCurrent = (0, import_react.useMemo)(() => {
115
- return __spreadProps(__spreadValues({}, maps), { current: currentMap == null ? void 0 : currentMap.map });
116
- }, [maps, currentMap]);
117
- return mapsWithCurrent;
118
- }
119
-
120
- // src/utils/deep-equal.ts
121
- function arePointsEqual(a, b) {
122
- const ax = Array.isArray(a) ? a[0] : a ? a.x : 0;
123
- const ay = Array.isArray(a) ? a[1] : a ? a.y : 0;
124
- const bx = Array.isArray(b) ? b[0] : b ? b.x : 0;
125
- const by = Array.isArray(b) ? b[1] : b ? b.y : 0;
126
- return ax === bx && ay === by;
127
- }
128
- function deepEqual(a, b) {
129
- if (a === b) {
130
- return true;
131
- }
132
- if (!a || !b) {
133
- return false;
134
- }
135
- if (Array.isArray(a)) {
136
- if (!Array.isArray(b) || a.length !== b.length) {
137
- return false;
138
- }
139
- for (let i = 0; i < a.length; i++) {
140
- if (!deepEqual(a[i], b[i])) {
141
- return false;
142
- }
143
- }
144
- return true;
145
- } else if (Array.isArray(b)) {
146
- return false;
147
- }
148
- if (typeof a === "object" && typeof b === "object") {
149
- const aKeys = Object.keys(a);
150
- const bKeys = Object.keys(b);
151
- if (aKeys.length !== bKeys.length) {
152
- return false;
153
- }
154
- for (const key of aKeys) {
155
- if (!b.hasOwnProperty(key)) {
156
- return false;
157
- }
158
- if (!deepEqual(a[key], b[key])) {
159
- return false;
160
- }
161
- }
162
- return true;
163
- }
164
- return false;
165
- }
166
-
167
- // src/utils/transform.ts
168
- function cloneTransform(tr) {
169
- const newTransform = tr.clone();
170
- newTransform.pixelsToGLUnits = tr.pixelsToGLUnits;
171
- return newTransform;
172
- }
173
- function syncProjection(src, dest) {
174
- if (!src.getProjection) {
175
- return;
176
- }
177
- const srcProjection = src.getProjection();
178
- const destProjection = dest.getProjection();
179
- if (!deepEqual(srcProjection, destProjection)) {
180
- dest.setProjection(srcProjection);
181
- }
182
- }
183
- function transformToViewState(tr) {
184
- return {
185
- longitude: tr.center.lng,
186
- latitude: tr.center.lat,
187
- zoom: tr.zoom,
188
- pitch: tr.pitch,
189
- bearing: tr.bearing,
190
- padding: tr.padding
191
- };
192
- }
193
- function applyViewStateToTransform(tr, props) {
194
- const v = props.viewState || props;
195
- let changed = false;
196
- if ("zoom" in v) {
197
- const zoom = tr.zoom;
198
- tr.zoom = v.zoom;
199
- changed = changed || zoom !== tr.zoom;
200
- }
201
- if ("bearing" in v) {
202
- const bearing = tr.bearing;
203
- tr.bearing = v.bearing;
204
- changed = changed || bearing !== tr.bearing;
205
- }
206
- if ("pitch" in v) {
207
- const pitch = tr.pitch;
208
- tr.pitch = v.pitch;
209
- changed = changed || pitch !== tr.pitch;
210
- }
211
- if (v.padding && !tr.isPaddingEqual(v.padding)) {
212
- changed = true;
213
- tr.padding = v.padding;
214
- }
215
- if ("longitude" in v && "latitude" in v) {
216
- const center = tr.center;
217
- tr.center = new center.constructor(v.longitude, v.latitude);
218
- changed = changed || center !== tr.center;
219
- }
220
- return changed;
221
- }
222
-
223
- // src/utils/style-utils.ts
224
- var refProps = ["type", "source", "source-layer", "minzoom", "maxzoom", "filter", "layout"];
225
- function normalizeStyle(style) {
226
- if (!style) {
227
- return null;
228
- }
229
- if (typeof style === "string") {
230
- return style;
231
- }
232
- if ("toJS" in style) {
233
- style = style.toJS();
234
- }
235
- if (!style.layers) {
236
- return style;
237
- }
238
- const layerIndex = {};
239
- for (const layer of style.layers) {
240
- layerIndex[layer.id] = layer;
241
- }
242
- const layers = style.layers.map((layer) => {
243
- let normalizedLayer = null;
244
- if ("interactive" in layer) {
245
- normalizedLayer = Object.assign({}, layer);
246
- delete normalizedLayer.interactive;
247
- }
248
- const layerRef = layerIndex[layer.ref];
249
- if (layerRef) {
250
- normalizedLayer = normalizedLayer || Object.assign({}, layer);
251
- delete normalizedLayer.ref;
252
- for (const propName of refProps) {
253
- if (propName in layerRef) {
254
- normalizedLayer[propName] = layerRef[propName];
255
- }
256
- }
257
- }
258
- return normalizedLayer || layer;
259
- });
260
- return __spreadProps(__spreadValues({}, style), { layers });
261
- }
262
-
263
- // src/mapbox/mapbox.ts
264
- var DEFAULT_STYLE = { version: 8, sources: {}, layers: [] };
265
- var pointerEvents = {
266
- mousedown: "onMouseDown",
267
- mouseup: "onMouseUp",
268
- mouseover: "onMouseOver",
269
- mousemove: "onMouseMove",
270
- click: "onClick",
271
- dblclick: "onDblClick",
272
- mouseenter: "onMouseEnter",
273
- mouseleave: "onMouseLeave",
274
- mouseout: "onMouseOut",
275
- contextmenu: "onContextMenu",
276
- touchstart: "onTouchStart",
277
- touchend: "onTouchEnd",
278
- touchmove: "onTouchMove",
279
- touchcancel: "onTouchCancel"
280
- };
281
- var cameraEvents = {
282
- movestart: "onMoveStart",
283
- move: "onMove",
284
- moveend: "onMoveEnd",
285
- dragstart: "onDragStart",
286
- drag: "onDrag",
287
- dragend: "onDragEnd",
288
- zoomstart: "onZoomStart",
289
- zoom: "onZoom",
290
- zoomend: "onZoomEnd",
291
- rotatestart: "onRotateStart",
292
- rotate: "onRotate",
293
- rotateend: "onRotateEnd",
294
- pitchstart: "onPitchStart",
295
- pitch: "onPitch",
296
- pitchend: "onPitchEnd"
297
- };
298
- var otherEvents = {
299
- wheel: "onWheel",
300
- boxzoomstart: "onBoxZoomStart",
301
- boxzoomend: "onBoxZoomEnd",
302
- boxzoomcancel: "onBoxZoomCancel",
303
- resize: "onResize",
304
- load: "onLoad",
305
- render: "onRender",
306
- idle: "onIdle",
307
- remove: "onRemove",
308
- data: "onData",
309
- styledata: "onStyleData",
310
- sourcedata: "onSourceData",
311
- error: "onError"
312
- };
313
- var settingNames = [
314
- "minZoom",
315
- "maxZoom",
316
- "minPitch",
317
- "maxPitch",
318
- "maxBounds",
319
- "projection",
320
- "renderWorldCopies"
321
- ];
322
- var handlerNames = [
323
- "scrollZoom",
324
- "boxZoom",
325
- "dragRotate",
326
- "dragPan",
327
- "keyboard",
328
- "doubleClickZoom",
329
- "touchZoomRotate",
330
- "touchPitch"
331
- ];
332
- var _Mapbox = class {
333
- constructor(MapClass, props, container) {
334
- // mapboxgl.Map instance
335
- this._map = null;
336
- // Internal states
337
- this._internalUpdate = false;
338
- this._inRender = false;
339
- this._hoveredFeatures = null;
340
- this._deferredEvents = {
341
- move: false,
342
- zoom: false,
343
- pitch: false,
344
- rotate: false
345
- };
346
- this._onEvent = (e) => {
347
- const cb = this.props[otherEvents[e.type]];
348
- if (cb) {
349
- cb(e);
350
- } else if (e.type === "error") {
351
- console.error(e.error);
352
- }
353
- };
354
- this._onPointerEvent = (e) => {
355
- if (e.type === "mousemove" || e.type === "mouseout") {
356
- this._updateHover(e);
357
- }
358
- const cb = this.props[pointerEvents[e.type]];
359
- if (cb) {
360
- if (this.props.interactiveLayerIds && e.type !== "mouseover" && e.type !== "mouseout") {
361
- e.features = this._hoveredFeatures || this._queryRenderedFeatures(e.point);
362
- }
363
- cb(e);
364
- delete e.features;
365
- }
366
- };
367
- this._onCameraEvent = (e) => {
368
- if (!this._internalUpdate) {
369
- const cb = this.props[cameraEvents[e.type]];
370
- if (cb) {
371
- cb(e);
372
- }
373
- }
374
- if (e.type in this._deferredEvents) {
375
- this._deferredEvents[e.type] = false;
376
- }
377
- };
378
- this._MapClass = MapClass;
379
- this.props = props;
380
- this._initialize(container);
381
- }
382
- get map() {
383
- return this._map;
384
- }
385
- get transform() {
386
- return this._renderTransform;
387
- }
388
- setProps(props) {
389
- const oldProps = this.props;
390
- this.props = props;
391
- const settingsChanged = this._updateSettings(props, oldProps);
392
- if (settingsChanged) {
393
- this._createShadowTransform(this._map);
394
- }
395
- const sizeChanged = this._updateSize(props);
396
- const viewStateChanged = this._updateViewState(props, true);
397
- this._updateStyle(props, oldProps);
398
- this._updateStyleComponents(props, oldProps);
399
- this._updateHandlers(props, oldProps);
400
- if (settingsChanged || sizeChanged || viewStateChanged && !this._map.isMoving()) {
401
- this.redraw();
402
- }
403
- }
404
- static reuse(props, container) {
405
- const that = _Mapbox.savedMaps.pop();
406
- if (!that) {
407
- return null;
408
- }
409
- const map = that.map;
410
- const oldContainer = map.getContainer();
411
- container.className = oldContainer.className;
412
- while (oldContainer.childNodes.length > 0) {
413
- container.appendChild(oldContainer.childNodes[0]);
414
- }
415
- map._container = container;
416
- const resizeObserver = map._resizeObserver;
417
- if (resizeObserver) {
418
- resizeObserver.disconnect();
419
- resizeObserver.observe(container);
420
- }
421
- that.setProps(__spreadProps(__spreadValues({}, props), { styleDiffing: false }));
422
- map.resize();
423
- const { initialViewState } = props;
424
- if (initialViewState) {
425
- if (initialViewState.bounds) {
426
- map.fitBounds(initialViewState.bounds, __spreadProps(__spreadValues({}, initialViewState.fitBoundsOptions), { duration: 0 }));
427
- } else {
428
- that._updateViewState(initialViewState, false);
429
- }
430
- }
431
- if (map.isStyleLoaded()) {
432
- map.fire("load");
433
- } else {
434
- map.once("styledata", () => map.fire("load"));
435
- }
436
- map._update();
437
- return that;
438
- }
439
- /* eslint-disable complexity,max-statements */
440
- _initialize(container) {
441
- const { props } = this;
442
- const { mapStyle = DEFAULT_STYLE } = props;
443
- const mapOptions = __spreadProps(__spreadValues(__spreadValues({}, props), props.initialViewState), {
444
- accessToken: props.mapboxAccessToken || getAccessTokenFromEnv() || null,
445
- container,
446
- style: normalizeStyle(mapStyle)
447
- });
448
- const viewState = mapOptions.initialViewState || mapOptions.viewState || mapOptions;
449
- Object.assign(mapOptions, {
450
- center: [viewState.longitude || 0, viewState.latitude || 0],
451
- zoom: viewState.zoom || 0,
452
- pitch: viewState.pitch || 0,
453
- bearing: viewState.bearing || 0
454
- });
455
- if (props.gl) {
456
- const getContext = HTMLCanvasElement.prototype.getContext;
457
- HTMLCanvasElement.prototype.getContext = () => {
458
- HTMLCanvasElement.prototype.getContext = getContext;
459
- return props.gl;
460
- };
461
- }
462
- const map = new this._MapClass(mapOptions);
463
- if (viewState.padding) {
464
- map.setPadding(viewState.padding);
465
- }
466
- if (props.cursor) {
467
- map.getCanvas().style.cursor = props.cursor;
468
- }
469
- this._createShadowTransform(map);
470
- const renderMap = map._render;
471
- map._render = (arg) => {
472
- this._inRender = true;
473
- renderMap.call(map, arg);
474
- this._inRender = false;
475
- };
476
- const runRenderTaskQueue = map._renderTaskQueue.run;
477
- map._renderTaskQueue.run = (arg) => {
478
- runRenderTaskQueue.call(map._renderTaskQueue, arg);
479
- this._onBeforeRepaint();
480
- };
481
- map.on("render", () => this._onAfterRepaint());
482
- const fireEvent = map.fire;
483
- map.fire = this._fireEvent.bind(this, fireEvent);
484
- map.on("resize", () => {
485
- this._renderTransform.resize(map.transform.width, map.transform.height);
486
- });
487
- map.on("styledata", () => {
488
- this._updateStyleComponents(this.props, {});
489
- syncProjection(map.transform, this._renderTransform);
490
- });
491
- map.on("sourcedata", () => this._updateStyleComponents(this.props, {}));
492
- for (const eventName in pointerEvents) {
493
- map.on(eventName, this._onPointerEvent);
494
- }
495
- for (const eventName in cameraEvents) {
496
- map.on(eventName, this._onCameraEvent);
497
- }
498
- for (const eventName in otherEvents) {
499
- map.on(eventName, this._onEvent);
500
- }
501
- this._map = map;
502
- }
503
- /* eslint-enable complexity,max-statements */
504
- recycle() {
505
- const container = this.map.getContainer();
506
- const children = container.querySelector("[mapboxgl-children]");
507
- children == null ? void 0 : children.remove();
508
- _Mapbox.savedMaps.push(this);
509
- }
510
- destroy() {
511
- this._map.remove();
512
- }
513
- // Force redraw the map now. Typically resize() and jumpTo() is reflected in the next
514
- // render cycle, which is managed by Mapbox's animation loop.
515
- // This removes the synchronization issue caused by requestAnimationFrame.
516
- redraw() {
517
- const map = this._map;
518
- if (!this._inRender && map.style) {
519
- if (map._frame) {
520
- map._frame.cancel();
521
- map._frame = null;
522
- }
523
- map._render();
524
- }
525
- }
526
- _createShadowTransform(map) {
527
- const renderTransform = cloneTransform(map.transform);
528
- map.painter.transform = renderTransform;
529
- this._renderTransform = renderTransform;
530
- }
531
- /* Trigger map resize if size is controlled
532
- @param {object} nextProps
533
- @returns {bool} true if size has changed
534
- */
535
- _updateSize(nextProps) {
536
- const { viewState } = nextProps;
537
- if (viewState) {
538
- const map = this._map;
539
- if (viewState.width !== map.transform.width || viewState.height !== map.transform.height) {
540
- map.resize();
541
- return true;
542
- }
543
- }
544
- return false;
545
- }
546
- // Adapted from map.jumpTo
547
- /* Update camera to match props
548
- @param {object} nextProps
549
- @param {bool} triggerEvents - should fire camera events
550
- @returns {bool} true if anything is changed
551
- */
552
- _updateViewState(nextProps, triggerEvents) {
553
- if (this._internalUpdate) {
554
- return false;
555
- }
556
- const map = this._map;
557
- const tr = this._renderTransform;
558
- const { zoom, pitch, bearing } = tr;
559
- const isMoving = map.isMoving();
560
- if (isMoving) {
561
- tr.cameraElevationReference = "sea";
562
- }
563
- const changed = applyViewStateToTransform(tr, __spreadValues(__spreadValues({}, transformToViewState(map.transform)), nextProps));
564
- if (isMoving) {
565
- tr.cameraElevationReference = "ground";
566
- }
567
- if (changed && triggerEvents) {
568
- const deferredEvents = this._deferredEvents;
569
- deferredEvents.move = true;
570
- deferredEvents.zoom || (deferredEvents.zoom = zoom !== tr.zoom);
571
- deferredEvents.rotate || (deferredEvents.rotate = bearing !== tr.bearing);
572
- deferredEvents.pitch || (deferredEvents.pitch = pitch !== tr.pitch);
573
- }
574
- if (!isMoving) {
575
- applyViewStateToTransform(map.transform, nextProps);
576
- }
577
- return changed;
578
- }
579
- /* Update camera constraints and projection settings to match props
580
- @param {object} nextProps
581
- @param {object} currProps
582
- @returns {bool} true if anything is changed
583
- */
584
- _updateSettings(nextProps, currProps) {
585
- const map = this._map;
586
- let changed = false;
587
- for (const propName of settingNames) {
588
- if (propName in nextProps && !deepEqual(nextProps[propName], currProps[propName])) {
589
- changed = true;
590
- const setter = map[`set${propName[0].toUpperCase()}${propName.slice(1)}`];
591
- setter == null ? void 0 : setter.call(map, nextProps[propName]);
592
- }
593
- }
594
- return changed;
595
- }
596
- /* Update map style to match props
597
- @param {object} nextProps
598
- @param {object} currProps
599
- @returns {bool} true if style is changed
600
- */
601
- _updateStyle(nextProps, currProps) {
602
- if (nextProps.cursor !== currProps.cursor) {
603
- this._map.getCanvas().style.cursor = nextProps.cursor || "";
604
- }
605
- if (nextProps.mapStyle !== currProps.mapStyle) {
606
- const { mapStyle = DEFAULT_STYLE, styleDiffing = true } = nextProps;
607
- const options = {
608
- diff: styleDiffing
609
- };
610
- if ("localIdeographFontFamily" in nextProps) {
611
- options.localIdeographFontFamily = nextProps.localIdeographFontFamily;
612
- }
613
- this._map.setStyle(normalizeStyle(mapStyle), options);
614
- return true;
615
- }
616
- return false;
617
- }
618
- /* Update fog, light and terrain to match props
619
- @param {object} nextProps
620
- @param {object} currProps
621
- @returns {bool} true if anything is changed
622
- */
623
- _updateStyleComponents(nextProps, currProps) {
624
- const map = this._map;
625
- let changed = false;
626
- if (map.isStyleLoaded()) {
627
- if ("light" in nextProps && map.setLight && !deepEqual(nextProps.light, currProps.light)) {
628
- changed = true;
629
- map.setLight(nextProps.light);
630
- }
631
- if ("fog" in nextProps && map.setFog && !deepEqual(nextProps.fog, currProps.fog)) {
632
- changed = true;
633
- map.setFog(nextProps.fog);
634
- }
635
- if ("terrain" in nextProps && map.setTerrain && !deepEqual(nextProps.terrain, currProps.terrain)) {
636
- if (!nextProps.terrain || map.getSource(nextProps.terrain.source)) {
637
- changed = true;
638
- map.setTerrain(nextProps.terrain);
639
- }
640
- }
641
- }
642
- return changed;
643
- }
644
- /* Update interaction handlers to match props
645
- @param {object} nextProps
646
- @param {object} currProps
647
- @returns {bool} true if anything is changed
648
- */
649
- _updateHandlers(nextProps, currProps) {
650
- var _a, _b;
651
- const map = this._map;
652
- let changed = false;
653
- for (const propName of handlerNames) {
654
- const newValue = (_a = nextProps[propName]) != null ? _a : true;
655
- const oldValue = (_b = currProps[propName]) != null ? _b : true;
656
- if (!deepEqual(newValue, oldValue)) {
657
- changed = true;
658
- if (newValue) {
659
- map[propName].enable(newValue);
660
- } else {
661
- map[propName].disable();
662
- }
663
- }
664
- }
665
- return changed;
666
- }
667
- _queryRenderedFeatures(point) {
668
- const map = this._map;
669
- const tr = map.transform;
670
- const { interactiveLayerIds = [] } = this.props;
671
- try {
672
- map.transform = this._renderTransform;
673
- return map.queryRenderedFeatures(point, {
674
- layers: interactiveLayerIds.filter(map.getLayer.bind(map))
675
- });
676
- } catch (e) {
677
- return [];
678
- } finally {
679
- map.transform = tr;
680
- }
681
- }
682
- _updateHover(e) {
683
- var _a;
684
- const { props } = this;
685
- const shouldTrackHoveredFeatures = props.interactiveLayerIds && (props.onMouseMove || props.onMouseEnter || props.onMouseLeave);
686
- if (shouldTrackHoveredFeatures) {
687
- const eventType = e.type;
688
- const wasHovering = ((_a = this._hoveredFeatures) == null ? void 0 : _a.length) > 0;
689
- const features = this._queryRenderedFeatures(e.point);
690
- const isHovering = features.length > 0;
691
- if (!isHovering && wasHovering) {
692
- e.type = "mouseleave";
693
- this._onPointerEvent(e);
694
- }
695
- this._hoveredFeatures = features;
696
- if (isHovering && !wasHovering) {
697
- e.type = "mouseenter";
698
- this._onPointerEvent(e);
699
- }
700
- e.type = eventType;
701
- } else {
702
- this._hoveredFeatures = null;
703
- }
704
- }
705
- _fireEvent(baseFire, event, properties) {
706
- const map = this._map;
707
- const tr = map.transform;
708
- const eventType = typeof event === "string" ? event : event.type;
709
- if (eventType === "move") {
710
- this._updateViewState(this.props, false);
711
- }
712
- if (eventType in cameraEvents) {
713
- if (typeof event === "object") {
714
- event.viewState = transformToViewState(tr);
715
- }
716
- if (this._map.isMoving()) {
717
- map.transform = this._renderTransform;
718
- baseFire.call(map, event, properties);
719
- map.transform = tr;
720
- return map;
721
- }
722
- }
723
- baseFire.call(map, event, properties);
724
- return map;
725
- }
726
- // All camera manipulations are complete, ready to repaint
727
- _onBeforeRepaint() {
728
- const map = this._map;
729
- this._internalUpdate = true;
730
- for (const eventType in this._deferredEvents) {
731
- if (this._deferredEvents[eventType]) {
732
- map.fire(eventType);
733
- }
734
- }
735
- this._internalUpdate = false;
736
- const tr = this._map.transform;
737
- map.transform = this._renderTransform;
738
- this._onAfterRepaint = () => {
739
- syncProjection(this._renderTransform, tr);
740
- map.transform = tr;
741
- };
742
- }
743
- };
744
- var Mapbox = _Mapbox;
745
- Mapbox.savedMaps = [];
746
- function getAccessTokenFromEnv() {
747
- let accessToken = null;
748
- if (typeof location !== "undefined") {
749
- const match = /access_token=([^&\/]*)/.exec(location.search);
750
- accessToken = match && match[1];
751
- }
752
- try {
753
- accessToken = accessToken || process.env.MapboxAccessToken;
754
- } catch (e) {
755
- }
756
- try {
757
- accessToken = accessToken || process.env.REACT_APP_MAPBOX_ACCESS_TOKEN;
758
- } catch (e) {
759
- }
760
- return accessToken;
761
- }
762
-
763
- // src/mapbox/create-ref.ts
764
- var skipMethods = [
765
- "setMaxBounds",
766
- "setMinZoom",
767
- "setMaxZoom",
768
- "setMinPitch",
769
- "setMaxPitch",
770
- "setRenderWorldCopies",
771
- "setProjection",
772
- "setStyle",
773
- "addSource",
774
- "removeSource",
775
- "addLayer",
776
- "removeLayer",
777
- "setLayerZoomRange",
778
- "setFilter",
779
- "setPaintProperty",
780
- "setLayoutProperty",
781
- "setLight",
782
- "setTerrain",
783
- "setFog",
784
- "remove"
785
- ];
786
- function createRef(mapInstance) {
787
- if (!mapInstance) {
788
- return null;
789
- }
790
- const map = mapInstance.map;
791
- const result = {
792
- getMap: () => map,
793
- // Overwrite getters to use our shadow transform
794
- getCenter: () => mapInstance.transform.center,
795
- getZoom: () => mapInstance.transform.zoom,
796
- getBearing: () => mapInstance.transform.bearing,
797
- getPitch: () => mapInstance.transform.pitch,
798
- getPadding: () => mapInstance.transform.padding,
799
- getBounds: () => mapInstance.transform.getBounds(),
800
- project: (lnglat) => {
801
- const tr = map.transform;
802
- map.transform = mapInstance.transform;
803
- const result2 = map.project(lnglat);
804
- map.transform = tr;
805
- return result2;
806
- },
807
- unproject: (point) => {
808
- const tr = map.transform;
809
- map.transform = mapInstance.transform;
810
- const result2 = map.unproject(point);
811
- map.transform = tr;
812
- return result2;
813
- },
814
- // options diverge between mapbox and maplibre
815
- queryTerrainElevation: (lnglat, options) => {
816
- const tr = map.transform;
817
- map.transform = mapInstance.transform;
818
- const result2 = map.queryTerrainElevation(lnglat, options);
819
- map.transform = tr;
820
- return result2;
821
- },
822
- queryRenderedFeatures: (geometry, options) => {
823
- const tr = map.transform;
824
- map.transform = mapInstance.transform;
825
- const result2 = map.queryRenderedFeatures(geometry, options);
826
- map.transform = tr;
827
- return result2;
828
- }
829
- };
830
- for (const key of getMethodNames(map)) {
831
- if (!(key in result) && !skipMethods.includes(key)) {
832
- result[key] = map[key].bind(map);
833
- }
834
- }
835
- return result;
836
- }
837
- function getMethodNames(obj) {
838
- const result = /* @__PURE__ */ new Set();
839
- let proto = obj;
840
- while (proto) {
841
- for (const key of Object.getOwnPropertyNames(proto)) {
842
- if (key[0] !== "_" && typeof obj[key] === "function" && key !== "fire" && key !== "setEventedParent") {
843
- result.add(key);
844
- }
845
- }
846
- proto = Object.getPrototypeOf(proto);
847
- }
848
- return Array.from(result);
849
- }
850
-
851
- // src/utils/use-isomorphic-layout-effect.ts
852
- var import_react2 = require("react");
853
- var useIsomorphicLayoutEffect = typeof document !== "undefined" ? import_react2.useLayoutEffect : import_react2.useEffect;
854
- var use_isomorphic_layout_effect_default = useIsomorphicLayoutEffect;
855
-
856
- // src/utils/set-globals.ts
857
- var globalSettings = [
858
- "baseApiUrl",
859
- "maxParallelImageRequests",
860
- "workerClass",
861
- "workerCount",
862
- "workerUrl"
863
- ];
864
- function setGlobals(mapLib2, props) {
865
- for (const key of globalSettings) {
866
- if (key in props) {
867
- mapLib2[key] = props[key];
868
- }
869
- }
870
- const {
871
- RTLTextPlugin = "https://api.mapbox.com/mapbox-gl-js/plugins/mapbox-gl-rtl-text/v0.2.3/mapbox-gl-rtl-text.js"
872
- } = props;
873
- if (RTLTextPlugin && mapLib2.getRTLTextPluginStatus && mapLib2.getRTLTextPluginStatus() === "unavailable") {
874
- mapLib2.setRTLTextPlugin(
875
- RTLTextPlugin,
876
- (error) => {
877
- if (error) {
878
- console.error(error);
879
- }
880
- },
881
- true
882
- );
883
- }
884
- }
885
-
886
- // src/components/map.tsx
887
- var MapContext = React2.createContext(null);
888
- function Map(props, ref, defaultLib) {
889
- const mountedMapsContext = (0, import_react3.useContext)(MountedMapsContext);
890
- const [mapInstance, setMapInstance] = (0, import_react3.useState)(null);
891
- const containerRef = (0, import_react3.useRef)();
892
- const { current: contextValue } = (0, import_react3.useRef)({ mapLib: null, map: null });
893
- (0, import_react3.useEffect)(() => {
894
- const mapLib2 = props.mapLib;
895
- let isMounted = true;
896
- let mapbox;
897
- Promise.resolve(mapLib2 || defaultLib).then((module2) => {
898
- if (!isMounted) {
899
- return;
900
- }
901
- if (!module2) {
902
- throw new Error("Invalid mapLib");
903
- }
904
- const mapboxgl = "Map" in module2 ? module2 : module2.default;
905
- if (!mapboxgl.Map) {
906
- throw new Error("Invalid mapLib");
907
- }
908
- setGlobals(mapboxgl, props);
909
- if (!mapboxgl.supported || mapboxgl.supported(props)) {
910
- if (props.reuseMaps) {
911
- mapbox = Mapbox.reuse(props, containerRef.current);
912
- }
913
- if (!mapbox) {
914
- mapbox = new Mapbox(mapboxgl.Map, props, containerRef.current);
915
- }
916
- contextValue.map = createRef(mapbox);
917
- contextValue.mapLib = mapboxgl;
918
- setMapInstance(mapbox);
919
- mountedMapsContext == null ? void 0 : mountedMapsContext.onMapMount(contextValue.map, props.id);
920
- } else {
921
- throw new Error("Map is not supported by this browser");
922
- }
923
- }).catch((error) => {
924
- const { onError } = props;
925
- if (onError) {
926
- onError({
927
- type: "error",
928
- target: null,
929
- originalEvent: null,
930
- error
931
- });
932
- } else {
933
- console.error(error);
934
- }
935
- });
936
- return () => {
937
- isMounted = false;
938
- if (mapbox) {
939
- mountedMapsContext == null ? void 0 : mountedMapsContext.onMapUnmount(props.id);
940
- if (props.reuseMaps) {
941
- mapbox.recycle();
942
- } else {
943
- mapbox.destroy();
944
- }
945
- }
946
- };
947
- }, []);
948
- use_isomorphic_layout_effect_default(() => {
949
- if (mapInstance) {
950
- mapInstance.setProps(props);
951
- }
952
- });
953
- (0, import_react3.useImperativeHandle)(ref, () => contextValue.map, [mapInstance]);
954
- const style = (0, import_react3.useMemo)(
955
- () => __spreadValues({
956
- position: "relative",
957
- width: "100%",
958
- height: "100%"
959
- }, props.style),
960
- [props.style]
961
- );
962
- const CHILD_CONTAINER_STYLE = {
963
- height: "100%"
964
- };
965
- 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)));
966
- }
967
-
968
- // src/components/marker.ts
969
- var React3 = __toESM(require("react"), 1);
970
- var import_react_dom = require("react-dom");
971
- var import_react4 = require("react");
972
-
973
- // src/utils/apply-react-style.ts
974
- var unitlessNumber = /box|flex|grid|column|lineHeight|fontWeight|opacity|order|tabSize|zIndex/;
975
- function applyReactStyle(element, styles) {
976
- if (!element || !styles) {
977
- return;
978
- }
979
- const style = element.style;
980
- for (const key in styles) {
981
- const value = styles[key];
982
- if (Number.isFinite(value) && !unitlessNumber.test(key)) {
983
- style[key] = `${value}px`;
984
- } else {
985
- style[key] = value;
986
- }
987
- }
988
- }
989
-
990
- // src/components/marker.ts
991
- function Marker(props, ref) {
992
- const { map, mapLib: mapLib2 } = (0, import_react4.useContext)(MapContext);
993
- const thisRef = (0, import_react4.useRef)({ props });
994
- thisRef.current.props = props;
995
- const marker = (0, import_react4.useMemo)(() => {
996
- let hasChildren = false;
997
- React3.Children.forEach(props.children, (el) => {
998
- if (el) {
999
- hasChildren = true;
1000
- }
1001
- });
1002
- const options = __spreadProps(__spreadValues({}, props), {
1003
- element: hasChildren ? document.createElement("div") : null
1004
- });
1005
- const mk = new mapLib2.Marker(options);
1006
- mk.setLngLat([props.longitude, props.latitude]);
1007
- mk.getElement().addEventListener("click", (e) => {
1008
- var _a, _b;
1009
- (_b = (_a = thisRef.current.props).onClick) == null ? void 0 : _b.call(_a, {
1010
- type: "click",
1011
- target: mk,
1012
- originalEvent: e
1013
- });
1014
- });
1015
- mk.on("dragstart", (e) => {
1016
- var _a, _b;
1017
- const evt = e;
1018
- evt.lngLat = marker.getLngLat();
1019
- (_b = (_a = thisRef.current.props).onDragStart) == null ? void 0 : _b.call(_a, evt);
1020
- });
1021
- mk.on("drag", (e) => {
1022
- var _a, _b;
1023
- const evt = e;
1024
- evt.lngLat = marker.getLngLat();
1025
- (_b = (_a = thisRef.current.props).onDrag) == null ? void 0 : _b.call(_a, evt);
1026
- });
1027
- mk.on("dragend", (e) => {
1028
- var _a, _b;
1029
- const evt = e;
1030
- evt.lngLat = marker.getLngLat();
1031
- (_b = (_a = thisRef.current.props).onDragEnd) == null ? void 0 : _b.call(_a, evt);
1032
- });
1033
- return mk;
1034
- }, []);
1035
- (0, import_react4.useEffect)(() => {
1036
- marker.addTo(map.getMap());
1037
- return () => {
1038
- marker.remove();
1039
- };
1040
- }, []);
1041
- const {
1042
- longitude,
1043
- latitude,
1044
- offset,
1045
- style,
1046
- draggable = false,
1047
- popup = null,
1048
- rotation = 0,
1049
- rotationAlignment = "auto",
1050
- pitchAlignment = "auto"
1051
- } = props;
1052
- (0, import_react4.useEffect)(() => {
1053
- applyReactStyle(marker.getElement(), style);
1054
- }, [style]);
1055
- (0, import_react4.useImperativeHandle)(ref, () => marker, []);
1056
- if (marker.getLngLat().lng !== longitude || marker.getLngLat().lat !== latitude) {
1057
- marker.setLngLat([longitude, latitude]);
1058
- }
1059
- if (offset && !arePointsEqual(marker.getOffset(), offset)) {
1060
- marker.setOffset(offset);
1061
- }
1062
- if (marker.isDraggable() !== draggable) {
1063
- marker.setDraggable(draggable);
1064
- }
1065
- if (marker.getRotation() !== rotation) {
1066
- marker.setRotation(rotation);
1067
- }
1068
- if (marker.getRotationAlignment() !== rotationAlignment) {
1069
- marker.setRotationAlignment(rotationAlignment);
1070
- }
1071
- if (marker.getPitchAlignment() !== pitchAlignment) {
1072
- marker.setPitchAlignment(pitchAlignment);
1073
- }
1074
- if (marker.getPopup() !== popup) {
1075
- marker.setPopup(popup);
1076
- }
1077
- return (0, import_react_dom.createPortal)(props.children, marker.getElement());
1078
- }
1079
- var marker_default = (0, import_react4.memo)((0, import_react4.forwardRef)(Marker));
1080
-
1081
- // src/components/popup.ts
1082
- var import_react_dom2 = require("react-dom");
1083
- var import_react5 = require("react");
1084
- function getClassList(className) {
1085
- return new Set(className ? className.trim().split(/\s+/) : []);
1086
- }
1087
- function Popup(props, ref) {
1088
- const { map, mapLib: mapLib2 } = (0, import_react5.useContext)(MapContext);
1089
- const container = (0, import_react5.useMemo)(() => {
1090
- return document.createElement("div");
1091
- }, []);
1092
- const thisRef = (0, import_react5.useRef)({ props });
1093
- thisRef.current.props = props;
1094
- const popup = (0, import_react5.useMemo)(() => {
1095
- const options = __spreadValues({}, props);
1096
- const pp = new mapLib2.Popup(options);
1097
- pp.setLngLat([props.longitude, props.latitude]);
1098
- pp.once("open", (e) => {
1099
- var _a, _b;
1100
- (_b = (_a = thisRef.current.props).onOpen) == null ? void 0 : _b.call(_a, e);
1101
- });
1102
- return pp;
1103
- }, []);
1104
- (0, import_react5.useEffect)(() => {
1105
- const onClose = (e) => {
1106
- var _a, _b;
1107
- (_b = (_a = thisRef.current.props).onClose) == null ? void 0 : _b.call(_a, e);
1108
- };
1109
- popup.on("close", onClose);
1110
- popup.setDOMContent(container).addTo(map.getMap());
1111
- return () => {
1112
- popup.off("close", onClose);
1113
- if (popup.isOpen()) {
1114
- popup.remove();
1115
- }
1116
- };
1117
- }, []);
1118
- (0, import_react5.useEffect)(() => {
1119
- applyReactStyle(popup.getElement(), props.style);
1120
- }, [props.style]);
1121
- (0, import_react5.useImperativeHandle)(ref, () => popup, []);
1122
- if (popup.isOpen()) {
1123
- if (popup.getLngLat().lng !== props.longitude || popup.getLngLat().lat !== props.latitude) {
1124
- popup.setLngLat([props.longitude, props.latitude]);
1125
- }
1126
- if (props.offset && !deepEqual(popup.options.offset, props.offset)) {
1127
- popup.setOffset(props.offset);
1128
- }
1129
- if (popup.options.anchor !== props.anchor || popup.options.maxWidth !== props.maxWidth) {
1130
- popup.options.anchor = props.anchor;
1131
- popup.setMaxWidth(props.maxWidth);
1132
- }
1133
- if (popup.options.className !== props.className) {
1134
- const prevClassList = getClassList(popup.options.className);
1135
- const nextClassList = getClassList(props.className);
1136
- for (const c of prevClassList) {
1137
- if (!nextClassList.has(c)) {
1138
- popup.removeClassName(c);
1139
- }
1140
- }
1141
- for (const c of nextClassList) {
1142
- if (!prevClassList.has(c)) {
1143
- popup.addClassName(c);
1144
- }
1145
- }
1146
- popup.options.className = props.className;
1147
- }
1148
- }
1149
- return (0, import_react_dom2.createPortal)(props.children, container);
1150
- }
1151
- var popup_default = (0, import_react5.memo)((0, import_react5.forwardRef)(Popup));
1152
-
1153
- // src/components/attribution-control.ts
1154
- var import_react7 = require("react");
1155
-
1156
- // src/components/use-control.ts
1157
- var import_react6 = require("react");
1158
- function useControl(onCreate, arg1, arg2, arg3) {
1159
- const context = (0, import_react6.useContext)(MapContext);
1160
- const ctrl = (0, import_react6.useMemo)(() => onCreate(context), []);
1161
- (0, import_react6.useEffect)(() => {
1162
- const opts = arg3 || arg2 || arg1;
1163
- const onAdd = typeof arg1 === "function" && typeof arg2 === "function" ? arg1 : null;
1164
- const onRemove = typeof arg2 === "function" ? arg2 : typeof arg1 === "function" ? arg1 : null;
1165
- const { map } = context;
1166
- if (!map.hasControl(ctrl)) {
1167
- map.addControl(ctrl, opts == null ? void 0 : opts.position);
1168
- if (onAdd) {
1169
- onAdd(context);
1170
- }
1171
- }
1172
- return () => {
1173
- if (onRemove) {
1174
- onRemove(context);
1175
- }
1176
- if (map.hasControl(ctrl)) {
1177
- map.removeControl(ctrl);
1178
- }
1179
- };
1180
- }, []);
1181
- return ctrl;
1182
- }
1183
- var use_control_default = useControl;
1184
-
1185
- // src/components/attribution-control.ts
1186
- function AttributionControl(props) {
1187
- const ctrl = use_control_default(
1188
- ({ mapLib: mapLib2 }) => new mapLib2.AttributionControl(props),
1189
- {
1190
- position: props.position
1191
- }
1192
- );
1193
- (0, import_react7.useEffect)(() => {
1194
- applyReactStyle(ctrl._container, props.style);
1195
- }, [props.style]);
1196
- return null;
1197
- }
1198
- var attribution_control_default = (0, import_react7.memo)(AttributionControl);
1199
-
1200
- // src/components/fullscreen-control.tsx
1201
- var import_react8 = require("react");
1202
- function FullscreenControl(props) {
1203
- const ctrl = use_control_default(
1204
- ({ mapLib: mapLib2 }) => new mapLib2.FullscreenControl({
1205
- container: props.containerId && document.getElementById(props.containerId)
1206
- }),
1207
- { position: props.position }
1208
- );
1209
- (0, import_react8.useEffect)(() => {
1210
- applyReactStyle(ctrl._controlContainer, props.style);
1211
- }, [props.style]);
1212
- return null;
1213
- }
1214
- var fullscreen_control_default = (0, import_react8.memo)(FullscreenControl);
1215
-
1216
- // src/components/geolocate-control.ts
1217
- var import_react9 = require("react");
1218
- function GeolocateControl(props, ref) {
1219
- const thisRef = (0, import_react9.useRef)({ props });
1220
- const ctrl = use_control_default(
1221
- ({ mapLib: mapLib2 }) => {
1222
- const gc = new mapLib2.GeolocateControl(props);
1223
- const setupUI = gc._setupUI;
1224
- gc._setupUI = (args) => {
1225
- if (!gc._container.hasChildNodes()) {
1226
- setupUI(args);
1227
- }
1228
- };
1229
- gc.on("geolocate", (e) => {
1230
- var _a, _b;
1231
- (_b = (_a = thisRef.current.props).onGeolocate) == null ? void 0 : _b.call(_a, e);
1232
- });
1233
- gc.on("error", (e) => {
1234
- var _a, _b;
1235
- (_b = (_a = thisRef.current.props).onError) == null ? void 0 : _b.call(_a, e);
1236
- });
1237
- gc.on("outofmaxbounds", (e) => {
1238
- var _a, _b;
1239
- (_b = (_a = thisRef.current.props).onOutOfMaxBounds) == null ? void 0 : _b.call(_a, e);
1240
- });
1241
- gc.on("trackuserlocationstart", (e) => {
1242
- var _a, _b;
1243
- (_b = (_a = thisRef.current.props).onTrackUserLocationStart) == null ? void 0 : _b.call(_a, e);
1244
- });
1245
- gc.on("trackuserlocationend", (e) => {
1246
- var _a, _b;
1247
- (_b = (_a = thisRef.current.props).onTrackUserLocationEnd) == null ? void 0 : _b.call(_a, e);
1248
- });
1249
- return gc;
1250
- },
1251
- { position: props.position }
1252
- );
1253
- thisRef.current.props = props;
1254
- (0, import_react9.useImperativeHandle)(ref, () => ctrl, []);
1255
- (0, import_react9.useEffect)(() => {
1256
- applyReactStyle(ctrl._container, props.style);
1257
- }, [props.style]);
1258
- return null;
1259
- }
1260
- var geolocate_control_default = (0, import_react9.memo)((0, import_react9.forwardRef)(GeolocateControl));
1261
-
1262
- // src/components/navigation-control.ts
1263
- var import_react10 = require("react");
1264
- function NavigationControl(props) {
1265
- const ctrl = use_control_default(({ mapLib: mapLib2 }) => new mapLib2.NavigationControl(props), {
1266
- position: props.position
1267
- });
1268
- (0, import_react10.useEffect)(() => {
1269
- applyReactStyle(ctrl._container, props.style);
1270
- }, [props.style]);
1271
- return null;
1272
- }
1273
- var navigation_control_default = (0, import_react10.memo)(NavigationControl);
1274
-
1275
- // src/components/scale-control.ts
1276
- var import_react11 = require("react");
1277
- function ScaleControl(props) {
1278
- const ctrl = use_control_default(({ mapLib: mapLib2 }) => new mapLib2.ScaleControl(props), {
1279
- position: props.position
1280
- });
1281
- const propsRef = (0, import_react11.useRef)(props);
1282
- const prevProps = propsRef.current;
1283
- propsRef.current = props;
1284
- const { style } = props;
1285
- if (props.maxWidth !== void 0 && props.maxWidth !== prevProps.maxWidth) {
1286
- ctrl.options.maxWidth = props.maxWidth;
1287
- }
1288
- if (props.unit !== void 0 && props.unit !== prevProps.unit) {
1289
- ctrl.setUnit(props.unit);
1290
- }
1291
- (0, import_react11.useEffect)(() => {
1292
- applyReactStyle(ctrl._container, style);
1293
- }, [style]);
1294
- return null;
1295
- }
1296
- var scale_control_default = (0, import_react11.memo)(ScaleControl);
1297
-
1298
- // src/components/layer.ts
1299
- var import_react12 = require("react");
1300
-
1301
- // src/utils/assert.ts
1302
- function assert(condition, message) {
1303
- if (!condition) {
1304
- throw new Error(message);
1305
- }
1306
- }
1307
-
1308
- // src/components/layer.ts
1309
- function updateLayer(map, id, props, prevProps) {
1310
- assert(props.id === prevProps.id, "layer id changed");
1311
- assert(props.type === prevProps.type, "layer type changed");
1312
- if (props.type === "custom" || prevProps.type === "custom") {
1313
- return;
1314
- }
1315
- const { layout = {}, paint = {}, filter, minzoom, maxzoom, beforeId } = props;
1316
- if (beforeId !== prevProps.beforeId) {
1317
- map.moveLayer(id, beforeId);
1318
- }
1319
- if (layout !== prevProps.layout) {
1320
- const prevLayout = prevProps.layout || {};
1321
- for (const key in layout) {
1322
- if (!deepEqual(layout[key], prevLayout[key])) {
1323
- map.setLayoutProperty(id, key, layout[key]);
1324
- }
1325
- }
1326
- for (const key in prevLayout) {
1327
- if (!layout.hasOwnProperty(key)) {
1328
- map.setLayoutProperty(id, key, void 0);
1329
- }
1330
- }
1331
- }
1332
- if (paint !== prevProps.paint) {
1333
- const prevPaint = prevProps.paint || {};
1334
- for (const key in paint) {
1335
- if (!deepEqual(paint[key], prevPaint[key])) {
1336
- map.setPaintProperty(id, key, paint[key]);
1337
- }
1338
- }
1339
- for (const key in prevPaint) {
1340
- if (!paint.hasOwnProperty(key)) {
1341
- map.setPaintProperty(id, key, void 0);
1342
- }
1343
- }
1344
- }
1345
- if (!deepEqual(filter, prevProps.filter)) {
1346
- map.setFilter(id, filter);
1347
- }
1348
- if (minzoom !== prevProps.minzoom || maxzoom !== prevProps.maxzoom) {
1349
- map.setLayerZoomRange(id, minzoom, maxzoom);
1350
- }
1351
- }
1352
- function createLayer(map, id, props) {
1353
- if (map.style && map.style._loaded && (!("source" in props) || map.getSource(props.source))) {
1354
- const options = __spreadProps(__spreadValues({}, props), { id });
1355
- delete options.beforeId;
1356
- map.addLayer(options, props.beforeId);
1357
- }
1358
- }
1359
- var layerCounter = 0;
1360
- function Layer(props) {
1361
- const map = (0, import_react12.useContext)(MapContext).map.getMap();
1362
- const propsRef = (0, import_react12.useRef)(props);
1363
- const [, setStyleLoaded] = (0, import_react12.useState)(0);
1364
- const id = (0, import_react12.useMemo)(() => props.id || `jsx-layer-${layerCounter++}`, []);
1365
- (0, import_react12.useEffect)(() => {
1366
- if (map) {
1367
- const forceUpdate = () => setStyleLoaded((version) => version + 1);
1368
- map.on("styledata", forceUpdate);
1369
- forceUpdate();
1370
- return () => {
1371
- map.off("styledata", forceUpdate);
1372
- if (map.style && map.style._loaded && map.getLayer(id)) {
1373
- map.removeLayer(id);
1374
- }
1375
- };
1376
- }
1377
- return void 0;
1378
- }, [map]);
1379
- const layer = map && map.style && map.getLayer(id);
1380
- if (layer) {
1381
- try {
1382
- updateLayer(map, id, props, propsRef.current);
1383
- } catch (error) {
1384
- console.warn(error);
1385
- }
1386
- } else {
1387
- createLayer(map, id, props);
1388
- }
1389
- propsRef.current = props;
1390
- return null;
1391
- }
1392
- var layer_default = Layer;
1393
-
1394
- // src/components/source.ts
1395
- var React4 = __toESM(require("react"), 1);
1396
- var import_react13 = require("react");
1397
- var import_react14 = require("react");
1398
- var sourceCounter = 0;
1399
- function createSource(map, id, props) {
1400
- if (map.style && map.style._loaded) {
1401
- const options = __spreadValues({}, props);
1402
- delete options.id;
1403
- delete options.children;
1404
- map.addSource(id, options);
1405
- return map.getSource(id);
1406
- }
1407
- return null;
1408
- }
1409
- function updateSource(source, props, prevProps) {
1410
- assert(props.id === prevProps.id, "source id changed");
1411
- assert(props.type === prevProps.type, "source type changed");
1412
- let changedKey = "";
1413
- let changedKeyCount = 0;
1414
- for (const key in props) {
1415
- if (key !== "children" && key !== "id" && !deepEqual(prevProps[key], props[key])) {
1416
- changedKey = key;
1417
- changedKeyCount++;
1418
- }
1419
- }
1420
- if (!changedKeyCount) {
1421
- return;
1422
- }
1423
- const type = props.type;
1424
- if (type === "geojson") {
1425
- source.setData(
1426
- props.data
1427
- );
1428
- } else if (type === "image") {
1429
- source.updateImage({
1430
- url: props.url,
1431
- coordinates: props.coordinates
1432
- });
1433
- } else if ("setCoordinates" in source && changedKeyCount === 1 && changedKey === "coordinates") {
1434
- source.setCoordinates(props.coordinates);
1435
- } else if ("setUrl" in source) {
1436
- switch (changedKey) {
1437
- case "url":
1438
- source.setUrl(props.url);
1439
- break;
1440
- case "tiles":
1441
- source.setTiles(props.tiles);
1442
- break;
1443
- default:
1444
- }
1445
- } else {
1446
- console.warn(`Unable to update <Source> prop: ${changedKey}`);
1447
- }
1448
- }
1449
- function Source(props) {
1450
- const map = (0, import_react13.useContext)(MapContext).map.getMap();
1451
- const propsRef = (0, import_react13.useRef)(props);
1452
- const [, setStyleLoaded] = (0, import_react13.useState)(0);
1453
- const id = (0, import_react13.useMemo)(() => props.id || `jsx-source-${sourceCounter++}`, []);
1454
- (0, import_react13.useEffect)(() => {
1455
- if (map) {
1456
- const forceUpdate = () => setTimeout(() => setStyleLoaded((version) => version + 1), 0);
1457
- map.on("styledata", forceUpdate);
1458
- forceUpdate();
1459
- return () => {
1460
- var _a;
1461
- map.off("styledata", forceUpdate);
1462
- if (map.style && map.style._loaded && map.getSource(id)) {
1463
- const allLayers = (_a = map.getStyle()) == null ? void 0 : _a.layers;
1464
- if (allLayers) {
1465
- for (const layer of allLayers) {
1466
- if (layer.source === id) {
1467
- map.removeLayer(layer.id);
1468
- }
1469
- }
1470
- }
1471
- map.removeSource(id);
1472
- }
1473
- };
1474
- }
1475
- return void 0;
1476
- }, [map]);
1477
- let source = map && map.style && map.getSource(id);
1478
- if (source) {
1479
- updateSource(source, props, propsRef.current);
1480
- } else {
1481
- source = createSource(map, id, props);
1482
- }
1483
- propsRef.current = props;
1484
- return source && React4.Children.map(
1485
- props.children,
1486
- (child) => child && (0, import_react14.cloneElement)(child, {
1487
- source: id
1488
- })
1489
- ) || null;
1490
- }
1491
- var source_default = Source;
1492
-
1493
- // src/exports-bkoi-gl.ts
1494
- function useMap2() {
1495
- return useMap();
1496
- }
1497
- var mapLib = import("bkoi-gl");
1498
- var Map2 = (() => {
1499
- return React5.forwardRef(function Map3(props, ref) {
1500
- return Map(props, ref, mapLib);
1501
- });
1502
- })();
1503
- var Marker2 = marker_default;
1504
- var Popup2 = popup_default;
1505
- var AttributionControl2 = attribution_control_default;
1506
- var FullscreenControl2 = fullscreen_control_default;
1507
- var NavigationControl2 = navigation_control_default;
1508
- var GeolocateControl2 = geolocate_control_default;
1509
- var ScaleControl2 = scale_control_default;
1510
- var Layer2 = layer_default;
1511
- var Source2 = source_default;
1512
- var exports_bkoi_gl_default = Map2;