@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
package/MapboxCluster.js
ADDED
|
@@ -0,0 +1,418 @@
|
|
|
1
|
+
import { AbstractMapboxMapChild } from "./AbstractMapboxMapChild.js";
|
|
2
|
+
import { debounce } from "@studiometa/js-toolkit/utils";
|
|
3
|
+
//#region MapboxCluster.ts
|
|
4
|
+
/**
|
|
5
|
+
* Document-level event a `MapboxCluster` dispatches when its instance mounts, so
|
|
6
|
+
* a `MapboxClusterItem` that mounted *before* its cluster can retry resolving it
|
|
7
|
+
* and register itself once the cluster is connected. The dispatching
|
|
8
|
+
* `MapboxCluster` instance travels in `detail`.
|
|
9
|
+
*/
|
|
10
|
+
const MAPBOX_CLUSTER_CONNECTED = "mapbox-cluster:connected";
|
|
11
|
+
/**
|
|
12
|
+
* Module level counter used to generate a unique base id per instance.
|
|
13
|
+
*/
|
|
14
|
+
let clusterCount = 0;
|
|
15
|
+
/**
|
|
16
|
+
* Generate the next unique cluster base id.
|
|
17
|
+
* @returns {string}
|
|
18
|
+
*/
|
|
19
|
+
function nextClusterId() {
|
|
20
|
+
const id = `mb-cluster-${clusterCount}`;
|
|
21
|
+
clusterCount += 1;
|
|
22
|
+
return id;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* A clustered GeoJSON **source driver** whose features ARE its rendered items.
|
|
26
|
+
*
|
|
27
|
+
* `MapboxCluster` merges the map source and the sidebar list of a classic
|
|
28
|
+
* "store locator" into a single declarative unit: `MapboxClusterItem`s (rendered
|
|
29
|
+
* list entries living outside the map) push themselves into the cluster's
|
|
30
|
+
* registry, and the cluster derives its clustered GeoJSON source from that
|
|
31
|
+
* registry. Items self-register, the cluster rebuilds (debounced) on every
|
|
32
|
+
* registry change, gated on `whenMapReady`, and nothing observes or `$query`s.
|
|
33
|
+
*
|
|
34
|
+
* The cluster is deliberately **thin**: it owns only the map data and the
|
|
35
|
+
* clustering interaction (a clustered source, the three layers and the
|
|
36
|
+
* click-to-zoom on clusters). It does **not** select, fly to, filter by viewport
|
|
37
|
+
* or open popups — those search-UX concerns belong to the optional
|
|
38
|
+
* [`StoreLocator`](./StoreLocator.js) orchestrator, which drives them on top of a
|
|
39
|
+
* cluster. Used standalone, a `MapboxCluster` still renders a working clustered
|
|
40
|
+
* map + list (points render, clusters zoom on click); it simply reports a click
|
|
41
|
+
* on an unclustered point through the `map-item-click` event and lets the caller
|
|
42
|
+
* decide what it means.
|
|
43
|
+
*
|
|
44
|
+
* @see https://ui.studiometa.dev/reference/items/MapboxMap/
|
|
45
|
+
*/
|
|
46
|
+
var MapboxCluster = class extends AbstractMapboxMapChild {
|
|
47
|
+
/**
|
|
48
|
+
* Config.
|
|
49
|
+
*/
|
|
50
|
+
static config = {
|
|
51
|
+
name: "MapboxCluster",
|
|
52
|
+
emits: [
|
|
53
|
+
"map-cluster-click",
|
|
54
|
+
"map-item-click",
|
|
55
|
+
"map-update"
|
|
56
|
+
],
|
|
57
|
+
options: {
|
|
58
|
+
clusterMaxZoom: {
|
|
59
|
+
type: Number,
|
|
60
|
+
default: 14
|
|
61
|
+
},
|
|
62
|
+
clusterRadius: {
|
|
63
|
+
type: Number,
|
|
64
|
+
default: 50
|
|
65
|
+
},
|
|
66
|
+
clusterMinPoints: {
|
|
67
|
+
type: Number,
|
|
68
|
+
default: 2
|
|
69
|
+
},
|
|
70
|
+
clusterProperties: {
|
|
71
|
+
type: Object,
|
|
72
|
+
default: () => ({})
|
|
73
|
+
},
|
|
74
|
+
clustersLayout: {
|
|
75
|
+
type: Object,
|
|
76
|
+
default: () => ({})
|
|
77
|
+
},
|
|
78
|
+
clustersPaint: {
|
|
79
|
+
type: Object,
|
|
80
|
+
default: () => ({
|
|
81
|
+
"circle-color": "#000",
|
|
82
|
+
"circle-radius": 40
|
|
83
|
+
})
|
|
84
|
+
},
|
|
85
|
+
clusterCountLayout: {
|
|
86
|
+
type: Object,
|
|
87
|
+
default: () => ({ "text-field": ["get", "point_count_abbreviated"] })
|
|
88
|
+
},
|
|
89
|
+
clusterCountPaint: {
|
|
90
|
+
type: Object,
|
|
91
|
+
default: () => ({ "text-color": "white" })
|
|
92
|
+
},
|
|
93
|
+
unclusteredPointLayerType: {
|
|
94
|
+
type: String,
|
|
95
|
+
default: "circle"
|
|
96
|
+
},
|
|
97
|
+
unclusteredPointLayout: {
|
|
98
|
+
type: Object,
|
|
99
|
+
default: () => ({})
|
|
100
|
+
},
|
|
101
|
+
unclusteredPointPaint: {
|
|
102
|
+
type: Object,
|
|
103
|
+
default: () => ({
|
|
104
|
+
"circle-color": "#000",
|
|
105
|
+
"circle-radius": 4
|
|
106
|
+
})
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
/**
|
|
111
|
+
* Unique base id for this instance.
|
|
112
|
+
* @private
|
|
113
|
+
*/
|
|
114
|
+
__id = nextClusterId();
|
|
115
|
+
/**
|
|
116
|
+
* Live registry of the mounted `MapboxClusterItem`s, in registration order.
|
|
117
|
+
* @private
|
|
118
|
+
*/
|
|
119
|
+
__items = [];
|
|
120
|
+
/**
|
|
121
|
+
* The registered `MapboxClusterItem`s, in registration order.
|
|
122
|
+
*
|
|
123
|
+
* Read-only surface for an orchestrator (e.g. `StoreLocator`) that needs to
|
|
124
|
+
* iterate the item set for viewport filtering, distance sorting or selection —
|
|
125
|
+
* the cluster owns the registry, consumers only read it. A defensive copy is
|
|
126
|
+
* returned so a consumer can not splice the live registry (which would corrupt
|
|
127
|
+
* click resolution and source generation without scheduling a rebuild).
|
|
128
|
+
*/
|
|
129
|
+
get items() {
|
|
130
|
+
return [...this.__items];
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Derive an id for the given suffix from the instance base id.
|
|
134
|
+
* @private
|
|
135
|
+
* @param {string} suffix
|
|
136
|
+
* @returns {string}
|
|
137
|
+
*/
|
|
138
|
+
__getId(suffix) {
|
|
139
|
+
return `${this.__id}-${suffix}`;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* The GeoJSON `FeatureCollection` derived from the whole registered item set.
|
|
143
|
+
*
|
|
144
|
+
* This is the single source of truth pushed to the map source and only changes
|
|
145
|
+
* when the item set changes — panning must never rebuild it.
|
|
146
|
+
*/
|
|
147
|
+
get featureCollection() {
|
|
148
|
+
return {
|
|
149
|
+
type: "FeatureCollection",
|
|
150
|
+
features: this.__items.map((item) => ({
|
|
151
|
+
type: "Feature",
|
|
152
|
+
geometry: {
|
|
153
|
+
type: "Point",
|
|
154
|
+
coordinates: item.lngLat
|
|
155
|
+
},
|
|
156
|
+
properties: {
|
|
157
|
+
...item.properties,
|
|
158
|
+
id: item.id
|
|
159
|
+
}
|
|
160
|
+
}))
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Register an item and schedule a coalesced rebuild so a batch of
|
|
165
|
+
* registrations (e.g. a `Fetch` list swap) results in a single map update.
|
|
166
|
+
* @param {MapboxClusterItem} item
|
|
167
|
+
*/
|
|
168
|
+
register(item) {
|
|
169
|
+
if (!this.__items.includes(item)) {
|
|
170
|
+
this.__items.push(item);
|
|
171
|
+
this.__scheduleRebuild();
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Unregister an item and schedule a coalesced rebuild.
|
|
176
|
+
* @param {MapboxClusterItem} item
|
|
177
|
+
*/
|
|
178
|
+
unregister(item) {
|
|
179
|
+
const index = this.__items.indexOf(item);
|
|
180
|
+
if (index > -1) {
|
|
181
|
+
this.__items.splice(index, 1);
|
|
182
|
+
this.__scheduleRebuild();
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Replace the live source data directly, bypassing the item registry.
|
|
187
|
+
*
|
|
188
|
+
* Kept for manual/imperative control; the common path is to let registered
|
|
189
|
+
* items drive the data. Safe to call before mount or after teardown.
|
|
190
|
+
*
|
|
191
|
+
* NOTE: this bypasses the registry-is-source invariant, so anything pushed
|
|
192
|
+
* here is transient — the next registry rebuild (any item mount/unmount, or a
|
|
193
|
+
* debounced `__scheduleRebuild`) derives the source from `featureCollection`
|
|
194
|
+
* again and silently overwrites it. Use it only for one-off imperative
|
|
195
|
+
* overlays that do not need to survive an item-set change.
|
|
196
|
+
*
|
|
197
|
+
* @param {GeoJSONSourceSpecification['data']} data
|
|
198
|
+
*/
|
|
199
|
+
setData(data) {
|
|
200
|
+
const source = this.__readyMap?.getSource(this.__getId("source"));
|
|
201
|
+
if (source && typeof source.setData === "function") source.setData(data);
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Coalesce rebuilds into a single trailing call, so a batch of registrations
|
|
205
|
+
* spanning multiple ticks results in one map data update.
|
|
206
|
+
* @private
|
|
207
|
+
*/
|
|
208
|
+
__scheduleRebuild = debounce(() => {
|
|
209
|
+
if (this.$isMounted) this.__rebuild();
|
|
210
|
+
}, 100);
|
|
211
|
+
/**
|
|
212
|
+
* Push the derived feature collection to the source and announce the change.
|
|
213
|
+
* No-op until the map is ready (the initial build happens in `whenMapReady`).
|
|
214
|
+
* @private
|
|
215
|
+
*/
|
|
216
|
+
__rebuild() {
|
|
217
|
+
if (!this.__readyMap) return;
|
|
218
|
+
this.setData(this.featureCollection);
|
|
219
|
+
this.$emit("map-update", this.items);
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* Click handler for the clusters layer, zooming on the clicked cluster.
|
|
223
|
+
* @private
|
|
224
|
+
*/
|
|
225
|
+
__handleClustersClick = (event) => {
|
|
226
|
+
const map = this.__readyMap;
|
|
227
|
+
if (!map) return;
|
|
228
|
+
const feature = map.queryRenderedFeatures(event.point, { layers: [this.__getId("clusters")] })[0];
|
|
229
|
+
if (!feature) return;
|
|
230
|
+
const clusterId = feature.properties?.cluster_id;
|
|
231
|
+
this.$emit("map-cluster-click", clusterId, event);
|
|
232
|
+
if (event.defaultPrevented) return;
|
|
233
|
+
map.getSource(this.__getId("source"))?.getClusterExpansionZoom(clusterId, (error, zoom) => {
|
|
234
|
+
if (this.__readyMap !== map || error || zoom === null || zoom === void 0 || feature.geometry.type !== "Point") return;
|
|
235
|
+
map.easeTo({
|
|
236
|
+
center: feature.geometry.coordinates,
|
|
237
|
+
zoom
|
|
238
|
+
});
|
|
239
|
+
});
|
|
240
|
+
};
|
|
241
|
+
/**
|
|
242
|
+
* Set the map canvas cursor, guarding against a missing map.
|
|
243
|
+
* @private
|
|
244
|
+
* @param {string} cursor
|
|
245
|
+
*/
|
|
246
|
+
__setCursor(cursor) {
|
|
247
|
+
const canvas = this.__readyMap?.getCanvas();
|
|
248
|
+
if (canvas) canvas.style.cursor = cursor;
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* Set a pointer cursor when entering the clusters layer.
|
|
252
|
+
* @private
|
|
253
|
+
*/
|
|
254
|
+
__handleClustersMouseenter = () => {
|
|
255
|
+
this.__setCursor("pointer");
|
|
256
|
+
};
|
|
257
|
+
/**
|
|
258
|
+
* Reset the cursor when leaving the clusters layer.
|
|
259
|
+
* @private
|
|
260
|
+
*/
|
|
261
|
+
__handleClustersMouseleave = () => {
|
|
262
|
+
this.__setCursor("");
|
|
263
|
+
};
|
|
264
|
+
/**
|
|
265
|
+
* Report a click on an unclustered point: resolve the feature back to the
|
|
266
|
+
* registered item behind it and emit `map-item-click`. The cluster makes no
|
|
267
|
+
* decision about what a click means — an orchestrator (e.g. `StoreLocator`)
|
|
268
|
+
* listens and selects, opens a popup, etc.
|
|
269
|
+
* @private
|
|
270
|
+
*/
|
|
271
|
+
__handleUnclusteredClick = (event) => {
|
|
272
|
+
const feature = event.features?.[0];
|
|
273
|
+
const id = feature?.properties?.id;
|
|
274
|
+
const item = id === void 0 || id === null ? void 0 : this.__items.find((candidate) => candidate.id === String(id));
|
|
275
|
+
this.$emit("map-item-click", item, feature, event);
|
|
276
|
+
};
|
|
277
|
+
/**
|
|
278
|
+
* Set a pointer cursor when entering an unclustered point.
|
|
279
|
+
* @private
|
|
280
|
+
*/
|
|
281
|
+
__handleUnclusteredMouseenter = () => {
|
|
282
|
+
this.__setCursor("pointer");
|
|
283
|
+
};
|
|
284
|
+
/**
|
|
285
|
+
* Reset the cursor when leaving an unclustered point.
|
|
286
|
+
* @private
|
|
287
|
+
*/
|
|
288
|
+
__handleUnclusteredMouseleave = () => {
|
|
289
|
+
this.__setCursor("");
|
|
290
|
+
};
|
|
291
|
+
/**
|
|
292
|
+
* Mounted hook: build the source and layers, wire the clustering interaction
|
|
293
|
+
* and announce the initial item set — all once the map is ready.
|
|
294
|
+
*/
|
|
295
|
+
mounted() {
|
|
296
|
+
document.dispatchEvent(new CustomEvent(MAPBOX_CLUSTER_CONNECTED, { detail: this }));
|
|
297
|
+
this.whenMapReady((map) => this.__inject(map));
|
|
298
|
+
}
|
|
299
|
+
/**
|
|
300
|
+
* Build the clustered source and its three layers and wire the clustering
|
|
301
|
+
* interaction — idempotently, so it can run both on first readiness and on a
|
|
302
|
+
* `style.load` re-injection after a `setStyle` wiped the style (H7, PR #567
|
|
303
|
+
* review).
|
|
304
|
+
*
|
|
305
|
+
* A `setStyle` clears sources and layers but leaves layer-scoped map listeners
|
|
306
|
+
* attached (they live on the map's event emitter, not the style), so this
|
|
307
|
+
* guards `addSource`/`addLayer` against an already-present resource and
|
|
308
|
+
* detaches every listener before re-attaching it — re-running never duplicates
|
|
309
|
+
* a listener nor throws a duplicate-id error.
|
|
310
|
+
* @private
|
|
311
|
+
* @param {Map} map
|
|
312
|
+
*/
|
|
313
|
+
__inject(map) {
|
|
314
|
+
const { clusterMaxZoom, clusterRadius, clusterMinPoints, clusterProperties, clustersLayout, clustersPaint, clusterCountLayout, clusterCountPaint, unclusteredPointLayerType, unclusteredPointLayout, unclusteredPointPaint } = this.$options;
|
|
315
|
+
const sourceId = this.__getId("source");
|
|
316
|
+
const clustersId = this.__getId("clusters");
|
|
317
|
+
const clusterCountId = this.__getId("cluster-count");
|
|
318
|
+
const unclusteredPointId = this.__getId("unclustered-point");
|
|
319
|
+
const clustersFilter = ["has", "point_count"];
|
|
320
|
+
const unclusteredFilter = ["!", ["has", "point_count"]];
|
|
321
|
+
const source = {
|
|
322
|
+
type: "geojson",
|
|
323
|
+
cluster: true,
|
|
324
|
+
data: this.featureCollection,
|
|
325
|
+
clusterMaxZoom,
|
|
326
|
+
clusterRadius,
|
|
327
|
+
clusterMinPoints,
|
|
328
|
+
clusterProperties
|
|
329
|
+
};
|
|
330
|
+
const clustersLayer = {
|
|
331
|
+
id: clustersId,
|
|
332
|
+
type: "circle",
|
|
333
|
+
source: sourceId,
|
|
334
|
+
filter: clustersFilter,
|
|
335
|
+
layout: clustersLayout,
|
|
336
|
+
paint: clustersPaint
|
|
337
|
+
};
|
|
338
|
+
const clusterCountLayer = {
|
|
339
|
+
id: clusterCountId,
|
|
340
|
+
type: "symbol",
|
|
341
|
+
source: sourceId,
|
|
342
|
+
filter: clustersFilter,
|
|
343
|
+
layout: clusterCountLayout,
|
|
344
|
+
paint: clusterCountPaint
|
|
345
|
+
};
|
|
346
|
+
const unclusteredPointLayer = {
|
|
347
|
+
id: unclusteredPointId,
|
|
348
|
+
type: unclusteredPointLayerType,
|
|
349
|
+
source: sourceId,
|
|
350
|
+
filter: unclusteredFilter,
|
|
351
|
+
layout: unclusteredPointLayout,
|
|
352
|
+
paint: unclusteredPointPaint
|
|
353
|
+
};
|
|
354
|
+
if (!map.getSource(sourceId)) map.addSource(sourceId, source);
|
|
355
|
+
for (const layer of [
|
|
356
|
+
clustersLayer,
|
|
357
|
+
clusterCountLayer,
|
|
358
|
+
unclusteredPointLayer
|
|
359
|
+
]) if (!map.getLayer(layer.id)) map.addLayer(layer);
|
|
360
|
+
this.__offClusterListeners(map);
|
|
361
|
+
map.on("click", clustersId, this.__handleClustersClick);
|
|
362
|
+
map.on("mouseenter", clustersId, this.__handleClustersMouseenter);
|
|
363
|
+
map.on("mouseleave", clustersId, this.__handleClustersMouseleave);
|
|
364
|
+
map.on("click", unclusteredPointId, this.__handleUnclusteredClick);
|
|
365
|
+
map.on("mouseenter", unclusteredPointId, this.__handleUnclusteredMouseenter);
|
|
366
|
+
map.on("mouseleave", unclusteredPointId, this.__handleUnclusteredMouseleave);
|
|
367
|
+
this.$emit("map-update", this.items);
|
|
368
|
+
}
|
|
369
|
+
/**
|
|
370
|
+
* Detach every map-scoped listener wired in `mounted`.
|
|
371
|
+
* @private
|
|
372
|
+
* @param {Map} map
|
|
373
|
+
*/
|
|
374
|
+
__offClusterListeners(map) {
|
|
375
|
+
const clustersId = this.__getId("clusters");
|
|
376
|
+
const unclusteredPointId = this.__getId("unclustered-point");
|
|
377
|
+
map.off("click", clustersId, this.__handleClustersClick);
|
|
378
|
+
map.off("mouseenter", clustersId, this.__handleClustersMouseenter);
|
|
379
|
+
map.off("mouseleave", clustersId, this.__handleClustersMouseleave);
|
|
380
|
+
map.off("click", unclusteredPointId, this.__handleUnclusteredClick);
|
|
381
|
+
map.off("mouseenter", unclusteredPointId, this.__handleUnclusteredMouseenter);
|
|
382
|
+
map.off("mouseleave", unclusteredPointId, this.__handleUnclusteredMouseleave);
|
|
383
|
+
}
|
|
384
|
+
/**
|
|
385
|
+
* Flush the per-layer listeners against the map being removed, while it is
|
|
386
|
+
* still referenceable — `__onDestroyed` runs later with `__readyMap` already
|
|
387
|
+
* cleared and could not reach the map to unsubscribe.
|
|
388
|
+
* @protected
|
|
389
|
+
* @param {Map} map
|
|
390
|
+
*/
|
|
391
|
+
__onMapRemove(map) {
|
|
392
|
+
this.__offClusterListeners(map);
|
|
393
|
+
}
|
|
394
|
+
/**
|
|
395
|
+
* Teardown hook: tear down listeners, layers and source.
|
|
396
|
+
*/
|
|
397
|
+
__onDestroyed() {
|
|
398
|
+
const map = this.__readyMap;
|
|
399
|
+
if (map) {
|
|
400
|
+
const clustersId = this.__getId("clusters");
|
|
401
|
+
const clusterCountId = this.__getId("cluster-count");
|
|
402
|
+
const unclusteredPointId = this.__getId("unclustered-point");
|
|
403
|
+
const sourceId = this.__getId("source");
|
|
404
|
+
this.__offClusterListeners(map);
|
|
405
|
+
for (const id of [
|
|
406
|
+
clustersId,
|
|
407
|
+
clusterCountId,
|
|
408
|
+
unclusteredPointId
|
|
409
|
+
]) if (map.getLayer(id)) map.removeLayer(id);
|
|
410
|
+
if (map.getSource(sourceId)) map.removeSource(sourceId);
|
|
411
|
+
}
|
|
412
|
+
this.__items = [];
|
|
413
|
+
}
|
|
414
|
+
};
|
|
415
|
+
//#endregion
|
|
416
|
+
export { MAPBOX_CLUSTER_CONNECTED, MapboxCluster, MapboxCluster as default };
|
|
417
|
+
|
|
418
|
+
//# sourceMappingURL=MapboxCluster.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MapboxCluster.js","names":[],"sources":["../MapboxCluster.ts"],"sourcesContent":["import { type BaseProps, type BaseConfig } from '@studiometa/js-toolkit';\nimport { debounce } from '@studiometa/js-toolkit/utils';\nimport type {\n Map,\n CircleLayerSpecification,\n SymbolLayerSpecification,\n LayerSpecification,\n FilterSpecification,\n GeoJSONSourceSpecification,\n GeoJSONSource,\n MapMouseEvent,\n LngLatLike,\n} from 'mapbox-gl';\nimport type { FeatureCollection, Point } from 'geojson';\nimport {\n AbstractMapboxMapChild,\n type AbstractMapboxMapChildProps,\n} from './AbstractMapboxMapChild.js';\nimport type { MapboxClusterItem } from './MapboxClusterItem.js';\n\n/**\n * Document-level event a `MapboxCluster` dispatches when its instance mounts, so\n * a `MapboxClusterItem` that mounted *before* its cluster can retry resolving it\n * and register itself once the cluster is connected. The dispatching\n * `MapboxCluster` instance travels in `detail`.\n */\nexport const MAPBOX_CLUSTER_CONNECTED = 'mapbox-cluster:connected';\n\n/**\n * Module level counter used to generate a unique base id per instance.\n */\nlet clusterCount = 0;\n\n/**\n * Generate the next unique cluster base id.\n * @returns {string}\n */\nfunction nextClusterId(): string {\n const id = `mb-cluster-${clusterCount}`;\n clusterCount += 1;\n return id;\n}\n\nexport interface MapboxClusterProps extends AbstractMapboxMapChildProps {\n $options: {\n clusterMaxZoom: number;\n clusterRadius: number;\n clusterMinPoints: number;\n clusterProperties: Record<string, unknown>;\n clustersLayout: CircleLayerSpecification['layout'];\n clustersPaint: CircleLayerSpecification['paint'];\n clusterCountLayout: SymbolLayerSpecification['layout'];\n clusterCountPaint: SymbolLayerSpecification['paint'];\n unclusteredPointLayerType: string;\n unclusteredPointLayout: Record<string, unknown>;\n unclusteredPointPaint: Record<string, unknown>;\n };\n}\n\n/**\n * A clustered GeoJSON **source driver** whose features ARE its rendered items.\n *\n * `MapboxCluster` merges the map source and the sidebar list of a classic\n * \"store locator\" into a single declarative unit: `MapboxClusterItem`s (rendered\n * list entries living outside the map) push themselves into the cluster's\n * registry, and the cluster derives its clustered GeoJSON source from that\n * registry. Items self-register, the cluster rebuilds (debounced) on every\n * registry change, gated on `whenMapReady`, and nothing observes or `$query`s.\n *\n * The cluster is deliberately **thin**: it owns only the map data and the\n * clustering interaction (a clustered source, the three layers and the\n * click-to-zoom on clusters). It does **not** select, fly to, filter by viewport\n * or open popups — those search-UX concerns belong to the optional\n * [`StoreLocator`](./StoreLocator.js) orchestrator, which drives them on top of a\n * cluster. Used standalone, a `MapboxCluster` still renders a working clustered\n * map + list (points render, clusters zoom on click); it simply reports a click\n * on an unclustered point through the `map-item-click` event and lets the caller\n * decide what it means.\n *\n * @see https://ui.studiometa.dev/reference/items/MapboxMap/\n */\nexport class MapboxCluster<T extends BaseProps = BaseProps> extends AbstractMapboxMapChild<\n T & MapboxClusterProps\n> {\n /**\n * Config.\n */\n static config: BaseConfig = {\n name: 'MapboxCluster',\n emits: ['map-cluster-click', 'map-item-click', 'map-update'],\n options: {\n clusterMaxZoom: {\n type: Number,\n default: 14,\n },\n clusterRadius: {\n type: Number,\n default: 50,\n },\n clusterMinPoints: {\n type: Number,\n default: 2,\n },\n clusterProperties: {\n type: Object,\n default: () => ({}),\n },\n clustersLayout: {\n type: Object,\n default: () => ({}),\n },\n clustersPaint: {\n type: Object,\n default: () => ({\n 'circle-color': '#000',\n 'circle-radius': 40,\n }),\n },\n clusterCountLayout: {\n type: Object,\n default: () => ({\n 'text-field': ['get', 'point_count_abbreviated'],\n }),\n },\n clusterCountPaint: {\n type: Object,\n default: () => ({\n 'text-color': 'white',\n }),\n },\n unclusteredPointLayerType: {\n type: String,\n default: 'circle',\n },\n unclusteredPointLayout: {\n type: Object,\n default: () => ({}),\n },\n unclusteredPointPaint: {\n type: Object,\n default: () => ({\n 'circle-color': '#000',\n 'circle-radius': 4,\n }),\n },\n },\n };\n\n /**\n * Unique base id for this instance.\n * @private\n */\n __id = nextClusterId();\n\n /**\n * Live registry of the mounted `MapboxClusterItem`s, in registration order.\n * @private\n */\n __items: MapboxClusterItem[] = [];\n\n /**\n * The registered `MapboxClusterItem`s, in registration order.\n *\n * Read-only surface for an orchestrator (e.g. `StoreLocator`) that needs to\n * iterate the item set for viewport filtering, distance sorting or selection —\n * the cluster owns the registry, consumers only read it. A defensive copy is\n * returned so a consumer can not splice the live registry (which would corrupt\n * click resolution and source generation without scheduling a rebuild).\n */\n get items(): readonly MapboxClusterItem[] {\n return [...this.__items];\n }\n\n /**\n * Derive an id for the given suffix from the instance base id.\n * @private\n * @param {string} suffix\n * @returns {string}\n */\n __getId(suffix: string): string {\n return `${this.__id}-${suffix}`;\n }\n\n /**\n * The GeoJSON `FeatureCollection` derived from the whole registered item set.\n *\n * This is the single source of truth pushed to the map source and only changes\n * when the item set changes — panning must never rebuild it.\n */\n get featureCollection(): FeatureCollection<Point, Record<string, unknown>> {\n return {\n type: 'FeatureCollection',\n features: this.__items.map((item) => ({\n type: 'Feature',\n geometry: {\n type: 'Point',\n coordinates: item.lngLat,\n },\n properties: {\n ...item.properties,\n id: item.id,\n },\n })),\n };\n }\n\n /**\n * Register an item and schedule a coalesced rebuild so a batch of\n * registrations (e.g. a `Fetch` list swap) results in a single map update.\n * @param {MapboxClusterItem} item\n */\n register(item: MapboxClusterItem) {\n if (!this.__items.includes(item)) {\n this.__items.push(item);\n this.__scheduleRebuild();\n }\n }\n\n /**\n * Unregister an item and schedule a coalesced rebuild.\n * @param {MapboxClusterItem} item\n */\n unregister(item: MapboxClusterItem) {\n const index = this.__items.indexOf(item);\n\n if (index > -1) {\n this.__items.splice(index, 1);\n this.__scheduleRebuild();\n }\n }\n\n /**\n * Replace the live source data directly, bypassing the item registry.\n *\n * Kept for manual/imperative control; the common path is to let registered\n * items drive the data. Safe to call before mount or after teardown.\n *\n * NOTE: this bypasses the registry-is-source invariant, so anything pushed\n * here is transient — the next registry rebuild (any item mount/unmount, or a\n * debounced `__scheduleRebuild`) derives the source from `featureCollection`\n * again and silently overwrites it. Use it only for one-off imperative\n * overlays that do not need to survive an item-set change.\n *\n * @param {GeoJSONSourceSpecification['data']} data\n */\n setData(data: GeoJSONSourceSpecification['data']) {\n const source = this.__readyMap?.getSource<GeoJSONSource>(this.__getId('source'));\n\n if (source && typeof source.setData === 'function') {\n source.setData(data);\n }\n }\n\n /**\n * Coalesce rebuilds into a single trailing call, so a batch of registrations\n * spanning multiple ticks results in one map data update.\n * @private\n */\n __scheduleRebuild = debounce(() => {\n if (this.$isMounted) {\n this.__rebuild();\n }\n }, 100);\n\n /**\n * Push the derived feature collection to the source and announce the change.\n * No-op until the map is ready (the initial build happens in `whenMapReady`).\n * @private\n */\n __rebuild() {\n const map = this.__readyMap;\n\n if (!map) {\n return;\n }\n\n this.setData(this.featureCollection as GeoJSONSourceSpecification['data']);\n // Let an orchestrator react to the new item set (fit the map, refilter the\n // list). The cluster itself never fits or filters — it only reports.\n this.$emit('map-update', this.items);\n }\n\n /**\n * Click handler for the clusters layer, zooming on the clicked cluster.\n * @private\n */\n __handleClustersClick = (event: MapMouseEvent) => {\n const map = this.__readyMap;\n\n if (!map) {\n return;\n }\n\n const feature = map.queryRenderedFeatures(event.point, {\n layers: [this.__getId('clusters')],\n })[0];\n\n if (!feature) {\n return;\n }\n\n const clusterId = feature.properties?.cluster_id as number;\n\n this.$emit('map-cluster-click', clusterId, event);\n\n if (event.defaultPrevented) {\n return;\n }\n\n const source = map.getSource<GeoJSONSource>(this.__getId('source'));\n\n source?.getClusterExpansionZoom(clusterId, (error, zoom) => {\n // The expansion zoom resolves asynchronously: the map may have been\n // removed (or replaced) in the meantime, in which case the base cleared\n // `__readyMap`. Bail unless the captured map is still the current one so\n // `easeTo` never runs against a dead map.\n if (\n this.__readyMap !== map ||\n error ||\n zoom === null ||\n zoom === undefined ||\n feature.geometry.type !== 'Point'\n ) {\n return;\n }\n\n map.easeTo({\n center: feature.geometry.coordinates as LngLatLike,\n zoom,\n });\n });\n };\n\n /**\n * Set the map canvas cursor, guarding against a missing map.\n * @private\n * @param {string} cursor\n */\n __setCursor(cursor: string) {\n const canvas = this.__readyMap?.getCanvas();\n\n if (canvas) {\n canvas.style.cursor = cursor;\n }\n }\n\n /**\n * Set a pointer cursor when entering the clusters layer.\n * @private\n */\n __handleClustersMouseenter = () => {\n this.__setCursor('pointer');\n };\n\n /**\n * Reset the cursor when leaving the clusters layer.\n * @private\n */\n __handleClustersMouseleave = () => {\n this.__setCursor('');\n };\n\n /**\n * Report a click on an unclustered point: resolve the feature back to the\n * registered item behind it and emit `map-item-click`. The cluster makes no\n * decision about what a click means — an orchestrator (e.g. `StoreLocator`)\n * listens and selects, opens a popup, etc.\n * @private\n */\n __handleUnclusteredClick = (event: MapMouseEvent) => {\n const feature = event.features?.[0];\n const id = feature?.properties?.id;\n const item =\n id === undefined || id === null\n ? undefined\n : this.__items.find((candidate) => candidate.id === String(id));\n\n this.$emit('map-item-click', item, feature, event);\n };\n\n /**\n * Set a pointer cursor when entering an unclustered point.\n * @private\n */\n __handleUnclusteredMouseenter = () => {\n this.__setCursor('pointer');\n };\n\n /**\n * Reset the cursor when leaving an unclustered point.\n * @private\n */\n __handleUnclusteredMouseleave = () => {\n this.__setCursor('');\n };\n\n /**\n * Mounted hook: build the source and layers, wire the clustering interaction\n * and announce the initial item set — all once the map is ready.\n */\n mounted() {\n // Announce the cluster so any `MapboxClusterItem` that mounted before it —\n // and is waiting on `MAPBOX_CLUSTER_CONNECTED` — can register now. Items\n // register independently of map readiness, so this fires outside the\n // `whenMapReady` gate.\n document.dispatchEvent(new CustomEvent(MAPBOX_CLUSTER_CONNECTED, { detail: this }));\n\n this.whenMapReady((map) => this.__inject(map));\n }\n\n /**\n * Build the clustered source and its three layers and wire the clustering\n * interaction — idempotently, so it can run both on first readiness and on a\n * `style.load` re-injection after a `setStyle` wiped the style (H7, PR #567\n * review).\n *\n * A `setStyle` clears sources and layers but leaves layer-scoped map listeners\n * attached (they live on the map's event emitter, not the style), so this\n * guards `addSource`/`addLayer` against an already-present resource and\n * detaches every listener before re-attaching it — re-running never duplicates\n * a listener nor throws a duplicate-id error.\n * @private\n * @param {Map} map\n */\n __inject(map: Map) {\n const {\n clusterMaxZoom,\n clusterRadius,\n clusterMinPoints,\n clusterProperties,\n clustersLayout,\n clustersPaint,\n clusterCountLayout,\n clusterCountPaint,\n unclusteredPointLayerType,\n unclusteredPointLayout,\n unclusteredPointPaint,\n } = this.$options;\n\n const sourceId = this.__getId('source');\n const clustersId = this.__getId('clusters');\n const clusterCountId = this.__getId('cluster-count');\n const unclusteredPointId = this.__getId('unclustered-point');\n const clustersFilter = ['has', 'point_count'] as FilterSpecification;\n const unclusteredFilter = ['!', ['has', 'point_count']] as FilterSpecification;\n\n const source: GeoJSONSourceSpecification = {\n type: 'geojson',\n cluster: true,\n // Seed the source with the currently-registered items. Items registered\n // before the map was ready are already in `__items`, so the first render\n // is correct without waiting for a debounced rebuild.\n data: this.featureCollection,\n clusterMaxZoom,\n clusterRadius,\n clusterMinPoints,\n clusterProperties,\n };\n\n const clustersLayer: CircleLayerSpecification = {\n id: clustersId,\n type: 'circle',\n source: sourceId,\n filter: clustersFilter,\n layout: clustersLayout,\n paint: clustersPaint,\n };\n\n const clusterCountLayer: SymbolLayerSpecification = {\n id: clusterCountId,\n type: 'symbol',\n source: sourceId,\n filter: clustersFilter,\n layout: clusterCountLayout,\n paint: clusterCountPaint,\n };\n\n const unclusteredPointLayer = {\n id: unclusteredPointId,\n type: unclusteredPointLayerType,\n source: sourceId,\n filter: unclusteredFilter,\n layout: unclusteredPointLayout,\n paint: unclusteredPointPaint,\n } as unknown as LayerSpecification;\n\n if (!map.getSource(sourceId)) {\n map.addSource(sourceId, source);\n }\n for (const layer of [clustersLayer, clusterCountLayer, unclusteredPointLayer]) {\n if (!map.getLayer(layer.id)) {\n map.addLayer(layer);\n }\n }\n\n // Detach before attaching so a re-injection never doubles a listener.\n this.__offClusterListeners(map);\n map.on('click', clustersId, this.__handleClustersClick);\n map.on('mouseenter', clustersId, this.__handleClustersMouseenter);\n map.on('mouseleave', clustersId, this.__handleClustersMouseleave);\n map.on('click', unclusteredPointId, this.__handleUnclusteredClick);\n map.on('mouseenter', unclusteredPointId, this.__handleUnclusteredMouseenter);\n map.on('mouseleave', unclusteredPointId, this.__handleUnclusteredMouseleave);\n\n // Announce the seeded item set so an orchestrator can run its first fit +\n // viewport filter against a cluster that was already populated at load.\n this.$emit('map-update', this.items);\n }\n\n /**\n * Detach every map-scoped listener wired in `mounted`.\n * @private\n * @param {Map} map\n */\n __offClusterListeners(map: Map) {\n const clustersId = this.__getId('clusters');\n const unclusteredPointId = this.__getId('unclustered-point');\n\n map.off('click', clustersId, this.__handleClustersClick);\n map.off('mouseenter', clustersId, this.__handleClustersMouseenter);\n map.off('mouseleave', clustersId, this.__handleClustersMouseleave);\n map.off('click', unclusteredPointId, this.__handleUnclusteredClick);\n map.off('mouseenter', unclusteredPointId, this.__handleUnclusteredMouseenter);\n map.off('mouseleave', unclusteredPointId, this.__handleUnclusteredMouseleave);\n }\n\n /**\n * Flush the per-layer listeners against the map being removed, while it is\n * still referenceable — `__onDestroyed` runs later with `__readyMap` already\n * cleared and could not reach the map to unsubscribe.\n * @protected\n * @param {Map} map\n */\n __onMapRemove(map: Map) {\n this.__offClusterListeners(map);\n }\n\n /**\n * Teardown hook: tear down listeners, layers and source.\n */\n __onDestroyed() {\n const map = this.__readyMap;\n\n if (map) {\n const clustersId = this.__getId('clusters');\n const clusterCountId = this.__getId('cluster-count');\n const unclusteredPointId = this.__getId('unclustered-point');\n const sourceId = this.__getId('source');\n\n this.__offClusterListeners(map);\n\n for (const id of [clustersId, clusterCountId, unclusteredPointId]) {\n if (map.getLayer(id)) {\n map.removeLayer(id);\n }\n }\n\n if (map.getSource(sourceId)) {\n map.removeSource(sourceId);\n }\n }\n\n this.__items = [];\n }\n}\n\nexport default MapboxCluster;\n"],"mappings":";;;;;;;;;AA0BA,MAAa,2BAA2B;;;;AAKxC,IAAI,eAAe;;;;;AAMnB,SAAS,gBAAwB;CAC/B,MAAM,KAAK,cAAc;AACzB,iBAAgB;AAChB,QAAO;;;;;;;;;;;;;;;;;;;;;;;;AAyCT,IAAa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,QAAK,sBAAsB,IAAI;AAE/B,QAAK,MAAM,MAAM;IAAC;IAAY;IAAgB;IAAmB,CAC/D,KAAI,IAAI,SAAS,GAAG,CAClB,KAAI,YAAY,GAAG;AAIvB,OAAI,IAAI,UAAU,SAAS,CACzB,KAAI,aAAa,SAAS;;AAI9B,OAAK,UAAU,EAAE"}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { MapboxCluster } from "./MapboxCluster.js";
|
|
2
|
+
import { Base, BaseConfig, BaseProps } from "@studiometa/js-toolkit";
|
|
3
|
+
|
|
4
|
+
//#region MapboxClusterItem.d.ts
|
|
5
|
+
interface MapboxClusterItemProps extends BaseProps {
|
|
6
|
+
$options: {
|
|
7
|
+
id: string;
|
|
8
|
+
lngLat: [number, number];
|
|
9
|
+
properties: Record<string, unknown>;
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* A single entry of a `MapboxCluster`.
|
|
14
|
+
*
|
|
15
|
+
* Unlike the other `@studiometa/ui-mapbox` components, this one is a **rendered**
|
|
16
|
+
* element (e.g. a list `<li>` in a sidebar) and does not extend
|
|
17
|
+
* `AbstractMapboxMapChild`: its DOM lives outside the `MapboxMap` element, so its
|
|
18
|
+
* context is the parent `MapboxCluster` — resolved via `$closest('MapboxCluster')`
|
|
19
|
+
* — rather than a map.
|
|
20
|
+
*
|
|
21
|
+
* It is at once the list item AND the map feature: the cluster derives its
|
|
22
|
+
* GeoJSON source from the set of registered items, so the same markup drives
|
|
23
|
+
* both the sidebar and the clustered points on the map. The child PUSHES itself
|
|
24
|
+
* to the cluster on mount (`register`) and PULLS itself out on destroy
|
|
25
|
+
* (`unregister`), so the cluster never has to query for its children.
|
|
26
|
+
*
|
|
27
|
+
* The component is headless and passive: it never selects itself. The state
|
|
28
|
+
* setters below reflect state as data-attributes on `$el` so the integrator can
|
|
29
|
+
* style the item with plain CSS, and they are driven by whoever coordinates the
|
|
30
|
+
* experience — a [`StoreLocator`](./StoreLocator.js) orchestrator on `moveend`
|
|
31
|
+
* and on selection, if one wraps the cluster:
|
|
32
|
+
*
|
|
33
|
+
* - `data-in-bounds` — present when the item's `lngLat` is inside the current
|
|
34
|
+
* map viewport (list-visibility signal).
|
|
35
|
+
* - `data-active` + `aria-current="true"` — present when the item is selected.
|
|
36
|
+
*
|
|
37
|
+
* Used under a bare `MapboxCluster` (no orchestrator) the item still registers
|
|
38
|
+
* and renders as a clustered point; it just carries no selection affordance of
|
|
39
|
+
* its own — a click is reported by the cluster's `map-item-click` event for a
|
|
40
|
+
* caller to act on.
|
|
41
|
+
*
|
|
42
|
+
* @see https://ui.studiometa.dev/reference/items/MapboxMap/
|
|
43
|
+
*/
|
|
44
|
+
declare class MapboxClusterItem<T extends BaseProps = BaseProps> extends Base<T & MapboxClusterItemProps> {
|
|
45
|
+
/**
|
|
46
|
+
* Config.
|
|
47
|
+
*/
|
|
48
|
+
static config: BaseConfig;
|
|
49
|
+
/**
|
|
50
|
+
* The parent `MapboxCluster` resolved at mount, cached so the item can still
|
|
51
|
+
* reach it on destroy.
|
|
52
|
+
*
|
|
53
|
+
* `destroyed()` runs *after* the element has been detached from the DOM (e.g.
|
|
54
|
+
* a `Fetch` list swap), and a `$closest` lookup on a disconnected node returns
|
|
55
|
+
* nothing — which would leave the removed item registered and its feature
|
|
56
|
+
* stuck on the map. Caching the reference keeps the unregister path working.
|
|
57
|
+
* @private
|
|
58
|
+
*/
|
|
59
|
+
__cluster?: MapboxCluster;
|
|
60
|
+
/**
|
|
61
|
+
* Off handler for the document-level `MAPBOX_CLUSTER_CONNECTED` retry
|
|
62
|
+
* subscription, used when the item mounts before its cluster.
|
|
63
|
+
* @private
|
|
64
|
+
*/
|
|
65
|
+
__offClusterConnected?: () => void;
|
|
66
|
+
/**
|
|
67
|
+
* The item's stable identifier, used to match map features back to the item.
|
|
68
|
+
*
|
|
69
|
+
* Expected to be non-empty and unique within a cluster. Duplicate ids are not
|
|
70
|
+
* rejected, but their behavior is defined rather than undefined: a click on
|
|
71
|
+
* any duplicate resolves to the FIRST registered item carrying that id (see
|
|
72
|
+
* `MapboxCluster.__handleUnclusteredClick`). Integrators wanting a distinct
|
|
73
|
+
* selection per element must give each item a unique id.
|
|
74
|
+
*/
|
|
75
|
+
get id(): string;
|
|
76
|
+
/**
|
|
77
|
+
* The item's coordinates as a `[lng, lat]` tuple.
|
|
78
|
+
*/
|
|
79
|
+
get lngLat(): [number, number];
|
|
80
|
+
/**
|
|
81
|
+
* Extra feature properties merged into the item's GeoJSON feature.
|
|
82
|
+
*/
|
|
83
|
+
get properties(): Record<string, unknown>;
|
|
84
|
+
/**
|
|
85
|
+
* The HTML used as the map popup content when this item is selected.
|
|
86
|
+
*
|
|
87
|
+
* Uses the inner HTML of an optional `[data-ref="popup"]` element when present
|
|
88
|
+
* so the sidebar card and the map popup can differ, otherwise falls back to
|
|
89
|
+
* the item's whole inner HTML.
|
|
90
|
+
*/
|
|
91
|
+
get popupContent(): string;
|
|
92
|
+
/**
|
|
93
|
+
* Mounted hook: resolve the parent cluster and register with it.
|
|
94
|
+
*/
|
|
95
|
+
mounted(): void;
|
|
96
|
+
/**
|
|
97
|
+
* Resolve the parent `MapboxCluster` and register, or wait for one to connect.
|
|
98
|
+
*
|
|
99
|
+
* Resolution is retryable: an item eagerly registered under a lazily imported
|
|
100
|
+
* cluster mounts first and finds nothing, so it waits for
|
|
101
|
+
* `MAPBOX_CLUSTER_CONNECTED` and registers once its cluster is up.
|
|
102
|
+
* @private
|
|
103
|
+
*/
|
|
104
|
+
__resolveCluster(): void;
|
|
105
|
+
/**
|
|
106
|
+
* Subscribe once to `MAPBOX_CLUSTER_CONNECTED` and retry resolution when a
|
|
107
|
+
* cluster whose element is an ancestor of this item connects.
|
|
108
|
+
* @private
|
|
109
|
+
*/
|
|
110
|
+
__waitForConnectedCluster(): void;
|
|
111
|
+
/**
|
|
112
|
+
* Destroyed hook: unregister from the cached cluster, even if the element has
|
|
113
|
+
* already been detached from the DOM, and drop any pending retry subscription.
|
|
114
|
+
*/
|
|
115
|
+
destroyed(): void;
|
|
116
|
+
/**
|
|
117
|
+
* Reflect the "in the current map viewport" state as a `data-in-bounds`
|
|
118
|
+
* attribute. Called by a `StoreLocator` orchestrator on every map `moveend`.
|
|
119
|
+
* @param {boolean} value
|
|
120
|
+
*/
|
|
121
|
+
setInBounds(value: boolean): void;
|
|
122
|
+
/**
|
|
123
|
+
* Reflect the "selected/active" state as a `data-active` attribute and the
|
|
124
|
+
* `aria-current` state. Called by a `StoreLocator` orchestrator on selection.
|
|
125
|
+
* @param {boolean} value
|
|
126
|
+
*/
|
|
127
|
+
setActive(value: boolean): void;
|
|
128
|
+
}
|
|
129
|
+
//#endregion
|
|
130
|
+
export { MapboxClusterItem, MapboxClusterItem as default, MapboxClusterItemProps };
|