@mcp-b/geo-maplibre 0.2.22 → 0.3.1

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,2 +1,138 @@
1
- import { t as SigveloMaplibreCircle } from "../../circle-CFH3gDcY.js";
1
+ import { t as __decorate } from "../../decorate-DcF3lt7P.js";
2
+ import { LitElement, html } from "lit";
3
+ import { customElement, property } from "lit/decorators.js";
4
+ import { findMapElement } from "@mcp-b/geo-support/base/find-map-element";
5
+ import styles from "@mcp-b/geo-support/styles/map-child.styles";
6
+ //#region src/components/circle/circle.ts
7
+ let circleCounter = 0;
8
+ /**
9
+ * Creates a GeoJSON polygon approximation of a circle on the map.
10
+ * @param lng - Center longitude
11
+ * @param lat - Center latitude
12
+ * @param radiusMeters - Radius in meters
13
+ * @param steps - Number of polygon vertices
14
+ */
15
+ function createCirclePolygon(lng, lat, radiusMeters, steps = 64) {
16
+ const coords = [];
17
+ const earthRadius = 6371008.8;
18
+ const latRad = lat * Math.PI / 180;
19
+ for (let i = 0; i <= steps; i++) {
20
+ const angle = i * 2 * Math.PI / steps;
21
+ const dLat = radiusMeters / earthRadius * Math.cos(angle);
22
+ const dLng = radiusMeters / (earthRadius * Math.cos(latRad)) * Math.sin(angle);
23
+ coords.push([lng + dLng * 180 / Math.PI, lat + dLat * 180 / Math.PI]);
24
+ }
25
+ return {
26
+ type: "Feature",
27
+ geometry: {
28
+ type: "Polygon",
29
+ coordinates: [coords]
30
+ },
31
+ properties: {}
32
+ };
33
+ }
34
+ let SigveloMaplibreCircle = class SigveloMaplibreCircle extends LitElement {
35
+ static {
36
+ this.styles = [styles];
37
+ }
38
+ constructor() {
39
+ super();
40
+ this.latitude = 0;
41
+ this.longitude = 0;
42
+ this.radius = 100;
43
+ this.fillColor = "#3388ff";
44
+ this.fillOpacity = .2;
45
+ this.strokeColor = "#3388ff";
46
+ this.strokeWidth = 2;
47
+ this._mapEl = null;
48
+ const id = ++circleCounter;
49
+ this._sourceId = `sigvelo-circle-source-${id}`;
50
+ this._fillLayerId = `sigvelo-circle-fill-${id}`;
51
+ this._strokeLayerId = `sigvelo-circle-stroke-${id}`;
52
+ }
53
+ async connectedCallback() {
54
+ super.connectedCallback();
55
+ this._mapEl = findMapElement(this, "sigvelo-maplibre-map");
56
+ await this._mapEl?.whenMapReady(this, () => this._addCircle());
57
+ }
58
+ disconnectedCallback() {
59
+ super.disconnectedCallback();
60
+ this._removeCircle();
61
+ }
62
+ _buildGeoJSON() {
63
+ return createCirclePolygon(this.longitude, this.latitude, this.radius);
64
+ }
65
+ _addCircle() {
66
+ const map = this._mapEl?.map;
67
+ if (!map) return;
68
+ map.addSource(this._sourceId, {
69
+ type: "geojson",
70
+ data: this._buildGeoJSON()
71
+ });
72
+ map.addLayer({
73
+ id: this._fillLayerId,
74
+ type: "fill",
75
+ source: this._sourceId,
76
+ paint: {
77
+ "fill-color": this.fillColor,
78
+ "fill-opacity": this.fillOpacity
79
+ }
80
+ });
81
+ map.addLayer({
82
+ id: this._strokeLayerId,
83
+ type: "line",
84
+ source: this._sourceId,
85
+ paint: {
86
+ "line-color": this.strokeColor,
87
+ "line-width": this.strokeWidth
88
+ }
89
+ });
90
+ }
91
+ _removeCircle() {
92
+ const map = this._mapEl?.map;
93
+ if (!map) return;
94
+ for (const id of [this._fillLayerId, this._strokeLayerId]) if (map.getLayer(id)) map.removeLayer(id);
95
+ if (map.getSource(this._sourceId)) map.removeSource(this._sourceId);
96
+ }
97
+ _updateSource() {
98
+ const map = this._mapEl?.map;
99
+ if (!map) return;
100
+ const source = map.getSource(this._sourceId);
101
+ if (source) source.setData(this._buildGeoJSON());
102
+ }
103
+ updated(changed) {
104
+ if (!this._mapEl?.map) return;
105
+ if (changed.has("latitude") || changed.has("longitude") || changed.has("radius")) this._updateSource();
106
+ if (changed.has("fillColor") || changed.has("fillOpacity")) {
107
+ if (this._mapEl.map.getLayer(this._fillLayerId)) {
108
+ this._mapEl.map.setPaintProperty(this._fillLayerId, "fill-color", this.fillColor);
109
+ this._mapEl.map.setPaintProperty(this._fillLayerId, "fill-opacity", this.fillOpacity);
110
+ }
111
+ }
112
+ if (changed.has("strokeColor") || changed.has("strokeWidth")) {
113
+ if (this._mapEl.map.getLayer(this._strokeLayerId)) {
114
+ this._mapEl.map.setPaintProperty(this._strokeLayerId, "line-color", this.strokeColor);
115
+ this._mapEl.map.setPaintProperty(this._strokeLayerId, "line-width", this.strokeWidth);
116
+ }
117
+ }
118
+ }
119
+ render() {
120
+ return html``;
121
+ }
122
+ };
123
+ __decorate([property({ type: Number })], SigveloMaplibreCircle.prototype, "latitude", void 0);
124
+ __decorate([property({ type: Number })], SigveloMaplibreCircle.prototype, "longitude", void 0);
125
+ __decorate([property({ type: Number })], SigveloMaplibreCircle.prototype, "radius", void 0);
126
+ __decorate([property({ attribute: "fill-color" })], SigveloMaplibreCircle.prototype, "fillColor", void 0);
127
+ __decorate([property({
128
+ attribute: "fill-opacity",
129
+ type: Number
130
+ })], SigveloMaplibreCircle.prototype, "fillOpacity", void 0);
131
+ __decorate([property({ attribute: "stroke-color" })], SigveloMaplibreCircle.prototype, "strokeColor", void 0);
132
+ __decorate([property({
133
+ attribute: "stroke-width",
134
+ type: Number
135
+ })], SigveloMaplibreCircle.prototype, "strokeWidth", void 0);
136
+ SigveloMaplibreCircle = __decorate([customElement("sigvelo-maplibre-circle")], SigveloMaplibreCircle);
137
+ //#endregion
2
138
  export { SigveloMaplibreCircle };
