@trailstash/ultra 3.8.7 → 3.9.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/components/ultra-map.js +11 -1
- package/lib/queryMap.js +23 -2
- package/lib/queryProviders/overpass.js +14 -4
- package/package.json +1 -1
package/components/ultra-map.js
CHANGED
|
@@ -46,6 +46,7 @@ export class UltraMap extends HTMLElement {
|
|
|
46
46
|
mapStyle:
|
|
47
47
|
"https://trailstash.github.io/naturalearthtiles/maps/natural_earth.vector.json",
|
|
48
48
|
popupTemplate: null,
|
|
49
|
+
popupOnHover: false,
|
|
49
50
|
querySources: ["ultra"],
|
|
50
51
|
options: {},
|
|
51
52
|
controls: [],
|
|
@@ -63,6 +64,7 @@ export class UltraMap extends HTMLElement {
|
|
|
63
64
|
mapStyle = UltraMap.defaults.mapStyle;
|
|
64
65
|
|
|
65
66
|
popupTemplate = UltraMap.defaults.popupTemplate;
|
|
67
|
+
popupOnHover = UltraMap.defaults.popupOnHover;
|
|
66
68
|
querySources = UltraMap.defaults.querySources;
|
|
67
69
|
|
|
68
70
|
options = UltraMap.defaults.options;
|
|
@@ -85,6 +87,7 @@ export class UltraMap extends HTMLElement {
|
|
|
85
87
|
"type",
|
|
86
88
|
"server",
|
|
87
89
|
"popupTemplate",
|
|
90
|
+
"popupOnHover",
|
|
88
91
|
"querySources",
|
|
89
92
|
"query",
|
|
90
93
|
"fitBounds",
|
|
@@ -97,6 +100,7 @@ export class UltraMap extends HTMLElement {
|
|
|
97
100
|
"type",
|
|
98
101
|
"server",
|
|
99
102
|
"popupTemplate",
|
|
103
|
+
"popupOnHover",
|
|
100
104
|
"querySources",
|
|
101
105
|
"query",
|
|
102
106
|
"fitBounds",
|
|
@@ -208,7 +212,13 @@ export class UltraMap extends HTMLElement {
|
|
|
208
212
|
),
|
|
209
213
|
);
|
|
210
214
|
this.refs.mapLibre.map.on("mousemove", (e) =>
|
|
211
|
-
handleMouseMove(
|
|
215
|
+
handleMouseMove(
|
|
216
|
+
e,
|
|
217
|
+
this.#popupTemplate,
|
|
218
|
+
this.#popupContextBuilder,
|
|
219
|
+
this.querySources,
|
|
220
|
+
this.popupOnHover,
|
|
221
|
+
),
|
|
212
222
|
);
|
|
213
223
|
this.refs.mapLibre.map.on("styleimagemissing", handleStyleImageMissing);
|
|
214
224
|
this.refs.mapLibre.map.on("moveend", this.onMoveEnd);
|
package/lib/queryMap.js
CHANGED
|
@@ -1,8 +1,18 @@
|
|
|
1
1
|
import maplibregl from "maplibre-gl";
|
|
2
|
+
import equal from "fast-deep-equal";
|
|
2
3
|
|
|
3
4
|
import { h } from "../lib/dom.js";
|
|
4
5
|
|
|
5
|
-
|
|
6
|
+
let currentPopup;
|
|
7
|
+
let currentFeatures;
|
|
8
|
+
|
|
9
|
+
export const handleMouseMove = (
|
|
10
|
+
e,
|
|
11
|
+
popupTemplate,
|
|
12
|
+
popupContextBuilder,
|
|
13
|
+
querySources,
|
|
14
|
+
onHover = false,
|
|
15
|
+
) => {
|
|
6
16
|
if (popupTemplate === false) {
|
|
7
17
|
return;
|
|
8
18
|
}
|
|
@@ -14,6 +24,9 @@ export const handleMouseMove = (e, popupTemplate, querySources) => {
|
|
|
14
24
|
} else {
|
|
15
25
|
e.target.getCanvas().style.cursor = "";
|
|
16
26
|
}
|
|
27
|
+
if (onHover) {
|
|
28
|
+
handleMouseClick(e, popupTemplate, popupContextBuilder, querySources);
|
|
29
|
+
}
|
|
17
30
|
};
|
|
18
31
|
|
|
19
32
|
export const handleMouseClick = (
|
|
@@ -32,6 +45,14 @@ export const handleMouseClick = (
|
|
|
32
45
|
for (const f of features) {
|
|
33
46
|
distinctFeatures[f.id] = f;
|
|
34
47
|
}
|
|
48
|
+
if (equal(currentFeatures, distinctFeatures) && currentPopup) {
|
|
49
|
+
currentPopup.setLngLat(e.lngLat);
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
currentFeatures = distinctFeatures;
|
|
53
|
+
if (currentPopup) {
|
|
54
|
+
currentPopup.remove();
|
|
55
|
+
}
|
|
35
56
|
const popup = h("map-popup");
|
|
36
57
|
popup.features = distinctFeatures;
|
|
37
58
|
if (popupTemplate) {
|
|
@@ -41,7 +62,7 @@ export const handleMouseClick = (
|
|
|
41
62
|
popup.contextBuilder = popupContextBuilder;
|
|
42
63
|
}
|
|
43
64
|
if (features.length > 0) {
|
|
44
|
-
new maplibregl.Popup()
|
|
65
|
+
currentPopup = new maplibregl.Popup()
|
|
45
66
|
.setMaxWidth("400px")
|
|
46
67
|
.setLngLat(e.lngLat)
|
|
47
68
|
.setDOMContent(popup)
|
|
@@ -87,12 +87,22 @@ export async function callInterpreter(
|
|
|
87
87
|
) {
|
|
88
88
|
let geoJSON;
|
|
89
89
|
if (resp.headers.get("content-type") == "application/osm3s+xml") {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
90
|
+
const dom = new window.DOMParser().parseFromString(
|
|
91
|
+
await resp.text(),
|
|
92
|
+
"text/xml",
|
|
93
93
|
);
|
|
94
|
+
if (dom.querySelector("remark")) {
|
|
95
|
+
alert(dom.querySelector("remark").textContent);
|
|
96
|
+
return { type: "FeatureCollection", features: [] };
|
|
97
|
+
}
|
|
98
|
+
geoJSON = osmtogeojson(dom, { flatProperties: false });
|
|
94
99
|
} else {
|
|
95
|
-
|
|
100
|
+
const json = await resp.json();
|
|
101
|
+
if (json.remark) {
|
|
102
|
+
alert(json.remark);
|
|
103
|
+
return { type: "FeatureCollection", features: [] };
|
|
104
|
+
}
|
|
105
|
+
geoJSON = osmtogeojson(json, { flatProperties: false });
|
|
96
106
|
}
|
|
97
107
|
|
|
98
108
|
return flattenProperties(geoJSON);
|
package/package.json
CHANGED