@openremote/or-map 1.8.0-snapshot.20250725074716 → 1.8.0-snapshot.20250725120001
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/@types/maplibre-gl-geocoder.d.ts +2 -2
- package/README.md +113 -113
- package/dist/umd/index.bundle.js +915 -915
- package/dist/umd/index.bundle.js.map +1 -1
- package/dist/umd/index.js +915 -915
- package/dist/umd/index.js.map +1 -1
- package/dist/umd/index.orbundle.js +974 -974
- package/dist/umd/index.orbundle.js.map +1 -1
- package/lib/index.js +519 -39
- package/lib/mapbox-url-utils.js +66 -1
- package/lib/mapwidget.js +885 -1
- package/lib/markers/or-map-marker-asset.js +178 -1
- package/lib/markers/or-map-marker.js +335 -80
- package/lib/or-map-asset-card.js +167 -18
- package/lib/style.js +242 -235
- package/lib/util.js +100 -1
- package/package.json +8 -8
package/lib/index.js
CHANGED
|
@@ -1,41 +1,521 @@
|
|
|
1
|
-
var __decorate
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
import manager from "@openremote/core";
|
|
8
|
+
import { FlattenedNodesObserver } from "@polymer/polymer/lib/utils/flattened-nodes-observer.js";
|
|
9
|
+
import { html, LitElement } from "lit";
|
|
10
|
+
import { customElement, property, query } from "lit/decorators.js";
|
|
11
|
+
import { LngLat, GeolocateControl } from "maplibre-gl";
|
|
12
|
+
import { MapWidget } from "./mapwidget";
|
|
13
|
+
import { style } from "./style";
|
|
14
|
+
import "./markers/or-map-marker";
|
|
15
|
+
import "./markers/or-map-marker-asset";
|
|
16
|
+
import { OrMapMarker, OrMapMarkerChangedEvent } from "./markers/or-map-marker";
|
|
17
|
+
import * as Util from "./util";
|
|
18
|
+
import { InputType, OrMwcInput } from "@openremote/or-mwc-components/or-mwc-input";
|
|
19
|
+
import { OrMwcDialog, showDialog } from "@openremote/or-mwc-components/or-mwc-dialog";
|
|
20
|
+
import { getMarkerIconAndColorFromAssetType } from "./util";
|
|
21
|
+
import { i18next } from "@openremote/or-translate";
|
|
22
|
+
import { debounce } from "lodash";
|
|
23
|
+
// Re-exports
|
|
24
|
+
export { Util };
|
|
25
|
+
export * from "./markers/or-map-marker";
|
|
26
|
+
export * from "./markers/or-map-marker-asset";
|
|
27
|
+
export * from "./or-map-asset-card";
|
|
28
|
+
export class OrMapLoadedEvent extends CustomEvent {
|
|
29
|
+
constructor() {
|
|
30
|
+
super(OrMapLoadedEvent.NAME, {
|
|
31
|
+
bubbles: true,
|
|
32
|
+
composed: true
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
OrMapLoadedEvent.NAME = "or-map-loaded";
|
|
37
|
+
export class OrMapClickedEvent extends CustomEvent {
|
|
38
|
+
constructor(lngLat, doubleClick = false) {
|
|
39
|
+
super(OrMapClickedEvent.NAME, {
|
|
40
|
+
detail: {
|
|
41
|
+
doubleClick: doubleClick,
|
|
42
|
+
lngLat: lngLat
|
|
43
|
+
},
|
|
44
|
+
bubbles: true,
|
|
45
|
+
composed: true
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
OrMapClickedEvent.NAME = "or-map-clicked";
|
|
50
|
+
export class OrMapLongPressEvent extends CustomEvent {
|
|
51
|
+
constructor(lngLat) {
|
|
52
|
+
super(OrMapLongPressEvent.NAME, {
|
|
53
|
+
detail: {
|
|
54
|
+
doubleClick: false,
|
|
55
|
+
lngLat: lngLat
|
|
56
|
+
},
|
|
57
|
+
bubbles: true,
|
|
58
|
+
composed: true
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
OrMapLongPressEvent.NAME = "or-map-long-press";
|
|
63
|
+
export class OrMapGeocoderChangeEvent extends CustomEvent {
|
|
64
|
+
constructor(geocode) {
|
|
65
|
+
super(OrMapGeocoderChangeEvent.NAME, {
|
|
66
|
+
detail: {
|
|
67
|
+
geocode
|
|
68
|
+
},
|
|
69
|
+
bubbles: true,
|
|
70
|
+
composed: true
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
OrMapGeocoderChangeEvent.NAME = "or-map-geocoder-change";
|
|
75
|
+
export class CenterControl {
|
|
76
|
+
onAdd(map) {
|
|
77
|
+
this.map = map;
|
|
78
|
+
const control = document.createElement("div");
|
|
79
|
+
control.classList.add("maplibregl-ctrl");
|
|
80
|
+
control.classList.add("maplibregl-ctrl-group");
|
|
81
|
+
const button = document.createElement("button");
|
|
82
|
+
button.className = "maplibregl-ctrl-compass";
|
|
83
|
+
button.addEventListener("click", (ev) => map.flyTo({
|
|
84
|
+
center: this.pos,
|
|
85
|
+
zoom: map.getZoom()
|
|
86
|
+
}));
|
|
87
|
+
const buttonIcon = document.createElement("span");
|
|
88
|
+
buttonIcon.className = "maplibregl-ctrl-icon";
|
|
89
|
+
button.appendChild(buttonIcon);
|
|
90
|
+
control.appendChild(button);
|
|
91
|
+
this.elem = control;
|
|
92
|
+
return control;
|
|
93
|
+
}
|
|
94
|
+
onRemove(map) {
|
|
95
|
+
this.map = undefined;
|
|
96
|
+
this.elem = undefined;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
const CoordinatesRegexPattern = "^[ ]*(?:Lat: )?(-?\\d+\\.?\\d*)[, ]+(?:Lng: )?(-?\\d+\\.?\\d*)[ ]*$";
|
|
100
|
+
function getCoordinatesInputKeyHandler(valueChangedHandler) {
|
|
101
|
+
return (e) => {
|
|
102
|
+
if (e.code === "Enter" || e.code === "NumpadEnter") {
|
|
103
|
+
const valStr = e.target.value;
|
|
104
|
+
let value = !valStr ? undefined : {};
|
|
105
|
+
if (valStr) {
|
|
106
|
+
const lngLatArr = valStr.split(/[ ,]/).filter(v => !!v);
|
|
107
|
+
if (lngLatArr.length === 2) {
|
|
108
|
+
value = new LngLat(Number.parseFloat(lngLatArr[0]), Number.parseFloat(lngLatArr[1]));
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
valueChangedHandler(value);
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
export class CoordinatesControl {
|
|
116
|
+
constructor(disabled = false, valueChangedHandler) {
|
|
117
|
+
this._readonly = false;
|
|
118
|
+
this._readonly = disabled;
|
|
119
|
+
this._valueChangedHandler = valueChangedHandler;
|
|
120
|
+
}
|
|
121
|
+
onAdd(map) {
|
|
122
|
+
this.map = map;
|
|
123
|
+
const control = document.createElement("div");
|
|
124
|
+
control.classList.add("maplibregl-ctrl");
|
|
125
|
+
control.classList.add("maplibregl-ctrl-group");
|
|
126
|
+
const input = new OrMwcInput();
|
|
127
|
+
input.type = InputType.TEXT;
|
|
128
|
+
input.outlined = true;
|
|
129
|
+
input.compact = true;
|
|
130
|
+
input.readonly = this._readonly;
|
|
131
|
+
input.icon = "crosshairs-gps";
|
|
132
|
+
input.value = this._value;
|
|
133
|
+
input.pattern = CoordinatesRegexPattern;
|
|
134
|
+
input.onkeyup = getCoordinatesInputKeyHandler(this._valueChangedHandler);
|
|
135
|
+
control.appendChild(input);
|
|
136
|
+
this.elem = control;
|
|
137
|
+
this.input = input;
|
|
138
|
+
return control;
|
|
139
|
+
}
|
|
140
|
+
onRemove(map) {
|
|
141
|
+
this.map = undefined;
|
|
142
|
+
this.elem = undefined;
|
|
143
|
+
}
|
|
144
|
+
set readonly(readonly) {
|
|
145
|
+
this._readonly = readonly;
|
|
146
|
+
if (this.input) {
|
|
147
|
+
this.input.readonly = readonly;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
set value(value) {
|
|
151
|
+
this._value = value;
|
|
152
|
+
if (this.input) {
|
|
153
|
+
this.input.value = value;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
export const geoJsonPointInputTemplateProvider = (assetDescriptor, valueHolder, valueHolderDescriptor, valueDescriptor, valueChangeNotifier, options) => {
|
|
158
|
+
const disabled = !!(options && options.disabled);
|
|
159
|
+
const readonly = !!(options && options.readonly);
|
|
160
|
+
const compact = !!(options && options.compact);
|
|
161
|
+
const comfortable = !!(options && options.comfortable);
|
|
162
|
+
const centerControl = new CenterControl();
|
|
163
|
+
const valueChangeHandler = (value) => {
|
|
164
|
+
if (!valueChangeNotifier) {
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
if (value !== undefined) {
|
|
168
|
+
valueChangeNotifier({
|
|
169
|
+
value: value ? Util.getGeoJSONPoint(value) : null
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
else {
|
|
173
|
+
valueChangeNotifier(undefined);
|
|
174
|
+
}
|
|
175
|
+
};
|
|
176
|
+
const coordinatesControl = new CoordinatesControl(disabled, valueChangeHandler);
|
|
177
|
+
let pos;
|
|
178
|
+
const templateFunction = (value, focused, loading, sending, error, helperText) => {
|
|
179
|
+
let center;
|
|
180
|
+
if (value) {
|
|
181
|
+
pos = Util.getLngLat(value);
|
|
182
|
+
center = pos ? Object.values(pos) : undefined;
|
|
183
|
+
}
|
|
184
|
+
const centerStr = center ? center.join(", ") : undefined;
|
|
185
|
+
centerControl.pos = pos || undefined;
|
|
186
|
+
coordinatesControl.readonly = disabled || readonly || sending || loading;
|
|
187
|
+
coordinatesControl.value = centerStr;
|
|
188
|
+
const iconAndColor = getMarkerIconAndColorFromAssetType(assetDescriptor);
|
|
189
|
+
let dialog;
|
|
190
|
+
const setPos = (lngLat) => {
|
|
191
|
+
if (readonly || disabled) {
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
194
|
+
pos = lngLat ? Util.getLngLat(lngLat) : null;
|
|
195
|
+
if (dialog) {
|
|
196
|
+
// We're in compact mode modal
|
|
197
|
+
const marker = dialog.shadowRoot.getElementById("geo-json-point-marker");
|
|
198
|
+
marker.lng = pos ? pos.lng : undefined;
|
|
199
|
+
marker.lat = pos ? pos.lat : undefined;
|
|
200
|
+
center = pos ? Object.values(pos) : undefined;
|
|
201
|
+
const centerStr = center ? center.join(", ") : undefined;
|
|
202
|
+
coordinatesControl.value = centerStr;
|
|
203
|
+
}
|
|
204
|
+
else {
|
|
205
|
+
valueChangeHandler(pos);
|
|
206
|
+
}
|
|
207
|
+
};
|
|
208
|
+
const controls = [[centerControl, "bottom-left"], [coordinatesControl, "top-right"]];
|
|
209
|
+
if (!readonly) {
|
|
210
|
+
const userLocationControl = new GeolocateControl({
|
|
211
|
+
positionOptions: {
|
|
212
|
+
enableHighAccuracy: true
|
|
213
|
+
},
|
|
214
|
+
showAccuracyCircle: false,
|
|
215
|
+
showUserLocation: false
|
|
216
|
+
});
|
|
217
|
+
userLocationControl.on('geolocate', (currentLocation) => {
|
|
218
|
+
setPos(new LngLat(currentLocation.coords.longitude, currentLocation.coords.latitude));
|
|
219
|
+
});
|
|
220
|
+
userLocationControl.on('outofmaxbounds', (currentLocation) => {
|
|
221
|
+
setPos(new LngLat(currentLocation.coords.longitude, currentLocation.coords.latitude));
|
|
222
|
+
});
|
|
223
|
+
controls.push([userLocationControl, "bottom-left"]);
|
|
224
|
+
}
|
|
225
|
+
let content = html `
|
|
226
|
+
<or-map id="geo-json-point-map" class="or-map" @or-map-long-press="${(ev) => { setPos(ev.detail.lngLat); }}" .center="${center}" .controls="${controls}" .showGeoCodingControl=${!readonly}>
|
|
227
|
+
<or-map-marker id="geo-json-point-marker" active .lng="${pos ? pos.lng : undefined}" .lat="${pos ? pos.lat : undefined}" .icon="${iconAndColor ? iconAndColor.icon : undefined}" .activeColor="${iconAndColor ? "#" + iconAndColor.color : undefined}" .colour="${iconAndColor ? "#" + iconAndColor.color : undefined}"></or-map-marker>
|
|
228
|
+
</or-map>
|
|
229
|
+
<span class="long-press-msg">${i18next.t('longPressSetLoc')}</span>
|
|
230
|
+
`;
|
|
231
|
+
if (compact) {
|
|
232
|
+
const mapContent = content;
|
|
233
|
+
const onClick = () => {
|
|
234
|
+
dialog = showDialog(new OrMwcDialog()
|
|
235
|
+
.setContent(mapContent)
|
|
236
|
+
.setStyles(html `
|
|
237
|
+
<style>
|
|
238
|
+
.dialog-container {
|
|
239
|
+
flex-direction: column !important;
|
|
240
|
+
}
|
|
241
|
+
.dialog-container .long-press-msg {
|
|
242
|
+
display: block;
|
|
243
|
+
text-align: center;
|
|
244
|
+
}
|
|
245
|
+
or-map {
|
|
246
|
+
width: 600px !important;
|
|
247
|
+
min-height: 600px !important;
|
|
248
|
+
}
|
|
249
|
+
</style>
|
|
250
|
+
`)
|
|
251
|
+
.setActions([
|
|
252
|
+
{
|
|
253
|
+
actionName: "none",
|
|
254
|
+
content: "none",
|
|
255
|
+
action: () => {
|
|
256
|
+
setPos(null);
|
|
257
|
+
valueChangeHandler(pos);
|
|
258
|
+
}
|
|
259
|
+
},
|
|
260
|
+
{
|
|
261
|
+
actionName: "ok",
|
|
262
|
+
content: "ok",
|
|
263
|
+
action: () => {
|
|
264
|
+
valueChangeHandler(pos);
|
|
265
|
+
}
|
|
266
|
+
},
|
|
267
|
+
{
|
|
268
|
+
default: true,
|
|
269
|
+
actionName: "cancel",
|
|
270
|
+
content: "cancel"
|
|
10
271
|
}
|
|
11
|
-
|
|
12
|
-
|
|
272
|
+
]));
|
|
273
|
+
};
|
|
274
|
+
content = html `
|
|
275
|
+
<style>
|
|
276
|
+
#geo-json-point-input-compact-wrapper {
|
|
277
|
+
display: table-cell;
|
|
278
|
+
}
|
|
279
|
+
#geo-json-point-input-compact-wrapper > * {
|
|
280
|
+
vertical-align: middle;
|
|
281
|
+
}
|
|
282
|
+
</style>
|
|
283
|
+
<div id="geo-json-point-input-compact-wrapper">
|
|
284
|
+
<or-mwc-input style="width: auto;" .comfortable="${comfortable}" .type="${InputType.TEXT}" .value="${centerStr}" .pattern="${CoordinatesRegexPattern}" @keyup="${(e) => getCoordinatesInputKeyHandler(valueChangeHandler)(e)}"></or-mwc-input>
|
|
285
|
+
<or-mwc-input style="width: auto;" .type="${InputType.BUTTON}" compact icon="crosshairs-gps" @or-mwc-input-changed="${onClick}"></or-mwc-input>
|
|
286
|
+
</div>
|
|
287
|
+
`;
|
|
288
|
+
}
|
|
289
|
+
return content;
|
|
290
|
+
};
|
|
291
|
+
return {
|
|
292
|
+
templateFunction: templateFunction,
|
|
293
|
+
supportsHelperText: false,
|
|
294
|
+
supportsLabel: false,
|
|
295
|
+
supportsSendButton: false,
|
|
296
|
+
validator: () => !pos || (pos.lat !== undefined && pos.lat !== null && pos.lng !== undefined && pos.lng !== null)
|
|
297
|
+
};
|
|
298
|
+
};
|
|
299
|
+
let OrMap = class OrMap extends LitElement {
|
|
300
|
+
constructor() {
|
|
301
|
+
super();
|
|
302
|
+
this.type = manager.mapType;
|
|
303
|
+
this._markerStyles = [];
|
|
304
|
+
this.showGeoCodingControl = false;
|
|
305
|
+
this.showBoundaryBoxControl = false;
|
|
306
|
+
this.useZoomControl = true;
|
|
307
|
+
this.showGeoJson = true;
|
|
308
|
+
this.boundary = [];
|
|
309
|
+
this._loaded = false;
|
|
310
|
+
this._markers = [];
|
|
311
|
+
this.addEventListener(OrMapMarkerChangedEvent.NAME, this._onMarkerChangedEvent);
|
|
312
|
+
}
|
|
313
|
+
firstUpdated(_changedProperties) {
|
|
314
|
+
super.firstUpdated(_changedProperties);
|
|
315
|
+
if (manager.ready) {
|
|
316
|
+
this.loadMap();
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
get markers() {
|
|
320
|
+
return this._markers;
|
|
321
|
+
}
|
|
322
|
+
connectedCallback() {
|
|
323
|
+
super.connectedCallback();
|
|
324
|
+
}
|
|
325
|
+
disconnectedCallback() {
|
|
326
|
+
var _a;
|
|
327
|
+
super.disconnectedCallback();
|
|
328
|
+
if (this._observer) {
|
|
329
|
+
this._observer.disconnect();
|
|
330
|
+
}
|
|
331
|
+
if (this._resizeObserver) {
|
|
332
|
+
this._resizeObserver.disconnect();
|
|
333
|
+
}
|
|
334
|
+
// Clean up of internal resources associated with the map
|
|
335
|
+
(_a = this._map) === null || _a === void 0 ? void 0 : _a.unload();
|
|
336
|
+
}
|
|
337
|
+
render() {
|
|
338
|
+
return html `
|
|
339
|
+
<div id="container">
|
|
340
|
+
<div id="map"></div>
|
|
341
|
+
<slot></slot>
|
|
342
|
+
<a id="openremote" href="https://openremote.io/" target="_blank">
|
|
343
|
+
<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAQAAADZc7J/AAAABGdBTUEAAYagMeiWXwAAAAJiS0dEAP+Hj8y/AAAESUlEQVRIx5XVbWzdZRnH8c//f07POe36sK7SrYXZjYGzbBokOqd4QtKATdnMDFFSkoFzmWGRQOAFSoYnsBSzxBdmGsN4Y7LEFwZkUdHpDoja/AnJjBvp1sm2upW5PtAV+zBS+7Tz//tiLe0emPF+d9/39fvmunJf9+8K3HBF1drFzurVn5+5XkTwPwBNOt1s0pCjDnnT+Xzy/wOa5jaXnLLfLwzlF0WENwaYckyvUTHS1tnjl+6JFqk+JoMOqqy2JqjPVpXP1k7U1+Ty8paBPk97NX/pYwEdgZUetNkdlirDrHGnyv6y5r3lm4M2WVzwpJfz8XUBHTntnrJO6qqLWE9u/125zBNq0WebN/PXAjqq/cBOVWDasCEsd5MsmEzt/3xP+S6fwNsezPdfBejI6fCEDMa95oAT/t31pVxDQ6p6oy2WYSb18w0D2V3Klez2w3y8CNAR2G6vShxXUCxMkXLvS7Y6E/5+3emaJ92JqezzG+8M2nHW/flTi59xladU4phtfluYgnsDWUt8Nv7+8UfO73UUuenvDLxuCKu0RQt90BFo14wxzzpamD8uExtHSsu5HSP7XMCtZ5uTPyO0SdVCBlXahHjNG4WFrGY9Y4tXzODL7zb7NYJS64eHzWK92xYAa9yBKa8Wphf0xaQ4XOz0qF9JhMnXh//mIm4dnDSMOusWALepwQUnrm2t4pi9hrGyP+ccloxV6kOZFemoWi2mOpclaQycqGlt9R8XHS/GixinnVWvbDpjDEEpNpdnWrtd+HvZWzMQT9xjj1iXzUau6MPS9X9NKOeTmqzPpZWwfMkEKnza2ivimqxCKZjQa9BMmFI2D+gxibql4z7EiobYOSy1o7V6Xt1aYacGvD/7lse1+GZ9t0Zc8kHaGcOa1K6o+FePL1iy7K7wYHy70FZa9+qVWOm7tgslfpecKcy46GS0xXKM6g6d14VU+RfTnRJ8Y223w8j4tkMOOeR1j6nAMT8tzkCUcvlbn3ImbJn0RyWC+1af1Iv6ukcbf+aIRKDR3b5ipVCiy+PenaupWRsSfzCWim0ftUmdiqrJwWLpbmk3196UfXG0X6NKIWKDXva0I0UQZT2nRaDfc/mhgCj0PS9ImZzefbg5fliIvuTA++/0ZaYDTDqqpzhn6lHoW36iSuLHnslfCiBqdMBGDI6/0LUhfkgGiWFbC29c+epRaJMX3YJuD+R75l15wG4DaKh5dsPJsj0GXLaawavkWY/MyUcU/JOPHCkK7fAjNZiIf/PeX/vWx1814muF0Y/EKWs95mFVuKhgX352EYAoY5vnNSDRF/9p/MgHfQ2dldNIqbPeJm2aBBix20vzg26RpUUpLfb43FxZU4YMmEJGoxXKQeIfCg4uzMkrTDVitZ0ecst1B05i0Cv26Vk8H68JjFKabXa/Zkul5w5Lxp120EHdlyu/AQCiQI1P+YxaGcwY1+20kasnM/wXCa5/Ik1hKTEAAAAldEVYdGRhdGU6Y3JlYXRlADIwMTktMDgtMjBUMTU6MTc6NTUrMDA6MDCwJSdSAAAAJXRFWHRkYXRlOm1vZGlmeQAyMDE5LTA4LTIwVDE1OjE3OjU1KzAwOjAwwXif7gAAAABJRU5ErkJggg==" />
|
|
344
|
+
</a>
|
|
345
|
+
</div>
|
|
346
|
+
`;
|
|
347
|
+
}
|
|
348
|
+
updated(changedProperties) {
|
|
349
|
+
var _a;
|
|
350
|
+
super.updated(changedProperties);
|
|
351
|
+
if (changedProperties.has("center") || changedProperties.has("zoom")) {
|
|
352
|
+
this.flyTo(this.center, this.zoom);
|
|
353
|
+
}
|
|
354
|
+
if (changedProperties.has("boundary") && this.showBoundaryBoxControl) {
|
|
355
|
+
(_a = this._map) === null || _a === void 0 ? void 0 : _a.createBoundaryBox(this.boundary);
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
refresh() {
|
|
359
|
+
if (this._map) {
|
|
360
|
+
this._map.loadViewSettings().then(() => {
|
|
361
|
+
if (!this._map)
|
|
362
|
+
return;
|
|
363
|
+
this._map.setCenter();
|
|
364
|
+
this._map.flyTo();
|
|
365
|
+
});
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
loadMap() {
|
|
369
|
+
if (this._loaded) {
|
|
370
|
+
return;
|
|
371
|
+
}
|
|
372
|
+
if (this._mapContainer && this._slotElement) {
|
|
373
|
+
this._map = new MapWidget(this.type, this.shadowRoot, this._mapContainer, this.showGeoCodingControl, this.showBoundaryBoxControl, this.useZoomControl, this.showGeoJson)
|
|
374
|
+
.setCenter(this.center)
|
|
375
|
+
.setZoom(this.zoom)
|
|
376
|
+
.setControls(this.controls)
|
|
377
|
+
.setGeoJson(this.geoJson);
|
|
378
|
+
this._map.load().then(() => {
|
|
379
|
+
var _a, _b;
|
|
380
|
+
// Get markers from slot
|
|
381
|
+
this._observer = new FlattenedNodesObserver(this._slotElement, (info) => {
|
|
382
|
+
this._processNewMarkers(info.addedNodes);
|
|
383
|
+
this._processRemovedMarkers(info.removedNodes);
|
|
384
|
+
});
|
|
385
|
+
(_a = this._resizeObserver) === null || _a === void 0 ? void 0 : _a.disconnect();
|
|
386
|
+
this._resizeObserver = new ResizeObserver(debounce(() => {
|
|
387
|
+
this.resize();
|
|
388
|
+
}, 200));
|
|
389
|
+
var container = (_b = this._mapContainer) === null || _b === void 0 ? void 0 : _b.parentElement;
|
|
390
|
+
if (container) {
|
|
391
|
+
this._resizeObserver.observe(container);
|
|
392
|
+
}
|
|
393
|
+
});
|
|
394
|
+
}
|
|
395
|
+
this._loaded = true;
|
|
396
|
+
}
|
|
397
|
+
resize() {
|
|
398
|
+
if (this._map) {
|
|
399
|
+
this._map.resize();
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
flyTo(coordinates, zoom) {
|
|
403
|
+
if (this._map) {
|
|
404
|
+
this._map.flyTo(coordinates, zoom);
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
_onMarkerChangedEvent(evt) {
|
|
408
|
+
if (this._map) {
|
|
409
|
+
this._map.onMarkerChanged(evt.detail.marker, evt.detail.property);
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
_processNewMarkers(nodes) {
|
|
413
|
+
nodes.forEach((node) => {
|
|
414
|
+
if (!this._map) {
|
|
415
|
+
return;
|
|
416
|
+
}
|
|
417
|
+
if (node instanceof OrMapMarker) {
|
|
418
|
+
this._markers.push(node);
|
|
419
|
+
// Add styles of marker class to the shadow root if not already added
|
|
420
|
+
const className = node.constructor.name;
|
|
421
|
+
if (this._markerStyles.indexOf(className) < 0) {
|
|
422
|
+
const styles = node.constructor.styles;
|
|
423
|
+
let stylesArr = [];
|
|
424
|
+
if (styles) {
|
|
425
|
+
if (!Array.isArray(styles)) {
|
|
426
|
+
stylesArr.push(styles);
|
|
427
|
+
}
|
|
428
|
+
else {
|
|
429
|
+
stylesArr = styles;
|
|
430
|
+
}
|
|
431
|
+
stylesArr.forEach((styleItem) => {
|
|
432
|
+
const styleElem = document.createElement("style");
|
|
433
|
+
styleElem.textContent = String(styleItem.toString());
|
|
434
|
+
if (this._mapContainer.children.length > 0) {
|
|
435
|
+
this._mapContainer.insertBefore(styleElem, this._mapContainer.children[0]);
|
|
436
|
+
}
|
|
437
|
+
else {
|
|
438
|
+
this._mapContainer.appendChild(styleElem);
|
|
439
|
+
}
|
|
440
|
+
});
|
|
13
441
|
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
442
|
+
this._markerStyles.push(className);
|
|
443
|
+
}
|
|
444
|
+
this._map.addMarker(node);
|
|
445
|
+
}
|
|
446
|
+
});
|
|
447
|
+
}
|
|
448
|
+
_processRemovedMarkers(nodes) {
|
|
449
|
+
nodes.forEach((node) => {
|
|
450
|
+
if (!this._map) {
|
|
451
|
+
return;
|
|
452
|
+
}
|
|
453
|
+
if (node instanceof OrMapMarker) {
|
|
454
|
+
const i = this._markers.indexOf(node);
|
|
455
|
+
if (i >= 0) {
|
|
456
|
+
this._markers.splice(i, 1);
|
|
457
|
+
}
|
|
458
|
+
this._map.removeMarker(node);
|
|
459
|
+
}
|
|
460
|
+
});
|
|
461
|
+
}
|
|
462
|
+
};
|
|
463
|
+
OrMap.styles = style;
|
|
464
|
+
__decorate([
|
|
465
|
+
property({ type: String })
|
|
466
|
+
], OrMap.prototype, "type", void 0);
|
|
467
|
+
__decorate([
|
|
468
|
+
property({ type: String, converter: {
|
|
469
|
+
fromAttribute(value, type) {
|
|
470
|
+
if (!value) {
|
|
471
|
+
return;
|
|
472
|
+
}
|
|
473
|
+
const coords = value.split(",");
|
|
474
|
+
if (coords.length !== 2) {
|
|
475
|
+
return;
|
|
476
|
+
}
|
|
477
|
+
const lng = Number(coords[0]);
|
|
478
|
+
const lat = Number(coords[1]);
|
|
479
|
+
return new LngLat(lng, lat);
|
|
480
|
+
},
|
|
481
|
+
toAttribute(value, type) {
|
|
482
|
+
const lngLat = Util.getLngLat(value);
|
|
483
|
+
if (!lngLat) {
|
|
484
|
+
return "";
|
|
485
|
+
}
|
|
486
|
+
return "" + lngLat.lng + "," + lngLat.lat;
|
|
487
|
+
}
|
|
488
|
+
} })
|
|
489
|
+
], OrMap.prototype, "center", void 0);
|
|
490
|
+
__decorate([
|
|
491
|
+
property({ type: Number })
|
|
492
|
+
], OrMap.prototype, "zoom", void 0);
|
|
493
|
+
__decorate([
|
|
494
|
+
property({ type: Boolean })
|
|
495
|
+
], OrMap.prototype, "showGeoCodingControl", void 0);
|
|
496
|
+
__decorate([
|
|
497
|
+
property({ type: Boolean })
|
|
498
|
+
], OrMap.prototype, "showBoundaryBoxControl", void 0);
|
|
499
|
+
__decorate([
|
|
500
|
+
property({ type: Boolean })
|
|
501
|
+
], OrMap.prototype, "useZoomControl", void 0);
|
|
502
|
+
__decorate([
|
|
503
|
+
property({ type: Object })
|
|
504
|
+
], OrMap.prototype, "geoJson", void 0);
|
|
505
|
+
__decorate([
|
|
506
|
+
property({ type: Boolean })
|
|
507
|
+
], OrMap.prototype, "showGeoJson", void 0);
|
|
508
|
+
__decorate([
|
|
509
|
+
property({ type: Array })
|
|
510
|
+
], OrMap.prototype, "boundary", void 0);
|
|
511
|
+
__decorate([
|
|
512
|
+
query("#map")
|
|
513
|
+
], OrMap.prototype, "_mapContainer", void 0);
|
|
514
|
+
__decorate([
|
|
515
|
+
query("slot")
|
|
516
|
+
], OrMap.prototype, "_slotElement", void 0);
|
|
517
|
+
OrMap = __decorate([
|
|
518
|
+
customElement("or-map")
|
|
519
|
+
], OrMap);
|
|
520
|
+
export { OrMap };
|
|
521
|
+
//# sourceMappingURL=index.js.map
|
package/lib/mapbox-url-utils.js
CHANGED
|
@@ -1 +1,66 @@
|
|
|
1
|
-
export function isMapboxURL(
|
|
1
|
+
export function isMapboxURL(url) {
|
|
2
|
+
return url.indexOf("mapbox:") === 0;
|
|
3
|
+
}
|
|
4
|
+
export function transformMapboxUrl(url, accessToken, resourceType) {
|
|
5
|
+
if (url.indexOf("/styles/") > -1 && url.indexOf("/sprite") === -1)
|
|
6
|
+
return { url: normalizeStyleURL(url, accessToken) };
|
|
7
|
+
if (url.indexOf("/sprites/") > -1)
|
|
8
|
+
return { url: normalizeSpriteURL(url, accessToken) };
|
|
9
|
+
if (url.indexOf("/fonts/") > -1)
|
|
10
|
+
return { url: normalizeGlyphsURL(url, accessToken) };
|
|
11
|
+
if (url.indexOf("/v4/") > -1)
|
|
12
|
+
return { url: normalizeSourceURL(url, accessToken) };
|
|
13
|
+
if (resourceType === "Source" /* ResourceType.Source */)
|
|
14
|
+
return { url: normalizeSourceURL(url, accessToken) };
|
|
15
|
+
}
|
|
16
|
+
function parseUrl(url) {
|
|
17
|
+
const urlRe = /^(\w+):\/\/([^/?]*)(\/[^?]+)?\??(.+)?/;
|
|
18
|
+
const parts = url.match(urlRe);
|
|
19
|
+
if (!parts) {
|
|
20
|
+
throw new Error("Unable to parse URL object");
|
|
21
|
+
}
|
|
22
|
+
return {
|
|
23
|
+
protocol: parts[1],
|
|
24
|
+
authority: parts[2],
|
|
25
|
+
path: parts[3] || "/",
|
|
26
|
+
params: parts[4] ? parts[4].split("&") : [],
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
function formatUrl(urlObject, accessToken) {
|
|
30
|
+
const apiUrlObject = parseUrl("https://api.mapbox.com");
|
|
31
|
+
urlObject.protocol = apiUrlObject.protocol;
|
|
32
|
+
urlObject.authority = apiUrlObject.authority;
|
|
33
|
+
urlObject.params.push(`access_token=${accessToken}`);
|
|
34
|
+
const params = urlObject.params.length ? `?${urlObject.params.join("&")}` : "";
|
|
35
|
+
return `${urlObject.protocol}://${urlObject.authority}${urlObject.path}${params}`;
|
|
36
|
+
}
|
|
37
|
+
function normalizeStyleURL(url, accessToken) {
|
|
38
|
+
const urlObject = parseUrl(url);
|
|
39
|
+
urlObject.path = `/styles/v1${urlObject.path}`;
|
|
40
|
+
return formatUrl(urlObject, accessToken);
|
|
41
|
+
}
|
|
42
|
+
function normalizeGlyphsURL(url, accessToken) {
|
|
43
|
+
const urlObject = parseUrl(url);
|
|
44
|
+
urlObject.path = `/fonts/v1${urlObject.path}`;
|
|
45
|
+
return formatUrl(urlObject, accessToken);
|
|
46
|
+
}
|
|
47
|
+
function normalizeSourceURL(url, accessToken) {
|
|
48
|
+
const urlObject = parseUrl(url);
|
|
49
|
+
urlObject.path = `/v4/${urlObject.authority}.json`;
|
|
50
|
+
urlObject.params.push("secure");
|
|
51
|
+
return formatUrl(urlObject, accessToken);
|
|
52
|
+
}
|
|
53
|
+
function normalizeSpriteURL(url, accessToken) {
|
|
54
|
+
const urlObject = parseUrl(url);
|
|
55
|
+
const path = urlObject.path.split(".");
|
|
56
|
+
let properPath = path[0];
|
|
57
|
+
const extension = path[1];
|
|
58
|
+
let format = "";
|
|
59
|
+
if (properPath.indexOf("@2x")) {
|
|
60
|
+
properPath = properPath.split("@2x")[0];
|
|
61
|
+
format = "@2x";
|
|
62
|
+
}
|
|
63
|
+
urlObject.path = `/styles/v1${properPath}/sprite${format}.${extension}`;
|
|
64
|
+
return formatUrl(urlObject, accessToken);
|
|
65
|
+
}
|
|
66
|
+
//# sourceMappingURL=mapbox-url-utils.js.map
|