@@ -1,12 +1,14 @@
1
- import { LitElement } from "lit";
1
+ import { LitElement, PropertyValues } from "lit";
2
+ import { ControlPosition } from "@mcp-b/geo-support/types";
2
3
 
3
4
  //#region src/components/control/control.d.ts
4
- type ControlPosition = "top-left" | "top-right" | "bottom-left" | "bottom-right";
5
5
  /**
6
6
  * A generic control container for a MapLibre map. Wraps arbitrary content
7
7
  * and places it in one of MapLibre's four control corners, stacking properly
8
8
  * with navigation, attribution, and other controls.
9
9
  *
10
+ * @slot - Control content, retained in the control’s light DOM.
11
+ *
10
12
  * @tag sigvelo-maplibre-control
11
13
  *
12
14
  * @example
@@ -23,12 +25,15 @@ declare class SigveloMaplibreControl extends LitElement {
23
25
  static styles: import("lit").CSSResult[];
24
26
  /** Position of the control on the map. */
25
27
  position: ControlPosition;
28
+ private _stopPlacement;
26
29
  /** @internal */
27
30
  private _control;
28
31
  /** @internal */
29
32
  private _mapEl;
30
33
  connectedCallback(): Promise<void>;
31
34
  disconnectedCallback(): void;
35
+ private _removeControl;
36
+ protected updated(changed: PropertyValues): void;
32
37
  /** @internal */
33
38
  private _addControl;
