@nextgis/leaflet-map-adapter 1.19.5 → 2.0.0-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,1716 +1,1951 @@
1
- /** Bundle of @nextgis/leaflet-map-adapter; version: 1.19.5; author: NextGIS */
1
+ /** Bundle of @nextgis/leaflet-map-adapter; version: 2.0.0-alpha.1; 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
- // @ts-ignore
828
- layer.options.pane = this.pane;
829
- this._layers.push(def);
830
- let ok = true;
831
- if (this._filterFun) {
832
- ok = this._filterFun(def);
833
- }
834
- if (ok) {
835
- const { popup, popupOptions, selectable, interactive, selectOnHover } = this.options;
836
- // @ts-ignore
837
- layer.options.interactive = defined(interactive) ? interactive : true;
838
- layer_.addLayer(layer);
839
- if (selectable) {
840
- if (selectOnHover) {
841
- layer.on('mouseover', () => {
842
- this._selectLayer(def, 'hover');
843
- });
844
- layer.on('mouseout', () => {
845
- this._unSelectLayer(def);
846
- });
847
- }
848
- else {
849
- layer.on('click', (e) => this._selectOnLayerClick(e), this);
850
- }
851
- }
852
- this._events.handleMouseEvents(layer);
853
- // The timeout is needed to display the popup immediately when adding a layer to the map.
854
- // Without a timeout, the layer may not yet have a _map object
855
- setTimeout(() => {
856
- if (popup) {
857
- this._openPopup({
858
- target: this,
859
- layer,
860
- feature,
861
- ...createFeaturePositionOptions(feature),
862
- }, popupOptions, 'api');
863
- }
864
- this._updateTooltip({ layer, feature });
865
- });
866
- }
867
- }
868
- }
869
- _selectOnLayerClick(e) {
870
- DomEvent.stopPropagation(e);
871
- const layer = e.target;
872
- const feature = layer.feature;
873
- const def = {
647
+ const ok = fun ? fun(__spreadValues$5({
874
648
  target: this,
875
- layer,
876
649
  feature,
877
- ...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
878
870
  };
879
- const isSelected = this._getSelected(layer);
880
- if (isSelected) {
881
- if (this.options && this.options.unselectOnSecondClick) {
882
- this._unSelectLayer(isSelected);
883
- }
884
- }
885
- else {
886
- this._selectLayer(def, 'click', e.latlng);
887
- }
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);
888
936
  }
889
- _selectLayer(def, type, latlng) {
890
- const { multiselect } = this.options;
891
- if (!multiselect) {
892
- // To unselect layer on another layer click
893
- this.map._addUnselectCb(() => {
894
- 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");
895
964
  });
896
- this._selectedLayers.forEach((x) => this._unSelectLayer(x));
897
- }
898
- this._selectedLayers.push(def);
899
- this.selected = true;
900
- const { selectedPaint, popupOnSelect, popupOptions } = this.options;
901
- if (selectedPaint && def.layer) {
902
- this._paint.setPaint(def, selectedPaint);
903
- }
904
- if (popupOnSelect) {
905
- this._openPopup(def, popupOptions, type, latlng);
906
- }
907
- if (this.options.onSelect) {
908
- const features = def.feature ? [def.feature] : [];
909
- this.options.onSelect({
910
- type,
911
- layer: this,
912
- features,
913
- ...createFeaturePositionOptions(features),
965
+ layer.on("mouseout", () => {
966
+ this._unSelectLayer(def);
914
967
  });
915
- }
916
- }
917
- _unSelectLayer(def) {
918
- const index = this._selectedLayers.indexOf(def);
919
- if (index !== -1) {
920
- this._selectedLayers.splice(index, 1);
921
- if (this.options) {
922
- if (this.options.paint) {
923
- this._paint.setPaint(def, this.options.paint);
924
- }
925
- if (this.options.popupOnSelect && def.layer) {
926
- this._removePopup(def.layer);
927
- }
928
- }
929
- }
930
- this.selected = this._selectedLayers.length > 0;
931
- }
932
- _addMapClickListener() {
933
- const map = this.map;
934
- if (map) {
935
- const { unselectOnClick } = this.options;
936
- const uoc = unselectOnClick !== null && unselectOnClick !== void 0 ? unselectOnClick : true;
937
- if (uoc) {
938
- map.on('click', this.$unselect);
939
- }
940
- }
941
- }
942
- _removeMapClickListener() {
943
- this.map.off('zoomend', this.$updateTooltip);
944
- this.map.off('moveend', this.$updateTooltip);
945
- this.map.off('click', this.$unselect);
946
- }
947
- _addMapListener() {
948
- const map = this.map;
949
- if (map) {
950
- const { label, labelField, labelOnHover } = this.options;
951
- this._addMapClickListener();
952
- if ((labelField || label) && !labelOnHover) {
953
- map.on('zoomend', this.$updateTooltip);
954
- map.on('moveend', this.$updateTooltip);
955
- }
956
- }
957
- }
958
- _removeMapListener() {
959
- this._removeMapClickListener();
960
- this.map.off('zoomend', this.$updateTooltip);
961
- this.map.off('moveend', this.$updateTooltip);
962
- }
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
+ }
963
1087
  }
964
1088
 
965
1089
  function callAjax(src, callback, headers) {
966
- const xhr = new XMLHttpRequest();
967
- xhr.open('GET', src);
968
- xhr.responseType = 'arraybuffer';
969
- for (const h in headers) {
970
- xhr.setRequestHeader(h, headers[h]);
971
- }
972
- xhr.onload = function () {
973
- const arrayBufferView = new Uint8Array(this.response);
974
- const blob = new Blob([arrayBufferView], { type: 'image/png' });
975
- // @ts-ignore for typedoc
976
- const urlCreator = window.URL || window.webkitURL;
977
- const imageUrl = urlCreator.createObjectURL(blob);
978
- callback(imageUrl);
979
- };
980
- xhr.send();
981
- return () => {
982
- xhr.abort();
983
- };
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
+ };
984
1107
  }
985
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
+ };
986
1115
  class ImageOverlay extends ImageOverlay$1 {
987
- constructor(imageUrl, bounds, options) {
988
- super(imageUrl, bounds, options);
989
- this._abort = [];
990
- }
991
- cancelLoad() {
992
- if (this._abort) {
993
- this._abort.forEach((x) => x());
994
- this._abort = [];
995
- }
996
- }
997
- _initImage() {
998
- // @ts-ignore
999
- super._initImage();
1000
- // @ts-ignore
1001
- const headers = this.options.headers;
1002
- if (headers) {
1003
- // @ts-ignore
1004
- const img = this._image;
1005
- const src = img.src;
1006
- img.src = '';
1007
- this._abort.push(callAjax(src, (response) => {
1008
- img.src = response;
1009
- }, headers));
1010
- }
1011
- }
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
+ }
1012
1144
  }
1013
1145
 
1014
- /*!
1015
- * leaflet.wms.js
1016
- * A collection of Leaflet utilities for working with Web Mapping services.
1017
- * (c) 2014-2016, Houston Engineering, Inc.
1018
- * MIT License
1019
- */
1020
- /*
1021
- * Overlay:
1022
- * "Single Tile" WMS image overlay that updates with map changes.
1023
- * Portions of wms.Overlay are directly extracted from L.TileLayer.WMS.
1024
- * See Leaflet license.
1025
- */
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
+ };
1026
1152
  class ImageLayer extends Layer {
1027
- constructor(url, options) {
1028
- super(options);
1029
- this.defaultWmsParams = {
1030
- service: 'WMS',
1031
- request: 'GetMap',
1032
- version: '1.1.1',
1033
- layers: '',
1034
- styles: '',
1035
- format: 'image/jpeg',
1036
- transparent: false,
1037
- };
1038
- this.options = {
1039
- crs: null,
1040
- uppercase: false,
1041
- attribution: '',
1042
- opacity: 1,
1043
- isBack: false,
1044
- minZoom: 0,
1045
- pane: 'tilePane',
1046
- headers: null,
1047
- viewPortBuffer: 0,
1048
- setViewDelay: 100,
1049
- };
1050
- this._url = url;
1051
- // Move WMS parameters to params object
1052
- const params = {};
1053
- const opts = {};
1054
- let opt;
1055
- for (opt in options) {
1056
- if (opt in this.options) {
1057
- opts[opt] = options[opt];
1058
- }
1059
- else {
1060
- params[opt] = options[opt];
1061
- }
1062
- }
1063
- Util.setOptions(this, opts);
1064
- this.wmsParams = Util.extend({}, this.defaultWmsParams, params);
1065
- }
1066
- setParams(params) {
1067
- Util.extend(this.wmsParams, params);
1068
- this.update();
1069
- }
1070
- getAttribution() {
1071
- return this.options.attribution || '';
1072
- }
1073
- onAdd() {
1074
- this.update();
1075
- return this;
1076
- }
1077
- onRemove(map) {
1078
- if (this._currentOverlay) {
1079
- this._currentOverlay.cancelLoad();
1080
- map.removeLayer(this._currentOverlay);
1081
- delete this._currentOverlay;
1082
- }
1083
- if (this._currentUrl) {
1084
- delete this._currentUrl;
1085
- }
1086
- return this;
1087
- }
1088
- getEvents() {
1089
- return {
1090
- moveend: debounce$1(this.update, this.options.setViewDelay),
1091
- };
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();
1092
1241
  }
1093
- update() {
1242
+ overlay.once(
1243
+ "load",
1244
+ () => {
1094
1245
  if (!this._map) {
1095
- return;
1096
- }
1097
- // Determine image URL and whether it has changed since last update
1098
- this.updateWmsParams();
1099
- const url = this.getImageUrl();
1100
- if (this._currentUrl === url) {
1101
- return;
1102
- }
1103
- this._currentUrl = url;
1104
- // Keep current image overlay in place until new one loads
1105
- // (inspired by esri.leaflet)
1106
- const viewPortBuffer = this.options.viewPortBuffer || 0;
1107
- const bounds = this._map.getBounds().pad(viewPortBuffer);
1108
- const overlay = new ImageOverlay(url, bounds, {
1109
- opacity: 0,
1110
- pane: this.options.pane,
1111
- headers: this.options.headers,
1112
- });
1113
- overlay.addTo(this._map);
1114
- if (this._currentOverlay) {
1115
- this._currentOverlay.cancelLoad();
1116
- }
1117
- overlay.once('load', () => {
1118
- if (!this._map) {
1119
- return;
1120
- }
1121
- // @ts-ignore
1122
- if (overlay._url !== this._currentUrl) {
1123
- this._map.removeLayer(overlay);
1124
- return;
1125
- }
1126
- else if (this._currentOverlay) {
1127
- this._map.removeLayer(this._currentOverlay);
1128
- }
1129
- this._currentOverlay = overlay;
1130
- overlay.setOpacity(this.options.opacity !== undefined ? this.options.opacity : 1);
1131
- if (this.options.isBack === true) {
1132
- overlay.bringToBack();
1133
- }
1134
- if (this.options.isBack === false) {
1135
- overlay.bringToFront();
1136
- }
1137
- if (this.options.zIndex !== undefined) {
1138
- overlay.setZIndex(this.options.zIndex);
1139
- }
1140
- }, this);
1141
- const { minZoom, maxZoom } = this.options;
1142
- if ((minZoom && this._map.getZoom() < minZoom) ||
1143
- (maxZoom && this._map.getZoom() > maxZoom)) {
1144
- this._map.removeLayer(overlay);
1145
- }
1146
- }
1147
- setOpacity(opacity) {
1148
- this.options.opacity = opacity;
1149
- if (this._currentOverlay) {
1150
- this._currentOverlay.setOpacity(opacity);
1151
- }
1152
- }
1153
- bringToBack() {
1154
- this.options.isBack = true;
1155
- if (this._currentOverlay) {
1156
- this._currentOverlay.bringToBack();
1157
- }
1158
- }
1159
- bringToFront() {
1160
- this.options.isBack = false;
1161
- if (this._currentOverlay) {
1162
- this._currentOverlay.bringToFront();
1163
- }
1164
- }
1165
- setZIndex(zIndex) {
1166
- this.options.zIndex = zIndex;
1167
- if (this._currentOverlay) {
1168
- this._currentOverlay.setZIndex(zIndex);
1169
- }
1170
- }
1171
- // See L.TileLayer.WMS: onAdd() & getTileUrl()
1172
- updateWmsParams(map) {
1173
- if (!map) {
1174
- map = this._map;
1175
- }
1176
- // Compute WMS options
1177
- const viewPortBuffer = this.options.viewPortBuffer || 0;
1178
- const bounds = map.getBounds().pad(viewPortBuffer);
1179
- const size = map.getSize();
1180
- if (this.options.viewPortBuffer !== 0) {
1181
- const factor = viewPortBuffer + 1;
1182
- size.x = Math.ceil(size.x * factor);
1183
- size.y = Math.ceil(size.y * factor);
1184
- }
1185
- const wmsVersion = parseFloat(this.wmsParams.version);
1186
- const crs = this.options.crs || map.options.crs;
1187
- const projectionKey = wmsVersion >= 1.3 ? 'crs' : 'srs';
1188
- if (crs) {
1189
- const nw = crs.project(bounds.getNorthWest());
1190
- const se = crs.project(bounds.getSouthEast());
1191
- // Assemble WMS parameter string
1192
- const params = {
1193
- width: size.x,
1194
- height: size.y,
1195
- };
1196
- params[projectionKey] = crs.code;
1197
- params.bbox = (wmsVersion >= 1.3 && crs === CRS.EPSG4326
1198
- ? [se.y, nw.x, nw.y, se.x]
1199
- : [nw.x, se.y, se.x, nw.y]).join(',');
1200
- Util.extend(this.wmsParams, params);
1201
- }
1202
- }
1203
- getImageUrl() {
1204
- const uppercase = this.options.uppercase || false;
1205
- const pstr = Util.getParamString(this.wmsParams, this._url, uppercase);
1206
- return this._url + pstr;
1207
- }
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
+ }
1208
1332
  }
1209
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
+ };
1210
1354
  class ImageAdapter extends BaseAdapter {
1211
- addLayer(options) {
1212
- const url = options && options.url;
1213
- if (url) {
1214
- options = { transparent: true, ...options };
1215
- const updateWmsParamsFromOpt = options.updateWmsParams;
1216
- this.layer = new ImageLayer(url, {
1217
- pane: this.pane,
1218
- headers: options.headers,
1219
- setViewDelay: options.setViewDelay,
1220
- /**
1221
- * TODO: safe remove, use only options.nativeOptions
1222
- */
1223
- ...options,
1224
- ...options.params,
1225
- ...options.nativeOptions,
1226
- });
1227
- if (updateWmsParamsFromOpt) {
1228
- const updateWmsParams = this.layer.updateWmsParams;
1229
- this.layer.updateWmsParams = function (map) {
1230
- updateWmsParams.call(this, map);
1231
- this.wmsParams = updateWmsParamsFromOpt(this.wmsParams);
1232
- };
1233
- }
1234
- return this.layer;
1235
- }
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;
1236
1377
  }
1378
+ }
1237
1379
  }
