@nextgis/leaflet-map-adapter 1.19.4 → 2.0.0-alpha.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,1715 +1,1951 @@
1
- /** Bundle of @nextgis/leaflet-map-adapter; version: 1.19.4; author: NextGIS */
1
+ /** Bundle of @nextgis/leaflet-map-adapter; version: 2.0.0-alpha.0; author: NextGIS */
2
2
  import { EventEmitter } from 'events';
3
3
  import { Control, DomEvent, GeoJSON, DivIcon, Marker, CircleMarker, FeatureGroup, ImageOverlay as ImageOverlay$1, Layer, Util, CRS, GridLayer, DomUtil, TileLayer as TileLayer$1, Map } from 'leaflet';
4
4
  import { defined, debounce as debounce$1 } from '@nextgis/utils';
5
5
  import { isPaintCallback, isPaint } from '@nextgis/paint';
6
6
 
7
7
  class AttributionControl extends Control.Attribution {
8
- // options: AttributionControlOptions
9
- constructor(options) {
10
- super(options);
11
- const customAttribution = options && options.customAttribution;
12
- if (customAttribution) {
13
- let attributions = [];
14
- if (Array.isArray(customAttribution)) {
15
- attributions = customAttribution;
16
- }
17
- else if (customAttribution) {
18
- attributions = [customAttribution];
19
- }
20
- attributions.forEach((x) => this.addAttribution(x));
21
- }
22
- }
8
+ // options: AttributionControlOptions
9
+ constructor(options) {
10
+ super(options);
11
+ const customAttribution = options && options.customAttribution;
12
+ if (customAttribution) {
13
+ let attributions = [];
14
+ if (Array.isArray(customAttribution)) {
15
+ attributions = customAttribution;
16
+ } else if (customAttribution) {
17
+ attributions = [customAttribution];
18
+ }
19
+ attributions.forEach((x) => this.addAttribution(x));
20
+ }
21
+ }
23
22
  }
24
23
 
25
24
  function createControl(control, options = {}, map) {
26
- const C = Control.extend({
27
- onAdd() {
28
- const element = document.createElement('div');
29
- const content = control.onAdd(map);
30
- element.classList.add('leaflet-control');
31
- if (options.bar) {
32
- element.classList.add('leaflet-bar');
33
- }
34
- if (options.addClass) {
35
- element.classList.add(options.addClass);
36
- }
37
- if (!options.margin && !options.bar) {
38
- element.style.marginBottom = '0px';
39
- element.style.marginTop = '0px';
40
- element.style.marginLeft = '0px';
41
- element.style.marginRight = '0px';
42
- }
43
- if (content) {
44
- element.appendChild(content);
45
- }
46
- DomEvent.disableClickPropagation(element);
47
- return element;
48
- },
49
- onRemove() {
50
- control.onRemove();
51
- },
52
- });
53
- return new C();
25
+ const C = Control.extend({
26
+ onAdd() {
27
+ const element = document.createElement("div");
28
+ const content = control.onAdd(map);
29
+ element.classList.add("leaflet-control");
30
+ if (options.bar) {
31
+ element.classList.add("leaflet-bar");
32
+ }
33
+ if (options.addClass) {
34
+ element.classList.add(options.addClass);
35
+ }
36
+ if (!options.margin && !options.bar) {
37
+ element.style.marginBottom = "0px";
38
+ element.style.marginTop = "0px";
39
+ element.style.marginLeft = "0px";
40
+ element.style.marginRight = "0px";
41
+ }
42
+ if (content) {
43
+ element.appendChild(content);
44
+ }
45
+ DomEvent.disableClickPropagation(element);
46
+ return element;
47
+ },
48
+ onRemove() {
49
+ control.onRemove();
50
+ }
51
+ });
52
+ return new C();
54
53
  }
55
54
 
56
55
  function createButtonControl(options, map) {
57
- const link = document.createElement('a');
58
- const title = options.title || '';
59
- link.href = '#';
60
- link.title = title;
61
- link.setAttribute('role', 'button');
62
- link.setAttribute('aria-label', title);
63
- if (options.addClass) {
64
- link.classList.add(options.addClass);
65
- }
66
- DomEvent.disableClickPropagation(link);
67
- DomEvent.on(link, 'click', DomEvent.stop);
68
- if (options.html instanceof HTMLElement) {
69
- link.appendChild(options.html);
70
- }
71
- else if (typeof options.html === 'string') {
72
- link.innerHTML = options.html;
73
- }
74
- const onClick = (e) => {
75
- e.stopPropagation();
76
- options.onClick();
77
- };
78
- return createControl({
79
- onAdd() {
80
- if (options.onClick !== undefined) {
81
- link.addEventListener('click', onClick);
82
- }
83
- return link;
84
- },
85
- onRemove() {
86
- const parent = link.parentNode;
87
- if (parent) {
88
- parent.removeChild(link);
89
- }
90
- if (options.onClick !== undefined) {
91
- link.removeEventListener('click', onClick);
92
- }
93
- },
94
- }, { bar: true }, map);
56
+ const link = document.createElement("a");
57
+ const title = options.title || "";
58
+ link.href = "#";
59
+ link.title = title;
60
+ link.setAttribute("role", "button");
61
+ link.setAttribute("aria-label", title);
62
+ if (options.addClass) {
63
+ link.classList.add(options.addClass);
64
+ }
65
+ DomEvent.disableClickPropagation(link);
66
+ DomEvent.on(link, "click", DomEvent.stop);
67
+ if (options.html instanceof HTMLElement) {
68
+ link.appendChild(options.html);
69
+ } else if (typeof options.html === "string") {
70
+ link.innerHTML = options.html;
71
+ }
72
+ const onClick = (e) => {
73
+ e.stopPropagation();
74
+ options.onClick();
75
+ };
76
+ return createControl(
77
+ {
78
+ onAdd() {
79
+ if (options.onClick !== void 0) {
80
+ link.addEventListener("click", onClick);
81
+ }
82
+ return link;
83
+ },
84
+ onRemove() {
85
+ const parent = link.parentNode;
86
+ if (parent) {
87
+ parent.removeChild(link);
88
+ }
89
+ if (options.onClick !== void 0) {
90
+ link.removeEventListener("click", onClick);
91
+ }
92
+ }
93
+ },
94
+ { bar: true },
95
+ map
96
+ );
95
97
  }
96
98
 
97
99
  function boundsToArray(bounds) {
98
- const ne = bounds.getNorthEast();
99
- const sw = bounds.getSouthWest();
100
- return [sw.lng, sw.lat, ne.lng, ne.lat];
100
+ const ne = bounds.getNorthEast();
101
+ const sw = bounds.getSouthWest();
102
+ return [sw.lng, sw.lat, ne.lng, ne.lat];
101
103
  }
102
104
 
103
105
  function findMostFrequentGeomType(arr) {
104
- const counts = {};
105
- for (let fry = 0; fry < arr.length; fry++) {
106
- counts[arr[fry]] = 1 + (counts[arr[fry]] || 0);
107
- }
108
- let maxName = '';
109
- for (const c in counts) {
110
- const maxCount = maxName ? counts[maxName] : 0;
111
- if (counts[c] > maxCount) {
112
- maxName = c;
113
- }
114
- }
115
- return maxName;
106
+ const counts = {};
107
+ for (let fry = 0; fry < arr.length; fry++) {
108
+ counts[arr[fry]] = 1 + (counts[arr[fry]] || 0);
109
+ }
110
+ let maxName = "";
111
+ for (const c in counts) {
112
+ const maxCount = maxName ? counts[maxName] : 0;
113
+ if (counts[c] > maxCount) {
114
+ maxName = c;
115
+ }
116
+ }
117
+ return maxName;
116
118
  }
117
119
  function detectType(geojson) {
118
- let geometry;
119
- if (geojson.type === 'FeatureCollection') {
120
- const featuresTypes = geojson.features.map((f) => f.geometry.type);
121
- geometry = findMostFrequentGeomType(featuresTypes);
122
- }
123
- else if (geojson.type === 'GeometryCollection') {
124
- const geometryTypes = geojson.geometries.map((g) => g.type);
125
- geometry = findMostFrequentGeomType(geometryTypes);
126
- }
127
- else if (geojson.type === 'Feature') {
128
- geometry = geojson.geometry.type;
129
- }
130
- else {
131
- geometry = geojson.type;
132
- }
133
- return geometry;
120
+ let geometry;
121
+ if (geojson.type === "FeatureCollection") {
122
+ const featuresTypes = geojson.features.map(
123
+ (f) => f.geometry.type
124
+ );
125
+ geometry = findMostFrequentGeomType(featuresTypes);
126
+ } else if (geojson.type === "GeometryCollection") {
127
+ const geometryTypes = geojson.geometries.map(
128
+ (g) => g.type
129
+ );
130
+ geometry = findMostFrequentGeomType(geometryTypes);
131
+ } else if (geojson.type === "Feature") {
132
+ geometry = geojson.geometry.type;
133
+ } else {
134
+ geometry = geojson.type;
135
+ }
136
+ return geometry;
134
137
  }
135
138
 
136
139
  const typeAlias = {
137
- Point: 'point',
138
- LineString: 'line',
139
- MultiPoint: 'point',
140
- Polygon: 'polygon',
141
- MultiLineString: 'line',
142
- MultiPolygon: 'polygon',
143
- GeometryCollection: 'polygon',
140
+ Point: "point",
141
+ LineString: "line",
142
+ MultiPoint: "point",
143
+ Polygon: "polygon",
144
+ MultiLineString: "line",
145
+ MultiPolygon: "polygon",
146
+ GeometryCollection: "polygon"
144
147
  };
145
148
  const PAINT = {
146
- stroke: false,
147
- opacity: 1,
149
+ stroke: false,
150
+ opacity: 1
148
151
  };
149
152
  const backAliases = {};
150
153
  for (const a in typeAlias) {
151
- const layerType = typeAlias[a];
152
- const backAlias = backAliases[layerType] || [];
153
- backAlias.push(a);
154
- backAliases[layerType] = backAlias;
154
+ const layerType = typeAlias[a];
155
+ const backAlias = backAliases[layerType] || [];
156
+ backAlias.push(a);
157
+ backAliases[layerType] = backAlias;
155
158
  }
156
159
  function geometryFilter(geometry, type) {
157
- const geoJsonGeometry = backAliases[type] || [];
158
- return geoJsonGeometry.indexOf(geometry) !== -1;
160
+ const geoJsonGeometry = backAliases[type] || [];
161
+ return geoJsonGeometry.indexOf(geometry) !== -1;
159
162
  }
160
163
  function filterGeometries(data, type) {
161
- if (data.type === 'FeatureCollection') {
162
- const _data = data;
163
- _data.features = _data.features.filter((f) => geometryFilter(f.geometry.type, type));
164
- }
165
- else if (data.type === 'Feature') {
166
- const allow = geometryFilter(data.geometry.type, type);
167
- if (!allow) {
168
- return false;
169
- }
170
- }
171
- else if (data.type === 'GeometryCollection') {
172
- const _data = data;
173
- _data.geometries = _data.geometries.filter((g) => geometryFilter(g.type, type));
174
- }
175
- return data;
164
+ if (data.type === "FeatureCollection") {
165
+ const _data = data;
166
+ _data.features = _data.features.filter(
167
+ (f) => geometryFilter(f.geometry.type, type)
168
+ );
169
+ } else if (data.type === "Feature") {
170
+ const allow = geometryFilter(data.geometry.type, type);
171
+ if (!allow) {
172
+ return false;
173
+ }
174
+ } else if (data.type === "GeometryCollection") {
175
+ const _data = data;
176
+ _data.geometries = _data.geometries.filter(
177
+ (g) => geometryFilter(g.type, type)
178
+ );
179
+ }
180
+ return data;
176
181
  }
177
182
  function featuresBounds(features) {
178
- const geoJsonLayer = new GeoJSON();
179
- const features_ = Array.isArray(features) ? features : [features];
180
- features_.forEach((f) => geoJsonLayer.addData(f));
181
- return geoJsonLayer.getBounds();
183
+ const geoJsonLayer = new GeoJSON();
184
+ const features_ = Array.isArray(features) ? features : [features];
185
+ features_.forEach((f) => geoJsonLayer.addData(f));
186
+ return geoJsonLayer.getBounds();
182
187
  }
183
188
  function getFeaturesBounds(features) {
184
- return boundsToArray(featuresBounds(features));
189
+ return boundsToArray(featuresBounds(features));
185
190
  }
186
191
  function getFeaturesCenter(features) {
187
- const { lat, lng } = featuresBounds(features).getCenter();
188
- return [lng, lat];
192
+ const { lat, lng } = featuresBounds(features).getCenter();
193
+ return [lng, lat];
189
194
  }
190
195
  function createFeaturePositionOptions(features) {
191
- return {
192
- getBounds: () => getFeaturesBounds(features),
193
- getCenter: () => getFeaturesCenter(features),
194
- };
196
+ return {
197
+ getBounds: () => getFeaturesBounds(features),
198
+ getCenter: () => getFeaturesCenter(features)
199
+ };
195
200
  }
196
201
 