34
39
  render(): import("lit-html").TemplateResult<1>;
@@ -1,2 +1,67 @@
1
- import { t as SigveloMaplibreControl } from "../../control-Bka68vGo.js";
1
+ import { t as __decorate } from "../../decorate-DcF3lt7P.js";
2
+ import { LitElement, html } from "lit";
3
+ import { customElement, property } from "lit/decorators.js";
4
+ import { findMapElement } from "@mcp-b/geo-support/base/find-map-element";
5
+ import { placeControl } from "@mcp-b/geo-support/base/control-placement";
6
+ import styles from "@mcp-b/geo-support/styles/control.styles";
7
+ //#region src/components/control/control.ts
8
+ let SigveloMaplibreControl = class SigveloMaplibreControl extends LitElement {
9
+ constructor(..._args) {
10
+ super(..._args);
11
+ this.position = "bottom-left";
12
+ this._stopPlacement = null;
13
+ this._control = null;
14
+ this._mapEl = null;
15
+ }
16
+ static {
17
+ this.styles = [styles];
18
+ }
19
+ async connectedCallback() {
20
+ super.connectedCallback();
21
+ this._mapEl = findMapElement(this, "sigvelo-maplibre-map");
22
+ await this._mapEl?.whenMapReady(this, () => {
23
+ if (!this._control) this._addControl();
24
+ });
25
+ }
26
+ disconnectedCallback() {
27
+ super.disconnectedCallback();
28
+ this._removeControl();
29
+ }
30
+ _removeControl() {
31
+ this._stopPlacement?.();
32
+ this._stopPlacement = null;
33
+ if (this._control && this._mapEl?.map) this._mapEl.map.removeControl(this._control);
34
+ this._control = null;
35
+ }
36
+ updated(changed) {
37
+ if (changed.has("position") && this._control) {
38
+ this._removeControl();
39
+ this._addControl();
40
+ }
41
+ }
42
+ /** @internal */
43
+ _addControl() {
44
+ const map = this._mapEl?.map;
45
+ if (!map) return;
46
+ let container;
47
+ this._control = {
48
+ onAdd: () => {
49
+ container = document.createElement("div");
50
+ container.className = "maplibregl-ctrl sigvelo-maplibre-custom-control";
51
+ return container;
52
+ },
53
+ onRemove: () => {
54
+ container?.remove();
55
+ }
56
+ };
57
+ map.addControl(this._control, this.position);
58
+ this._stopPlacement = placeControl(this, container, this._mapEl);
59
+ }
60
+ render() {
61
+ return html` <slot></slot> `;
62
+ }
63
+ };
64
+ __decorate([property()], SigveloMaplibreControl.prototype, "position", void 0);
65
+ SigveloMaplibreControl = __decorate([customElement("sigvelo-maplibre-control")], SigveloMaplibreControl);
66
+ //#endregion
2
67
  export { SigveloMaplibreControl };
