@tileflow/vue 0.1.0-alpha.16 → 0.1.0-alpha.17
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/index.js +67 -88
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -18,14 +18,18 @@ import {
|
|
|
18
18
|
mergeTileflowAnalytics,
|
|
19
19
|
normalizeTileflowCaptureId,
|
|
20
20
|
normalizeTileflowStaticImageSize,
|
|
21
|
-
resolveTileflowAnalyticsRequestUrl,
|
|
22
21
|
resolveTileflowManifestMap,
|
|
23
22
|
resolveTileflowMapMode,
|
|
24
23
|
resolveTileflowRuntimeStyle,
|
|
25
24
|
resolveTileflowStaticImageUrl,
|
|
26
|
-
shouldLoadTileflowManifest
|
|
27
|
-
startTileflowSession
|
|
25
|
+
shouldLoadTileflowManifest
|
|
28
26
|
} from "@tileflow/core";
|
|
27
|
+
import {
|
|
28
|
+
attachTileflowMapLifecycle,
|
|
29
|
+
createTileflowMarkerController,
|
|
30
|
+
createTileflowSessionStarter,
|
|
31
|
+
createTileflowTransformRequest
|
|
32
|
+
} from "@tileflow/core/browser";
|
|
29
33
|
var defaultCenter = [0, 20];
|
|
30
34
|
var defaultZoom = 2;
|
|
31
35
|
var TileflowMap = defineComponent({
|
|
@@ -89,9 +93,22 @@ var TileflowMap = defineComponent({
|
|
|
89
93
|
const mapRef = shallowRef(null);
|
|
90
94
|
const captureState = ref("loading");
|
|
91
95
|
const sessionId = createTileflowSessionId();
|
|
92
|
-
const
|
|
93
|
-
|
|
96
|
+
const markerController = createTileflowMarkerController({
|
|
97
|
+
attach(markerInstance, map, marker) {
|
|
98
|
+
markerInstance.setLngLat(marker.coordinates).addTo(map);
|
|
99
|
+
markerInstance.getElement().title = marker.label ?? marker.id;
|
|
100
|
+
},
|
|
101
|
+
create: (marker) => new maplibregl.Marker({
|
|
102
|
+
color: marker.color ?? "#C6A15B"
|
|
103
|
+
}),
|
|
104
|
+
remove: (marker) => marker.remove()
|
|
105
|
+
});
|
|
106
|
+
const sessionStarter = createTileflowSessionStarter({
|
|
107
|
+
sessionId,
|
|
108
|
+
source: "vue"
|
|
109
|
+
});
|
|
94
110
|
let imageResizeObserver = null;
|
|
111
|
+
let mapLifecycle = null;
|
|
95
112
|
let mapResizeObserver = null;
|
|
96
113
|
let manifestLoadId = 0;
|
|
97
114
|
let readinessRunId = 0;
|
|
@@ -193,11 +210,25 @@ var TileflowMap = defineComponent({
|
|
|
193
210
|
};
|
|
194
211
|
const destroyMap = () => {
|
|
195
212
|
readinessRunId += 1;
|
|
196
|
-
|
|
213
|
+
const lifecycle = mapLifecycle;
|
|
214
|
+
const resizeObserver = mapResizeObserver;
|
|
215
|
+
const map = mapRef.value;
|
|
216
|
+
mapLifecycle = null;
|
|
197
217
|
mapResizeObserver = null;
|
|
198
|
-
clearMarkers(markerInstances);
|
|
199
|
-
mapRef.value?.remove();
|
|
200
218
|
mapRef.value = null;
|
|
219
|
+
try {
|
|
220
|
+
lifecycle?.dispose();
|
|
221
|
+
} finally {
|
|
222
|
+
try {
|
|
223
|
+
resizeObserver?.disconnect();
|
|
224
|
+
} finally {
|
|
225
|
+
try {
|
|
226
|
+
markerController.clear();
|
|
227
|
+
} finally {
|
|
228
|
+
map?.remove();
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
}
|
|
201
232
|
};
|
|
202
233
|
const recreateMap = () => {
|
|
203
234
|
destroyMap();
|
|
@@ -206,6 +237,7 @@ var TileflowMap = defineComponent({
|
|
|
206
237
|
return;
|
|
207
238
|
}
|
|
208
239
|
const runtime = runtimeStyle.value;
|
|
240
|
+
const analyticsForMap = resolvedAnalytics.value;
|
|
209
241
|
const map = new maplibregl.Map({
|
|
210
242
|
...props.mapOptions,
|
|
211
243
|
attributionControl: props.mapOptions?.attributionControl ?? { compact: true },
|
|
@@ -213,11 +245,11 @@ var TileflowMap = defineComponent({
|
|
|
213
245
|
container: containerRef.value,
|
|
214
246
|
interactive: resolvedInteractive.value,
|
|
215
247
|
style: runtime.style,
|
|
216
|
-
transformRequest:
|
|
217
|
-
|
|
248
|
+
transformRequest: createTileflowTransformRequest({
|
|
249
|
+
getAnalytics: () => analyticsForMap,
|
|
218
250
|
sessionId,
|
|
219
|
-
props.mapOptions?.transformRequest
|
|
220
|
-
),
|
|
251
|
+
transformRequest: props.mapOptions?.transformRequest ?? void 0
|
|
252
|
+
}),
|
|
221
253
|
zoom: resolvedZoom.value
|
|
222
254
|
});
|
|
223
255
|
mapRef.value = map;
|
|
@@ -228,45 +260,29 @@ var TileflowMap = defineComponent({
|
|
|
228
260
|
map.resize();
|
|
229
261
|
});
|
|
230
262
|
mapResizeObserver.observe(containerRef.value);
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
263
|
+
mapLifecycle = attachTileflowMapLifecycle({
|
|
264
|
+
getSession: () => {
|
|
265
|
+
const analyticsForLoad = resolvedAnalytics.value;
|
|
266
|
+
return {
|
|
267
|
+
analytics: analyticsForLoad,
|
|
268
|
+
styleId: analyticsForLoad?.styleId ?? (typeof runtime.style === "string" ? runtime.style : props.map)
|
|
269
|
+
};
|
|
270
|
+
},
|
|
271
|
+
map,
|
|
272
|
+
onLoad: (loadedMap) => emit("load", loadedMap),
|
|
273
|
+
scheduler: {
|
|
274
|
+
cancelFrame: (frame) => cancelAnimationFrame(frame),
|
|
275
|
+
requestFrame: (callback) => requestAnimationFrame(callback)
|
|
276
|
+
},
|
|
277
|
+
sessionStarter,
|
|
278
|
+
setState: (state) => {
|
|
279
|
+
captureState.value = state;
|
|
280
|
+
},
|
|
281
|
+
subscribe: (subscribedMap, event, listener) => {
|
|
282
|
+
const subscription = subscribedMap.on(event, listener);
|
|
283
|
+
return () => subscription.unsubscribe();
|
|
246
284
|
}
|
|
247
285
|
});
|
|
248
|
-
map.on("dataloading", () => {
|
|
249
|
-
readinessRunId += 1;
|
|
250
|
-
captureState.value = "loading";
|
|
251
|
-
});
|
|
252
|
-
map.on("styledataloading", () => {
|
|
253
|
-
readinessRunId += 1;
|
|
254
|
-
captureState.value = "loading";
|
|
255
|
-
});
|
|
256
|
-
map.on("idle", () => {
|
|
257
|
-
const runId = ++readinessRunId;
|
|
258
|
-
requestAnimationFrame(() => {
|
|
259
|
-
requestAnimationFrame(() => {
|
|
260
|
-
if (runId === readinessRunId && mapRef.value === map) {
|
|
261
|
-
captureState.value = "idle";
|
|
262
|
-
}
|
|
263
|
-
});
|
|
264
|
-
});
|
|
265
|
-
});
|
|
266
|
-
map.on("error", () => {
|
|
267
|
-
readinessRunId += 1;
|
|
268
|
-
captureState.value = "error";
|
|
269
|
-
});
|
|
270
286
|
syncMarkers();
|
|
271
287
|
};
|
|
272
288
|
const syncView = () => {
|
|
@@ -277,17 +293,11 @@ var TileflowMap = defineComponent({
|
|
|
277
293
|
};
|
|
278
294
|
const syncMarkers = () => {
|
|
279
295
|
const map = mapRef.value;
|
|
280
|
-
clearMarkers(markerInstances);
|
|
281
296
|
if (!map) {
|
|
297
|
+
markerController.clear();
|
|
282
298
|
return;
|
|
283
299
|
}
|
|
284
|
-
|
|
285
|
-
const markerInstance = new maplibregl.Marker({
|
|
286
|
-
color: marker.color ?? "#C6A15B"
|
|
287
|
-
}).setLngLat(marker.coordinates).addTo(map);
|
|
288
|
-
markerInstance.getElement().title = marker.label ?? marker.id;
|
|
289
|
-
markerInstances.push(markerInstance);
|
|
290
|
-
}
|
|
300
|
+
markerController.replace(map, props.markers);
|
|
291
301
|
};
|
|
292
302
|
const markImageReady = async (image) => {
|
|
293
303
|
const runId = ++readinessRunId;
|
|
@@ -421,40 +431,9 @@ var TileflowMap = defineComponent({
|
|
|
421
431
|
}
|
|
422
432
|
});
|
|
423
433
|
var index_default = TileflowMap;
|
|
424
|
-
function createTransformRequest(analytics, sessionId, userTransformRequest) {
|
|
425
|
-
if ((!analytics || analytics.enabled === false) && !userTransformRequest) {
|
|
426
|
-
return void 0;
|
|
427
|
-
}
|
|
428
|
-
return (url, resourceType) => {
|
|
429
|
-
const request = userTransformRequest?.(url, resourceType);
|
|
430
|
-
if (isPromiseLike(request)) {
|
|
431
|
-
return request.then(
|
|
432
|
-
(resolvedRequest) => applyTileflowAnalyticsRequest(url, resolvedRequest, analytics, sessionId) ?? resolvedRequest
|
|
433
|
-
);
|
|
434
|
-
}
|
|
435
|
-
return applyTileflowAnalyticsRequest(url, request, analytics, sessionId);
|
|
436
|
-
};
|
|
437
|
-
}
|
|
438
|
-
function applyTileflowAnalyticsRequest(url, request, analytics, sessionId) {
|
|
439
|
-
const requestUrl = request?.url ?? url;
|
|
440
|
-
const nextUrl = resolveTileflowAnalyticsRequestUrl(requestUrl, analytics, sessionId);
|
|
441
|
-
if (!nextUrl) {
|
|
442
|
-
return request;
|
|
443
|
-
}
|
|
444
|
-
return request ? { ...request, url: nextUrl } : { url: nextUrl };
|
|
445
|
-
}
|
|
446
|
-
function isPromiseLike(value) {
|
|
447
|
-
return Boolean(value && typeof value.then === "function");
|
|
448
|
-
}
|
|
449
434
|
function formatHeight(height) {
|
|
450
435
|
return typeof height === "number" ? `${height}px` : height;
|
|
451
436
|
}
|
|
452
|
-
function clearMarkers(markerInstances) {
|
|
453
|
-
for (const marker of markerInstances) {
|
|
454
|
-
marker.remove();
|
|
455
|
-
}
|
|
456
|
-
markerInstances.splice(0);
|
|
457
|
-
}
|
|
458
437
|
export {
|
|
459
438
|
TileflowMap,
|
|
460
439
|
index_default as default
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tileflow/vue",
|
|
3
|
-
"version": "0.1.0-alpha.
|
|
3
|
+
"version": "0.1.0-alpha.17",
|
|
4
4
|
"description": "Vue component for rendering Tileflow maps with MapLibre.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"access": "public"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@tileflow/core": "0.1.0-alpha.
|
|
39
|
+
"@tileflow/core": ">=0.1.0-alpha.17 <0.1.0-beta.0"
|
|
40
40
|
},
|
|
41
41
|
"peerDependencies": {
|
|
42
42
|
"maplibre-gl": ">=5",
|