@openremote/or-map 1.0.2-alpha → 1.2.0-snapshot.20240512154942

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.
Files changed (58) hide show
  1. package/@types/maplibre-gl-geocoder.d.ts +2 -0
  2. package/README.md +94 -27
  3. package/lib/index.d.ts +115 -0
  4. package/lib/index.js +41 -0
  5. package/lib/index.js.map +1 -0
  6. package/lib/mapwidget.d.ts +94 -0
  7. package/lib/mapwidget.js +1 -0
  8. package/lib/mapwidget.js.map +1 -0
  9. package/lib/markers/or-map-marker-asset.d.ts +78 -0
  10. package/lib/markers/or-map-marker-asset.js +1 -0
  11. package/lib/markers/or-map-marker-asset.js.map +1 -0
  12. package/{dist → lib}/markers/or-map-marker.d.ts +30 -19
  13. package/lib/markers/or-map-marker.js +70 -0
  14. package/lib/markers/or-map-marker.js.map +1 -0
  15. package/lib/or-map-asset-card.d.ts +70 -0
  16. package/lib/or-map-asset-card.js +18 -0
  17. package/lib/or-map-asset-card.js.map +1 -0
  18. package/lib/style.d.ts +4 -0
  19. package/lib/style.js +230 -0
  20. package/lib/style.js.map +1 -0
  21. package/lib/util.d.ts +19 -0
  22. package/lib/util.js +1 -0
  23. package/lib/util.js.map +1 -0
  24. package/package.json +28 -17
  25. package/@types/mapbox.js.d.ts +0 -139
  26. package/dist/index.d.ts +0 -41
  27. package/dist/index.js +0 -196
  28. package/dist/index.js.map +0 -1
  29. package/dist/mapwidget.d.ts +0 -31
  30. package/dist/mapwidget.js +0 -262
  31. package/dist/mapwidget.js.map +0 -1
  32. package/dist/markers/or-map-marker-asset.d.ts +0 -33
  33. package/dist/markers/or-map-marker-asset.js +0 -76
  34. package/dist/markers/or-map-marker-asset.js.map +0 -1
  35. package/dist/markers/or-map-marker.js +0 -247
  36. package/dist/markers/or-map-marker.js.map +0 -1
  37. package/dist/util.d.ts +0 -6
  38. package/dist/util.js +0 -53
  39. package/dist/util.js.map +0 -1
  40. package/src/index.d.ts +0 -27
  41. package/src/index.js +0 -121
  42. package/src/index.js.map +0 -1
  43. package/src/index.ts +0 -226
  44. package/src/mapwidget.d.ts +0 -21
  45. package/src/mapwidget.js +0 -164
  46. package/src/mapwidget.js.map +0 -1
  47. package/src/mapwidget.ts +0 -302
  48. package/src/markers/or-map-marker-asset.d.ts +0 -17
  49. package/src/markers/or-map-marker-asset.js +0 -87
  50. package/src/markers/or-map-marker-asset.js.map +0 -1
  51. package/src/markers/or-map-marker-asset.ts +0 -79
  52. package/src/markers/or-map-marker.d.ts +0 -23
  53. package/src/markers/or-map-marker.js +0 -125
  54. package/src/markers/or-map-marker.js.map +0 -1
  55. package/src/markers/or-map-marker.ts +0 -270
  56. package/src/util.ts +0 -64
  57. package/tsconfig.json +0 -15
  58. package/tsconfig.tsbuildinfo +0 -10143
