@openremote/or-map 1.0.1-alpha → 1.2.0-snapshot.20240512160221
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 -0
- package/README.md +94 -27
- package/lib/index.d.ts +115 -0
- package/lib/index.js +41 -0
- package/lib/index.js.map +1 -0
- package/lib/mapwidget.d.ts +94 -0
- package/lib/mapwidget.js +1 -0
- package/lib/mapwidget.js.map +1 -0
- package/lib/markers/or-map-marker-asset.d.ts +78 -0
- package/lib/markers/or-map-marker-asset.js +1 -0
- package/lib/markers/or-map-marker-asset.js.map +1 -0
- package/{dist → lib}/markers/or-map-marker.d.ts +30 -19
- package/lib/markers/or-map-marker.js +70 -0
- package/lib/markers/or-map-marker.js.map +1 -0
- package/lib/or-map-asset-card.d.ts +70 -0
- package/lib/or-map-asset-card.js +18 -0
- package/lib/or-map-asset-card.js.map +1 -0
- package/lib/style.d.ts +4 -0
- package/lib/style.js +230 -0
- package/lib/style.js.map +1 -0
- package/lib/util.d.ts +19 -0
- package/lib/util.js +1 -0
- package/lib/util.js.map +1 -0
- package/package.json +28 -17
- package/@types/mapbox.js.d.ts +0 -139
- package/dist/index.d.ts +0 -41
- package/dist/index.js +0 -196
- package/dist/index.js.map +0 -1
- package/dist/mapwidget.d.ts +0 -31
- package/dist/mapwidget.js +0 -262
- package/dist/mapwidget.js.map +0 -1
- package/dist/markers/or-map-marker-asset.d.ts +0 -33
- package/dist/markers/or-map-marker-asset.js +0 -76
- package/dist/markers/or-map-marker-asset.js.map +0 -1
- package/dist/markers/or-map-marker.js +0 -247
- package/dist/markers/or-map-marker.js.map +0 -1
- package/dist/util.d.ts +0 -6
- package/dist/util.js +0 -53
- package/dist/util.js.map +0 -1
- package/src/index.d.ts +0 -27
- package/src/index.js +0 -121
- package/src/index.js.map +0 -1
- package/src/index.ts +0 -226
- package/src/mapwidget.d.ts +0 -21
- package/src/mapwidget.js +0 -164
- package/src/mapwidget.js.map +0 -1
- package/src/mapwidget.ts +0 -302
- package/src/markers/or-map-marker-asset.d.ts +0 -17
- package/src/markers/or-map-marker-asset.js +0 -87
- package/src/markers/or-map-marker-asset.js.map +0 -1
- package/src/markers/or-map-marker-asset.ts +0 -79
- package/src/markers/or-map-marker.d.ts +0 -23
- package/src/markers/or-map-marker.js +0 -125
- package/src/markers/or-map-marker.js.map +0 -1
- package/src/markers/or-map-marker.ts +0 -270
- package/src/util.ts +0 -64
- package/tsconfig.json +0 -15
- package/tsconfig.tsbuildinfo +0 -10143
package/src/mapwidget.ts
DELETED
|
@@ -1,302 +0,0 @@
|
|
|
1
|
-
import openremote from "@openremote/core";
|
|
2
|
-
import rest from "@openremote/rest";
|
|
3
|
-
import {LngLatLike, Map as MapGL, MapboxOptions as OptionsGL, Marker as MarkerGL, Style as StyleGL, LngLat, MapEventType,
|
|
4
|
-
MapMouseEvent} from "mapbox-gl";
|
|
5
|
-
import L, {Map as MapJS, MapOptions as OptionsJS, Marker as MarkerJS} from "mapbox.js";
|
|
6
|
-
import {Type, ViewSettings} from "./index";
|
|
7
|
-
import {OrMapMarker, OrMapMarkerClickedEvent} from "./markers/or-map-marker";
|
|
8
|
-
import {getLatLng, getLatLngBounds, getLngLat, getLngLatBounds} from "./util";
|
|
9
|
-
|
|
10
|
-
export class MapWidget {
|
|
11
|
-
protected static _mapboxGlStyle?: any;
|
|
12
|
-
protected static _mapboxJsStyle?: any;
|
|
13
|
-
protected _mapJs?: MapJS;
|
|
14
|
-
protected _mapGl?: MapGL;
|
|
15
|
-
protected _type: Type;
|
|
16
|
-
protected _styleParent: Node;
|
|
17
|
-
protected _mapContainer: HTMLElement;
|
|
18
|
-
protected _loaded: boolean = false;
|
|
19
|
-
protected _markersJs: Map<OrMapMarker, MarkerJS> = new Map();
|
|
20
|
-
protected _markersGl: Map<OrMapMarker, MarkerGL> = new Map();
|
|
21
|
-
protected _viewSettings?: ViewSettings;
|
|
22
|
-
protected _center?: LngLat;
|
|
23
|
-
protected _zoom?: number;
|
|
24
|
-
protected _clickHandlers: Map<OrMapMarker, (ev: MouseEvent) => void> = new Map();
|
|
25
|
-
|
|
26
|
-
constructor(type: Type, styleParent: Node, mapContainer: HTMLElement) {
|
|
27
|
-
this._type = type;
|
|
28
|
-
this._styleParent = styleParent;
|
|
29
|
-
this._mapContainer = mapContainer;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
public setCenter(center?: LngLatLike): this {
|
|
33
|
-
|
|
34
|
-
this._center = getLngLat(center);
|
|
35
|
-
|
|
36
|
-
switch (this._type) {
|
|
37
|
-
case Type.RASTER:
|
|
38
|
-
if (this._mapJs) {
|
|
39
|
-
const latLng = getLatLng(this._center) || (this._viewSettings ? getLatLng(this._viewSettings.center) : undefined);
|
|
40
|
-
if (latLng) {
|
|
41
|
-
this._mapJs.setView(latLng, undefined, {pan: {animate: false}, zoom: {animate: false}});
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
break;
|
|
45
|
-
case Type.VECTOR:
|
|
46
|
-
if (this._mapGl && this._center) {
|
|
47
|
-
this._mapGl.setCenter(this._center);
|
|
48
|
-
}
|
|
49
|
-
break;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
return this;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
public setZoom(zoom?: number): this {
|
|
56
|
-
|
|
57
|
-
this._zoom = zoom;
|
|
58
|
-
|
|
59
|
-
switch (this._type) {
|
|
60
|
-
case Type.RASTER:
|
|
61
|
-
if (this._mapJs && this._zoom) {
|
|
62
|
-
this._mapJs.setZoom(this._zoom, {animate: false});
|
|
63
|
-
}
|
|
64
|
-
break;
|
|
65
|
-
case Type.VECTOR:
|
|
66
|
-
if (this._mapGl && this._zoom) {
|
|
67
|
-
this._mapGl.setZoom(this._zoom);
|
|
68
|
-
}
|
|
69
|
-
break;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
return this;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
public async load(): Promise<void> {
|
|
76
|
-
if (this._loaded) {
|
|
77
|
-
return;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
if (this._type === Type.RASTER) {
|
|
81
|
-
|
|
82
|
-
if (!MapWidget._mapboxJsStyle) {
|
|
83
|
-
// @ts-ignore
|
|
84
|
-
MapWidget._mapboxJsStyle = await import(/* webpackChunkName: "mapbox-js-css" */ "mapbox.js/dist/mapbox.css");
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
// Add style to shadow root
|
|
88
|
-
const style = document.createElement("style");
|
|
89
|
-
style.id = "mapboxJsStyle";
|
|
90
|
-
style.textContent = MapWidget._mapboxJsStyle.default.toString();
|
|
91
|
-
this._styleParent.appendChild(style);
|
|
92
|
-
const settingsResponse = await rest.api.MapResource.getSettingsJs();
|
|
93
|
-
const settings = settingsResponse.data as any;
|
|
94
|
-
|
|
95
|
-
// Load options for current realm or fallback to default if exist
|
|
96
|
-
this._viewSettings = settings.options ? settings.options[openremote.getRealm() || "default"] ? settings.options[openremote.getRealm() || "default"] : settings.options.default : null;
|
|
97
|
-
let options: OptionsJS | undefined;
|
|
98
|
-
if (this._viewSettings) {
|
|
99
|
-
options = {};
|
|
100
|
-
|
|
101
|
-
// JS zoom is out compared to GL
|
|
102
|
-
options.zoom = this._viewSettings.zoom ? this._viewSettings.zoom + 1 : undefined;
|
|
103
|
-
options.maxZoom = this._viewSettings.maxZoom ? this._viewSettings.maxZoom - 1 : undefined;
|
|
104
|
-
options.minZoom = this._viewSettings.minZoom ? this._viewSettings.minZoom + 1 : undefined;
|
|
105
|
-
options.boxZoom = this._viewSettings.boxZoom;
|
|
106
|
-
|
|
107
|
-
// JS uses lat then lng unlike GL
|
|
108
|
-
if (this._viewSettings.bounds) {
|
|
109
|
-
options.maxBounds = getLatLngBounds(this._viewSettings.bounds);
|
|
110
|
-
}
|
|
111
|
-
if (this._viewSettings.center) {
|
|
112
|
-
options.center = getLatLng(this._viewSettings.center);
|
|
113
|
-
}
|
|
114
|
-
if (this._center) {
|
|
115
|
-
options.center = getLatLng(this._center);
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
this._mapJs = L.mapbox.map(this._mapContainer, settings, options);
|
|
120
|
-
|
|
121
|
-
if (options && options.maxBounds) {
|
|
122
|
-
const minZoom = this._mapJs.getBoundsZoom(options.maxBounds, true);
|
|
123
|
-
if (!options.minZoom || options.minZoom < minZoom) {
|
|
124
|
-
this._mapJs.setMinZoom(minZoom);
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
} else {
|
|
129
|
-
if (!MapWidget._mapboxGlStyle) {
|
|
130
|
-
// @ts-ignore
|
|
131
|
-
MapWidget._mapboxGlStyle = await import(/* webpackChunkName: "mapbox-gl-css" */ "mapbox-gl/dist/mapbox-gl.css");
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
// Add style to shadow root
|
|
135
|
-
const style = document.createElement("style");
|
|
136
|
-
style.id = "mapboxGlStyle";
|
|
137
|
-
style.textContent = MapWidget._mapboxGlStyle.default.toString();
|
|
138
|
-
this._styleParent.appendChild(style);
|
|
139
|
-
|
|
140
|
-
const map: typeof import("mapbox-gl") = await import(/* webpackChunkName: "mapbox-gl" */ "mapbox-gl");
|
|
141
|
-
const settingsResponse = await rest.api.MapResource.getSettings();
|
|
142
|
-
const settings = settingsResponse.data as any;
|
|
143
|
-
|
|
144
|
-
// Load options for current realm or fallback to default if exist
|
|
145
|
-
this._viewSettings = settings.options ? settings.options[openremote.getRealm() || "default"] ? settings.options[openremote.getRealm() || "default"] : settings.options.default : null;
|
|
146
|
-
const options: OptionsGL = {
|
|
147
|
-
attributionControl: true,
|
|
148
|
-
container: this._mapContainer,
|
|
149
|
-
style: settings as StyleGL,
|
|
150
|
-
transformRequest: (url, resourceType) => {
|
|
151
|
-
return {
|
|
152
|
-
headers: {Authorization: openremote.getAuthorizationHeader()},
|
|
153
|
-
url
|
|
154
|
-
};
|
|
155
|
-
}
|
|
156
|
-
};
|
|
157
|
-
|
|
158
|
-
if (this._viewSettings) {
|
|
159
|
-
options.minZoom = this._viewSettings.minZoom;
|
|
160
|
-
options.maxZoom = this._viewSettings.maxZoom;
|
|
161
|
-
options.maxBounds = this._viewSettings.bounds;
|
|
162
|
-
options.boxZoom = this._viewSettings.boxZoom;
|
|
163
|
-
options.zoom = this._viewSettings.zoom;
|
|
164
|
-
options.center = this._viewSettings.center;
|
|
165
|
-
}
|
|
166
|
-
if (this._center) {
|
|
167
|
-
options.center = this._center;
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
this._mapGl = new map.Map(options);
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
this._loaded = true;
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
public addMarker(marker: OrMapMarker) {
|
|
177
|
-
if (marker.lat && marker.lng) {
|
|
178
|
-
this._updateMarkerElement(marker, true);
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
public removeMarker(marker: OrMapMarker) {
|
|
183
|
-
this._updateMarkerElement(marker, false);
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
public onMarkerChanged(marker: OrMapMarker, prop: string) {
|
|
187
|
-
if (!this._loaded) {
|
|
188
|
-
return;
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
switch (prop) {
|
|
192
|
-
case "lat":
|
|
193
|
-
case "lng":
|
|
194
|
-
if (marker.lat && marker.lng) {
|
|
195
|
-
if (marker._actualMarkerElement) {
|
|
196
|
-
this._updateMarkerPosition(marker);
|
|
197
|
-
} else {
|
|
198
|
-
this._updateMarkerElement(marker, true);
|
|
199
|
-
}
|
|
200
|
-
} else if (marker._actualMarkerElement) {
|
|
201
|
-
this._updateMarkerElement(marker, false);
|
|
202
|
-
}
|
|
203
|
-
break;
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
protected _updateMarkerPosition(marker: OrMapMarker) {
|
|
208
|
-
switch (this._type) {
|
|
209
|
-
case Type.RASTER:
|
|
210
|
-
const m: MarkerJS | undefined = this._markersJs.get(marker);
|
|
211
|
-
if (m) {
|
|
212
|
-
m.setLatLng([marker.lat!, marker.lng!]);
|
|
213
|
-
}
|
|
214
|
-
break;
|
|
215
|
-
case Type.VECTOR:
|
|
216
|
-
const mGl: MarkerGL | undefined = this._markersGl.get(marker);
|
|
217
|
-
if (mGl) {
|
|
218
|
-
mGl.setLngLat([marker.lng!, marker.lat!]);
|
|
219
|
-
}
|
|
220
|
-
break;
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
protected _updateMarkerElement(marker: OrMapMarker, doAdd: boolean) {
|
|
225
|
-
|
|
226
|
-
switch (this._type) {
|
|
227
|
-
case Type.RASTER:
|
|
228
|
-
let m = this._markersJs.get(marker);
|
|
229
|
-
if (m) {
|
|
230
|
-
this._removeMarkerClickHandler(marker, marker.markerContainer as HTMLElement);
|
|
231
|
-
marker._actualMarkerElement = undefined;
|
|
232
|
-
m.removeFrom(this._mapJs!);
|
|
233
|
-
this._markersJs.delete(marker);
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
if (doAdd) {
|
|
237
|
-
const elem = marker._createMarkerElement();
|
|
238
|
-
if (elem) {
|
|
239
|
-
const icon = L.divIcon({html: elem.outerHTML, className: "or-marker-raster"});
|
|
240
|
-
m = L.marker([marker.lat!, marker.lng!], {icon: icon, clickable: marker.interactive});
|
|
241
|
-
m.addTo(this._mapJs!);
|
|
242
|
-
marker._actualMarkerElement = m.getElement() ? m.getElement().firstElementChild as HTMLDivElement : undefined;
|
|
243
|
-
if (marker.interactive) {
|
|
244
|
-
this._addMarkerClickHandler(marker, marker.markerContainer as HTMLElement);
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
this._markersJs.set(marker, m);
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
break;
|
|
251
|
-
case Type.VECTOR:
|
|
252
|
-
let mGl = this._markersGl.get(marker);
|
|
253
|
-
if (mGl) {
|
|
254
|
-
marker._actualMarkerElement = undefined;
|
|
255
|
-
this._removeMarkerClickHandler(marker, mGl.getElement());
|
|
256
|
-
mGl.remove();
|
|
257
|
-
this._markersGl.delete(marker);
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
if (doAdd) {
|
|
261
|
-
const elem = marker._createMarkerElement();
|
|
262
|
-
|
|
263
|
-
if (elem) {
|
|
264
|
-
mGl = new MarkerGL({
|
|
265
|
-
element: elem,
|
|
266
|
-
anchor: "top-left"
|
|
267
|
-
})
|
|
268
|
-
.setLngLat([marker.lng!, marker.lat!])
|
|
269
|
-
.addTo(this._mapGl!);
|
|
270
|
-
|
|
271
|
-
this._markersGl.set(marker, mGl);
|
|
272
|
-
|
|
273
|
-
marker._actualMarkerElement = mGl.getElement() as HTMLDivElement;
|
|
274
|
-
|
|
275
|
-
if (marker.interactive) {
|
|
276
|
-
this._addMarkerClickHandler(marker, mGl.getElement());
|
|
277
|
-
}
|
|
278
|
-
}
|
|
279
|
-
}
|
|
280
|
-
break;
|
|
281
|
-
}
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
protected _addMarkerClickHandler(marker: OrMapMarker, elem: HTMLElement) {
|
|
285
|
-
if (elem) {
|
|
286
|
-
const handler = (ev: MouseEvent) => {
|
|
287
|
-
ev.stopPropagation();
|
|
288
|
-
marker._onClick(ev);
|
|
289
|
-
};
|
|
290
|
-
this._clickHandlers.set(marker, handler);
|
|
291
|
-
elem.addEventListener("click", handler);
|
|
292
|
-
}
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
protected _removeMarkerClickHandler(marker: OrMapMarker, elem: HTMLElement) {
|
|
296
|
-
const handler = this._clickHandlers.get(marker);
|
|
297
|
-
if (handler && elem) {
|
|
298
|
-
elem.removeEventListener("click", handler);
|
|
299
|
-
this._clickHandlers.delete(marker);
|
|
300
|
-
}
|
|
301
|
-
}
|
|
302
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { OrMapMarker } from "./or-map-marker";
|
|
2
|
-
import { Asset } from "@openremote/model";
|
|
3
|
-
/**
|
|
4
|
-
* `or-map-marker-asset`
|
|
5
|
-
* Asset linked map marker
|
|
6
|
-
*/
|
|
7
|
-
export declare class OrMapMarkerAsset extends OrMapMarker {
|
|
8
|
-
asset?: string;
|
|
9
|
-
_ele: HTMLElement;
|
|
10
|
-
constructor();
|
|
11
|
-
_createMarkerElement(): HTMLElement;
|
|
12
|
-
refreshMarker(): void;
|
|
13
|
-
getAsset(): Promise<Asset>;
|
|
14
|
-
_assetChanged(): void;
|
|
15
|
-
_elementChanged(): void;
|
|
16
|
-
private _createAssetMarker;
|
|
17
|
-
}
|
|
@@ -1,87 +0,0 @@
|
|
|
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
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
8
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
9
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
10
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
11
|
-
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
|
|
12
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
13
|
-
});
|
|
14
|
-
};
|
|
15
|
-
import { customElement, property } from "@polymer/decorators";
|
|
16
|
-
import { OrMapMarker } from "./or-map-marker";
|
|
17
|
-
import rest from "@openremote/rest";
|
|
18
|
-
/**
|
|
19
|
-
* `or-map-marker-asset`
|
|
20
|
-
* Asset linked map marker
|
|
21
|
-
*/
|
|
22
|
-
let OrMapMarkerAsset = class OrMapMarkerAsset extends OrMapMarker {
|
|
23
|
-
constructor() {
|
|
24
|
-
super();
|
|
25
|
-
}
|
|
26
|
-
_createMarkerElement() {
|
|
27
|
-
let className = ("or-map-marker " + this.className).trim();
|
|
28
|
-
let ele = document.createElement("div");
|
|
29
|
-
ele.className = className;
|
|
30
|
-
return ele;
|
|
31
|
-
}
|
|
32
|
-
refreshMarker() {
|
|
33
|
-
this.getAsset().then((asset) => {
|
|
34
|
-
const attrs = asset.attributes;
|
|
35
|
-
const attr = attrs.location;
|
|
36
|
-
if (!attr) {
|
|
37
|
-
this.visible = false;
|
|
38
|
-
return;
|
|
39
|
-
}
|
|
40
|
-
const location = attr.value;
|
|
41
|
-
if (!location) {
|
|
42
|
-
this.visible = false;
|
|
43
|
-
return;
|
|
44
|
-
}
|
|
45
|
-
this._createAssetMarker();
|
|
46
|
-
// Model d.ts is clearly not perfect need to sort out Jackson annotations
|
|
47
|
-
this.lat = location.coordinates[1] || 0;
|
|
48
|
-
this.lng = location.coordinates[0] || 0;
|
|
49
|
-
this.visible = true;
|
|
50
|
-
}).catch(() => {
|
|
51
|
-
this.visible = false;
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
getAsset() {
|
|
55
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
56
|
-
const response = yield rest.api.AssetResource.get(this.asset);
|
|
57
|
-
return response.data;
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
_assetChanged() {
|
|
61
|
-
this.visible = false;
|
|
62
|
-
if (this.asset) {
|
|
63
|
-
this.refreshMarker();
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
_elementChanged() {
|
|
67
|
-
this._updateMarker();
|
|
68
|
-
}
|
|
69
|
-
_createAssetMarker() {
|
|
70
|
-
// Create basic element of _ele is undefined
|
|
71
|
-
if (typeof this._ele === 'undefined') {
|
|
72
|
-
this._ele = document.createElement("div");
|
|
73
|
-
this._ele.className = "marker";
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
};
|
|
77
|
-
__decorate([
|
|
78
|
-
property({ type: String, observer: "_assetChanged" })
|
|
79
|
-
], OrMapMarkerAsset.prototype, "asset", void 0);
|
|
80
|
-
__decorate([
|
|
81
|
-
property({ type: Object })
|
|
82
|
-
], OrMapMarkerAsset.prototype, "_ele", void 0);
|
|
83
|
-
OrMapMarkerAsset = __decorate([
|
|
84
|
-
customElement('or-map-marker-asset')
|
|
85
|
-
], OrMapMarkerAsset);
|
|
86
|
-
export { OrMapMarkerAsset };
|
|
87
|
-
//# sourceMappingURL=or-map-marker-asset.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"or-map-marker-asset.js","sourceRoot":"","sources":["or-map-marker-asset.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AACA,OAAO,EAAC,aAAa,EAAE,QAAQ,EAAU,MAAM,qBAAqB,CAAC;AACrE,OAAO,EAAC,WAAW,EAAC,MAAM,iBAAiB,CAAC;AAC5C,OAAO,IAAI,MAAM,kBAAkB,CAAC;AAIpC;;;GAGG;AAGH,IAAa,gBAAgB,GAA7B,MAAa,gBAAiB,SAAQ,WAAW;IAQ7C;QACI,KAAK,EAAE,CAAC;IACZ,CAAC;IAED,oBAAoB;QAChB,IAAI,SAAS,GAAG,CAAC,gBAAgB,GAAG,IAAI,CAAC,SAAS,CAAC,CAAC,IAAI,EAAE,CAAC;QAC3D,IAAI,GAAG,GAAG,QAAQ,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;QACxC,GAAG,CAAC,SAAS,GAAG,SAAS,CAAC;QAC1B,OAAO,GAAG,CAAC;IACf,CAAC;IAED,aAAa;QACT,IAAI,CAAC,QAAQ,EAAE,CAAC,IA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AI,CAAC,IAAI,GAAG,QAAQ,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;YAC1C,IAAI,CAAC,IAAI,CAAC,SAAS,GAAG,QAAQ,CAAC;SAClC;IACL,CAAC;CACJ,CAAA;AAlEG;IADC,QAAQ,CAAC,EAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,eAAe,EAAC,CAAC;+CACrC;AAGf;IADC,QAAQ,CAAC,EAAC,IAAI,EAAE,MAAM,EAAC,CAAC;8CACN;AANV,gBAAgB;IAD5B,aAAa,CAAC,qBAAqB,CAAC;GACxB,gBAAgB,CAqE5B;SArEY,gBAAgB"}
|
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
import {customElement, property, PropertyValues} from "lit-element";
|
|
2
|
-
import {OrMapMarker} from "./or-map-marker";
|
|
3
|
-
import {AttributeEvent, Attribute, AttributeType, GeoJSONPoint, AssetType, AssetEvent, AssetEventCause} from "@openremote/model";
|
|
4
|
-
import {subscribe} from "@openremote/core/dist/asset-mixin";
|
|
5
|
-
import openremote, {AssetModelUtil} from "@openremote/core";
|
|
6
|
-
|
|
7
|
-
@customElement("or-map-marker-asset")
|
|
8
|
-
export class OrMapMarkerAsset extends subscribe(openremote)(OrMapMarker) {
|
|
9
|
-
|
|
10
|
-
@property({type: String, reflect: true, attribute: true})
|
|
11
|
-
public asset?: string;
|
|
12
|
-
|
|
13
|
-
public assetTypeAsIcon: boolean = true;
|
|
14
|
-
|
|
15
|
-
constructor() {
|
|
16
|
-
super();
|
|
17
|
-
this.visible = false;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
protected set type(type: string | undefined) {
|
|
21
|
-
if (!type) {
|
|
22
|
-
this.visible = false;
|
|
23
|
-
return;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
if (this.assetTypeAsIcon) {
|
|
27
|
-
const descriptor = AssetModelUtil.getAssetDescriptor(type);
|
|
28
|
-
const icon = descriptor ? descriptor.icon : AssetType.THING.icon;
|
|
29
|
-
this.icon = icon;
|
|
30
|
-
}
|
|
31
|
-
this.visible = true;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
protected shouldUpdate(_changedProperties: PropertyValues): boolean {
|
|
35
|
-
if (_changedProperties.has("asset")) {
|
|
36
|
-
|
|
37
|
-
this.lat = undefined;
|
|
38
|
-
this.lng = undefined;
|
|
39
|
-
this.type = undefined;
|
|
40
|
-
this.assetIds = this.asset && this.asset.length > 0 ? [this.asset] : undefined;
|
|
41
|
-
|
|
42
|
-
if (Object.keys(_changedProperties).length === 1) {
|
|
43
|
-
return false;
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
return super.shouldUpdate(_changedProperties);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
public onAttributeEvent(event: AttributeEvent) {
|
|
50
|
-
if (event.attributeState!.attributeRef!.attributeName !== AttributeType.LOCATION.attributeName) {
|
|
51
|
-
return;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
this._updateLocation(event.attributeState!.value as GeoJSONPoint);
|
|
55
|
-
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
public onAssetEvent(event: AssetEvent) {
|
|
59
|
-
switch (event.cause) {
|
|
60
|
-
case AssetEventCause.READ:
|
|
61
|
-
const attr = event.asset && event.asset.attributes && event.asset.attributes.hasOwnProperty("location") ? event.asset.attributes.location as Attribute : null;
|
|
62
|
-
this._updateLocation(attr ? attr.value as GeoJSONPoint : null);
|
|
63
|
-
case AssetEventCause.CREATE:
|
|
64
|
-
case AssetEventCause.UPDATE:
|
|
65
|
-
this.type = event.asset!.type;
|
|
66
|
-
break;
|
|
67
|
-
case AssetEventCause.DELETE:
|
|
68
|
-
this.type = undefined;
|
|
69
|
-
this.lat = undefined;
|
|
70
|
-
this.lng = undefined;
|
|
71
|
-
break;
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
protected _updateLocation(location: GeoJSONPoint | null) {
|
|
76
|
-
this.lat = location && location.coordinates ? (location.coordinates as any)[1] : undefined;
|
|
77
|
-
this.lng = location && location.coordinates ? (location.coordinates as any)[0] : undefined;
|
|
78
|
-
}
|
|
79
|
-
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { PolymerElement } from "@polymer/polymer";
|
|
2
|
-
import { MapWidget } from "../mapwidget";
|
|
3
|
-
/**
|
|
4
|
-
* Base class for all map markers
|
|
5
|
-
*/
|
|
6
|
-
export declare class OrMapMarker extends PolymerElement {
|
|
7
|
-
protected _added: boolean;
|
|
8
|
-
protected _attached: boolean;
|
|
9
|
-
lat: number;
|
|
10
|
-
lng: number;
|
|
11
|
-
visible: boolean;
|
|
12
|
-
_ele: HTMLElement;
|
|
13
|
-
map?: MapWidget;
|
|
14
|
-
_slot: HTMLSlotElement;
|
|
15
|
-
static readonly template: HTMLTemplateElement;
|
|
16
|
-
connectedCallback(): void;
|
|
17
|
-
disconnectedCallback(): void;
|
|
18
|
-
_updateMarker(): void;
|
|
19
|
-
_addMarker(): void;
|
|
20
|
-
_removeMarker(): void;
|
|
21
|
-
_onClick(e: any): void;
|
|
22
|
-
_createMarkerElement(): HTMLElement;
|
|
23
|
-
}
|
|
@@ -1,125 +0,0 @@
|
|
|
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 { html, PolymerElement } from "@polymer/polymer";
|
|
8
|
-
import { property, query, observe, customElement } from "@polymer/decorators";
|
|
9
|
-
/**
|
|
10
|
-
* Base class for all map markers
|
|
11
|
-
*/
|
|
12
|
-
let OrMapMarker = class OrMapMarker extends PolymerElement {
|
|
13
|
-
/**
|
|
14
|
-
* Base class for all map markers
|
|
15
|
-
*/
|
|
16
|
-
constructor() {
|
|
17
|
-
super(...arguments);
|
|
18
|
-
this._added = false;
|
|
19
|
-
this._attached = false;
|
|
20
|
-
this.lat = 0;
|
|
21
|
-
this.lng = 0;
|
|
22
|
-
this.visible = true;
|
|
23
|
-
}
|
|
24
|
-
static get template() {
|
|
25
|
-
return html `
|
|
26
|
-
<style>
|
|
27
|
-
:host {
|
|
28
|
-
display: block;
|
|
29
|
-
overflow: hidden;
|
|
30
|
-
}
|
|
31
|
-
#map {
|
|
32
|
-
position: relative;
|
|
33
|
-
width: 100%;
|
|
34
|
-
height: 100%;
|
|
35
|
-
}
|
|
36
|
-
slot {
|
|
37
|
-
display: none;
|
|
38
|
-
}
|
|
39
|
-
</style>
|
|
40
|
-
<slot></slot>
|
|
41
|
-
`;
|
|
42
|
-
}
|
|
43
|
-
connectedCallback() {
|
|
44
|
-
super.connectedCallback();
|
|
45
|
-
this._attached = true;
|
|
46
|
-
this._ele = this._createMarkerElement();
|
|
47
|
-
}
|
|
48
|
-
disconnectedCallback() {
|
|
49
|
-
super.disconnectedCallback();
|
|
50
|
-
this._removeMarker();
|
|
51
|
-
this._attached = false;
|
|
52
|
-
}
|
|
53
|
-
_updateMarker() {
|
|
54
|
-
if (!this._attached || !this.map)
|
|
55
|
-
return;
|
|
56
|
-
if (!this._ele) {
|
|
57
|
-
this._ele = this._createMarkerElement();
|
|
58
|
-
}
|
|
59
|
-
if (!this._ele) {
|
|
60
|
-
return;
|
|
61
|
-
}
|
|
62
|
-
if (!this.visible) {
|
|
63
|
-
this._removeMarker();
|
|
64
|
-
}
|
|
65
|
-
else {
|
|
66
|
-
this._addMarker();
|
|
67
|
-
this.map.updateMarkerPosition(this);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
_addMarker() {
|
|
71
|
-
if (!this._added) {
|
|
72
|
-
this.map.addMarker(this);
|
|
73
|
-
this._added = true;
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
_removeMarker() {
|
|
77
|
-
if (this._added) {
|
|
78
|
-
this.map.removeMarker(this);
|
|
79
|
-
this._added = false;
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
//TODO make this optional?
|
|
83
|
-
_onClick(e) {
|
|
84
|
-
}
|
|
85
|
-
_createMarkerElement() {
|
|
86
|
-
let children = this._slot.assignedNodes({ flatten: true });
|
|
87
|
-
let len = children.length;
|
|
88
|
-
let className = ("or-map-marker " + this.className).trim();
|
|
89
|
-
let ele = document.createElement("div");
|
|
90
|
-
ele.className = className;
|
|
91
|
-
if (len > 0) {
|
|
92
|
-
// if more than 1 ele put inside wrapper
|
|
93
|
-
for (var i = 0; i < len; ++i) {
|
|
94
|
-
ele.appendChild(children[i]);
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
return ele;
|
|
98
|
-
}
|
|
99
|
-
};
|
|
100
|
-
__decorate([
|
|
101
|
-
property({ type: Number })
|
|
102
|
-
], OrMapMarker.prototype, "lat", void 0);
|
|
103
|
-
__decorate([
|
|
104
|
-
property({ type: Number })
|
|
105
|
-
], OrMapMarker.prototype, "lng", void 0);
|
|
106
|
-
__decorate([
|
|
107
|
-
property({ type: Boolean })
|
|
108
|
-
], OrMapMarker.prototype, "visible", void 0);
|
|
109
|
-
__decorate([
|
|
110
|
-
property({ type: Object })
|
|
111
|
-
], OrMapMarker.prototype, "_ele", void 0);
|
|
112
|
-
__decorate([
|
|
113
|
-
property({ type: Object })
|
|
114
|
-
], OrMapMarker.prototype, "map", void 0);
|
|
115
|
-
__decorate([
|
|
116
|
-
query("slot")
|
|
117
|
-
], OrMapMarker.prototype, "_slot", void 0);
|
|
118
|
-
__decorate([
|
|
119
|
-
observe("visible", "lat", "lng", "map")
|
|
120
|
-
], OrMapMarker.prototype, "_updateMarker", null);
|
|
121
|
-
OrMapMarker = __decorate([
|
|
122
|
-
customElement("or-map-marker")
|
|
123
|
-
], OrMapMarker);
|
|
124
|
-
export { OrMapMarker };
|
|
125
|
-
//# sourceMappingURL=or-map-marker.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"or-map-marker.js","sourceRoot":"","sources":["or-map-marker.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAC,IAAI,EAAE,cAAc,EAAC,MAAM,kBAAkB,CAAC;AACtD,OAAO,EAAC,QAAQ,EAAE,KAAK,EAAE,OAAO,EAAE,aAAa,EAAC,MAAM,qBAAqB,CAAC;AAG5E;;GAEG;AAEH,IAAa,WAAW,GAAxB,MAAa,WAAY,SAAQ,cAAc;IAJ/C;;OAEG;IACH;;QAEc,WAAM,GAAY,KAAK,CAAC;QACxB,cAAS,GAAY,KAAK,CAAC;QAGrC,QAAG,GAAW,CAAC,CAAC;QAGhB,QAAG,GAAW,CAAC,CAAC;QAGhB,YAAO,GAAY,IAAI,CAAC;IAgG5B,CAAC;IArFG,MAAM,KAAK,QAAQ;QACf,OAAO,IAAI,CAAA;;;;;;;;;;;;;;;;SAgBV,CAAC;IACN,CAAC;IAED,iBAAiB;QACb,KAAK,CAAC,iBAAiB,EAAE,CAAC;QAC1B,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC;QACtB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,oBAAoB,EAAE,CAAC;IAC5C,CAAC;IAED,oBAAoB;QAChB,KAAK,CAAC,oBAAoB,EAAE,CAAC;QAC7B,IAAI,CAAC,aAAa,EAAE,CAAC;QACrB,IAAI,CAAC,SAAS,GAAG,KAAK,CAAC;IAC3B,CAAC;IAGD,aAAa;QACT,IAAI,CAAC,IAAI,CAAC,SAAS,IAAI,CAAC,IAAI,CAAC,GAAG;YAAE,OAAO;QAEzC,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE;YACZ,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,oBAAoB,EAAE,C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