@trailstash/ultra 3.2.3 → 3.3.1

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.
@@ -23,9 +23,9 @@ ${description}
23
23
  ${queryContent}
24
24
  \`\`\`
25
25
  <br>
26
- <a target="_blank" href="/#map&${params.toString()}">View Map on Overpass Ultra</a>
26
+ <a target="_blank" href="/#map&${params.toString()}">View Map on Ultra</a>
27
27
  <br>
28
- <a target="_blank" href="/#${params.toString()}">Edit Query on Overpass Ultra</a>`;
28
+ <a target="_blank" href="/#${params.toString()}">Edit Query on Ultra</a>`;
29
29
  if (dir.startsWith("MapLibre-Examples"))
30
30
  html += `<br>
31
31
  <a target="_blank" href="https://maplibre.org/maplibre-gl-js/docs/examples/${file.replace(".ultra", "")}/">View MapLibre Example</a>
Binary file
@@ -32,39 +32,6 @@ export class HelpModal extends HTMLElement {
32
32
  `
33
33
  ${readmeHTML}
34
34
  <div>
35
- <h4>Data Sources</h4>
36
- <ul>
37
- <li>
38
- Data ©
39
- <a target="_blank" href="http://openstreetmap.org/">OpenStreetMap</a>
40
- contributors,
41
- <span style="font-size: smaller">
42
- <a target="_blank" href="http://opendatacommons.org/licenses/odbl/1-0/"
43
- >ODbL</a
44
- >
45
- (<a target="_blank" href="http://www.openstreetmap.org/copyright">Terms</a>)
46
- </span>
47
- </li>
48
- <li>
49
- Data mining by
50
- <a target="_blank" href="http://overpass-api.de/">Overpass API</a>
51
- </li>
52
- <li>
53
- <a target="_blank" href="https://www.openmaptiles.org/"
54
- >OpenMapTiles
55
- </a>
56
- hosted by the
57
- <a target="_blank" href="http://tile.ourmap.us/">
58
- OSM Americana Community Vector Tile Server</a
59
- >
60
- </li>
61
- <li>
62
- <a target="_blank" href="https://www.protomaps.com/"
63
- >Protomaps
64
- </a>
65
- hosted by the Protomaps API
66
- </li>
67
- </ul>
68
35
  <h4>Software &amp; Libraries</h4>
69
36
  <ul>
70
37
  <li>
@@ -95,7 +95,7 @@ export class UltraIDE extends HTMLElement {
95
95
  "options",
96
96
  "controls",
97
97
  "mapStyle",
98
- "extraQueryProviders",
98
+ "queryProviders",
99
99
  "persistState",
100
100
  ];
101
101
  static props = ["settings", "query", "styles", "title", "icon", "help"];
@@ -121,7 +121,7 @@ export class UltraIDE extends HTMLElement {
121
121
  shadow.appendChild(
122
122
  h(
123
123
  "nav-bar",
124
- { title: this.title, icon: this.icon },
124
+ { title: this.settings.title, icon: this.settings.icon },
125
125
  h("fs-button", { slot: "fs-button" }),
126
126
  h(
127
127
  "span",
@@ -5,7 +5,6 @@ import { setQueryBounds } from "../lib/bounds.js";
5
5
  import { setBaseStyle } from "../lib/style.js";
6
6
  import { parseSettings } from "../lib/settings.js";
7
7
  import queryProviders from "../lib/queryProviders/index.js";
8
- import AutoProvider from "../lib/queryProviders/auto.js";
9
8
  import {
10
9
  hasHash,
11
10
  getOptionsFromQueryParams,
@@ -48,7 +47,7 @@ export class UltraMap extends HTMLElement {
48
47
  options: {},
49
48
  controls: [],
50
49
  fitBounds: false,
51
- extraQueryProviders: {},
50
+ queryProviders,
52
51
  persistState: false,
53
52
  };
54
53
 
@@ -70,10 +69,10 @@ export class UltraMap extends HTMLElement {
70
69
 
71
70
  persistState = UltraMap.defaults.persistState;
72
71
 
73
- extraQueryProviders = UltraMap.defaults.extraQueryProviders;
72
+ queryProviders = UltraMap.defaults.queryProviders;
74
73
 
75
74
  static CONFIG_SETTINGS = [
76
- "extraQueryProviders",
75
+ "queryProviders",
77
76
  "loadSettingsFromQueryParams",
78
77
  "persistState",
79
78
  ];
@@ -87,6 +86,9 @@ export class UltraMap extends HTMLElement {
87
86
  "query",
88
87
  "fitBounds",
89
88
  "mapStyle",
89
+ "icon",
90
+ "title",
91
+ "description",
90
92
  ];
91
93
  static RUNTIME_SETTINGS = [
92
94
  "type",
@@ -163,6 +165,16 @@ export class UltraMap extends HTMLElement {
163
165
  #initUnbound(mapStyle) {
164
166
  const hadHash = hasHash(this.options.hash);
165
167
 
168
+ if (this.title) {
169
+ document.title = this.title;
170
+ }
171
+ if (this.icon) {
172
+ document.querySelector('[rel=icon]').href = this.icon;
173
+ }
174
+ if (this.description) {
175
+ // TODO?
176
+ }
177
+
166
178
  this.refs = {
167
179
  mapLibre: h("map-libre", {
168
180
  mapStyle,
@@ -192,7 +204,8 @@ export class UltraMap extends HTMLElement {
192
204
  this.#fitBounds &&
193
205
  (!this.options.hash || !hadHash) &&
194
206
  !this.options.bounds &&
195
- (this.options.zoom === undefined || !this.options.center)
207
+ this.options.zoom === undefined &&
208
+ !this.options.center
196
209
  ) {
197
210
  if (
198
211
  this.#cachedSource?.type === "geojson" &&
@@ -241,7 +254,7 @@ export class UltraMap extends HTMLElement {
241
254
  controller = new AbortController();
242
255
  }
243
256
 
244
- const queryProvider = this.#queryProviders[this.type];
257
+ const queryProvider = this.queryProviders[this.type];
245
258
  if (!queryProvider) {
246
259
  throw new Error(`invalid query provider: ${this.type}`);
247
260
  }
@@ -266,25 +279,11 @@ export class UltraMap extends HTMLElement {
266
279
  return this.#cachedSource.data;
267
280
  }
268
281
 
269
- get #queryProviders() {
270
- if (!this.#autoProvider) {
271
- this.#autoProvider = new AutoProvider({
272
- ...queryProviders,
273
- ...this.extraQueryProviders,
274
- });
275
- }
276
- return {
277
- auto: this.#autoProvider,
278
- ...queryProviders,
279
- ...this.extraQueryProviders,
280
- };
281
- }
282
-
283
282
  get #fitBounds() {
284
283
  if (this.fitBounds) {
285
284
  return this.fitBounds;
286
285
  }
287
- const queryProvider = this.#queryProviders[this.type];
286
+ const queryProvider = this.queryProviders[this.type];
288
287
  if (queryProvider && queryProvider.fitBounds) {
289
288
  return queryProvider.fitBounds;
290
289
  }
@@ -294,14 +293,14 @@ export class UltraMap extends HTMLElement {
294
293
  if (this.popupTemplate) {
295
294
  return this.popupTemplate;
296
295
  }
297
- const queryProvider = this.#queryProviders[this.type];
296
+ const queryProvider = this.queryProviders[this.type];
298
297
  if (queryProvider && queryProvider.popupTemplate) {
299
298
  return queryProvider.popupTemplate;
300
299
  }
301
300
  return this.popupTemplate;
302
301
  }
303
302
  get #popupContextBuilder() {
304
- const queryProvider = this.#queryProviders[this.type];
303
+ const queryProvider = this.queryProviders[this.type];
305
304
  if (queryProvider && queryProvider.popupContextBuilder) {
306
305
  return queryProvider.popupContextBuilder;
307
306
  }
package/docs/yaml.md CHANGED
@@ -42,26 +42,89 @@ popupTemplate: "{{type}} {{id}} - {{tags.name}}"
42
42
 
43
43
  Specify the type of source in the query.
44
44
 
45
- **Default:** `overpass`
45
+ **Default:** `auto`
46
+
47
+ ### `auto`
48
+ Automatically detects and chooses the right query provider out of the following:
49
+ * `overpass`
50
+ * `osmWebsite`
51
+ * `osmWiki`
52
+ * `geojson`
53
+ * `osmxml`
54
+ * `osmjson`
55
+ * `kml`
56
+ * `gpx`
57
+ * `tcx`
58
+
59
+ See each provider for how it is auto-detected
46
60
 
47
61
  ### `overpass`
48
62
  An [Overpass QL](https://wiki.openstreetmap.org/wiki/Overpass_API/Overpass_QL) query. Results
49
63
  converted into a [GeoJSON source](https://maplibre.org/maplibre-style-spec/sources/#geojson) with
50
64
  [`osmtogeojson`](https://github.com/tyrasd/osmtogeojson).
51
65
 
66
+ Detected if:
67
+ * Parses as XML and the top level tag is `osm-script`
68
+ * Matches one of the regexes defined [here](https://gitlab.com/trailstash/ultra/-/blob/main/lib/queryProviders/overpass.js#L11-34)
69
+
70
+ ### `osmWebsite`
71
+ Parses a URL to an node/way/relation on `osm.org` and fetches that element using an Overpass query
72
+ using `out geom;`
73
+
74
+ Detected if:
75
+ * A URL on osm.org starting with node/way/relation
76
+
77
+ ### `osmWiki`
78
+ Perform an Overpass query using `nwr` and `out geom;` for an OSM wiki URL starting with `Tag:` or
79
+ `Key:`
80
+
81
+ Detected if:
82
+ * A URL to the OSM wiki starting with `Tag:` or `Key:`
83
+
52
84
  ### `osmxml`
53
85
  An [OSM XML](https://wiki.openstreetmap.org/wiki/OSM_XML) document or a URL to one. Converted into
54
86
  a [GeoJSON source](https://maplibre.org/maplibre-style-spec/sources/#geojson) with
55
87
  [`osmtogeojson`](https://github.com/tyrasd/osmtogeojson).
56
88
 
89
+ Detected if:
90
+ * Parses as XML and the top level tag is `osm`
91
+ * Parses as a URL and the path matches that of an `node/:id`, `way/:id/full`, or
92
+ `relation/:id/full` OSM API route
93
+
57
94
  ### `osmjson`
58
95
  An [OSM JSON](https://wiki.openstreetmap.org/wiki/OSM_JSON) document or a URL to one. Converted
59
96
  into a [GeoJSON source](https://maplibre.org/maplibre-style-spec/sources/#geojson) with
60
97
  [`osmtogeojson`](https://github.com/tyrasd/osmtogeojson).
61
98
 
99
+ Detected if:
100
+ * Parses as JSON and contains a `version` key containing the value `0.6` at the top level.
101
+ * Parses as a URL and the path matches that of an `node/:id`, `way/:id/full`, or
102
+ `relation/:id/full` OSM API route
103
+
62
104
  ### `geojson`
63
105
  A JSON-encoded GeoJSON object or a URL to a GeoJSON file.
64
106
 
107
+ Detected if:
108
+ * Parses as JSON and contains a `type` with a valid GeoJSON type.
109
+
110
+ ### `kml`
111
+ A KML file or URL to a KML file.
112
+
113
+ Detected if
114
+ * Parses as XML and contains a top level `kml` tag
115
+
116
+ ### `gpx`
117
+ A GPX file or URL to a GPX file.
118
+
119
+ Detected if
120
+ * Parses as XML and contains a top level `gpx` tag
121
+
122
+ ### `tcx`
123
+ A TCX file or URL to a TCX file.
124
+
125
+ Detected if
126
+ * Parses as XML and contains a top level `tcx` tag
127
+
65
128
  ### `raster`
66
129
  A line delimited list of [tile URLs](https://maplibre.org/maplibre-style-spec/sources/#tiles_1) for
67
130
  a [raster source](https://maplibre.org/maplibre-style-spec/sources/#raster) or a [TileJSON
@@ -42,16 +42,16 @@ const fetchURL = async (url) => {
42
42
  };
43
43
 
44
44
  export const hasHash = (hashName) => {
45
- let hash = window.location.hash.slice(1)
45
+ let hash = window.location.hash.slice(1);
46
46
  if (hashName) {
47
47
  const params = new URLSearchParams(hash);
48
48
  hash = params.get(hashName);
49
49
  }
50
50
  if (!hash) {
51
- return false
51
+ return false;
52
52
  }
53
53
  const loc = hash.split("/");
54
- return loc.length >= 3 && !loc.some(v => isNaN(v));
54
+ return loc.length >= 3 && !loc.some((v) => isNaN(v));
55
55
  };
56
56
 
57
57
  export const getQueryFromQueryParams = () => {
@@ -1,3 +1,4 @@
1
+ import AutoProvider from "./auto.js";
1
2
  import overpass, { osmWebsite, osmWiki } from "./overpass.js";
2
3
  import geojson from "./geojson.js";
3
4
  import raster from "./raster.js";
@@ -7,7 +8,7 @@ import kml from "./kml.js";
7
8
  import gpx from "./gpx.js";
8
9
  import tcx from "./tcx.js";
9
10
 
10
- export default {
11
+ export const all = {
11
12
  overpass,
12
13
  osmWebsite,
13
14
  osmWiki,
@@ -20,3 +21,5 @@ export default {
20
21
  raster,
21
22
  vector,
22
23
  };
24
+
25
+ export default { auto: new AutoProvider(all), ...all };
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "3.2.3",
6
+ "version": "3.3.1",
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": {