1238
1380
 
1239
- // based on https://github.com/bvaughn/debounce-decorator
1240
1381
  function debounce(cb, wait = 10) {
1241
- let timeoutId;
1242
- function wrapper(...args) {
1243
- wrapper.clear();
1244
- timeoutId = setTimeout(() => {
1245
- timeoutId = null;
1246
- cb.apply(this, args);
1247
- }, wait);
1248
- }
1249
- wrapper.clear = function () {
1250
- if (timeoutId) {
1251
- clearTimeout(timeoutId);
1252
- timeoutId = null;
1253
- }
1254
- };
1255
- 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;
1256
1397
  }
1257
1398
 
1258
1399
  function makeRemote(Base) {
1259
- return class RemoteTileLayer extends Base {
1260
- constructor(...args) {
1261
- super(...args);
1262
- if (this.options.setViewDelay) {
1263
- // @ts-ignore
1264
- this._update = debounce((...a) => {
1265
- // @ts-ignore
1266
- GridLayer.prototype._update.call(this, ...a);
1267
- }, this.options.setViewDelay);
1268
- }
1269
- }
1270
- createTile(coords, done) {
1271
- // @ts-ignore
1272
- const url = this.getTileUrl(coords);
1273
- const tile = document.createElement('img');
1274
- tile.abort = callAjax(url, (response) => {
1275
- tile.src = response;
1276
- done(null, tile);
1277
- },
1278
- // @ts-ignore
1279
- this.options.headers);
1280
- if (this.options.crossOrigin || this.options.crossOrigin === '') {
1281
- tile.crossOrigin =
1282
- this.options.crossOrigin === true ? '' : this.options.crossOrigin;
1283
- }
1284
- tile.alt = '';
1285
- tile.setAttribute('role', 'presentation');
1286
- return tile;
1287
- }
1288
- _abortLoading() {
1289
- // @ts-ignore
1290
- const tiles = this._tiles;
1291
- // @ts-ignore
1292
- const tileZoom = this._tileZoom;
1293
- for (const i in tiles) {
1294
- if (tiles[i].coords.z !== tileZoom) {
1295
- const tile = tiles[i].el;
1296
- tile.onload = Util.falseFn;
1297
- tile.onerror = Util.falseFn;
1298
- if (!tile.complete) {
1299
- if (tile.abort) {
1300
- tile.abort();
1301
- }
1302
- tile.src = Util.emptyImageUrl;
1303
- DomUtil.remove(tile);
1304
- delete tiles[i];
1305
- }
1306
- }
1307
- }
1308
- }
1309
- };
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
+ };
1310
1448
  }
