@nextgis/leaflet-map-adapter 1.16.9 → 1.18.0

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