@trailstash/ultra 3.4.5 → 3.5.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.
@@ -1,9 +1,9 @@
1
1
  ---
2
2
  title: Load GeoJSON with custom BBOX format
3
- description: Load GeoJSON from the Bunting Labs API using the east/west/south/north shortcuts.
3
+ description: Load GeoJSON from the ohsome API using the east/west/south/north shortcuts.
4
4
  type: geojson
5
5
  options:
6
6
  center: [-122.6847, 45.5112]
7
7
  zoom: 15
8
8
  ---
9
- https://osm.buntinglabs.com/v1/osm/extract?bbox={{west}},{{south}},{{east}},{{north}}&tags=amenity%3Dbicycle_repair_station&api_key=4WBfyRaP9pGv
9
+ https://api.ohsome.org/v1/elements/geometry?bboxes={{west}},{{south}},{{east}},{{north}}&filter=amenity%3Dbicycle_repair_station
@@ -10,22 +10,11 @@ import { version as osmtogeojsonVersion } from "osmtogeojson/package.json";
10
10
  const help = `# Introduction
11
11
 
12
12
  Ultra (née Overpass Ultra) is a web-application made to simplify making maps with [MapLibre GL
13
- JS](https://maplibre.org).
14
-
15
- It can easily visualize the following file/query types:
16
-
17
- * [GeoJSON](https://geojson.org/)
18
- * [KML](https://developers.google.com/kml/documentation/kml_tut)
19
- * [GPX](https://www.topografix.com/gpx.asp)
20
- * [TCX](https://en.wikipedia.org/wiki/Training_Center_XML)
21
- * [OverpassQL](https://wiki.openstreetmap.org/wiki/Overpass_API/Overpass_QL)
22
- * [Overpass XML](https://wiki.openstreetmap.org/wiki/Overpass_API/Language_Guide)
23
- * [OSM XML](https://wiki.openstreetmap.org/wiki/OSM_XML)
24
- * [OSM JSON](https://wiki.openstreetmap.org/wiki/OSM_JSON)
13
+ JS](https://maplibre.org) with data from various file/query types such as Overpass, GeoJSON, GPX, and more.
25
14
 
26
15
  ## Documentation
27
16
 
28
- Full documentation for Ultra is available at ${window.location.origin}/docs
17
+ Full documentation for Ultra is available at ${new URL("docs", window.location).toString()}
29
18
 
30
19
  ## Configuration
31
20
 
@@ -76,6 +65,7 @@ export class HelpModal extends HTMLElement {
76
65
  super();
77
66
  this.help = HelpModal.defaults.help;
78
67
  this.styles = [];
68
+ this.queryProviders = {};
79
69
  }
80
70
 
81
71
  connectedCallback() {
@@ -105,6 +95,14 @@ export class HelpModal extends HTMLElement {
105
95
  { style: "padding: 0 8px 8px;max-width:800px;", slot: "modal-content" },
106
96
  `
107
97
  ${helpHTML}
98
+ <div>
99
+ <h4>Installed Query Providers</h4>
100
+ <ul>
101
+ ${Object.entries(this.queryProviders)
102
+ .map(([name]) => `<li><code>${name}</code></li>`)
103
+ .join("\n")}
104
+ </ul>
105
+ </div>
108
106
  ${stylesHTML}
109
107
  <div>
110
108
  <h4>Software &amp; Libraries</h4>