@@ -1,2 +1,235 @@
1
- import { t as SigveloMaplibreGeojson } from "../../geojson-BW9JQxtv.js";
1
+ import { t as __decorate } from "../../decorate-DcF3lt7P.js";
2
+ import { LitElement, html } from "lit";
3
+ import { customElement, property } from "lit/decorators.js";
4
+ import { SigveloFeatureClickEvent } from "@mcp-b/geo-support/events";
5
+ import { findMapElement } from "@mcp-b/geo-support/base/find-map-element";
6
+ import styles from "@mcp-b/geo-support/styles/map-child.styles";
7
+ import { subscribeClassify } from "@mcp-b/geo-support/classification";
8
+ //#region src/components/geojson/geojson.ts
9
+ let sourceCounter = 0;
10
+ let SigveloMaplibreGeojson = class SigveloMaplibreGeojson extends LitElement {
11
+ static {
12
+ this.styles = [styles];
13
+ }
14
+ constructor() {
15
+ super();
16
+ this.data = null;
17
+ this.styleFunction = null;
18
+ this.fillColor = "#3388ff";
19
+ this.fillOpacity = .2;
20
+ this.strokeColor = "#3388ff";
21
+ this.strokeWidth = 2;
22
+ this.circleRadius = 6;
23
+ this.interactive = true;
24
+ this.channel = "";
25
+ this._mapEl = null;
26
+ this._onStyleLoad = () => this._addSource();
27
+ this._unsubscribeChannel = null;
28
+ const id = ++sourceCounter;
29
+ this._sourceId = `sigvelo-geojson-source-${id}`;
30
+ this._fillLayerId = `sigvelo-geojson-fill-${id}`;
31
+ this._lineLayerId = `sigvelo-geojson-line-${id}`;
32
+ this._circleLayerId = `sigvelo-geojson-circle-${id}`;
33
+ }
34
+ async connectedCallback() {
35
+ super.connectedCallback();
36
+ this._subscribeChannel();
37
+ this._mapEl = findMapElement(this, "sigvelo-maplibre-map");
38
+ await this._mapEl?.whenMapReady(this, () => {
39
+ this._mapEl?.map?.on("style.load", this._onStyleLoad);
40
+ this._addSource();
41
+ });
42
+ }
43
+ disconnectedCallback() {
44
+ super.disconnectedCallback();
45
+ this._unsubscribeChannel?.();
46
+ this._unsubscribeChannel = null;
47
+ this._mapEl?.map?.off("style.load", this._onStyleLoad);
48
+ this._removeSource();
49
+ }
50
+ /** @internal */
51
+ _subscribeChannel() {
52
+ this._unsubscribeChannel?.();
53
+ this._unsubscribeChannel = null;
54
+ if (!this.isConnected || !this.channel) return;
55
+ this._unsubscribeChannel = subscribeClassify(this.channel, (detail) => {
56
+ this.styleFunction = detail.styleFunction;
57
+ });
58
+ }
59
+ /**
60
+ * When styleFunction is set, clone the data and inject computed style
61
+ * properties into each feature so MapLibre can use data-driven expressions.
62
+ * @internal
63
+ */
64
+ _prepareData() {
65
+ if (!this.data) return null;
66
+ if (!this.styleFunction) return this.data;
67
+ const clone = JSON.parse(JSON.stringify(this.data));
68
+ const features = clone.type === "FeatureCollection" ? clone.features : [clone];
69
+ for (const feature of features) {
70
+ const s = this.styleFunction(feature);
71
+ if (s) {
72
+ feature.properties = feature.properties ?? {};
73
+ if (s.fillColor != null) feature.properties._sigvelo_fill_color = s.fillColor;
74
+ if (s.fillOpacity != null) feature.properties._sigvelo_fill_opacity = s.fillOpacity;
75
+ if (s.strokeColor != null) feature.properties._sigvelo_stroke_color = s.strokeColor;
76
+ if (s.strokeWidth != null) feature.properties._sigvelo_stroke_width = s.strokeWidth;
77
+ }
78
+ }
79
+ return clone;
80
+ }
81
+ _addSource() {
82
+ const map = this._mapEl?.map;
83
+ if (!this.isConnected || !map || !this.data) return;
84
+ if (!map.isStyleLoaded()) return;
85
+ this._removeSource();
86
+ const processedData = this._prepareData();
87
+ if (!processedData) return;
88
+ map.addSource(this._sourceId, {
89
+ type: "geojson",
90
+ data: processedData
91
+ });
92
+ const hasStyleFn = this.styleFunction != null;
93
+ map.addLayer({
94
+ id: this._fillLayerId,
95
+ type: "fill",
96
+ source: this._sourceId,
97
+ paint: {
98
+ "fill-color": hasStyleFn ? [
99
+ "coalesce",
100
+ ["get", "_sigvelo_fill_color"],
101
+ this.fillColor
102
+ ] : this.fillColor,
103
+ "fill-opacity": hasStyleFn ? [
104
+ "coalesce",
105
+ ["get", "_sigvelo_fill_opacity"],
106
+ this.fillOpacity
107
+ ] : this.fillOpacity
108
+ },
109
+ filter: [
110
+ "==",
111
+ "$type",
112
+ "Polygon"
113
+ ]
114
+ });
115
+ map.addLayer({
116
+ id: this._lineLayerId,
117
+ type: "line",
118
+ source: this._sourceId,
119
+ paint: {
120
+ "line-color": hasStyleFn ? [
121
+ "coalesce",
122
+ ["get", "_sigvelo_stroke_color"],
123
+ this.strokeColor
124
+ ] : this.strokeColor,
125
+ "line-width": hasStyleFn ? [
126
+ "coalesce",
127
+ ["get", "_sigvelo_stroke_width"],
128
+ this.strokeWidth
129
+ ] : this.strokeWidth
130
+ },
131
+ filter: [
132
+ "any",
133
+ [
134
+ "==",
135
+ "$type",
136
+ "LineString"
137
+ ],
138
+ [
139
+ "==",
140
+ "$type",
141
+ "Polygon"
142
+ ]
143
+ ]
144
+ });
145
+ map.addLayer({
146
+ id: this._circleLayerId,
147
+ type: "circle",
148
+ source: this._sourceId,
149
+ paint: {
150
+ "circle-color": hasStyleFn ? [
151
+ "coalesce",
152
+ ["get", "_sigvelo_fill_color"],
153
+ this.fillColor
154
+ ] : this.fillColor,
155
+ "circle-radius": this.circleRadius,
156
+ "circle-stroke-color": hasStyleFn ? [
157
+ "coalesce",
158
+ ["get", "_sigvelo_stroke_color"],
159
+ this.strokeColor
160
+ ] : this.strokeColor,
161
+ "circle-stroke-width": hasStyleFn ? [
162
+ "coalesce",
163
+ ["get", "_sigvelo_stroke_width"],
164
+ this.strokeWidth
165
+ ] : this.strokeWidth
166
+ },
167
+ filter: [
168
+ "==",
169
+ "$type",
170
+ "Point"
171
+ ]
172
+ });
173
+ if (this.interactive) {
174
+ const layerIds = [
175
+ this._fillLayerId,
176
+ this._lineLayerId,
177
+ this._circleLayerId
178
+ ];
179
+ for (const layerId of layerIds) map.on("click", layerId, (e) => {
180
+ const feature = e.features?.[0];
181
+ if (!feature) return;
182
+ this.dispatchEvent(new SigveloFeatureClickEvent({
183
+ type: "Feature",
184
+ geometry: feature.geometry,
185
+ properties: feature.properties ?? null,
186
+ id: feature.id
187
+ }, {
188
+ lat: e.lngLat.lat,
189
+ lng: e.lngLat.lng
190
+ }));
191
+ });
192
+ }
193
+ }
194
+ _removeSource() {
195
+ const map = this._mapEl?.map;
196
+ if (!map) return;
197
+ for (const id of [
198
+ this._fillLayerId,
199
+ this._lineLayerId,
200
+ this._circleLayerId
201
+ ]) if (map.getLayer(id)) map.removeLayer(id);
202
+ if (map.getSource(this._sourceId)) map.removeSource(this._sourceId);
203
+ }
204
+ updated(changed) {
205
+ if (changed.has("channel")) this._subscribeChannel();
206
+ if (changed.has("data") || changed.has("styleFunction") || changed.has("fillColor") || changed.has("fillOpacity") || changed.has("strokeColor") || changed.has("strokeWidth") || changed.has("circleRadius")) {
207
+ this._removeSource();
208
+ this._addSource();
209
+ }
210
+ }
211
+ render() {
212
+ return html``;
213
+ }
214
+ };
215
+ __decorate([property({ attribute: false })], SigveloMaplibreGeojson.prototype, "data", void 0);
216
+ __decorate([property({ attribute: false })], SigveloMaplibreGeojson.prototype, "styleFunction", void 0);
217
+ __decorate([property({ attribute: "fill-color" })], SigveloMaplibreGeojson.prototype, "fillColor", void 0);
218
+ __decorate([property({
219
+ attribute: "fill-opacity",
220
+ type: Number
221
+ })], SigveloMaplibreGeojson.prototype, "fillOpacity", void 0);
222
+ __decorate([property({ attribute: "stroke-color" })], SigveloMaplibreGeojson.prototype, "strokeColor", void 0);
223
+ __decorate([property({
224
+ attribute: "stroke-width",
225
+ type: Number
226
+ })], SigveloMaplibreGeojson.prototype, "strokeWidth", void 0);
227
+ __decorate([property({
228
+ attribute: "circle-radius",
229
+ type: Number
230
+ })], SigveloMaplibreGeojson.prototype, "circleRadius", void 0);
231
+ __decorate([property({ type: Boolean })], SigveloMaplibreGeojson.prototype, "interactive", void 0);
232
+ __decorate([property()], SigveloMaplibreGeojson.prototype, "channel", void 0);
233
+ SigveloMaplibreGeojson = __decorate([customElement("sigvelo-maplibre-geojson")], SigveloMaplibreGeojson);
234
+ //#endregion
2
235
  export { SigveloMaplibreGeojson };
