@studiometa/ui-mapbox 1.11.0 → 2.0.0-alpha.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/dist/AbstractMapboxControl.js +1 -1
- package/dist/AbstractMapboxControl.js.map +1 -1
- package/dist/AbstractMapboxMapChild.d.ts +32 -12
- package/dist/AbstractMapboxMapChild.js +24 -17
- package/dist/AbstractMapboxMapChild.js.map +1 -1
- package/dist/MapboxCluster.d.ts +19 -2
- package/dist/MapboxCluster.js +11 -9
- package/dist/MapboxCluster.js.map +1 -1
- package/dist/MapboxClusterItem.d.ts +11 -3
- package/dist/MapboxClusterItem.js +5 -6
- package/dist/MapboxClusterItem.js.map +1 -1
- package/dist/MapboxFullscreenControl.d.ts +8 -4
- package/dist/MapboxFullscreenControl.js +6 -2
- package/dist/MapboxFullscreenControl.js.map +1 -1
- package/dist/MapboxGeocoder.d.ts +9 -0
- package/dist/MapboxGeocoder.js +1 -2
- package/dist/MapboxGeocoder.js.map +1 -1
- package/dist/MapboxGeolocateControl.d.ts +8 -4
- package/dist/MapboxGeolocateControl.js +16 -12
- package/dist/MapboxGeolocateControl.js.map +1 -1
- package/dist/MapboxImage.d.ts +11 -1
- package/dist/MapboxImage.js +0 -1
- package/dist/MapboxImage.js.map +1 -1
- package/dist/MapboxImages.d.ts +9 -1
- package/dist/MapboxImages.js +1 -2
- package/dist/MapboxImages.js.map +1 -1
- package/dist/MapboxLayer.js.map +1 -1
- package/dist/MapboxMap.d.ts +17 -2
- package/dist/MapboxMap.js +4 -5
- package/dist/MapboxMap.js.map +1 -1
- package/dist/MapboxMarker.js.map +1 -1
- package/dist/MapboxNavigationControl.d.ts +8 -4
- package/dist/MapboxNavigationControl.js +13 -9
- package/dist/MapboxNavigationControl.js.map +1 -1
- package/dist/MapboxPopup.js.map +1 -1
- package/dist/MapboxSource.js +1 -1
- package/dist/MapboxSource.js.map +1 -1
- package/dist/StoreLocator.d.ts +76 -51
- package/dist/StoreLocator.js +111 -105
- package/dist/StoreLocator.js.map +1 -1
- package/dist/catalog.js.map +1 -1
- package/dist/dependencies.d.ts +6 -4
- package/dist/dependencies.js +6 -4
- package/dist/dependencies.js.map +1 -1
- package/dist/manifest.js +14 -84
- package/dist/manifest.js.map +1 -1
- package/dist/scripts/manifest-types.d.ts +3 -3
- package/package.json +3 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MapboxClusterItem.js","names":[],"sources":["../src/MapboxClusterItem.ts"],"sourcesContent":["import { Base } from '@studiometa/js-toolkit/Base';\nimport type { BaseProps, BaseConfig } from '@studiometa/js-toolkit';\nimport { MAPBOX_CLUSTER_CONNECTED, type MapboxCluster } from './MapboxCluster.js';\n\nexport interface MapboxClusterItemProps extends BaseProps {\n $options: {\n id: string;\n lngLat: [number, number];\n properties: Record<string, unknown>;\n };\n}\n\n/**\n * A single entry of a `MapboxCluster`.\n *\n * Unlike the other `@studiometa/ui-mapbox` components, this one is a **rendered**\n * element (e.g. a list `<li>` in a sidebar) and does not extend\n * `AbstractMapboxMapChild`: its DOM lives outside the `MapboxMap` element, so its\n * context is the parent `MapboxCluster` — resolved via `$closest('MapboxCluster')`\n * — rather than a map.\n *\n * It is at once the list item AND the map feature: the cluster derives its\n * GeoJSON source from the set of registered items, so the same markup drives\n * both the sidebar and the clustered points on the map. The child PUSHES itself\n * to the cluster on mount (`register`) and PULLS itself out on destroy\n * (`unregister`), so the cluster never has to query for its children.\n *\n * The component is headless and passive: it never selects itself. The state\n * setters below reflect state as data-attributes on `$el` so the integrator can\n * style the item with plain CSS, and they are driven by whoever coordinates the\n * experience — a [`StoreLocator`](./StoreLocator.js) orchestrator on `moveend`\n * and on selection, if one wraps the cluster:\n *\n * - `data-in-bounds` — present when the item's `lngLat` is inside the current\n * map viewport (list-visibility signal).\n * - `data-active` + `aria-current=\"true\"` — present when the item is selected.\n *\n * Used under a bare `MapboxCluster` (no orchestrator) the item still registers\n * and renders as a clustered point; it just carries no selection affordance of\n * its own — a click is reported by the cluster's `map-item-click` event for a\n * caller to act on.\n *\n * @see https://ui.studiometa.dev/reference/items/MapboxMap/\n */\nexport class MapboxClusterItem<T extends BaseProps = BaseProps> extends Base<\n T & MapboxClusterItemProps\n> {\n /**\n * Config.\n */\n static config: BaseConfig = {\n name: 'MapboxClusterItem',\n
|
|
1
|
+
{"version":3,"file":"MapboxClusterItem.js","names":[],"sources":["../src/MapboxClusterItem.ts"],"sourcesContent":["import { Base } from '@studiometa/js-toolkit/Base';\nimport type { BaseProps, BaseConfig } from '@studiometa/js-toolkit';\nimport { MAPBOX_CLUSTER_CONNECTED, type MapboxCluster } from './MapboxCluster.js';\n\nexport interface MapboxClusterItemProps extends BaseProps {\n $options: {\n id: string;\n lngLat: [number, number];\n properties: Record<string, unknown>;\n };\n /**\n * The item shares the map family's error channel.\n */\n $emits: {\n 'map-error': { error: unknown };\n };\n}\n\n/**\n * A single entry of a `MapboxCluster`.\n *\n * Unlike the other `@studiometa/ui-mapbox` components, this one is a **rendered**\n * element (e.g. a list `<li>` in a sidebar) and does not extend\n * `AbstractMapboxMapChild`: its DOM lives outside the `MapboxMap` element, so its\n * context is the parent `MapboxCluster` — resolved via `$closest('MapboxCluster')`\n * — rather than a map.\n *\n * It is at once the list item AND the map feature: the cluster derives its\n * GeoJSON source from the set of registered items, so the same markup drives\n * both the sidebar and the clustered points on the map. The child PUSHES itself\n * to the cluster on mount (`register`) and PULLS itself out on destroy\n * (`unregister`), so the cluster never has to query for its children.\n *\n * The component is headless and passive: it never selects itself. The state\n * setters below reflect state as data-attributes on `$el` so the integrator can\n * style the item with plain CSS, and they are driven by whoever coordinates the\n * experience — a [`StoreLocator`](./StoreLocator.js) orchestrator on `moveend`\n * and on selection, if one wraps the cluster:\n *\n * - `data-in-bounds` — present when the item's `lngLat` is inside the current\n * map viewport (list-visibility signal).\n * - `data-active` + `aria-current=\"true\"` — present when the item is selected.\n *\n * Used under a bare `MapboxCluster` (no orchestrator) the item still registers\n * and renders as a clustered point; it just carries no selection affordance of\n * its own — a click is reported by the cluster's `map-item-click` event for a\n * caller to act on.\n *\n * @see https://ui.studiometa.dev/reference/items/MapboxMap/\n */\nexport class MapboxClusterItem<T extends BaseProps = BaseProps> extends Base<\n T & MapboxClusterItemProps\n> {\n /**\n * Config.\n */\n static config: BaseConfig = {\n name: 'MapboxClusterItem',\n options: {\n id: String,\n lngLat: {\n type: Array,\n default: () => [0, 0],\n },\n properties: {\n type: Object,\n default: () => ({}),\n },\n },\n };\n\n /**\n * The parent `MapboxCluster` resolved at mount, cached so the item can still\n * reach it on destroy.\n *\n * `unmounted()` runs *after* the element has been detached from the DOM (e.g.\n * a `Fetch` list swap), and a `$closest` lookup on a disconnected node returns\n * nothing — which would leave the removed item registered and its feature\n * stuck on the map. Caching the reference keeps the unregister path working.\n * @private\n */\n __cluster?: MapboxCluster;\n\n /**\n * Off handler for the document-level `MAPBOX_CLUSTER_CONNECTED` retry\n * subscription, used when the item mounts before its cluster.\n * @private\n */\n __offClusterConnected?: () => void;\n\n /**\n * The item's stable identifier, used to match map features back to the item.\n *\n * Expected to be non-empty and unique within a cluster. Duplicate ids are not\n * rejected, but their behavior is defined rather than undefined: a click on\n * any duplicate resolves to the FIRST registered item carrying that id (see\n * `MapboxCluster.__handleUnclusteredClick`). Integrators wanting a distinct\n * selection per element must give each item a unique id.\n */\n get id(): string {\n return this.$options.id;\n }\n\n /**\n * The item's coordinates as a `[lng, lat]` tuple.\n */\n get lngLat(): [number, number] {\n return this.$options.lngLat;\n }\n\n /**\n * Extra feature properties merged into the item's GeoJSON feature.\n */\n get properties(): Record<string, unknown> {\n return this.$options.properties;\n }\n\n /**\n * The HTML used as the map popup content when this item is selected.\n *\n * Uses the inner HTML of an optional `[data-ref=\"popup\"]` element when present\n * so the sidebar card and the map popup can differ, otherwise falls back to\n * the item's whole inner HTML.\n */\n get popupContent(): string {\n const ref = this.$el.querySelector('[data-ref=\"popup\"]');\n return (ref ?? this.$el).innerHTML.trim();\n }\n\n /**\n * Mounted hook: resolve the parent cluster and register with it.\n */\n mounted() {\n this.__resolveCluster();\n }\n\n /**\n * Resolve the parent `MapboxCluster` and register, or wait for one to connect.\n *\n * Resolution is retryable: an item eagerly registered under a lazily imported\n * cluster mounts first and finds nothing, so it waits for\n * `MAPBOX_CLUSTER_CONNECTED` and registers once its cluster is up.\n * @private\n */\n __resolveCluster() {\n const cluster = this.$closest<MapboxCluster>('MapboxCluster');\n\n if (!cluster) {\n this.__waitForConnectedCluster();\n return;\n }\n\n this.__cluster = cluster;\n cluster.register(this);\n }\n\n /**\n * Subscribe once to `MAPBOX_CLUSTER_CONNECTED` and retry resolution when a\n * cluster whose element is an ancestor of this item connects.\n * @private\n */\n __waitForConnectedCluster() {\n if (this.__offClusterConnected) {\n return;\n }\n\n const handler = (event: Event) => {\n const cluster = (event as CustomEvent<MapboxCluster>).detail;\n\n if (!cluster?.$el?.contains(this.$el)) {\n return;\n }\n\n this.__offClusterConnected?.();\n this.__offClusterConnected = undefined;\n this.__resolveCluster();\n };\n\n document.addEventListener(MAPBOX_CLUSTER_CONNECTED, handler);\n this.__offClusterConnected = () =>\n document.removeEventListener(MAPBOX_CLUSTER_CONNECTED, handler);\n }\n\n /**\n * Unmounted hook: unregister from the cached cluster, even if the element has\n * already been detached from the DOM, and drop any pending retry subscription.\n */\n unmounted() {\n try {\n this.__cluster?.unregister(this);\n } catch (err) {\n this.$error(\n 'mapbox-cluster-item.unregister-failed',\n 'Unregistering from the cluster threw.',\n err,\n );\n this.$emit('map-error', { error: err });\n }\n\n this.__cluster = undefined;\n this.__offClusterConnected?.();\n this.__offClusterConnected = undefined;\n }\n\n /**\n * Reflect the \"in the current map viewport\" state as a `data-in-bounds`\n * attribute. Called by a `StoreLocator` orchestrator on every map `moveend`.\n * @param {boolean} value\n */\n setInBounds(value: boolean) {\n this.$el.toggleAttribute('data-in-bounds', value);\n }\n\n /**\n * Reflect the \"selected/active\" state as a `data-active` attribute and the\n * `aria-current` state. Called by a `StoreLocator` orchestrator on selection.\n * @param {boolean} value\n */\n setActive(value: boolean) {\n this.$el.toggleAttribute('data-active', value);\n\n if (value) {\n this.$el.setAttribute('aria-current', 'true');\n } else {\n this.$el.removeAttribute('aria-current');\n }\n }\n}\n\nexport default MapboxClusterItem;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkDA,IAAa,oBAAb,cAAwE,KAEtE;;;;CAIA,OAAO,SAAqB;EAC1B,MAAM;EACN,SAAS;GACP,IAAI;GACJ,QAAQ;IACN,MAAM;IACN,eAAe,CAAC,GAAG,EAAE;IACtB;GACD,YAAY;IACV,MAAM;IACN,gBAAgB,EAAE;IACnB;GACF;EACF;;;;;;;;;;;CAYD;;;;;;CAOA;;;;;;;;;;CAWA,IAAI,KAAa;AACf,SAAO,KAAK,SAAS;;;;;CAMvB,IAAI,SAA2B;AAC7B,SAAO,KAAK,SAAS;;;;;CAMvB,IAAI,aAAsC;AACxC,SAAO,KAAK,SAAS;;;;;;;;;CAUvB,IAAI,eAAuB;AAEzB,UADY,KAAK,IAAI,cAAc,uBAAqB,IACzC,KAAK,KAAK,UAAU,MAAM;;;;;CAM3C,UAAU;AACR,OAAK,kBAAkB;;;;;;;;;;CAWzB,mBAAmB;EACjB,MAAM,UAAU,KAAK,SAAwB,gBAAgB;AAE7D,MAAI,CAAC,SAAS;AACZ,QAAK,2BAA2B;AAChC;;AAGF,OAAK,YAAY;AACjB,UAAQ,SAAS,KAAK;;;;;;;CAQxB,4BAA4B;AAC1B,MAAI,KAAK,sBACP;EAGF,MAAM,WAAW,UAAiB;AAGhC,OAAI,CAFa,MAAqC,QAExC,KAAK,SAAS,KAAK,IAAI,CACnC;AAGF,QAAK,yBAAyB;AAC9B,QAAK,wBAAwB,KAAA;AAC7B,QAAK,kBAAkB;;AAGzB,WAAS,iBAAiB,0BAA0B,QAAQ;AAC5D,OAAK,8BACH,SAAS,oBAAoB,0BAA0B,QAAQ;;;;;;CAOnE,YAAY;AACV,MAAI;AACF,QAAK,WAAW,WAAW,KAAK;WACzB,KAAK;AACZ,QAAK,OACH,yCACA,yCACA,IACD;AACD,QAAK,MAAM,aAAa,EAAE,OAAO,KAAK,CAAC;;AAGzC,OAAK,YAAY,KAAA;AACjB,OAAK,yBAAyB;AAC9B,OAAK,wBAAwB,KAAA;;;;;;;CAQ/B,YAAY,OAAgB;AAC1B,OAAK,IAAI,gBAAgB,kBAAkB,MAAM;;;;;;;CAQnD,UAAU,OAAgB;AACxB,OAAK,IAAI,gBAAgB,eAAe,MAAM;AAE9C,MAAI,MACF,MAAK,IAAI,aAAa,gBAAgB,OAAO;MAE7C,MAAK,IAAI,gBAAgB,eAAe"}
|
|
@@ -1,16 +1,20 @@
|
|
|
1
|
-
import { AbstractMapboxControlProps } from "./AbstractMapboxControl.js";
|
|
2
|
-
import
|
|
1
|
+
import { AbstractMapboxControl, AbstractMapboxControlProps } from "./AbstractMapboxControl.js";
|
|
2
|
+
import { BaseConfig, BaseProps } from "@studiometa/js-toolkit";
|
|
3
3
|
import * as mapbox_gl0 from "mapbox-gl";
|
|
4
4
|
import { FullscreenControlOptions } from "mapbox-gl";
|
|
5
5
|
|
|
6
6
|
//#region src/MapboxFullscreenControl.d.ts
|
|
7
7
|
interface MapboxFullscreenControlProps extends AbstractMapboxControlProps {}
|
|
8
|
-
declare const MapboxFullscreenControl_base: _studiometa_js_toolkit0.BaseDecorator<_studiometa_js_toolkit0.BaseInterface, _studiometa_js_toolkit0.Base<_studiometa_js_toolkit0.BaseProps>>;
|
|
9
8
|
/**
|
|
10
9
|
* Add a fullscreen control to the map.
|
|
10
|
+
*
|
|
11
11
|
* @see https://ui.studiometa.dev/reference/items/MapboxMap/
|
|
12
12
|
*/
|
|
13
|
-
declare class MapboxFullscreenControl extends
|
|
13
|
+
declare class MapboxFullscreenControl<T extends BaseProps = BaseProps> extends AbstractMapboxControl<T & MapboxFullscreenControlProps> {
|
|
14
|
+
/**
|
|
15
|
+
* Config.
|
|
16
|
+
*/
|
|
17
|
+
static config: BaseConfig;
|
|
14
18
|
/**
|
|
15
19
|
* Create the mapbox FullscreenControl instance.
|
|
16
20
|
* @protected
|
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
import { AbstractMapboxControl } from "./AbstractMapboxControl.js";
|
|
2
2
|
import { getMapboxGl } from "./dependencies.js";
|
|
3
|
-
import { withExtraConfig } from "@studiometa/js-toolkit/withExtraConfig";
|
|
4
3
|
//#region src/MapboxFullscreenControl.ts
|
|
5
4
|
/**
|
|
6
5
|
* Add a fullscreen control to the map.
|
|
6
|
+
*
|
|
7
7
|
* @see https://ui.studiometa.dev/reference/items/MapboxMap/
|
|
8
8
|
*/
|
|
9
|
-
var MapboxFullscreenControl = class extends
|
|
9
|
+
var MapboxFullscreenControl = class extends AbstractMapboxControl {
|
|
10
|
+
/**
|
|
11
|
+
* Config.
|
|
12
|
+
*/
|
|
13
|
+
static config = { name: "MapboxFullscreenControl" };
|
|
10
14
|
/**
|
|
11
15
|
* Create the mapbox FullscreenControl instance.
|
|
12
16
|
* @protected
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MapboxFullscreenControl.js","names":[],"sources":["../src/MapboxFullscreenControl.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"MapboxFullscreenControl.js","names":[],"sources":["../src/MapboxFullscreenControl.ts"],"sourcesContent":["import type { BaseConfig, BaseProps } from '@studiometa/js-toolkit';\nimport type { FullscreenControlOptions } from 'mapbox-gl';\nimport { AbstractMapboxControl, type AbstractMapboxControlProps } from './AbstractMapboxControl.js';\nimport { getMapboxGl } from './dependencies.js';\n\nexport interface MapboxFullscreenControlProps extends AbstractMapboxControlProps {}\n\n/**\n * Add a fullscreen control to the map.\n *\n * @see https://ui.studiometa.dev/reference/items/MapboxMap/\n */\nexport class MapboxFullscreenControl<T extends BaseProps = BaseProps> extends AbstractMapboxControl<\n T & MapboxFullscreenControlProps\n> {\n /**\n * Config.\n */\n static config: BaseConfig = {\n name: 'MapboxFullscreenControl',\n };\n\n /**\n * Create the mapbox FullscreenControl instance.\n * @protected\n */\n createControl(options: FullscreenControlOptions) {\n return new (getMapboxGl().FullscreenControl)(options);\n }\n}\n\nexport default MapboxFullscreenControl;\n"],"mappings":";;;;;;;;AAYA,IAAa,0BAAb,cAA8E,sBAE5E;;;;CAIA,OAAO,SAAqB,EAC1B,MAAM,2BACP;;;;;CAMD,cAAc,SAAmC;AAC/C,SAAO,KAAK,aAAa,EAAC,kBAAmB,QAAQ"}
|
package/dist/MapboxGeocoder.d.ts
CHANGED
|
@@ -19,6 +19,15 @@ interface MapboxGeocoderProps extends AbstractMapboxMapChildProps {
|
|
|
19
19
|
*/
|
|
20
20
|
options: Record<string, unknown>;
|
|
21
21
|
};
|
|
22
|
+
/**
|
|
23
|
+
* The geocoder's own event, declared in the props type. The geocoded result
|
|
24
|
+
* travels as `detail.result`.
|
|
25
|
+
*/
|
|
26
|
+
$emits: AbstractMapboxMapChildProps['$emits'] & {
|
|
27
|
+
'map-result': {
|
|
28
|
+
result: unknown;
|
|
29
|
+
};
|
|
30
|
+
};
|
|
22
31
|
}
|
|
23
32
|
/**
|
|
24
33
|
* Add a geocoder control to the map.
|
package/dist/MapboxGeocoder.js
CHANGED
|
@@ -16,7 +16,6 @@ var MapboxGeocoder = class extends AbstractMapboxMapChild {
|
|
|
16
16
|
*/
|
|
17
17
|
static config = {
|
|
18
18
|
name: "MapboxGeocoder",
|
|
19
|
-
emits: ["map-result"],
|
|
20
19
|
options: {
|
|
21
20
|
addToMap: Boolean,
|
|
22
21
|
options: Object
|
|
@@ -59,7 +58,7 @@ var MapboxGeocoder = class extends AbstractMapboxMapChild {
|
|
|
59
58
|
mapboxgl: getMapboxGl(),
|
|
60
59
|
accessToken: this.$options.options.accessToken ?? this.__readyMapboxMap?.$options.accessToken
|
|
61
60
|
});
|
|
62
|
-
this.__control.on?.("result", (event) => this.$emit("map-result", event.result));
|
|
61
|
+
this.__control.on?.("result", (event) => this.$emit("map-result", { result: event.result }));
|
|
63
62
|
this.__control.addTo(this.target);
|
|
64
63
|
});
|
|
65
64
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MapboxGeocoder.js","names":[],"sources":["../src/MapboxGeocoder.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"MapboxGeocoder.js","names":[],"sources":["../src/MapboxGeocoder.ts"],"sourcesContent":["import type { BaseProps, BaseConfig } from '@studiometa/js-toolkit';\nimport type { Map, IControl } from 'mapbox-gl';\nimport {\n AbstractMapboxMapChild,\n type AbstractMapboxMapChildProps,\n} from './AbstractMapboxMapChild.js';\nimport { getMapboxGl, resolveMapboxGeocoder, type MapboxGeocoderControl } from './dependencies.js';\n\nexport interface MapboxGeocoderProps extends AbstractMapboxMapChildProps {\n $options: {\n /**\n * Wether to add the geocoder to the map or to the component's root element.\n */\n addToMap: boolean;\n /**\n * All MapboxGeocoder options, except the non serializable ones.\n *\n * Typed structurally (rather than with the optional geocoder peer types) to\n * keep the peer out of the public type surface. Refer to the Mapbox geocoder\n * package documentation (API.md#parameters) for the accepted options.\n */\n options: Record<string, unknown>;\n };\n /**\n * The geocoder's own event, declared in the props type. The geocoded result\n * travels as `detail.result`.\n */\n $emits: AbstractMapboxMapChildProps['$emits'] & {\n 'map-result': { result: unknown };\n };\n}\n\n/**\n * Add a geocoder control to the map.\n *\n * The Mapbox geocoder module is an optional peer dependency and is loaded on\n * demand with a dynamic `import()` when the component mounts, so the rest of the\n * package keeps working without it installed.\n *\n * @see https://ui.studiometa.dev/reference/items/MapboxMap/\n */\nexport class MapboxGeocoder<T extends BaseProps = BaseProps> extends AbstractMapboxMapChild<\n T & MapboxGeocoderProps\n> {\n /**\n * Config.\n */\n static config: BaseConfig = {\n name: 'MapboxGeocoder',\n options: {\n addToMap: Boolean,\n options: Object,\n },\n };\n\n /**\n * Control instance, created once the lazily imported module resolves.\n * @private\n */\n __control?: MapboxGeocoderControl;\n\n /**\n * The Mapbox geocoder control instance, if it has been created yet.\n */\n get control(): MapboxGeocoderControl | undefined {\n return this.__control;\n }\n\n /**\n * Target element the geocoder is added to: the map when `addToMap` is set,\n * otherwise the component's own root element.\n */\n get target(): Map | HTMLElement | string {\n return this.$options.addToMap ? this.map : this.$el;\n }\n\n /**\n * Mounted hook.\n *\n * Lazily loads the optional Mapbox geocoder module, then builds and adds the\n * control once the parent map is ready.\n */\n async mounted() {\n const GeocoderControlClass = await resolveMapboxGeocoder();\n\n // The component may have been destroyed while the dynamic import was still\n // resolving. Bail out before creating and adding the control, otherwise it\n // would be attached after `__onDestroyed()` already ran (and saw `__control`\n // undefined), leaking an orphan control.\n if (!this.$isMounted) {\n return;\n }\n\n this.whenMapReady(() => {\n // The ready callback is standing: it re-runs on every map replacement. An\n // element-targeted control (`addToMap` false) lives on `$el`, which\n // survives the map swap, so a previous control must be removed first or\n // each replacement would stack another geocoder onto the element. A\n // map-targeted control went away with its (removed) map, so only its\n // reference needs dropping.\n if (this.__control) {\n if (!this.$options.addToMap) {\n this.__control.onRemove();\n }\n this.__control = undefined;\n }\n\n const options = {\n ...this.$options.options,\n mapboxgl: getMapboxGl(),\n accessToken:\n this.$options.options.accessToken ?? this.__readyMapboxMap?.$options.accessToken,\n };\n this.__control = new GeocoderControlClass(\n options as ConstructorParameters<typeof GeocoderControlClass>[0],\n );\n // Re-emit the control's `result` event as a prefixed component event so\n // consumers (e.g. a `StoreLocator`) can react to a geocoded address.\n this.__control.on?.('result', (event) => this.$emit('map-result', { result: event.result }));\n this.__control.addTo(this.target);\n });\n }\n\n /**\n * Teardown hook.\n */\n __onDestroyed() {\n // The control may not exist yet: the dynamic import in `mounted()` might not\n // have resolved, or the geocoder module was never loaded.\n if (this.__control) {\n if (this.$options.addToMap) {\n this.__readyMap?.removeControl(this.__control as unknown as IControl);\n } else {\n this.__control.onRemove();\n }\n this.__control = undefined;\n }\n }\n}\n\nexport default MapboxGeocoder;\n"],"mappings":";;;;;;;;;;;;AAyCA,IAAa,iBAAb,cAAqE,uBAEnE;;;;CAIA,OAAO,SAAqB;EAC1B,MAAM;EACN,SAAS;GACP,UAAU;GACV,SAAS;GACV;EACF;;;;;CAMD;;;;CAKA,IAAI,UAA6C;AAC/C,SAAO,KAAK;;;;;;CAOd,IAAI,SAAqC;AACvC,SAAO,KAAK,SAAS,WAAW,KAAK,MAAM,KAAK;;;;;;;;CASlD,MAAM,UAAU;EACd,MAAM,uBAAuB,MAAM,uBAAuB;AAM1D,MAAI,CAAC,KAAK,WACR;AAGF,OAAK,mBAAmB;AAOtB,OAAI,KAAK,WAAW;AAClB,QAAI,CAAC,KAAK,SAAS,SACjB,MAAK,UAAU,UAAU;AAE3B,SAAK,YAAY,KAAA;;AASnB,QAAK,YAAY,IAAI,qBANL;IACd,GAAG,KAAK,SAAS;IACjB,UAAU,aAAa;IACvB,aACE,KAAK,SAAS,QAAQ,eAAe,KAAK,kBAAkB,SAAS;IACxE,CAGA;AAGD,QAAK,UAAU,KAAK,WAAW,UAAU,KAAK,MAAM,cAAc,EAAE,QAAQ,MAAM,QAAQ,CAAC,CAAC;AAC5F,QAAK,UAAU,MAAM,KAAK,OAAO;IACjC;;;;;CAMJ,gBAAgB;AAGd,MAAI,KAAK,WAAW;AAClB,OAAI,KAAK,SAAS,SAChB,MAAK,YAAY,cAAc,KAAK,UAAiC;OAErE,MAAK,UAAU,UAAU;AAE3B,QAAK,YAAY,KAAA"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { AbstractMapboxControlProps } from "./AbstractMapboxControl.js";
|
|
2
|
-
import
|
|
1
|
+
import { AbstractMapboxControl, AbstractMapboxControlProps } from "./AbstractMapboxControl.js";
|
|
2
|
+
import { BaseConfig, BaseProps } from "@studiometa/js-toolkit";
|
|
3
3
|
import * as mapbox_gl0 from "mapbox-gl";
|
|
4
4
|
import { GeolocateControlOptions } from "mapbox-gl";
|
|
5
5
|
|
|
@@ -7,12 +7,16 @@ import { GeolocateControlOptions } from "mapbox-gl";
|
|
|
7
7
|
interface MapboxGeolocateControlProps extends AbstractMapboxControlProps {
|
|
8
8
|
$options: AbstractMapboxControlProps['$options'] & Omit<GeolocateControlOptions, 'geolocation'>;
|
|
9
9
|
}
|
|
10
|
-
declare const MapboxGeolocateControl_base: _studiometa_js_toolkit0.BaseDecorator<_studiometa_js_toolkit0.BaseInterface, _studiometa_js_toolkit0.Base<_studiometa_js_toolkit0.BaseProps>>;
|
|
11
10
|
/**
|
|
12
11
|
* Add a geolocate control to the map.
|
|
12
|
+
*
|
|
13
13
|
* @see https://ui.studiometa.dev/reference/items/MapboxMap/
|
|
14
14
|
*/
|
|
15
|
-
declare class MapboxGeolocateControl extends
|
|
15
|
+
declare class MapboxGeolocateControl<T extends BaseProps = BaseProps> extends AbstractMapboxControl<T & MapboxGeolocateControlProps> {
|
|
16
|
+
/**
|
|
17
|
+
* Config.
|
|
18
|
+
*/
|
|
19
|
+
static config: BaseConfig;
|
|
16
20
|
/**
|
|
17
21
|
* Create the mapbox GeolocateControl instance.
|
|
18
22
|
* @protected
|
|
@@ -1,22 +1,26 @@
|
|
|
1
1
|
import { AbstractMapboxControl } from "./AbstractMapboxControl.js";
|
|
2
2
|
import { getMapboxGl } from "./dependencies.js";
|
|
3
|
-
import { withExtraConfig } from "@studiometa/js-toolkit/withExtraConfig";
|
|
4
3
|
//#region src/MapboxGeolocateControl.ts
|
|
5
4
|
/**
|
|
6
5
|
* Add a geolocate control to the map.
|
|
6
|
+
*
|
|
7
7
|
* @see https://ui.studiometa.dev/reference/items/MapboxMap/
|
|
8
8
|
*/
|
|
9
|
-
var MapboxGeolocateControl = class extends
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
9
|
+
var MapboxGeolocateControl = class extends AbstractMapboxControl {
|
|
10
|
+
/**
|
|
11
|
+
* Config.
|
|
12
|
+
*/
|
|
13
|
+
static config = {
|
|
14
|
+
name: "MapboxGeolocateControl",
|
|
15
|
+
options: {
|
|
16
|
+
positionOptions: Object,
|
|
17
|
+
fitBoundsOptions: Object,
|
|
18
|
+
trackUserLocation: Boolean,
|
|
19
|
+
showAccuracyCircle: Boolean,
|
|
20
|
+
showUserLocation: Boolean,
|
|
21
|
+
showUserHeading: Boolean
|
|
22
|
+
}
|
|
23
|
+
};
|
|
20
24
|
/**
|
|
21
25
|
* Create the mapbox GeolocateControl instance.
|
|
22
26
|
* @protected
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MapboxGeolocateControl.js","names":[],"sources":["../src/MapboxGeolocateControl.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"MapboxGeolocateControl.js","names":[],"sources":["../src/MapboxGeolocateControl.ts"],"sourcesContent":["import type { BaseConfig, BaseProps } from '@studiometa/js-toolkit';\nimport type { GeolocateControlOptions } from 'mapbox-gl';\nimport { AbstractMapboxControl, type AbstractMapboxControlProps } from './AbstractMapboxControl.js';\nimport { getMapboxGl } from './dependencies.js';\n\nexport interface MapboxGeolocateControlProps extends AbstractMapboxControlProps {\n $options: AbstractMapboxControlProps['$options'] & Omit<GeolocateControlOptions, 'geolocation'>;\n}\n\n/**\n * Add a geolocate control to the map.\n *\n * @see https://ui.studiometa.dev/reference/items/MapboxMap/\n */\nexport class MapboxGeolocateControl<T extends BaseProps = BaseProps> extends AbstractMapboxControl<\n T & MapboxGeolocateControlProps\n> {\n /**\n * Config.\n */\n static config: BaseConfig = {\n name: 'MapboxGeolocateControl',\n options: {\n positionOptions: Object,\n fitBoundsOptions: Object,\n trackUserLocation: Boolean,\n showAccuracyCircle: Boolean,\n showUserLocation: Boolean,\n showUserHeading: Boolean,\n },\n };\n\n /**\n * Create the mapbox GeolocateControl instance.\n * @protected\n */\n createControl(options: GeolocateControlOptions) {\n return new (getMapboxGl().GeolocateControl)(options);\n }\n}\n\nexport default MapboxGeolocateControl;\n"],"mappings":";;;;;;;;AAcA,IAAa,yBAAb,cAA6E,sBAE3E;;;;CAIA,OAAO,SAAqB;EAC1B,MAAM;EACN,SAAS;GACP,iBAAiB;GACjB,kBAAkB;GAClB,mBAAmB;GACnB,oBAAoB;GACpB,kBAAkB;GAClB,iBAAiB;GAClB;EACF;;;;;CAMD,cAAc,SAAkC;AAC9C,SAAO,KAAK,aAAa,EAAC,iBAAkB,QAAQ"}
|
package/dist/MapboxImage.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AbstractMapboxMapChild, AbstractMapboxMapChildProps } from "./AbstractMapboxMapChild.js";
|
|
2
|
-
import { MapboxImageOptions } from "./utils.js";
|
|
2
|
+
import { MapboxImage as MapboxImage$1, MapboxImageOptions } from "./utils.js";
|
|
3
3
|
import { BaseConfig, BaseProps } from "@studiometa/js-toolkit";
|
|
4
4
|
|
|
5
5
|
//#region src/MapboxImage.d.ts
|
|
@@ -13,6 +13,16 @@ interface MapboxImageProps extends AbstractMapboxMapChildProps {
|
|
|
13
13
|
*/
|
|
14
14
|
options: MapboxImageOptions;
|
|
15
15
|
};
|
|
16
|
+
/**
|
|
17
|
+
* Announced once the sprite is registered against the map.
|
|
18
|
+
*/
|
|
19
|
+
$emits: AbstractMapboxMapChildProps['$emits'] & {
|
|
20
|
+
'map-ready': {
|
|
21
|
+
name: string;
|
|
22
|
+
image: MapboxImage$1;
|
|
23
|
+
options: MapboxImageOptions;
|
|
24
|
+
};
|
|
25
|
+
};
|
|
16
26
|
}
|
|
17
27
|
/**
|
|
18
28
|
* Load and register a single image against the map sprite.
|
package/dist/MapboxImage.js
CHANGED
package/dist/MapboxImage.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MapboxImage.js","names":[],"sources":["../src/MapboxImage.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"MapboxImage.js","names":[],"sources":["../src/MapboxImage.ts"],"sourcesContent":["import type { BaseProps, BaseConfig } from '@studiometa/js-toolkit';\nimport {\n AbstractMapboxMapChild,\n type AbstractMapboxMapChildProps,\n} from './AbstractMapboxMapChild.js';\nimport {\n addMapboxImage,\n claimMapboxOwnership,\n getMapboxOwner,\n releaseMapboxOwnership,\n type MapboxImage as MapboxImageBitmap,\n type MapboxImageOptions,\n} from './utils.js';\n\nexport interface MapboxImageProps extends AbstractMapboxMapChildProps {\n $options: {\n name: string;\n url: string;\n /**\n * The image options forwarded to `map.addImage`.\n * @see https://docs.mapbox.com/mapbox-gl-js/api/map/#map#addimage\n */\n options: MapboxImageOptions;\n };\n /**\n * Announced once the sprite is registered against the map.\n */\n $emits: AbstractMapboxMapChildProps['$emits'] & {\n 'map-ready': { name: string; image: MapboxImageBitmap; options: MapboxImageOptions };\n };\n}\n\n/**\n * Load and register a single image against the map sprite.\n * @see https://ui.studiometa.dev/reference/items/MapboxMap/\n */\nexport class MapboxImage<T extends BaseProps = BaseProps> extends AbstractMapboxMapChild<\n T & MapboxImageProps\n> {\n /**\n * Config.\n */\n static config: BaseConfig = {\n name: 'MapboxImage',\n options: {\n name: String,\n url: String,\n options: {\n type: Object,\n default: () => ({ pixelRatio: 1, sdf: false }),\n },\n },\n };\n\n /**\n * Whether this instance owns the sprite under its name. Only a sprite this\n * instance owns may be removed on teardown; a pre-existing sprite declared\n * outside the family is left untouched, and a sprite a newer sibling has since\n * adopted (a same-name `Fetch` swap) is left to that sibling.\n * @private\n */\n __owned = false;\n\n /**\n * The `kind:name` ownership key for this sprite.\n * @private\n */\n get __ownershipKey(): string {\n return `image:${this.$options.name}`;\n }\n\n /**\n * Mounted hook.\n */\n mounted() {\n this.whenMapReady(async (map) => {\n const { name, url, options } = this.$options;\n const { image, added } = await addMapboxImage(map, { name, url, options });\n\n // The component may have been destroyed — or the map removed/replaced —\n // while the image was loading. Undo the add (only when THIS call added it,\n // and only while the map is still current & alive; a removed map took its\n // sprites with it) and bail before emitting so no orphan sprite survives.\n if (!this.$isMounted || this.__readyMap !== map) {\n if (added && this.__readyMap === map && map.hasImage(name)) {\n map.removeImage(name);\n }\n return;\n }\n\n // Own the sprite when we added it, or adopt it from a family sibling — a\n // same-name `Fetch` swap that added the sprite before this instance\n // mounted — so the outgoing instance's teardown does not remove the sprite\n // this mounted replacement now depends on. An unowned external sprite is\n // left untouched (and unclaimed).\n if (added || getMapboxOwner(map, this.__ownershipKey)) {\n // Sprites expose no object identity, so liveness can only probe\n // `hasImage`: enough to drop the entry after a `setStyle` wipe or an\n // external `removeImage`, and to re-own on a `style.load` re-injection.\n claimMapboxOwnership(map, this.__ownershipKey, this, () => map.hasImage(name));\n this.__owned = true;\n }\n\n this.$emit('map-ready', { name, image, options });\n });\n }\n\n /**\n * Teardown hook.\n */\n __onDestroyed() {\n const { name } = this.$options;\n const map = this.__readyMap;\n\n // Only remove a sprite this instance still owns: a newer sibling may have\n // adopted the name, and a removed map is already gone (`__readyMap` is unset).\n if (\n this.__owned &&\n getMapboxOwner(map as object, this.__ownershipKey) === this &&\n map?.hasImage(name)\n ) {\n map.removeImage(name);\n releaseMapboxOwnership(map, this.__ownershipKey, this);\n }\n }\n}\n\nexport default MapboxImage;\n"],"mappings":";;;;;;;AAoCA,IAAa,cAAb,cAAkE,uBAEhE;;;;CAIA,OAAO,SAAqB;EAC1B,MAAM;EACN,SAAS;GACP,MAAM;GACN,KAAK;GACL,SAAS;IACP,MAAM;IACN,gBAAgB;KAAE,YAAY;KAAG,KAAK;KAAO;IAC9C;GACF;EACF;;;;;;;;CASD,UAAU;;;;;CAMV,IAAI,iBAAyB;AAC3B,SAAO,SAAS,KAAK,SAAS;;;;;CAMhC,UAAU;AACR,OAAK,aAAa,OAAO,QAAQ;GAC/B,MAAM,EAAE,MAAM,KAAK,YAAY,KAAK;GACpC,MAAM,EAAE,OAAO,UAAU,MAAM,eAAe,KAAK;IAAE;IAAM;IAAK;IAAS,CAAC;AAM1E,OAAI,CAAC,KAAK,cAAc,KAAK,eAAe,KAAK;AAC/C,QAAI,SAAS,KAAK,eAAe,OAAO,IAAI,SAAS,KAAK,CACxD,KAAI,YAAY,KAAK;AAEvB;;AAQF,OAAI,SAAS,eAAe,KAAK,KAAK,eAAe,EAAE;AAIrD,yBAAqB,KAAK,KAAK,gBAAgB,YAAY,IAAI,SAAS,KAAK,CAAC;AAC9E,SAAK,UAAU;;AAGjB,QAAK,MAAM,aAAa;IAAE;IAAM;IAAO;IAAS,CAAC;IACjD;;;;;CAMJ,gBAAgB;EACd,MAAM,EAAE,SAAS,KAAK;EACtB,MAAM,MAAM,KAAK;AAIjB,MACE,KAAK,WACL,eAAe,KAAe,KAAK,eAAe,KAAK,QACvD,KAAK,SAAS,KAAK,EACnB;AACA,OAAI,YAAY,KAAK;AACrB,0BAAuB,KAAK,KAAK,gBAAgB,KAAK"}
|
package/dist/MapboxImages.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AbstractMapboxMapChild, AbstractMapboxMapChildProps } from "./AbstractMapboxMapChild.js";
|
|
2
|
-
import { MapboxImageDefinition } from "./utils.js";
|
|
2
|
+
import { MapboxImage, MapboxImageDefinition } from "./utils.js";
|
|
3
3
|
import { BaseConfig, BaseProps } from "@studiometa/js-toolkit";
|
|
4
4
|
import { Map } from "mapbox-gl";
|
|
5
5
|
|
|
@@ -12,6 +12,14 @@ interface MapboxImagesProps extends AbstractMapboxMapChildProps {
|
|
|
12
12
|
*/
|
|
13
13
|
sources: MapboxImageDefinition[];
|
|
14
14
|
};
|
|
15
|
+
/**
|
|
16
|
+
* Announced once every sprite in the list is registered against the map.
|
|
17
|
+
*/
|
|
18
|
+
$emits: AbstractMapboxMapChildProps['$emits'] & {
|
|
19
|
+
'map-ready': {
|
|
20
|
+
images: MapboxImage[];
|
|
21
|
+
};
|
|
22
|
+
};
|
|
15
23
|
}
|
|
16
24
|
/**
|
|
17
25
|
* Load and register a list of images against the map sprite.
|
package/dist/MapboxImages.js
CHANGED
|
@@ -11,7 +11,6 @@ var MapboxImages = class extends AbstractMapboxMapChild {
|
|
|
11
11
|
*/
|
|
12
12
|
static config = {
|
|
13
13
|
name: "MapboxImages",
|
|
14
|
-
emits: ["map-ready"],
|
|
15
14
|
options: { sources: {
|
|
16
15
|
type: Array,
|
|
17
16
|
default: () => []
|
|
@@ -48,7 +47,7 @@ var MapboxImages = class extends AbstractMapboxMapChild {
|
|
|
48
47
|
if (this.__readyMap === map) this.__removeOwned(map);
|
|
49
48
|
return;
|
|
50
49
|
}
|
|
51
|
-
this.$emit("map-ready", images);
|
|
50
|
+
this.$emit("map-ready", { images });
|
|
52
51
|
});
|
|
53
52
|
}
|
|
54
53
|
/**
|
package/dist/MapboxImages.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MapboxImages.js","names":[],"sources":["../src/MapboxImages.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"MapboxImages.js","names":[],"sources":["../src/MapboxImages.ts"],"sourcesContent":["import type { BaseProps, BaseConfig } from '@studiometa/js-toolkit';\nimport {\n AbstractMapboxMapChild,\n type AbstractMapboxMapChildProps,\n} from './AbstractMapboxMapChild.js';\nimport type { Map } from 'mapbox-gl';\nimport {\n addMapboxImage,\n claimMapboxOwnership,\n getMapboxOwner,\n releaseMapboxOwnership,\n type MapboxImage,\n type MapboxImageDefinition,\n} from './utils.js';\n\nexport interface MapboxImagesProps extends AbstractMapboxMapChildProps {\n $options: {\n /**\n * A list of images to register against the map sprite.\n * @see ./MapboxImage.ts\n */\n sources: MapboxImageDefinition[];\n };\n /**\n * Announced once every sprite in the list is registered against the map.\n */\n $emits: AbstractMapboxMapChildProps['$emits'] & {\n 'map-ready': { images: MapboxImage[] };\n };\n}\n\n/**\n * Load and register a list of images against the map sprite.\n * @see https://ui.studiometa.dev/reference/items/MapboxMap/\n */\nexport class MapboxImages<T extends BaseProps = BaseProps> extends AbstractMapboxMapChild<\n T & MapboxImagesProps\n> {\n /**\n * Config.\n */\n static config: BaseConfig = {\n name: 'MapboxImages',\n options: {\n sources: {\n type: Array,\n default: () => [],\n },\n },\n };\n\n /**\n * The names of the sprites this instance owns. Only these may be removed on\n * teardown; pre-existing sprites (registered by someone else) are left\n * untouched, and a sprite a newer sibling has since adopted is left to it.\n * @private\n */\n __ownedNames: string[] = [];\n\n /**\n * The `kind:name` ownership key for the given sprite.\n * @private\n * @param {string} name\n * @returns {string}\n */\n __ownershipKey(name: string): string {\n return `image:${name}`;\n }\n\n /**\n * Mounted hook.\n */\n mounted() {\n this.whenMapReady(async (map) => {\n const { sources } = this.$options;\n const images = await Promise.all(\n sources.map(async (source) => {\n const { image, added } = await addMapboxImage(map, source);\n // Take ownership incrementally, as each image settles, rather than\n // after the whole batch: if a later entry rejects, `Promise.all`\n // rejects, but the sprites already added stay owned and removable on\n // teardown instead of orphaned.\n this.__adopt(map, source.name, added);\n return image;\n }),\n );\n\n // The component may have been destroyed — or the map removed/replaced —\n // while the images were loading. Remove the ones we own (only while the\n // map is still current & alive) and bail before emitting to avoid orphans.\n if (!this.$isMounted || this.__readyMap !== map) {\n if (this.__readyMap === map) {\n this.__removeOwned(map);\n }\n return;\n }\n\n this.$emit('map-ready', { images });\n });\n }\n\n /**\n * Own a sprite this instance added, or adopt one from a family sibling (a\n * same-name `Fetch` swap), so the outgoing instance's teardown does not remove\n * a sprite this replacement now depends on.\n * @private\n * @param {Map} map\n * @param {string} name\n * @param {boolean} added\n */\n __adopt(map: Map, name: string, added: boolean) {\n if (added || getMapboxOwner(map, this.__ownershipKey(name))) {\n // Sprites expose no object identity, so liveness can only probe\n // `hasImage`: enough to drop the entry after a `setStyle` wipe or an\n // external `removeImage`, and to re-own on a `style.load` re-injection.\n claimMapboxOwnership(map, this.__ownershipKey(name), this, () => map.hasImage(name));\n if (!this.__ownedNames.includes(name)) {\n this.__ownedNames.push(name);\n }\n }\n }\n\n /**\n * Remove every sprite this instance still owns from the given map, releasing\n * ownership as it goes.\n * @private\n * @param {Map | undefined} map\n */\n __removeOwned(map?: Map) {\n for (const name of this.__ownedNames) {\n const key = this.__ownershipKey(name);\n if (getMapboxOwner(map as object, key) === this && map?.hasImage(name)) {\n map.removeImage(name);\n releaseMapboxOwnership(map, key, this);\n }\n }\n this.__ownedNames = [];\n }\n\n /**\n * Teardown hook.\n */\n __onDestroyed() {\n this.__removeOwned(this.__readyMap);\n }\n}\n\nexport default MapboxImages;\n"],"mappings":";;;;;;;AAmCA,IAAa,eAAb,cAAmE,uBAEjE;;;;CAIA,OAAO,SAAqB;EAC1B,MAAM;EACN,SAAS,EACP,SAAS;GACP,MAAM;GACN,eAAe,EAAE;GAClB,EACF;EACF;;;;;;;CAQD,eAAyB,EAAE;;;;;;;CAQ3B,eAAe,MAAsB;AACnC,SAAO,SAAS;;;;;CAMlB,UAAU;AACR,OAAK,aAAa,OAAO,QAAQ;GAC/B,MAAM,EAAE,YAAY,KAAK;GACzB,MAAM,SAAS,MAAM,QAAQ,IAC3B,QAAQ,IAAI,OAAO,WAAW;IAC5B,MAAM,EAAE,OAAO,UAAU,MAAM,eAAe,KAAK,OAAO;AAK1D,SAAK,QAAQ,KAAK,OAAO,MAAM,MAAM;AACrC,WAAO;KACP,CACH;AAKD,OAAI,CAAC,KAAK,cAAc,KAAK,eAAe,KAAK;AAC/C,QAAI,KAAK,eAAe,IACtB,MAAK,cAAc,IAAI;AAEzB;;AAGF,QAAK,MAAM,aAAa,EAAE,QAAQ,CAAC;IACnC;;;;;;;;;;;CAYJ,QAAQ,KAAU,MAAc,OAAgB;AAC9C,MAAI,SAAS,eAAe,KAAK,KAAK,eAAe,KAAK,CAAC,EAAE;AAI3D,wBAAqB,KAAK,KAAK,eAAe,KAAK,EAAE,YAAY,IAAI,SAAS,KAAK,CAAC;AACpF,OAAI,CAAC,KAAK,aAAa,SAAS,KAAK,CACnC,MAAK,aAAa,KAAK,KAAK;;;;;;;;;CAWlC,cAAc,KAAW;AACvB,OAAK,MAAM,QAAQ,KAAK,cAAc;GACpC,MAAM,MAAM,KAAK,eAAe,KAAK;AACrC,OAAI,eAAe,KAAe,IAAI,KAAK,QAAQ,KAAK,SAAS,KAAK,EAAE;AACtE,QAAI,YAAY,KAAK;AACrB,2BAAuB,KAAK,KAAK,KAAK;;;AAG1C,OAAK,eAAe,EAAE;;;;;CAMxB,gBAAgB;AACd,OAAK,cAAc,KAAK,WAAW"}
|
package/dist/MapboxLayer.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MapboxLayer.js","names":[],"sources":["../src/MapboxLayer.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"MapboxLayer.js","names":[],"sources":["../src/MapboxLayer.ts"],"sourcesContent":["import type { BaseProps, BaseConfig } from '@studiometa/js-toolkit';\nimport type { LayerSpecification, Map, MapSourceDataEvent } from 'mapbox-gl';\nimport {\n AbstractMapboxMapChild,\n type AbstractMapboxMapChildProps,\n} from './AbstractMapboxMapChild.js';\nimport { claimMapboxOwnership, getMapboxOwner, releaseMapboxOwnership } from './utils.js';\n\nexport interface MapboxLayerProps extends AbstractMapboxMapChildProps {\n $options: {\n id: string;\n layer: LayerSpecification;\n beforeId: string;\n };\n}\n\n/**\n * Add a layer to the map.\n * @see https://ui.studiometa.dev/reference/items/MapboxMap/\n */\nexport class MapboxLayer<T extends BaseProps = BaseProps> extends AbstractMapboxMapChild<\n T & MapboxLayerProps\n> {\n /**\n * Config.\n */\n static config: BaseConfig = {\n name: 'MapboxLayer',\n options: {\n id: String,\n layer: Object,\n beforeId: String,\n },\n };\n\n /**\n * Whether this instance owns the layer under its id. Only a layer this\n * instance owns may be removed on teardown; a layer declared outside the\n * family, or one a newer sibling has since adopted, is left untouched.\n * @private\n */\n __added = false;\n\n /**\n * The `kind:id` ownership key for this layer.\n * @private\n */\n get __ownershipKey(): string {\n return `layer:${this.$options.id}`;\n }\n\n /**\n * The source id this layer references, when it references one by string.\n * @private\n */\n get __sourceId(): string | undefined {\n const { source } = this.$options.layer as { source?: unknown };\n return typeof source === 'string' ? source : undefined;\n }\n\n /**\n * Add (or re-add) the layer whenever its referenced source becomes available\n * and the layer is not currently on the map.\n *\n * This is a *standing* recovery watch, not a one-shot: it stays subscribed for\n * the layer's whole life so the layer re-commits itself if its source\n * disappears and comes back — e.g. a sibling `MapboxSource` teardown removes\n * this still-mounted layer to drop its source, then the source is re-added\n * later (H7, PR #567 review). Committing once and unsubscribing (the previous\n * behaviour) left such a layer gone for good.\n *\n * It is kept cheap: `sourcedata` fires often, so the handler early-returns\n * unless this layer is actually missing, and — when the event identifies a\n * source — ignores events for any source other than this layer's. The commit\n * itself is deferred to a microtask because mutating the style from within\n * mapbox-gl's render loop can leave a layer half-initialized and crash the\n * symbol placement pass.\n * @private\n * @param {MapSourceDataEvent} [event]\n */\n __handleSourceData = (event?: MapSourceDataEvent) => {\n const map = this.__readyMap;\n const { id } = this.$options;\n\n // Ignore events for an unrelated source when the event tells us which one it\n // is: this gates the standing watch to this layer's source id.\n if (event?.sourceId && this.__sourceId && event.sourceId !== this.__sourceId) {\n return;\n }\n\n if (!map || map.getLayer(id) || !this.__sourceIsAvailable(map)) {\n return;\n }\n\n queueMicrotask(() => {\n // Re-check under the microtask: the map may have been removed/replaced, the\n // component destroyed, or the layer committed by another path in between.\n if (this.$isMounted && this.__readyMap === map && !map.getLayer(id)) {\n this.__commitLayer(map);\n }\n });\n };\n\n /**\n * Add the layer to the map, or adopt an existing one.\n *\n * When the id is free the layer is added and ownership claimed. When a layer\n * with this id already exists, re-adding it would throw a duplicate-id error,\n * so it is left in place; ownership is only taken over from a sibling\n * `MapboxLayer` (e.g. a `Fetch` swap), never from an externally declared layer.\n * @private\n * @param {Map} map\n */\n __commitLayer(map: Map): void {\n const { beforeId, id, layer } = this.$options;\n // `$options.layer` returns a freshly parsed object, so re-apply the id.\n layer.id = id;\n\n if (map.getLayer(id)) {\n // The id is taken. Only adopt it from another family instance (e.g. a\n // `Fetch` swap that mounted the replacement before the original tore\n // down); an externally declared layer stays untouched. Adopt AND refresh:\n // the incoming definition may differ in source/type/paint/layout/filter/\n // zoom range/beforeId, so re-add it (we own it) rather than leaving Mapbox\n // rendering the outgoing definition — matching how `MapboxSource` refreshes\n // its data on adopt.\n if (getMapboxOwner(map, this.__ownershipKey)) {\n map.removeLayer(id);\n map.addLayer(layer, beforeId);\n const added = map.getLayer(id);\n claimMapboxOwnership(map, this.__ownershipKey, this, () => map.getLayer(id) === added);\n this.__added = true;\n }\n return;\n }\n\n map.addLayer(layer, beforeId);\n // Own the id, keyed to the very layer object just added: the liveness probe\n // reports the entry stale the moment this layer is removed (a `setStyle`\n // wipe, a sibling source teardown, an external `removeLayer`) or replaced\n // under the same id, so it can never misclassify a stranger's later layer.\n const added = map.getLayer(id);\n claimMapboxOwnership(map, this.__ownershipKey, this, () => map.getLayer(id) === added);\n this.__added = true;\n }\n\n /**\n * Whether the source referenced by the layer is available on the map.\n *\n * Layers referencing an inline source object — or no source at all, like a\n * `background` layer — are always considered available.\n * @private\n * @param {Map} map\n * @returns {boolean}\n */\n __sourceIsAvailable(map: Map): boolean {\n const { source } = this.$options.layer as { source?: unknown };\n return typeof source !== 'string' || Boolean(map.getSource(source));\n }\n\n /**\n * Mounted hook.\n */\n mounted() {\n this.whenMapReady((map) => {\n // Install (or re-install, on a `style.load` re-injection) the standing\n // recovery watch exactly once. `off` before `on` keeps a single\n // subscription when `whenMapReady`'s callback re-runs after a `setStyle`.\n map.off('sourcedata', this.__handleSourceData);\n map.on('sourcedata', this.__handleSourceData);\n\n // The referenced source may be declared by a sibling `MapboxSource` that\n // has not mounted yet — sibling mount order is not guaranteed. Adding a\n // layer before its source silently fails, so commit now when the source is\n // available and otherwise let the standing watch commit once it arrives.\n if (this.__sourceIsAvailable(map)) {\n this.__commitLayer(map);\n }\n });\n }\n\n /**\n * Flush the standing `sourcedata` recovery watch against the map being\n * removed, while it is still referenceable — `__onDestroyed` runs later with\n * `__readyMap` already cleared and could not reach the map to unsubscribe.\n * @protected\n * @param {Map} map\n */\n __onMapRemove(map: Map) {\n map.off('sourcedata', this.__handleSourceData);\n }\n\n /**\n * Teardown hook.\n */\n __onDestroyed() {\n const map = this.__readyMap;\n const { id } = this.$options;\n\n map?.off('sourcedata', this.__handleSourceData);\n\n // Only remove a layer 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?.getLayer(id)\n ) {\n map.removeLayer(id);\n releaseMapboxOwnership(map, this.__ownershipKey, this);\n }\n }\n}\n\nexport default MapboxLayer;\n"],"mappings":";;;;;;;AAoBA,IAAa,cAAb,cAAkE,uBAEhE;;;;CAIA,OAAO,SAAqB;EAC1B,MAAM;EACN,SAAS;GACP,IAAI;GACJ,OAAO;GACP,UAAU;GACX;EACF;;;;;;;CAQD,UAAU;;;;;CAMV,IAAI,iBAAyB;AAC3B,SAAO,SAAS,KAAK,SAAS;;;;;;CAOhC,IAAI,aAAiC;EACnC,MAAM,EAAE,WAAW,KAAK,SAAS;AACjC,SAAO,OAAO,WAAW,WAAW,SAAS,KAAA;;;;;;;;;;;;;;;;;;;;;;CAuB/C,sBAAsB,UAA+B;EACnD,MAAM,MAAM,KAAK;EACjB,MAAM,EAAE,OAAO,KAAK;AAIpB,MAAI,OAAO,YAAY,KAAK,cAAc,MAAM,aAAa,KAAK,WAChE;AAGF,MAAI,CAAC,OAAO,IAAI,SAAS,GAAG,IAAI,CAAC,KAAK,oBAAoB,IAAI,CAC5D;AAGF,uBAAqB;AAGnB,OAAI,KAAK,cAAc,KAAK,eAAe,OAAO,CAAC,IAAI,SAAS,GAAG,CACjE,MAAK,cAAc,IAAI;IAEzB;;;;;;;;;;;;CAaJ,cAAc,KAAgB;EAC5B,MAAM,EAAE,UAAU,IAAI,UAAU,KAAK;AAErC,QAAM,KAAK;AAEX,MAAI,IAAI,SAAS,GAAG,EAAE;AAQpB,OAAI,eAAe,KAAK,KAAK,eAAe,EAAE;AAC5C,QAAI,YAAY,GAAG;AACnB,QAAI,SAAS,OAAO,SAAS;IAC7B,MAAM,QAAQ,IAAI,SAAS,GAAG;AAC9B,yBAAqB,KAAK,KAAK,gBAAgB,YAAY,IAAI,SAAS,GAAG,KAAK,MAAM;AACtF,SAAK,UAAU;;AAEjB;;AAGF,MAAI,SAAS,OAAO,SAAS;EAK7B,MAAM,QAAQ,IAAI,SAAS,GAAG;AAC9B,uBAAqB,KAAK,KAAK,gBAAgB,YAAY,IAAI,SAAS,GAAG,KAAK,MAAM;AACtF,OAAK,UAAU;;;;;;;;;;;CAYjB,oBAAoB,KAAmB;EACrC,MAAM,EAAE,WAAW,KAAK,SAAS;AACjC,SAAO,OAAO,WAAW,YAAY,QAAQ,IAAI,UAAU,OAAO,CAAC;;;;;CAMrE,UAAU;AACR,OAAK,cAAc,QAAQ;AAIzB,OAAI,IAAI,cAAc,KAAK,mBAAmB;AAC9C,OAAI,GAAG,cAAc,KAAK,mBAAmB;AAM7C,OAAI,KAAK,oBAAoB,IAAI,CAC/B,MAAK,cAAc,IAAI;IAEzB;;;;;;;;;CAUJ,cAAc,KAAU;AACtB,MAAI,IAAI,cAAc,KAAK,mBAAmB;;;;;CAMhD,gBAAgB;EACd,MAAM,MAAM,KAAK;EACjB,MAAM,EAAE,OAAO,KAAK;AAEpB,OAAK,IAAI,cAAc,KAAK,mBAAmB;AAI/C,MACE,KAAK,WACL,eAAe,KAAe,KAAK,eAAe,KAAK,QACvD,KAAK,SAAS,GAAG,EACjB;AACA,OAAI,YAAY,GAAG;AACnB,0BAAuB,KAAK,KAAK,gBAAgB,KAAK"}
|
package/dist/MapboxMap.d.ts
CHANGED
|
@@ -3,6 +3,9 @@ import { Map, MapOptions } from "mapbox-gl";
|
|
|
3
3
|
import { Base } from "@studiometa/js-toolkit/Base";
|
|
4
4
|
|
|
5
5
|
//#region src/MapboxMap.d.ts
|
|
6
|
+
declare const FORWARDED_MAP_EVENTS: readonly ["click", "dblclick", "mouseenter", "mouseleave", "mousemove", "movestart", "move", "moveend", "zoomstart", "zoom", "zoomend", "rotatestart", "rotate", "rotateend", "pitchstart", "pitch", "pitchend", "dragstart", "drag", "dragend", "idle", "render", "resize", "remove", "error"];
|
|
7
|
+
/** One forwarded mapbox event name, prefixed the way the component re-emits it. */
|
|
8
|
+
type ForwardedMapEvent = `map-${(typeof FORWARDED_MAP_EVENTS)[number]}`;
|
|
6
9
|
interface MapboxMapProps extends BaseProps {
|
|
7
10
|
$refs: {
|
|
8
11
|
container: HTMLElement;
|
|
@@ -13,6 +16,18 @@ interface MapboxMapProps extends BaseProps {
|
|
|
13
16
|
center: [number, number];
|
|
14
17
|
mapOptions: Partial<Omit<MapOptions, 'container'>>;
|
|
15
18
|
};
|
|
19
|
+
/**
|
|
20
|
+
* The map lifecycle: `map-load` once the Mapbox instance is ready, plus one
|
|
21
|
+
* `map-*` event per entry of `FORWARDED_MAP_EVENTS` carrying the original
|
|
22
|
+
* mapbox event.
|
|
23
|
+
*/
|
|
24
|
+
$emits: {
|
|
25
|
+
'map-load': {
|
|
26
|
+
map: Map;
|
|
27
|
+
};
|
|
28
|
+
} & Record<ForwardedMapEvent, {
|
|
29
|
+
event: unknown;
|
|
30
|
+
}>;
|
|
16
31
|
}
|
|
17
32
|
/**
|
|
18
33
|
* Display a Mapbox GL map.
|
|
@@ -57,9 +72,9 @@ declare class MapboxMap<T extends BaseProps = BaseProps> extends Base<T & Mapbox
|
|
|
57
72
|
*/
|
|
58
73
|
mounted(): Promise<void>;
|
|
59
74
|
/**
|
|
60
|
-
*
|
|
75
|
+
* Unmounted hook.
|
|
61
76
|
*/
|
|
62
|
-
|
|
77
|
+
unmounted(): void;
|
|
63
78
|
}
|
|
64
79
|
//#endregion
|
|
65
80
|
export { MapboxMap, MapboxMap as default, MapboxMapProps };
|
package/dist/MapboxMap.js
CHANGED
|
@@ -39,7 +39,6 @@ var MapboxMap = class extends Base {
|
|
|
39
39
|
*/
|
|
40
40
|
static config = {
|
|
41
41
|
name: "MapboxMap",
|
|
42
|
-
emits: ["map-load", ...FORWARDED_MAP_EVENTS.map((event) => `map-${event}`)],
|
|
43
42
|
refs: ["container"],
|
|
44
43
|
options: {
|
|
45
44
|
accessToken: String,
|
|
@@ -101,13 +100,13 @@ var MapboxMap = class extends Base {
|
|
|
101
100
|
this.__map = map;
|
|
102
101
|
const onLoad = () => {
|
|
103
102
|
this.isLoaded = true;
|
|
104
|
-
this.$emit("map-load", map);
|
|
103
|
+
this.$emit("map-load", { map });
|
|
105
104
|
};
|
|
106
105
|
map.on("load", onLoad);
|
|
107
106
|
this.__offMapListeners.push(() => this.__map?.off("load", onLoad));
|
|
108
107
|
for (const event of FORWARDED_MAP_EVENTS) {
|
|
109
108
|
const handler = (e) => {
|
|
110
|
-
this.$emit(`map-${event}`, e);
|
|
109
|
+
this.$emit(`map-${event}`, { event: e });
|
|
111
110
|
};
|
|
112
111
|
map.on(event, handler);
|
|
113
112
|
this.__offMapListeners.push(() => this.__map?.off(event, handler));
|
|
@@ -115,9 +114,9 @@ var MapboxMap = class extends Base {
|
|
|
115
114
|
document.dispatchEvent(new CustomEvent(MAPBOX_MAP_CONNECTED, { detail: this }));
|
|
116
115
|
}
|
|
117
116
|
/**
|
|
118
|
-
*
|
|
117
|
+
* Unmounted hook.
|
|
119
118
|
*/
|
|
120
|
-
|
|
119
|
+
unmounted() {
|
|
121
120
|
for (const off of this.__offMapListeners) off();
|
|
122
121
|
this.__offMapListeners = [];
|
|
123
122
|
this.__map?.remove();
|
package/dist/MapboxMap.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MapboxMap.js","names":[],"sources":["../src/MapboxMap.ts"],"sourcesContent":["import { Base } from '@studiometa/js-toolkit/Base';\nimport type { BaseConfig, BaseProps } from '@studiometa/js-toolkit';\nimport type { Map, MapOptions } from 'mapbox-gl';\nimport { resolveMapboxGl } from './dependencies.js';\nimport { MAPBOX_MAP_CONNECTED } from './AbstractMapboxMapChild.js';\n\nconst FORWARDED_MAP_EVENTS = [\n 'click',\n 'dblclick',\n 'mouseenter',\n 'mouseleave',\n 'mousemove',\n 'movestart',\n 'move',\n 'moveend',\n 'zoomstart',\n 'zoom',\n 'zoomend',\n 'rotatestart',\n 'rotate',\n 'rotateend',\n 'pitchstart',\n 'pitch',\n 'pitchend',\n 'dragstart',\n 'drag',\n 'dragend',\n 'idle',\n 'render',\n 'resize',\n 'remove',\n 'error',\n] as const;\n\nexport interface MapboxMapProps extends BaseProps {\n $refs: {\n container: HTMLElement;\n };\n $options: {\n accessToken: string;\n zoom: number;\n center: [number, number];\n mapOptions: Partial<Omit<MapOptions, 'container'>>;\n };\n}\n\n/**\n * Display a Mapbox GL map.\n * @see https://ui.studiometa.dev/reference/items/MapboxMap/\n */\nexport class MapboxMap<T extends BaseProps = BaseProps> extends Base<T & MapboxMapProps> {\n /**\n * Config.\n */\n static config: BaseConfig = {\n name: 'MapboxMap',\n
|
|
1
|
+
{"version":3,"file":"MapboxMap.js","names":[],"sources":["../src/MapboxMap.ts"],"sourcesContent":["import { Base } from '@studiometa/js-toolkit/Base';\nimport type { BaseConfig, BaseProps } from '@studiometa/js-toolkit';\nimport type { Map, MapOptions } from 'mapbox-gl';\nimport { resolveMapboxGl } from './dependencies.js';\nimport { MAPBOX_MAP_CONNECTED } from './AbstractMapboxMapChild.js';\n\nconst FORWARDED_MAP_EVENTS = [\n 'click',\n 'dblclick',\n 'mouseenter',\n 'mouseleave',\n 'mousemove',\n 'movestart',\n 'move',\n 'moveend',\n 'zoomstart',\n 'zoom',\n 'zoomend',\n 'rotatestart',\n 'rotate',\n 'rotateend',\n 'pitchstart',\n 'pitch',\n 'pitchend',\n 'dragstart',\n 'drag',\n 'dragend',\n 'idle',\n 'render',\n 'resize',\n 'remove',\n 'error',\n] as const;\n\n/** One forwarded mapbox event name, prefixed the way the component re-emits it. */\ntype ForwardedMapEvent = `map-${(typeof FORWARDED_MAP_EVENTS)[number]}`;\n\nexport interface MapboxMapProps extends BaseProps {\n $refs: {\n container: HTMLElement;\n };\n $options: {\n accessToken: string;\n zoom: number;\n center: [number, number];\n mapOptions: Partial<Omit<MapOptions, 'container'>>;\n };\n /**\n * The map lifecycle: `map-load` once the Mapbox instance is ready, plus one\n * `map-*` event per entry of `FORWARDED_MAP_EVENTS` carrying the original\n * mapbox event.\n */\n $emits: { 'map-load': { map: Map } } & Record<ForwardedMapEvent, { event: unknown }>;\n}\n\n/**\n * Display a Mapbox GL map.\n * @see https://ui.studiometa.dev/reference/items/MapboxMap/\n */\nexport class MapboxMap<T extends BaseProps = BaseProps> extends Base<T & MapboxMapProps> {\n /**\n * Config.\n */\n static config: BaseConfig = {\n name: 'MapboxMap',\n refs: ['container'],\n options: {\n accessToken: String,\n zoom: Number,\n center: {\n type: Array,\n default: () => [0, 0],\n },\n // Any other `mapbox-gl` `Map` option — including `style`, `pitch`,\n // `bearing`, `bounds`, ... — spread as-is into the `Map` constructor. The\n // convenience options above act as overridable defaults, while `container`\n // is always resolved from the component and can not be overridden.\n mapOptions: {\n type: Object,\n default: () => ({}),\n },\n },\n // `MapboxMap` declares no child components. Each child component\n // (markers, popups, controls, sources, layers, clusters, ...) is registered\n // globally and resolves this map on its own via `$closest('MapboxMap')`,\n // then waits for readiness through `AbstractMapboxMapChild.whenMapReady`.\n // This makes the whole family dynamic-DOM-native: a child appended under a\n // map at any time mounts and injects itself, and cleans up when removed.\n };\n\n /**\n * Is the map loaded?\n */\n isLoaded = false;\n\n /**\n * Map instance, or `undefined` until it is built in `mounted()` and once it is\n * cleared on teardown.\n * @private\n */\n __map: Map | undefined;\n\n /**\n * Off handles for every forwarding listener attached to the map, flushed on\n * teardown so a retained reference to a removed `Map` does not keep this\n * component (and its `$emit` closures) alive.\n * @private\n */\n __offMapListeners: Array<() => void> = [];\n\n /**\n * The mapbox Map instance, or `undefined` until it has been built.\n *\n * The map is built in `mounted()` after `mapbox-gl` resolves (it may be\n * injected or lazily imported), so this getter returns `undefined` while that\n * resolution is still pending. Children read it after the map announces itself\n * through `MAPBOX_MAP_CONNECTED`, which only fires once the instance exists.\n */\n get map(): Map | undefined {\n return this.__map;\n }\n\n /**\n * Mounted hook.\n *\n * Resolves `mapbox-gl` (injected or lazily imported), builds the map, then\n * announces it so children can inject themselves.\n */\n async mounted() {\n const mapboxgl = await resolveMapboxGl();\n\n // The component may have been destroyed while `mapbox-gl` was resolving: bail\n // out before building a map that nothing would ever tear down.\n if (!this.$isMounted) {\n return;\n }\n\n const map = new mapboxgl.Map({\n accessToken: this.$options.accessToken,\n zoom: this.$options.zoom,\n center: this.$options.center,\n ...this.$options.mapOptions,\n container: this.$refs.container ?? this.$el,\n });\n this.__map = map;\n\n const onLoad = () => {\n this.isLoaded = true;\n this.$emit('map-load', { map });\n };\n map.on('load', onLoad);\n this.__offMapListeners.push(() => this.__map?.off('load', onLoad));\n\n for (const event of FORWARDED_MAP_EVENTS) {\n const handler = (e: unknown) => {\n this.$emit(`map-${event}`, { event: e });\n };\n map.on(event, handler);\n this.__offMapListeners.push(() => this.__map?.off(event, handler));\n }\n\n // Announce this map so any child that mounted before it — and is waiting on\n // `MAPBOX_MAP_CONNECTED` — can resolve and inject itself now. This also fires\n // on a remount, letting still-mounted children re-inject on the new map.\n document.dispatchEvent(new CustomEvent(MAPBOX_MAP_CONNECTED, { detail: this }));\n }\n\n /**\n * Unmounted hook.\n */\n unmounted() {\n // Flush the forwarding listeners before removing the map so neither the map\n // nor this component leaks through a retained `Map` reference.\n for (const off of this.__offMapListeners) {\n off();\n }\n this.__offMapListeners = [];\n\n this.__map?.remove();\n this.__map = undefined;\n this.isLoaded = false;\n }\n}\n\nexport default MapboxMap;\n"],"mappings":";;;;AAMA,MAAM,uBAAuB;CAC3B;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD;;;;;AA2BD,IAAa,YAAb,cAAgE,KAAyB;;;;CAIvF,OAAO,SAAqB;EAC1B,MAAM;EACN,MAAM,CAAC,YAAY;EACnB,SAAS;GACP,aAAa;GACb,MAAM;GACN,QAAQ;IACN,MAAM;IACN,eAAe,CAAC,GAAG,EAAE;IACtB;GAKD,YAAY;IACV,MAAM;IACN,gBAAgB,EAAE;IACnB;GACF;EAOF;;;;CAKD,WAAW;;;;;;CAOX;;;;;;;CAQA,oBAAuC,EAAE;;;;;;;;;CAUzC,IAAI,MAAuB;AACzB,SAAO,KAAK;;;;;;;;CASd,MAAM,UAAU;EACd,MAAM,WAAW,MAAM,iBAAiB;AAIxC,MAAI,CAAC,KAAK,WACR;EAGF,MAAM,MAAM,IAAI,SAAS,IAAI;GAC3B,aAAa,KAAK,SAAS;GAC3B,MAAM,KAAK,SAAS;GACpB,QAAQ,KAAK,SAAS;GACtB,GAAG,KAAK,SAAS;GACjB,WAAW,KAAK,MAAM,aAAa,KAAK;GACzC,CAAC;AACF,OAAK,QAAQ;EAEb,MAAM,eAAe;AACnB,QAAK,WAAW;AAChB,QAAK,MAAM,YAAY,EAAE,KAAK,CAAC;;AAEjC,MAAI,GAAG,QAAQ,OAAO;AACtB,OAAK,kBAAkB,WAAW,KAAK,OAAO,IAAI,QAAQ,OAAO,CAAC;AAElE,OAAK,MAAM,SAAS,sBAAsB;GACxC,MAAM,WAAW,MAAe;AAC9B,SAAK,MAAM,OAAO,SAAS,EAAE,OAAO,GAAG,CAAC;;AAE1C,OAAI,GAAG,OAAO,QAAQ;AACtB,QAAK,kBAAkB,WAAW,KAAK,OAAO,IAAI,OAAO,QAAQ,CAAC;;AAMpE,WAAS,cAAc,IAAI,YAAY,sBAAsB,EAAE,QAAQ,MAAM,CAAC,CAAC;;;;;CAMjF,YAAY;AAGV,OAAK,MAAM,OAAO,KAAK,kBACrB,MAAK;AAEP,OAAK,oBAAoB,EAAE;AAE3B,OAAK,OAAO,QAAQ;AACpB,OAAK,QAAQ,KAAA;AACb,OAAK,WAAW"}
|
package/dist/MapboxMarker.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MapboxMarker.js","names":[],"sources":["../src/MapboxMarker.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"MapboxMarker.js","names":[],"sources":["../src/MapboxMarker.ts"],"sourcesContent":["import type { BaseProps, 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"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { AbstractMapboxControlProps } from "./AbstractMapboxControl.js";
|
|
2
|
-
import
|
|
1
|
+
import { AbstractMapboxControl, AbstractMapboxControlProps } from "./AbstractMapboxControl.js";
|
|
2
|
+
import { BaseConfig, BaseProps } from "@studiometa/js-toolkit";
|
|
3
3
|
import * as mapbox_gl0 from "mapbox-gl";
|
|
4
4
|
import { NavigationControlOptions } from "mapbox-gl";
|
|
5
5
|
|
|
@@ -11,12 +11,16 @@ interface MapboxNavigationControlProps extends AbstractMapboxControlProps {
|
|
|
11
11
|
visualizePitch: boolean;
|
|
12
12
|
};
|
|
13
13
|
}
|
|
14
|
-
declare const MapboxNavigationControl_base: _studiometa_js_toolkit0.BaseDecorator<_studiometa_js_toolkit0.BaseInterface, _studiometa_js_toolkit0.Base<_studiometa_js_toolkit0.BaseProps>>;
|
|
15
14
|
/**
|
|
16
15
|
* Add a navigation control to the map.
|
|
16
|
+
*
|
|
17
17
|
* @see https://ui.studiometa.dev/reference/items/MapboxMap/
|
|
18
18
|
*/
|
|
19
|
-
declare class MapboxNavigationControl extends
|
|
19
|
+
declare class MapboxNavigationControl<T extends BaseProps = BaseProps> extends AbstractMapboxControl<T & MapboxNavigationControlProps> {
|
|
20
|
+
/**
|
|
21
|
+
* Config.
|
|
22
|
+
*/
|
|
23
|
+
static config: BaseConfig;
|
|
20
24
|
/**
|
|
21
25
|
* Create the mapbox NavigationControl instance.
|
|
22
26
|
* @protected
|