@mcp-b/geo-maplibre 0.2.0
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/LICENSE +21 -0
- package/dist/circle-CFH3gDcY.js +146 -0
- package/dist/components/circle/circle.d.ts +51 -0
- package/dist/components/circle/circle.js +2 -0
- package/dist/components/control/control.d.ts +42 -0
- package/dist/components/control/control.js +2 -0
- package/dist/components/geojson/geojson.d.ts +74 -0
- package/dist/components/geojson/geojson.js +2 -0
- package/dist/components/layer/layer.d.ts +35 -0
- package/dist/components/layer/layer.js +2 -0
- package/dist/components/map/map.d.ts +43 -0
- package/dist/components/map/map.js +2 -0
- package/dist/components/marker/marker.d.ts +42 -0
- package/dist/components/marker/marker.js +2 -0
- package/dist/components/polygon/polygon.d.ts +46 -0
- package/dist/components/polygon/polygon.js +2 -0
- package/dist/components/polyline/polyline.d.ts +44 -0
- package/dist/components/polyline/polyline.js +2 -0
- package/dist/components/popup/popup.d.ts +27 -0
- package/dist/components/popup/popup.js +2 -0
- package/dist/components/scale-control/scale-control.d.ts +33 -0
- package/dist/components/scale-control/scale-control.js +2 -0
- package/dist/components/tilelayer/tilelayer.d.ts +65 -0
- package/dist/components/tilelayer/tilelayer.js +2 -0
- package/dist/control-Bka68vGo.js +61 -0
- package/dist/decorate-DcF3lt7P.js +9 -0
- package/dist/docs/custom-elements.json +1596 -0
- package/dist/geojson-BW9JQxtv.js +240 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.js +12 -0
- package/dist/layer-COvBRP1h.js +61 -0
- package/dist/map-CYqh-osb.js +135 -0
- package/dist/marker-DzWveHNW.js +79 -0
- package/dist/polygon-BJ-z1X7p.js +119 -0
- package/dist/polyline-Dt4yBInz.js +98 -0
- package/dist/popup-BNRD9rNd.js +30 -0
- package/dist/scale-control-DPWq0EHU.js +58 -0
- package/dist/tilelayer-CCmClbSv.js +85 -0
- package/package.json +75 -0
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
import { t as __decorate } from "./decorate-DcF3lt7P.js";
|
|
2
|
+
import { LitElement, css, html } from "lit";
|
|
3
|
+
import { customElement, property } from "lit/decorators.js";
|
|
4
|
+
import { SigveloFeatureClickEvent } from "@mcp-b/geo-support/events";
|
|
5
|
+
import { subscribeClassify } from "@mcp-b/geo-support/classification";
|
|
6
|
+
//#region src/components/geojson/geojson.styles.ts
|
|
7
|
+
var geojson_styles_default = css`
|
|
8
|
+
:host {
|
|
9
|
+
display: none;
|
|
10
|
+
}
|
|
11
|
+
`;
|
|
12
|
+
//#endregion
|
|
13
|
+
//#region src/components/geojson/geojson.ts
|
|
14
|
+
let sourceCounter = 0;
|
|
15
|
+
let SigveloMaplibreGeojson = class SigveloMaplibreGeojson extends LitElement {
|
|
16
|
+
static {
|
|
17
|
+
this.styles = [geojson_styles_default];
|
|
18
|
+
}
|
|
19
|
+
constructor() {
|
|
20
|
+
super();
|
|
21
|
+
this.data = null;
|
|
22
|
+
this.styleFunction = null;
|
|
23
|
+
this.fillColor = "#3388ff";
|
|
24
|
+
this.fillOpacity = .2;
|
|
25
|
+
this.strokeColor = "#3388ff";
|
|
26
|
+
this.strokeWidth = 2;
|
|
27
|
+
this.circleRadius = 6;
|
|
28
|
+
this.interactive = true;
|
|
29
|
+
this.channel = "";
|
|
30
|
+
this._mapEl = null;
|
|
31
|
+
this._onStyleLoad = () => this._addSource();
|
|
32
|
+
this._unsubscribeChannel = null;
|
|
33
|
+
const id = ++sourceCounter;
|
|
34
|
+
this._sourceId = `sigvelo-geojson-source-${id}`;
|
|
35
|
+
this._fillLayerId = `sigvelo-geojson-fill-${id}`;
|
|
36
|
+
this._lineLayerId = `sigvelo-geojson-line-${id}`;
|
|
37
|
+
this._circleLayerId = `sigvelo-geojson-circle-${id}`;
|
|
38
|
+
}
|
|
39
|
+
async connectedCallback() {
|
|
40
|
+
super.connectedCallback();
|
|
41
|
+
this._subscribeChannel();
|
|
42
|
+
this._mapEl = this.closest("sigvelo-maplibre-map");
|
|
43
|
+
if (this._mapEl) {
|
|
44
|
+
await this._mapEl.mapReady;
|
|
45
|
+
const map = this._mapEl.map;
|
|
46
|
+
if (map) map.on("style.load", this._onStyleLoad);
|
|
47
|
+
this._addSource();
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
disconnectedCallback() {
|
|
51
|
+
super.disconnectedCallback();
|
|
52
|
+
this._unsubscribeChannel?.();
|
|
53
|
+
this._unsubscribeChannel = null;
|
|
54
|
+
this._mapEl?.map?.off("style.load", this._onStyleLoad);
|
|
55
|
+
this._removeSource();
|
|
56
|
+
}
|
|
57
|
+
/** @internal */
|
|
58
|
+
_subscribeChannel() {
|
|
59
|
+
this._unsubscribeChannel?.();
|
|
60
|
+
if (!this.channel) return;
|
|
61
|
+
this._unsubscribeChannel = subscribeClassify(this.channel, (detail) => {
|
|
62
|
+
this.styleFunction = detail.styleFunction;
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* When styleFunction is set, clone the data and inject computed style
|
|
67
|
+
* properties into each feature so MapLibre can use data-driven expressions.
|
|
68
|
+
* @internal
|
|
69
|
+
*/
|
|
70
|
+
_prepareData() {
|
|
71
|
+
if (!this.data) return null;
|
|
72
|
+
if (!this.styleFunction) return this.data;
|
|
73
|
+
const clone = JSON.parse(JSON.stringify(this.data));
|
|
74
|
+
const features = clone.type === "FeatureCollection" ? clone.features : [clone];
|
|
75
|
+
for (const feature of features) {
|
|
76
|
+
const s = this.styleFunction(feature);
|
|
77
|
+
if (s) {
|
|
78
|
+
feature.properties = feature.properties ?? {};
|
|
79
|
+
if (s.fillColor != null) feature.properties._sigvelo_fill_color = s.fillColor;
|
|
80
|
+
if (s.fillOpacity != null) feature.properties._sigvelo_fill_opacity = s.fillOpacity;
|
|
81
|
+
if (s.strokeColor != null) feature.properties._sigvelo_stroke_color = s.strokeColor;
|
|
82
|
+
if (s.strokeWidth != null) feature.properties._sigvelo_stroke_width = s.strokeWidth;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
return clone;
|
|
86
|
+
}
|
|
87
|
+
_addSource() {
|
|
88
|
+
const map = this._mapEl?.map;
|
|
89
|
+
if (!map || !this.data) return;
|
|
90
|
+
if (!map.isStyleLoaded()) return;
|
|
91
|
+
this._removeSource();
|
|
92
|
+
const processedData = this._prepareData();
|
|
93
|
+
if (!processedData) return;
|
|
94
|
+
map.addSource(this._sourceId, {
|
|
95
|
+
type: "geojson",
|
|
96
|
+
data: processedData
|
|
97
|
+
});
|
|
98
|
+
const hasStyleFn = this.styleFunction != null;
|
|
99
|
+
map.addLayer({
|
|
100
|
+
id: this._fillLayerId,
|
|
101
|
+
type: "fill",
|
|
102
|
+
source: this._sourceId,
|
|
103
|
+
paint: {
|
|
104
|
+
"fill-color": hasStyleFn ? [
|
|
105
|
+
"coalesce",
|
|
106
|
+
["get", "_sigvelo_fill_color"],
|
|
107
|
+
this.fillColor
|
|
108
|
+
] : this.fillColor,
|
|
109
|
+
"fill-opacity": hasStyleFn ? [
|
|
110
|
+
"coalesce",
|
|
111
|
+
["get", "_sigvelo_fill_opacity"],
|
|
112
|
+
this.fillOpacity
|
|
113
|
+
] : this.fillOpacity
|
|
114
|
+
},
|
|
115
|
+
filter: [
|
|
116
|
+
"==",
|
|
117
|
+
"$type",
|
|
118
|
+
"Polygon"
|
|
119
|
+
]
|
|
120
|
+
});
|
|
121
|
+
map.addLayer({
|
|
122
|
+
id: this._lineLayerId,
|
|
123
|
+
type: "line",
|
|
124
|
+
source: this._sourceId,
|
|
125
|
+
paint: {
|
|
126
|
+
"line-color": hasStyleFn ? [
|
|
127
|
+
"coalesce",
|
|
128
|
+
["get", "_sigvelo_stroke_color"],
|
|
129
|
+
this.strokeColor
|
|
130
|
+
] : this.strokeColor,
|
|
131
|
+
"line-width": hasStyleFn ? [
|
|
132
|
+
"coalesce",
|
|
133
|
+
["get", "_sigvelo_stroke_width"],
|
|
134
|
+
this.strokeWidth
|
|
135
|
+
] : this.strokeWidth
|
|
136
|
+
},
|
|
137
|
+
filter: [
|
|
138
|
+
"any",
|
|
139
|
+
[
|
|
140
|
+
"==",
|
|
141
|
+
"$type",
|
|
142
|
+
"LineString"
|
|
143
|
+
],
|
|
144
|
+
[
|
|
145
|
+
"==",
|
|
146
|
+
"$type",
|
|
147
|
+
"Polygon"
|
|
148
|
+
]
|
|
149
|
+
]
|
|
150
|
+
});
|
|
151
|
+
map.addLayer({
|
|
152
|
+
id: this._circleLayerId,
|
|
153
|
+
type: "circle",
|
|
154
|
+
source: this._sourceId,
|
|
155
|
+
paint: {
|
|
156
|
+
"circle-color": hasStyleFn ? [
|
|
157
|
+
"coalesce",
|
|
158
|
+
["get", "_sigvelo_fill_color"],
|
|
159
|
+
this.fillColor
|
|
160
|
+
] : this.fillColor,
|
|
161
|
+
"circle-radius": this.circleRadius,
|
|
162
|
+
"circle-stroke-color": hasStyleFn ? [
|
|
163
|
+
"coalesce",
|
|
164
|
+
["get", "_sigvelo_stroke_color"],
|
|
165
|
+
this.strokeColor
|
|
166
|
+
] : this.strokeColor,
|
|
167
|
+
"circle-stroke-width": hasStyleFn ? [
|
|
168
|
+
"coalesce",
|
|
169
|
+
["get", "_sigvelo_stroke_width"],
|
|
170
|
+
this.strokeWidth
|
|
171
|
+
] : this.strokeWidth
|
|
172
|
+
},
|
|
173
|
+
filter: [
|
|
174
|
+
"==",
|
|
175
|
+
"$type",
|
|
176
|
+
"Point"
|
|
177
|
+
]
|
|
178
|
+
});
|
|
179
|
+
if (this.interactive) {
|
|
180
|
+
const layerIds = [
|
|
181
|
+
this._fillLayerId,
|
|
182
|
+
this._lineLayerId,
|
|
183
|
+
this._circleLayerId
|
|
184
|
+
];
|
|
185
|
+
for (const layerId of layerIds) map.on("click", layerId, (e) => {
|
|
186
|
+
const feature = e.features?.[0];
|
|
187
|
+
if (!feature) return;
|
|
188
|
+
this.dispatchEvent(new SigveloFeatureClickEvent({
|
|
189
|
+
type: "Feature",
|
|
190
|
+
geometry: feature.geometry,
|
|
191
|
+
properties: feature.properties ?? null,
|
|
192
|
+
id: feature.id
|
|
193
|
+
}, {
|
|
194
|
+
lat: e.lngLat.lat,
|
|
195
|
+
lng: e.lngLat.lng
|
|
196
|
+
}));
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
_removeSource() {
|
|
201
|
+
const map = this._mapEl?.map;
|
|
202
|
+
if (!map) return;
|
|
203
|
+
for (const id of [
|
|
204
|
+
this._fillLayerId,
|
|
205
|
+
this._lineLayerId,
|
|
206
|
+
this._circleLayerId
|
|
207
|
+
]) if (map.getLayer(id)) map.removeLayer(id);
|
|
208
|
+
if (map.getSource(this._sourceId)) map.removeSource(this._sourceId);
|
|
209
|
+
}
|
|
210
|
+
updated(changed) {
|
|
211
|
+
if (changed.has("data") || changed.has("styleFunction") || changed.has("fillColor") || changed.has("fillOpacity") || changed.has("strokeColor") || changed.has("strokeWidth") || changed.has("circleRadius")) {
|
|
212
|
+
this._removeSource();
|
|
213
|
+
this._addSource();
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
render() {
|
|
217
|
+
return html``;
|
|
218
|
+
}
|
|
219
|
+
};
|
|
220
|
+
__decorate([property({ attribute: false })], SigveloMaplibreGeojson.prototype, "data", void 0);
|
|
221
|
+
__decorate([property({ attribute: false })], SigveloMaplibreGeojson.prototype, "styleFunction", void 0);
|
|
222
|
+
__decorate([property({ attribute: "fill-color" })], SigveloMaplibreGeojson.prototype, "fillColor", void 0);
|
|
223
|
+
__decorate([property({
|
|
224
|
+
attribute: "fill-opacity",
|
|
225
|
+
type: Number
|
|
226
|
+
})], SigveloMaplibreGeojson.prototype, "fillOpacity", void 0);
|
|
227
|
+
__decorate([property({ attribute: "stroke-color" })], SigveloMaplibreGeojson.prototype, "strokeColor", void 0);
|
|
228
|
+
__decorate([property({
|
|
229
|
+
attribute: "stroke-width",
|
|
230
|
+
type: Number
|
|
231
|
+
})], SigveloMaplibreGeojson.prototype, "strokeWidth", void 0);
|
|
232
|
+
__decorate([property({
|
|
233
|
+
attribute: "circle-radius",
|
|
234
|
+
type: Number
|
|
235
|
+
})], SigveloMaplibreGeojson.prototype, "circleRadius", void 0);
|
|
236
|
+
__decorate([property({ type: Boolean })], SigveloMaplibreGeojson.prototype, "interactive", void 0);
|
|
237
|
+
__decorate([property()], SigveloMaplibreGeojson.prototype, "channel", void 0);
|
|
238
|
+
SigveloMaplibreGeojson = __decorate([customElement("sigvelo-maplibre-geojson")], SigveloMaplibreGeojson);
|
|
239
|
+
//#endregion
|
|
240
|
+
export { SigveloMaplibreGeojson as t };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { SigveloMaplibreCircle } from "./components/circle/circle.js";
|
|
2
|
+
import { SigveloMaplibreControl } from "./components/control/control.js";
|
|
3
|
+
import { SigveloMaplibreGeojson } from "./components/geojson/geojson.js";
|
|
4
|
+
import { SigveloMaplibreLayer } from "./components/layer/layer.js";
|
|
5
|
+
import { SigveloMaplibreMap } from "./components/map/map.js";
|
|
6
|
+
import { SigveloMaplibreMarker } from "./components/marker/marker.js";
|
|
7
|
+
import { SigveloMaplibrePolygon } from "./components/polygon/polygon.js";
|
|
8
|
+
import { SigveloMaplibrePolyline } from "./components/polyline/polyline.js";
|
|
9
|
+
import { SigveloMaplibrePopup } from "./components/popup/popup.js";
|
|
10
|
+
import { SigveloMaplibreScaleControl } from "./components/scale-control/scale-control.js";
|
|
11
|
+
import { SigveloMaplibreTilelayer } from "./components/tilelayer/tilelayer.js";
|
|
12
|
+
export { SigveloMaplibreCircle, SigveloMaplibreControl, SigveloMaplibreGeojson, SigveloMaplibreLayer, SigveloMaplibreMap, SigveloMaplibreMarker, SigveloMaplibrePolygon, SigveloMaplibrePolyline, SigveloMaplibrePopup, SigveloMaplibreScaleControl, SigveloMaplibreTilelayer };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { t as SigveloMaplibreMap } from "./map-CYqh-osb.js";
|
|
2
|
+
import { t as SigveloMaplibreTilelayer } from "./tilelayer-CCmClbSv.js";
|
|
3
|
+
import { t as SigveloMaplibreMarker } from "./marker-DzWveHNW.js";
|
|
4
|
+
import { t as SigveloMaplibrePopup } from "./popup-BNRD9rNd.js";
|
|
5
|
+
import { t as SigveloMaplibreGeojson } from "./geojson-BW9JQxtv.js";
|
|
6
|
+
import { t as SigveloMaplibreCircle } from "./circle-CFH3gDcY.js";
|
|
7
|
+
import { t as SigveloMaplibrePolyline } from "./polyline-Dt4yBInz.js";
|
|
8
|
+
import { t as SigveloMaplibrePolygon } from "./polygon-BJ-z1X7p.js";
|
|
9
|
+
import { t as SigveloMaplibreScaleControl } from "./scale-control-DPWq0EHU.js";
|
|
10
|
+
import { t as SigveloMaplibreLayer } from "./layer-COvBRP1h.js";
|
|
11
|
+
import { t as SigveloMaplibreControl } from "./control-Bka68vGo.js";
|
|
12
|
+
export { SigveloMaplibreCircle, SigveloMaplibreControl, SigveloMaplibreGeojson, SigveloMaplibreLayer, SigveloMaplibreMap, SigveloMaplibreMarker, SigveloMaplibrePolygon, SigveloMaplibrePolyline, SigveloMaplibrePopup, SigveloMaplibreScaleControl, SigveloMaplibreTilelayer };
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { t as __decorate } from "./decorate-DcF3lt7P.js";
|
|
2
|
+
import { LitElement, css, html } from "lit";
|
|
3
|
+
import { customElement, property } from "lit/decorators.js";
|
|
4
|
+
//#region src/components/layer/layer.styles.ts
|
|
5
|
+
var layer_styles_default = css`
|
|
6
|
+
:host {
|
|
7
|
+
display: none;
|
|
8
|
+
}
|
|
9
|
+
`;
|
|
10
|
+
//#endregion
|
|
11
|
+
//#region src/components/layer/layer.ts
|
|
12
|
+
let SigveloMaplibreLayer = class SigveloMaplibreLayer extends LitElement {
|
|
13
|
+
constructor(..._args) {
|
|
14
|
+
super(..._args);
|
|
15
|
+
this.spec = null;
|
|
16
|
+
this.beforeId = "";
|
|
17
|
+
this._mapEl = null;
|
|
18
|
+
this._addedLayerId = null;
|
|
19
|
+
}
|
|
20
|
+
static {
|
|
21
|
+
this.styles = [layer_styles_default];
|
|
22
|
+
}
|
|
23
|
+
async connectedCallback() {
|
|
24
|
+
super.connectedCallback();
|
|
25
|
+
this._mapEl = this.closest("sigvelo-maplibre-map");
|
|
26
|
+
if (this._mapEl) {
|
|
27
|
+
await this._mapEl.mapReady;
|
|
28
|
+
this._addLayer();
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
disconnectedCallback() {
|
|
32
|
+
super.disconnectedCallback();
|
|
33
|
+
this._removeLayer();
|
|
34
|
+
}
|
|
35
|
+
_addLayer() {
|
|
36
|
+
const map = this._mapEl?.map;
|
|
37
|
+
if (!map || !this.spec) return;
|
|
38
|
+
map.addLayer(this.spec, this.beforeId || void 0);
|
|
39
|
+
this._addedLayerId = this.spec.id;
|
|
40
|
+
}
|
|
41
|
+
_removeLayer() {
|
|
42
|
+
const map = this._mapEl?.map;
|
|
43
|
+
if (!map || !this._addedLayerId) return;
|
|
44
|
+
if (map.getLayer(this._addedLayerId)) map.removeLayer(this._addedLayerId);
|
|
45
|
+
this._addedLayerId = null;
|
|
46
|
+
}
|
|
47
|
+
updated(changed) {
|
|
48
|
+
if (changed.has("spec")) {
|
|
49
|
+
this._removeLayer();
|
|
50
|
+
this._addLayer();
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
render() {
|
|
54
|
+
return html``;
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
__decorate([property({ attribute: false })], SigveloMaplibreLayer.prototype, "spec", void 0);
|
|
58
|
+
__decorate([property({ attribute: "before-id" })], SigveloMaplibreLayer.prototype, "beforeId", void 0);
|
|
59
|
+
SigveloMaplibreLayer = __decorate([customElement("sigvelo-maplibre-layer")], SigveloMaplibreLayer);
|
|
60
|
+
//#endregion
|
|
61
|
+
export { SigveloMaplibreLayer as t };
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { t as __decorate } from "./decorate-DcF3lt7P.js";
|
|
2
|
+
import { css, unsafeCSS } from "lit";
|
|
3
|
+
import { customElement, property } from "lit/decorators.js";
|
|
4
|
+
import { GeoMapElement } from "@mcp-b/geo-support/base/geo-map-element";
|
|
5
|
+
import { SigveloMapClickEvent, SigveloMapLoadEvent, SigveloMapMoveEndEvent, SigveloMapMoveEvent, SigveloMapZoomEndEvent, SigveloMapZoomEvent } from "@mcp-b/geo-support/events";
|
|
6
|
+
import maplibregl from "maplibre-gl";
|
|
7
|
+
import maplibreCss from "maplibre-gl/dist/maplibre-gl.css?raw";
|
|
8
|
+
//#region src/components/map/map.styles.ts
|
|
9
|
+
var map_styles_default = css`
|
|
10
|
+
:host {
|
|
11
|
+
display: block;
|
|
12
|
+
position: relative;
|
|
13
|
+
min-height: 300px;
|
|
14
|
+
}
|
|
15
|
+
`;
|
|
16
|
+
//#endregion
|
|
17
|
+
//#region src/components/map/map.ts
|
|
18
|
+
/** Empty style used when no tilelayer child provides a style-url. */
|
|
19
|
+
const EMPTY_STYLE = {
|
|
20
|
+
version: 8,
|
|
21
|
+
sources: {},
|
|
22
|
+
layers: []
|
|
23
|
+
};
|
|
24
|
+
let SigveloMaplibreMap = class SigveloMaplibreMap extends GeoMapElement {
|
|
25
|
+
constructor(..._args) {
|
|
26
|
+
super(..._args);
|
|
27
|
+
this.navControl = true;
|
|
28
|
+
this._map = null;
|
|
29
|
+
}
|
|
30
|
+
static {
|
|
31
|
+
this.styles = [
|
|
32
|
+
...GeoMapElement.styles,
|
|
33
|
+
unsafeCSS(maplibreCss),
|
|
34
|
+
map_styles_default
|
|
35
|
+
];
|
|
36
|
+
}
|
|
37
|
+
/** Access the underlying MapLibre map instance (after mapReady resolves). */
|
|
38
|
+
get map() {
|
|
39
|
+
return this._map;
|
|
40
|
+
}
|
|
41
|
+
createMap(container) {
|
|
42
|
+
this._map = new maplibregl.Map({
|
|
43
|
+
container,
|
|
44
|
+
style: EMPTY_STYLE,
|
|
45
|
+
center: [this.longitude, this.latitude],
|
|
46
|
+
zoom: this.zoom,
|
|
47
|
+
minZoom: this.minZoom,
|
|
48
|
+
maxZoom: this.maxZoom,
|
|
49
|
+
bearing: this.bearing,
|
|
50
|
+
pitch: this.pitch
|
|
51
|
+
});
|
|
52
|
+
if (this.navControl) this._map.addControl(new maplibregl.NavigationControl());
|
|
53
|
+
this._map.on("click", (e) => {
|
|
54
|
+
this.dispatchEvent(new SigveloMapClickEvent({
|
|
55
|
+
lat: e.lngLat.lat,
|
|
56
|
+
lng: e.lngLat.lng
|
|
57
|
+
}, e.originalEvent));
|
|
58
|
+
});
|
|
59
|
+
this._map.on("move", () => {
|
|
60
|
+
if (!this._map) return;
|
|
61
|
+
const center = this._map.getCenter();
|
|
62
|
+
this._suppressExternalUpdate = true;
|
|
63
|
+
this.latitude = center.lat;
|
|
64
|
+
this.longitude = center.lng;
|
|
65
|
+
this._suppressExternalUpdate = false;
|
|
66
|
+
this.dispatchEvent(new SigveloMapMoveEvent({
|
|
67
|
+
lat: center.lat,
|
|
68
|
+
lng: center.lng
|
|
69
|
+
}));
|
|
70
|
+
});
|
|
71
|
+
this._map.on("moveend", () => {
|
|
72
|
+
if (!this._map) return;
|
|
73
|
+
const center = this._map.getCenter();
|
|
74
|
+
this.dispatchEvent(new SigveloMapMoveEndEvent({
|
|
75
|
+
lat: center.lat,
|
|
76
|
+
lng: center.lng
|
|
77
|
+
}));
|
|
78
|
+
});
|
|
79
|
+
this._map.on("zoom", () => {
|
|
80
|
+
if (!this._map) return;
|
|
81
|
+
const zoom = this._map.getZoom();
|
|
82
|
+
this._suppressExternalUpdate = true;
|
|
83
|
+
this.zoom = zoom;
|
|
84
|
+
this._suppressExternalUpdate = false;
|
|
85
|
+
this.dispatchEvent(new SigveloMapZoomEvent(zoom));
|
|
86
|
+
});
|
|
87
|
+
this._map.on("zoomend", () => {
|
|
88
|
+
if (!this._map) return;
|
|
89
|
+
this.dispatchEvent(new SigveloMapZoomEndEvent(this._map.getZoom()));
|
|
90
|
+
});
|
|
91
|
+
this._map.on("load", () => {
|
|
92
|
+
this._resolveMapReady();
|
|
93
|
+
this.dispatchEvent(new SigveloMapLoadEvent());
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
destroyMap() {
|
|
97
|
+
this._map?.remove();
|
|
98
|
+
this._map = null;
|
|
99
|
+
}
|
|
100
|
+
updateView(changed) {
|
|
101
|
+
if (!this._map) return;
|
|
102
|
+
if (changed.has("latitude") || changed.has("longitude")) this._map.setCenter([this.longitude, this.latitude]);
|
|
103
|
+
if (changed.has("zoom")) this._map.setZoom(this.zoom);
|
|
104
|
+
if (changed.has("bearing")) this._map.setBearing(this.bearing);
|
|
105
|
+
if (changed.has("pitch")) this._map.setPitch(this.pitch);
|
|
106
|
+
if (changed.has("minZoom")) this._map.setMinZoom(this.minZoom);
|
|
107
|
+
if (changed.has("maxZoom")) this._map.setMaxZoom(this.maxZoom);
|
|
108
|
+
}
|
|
109
|
+
invalidateSize() {
|
|
110
|
+
this._map?.resize();
|
|
111
|
+
}
|
|
112
|
+
flyTo(options) {
|
|
113
|
+
this._map?.flyTo({
|
|
114
|
+
center: [options.center.lng, options.center.lat],
|
|
115
|
+
zoom: options.zoom,
|
|
116
|
+
bearing: options.bearing,
|
|
117
|
+
pitch: options.pitch,
|
|
118
|
+
duration: options.duration
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
fitBounds(options) {
|
|
122
|
+
this._map?.fitBounds([[options.bounds.west, options.bounds.south], [options.bounds.east, options.bounds.north]], {
|
|
123
|
+
padding: options.padding,
|
|
124
|
+
maxZoom: options.maxZoom,
|
|
125
|
+
duration: options.duration
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
};
|
|
129
|
+
__decorate([property({
|
|
130
|
+
attribute: "nav-control",
|
|
131
|
+
type: Boolean
|
|
132
|
+
})], SigveloMaplibreMap.prototype, "navControl", void 0);
|
|
133
|
+
SigveloMaplibreMap = __decorate([customElement("sigvelo-maplibre-map")], SigveloMaplibreMap);
|
|
134
|
+
//#endregion
|
|
135
|
+
export { SigveloMaplibreMap as t };
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { t as __decorate } from "./decorate-DcF3lt7P.js";
|
|
2
|
+
import { LitElement, css, html } from "lit";
|
|
3
|
+
import { customElement, property } from "lit/decorators.js";
|
|
4
|
+
import maplibregl from "maplibre-gl";
|
|
5
|
+
//#region src/components/marker/marker.styles.ts
|
|
6
|
+
var marker_styles_default = css`
|
|
7
|
+
:host {
|
|
8
|
+
display: none;
|
|
9
|
+
}
|
|
10
|
+
`;
|
|
11
|
+
//#endregion
|
|
12
|
+
//#region src/components/marker/marker.ts
|
|
13
|
+
let SigveloMaplibreMarker = class SigveloMaplibreMarker extends LitElement {
|
|
14
|
+
constructor(..._args) {
|
|
15
|
+
super(..._args);
|
|
16
|
+
this.latitude = 0;
|
|
17
|
+
this.longitude = 0;
|
|
18
|
+
this.color = "#3fb1ce";
|
|
19
|
+
this.draggable = false;
|
|
20
|
+
this.scale = 1;
|
|
21
|
+
this._marker = null;
|
|
22
|
+
this._mapEl = null;
|
|
23
|
+
}
|
|
24
|
+
static {
|
|
25
|
+
this.styles = [marker_styles_default];
|
|
26
|
+
}
|
|
27
|
+
/** Access the underlying MapLibre marker instance. */
|
|
28
|
+
get marker() {
|
|
29
|
+
return this._marker;
|
|
30
|
+
}
|
|
31
|
+
async connectedCallback() {
|
|
32
|
+
super.connectedCallback();
|
|
33
|
+
this._mapEl = this.closest("sigvelo-maplibre-map");
|
|
34
|
+
if (this._mapEl) {
|
|
35
|
+
await this._mapEl.mapReady;
|
|
36
|
+
this._addMarker();
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
disconnectedCallback() {
|
|
40
|
+
super.disconnectedCallback();
|
|
41
|
+
this._marker?.remove();
|
|
42
|
+
this._marker = null;
|
|
43
|
+
}
|
|
44
|
+
_addMarker() {
|
|
45
|
+
if (!this._mapEl?.map) return;
|
|
46
|
+
this._marker = new maplibregl.Marker({
|
|
47
|
+
color: this.color,
|
|
48
|
+
draggable: this.draggable,
|
|
49
|
+
scale: this.scale
|
|
50
|
+
}).setLngLat([this.longitude, this.latitude]).addTo(this._mapEl.map);
|
|
51
|
+
const popupEl = this.querySelector("sigvelo-maplibre-popup");
|
|
52
|
+
if (popupEl) {
|
|
53
|
+
const content = document.createElement("div");
|
|
54
|
+
for (const node of Array.from(popupEl.childNodes)) content.appendChild(node.cloneNode(true));
|
|
55
|
+
const popup = new maplibregl.Popup().setDOMContent(content);
|
|
56
|
+
this._marker.setPopup(popup);
|
|
57
|
+
}
|
|
58
|
+
this._marker.on("dragend", () => {
|
|
59
|
+
if (!this._marker) return;
|
|
60
|
+
const pos = this._marker.getLngLat();
|
|
61
|
+
this.latitude = pos.lat;
|
|
62
|
+
this.longitude = pos.lng;
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
updated() {
|
|
66
|
+
if (this._marker) this._marker.setLngLat([this.longitude, this.latitude]);
|
|
67
|
+
}
|
|
68
|
+
render() {
|
|
69
|
+
return html` <slot></slot> `;
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
__decorate([property({ type: Number })], SigveloMaplibreMarker.prototype, "latitude", void 0);
|
|
73
|
+
__decorate([property({ type: Number })], SigveloMaplibreMarker.prototype, "longitude", void 0);
|
|
74
|
+
__decorate([property()], SigveloMaplibreMarker.prototype, "color", void 0);
|
|
75
|
+
__decorate([property({ type: Boolean })], SigveloMaplibreMarker.prototype, "draggable", void 0);
|
|
76
|
+
__decorate([property({ type: Number })], SigveloMaplibreMarker.prototype, "scale", void 0);
|
|
77
|
+
SigveloMaplibreMarker = __decorate([customElement("sigvelo-maplibre-marker")], SigveloMaplibreMarker);
|
|
78
|
+
//#endregion
|
|
79
|
+
export { SigveloMaplibreMarker as t };
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { t as __decorate } from "./decorate-DcF3lt7P.js";
|
|
2
|
+
import { LitElement, css, html } from "lit";
|
|
3
|
+
import { customElement, property } from "lit/decorators.js";
|
|
4
|
+
//#region src/components/polygon/polygon.styles.ts
|
|
5
|
+
var polygon_styles_default = css`
|
|
6
|
+
:host {
|
|
7
|
+
display: none;
|
|
8
|
+
}
|
|
9
|
+
`;
|
|
10
|
+
//#endregion
|
|
11
|
+
//#region src/components/polygon/polygon.ts
|
|
12
|
+
let polygonCounter = 0;
|
|
13
|
+
let SigveloMaplibrePolygon = class SigveloMaplibrePolygon extends LitElement {
|
|
14
|
+
static {
|
|
15
|
+
this.styles = [polygon_styles_default];
|
|
16
|
+
}
|
|
17
|
+
constructor() {
|
|
18
|
+
super();
|
|
19
|
+
this.positions = [];
|
|
20
|
+
this.fillColor = "#3388ff";
|
|
21
|
+
this.fillOpacity = .2;
|
|
22
|
+
this.strokeColor = "#3388ff";
|
|
23
|
+
this.strokeWidth = 2;
|
|
24
|
+
this._mapEl = null;
|
|
25
|
+
const id = ++polygonCounter;
|
|
26
|
+
this._sourceId = `sigvelo-polygon-source-${id}`;
|
|
27
|
+
this._fillLayerId = `sigvelo-polygon-fill-${id}`;
|
|
28
|
+
this._strokeLayerId = `sigvelo-polygon-stroke-${id}`;
|
|
29
|
+
}
|
|
30
|
+
async connectedCallback() {
|
|
31
|
+
super.connectedCallback();
|
|
32
|
+
this._mapEl = this.closest("sigvelo-maplibre-map");
|
|
33
|
+
if (this._mapEl) {
|
|
34
|
+
await this._mapEl.mapReady;
|
|
35
|
+
this._addPolygon();
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
disconnectedCallback() {
|
|
39
|
+
super.disconnectedCallback();
|
|
40
|
+
this._removePolygon();
|
|
41
|
+
}
|
|
42
|
+
_toGeoJSON() {
|
|
43
|
+
const ring = this.positions.map(([lat, lng]) => [lng, lat]);
|
|
44
|
+
if (ring.length > 0) {
|
|
45
|
+
const first = ring[0];
|
|
46
|
+
const last = ring[ring.length - 1];
|
|
47
|
+
if (first[0] !== last[0] || first[1] !== last[1]) ring.push([...first]);
|
|
48
|
+
}
|
|
49
|
+
return {
|
|
50
|
+
type: "Feature",
|
|
51
|
+
geometry: {
|
|
52
|
+
type: "Polygon",
|
|
53
|
+
coordinates: [ring]
|
|
54
|
+
},
|
|
55
|
+
properties: {}
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
_addPolygon() {
|
|
59
|
+
const map = this._mapEl?.map;
|
|
60
|
+
if (!map || this.positions.length < 3) return;
|
|
61
|
+
map.addSource(this._sourceId, {
|
|
62
|
+
type: "geojson",
|
|
63
|
+
data: this._toGeoJSON()
|
|
64
|
+
});
|
|
65
|
+
map.addLayer({
|
|
66
|
+
id: this._fillLayerId,
|
|
67
|
+
type: "fill",
|
|
68
|
+
source: this._sourceId,
|
|
69
|
+
paint: {
|
|
70
|
+
"fill-color": this.fillColor,
|
|
71
|
+
"fill-opacity": this.fillOpacity
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
map.addLayer({
|
|
75
|
+
id: this._strokeLayerId,
|
|
76
|
+
type: "line",
|
|
77
|
+
source: this._sourceId,
|
|
78
|
+
paint: {
|
|
79
|
+
"line-color": this.strokeColor,
|
|
80
|
+
"line-width": this.strokeWidth
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
_removePolygon() {
|
|
85
|
+
const map = this._mapEl?.map;
|
|
86
|
+
if (!map) return;
|
|
87
|
+
for (const id of [this._fillLayerId, this._strokeLayerId]) if (map.getLayer(id)) map.removeLayer(id);
|
|
88
|
+
if (map.getSource(this._sourceId)) map.removeSource(this._sourceId);
|
|
89
|
+
}
|
|
90
|
+
updated(changed) {
|
|
91
|
+
const map = this._mapEl?.map;
|
|
92
|
+
if (!map) return;
|
|
93
|
+
if (changed.has("positions")) {
|
|
94
|
+
const source = map.getSource(this._sourceId);
|
|
95
|
+
if (source) source.setData(this._toGeoJSON());
|
|
96
|
+
}
|
|
97
|
+
if (changed.has("fillColor") && map.getLayer(this._fillLayerId)) map.setPaintProperty(this._fillLayerId, "fill-color", this.fillColor);
|
|
98
|
+
if (changed.has("fillOpacity") && map.getLayer(this._fillLayerId)) map.setPaintProperty(this._fillLayerId, "fill-opacity", this.fillOpacity);
|
|
99
|
+
if (changed.has("strokeColor") && map.getLayer(this._strokeLayerId)) map.setPaintProperty(this._strokeLayerId, "line-color", this.strokeColor);
|
|
100
|
+
if (changed.has("strokeWidth") && map.getLayer(this._strokeLayerId)) map.setPaintProperty(this._strokeLayerId, "line-width", this.strokeWidth);
|
|
101
|
+
}
|
|
102
|
+
render() {
|
|
103
|
+
return html``;
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
__decorate([property({ attribute: false })], SigveloMaplibrePolygon.prototype, "positions", void 0);
|
|
107
|
+
__decorate([property({ attribute: "fill-color" })], SigveloMaplibrePolygon.prototype, "fillColor", void 0);
|
|
108
|
+
__decorate([property({
|
|
109
|
+
attribute: "fill-opacity",
|
|
110
|
+
type: Number
|
|
111
|
+
})], SigveloMaplibrePolygon.prototype, "fillOpacity", void 0);
|
|
112
|
+
__decorate([property({ attribute: "stroke-color" })], SigveloMaplibrePolygon.prototype, "strokeColor", void 0);
|
|
113
|
+
__decorate([property({
|
|
114
|
+
attribute: "stroke-width",
|
|
115
|
+
type: Number
|
|
116
|
+
})], SigveloMaplibrePolygon.prototype, "strokeWidth", void 0);
|
|
117
|
+
SigveloMaplibrePolygon = __decorate([customElement("sigvelo-maplibre-polygon")], SigveloMaplibrePolygon);
|
|
118
|
+
//#endregion
|
|
119
|
+
export { SigveloMaplibrePolygon as t };
|