@@ -1,2 +1,53 @@
1
- import { t as SigveloMaplibreLayer } from "../../layer-COvBRP1h.js";
1
+ import { t as __decorate } from "../../decorate-DcF3lt7P.js";
2
+ import { LitElement, html } from "lit";
3
+ import { customElement, property } from "lit/decorators.js";
4
+ import { findMapElement } from "@mcp-b/geo-support/base/find-map-element";
5
+ import styles from "@mcp-b/geo-support/styles/map-child.styles";
6
+ //#region src/components/layer/layer.ts
7
+ let SigveloMaplibreLayer = class SigveloMaplibreLayer extends LitElement {
8
+ constructor(..._args) {
9
+ super(..._args);
10
+ this.spec = null;
11
+ this.beforeId = "";
12
+ this._mapEl = null;
13
+ this._addedLayerId = null;
14
+ }
15
+ static {
16
+ this.styles = [styles];
17
+ }
18
+ async connectedCallback() {
19
+ super.connectedCallback();
20
+ this._mapEl = findMapElement(this, "sigvelo-maplibre-map");
21
+ await this._mapEl?.whenMapReady(this, () => this._addLayer());
22
+ }
23
+ disconnectedCallback() {
24
+ super.disconnectedCallback();
25
+ this._removeLayer();
26
+ }
27
+ _addLayer() {
28
+ const map = this._mapEl?.map;
29
+ if (!map || !this.spec) return;
30
+ map.addLayer(this.spec, this.beforeId || void 0);
31
+ this._addedLayerId = this.spec.id;
32
+ }
33
+ _removeLayer() {
34
+ const map = this._mapEl?.map;
35
+ if (!map || !this._addedLayerId) return;
36
+ if (map.getLayer(this._addedLayerId)) map.removeLayer(this._addedLayerId);
37
+ this._addedLayerId = null;
38
+ }
39
+ updated(changed) {
40
+ if (changed.has("spec")) {
41
+ this._removeLayer();
42
+ this._addLayer();
43
+ }
44
+ }
45
+ render() {
46
+ return html``;
47
+ }
48
+ };
49
+ __decorate([property({ attribute: false })], SigveloMaplibreLayer.prototype, "spec", void 0);
50
+ __decorate([property({ attribute: "before-id" })], SigveloMaplibreLayer.prototype, "beforeId", void 0);
51
+ SigveloMaplibreLayer = __decorate([customElement("sigvelo-maplibre-layer")], SigveloMaplibreLayer);
52
+ //#endregion
2
53
  export { SigveloMaplibreLayer };