1311
1449
 
1312
1450
  class TileLayerBase extends TileLayer$1 {
1313
- constructor(urlTemplate, options) {
1314
- super(urlTemplate, options);
1315
- Object.assign(this.options, options);
1316
- }
1451
+ constructor(urlTemplate, options) {
1452
+ super(urlTemplate, options);
1453
+ Object.assign(this.options, options);
1454
+ }
1317
1455
  }
1318
1456
  const TileLayer = makeRemote(TileLayerBase);
1319
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
+ };
1320
1489
  class TileAdapter extends BaseAdapter {
1321
- addLayer(options) {
1322
- this.options = Object.assign(this.options, options);
1323
- if (options) {
1324
- const { url, ...opt } = options;
1325
- if (url) {
1326
- const tileLayerOptions = {
1327
- pane: this.pane,
1328
- attribution: opt.attribution,
1329
- minZoom: opt.minZoom,
1330
- maxZoom: opt.maxZoom,
1331
- ...opt.nativeOptions,
1332
- };
1333
- if (opt.subdomains) {
1334
- tileLayerOptions.subdomains = opt.subdomains;
1335
- }
1336
- let layer;
1337
- if (opt.headers) {
1338
- layer = new TileLayer(url, {
1339
- ...tileLayerOptions,
1340
- headers: opt.headers,
1341
- setViewDelay: opt.setViewDelay,
1342
- });
1343
- }
1344
- else {
1345
- layer = new TileLayer$1(url, tileLayerOptions);
1346
- }
1347
- return layer;
1348
- }
1349
- }
1350
- }
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
+ }
1351
1517
  }
