@mcp-b/geo-openlayers 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,59 +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 Control from "ol/control/Control.js";
5
- //#region src/components/control/control.styles.ts
6
- var control_styles_default = css`
7
- :host {
8
- display: none;
9
- }
10
- `;
11
- //#endregion
12
- //#region src/components/control/control.ts
13
- const POSITION_CSS = {
14
- "top-left": "top: 0.5em; left: 0.5em;",
15
- "top-right": "top: 0.5em; right: 0.5em;",
16
- "bottom-left": "bottom: 0.5em; left: 0.5em;",
17
- "bottom-right": "bottom: 0.5em; right: 0.5em;"
18
- };
19
- let SigveloOlControl = class SigveloOlControl extends LitElement {
20
- constructor(..._args) {
21
- super(..._args);
22
- this.position = "bottom-left";
23
- this._control = null;
24
- this._mapEl = null;
25
- }
26
- static {
27
- this.styles = [control_styles_default];
28
- }
29
- async connectedCallback() {
30
- super.connectedCallback();
31
- this._mapEl = this.closest("sigvelo-ol-map");
32
- if (this._mapEl) {
33
- await this._mapEl.mapReady;
34
- this._addControl();
35
- }
36
- }
37
- disconnectedCallback() {
38
- super.disconnectedCallback();
39
- if (this._control && this._mapEl?.map) this._mapEl.map.removeControl(this._control);
40
- this._control = null;
41
- }
42
- /** @internal */
43
- _addControl() {
44
- if (!this._mapEl?.map) return;
45
- const container = document.createElement("div");
46
- container.className = "ol-control sigvelo-ol-custom-control";
47
- container.style.cssText = `position: absolute; ${POSITION_CSS[this.position]} pointer-events: auto;`;
48
- for (const child of Array.from(this.children)) container.appendChild(child);
49
- this._control = new Control({ element: container });
50
- this._mapEl.map.addControl(this._control);
51
- }
52
- render() {
53
- return html` <slot></slot> `;
54
- }
55
- };
56
- __decorate([property()], SigveloOlControl.prototype, "position", void 0);
57
- SigveloOlControl = __decorate([customElement("sigvelo-ol-control")], SigveloOlControl);
58
- //#endregion
59
- export { SigveloOlControl as t };
@@ -1,184 +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 { SigveloFeatureClickEvent } from "@mcp-b/geo-support/events";
5
- import { toLonLat } from "ol/proj.js";
6
- import { subscribeClassify } from "@mcp-b/geo-support/classification";
7
- import VectorLayer from "ol/layer/Vector.js";
8
- import VectorSource from "ol/source/Vector.js";
9
- import GeoJSON from "ol/format/GeoJSON.js";
10
- import { Circle, Fill, Stroke, Style } from "ol/style.js";
11
- //#region src/components/geojson/geojson.styles.ts
12
- var geojson_styles_default = css`
13
- :host {
14
- display: none;
15
- }
16
- `;
17
- //#endregion
18
- //#region src/components/geojson/geojson.ts
19
- let SigveloOlGeojson = class SigveloOlGeojson extends LitElement {
20
- constructor(..._args) {
21
- super(..._args);
22
- this.data = null;
23
- this.styleFunction = null;
24
- this.fillColor = "#3388ff";
25
- this.fillOpacity = .2;
26
- this.strokeColor = "#3388ff";
27
- this.strokeWidth = 2;
28
- this.circleRadius = 6;
29
- this.interactive = true;
30
- this.channel = "";
31
- this._layer = null;
32
- this._mapEl = null;
33
- this._unsubscribeChannel = null;
34
- }
35
- static {
36
- this.styles = [geojson_styles_default];
37
- }
38
- async connectedCallback() {
39
- super.connectedCallback();
40
- this._subscribeChannel();
41
- this._mapEl = this.closest("sigvelo-ol-map");
42
- if (this._mapEl) {
43
- await this._mapEl.mapReady;
44
- this._addLayer();
45
- this._bindClickHandler();
46
- }
47
- }
48
- disconnectedCallback() {
49
- super.disconnectedCallback();
50
- this._unsubscribeChannel?.();
51
- this._unsubscribeChannel = null;
52
- this._removeLayer();
53
- }
54
- /** @internal */
55
- _subscribeChannel() {
56
- this._unsubscribeChannel?.();
57
- if (!this.channel) return;
58
- this._unsubscribeChannel = subscribeClassify(this.channel, (detail) => {
59
- this.styleFunction = detail.styleFunction;
60
- });
61
- }
62
- /** @internal Convert an OL Feature to a GeoJsonFeature for the styleFunction. */
63
- _toGeoJsonFeature(olFeature) {
64
- const { geometry: _g, ...rest } = olFeature.getProperties();
65
- return {
66
- type: "Feature",
67
- geometry: {
68
- type: olFeature.getGeometry()?.getType() ?? "Point",
69
- coordinates: null
70
- },
71
- properties: rest,
72
- id: olFeature.getId()
73
- };
74
- }
75
- /** @internal */
76
- _addLayer() {
77
- if (!this._mapEl?.map || !this.data) return;
78
- const source = new VectorSource({ features: new GeoJSON().readFeatures(this.data, { featureProjection: "EPSG:3857" }) });
79
- const defaultStyle = new Style({
80
- fill: new Fill({ color: this._hexToRgba(this.fillColor, this.fillOpacity) }),
81
- stroke: new Stroke({
82
- color: this.strokeColor,
83
- width: this.strokeWidth
84
- }),
85
- image: new Circle({
86
- radius: this.circleRadius,
87
- fill: new Fill({ color: this.fillColor }),
88
- stroke: new Stroke({
89
- color: this.strokeColor,
90
- width: this.strokeWidth
91
- })
92
- })
93
- });
94
- const styleFn = this.styleFunction;
95
- const olStyleFn = styleFn ? (olFeature) => {
96
- const s = styleFn(this._toGeoJsonFeature(olFeature));
97
- if (!s) return defaultStyle;
98
- return new Style({
99
- fill: new Fill({ color: this._hexToRgba(s.fillColor ?? this.fillColor, s.fillOpacity ?? this.fillOpacity) }),
100
- stroke: new Stroke({
101
- color: s.strokeColor ?? this.strokeColor,
102
- width: s.strokeWidth ?? this.strokeWidth
103
- }),
104
- image: new Circle({
105
- radius: this.circleRadius,
106
- fill: new Fill({ color: this._hexToRgba(s.fillColor ?? this.fillColor, s.fillOpacity ?? this.fillOpacity) }),
107
- stroke: new Stroke({
108
- color: s.strokeColor ?? this.strokeColor,
109
- width: s.strokeWidth ?? this.strokeWidth
110
- })
111
- })
112
- });
113
- } : defaultStyle;
114
- this._layer = new VectorLayer({
115
- source,
116
- style: olStyleFn
117
- });
118
- this._mapEl.map.addLayer(this._layer);
119
- }
120
- /** @internal */
121
- _removeLayer() {
122
- if (this._layer && this._mapEl?.map) this._mapEl.map.removeLayer(this._layer);
123
- this._layer = null;
124
- }
125
- /** @internal */
126
- _bindClickHandler() {
127
- if (!this.interactive || !this._mapEl?.map) return;
128
- this._mapEl.map.on("click", (e) => {
129
- if (!this._mapEl?.map) return;
130
- this._mapEl.map.forEachFeatureAtPixel(e.pixel, (feature) => {
131
- const geom = feature.getGeometry();
132
- if (!geom) return;
133
- const [lng, lat] = toLonLat(e.coordinate);
134
- const { geometry: _geom, ...rest } = feature.getProperties();
135
- this.dispatchEvent(new SigveloFeatureClickEvent({
136
- type: "Feature",
137
- geometry: {
138
- type: geom.getType(),
139
- coordinates: null
140
- },
141
- properties: rest,
142
- id: feature.getId()
143
- }, {
144
- lat,
145
- lng
146
- }));
147
- }, { layerFilter: (l) => l === this._layer });
148
- });
149
- }
150
- /** @internal */
151
- _hexToRgba(hex, opacity) {
152
- return `rgba(${parseInt(hex.slice(1, 3), 16)}, ${parseInt(hex.slice(3, 5), 16)}, ${parseInt(hex.slice(5, 7), 16)}, ${opacity})`;
153
- }
154
- updated(changed) {
155
- if (changed.has("data") || changed.has("styleFunction") || changed.has("fillColor") || changed.has("fillOpacity") || changed.has("strokeColor") || changed.has("strokeWidth") || changed.has("circleRadius")) {
156
- this._removeLayer();
157
- this._addLayer();
158
- }
159
- }
160
- render() {
161
- return html``;
162
- }
163
- };
164
- __decorate([property({ attribute: false })], SigveloOlGeojson.prototype, "data", void 0);
165
- __decorate([property({ attribute: false })], SigveloOlGeojson.prototype, "styleFunction", void 0);
166
- __decorate([property({ attribute: "fill-color" })], SigveloOlGeojson.prototype, "fillColor", void 0);
167
- __decorate([property({
168
- attribute: "fill-opacity",
169
- type: Number
170
- })], SigveloOlGeojson.prototype, "fillOpacity", void 0);
171
- __decorate([property({ attribute: "stroke-color" })], SigveloOlGeojson.prototype, "strokeColor", void 0);
172
- __decorate([property({
173
- attribute: "stroke-width",
174
- type: Number
175
- })], SigveloOlGeojson.prototype, "strokeWidth", void 0);
176
- __decorate([property({
177
- attribute: "circle-radius",
178
- type: Number
179
- })], SigveloOlGeojson.prototype, "circleRadius", void 0);
180
- __decorate([property({ type: Boolean })], SigveloOlGeojson.prototype, "interactive", void 0);
181
- __decorate([property()], SigveloOlGeojson.prototype, "channel", void 0);
182
- SigveloOlGeojson = __decorate([customElement("sigvelo-ol-geojson")], SigveloOlGeojson);
183
- //#endregion
184
- export { SigveloOlGeojson as t };
@@ -1,146 +0,0 @@
1
- import { t as __decorate } from "./decorate-DcF3lt7P.js";
2
- import { css, unsafeCSS } from "lit";
3
- import { customElement } 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 OlMap from "ol/Map.js";
7
- import View from "ol/View.js";
8
- import { fromLonLat, toLonLat } from "ol/proj.js";
9
- import olCss from "ol/ol.css?raw";
10
- //#region src/components/map/map.styles.ts
11
- var map_styles_default = css`
12
- :host {
13
- display: block;
14
- position: relative;
15
- min-height: 300px;
16
- }
17
- `;
18
- //#endregion
19
- //#region src/components/map/map.ts
20
- let SigveloOlMap = class SigveloOlMap extends GeoMapElement {
21
- constructor(..._args) {
22
- super(..._args);
23
- this._map = null;
24
- this._view = null;
25
- }
26
- static {
27
- this.styles = [
28
- ...GeoMapElement.styles,
29
- unsafeCSS(olCss),
30
- map_styles_default
31
- ];
32
- }
33
- /** Access the underlying OpenLayers map instance (after mapReady resolves). */
34
- get map() {
35
- return this._map;
36
- }
37
- /** Access the underlying OpenLayers view instance. */
38
- get view() {
39
- return this._view;
40
- }
41
- createMap(container) {
42
- this._view = new View({
43
- center: fromLonLat([this.longitude, this.latitude]),
44
- zoom: this.zoom,
45
- minZoom: this.minZoom,
46
- maxZoom: this.maxZoom,
47
- rotation: this.bearing * Math.PI / 180
48
- });
49
- this._map = new OlMap({
50
- target: container,
51
- view: this._view
52
- });
53
- this._map.on("click", (e) => {
54
- const [lng, lat] = toLonLat(e.coordinate);
55
- this.dispatchEvent(new SigveloMapClickEvent({
56
- lat,
57
- lng
58
- }, e.originalEvent));
59
- });
60
- this._view.on("change:center", () => {
61
- if (!this._view) return;
62
- const center = this._view.getCenter();
63
- if (!center) return;
64
- const [lng, lat] = toLonLat(center);
65
- this._suppressExternalUpdate = true;
66
- this.latitude = lat;
67
- this.longitude = lng;
68
- this._suppressExternalUpdate = false;
69
- this.dispatchEvent(new SigveloMapMoveEvent({
70
- lat,
71
- lng
72
- }));
73
- });
74
- this._view.on("change:resolution", () => {
75
- if (!this._view) return;
76
- const zoom = this._view.getZoom() ?? this.zoom;
77
- this._suppressExternalUpdate = true;
78
- this.zoom = zoom;
79
- this._suppressExternalUpdate = false;
80
- this.dispatchEvent(new SigveloMapZoomEvent(zoom));
81
- });
82
- this._map.on("moveend", () => {
83
- if (!this._view) return;
84
- const center = this._view.getCenter();
85
- if (!center) return;
86
- const [lng, lat] = toLonLat(center);
87
- const zoom = this._view.getZoom() ?? this.zoom;
88
- this.dispatchEvent(new SigveloMapMoveEndEvent({
89
- lat,
90
- lng
91
- }));
92
- this.dispatchEvent(new SigveloMapZoomEndEvent(zoom));
93
- });
94
- this._map.once("rendercomplete", () => {
95
- this._resolveMapReady();
96
- this.dispatchEvent(new SigveloMapLoadEvent());
97
- });
98
- }
99
- destroyMap() {
100
- this._map?.setTarget(void 0);
101
- this._map = null;
102
- this._view = null;
103
- }
104
- updateView(changed) {
105
- if (!this._view) return;
106
- if (changed.has("latitude") || changed.has("longitude")) this._view.setCenter(fromLonLat([this.longitude, this.latitude]));
107
- if (changed.has("zoom")) this._view.setZoom(this.zoom);
108
- if (changed.has("bearing")) this._view.setRotation(this.bearing * Math.PI / 180);
109
- if (changed.has("minZoom")) this._view.setMinZoom(this.minZoom);
110
- if (changed.has("maxZoom")) this._view.setMaxZoom(this.maxZoom);
111
- }
112
- invalidateSize() {
113
- this._map?.updateSize();
114
- }
115
- flyTo(options) {
116
- this._view?.animate({
117
- center: fromLonLat([options.center.lng, options.center.lat]),
118
- zoom: options.zoom,
119
- rotation: options.bearing ? options.bearing * Math.PI / 180 : void 0,
120
- duration: options.duration ?? 1e3
121
- });
122
- }
123
- fitBounds(options) {
124
- if (!this._view || !this._map) return;
125
- const sw = fromLonLat([options.bounds.west, options.bounds.south]);
126
- const ne = fromLonLat([options.bounds.east, options.bounds.north]);
127
- this._view.fit([
128
- sw[0],
129
- sw[1],
130
- ne[0],
131
- ne[1]
132
- ], {
133
- padding: options.padding ? [
134
- options.padding,
135
- options.padding,
136
- options.padding,
137
- options.padding
138
- ] : void 0,
139
- maxZoom: options.maxZoom,
140
- duration: options.duration ?? 1e3
141
- });
142
- }
143
- };
144
- SigveloOlMap = __decorate([customElement("sigvelo-ol-map")], SigveloOlMap);
145
- //#endregion
146
- export { SigveloOlMap as t };
@@ -1,124 +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 { fromLonLat } from "ol/proj.js";
5
- import Overlay from "ol/Overlay.js";
6
- //#region src/components/marker/marker.styles.ts
7
- var marker_styles_default = css`
8
- :host {
9
- display: none;
10
- }
11
-
12
- .marker-icon {
13
- width: 25px;
14
- height: 41px;
15
- cursor: pointer;
16
- transform: translate(-50%, -100%);
17
- }
18
-
19
- .marker-icon--default {
20
- width: 25px;
21
- height: 41px;
22
- position: relative;
23
- }
24
-
25
- .marker-icon--default svg {
26
- width: 100%;
27
- height: 100%;
28
- filter: drop-shadow(0 1px 3px rgba(0, 0, 0, 0.3));
29
- }
30
- `;
31
- //#endregion
32
- //#region src/components/marker/marker.ts
33
- let SigveloOlMarker = class SigveloOlMarker extends LitElement {
34
- constructor(..._args) {
35
- super(..._args);
36
- this.latitude = 0;
37
- this.longitude = 0;
38
- this.color = "#3fb1ce";
39
- this.title = "";
40
- this._overlay = null;
41
- this._markerEl = null;
42
- this._mapEl = null;
43
- this._popupOverlay = null;
44
- }
45
- static {
46
- this.styles = [marker_styles_default];
47
- }
48
- async connectedCallback() {
49
- super.connectedCallback();
50
- this._mapEl = this.closest("sigvelo-ol-map");
51
- if (this._mapEl) {
52
- await this._mapEl.mapReady;
53
- this._addMarker();
54
- }
55
- }
56
- disconnectedCallback() {
57
- super.disconnectedCallback();
58
- if (this._overlay && this._mapEl?.map) this._mapEl.map.removeOverlay(this._overlay);
59
- this._overlay = null;
60
- this._markerEl = null;
61
- }
62
- /** @internal */
63
- _addMarker() {
64
- if (!this._mapEl?.map) return;
65
- this._markerEl = document.createElement("div");
66
- if (this.title) this._markerEl.title = this.title;
67
- this._markerEl.style.cursor = "pointer";
68
- this._markerEl.innerHTML = `
69
- <svg viewBox="0 0 27 43" xmlns="http://www.w3.org/2000/svg"
70
- width="25" height="41"
71
- style="filter: drop-shadow(0 1px 3px rgba(0,0,0,0.3));">
72
- <path d="M13.5 0C6 0 0 6 0 13.5C0 25 13.5 43 13.5 43S27 25 27 13.5C27 6 21 0 13.5 0Z"
73
- fill="${this.color}" stroke="white" stroke-width="1.5"/>
74
- <circle cx="13.5" cy="13.5" r="5" fill="white"/>
75
- </svg>
76
- `;
77
- const popupEl = this.querySelector("sigvelo-ol-popup");
78
- if (popupEl) {
79
- this._markerEl.style.cursor = "pointer";
80
- this._markerEl.addEventListener("click", () => {
81
- this._showPopup(popupEl);
82
- });
83
- }
84
- this._overlay = new Overlay({
85
- position: fromLonLat([this.longitude, this.latitude]),
86
- positioning: "bottom-center",
87
- element: this._markerEl,
88
- stopEvent: false
89
- });
90
- this._mapEl.map.addOverlay(this._overlay);
91
- }
92
- /** @internal */
93
- _showPopup(popupEl) {
94
- if (!this._mapEl?.map) return;
95
- if (this._popupOverlay) this._mapEl.map.removeOverlay(this._popupOverlay);
96
- const content = document.createElement("div");
97
- content.style.background = "white";
98
- content.style.padding = "8px 12px";
99
- content.style.borderRadius = "4px";
100
- content.style.boxShadow = "0 2px 8px rgba(0,0,0,0.2)";
101
- content.style.transform = "translate(-50%, -8px)";
102
- for (const node of Array.from(popupEl.childNodes)) content.appendChild(node.cloneNode(true));
103
- this._popupOverlay = new Overlay({
104
- position: fromLonLat([this.longitude, this.latitude]),
105
- positioning: "bottom-center",
106
- element: content,
107
- offset: [0, -45]
108
- });
109
- this._mapEl.map.addOverlay(this._popupOverlay);
110
- }
111
- updated() {
112
- if (this._overlay) this._overlay.setPosition(fromLonLat([this.longitude, this.latitude]));
113
- }
114
- render() {
115
- return html` <slot></slot> `;
116
- }
117
- };
118
- __decorate([property({ type: Number })], SigveloOlMarker.prototype, "latitude", void 0);
119
- __decorate([property({ type: Number })], SigveloOlMarker.prototype, "longitude", void 0);
120
- __decorate([property()], SigveloOlMarker.prototype, "color", void 0);
121
- __decorate([property()], SigveloOlMarker.prototype, "title", void 0);
122
- SigveloOlMarker = __decorate([customElement("sigvelo-ol-marker")], SigveloOlMarker);
123
- //#endregion
124
- export { SigveloOlMarker as t };
@@ -1,65 +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 { fromLonLat } from "ol/proj.js";
5
- import Overlay from "ol/Overlay.js";
6
- //#region src/components/overlay/overlay.styles.ts
7
- var overlay_styles_default = css`
8
- :host {
9
- display: none;
10
- }
11
- `;
12
- //#endregion
13
- //#region src/components/overlay/overlay.ts
14
- let SigveloOlOverlay = class SigveloOlOverlay extends LitElement {
15
- constructor(..._args) {
16
- super(..._args);
17
- this.latitude = 0;
18
- this.longitude = 0;
19
- this.positioning = "bottom-center";
20
- this._overlay = null;
21
- this._contentEl = null;
22
- this._mapEl = null;
23
- }
24
- static {
25
- this.styles = [overlay_styles_default];
26
- }
27
- async connectedCallback() {
28
- super.connectedCallback();
29
- this._mapEl = this.closest("sigvelo-ol-map");
30
- if (this._mapEl) {
31
- await this._mapEl.mapReady;
32
- this._addOverlay();
33
- }
34
- }
35
- disconnectedCallback() {
36
- super.disconnectedCallback();
37
- if (this._overlay && this._mapEl?.map) this._mapEl.map.removeOverlay(this._overlay);
38
- this._overlay = null;
39
- }
40
- /** @internal */
41
- _addOverlay() {
42
- if (!this._mapEl?.map) return;
43
- this._contentEl = document.createElement("div");
44
- for (const node of Array.from(this.childNodes)) this._contentEl.appendChild(node.cloneNode(true));
45
- this._overlay = new Overlay({
46
- position: fromLonLat([this.longitude, this.latitude]),
47
- positioning: this.positioning,
48
- element: this._contentEl,
49
- stopEvent: false
50
- });
51
- this._mapEl.map.addOverlay(this._overlay);
52
- }
53
- updated() {
54
- if (this._overlay) this._overlay.setPosition(fromLonLat([this.longitude, this.latitude]));
55
- }
56
- render() {
57
- return html` <slot></slot> `;
58
- }
59
- };
60
- __decorate([property({ type: Number })], SigveloOlOverlay.prototype, "latitude", void 0);
61
- __decorate([property({ type: Number })], SigveloOlOverlay.prototype, "longitude", void 0);
62
- __decorate([property()], SigveloOlOverlay.prototype, "positioning", void 0);
63
- SigveloOlOverlay = __decorate([customElement("sigvelo-ol-overlay")], SigveloOlOverlay);
64
- //#endregion
65
- export { SigveloOlOverlay as t };
@@ -1,105 +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 { fromLonLat } from "ol/proj.js";
5
- import VectorLayer from "ol/layer/Vector.js";
6
- import VectorSource from "ol/source/Vector.js";
7
- import { Fill, Stroke, Style } from "ol/style.js";
8
- import Feature from "ol/Feature.js";
9
- import Polygon from "ol/geom/Polygon.js";
10
- //#region src/components/polygon/polygon.styles.ts
11
- var polygon_styles_default = css`
12
- :host {
13
- display: none;
14
- }
15
- `;
16
- //#endregion
17
- //#region src/components/polygon/polygon.ts
18
- let SigveloOlPolygon = class SigveloOlPolygon extends LitElement {
19
- constructor(..._args) {
20
- super(..._args);
21
- this.positions = [];
22
- this.fillColor = "#3388ff";
23
- this.fillOpacity = .2;
24
- this.strokeColor = "#3388ff";
25
- this.strokeWidth = 2;
26
- this._layer = null;
27
- this._feature = null;
28
- this._mapEl = null;
29
- }
30
- static {
31
- this.styles = [polygon_styles_default];
32
- }
33
- async connectedCallback() {
34
- super.connectedCallback();
35
- this._mapEl = this.closest("sigvelo-ol-map");
36
- if (this._mapEl) {
37
- await this._mapEl.mapReady;
38
- this._addPolygon();
39
- }
40
- }
41
- disconnectedCallback() {
42
- super.disconnectedCallback();
43
- if (this._layer && this._mapEl?.map) this._mapEl.map.removeLayer(this._layer);
44
- this._layer = null;
45
- this._feature = null;
46
- }
47
- /** @internal */
48
- _toCoords() {
49
- const ring = this.positions.map(([lat, lng]) => fromLonLat([lng, lat]));
50
- if (ring.length > 0) {
51
- const first = ring[0];
52
- const last = ring[ring.length - 1];
53
- if (first[0] !== last[0] || first[1] !== last[1]) ring.push([...first]);
54
- }
55
- return [ring];
56
- }
57
- /** @internal */
58
- _hexToRgba(hex, opacity) {
59
- return `rgba(${parseInt(hex.slice(1, 3), 16)}, ${parseInt(hex.slice(3, 5), 16)}, ${parseInt(hex.slice(5, 7), 16)}, ${opacity})`;
60
- }
61
- /** @internal */
62
- _addPolygon() {
63
- if (!this._mapEl?.map || this.positions.length < 3) return;
64
- this._feature = new Feature({ geometry: new Polygon(this._toCoords()) });
65
- this._layer = new VectorLayer({
66
- source: new VectorSource({ features: [this._feature] }),
67
- style: new Style({
68
- fill: new Fill({ color: this._hexToRgba(this.fillColor, this.fillOpacity) }),
69
- stroke: new Stroke({
70
- color: this.strokeColor,
71
- width: this.strokeWidth
72
- })
73
- })
74
- });
75
- this._mapEl.map.addLayer(this._layer);
76
- }
77
- updated(changed) {
78
- if (!this._feature || !this._layer) return;
79
- if (changed.has("positions")) this._feature.getGeometry().setCoordinates(this._toCoords());
80
- if (changed.has("fillColor") || changed.has("fillOpacity") || changed.has("strokeColor") || changed.has("strokeWidth")) this._layer.setStyle(new Style({
81
- fill: new Fill({ color: this._hexToRgba(this.fillColor, this.fillOpacity) }),
82
- stroke: new Stroke({
83
- color: this.strokeColor,
84
- width: this.strokeWidth
85
- })
86
- }));
87
- }
88
- render() {
89
- return html``;
90
- }
91
- };
92
- __decorate([property({ attribute: false })], SigveloOlPolygon.prototype, "positions", void 0);
93
- __decorate([property({ attribute: "fill-color" })], SigveloOlPolygon.prototype, "fillColor", void 0);
94
- __decorate([property({
95
- attribute: "fill-opacity",
96
- type: Number
97
- })], SigveloOlPolygon.prototype, "fillOpacity", void 0);
98
- __decorate([property({ attribute: "stroke-color" })], SigveloOlPolygon.prototype, "strokeColor", void 0);
99
- __decorate([property({
100
- attribute: "stroke-width",
101
- type: Number
102
- })], SigveloOlPolygon.prototype, "strokeWidth", void 0);
103
- SigveloOlPolygon = __decorate([customElement("sigvelo-ol-polygon")], SigveloOlPolygon);
104
- //#endregion
105
- export { SigveloOlPolygon as t };