react-bkoi-gl 2.0.0 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +9 -0
- package/dist/index.cjs +137 -111
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +370 -0
- package/dist/index.d.ts +370 -2
- package/dist/index.js +1434 -2
- package/dist/index.js.map +1 -1
- package/dist/styles/react-bkoi-gl.css +1 -1
- package/package.json +62 -30
- package/dist/components/attribution-control.d.ts +0 -9
- package/dist/components/attribution-control.js +0 -20
- package/dist/components/attribution-control.js.map +0 -1
- package/dist/components/fullscreen-control.d.ts +0 -12
- package/dist/components/fullscreen-control.js +0 -21
- package/dist/components/fullscreen-control.js.map +0 -1
- package/dist/components/geolocate-control.d.ts +0 -21
- package/dist/components/geolocate-control.js +0 -46
- package/dist/components/geolocate-control.js.map +0 -1
- package/dist/components/layer.d.ts +0 -18
- package/dist/components/layer.js +0 -98
- package/dist/components/layer.js.map +0 -1
- package/dist/components/logo-control.d.ts +0 -9
- package/dist/components/logo-control.js +0 -28
- package/dist/components/logo-control.js.map +0 -1
- package/dist/components/map.d.ts +0 -27
- package/dist/components/map.js +0 -108
- package/dist/components/map.js.map +0 -1
- package/dist/components/marker.d.ts +0 -18
- package/dist/components/marker.js +0 -105
- package/dist/components/marker.js.map +0 -1
- package/dist/components/navigation-control.d.ts +0 -9
- package/dist/components/navigation-control.js +0 -19
- package/dist/components/navigation-control.js.map +0 -1
- package/dist/components/popup.d.ts +0 -15
- package/dist/components/popup.js +0 -68
- package/dist/components/popup.js.map +0 -1
- package/dist/components/scale-control.d.ts +0 -11
- package/dist/components/scale-control.js +0 -31
- package/dist/components/scale-control.js.map +0 -1
- package/dist/components/source.d.ts +0 -6
- package/dist/components/source.js +0 -95
- package/dist/components/source.js.map +0 -1
- package/dist/components/terrain-control.d.ts +0 -10
- package/dist/components/terrain-control.js +0 -19
- package/dist/components/terrain-control.js.map +0 -1
- package/dist/components/use-control.d.ts +0 -9
- package/dist/components/use-control.js +0 -30
- package/dist/components/use-control.js.map +0 -1
- package/dist/components/use-map.d.ts +0 -19
- package/dist/components/use-map.js +0 -54
- package/dist/components/use-map.js.map +0 -1
- package/dist/exports-maplibre-gl.d.ts +0 -33
- package/dist/exports-maplibre-gl.js +0 -21
- package/dist/exports-maplibre-gl.js.map +0 -1
- package/dist/maplibre/create-ref.d.ts +0 -9
- package/dist/maplibre/create-ref.js +0 -30
- package/dist/maplibre/create-ref.js.map +0 -1
- package/dist/maplibre/maplibre.d.ts +0 -81
- package/dist/maplibre/maplibre.js +0 -387
- package/dist/maplibre/maplibre.js.map +0 -1
- package/dist/styles.d.js +0 -2
- package/dist/styles.d.js.map +0 -1
- package/dist/tsconfig.build.tsbuildinfo +0 -1
- package/dist/types/common.d.ts +0 -20
- package/dist/types/common.js +0 -2
- package/dist/types/common.js.map +0 -1
- package/dist/types/events.d.ts +0 -80
- package/dist/types/events.js +0 -2
- package/dist/types/events.js.map +0 -1
- package/dist/types/internal.d.ts +0 -14
- package/dist/types/internal.js +0 -2
- package/dist/types/internal.js.map +0 -1
- package/dist/types/lib.d.ts +0 -40
- package/dist/types/lib.js +0 -2
- package/dist/types/lib.js.map +0 -1
- package/dist/types/style-spec.d.ts +0 -1
- package/dist/types/style-spec.js +0 -2
- package/dist/types/style-spec.js.map +0 -1
- package/dist/utils/apply-react-style.d.ts +0 -2
- package/dist/utils/apply-react-style.js +0 -16
- package/dist/utils/apply-react-style.js.map +0 -1
- package/dist/utils/assert.d.ts +0 -1
- package/dist/utils/assert.js +0 -6
- package/dist/utils/assert.js.map +0 -1
- package/dist/utils/compare-class-names.d.ts +0 -2
- package/dist/utils/compare-class-names.js +0 -23
- package/dist/utils/compare-class-names.js.map +0 -1
- package/dist/utils/deep-equal.d.ts +0 -15
- package/dist/utils/deep-equal.js +0 -46
- package/dist/utils/deep-equal.js.map +0 -1
- package/dist/utils/set-globals.d.ts +0 -20
- package/dist/utils/set-globals.js +0 -31
- package/dist/utils/set-globals.js.map +0 -1
- package/dist/utils/style-utils.d.ts +0 -3
- package/dist/utils/style-utils.js +0 -42
- package/dist/utils/style-utils.js.map +0 -1
- package/dist/utils/transform.d.ts +0 -18
- package/dist/utils/transform.js +0 -33
- package/dist/utils/transform.js.map +0 -1
- package/dist/utils/use-isomorphic-layout-effect.d.ts +0 -3
- package/dist/utils/use-isomorphic-layout-effect.js +0 -4
- package/dist/utils/use-isomorphic-layout-effect.js.map +0 -1
- package/src/components/attribution-control.ts +0 -56
- package/src/components/fullscreen-control.ts +0 -40
- package/src/components/geolocate-control.ts +0 -96
- package/src/components/layer.ts +0 -141
- package/src/components/logo-control.ts +0 -44
- package/src/components/map.tsx +0 -166
- package/src/components/marker.ts +0 -155
- package/src/components/navigation-control.ts +0 -28
- package/src/components/popup.ts +0 -113
- package/src/components/scale-control.ts +0 -44
- package/src/components/source.ts +0 -159
- package/src/components/terrain-control.ts +0 -29
- package/src/components/use-control.ts +0 -68
- package/src/components/use-map.tsx +0 -71
- package/src/exports-maplibre-gl.ts +0 -37
- package/src/index.ts +0 -3
- package/src/maplibre/create-ref.ts +0 -70
- package/src/maplibre/maplibre.ts +0 -624
- package/src/styles.d.ts +0 -4
- package/src/types/common.ts +0 -34
- package/src/types/events.ts +0 -133
- package/src/types/internal.ts +0 -26
- package/src/types/lib.ts +0 -84
- package/src/types/style-spec.ts +0 -34
- package/src/utils/apply-react-style.ts +0 -24
- package/src/utils/assert.ts +0 -5
- package/src/utils/compare-class-names.ts +0 -29
- package/src/utils/deep-equal.ts +0 -61
- package/src/utils/set-globals.ts +0 -51
- package/src/utils/style-utils.ts +0 -68
- package/src/utils/transform.ts +0 -58
- package/src/utils/use-isomorphic-layout-effect.ts +0 -8
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Barikoi
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
<h1 align="center">react-bkoi-gl | <a href="https://docs.barikoi.com/npm/npm-intro">Docs</a></h1>
|
|
2
2
|
|
|
3
|
+
<p align="center">
|
|
4
|
+
<a href="https://www.npmjs.com/package/react-bkoi-gl"><img src="https://img.shields.io/npm/v/react-bkoi-gl.svg" alt="npm version"></a>
|
|
5
|
+
<a href="https://www.npmjs.com/package/react-bkoi-gl"><img src="https://img.shields.io/npm/dw/react-bkoi-gl" alt="npm downloads"></a>
|
|
6
|
+
<a href="https://bundlephobia.com/package/react-bkoi-gl"><img src="https://img.shields.io/bundlephobia/min/react-bkoi-gl" alt="Bundle Size"></a>
|
|
7
|
+
<a href="https://www.typescriptlang.org/"><img src="https://img.shields.io/badge/TypeScript-007ACC?logo=typescript&logoColor=white" alt="TypeScript"></a>
|
|
8
|
+
<a href="https://nodejs.org/"><img src="https://img.shields.io/node/v/react-bkoi-gl" alt="Node.js Version"></a>
|
|
9
|
+
<a href="https://opensource.org/licenses/MIT"><img src="https://img.shields.io/badge/License-MIT-yellow.svg" alt="License: MIT"></a>
|
|
10
|
+
</p>
|
|
11
|
+
|
|
3
12
|
## Description
|
|
4
13
|
|
|
5
14
|
`react-bkoi-gl` is a suite of [React](http://facebook.github.io/react/) components designed to provide a API for [Barikoi Maps](https://docs.barikoi.com/docs/maps-api). More information in the online documentation.
|
package/dist/index.cjs
CHANGED
|
@@ -1,26 +1,9 @@
|
|
|
1
1
|
var __create = Object.create;
|
|
2
2
|
var __defProp = Object.defineProperty;
|
|
3
|
-
var __defProps = Object.defineProperties;
|
|
4
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
6
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
8
5
|
var __getProtoOf = Object.getPrototypeOf;
|
|
9
6
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
10
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
11
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
12
|
-
var __spreadValues = (a, b) => {
|
|
13
|
-
for (var prop in b || (b = {}))
|
|
14
|
-
if (__hasOwnProp.call(b, prop))
|
|
15
|
-
__defNormalProp(a, prop, b[prop]);
|
|
16
|
-
if (__getOwnPropSymbols)
|
|
17
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
18
|
-
if (__propIsEnum.call(b, prop))
|
|
19
|
-
__defNormalProp(a, prop, b[prop]);
|
|
20
|
-
}
|
|
21
|
-
return a;
|
|
22
|
-
};
|
|
23
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
24
7
|
var __export = (target, all) => {
|
|
25
8
|
for (var name in all)
|
|
26
9
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -44,8 +27,8 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
44
27
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
45
28
|
|
|
46
29
|
// src/index.ts
|
|
47
|
-
var
|
|
48
|
-
__export(
|
|
30
|
+
var index_exports = {};
|
|
31
|
+
__export(index_exports, {
|
|
49
32
|
AttributionControl: () => AttributionControl,
|
|
50
33
|
FullscreenControl: () => FullscreenControl,
|
|
51
34
|
GeolocateControl: () => GeolocateControl,
|
|
@@ -63,7 +46,7 @@ __export(src_exports, {
|
|
|
63
46
|
useControl: () => useControl,
|
|
64
47
|
useMap: () => useMap
|
|
65
48
|
});
|
|
66
|
-
module.exports = __toCommonJS(
|
|
49
|
+
module.exports = __toCommonJS(index_exports);
|
|
67
50
|
|
|
68
51
|
// src/components/map.tsx
|
|
69
52
|
var React2 = __toESM(require("react"), 1);
|
|
@@ -83,13 +66,13 @@ var MapProvider = (props) => {
|
|
|
83
66
|
if (currMaps[id]) {
|
|
84
67
|
throw new Error(`Multiple maps with the same id: ${id}`);
|
|
85
68
|
}
|
|
86
|
-
return
|
|
69
|
+
return { ...currMaps, [id]: map };
|
|
87
70
|
});
|
|
88
71
|
}, []);
|
|
89
72
|
const onMapUnmount = (0, import_react.useCallback)((id = "default") => {
|
|
90
73
|
setMaps((currMaps) => {
|
|
91
74
|
if (currMaps[id]) {
|
|
92
|
-
const nextMaps =
|
|
75
|
+
const nextMaps = { ...currMaps };
|
|
93
76
|
delete nextMaps[id];
|
|
94
77
|
return nextMaps;
|
|
95
78
|
}
|
|
@@ -109,11 +92,10 @@ var MapProvider = (props) => {
|
|
|
109
92
|
);
|
|
110
93
|
};
|
|
111
94
|
function useMap() {
|
|
112
|
-
|
|
113
|
-
const maps = (_a = (0, import_react.useContext)(MountedMapsContext)) == null ? void 0 : _a.maps;
|
|
95
|
+
const maps = (0, import_react.useContext)(MountedMapsContext)?.maps;
|
|
114
96
|
const currentMap = (0, import_react.useContext)(MapContext);
|
|
115
97
|
const mapsWithCurrent = (0, import_react.useMemo)(() => {
|
|
116
|
-
return
|
|
98
|
+
return { ...maps, current: currentMap?.map };
|
|
117
99
|
}, [maps, currentMap]);
|
|
118
100
|
return mapsWithCurrent;
|
|
119
101
|
}
|
|
@@ -153,7 +135,7 @@ function deepEqual(a, b) {
|
|
|
153
135
|
return false;
|
|
154
136
|
}
|
|
155
137
|
for (const key of aKeys) {
|
|
156
|
-
if (!
|
|
138
|
+
if (!Object.prototype.hasOwnProperty.call(b, key)) {
|
|
157
139
|
return false;
|
|
158
140
|
}
|
|
159
141
|
if (!deepEqual(a[key], b[key])) {
|
|
@@ -243,7 +225,7 @@ function normalizeStyle(style) {
|
|
|
243
225
|
}
|
|
244
226
|
return normalizedLayer || layer;
|
|
245
227
|
});
|
|
246
|
-
return
|
|
228
|
+
return { ...style, layers };
|
|
247
229
|
}
|
|
248
230
|
|
|
249
231
|
// src/maplibre/maplibre.ts
|
|
@@ -319,7 +301,7 @@ var handlerNames = [
|
|
|
319
301
|
"touchZoomRotate",
|
|
320
302
|
"touchPitch"
|
|
321
303
|
];
|
|
322
|
-
var
|
|
304
|
+
var Maplibre = class _Maplibre {
|
|
323
305
|
constructor(MapClass, props, container) {
|
|
324
306
|
// mapboxgl.Map instance
|
|
325
307
|
this._map = null;
|
|
@@ -370,6 +352,10 @@ var _Maplibre = class {
|
|
|
370
352
|
this.props = props;
|
|
371
353
|
this._initialize(container);
|
|
372
354
|
}
|
|
355
|
+
static {
|
|
356
|
+
// eslint-disable-next-line no-use-before-define
|
|
357
|
+
this.savedMaps = [];
|
|
358
|
+
}
|
|
373
359
|
get map() {
|
|
374
360
|
return this._map;
|
|
375
361
|
}
|
|
@@ -403,14 +389,15 @@ var _Maplibre = class {
|
|
|
403
389
|
resizeObserver.disconnect();
|
|
404
390
|
resizeObserver.observe(container);
|
|
405
391
|
}
|
|
406
|
-
that.setProps(
|
|
392
|
+
that.setProps({ ...props, styleDiffing: false });
|
|
407
393
|
map.resize();
|
|
408
394
|
const { initialViewState } = props;
|
|
409
395
|
if (initialViewState) {
|
|
410
396
|
if (initialViewState.bounds) {
|
|
411
|
-
map.fitBounds(initialViewState.bounds,
|
|
397
|
+
map.fitBounds(initialViewState.bounds, {
|
|
398
|
+
...initialViewState.fitBoundsOptions,
|
|
412
399
|
duration: 0
|
|
413
|
-
})
|
|
400
|
+
});
|
|
414
401
|
} else {
|
|
415
402
|
that._updateViewState(initialViewState);
|
|
416
403
|
}
|
|
@@ -427,10 +414,12 @@ var _Maplibre = class {
|
|
|
427
414
|
_initialize(container) {
|
|
428
415
|
const { props } = this;
|
|
429
416
|
const { mapStyle = DEFAULT_STYLE } = props;
|
|
430
|
-
const mapOptions =
|
|
417
|
+
const mapOptions = {
|
|
418
|
+
...props,
|
|
419
|
+
...props.initialViewState,
|
|
431
420
|
container,
|
|
432
421
|
style: normalizeStyle(mapStyle)
|
|
433
|
-
}
|
|
422
|
+
};
|
|
434
423
|
const viewState = mapOptions.initialViewState || mapOptions.viewState || mapOptions;
|
|
435
424
|
Object.assign(mapOptions, {
|
|
436
425
|
center: [viewState.longitude || 0, viewState.latitude || 0],
|
|
@@ -454,12 +443,11 @@ var _Maplibre = class {
|
|
|
454
443
|
}
|
|
455
444
|
map.transformCameraUpdate = this._onCameraUpdate;
|
|
456
445
|
map.on("style.load", () => {
|
|
457
|
-
var _a;
|
|
458
446
|
this._styleComponents = {
|
|
459
447
|
light: map.getLight(),
|
|
460
448
|
sky: map.getSky(),
|
|
461
449
|
// @ts-ignore getProjection() does not exist in v4
|
|
462
|
-
projection:
|
|
450
|
+
projection: map.getProjection?.(),
|
|
463
451
|
terrain: map.getTerrain()
|
|
464
452
|
};
|
|
465
453
|
this._updateStyleComponents(this.props);
|
|
@@ -482,7 +470,7 @@ var _Maplibre = class {
|
|
|
482
470
|
recycle() {
|
|
483
471
|
const container = this.map.getContainer();
|
|
484
472
|
const children = container.querySelector("[mapboxgl-children]");
|
|
485
|
-
children
|
|
473
|
+
children?.remove();
|
|
486
474
|
_Maplibre.savedMaps.push(this);
|
|
487
475
|
}
|
|
488
476
|
destroy() {
|
|
@@ -549,7 +537,7 @@ var _Maplibre = class {
|
|
|
549
537
|
if (propName in nextProps && !deepEqual(nextProps[propName], currProps[propName])) {
|
|
550
538
|
changed = true;
|
|
551
539
|
const setter = map[`set${propName[0].toUpperCase()}${propName.slice(1)}`];
|
|
552
|
-
setter
|
|
540
|
+
setter?.call(map, nextProps[propName]);
|
|
553
541
|
}
|
|
554
542
|
}
|
|
555
543
|
return changed;
|
|
@@ -581,7 +569,6 @@ var _Maplibre = class {
|
|
|
581
569
|
sky,
|
|
582
570
|
terrain
|
|
583
571
|
}) {
|
|
584
|
-
var _a, _b;
|
|
585
572
|
const map = this._map;
|
|
586
573
|
const currProps = this._styleComponents;
|
|
587
574
|
if (map.style._loaded) {
|
|
@@ -589,9 +576,9 @@ var _Maplibre = class {
|
|
|
589
576
|
currProps.light = light;
|
|
590
577
|
map.setLight(light);
|
|
591
578
|
}
|
|
592
|
-
if (projection && !deepEqual(projection, currProps.projection) && projection !==
|
|
579
|
+
if (projection && !deepEqual(projection, currProps.projection) && projection !== currProps.projection?.type) {
|
|
593
580
|
currProps.projection = typeof projection === "string" ? { type: projection } : projection;
|
|
594
|
-
|
|
581
|
+
map.setProjection?.(currProps.projection);
|
|
595
582
|
}
|
|
596
583
|
if (sky && !deepEqual(sky, currProps.sky)) {
|
|
597
584
|
currProps.sky = sky;
|
|
@@ -607,11 +594,10 @@ var _Maplibre = class {
|
|
|
607
594
|
}
|
|
608
595
|
/* Update interaction handlers to match props */
|
|
609
596
|
_updateHandlers(nextProps, currProps) {
|
|
610
|
-
var _a, _b;
|
|
611
597
|
const map = this._map;
|
|
612
598
|
for (const propName of handlerNames) {
|
|
613
|
-
const newValue =
|
|
614
|
-
const oldValue =
|
|
599
|
+
const newValue = nextProps[propName] ?? true;
|
|
600
|
+
const oldValue = currProps[propName] ?? true;
|
|
615
601
|
if (!deepEqual(newValue, oldValue)) {
|
|
616
602
|
if (newValue) {
|
|
617
603
|
map[propName].enable(newValue);
|
|
@@ -628,17 +614,16 @@ var _Maplibre = class {
|
|
|
628
614
|
return map.queryRenderedFeatures(point, {
|
|
629
615
|
layers: interactiveLayerIds.filter(map.getLayer.bind(map))
|
|
630
616
|
});
|
|
631
|
-
} catch
|
|
617
|
+
} catch {
|
|
632
618
|
return [];
|
|
633
619
|
}
|
|
634
620
|
}
|
|
635
621
|
_updateHover(e) {
|
|
636
|
-
var _a;
|
|
637
622
|
const { props } = this;
|
|
638
623
|
const shouldTrackHoveredFeatures = props.interactiveLayerIds && (props.onMouseMove || props.onMouseEnter || props.onMouseLeave);
|
|
639
624
|
if (shouldTrackHoveredFeatures) {
|
|
640
625
|
const eventType = e.type;
|
|
641
|
-
const wasHovering =
|
|
626
|
+
const wasHovering = this._hoveredFeatures?.length > 0;
|
|
642
627
|
const features = this._queryRenderedFeatures(e.point);
|
|
643
628
|
const isHovering = features.length > 0;
|
|
644
629
|
if (!isHovering && wasHovering) {
|
|
@@ -656,8 +641,6 @@ var _Maplibre = class {
|
|
|
656
641
|
}
|
|
657
642
|
}
|
|
658
643
|
};
|
|
659
|
-
var Maplibre = _Maplibre;
|
|
660
|
-
Maplibre.savedMaps = [];
|
|
661
644
|
|
|
662
645
|
// src/maplibre/create-ref.ts
|
|
663
646
|
var skipMethods = [
|
|
@@ -773,7 +756,7 @@ function useControl(onCreate, arg1, arg2, arg3) {
|
|
|
773
756
|
const onRemove = typeof arg2 === "function" ? arg2 : typeof arg1 === "function" ? arg1 : null;
|
|
774
757
|
const { map } = context;
|
|
775
758
|
if (!map.hasControl(ctrl)) {
|
|
776
|
-
map.addControl(ctrl, opts
|
|
759
|
+
map.addControl(ctrl, opts?.position);
|
|
777
760
|
if (onAdd) {
|
|
778
761
|
onAdd(context);
|
|
779
762
|
}
|
|
@@ -792,23 +775,36 @@ function useControl(onCreate, arg1, arg2, arg3) {
|
|
|
792
775
|
|
|
793
776
|
// src/components/logo-control.ts
|
|
794
777
|
function _LogoControl(props) {
|
|
795
|
-
const ctrl = useControl(
|
|
796
|
-
|
|
797
|
-
|
|
778
|
+
const ctrl = useControl(
|
|
779
|
+
() => {
|
|
780
|
+
const control = {
|
|
781
|
+
onAdd: (map) => {
|
|
782
|
+
if (map.getContainer) {
|
|
783
|
+
const existingLogo = map.getContainer().querySelector('a.maplibregl-ctrl-logo[href="https://www.barikoi.com"]');
|
|
784
|
+
if (existingLogo) {
|
|
785
|
+
existingLogo.remove();
|
|
786
|
+
}
|
|
787
|
+
}
|
|
788
|
+
const container = document.createElement("a");
|
|
789
|
+
container.className = "maplibregl-ctrl-logo";
|
|
790
|
+
container.href = "https://www.barikoi.com";
|
|
791
|
+
container.target = "_blank";
|
|
792
|
+
container.setAttribute("alt", "Barikoi");
|
|
793
|
+
container.setAttribute("aria-label", "Barikoi logo");
|
|
794
|
+
container.setAttribute("rel", "noopener nofollow");
|
|
795
|
+
control._container = container;
|
|
796
|
+
return container;
|
|
797
|
+
},
|
|
798
|
+
onRemove: () => {
|
|
799
|
+
delete control._container;
|
|
800
|
+
}
|
|
801
|
+
};
|
|
802
|
+
return control;
|
|
803
|
+
},
|
|
804
|
+
{ position: props.position }
|
|
805
|
+
);
|
|
798
806
|
(0, import_react4.useEffect)(() => {
|
|
799
|
-
var _a;
|
|
800
807
|
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
808
|
}, [props.style, ctrl._container]);
|
|
813
809
|
return null;
|
|
814
810
|
}
|
|
@@ -817,15 +813,36 @@ var LogoControl = (0, import_react4.memo)(_LogoControl);
|
|
|
817
813
|
// src/components/attribution-control.ts
|
|
818
814
|
var import_react5 = require("react");
|
|
819
815
|
function _AttributionControl(props) {
|
|
816
|
+
const { current: map } = useMap();
|
|
820
817
|
const ctrl = useControl(
|
|
821
|
-
({ mapLib }) => new mapLib.AttributionControl(
|
|
818
|
+
({ mapLib }) => new mapLib.AttributionControl({
|
|
819
|
+
compact: true,
|
|
820
|
+
...props
|
|
821
|
+
}),
|
|
822
822
|
{ position: props.position }
|
|
823
823
|
);
|
|
824
824
|
(0, import_react5.useEffect)(() => {
|
|
825
825
|
applyReactStyle(ctrl._container, props.style);
|
|
826
|
-
if (!ctrl._container)
|
|
827
|
-
|
|
828
|
-
|
|
826
|
+
if (!ctrl._container || !map) return;
|
|
827
|
+
const onLoad = () => {
|
|
828
|
+
setTimeout(() => {
|
|
829
|
+
const inner = ctrl._container.querySelector(
|
|
830
|
+
".maplibregl-ctrl-attrib-inner"
|
|
831
|
+
);
|
|
832
|
+
if (inner) {
|
|
833
|
+
inner.innerHTML = '\xA9 <a href="https://barikoi.com" target="_blank">Barikoi</a> \xA9 <a href="https://openmaptiles.org" target="_blank">OpenMapTiles</a> \xA9 <a href="https://www.openstreetmap.org/copyright" target="_blank">OpenStreetMap contributors</a>';
|
|
834
|
+
}
|
|
835
|
+
}, 0);
|
|
836
|
+
};
|
|
837
|
+
if (map.loaded()) {
|
|
838
|
+
onLoad();
|
|
839
|
+
} else {
|
|
840
|
+
map.once("load", onLoad);
|
|
841
|
+
}
|
|
842
|
+
return () => {
|
|
843
|
+
map.off("load", onLoad);
|
|
844
|
+
};
|
|
845
|
+
}, [props.style, ctrl._container, map]);
|
|
829
846
|
return null;
|
|
830
847
|
}
|
|
831
848
|
var AttributionControl = (0, import_react5.memo)(_AttributionControl);
|
|
@@ -862,17 +879,18 @@ function _Map(props, ref) {
|
|
|
862
879
|
if (!maplibre) {
|
|
863
880
|
maplibre = new Maplibre(
|
|
864
881
|
mapboxgl.Map,
|
|
865
|
-
|
|
866
|
-
|
|
882
|
+
{
|
|
883
|
+
...props,
|
|
884
|
+
// @ts-ignore - attributionControl is not in the type definition but is supported by maplibre-gl
|
|
867
885
|
attributionControl: false
|
|
868
|
-
}
|
|
886
|
+
},
|
|
869
887
|
containerRef.current
|
|
870
888
|
);
|
|
871
889
|
}
|
|
872
890
|
contextValue.map = createRef(maplibre);
|
|
873
891
|
contextValue.mapLib = mapboxgl;
|
|
874
892
|
setMapInstance(maplibre);
|
|
875
|
-
mountedMapsContext
|
|
893
|
+
mountedMapsContext?.onMapMount(contextValue.map, props.id);
|
|
876
894
|
}).catch((error) => {
|
|
877
895
|
const { onError } = props;
|
|
878
896
|
if (onError) {
|
|
@@ -889,7 +907,7 @@ function _Map(props, ref) {
|
|
|
889
907
|
return () => {
|
|
890
908
|
isMounted = false;
|
|
891
909
|
if (maplibre) {
|
|
892
|
-
mountedMapsContext
|
|
910
|
+
mountedMapsContext?.onMapUnmount(props.id);
|
|
893
911
|
if (props.reuseMaps) {
|
|
894
912
|
maplibre.recycle();
|
|
895
913
|
} else {
|
|
@@ -905,11 +923,12 @@ function _Map(props, ref) {
|
|
|
905
923
|
});
|
|
906
924
|
(0, import_react6.useImperativeHandle)(ref, () => contextValue.map, [mapInstance]);
|
|
907
925
|
const style = (0, import_react6.useMemo)(
|
|
908
|
-
() =>
|
|
926
|
+
() => ({
|
|
909
927
|
position: "relative",
|
|
910
928
|
width: "100%",
|
|
911
|
-
height: "100%"
|
|
912
|
-
|
|
929
|
+
height: "100%",
|
|
930
|
+
...props.style
|
|
931
|
+
}),
|
|
913
932
|
[props.style]
|
|
914
933
|
);
|
|
915
934
|
const CHILD_CONTAINER_STYLE = {
|
|
@@ -960,36 +979,33 @@ var Marker = (0, import_react7.memo)(
|
|
|
960
979
|
hasChildren = true;
|
|
961
980
|
}
|
|
962
981
|
});
|
|
963
|
-
const options =
|
|
982
|
+
const options = {
|
|
983
|
+
...props,
|
|
964
984
|
element: hasChildren ? document.createElement("div") : void 0
|
|
965
|
-
}
|
|
985
|
+
};
|
|
966
986
|
const mk = new mapLib.Marker(options);
|
|
967
987
|
mk.setLngLat([props.longitude, props.latitude]);
|
|
968
988
|
mk.getElement().addEventListener("click", (e) => {
|
|
969
|
-
|
|
970
|
-
(_b = (_a = thisRef.current.props).onClick) == null ? void 0 : _b.call(_a, {
|
|
989
|
+
thisRef.current.props.onClick?.({
|
|
971
990
|
type: "click",
|
|
972
991
|
target: mk,
|
|
973
992
|
originalEvent: e
|
|
974
993
|
});
|
|
975
994
|
});
|
|
976
995
|
mk.on("dragstart", (e) => {
|
|
977
|
-
var _a, _b;
|
|
978
996
|
const evt = e;
|
|
979
997
|
evt.lngLat = marker.getLngLat();
|
|
980
|
-
|
|
998
|
+
thisRef.current.props.onDragStart?.(evt);
|
|
981
999
|
});
|
|
982
1000
|
mk.on("drag", (e) => {
|
|
983
|
-
var _a, _b;
|
|
984
1001
|
const evt = e;
|
|
985
1002
|
evt.lngLat = marker.getLngLat();
|
|
986
|
-
|
|
1003
|
+
thisRef.current.props.onDrag?.(evt);
|
|
987
1004
|
});
|
|
988
1005
|
mk.on("dragend", (e) => {
|
|
989
|
-
var _a, _b;
|
|
990
1006
|
const evt = e;
|
|
991
1007
|
evt.lngLat = marker.getLngLat();
|
|
992
|
-
|
|
1008
|
+
thisRef.current.props.onDragEnd?.(evt);
|
|
993
1009
|
});
|
|
994
1010
|
return mk;
|
|
995
1011
|
}, []);
|
|
@@ -1061,19 +1077,17 @@ var Popup = (0, import_react8.memo)(
|
|
|
1061
1077
|
}, []);
|
|
1062
1078
|
const thisRef = (0, import_react8.useRef)({ props });
|
|
1063
1079
|
const popup = (0, import_react8.useMemo)(() => {
|
|
1064
|
-
const options =
|
|
1080
|
+
const options = { ...props };
|
|
1065
1081
|
const pp = new mapLib.Popup(options);
|
|
1066
1082
|
pp.setLngLat([props.longitude, props.latitude]);
|
|
1067
1083
|
pp.once("open", (e) => {
|
|
1068
|
-
|
|
1069
|
-
(_b = (_a = thisRef.current.props).onOpen) == null ? void 0 : _b.call(_a, e);
|
|
1084
|
+
thisRef.current.props.onOpen?.(e);
|
|
1070
1085
|
});
|
|
1071
1086
|
return pp;
|
|
1072
1087
|
}, []);
|
|
1073
1088
|
(0, import_react8.useEffect)(() => {
|
|
1074
1089
|
const onClose = (e) => {
|
|
1075
|
-
|
|
1076
|
-
(_b = (_a = thisRef.current.props).onClose) == null ? void 0 : _b.call(_a, e);
|
|
1090
|
+
thisRef.current.props.onClose?.(e);
|
|
1077
1091
|
};
|
|
1078
1092
|
popup.on("close", onClose);
|
|
1079
1093
|
popup.setDOMContent(container).addTo(map.getMap());
|
|
@@ -1145,24 +1159,19 @@ function _GeolocateControl(props, ref) {
|
|
|
1145
1159
|
}
|
|
1146
1160
|
};
|
|
1147
1161
|
gc.on("geolocate", (e) => {
|
|
1148
|
-
|
|
1149
|
-
(_b = (_a = thisRef.current.props).onGeolocate) == null ? void 0 : _b.call(_a, e);
|
|
1162
|
+
thisRef.current.props.onGeolocate?.(e);
|
|
1150
1163
|
});
|
|
1151
1164
|
gc.on("error", (e) => {
|
|
1152
|
-
|
|
1153
|
-
(_b = (_a = thisRef.current.props).onError) == null ? void 0 : _b.call(_a, e);
|
|
1165
|
+
thisRef.current.props.onError?.(e);
|
|
1154
1166
|
});
|
|
1155
1167
|
gc.on("outofmaxbounds", (e) => {
|
|
1156
|
-
|
|
1157
|
-
(_b = (_a = thisRef.current.props).onOutOfMaxBounds) == null ? void 0 : _b.call(_a, e);
|
|
1168
|
+
thisRef.current.props.onOutOfMaxBounds?.(e);
|
|
1158
1169
|
});
|
|
1159
1170
|
gc.on("trackuserlocationstart", (e) => {
|
|
1160
|
-
|
|
1161
|
-
(_b = (_a = thisRef.current.props).onTrackUserLocationStart) == null ? void 0 : _b.call(_a, e);
|
|
1171
|
+
thisRef.current.props.onTrackUserLocationStart?.(e);
|
|
1162
1172
|
});
|
|
1163
1173
|
gc.on("trackuserlocationend", (e) => {
|
|
1164
|
-
|
|
1165
|
-
(_b = (_a = thisRef.current.props).onTrackUserLocationEnd) == null ? void 0 : _b.call(_a, e);
|
|
1174
|
+
thisRef.current.props.onTrackUserLocationEnd?.(e);
|
|
1166
1175
|
});
|
|
1167
1176
|
return gc;
|
|
1168
1177
|
},
|
|
@@ -1243,7 +1252,7 @@ function assert(condition, message) {
|
|
|
1243
1252
|
var sourceCounter = 0;
|
|
1244
1253
|
function createSource(map, id, props) {
|
|
1245
1254
|
if (map.style && map.style._loaded) {
|
|
1246
|
-
const options =
|
|
1255
|
+
const options = { ...props };
|
|
1247
1256
|
delete options.id;
|
|
1248
1257
|
delete options.children;
|
|
1249
1258
|
map.addSource(id, options);
|
|
@@ -1252,7 +1261,6 @@ function createSource(map, id, props) {
|
|
|
1252
1261
|
return null;
|
|
1253
1262
|
}
|
|
1254
1263
|
function updateSource(source, props, prevProps) {
|
|
1255
|
-
var _a, _b, _c;
|
|
1256
1264
|
assert(props.id === prevProps.id, "source id changed");
|
|
1257
1265
|
assert(props.type === prevProps.type, "source type changed");
|
|
1258
1266
|
let changedKey = "";
|
|
@@ -1277,13 +1285,13 @@ function updateSource(source, props, prevProps) {
|
|
|
1277
1285
|
} else {
|
|
1278
1286
|
switch (changedKey) {
|
|
1279
1287
|
case "coordinates":
|
|
1280
|
-
|
|
1288
|
+
source.setCoordinates?.(props.coordinates);
|
|
1281
1289
|
break;
|
|
1282
1290
|
case "url":
|
|
1283
|
-
|
|
1291
|
+
source.setUrl?.(props.url);
|
|
1284
1292
|
break;
|
|
1285
1293
|
case "tiles":
|
|
1286
|
-
|
|
1294
|
+
source.setTiles?.(props.tiles);
|
|
1287
1295
|
break;
|
|
1288
1296
|
default:
|
|
1289
1297
|
console.warn(`Unable to update <Source> prop: ${changedKey}`);
|
|
@@ -1301,10 +1309,9 @@ function Source(props) {
|
|
|
1301
1309
|
map.on("styledata", forceUpdate);
|
|
1302
1310
|
forceUpdate();
|
|
1303
1311
|
return () => {
|
|
1304
|
-
var _a;
|
|
1305
1312
|
map.off("styledata", forceUpdate);
|
|
1306
1313
|
if (map.style && map.style._loaded && map.getSource(id)) {
|
|
1307
|
-
const allLayers =
|
|
1314
|
+
const allLayers = map.getStyle()?.layers;
|
|
1308
1315
|
if (allLayers) {
|
|
1309
1316
|
for (const layer of allLayers) {
|
|
1310
1317
|
if (layer.source === id) {
|
|
@@ -1353,7 +1360,7 @@ function updateLayer(map, id, props, prevProps) {
|
|
|
1353
1360
|
}
|
|
1354
1361
|
}
|
|
1355
1362
|
for (const key in prevLayout) {
|
|
1356
|
-
if (!
|
|
1363
|
+
if (!Object.prototype.hasOwnProperty.call(layout, key)) {
|
|
1357
1364
|
map.setLayoutProperty(id, key, void 0);
|
|
1358
1365
|
}
|
|
1359
1366
|
}
|
|
@@ -1366,7 +1373,7 @@ function updateLayer(map, id, props, prevProps) {
|
|
|
1366
1373
|
}
|
|
1367
1374
|
}
|
|
1368
1375
|
for (const key in prevPaint) {
|
|
1369
|
-
if (!
|
|
1376
|
+
if (!Object.prototype.hasOwnProperty.call(paint, key)) {
|
|
1370
1377
|
map.setPaintProperty(id, key, void 0);
|
|
1371
1378
|
}
|
|
1372
1379
|
}
|
|
@@ -1380,7 +1387,7 @@ function updateLayer(map, id, props, prevProps) {
|
|
|
1380
1387
|
}
|
|
1381
1388
|
function createLayer(map, id, props) {
|
|
1382
1389
|
if (map.style && map.style._loaded && (!("source" in props) || map.getSource(props.source))) {
|
|
1383
|
-
const options =
|
|
1390
|
+
const options = { ...props, id };
|
|
1384
1391
|
delete options.beforeId;
|
|
1385
1392
|
map.addLayer(options, props.beforeId);
|
|
1386
1393
|
}
|
|
@@ -1421,3 +1428,22 @@ function Layer(props) {
|
|
|
1421
1428
|
|
|
1422
1429
|
// src/exports-maplibre-gl.ts
|
|
1423
1430
|
var exports_maplibre_gl_default = Map;
|
|
1431
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
1432
|
+
0 && (module.exports = {
|
|
1433
|
+
AttributionControl,
|
|
1434
|
+
FullscreenControl,
|
|
1435
|
+
GeolocateControl,
|
|
1436
|
+
Layer,
|
|
1437
|
+
LogoControl,
|
|
1438
|
+
Map,
|
|
1439
|
+
MapProvider,
|
|
1440
|
+
Marker,
|
|
1441
|
+
NavigationControl,
|
|
1442
|
+
Popup,
|
|
1443
|
+
ScaleControl,
|
|
1444
|
+
Source,
|
|
1445
|
+
TerrainControl,
|
|
1446
|
+
useControl,
|
|
1447
|
+
useMap
|
|
1448
|
+
});
|
|
1449
|
+
//# sourceMappingURL=index.cjs.map
|