@@ -1,2 +1,122 @@
1
- import { t as SigveloMaplibreMap } from "../../map-CYqh-osb.js";
1
+ import { t as __decorate } from "../../decorate-DcF3lt7P.js";
2
+ import { 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.ts
9
+ /** Empty style used when no tilelayer child provides a style-url. */
10
+ const EMPTY_STYLE = {
11
+ version: 8,
12
+ sources: {},
13
+ layers: []
14
+ };
15
+ let SigveloMaplibreMap = class SigveloMaplibreMap extends GeoMapElement {
16
+ constructor(..._args) {
17
+ super(..._args);
18
+ this.navControl = true;
19
+ this._map = null;
20
+ }
21
+ static {
22
+ this.styles = [...GeoMapElement.styles, unsafeCSS(maplibreCss)];
23
+ }
24
+ /** Access the underlying MapLibre map instance (after mapReady resolves). */
25
+ get map() {
26
+ return this._map;
27
+ }
28
+ createMap(container) {
29
+ this._map = new maplibregl.Map({
30
+ container,
31
+ style: EMPTY_STYLE,
32
+ center: [this.longitude, this.latitude],
33
+ zoom: this.zoom,
34
+ minZoom: this.minZoom,
35
+ maxZoom: this.maxZoom,
36
+ bearing: this.bearing,
37
+ pitch: this.pitch
38
+ });
39
+ if (this.navControl) this._map.addControl(new maplibregl.NavigationControl());
40
+ this._map.on("click", (e) => {
41
+ this.dispatchEvent(new SigveloMapClickEvent({
42
+ lat: e.lngLat.lat,
43
+ lng: e.lngLat.lng
44
+ }, e.originalEvent));
45
+ });
46
+ this._map.on("move", () => {
47
+ if (!this._map) return;
48
+ const center = this._map.getCenter();
49
+ this._suppressExternalUpdate = true;
50
+ this.latitude = center.lat;
51
+ this.longitude = center.lng;
52
+ this._suppressExternalUpdate = false;
53
+ this.dispatchEvent(new SigveloMapMoveEvent({
54
+ lat: center.lat,
55
+ lng: center.lng
56
+ }));
57
+ });
58
+ this._map.on("moveend", () => {
59
+ if (!this._map) return;
60
+ const center = this._map.getCenter();
61
+ this.dispatchEvent(new SigveloMapMoveEndEvent({
62
+ lat: center.lat,
63
+ lng: center.lng
64
+ }));
65
+ });
66
+ this._map.on("zoom", () => {
67
+ if (!this._map) return;
68
+ const zoom = this._map.getZoom();
69
+ this._suppressExternalUpdate = true;
70
+ this.zoom = zoom;
71
+ this._suppressExternalUpdate = false;
72
+ this.dispatchEvent(new SigveloMapZoomEvent(zoom));
73
+ });
74
+ this._map.on("zoomend", () => {
75
+ if (!this._map) return;
76
+ this.dispatchEvent(new SigveloMapZoomEndEvent(this._map.getZoom()));
77
+ });
78
+ this._map.on("load", () => {
79
+ this._resolveMapReady();
80
+ this.dispatchEvent(new SigveloMapLoadEvent());
81
+ });
82
+ }
83
+ destroyMap() {
84
+ this._map?.remove();
85
+ this._map = null;
86
+ }
87
+ updateView(changed) {
88
+ if (!this._map) return;
89
+ if (changed.has("latitude") || changed.has("longitude")) this._map.setCenter([this.longitude, this.latitude]);
90
+ if (changed.has("zoom")) this._map.setZoom(this.zoom);
91
+ if (changed.has("bearing")) this._map.setBearing(this.bearing);
92
+ if (changed.has("pitch")) this._map.setPitch(this.pitch);
93
+ if (changed.has("minZoom")) this._map.setMinZoom(this.minZoom);
94
+ if (changed.has("maxZoom")) this._map.setMaxZoom(this.maxZoom);
95
+ }
96
+ invalidateSize() {
97
+ this._map?.resize();
98
+ }
99
+ flyTo(options) {
100
+ this._map?.flyTo({
101
+ center: [options.center.lng, options.center.lat],
102
+ zoom: options.zoom,
103
+ bearing: options.bearing,
104
+ pitch: options.pitch,
105
+ duration: options.duration
106
+ });
107
+ }
108
+ fitBounds(options) {
109
+ this._map?.fitBounds([[options.bounds.west, options.bounds.south], [options.bounds.east, options.bounds.north]], {
110
+ padding: options.padding,
111
+ maxZoom: options.maxZoom,
112
+ duration: options.duration
113
+ });
114
+ }
115
+ };
116
+ __decorate([property({
117
+ attribute: "nav-control",
118
+ type: Boolean
119
+ })], SigveloMaplibreMap.prototype, "navControl", void 0);
120
+ SigveloMaplibreMap = __decorate([customElement("sigvelo-maplibre-map")], SigveloMaplibreMap);
121
+ //#endregion
2
122
  export { SigveloMaplibreMap };