@mcp-b/geo-maplibre 0.2.21 → 0.3.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.
@@ -1,79 +0,0 @@
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 };
@@ -1,119 +0,0 @@
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 };
@@ -1,98 +0,0 @@
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/polyline/polyline.styles.ts
5
- var polyline_styles_default = css`
6
- :host {
7
- display: none;
8
- }
9
- `;
10
- //#endregion
11
- //#region src/components/polyline/polyline.ts
12
- let lineCounter = 0;
13
- let SigveloMaplibrePolyline = class SigveloMaplibrePolyline extends LitElement {
14
- static {
15
- this.styles = [polyline_styles_default];
16
- }
17
- constructor() {
18
- super();
19
- this.positions = [];
20
- this.color = "#3388ff";
21
- this.width = 3;
22
- this.opacity = 1;
23
- this.dashArray = [];
24
- this._mapEl = null;
25
- const id = ++lineCounter;
26
- this._sourceId = `sigvelo-line-source-${id}`;
27
- this._layerId = `sigvelo-line-layer-${id}`;
28
- }
29
- async connectedCallback() {
30
- super.connectedCallback();
31
- this._mapEl = this.closest("sigvelo-maplibre-map");
32
- if (this._mapEl) {
33
- await this._mapEl.mapReady;
34
- this._addLine();
35
- }
36
- }
37
- disconnectedCallback() {
38
- super.disconnectedCallback();
39
- this._removeLine();
40
- }
41
- _toGeoJSON() {
42
- return {
43
- type: "Feature",
44
- geometry: {
45
- type: "LineString",
46
- coordinates: this.positions.map(([lat, lng]) => [lng, lat])
47
- },
48
- properties: {}
49
- };
50
- }
51
- _addLine() {
52
- const map = this._mapEl?.map;
53
- if (!map || this.positions.length < 2) return;
54
- map.addSource(this._sourceId, {
55
- type: "geojson",
56
- data: this._toGeoJSON()
57
- });
58
- map.addLayer({
59
- id: this._layerId,
60
- type: "line",
61
- source: this._sourceId,
62
- paint: {
63
- "line-color": this.color,
64
- "line-width": this.width,
65
- "line-opacity": this.opacity,
66
- ...this.dashArray.length ? { "line-dasharray": this.dashArray } : {}
67
- }
68
- });
69
- }
70
- _removeLine() {
71
- const map = this._mapEl?.map;
72
- if (!map) return;
73
- if (map.getLayer(this._layerId)) map.removeLayer(this._layerId);
74
- if (map.getSource(this._sourceId)) map.removeSource(this._sourceId);
75
- }
76
- updated(changed) {
77
- const map = this._mapEl?.map;
78
- if (!map) return;
79
- if (changed.has("positions")) {
80
- const source = map.getSource(this._sourceId);
81
- if (source) source.setData(this._toGeoJSON());
82
- }
83
- if (changed.has("color") && map.getLayer(this._layerId)) map.setPaintProperty(this._layerId, "line-color", this.color);
84
- if (changed.has("width") && map.getLayer(this._layerId)) map.setPaintProperty(this._layerId, "line-width", this.width);
85
- if (changed.has("opacity") && map.getLayer(this._layerId)) map.setPaintProperty(this._layerId, "line-opacity", this.opacity);
86
- }
87
- render() {
88
- return html``;
89
- }
90
- };
91
- __decorate([property({ attribute: false })], SigveloMaplibrePolyline.prototype, "positions", void 0);
92
- __decorate([property()], SigveloMaplibrePolyline.prototype, "color", void 0);
93
- __decorate([property({ type: Number })], SigveloMaplibrePolyline.prototype, "width", void 0);
94
- __decorate([property({ type: Number })], SigveloMaplibrePolyline.prototype, "opacity", void 0);
95
- __decorate([property({ attribute: false })], SigveloMaplibrePolyline.prototype, "dashArray", void 0);
96
- SigveloMaplibrePolyline = __decorate([customElement("sigvelo-maplibre-polyline")], SigveloMaplibrePolyline);
97
- //#endregion
98
- export { SigveloMaplibrePolyline as t };
@@ -1,30 +0,0 @@
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/popup/popup.styles.ts
5
- var popup_styles_default = css`
6
- :host {
7
- display: none;
8
- }
9
- `;
10
- //#endregion
11
- //#region src/components/popup/popup.ts
12
- let SigveloMaplibrePopup = class SigveloMaplibrePopup extends LitElement {
13
- constructor(..._args) {
14
- super(..._args);
15
- this.maxWidth = 300;
16
- }
17
- static {
18
- this.styles = [popup_styles_default];
19
- }
20
- render() {
21
- return html` <slot></slot> `;
22
- }
23
- };
24
- __decorate([property({
25
- attribute: "max-width",
26
- type: Number
27
- })], SigveloMaplibrePopup.prototype, "maxWidth", void 0);
28
- SigveloMaplibrePopup = __decorate([customElement("sigvelo-maplibre-popup")], SigveloMaplibrePopup);
29
- //#endregion
30
- export { SigveloMaplibrePopup as t };
@@ -1,58 +0,0 @@
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/scale-control/scale-control.styles.ts
6
- var scale_control_styles_default = css`
7
- :host {
8
- display: none;
9
- }
10
- `;
11
- //#endregion
12
- //#region src/components/scale-control/scale-control.ts
13
- let SigveloMaplibreScaleControl = class SigveloMaplibreScaleControl extends LitElement {
14
- constructor(..._args) {
15
- super(..._args);
16
- this.position = "bottom-left";
17
- this.unit = "metric";
18
- this.maxWidth = 100;
19
- this._control = null;
20
- this._mapEl = null;
21
- }
22
- static {
23
- this.styles = [scale_control_styles_default];
24
- }
25
- async connectedCallback() {
26
- super.connectedCallback();
27
- this._mapEl = this.closest("sigvelo-maplibre-map");
28
- if (this._mapEl) {
29
- await this._mapEl.mapReady;
30
- this._addControl();
31
- }
32
- }
33
- disconnectedCallback() {
34
- super.disconnectedCallback();
35
- if (this._control && this._mapEl?.map) this._mapEl.map.removeControl(this._control);
36
- this._control = null;
37
- }
38
- _addControl() {
39
- if (!this._mapEl?.map) return;
40
- this._control = new maplibregl.ScaleControl({
41
- maxWidth: this.maxWidth,
42
- unit: this.unit
43
- });
44
- this._mapEl.map.addControl(this._control, this.position);
45
- }
46
- render() {
47
- return html``;
48
- }
49
- };
50
- __decorate([property()], SigveloMaplibreScaleControl.prototype, "position", void 0);
51
- __decorate([property()], SigveloMaplibreScaleControl.prototype, "unit", void 0);
52
- __decorate([property({
53
- attribute: "max-width",
54
- type: Number
55
- })], SigveloMaplibreScaleControl.prototype, "maxWidth", void 0);
56
- SigveloMaplibreScaleControl = __decorate([customElement("sigvelo-maplibre-scale-control")], SigveloMaplibreScaleControl);
57
- //#endregion
58
- export { SigveloMaplibreScaleControl as t };
@@ -1,85 +0,0 @@
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/tilelayer/tilelayer.styles.ts
5
- var tilelayer_styles_default = css`
6
- :host {
7
- display: none;
8
- }
9
- `;
10
- //#endregion
11
- //#region src/components/tilelayer/tilelayer.ts
12
- let SigveloMaplibreTilelayer = class SigveloMaplibreTilelayer extends LitElement {
13
- constructor(..._args) {
14
- super(..._args);
15
- this.styleUrl = "";
16
- this.url = "";
17
- this.attribution = "";
18
- this.opacity = 1;
19
- this._rasterSourceId = "sigvelo-raster-source";
20
- this._rasterLayerId = "sigvelo-raster-layer";
21
- this._mapEl = null;
22
- }
23
- static {
24
- this.styles = [tilelayer_styles_default];
25
- }
26
- async connectedCallback() {
27
- super.connectedCallback();
28
- this._mapEl = this.closest("sigvelo-maplibre-map");
29
- if (this._mapEl) {
30
- await this._mapEl.mapReady;
31
- this._applyTiles();
32
- }
33
- }
34
- disconnectedCallback() {
35
- super.disconnectedCallback();
36
- this._removeRasterLayer();
37
- }
38
- _applyTiles() {
39
- const map = this._mapEl?.map;
40
- if (!map) return;
41
- if (this.styleUrl) map.setStyle(this.styleUrl);
42
- else if (this.url) this._addRasterLayer();
43
- }
44
- _addRasterLayer() {
45
- const map = this._mapEl?.map;
46
- if (!map || !this.url) return;
47
- if (!map.isStyleLoaded()) return;
48
- this._removeRasterLayer();
49
- map.addSource(this._rasterSourceId, {
50
- type: "raster",
51
- tiles: [this.url],
52
- tileSize: 256,
53
- attribution: this.attribution || void 0
54
- });
55
- map.addLayer({
56
- id: this._rasterLayerId,
57
- type: "raster",
58
- source: this._rasterSourceId,
59
- paint: { "raster-opacity": this.opacity }
60
- });
61
- }
62
- _removeRasterLayer() {
63
- const map = this._mapEl?.map;
64
- if (!map) return;
65
- if (map.getLayer(this._rasterLayerId)) map.removeLayer(this._rasterLayerId);
66
- if (map.getSource(this._rasterSourceId)) map.removeSource(this._rasterSourceId);
67
- }
68
- updated(changed) {
69
- if (changed.has("styleUrl") || changed.has("url")) this._applyTiles();
70
- if (changed.has("opacity") && this._mapEl?.map) {
71
- const map = this._mapEl.map;
72
- if (map.getLayer(this._rasterLayerId)) map.setPaintProperty(this._rasterLayerId, "raster-opacity", this.opacity);
73
- }
74
- }
75
- render() {
76
- return html``;
77
- }
78
- };
79
- __decorate([property({ attribute: "style-url" })], SigveloMaplibreTilelayer.prototype, "styleUrl", void 0);
80
- __decorate([property()], SigveloMaplibreTilelayer.prototype, "url", void 0);
81
- __decorate([property()], SigveloMaplibreTilelayer.prototype, "attribution", void 0);
82
- __decorate([property({ type: Number })], SigveloMaplibreTilelayer.prototype, "opacity", void 0);
83
- SigveloMaplibreTilelayer = __decorate([customElement("sigvelo-maplibre-tilelayer")], SigveloMaplibreTilelayer);
84
- //#endregion
85
- export { SigveloMaplibreTilelayer as t };