@trailstash/ultra 3.5.1 → 3.6.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.
@@ -58,6 +58,7 @@ The [source code](https://gitlab.com/trailstash/ultra) of this application is re
58
58
  `;
59
59
 
60
60
  export class HelpModal extends HTMLElement {
61
+ type;
61
62
  static defaults = {
62
63
  help,
63
64
  };
@@ -99,9 +100,14 @@ export class HelpModal extends HTMLElement {
99
100
  <h4>Installed Query Providers</h4>
100
101
  <ul>
101
102
  ${Object.entries(this.queryProviders)
102
- .map(([name]) => `<li><code>${name}</code></li>`)
103
+ .map(
104
+ ([name, { detect }]) =>
105
+ `<li><code>${name}${name == this.type ? "+" : ""}${"auto" in this.queryProviders && detect ? "*" : ""}</code></li>`,
106
+ )
103
107
  .join("\n")}
104
108
  </ul>
109
+ <code>+</code> default provider.
110
+ ${"auto" in this.queryProviders && Object.values(this.queryProviders).some(({ detect }) => !!detect) ? "<br><code>*</code> detected by <code>auto</code> provider." : ""}
105
111
  </div>
106
112
  ${stylesHTML}
107
113
  <div>
@@ -135,6 +135,7 @@ export class UltraIDE extends HTMLElement {
135
135
  h("help-modal", {
136
136
  help: this.help || HelpModal.defaults.help,
137
137
  styles: this.styles || StylePicker.defaults.styles,
138
+ type: this.settings.type || UltraMap.defaults.type,
138
139
  queryProviders:
139
140
  this.settings.queryProviders || UltraMap.defaults.queryProviders,
140
141
  }),
@@ -30,6 +30,7 @@ export class UltraMap extends HTMLElement {
30
30
  #init;
31
31
  #shadow;
32
32
 
33
+ #cachedBBox;
33
34
  #cachedType;
34
35
  #cachedQuery;
35
36
  #cachedSource;
@@ -263,8 +264,12 @@ export class UltraMap extends HTMLElement {
263
264
  if (
264
265
  !this.#cachedSource ||
265
266
  this.type !== this.#cachedType ||
266
- query !== this.#cachedQuery
267
+ query !== this.#cachedQuery ||
268
+ (queryProvider.invalidateCacheOnBBox &&
269
+ this.#cachedBBox !=
270
+ setQueryBounds("{{bbox}}", this.refs.mapLibre.bounds))
267
271
  ) {
272
+ this.#cachedBBox = setQueryBounds("{{bbox}}", this.refs.mapLibre.bounds);
268
273
  this.#cachedQuery = query;
269
274
  this.#cachedType = this.type;
270
275
  this.#cachedSource = await queryProvider.source(query, controller, {
package/docs/yaml.md CHANGED
@@ -59,6 +59,7 @@ Automatically detects and chooses the right query provider out of the following:
59
59
  - `kml`
60
60
  - `gpx`
61
61
  - `tcx`
62
+ - `raw`
62
63
 
63
64
  See each provider for how it is auto-detected
64
65
 
@@ -156,6 +157,14 @@ Detected if
156
157
 
157
158
  - Parses as XML and contains a top level `tcx` tag
158
159
 
160
+ ### `raw`
161
+
162
+ A full [MapLibre Source](https://maplibre.org/maplibre-style-spec/sources/) as JSON or YAML.
163
+
164
+ Detected if
165
+
166
+ - Parses as JSON or YAML and contains a valid MapLibre Source `type`.
167
+
159
168
  ### `raster`
160
169
 
161
170
  A line delimited list of [tile URLs](https://maplibre.org/maplibre-style-spec/sources/#tiles_1) for
@@ -3,6 +3,7 @@ export default class AutoProvider {
3
3
  #layers;
4
4
  #popupContextBuilder;
5
5
  #popupTemplate;
6
+ #invalidateCacheOnBBox;
6
7
  #providers;
7
8
 
8
9
  constructor(providers = {}) {
@@ -23,6 +24,7 @@ export default class AutoProvider {
23
24
  this.#layers = provider.layers;
24
25
  this.#popupContextBuilder = provider.popupContextBuilder;
25
26
  this.#popupTemplate = provider.popupTemplate;
27
+ this.#invalidateCacheOnBBox = provider.invalidateCacheOnBBox;
26
28
  return provider.source(query, controller, { server, bounds });
27
29
  }
28
30
  }
@@ -44,4 +46,12 @@ export default class AutoProvider {
44
46
  get popupTemplate() {
45
47
  return this.#popupTemplate;
46
48
  }
49
+
50
+ get invalidateCacheOnBBox() {
51
+ // This isn't ideal, because this is called _before_ `source`, but it will work because it's either:
52
+ // * undefined & the first run, so bc first run it always will execute anyway
53
+ // * different type, which might mean a different invalidateCacheOnBBox value, but we always run on new type anyway
54
+ // * type unchanged, & subsequent run, so actually valid value
55
+ return this.#invalidateCacheOnBBox;
56
+ }
47
57
  }
@@ -8,20 +8,22 @@ import { osmxml, osmjson } from "./osm.js";
8
8
  import kml from "./kml.js";
9
9
  import gpx from "./gpx.js";
10
10
  import tcx from "./tcx.js";
11
+ import raw from "./raw.js";
11
12
 
12
13
  export const all = {
14
+ raw,
15
+ raster,
16
+ vector,
13
17
  overpass,
14
18
  osmWebsite,
15
19
  osmWiki,
16
- ohsome,
17
- geojson,
18
20
  osmxml,
19
21
  osmjson,
22
+ geojson,
20
23
  kml,
21
24
  gpx,
22
25
  tcx,
23
- raster,
24
- vector,
26
+ ohsome,
25
27
  };
26
28
 
27
29
  export default { auto: new AutoProvider(all), ...all };
@@ -58,5 +58,6 @@ const overpass = {
58
58
  layers,
59
59
  popupTemplate,
60
60
  popupContextBuilder,
61
+ invalidateCacheOnBBox: true,
61
62
  };
62
63
  export default overpass;
@@ -126,6 +126,7 @@ export const osmWebsite = {
126
126
  return !!query.match(osmUrlRe);
127
127
  },
128
128
  fitBounds: true,
129
+ invalidateCacheOnBBox: true,
129
130
  };
130
131
 
131
132
  export const osmWiki = {
@@ -165,4 +166,5 @@ out geom;`,
165
166
  const page = decodeURIComponent(url.pathname.slice(6));
166
167
  return page.split(":")[0] === "Tag" || page.split(":")[0] === "Key";
167
168
  },
169
+ invalidateCacheOnBBox: true,
168
170
  };
@@ -0,0 +1,36 @@
1
+ import YAML from "yaml";
2
+
3
+ export default {
4
+ source: async function geojson(query, controller) {
5
+ let data;
6
+ try {
7
+ return JSON.parse(query);
8
+ } catch {
9
+ return YAML.parse(query, { merge: true });
10
+ }
11
+ },
12
+ detect,
13
+ };
14
+
15
+ const sourceTypes = [
16
+ "vector",
17
+ "raster",
18
+ "geojson",
19
+ "image",
20
+ "raster-dem",
21
+ "video",
22
+ ];
23
+
24
+ function detect(query) {
25
+ try {
26
+ let json;
27
+ try {
28
+ json = JSON.parse(query);
29
+ } catch {
30
+ json = YAML.parse(query, { merge: true });
31
+ }
32
+ if (sourceTypes.includes(json.type)) {
33
+ return true;
34
+ }
35
+ } catch {}
36
+ }
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "3.5.1",
6
+ "version": "3.6.0",
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": {