1352
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));
1353
1538
  class OsmAdapter extends TileAdapter {
1354
- addLayer(options) {
1355
- const url = 'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png';
1356
- return super.addLayer({
1357
- name: 'OpenStreetMap',
1358
- attribution: '&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors',
1359
- ...options,
1360
- url,
1361
- });
1362
- }
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
+ }
1363
1548
  }
1364
1549
 
1365
1550
  class WmsLayerBase extends TileLayer$1.WMS {
1366
- constructor(urlTemplate, options) {
1367
- super(urlTemplate, options);
1368
- }
1551
+ constructor(urlTemplate, options) {
1552
+ super(urlTemplate, options);
1553
+ }
1369
1554
  }
1370
1555
  const WmsLayer = makeRemote(WmsLayerBase);
1371
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
+ };
1372
1588
  class WmsAdapter extends BaseAdapter {
1373
- addLayer(options) {
1374
- Object.assign(this.options, options);
1375
- const { url, ...opt } = options;
1376
- if (url) {
1377
- const layerOptions = {
1378
- pane: this.pane,
1379
- attribution: opt.attribution,
1380
- minZoom: opt.minZoom,
1381
- maxZoom: opt.maxZoom,
1382
- layers: options.layers,
1383
- format: options.format,
1384
- ...options.nativeOptions,
1385
- };
1386
- let layer;
1387
- if (opt.headers) {
1388
- layer = new WmsLayer(url, { ...layerOptions, headers: opt.headers });
1389
- }
1390
- else {
1391
- layer = new TileLayer$1.WMS(url, layerOptions);
1392
- }
1393
- return layer;
1394
- }
1395
- }
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
+ }
1396
1610
  }