package/dist/util.js DELETED
@@ -1,53 +0,0 @@
1
- import { LngLat, LngLatBounds } from "mapbox-gl";
2
- import L from "mapbox.js";
3
- export function getLngLat(lngLatLike) {
4
- if (lngLatLike) {
5
- if (lngLatLike instanceof LngLat) {
6
- return lngLatLike;
7
- }
8
- const obj = lngLatLike;
9
- if (obj.hasOwnProperty("lng")) {
10
- const lngLatObj = obj;
11
- return new LngLat(lngLatObj.lng, lngLatObj.lat);
12
- }
13
- if (obj.hasOwnProperty("lon")) {
14
- const lonLatObj = obj;
15
- return new LngLat(lonLatObj.lon, lonLatObj.lat);
16
- }
17
- const lonLatArr = obj;
18
- if (lonLatArr.length === 2) {
19
- return new LngLat(lonLatArr[0], lonLatArr[1]);
20
- }
21
- }
22
- }
23
- export function getLngLatBounds(lngLatBoundsLike) {
24
- if (lngLatBoundsLike) {
25
- if (lngLatBoundsLike instanceof LngLatBounds) {
26
- return lngLatBoundsLike;
27
- }
28
- const arr = lngLatBoundsLike;
29
- if (arr.length === 2) {
30
- const sw = getLngLat(arr[0]);
31
- const ne = getLngLat(arr[1]);
32
- if (sw && ne) {
33
- return new LngLatBounds(sw, ne);
34
- }
35
- }
36
- if (arr.length === 4) {
37
- return new LngLatBounds([arr[0], arr[1], arr[2], arr[3]]);
38
- }
39
- }
40
- }
41
- export function getLatLng(lngLatLike) {
42
- const lngLat = getLngLat(lngLatLike);
43
- if (lngLat) {
44
- return L.latLng(lngLat.lat, lngLat.lng);
45
- }
46
- }
47
- export function getLatLngBounds(lngLatBoundsLike) {
48
- const lngLatBounds = getLngLatBounds(lngLatBoundsLike);
49
- if (lngLatBounds) {
50
- return L.latLngBounds(getLatLng(lngLatBounds.getNorthEast()), getLatLng(lngLatBounds.getSouthWest()));
51
- }
52
- }
53
- //# sourceMappingURL=util.js.map
package/dist/util.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"util.js","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,MAAM,EAAE,YAAY,EAA+B,MAAM,WAAW,CAAC;AAC7E,OAAO,CAAyB,MAAM,WAAW,CAAC;AAElD,MAAM,UAAU,SAAS,CAAC,UAAuB;IAC7C,IAAI,UAAU,EAAE;QAEZ,IAAI,UAAU,YAAY,MAAM,EAAE;YAC9B,OAAO,UAAoB,CAAC;SAC/B;QAED,MAAM,GAAG,GAAG,UAAoB,CAAC;QAEjC,IAAI,GAAG,CAAC,cAAc,CAAC,KAAK,CAAC,EAAE;YAC3B,MAAM,SAAS,GAAG,GAAoC,CAAC;YACvD,OAAO,IAAI,MAAM,CAAC,SAAS,CAAC,GAAG,EAAE,SAAS,CAAC,GAAG,CAAC,CAAC;SACnD;QAED,IAAI,GAAG,CAAC,cAAc,CAAC,KAAK,CAAC,EAAE;YAC3B,MAAM,SAAS,GAAG,GAAoC,CAAC;YACvD,OAAO,IAAI,MAAM,CAAC,SAAS,CAAC,GAAG,EAAE,SAAS,CAAC,GAAG,CAAC,CAAC;SACnD;QACD,MAAM,SAAS,GAAG,GAAe,CAAC;QAElC,IAAI,SAAS,CAAC,MAAM,KAAK,CAAC,EAAE;YACxB,OAAO,IAAI,MAAM,CAAC,SAAS,CAA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C,YAAY,CAAC,YAAY,EAAE,CAAE,CAAC,CAAC;KAC3G;AACL,CAAC"}
package/src/index.d.ts DELETED
@@ -1,27 +0,0 @@
1
- import { EventCallback } from "@openremote/core";
2
- import { PolymerElement } from "@polymer/polymer";
3
- import { FlattenedNodesObserver } from '@polymer/polymer/lib/utils/flattened-nodes-observer.js';
4
- import { MapWidget } from "./mapwidget";
5
- export declare enum Type {
6
- VECTOR = "VECTOR",
7
- RASTER = "RASTER"
8
- }
9
- /**
10
- * `or-map`
11
- * Displays a map
12
- *
13
- */
14
- export declare class OrMap extends PolymerElement {
15
- protected _initCallback?: EventCallback;
16
- protected _map?: MapWidget;
17
- protected _loaded: boolean;
18
- protected _observer?: FlattenedNodesObserver;
19
- static readonly template: HTMLTemplateElement;
20
- type: Type;
21
- constructor();
22
- _processNewMarkers(nodes: Element[]): void;
23
- _processRemovedMarkers(nodes: Element[]): void;
24
- disconnectedCallback(): void;
25
- ready(): void;
26
- loadMap(): void;
27
- }
package/src/index.js DELETED
@@ -1,121 +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 openremote, { OREvent } from "@openremote/core";
8
- import { html, PolymerElement } from "@polymer/polymer";
9
- import { FlattenedNodesObserver } from '@polymer/polymer/lib/utils/flattened-nodes-observer.js';
10
- import { customElement, property } from '@polymer/decorators';
11
- import { OrMapMarker } from "./markers/or-map-marker";
12
- import { MapWidget } from "./mapwidget";
13
- export var Type;
14
- (function (Type) {
15
- Type["VECTOR"] = "VECTOR";
16
- Type["RASTER"] = "RASTER";
17
- })(Type || (Type = {}));
18
- /**
19
- * `or-map`
20
- * Displays a map
21
- *
22
- */
23
- let OrMap = class OrMap extends PolymerElement {
24
- constructor() {
25
- super();
26
- this._loaded = false;
27
- this.type = Type.VECTOR;
28
- }
29
- static get template() {
30
- return html `
31
- <style>
32
- :host {
33
- display: block;
34
- overflow: hidden;
35
- }
36
- #map {
37
- position: relative;
38
- width: 100%;
39
- height: 100%;
40
- }
41
- slot {
42
- display: none;
43
- }
44
- .marker {
45
- background-image: url('http://pngimg.com/uploads/smiley/smiley_PNG36233.png');
46
- position: absolute;
47
- width: 32px;
48
- height: 32px;
49
- background-size: 32px;
50
- }
51
- </style>
52
- <div id="map"></div>
53
- <slot id="markers-slot"></slot>
54
- `;
55
- }
56
- _processNewMarkers(nodes) {
57
- nodes.forEach((node) => {
58
- if (!this._map) {
59
- return;
60
- }
61
- if (node instanceof OrMapMarker) {
62
- node.map = this._map;
63
- }
64
- });
65
- }
66
- _processRemovedMarkers(nodes) {
67
- nodes.forEach((node) => {
68
- if (!this._map) {
69
- return;
70
- }
71
- if (node instanceof OrMapMarker) {
72
- node.map = undefined;
73
- }
74
- });
75
- }
76
- disconnectedCallback() {
77
- super.disconnectedCallback();
78
- this._observer.disconnect();
79
- }
80
- ready() {
81
- super.ready();
82
- if (!openremote.ready) {
83
- // Defer until openremote is initialised
84
- this._initCallback = (initEvent) => {
85
- if (initEvent === OREvent.READY) {
86
- this.loadMap();
87
- }
88
- };
89
- openremote.addListener(this._initCallback);
90
- }
91
- else {
92
- this.loadMap();
93
- }
94
- }
95
- loadMap() {
96
- if (this._loaded) {
97
- return;
98
- }
99
- if (this.shadowRoot) {
100
- const mapElement = this.shadowRoot.getElementById('map');
101
- this._map = new MapWidget(this.type, this.shadowRoot, mapElement);
102
- this._map.load().then(() => {
103
- // Get markers from slot
104
- let slotElement = this.shadowRoot.getElementById('markers-slot');
105
- this._observer = new FlattenedNodesObserver(slotElement, (info) => {
106
- this._processNewMarkers(info.addedNodes);
107
- this._processRemovedMarkers(info.removedNodes);
108
- });
109
- });
110
- }
111
- this._loaded = true;
112
- }
113
- };
114
- __decorate([
115
- property({ type: String })
116
- ], OrMap.prototype, "type", void 0);
117
- OrMap = __decorate([
118
- customElement('or-map')
119
- ], OrMap);
120
- export { OrMap };
121
- //# sourceMappingURL=index.js.map
package/src/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,UAAU,EAAE,EAAgB,OAAO,EAAC,MAAM,kBAAkB,CAAC;AACpE,OAAO,EAAC,IAAI,EAAE,cAAc,EAAC,MAAM,kBAAkB,CAAC;AACtD,OAAO,EAAE,sBAAsB,EAAE,MAAM,wDAAwD,CAAC;AAChG,OAAO,EAAC,aAAa,EAAE,QAAQ,EAAC,MAAM,qBAAqB,CAAC;AAC5D,OAAO,EAAC,WAAW,EAAC,MAAM,yBAAyB,CAAC;AAEpD,OAAO,EAAC,SAAS,EAAC,MAAM,aAAa,CAAC;AAEtC,MAAM,CAAN,IAAY,IAGX;AAHD,WAAY,IAAI;IACZ,yBAAiB,CAAA;IACjB,yBAAiB,CAAA;AACrB,CAAC,EAHW,IAAI,KAAJ,IAAI,QAGf;AAED;;;;GAIG;AAEH,IAAa,KAAK,GAAlB,MAAa,KAAM,SAAQ,cAAc;IAqCrC;QACI,KAAK,EAAE,CAAC;QAnCF,YAAO,GAAY,KAAK,CAAC;QAgCnC,SAAI,GAAS,IAAI,CAAC,MAAM,CAAC;IAIzB,CAAC;IAjCD,MAAM,KAAK,QAAQ;QACf,OAAO,IAAI,CAAA;;;;;;;;;;;;;;;;;;;;;;;;KAwBd,CAAC;IACF,CAAC;IASD,kBAAkB,CAAC,KAAiB;QAChC,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;YACnB,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE;gBACZ,OAAO;aACV;YAED,IAAG,IAAI,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C,GAAG,EAAE;gBACvB,wBAAwB;gBACxB,IAAI,WAAW,GAAG,IAAI,CAAC,UAAW,CAAC,cAAc,CAAC,cAAc,CAAC,CAAC;gBAClE,IAAI,CAAC,SAAS,GAAG,IAAI,sBAAsB,CAAC,WAAY,EAAE,CAAC,IAAI,EAAE,EAAE;oBAC/D,IAAI,CAAC,kBAAkB,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;oBACzC,IAAI,CAAC,sBAAsB,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;gBACnD,CAAC,CAAC,CAAC;YACP,CAAC,CAAC,CAAC;SACN;QAED,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC;IACxB,CAAC;CACJ,CAAA;AA1EG;IADC,QAAQ,CAAC,EAAC,IAAI,EAAE,MAAM,EAAC,CAAC;mCACA;AAnChB,KAAK;IADjB,aAAa,CAAC,QAAQ,CAAC;GACX,KAAK,CA6GjB;SA7GY,KAAK"}
package/src/index.ts DELETED
@@ -1,226 +0,0 @@
1
- import openremote, {EventCallback, OREvent} from "@openremote/core";
2
- import {FlattenedNodesObserver} from "@polymer/polymer/lib/utils/flattened-nodes-observer.js";
3
- import {css, customElement, html, LitElement, property, query, PropertyValues, CSSResult} from "lit-element";
4
- import {LngLat, LngLatBoundsLike, LngLatLike} from "mapbox-gl";
5
- import {MapWidget} from "./mapwidget";
6
- import {
7
- OrMapMarker, OrMapMarkerEvent, OrMapMarkerChangedEvent, MarkerStyle
8
- } from "./markers/or-map-marker";
9
- import {getLngLat} from "./util";
10
-
11
- export enum Type {
12
- VECTOR = "VECTOR",
13
- RASTER = "RASTER"
14
- }
15
-
16
- export interface ViewSettings {
17
- "center": LngLatLike;
18
- "bounds": LngLatBoundsLike;
19
- "zoom": number;
20
- "maxZoom": number;
21
- "minZoom": number;
22
- "boxZoom": boolean;
23
- }
24
-
25
- @customElement("or-map")
26
- export class OrMap extends LitElement {
27
-
28
- public static styles = [
29
- MarkerStyle,
30
- css`
31
- :host {
32
- display: block;
33
- overflow: hidden;
34
- }
35
-
36
- #map {
37
- position: relative;
38
- width: 100%;
39
- height: 100%;
40
- }
41
-
42
- slot {
43
- display: none;
44
- }
45
-
46
- :host([hidden]) {
47
- display: none;
48
- }
49
-
50
- .leaflet-marker-icon, .mapboxgl-marker {
51
- pointer-events: none !important;
52
- }
53
- `];
54
-
55
- @property({type: String})
56
- public type: Type = Type.VECTOR;
57
-
58
- protected _markerStyles: string[] = [];
59
-
60
- @property({type: String, converter: {
61
- fromAttribute(value: string | null, type?: String): LngLatLike | undefined {
62
- if (!value) {
63
- return;
64
- }
65
-
66
- const coords = value.split(",");
67
- if (coords.length !== 2) {
68
- return;
69
- }
70
- const lng = Number(coords[0]);
71
- const lat = Number(coords[1]);
72
- return new LngLat(lng, lat);
73
- },
74
-
75
- toAttribute(value?: LngLatLike, type?: String): string {
76
- const lngLat = getLngLat(value);
77
-
78
- if (!lngLat) {
79
- return "";
80
- }
81
-
82
- return "" + lngLat.lng + "," + lngLat.lat;
83
- }
84
- }})
85
- public center?: LngLatLike;
86
-
87
- @property({type: Number})
88
- public zoom?: number;
89
-
90
- protected _initCallback?: EventCallback;
91
- protected _map?: MapWidget;
92
- protected _loaded: boolean = false;
93
- protected _observer?: FlattenedNodesObserver;
94
- protected _markers: OrMapMarker[] = [];
95
-
96
- @query("#map")
97
- protected _mapContainer?: HTMLElement;
98
-
99
- @query("slot")
100
- protected _slotElement?: HTMLSlotElement;
101
-
102
- constructor() {
103
- super();
104
- this.addEventListener(OrMapMarkerEvent.CHANGED, this._onMarkerChangedEvent);
105
- }
106
-
107
- public get markers(): OrMapMarker[] {
108
- return this._markers;
109
- }
110
-
111
- public disconnectedCallback() {
112
- super.disconnectedCallback();
113
- this._observer!.disconnect();
114
- }
115
-
116
- protected firstUpdated(_changedProperties: PropertyValues): void {
117
-
118
- if (!openremote.ready) {
119
- // Defer until openremote is initialised
120
- this._initCallback = (initEvent) => {
121
- if (initEvent === OREvent.READY) {
122
- this.loadMap();
123
-
124
- openremote.removeListener(this._initCallback!);
125
- }
126
- };
127
- openremote.addListener(this._initCallback);
128
- } else {
129
- this.loadMap();
130
- }
131
- }
132
-
133
- public loadMap() {
134
-
135
- if (this._loaded) {
136
- return;
137
- }
138
-
139
- if (this._mapContainer && this._slotElement) {
140
-
141
- this._map = new MapWidget(this.type, this.shadowRoot!, this._mapContainer)
142
- .setCenter(this.center)
143
- .setZoom(this.zoom);
144
- this._map.load().then(() => {
145
- // Get markers from slot
146
- this._observer = new FlattenedNodesObserver(this._slotElement!, (info: any) => {
147
- this._processNewMarkers(info.addedNodes);
148
- this._processRemovedMarkers(info.removedNodes);
149
- });
150
- });
151
- }
152
-
153
- this._loaded = true;
154
- }
155
-
156
- protected _onMarkerChangedEvent(evt: OrMapMarkerChangedEvent) {
157
- if (this._map) {
158
- this._map.onMarkerChanged(evt.detail.marker, evt.detail.property);
159
- }
160
- }
161
-
162
- protected _processNewMarkers(nodes: Element[]) {
163
- nodes.forEach((node) => {
164
- if (!this._map) {
165
- return;
166
- }
167
-
168
- if (node instanceof OrMapMarker) {
169
-
170
- this._markers.push(node);
171
-
172
- // Add styles of marker class to the shadow root if not already added
173
- const className = node.constructor.name;
174
- if (this._markerStyles.indexOf(className) < 0) {
175
- const styles = (node.constructor as any).styles;
176
- let stylesArr: CSSResult[] = [];
177
-
178
- if (styles) {
179
- if (!Array.isArray(styles)) {
180
- stylesArr.push(styles as CSSResult);
181
- } else {
182
- stylesArr = styles as CSSResult[];
183
- }
184
-
185
- stylesArr.forEach((styleItem) => {
186
- const styleElem = document.createElement("style");
187
- styleElem.textContent = styleItem.toString();
188
- if (this._mapContainer!.children.length > 0) {
189
- this._mapContainer!.insertBefore(styleElem, this._mapContainer!.children[0]);
190
- } else {
191
- this._mapContainer!.appendChild(styleElem);
192
- }
193
- })
194
- }
195
-
196
- this._markerStyles.push(className);
197
- }
198
-
199
- this._map.addMarker(node);
200
- }
201
- });
202
- }
203
-
204
- protected _processRemovedMarkers(nodes: Element[]) {
205
- nodes.forEach((node) => {
206
- if (!this._map) {
207
- return;
208
- }
209
-
210
- if (node instanceof OrMapMarker) {
211
- const i = this._markers.indexOf(node);
212
- if (i >= 0) {
213
- this._markers.splice(i, 1);
214
- }
215
- this._map.removeMarker(node);
216
- }
217
- });
218
- }
219
-
220
- protected render() {
221
- return html`
222
- <div id="map"></div>
223
- <slot></slot>
224
- `;
225
- }
226
- }
@@ -1,21 +0,0 @@
1
- import L, { Marker } from "mapbox.js";
2
- import { Type } from "./index";
3
- import { Map as MapGL, Marker as MarkerGL } from "mapbox-gl";
4
- import { OrMapMarker } from "./markers/or-map-marker";
5
- export declare class MapWidget {
6
- protected _mapJs?: L.mapbox.map;
7
- protected _mapGl?: MapGL;
8
- protected static _mapboxGlStyle?: any;
9
- protected static _mapboxJsStyle?: any;
10
- protected _type: Type;
11
- protected _styleParent: Node;
12
- protected _mapContainer: HTMLElement;
13
- protected _loaded: boolean;
14
- protected _markersJs?: Map<OrMapMarker, Marker>;
15
- protected _markersGl?: Map<OrMapMarker, MarkerGL>;
16
- constructor(type: Type, styleParent: Node, mapContainer: HTMLElement);
17
- load(): Promise<void>;
18
- addMarker(marker: OrMapMarker): void;
19
- removeMarker(marker: OrMapMarker): void;
20
- updateMarkerPosition(marker: OrMapMarker): void;
21
- }
package/src/mapwidget.js DELETED
@@ -1,164 +0,0 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- return new (P || (P = Promise))(function (resolve, reject) {
3
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
4
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
5
- function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
6
- step((generator = generator.apply(thisArg, _arguments || [])).next());
7
- });
8
- };
9
- import L from "mapbox.js";
10
- import { Type } from "./index";
11
- import rest from "@openremote/rest";
12
- import openremote from "@openremote/core";
13
- import { Marker as MarkerGL } from "mapbox-gl";
14
- export class MapWidget {
15
- constructor(type, styleParent, mapContainer) {
16
- this._loaded = false;
17
- this._type = type;
18
- this._styleParent = styleParent;
19
- this._mapContainer = mapContainer;
20
- switch (type) {
21
- case Type.RASTER:
22
- this._markersJs = new Map();
23
- break;
24
- case Type.VECTOR:
25
- this._markersGl = new Map();
26
- break;
27
- }
28
- }
29
- load() {
30
- return __awaiter(this, void 0, void 0, function* () {
31
- if (this._loaded) {
32
- return;
33
- }
34
- this._loaded = true;
35
- if (this._type === Type.RASTER) {
36
- if (!MapWidget._mapboxJsStyle) {
37
- // @ts-ignore
38
- MapWidget._mapboxJsStyle = yield import("mapbox.js/theme/style.css");
39
- }
40
- // Add style to shadow root
41
- var style = document.createElement('style');
42
- style.id = "mapboxJsStyle";
43
- style.textContent = MapWidget._mapboxJsStyle.default.toString();
44
- this._styleParent.appendChild(style);
45
- const settingsResponse = yield rest.api.MapResource.getSettingsJs();
46
- const settings = settingsResponse.data;
47
- // Load options for current realm or fallback to default if exist
48
- let settingOptions = settings.options ? settings.options[openremote.getRealm() || "default"] ? settings.options[openremote.getRealm() || "default"] : settings.options.default : null;
49
- let options;
50
- if (settingOptions) {
51
- options = {};
52
- // JS zoom is out by one compared to GL
53
- options.zoom = settingOptions.zoom ? settingOptions.zoom + 1 : undefined;
54
- options.maxZoom = settingOptions.maxZoom;
55
- options.minZoom = settingOptions.minZoom;
56
- options.boxZoom = settingOptions.boxZoom;
57
- // JS uses lat then lng unlike GL
58
- if (settingOptions.bounds) {
59
- let b = settingOptions.bounds;
60
- options.maxBounds = [
61
- [b[1], b[0]],
62
- [b[3], b[2]],
63
- ];
64
- }
65
- if (settingOptions.center) {
66
- let c = settingOptions.center;
67
- options.center = [
68
- c[1], c[0]
69
- ];
70
- }
71
- }
72
- this._mapJs = new L.mapbox.map(this._mapContainer, settings, options);
73
- if (options && options.maxBounds) {
74
- const minZoom = this._mapJs.getBoundsZoom(options.maxBounds, true);
75
- if (!options.minZoom || options.minZoom < minZoom) {
76
- this._mapJs.setMinZoom(minZoom);
77
- }
78
- }
79
- }
80
- else {
81
- if (!MapWidget._mapboxGlStyle) {
82
- // @ts-ignore
83
- MapWidget._mapboxGlStyle = yield import("mapbox-gl/dist/mapbox-gl.css");
84
- }
85
- // Add style to shadow root
86
- const style = document.createElement('style');
87
- style.id = "mapboxGlStyle";
88
- style.textContent = MapWidget._mapboxGlStyle.default.toString();
89
- this._styleParent.appendChild(style);
90
- const map = yield import("mapbox-gl");
91
- const settingsResponse = yield rest.api.MapResource.getSettings();
92
- const settings = settingsResponse.data;
93
- // Load options for current realm or fallback to default if exist
94
- let settingOptions = settings.options ? settings.options[openremote.getRealm() || "default"] ? settings.options[openremote.getRealm() || "default"] : settings.options.default : null;
95
- let options = {
96
- container: this._mapContainer,
97
- style: settings,
98
- attributionControl: true,
99
- transformRequest: (url, resourceType) => {
100
- return {
101
- url: url,
102
- headers: { 'Authorization': openremote.getAuthorizationHeader() }
103
- };
104
- }
105
- };
106
- if (settingOptions) {
107
- options.minZoom = settingOptions.minZoom;
108
- options.maxZoom = settingOptions.maxZoom;
109
- options.maxBounds = settingOptions.bounds;
110
- options.boxZoom = settingOptions.boxZoom;
111
- options.zoom = settingOptions.zoom;
112
- options.center = settingOptions.center;
113
- }
114
- this._mapGl = new map.Map(options);
115
- }
116
- });
117
- }
118
- addMarker(marker) {
119
- if (marker._ele) {
120
- switch (this._type) {
121
- case Type.RASTER:
122
- let icon = L.divIcon({ className: 'map-marker', html: marker._ele.outerHTML });
123
- let m = L.marker([marker.lat, marker.lng], { icon: icon });
124
- m.addTo(this._mapJs);
125
- if (marker._onClick) {
126
- m.on('click', marker._onClick);
127
- }
128
- this._markersJs.set(marker, m);
129
- break;
130
- case Type.VECTOR:
131
- new MarkerGL(marker._ele)
132
- .setLngLat([marker.lng, marker.lat])
133
- .addTo(this._mapGl);
134
- break;
135
- }
136
- }
137
- }
138
- removeMarker(marker) {
139
- switch (this._type) {
140
- case Type.RASTER:
141
- let m = this._markersJs.get(marker);
142
- if (m) {
143
- this._markersJs.delete(marker);
144
- m.removeFrom(this._mapJs);
145
- }
146
- break;
147
- case Type.VECTOR:
148
- break;
149
- }
150
- }
151
- updateMarkerPosition(marker) {
152
- switch (this._type) {
153
- case Type.RASTER:
154
- let m = this._markersJs.get(marker);
155
- if (m) {
156
- m.setLatLng([marker.lat, marker.lng]);
157
- }
158
- break;
159
- case Type.VECTOR:
160
- break;
161
- }
162
- }
163
- }
164
- //# sourceMappingURL=mapwidget.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"mapwidget.js","sourceRoot":"","sources":["mapwidget.ts"],"names":[],"mappings":";;;;;;;;AAAA,OAAO,CAAuB,MAAM,WAAW,CAAC;AAChD,OAAO,EAAC,IAAI,EAAC,MAAM,SAAS,CAAC;AAC7B,OAAO,IAAI,MAAM,kBAAkB,CAAC;AACpC,OAAO,UAAU,MAAM,kBAAkB,CAAC;AAC1C,OAAO,EAAoD,MAAM,IAAI,QAAQ,EAAC,MAAM,WAAW,CAAC;AAGhG,MAAM,OAAO,SAAS;IAYlB,YAAY,IAAU,EAAE,WAAiB,EAAE,YAAyB;QAJ1D,YAAO,GAAY,KAAK,CAAC;QAK/B,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;QAClB,IAAI,CAAC,YAAY,GAAG,WAAW,CAAC;QAChC,IAAI,CAAC,aAAa,GAAG,YAAY,CAAC;QAElC,QAAO,IAAI,EAAE;YACT,KAAK,IAAI,CAAC,MAAM;gBACZ,IAAI,CAAC,UAAU,GAAG,IAAI,GAAG,EAAuB,CAAC;gBACjD,MAAM;YACV,KAAK,IAAI,CAAC,MAAM;gBACZ,IAAI,CAAC,UAAU,GAAG,IAAI,GAAG,EAAyB,CAAC;gBACnD,MAAM;SACb;IACL,CAAC;IAEK,IAAI;;YACN,IAAI,IAAI,CAAC,OAAO,EAAE;gBACd,OAAO;aACV;YAED,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC;YAEpB,IAAI,IAAI,C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