@studiometa/ui-mapbox 0.0.1 → 1.10.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AbstractMapboxControl.d.ts +53 -0
- package/AbstractMapboxControl.js +70 -0
- package/AbstractMapboxControl.js.map +1 -0
- package/AbstractMapboxMapChild.d.ts +229 -0
- package/AbstractMapboxMapChild.js +336 -0
- package/AbstractMapboxMapChild.js.map +1 -0
- package/LICENSE.md +110 -0
- package/MapboxCluster.d.ts +208 -0
- package/MapboxCluster.js +418 -0
- package/MapboxCluster.js.map +1 -0
- package/MapboxClusterItem.d.ts +130 -0
- package/MapboxClusterItem.js +182 -0
- package/MapboxClusterItem.js.map +1 -0
- package/MapboxFullscreenControl.d.ts +21 -0
- package/MapboxFullscreenControl.js +21 -0
- package/MapboxFullscreenControl.js.map +1 -0
- package/MapboxGeocoder.d.ts +64 -0
- package/MapboxGeocoder.js +80 -0
- package/MapboxGeocoder.js.map +1 -0
- package/MapboxGeolocateControl.d.ts +23 -0
- package/MapboxGeolocateControl.js +31 -0
- package/MapboxGeolocateControl.js.map +1 -0
- package/MapboxImage.d.ts +49 -0
- package/MapboxImage.js +83 -0
- package/MapboxImage.js.map +1 -0
- package/MapboxImages.d.ts +66 -0
- package/MapboxImages.js +95 -0
- package/MapboxImages.js.map +1 -0
- package/MapboxLayer.d.ts +99 -0
- package/MapboxLayer.js +148 -0
- package/MapboxLayer.js.map +1 -0
- package/MapboxMap.d.ts +64 -0
- package/MapboxMap.js +131 -0
- package/MapboxMap.js.map +1 -0
- package/MapboxMarker.d.ts +56 -0
- package/MapboxMarker.js +73 -0
- package/MapboxMarker.js.map +1 -0
- package/MapboxNavigationControl.d.ts +27 -0
- package/MapboxNavigationControl.js +28 -0
- package/MapboxNavigationControl.js.map +1 -0
- package/MapboxPopup.d.ts +51 -0
- package/MapboxPopup.js +76 -0
- package/MapboxPopup.js.map +1 -0
- package/MapboxSource.d.ts +68 -0
- package/MapboxSource.js +104 -0
- package/MapboxSource.js.map +1 -0
- package/README.md +85 -0
- package/StoreLocator.d.ts +323 -0
- package/StoreLocator.js +538 -0
- package/StoreLocator.js.map +1 -0
- package/catalog.d.ts +7 -0
- package/catalog.js +68 -0
- package/catalog.js.map +1 -0
- package/dependencies.d.ts +85 -0
- package/dependencies.js +84 -0
- package/dependencies.js.map +1 -0
- package/index.d.ts +18 -0
- package/index.js +19 -0
- package/index.js.map +1 -0
- package/manifest.d.ts +6 -0
- package/manifest.js +133 -0
- package/manifest.js.map +1 -0
- package/package.json +43 -3
- package/utils.d.ts +112 -0
- package/utils.js +143 -0
- package/utils.js.map +1 -0
- package/Claude-of-Duty/node_modules/@esbuild/darwin-arm64/bin/esbuild +0 -0
- package/alfred-projects-cache.tsv +0 -137
- package/claude-501/-Users-titouanmathis--dotfiles/298a49f7-c4b3-4a50-9707-a9c0d0733e95/scratchpad/pptest/config.json +0 -1
- package/claude-501/-Users-titouanmathis--dotfiles/298a49f7-c4b3-4a50-9707-a9c0d0733e95/scratchpad/pptest/stub/herdr +0 -8
- package/claude-501/-Users-titouanmathis--dotfiles/7d127a50-a71a-411a-bc1f-15b070f909f9/tasks/bg1cckto6.output +0 -4
- package/claude-501/-Users-titouanmathis--dotfiles/dd4cd328-df52-4522-a502-48fa24b7b142/scratchpad/after.toml +0 -298
- package/claude-501/-Users-titouanmathis--dotfiles/dd4cd328-df52-4522-a502-48fa24b7b142/scratchpad/before.toml +0 -298
- package/claude-501/-Users-titouanmathis--dotfiles/dd4cd328-df52-4522-a502-48fa24b7b142/scratchpad/extracted.txt +0 -36
- package/claude-501/-Users-titouanmathis--dotfiles/dd4cd328-df52-4522-a502-48fa24b7b142/scratchpad/final.log +0 -496
- package/claude-501/-Users-titouanmathis--dotfiles/dd4cd328-df52-4522-a502-48fa24b7b142/scratchpad/guard.sh +0 -18
- package/claude-501/-Users-titouanmathis--dotfiles/dd4cd328-df52-4522-a502-48fa24b7b142/scratchpad/lock.check +0 -917
- package/claude-501/-Users-titouanmathis--dotfiles/dd4cd328-df52-4522-a502-48fa24b7b142/scratchpad/mise-registry.json +0 -3827
- package/claude-501/-Users-titouanmathis--dotfiles/dd4cd328-df52-4522-a502-48fa24b7b142/scratchpad/mise.lock.before +0 -917
- package/claude-501/-Users-titouanmathis--dotfiles/dd4cd328-df52-4522-a502-48fa24b7b142/scratchpad/misetest/.config/mise/conf.d/extra.toml +0 -2
- package/claude-501/-Users-titouanmathis--dotfiles/dd4cd328-df52-4522-a502-48fa24b7b142/scratchpad/misetest/.config/mise/mise.lock +0 -47
- package/claude-501/-Users-titouanmathis--dotfiles/dd4cd328-df52-4522-a502-48fa24b7b142/scratchpad/misetest/mise.lock +0 -47
- package/claude-501/-Users-titouanmathis--dotfiles/dd4cd328-df52-4522-a502-48fa24b7b142/scratchpad/misetest/mise.toml +0 -2
- package/claude-501/-Users-titouanmathis--dotfiles/dd4cd328-df52-4522-a502-48fa24b7b142/scratchpad/probe/.github/workflows/mise-check.yml +0 -188
- package/claude-501/-Users-titouanmathis--dotfiles/dd4cd328-df52-4522-a502-48fa24b7b142/scratchpad/probe/.github/workflows/renovate.yml +0 -62
- package/claude-501/-Users-titouanmathis--dotfiles/dd4cd328-df52-4522-a502-48fa24b7b142/scratchpad/probe/mise.lock +0 -917
- package/claude-501/-Users-titouanmathis--dotfiles/dd4cd328-df52-4522-a502-48fa24b7b142/scratchpad/probe/mise.toml +0 -291
- package/claude-501/-Users-titouanmathis--dotfiles/dd4cd328-df52-4522-a502-48fa24b7b142/scratchpad/probe/probe.log +0 -4974
- package/claude-501/-Users-titouanmathis--dotfiles/dd4cd328-df52-4522-a502-48fa24b7b142/scratchpad/probe/probe2.log +0 -22
- package/claude-501/-Users-titouanmathis--dotfiles/dd4cd328-df52-4522-a502-48fa24b7b142/scratchpad/probe/probe3.log +0 -4916
- package/claude-501/-Users-titouanmathis--dotfiles/dd4cd328-df52-4522-a502-48fa24b7b142/scratchpad/probe/renovate.json +0 -62
- package/claude-501/-Users-titouanmathis--dotfiles/dd4cd328-df52-4522-a502-48fa24b7b142/scratchpad/renovate-local.log +0 -670
- package/claude-501/-Users-titouanmathis--dotfiles/dd4cd328-df52-4522-a502-48fa24b7b142/scratchpad/symtest/link/mise.lock +0 -47
- package/claude-501/-Users-titouanmathis--dotfiles/dd4cd328-df52-4522-a502-48fa24b7b142/scratchpad/symtest/real/source.toml +0 -4
- package/claude-501/-Users-titouanmathis-Lab--studiometa-automations/d6c27f69-577a-468b-9bb3-a45c03a66143/scratchpad/cookie.txt +0 -1
- package/gitlab-docs-read.md +0 -8
- package/gitlab-instance-limits.txt +0 -8
- package/piab-501/piab-devops-019fcbcc991d-59c77b27-fresh-47da8bd318.config +0 -1
- package/pins-new.txt +0 -36
- package/pins-old.txt +0 -36
- package/reply +0 -0
- package/zsh0IBbcP +0 -0
- package/zsh2LqT39 +0 -0
- package/zsh6KJGTP +0 -0
- package/zshN1hNdy +0 -0
- package/zshNjWSYH +0 -11
- package/zshNvB745 +0 -0
- package/zshOXC0uH +0 -0
- package/zshPG9CFU +0 -0
- package/zshVOeZsK +0 -0
- package/zshVqIgQS +0 -0
- package/zshXTrFg8 +0 -0
- package/zshaUGubs +0 -11
- package/zshbzOT6d +0 -1
- package/zshnbtbGK +0 -0
- package/zshpQi1EI +0 -2
- package/zshwhMjOD +0 -1
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { AbstractMapboxMapChild, AbstractMapboxMapChildProps } from "./AbstractMapboxMapChild.js";
|
|
2
|
+
import { MapboxPopup } from "./MapboxPopup.js";
|
|
3
|
+
import { BaseConfig, BaseProps } from "@studiometa/js-toolkit";
|
|
4
|
+
import { Marker, MarkerOptions } from "mapbox-gl";
|
|
5
|
+
|
|
6
|
+
//#region MapboxMarker.d.ts
|
|
7
|
+
interface MapboxMarkerProps extends AbstractMapboxMapChildProps {
|
|
8
|
+
$options: {
|
|
9
|
+
lngLat: [number, number];
|
|
10
|
+
markerOptions: MarkerOptions;
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Add a marker to Mapbox map.
|
|
15
|
+
* @see https://ui.studiometa.dev/reference/items/MapboxMap/
|
|
16
|
+
*/
|
|
17
|
+
declare class MapboxMarker<T extends BaseProps = BaseProps> extends AbstractMapboxMapChild<T & MapboxMarkerProps> {
|
|
18
|
+
/**
|
|
19
|
+
* Config.
|
|
20
|
+
*/
|
|
21
|
+
static config: BaseConfig;
|
|
22
|
+
/**
|
|
23
|
+
* Marker instance.
|
|
24
|
+
* @private
|
|
25
|
+
*/
|
|
26
|
+
__marker: Marker;
|
|
27
|
+
/**
|
|
28
|
+
* The mapbox Marker instance.
|
|
29
|
+
*/
|
|
30
|
+
get marker(): Marker;
|
|
31
|
+
/**
|
|
32
|
+
* The optional child popup component instance.
|
|
33
|
+
*/
|
|
34
|
+
get popup(): MapboxPopup<BaseProps>;
|
|
35
|
+
/**
|
|
36
|
+
* Attach a child `MapboxPopup`'s popup to this marker.
|
|
37
|
+
*
|
|
38
|
+
* Called from either side of the wiring, whichever mounts last: the marker
|
|
39
|
+
* pulls its child popup on ready, and the popup pushes itself here when it
|
|
40
|
+
* mounts after the marker (a dynamic append to an already-loaded map, where
|
|
41
|
+
* the marker mounted first and found no popup to query yet). Setting the same
|
|
42
|
+
* popup twice is idempotent.
|
|
43
|
+
* @param {MapboxPopup} popupComponent
|
|
44
|
+
*/
|
|
45
|
+
setChildPopup(popupComponent: MapboxPopup): void;
|
|
46
|
+
/**
|
|
47
|
+
* Mounted hook.
|
|
48
|
+
*/
|
|
49
|
+
mounted(): void;
|
|
50
|
+
/**
|
|
51
|
+
* Teardown hook.
|
|
52
|
+
*/
|
|
53
|
+
__onDestroyed(): void;
|
|
54
|
+
}
|
|
55
|
+
//#endregion
|
|
56
|
+
export { MapboxMarker, MapboxMarker as default, MapboxMarkerProps };
|
package/MapboxMarker.js
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { AbstractMapboxMapChild } from "./AbstractMapboxMapChild.js";
|
|
2
|
+
import { getMapboxGl } from "./dependencies.js";
|
|
3
|
+
//#region MapboxMarker.ts
|
|
4
|
+
/**
|
|
5
|
+
* Add a marker to Mapbox map.
|
|
6
|
+
* @see https://ui.studiometa.dev/reference/items/MapboxMap/
|
|
7
|
+
*/
|
|
8
|
+
var MapboxMarker = class extends AbstractMapboxMapChild {
|
|
9
|
+
/**
|
|
10
|
+
* Config.
|
|
11
|
+
*/
|
|
12
|
+
static config = {
|
|
13
|
+
name: "MapboxMarker",
|
|
14
|
+
options: {
|
|
15
|
+
lngLat: {
|
|
16
|
+
type: Array,
|
|
17
|
+
default: () => [0, 0]
|
|
18
|
+
},
|
|
19
|
+
markerOptions: Object
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* Marker instance.
|
|
24
|
+
* @private
|
|
25
|
+
*/
|
|
26
|
+
__marker;
|
|
27
|
+
/**
|
|
28
|
+
* The mapbox Marker instance.
|
|
29
|
+
*/
|
|
30
|
+
get marker() {
|
|
31
|
+
if (!this.__marker) this.__marker = new (getMapboxGl()).Marker(this.$options.markerOptions);
|
|
32
|
+
return this.__marker;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* The optional child popup component instance.
|
|
36
|
+
*/
|
|
37
|
+
get popup() {
|
|
38
|
+
return this.$query("MapboxPopup")[0];
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Attach a child `MapboxPopup`'s popup to this marker.
|
|
42
|
+
*
|
|
43
|
+
* Called from either side of the wiring, whichever mounts last: the marker
|
|
44
|
+
* pulls its child popup on ready, and the popup pushes itself here when it
|
|
45
|
+
* mounts after the marker (a dynamic append to an already-loaded map, where
|
|
46
|
+
* the marker mounted first and found no popup to query yet). Setting the same
|
|
47
|
+
* popup twice is idempotent.
|
|
48
|
+
* @param {MapboxPopup} popupComponent
|
|
49
|
+
*/
|
|
50
|
+
setChildPopup(popupComponent) {
|
|
51
|
+
this.marker.setPopup(popupComponent.popup);
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Mounted hook.
|
|
55
|
+
*/
|
|
56
|
+
mounted() {
|
|
57
|
+
this.whenMapReady((map) => {
|
|
58
|
+
this.marker.setLngLat(this.$options.lngLat).addTo(map);
|
|
59
|
+
if (this.popup) this.setChildPopup(this.popup);
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Teardown hook.
|
|
64
|
+
*/
|
|
65
|
+
__onDestroyed() {
|
|
66
|
+
this.__marker?.remove();
|
|
67
|
+
this.__marker = void 0;
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
//#endregion
|
|
71
|
+
export { MapboxMarker, MapboxMarker as default };
|
|
72
|
+
|
|
73
|
+
//# sourceMappingURL=MapboxMarker.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MapboxMarker.js","names":[],"sources":["../MapboxMarker.ts"],"sourcesContent":["import { type BaseProps, type BaseConfig } from '@studiometa/js-toolkit';\nimport type { Marker, MarkerOptions } from 'mapbox-gl';\nimport {\n AbstractMapboxMapChild,\n type AbstractMapboxMapChildProps,\n} from './AbstractMapboxMapChild.js';\nimport { getMapboxGl } from './dependencies.js';\nimport { MapboxPopup } from './MapboxPopup.js';\n\nexport interface MapboxMarkerProps extends AbstractMapboxMapChildProps {\n $options: {\n lngLat: [number, number];\n markerOptions: MarkerOptions;\n };\n}\n\n/**\n * Add a marker to Mapbox map.\n * @see https://ui.studiometa.dev/reference/items/MapboxMap/\n */\nexport class MapboxMarker<T extends BaseProps = BaseProps> extends AbstractMapboxMapChild<\n T & MapboxMarkerProps\n> {\n /**\n * Config.\n */\n static config: BaseConfig = {\n name: 'MapboxMarker',\n options: {\n lngLat: {\n type: Array,\n default: () => [0, 0],\n },\n // Marker options. (https://docs.mapbox.com/mapbox-gl-js/api/markers#marker)\n markerOptions: Object,\n },\n };\n\n /**\n * Marker instance.\n * @private\n */\n __marker: Marker;\n\n /**\n * The mapbox Marker instance.\n */\n get marker() {\n if (!this.__marker) {\n this.__marker = new (getMapboxGl().Marker)(this.$options.markerOptions);\n }\n\n return this.__marker;\n }\n\n /**\n * The optional child popup component instance.\n */\n get popup() {\n return this.$query<MapboxPopup>('MapboxPopup')[0];\n }\n\n /**\n * Attach a child `MapboxPopup`'s popup to this marker.\n *\n * Called from either side of the wiring, whichever mounts last: the marker\n * pulls its child popup on ready, and the popup pushes itself here when it\n * mounts after the marker (a dynamic append to an already-loaded map, where\n * the marker mounted first and found no popup to query yet). Setting the same\n * popup twice is idempotent.\n * @param {MapboxPopup} popupComponent\n */\n setChildPopup(popupComponent: MapboxPopup) {\n this.marker.setPopup(popupComponent.popup);\n }\n\n /**\n * Mounted hook.\n */\n mounted() {\n this.whenMapReady((map) => {\n this.marker.setLngLat(this.$options.lngLat).addTo(map);\n\n // Pull the optional child popup if it has already mounted. When it mounts\n // *after* the marker instead (dynamic append), the popup pushes itself via\n // `setChildPopup`, so either mount order wires the pair.\n if (this.popup) {\n this.setChildPopup(this.popup);\n }\n });\n }\n\n /**\n * Teardown hook.\n */\n __onDestroyed() {\n this.__marker?.remove();\n this.__marker = undefined;\n }\n}\n\nexport default MapboxMarker;\n"],"mappings":";;;;;;;AAoBA,IAAa,eAAb,cAAmE,uBAEjE;;;;CAIA,OAAO,SAAqB;EAC1B,MAAM;EACN,SAAS;GACP,QAAQ;IACN,MAAM;IACN,eAAe,CAAC,GAAG,EAAE;IACtB;GAED,eAAe;GAChB;EACF;;;;;CAMD;;;;CAKA,IAAI,SAAS;AACX,MAAI,CAAC,KAAK,SACR,MAAK,WAAW,KAAK,aAAa,EAAC,OAAQ,KAAK,SAAS,cAAc;AAGzE,SAAO,KAAK;;;;;CAMd,IAAI,QAAQ;AACV,SAAO,KAAK,OAAoB,cAAc,CAAC;;;;;;;;;;;;CAajD,cAAc,gBAA6B;AACzC,OAAK,OAAO,SAAS,eAAe,MAAM;;;;;CAM5C,UAAU;AACR,OAAK,cAAc,QAAQ;AACzB,QAAK,OAAO,UAAU,KAAK,SAAS,OAAO,CAAC,MAAM,IAAI;AAKtD,OAAI,KAAK,MACP,MAAK,cAAc,KAAK,MAAM;IAEhC;;;;;CAMJ,gBAAgB;AACd,OAAK,UAAU,QAAQ;AACvB,OAAK,WAAW,KAAA"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { AbstractMapboxControlProps } from "./AbstractMapboxControl.js";
|
|
2
|
+
import * as _studiometa_js_toolkit0 from "@studiometa/js-toolkit";
|
|
3
|
+
import * as mapbox_gl0 from "mapbox-gl";
|
|
4
|
+
import { NavigationControlOptions } from "mapbox-gl";
|
|
5
|
+
|
|
6
|
+
//#region MapboxNavigationControl.d.ts
|
|
7
|
+
interface MapboxNavigationControlProps extends AbstractMapboxControlProps {
|
|
8
|
+
$options: AbstractMapboxControlProps['$options'] & {
|
|
9
|
+
showCompass: boolean;
|
|
10
|
+
showZoom: boolean;
|
|
11
|
+
visualizePitch: boolean;
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
declare const MapboxNavigationControl_base: _studiometa_js_toolkit0.BaseDecorator<_studiometa_js_toolkit0.BaseInterface, _studiometa_js_toolkit0.Base<_studiometa_js_toolkit0.BaseProps>>;
|
|
15
|
+
/**
|
|
16
|
+
* Add a navigation control to the map.
|
|
17
|
+
* @see https://ui.studiometa.dev/reference/items/MapboxMap/
|
|
18
|
+
*/
|
|
19
|
+
declare class MapboxNavigationControl extends MapboxNavigationControl_base {
|
|
20
|
+
/**
|
|
21
|
+
* Create the mapbox NavigationControl instance.
|
|
22
|
+
* @protected
|
|
23
|
+
*/
|
|
24
|
+
createControl(options: NavigationControlOptions): mapbox_gl0.NavigationControl;
|
|
25
|
+
}
|
|
26
|
+
//#endregion
|
|
27
|
+
export { MapboxNavigationControl, MapboxNavigationControl as default, MapboxNavigationControlProps };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { AbstractMapboxControl } from "./AbstractMapboxControl.js";
|
|
2
|
+
import { getMapboxGl } from "./dependencies.js";
|
|
3
|
+
import { withExtraConfig } from "@studiometa/js-toolkit";
|
|
4
|
+
//#region MapboxNavigationControl.ts
|
|
5
|
+
/**
|
|
6
|
+
* Add a navigation control to the map.
|
|
7
|
+
* @see https://ui.studiometa.dev/reference/items/MapboxMap/
|
|
8
|
+
*/
|
|
9
|
+
var MapboxNavigationControl = class extends withExtraConfig(AbstractMapboxControl, {
|
|
10
|
+
name: "MapboxNavigationControl",
|
|
11
|
+
options: {
|
|
12
|
+
showCompass: Boolean,
|
|
13
|
+
showZoom: Boolean,
|
|
14
|
+
visualizePitch: Boolean
|
|
15
|
+
}
|
|
16
|
+
}) {
|
|
17
|
+
/**
|
|
18
|
+
* Create the mapbox NavigationControl instance.
|
|
19
|
+
* @protected
|
|
20
|
+
*/
|
|
21
|
+
createControl(options) {
|
|
22
|
+
return new (getMapboxGl()).NavigationControl(options);
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
//#endregion
|
|
26
|
+
export { MapboxNavigationControl, MapboxNavigationControl as default };
|
|
27
|
+
|
|
28
|
+
//# sourceMappingURL=MapboxNavigationControl.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MapboxNavigationControl.js","names":[],"sources":["../MapboxNavigationControl.ts"],"sourcesContent":["import { withExtraConfig } from '@studiometa/js-toolkit';\nimport type { NavigationControlOptions } from 'mapbox-gl';\nimport {\n AbstractMapboxControl,\n type AbstractMapboxControlProps,\n} from './AbstractMapboxControl.js';\nimport { getMapboxGl } from './dependencies.js';\n\nexport interface MapboxNavigationControlProps extends AbstractMapboxControlProps {\n $options: AbstractMapboxControlProps['$options'] & {\n showCompass: boolean;\n showZoom: boolean;\n visualizePitch: boolean;\n };\n}\n\n/**\n * Add a navigation control to the map.\n * @see https://ui.studiometa.dev/reference/items/MapboxMap/\n */\nexport class MapboxNavigationControl extends withExtraConfig(AbstractMapboxControl, {\n name: 'MapboxNavigationControl',\n options: {\n showCompass: Boolean,\n showZoom: Boolean,\n visualizePitch: Boolean,\n },\n}) {\n /**\n * Create the mapbox NavigationControl instance.\n * @protected\n */\n createControl(options: NavigationControlOptions) {\n return new (getMapboxGl().NavigationControl)(options);\n }\n}\n\nexport default MapboxNavigationControl;\n"],"mappings":";;;;;;;;AAoBA,IAAa,0BAAb,cAA6C,gBAAgB,uBAAuB;CAClF,MAAM;CACN,SAAS;EACP,aAAa;EACb,UAAU;EACV,gBAAgB;EACjB;CACF,CAAC,CAAC;;;;;CAKD,cAAc,SAAmC;AAC/C,SAAO,KAAK,aAAa,EAAC,kBAAmB,QAAQ"}
|
package/MapboxPopup.d.ts
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { AbstractMapboxMapChild, AbstractMapboxMapChildProps } from "./AbstractMapboxMapChild.js";
|
|
2
|
+
import { BaseConfig, BaseProps } from "@studiometa/js-toolkit";
|
|
3
|
+
import { Popup, PopupOptions } from "mapbox-gl";
|
|
4
|
+
|
|
5
|
+
//#region MapboxPopup.d.ts
|
|
6
|
+
interface MapboxPopupProps extends AbstractMapboxMapChildProps {
|
|
7
|
+
$options: {
|
|
8
|
+
lngLat: [number, number];
|
|
9
|
+
/**
|
|
10
|
+
* Popup options.
|
|
11
|
+
* @see https://docs.mapbox.com/mapbox-gl-js/api/markers#popup
|
|
12
|
+
*/
|
|
13
|
+
popupOptions: PopupOptions;
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Display a popup on a MapboxMap map.
|
|
18
|
+
* @see https://ui.studiometa.dev/reference/items/MapboxMap
|
|
19
|
+
*/
|
|
20
|
+
declare class MapboxPopup<T extends BaseProps = BaseProps> extends AbstractMapboxMapChild<T & MapboxPopupProps> {
|
|
21
|
+
/**
|
|
22
|
+
* Config.
|
|
23
|
+
*/
|
|
24
|
+
static config: BaseConfig;
|
|
25
|
+
/**
|
|
26
|
+
* Popup instance.
|
|
27
|
+
* @private
|
|
28
|
+
*/
|
|
29
|
+
__popup: Popup;
|
|
30
|
+
/**
|
|
31
|
+
* Whether this component hid its own source element (to avoid rendering the
|
|
32
|
+
* content twice). Tracked so teardown restores the original visibility only
|
|
33
|
+
* when it was the one to change it.
|
|
34
|
+
* @private
|
|
35
|
+
*/
|
|
36
|
+
__didHide: boolean;
|
|
37
|
+
/**
|
|
38
|
+
* The mapbox Popup instance.
|
|
39
|
+
*/
|
|
40
|
+
get popup(): Popup;
|
|
41
|
+
/**
|
|
42
|
+
* Mounted hook.
|
|
43
|
+
*/
|
|
44
|
+
mounted(): void;
|
|
45
|
+
/**
|
|
46
|
+
* Teardown hook.
|
|
47
|
+
*/
|
|
48
|
+
__onDestroyed(): void;
|
|
49
|
+
}
|
|
50
|
+
//#endregion
|
|
51
|
+
export { MapboxPopup, MapboxPopup as default, MapboxPopupProps };
|
package/MapboxPopup.js
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { AbstractMapboxMapChild } from "./AbstractMapboxMapChild.js";
|
|
2
|
+
import { getMapboxGl } from "./dependencies.js";
|
|
3
|
+
//#region MapboxPopup.ts
|
|
4
|
+
/**
|
|
5
|
+
* Display a popup on a MapboxMap map.
|
|
6
|
+
* @see https://ui.studiometa.dev/reference/items/MapboxMap
|
|
7
|
+
*/
|
|
8
|
+
var MapboxPopup = class extends AbstractMapboxMapChild {
|
|
9
|
+
/**
|
|
10
|
+
* Config.
|
|
11
|
+
*/
|
|
12
|
+
static config = {
|
|
13
|
+
name: "MapboxPopup",
|
|
14
|
+
options: {
|
|
15
|
+
lngLat: {
|
|
16
|
+
type: Array,
|
|
17
|
+
default: () => [0, 0]
|
|
18
|
+
},
|
|
19
|
+
popupOptions: Object
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* Popup instance.
|
|
24
|
+
* @private
|
|
25
|
+
*/
|
|
26
|
+
__popup;
|
|
27
|
+
/**
|
|
28
|
+
* Whether this component hid its own source element (to avoid rendering the
|
|
29
|
+
* content twice). Tracked so teardown restores the original visibility only
|
|
30
|
+
* when it was the one to change it.
|
|
31
|
+
* @private
|
|
32
|
+
*/
|
|
33
|
+
__didHide = false;
|
|
34
|
+
/**
|
|
35
|
+
* The mapbox Popup instance.
|
|
36
|
+
*/
|
|
37
|
+
get popup() {
|
|
38
|
+
if (!this.__popup) this.__popup = new (getMapboxGl()).Popup(this.$options.popupOptions);
|
|
39
|
+
return this.__popup;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Mounted hook.
|
|
43
|
+
*/
|
|
44
|
+
mounted() {
|
|
45
|
+
this.whenMapReady((map) => {
|
|
46
|
+
const { popup, $el, $options } = this;
|
|
47
|
+
popup.setLngLat($options.lngLat);
|
|
48
|
+
const content = $el.innerHTML.trim();
|
|
49
|
+
if (content) {
|
|
50
|
+
popup.setHTML(content);
|
|
51
|
+
if (!$el.hidden) {
|
|
52
|
+
$el.hidden = true;
|
|
53
|
+
this.__didHide = true;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
const marker = this.$closest("MapboxMarker");
|
|
57
|
+
if (marker) marker.setChildPopup(this);
|
|
58
|
+
else popup.addTo(map);
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Teardown hook.
|
|
63
|
+
*/
|
|
64
|
+
__onDestroyed() {
|
|
65
|
+
this.__popup?.remove();
|
|
66
|
+
this.__popup = void 0;
|
|
67
|
+
if (this.__didHide) {
|
|
68
|
+
this.$el.hidden = false;
|
|
69
|
+
this.__didHide = false;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
//#endregion
|
|
74
|
+
export { MapboxPopup, MapboxPopup as default };
|
|
75
|
+
|
|
76
|
+
//# sourceMappingURL=MapboxPopup.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MapboxPopup.js","names":[],"sources":["../MapboxPopup.ts"],"sourcesContent":["import { type BaseConfig, type BaseProps } from '@studiometa/js-toolkit';\nimport type { Popup, PopupOptions } from 'mapbox-gl';\nimport {\n AbstractMapboxMapChild,\n type AbstractMapboxMapChildProps,\n} from './AbstractMapboxMapChild.js';\nimport { getMapboxGl } from './dependencies.js';\nimport type { MapboxMarker } from './MapboxMarker.js';\n\nexport interface MapboxPopupProps extends AbstractMapboxMapChildProps {\n $options: {\n lngLat: [number, number];\n /**\n * Popup options.\n * @see https://docs.mapbox.com/mapbox-gl-js/api/markers#popup\n */\n popupOptions: PopupOptions;\n };\n}\n\n/**\n * Display a popup on a MapboxMap map.\n * @see https://ui.studiometa.dev/reference/items/MapboxMap\n */\nexport class MapboxPopup<T extends BaseProps = BaseProps> extends AbstractMapboxMapChild<\n T & MapboxPopupProps\n> {\n /**\n * Config.\n */\n static config: BaseConfig = {\n name: 'MapboxPopup',\n options: {\n lngLat: {\n type: Array,\n default: () => [0, 0],\n },\n popupOptions: Object,\n },\n };\n\n /**\n * Popup instance.\n * @private\n */\n __popup: Popup;\n\n /**\n * Whether this component hid its own source element (to avoid rendering the\n * content twice). Tracked so teardown restores the original visibility only\n * when it was the one to change it.\n * @private\n */\n __didHide = false;\n\n /**\n * The mapbox Popup instance.\n */\n get popup() {\n if (!this.__popup) {\n this.__popup = new (getMapboxGl().Popup)(this.$options.popupOptions);\n }\n\n return this.__popup;\n }\n\n /**\n * Mounted hook.\n */\n mounted() {\n this.whenMapReady((map) => {\n const { popup, $el, $options } = this;\n\n popup.setLngLat($options.lngLat);\n\n const content = $el.innerHTML.trim();\n if (content) {\n popup.setHTML(content);\n // Hide the source markup so the content is not rendered twice: once in\n // the popup and once in the document. Remember we did so — only when it\n // was visible — to restore it on teardown.\n if (!$el.hidden) {\n $el.hidden = true;\n this.__didHide = true;\n }\n }\n\n // When inside a marker, hand the popup to it rather than adding it to the\n // map directly (the marker owns its popup via `setPopup`). Pushing to the\n // marker — instead of letting the marker pull us — also covers the dynamic\n // append case where the marker mounted first and found no popup to query.\n const marker = this.$closest<MapboxMarker>('MapboxMarker');\n if (marker) {\n marker.setChildPopup(this);\n } else {\n popup.addTo(map);\n }\n });\n }\n\n /**\n * Teardown hook.\n */\n __onDestroyed() {\n this.__popup?.remove();\n this.__popup = undefined;\n\n // Restore the source element's visibility only if this component hid it, so\n // a reused or remounted element keeps its original state.\n if (this.__didHide) {\n this.$el.hidden = false;\n this.__didHide = false;\n }\n }\n}\n\nexport default MapboxPopup;\n"],"mappings":";;;;;;;AAwBA,IAAa,cAAb,cAAkE,uBAEhE;;;;CAIA,OAAO,SAAqB;EAC1B,MAAM;EACN,SAAS;GACP,QAAQ;IACN,MAAM;IACN,eAAe,CAAC,GAAG,EAAE;IACtB;GACD,cAAc;GACf;EACF;;;;;CAMD;;;;;;;CAQA,YAAY;;;;CAKZ,IAAI,QAAQ;AACV,MAAI,CAAC,KAAK,QACR,MAAK,UAAU,KAAK,aAAa,EAAC,MAAO,KAAK,SAAS,aAAa;AAGtE,SAAO,KAAK;;;;;CAMd,UAAU;AACR,OAAK,cAAc,QAAQ;GACzB,MAAM,EAAE,OAAO,KAAK,aAAa;AAEjC,SAAM,UAAU,SAAS,OAAO;GAEhC,MAAM,UAAU,IAAI,UAAU,MAAM;AACpC,OAAI,SAAS;AACX,UAAM,QAAQ,QAAQ;AAItB,QAAI,CAAC,IAAI,QAAQ;AACf,SAAI,SAAS;AACb,UAAK,YAAY;;;GAQrB,MAAM,SAAS,KAAK,SAAuB,eAAe;AAC1D,OAAI,OACF,QAAO,cAAc,KAAK;OAE1B,OAAM,MAAM,IAAI;IAElB;;;;;CAMJ,gBAAgB;AACd,OAAK,SAAS,QAAQ;AACtB,OAAK,UAAU,KAAA;AAIf,MAAI,KAAK,WAAW;AAClB,QAAK,IAAI,SAAS;AAClB,QAAK,YAAY"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { AbstractMapboxMapChild, AbstractMapboxMapChildProps } from "./AbstractMapboxMapChild.js";
|
|
2
|
+
import { BaseConfig, BaseProps } from "@studiometa/js-toolkit";
|
|
3
|
+
import { SourceSpecification } from "mapbox-gl";
|
|
4
|
+
|
|
5
|
+
//#region MapboxSource.d.ts
|
|
6
|
+
interface MapboxSourceProps extends AbstractMapboxMapChildProps {
|
|
7
|
+
$refs: {
|
|
8
|
+
geojson?: HTMLScriptElement;
|
|
9
|
+
};
|
|
10
|
+
$options: {
|
|
11
|
+
id: string;
|
|
12
|
+
/**
|
|
13
|
+
* The source specification, e.g. `{ type: 'geojson', data }`.
|
|
14
|
+
* @see https://docs.mapbox.com/style-spec/reference/sources/
|
|
15
|
+
*/
|
|
16
|
+
source: SourceSpecification;
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Add a source to the map.
|
|
21
|
+
* @see https://ui.studiometa.dev/reference/items/MapboxMap/
|
|
22
|
+
*/
|
|
23
|
+
declare class MapboxSource<T extends BaseProps = BaseProps> extends AbstractMapboxMapChild<T & MapboxSourceProps> {
|
|
24
|
+
/**
|
|
25
|
+
* Config.
|
|
26
|
+
*/
|
|
27
|
+
static config: BaseConfig;
|
|
28
|
+
/**
|
|
29
|
+
* Resolve the source specification.
|
|
30
|
+
*
|
|
31
|
+
* When a `geojson` ref — a `<script data-ref="geojson" type="application/json">`
|
|
32
|
+
* element — is present, its content is parsed as inline GeoJSON and injected
|
|
33
|
+
* as the source spec's `data`. Otherwise the `source` option is used as is.
|
|
34
|
+
*/
|
|
35
|
+
get source(): SourceSpecification;
|
|
36
|
+
/**
|
|
37
|
+
* Whether this instance owns the source under its id. Only a source this
|
|
38
|
+
* instance owns — along with the layers tied to it — may be removed on
|
|
39
|
+
* teardown; a source declared by someone else outside the family is left
|
|
40
|
+
* untouched, and a source a newer sibling has since adopted is left to that
|
|
41
|
+
* sibling.
|
|
42
|
+
* @private
|
|
43
|
+
*/
|
|
44
|
+
__added: boolean;
|
|
45
|
+
/**
|
|
46
|
+
* The `kind:id` ownership key for this source.
|
|
47
|
+
* @private
|
|
48
|
+
*/
|
|
49
|
+
get __ownershipKey(): string;
|
|
50
|
+
/**
|
|
51
|
+
* Mounted hook.
|
|
52
|
+
*
|
|
53
|
+
* Adopt-or-add: when the id is free, add the source and claim ownership. When
|
|
54
|
+
* a source with this id already exists, adding it again would throw a
|
|
55
|
+
* duplicate-id error, so instead update its data (for GeoJSON) and — when the
|
|
56
|
+
* existing source belongs to a sibling `MapboxSource` (e.g. a `Fetch` swap
|
|
57
|
+
* mounted the replacement before the original tore down) — take over
|
|
58
|
+
* ownership. A source declared outside the family is left untouched and not
|
|
59
|
+
* owned.
|
|
60
|
+
*/
|
|
61
|
+
mounted(): void;
|
|
62
|
+
/**
|
|
63
|
+
* Teardown hook.
|
|
64
|
+
*/
|
|
65
|
+
__onDestroyed(): void;
|
|
66
|
+
}
|
|
67
|
+
//#endregion
|
|
68
|
+
export { MapboxSource, MapboxSource as default, MapboxSourceProps };
|
package/MapboxSource.js
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { AbstractMapboxMapChild } from "./AbstractMapboxMapChild.js";
|
|
2
|
+
import { claimMapboxOwnership, getMapboxOwner, releaseMapboxOwnership } from "./utils.js";
|
|
3
|
+
//#region MapboxSource.ts
|
|
4
|
+
/**
|
|
5
|
+
* Add a source to the map.
|
|
6
|
+
* @see https://ui.studiometa.dev/reference/items/MapboxMap/
|
|
7
|
+
*/
|
|
8
|
+
var MapboxSource = class extends AbstractMapboxMapChild {
|
|
9
|
+
/**
|
|
10
|
+
* Config.
|
|
11
|
+
*/
|
|
12
|
+
static config = {
|
|
13
|
+
name: "MapboxSource",
|
|
14
|
+
refs: ["geojson"],
|
|
15
|
+
options: {
|
|
16
|
+
id: String,
|
|
17
|
+
source: Object
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Resolve the source specification.
|
|
22
|
+
*
|
|
23
|
+
* When a `geojson` ref — a `<script data-ref="geojson" type="application/json">`
|
|
24
|
+
* element — is present, its content is parsed as inline GeoJSON and injected
|
|
25
|
+
* as the source spec's `data`. Otherwise the `source` option is used as is.
|
|
26
|
+
*/
|
|
27
|
+
get source() {
|
|
28
|
+
const { source } = this.$options;
|
|
29
|
+
const content = this.$refs.geojson?.textContent?.trim();
|
|
30
|
+
if (!content) return source;
|
|
31
|
+
try {
|
|
32
|
+
const data = JSON.parse(content);
|
|
33
|
+
return {
|
|
34
|
+
...source,
|
|
35
|
+
data
|
|
36
|
+
};
|
|
37
|
+
} catch (err) {
|
|
38
|
+
this.$warn("Invalid JSON in the `geojson` ref:", err);
|
|
39
|
+
return source;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Whether this instance owns the source under its id. Only a source this
|
|
44
|
+
* instance owns — along with the layers tied to it — may be removed on
|
|
45
|
+
* teardown; a source declared by someone else outside the family is left
|
|
46
|
+
* untouched, and a source a newer sibling has since adopted is left to that
|
|
47
|
+
* sibling.
|
|
48
|
+
* @private
|
|
49
|
+
*/
|
|
50
|
+
__added = false;
|
|
51
|
+
/**
|
|
52
|
+
* The `kind:id` ownership key for this source.
|
|
53
|
+
* @private
|
|
54
|
+
*/
|
|
55
|
+
get __ownershipKey() {
|
|
56
|
+
return `source:${this.$options.id}`;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Mounted hook.
|
|
60
|
+
*
|
|
61
|
+
* Adopt-or-add: when the id is free, add the source and claim ownership. When
|
|
62
|
+
* a source with this id already exists, adding it again would throw a
|
|
63
|
+
* duplicate-id error, so instead update its data (for GeoJSON) and — when the
|
|
64
|
+
* existing source belongs to a sibling `MapboxSource` (e.g. a `Fetch` swap
|
|
65
|
+
* mounted the replacement before the original tore down) — take over
|
|
66
|
+
* ownership. A source declared outside the family is left untouched and not
|
|
67
|
+
* owned.
|
|
68
|
+
*/
|
|
69
|
+
mounted() {
|
|
70
|
+
this.whenMapReady((map) => {
|
|
71
|
+
const { id } = this.$options;
|
|
72
|
+
const { source } = this;
|
|
73
|
+
if (!map.getSource(id)) {
|
|
74
|
+
map.addSource(id, source);
|
|
75
|
+
const added = map.getSource(id);
|
|
76
|
+
claimMapboxOwnership(map, this.__ownershipKey, this, () => map.getSource(id) === added);
|
|
77
|
+
this.__added = true;
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
if (getMapboxOwner(map, this.__ownershipKey)) {
|
|
81
|
+
if (source.type === "geojson" && "data" in source) map.getSource(id)?.setData(source.data);
|
|
82
|
+
const existing = map.getSource(id);
|
|
83
|
+
claimMapboxOwnership(map, this.__ownershipKey, this, () => map.getSource(id) === existing);
|
|
84
|
+
this.__added = true;
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Teardown hook.
|
|
90
|
+
*/
|
|
91
|
+
__onDestroyed() {
|
|
92
|
+
const map = this.__readyMap;
|
|
93
|
+
const { id } = this.$options;
|
|
94
|
+
if (this.__added && getMapboxOwner(map, this.__ownershipKey) === this && map?.getSource(id)) {
|
|
95
|
+
for (const layer of map.getStyle().layers) if ("source" in layer && layer.source === id) map.removeLayer(layer.id);
|
|
96
|
+
map.removeSource(id);
|
|
97
|
+
releaseMapboxOwnership(map, this.__ownershipKey, this);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
//#endregion
|
|
102
|
+
export { MapboxSource, MapboxSource as default };
|
|
103
|
+
|
|
104
|
+
//# sourceMappingURL=MapboxSource.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MapboxSource.js","names":[],"sources":["../MapboxSource.ts"],"sourcesContent":["import { type BaseProps, type BaseConfig } from '@studiometa/js-toolkit';\nimport type { SourceSpecification, GeoJSONSourceSpecification, GeoJSONSource } from 'mapbox-gl';\nimport {\n AbstractMapboxMapChild,\n type AbstractMapboxMapChildProps,\n} from './AbstractMapboxMapChild.js';\nimport { claimMapboxOwnership, getMapboxOwner, releaseMapboxOwnership } from './utils.js';\n\nexport interface MapboxSourceProps extends AbstractMapboxMapChildProps {\n $refs: {\n geojson?: HTMLScriptElement;\n };\n $options: {\n id: string;\n /**\n * The source specification, e.g. `{ type: 'geojson', data }`.\n * @see https://docs.mapbox.com/style-spec/reference/sources/\n */\n source: SourceSpecification;\n };\n}\n\n/**\n * Add a source to the map.\n * @see https://ui.studiometa.dev/reference/items/MapboxMap/\n */\nexport class MapboxSource<T extends BaseProps = BaseProps> extends AbstractMapboxMapChild<\n T & MapboxSourceProps\n> {\n /**\n * Config.\n */\n static config: BaseConfig = {\n name: 'MapboxSource',\n refs: ['geojson'],\n options: {\n id: String,\n source: Object,\n },\n };\n\n /**\n * Resolve the source specification.\n *\n * When a `geojson` ref — a `<script data-ref=\"geojson\" type=\"application/json\">`\n * element — is present, its content is parsed as inline GeoJSON and injected\n * as the source spec's `data`. Otherwise the `source` option is used as is.\n */\n get source(): SourceSpecification {\n const { source } = this.$options;\n const script = this.$refs.geojson;\n const content = script?.textContent?.trim();\n\n // Only inject inline data when the script ref holds actual content. A\n // missing, empty or whitespace-only ref is treated as \"no inline data\" and\n // the `source` option is used as is instead of injecting `data: null`.\n if (!content) {\n return source;\n }\n\n try {\n const data = JSON.parse(content) as GeoJSONSourceSpecification['data'];\n return { ...source, data } as SourceSpecification;\n } catch (err) {\n this.$warn('Invalid JSON in the `geojson` ref:', err);\n return source;\n }\n }\n\n /**\n * Whether this instance owns the source under its id. Only a source this\n * instance owns — along with the layers tied to it — may be removed on\n * teardown; a source declared by someone else outside the family is left\n * untouched, and a source a newer sibling has since adopted is left to that\n * sibling.\n * @private\n */\n __added = false;\n\n /**\n * The `kind:id` ownership key for this source.\n * @private\n */\n get __ownershipKey(): string {\n return `source:${this.$options.id}`;\n }\n\n /**\n * Mounted hook.\n *\n * Adopt-or-add: when the id is free, add the source and claim ownership. When\n * a source with this id already exists, adding it again would throw a\n * duplicate-id error, so instead update its data (for GeoJSON) and — when the\n * existing source belongs to a sibling `MapboxSource` (e.g. a `Fetch` swap\n * mounted the replacement before the original tore down) — take over\n * ownership. A source declared outside the family is left untouched and not\n * owned.\n */\n mounted() {\n this.whenMapReady((map) => {\n const { id } = this.$options;\n const { source } = this;\n\n if (!map.getSource(id)) {\n map.addSource(id, source);\n // Own the id, keyed to the very source object just added: the liveness\n // probe reports the entry stale the moment this source is removed (a\n // `setStyle` wipe, an external `removeSource`) or replaced under the same\n // id, so it can never misclassify a stranger's later source (H6).\n const added = map.getSource(id);\n claimMapboxOwnership(map, this.__ownershipKey, this, () => map.getSource(id) === added);\n this.__added = true;\n return;\n }\n\n // The id is taken. Only adopt it from another family instance; an\n // externally declared source stays untouched. `getMapboxOwner` validates\n // the existing owner's liveness, so a stale entry left by a wiped/removed\n // source does not read as owned and is not adopted here.\n if (getMapboxOwner(map, this.__ownershipKey)) {\n if (source.type === 'geojson' && 'data' in source) {\n const existing = map.getSource<GeoJSONSource>(id);\n existing?.setData(source.data as GeoJSONSourceSpecification['data']);\n }\n\n const existing = map.getSource(id);\n claimMapboxOwnership(map, this.__ownershipKey, this, () => map.getSource(id) === existing);\n this.__added = true;\n }\n });\n }\n\n /**\n * Teardown hook.\n */\n __onDestroyed() {\n const map = this.__readyMap;\n const { id } = this.$options;\n\n // Only remove a source this instance still owns: a newer sibling may have\n // adopted the id, and a removed map is already gone (`__readyMap` is unset).\n if (\n this.__added &&\n getMapboxOwner(map as object, this.__ownershipKey) === this &&\n map?.getSource(id)\n ) {\n // Remove every layer tied to the source before removing the source itself,\n // otherwise Mapbox throws because layers still reference a missing source.\n //\n // H7 (PR #567 review): this also removes layers owned by still-mounted\n // `MapboxLayer` instances. Those layers now keep a standing `sourcedata`\n // recovery watch (see `MapboxLayer.__handleSourceData`), so when a source\n // with the same id is later re-added they re-commit themselves rather than\n // vanishing permanently. The removal here is unavoidable (Mapbox rejects\n // removing a source still referenced by a layer); recovery is the layer's\n // job. The common `Fetch` swap (source AND layers replaced together) is\n // likewise fine: the replacement layers re-commit on their own.\n for (const layer of map.getStyle().layers) {\n if ('source' in layer && layer.source === id) {\n map.removeLayer(layer.id);\n }\n }\n\n map.removeSource(id);\n releaseMapboxOwnership(map, this.__ownershipKey, this);\n }\n }\n}\n\nexport default MapboxSource;\n"],"mappings":";;;;;;;AA0BA,IAAa,eAAb,cAAmE,uBAEjE;;;;CAIA,OAAO,SAAqB;EAC1B,MAAM;EACN,MAAM,CAAC,UAAU;EACjB,SAAS;GACP,IAAI;GACJ,QAAQ;GACT;EACF;;;;;;;;CASD,IAAI,SAA8B;EAChC,MAAM,EAAE,WAAW,KAAK;EAExB,MAAM,UADS,KAAK,MAAM,SACF,aAAa,MAAM;AAK3C,MAAI,CAAC,QACH,QAAO;AAGT,MAAI;GACF,MAAM,OAAO,KAAK,MAAM,QAAQ;AAChC,UAAO;IAAE,GAAG;IAAQ;IAAM;WACnB,KAAK;AACZ,QAAK,MAAM,sCAAsC,IAAI;AACrD,UAAO;;;;;;;;;;;CAYX,UAAU;;;;;CAMV,IAAI,iBAAyB;AAC3B,SAAO,UAAU,KAAK,SAAS;;;;;;;;;;;;;CAcjC,UAAU;AACR,OAAK,cAAc,QAAQ;GACzB,MAAM,EAAE,OAAO,KAAK;GACpB,MAAM,EAAE,WAAW;AAEnB,OAAI,CAAC,IAAI,UAAU,GAAG,EAAE;AACtB,QAAI,UAAU,IAAI,OAAO;IAKzB,MAAM,QAAQ,IAAI,UAAU,GAAG;AAC/B,yBAAqB,KAAK,KAAK,gBAAgB,YAAY,IAAI,UAAU,GAAG,KAAK,MAAM;AACvF,SAAK,UAAU;AACf;;AAOF,OAAI,eAAe,KAAK,KAAK,eAAe,EAAE;AAC5C,QAAI,OAAO,SAAS,aAAa,UAAU,OACxB,KAAI,UAAyB,GAAG,EACvC,QAAQ,OAAO,KAA2C;IAGtE,MAAM,WAAW,IAAI,UAAU,GAAG;AAClC,yBAAqB,KAAK,KAAK,gBAAgB,YAAY,IAAI,UAAU,GAAG,KAAK,SAAS;AAC1F,SAAK,UAAU;;IAEjB;;;;;CAMJ,gBAAgB;EACd,MAAM,MAAM,KAAK;EACjB,MAAM,EAAE,OAAO,KAAK;AAIpB,MACE,KAAK,WACL,eAAe,KAAe,KAAK,eAAe,KAAK,QACvD,KAAK,UAAU,GAAG,EAClB;AAYA,QAAK,MAAM,SAAS,IAAI,UAAU,CAAC,OACjC,KAAI,YAAY,SAAS,MAAM,WAAW,GACxC,KAAI,YAAY,MAAM,GAAG;AAI7B,OAAI,aAAa,GAAG;AACpB,0BAAuB,KAAK,KAAK,gBAAgB,KAAK"}
|
package/README.md
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
# @studiometa/ui-mapbox
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/@studiometa/ui-mapbox/)
|
|
4
|
+
[](https://www.npmjs.com/package/@studiometa/ui-mapbox/)
|
|
5
|
+
|
|
6
|
+
> Vanilla [@studiometa/js-toolkit](https://github.com/studiometa/js-toolkit) components to build [Mapbox GL](https://docs.mapbox.com/mapbox-gl-js/) maps declaratively.
|
|
7
|
+
|
|
8
|
+
## Installation
|
|
9
|
+
|
|
10
|
+
Install the package along with its `mapbox-gl` peer dependency:
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
npm install @studiometa/ui-mapbox mapbox-gl
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
The geocoder component relies on the optional `@mapbox/mapbox-gl-geocoder` peer dependency, install it only if you need it:
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
npm install @mapbox/mapbox-gl-geocoder
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Usage
|
|
23
|
+
|
|
24
|
+
Register each component your page uses: each one registers independently and resolves its parent map on its own. `mapbox-gl` is heavy (~230 kB gzipped), so the recommended default is to lazy-register each component with js-toolkit's `importWhen*` helpers and the per-component subpaths (each subpath's default export is the component class), keeping the dependency out of your main bundle until a map is actually on the page:
|
|
25
|
+
|
|
26
|
+
```js
|
|
27
|
+
import { registerComponents, importWhenVisible } from '@studiometa/js-toolkit';
|
|
28
|
+
|
|
29
|
+
// Register only the components your page uses; order doesn't matter.
|
|
30
|
+
registerComponents(
|
|
31
|
+
importWhenVisible(() => import('@studiometa/ui-mapbox/MapboxMap'), 'MapboxMap'),
|
|
32
|
+
importWhenVisible(() => import('@studiometa/ui-mapbox/MapboxMarker'), 'MapboxMarker'),
|
|
33
|
+
importWhenVisible(() => import('@studiometa/ui-mapbox/MapboxPopup'), 'MapboxPopup'),
|
|
34
|
+
);
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
Other triggers are available too — `importWhenIdle`, `importOnInteraction` and `importOnMediaQuery` — see the [`importWhen*` helper docs](https://js-toolkit.studiometa.dev/api/helpers/importWhenVisible.html). Then author the map declaratively in your markup:
|
|
38
|
+
|
|
39
|
+
```html
|
|
40
|
+
<div
|
|
41
|
+
data-component="MapboxMap"
|
|
42
|
+
data-option-access-token="pk.your-access-token"
|
|
43
|
+
data-option-zoom="10"
|
|
44
|
+
data-option-center="[2.3522, 48.8566]">
|
|
45
|
+
<div data-ref="container" class="h-96 w-full"></div>
|
|
46
|
+
|
|
47
|
+
<div hidden data-component="MapboxMarker" data-option-lng-lat="[2.3522, 48.8566]"></div>
|
|
48
|
+
</div>
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
If you do not need code-splitting, register eagerly instead — each component is exported by name from the package:
|
|
52
|
+
|
|
53
|
+
```js
|
|
54
|
+
import { registerComponent } from '@studiometa/js-toolkit';
|
|
55
|
+
import { MapboxMap } from '@studiometa/ui-mapbox';
|
|
56
|
+
|
|
57
|
+
registerComponent(MapboxMap);
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
Do not forget to include the `mapbox-gl` stylesheet so the map renders correctly.
|
|
61
|
+
|
|
62
|
+
## Providing `mapbox-gl`
|
|
63
|
+
|
|
64
|
+
By default the components resolve `mapbox-gl` (and the optional `@mapbox/mapbox-gl-geocoder`) with a lazy `import()` the first time a map is built, so the dependency stays out of your main bundle until it is needed. You never have to configure anything for the default to work — just keep `mapbox-gl` installed.
|
|
65
|
+
|
|
66
|
+
When you need to control which `mapbox-gl` the components use — a specific version, a self-hosted build (e.g. a same-origin worker under a strict CSP), or a module served from an import map or a CDN — inject your own instance once, before the components mount:
|
|
67
|
+
|
|
68
|
+
```js
|
|
69
|
+
import mapboxgl from 'mapbox-gl';
|
|
70
|
+
import { provideMapboxGl, provideMapboxGeocoder } from '@studiometa/ui-mapbox';
|
|
71
|
+
|
|
72
|
+
provideMapboxGl(mapboxgl);
|
|
73
|
+
|
|
74
|
+
// Optional: inject the geocoder control constructor as well.
|
|
75
|
+
import MapboxGeocoder from '@mapbox/mapbox-gl-geocoder';
|
|
76
|
+
provideMapboxGeocoder(MapboxGeocoder);
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
Once provided, `@studiometa/ui-mapbox` never imports `mapbox-gl` by specifier — it uses the instance you handed it. `resolveMapboxGl()` / `resolveMapboxGeocoder()` are also exported if you want to trigger (and await) resolution yourself, for example to preload the module.
|
|
80
|
+
|
|
81
|
+
Heads up to [ui.studiometa.dev](https://ui.studiometa.dev/reference/items/MapboxMap/) for the full documentation.
|
|
82
|
+
|
|
83
|
+
## Contributing
|
|
84
|
+
|
|
85
|
+
Please read the [contribution docs](https://ui.studiometa.dev/guide/contributing/).
|