@trailstash/ultra 3.2.3 → 3.3.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/build-examples-docs.js +2 -2
- package/components/ultra-ide.js +1 -1
- package/components/ultra-map.js +9 -23
- package/docs/yaml.md +64 -1
- package/lib/queryParams.js +3 -3
- package/lib/queryProviders/index.js +4 -1
- package/package.json +1 -1
package/build-examples-docs.js
CHANGED
|
@@ -23,9 +23,9 @@ ${description}
|
|
|
23
23
|
${queryContent}
|
|
24
24
|
\`\`\`
|
|
25
25
|
<br>
|
|
26
|
-
<a target="_blank" href="/#map&${params.toString()}">View Map on
|
|
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
|
|
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>
|
package/components/ultra-ide.js
CHANGED
package/components/ultra-map.js
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
72
|
+
queryProviders = UltraMap.defaults.queryProviders;
|
|
74
73
|
|
|
75
74
|
static CONFIG_SETTINGS = [
|
|
76
|
-
"
|
|
75
|
+
"queryProviders",
|
|
77
76
|
"loadSettingsFromQueryParams",
|
|
78
77
|
"persistState",
|
|
79
78
|
];
|
|
@@ -192,7 +191,8 @@ export class UltraMap extends HTMLElement {
|
|
|
192
191
|
this.#fitBounds &&
|
|
193
192
|
(!this.options.hash || !hadHash) &&
|
|
194
193
|
!this.options.bounds &&
|
|
195
|
-
|
|
194
|
+
this.options.zoom === undefined &&
|
|
195
|
+
!this.options.center
|
|
196
196
|
) {
|
|
197
197
|
if (
|
|
198
198
|
this.#cachedSource?.type === "geojson" &&
|
|
@@ -241,7 +241,7 @@ export class UltraMap extends HTMLElement {
|
|
|
241
241
|
controller = new AbortController();
|
|
242
242
|
}
|
|
243
243
|
|
|
244
|
-
const queryProvider = this
|
|
244
|
+
const queryProvider = this.queryProviders[this.type];
|
|
245
245
|
if (!queryProvider) {
|
|
246
246
|
throw new Error(`invalid query provider: ${this.type}`);
|
|
247
247
|
}
|
|
@@ -266,25 +266,11 @@ export class UltraMap extends HTMLElement {
|
|
|
266
266
|
return this.#cachedSource.data;
|
|
267
267
|
}
|
|
268
268
|
|
|
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
269
|
get #fitBounds() {
|
|
284
270
|
if (this.fitBounds) {
|
|
285
271
|
return this.fitBounds;
|
|
286
272
|
}
|
|
287
|
-
const queryProvider = this
|
|
273
|
+
const queryProvider = this.queryProviders[this.type];
|
|
288
274
|
if (queryProvider && queryProvider.fitBounds) {
|
|
289
275
|
return queryProvider.fitBounds;
|
|
290
276
|
}
|
|
@@ -294,14 +280,14 @@ export class UltraMap extends HTMLElement {
|
|
|
294
280
|
if (this.popupTemplate) {
|
|
295
281
|
return this.popupTemplate;
|
|
296
282
|
}
|
|
297
|
-
const queryProvider = this
|
|
283
|
+
const queryProvider = this.queryProviders[this.type];
|
|
298
284
|
if (queryProvider && queryProvider.popupTemplate) {
|
|
299
285
|
return queryProvider.popupTemplate;
|
|
300
286
|
}
|
|
301
287
|
return this.popupTemplate;
|
|
302
288
|
}
|
|
303
289
|
get #popupContextBuilder() {
|
|
304
|
-
const queryProvider = this
|
|
290
|
+
const queryProvider = this.queryProviders[this.type];
|
|
305
291
|
if (queryProvider && queryProvider.popupContextBuilder) {
|
|
306
292
|
return queryProvider.popupContextBuilder;
|
|
307
293
|
}
|
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:** `
|
|
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
|
package/lib/queryParams.js
CHANGED
|
@@ -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
|
|
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