@openremote/or-map 1.0.2-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
|
@@ -1,270 +0,0 @@
|
|
|
1
|
-
import {css, customElement, LitElement, property, PropertyValues, query, html} from "lit-element";
|
|
2
|
-
import {Type} from "../index";
|
|
3
|
-
import {Marker as MarkerJS} from "mapbox.js";
|
|
4
|
-
|
|
5
|
-
export enum OrMapMarkerEvent {
|
|
6
|
-
CLICKED = "or-map-marker-clicked",
|
|
7
|
-
CHANGED = "or-map-marker-changed"
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
declare global {
|
|
11
|
-
export interface HTMLElementEventMap {
|
|
12
|
-
[OrMapMarkerEvent.CHANGED]: OrMapMarkerChangedEvent;
|
|
13
|
-
[OrMapMarkerEvent.CLICKED]: OrMapMarkerClickedEvent;
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export class OrMapMarkerChangedEvent extends CustomEvent<MarkerChangedEventDetail> {
|
|
18
|
-
|
|
19
|
-
constructor(marker: OrMapMarker, prop: string) {
|
|
20
|
-
super(OrMapMarkerEvent.CHANGED, {
|
|
21
|
-
detail: {
|
|
22
|
-
marker: marker,
|
|
23
|
-
property: prop
|
|
24
|
-
},
|
|
25
|
-
bubbles: true,
|
|
26
|
-
composed: true
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export class OrMapMarkerClickedEvent extends CustomEvent<MarkerEventDetail> {
|
|
32
|
-
|
|
33
|
-
constructor(marker: OrMapMarker) {
|
|
34
|
-
super(OrMapMarkerEvent.CLICKED, {
|
|
35
|
-
detail: {
|
|
36
|
-
marker: marker
|
|
37
|
-
},
|
|
38
|
-
bubbles: true,
|
|
39
|
-
composed: true
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
export interface MarkerEventDetail {
|
|
45
|
-
marker: OrMapMarker;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
export interface MarkerChangedEventDetail extends MarkerEventDetail {
|
|
49
|
-
property: string;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
export const MarkerStyle = css`
|
|
53
|
-
.or-map-marker {
|
|
54
|
-
position: absolute; /* This makes mapboxJS behave like mapboxGL */
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
.marker-container {
|
|
58
|
-
position: relative;
|
|
59
|
-
transform: var(--or-map-marker-transform, translate(-24px, -45px));
|
|
60
|
-
cursor: pointer;
|
|
61
|
-
--or-icon-width: var(--or-map-marker-width, 48px);
|
|
62
|
-
--or-icon-height: var(--or-map-marker-height, 48px);
|
|
63
|
-
--or-icon-fill-color: var(--or-map-marker-fill, #1D5632);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
.or-map-marker.interactive .marker-container {
|
|
67
|
-
pointer-events: all;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
.or-map-marker-default.interactive .marker-container {
|
|
71
|
-
pointer-events: none;
|
|
72
|
-
--or-icon-pointer-events: visible;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
.or-map-marker .marker-icon {
|
|
76
|
-
position: absolute;
|
|
77
|
-
left: 50%;
|
|
78
|
-
top: 50%;
|
|
79
|
-
z-index: 1000;
|
|
80
|
-
--or-icon-fill-color: var(--or-map-marker-icon-fill, #FFF);
|
|
81
|
-
--or-icon-width: var(--or-map-marker-icon-width, 24px);
|
|
82
|
-
--or-icon-height: var(--or-map-marker-icon-height, 24px);
|
|
83
|
-
transform: var(--or-map-marker-icon-transform, translate(-50%, -19px));
|
|
84
|
-
}
|
|
85
|
-
`;
|
|
86
|
-
|
|
87
|
-
/**
|
|
88
|
-
* Base class for all map markers.
|
|
89
|
-
*
|
|
90
|
-
* This component doesn't directly render anything instead it generates DOM that can be added to the map component
|
|
91
|
-
*/
|
|
92
|
-
@customElement("or-map-marker")
|
|
93
|
-
export class OrMapMarker extends LitElement {
|
|
94
|
-
|
|
95
|
-
protected static _defaultTemplate = (icon: string | undefined) => `
|
|
96
|
-
<or-icon icon="or:marker"></or-icon>
|
|
97
|
-
<or-icon class="marker-icon" icon="${icon || ""}"></or-icon>
|
|
98
|
-
`
|
|
99
|
-
|
|
100
|
-
@property({type: Number, reflect: true, attribute: true})
|
|
101
|
-
public lat?: number;
|
|
102
|
-
|
|
103
|
-
@property({type: Number, reflect: true})
|
|
104
|
-
public lng?: number;
|
|
105
|
-
|
|
106
|
-
@property({type: Boolean})
|
|
107
|
-
public visible: boolean = true;
|
|
108
|
-
|
|
109
|
-
@property({type: String})
|
|
110
|
-
public icon?: string;
|
|
111
|
-
|
|
112
|
-
@property({type: Boolean})
|
|
113
|
-
public interactive: boolean = true;
|
|
114
|
-
|
|
115
|
-
@property({type: Boolean})
|
|
116
|
-
active: boolean = false;
|
|
117
|
-
|
|
118
|
-
// This is the actual map marker element not the same element as returned from createMarkerElement when using raster map
|
|
119
|
-
public _actualMarkerElement?: HTMLDivElement;
|
|
120
|
-
|
|
121
|
-
@query("slot")
|
|
122
|
-
protected _slot?: HTMLSlotElement;
|
|
123
|
-
|
|
124
|
-
public get markerContainer(): HTMLDivElement | undefined {
|
|
125
|
-
if (this._actualMarkerElement) {
|
|
126
|
-
return this._actualMarkerElement.firstElementChild as HTMLDivElement;
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
public _onClick(e: MouseEvent) {
|
|
131
|
-
this.dispatchEvent(new OrMapMarkerClickedEvent(this));
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
public _createMarkerElement(): HTMLDivElement {
|
|
135
|
-
const markerElem = document.createElement("div");
|
|
136
|
-
const markerContainerElem = document.createElement("div");
|
|
137
|
-
markerElem.appendChild(markerContainerElem);
|
|
138
|
-
this.addMarkerClassNames(markerElem);
|
|
139
|
-
this.addMarkerContainerClassNames(markerContainerElem);
|
|
140
|
-
let content = this.createMarkerContent();
|
|
141
|
-
if (!content) {
|
|
142
|
-
// Append default marker
|
|
143
|
-
markerElem.classList.add("or-map-marker-default");
|
|
144
|
-
content = this.createDefaultMarkerContent();
|
|
145
|
-
}
|
|
146
|
-
markerContainerElem.appendChild(content);
|
|
147
|
-
this.updateInteractive(markerElem);
|
|
148
|
-
this.updateVisibility(markerElem);
|
|
149
|
-
this.updateActive(markerElem);
|
|
150
|
-
return markerElem;
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
/**
|
|
154
|
-
* Override in sub types to customise the look of the marker. If undefined returned then a default marker will
|
|
155
|
-
* be used instead.
|
|
156
|
-
*/
|
|
157
|
-
public createMarkerContent(): HTMLElement | undefined {
|
|
158
|
-
|
|
159
|
-
// Append child elements
|
|
160
|
-
let hasChildren = false;
|
|
161
|
-
let container = document.createElement("div");
|
|
162
|
-
|
|
163
|
-
if (this._slot) {
|
|
164
|
-
this._slot.assignedNodes({flatten: true}).forEach((child) => {
|
|
165
|
-
if (child instanceof HTMLElement) {
|
|
166
|
-
container.appendChild(child.cloneNode(true));
|
|
167
|
-
hasChildren = true;
|
|
168
|
-
}
|
|
169
|
-
});
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
if (!hasChildren) {
|
|
173
|
-
return;
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
return container;
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
protected shouldUpdate(_changedProperties: PropertyValues): boolean {
|
|
180
|
-
if (_changedProperties.has("icon")) {
|
|
181
|
-
this.refreshMarkerContent();
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
if (_changedProperties.has("visible")) {
|
|
185
|
-
this.updateVisibility(this._actualMarkerElement);
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
if (_changedProperties.has("interactive")) {
|
|
189
|
-
this.updateInteractive(this._actualMarkerElement);
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
if (_changedProperties.has("active")) {
|
|
193
|
-
this.updateActive(this._actualMarkerElement);
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
_changedProperties.forEach((oldValue, prop) => this._raisePropertyChange(prop as string));
|
|
197
|
-
return false;
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
protected updateVisibility(container?: HTMLDivElement) {
|
|
201
|
-
if (container) {
|
|
202
|
-
if (this.visible) {
|
|
203
|
-
container.removeAttribute("hidden");
|
|
204
|
-
} else {
|
|
205
|
-
container.setAttribute("hidden", "true");
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
protected updateActive(container?: HTMLDivElement) {
|
|
211
|
-
if (container) {
|
|
212
|
-
if (this.active) {
|
|
213
|
-
container.classList.add("active");
|
|
214
|
-
} else {
|
|
215
|
-
container.classList.remove("active");
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
protected updateInteractive(container?: HTMLDivElement) {
|
|
221
|
-
if (container) {
|
|
222
|
-
if (this.interactive) {
|
|
223
|
-
container.classList.add("interactive");
|
|
224
|
-
} else {
|
|
225
|
-
container.classList.remove("interactive");
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
protected refreshMarkerContent() {
|
|
231
|
-
if (this.markerContainer) {
|
|
232
|
-
let content = this.createMarkerContent();
|
|
233
|
-
if (!content) {
|
|
234
|
-
// Append default marker
|
|
235
|
-
this._actualMarkerElement!.classList.add("or-map-marker-default");
|
|
236
|
-
content = this.createDefaultMarkerContent();
|
|
237
|
-
} else {
|
|
238
|
-
this._actualMarkerElement!.classList.remove("or-map-marker-default");
|
|
239
|
-
}
|
|
240
|
-
if (this.markerContainer.children.length > 0) {
|
|
241
|
-
this.markerContainer.removeChild(this.markerContainer.children[0]);
|
|
242
|
-
}
|
|
243
|
-
this.markerContainer.appendChild(content);
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
protected render() {
|
|
248
|
-
return html`
|
|
249
|
-
<slot></slot>
|
|
250
|
-
`;
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
protected _raisePropertyChange(prop: string) {
|
|
254
|
-
this.dispatchEvent(new OrMapMarkerChangedEvent(this, prop));
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
protected addMarkerClassNames(markerElement: HTMLElement) {
|
|
258
|
-
markerElement.classList.add("or-map-marker");
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
protected addMarkerContainerClassNames(markerContainer: HTMLElement) {
|
|
262
|
-
markerContainer.classList.add("marker-container");
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
protected createDefaultMarkerContent(): HTMLElement {
|
|
266
|
-
const div = document.createElement("div");
|
|
267
|
-
div.innerHTML = OrMapMarker._defaultTemplate(this.icon);
|
|
268
|
-
return div;
|
|
269
|
-
}
|
|
270
|
-
}
|
package/src/util.ts
DELETED
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import {LngLat, LngLatBounds, LngLatBoundsLike, LngLatLike} from "mapbox-gl";
|
|
2
|
-
import L, {LatLng, LatLngBounds} from "mapbox.js";
|
|
3
|
-
|
|
4
|
-
export function getLngLat(lngLatLike?: LngLatLike): LngLat | undefined {
|
|
5
|
-
if (lngLatLike) {
|
|
6
|
-
|
|
7
|
-
if (lngLatLike instanceof LngLat) {
|
|
8
|
-
return lngLatLike as LngLat;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
const obj = lngLatLike as object;
|
|
12
|
-
|
|
13
|
-
if (obj.hasOwnProperty("lng")) {
|
|
14
|
-
const lngLatObj = obj as { lng: number; lat: number; };
|
|
15
|
-
return new LngLat(lngLatObj.lng, lngLatObj.lat);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
if (obj.hasOwnProperty("lon")) {
|
|
19
|
-
const lonLatObj = obj as { lon: number; lat: number; };
|
|
20
|
-
return new LngLat(lonLatObj.lon, lonLatObj.lat);
|
|
21
|
-
}
|
|
22
|
-
const lonLatArr = obj as number[];
|
|
23
|
-
|
|
24
|
-
if (lonLatArr.length === 2) {
|
|
25
|
-
return new LngLat(lonLatArr[0], lonLatArr[1]);
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export function getLngLatBounds(lngLatBoundsLike?: LngLatBoundsLike): LngLatBounds | undefined {
|
|
31
|
-
if (lngLatBoundsLike) {
|
|
32
|
-
|
|
33
|
-
if (lngLatBoundsLike instanceof LngLatBounds) {
|
|
34
|
-
return lngLatBoundsLike as LngLatBounds;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
const arr = lngLatBoundsLike as any[];
|
|
38
|
-
if (arr.length === 2) {
|
|
39
|
-
const sw = getLngLat(arr[0]);
|
|
40
|
-
const ne = getLngLat(arr[1]);
|
|
41
|
-
if (sw && ne) {
|
|
42
|
-
return new LngLatBounds(sw, ne);
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
if (arr.length === 4) {
|
|
47
|
-
return new LngLatBounds([arr[0], arr[1], arr[2], arr[3]]);
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
export function getLatLng(lngLatLike?: LngLatLike): LatLng | undefined {
|
|
53
|
-
const lngLat = getLngLat(lngLatLike);
|
|
54
|
-
if (lngLat) {
|
|
55
|
-
return L.latLng(lngLat.lat, lngLat.lng);
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
export function getLatLngBounds(lngLatBoundsLike?: LngLatBoundsLike): LatLngBounds | undefined {
|
|
60
|
-
const lngLatBounds = getLngLatBounds(lngLatBoundsLike);
|
|
61
|
-
if (lngLatBounds) {
|
|
62
|
-
return L.latLngBounds(getLatLng(lngLatBounds.getNorthEast())!, getLatLng(lngLatBounds.getSouthWest())!);
|
|
63
|
-
}
|
|
64
|
-
}
|
package/tsconfig.json
DELETED