@trailstash/ultra 4.1.3 → 4.1.4

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.
@@ -1,6 +1,6 @@
1
1
  import pick from "lodash.pick";
2
2
  import bbox from "@turf/bbox";
3
- import { h } from "../lib/dom.js";
3
+ import { h, t } from "../lib/dom.js";
4
4
  import { setQueryBounds } from "../lib/bounds.js";
5
5
  import { setBaseStyle } from "../lib/style.js";
6
6
  import { parseSettings } from "../lib/settings.js";
@@ -24,6 +24,31 @@ css.replaceSync(`
24
24
  display: flex;
25
25
  flex-direction: column;
26
26
  }
27
+ main {
28
+ justify-content: center;
29
+ align-items: center;
30
+ }
31
+ .loading-indicator {
32
+ width: 4.5em;
33
+ position: absolute;
34
+ background: rgba(0,0,0,0.5);
35
+ color: white;
36
+ z-index: 1000;
37
+ padding: 1em;
38
+ display: none;
39
+ }
40
+ .loading-indicator:after {
41
+ display: inline-block;
42
+ animation: dotty steps(1,end) 1s infinite;
43
+ content: '';
44
+ }
45
+ @keyframes dotty {
46
+ 0% { content: ''; }
47
+ 25% { content: '.'; }
48
+ 50% { content: '..'; }
49
+ 75% { content: '...'; }
50
+ 100% { content: ''; }
51
+ }
27
52
  `);
28
53
 
29
54
  export class UltraMap extends HTMLElement {
@@ -194,13 +219,20 @@ export class UltraMap extends HTMLElement {
194
219
  }
195
220
 
196
221
  this.refs = {
222
+ loadingIndicator: h(
223
+ "div",
224
+ { className: "loading-indicator" },
225
+ t("Loading"),
226
+ ),
197
227
  mapLibre: h("map-libre", {
198
228
  mapStyle,
199
229
  options: this.options,
200
230
  controls: this.controls,
201
231
  }),
202
232
  };
203
- this.#shadow.appendChild(h("main", {}, this.refs.mapLibre));
233
+ this.#shadow.appendChild(
234
+ h("main", {}, this.refs.loadingIndicator, this.refs.mapLibre),
235
+ );
204
236
 
205
237
  this.refs.mapLibre.map.on("click", (e) =>
206
238
  handleMouseClick(
@@ -274,39 +306,48 @@ export class UltraMap extends HTMLElement {
274
306
  return;
275
307
  }
276
308
 
277
- if (!controller) {
278
- controller = new AbortController();
279
- }
309
+ this.refs.loadingIndicator.style.display = "block";
280
310
 
281
- const queryProvider = this.queryProviders[this.type];
282
- if (!queryProvider) {
283
- throw new Error(`invalid query provider: ${this.type}`);
284
- }
285
- const query = setQueryBounds(this.query, this.refs.mapLibre.bounds);
286
- if (
287
- !this.#cachedSource ||
288
- this.type !== this.#cachedType ||
289
- query !== this.#cachedQuery ||
290
- (queryProvider.invalidateCacheOnBBox &&
291
- this.#cachedBBox !=
292
- setQueryBounds("{{bbox}}", this.refs.mapLibre.bounds))
293
- ) {
294
- this.#cachedBBox = setQueryBounds("{{bbox}}", this.refs.mapLibre.bounds);
295
- this.#cachedQuery = query;
296
- this.#cachedType = this.type;
297
- this.#cachedSource = await queryProvider.source(query, controller, {
298
- server: this.server,
299
- bounds: this.refs.mapLibre.bounds,
311
+ try {
312
+ if (!controller) {
313
+ controller = new AbortController();
314
+ }
315
+
316
+ const queryProvider = this.queryProviders[this.type];
317
+ if (!queryProvider) {
318
+ throw new Error(`invalid query provider: ${this.type}`);
319
+ }
320
+ const query = setQueryBounds(this.query, this.refs.mapLibre.bounds);
321
+ if (
322
+ !this.#cachedSource ||
323
+ this.type !== this.#cachedType ||
324
+ query !== this.#cachedQuery ||
325
+ (queryProvider.invalidateCacheOnBBox &&
326
+ this.#cachedBBox !=
327
+ setQueryBounds("{{bbox}}", this.refs.mapLibre.bounds))
328
+ ) {
329
+ this.#cachedBBox = setQueryBounds(
330
+ "{{bbox}}",
331
+ this.refs.mapLibre.bounds,
332
+ );
333
+ this.#cachedQuery = query;
334
+ this.#cachedType = this.type;
335
+ this.#cachedSource = await queryProvider.source(query, controller, {
336
+ server: this.server,
337
+ bounds: this.refs.mapLibre.bounds,
338
+ });
339
+ }
340
+ this.refs.mapLibre.mapStyle = await getStyle(this.mapStyle, {
341
+ // Don't love this...
342
+ source: this.#cachedSource,
343
+ layers: queryProvider.layers
344
+ ? await Promise.resolve(queryProvider.layers("ultra", query))
345
+ : [],
300
346
  });
347
+ return this.#cachedSource.data;
348
+ } finally {
349
+ this.refs.loadingIndicator.style.display = "none";
301
350
  }
302
- this.refs.mapLibre.mapStyle = await getStyle(this.mapStyle, {
303
- // Don't love this...
304
- source: this.#cachedSource,
305
- layers: queryProvider.layers
306
- ? await Promise.resolve(queryProvider.layers("ultra", query))
307
- : [],
308
- });
309
- return this.#cachedSource.data;
310
351
  }
311
352
 
312
353
  get #fitBounds() {
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "4.1.3",
6
+ "version": "4.1.4",
7
7
  "description": "A web based tool for making MapLibre GL maps with data from sources such as Overpass, GeoJSON, GPX, KML, TCX, etc",
8
8
  "main": "index.js",
9
9
  "scripts": {