@@ -120,18 +118,31 @@ export class HelpModal extends HTMLElement {
120
118
  >maplibre-gl</a
121
119
  > <code>${maplibreVersion}</code>
122
120
  </li>
123
- <li>
121
+ ${
122
+ this.queryProviders.overpass ||
123
+ this.queryProviders.osmjson ||
124
+ this.queryProviders.osmxml
125
+ ? `<li>
124
126
  OSM to GeoJSON conversion powered by
125
127
  <a target="_blank" href="https://github.com/tyrasd/osmtogeojson"
126
128
  >osmtogeojson</a
127
129
  > <code>${osmtogeojsonVersion}</code>
128
- </li>
129
- <li>
130
+ </li>`
131
+ : ""
132
+ }
133
+
134
+ ${
135
+ this.queryProviders.gpx ||
136
+ this.queryProviders.tcx ||
137
+ this.queryProviders.kml
138
+ ? `<li>
130
139
  KML/GPX/TCX to GeoJSON conversion powered by
131
140
  <a target="_blank" href="https://github.com/placemark/togeojson"
132
141
  >@tmcw/togeojson</a
133
142
  >
134
- </li>
143
+ </li>`
144
+ : ""
145
+ }
135
146
  </ul>
136
147
  </div>
137
148
  `,
@@ -135,6 +135,8 @@ 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
+ queryProviders:
139
+ this.settings.queryProviders || UltraMap.defaults.queryProviders,
138
140
  }),
139
141
  ),
140
142
  ),
@@ -47,7 +47,7 @@ export class UltraMap extends HTMLElement {
47
47
  querySources: ["ultra"],
48
48
  options: {},
49
49
  controls: [],
50
- fitBounds: false,
50
+ fitBounds: undefined,
51
51
  queryProviders,
52
52
  persistState: false,
53
53
  };
@@ -281,11 +281,15 @@ export class UltraMap extends HTMLElement {
281
281
  }
282
282
 
283
283
  get #fitBounds() {
284
- if (this.fitBounds) {
284
+ if (this.fitBounds !== undefined) {
285
285
  return this.fitBounds;
286
286
  }
287
287
  const queryProvider = this.queryProviders[this.type];
288
- if (queryProvider && queryProvider.fitBounds) {
288
+ if (
289
+ queryProvider &&
290
+ queryProvider.fitBounds &&
291
+ setQueryBounds(this.query, this.refs.mapLibre.bounds) === this.query
292
+ ) {
289
293
  return queryProvider.fitBounds;
290
294
  }
291
295
  return this.fitBounds;
package/docs/index.md CHANGED
@@ -1,21 +1,10 @@
1
1
  # Introduction
2
2
 
3
3
  Ultra (née Overpass Ultra) is a web-application made to simplify making maps with [MapLibre GL
4
- JS](https://maplibre.org).
4
+ JS](https://maplibre.org) with data from various file/query types such as Overpass, GeoJSON, GPX, and more.
5
5
 
6
6
  ![](./assets/screenshot.png)
7
7
 
8
- It can easily visualize the following file/query types:
9
-
10
- * [GeoJSON](https://geojson.org/)
11
- * [KML](https://developers.google.com/kml/documentation/kml_tut)
12
- * [GPX](https://www.topografix.com/gpx.asp)
13
- * [TCX](https://en.wikipedia.org/wiki/Training_Center_XML)
14
- * [OverpassQL](https://wiki.openstreetmap.org/wiki/Overpass_API/Overpass_QL)
15
- * [Overpass XML](https://wiki.openstreetmap.org/wiki/Overpass_API/Language_Guide)
16
- * [OSM XML](https://wiki.openstreetmap.org/wiki/OSM_XML)
17
- * [OSM JSON](https://wiki.openstreetmap.org/wiki/OSM_JSON)
18
-
19
8
  ## Getting Started
20
9
  All Ultra maps defined by a document containing an optional configuration and optional query. For
21
10
  example, to query bicycle repair stations using the [Overpass API](https://overpass-api.de), you
package/docs/yaml.md CHANGED
@@ -115,6 +115,15 @@ Detected if:
115
115
  - Parses as a URL and the path matches that of an `node/:id`, `way/:id/full`, or
116
116
  `relation/:id/full` OSM API route
117
117
 
118
+ ### `ohsome`
119
+
120
+ An [ohsome API](https://api.ohsome.org/) [filter](https://docs.ohsome.org/ohsome-api/v1/filter.html).
121
+
122
+ Automatically adds the current bbox with the [`bboxes` param](https://docs.ohsome.org/ohsome-api/v1/boundaries.html#bboxes) and `properties=tags,metadata` using the [extracts endpoint](https://docs.ohsome.org/ohsome-api/v1/endpoints.html#elements-extraction).
123
+
124
+ For more complex ohsome API usage, make a request using the [`geojson`](#geojson) provider with [a
125
+ custom BBOX format](./Examples/alt-bbox-format.md).
126
+
118
127
  ### `geojson`
119
128
 
120
129
  A JSON-encoded GeoJSON object or a URL to a GeoJSON file.
@@ -1,5 +1,6 @@
1
1
  import AutoProvider from "./auto.js";
2
2
  import overpass, { osmWebsite, osmWiki } from "./overpass.js";
3
+ import ohsome from "./ohsome.js";
3
4
  import geojson from "./geojson.js";
4
5
  import raster from "./raster.js";
5
6
  import vector from "./vector.js";
@@ -12,6 +13,7 @@ export const all = {
12
13
  overpass,
13
14
  osmWebsite,
14
15
  osmWiki,
16
+ ohsome,
15
17
  geojson,
16
18
  osmxml,
17
19
  osmjson,
@@ -0,0 +1,62 @@
1
+ import osmtogeojson from "osmtogeojson";
2
+ import { setQueryBounds } from "../bounds.js";
3
+
4
+ import { layers, popupTemplate } from "./osm.js";
5
+
6
+ const popupContextBuilder = ({ properties, geometry }) => {
7
+ const templateContext = {
8
+ id: properties["@osmId"].split("/")[1],
9
+ type: properties["@osmType"],
10
+ meta: {
11
+ changeset: properties["@changesetId"],
12
+ version: properties["@version"],
13
+ lastEdit: properties["@lastEdit"],
14
+ snapshotTimestamp: properties["@snapshotTimestamp"],
15
+ },
16
+ tags: { ...properties },
17
+ };
18
+ delete templateContext.tags["@osmId"];
19
+ delete templateContext.tags["@osmType"];
20
+ delete templateContext.tags["@changesetId"];
21
+ delete templateContext.tags["@version"];
22
+ delete templateContext.tags["@lastEdit"];
23
+ delete templateContext.tags["@snapshotTimestamp"];
24
+ if (properties["@type"] === "node") {
25
+ templateContext.coordinates = geometry.coordinates;
26
+ }
27
+ return templateContext;
28
+ };
29
+
30
+ const overpass = {
31
+ source: async function (query, controller, { server, bounds }) {
32
+ if (!server) {
33
+ server = "https://api.ohsome.org/v1";
34
+ }
35
+ const body = new FormData();
36
+ body.append(
37
+ "bboxes",
38
+ `${bounds.getWest()},${bounds.getSouth()},${bounds.getEast()},${bounds.getNorth()}`,
39
+ );
40
+ body.append("filter", query);
41
+ body.append("properties", "tags,metadata");
42
+ const resp = await fetch(`${server}/elements/geometry`, {
43
+ method: "POST",
44
+ body,
45
+ });
46
+ if (!resp.ok) {
47
+ throw new Error(`Ohsome API returned ${resp.status}`);
48
+ }
49
+ const data = await resp.json();
50
+ return {
51
+ type: "geojson",
52
+ data,
53
+ attribution:
54
+ '\u003Ca href="https://www.openstreetmap.org/copyright" target="_blank"\u003E© OpenStreetMap contributors\u003C/a\u003E',
55
+ generateId: true,
56
+ };
57
+ },
58
+ layers,
59
+ popupTemplate,
60
+ popupContextBuilder,
61
+ };
62
+ export default overpass;
@@ -24,7 +24,7 @@ export const popupTemplate = `
24
24
  <a href="https://openstreetmap.org/{{ type }}/{{ id }}" target="_blank">{{ id }}</a>
25
25
  <a href="https://openstreetmap.org/edit?{{ type }}={{ id }}" target="_blank">✏️</a>
26
26
  </h2>
27
- <h3>Properties</h3>
27
+ <h3>Tags</h3>
28
28
  {%- for tag in tags %}
29
29
  {%- if tag[0] contains "website" %}
30
30
  <code>{{ tag[0] }} = <a href="{{ tag[1] }}" target="_blank">{{ tag[1] }}</a></code>
package/lib/style.js CHANGED
@@ -160,13 +160,13 @@ export function ensureSourceAndLayers(style, source) {
160
160
  if (!spritesheets.includes("maki")) {
161
161
  style.sprite.push({
162
162
  id: "maki",
163
- url: window.location.origin + "/sprites/maki",
163
+ url: new URL("sprites/maki", window.location).toString(),
164
164
  });
165
165
  }
166
166
  if (!spritesheets.includes("temaki")) {
167
167
  style.sprite.push({
168
168
  id: "temaki",
169
- url: window.location.origin + "/sprites/temaki",
169
+ url: new URL("sprites/temaki", window.location).toString(),
170
170
  });
171
171
  }
172
172
  if (source && !style.sources.ultra) {
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "3.4.5",
6
+ "version": "3.5.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": {