1397
1611
 
1398
1612
  function arrayToBoundsExpression(bounds) {
1399
- const e = bounds;
1400
- // top, left, bottom, right
1401
- return [
1402
- [e[3], e[0]],
1403
- [e[1], e[2]],
1404
- ];
1613
+ const e = bounds;
1614
+ return [
1615
+ [e[3], e[0]],
1616
+ [e[1], e[2]]
1617
+ ];
1405
1618
  }
1406
1619
 
1407
- class LeafletMapAdapter$1 {
1408
- constructor() {
1409
- this.options = { target: 'map' };
1410
- this.layerAdapters = LeafletMapAdapter$1.layerAdapters;
1411
- this.controlAdapters = LeafletMapAdapter$1.controlAdapters;
1412
- this.emitter = new EventEmitter();
1413
- this._unselectCb = [];
1414
- this._universalEvents = [
1415
- 'move',
1416
- 'zoom',
1417
- 'zoomend',
1418
- 'zoomstart',
1419
- 'moveend',
1420
- 'movestart',
1421
- ];
1422
- this._positionEvents = [
1423
- 'mousemove',
1424
- 'mouseout',
1425
- 'mouseover',
1426
- ];
1427
- }
1428
- create(options) {
1429
- this.options = { ...options };
1430
- if (this.options.target) {
1431
- const { zoom, center, maxZoom, minZoom, maxBounds: mb, mapAdapterOptions, } = this.options;
1432
- this.map =
1433
- this.options.map ||
1434
- new Map(this.options.target, {
1435
- attributionControl: false,
1436
- zoomControl: false,
1437
- maxBounds: mb ? arrayToBoundsExpression(mb) : undefined,
1438
- maxZoom,
1439
- minZoom,
1440
- center: center && [center[1], center[0]],
1441
- zoom,
1442
- ...mapAdapterOptions,
1443
- });
1444
- // create default pane
1445
- const defPane = this.map.createPane('order-0');
1446
- this.map._addUnselectCb = (def) => {
1447
- this._addUnselectCb(def);
1448
- };
1449
- defPane.style.zIndex = String(0);
1450
- this.emitter.emit('create', this);
1451
- this._addMapListeners();
1452
- }
1453
- }
1454
- destroy() {
1455
- if (this.map) {
1456
- this.map.remove();
1457
- }
1458
- this._stopWatchSizeChangeToUpdateMinZoom();
1459
- }
1460
- getContainer() {
1461
- return this.map && this.map.getContainer();
1462
- }
1463
- getControlContainer() {
1464
- const controlContainer = this.map && this.map._controlContainer;
1465
- if (controlContainer) {
1466
- return controlContainer;
1467
- }
1468
- throw new Error('Leaflet Map is not initialized yet');
1469
- }
1470
- setCursor(cursor) {
1471
- if (this.map) {
1472
- this.map.getContainer().style.cursor = cursor;
1473
- }
1474
- }
1475
- setView(lngLatOrOpt, zoom) {
1476
- const map = this.map;
1477
- if (!map)
1478
- return;
1479
- if (Array.isArray(lngLatOrOpt)) {
1480
- const lngLat = lngLatOrOpt;
1481
- const [lng, lat] = lngLat;
1482
- if (this.map) {
1483
- if (typeof zoom === 'number') {
1484
- this.map.setView([lat, lng], zoom, { animate: false });
1485
- }
1486
- else {
1487
- this.setCenter([lng, lat]);
1488
- }
1489
- }
1490
- }
1491
- else {
1492
- const { zoom, center, maxBounds, bounds, minZoom, maxZoom } = lngLatOrOpt;
1493
- if (center && zoom !== undefined) {
1494
- this.setView(center, zoom);
1495
- }
1496
- else {
1497
- if (zoom !== undefined) {
1498
- this.setZoom(zoom);
1499
- }
1500
- if (center) {
1501
- this.setCenter(center);
1502
- }
1503
- }
1504
- if (bounds) {
1505
- this.fitBounds(bounds);
1506
- }
1507
- if (maxBounds !== undefined) {
1508
- if (maxBounds) {
1509
- const b = arrayToBoundsExpression(maxBounds);
1510
- map.setMaxBounds(b);
1511
- map.setMinZoom(map.getBoundsZoom(b));
1512
- this._watchSizeChangeToUpdateMinZoom(b);
1513
- }
1514
- else {
1515
- // @ts-ignore `null` works for unset maxBounds, but not in typing
1516
- map.setMaxBounds(null);
1517
- this._stopWatchSizeChangeToUpdateMinZoom();
1518
- }
1519
- }
1520
- if (maxZoom !== undefined) {
1521
- map.setMaxZoom(maxZoom);
1522
- }
1523
- if (minZoom !== undefined) {
1524
- this._stopWatchSizeChangeToUpdateMinZoom();
1525
- map.setMinZoom(minZoom);
1526
- }
1527
- }
1528
- }
1529
- setCenter(lngLat) {
1530
- const [lng, lat] = lngLat;
1531
- if (this.map) {
1532
- this.map.panTo([lat, lng]);
1533
- }
1534
- }
1535
- getCenter() {
1536
- const map = this.map;
1537
- if (map) {
1538
- const bounds = map.getBounds();
1539
- const center = bounds.getCenter();
1540
- return [center.lng, center.lat];
1541
- }
1542
- }
1543
- setZoom(zoom) {
1544
- if (this.map) {
1545
- this.map.setZoom(zoom);
1546
- }
1547
- }
1548
- getZoom() {
1549
- var _a;
1550
- return (_a = (this.map && this.map.getZoom())) !== null && _a !== void 0 ? _a : undefined;
1551
- }
1552
- getBounds() {
1553
- if (!this.map)
1554
- return undefined;
1555
- const b = this.map.getBounds();
1556
- const sw = b.getSouthWest();
1557
- const ne = b.getNorthEast();
1558
- return [sw.lng, sw.lat, ne.lng, ne.lat];
1559
- }
1560
- // [west, south, east, north]
1561
- fitBounds(bounds, options = {}) {
1562
- if (this.map) {
1563
- const { maxZoom, offset, padding } = options;
1564
- const opt = {};
1565
- if (maxZoom) {
1566
- opt.maxZoom = maxZoom;
1567
- }
1568
- if (padding) {
1569
- opt.padding = [padding, padding];
1570
- }
1571
- if (offset) {
1572
- opt.padding = offset;
1573
- }
1574
- this.map.fitBounds(arrayToBoundsExpression(bounds), opt);
1575
- }
1576
- }
1577
- getLayerAdapter(name) {
1578
- return LeafletMapAdapter$1.layerAdapters[name];
1579
- }
1580
- createControl(control, options) {
1581
- return createControl(control, options, this);
1582
- }
1583
- createButtonControl(options) {
1584
- return createButtonControl(options, this);
1585
- }
1586
- addControl(control, position) {
1587
- control.options.position = position.replace('-', '');
1588
- if (this.map) {
1589
- this.map.addControl(control);
1590
- return control;
1591
- }
1592
- }
1593
- removeControl(control) {
1594
- if (this.map) {
1595
- this.map.removeControl(control);
1596
- }
1597
- }
1598
- removeLayer(layer) {
1599
- layer && layer.remove && layer.remove();
1600
- }
1601
- showLayer(layer) {
1602
- if (this.map) {
1603
- layer.addTo(this.map);
1604
- }
1605
- }
1606
- hideLayer(layer) {
1607
- layer.remove();
1608
- }
1609
- setLayerOpacity(layer, value) {
1610
- if ('setOpacity' in layer) {
1611
- layer.setOpacity(value);
1612
- }
1613
- }
1614
- setLayerOrder(layer, order, layers) {
1615
- //
1616
- }
1617
- onMapClick(evt) {
1618
- const converted = convertMapClickEvent(evt);
1619
- this.emitter.emit('preclick', converted);
1620
- this.emitter.emit('click', converted);
1621
- }
1622
- locate(opt, events) {
1623
- const map = this.map;
1624
- if (map) {
1625
- map.locate(opt);
1626
- if (events) {
1627
- const { locationfound, locationerror } = events;
1628
- const locationFound = (e) => {
1629
- const event = e;
1630
- const lngLat = [event.latlng.lng, event.latlng.lat];
1631
- locationfound({ lngLat });
1632
- };
1633
- if (locationfound !== undefined) {
1634
- map.on('locationfound', locationFound, this);
1635
- }
1636
- if (locationerror) {
1637
- map.on('locationerror', locationerror, this);
1638
- }
1639
- const stop = () => {
1640
- if (locationfound !== undefined) {
1641
- map.off('locationfound', locationFound);
1642
- }
1643
- if (locationerror) {
1644
- map.off('locationerror', locationerror);
1645
- }
1646
- };
1647
- return { stop };
1648
- }
1649
- }
1650
- const stop = () => void 'fake function';
1651
- return { stop };
1652
- }
1653
- _addUnselectCb(cb) {
1654
- for (const p of this._unselectCb) {
1655
- p();
1656
- }
1657
- this._unselectCb.length = 0;
1658
- this._unselectCb.push(cb);
1659
- }
1660
- _watchSizeChangeToUpdateMinZoom(bounds) {
1661
- this._stopWatchSizeChangeToUpdateMinZoom();
1662
- const container = this.getContainer();
1663
- const map = this.map;
1664
- if (container && map && window.ResizeObserver) {
1665
- this._resizeObserver = new ResizeObserver(() => {
1666
- map.setMinZoom(map.getBoundsZoom(bounds));
1667
- });
1668
- this._resizeObserver.observe(container);
1669
- }
1670
- }
1671
- _stopWatchSizeChangeToUpdateMinZoom() {
1672
- const map = this.map;
1673
- if (map) {
1674
- map.setMinZoom(0);
1675
- }
1676
- if (this._resizeObserver) {
1677
- this._resizeObserver.disconnect();
1678
- this._resizeObserver = undefined;
1679
- }
1680
- }
1681
- _addMapListeners() {
1682
- const map = this.map;
1683
- if (map) {
1684
- map.on('click', (evt) => {
1685
- this.onMapClick(evt);
1686
- });
1687
- for (const e of this._universalEvents) {
1688
- map.on(e, () => this.emitter.emit(e, this), map);
1689
- }
1690
- for (const e of this._positionEvents) {
1691
- map.on(e, (evt) => this.emitter.emit(e, convertMapClickEvent(evt)), map);
1692
- }
1693
- }
1694
- }
1695
- }
1696
- LeafletMapAdapter$1.layerAdapters = {
1697
- GEOJSON: GeoJsonAdapter,
1698
- IMAGE: ImageAdapter,
1699
- TILE: TileAdapter,
1700
- WMS: WmsAdapter,
1701
- // // MVT: MvtAdapter,
1702
- 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;
1703
1635
  };
1704
- LeafletMapAdapter$1.controlAdapters = {
1705
- ZOOM: Control.Zoom,
1706
- ATTRIBUTION: AttributionControl,
1636
+ var __publicField = (obj, key, value) => {
1637
+ __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
1638
+ return value;
1707
1639
  };
1708
- LeafletMapAdapter$1.Map = Map;
1709
-
1710
- /**
1711
- * @module leaflet-map-adapter
1712
- */
1713
- 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;
1714
1949
 
1715
1950
  export { LeafletMapAdapter as default };
1716
1951
  //# sourceMappingURL=leaflet-map-adapter.esm-bundler.js.map