202
+ var __defProp$b = Object.defineProperty;
203
+ var __defNormalProp$b = (obj, key, value) => key in obj ? __defProp$b(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
204
+ var __publicField$7 = (obj, key, value) => {
205
+ __defNormalProp$b(obj, typeof key !== "symbol" ? key + "" : key, value);
206
+ return value;
207
+ };
197
208
  class BaseAdapter {
198
- constructor(map, options) {
199
- this.map = map;
200
- this.options = options;
201
- this.pane = 'order-0';
202
- if (options.order !== undefined) {
203
- const pane = 'order-' + options.order;
204
- let exist = map.getPane(pane);
205
- if (!exist) {
206
- exist = map.createPane(pane);
207
- }
208
- exist.style.zIndex = String(Math.round(options.order * 100));
209
- this.pane = pane;
210
- }
211
- }
212
- addLayer(options) {
213
- Object.assign(this.options, options);
214
- return undefined;
215
- }
209
+ constructor(map, options) {
210
+ this.map = map;
211
+ this.options = options;
212
+ __publicField$7(this, "layer");
213
+ __publicField$7(this, "pane", "order-0");
214
+ if (options.order !== void 0) {
215
+ const pane = "order-" + options.order;
216
+ let exist = map.getPane(pane);
217
+ if (!exist) {
218
+ exist = map.createPane(pane);
219
+ }
220
+ exist.style.zIndex = String(Math.round(options.order * 100));
221
+ this.pane = pane;
222
+ }
223
+ }
224
+ addLayer(options) {
225
+ Object.assign(this.options, options);
226
+ return void 0;
227
+ }
216
228
  }
217
229
 
218
230
  function convertMapClickEvent(evt) {
219
- const coord = evt.containerPoint;
220
- const latLng = evt.latlng;
221
- const { lat, lng } = latLng;
222
- return {
223
- latLng,
224
- lngLat: [lng, lat],
225
- pixel: { left: coord.x, top: coord.y },
226
- source: evt,
227
- };
231
+ const coord = evt.containerPoint;
232
+ const latLng = evt.latlng;
233
+ const { lat, lng } = latLng;
234
+ return {
235
+ latLng,
236
+ lngLat: [lng, lat],
237
+ pixel: { left: coord.x, top: coord.y },
238
+ source: evt
239
+ };
228
240
  }
229
241
 
230
- function createMouseEvent({ layer, source, }) {
231
- const layer_ = source.target;
232
- const feature = layer_.feature;
233
- const opt = {
234
- layer,
235
- feature,
236
- event: convertMapClickEvent(source),
237
- source,
238
- ...createFeaturePositionOptions(feature),
239
- };
240
- return opt;
242
+ var __defProp$a = Object.defineProperty;
243
+ var __getOwnPropSymbols$8 = Object.getOwnPropertySymbols;
244
+ var __hasOwnProp$8 = Object.prototype.hasOwnProperty;
245
+ var __propIsEnum$8 = Object.prototype.propertyIsEnumerable;
246
+ var __defNormalProp$a = (obj, key, value) => key in obj ? __defProp$a(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
247
+ var __spreadValues$8 = (a, b) => {
248
+ for (var prop in b || (b = {}))
249
+ if (__hasOwnProp$8.call(b, prop))
250
+ __defNormalProp$a(a, prop, b[prop]);
251
+ if (__getOwnPropSymbols$8)
252
+ for (var prop of __getOwnPropSymbols$8(b)) {
253
+ if (__propIsEnum$8.call(b, prop))
254
+ __defNormalProp$a(a, prop, b[prop]);
255
+ }
256
+ return a;
257
+ };
258
+ function createMouseEvent({
259
+ layer,
260
+ source
261
+ }) {
262
+ const layer_ = source.target;
263
+ const feature = layer_.feature;
264
+ const opt = __spreadValues$8({
265
+ layer,
266
+ feature,
267
+ event: convertMapClickEvent(source),
268
+ source
269
+ }, createFeaturePositionOptions(feature));
270
+ return opt;
241
271
  }
242
272
 
273
+ var __defProp$9 = Object.defineProperty;
274
+ var __getOwnPropSymbols$7 = Object.getOwnPropertySymbols;
275
+ var __hasOwnProp$7 = Object.prototype.hasOwnProperty;
276
+ var __propIsEnum$7 = Object.prototype.propertyIsEnumerable;
277
+ var __defNormalProp$9 = (obj, key, value) => key in obj ? __defProp$9(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
278
+ var __spreadValues$7 = (a, b) => {
279
+ for (var prop in b || (b = {}))
280
+ if (__hasOwnProp$7.call(b, prop))
281
+ __defNormalProp$9(a, prop, b[prop]);
282
+ if (__getOwnPropSymbols$7)
283
+ for (var prop of __getOwnPropSymbols$7(b)) {
284
+ if (__propIsEnum$7.call(b, prop))
285
+ __defNormalProp$9(a, prop, b[prop]);
286
+ }
287
+ return a;
288
+ };
289
+ var __publicField$6 = (obj, key, value) => {
290
+ __defNormalProp$9(obj, typeof key !== "symbol" ? key + "" : key, value);
291
+ return value;
292
+ };
243
293
  class GeoJsonEvents {
244
- constructor(layer) {
245
- this.layer = layer;
246
- }
247
- handleMouseEvents(layer) {
248
- const { onClick, onLayerClick, onMouseOut, onMouseOver } = this.layer.options;
249
- // TODO: remove backward compatibility for onLayerClick
250
- const onClick_ = onClick || onLayerClick;
251
- if (onClick_) {
252
- this._onclick = (e) => {
253
- const selected = !!this.layer._getSelected(layer);
254
- onClick_({
255
- selected,
256
- ...this._createMouseEvent(e),
257
- });
258
- };
259
- layer.on('click', this._onclick, this);
260
- }
261
- if (onMouseOut) {
262
- this._mouseout = (e) => {
263
- onMouseOut(this._createMouseEvent(e));
264
- };
265
- layer.on('mouseout', this._mouseout, this);
266
- }
267
- if (onMouseOver) {
268
- this._mouseover = (e) => {
269
- onMouseOver(this._createMouseEvent(e));
270
- };
271
- layer.on('mouseover', this._mouseover, this);
272
- }
273
- }
274
- stopMouseEvents(layer) {
275
- if (this._mouseover) {
276
- layer.off('mouseover', this._mouseover, this);
277
- }
278
- if (this._mouseout) {
279
- layer.off('mouseout', this._mouseout, this);
280
- }
281
- if (this._onclick) {
282
- layer.off('click', this._onclick, this);
283
- }
284
- }
285
- _createMouseEvent(source) {
286
- return createMouseEvent({
287
- layer: this.layer,
288
- source: source,
289
- });
290
- }
294
+ constructor(layer) {
295
+ __publicField$6(this, "layer");
296
+ __publicField$6(this, "_onclick");
297
+ __publicField$6(this, "_mouseout");
298
+ __publicField$6(this, "_mouseover");
299
+ this.layer = layer;
300
+ }
301
+ handleMouseEvents(layer) {
302
+ const { onClick, onLayerClick, onMouseOut, onMouseOver } = this.layer.options;
303
+ const onClick_ = onClick || onLayerClick;
304
+ if (onClick_) {
305
+ this._onclick = (e) => {
306
+ const selected = !!this.layer._getSelected(layer);
307
+ onClick_(__spreadValues$7({
308
+ selected
309
+ }, this._createMouseEvent(e)));
310
+ };
311
+ layer.on("click", this._onclick, this);
312
+ }
313
+ if (onMouseOut) {
314
+ this._mouseout = (e) => {
315
+ onMouseOut(this._createMouseEvent(e));
316
+ };
317
+ layer.on("mouseout", this._mouseout, this);
318
+ }
319
+ if (onMouseOver) {
320
+ this._mouseover = (e) => {
321
+ onMouseOver(this._createMouseEvent(e));
322
+ };
323
+ layer.on("mouseover", this._mouseover, this);
324
+ }
325
+ }
326
+ stopMouseEvents(layer) {
327
+ if (this._mouseover) {
328
+ layer.off("mouseover", this._mouseover, this);
329
+ }
330
+ if (this._mouseout) {
331
+ layer.off("mouseout", this._mouseout, this);
332
+ }
333
+ if (this._onclick) {
334
+ layer.off("click", this._onclick, this);
335
+ }
336
+ }
337
+ _createMouseEvent(source) {
338
+ return createMouseEvent({
339
+ layer: this.layer,
340
+ source
341
+ });
342
+ }
291
343
  }
292
344
 
345
+ var __defProp$8 = Object.defineProperty;
346
+ var __defProps$4 = Object.defineProperties;
347
+ var __getOwnPropDescs$4 = Object.getOwnPropertyDescriptors;
348
+ var __getOwnPropSymbols$6 = Object.getOwnPropertySymbols;
349
+ var __hasOwnProp$6 = Object.prototype.hasOwnProperty;
350
+ var __propIsEnum$6 = Object.prototype.propertyIsEnumerable;
351
+ var __defNormalProp$8 = (obj, key, value) => key in obj ? __defProp$8(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
352
+ var __spreadValues$6 = (a, b) => {
353
+ for (var prop in b || (b = {}))
354
+ if (__hasOwnProp$6.call(b, prop))
355
+ __defNormalProp$8(a, prop, b[prop]);
356
+ if (__getOwnPropSymbols$6)
357
+ for (var prop of __getOwnPropSymbols$6(b)) {
358
+ if (__propIsEnum$6.call(b, prop))
359
+ __defNormalProp$8(a, prop, b[prop]);
360
+ }
361
+ return a;
362
+ };
363
+ var __spreadProps$4 = (a, b) => __defProps$4(a, __getOwnPropDescs$4(b));
364
+ var __objRest$2 = (source, exclude) => {
365
+ var target = {};
366
+ for (var prop in source)
367
+ if (__hasOwnProp$6.call(source, prop) && exclude.indexOf(prop) < 0)
368
+ target[prop] = source[prop];
369
+ if (source != null && __getOwnPropSymbols$6)
370
+ for (var prop of __getOwnPropSymbols$6(source)) {
371
+ if (exclude.indexOf(prop) < 0 && __propIsEnum$6.call(source, prop))
372
+ target[prop] = source[prop];
373
+ }
374
+ return target;
375
+ };
376
+ var __publicField$5 = (obj, key, value) => {
377
+ __defNormalProp$8(obj, typeof key !== "symbol" ? key + "" : key, value);
378
+ return value;
379
+ };
293
380
  class GeoJsonPaint {
294
- constructor(layer) {
295
- this.layer = layer;
296
- }
297
- setPaintEachLayer(paint) {
298
- this.layer._layers.forEach((layerDef) => {
299
- this.setPaint(layerDef, paint);
300
- });
301
- }
302
- setPaint(layerDef, paint) {
303
- let style = undefined;
304
- const { layer, feature } = layerDef;
305
- if (layer && feature) {
306
- if (isPaintCallback(paint)) {
307
- style = paint(feature);
308
- }
309
- else if (isPaint(paint)) {
310
- style = paint;
311
- }
312
- if (style) {
313
- if (this.layer.type === 'point' && style.type === 'icon') {
314
- const marker = layer;
315
- const divIcon = this._createDivIcon(style);
316
- setTimeout(() => {
317
- marker.setIcon(divIcon);
318
- }, 10);
319
- }
320
- else if ('setStyle' in layer) {
321
- layer.setStyle(this.preparePaint(style));
322
- }
323
- }
324
- }
325
- }
326
- preparePaint(paint) {
327
- if (paint.type !== 'get-paint') {
328
- const paintAliases = [
329
- ['color', 'strokeColor'],
330
- ['opacity', 'strokeOpacity'],
331
- ['stroke', 'stroke'],
332
- ['fillColor', 'fillColor'],
333
- ['fillOpacity', 'fillOpacity'],
334
- ['fill', 'fill'],
335
- ['weight', 'weight'],
336
- ];
337
- const aliases = this.layer.type === 'line'
338
- ? [
339
- ['color', 'strokeColor'],
340
- ['opacity', 'strokeOpacity'],
341
- ['weight', 'weight'],
342
- ]
343
- : paintAliases;
344
- const readyPaint = {};
345
- if ('radius' in paint && typeof paint.radius === 'number') {
346
- readyPaint.radius = paint.radius;
347
- }
348
- for (const [to, from] of aliases) {
349
- const opacity = this.layer.options.opacity;
350
- let paintProp = paint[from];
351
- if (defined(opacity) && from.toLowerCase().indexOf('opacity') !== -1) {
352
- paintProp = Number(paintProp) * opacity;
353
- }
354
- if (paintProp !== undefined) {
355
- Object.defineProperty(readyPaint, to, {
356
- enumerable: true,
357
- value: paintProp,
358
- });
359
- }
360
- }
361
- return readyPaint;
362
- }
363
- return PAINT;
364
- }
365
- _createDivIcon(icon) {
366
- const { html, rotate, className, ...toLIconOpt } = icon;
367
- const element = document.createElement('div');
368
- if (className) {
369
- element.className = className;
370
- }
371
- if (rotate) {
372
- element.style.transform = `rotateZ(${rotate}deg)`;
373
- }
374
- if (html) {
375
- element.innerHTML = html;
376
- }
377
- const divIcon = new DivIcon({
378
- className: '',
379
- ...toLIconOpt,
380
- html: element,
381
- });
382
- return divIcon;
383
- }
384
- createPaintToLayer(icon) {
385
- if (icon && icon.type) {
386
- if (icon.type === 'icon') {
387
- const iconClassName = icon.className;
388
- const html = icon.html;
389
- if (iconClassName || html) {
390
- return (_, latlng) => {
391
- const divIcon = this._createDivIcon(icon);
392
- return new Marker(latlng, { icon: divIcon });
393
- };
394
- }
395
- }
396
- else if (icon.type === 'pin') {
397
- return (_, latlng) => {
398
- return new Marker(latlng);
399
- };
400
- }
401
- }
381
+ constructor(layer) {
382
+ __publicField$5(this, "layer");
383
+ this.layer = layer;
384
+ }
385
+ setPaintEachLayer(paint) {
386
+ this.layer._layers.forEach((layerDef) => {
387
+ this.setPaint(layerDef, paint);
388
+ });
389
+ }
390
+ setPaint(layerDef, paint) {
391
+ let style = void 0;
392
+ const { layer, feature } = layerDef;
393
+ if (layer && feature) {
394
+ if (isPaintCallback(paint)) {
395
+ style = paint(feature);
396
+ } else if (isPaint(paint)) {
397
+ style = paint;
398
+ }
399
+ if (style) {
400
+ if (this.layer.type === "point" && style.type === "icon") {
401
+ const marker = layer;
402
+ const divIcon = this._createDivIcon(style);
403
+ setTimeout(() => {
404
+ marker.setIcon(divIcon);
405
+ }, 10);
406
+ } else if ("setStyle" in layer) {
407
+ layer.setStyle(this.preparePaint(style));
408
+ }
409
+ }
410
+ }
411
+ }
412
+ preparePaint(paint) {
413
+ if (paint.type !== "get-paint") {
414
+ const paintAliases = [
415
+ ["color", "strokeColor"],
416
+ ["opacity", "strokeOpacity"],
417
+ ["stroke", "stroke"],
418
+ ["fillColor", "fillColor"],
419
+ ["fillOpacity", "fillOpacity"],
420
+ ["fill", "fill"],
421
+ ["weight", "weight"]
422
+ ];
423
+ const aliases = this.layer.type === "line" ? [
424
+ ["color", "strokeColor"],
425
+ ["opacity", "strokeOpacity"],
426
+ ["weight", "weight"]
427
+ ] : paintAliases;
428
+ const readyPaint = {};
429
+ if ("radius" in paint && typeof paint.radius === "number") {
430
+ readyPaint.radius = paint.radius;
431
+ }
432
+ for (const [to, from] of aliases) {
433
+ const opacity = this.layer.options.opacity;
434
+ let paintProp = paint[from];
435
+ if (defined(opacity) && from.toLowerCase().indexOf("opacity") !== -1) {
436
+ paintProp = Number(paintProp) * opacity;
437
+ }
438
+ if (paintProp !== void 0) {
439
+ Object.defineProperty(readyPaint, to, {
440
+ enumerable: true,
441
+ value: paintProp
442
+ });
443
+ }
444
+ }
445
+ return readyPaint;
446
+ }
447
+ return PAINT;
448
+ }
449
+ _createDivIcon(icon) {
450
+ const _a = icon, { html, rotate, className } = _a, toLIconOpt = __objRest$2(_a, ["html", "rotate", "className"]);
451
+ const element = document.createElement("div");
452
+ if (className) {
453
+ element.className = className;
454
+ }
455
+ if (rotate) {
456
+ element.style.transform = `rotateZ(${rotate}deg)`;
457
+ }
458
+ if (html) {
459
+ element.innerHTML = html;
460
+ }
461
+ const divIcon = new DivIcon(__spreadProps$4(__spreadValues$6({
462
+ className: ""
463
+ }, toLIconOpt), {
464
+ html: element
465
+ }));
466
+ return divIcon;
467
+ }
468
+ createPaintToLayer(icon) {
469
+ if (icon && icon.type) {
470
+ if (icon.type === "icon") {
471
+ const iconClassName = icon.className;
472
+ const html = icon.html;
473
+ if (iconClassName || html) {
474
+ return (_, latlng) => {
475
+ const divIcon = this._createDivIcon(icon);
476
+ return new Marker(latlng, { icon: divIcon });
477
+ };
478
+ }
479
+ } else if (icon.type === "pin") {
402
480
  return (_, latlng) => {
403
- const p = PAINT;
404
- return new CircleMarker(latlng, this.preparePaint({ ...p, ...icon }));
481
+ return new Marker(latlng);
405
482
  };
483
+ }
406
484
  }
407
- createPaintOptions(paint) {
408
- const geoJsonOptions = {};
409
- const newPaint = this.preparePaint(paint);
410
- if (paint) {
411
- geoJsonOptions.style = () => {
412
- return newPaint;
413
- };
414
- }
415
- if (this.layer.type === 'point') {
416
- geoJsonOptions.pointToLayer = this.createPaintToLayer(paint);
417
- }
418
- else if (this.layer.type === 'line') {
419
- newPaint.stroke = true;
420
- }
421
- return geoJsonOptions;
422
- }
485
+ return (_, latlng) => {
486
+ const p = PAINT;
487
+ return new CircleMarker(latlng, this.preparePaint(__spreadValues$6(__spreadValues$6({}, p), icon)));
488
+ };
489
+ }
490
+ createPaintOptions(paint) {
491
+ const geoJsonOptions = {};
492
+ const newPaint = this.preparePaint(paint);
493
+ if (paint) {
494
+ geoJsonOptions.style = () => {
495
+ return newPaint;
496
+ };
497
+ }
498
+ if (this.layer.type === "point") {
499
+ geoJsonOptions.pointToLayer = this.createPaintToLayer(
500
+ paint
501
+ );
502
+ } else if (this.layer.type === "line") {
503
+ newPaint.stroke = true;
504
+ }
505
+ return geoJsonOptions;
506
+ }
423
507
  }
424
508
 
509
+ var __defProp$7 = Object.defineProperty;
510
+ var __defProps$3 = Object.defineProperties;
511
+ var __getOwnPropDescs$3 = Object.getOwnPropertyDescriptors;
512
+ var __getOwnPropSymbols$5 = Object.getOwnPropertySymbols;
513
+ var __hasOwnProp$5 = Object.prototype.hasOwnProperty;
514
+ var __propIsEnum$5 = Object.prototype.propertyIsEnumerable;
515
+ var __defNormalProp$7 = (obj, key, value) => key in obj ? __defProp$7(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
516
+ var __spreadValues$5 = (a, b) => {
517
+ for (var prop in b || (b = {}))
518
+ if (__hasOwnProp$5.call(b, prop))
519
+ __defNormalProp$7(a, prop, b[prop]);
520
+ if (__getOwnPropSymbols$5)
521
+ for (var prop of __getOwnPropSymbols$5(b)) {
522
+ if (__propIsEnum$5.call(b, prop))
523
+ __defNormalProp$7(a, prop, b[prop]);
524
+ }
525
+ return a;
526
+ };
527
+ var __spreadProps$3 = (a, b) => __defProps$3(a, __getOwnPropDescs$3(b));
528
+ var __publicField$4 = (obj, key, value) => {
529
+ __defNormalProp$7(obj, typeof key !== "symbol" ? key + "" : key, value);
530
+ return value;
531
+ };
532
+ var __async = (__this, __arguments, generator) => {
533
+ return new Promise((resolve, reject) => {
534
+ var fulfilled = (value) => {
535
+ try {
536
+ step(generator.next(value));
537
+ } catch (e) {
538
+ reject(e);
539
+ }
540
+ };
541
+ var rejected = (value) => {
542
+ try {
543
+ step(generator.throw(value));
544
+ } catch (e) {
545
+ reject(e);
546
+ }
547
+ };
548
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
549
+ step((generator = generator.apply(__this, __arguments)).next());
550
+ });
551
+ };
425
552
  class GeoJsonAdapter extends BaseAdapter {
426
- constructor(map, options) {
427
- super(map, options);
428
- this.selected = false;
429
- this._layers = [];
430
- this._selectedLayers = [];
431
- this._filteredLayers = [];
432
- this._openedPopup = [];
433
- this.$updateTooltip = debounce$1(() => {
434
- this.updateTooltip();
435
- }, 300);
436
- this.$unselect = () => {
437
- this.unselect();
438
- };
439
- this._events = new GeoJsonEvents(this);
440
- this._paint = new GeoJsonPaint(this);
441
- }
442
- addLayer(options) {
443
- Object.assign(this.options, options);
444
- this.paint = options.paint;
445
- this.layer = new FeatureGroup([], {
446
- ...options.nativeOptions,
447
- pane: this.pane,
448
- });
449
- this.selectedPaint = options.selectedPaint;
450
- options.paint = this.paint;
451
- if (options.data) {
452
- this.addData(options.data);
453
- }
454
- this._addMapListener();
455
- return this.layer;
456
- }
457
- beforeRemove() {
458
- this._removeMapListener();
459
- }
460
- select(findFeatureFun) {
461
- this.unselect();
462
- if (findFeatureFun) {
463
- const def = this._layers.filter(findFeatureFun);
464
- for (const x of def) {
465
- this._selectLayer(x, 'api');
466
- }
467
- }
468
- else if (!this.selected) {
469
- this.selected = true;
470
- if (this.selectedPaint) {
471
- this._paint.setPaintEachLayer(this.selectedPaint);
472
- }
473
- }
474
- }
475
- unselect(findFeatureFun) {
476
- if (findFeatureFun) {
477
- const feature = this._layers.filter(findFeatureFun);
478
- feature.forEach((x) => {
479
- this._unSelectLayer(x);
480
- });
481
- }
482
- else if (this.selected) {
483
- for (const p of this._openedPopup) {
484
- this._removePopup(p[0]);
485
- }
486
- if (this.paint) {
487
- this._paint.setPaintEachLayer(this.paint);
488
- }
489
- this._selectedLayers.length = 0;
490
- this.selected = false;
491
- }
492
- }
493
- getSelected() {
494
- return this._selectedLayers.map((x) => {
495
- return {
496
- target: this,
497
- feature: x.feature,
498
- layer: x,
499
- ...createFeaturePositionOptions(x.feature),
500
- };
501
- });
502
- }
503
- getFiltered() {
504
- return this._filteredLayers;
505
- }
506
- filter(fun) {
507
- // Some optimization
508
- this._filterFun = fun;
509
- const layer_ = this.layer;
510
- const map = layer_ && layer_._map;
511
- if (layer_ && map) {
512
- layer_.remove();
513
- const filteredLayers = [];
514
- this._layers.forEach(({ feature, layer }) => {
515
- if (layer) {
516
- const ok = fun
517
- ? fun({
518
- target: this,
519
- feature,
520
- layer,
521
- ...createFeaturePositionOptions(feature),
522
- })
523
- : true;
524
- if (ok) {
525
- layer_.addLayer(layer);
526
- filteredLayers.push({
527
- target: this,
528
- feature,
529
- layer,
530
- ...createFeaturePositionOptions(feature),
531
- });
532
- }
533
- else {
534
- layer_.removeLayer(layer);
535
- }
536
- }
537
- });
538
- this._filteredLayers = filteredLayers;
539
- layer_.addTo(map);
540
- }
541
- return this._filteredLayers;
542
- }
543
- cleanFilter() {
544
- this.filter();
545
- }
546
- getLayers() {
547
- return this._layers.map(({ layer, feature }) => {
548
- const visible = layer && !!layer._map;
549
- return {
550
- feature,
551
- layer,
552
- visible,
553
- target: this,
554
- ...createFeaturePositionOptions(feature),
555
- };
556
- });
557
- }
558
- clearLayer(cb) {
559
- this.unselect();
560
- const layer_ = this.layer;
561
- if (layer_) {
562
- if (cb) {
563
- for (let fry = this._layers.length; fry--;) {
564
- const def = this._layers[fry];
565
- if (def) {
566
- const { feature, layer } = def;
567
- if (feature && layer) {
568
- const exist = cb(feature);
569
- if (exist) {
570
- layer_.removeLayer(layer);
571
- this._layers.splice(fry, 1);
572
- }
573
- }
574
- }
575
- }
576
- }
577
- else {
578
- layer_.clearLayers();
579
- this._layers = [];
580
- }
581
- }
582
- }
583
- setData(data) {
584
- this.clearLayer();
585
- this.addData(data);
586
- }
587
- addData(data) {
588
- const options = this.options;
589
- let geoJsonOptions;
590
- if (options) {
591
- if (data) {
592
- let type;
593
- if (!options.type) {
594
- const detectedType = detectType(data);
595
- type = typeAlias[detectedType];
596
- }
597
- else {
598
- type = options.type;
599
- }
600
- if (this.type && this.type !== type) {
601
- console.warn('no other data type than layer can be added');
602
- return;
603
- }
604
- this.type = type;
605
- data = filterGeometries(data, type);
606
- if (data) {
607
- geoJsonOptions = this._getGeoJsonOptions(options, type);
608
- }
609
- }
610
- new GeoJSON(data || undefined, geoJsonOptions);
611
- }
612
- }
613
- openPopup(findFeatureFun, options) {
614
- if (findFeatureFun) {
615
- const def = this._layers.filter(findFeatureFun);
616
- def.forEach((x) => {
617
- this._openPopup(x, options, 'api');
618
- });
619
- }
620
- }
621
- closePopup(findFeatureFun) {
622
- const popupToClose = findFeatureFun
623
- ? this._openedPopup.filter((x) => findFeatureFun(x[2]))
624
- : this._openedPopup;
625
- popupToClose.forEach((x) => {
626
- this._removePopup(x[0]);
627
- });
628
- }
629
- updateTooltip(layerDef) {
630
- if (layerDef) {
631
- this._updateTooltip(layerDef);
632
- }
633
- else {
634
- this.getLayers().forEach((x) => this._updateTooltip({ feature: x.feature, layer: x.layer }));
635
- }
636
- }
637
- /** @deprecated use {@link GeoJsonAdapter.getBounds} instead */
638
- getExtent() {
639
- return this.getBounds();
640
- }
641
- getBounds() {
642
- if (this.layer) {
643
- const bounds = this.layer.getBounds();
644
- if (bounds.isValid()) {
645
- return boundsToArray(bounds);
646
- }
647
- }
648
- }
649
- setOpacity(value) {
650
- this.options.opacity = value;
651
- this.setPaint(this.paint);
652
- this.setSelectedPaint(this.selectedPaint);
653
- }
654
- setPaint(paint) {
655
- if (paint) {
656
- this.paint = paint;
657
- for (const l of this._layers) {
658
- this._paint.setPaint(l, paint);
659
- }
660
- }
661
- }
662
- setSelectedPaint(paint) {
663
- if (paint) {
664
- this.selectedPaint = paint;
665
- for (const l of this._selectedLayers) {
666
- this._paint.setPaint(l, paint);
667
- }
668
- }
669
- }
670
- updatePaint(paint) {
671
- this.paint = { ...this.paint, ...paint };
672
- for (const l of this._layers) {
673
- this._paint.setPaint(l, this.paint);
674
- }
675
- }
676
- updateSelectedPaint(paint) {
677
- this.selectedPaint = { ...this.selectedPaint, ...paint };
678
- for (const l of this._selectedLayers) {
679
- this._paint.setPaint(l, this.selectedPaint);
680
- }
681
- }
682
- _getSelected(layer) {
683
- return this._selectedLayers.find((x) => x.layer === layer);
684
- }
685
- _updateTooltip(layerDef) {
686
- const { feature, layer } = layerDef;
687
- const { label, labelField, labelOnHover } = this.options;
553
+ constructor(map, options) {
554
+ super(map, options);
555
+ __publicField$4(this, "layer");
556
+ __publicField$4(this, "selected", false);
557
+ __publicField$4(this, "type");
558
+ __publicField$4(this, "_layers", []);
559
+ __publicField$4(this, "_events");
560
+ __publicField$4(this, "paint");
561
+ __publicField$4(this, "selectedPaint");
562
+ __publicField$4(this, "_selectedLayers", []);
563
+ __publicField$4(this, "_filteredLayers", []);
564
+ __publicField$4(this, "_filterFun");
565
+ __publicField$4(this, "_openedPopup", []);
566
+ __publicField$4(this, "_paint");
567
+ __publicField$4(this, "$updateTooltip", debounce$1(() => {
568
+ this.updateTooltip();
569
+ }, 300));
570
+ __publicField$4(this, "$unselect", () => {
571
+ this.unselect();
572
+ });
573
+ this._events = new GeoJsonEvents(this);
574
+ this._paint = new GeoJsonPaint(this);
575
+ }
576
+ addLayer(options) {
577
+ Object.assign(this.options, options);
578
+ this.paint = options.paint;
579
+ this.layer = new FeatureGroup([], __spreadProps$3(__spreadValues$5({}, options.nativeOptions), {
580
+ pane: this.pane
581
+ }));
582
+ this.selectedPaint = options.selectedPaint;
583
+ options.paint = this.paint;
584
+ if (options.data) {
585
+ this.addData(options.data);
586
+ }
587
+ this._addMapListener();
588
+ return this.layer;
589
+ }
590
+ beforeRemove() {
591
+ this._removeMapListener();
592
+ }
593
+ select(findFeatureFun) {
594
+ this.unselect();
595
+ if (findFeatureFun) {
596
+ const def = this._layers.filter(findFeatureFun);
597
+ for (const x of def) {
598
+ this._selectLayer(x, "api");
599
+ }
600
+ } else if (!this.selected) {
601
+ this.selected = true;
602
+ if (this.selectedPaint) {
603
+ this._paint.setPaintEachLayer(
604
+ this.selectedPaint
605
+ );
606
+ }
607
+ }
608
+ }
609
+ unselect(findFeatureFun) {
610
+ if (findFeatureFun) {
611
+ const feature = this._layers.filter(findFeatureFun);
612
+ feature.forEach((x) => {
613
+ this._unSelectLayer(x);
614
+ });
615
+ } else if (this.selected) {
616
+ for (const p of this._openedPopup) {
617
+ this._removePopup(p[0]);
618
+ }
619
+ if (this.paint) {
620
+ this._paint.setPaintEachLayer(this.paint);
621
+ }
622
+ this._selectedLayers.length = 0;
623
+ this.selected = false;
624
+ }
625
+ }
626
+ getSelected() {
627
+ return this._selectedLayers.map((x) => {
628
+ return __spreadValues$5({
629
+ target: this,
630
+ feature: x.feature,
631
+ layer: x
632
+ }, createFeaturePositionOptions(x.feature));
633
+ });
634
+ }
635
+ getFiltered() {
636
+ return this._filteredLayers;
637
+ }
638
+ filter(fun) {
639
+ this._filterFun = fun;
640
+ const layer_ = this.layer;
641
+ const map = layer_ && layer_._map;
642
+ if (layer_ && map) {
643
+ layer_.remove();
644
+ const filteredLayers = [];
645
+ this._layers.forEach(({ feature, layer }) => {
688
646
  if (layer) {
689
- layer.unbindTooltip();
690
- let message;
691
- if (feature.properties && labelField) {
692
- message = feature.properties[labelField];
693
- }
694
- else if (label) {
695
- message = label({
696
- target: this,
697
- ...layerDef,
698
- ...createFeaturePositionOptions(feature),
699
- });
700
- }
701
- if (message) {
702
- const permanent = !labelOnHover;
703
- layer.bindTooltip(String(message), { permanent, sticky: false });
704
- }
705
- }
706
- }
707
- async _openPopup(def, options = {}, type, latLng) {
708
- var _a, _b;
709
- const { feature, layer } = def;
710
- const { minWidth, autoPan, maxWidth, closeButton: closeButton_, } = {
711
- minWidth: 300,
712
- ...options,
713
- };
714
- const closeButton = closeButton_ !== null && closeButton_ !== void 0 ? closeButton_ : !this.options.selectOnHover;
715
- let popup;
716
- const _closeHandlers = [];
717
- const onClose = (handler) => {
718
- _closeHandlers.push(handler);
719
- };
720
- const close = () => {
721
- if (popup) {
722
- this._removePopup(popup);
723
- }
724
- };
725
- let content;
726
- if (options.createPopupContent) {
727
- content = await options.createPopupContent({
728
- layer,
729
- feature,
730
- target: this,
731
- type,
732
- close,
733
- onClose,
734
- ...createFeaturePositionOptions(feature),
735
- });
736
- }
737
- else {
738
- content = options.popupContent;
739
- }
740
- if (content && layer) {
741
- const popupOptions = {
742
- minWidth,
743
- autoPan,
744
- // maxWidth,
745
- closeButton,
746
- closeOnClick: false,
747
- autoClose: false,
748
- };
749
- if (defined(maxWidth)) {
750
- popupOptions.maxWidth = maxWidth;
751
- }
752
- popup = layer.bindPopup(content, popupOptions);
753
- const unselectOnClose = (_b = (_a = this.options.popupOptions) === null || _a === void 0 ? void 0 : _a.unselectOnClose) !== null && _b !== void 0 ? _b : true;
754
- if (unselectOnClose) {
755
- const p = layer.getPopup();
756
- p &&
757
- p.once('remove', () => {
758
- close();
759
- }, this);
760
- }
761
- this._openedPopup.push([popup, _closeHandlers, def]);
762
- popup.openPopup(latLng);
763
- }
764
- }
765
- _removePopup(popup) {
766
- var _a, _b;
767
- const map = this.map;
768
- if (map) {
769
- popup.closePopup().unbindPopup();
770
- const index = this._openedPopup.findIndex((x) => x[0] === popup);
771
- if (index !== -1) {
772
- const unselectOnClose = (_b = (_a = this.options.popupOptions) === null || _a === void 0 ? void 0 : _a.unselectOnClose) !== null && _b !== void 0 ? _b : true;
773
- const [, closeHandlers, def] = this._openedPopup[index];
774
- for (const h of closeHandlers) {
775
- h(def);
776
- }
777
- closeHandlers.length = 0;
778
- if (unselectOnClose) {
779
- this._unSelectLayer(def);
780
- }
781
- this._openedPopup.splice(index, 1);
782
- }
783
- }
784
- }
785
- _getGeoJsonOptions(options, type) {
786
- const paint = options.paint;
787
- let lopt = {};
788
- if (typeof paint === 'function') {
789
- if (type === 'point') {
790
- // TODO: fix types (@geoman-io/leaflet-geoman-free)
791
- lopt.pointToLayer = (feature, latLng) => {
792
- const iconOpt = paint(feature);
793
- const pointToLayer = this._paint.createPaintToLayer(iconOpt);
794
- return pointToLayer(feature, latLng);
795
- };
796
- }
797
- else {
798
- lopt = {
799
- style: (feature) => {
800
- if (feature) {
801
- return this._paint.preparePaint({ ...PAINT, ...paint(feature) });
802
- }
803
- else {
804
- return this._paint.preparePaint({ ...PAINT, type: 'path' });
805
- }
806
- },
807
- };
808
- }
809
- }
810
- else {
811
- lopt = this._paint.createPaintOptions(paint);
812
- }
813
- lopt.onEachFeature = (feature, layer) => {
814
- this._onEachFeature(feature, layer);
815
- };
816
- return lopt;
817
- }
818
- _onEachFeature(feature, layer) {
819
- const layer_ = this.layer;
820
- if (layer_) {
821
- const def = {
822
- target: this,
823
- feature,
824
- layer,
825
- ...createFeaturePositionOptions(feature),
826
- };
827
- layer.options.pane = this.pane;
828
- this._layers.push(def);
829
- let ok = true;
830
- if (this._filterFun) {
831
- ok = this._filterFun(def);
832
- }
833
- if (ok) {
834
- const { popup, popupOptions, selectable, interactive, selectOnHover } = this.options;
835
- // @ts-ignore
836
- layer.options.interactive = defined(interactive) ? interactive : true;
837
- layer_.addLayer(layer);
838
- if (selectable) {
839
- if (selectOnHover) {
840
- layer.on('mouseover', () => {
841
- this._selectLayer(def, 'hover');
842
- });
843
- layer.on('mouseout', () => {
844
- this._unSelectLayer(def);
845
- });
846
- }
847
- else {
848
- layer.on('click', (e) => this._selectOnLayerClick(e), this);
849
- }
850
- }
851
- this._events.handleMouseEvents(layer);
852
- // The timeout is needed to display the popup immediately when adding a layer to the map.
853
- // Without a timeout, the layer may not yet have a _map object
854
- setTimeout(() => {
855
- if (popup) {
856
- this._openPopup({
857
- target: this,
858
- layer,
859
- feature,
860
- ...createFeaturePositionOptions(feature),
861
- }, popupOptions, 'api');
862
- }
863
- this._updateTooltip({ layer, feature });
864
- });
865
- }
866
- }
867
- }
868
- _selectOnLayerClick(e) {
869
- DomEvent.stopPropagation(e);
870
- const layer = e.target;
871
- const feature = layer.feature;
872
- const def = {
647
+ const ok = fun ? fun(__spreadValues$5({
873
648
  target: this,
874
- layer,
875
649
  feature,
876
- ...createFeaturePositionOptions(feature),
650
+ layer
651
+ }, createFeaturePositionOptions(feature))) : true;
652
+ if (ok) {
653
+ layer_.addLayer(layer);
654
+ filteredLayers.push(__spreadValues$5({
655
+ target: this,
656
+ feature,
657
+ layer
658
+ }, createFeaturePositionOptions(feature)));
659
+ } else {
660
+ layer_.removeLayer(layer);
661
+ }
662
+ }
663
+ });
664
+ this._filteredLayers = filteredLayers;
665
+ layer_.addTo(map);
666
+ }
667
+ return this._filteredLayers;
668
+ }
669
+ cleanFilter() {
670
+ this.filter();
671
+ }
672
+ getLayers() {
673
+ return this._layers.map(({ layer, feature }) => {
674
+ const visible = layer && !!layer._map;
675
+ return __spreadValues$5({
676
+ feature,
677
+ layer,
678
+ visible,
679
+ target: this
680
+ }, createFeaturePositionOptions(feature));
681
+ });
682
+ }
683
+ clearLayer(cb) {
684
+ this.unselect();
685
+ const layer_ = this.layer;
686
+ if (layer_) {
687
+ if (cb) {
688
+ for (let fry = this._layers.length; fry--; ) {
689
+ const def = this._layers[fry];
690
+ if (def) {
691
+ const { feature, layer } = def;
692
+ if (feature && layer) {
693
+ const exist = cb(feature);
694
+ if (exist) {
695
+ layer_.removeLayer(layer);
696
+ this._layers.splice(fry, 1);
697
+ }
698
+ }
699
+ }
700
+ }
701
+ } else {
702
+ layer_.clearLayers();
703
+ this._layers = [];
704
+ }
705
+ }
706
+ }
707
+ setData(data) {
708
+ this.clearLayer();
709
+ this.addData(data);
710
+ }
711
+ addData(data) {
712
+ const options = this.options;
713
+ let geoJsonOptions;
714
+ if (options) {
715
+ if (data) {
716
+ let type;
717
+ if (!options.type) {
718
+ const detectedType = detectType(data);
719
+ type = typeAlias[detectedType];
720
+ } else {
721
+ type = options.type;
722
+ }
723
+ if (this.type && this.type !== type) {
724
+ console.warn("no other data type than layer can be added");
725
+ return;
726
+ }
727
+ this.type = type;
728
+ data = filterGeometries(data, type);
729
+ if (data) {
730
+ geoJsonOptions = this._getGeoJsonOptions(options, type);
731
+ }
732
+ }
733
+ new GeoJSON(data || void 0, geoJsonOptions);
734
+ }
735
+ }
736
+ openPopup(findFeatureFun, options) {
737
+ if (findFeatureFun) {
738
+ const def = this._layers.filter(findFeatureFun);
739
+ def.forEach((x) => {
740
+ this._openPopup(x, options, "api");
741
+ });
742
+ }
743
+ }
744
+ closePopup(findFeatureFun) {
745
+ const popupToClose = findFeatureFun ? this._openedPopup.filter((x) => findFeatureFun(x[2])) : this._openedPopup;
746
+ popupToClose.forEach((x) => {
747
+ this._removePopup(x[0]);
748
+ });
749
+ }
750
+ updateTooltip(layerDef) {
751
+ if (layerDef) {
752
+ this._updateTooltip(layerDef);
753
+ } else {
754
+ this.getLayers().forEach(
755
+ (x) => this._updateTooltip({ feature: x.feature, layer: x.layer })
756
+ );
757
+ }
758
+ }
759
+ /** @deprecated use {@link GeoJsonAdapter.getBounds} instead */
760
+ getExtent() {
761
+ return this.getBounds();
762
+ }
763
+ getBounds() {
764
+ if (this.layer) {
765
+ const bounds = this.layer.getBounds();
766
+ if (bounds.isValid()) {
767
+ return boundsToArray(bounds);
768
+ }
769
+ }
770
+ }
771
+ setOpacity(value) {
772
+ this.options.opacity = value;
773
+ this.setPaint(this.paint);
774
+ this.setSelectedPaint(this.selectedPaint);
775
+ }
776
+ setPaint(paint) {
777
+ if (paint) {
778
+ this.paint = paint;
779
+ for (const l of this._layers) {
780
+ this._paint.setPaint(l, paint);
781
+ }
782
+ }
783
+ }
784
+ setSelectedPaint(paint) {
785
+ if (paint) {
786
+ this.selectedPaint = paint;
787
+ for (const l of this._selectedLayers) {
788
+ this._paint.setPaint(l, paint);
789
+ }
790
+ }
791
+ }
792
+ updatePaint(paint) {
793
+ this.paint = __spreadValues$5(__spreadValues$5({}, this.paint), paint);
794
+ for (const l of this._layers) {
795
+ this._paint.setPaint(l, this.paint);
796
+ }
797
+ }
798
+ updateSelectedPaint(paint) {
799
+ this.selectedPaint = __spreadValues$5(__spreadValues$5({}, this.selectedPaint), paint);
800
+ for (const l of this._selectedLayers) {
801
+ this._paint.setPaint(l, this.selectedPaint);
802
+ }
803
+ }
804
+ _getSelected(layer) {
805
+ return this._selectedLayers.find((x) => x.layer === layer);
806
+ }
807
+ _updateTooltip(layerDef) {
808
+ const { feature, layer } = layerDef;
809
+ const { label, labelField, labelOnHover } = this.options;
810
+ if (layer) {
811
+ layer.unbindTooltip();
812
+ let message;
813
+ if (feature.properties && labelField) {
814
+ message = feature.properties[labelField];
815
+ } else if (label) {
816
+ message = label(__spreadValues$5(__spreadValues$5({
817
+ target: this
818
+ }, layerDef), createFeaturePositionOptions(feature)));
819
+ }
820
+ if (message) {
821
+ const permanent = !labelOnHover;
822
+ layer.bindTooltip(String(message), { permanent, sticky: false });
823
+ }
824
+ }
825
+ }
826
+ _openPopup(_0) {
827
+ return __async(this, arguments, function* (def, options = {}, type, latLng) {
828
+ var _a, _b;
829
+ const { feature, layer } = def;
830
+ const {
831
+ minWidth,
832
+ autoPan,
833
+ maxWidth,
834
+ closeButton: closeButton_
835
+ } = __spreadValues$5({
836
+ minWidth: 300
837
+ }, options);
838
+ const closeButton = closeButton_ != null ? closeButton_ : !this.options.selectOnHover;
839
+ let popup;
840
+ const _closeHandlers = [];
841
+ const onClose = (handler) => {
842
+ _closeHandlers.push(handler);
843
+ };
844
+ const close = () => {
845
+ if (popup) {
846
+ this._removePopup(popup);
847
+ }
848
+ };
849
+ let content;
850
+ if (options.createPopupContent) {
851
+ content = yield options.createPopupContent(__spreadValues$5({
852
+ layer,
853
+ feature,
854
+ target: this,
855
+ type,
856
+ close,
857
+ onClose
858
+ }, createFeaturePositionOptions(feature)));
859
+ } else {
860
+ content = options.popupContent;
861
+ }
862
+ if (content && layer) {
863
+ const popupOptions = {
864
+ minWidth,
865
+ autoPan,
866
+ // maxWidth,
867
+ closeButton,
868
+ closeOnClick: false,
869
+ autoClose: false
877
870
  };
878
- const isSelected = this._getSelected(layer);
879
- if (isSelected) {
880
- if (this.options && this.options.unselectOnSecondClick) {
881
- this._unSelectLayer(isSelected);
882
- }
883
- }
884
- else {
885
- this._selectLayer(def, 'click', e.latlng);
886
- }
871
+ if (defined(maxWidth)) {
872
+ popupOptions.maxWidth = maxWidth;
873
+ }
874
+ popup = layer.bindPopup(content, popupOptions);
875
+ const unselectOnClose = (_b = (_a = this.options.popupOptions) == null ? void 0 : _a.unselectOnClose) != null ? _b : true;
876
+ if (unselectOnClose) {
877
+ const p = layer.getPopup();
878
+ p && p.once(
879
+ "remove",
880
+ () => {
881
+ close();
882
+ },
883
+ this
884
+ );
885
+ }
886
+ this._openedPopup.push([popup, _closeHandlers, def]);
887
+ popup.openPopup(latLng);
888
+ }
889
+ });
890
+ }
891
+ _removePopup(popup) {
892
+ var _a, _b;
893
+ const map = this.map;
894
+ if (map) {
895
+ popup.closePopup().unbindPopup();
896
+ const index = this._openedPopup.findIndex((x) => x[0] === popup);
897
+ if (index !== -1) {
898
+ const unselectOnClose = (_b = (_a = this.options.popupOptions) == null ? void 0 : _a.unselectOnClose) != null ? _b : true;
899
+ const [, closeHandlers, def] = this._openedPopup[index];
900
+ for (const h of closeHandlers) {
901
+ h(def);
902
+ }
903
+ closeHandlers.length = 0;
904
+ if (unselectOnClose) {
905
+ this._unSelectLayer(def);
906
+ }
907
+ this._openedPopup.splice(index, 1);
908
+ }
909
+ }
910
+ }
911
+ _getGeoJsonOptions(options, type) {
912
+ const paint = options.paint;
913
+ let lopt = {};
914
+ if (typeof paint === "function") {
915
+ if (type === "point") {
916
+ lopt.pointToLayer = (feature, latLng) => {
917
+ const iconOpt = paint(feature);
918
+ const pointToLayer = this._paint.createPaintToLayer(
919
+ iconOpt
920
+ );
921
+ return pointToLayer(feature, latLng);
922
+ };
923
+ } else {
924
+ lopt = {
925
+ style: (feature) => {
926
+ if (feature) {
927
+ return this._paint.preparePaint(__spreadValues$5(__spreadValues$5({}, PAINT), paint(feature)));
928
+ } else {
929
+ return this._paint.preparePaint(__spreadProps$3(__spreadValues$5({}, PAINT), { type: "path" }));
930
+ }
931
+ }
932
+ };
933
+ }
934
+ } else {
935
+ lopt = this._paint.createPaintOptions(paint);
887
936
  }
888
- _selectLayer(def, type, latlng) {
889
- const { multiselect } = this.options;
890
- if (!multiselect) {
891
- // To unselect layer on another layer click
892
- this.map._addUnselectCb(() => {
893
- this._unSelectLayer(def);
937
+ lopt.onEachFeature = (feature, layer) => {
938
+ this._onEachFeature(feature, layer);
939
+ };
940
+ return lopt;
941
+ }
942
+ _onEachFeature(feature, layer) {
943
+ const layer_ = this.layer;
944
+ if (layer_) {
945
+ const def = __spreadValues$5({
946
+ target: this,
947
+ feature,
948
+ layer
949
+ }, createFeaturePositionOptions(feature));
950
+ layer.options.pane = this.pane;
951
+ this._layers.push(def);
952
+ let ok = true;
953
+ if (this._filterFun) {
954
+ ok = this._filterFun(def);
955
+ }
956
+ if (ok) {
957
+ const { popup, popupOptions, selectable, interactive, selectOnHover } = this.options;
958
+ layer.options.interactive = defined(interactive) ? interactive : true;
959
+ layer_.addLayer(layer);
960
+ if (selectable) {
961
+ if (selectOnHover) {
962
+ layer.on("mouseover", () => {
963
+ this._selectLayer(def, "hover");
894
964
  });
895
- this._selectedLayers.forEach((x) => this._unSelectLayer(x));
896
- }
897
- this._selectedLayers.push(def);
898
- this.selected = true;
899
- const { selectedPaint, popupOnSelect, popupOptions } = this.options;
900
- if (selectedPaint && def.layer) {
901
- this._paint.setPaint(def, selectedPaint);
902
- }
903
- if (popupOnSelect) {
904
- this._openPopup(def, popupOptions, type, latlng);
905
- }
906
- if (this.options.onSelect) {
907
- const features = def.feature ? [def.feature] : [];
908
- this.options.onSelect({
909
- type,
910
- layer: this,
911
- features,
912
- ...createFeaturePositionOptions(features),
965
+ layer.on("mouseout", () => {
966
+ this._unSelectLayer(def);
913
967
  });
914
- }
915
- }
916
- _unSelectLayer(def) {
917
- const index = this._selectedLayers.indexOf(def);
918
- if (index !== -1) {
919
- this._selectedLayers.splice(index, 1);
920
- if (this.options) {
921
- if (this.options.paint) {
922
- this._paint.setPaint(def, this.options.paint);
923
- }
924
- if (this.options.popupOnSelect && def.layer) {
925
- this._removePopup(def.layer);
926
- }
927
- }
928
- }
929
- this.selected = this._selectedLayers.length > 0;
930
- }
931
- _addMapClickListener() {
932
- const map = this.map;
933
- if (map) {
934
- const { unselectOnClick } = this.options;
935
- const uoc = unselectOnClick !== null && unselectOnClick !== void 0 ? unselectOnClick : true;
936
- if (uoc) {
937
- map.on('click', this.$unselect);
938
- }
939
- }
940
- }
941
- _removeMapClickListener() {
942
- this.map.off('zoomend', this.$updateTooltip);
943
- this.map.off('moveend', this.$updateTooltip);
944
- this.map.off('click', this.$unselect);
945
- }
946
- _addMapListener() {
947
- const map = this.map;
948
- if (map) {
949
- const { label, labelField, labelOnHover } = this.options;
950
- this._addMapClickListener();
951
- if ((labelField || label) && !labelOnHover) {
952
- map.on('zoomend', this.$updateTooltip);
953
- map.on('moveend', this.$updateTooltip);
954
- }
955
- }
956
- }
957
- _removeMapListener() {
958
- this._removeMapClickListener();
959
- this.map.off('zoomend', this.$updateTooltip);
960
- this.map.off('moveend', this.$updateTooltip);
961
- }
968
+ } else {
969
+ layer.on(
970
+ "click",
971
+ (e) => this._selectOnLayerClick(e),
972
+ this
973
+ );
974
+ }
975
+ }
976
+ this._events.handleMouseEvents(layer);
977
+ setTimeout(() => {
978
+ if (popup) {
979
+ this._openPopup(
980
+ __spreadValues$5({
981
+ target: this,
982
+ layer,
983
+ feature
984
+ }, createFeaturePositionOptions(feature)),
985
+ popupOptions,
986
+ "api"
987
+ );
988
+ }
989
+ this._updateTooltip({ layer, feature });
990
+ });
991
+ }
992
+ }
993
+ }
994
+ _selectOnLayerClick(e) {
995
+ DomEvent.stopPropagation(e);
996
+ const layer = e.target;
997
+ const feature = layer.feature;
998
+ const def = __spreadValues$5({
999
+ target: this,
1000
+ layer,
1001
+ feature
1002
+ }, createFeaturePositionOptions(feature));
1003
+ const isSelected = this._getSelected(layer);
1004
+ if (isSelected) {
1005
+ if (this.options && this.options.unselectOnSecondClick) {
1006
+ this._unSelectLayer(isSelected);
1007
+ }
1008
+ } else {
1009
+ this._selectLayer(def, "click", e.latlng);
1010
+ }
1011
+ }
1012
+ _selectLayer(def, type, latlng) {
1013
+ const { multiselect } = this.options;
1014
+ if (!multiselect) {
1015
+ this.map._addUnselectCb(() => {
1016
+ this._unSelectLayer(def);
1017
+ });
1018
+ this._selectedLayers.forEach((x) => this._unSelectLayer(x));
1019
+ }
1020
+ this._selectedLayers.push(def);
1021
+ this.selected = true;
1022
+ const { selectedPaint, popupOnSelect, popupOptions } = this.options;
1023
+ if (selectedPaint && def.layer) {
1024
+ this._paint.setPaint(def, selectedPaint);
1025
+ }
1026
+ if (popupOnSelect) {
1027
+ this._openPopup(def, popupOptions, type, latlng);
1028
+ }
1029
+ if (this.options.onSelect) {
1030
+ const features = def.feature ? [def.feature] : [];
1031
+ this.options.onSelect(__spreadValues$5({
1032
+ type,
1033
+ layer: this,
1034
+ features
1035
+ }, createFeaturePositionOptions(features)));
1036
+ }
1037
+ }
1038
+ _unSelectLayer(def) {
1039
+ const index = this._selectedLayers.indexOf(def);
1040
+ if (index !== -1) {
1041
+ this._selectedLayers.splice(index, 1);
1042
+ if (this.options) {
1043
+ if (this.options.paint) {
1044
+ this._paint.setPaint(
1045
+ def,
1046
+ this.options.paint
1047
+ );
1048
+ }
1049
+ if (this.options.popupOnSelect && def.layer) {
1050
+ this._removePopup(def.layer);
1051
+ }
1052
+ }
1053
+ }
1054
+ this.selected = this._selectedLayers.length > 0;
1055
+ }
1056
+ _addMapClickListener() {
1057
+ const map = this.map;
1058
+ if (map) {
1059
+ const { unselectOnClick } = this.options;
1060
+ const uoc = unselectOnClick != null ? unselectOnClick : true;
1061
+ if (uoc) {
1062
+ map.on("click", this.$unselect);
1063
+ }
1064
+ }
1065
+ }
1066
+ _removeMapClickListener() {
1067
+ this.map.off("zoomend", this.$updateTooltip);
1068
+ this.map.off("moveend", this.$updateTooltip);
1069
+ this.map.off("click", this.$unselect);
1070
+ }
1071
+ _addMapListener() {
1072
+ const map = this.map;
1073
+ if (map) {
1074
+ const { label, labelField, labelOnHover } = this.options;
1075
+ this._addMapClickListener();
1076
+ if ((labelField || label) && !labelOnHover) {
1077
+ map.on("zoomend", this.$updateTooltip);
1078
+ map.on("moveend", this.$updateTooltip);
1079
+ }
1080
+ }
1081
+ }
1082
+ _removeMapListener() {
1083
+ this._removeMapClickListener();
1084
+ this.map.off("zoomend", this.$updateTooltip);
1085
+ this.map.off("moveend", this.$updateTooltip);
1086
+ }
962
1087
  }
963
1088
 
964
1089
  function callAjax(src, callback, headers) {
965
- const xhr = new XMLHttpRequest();
966
- xhr.open('GET', src);
967
- xhr.responseType = 'arraybuffer';
968
- for (const h in headers) {
969
- xhr.setRequestHeader(h, headers[h]);
970
- }
971
- xhr.onload = function () {
972
- const arrayBufferView = new Uint8Array(this.response);
973
- const blob = new Blob([arrayBufferView], { type: 'image/png' });
974
- // @ts-ignore for typedoc
975
- const urlCreator = window.URL || window.webkitURL;
976
- const imageUrl = urlCreator.createObjectURL(blob);
977
- callback(imageUrl);
978
- };
979
- xhr.send();
980
- return () => {
981
- xhr.abort();
982
- };
1090
+ const xhr = new XMLHttpRequest();
1091
+ xhr.open("GET", src);
1092
+ xhr.responseType = "arraybuffer";
1093
+ for (const h in headers) {
1094
+ xhr.setRequestHeader(h, headers[h]);
1095
+ }
1096
+ xhr.onload = function() {
1097
+ const arrayBufferView = new Uint8Array(this.response);
1098
+ const blob = new Blob([arrayBufferView], { type: "image/png" });
1099
+ const urlCreator = window.URL || window.webkitURL;
1100
+ const imageUrl = urlCreator.createObjectURL(blob);
1101
+ callback(imageUrl);
1102
+ };
1103
+ xhr.send();
1104
+ return () => {
1105
+ xhr.abort();
1106
+ };
983
1107
  }
984
1108
 
1109
+ var __defProp$6 = Object.defineProperty;
1110
+ var __defNormalProp$6 = (obj, key, value) => key in obj ? __defProp$6(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1111
+ var __publicField$3 = (obj, key, value) => {
1112
+ __defNormalProp$6(obj, typeof key !== "symbol" ? key + "" : key, value);
1113
+ return value;
1114
+ };
985
1115
  class ImageOverlay extends ImageOverlay$1 {
986
- constructor(imageUrl, bounds, options) {
987
- super(imageUrl, bounds, options);
988
- this._abort = [];
989
- }
990
- cancelLoad() {
991
- if (this._abort) {
992
- this._abort.forEach((x) => x());
993
- this._abort = [];
994
- }
995
- }
996
- _initImage() {
997
- // @ts-ignore
998
- super._initImage();
999
- // @ts-ignore
1000
- const headers = this.options.headers;
1001
- if (headers) {
1002
- // @ts-ignore
1003
- const img = this._image;
1004
- const src = img.src;
1005
- img.src = '';
1006
- this._abort.push(callAjax(src, (response) => {
1007
- img.src = response;
1008
- }, headers));
1009
- }
1010
- }
1116
+ constructor(imageUrl, bounds, options) {
1117
+ super(imageUrl, bounds, options);
1118
+ __publicField$3(this, "_abort", []);
1119
+ }
1120
+ cancelLoad() {
1121
+ if (this._abort) {
1122
+ this._abort.forEach((x) => x());
1123
+ this._abort = [];
1124
+ }
1125
+ }
1126
+ _initImage() {
1127
+ super._initImage();
1128
+ const headers = this.options.headers;
1129
+ if (headers) {
1130
+ const img = this._image;
1131
+ const src = img.src;
1132
+ img.src = "";
1133
+ this._abort.push(
1134
+ callAjax(
1135
+ src,
1136
+ (response) => {
1137
+ img.src = response;
1138
+ },
1139
+ headers
1140
+ )
1141
+ );
1142
+ }
1143
+ }
1011
1144
  }
1012
1145
 
1013
- /*!
1014
- * leaflet.wms.js
1015
- * A collection of Leaflet utilities for working with Web Mapping services.
1016
- * (c) 2014-2016, Houston Engineering, Inc.
1017
- * MIT License
1018
- */
1019
- /*
1020
- * Overlay:
1021
- * "Single Tile" WMS image overlay that updates with map changes.
1022
- * Portions of wms.Overlay are directly extracted from L.TileLayer.WMS.
1023
- * See Leaflet license.
1024
- */
1146
+ var __defProp$5 = Object.defineProperty;
1147
+ var __defNormalProp$5 = (obj, key, value) => key in obj ? __defProp$5(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1148
+ var __publicField$2 = (obj, key, value) => {
1149
+ __defNormalProp$5(obj, typeof key !== "symbol" ? key + "" : key, value);
1150
+ return value;
1151
+ };
1025
1152
  class ImageLayer extends Layer {
1026
- constructor(url, options) {
1027
- super(options);
1028
- this.defaultWmsParams = {
1029
- service: 'WMS',
1030
- request: 'GetMap',
1031
- version: '1.1.1',
1032
- layers: '',
1033
- styles: '',
1034
- format: 'image/jpeg',
1035
- transparent: false,
1036
- };
1037
- this.options = {
1038
- crs: null,
1039
- uppercase: false,
1040
- attribution: '',
1041
- opacity: 1,
1042
- isBack: false,
1043
- minZoom: 0,
1044
- pane: 'tilePane',
1045
- headers: null,
1046
- viewPortBuffer: 0,
1047
- setViewDelay: 100,
1048
- };
1049
- this._url = url;
1050
- // Move WMS parameters to params object
1051
- const params = {};
1052
- const opts = {};
1053
- let opt;
1054
- for (opt in options) {
1055
- if (opt in this.options) {
1056
- opts[opt] = options[opt];
1057
- }
1058
- else {
1059
- params[opt] = options[opt];
1060
- }
1061
- }
1062
- Util.setOptions(this, opts);
1063
- this.wmsParams = Util.extend({}, this.defaultWmsParams, params);
1064
- }
1065
- setParams(params) {
1066
- Util.extend(this.wmsParams, params);
1067
- this.update();
1068
- }
1069
- getAttribution() {
1070
- return this.options.attribution || '';
1071
- }
1072
- onAdd() {
1073
- this.update();
1074
- return this;
1075
- }
1076
- onRemove(map) {
1077
- if (this._currentOverlay) {
1078
- this._currentOverlay.cancelLoad();
1079
- map.removeLayer(this._currentOverlay);
1080
- delete this._currentOverlay;
1081
- }
1082
- if (this._currentUrl) {
1083
- delete this._currentUrl;
1084
- }
1085
- return this;
1086
- }
1087
- getEvents() {
1088
- return {
1089
- moveend: debounce$1(this.update, this.options.setViewDelay),
1090
- };
1153
+ constructor(url, options) {
1154
+ super(options);
1155
+ __publicField$2(this, "defaultWmsParams", {
1156
+ service: "WMS",
1157
+ request: "GetMap",
1158
+ version: "1.1.1",
1159
+ layers: "",
1160
+ styles: "",
1161
+ format: "image/jpeg",
1162
+ transparent: false
1163
+ });
1164
+ __publicField$2(this, "options", {
1165
+ crs: null,
1166
+ uppercase: false,
1167
+ attribution: "",
1168
+ opacity: 1,
1169
+ isBack: false,
1170
+ minZoom: 0,
1171
+ pane: "tilePane",
1172
+ headers: null,
1173
+ viewPortBuffer: 0,
1174
+ setViewDelay: 100
1175
+ });
1176
+ __publicField$2(this, "wmsParams");
1177
+ __publicField$2(this, "_url");
1178
+ __publicField$2(this, "_currentUrl");
1179
+ __publicField$2(this, "_currentOverlay");
1180
+ this._url = url;
1181
+ const params = {};
1182
+ const opts = {};
1183
+ let opt;
1184
+ for (opt in options) {
1185
+ if (opt in this.options) {
1186
+ opts[opt] = options[opt];
1187
+ } else {
1188
+ params[opt] = options[opt];
1189
+ }
1190
+ }
1191
+ Util.setOptions(this, opts);
1192
+ this.wmsParams = Util.extend({}, this.defaultWmsParams, params);
1193
+ }
1194
+ setParams(params) {
1195
+ Util.extend(this.wmsParams, params);
1196
+ this.update();
1197
+ }
1198
+ getAttribution() {
1199
+ return this.options.attribution || "";
1200
+ }
1201
+ onAdd() {
1202
+ this.update();
1203
+ return this;
1204
+ }
1205
+ onRemove(map) {
1206
+ if (this._currentOverlay) {
1207
+ this._currentOverlay.cancelLoad();
1208
+ map.removeLayer(this._currentOverlay);
1209
+ delete this._currentOverlay;
1210
+ }
1211
+ if (this._currentUrl) {
1212
+ delete this._currentUrl;
1213
+ }
1214
+ return this;
1215
+ }
1216
+ getEvents() {
1217
+ return {
1218
+ moveend: debounce$1(this.update, this.options.setViewDelay)
1219
+ };
1220
+ }
1221
+ update() {
1222
+ if (!this._map) {
1223
+ return;
1224
+ }
1225
+ this.updateWmsParams();
1226
+ const url = this.getImageUrl();
1227
+ if (this._currentUrl === url) {
1228
+ return;
1229
+ }
1230
+ this._currentUrl = url;
1231
+ const viewPortBuffer = this.options.viewPortBuffer || 0;
1232
+ const bounds = this._map.getBounds().pad(viewPortBuffer);
1233
+ const overlay = new ImageOverlay(url, bounds, {
1234
+ opacity: 0,
1235
+ pane: this.options.pane,
1236
+ headers: this.options.headers
1237
+ });
1238
+ overlay.addTo(this._map);
1239
+ if (this._currentOverlay) {
1240
+ this._currentOverlay.cancelLoad();
1091
1241
  }
1092
- update() {
1242
+ overlay.once(
1243
+ "load",
1244
+ () => {
1093
1245
  if (!this._map) {
1094
- return;
1095
- }
1096
- // Determine image URL and whether it has changed since last update
1097
- this.updateWmsParams();
1098
- const url = this.getImageUrl();
1099
- if (this._currentUrl === url) {
1100
- return;
1101
- }
1102
- this._currentUrl = url;
1103
- // Keep current image overlay in place until new one loads
1104
- // (inspired by esri.leaflet)
1105
- const viewPortBuffer = this.options.viewPortBuffer || 0;
1106
- const bounds = this._map.getBounds().pad(viewPortBuffer);
1107
- const overlay = new ImageOverlay(url, bounds, {
1108
- opacity: 0,
1109
- pane: this.options.pane,
1110
- headers: this.options.headers,
1111
- });
1112
- overlay.addTo(this._map);
1113
- if (this._currentOverlay) {
1114
- this._currentOverlay.cancelLoad();
1115
- }
1116
- overlay.once('load', () => {
1117
- if (!this._map) {
1118
- return;
1119
- }
1120
- // @ts-ignore
1121
- if (overlay._url !== this._currentUrl) {
1122
- this._map.removeLayer(overlay);
1123
- return;
1124
- }
1125
- else if (this._currentOverlay) {
1126
- this._map.removeLayer(this._currentOverlay);
1127
- }
1128
- this._currentOverlay = overlay;
1129
- overlay.setOpacity(this.options.opacity !== undefined ? this.options.opacity : 1);
1130
- if (this.options.isBack === true) {
1131
- overlay.bringToBack();
1132
- }
1133
- if (this.options.isBack === false) {
1134
- overlay.bringToFront();
1135
- }
1136
- if (this.options.zIndex !== undefined) {
1137
- overlay.setZIndex(this.options.zIndex);
1138
- }
1139
- }, this);
1140
- const { minZoom, maxZoom } = this.options;
1141
- if ((minZoom && this._map.getZoom() < minZoom) ||
1142
- (maxZoom && this._map.getZoom() > maxZoom)) {
1143
- this._map.removeLayer(overlay);
1144
- }
1145
- }
1146
- setOpacity(opacity) {
1147
- this.options.opacity = opacity;
1148
- if (this._currentOverlay) {
1149
- this._currentOverlay.setOpacity(opacity);
1150
- }
1151
- }
1152
- bringToBack() {
1153
- this.options.isBack = true;
1154
- if (this._currentOverlay) {
1155
- this._currentOverlay.bringToBack();
1156
- }
1157
- }
1158
- bringToFront() {
1159
- this.options.isBack = false;
1160
- if (this._currentOverlay) {
1161
- this._currentOverlay.bringToFront();
1162
- }
1163
- }
1164
- setZIndex(zIndex) {
1165
- this.options.zIndex = zIndex;
1166
- if (this._currentOverlay) {
1167
- this._currentOverlay.setZIndex(zIndex);
1168
- }
1169
- }
1170
- // See L.TileLayer.WMS: onAdd() & getTileUrl()
1171
- updateWmsParams(map) {
1172
- if (!map) {
1173
- map = this._map;
1174
- }
1175
- // Compute WMS options
1176
- const viewPortBuffer = this.options.viewPortBuffer || 0;
1177
- const bounds = map.getBounds().pad(viewPortBuffer);
1178
- const size = map.getSize();
1179
- if (this.options.viewPortBuffer !== 0) {
1180
- const factor = viewPortBuffer + 1;
1181
- size.x = Math.ceil(size.x * factor);
1182
- size.y = Math.ceil(size.y * factor);
1183
- }
1184
- const wmsVersion = parseFloat(this.wmsParams.version);
1185
- const crs = this.options.crs || map.options.crs;
1186
- const projectionKey = wmsVersion >= 1.3 ? 'crs' : 'srs';
1187
- if (crs) {
1188
- const nw = crs.project(bounds.getNorthWest());
1189
- const se = crs.project(bounds.getSouthEast());
1190
- // Assemble WMS parameter string
1191
- const params = {
1192
- width: size.x,
1193
- height: size.y,
1194
- };
1195
- params[projectionKey] = crs.code;
1196
- params.bbox = (wmsVersion >= 1.3 && crs === CRS.EPSG4326
1197
- ? [se.y, nw.x, nw.y, se.x]
1198
- : [nw.x, se.y, se.x, nw.y]).join(',');
1199
- Util.extend(this.wmsParams, params);
1200
- }
1201
- }
1202
- getImageUrl() {
1203
- const uppercase = this.options.uppercase || false;
1204
- const pstr = Util.getParamString(this.wmsParams, this._url, uppercase);
1205
- return this._url + pstr;
1206
- }
1246
+ return;
1247
+ }
1248
+ if (overlay._url !== this._currentUrl) {
1249
+ this._map.removeLayer(overlay);
1250
+ return;
1251
+ } else if (this._currentOverlay) {
1252
+ this._map.removeLayer(this._currentOverlay);
1253
+ }
1254
+ this._currentOverlay = overlay;
1255
+ overlay.setOpacity(
1256
+ this.options.opacity !== void 0 ? this.options.opacity : 1
1257
+ );
1258
+ if (this.options.isBack === true) {
1259
+ overlay.bringToBack();
1260
+ }
1261
+ if (this.options.isBack === false) {
1262
+ overlay.bringToFront();
1263
+ }
1264
+ if (this.options.zIndex !== void 0) {
1265
+ overlay.setZIndex(this.options.zIndex);
1266
+ }
1267
+ },
1268
+ this
1269
+ );
1270
+ const { minZoom, maxZoom } = this.options;
1271
+ if (minZoom && this._map.getZoom() < minZoom || maxZoom && this._map.getZoom() > maxZoom) {
1272
+ this._map.removeLayer(overlay);
1273
+ }
1274
+ }
1275
+ setOpacity(opacity) {
1276
+ this.options.opacity = opacity;
1277
+ if (this._currentOverlay) {
1278
+ this._currentOverlay.setOpacity(opacity);
1279
+ }
1280
+ }
1281
+ bringToBack() {
1282
+ this.options.isBack = true;
1283
+ if (this._currentOverlay) {
1284
+ this._currentOverlay.bringToBack();
1285
+ }
1286
+ }
1287
+ bringToFront() {
1288
+ this.options.isBack = false;
1289
+ if (this._currentOverlay) {
1290
+ this._currentOverlay.bringToFront();
1291
+ }
1292
+ }
1293
+ setZIndex(zIndex) {
1294
+ this.options.zIndex = zIndex;
1295
+ if (this._currentOverlay) {
1296
+ this._currentOverlay.setZIndex(zIndex);
1297
+ }
1298
+ }
1299
+ // See L.TileLayer.WMS: onAdd() & getTileUrl()
1300
+ updateWmsParams(map) {
1301
+ if (!map) {
1302
+ map = this._map;
1303
+ }
1304
+ const viewPortBuffer = this.options.viewPortBuffer || 0;
1305
+ const bounds = map.getBounds().pad(viewPortBuffer);
1306
+ const size = map.getSize();
1307
+ if (this.options.viewPortBuffer !== 0) {
1308
+ const factor = viewPortBuffer + 1;
1309
+ size.x = Math.ceil(size.x * factor);
1310
+ size.y = Math.ceil(size.y * factor);
1311
+ }
1312
+ const wmsVersion = parseFloat(this.wmsParams.version);
1313
+ const crs = this.options.crs || map.options.crs;
1314
+ const projectionKey = wmsVersion >= 1.3 ? "crs" : "srs";
1315
+ if (crs) {
1316
+ const nw = crs.project(bounds.getNorthWest());
1317
+ const se = crs.project(bounds.getSouthEast());
1318
+ const params = {
1319
+ width: size.x,
1320
+ height: size.y
1321
+ };
1322
+ params[projectionKey] = crs.code;
1323
+ params.bbox = (wmsVersion >= 1.3 && crs === CRS.EPSG4326 ? [se.y, nw.x, nw.y, se.x] : [nw.x, se.y, se.x, nw.y]).join(",");
1324
+ Util.extend(this.wmsParams, params);
1325
+ }
1326
+ }
1327
+ getImageUrl() {
1328
+ const uppercase = this.options.uppercase || false;
1329
+ const pstr = Util.getParamString(this.wmsParams, this._url, uppercase);
1330
+ return this._url + pstr;
1331
+ }
1207
1332
  }
1208
1333
 
1334
+ var __defProp$4 = Object.defineProperty;
1335
+ var __getOwnPropSymbols$4 = Object.getOwnPropertySymbols;
1336
+ var __hasOwnProp$4 = Object.prototype.hasOwnProperty;
1337
+ var __propIsEnum$4 = Object.prototype.propertyIsEnumerable;
1338
+ var __defNormalProp$4 = (obj, key, value) => key in obj ? __defProp$4(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1339
+ var __spreadValues$4 = (a, b) => {
1340
+ for (var prop in b || (b = {}))
1341
+ if (__hasOwnProp$4.call(b, prop))
1342
+ __defNormalProp$4(a, prop, b[prop]);
1343
+ if (__getOwnPropSymbols$4)
1344
+ for (var prop of __getOwnPropSymbols$4(b)) {
1345
+ if (__propIsEnum$4.call(b, prop))
1346
+ __defNormalProp$4(a, prop, b[prop]);
1347
+ }
1348
+ return a;
1349
+ };
1350
+ var __publicField$1 = (obj, key, value) => {
1351
+ __defNormalProp$4(obj, typeof key !== "symbol" ? key + "" : key, value);
1352
+ return value;
1353
+ };
1209
1354
  class ImageAdapter extends BaseAdapter {
1210
- addLayer(options) {
1211
- const url = options && options.url;
1212
- if (url) {
1213
- options = { transparent: true, ...options };
1214
- const updateWmsParamsFromOpt = options.updateWmsParams;
1215
- this.layer = new ImageLayer(url, {
1216
- pane: this.pane,
1217
- headers: options.headers,
1218
- setViewDelay: options.setViewDelay,
1219
- /**
1220
- * TODO: safe remove, use only options.nativeOptions
1221
- */
1222
- ...options,
1223
- ...options.params,
1224
- ...options.nativeOptions,
1225
- });
1226
- if (updateWmsParamsFromOpt) {
1227
- const updateWmsParams = this.layer.updateWmsParams;
1228
- this.layer.updateWmsParams = function (map) {
1229
- updateWmsParams.call(this, map);
1230
- this.wmsParams = updateWmsParamsFromOpt(this.wmsParams);
1231
- };
1232
- }
1233
- return this.layer;
1234
- }
1355
+ constructor() {
1356
+ super(...arguments);
1357
+ __publicField$1(this, "layer");
1358
+ }
1359
+ addLayer(options) {
1360
+ const url = options && options.url;
1361
+ if (url) {
1362
+ options = __spreadValues$4({ transparent: true }, options);
1363
+ const updateWmsParamsFromOpt = options.updateWmsParams;
1364
+ this.layer = new ImageLayer(url, __spreadValues$4(__spreadValues$4(__spreadValues$4({
1365
+ pane: this.pane,
1366
+ headers: options.headers,
1367
+ setViewDelay: options.setViewDelay
1368
+ }, options), options.params), options.nativeOptions));
1369
+ if (updateWmsParamsFromOpt) {
1370
+ const updateWmsParams = this.layer.updateWmsParams;
1371
+ this.layer.updateWmsParams = function(map) {
1372
+ updateWmsParams.call(this, map);
1373
+ this.wmsParams = updateWmsParamsFromOpt(this.wmsParams);
1374
+ };
1375
+ }
1376
+ return this.layer;
1235
1377
  }
1378
+ }
1236
1379
  }
1237
1380
 
1238
- // based on https://github.com/bvaughn/debounce-decorator
1239
1381
  function debounce(cb, wait = 10) {
1240
- let timeoutId;
1241
- function wrapper(...args) {
1242
- wrapper.clear();
1243
- timeoutId = setTimeout(() => {
1244
- timeoutId = null;
1245
- cb.apply(this, args);
1246
- }, wait);
1247
- }
1248
- wrapper.clear = function () {
1249
- if (timeoutId) {
1250
- clearTimeout(timeoutId);
1251
- timeoutId = null;
1252
- }
1253
- };
1254
- return wrapper;
1382
+ let timeoutId;
1383
+ function wrapper(...args) {
1384
+ wrapper.clear();
1385
+ timeoutId = setTimeout(() => {
1386
+ timeoutId = null;
1387
+ cb.apply(this, args);
1388
+ }, wait);
1389
+ }
1390
+ wrapper.clear = function() {
1391
+ if (timeoutId) {
1392
+ clearTimeout(timeoutId);
1393
+ timeoutId = null;
1394
+ }
1395
+ };
1396
+ return wrapper;
1255
1397
  }
1256
1398
 
1257
1399
  function makeRemote(Base) {
1258
- return class RemoteTileLayer extends Base {
1259
- constructor(...args) {
1260
- super(...args);
1261
- if (this.options.setViewDelay) {
1262
- // @ts-ignore
1263
- this._update = debounce((...a) => {
1264
- // @ts-ignore
1265
- GridLayer.prototype._update.call(this, ...a);
1266
- }, this.options.setViewDelay);
1267
- }
1268
- }
1269
- createTile(coords, done) {
1270
- // @ts-ignore
1271
- const url = this.getTileUrl(coords);
1272
- const tile = document.createElement('img');
1273
- tile.abort = callAjax(url, (response) => {
1274
- tile.src = response;
1275
- done(null, tile);
1276
- },
1277
- // @ts-ignore
1278
- this.options.headers);
1279
- if (this.options.crossOrigin || this.options.crossOrigin === '') {
1280
- tile.crossOrigin =
1281
- this.options.crossOrigin === true ? '' : this.options.crossOrigin;
1282
- }
1283
- tile.alt = '';
1284
- tile.setAttribute('role', 'presentation');
1285
- return tile;
1286
- }
1287
- _abortLoading() {
1288
- // @ts-ignore
1289
- const tiles = this._tiles;
1290
- // @ts-ignore
1291
- const tileZoom = this._tileZoom;
1292
- for (const i in tiles) {
1293
- if (tiles[i].coords.z !== tileZoom) {
1294
- const tile = tiles[i].el;
1295
- tile.onload = Util.falseFn;
1296
- tile.onerror = Util.falseFn;
1297
- if (!tile.complete) {
1298
- if (tile.abort) {
1299
- tile.abort();
1300
- }
1301
- tile.src = Util.emptyImageUrl;
1302
- DomUtil.remove(tile);
1303
- delete tiles[i];
1304
- }
1305
- }
1306
- }
1307
- }
1308
- };
1400
+ return class RemoteTileLayer extends Base {
1401
+ constructor(...args) {
1402
+ super(...args);
1403
+ if (this.options.setViewDelay) {
1404
+ this._update = debounce((...a) => {
1405
+ GridLayer.prototype._update.call(this, ...a);
1406
+ }, this.options.setViewDelay);
1407
+ }
1408
+ }
1409
+ createTile(coords, done) {
1410
+ const url = this.getTileUrl(coords);
1411
+ const tile = document.createElement("img");
1412
+ tile.abort = callAjax(
1413
+ url,
1414
+ (response) => {
1415
+ tile.src = response;
1416
+ done(null, tile);
1417
+ },
1418
+ // @ts-ignore
1419
+ this.options.headers
1420
+ );
1421
+ if (this.options.crossOrigin || this.options.crossOrigin === "") {
1422
+ tile.crossOrigin = this.options.crossOrigin === true ? "" : this.options.crossOrigin;
1423
+ }
1424
+ tile.alt = "";
1425
+ tile.setAttribute("role", "presentation");
1426
+ return tile;
1427
+ }
1428
+ _abortLoading() {
1429
+ const tiles = this._tiles;
1430
+ const tileZoom = this._tileZoom;
1431
+ for (const i in tiles) {
1432
+ if (tiles[i].coords.z !== tileZoom) {
1433
+ const tile = tiles[i].el;
1434
+ tile.onload = Util.falseFn;
1435
+ tile.onerror = Util.falseFn;
1436
+ if (!tile.complete) {
1437
+ if (tile.abort) {
1438
+ tile.abort();
1439
+ }
1440
+ tile.src = Util.emptyImageUrl;
1441
+ DomUtil.remove(tile);
1442
+ delete tiles[i];
1443
+ }
1444
+ }
1445
+ }
1446
+ }
1447
+ };
1309
1448
  }
1310
1449
 
1311
1450
  class TileLayerBase extends TileLayer$1 {
1312
- constructor(urlTemplate, options) {
1313
- super(urlTemplate, options);
1314
- Object.assign(this.options, options);
1315
- }
1451
+ constructor(urlTemplate, options) {
1452
+ super(urlTemplate, options);
1453
+ Object.assign(this.options, options);
1454
+ }
1316
1455
  }
1317
1456
  const TileLayer = makeRemote(TileLayerBase);
1318
1457
 
1458
+ var __defProp$3 = Object.defineProperty;
1459
+ var __defProps$2 = Object.defineProperties;
1460
+ var __getOwnPropDescs$2 = Object.getOwnPropertyDescriptors;
1461
+ var __getOwnPropSymbols$3 = Object.getOwnPropertySymbols;
1462
+ var __hasOwnProp$3 = Object.prototype.hasOwnProperty;
1463
+ var __propIsEnum$3 = Object.prototype.propertyIsEnumerable;
1464
+ var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1465
+ var __spreadValues$3 = (a, b) => {
1466
+ for (var prop in b || (b = {}))
1467
+ if (__hasOwnProp$3.call(b, prop))
1468
+ __defNormalProp$3(a, prop, b[prop]);
1469
+ if (__getOwnPropSymbols$3)
1470
+ for (var prop of __getOwnPropSymbols$3(b)) {
1471
+ if (__propIsEnum$3.call(b, prop))
1472
+ __defNormalProp$3(a, prop, b[prop]);
1473
+ }
1474
+ return a;
1475
+ };
1476
+ var __spreadProps$2 = (a, b) => __defProps$2(a, __getOwnPropDescs$2(b));
1477
+ var __objRest$1 = (source, exclude) => {
1478
+ var target = {};
1479
+ for (var prop in source)
1480
+ if (__hasOwnProp$3.call(source, prop) && exclude.indexOf(prop) < 0)
1481
+ target[prop] = source[prop];
1482
+ if (source != null && __getOwnPropSymbols$3)
1483
+ for (var prop of __getOwnPropSymbols$3(source)) {
1484
+ if (exclude.indexOf(prop) < 0 && __propIsEnum$3.call(source, prop))
1485
+ target[prop] = source[prop];
1486
+ }
1487
+ return target;
1488
+ };
1319
1489
  class TileAdapter extends BaseAdapter {
1320
- addLayer(options) {
1321
- this.options = Object.assign(this.options, options);
1322
- if (options) {
1323
- const { url, ...opt } = options;
1324
- if (url) {
1325
- const tileLayerOptions = {
1326
- pane: this.pane,
1327
- attribution: opt.attribution,
1328
- minZoom: opt.minZoom,
1329
- maxZoom: opt.maxZoom,
1330
- ...opt.nativeOptions,
1331
- };
1332
- if (opt.subdomains) {
1333
- tileLayerOptions.subdomains = opt.subdomains;
1334
- }
1335
- let layer;
1336
- if (opt.headers) {
1337
- layer = new TileLayer(url, {
1338
- ...tileLayerOptions,
1339
- headers: opt.headers,
1340
- setViewDelay: opt.setViewDelay,
1341
- });
1342
- }
1343
- else {
1344
- layer = new TileLayer$1(url, tileLayerOptions);
1345
- }
1346
- return layer;
1347
- }
1348
- }
1349
- }
1490
+ addLayer(options) {
1491
+ this.options = Object.assign(this.options, options);
1492
+ if (options) {
1493
+ const _a = options, { url } = _a, opt = __objRest$1(_a, ["url"]);
1494
+ if (url) {
1495
+ const tileLayerOptions = __spreadValues$3({
1496
+ pane: this.pane,
1497
+ attribution: opt.attribution,
1498
+ minZoom: opt.minZoom,
1499
+ maxZoom: opt.maxZoom
1500
+ }, opt.nativeOptions);
1501
+ if (opt.subdomains) {
1502
+ tileLayerOptions.subdomains = opt.subdomains;
1503
+ }
1504
+ let layer;
1505
+ if (opt.headers) {
1506
+ layer = new TileLayer(url, __spreadProps$2(__spreadValues$3({}, tileLayerOptions), {
1507
+ headers: opt.headers,
1508
+ setViewDelay: opt.setViewDelay
1509
+ }));
1510
+ } else {
1511
+ layer = new TileLayer$1(url, tileLayerOptions);
1512
+ }
1513
+ return layer;
1514
+ }
1515
+ }
1516
+ }
1350
1517
  }
1351
1518
 
1519
+ var __defProp$2 = Object.defineProperty;
1520
+ var __defProps$1 = Object.defineProperties;
1521
+ var __getOwnPropDescs$1 = Object.getOwnPropertyDescriptors;
1522
+ var __getOwnPropSymbols$2 = Object.getOwnPropertySymbols;
1523
+ var __hasOwnProp$2 = Object.prototype.hasOwnProperty;
1524
+ var __propIsEnum$2 = Object.prototype.propertyIsEnumerable;
1525
+ var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1526
+ var __spreadValues$2 = (a, b) => {
1527
+ for (var prop in b || (b = {}))
1528
+ if (__hasOwnProp$2.call(b, prop))
1529
+ __defNormalProp$2(a, prop, b[prop]);
1530
+ if (__getOwnPropSymbols$2)
1531
+ for (var prop of __getOwnPropSymbols$2(b)) {
1532
+ if (__propIsEnum$2.call(b, prop))
1533
+ __defNormalProp$2(a, prop, b[prop]);
1534
+ }
1535
+ return a;
1536
+ };
1537
+ var __spreadProps$1 = (a, b) => __defProps$1(a, __getOwnPropDescs$1(b));
1352
1538
  class OsmAdapter extends TileAdapter {
1353
- addLayer(options) {
1354
- const url = 'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png';
1355
- return super.addLayer({
1356
- name: 'OpenStreetMap',
1357
- attribution: '&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors',
1358
- ...options,
1359
- url,
1360
- });
1361
- }
1539
+ addLayer(options) {
1540
+ const url = "https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png";
1541
+ return super.addLayer(__spreadProps$1(__spreadValues$2({
1542
+ name: "OpenStreetMap",
1543
+ attribution: '&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
1544
+ }, options), {
1545
+ url
1546
+ }));
1547
+ }
1362
1548
  }
1363
1549
 
1364
1550
  class WmsLayerBase extends TileLayer$1.WMS {
1365
- constructor(urlTemplate, options) {
1366
- super(urlTemplate, options);
1367
- }
1551
+ constructor(urlTemplate, options) {
1552
+ super(urlTemplate, options);
1553
+ }
1368
1554
  }
1369
1555
  const WmsLayer = makeRemote(WmsLayerBase);
1370
1556
 
1557
+ var __defProp$1 = Object.defineProperty;
1558
+ var __defProps = Object.defineProperties;
1559
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
1560
+ var __getOwnPropSymbols$1 = Object.getOwnPropertySymbols;
1561
+ var __hasOwnProp$1 = Object.prototype.hasOwnProperty;
1562
+ var __propIsEnum$1 = Object.prototype.propertyIsEnumerable;
1563
+ var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1564
+ var __spreadValues$1 = (a, b) => {
1565
+ for (var prop in b || (b = {}))
1566
+ if (__hasOwnProp$1.call(b, prop))
1567
+ __defNormalProp$1(a, prop, b[prop]);
1568
+ if (__getOwnPropSymbols$1)
1569
+ for (var prop of __getOwnPropSymbols$1(b)) {
1570
+ if (__propIsEnum$1.call(b, prop))
1571
+ __defNormalProp$1(a, prop, b[prop]);
1572
+ }
1573
+ return a;
1574
+ };
1575
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
1576
+ var __objRest = (source, exclude) => {
1577
+ var target = {};
1578
+ for (var prop in source)
1579
+ if (__hasOwnProp$1.call(source, prop) && exclude.indexOf(prop) < 0)
1580
+ target[prop] = source[prop];
1581
+ if (source != null && __getOwnPropSymbols$1)
1582
+ for (var prop of __getOwnPropSymbols$1(source)) {
1583
+ if (exclude.indexOf(prop) < 0 && __propIsEnum$1.call(source, prop))
1584
+ target[prop] = source[prop];
1585
+ }
1586
+ return target;
1587
+ };
1371
1588
  class WmsAdapter extends BaseAdapter {
1372
- addLayer(options) {
1373
- Object.assign(this.options, options);
1374
- const { url, ...opt } = options;
1375
- if (url) {
1376
- const layerOptions = {
1377
- pane: this.pane,
1378
- attribution: opt.attribution,
1379
- minZoom: opt.minZoom,
1380
- maxZoom: opt.maxZoom,
1381
- layers: options.layers,
1382
- format: options.format,
1383
- ...options.nativeOptions,
1384
- };
1385
- let layer;
1386
- if (opt.headers) {
1387
- layer = new WmsLayer(url, { ...layerOptions, headers: opt.headers });
1388
- }
1389
- else {
1390
- layer = new TileLayer$1.WMS(url, layerOptions);
1391
- }
1392
- return layer;
1393
- }
1394
- }
1589
+ addLayer(options) {
1590
+ Object.assign(this.options, options);
1591
+ const _a = options, { url } = _a, opt = __objRest(_a, ["url"]);
1592
+ if (url) {
1593
+ const layerOptions = __spreadValues$1({
1594
+ pane: this.pane,
1595
+ attribution: opt.attribution,
1596
+ minZoom: opt.minZoom,
1597
+ maxZoom: opt.maxZoom,
1598
+ layers: options.layers,
1599
+ format: options.format
1600
+ }, options.nativeOptions);
1601
+ let layer;
1602
+ if (opt.headers) {
1603
+ layer = new WmsLayer(url, __spreadProps(__spreadValues$1({}, layerOptions), { headers: opt.headers }));
1604
+ } else {
1605
+ layer = new TileLayer$1.WMS(url, layerOptions);
1606
+ }
1607
+ return layer;
1608
+ }
1609
+ }
1395
1610
  }
1396
1611
 
1397
1612
  function arrayToBoundsExpression(bounds) {
1398
- const e = bounds;
1399
- // top, left, bottom, right
1400
- return [
1401
- [e[3], e[0]],
1402
- [e[1], e[2]],
1403
- ];
1613
+ const e = bounds;
1614
+ return [
1615
+ [e[3], e[0]],
1616
+ [e[1], e[2]]
1617
+ ];
1404
1618
  }
1405
1619
 
1406
- class LeafletMapAdapter$1 {
1407
- constructor() {
1408
- this.options = { target: 'map' };
1409
- this.layerAdapters = LeafletMapAdapter$1.layerAdapters;
1410
- this.controlAdapters = LeafletMapAdapter$1.controlAdapters;
1411
- this.emitter = new EventEmitter();
1412
- this._unselectCb = [];
1413
- this._universalEvents = [
1414
- 'move',
1415
- 'zoom',
1416
- 'zoomend',
1417
- 'zoomstart',
1418
- 'moveend',
1419
- 'movestart',
1420
- ];
1421
- this._positionEvents = [
1422
- 'mousemove',
1423
- 'mouseout',
1424
- 'mouseover',
1425
- ];
1426
- }
1427
- create(options) {
1428
- this.options = { ...options };
1429
- if (this.options.target) {
1430
- const { zoom, center, maxZoom, minZoom, maxBounds: mb, mapAdapterOptions, } = this.options;
1431
- this.map =
1432
- this.options.map ||
1433
- new Map(this.options.target, {
1434
- attributionControl: false,
1435
- zoomControl: false,
1436
- maxBounds: mb ? arrayToBoundsExpression(mb) : undefined,
1437
- maxZoom,
1438
- minZoom,
1439
- center: center && [center[1], center[0]],
1440
- zoom,
1441
- ...mapAdapterOptions,
1442
- });
1443
- // create default pane
1444
- const defPane = this.map.createPane('order-0');
1445
- this.map._addUnselectCb = (def) => {
1446
- this._addUnselectCb(def);
1447
- };
1448
- defPane.style.zIndex = String(0);
1449
- this.emitter.emit('create', this);
1450
- this._addMapListeners();
1451
- }
1452
- }
1453
- destroy() {
1454
- if (this.map) {
1455
- this.map.remove();
1456
- }
1457
- this._stopWatchSizeChangeToUpdateMinZoom();
1458
- }
1459
- getContainer() {
1460
- return this.map && this.map.getContainer();
1461
- }
1462
- getControlContainer() {
1463
- const controlContainer = this.map && this.map._controlContainer;
1464
- if (controlContainer) {
1465
- return controlContainer;
1466
- }
1467
- throw new Error('Leaflet Map is not initialized yet');
1468
- }
1469
- setCursor(cursor) {
1470
- if (this.map) {
1471
- this.map.getContainer().style.cursor = cursor;
1472
- }
1473
- }
1474
- setView(lngLatOrOpt, zoom) {
1475
- const map = this.map;
1476
- if (!map)
1477
- return;
1478
- if (Array.isArray(lngLatOrOpt)) {
1479
- const lngLat = lngLatOrOpt;
1480
- const [lng, lat] = lngLat;
1481
- if (this.map) {
1482
- if (typeof zoom === 'number') {
1483
- this.map.setView([lat, lng], zoom, { animate: false });
1484
- }
1485
- else {
1486
- this.setCenter([lng, lat]);
1487
- }
1488
- }
1489
- }
1490
- else {
1491
- const { zoom, center, maxBounds, bounds, minZoom, maxZoom } = lngLatOrOpt;
1492
- if (center && zoom !== undefined) {
1493
- this.setView(center, zoom);
1494
- }
1495
- else {
1496
- if (zoom !== undefined) {
1497
- this.setZoom(zoom);
1498
- }
1499
- if (center) {
1500
- this.setCenter(center);
1501
- }
1502
- }
1503
- if (bounds) {
1504
- this.fitBounds(bounds);
1505
- }
1506
- if (maxBounds !== undefined) {
1507
- if (maxBounds) {
1508
- const b = arrayToBoundsExpression(maxBounds);
1509
- map.setMaxBounds(b);
1510
- map.setMinZoom(map.getBoundsZoom(b));
1511
- this._watchSizeChangeToUpdateMinZoom(b);
1512
- }
1513
- else {
1514
- // @ts-ignore `null` works for unset maxBounds, but not in typing
1515
- map.setMaxBounds(null);
1516
- this._stopWatchSizeChangeToUpdateMinZoom();
1517
- }
1518
- }
1519
- if (maxZoom !== undefined) {
1520
- map.setMaxZoom(maxZoom);
1521
- }
1522
- if (minZoom !== undefined) {
1523
- this._stopWatchSizeChangeToUpdateMinZoom();
1524
- map.setMinZoom(minZoom);
1525
- }
1526
- }
1527
- }
1528
- setCenter(lngLat) {
1529
- const [lng, lat] = lngLat;
1530
- if (this.map) {
1531
- this.map.panTo([lat, lng]);
1532
- }
1533
- }
1534
- getCenter() {
1535
- const map = this.map;
1536
- if (map) {
1537
- const bounds = map.getBounds();
1538
- const center = bounds.getCenter();
1539
- return [center.lng, center.lat];
1540
- }
1541
- }
1542
- setZoom(zoom) {
1543
- if (this.map) {
1544
- this.map.setZoom(zoom);
1545
- }
1546
- }
1547
- getZoom() {
1548
- var _a;
1549
- return (_a = (this.map && this.map.getZoom())) !== null && _a !== void 0 ? _a : undefined;
1550
- }
1551
- getBounds() {
1552
- if (!this.map)
1553
- return undefined;
1554
- const b = this.map.getBounds();
1555
- const sw = b.getSouthWest();
1556
- const ne = b.getNorthEast();
1557
- return [sw.lng, sw.lat, ne.lng, ne.lat];
1558
- }
1559
- // [west, south, east, north]
1560
- fitBounds(bounds, options = {}) {
1561
- if (this.map) {
1562
- const { maxZoom, offset, padding } = options;
1563
- const opt = {};
1564
- if (maxZoom) {
1565
- opt.maxZoom = maxZoom;
1566
- }
1567
- if (padding) {
1568
- opt.padding = [padding, padding];
1569
- }
1570
- if (offset) {
1571
- opt.padding = offset;
1572
- }
1573
- this.map.fitBounds(arrayToBoundsExpression(bounds), opt);
1574
- }
1575
- }
1576
- getLayerAdapter(name) {
1577
- return LeafletMapAdapter$1.layerAdapters[name];
1578
- }
1579
- createControl(control, options) {
1580
- return createControl(control, options, this);
1581
- }
1582
- createButtonControl(options) {
1583
- return createButtonControl(options, this);
1584
- }
1585
- addControl(control, position) {
1586
- control.options.position = position.replace('-', '');
1587
- if (this.map) {
1588
- this.map.addControl(control);
1589
- return control;
1590
- }
1591
- }
1592
- removeControl(control) {
1593
- if (this.map) {
1594
- this.map.removeControl(control);
1595
- }
1596
- }
1597
- removeLayer(layer) {
1598
- layer && layer.remove && layer.remove();
1599
- }
1600
- showLayer(layer) {
1601
- if (this.map) {
1602
- layer.addTo(this.map);
1603
- }
1604
- }
1605
- hideLayer(layer) {
1606
- layer.remove();
1607
- }
1608
- setLayerOpacity(layer, value) {
1609
- if ('setOpacity' in layer) {
1610
- layer.setOpacity(value);
1611
- }
1612
- }
1613
- setLayerOrder(layer, order, layers) {
1614
- //
1615
- }
1616
- onMapClick(evt) {
1617
- const converted = convertMapClickEvent(evt);
1618
- this.emitter.emit('preclick', converted);
1619
- this.emitter.emit('click', converted);
1620
- }
1621
- locate(opt, events) {
1622
- const map = this.map;
1623
- if (map) {
1624
- map.locate(opt);
1625
- if (events) {
1626
- const { locationfound, locationerror } = events;
1627
- const locationFound = (e) => {
1628
- const event = e;
1629
- const lngLat = [event.latlng.lng, event.latlng.lat];
1630
- locationfound({ lngLat });
1631
- };
1632
- if (locationfound !== undefined) {
1633
- map.on('locationfound', locationFound, this);
1634
- }
1635
- if (locationerror) {
1636
- map.on('locationerror', locationerror, this);
1637
- }
1638
- const stop = () => {
1639
- if (locationfound !== undefined) {
1640
- map.off('locationfound', locationFound);
1641
- }
1642
- if (locationerror) {
1643
- map.off('locationerror', locationerror);
1644
- }
1645
- };
1646
- return { stop };
1647
- }
1648
- }
1649
- const stop = () => void 'fake function';
1650
- return { stop };
1651
- }
1652
- _addUnselectCb(cb) {
1653
- for (const p of this._unselectCb) {
1654
- p();
1655
- }
1656
- this._unselectCb.length = 0;
1657
- this._unselectCb.push(cb);
1658
- }
1659
- _watchSizeChangeToUpdateMinZoom(bounds) {
1660
- this._stopWatchSizeChangeToUpdateMinZoom();
1661
- const container = this.getContainer();
1662
- const map = this.map;
1663
- if (container && map && window.ResizeObserver) {
1664
- this._resizeObserver = new ResizeObserver(() => {
1665
- map.setMinZoom(map.getBoundsZoom(bounds));
1666
- });
1667
- this._resizeObserver.observe(container);
1668
- }
1669
- }
1670
- _stopWatchSizeChangeToUpdateMinZoom() {
1671
- const map = this.map;
1672
- if (map) {
1673
- map.setMinZoom(0);
1674
- }
1675
- if (this._resizeObserver) {
1676
- this._resizeObserver.disconnect();
1677
- this._resizeObserver = undefined;
1678
- }
1679
- }
1680
- _addMapListeners() {
1681
- const map = this.map;
1682
- if (map) {
1683
- map.on('click', (evt) => {
1684
- this.onMapClick(evt);
1685
- });
1686
- for (const e of this._universalEvents) {
1687
- map.on(e, () => this.emitter.emit(e, this), map);
1688
- }
1689
- for (const e of this._positionEvents) {
1690
- map.on(e, (evt) => this.emitter.emit(e, convertMapClickEvent(evt)), map);
1691
- }
1692
- }
1693
- }
1694
- }
1695
- LeafletMapAdapter$1.layerAdapters = {
1696
- GEOJSON: GeoJsonAdapter,
1697
- IMAGE: ImageAdapter,
1698
- TILE: TileAdapter,
1699
- WMS: WmsAdapter,
1700
- // // MVT: MvtAdapter,
1701
- OSM: OsmAdapter,
1620
+ var __defProp = Object.defineProperty;
1621
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
1622
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
1623
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
1624
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1625
+ var __spreadValues = (a, b) => {
1626
+ for (var prop in b || (b = {}))
1627
+ if (__hasOwnProp.call(b, prop))
1628
+ __defNormalProp(a, prop, b[prop]);
1629
+ if (__getOwnPropSymbols)
1630
+ for (var prop of __getOwnPropSymbols(b)) {
1631
+ if (__propIsEnum.call(b, prop))
1632
+ __defNormalProp(a, prop, b[prop]);
1633
+ }
1634
+ return a;
1702
1635
  };
1703
- LeafletMapAdapter$1.controlAdapters = {
1704
- ZOOM: Control.Zoom,
1705
- ATTRIBUTION: AttributionControl,
1636
+ var __publicField = (obj, key, value) => {
1637
+ __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
1638
+ return value;
1706
1639
  };
1707
- LeafletMapAdapter$1.Map = Map;
1708
-
1709
- /**
1710
- * @module leaflet-map-adapter
1711
- */
1712
- var LeafletMapAdapter = LeafletMapAdapter$1;
1640
+ const _LeafletMapAdapter = class _LeafletMapAdapter {
1641
+ constructor() {
1642
+ __publicField(this, "options", { target: "map" });
1643
+ __publicField(this, "layerAdapters", _LeafletMapAdapter.layerAdapters);
1644
+ __publicField(this, "controlAdapters", _LeafletMapAdapter.controlAdapters);
1645
+ __publicField(this, "emitter", new EventEmitter());
1646
+ __publicField(this, "map");
1647
+ __publicField(this, "_resizeObserver");
1648
+ __publicField(this, "_unselectCb", []);
1649
+ __publicField(this, "_universalEvents", [
1650
+ "move",
1651
+ "zoom",
1652
+ "zoomend",
1653
+ "zoomstart",
1654
+ "moveend",
1655
+ "movestart"
1656
+ ]);
1657
+ __publicField(this, "_positionEvents", [
1658
+ "mousemove",
1659
+ "mouseout",
1660
+ "mouseover"
1661
+ ]);
1662
+ }
1663
+ create(options) {
1664
+ this.options = __spreadValues({}, options);
1665
+ if (this.options.target) {
1666
+ const {
1667
+ zoom,
1668
+ center,
1669
+ maxZoom,
1670
+ minZoom,
1671
+ maxBounds: mb,
1672
+ mapAdapterOptions
1673
+ } = this.options;
1674
+ this.map = this.options.map || new Map(this.options.target, __spreadValues({
1675
+ attributionControl: false,
1676
+ zoomControl: false,
1677
+ maxBounds: mb ? arrayToBoundsExpression(mb) : void 0,
1678
+ maxZoom,
1679
+ minZoom,
1680
+ center: center && [center[1], center[0]],
1681
+ zoom
1682
+ }, mapAdapterOptions));
1683
+ const defPane = this.map.createPane("order-0");
1684
+ this.map._addUnselectCb = (def) => {
1685
+ this._addUnselectCb(def);
1686
+ };
1687
+ defPane.style.zIndex = String(0);
1688
+ this.emitter.emit("create", this);
1689
+ this._addMapListeners();
1690
+ }
1691
+ }
1692
+ destroy() {
1693
+ if (this.map) {
1694
+ this.map.remove();
1695
+ }
1696
+ this._stopWatchSizeChangeToUpdateMinZoom();
1697
+ }
1698
+ getContainer() {
1699
+ return this.map && this.map.getContainer();
1700
+ }
1701
+ getControlContainer() {
1702
+ const controlContainer = this.map && this.map._controlContainer;
1703
+ if (controlContainer) {
1704
+ return controlContainer;
1705
+ }
1706
+ throw new Error("Leaflet Map is not initialized yet");
1707
+ }
1708
+ setCursor(cursor) {
1709
+ if (this.map) {
1710
+ this.map.getContainer().style.cursor = cursor;
1711
+ }
1712
+ }
1713
+ setView(lngLatOrOpt, zoom) {
1714
+ const map = this.map;
1715
+ if (!map)
1716
+ return;
1717
+ if (Array.isArray(lngLatOrOpt)) {
1718
+ const lngLat = lngLatOrOpt;
1719
+ const [lng, lat] = lngLat;
1720
+ if (this.map) {
1721
+ if (typeof zoom === "number") {
1722
+ this.map.setView([lat, lng], zoom, { animate: false });
1723
+ } else {
1724
+ this.setCenter([lng, lat]);
1725
+ }
1726
+ }
1727
+ } else {
1728
+ const { zoom: zoom2, center, maxBounds, bounds, minZoom, maxZoom } = lngLatOrOpt;
1729
+ if (center && zoom2 !== void 0) {
1730
+ this.setView(center, zoom2);
1731
+ } else {
1732
+ if (zoom2 !== void 0) {
1733
+ this.setZoom(zoom2);
1734
+ }
1735
+ if (center) {
1736
+ this.setCenter(center);
1737
+ }
1738
+ }
1739
+ if (bounds) {
1740
+ this.fitBounds(bounds);
1741
+ }
1742
+ if (maxBounds !== void 0) {
1743
+ if (maxBounds) {
1744
+ const b = arrayToBoundsExpression(maxBounds);
1745
+ map.setMaxBounds(b);
1746
+ map.setMinZoom(map.getBoundsZoom(b));
1747
+ this._watchSizeChangeToUpdateMinZoom(b);
1748
+ } else {
1749
+ map.setMaxBounds(null);
1750
+ this._stopWatchSizeChangeToUpdateMinZoom();
1751
+ }
1752
+ }
1753
+ if (maxZoom !== void 0) {
1754
+ map.setMaxZoom(maxZoom);
1755
+ }
1756
+ if (minZoom !== void 0) {
1757
+ this._stopWatchSizeChangeToUpdateMinZoom();
1758
+ map.setMinZoom(minZoom);
1759
+ }
1760
+ }
1761
+ }
1762
+ setCenter(lngLat) {
1763
+ const [lng, lat] = lngLat;
1764
+ if (this.map) {
1765
+ this.map.panTo([lat, lng]);
1766
+ }
1767
+ }
1768
+ getCenter() {
1769
+ const map = this.map;
1770
+ if (map) {
1771
+ const bounds = map.getBounds();
1772
+ const center = bounds.getCenter();
1773
+ return [center.lng, center.lat];
1774
+ }
1775
+ }
1776
+ setZoom(zoom) {
1777
+ if (this.map) {
1778
+ this.map.setZoom(zoom);
1779
+ }
1780
+ }
1781
+ getZoom() {
1782
+ var _a;
1783
+ return (_a = this.map && this.map.getZoom()) != null ? _a : void 0;
1784
+ }
1785
+ getBounds() {
1786
+ if (!this.map)
1787
+ return void 0;
1788
+ const b = this.map.getBounds();
1789
+ const sw = b.getSouthWest();
1790
+ const ne = b.getNorthEast();
1791
+ return [sw.lng, sw.lat, ne.lng, ne.lat];
1792
+ }
1793
+ // [west, south, east, north]
1794
+ fitBounds(bounds, options = {}) {
1795
+ if (this.map) {
1796
+ const { maxZoom, offset, padding } = options;
1797
+ const opt = {};
1798
+ if (maxZoom) {
1799
+ opt.maxZoom = maxZoom;
1800
+ }
1801
+ if (padding) {
1802
+ opt.padding = [padding, padding];
1803
+ }
1804
+ if (offset) {
1805
+ opt.padding = offset;
1806
+ }
1807
+ this.map.fitBounds(arrayToBoundsExpression(bounds), opt);
1808
+ }
1809
+ }
1810
+ getLayerAdapter(name) {
1811
+ return _LeafletMapAdapter.layerAdapters[name];
1812
+ }
1813
+ createControl(control, options) {
1814
+ return createControl(control, options, this);
1815
+ }
1816
+ createButtonControl(options) {
1817
+ return createButtonControl(options, this);
1818
+ }
1819
+ addControl(control, position) {
1820
+ control.options.position = position.replace("-", "");
1821
+ if (this.map) {
1822
+ this.map.addControl(control);
1823
+ return control;
1824
+ }
1825
+ }
1826
+ removeControl(control) {
1827
+ if (this.map) {
1828
+ this.map.removeControl(control);
1829
+ }
1830
+ }
1831
+ removeLayer(layer) {
1832
+ layer && layer.remove && layer.remove();
1833
+ }
1834
+ showLayer(layer) {
1835
+ if (this.map) {
1836
+ layer.addTo(this.map);
1837
+ }
1838
+ }
1839
+ hideLayer(layer) {
1840
+ layer.remove();
1841
+ }
1842
+ setLayerOpacity(layer, value) {
1843
+ if ("setOpacity" in layer) {
1844
+ layer.setOpacity(value);
1845
+ }
1846
+ }
1847
+ setLayerOrder(layer, order, layers) {
1848
+ }
1849
+ onMapClick(evt) {
1850
+ const converted = convertMapClickEvent(evt);
1851
+ this.emitter.emit("preclick", converted);
1852
+ this.emitter.emit("click", converted);
1853
+ }
1854
+ locate(opt, events) {
1855
+ const map = this.map;
1856
+ if (map) {
1857
+ map.locate(opt);
1858
+ if (events) {
1859
+ const { locationfound, locationerror } = events;
1860
+ const locationFound = (e) => {
1861
+ const event = e;
1862
+ const lngLat = [event.latlng.lng, event.latlng.lat];
1863
+ locationfound({ lngLat });
1864
+ };
1865
+ if (locationfound !== void 0) {
1866
+ map.on("locationfound", locationFound, this);
1867
+ }
1868
+ if (locationerror) {
1869
+ map.on("locationerror", locationerror, this);
1870
+ }
1871
+ const stop2 = () => {
1872
+ if (locationfound !== void 0) {
1873
+ map.off("locationfound", locationFound);
1874
+ }
1875
+ if (locationerror) {
1876
+ map.off("locationerror", locationerror);
1877
+ }
1878
+ };
1879
+ return { stop: stop2 };
1880
+ }
1881
+ }
1882
+ const stop = () => void 0;
1883
+ return { stop };
1884
+ }
1885
+ _addUnselectCb(cb) {
1886
+ for (const p of this._unselectCb) {
1887
+ p();
1888
+ }
1889
+ this._unselectCb.length = 0;
1890
+ this._unselectCb.push(cb);
1891
+ }
1892
+ _watchSizeChangeToUpdateMinZoom(bounds) {
1893
+ this._stopWatchSizeChangeToUpdateMinZoom();
1894
+ const container = this.getContainer();
1895
+ const map = this.map;
1896
+ if (container && map && window.ResizeObserver) {
1897
+ this._resizeObserver = new ResizeObserver(() => {
1898
+ map.setMinZoom(map.getBoundsZoom(bounds));
1899
+ });
1900
+ this._resizeObserver.observe(container);
1901
+ }
1902
+ }
1903
+ _stopWatchSizeChangeToUpdateMinZoom() {
1904
+ const map = this.map;
1905
+ if (map) {
1906
+ map.setMinZoom(0);
1907
+ }
1908
+ if (this._resizeObserver) {
1909
+ this._resizeObserver.disconnect();
1910
+ this._resizeObserver = void 0;
1911
+ }
1912
+ }
1913
+ _addMapListeners() {
1914
+ const map = this.map;
1915
+ if (map) {
1916
+ map.on("click", (evt) => {
1917
+ this.onMapClick(evt);
1918
+ });
1919
+ for (const e of this._universalEvents) {
1920
+ map.on(e, () => this.emitter.emit(e, this), map);
1921
+ }
1922
+ for (const e of this._positionEvents) {
1923
+ map.on(
1924
+ e,
1925
+ (evt) => this.emitter.emit(
1926
+ e,
1927
+ convertMapClickEvent(evt)
1928
+ ),
1929
+ map
1930
+ );
1931
+ }
1932
+ }
1933
+ }
1934
+ };
1935
+ __publicField(_LeafletMapAdapter, "layerAdapters", {
1936
+ GEOJSON: GeoJsonAdapter,
1937
+ IMAGE: ImageAdapter,
1938
+ TILE: TileAdapter,
1939
+ WMS: WmsAdapter,
1940
+ // // MVT: MvtAdapter,
1941
+ OSM: OsmAdapter
1942
+ });
1943
+ __publicField(_LeafletMapAdapter, "controlAdapters", {
1944
+ ZOOM: Control.Zoom,
1945
+ ATTRIBUTION: AttributionControl
1946
+ });
1947
+ __publicField(_LeafletMapAdapter, "Map", Map);
1948
+ let LeafletMapAdapter = _LeafletMapAdapter;
1713
1949
 
1714
1950
  export { LeafletMapAdapter as default };
1715
1951
  //# sourceMappingURL=leaflet-map-adapter.esm-bundler.js.map