@openremote/or-map 1.8.0-snapshot.20250725120002 → 1.8.0-snapshot.20250728102340
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 +39 -519
- package/lib/mapbox-url-utils.js +1 -66
- package/lib/mapwidget.js +1 -885
- package/lib/markers/or-map-marker-asset.js +1 -178
- package/lib/markers/or-map-marker.js +80 -335
- package/lib/or-map-asset-card.js +18 -167
- package/lib/style.js +235 -242
- package/lib/util.js +1 -100
- package/package.json +8 -8
package/lib/index.js
CHANGED
|
@@ -1,521 +1,41 @@
|
|
|
1
|
-
var __decorate = (this && this.
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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"
|
|
1
|
+
var __decorate=this&&this.__decorate||function(e,t,o,r){var a,n=arguments.length,s=n<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,o):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(e,t,o,r);else for(var i=e.length-1;i>=0;i--)(a=e[i])&&(s=(n<3?a(s):n>3?a(t,o,s):a(t,o))||s);return n>3&&s&&Object.defineProperty(t,o,s),s};import e from"@openremote/core";import{FlattenedNodesObserver as t}from"@polymer/polymer/lib/utils/flattened-nodes-observer.js";import{html as o,LitElement as r}from"lit";import{customElement as a,property as n,query as s}from"lit/decorators.js";import{LngLat as i,GeolocateControl as l}from"maplibre-gl";import{MapWidget as p}from"./mapwidget";import{style as d}from"./style";import"./markers/or-map-marker";import"./markers/or-map-marker-asset";import{OrMapMarker as m,OrMapMarkerChangedEvent as c}from"./markers/or-map-marker";import*as h from"./util";import{InputType as u,OrMwcInput as v}from"@openremote/or-mwc-components/or-mwc-input";import{OrMwcDialog as g,showDialog as y}from"@openremote/or-mwc-components/or-mwc-dialog";import{getMarkerIconAndColorFromAssetType as f}from"./util";import{i18next as C}from"@openremote/or-translate";import{debounce as _}from"lodash";export*from"./markers/or-map-marker";export*from"./markers/or-map-marker-asset";export*from"./or-map-asset-card";export class OrMapLoadedEvent extends CustomEvent{constructor(){super(OrMapLoadedEvent.NAME,{bubbles:!0,composed:!0})}}OrMapLoadedEvent.NAME="or-map-loaded";export class OrMapClickedEvent extends CustomEvent{constructor(e,t=!1){super(OrMapClickedEvent.NAME,{detail:{doubleClick:t,lngLat:e},bubbles:!0,composed:!0})}}OrMapClickedEvent.NAME="or-map-clicked";export class OrMapLongPressEvent extends CustomEvent{constructor(e){super(OrMapLongPressEvent.NAME,{detail:{doubleClick:!1,lngLat:e},bubbles:!0,composed:!0})}}OrMapLongPressEvent.NAME="or-map-long-press";export class OrMapGeocoderChangeEvent extends CustomEvent{constructor(e){super(OrMapGeocoderChangeEvent.NAME,{detail:{geocode:e},bubbles:!0,composed:!0})}}OrMapGeocoderChangeEvent.NAME="or-map-geocoder-change";export class CenterControl{onAdd(e){this.map=e;let t=document.createElement("div");t.classList.add("maplibregl-ctrl"),t.classList.add("maplibregl-ctrl-group");let o=document.createElement("button");o.className="maplibregl-ctrl-compass",o.addEventListener("click",t=>e.flyTo({center:this.pos,zoom:e.getZoom()}));let r=document.createElement("span");return r.className="maplibregl-ctrl-icon",o.appendChild(r),t.appendChild(o),this.elem=t,t}onRemove(e){this.map=void 0,this.elem=void 0}}let CoordinatesRegexPattern="^[ ]*(?:Lat: )?(-?\\d+\\.?\\d*)[, ]+(?:Lng: )?(-?\\d+\\.?\\d*)[ ]*$";function getCoordinatesInputKeyHandler(e){return t=>{if("Enter"===t.code||"NumpadEnter"===t.code){let o=t.target.value,r=o?{}:void 0;if(o){let e=o.split(/[ ,]/).filter(e=>!!e);2===e.length&&(r=new i(Number.parseFloat(e[0]),Number.parseFloat(e[1])))}e(r)}}}export class CoordinatesControl{constructor(e=!1,t){this._readonly=!1,this._readonly=e,this._valueChangedHandler=t}onAdd(e){this.map=e;let t=document.createElement("div");t.classList.add("maplibregl-ctrl"),t.classList.add("maplibregl-ctrl-group");let o=new v;return o.type=u.TEXT,o.outlined=!0,o.compact=!0,o.readonly=this._readonly,o.icon="crosshairs-gps",o.value=this._value,o.pattern=CoordinatesRegexPattern,o.onkeyup=getCoordinatesInputKeyHandler(this._valueChangedHandler),t.appendChild(o),this.elem=t,this.input=o,t}onRemove(e){this.map=void 0,this.elem=void 0}set readonly(e){this._readonly=e,this.input&&(this.input.readonly=e)}set value(e){this._value=e,this.input&&(this.input.value=e)}}export const geoJsonPointInputTemplateProvider=(e,t,r,a,n,s)=>{let p,d=!!(s&&s.disabled),m=!!(s&&s.readonly),c=!!(s&&s.compact),v=!!(s&&s.comfortable),_=new CenterControl,b=e=>{n&&(void 0!==e?n({value:e?h.getGeoJSONPoint(e):null}):n(void 0))},A=new CoordinatesControl(d,b);return{templateFunction:(t,r,a,n,s,M)=>{let k,w;t&&(k=(p=h.getLngLat(t))?Object.values(p):void 0);let E=k?k.join(", "):void 0;_.pos=p||void 0,A.readonly=d||m||n||a,A.value=E;let O=f(e),x=e=>{if(!m&&!d)if(p=e?h.getLngLat(e):null,w){let e=w.shadowRoot.getElementById("geo-json-point-marker");e.lng=p?p.lng:void 0,e.lat=p?p.lat:void 0,A.value=(k=p?Object.values(p):void 0)?k.join(", "):void 0}else b(p)},z=[[_,"bottom-left"],[A,"top-right"]];if(!m){let e=new l({positionOptions:{enableHighAccuracy:!0},showAccuracyCircle:!1,showUserLocation:!1});e.on("geolocate",e=>{x(new i(e.coords.longitude,e.coords.latitude))}),e.on("outofmaxbounds",e=>{x(new i(e.coords.longitude,e.coords.latitude))}),z.push([e,"bottom-left"])}let N=o`
|
|
2
|
+
<or-map id="geo-json-point-map" class="or-map" @or-map-long-press="${e=>{x(e.detail.lngLat)}}" .center="${k}" .controls="${z}" .showGeoCodingControl=${!m}>
|
|
3
|
+
<or-map-marker id="geo-json-point-marker" active .lng="${p?p.lng:void 0}" .lat="${p?p.lat:void 0}" .icon="${O?O.icon:void 0}" .activeColor="${O?"#"+O.color:void 0}" .colour="${O?"#"+O.color:void 0}"></or-map-marker>
|
|
4
|
+
</or-map>
|
|
5
|
+
<span class="long-press-msg">${C.t("longPressSetLoc")}</span>
|
|
6
|
+
`;if(c){let e=N;N=o`
|
|
7
|
+
<style>
|
|
8
|
+
#geo-json-point-input-compact-wrapper {
|
|
9
|
+
display: table-cell;
|
|
271
10
|
}
|
|
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
|
-
});
|
|
11
|
+
#geo-json-point-input-compact-wrapper > * {
|
|
12
|
+
vertical-align: middle;
|
|
441
13
|
}
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
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
|
|
14
|
+
</style>
|
|
15
|
+
<div id="geo-json-point-input-compact-wrapper">
|
|
16
|
+
<or-mwc-input style="width: auto;" .comfortable="${v}" .type="${u.TEXT}" .value="${E}" .pattern="${CoordinatesRegexPattern}" @keyup="${e=>getCoordinatesInputKeyHandler(b)(e)}"></or-mwc-input>
|
|
17
|
+
<or-mwc-input style="width: auto;" .type="${u.BUTTON}" compact icon="crosshairs-gps" @or-mwc-input-changed="${()=>{w=y(new g().setContent(e).setStyles(o`
|
|
18
|
+
<style>
|
|
19
|
+
.dialog-container {
|
|
20
|
+
flex-direction: column !important;
|
|
21
|
+
}
|
|
22
|
+
.dialog-container .long-press-msg {
|
|
23
|
+
display: block;
|
|
24
|
+
text-align: center;
|
|
25
|
+
}
|
|
26
|
+
or-map {
|
|
27
|
+
width: 600px !important;
|
|
28
|
+
min-height: 600px !important;
|
|
29
|
+
}
|
|
30
|
+
</style>
|
|
31
|
+
`).setActions([{actionName:"none",content:"none",action:()=>{x(null),b(p)}},{actionName:"ok",content:"ok",action:()=>{b(p)}},{default:!0,actionName:"cancel",content:"cancel"}]))}}"></or-mwc-input>
|
|
32
|
+
</div>
|
|
33
|
+
`}return N},supportsHelperText:!1,supportsLabel:!1,supportsSendButton:!1,validator:()=>!p||void 0!==p.lat&&null!==p.lat&&void 0!==p.lng&&null!==p.lng}};let OrMap=class extends r{constructor(){super(),this.type=e.mapType,this._markerStyles=[],this.showGeoCodingControl=!1,this.showBoundaryBoxControl=!1,this.useZoomControl=!0,this.showGeoJson=!0,this.boundary=[],this._loaded=!1,this._markers=[],this.addEventListener(c.NAME,this._onMarkerChangedEvent)}firstUpdated(t){super.firstUpdated(t),e.ready&&this.loadMap()}get markers(){return this._markers}connectedCallback(){super.connectedCallback()}disconnectedCallback(){var e;super.disconnectedCallback(),this._observer&&this._observer.disconnect(),this._resizeObserver&&this._resizeObserver.disconnect(),null==(e=this._map)||e.unload()}render(){return o`
|
|
34
|
+
<div id="container">
|
|
35
|
+
<div id="map"></div>
|
|
36
|
+
<slot></slot>
|
|
37
|
+
<a id="openremote" href="https://openremote.io/" target="_blank">
|
|
38
|
+
<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==" />
|
|
39
|
+
</a>
|
|
40
|
+
</div>
|
|
41
|
+
`}updated(e){var t;super.updated(e),(e.has("center")||e.has("zoom"))&&this.flyTo(this.center,this.zoom),e.has("boundary")&&this.showBoundaryBoxControl&&(null==(t=this._map)||t.createBoundaryBox(this.boundary))}refresh(){this._map&&this._map.loadViewSettings().then(()=>{this._map&&(this._map.setCenter(),this._map.flyTo())})}loadMap(){this._loaded||(this._mapContainer&&this._slotElement&&(this._map=new p(this.type,this.shadowRoot,this._mapContainer,this.showGeoCodingControl,this.showBoundaryBoxControl,this.useZoomControl,this.showGeoJson).setCenter(this.center).setZoom(this.zoom).setControls(this.controls).setGeoJson(this.geoJson),this._map.load().then(()=>{this._observer=new t(this._slotElement,e=>{this._processNewMarkers(e.addedNodes),this._processRemovedMarkers(e.removedNodes)}),null==(e=this._resizeObserver)||e.disconnect(),this._resizeObserver=new ResizeObserver(_(()=>{this.resize()},200));var e,o,r=null==(o=this._mapContainer)?void 0:o.parentElement;r&&this._resizeObserver.observe(r)})),this._loaded=!0)}resize(){this._map&&this._map.resize()}flyTo(e,t){this._map&&this._map.flyTo(e,t)}_onMarkerChangedEvent(e){this._map&&this._map.onMarkerChanged(e.detail.marker,e.detail.property)}_processNewMarkers(e){e.forEach(e=>{if(this._map&&e instanceof m){this._markers.push(e);let t=e.constructor.name;if(0>this._markerStyles.indexOf(t)){let o=e.constructor.styles,r=[];o&&(Array.isArray(o)?r=o:r.push(o),r.forEach(e=>{let t=document.createElement("style");t.textContent=String(e.toString()),this._mapContainer.children.length>0?this._mapContainer.insertBefore(t,this._mapContainer.children[0]):this._mapContainer.appendChild(t)})),this._markerStyles.push(t)}this._map.addMarker(e)}})}_processRemovedMarkers(e){e.forEach(e=>{if(this._map&&e instanceof m){let t=this._markers.indexOf(e);t>=0&&this._markers.splice(t,1),this._map.removeMarker(e)}})}};OrMap.styles=d,__decorate([n({type:String})],OrMap.prototype,"type",void 0),__decorate([n({type:String,converter:{fromAttribute(e,t){if(!e)return;let o=e.split(",");if(2===o.length)return new i(Number(o[0]),Number(o[1]))},toAttribute(e,t){let o=h.getLngLat(e);return o?""+o.lng+","+o.lat:""}}})],OrMap.prototype,"center",void 0),__decorate([n({type:Number})],OrMap.prototype,"zoom",void 0),__decorate([n({type:Boolean})],OrMap.prototype,"showGeoCodingControl",void 0),__decorate([n({type:Boolean})],OrMap.prototype,"showBoundaryBoxControl",void 0),__decorate([n({type:Boolean})],OrMap.prototype,"useZoomControl",void 0),__decorate([n({type:Object})],OrMap.prototype,"geoJson",void 0),__decorate([n({type:Boolean})],OrMap.prototype,"showGeoJson",void 0),__decorate([n({type:Array})],OrMap.prototype,"boundary",void 0),__decorate([s("#map")],OrMap.prototype,"_mapContainer",void 0),__decorate([s("slot")],OrMap.prototype,"_slotElement",void 0),OrMap=__decorate([a("or-map")],OrMap);export{h as Util,OrMap};
|
package/lib/mapbox-url-utils.js
CHANGED
|
@@ -1,66 +1 @@
|
|
|
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
|
|
1
|
+
export function isMapboxURL(r){return 0===r.indexOf("mapbox:")}export function transformMapboxUrl(r,t,e){return r.indexOf("/styles/")>-1&&-1===r.indexOf("/sprite")?{url:normalizeStyleURL(r,t)}:r.indexOf("/sprites/")>-1?{url:normalizeSpriteURL(r,t)}:r.indexOf("/fonts/")>-1?{url:normalizeGlyphsURL(r,t)}:r.indexOf("/v4/")>-1||"Source"===e?{url:normalizeSourceURL(r,t)}:void 0}function parseUrl(r){let t=r.match(/^(\w+):\/\/([^/?]*)(\/[^?]+)?\??(.+)?/);if(!t)throw Error("Unable to parse URL object");return{protocol:t[1],authority:t[2],path:t[3]||"/",params:t[4]?t[4].split("&"):[]}}function formatUrl(r,t){let e=parseUrl("https://api.mapbox.com");r.protocol=e.protocol,r.authority=e.authority,r.params.push(`access_token=${t}`);let o=r.params.length?`?${r.params.join("&")}`:"";return`${r.protocol}://${r.authority}${r.path}${o}`}function normalizeStyleURL(r,t){let e=parseUrl(r);return e.path=`/styles/v1${e.path}`,formatUrl(e,t)}function normalizeGlyphsURL(r,t){let e=parseUrl(r);return e.path=`/fonts/v1${e.path}`,formatUrl(e,t)}function normalizeSourceURL(r,t){let e=parseUrl(r);return e.path=`/v4/${e.authority}.json`,e.params.push("secure"),formatUrl(e,t)}function normalizeSpriteURL(r,t){let e=parseUrl(r),o=e.path.split("."),a=o[0],l=o[1],n="";return a.indexOf("@2x")&&(a=a.split("@2x")[0],n="@2x"),e.path=`/styles/v1${a}/sprite${n}.${l}`,formatUrl(e,t)}
|