@nextgis/leaflet-map-adapter 1.16.8 → 1.17.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,106 +1,4 @@
1
- /** Bundle of @nextgis/leaflet-map-adapter; version: 1.16.8; author: NextGIS */
2
- /******************************************************************************
3
- Copyright (c) Microsoft Corporation.
4
-
5
- Permission to use, copy, modify, and/or distribute this software for any
6
- purpose with or without fee is hereby granted.
7
-
8
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
9
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
10
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
11
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
12
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
13
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
14
- PERFORMANCE OF THIS SOFTWARE.
15
- ***************************************************************************** */
16
- /* global Reflect, Promise */
17
-
18
- var extendStatics = function(d, b) {
19
- extendStatics = Object.setPrototypeOf ||
20
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
21
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
22
- return extendStatics(d, b);
23
- };
24
-
25
- function __extends(d, b) {
26
- if (typeof b !== "function" && b !== null)
27
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
28
- extendStatics(d, b);
29
- function __() { this.constructor = d; }
30
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
31
- }
32
-
33
- var __assign = function() {
34
- __assign = Object.assign || function __assign(t) {
35
- for (var s, i = 1, n = arguments.length; i < n; i++) {
36
- s = arguments[i];
37
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
38
- }
39
- return t;
40
- };
41
- return __assign.apply(this, arguments);
42
- };
43
-
44
- function __rest(s, e) {
45
- var t = {};
46
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
47
- t[p] = s[p];
48
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
49
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
50
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
51
- t[p[i]] = s[p[i]];
52
- }
53
- return t;
54
- }
55
-
56
- function __awaiter(thisArg, _arguments, P, generator) {
57
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
58
- return new (P || (P = Promise))(function (resolve, reject) {
59
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
60
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
61
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
62
- step((generator = generator.apply(thisArg, _arguments || [])).next());
63
- });
64
- }
65
-
66
- function __generator(thisArg, body) {
67
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
68
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
69
- function verb(n) { return function (v) { return step([n, v]); }; }
70
- function step(op) {
71
- if (f) throw new TypeError("Generator is already executing.");
72
- while (_) try {
73
- 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;
74
- if (y = 0, t) op = [op[0] & 2, t.value];
75
- switch (op[0]) {
76
- case 0: case 1: t = op; break;
77
- case 4: _.label++; return { value: op[1], done: false };
78
- case 5: _.label++; y = op[1]; op = [0]; continue;
79
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
80
- default:
81
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
82
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
83
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
84
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
85
- if (t[2]) _.ops.pop();
86
- _.trys.pop(); continue;
87
- }
88
- op = body.call(thisArg, _);
89
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
90
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
91
- }
92
- }
93
-
94
- function __spreadArray(to, from, pack) {
95
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
96
- if (ar || !(i in from)) {
97
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
98
- ar[i] = from[i];
99
- }
100
- }
101
- return to.concat(ar || Array.prototype.slice.call(from));
102
- }
103
-
1
+ /** Bundle of @nextgis/leaflet-map-adapter; version: 1.17.0; author: NextGIS */
104
2
  var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
105
3
 
106
4
  var events = {exports: {}};
@@ -14643,1703 +14541,1694 @@ var leafletSrc = {exports: {}};
14643
14541
 
14644
14542
  } (leafletSrc, leafletSrc.exports));
14645
14543
 
14646
- function convertMapClickEvent(evt) {
14647
- var coord = evt.containerPoint;
14648
- var latLng = evt.latlng;
14649
- var lat = latLng.lat, lng = latLng.lng;
14650
- return {
14651
- latLng: latLng,
14652
- lngLat: [lng, lat],
14653
- pixel: { left: coord.x, top: coord.y },
14654
- source: evt,
14655
- };
14544
+ function convertMapClickEvent(evt) {
14545
+ const coord = evt.containerPoint;
14546
+ const latLng = evt.latlng;
14547
+ const { lat, lng } = latLng;
14548
+ return {
14549
+ latLng,
14550
+ lngLat: [lng, lat],
14551
+ pixel: { left: coord.x, top: coord.y },
14552
+ source: evt,
14553
+ };
14656
14554
  }
14657
14555
 
14658
- function createControl(control, options, map) {
14659
- if (options === void 0) { options = {}; }
14660
- var C = leafletSrc.exports.Control.extend({
14661
- onAdd: function () {
14662
- var element = document.createElement('div');
14663
- var content = control.onAdd(map);
14664
- element.classList.add('leaflet-control');
14665
- if (options.bar) {
14666
- element.classList.add('leaflet-bar');
14667
- }
14668
- if (options.addClass) {
14669
- element.classList.add(options.addClass);
14670
- }
14671
- if (!options.margin && !options.bar) {
14672
- element.style.marginBottom = '0px';
14673
- element.style.marginTop = '0px';
14674
- element.style.marginLeft = '0px';
14675
- element.style.marginRight = '0px';
14676
- }
14677
- if (content) {
14678
- element.appendChild(content);
14679
- }
14680
- leafletSrc.exports.DomEvent.disableClickPropagation(element);
14681
- return element;
14682
- },
14683
- onRemove: function () {
14684
- control.onRemove();
14685
- },
14686
- });
14687
- return new C();
14556
+ function createControl(control, options = {}, map) {
14557
+ const C = leafletSrc.exports.Control.extend({
14558
+ onAdd() {
14559
+ const element = document.createElement('div');
14560
+ const content = control.onAdd(map);
14561
+ element.classList.add('leaflet-control');
14562
+ if (options.bar) {
14563
+ element.classList.add('leaflet-bar');
14564
+ }
14565
+ if (options.addClass) {
14566
+ element.classList.add(options.addClass);
14567
+ }
14568
+ if (!options.margin && !options.bar) {
14569
+ element.style.marginBottom = '0px';
14570
+ element.style.marginTop = '0px';
14571
+ element.style.marginLeft = '0px';
14572
+ element.style.marginRight = '0px';
14573
+ }
14574
+ if (content) {
14575
+ element.appendChild(content);
14576
+ }
14577
+ leafletSrc.exports.DomEvent.disableClickPropagation(element);
14578
+ return element;
14579
+ },
14580
+ onRemove() {
14581
+ control.onRemove();
14582
+ },
14583
+ });
14584
+ return new C();
14688
14585
  }
14689
14586
 
14690
- function createButtonControl(options, map) {
14691
- var link = document.createElement('a');
14692
- var title = options.title || '';
14693
- link.href = '#';
14694
- link.title = title;
14695
- link.setAttribute('role', 'button');
14696
- link.setAttribute('aria-label', title);
14697
- if (options.addClass) {
14698
- link.classList.add(options.addClass);
14699
- }
14700
- leafletSrc.exports.DomEvent.disableClickPropagation(link);
14701
- leafletSrc.exports.DomEvent.on(link, 'click', leafletSrc.exports.DomEvent.stop);
14702
- if (options.html instanceof HTMLElement) {
14703
- link.appendChild(options.html);
14704
- }
14705
- else if (typeof options.html === 'string') {
14706
- link.innerHTML = options.html;
14707
- }
14708
- var onClick = function (e) {
14709
- e.stopPropagation();
14710
- options.onClick();
14711
- };
14712
- return createControl({
14713
- onAdd: function () {
14714
- if (options.onClick !== undefined) {
14715
- link.addEventListener('click', onClick);
14716
- }
14717
- return link;
14718
- },
14719
- onRemove: function () {
14720
- var parent = link.parentNode;
14721
- if (parent) {
14722
- parent.removeChild(link);
14723
- }
14724
- if (options.onClick !== undefined) {
14725
- link.removeEventListener('click', onClick);
14726
- }
14727
- },
14728
- }, { bar: true }, map);
14587
+ function createButtonControl(options, map) {
14588
+ const link = document.createElement('a');
14589
+ const title = options.title || '';
14590
+ link.href = '#';
14591
+ link.title = title;
14592
+ link.setAttribute('role', 'button');
14593
+ link.setAttribute('aria-label', title);
14594
+ if (options.addClass) {
14595
+ link.classList.add(options.addClass);
14596
+ }
14597
+ leafletSrc.exports.DomEvent.disableClickPropagation(link);
14598
+ leafletSrc.exports.DomEvent.on(link, 'click', leafletSrc.exports.DomEvent.stop);
14599
+ if (options.html instanceof HTMLElement) {
14600
+ link.appendChild(options.html);
14601
+ }
14602
+ else if (typeof options.html === 'string') {
14603
+ link.innerHTML = options.html;
14604
+ }
14605
+ const onClick = (e) => {
14606
+ e.stopPropagation();
14607
+ options.onClick();
14608
+ };
14609
+ return createControl({
14610
+ onAdd() {
14611
+ if (options.onClick !== undefined) {
14612
+ link.addEventListener('click', onClick);
14613
+ }
14614
+ return link;
14615
+ },
14616
+ onRemove() {
14617
+ const parent = link.parentNode;
14618
+ if (parent) {
14619
+ parent.removeChild(link);
14620
+ }
14621
+ if (options.onClick !== undefined) {
14622
+ link.removeEventListener('click', onClick);
14623
+ }
14624
+ },
14625
+ }, { bar: true }, map);
14729
14626
  }
14730
14627
 
14731
- var AttributionControl = /** @class */ (function (_super) {
14732
- __extends(AttributionControl, _super);
14733
- // options: AttributionControlOptions
14734
- function AttributionControl(options) {
14735
- var _this = _super.call(this, options) || this;
14736
- var customAttribution = options && options.customAttribution;
14737
- if (customAttribution) {
14738
- var attributions = [];
14739
- if (Array.isArray(customAttribution)) {
14740
- attributions = customAttribution;
14741
- }
14742
- else if (customAttribution) {
14743
- attributions = [customAttribution];
14744
- }
14745
- attributions.forEach(function (x) { return _this.addAttribution(x); });
14746
- }
14747
- return _this;
14748
- }
14749
- return AttributionControl;
14750
- }(leafletSrc.exports.Control.Attribution));
14751
-
14752
- /**
14753
- * from https://github.com/CesiumGS/cesium/blob/master/Source/Core/defined.js
14754
- *
14755
- * @param val - The object.
14756
- * @returns Returns true if the object is defined, returns false otherwise.
14757
- *
14758
- * @example
14759
- * ```javascript
14760
- * if (defined(positions)) {
14761
- * doSomething();
14762
- * } else {
14763
- * doSomethingElse();
14764
- * }
14765
- * ```
14766
- */
14767
- function defined(val) {
14768
- return val !== undefined && val !== null;
14628
+ class AttributionControl extends leafletSrc.exports.Control.Attribution {
14629
+ // options: AttributionControlOptions
14630
+ constructor(options) {
14631
+ super(options);
14632
+ const customAttribution = options && options.customAttribution;
14633
+ if (customAttribution) {
14634
+ let attributions = [];
14635
+ if (Array.isArray(customAttribution)) {
14636
+ attributions = customAttribution;
14637
+ }
14638
+ else if (customAttribution) {
14639
+ attributions = [customAttribution];
14640
+ }
14641
+ attributions.forEach((x) => this.addAttribution(x));
14642
+ }
14643
+ }
14769
14644
  }
14770
14645
 
14771
- // based on https://github.com/bvaughn/debounce-decorator
14772
- function debounce(cb, wait) {
14773
- if (wait === void 0) { wait = 10; }
14774
- var timeoutId;
14775
- function wrapper() {
14776
- var _this = this;
14777
- var args = [];
14778
- for (var _i = 0; _i < arguments.length; _i++) {
14779
- args[_i] = arguments[_i];
14780
- }
14781
- wrapper.clear();
14782
- timeoutId = setTimeout(function () {
14783
- timeoutId = null;
14784
- cb.apply(_this, args);
14785
- }, wait);
14786
- }
14787
- wrapper.clear = function () {
14788
- if (timeoutId) {
14789
- clearTimeout(timeoutId);
14790
- timeoutId = null;
14791
- }
14792
- };
14793
- return wrapper;
14646
+ /**
14647
+ * from https://github.com/CesiumGS/cesium/blob/master/Source/Core/defined.js
14648
+ *
14649
+ * @param val - The object.
14650
+ * @returns Returns true if the object is defined, returns false otherwise.
14651
+ *
14652
+ * @example
14653
+ * ```javascript
14654
+ * if (defined(positions)) {
14655
+ * doSomething();
14656
+ * } else {
14657
+ * doSomethingElse();
14658
+ * }
14659
+ * ```
14660
+ */
14661
+ function defined(val) {
14662
+ return val !== undefined && val !== null;
14794
14663
  }
14795
14664
 
14796
- function isPaint(paint) {
14797
- if (Object.prototype.toString.call(paint) === '[object Object]') {
14798
- return true;
14799
- }
14800
- return false;
14801
- }
14802
- function isPaintCallback(paint) {
14803
- if (typeof paint === 'function') {
14804
- return true;
14805
- }
14806
- return false;
14665
+ // based on https://github.com/bvaughn/debounce-decorator
14666
+ function debounce(cb, wait = 10) {
14667
+ let timeoutId;
14668
+ function wrapper(...args) {
14669
+ wrapper.clear();
14670
+ timeoutId = setTimeout(() => {
14671
+ timeoutId = null;
14672
+ cb.apply(this, args);
14673
+ }, wait);
14674
+ }
14675
+ wrapper.clear = function () {
14676
+ if (timeoutId) {
14677
+ clearTimeout(timeoutId);
14678
+ timeoutId = null;
14679
+ }
14680
+ };
14681
+ return wrapper;
14807
14682
  }
14808
14683
 
14809
- function boundsToArray(bounds) {
14810
- var ne = bounds.getNorthEast();
14811
- var sw = bounds.getSouthWest();
14812
- return [sw.lng, sw.lat, ne.lng, ne.lat];
14684
+ function isPaint(paint) {
14685
+ if (Object.prototype.toString.call(paint) === '[object Object]') {
14686
+ return true;
14687
+ }
14688
+ return false;
14689
+ }
14690
+ function isPaintCallback(paint) {
14691
+ if (typeof paint === 'function') {
14692
+ return true;
14693
+ }
14694
+ return false;
14813
14695
  }
14814
14696
 
14815
- var typeAlias = {
14816
- Point: 'point',
14817
- LineString: 'line',
14818
- MultiPoint: 'point',
14819
- Polygon: 'polygon',
14820
- MultiLineString: 'line',
14821
- MultiPolygon: 'polygon',
14822
- GeometryCollection: 'polygon',
14823
- };
14824
- var PAINT = {
14825
- stroke: false,
14826
- opacity: 1,
14827
- };
14828
- var backAliases = {};
14829
- for (var a in typeAlias) {
14830
- var layerType = typeAlias[a];
14831
- var backAlias = backAliases[layerType] || [];
14832
- backAlias.push(a);
14833
- backAliases[layerType] = backAlias;
14834
- }
14835
- function geometryFilter(geometry, type) {
14836
- var geoJsonGeometry = backAliases[type] || [];
14837
- return geoJsonGeometry.indexOf(geometry) !== -1;
14838
- }
14839
- function filterGeometries(data, type) {
14840
- if (data.type === 'FeatureCollection') {
14841
- var _data = data;
14842
- _data.features = _data.features.filter(function (f) {
14843
- return geometryFilter(f.geometry.type, type);
14844
- });
14845
- }
14846
- else if (data.type === 'Feature') {
14847
- var allow = geometryFilter(data.geometry.type, type);
14848
- if (!allow) {
14849
- return false;
14850
- }
14851
- }
14852
- else if (data.type === 'GeometryCollection') {
14853
- var _data = data;
14854
- _data.geometries = _data.geometries.filter(function (g) {
14855
- return geometryFilter(g.type, type);
14856
- });
14857
- }
14858
- return data;
14859
- }
14860
- function featuresBounds(features) {
14861
- var geoJsonLayer = new leafletSrc.exports.GeoJSON();
14862
- var features_ = Array.isArray(features) ? features : [features];
14863
- features_.forEach(function (f) { return geoJsonLayer.addData(f); });
14864
- return geoJsonLayer.getBounds();
14865
- }
14866
- function getFeaturesBounds(features) {
14867
- return boundsToArray(featuresBounds(features));
14868
- }
14869
- function getFeaturesCenter(features) {
14870
- var _a = featuresBounds(features).getCenter(), lat = _a.lat, lng = _a.lng;
14871
- return [lng, lat];
14872
- }
14873
- function createFeaturePositionOptions(features) {
14874
- return {
14875
- getBounds: function () { return getFeaturesBounds(features); },
14876
- getCenter: function () { return getFeaturesCenter(features); },
14877
- };
14697
+ function boundsToArray(bounds) {
14698
+ const ne = bounds.getNorthEast();
14699
+ const sw = bounds.getSouthWest();
14700
+ return [sw.lng, sw.lat, ne.lng, ne.lat];
14878
14701
  }
14879
14702
 
14880
- function createMouseEvent(_a) {
14881
- var layer = _a.layer, source = _a.source;
14882
- var layer_ = source.target;
14883
- var feature = layer_.feature;
14884
- var opt = __assign({ layer: layer, feature: feature, event: convertMapClickEvent(source), source: source }, createFeaturePositionOptions(feature));
14885
- return opt;
14703
+ const typeAlias = {
14704
+ Point: 'point',
14705
+ LineString: 'line',
14706
+ MultiPoint: 'point',
14707
+ Polygon: 'polygon',
14708
+ MultiLineString: 'line',
14709
+ MultiPolygon: 'polygon',
14710
+ GeometryCollection: 'polygon',
14711
+ };
14712
+ const PAINT = {
14713
+ stroke: false,
14714
+ opacity: 1,
14715
+ };
14716
+ const backAliases = {};
14717
+ for (const a in typeAlias) {
14718
+ const layerType = typeAlias[a];
14719
+ const backAlias = backAliases[layerType] || [];
14720
+ backAlias.push(a);
14721
+ backAliases[layerType] = backAlias;
14722
+ }
14723
+ function geometryFilter(geometry, type) {
14724
+ const geoJsonGeometry = backAliases[type] || [];
14725
+ return geoJsonGeometry.indexOf(geometry) !== -1;
14726
+ }
14727
+ function filterGeometries(data, type) {
14728
+ if (data.type === 'FeatureCollection') {
14729
+ const _data = data;
14730
+ _data.features = _data.features.filter((f) => geometryFilter(f.geometry.type, type));
14731
+ }
14732
+ else if (data.type === 'Feature') {
14733
+ const allow = geometryFilter(data.geometry.type, type);
14734
+ if (!allow) {
14735
+ return false;
14736
+ }
14737
+ }
14738
+ else if (data.type === 'GeometryCollection') {
14739
+ const _data = data;
14740
+ _data.geometries = _data.geometries.filter((g) => geometryFilter(g.type, type));
14741
+ }
14742
+ return data;
14743
+ }
14744
+ function featuresBounds(features) {
14745
+ const geoJsonLayer = new leafletSrc.exports.GeoJSON();
14746
+ const features_ = Array.isArray(features) ? features : [features];
14747
+ features_.forEach((f) => geoJsonLayer.addData(f));
14748
+ return geoJsonLayer.getBounds();
14749
+ }
14750
+ function getFeaturesBounds(features) {
14751
+ return boundsToArray(featuresBounds(features));
14752
+ }
14753
+ function getFeaturesCenter(features) {
14754
+ const { lat, lng } = featuresBounds(features).getCenter();
14755
+ return [lng, lat];
14756
+ }
14757
+ function createFeaturePositionOptions(features) {
14758
+ return {
14759
+ getBounds: () => getFeaturesBounds(features),
14760
+ getCenter: () => getFeaturesCenter(features),
14761
+ };
14886
14762
  }
14887
14763
 
14888
- function findMostFrequentGeomType(arr) {
14889
- var counts = {};
14890
- for (var fry = 0; fry < arr.length; fry++) {
14891
- counts[arr[fry]] = 1 + (counts[arr[fry]] || 0);
14892
- }
14893
- var maxName = '';
14894
- for (var c in counts) {
14895
- var maxCount = maxName ? counts[maxName] : 0;
14896
- if (counts[c] > maxCount) {
14897
- maxName = c;
14898
- }
14899
- }
14900
- return maxName;
14901
- }
14902
- function detectType(geojson) {
14903
- var geometry;
14904
- if (geojson.type === 'FeatureCollection') {
14905
- var featuresTypes = geojson.features.map(function (f) { return f.geometry.type; });
14906
- geometry = findMostFrequentGeomType(featuresTypes);
14907
- }
14908
- else if (geojson.type === 'GeometryCollection') {
14909
- var geometryTypes = geojson.geometries.map(function (g) { return g.type; });
14910
- geometry = findMostFrequentGeomType(geometryTypes);
14911
- }
14912
- else if (geojson.type === 'Feature') {
14913
- geometry = geojson.geometry.type;
14914
- }
14915
- else {
14916
- geometry = geojson.type;
14917
- }
14918
- return geometry;
14764
+ function createMouseEvent({ layer, source, }) {
14765
+ const layer_ = source.target;
14766
+ const feature = layer_.feature;
14767
+ const opt = {
14768
+ layer,
14769
+ feature,
14770
+ event: convertMapClickEvent(source),
14771
+ source,
14772
+ ...createFeaturePositionOptions(feature),
14773
+ };
14774
+ return opt;
14919
14775
  }
14920
14776
 
14921
- var BaseAdapter = /** @class */ (function () {
14922
- function BaseAdapter(map, options) {
14923
- this.map = map;
14924
- this.options = options;
14925
- this.pane = 'order-0';
14926
- if (options.order !== undefined) {
14927
- var pane = 'order-' + options.order;
14928
- var exist = map.getPane(pane);
14929
- if (!exist) {
14930
- exist = map.createPane(pane);
14931
- }
14932
- exist.style.zIndex = String(Math.round(options.order * 100));
14933
- this.pane = pane;
14934
- }
14935
- }
14936
- BaseAdapter.prototype.addLayer = function (options) {
14937
- Object.assign(this.options, options);
14938
- return undefined;
14939
- };
14940
- return BaseAdapter;
14941
- }());
14942
-
14943
- var GeoJsonAdapter = /** @class */ (function (_super) {
14944
- __extends(GeoJsonAdapter, _super);
14945
- function GeoJsonAdapter(map, options) {
14946
- var _this = _super.call(this, map, options) || this;
14947
- _this.selected = false;
14948
- _this._layers = [];
14949
- _this._selectedLayers = [];
14950
- _this._filteredLayers = [];
14951
- _this._openedPopup = [];
14952
- _this.$updateTooltip = debounce(function () {
14953
- _this.updateTooltip();
14954
- }, 300);
14955
- _this.$unselect = function () {
14956
- _this.unselect();
14957
- };
14958
- return _this;
14959
- }
14960
- GeoJsonAdapter.prototype.addLayer = function (options) {
14961
- Object.assign(this.options, options);
14962
- this.paint = options.paint;
14963
- this.layer = new leafletSrc.exports.FeatureGroup([], __assign(__assign({}, options.nativeOptions), { pane: this.pane }));
14964
- this.selectedPaint = options.selectedPaint;
14965
- options.paint = this.paint;
14966
- if (options.data) {
14967
- this.addData(options.data);
14968
- }
14969
- this._addMapListener();
14970
- return this.layer;
14971
- };
14972
- GeoJsonAdapter.prototype.beforeRemove = function () {
14973
- this._removeMapListener();
14974
- };
14975
- GeoJsonAdapter.prototype.select = function (findFeatureFun) {
14976
- this.unselect();
14977
- if (findFeatureFun) {
14978
- var def = this._layers.filter(findFeatureFun);
14979
- for (var _i = 0, def_1 = def; _i < def_1.length; _i++) {
14980
- var x = def_1[_i];
14981
- this._selectLayer(x, 'api');
14982
- }
14983
- }
14984
- else if (!this.selected) {
14985
- this.selected = true;
14986
- if (this.selectedPaint) {
14987
- this._setPaintEachLayer(this.selectedPaint);
14988
- }
14989
- }
14990
- };
14991
- GeoJsonAdapter.prototype.unselect = function (findFeatureFun) {
14992
- var _this = this;
14993
- if (findFeatureFun) {
14994
- var feature = this._layers.filter(findFeatureFun);
14995
- feature.forEach(function (x) {
14996
- _this._unSelectLayer(x);
14997
- });
14998
- }
14999
- else if (this.selected) {
15000
- for (var _i = 0, _a = this._openedPopup; _i < _a.length; _i++) {
15001
- var p = _a[_i];
15002
- this._removePopup(p[0]);
15003
- }
15004
- if (this.paint) {
15005
- this._setPaintEachLayer(this.paint);
15006
- }
15007
- this._selectedLayers.length = 0;
15008
- this.selected = false;
15009
- }
15010
- };
15011
- GeoJsonAdapter.prototype.getSelected = function () {
15012
- var _this = this;
15013
- return this._selectedLayers.map(function (x) {
15014
- return __assign({ target: _this, feature: x.feature, layer: x }, createFeaturePositionOptions(x.feature));
15015
- });
15016
- };
15017
- GeoJsonAdapter.prototype.getFiltered = function () {
15018
- return this._filteredLayers;
15019
- };
15020
- GeoJsonAdapter.prototype.filter = function (fun) {
15021
- var _this = this;
15022
- // Some optimization
15023
- this._filterFun = fun;
15024
- var layer_ = this.layer;
15025
- var map = layer_ && layer_._map;
15026
- if (layer_ && map) {
15027
- layer_.remove();
15028
- var filteredLayers_1 = [];
15029
- this._layers.forEach(function (_a) {
15030
- var feature = _a.feature, layer = _a.layer;
15031
- if (layer) {
15032
- var ok = fun
15033
- ? fun(__assign({ target: _this, feature: feature, layer: layer }, createFeaturePositionOptions(feature)))
15034
- : true;
15035
- if (ok) {
15036
- layer_.addLayer(layer);
15037
- filteredLayers_1.push(__assign({ target: _this, feature: feature, layer: layer }, createFeaturePositionOptions(feature)));
15038
- }
15039
- else {
15040
- layer_.removeLayer(layer);
15041
- }
15042
- }
15043
- });
15044
- this._filteredLayers = filteredLayers_1;
15045
- layer_.addTo(map);
15046
- }
15047
- return this._filteredLayers;
15048
- };
15049
- GeoJsonAdapter.prototype.cleanFilter = function () {
15050
- this.filter();
15051
- };
15052
- GeoJsonAdapter.prototype.getLayers = function () {
15053
- var _this = this;
15054
- return this._layers.map(function (_a) {
15055
- var layer = _a.layer, feature = _a.feature;
15056
- var visible = layer && !!layer._map;
15057
- return __assign({ feature: feature, layer: layer, visible: visible, target: _this }, createFeaturePositionOptions(feature));
15058
- });
15059
- };
15060
- GeoJsonAdapter.prototype.clearLayer = function (cb) {
15061
- this.unselect();
15062
- var layer_ = this.layer;
15063
- if (layer_) {
15064
- if (cb) {
15065
- for (var fry = this._layers.length; fry--;) {
15066
- var def = this._layers[fry];
15067
- if (def) {
15068
- var feature = def.feature, layer = def.layer;
15069
- if (feature && layer) {
15070
- var exist = cb(feature);
15071
- if (exist) {
15072
- layer_.removeLayer(layer);
15073
- this._layers.splice(fry, 1);
15074
- }
15075
- }
15076
- }
15077
- }
15078
- }
15079
- else {
15080
- layer_.clearLayers();
15081
- this._layers = [];
15082
- }
15083
- }
15084
- };
15085
- GeoJsonAdapter.prototype.setData = function (data) {
15086
- this.clearLayer();
15087
- this.addData(data);
15088
- };
15089
- GeoJsonAdapter.prototype.addData = function (data) {
15090
- var options = this.options;
15091
- var geoJsonOptions;
15092
- if (options) {
15093
- if (data) {
15094
- var type = void 0;
15095
- if (!options.type) {
15096
- var detectedType = detectType(data);
15097
- type = typeAlias[detectedType];
15098
- }
15099
- else {
15100
- type = options.type;
15101
- }
15102
- if (this.type && this.type !== type) {
15103
- console.warn('no other data type than layer can be added');
15104
- return;
15105
- }
15106
- this.type = type;
15107
- data = filterGeometries(data, type);
15108
- if (data) {
15109
- geoJsonOptions = this._getGeoJsonOptions(options, type);
15110
- }
15111
- }
15112
- new leafletSrc.exports.GeoJSON(data || undefined, geoJsonOptions);
15113
- }
15114
- };
15115
- GeoJsonAdapter.prototype.openPopup = function (findFeatureFun, options) {
15116
- var _this = this;
15117
- if (findFeatureFun) {
15118
- var def = this._layers.filter(findFeatureFun);
15119
- def.forEach(function (x) {
15120
- _this._openPopup(x, options, 'api');
15121
- });
15122
- }
15123
- };
15124
- GeoJsonAdapter.prototype.closePopup = function (findFeatureFun) {
15125
- var _this = this;
15126
- var popupToClose = findFeatureFun
15127
- ? this._openedPopup.filter(function (x) { return findFeatureFun(x[2]); })
15128
- : this._openedPopup;
15129
- popupToClose.forEach(function (x) {
15130
- _this._removePopup(x[0]);
15131
- });
15132
- };
15133
- GeoJsonAdapter.prototype.updateTooltip = function (layerDef) {
15134
- var _this = this;
15135
- if (layerDef) {
15136
- this._updateTooltip(layerDef);
15137
- }
15138
- else {
15139
- this.getLayers().forEach(function (x) {
15140
- return _this._updateTooltip({ feature: x.feature, layer: x.layer });
15141
- });
15142
- }
15143
- };
15144
- /** @deprecated use {@link GeoJsonAdapter.getBounds} instead */
15145
- GeoJsonAdapter.prototype.getExtent = function () {
15146
- return this.getBounds();
15147
- };
15148
- GeoJsonAdapter.prototype.getBounds = function () {
15149
- if (this.layer) {
15150
- var bounds = this.layer.getBounds();
15151
- if (bounds.isValid()) {
15152
- return boundsToArray(bounds);
15153
- }
15154
- }
15155
- };
15156
- GeoJsonAdapter.prototype.setOpacity = function (value) {
15157
- this.options.opacity = value;
15158
- this.setPaint(this.paint);
15159
- this.setSelectedPaint(this.selectedPaint);
15160
- };
15161
- GeoJsonAdapter.prototype.setPaint = function (paint) {
15162
- if (paint) {
15163
- this.paint = paint;
15164
- for (var _i = 0, _a = this._layers; _i < _a.length; _i++) {
15165
- var l = _a[_i];
15166
- this._setPaint(l, paint);
15167
- }
15168
- }
15169
- };
15170
- GeoJsonAdapter.prototype.setSelectedPaint = function (paint) {
15171
- if (paint) {
15172
- this.selectedPaint = paint;
15173
- for (var _i = 0, _a = this._selectedLayers; _i < _a.length; _i++) {
15174
- var l = _a[_i];
15175
- this._setPaint(l, paint);
15176
- }
15177
- }
15178
- };
15179
- GeoJsonAdapter.prototype.updatePaint = function (paint) {
15180
- this.paint = __assign(__assign({}, this.paint), paint);
15181
- for (var _i = 0, _a = this._layers; _i < _a.length; _i++) {
15182
- var l = _a[_i];
15183
- this._setPaint(l, this.paint);
15184
- }
15185
- };
15186
- GeoJsonAdapter.prototype.updateSelectedPaint = function (paint) {
15187
- this.selectedPaint = __assign(__assign({}, this.selectedPaint), paint);
15188
- for (var _i = 0, _a = this._selectedLayers; _i < _a.length; _i++) {
15189
- var l = _a[_i];
15190
- this._setPaint(l, this.selectedPaint);
15191
- }
15192
- };
15193
- GeoJsonAdapter.prototype._updateTooltip = function (layerDef) {
15194
- var feature = layerDef.feature, layer = layerDef.layer;
15195
- if (feature && layer && feature.properties && this.options.labelField) {
15196
- layer.unbindTooltip();
15197
- var message = feature.properties[this.options.labelField];
15198
- if (message !== undefined) {
15199
- var permanent = !this.options.labelOnHover;
15200
- layer.bindTooltip(String(message), { permanent: permanent, sticky: false });
15201
- }
15202
- }
15203
- };
15204
- GeoJsonAdapter.prototype._openPopup = function (def, options, type, latLng) {
15205
- var _a, _b;
15206
- if (options === void 0) { options = {}; }
15207
- return __awaiter(this, void 0, void 0, function () {
15208
- var feature, layer, _c, minWidth, autoPan, maxWidth, closeButton_, closeButton, popup, _closeHandlers, onClose, close, content, popupOptions, unselectOnClose, p;
15209
- var _this = this;
15210
- return __generator(this, function (_d) {
15211
- switch (_d.label) {
15212
- case 0:
15213
- feature = def.feature, layer = def.layer;
15214
- _c = __assign({ minWidth: 300 }, options), minWidth = _c.minWidth, autoPan = _c.autoPan, maxWidth = _c.maxWidth, closeButton_ = _c.closeButton;
15215
- closeButton = closeButton_ !== null && closeButton_ !== void 0 ? closeButton_ : !this.options.selectOnHover;
15216
- _closeHandlers = [];
15217
- onClose = function (handler) {
15218
- _closeHandlers.push(handler);
15219
- };
15220
- close = function () {
15221
- if (popup) {
15222
- _this._removePopup(popup);
15223
- }
15224
- };
15225
- if (!options.createPopupContent) return [3 /*break*/, 2];
15226
- return [4 /*yield*/, options.createPopupContent(__assign({ layer: layer, feature: feature, target: this, type: type, close: close, onClose: onClose }, createFeaturePositionOptions(feature)))];
15227
- case 1:
15228
- content = _d.sent();
15229
- return [3 /*break*/, 3];
15230
- case 2:
15231
- content = options.popupContent;
15232
- _d.label = 3;
15233
- case 3:
15234
- if (content && layer) {
15235
- popupOptions = {
15236
- minWidth: minWidth,
15237
- autoPan: autoPan,
15238
- // maxWidth,
15239
- closeButton: closeButton,
15240
- closeOnClick: false,
15241
- autoClose: false,
15242
- };
15243
- if (defined(maxWidth)) {
15244
- popupOptions.maxWidth = maxWidth;
15245
- }
15246
- popup = layer.bindPopup(content, popupOptions);
15247
- unselectOnClose = (_b = (_a = this.options.popupOptions) === null || _a === void 0 ? void 0 : _a.unselectOnClose) !== null && _b !== void 0 ? _b : true;
15248
- if (unselectOnClose) {
15249
- p = layer.getPopup();
15250
- p &&
15251
- p.once('remove', function () {
15252
- close();
15253
- }, this);
15254
- }
15255
- this._openedPopup.push([popup, _closeHandlers, def]);
15256
- popup.openPopup(latLng);
15257
- }
15258
- return [2 /*return*/];
15259
- }
15260
- });
15261
- });
15262
- };
15263
- GeoJsonAdapter.prototype._removePopup = function (popup) {
15264
- var _a, _b;
15265
- var map = this.map;
15266
- if (map) {
15267
- popup.closePopup().unbindPopup();
15268
- var index = this._openedPopup.findIndex(function (x) { return x[0] === popup; });
15269
- if (index !== -1) {
15270
- var unselectOnClose = (_b = (_a = this.options.popupOptions) === null || _a === void 0 ? void 0 : _a.unselectOnClose) !== null && _b !== void 0 ? _b : true;
15271
- var _c = this._openedPopup[index], closeHandlers = _c[1], def = _c[2];
15272
- for (var _i = 0, closeHandlers_1 = closeHandlers; _i < closeHandlers_1.length; _i++) {
15273
- var h = closeHandlers_1[_i];
15274
- h(def);
15275
- }
15276
- closeHandlers.length = 0;
15277
- if (unselectOnClose) {
15278
- this._unSelectLayer(def);
15279
- }
15280
- this._openedPopup.splice(index, 1);
15281
- }
15282
- }
15283
- };
15284
- GeoJsonAdapter.prototype._setPaintEachLayer = function (paint) {
15285
- var _this = this;
15286
- this._layers.forEach(function (l) {
15287
- _this._setPaint(l, paint);
15288
- });
15289
- };
15290
- GeoJsonAdapter.prototype._setPaint = function (def, paint) {
15291
- var style = undefined;
15292
- var layer = def.layer, feature = def.feature;
15293
- if (layer && feature) {
15294
- if (isPaintCallback(paint)) {
15295
- style = paint(feature);
15296
- }
15297
- else if (isPaint(paint)) {
15298
- style = paint;
15299
- }
15300
- if (style) {
15301
- if (this.type === 'point' && style.type === 'icon') {
15302
- var marker = layer;
15303
- var divIcon = this._createDivIcon(style);
15304
- marker.setIcon(divIcon);
15305
- }
15306
- else if ('setStyle' in layer) {
15307
- layer.setStyle(this._preparePaint(style));
15308
- }
15309
- }
15310
- }
15311
- };
15312
- GeoJsonAdapter.prototype._preparePaint = function (paint) {
15313
- if (paint.type !== 'get-paint') {
15314
- // const path: CircleMarkerOptions | PathOptions = paint as CircleMarkerOptions | PathOptions;
15315
- // if (path.opacity) {
15316
- // path.fillOpacity = path.opacity;
15317
- // }
15318
- var paintAliases = [
15319
- // ['color', 'color'],
15320
- ['color', 'strokeColor'],
15321
- ['opacity', 'strokeOpacity'],
15322
- ['stroke', 'stroke'],
15323
- ['fillColor', 'fillColor'],
15324
- ['fillOpacity', 'fillOpacity'],
15325
- ['fill', 'fill'],
15326
- ['weight', 'weight'],
15327
- ];
15328
- var aliases = this.type === 'line'
15329
- ? [
15330
- ['color', 'strokeColor'],
15331
- ['opacity', 'strokeOpacity'],
15332
- ['weight', 'weight'],
15333
- ]
15334
- : paintAliases;
15335
- var readyPaint = {};
15336
- if ('radius' in paint && typeof paint.radius === 'number') {
15337
- readyPaint.radius = paint.radius;
15338
- }
15339
- for (var _i = 0, aliases_1 = aliases; _i < aliases_1.length; _i++) {
15340
- var _a = aliases_1[_i], to = _a[0], from = _a[1];
15341
- var paintProp = paint[from];
15342
- if (defined(this.options.opacity) &&
15343
- from.toLowerCase().indexOf('opacity') !== -1) {
15344
- paintProp = Number(paintProp) * this.options.opacity;
15345
- }
15346
- if (paintProp !== undefined) {
15347
- Object.defineProperty(readyPaint, to, {
15348
- enumerable: true,
15349
- value: paintProp,
15350
- });
15351
- }
15352
- }
15353
- return readyPaint;
15354
- }
15355
- return PAINT;
15356
- };
15357
- GeoJsonAdapter.prototype._getGeoJsonOptions = function (options, type) {
15358
- var _this = this;
15359
- var paint = options.paint;
15360
- var lopt = {};
15361
- if (typeof paint === 'function') {
15362
- if (type === 'point') {
15363
- // TODO: fix types (@geoman-io/leaflet-geoman-free)
15364
- lopt.pointToLayer = function (feature, latLng) {
15365
- var iconOpt = paint(feature);
15366
- var pointToLayer = _this._createPaintToLayer(iconOpt);
15367
- return pointToLayer(feature, latLng);
15368
- };
15369
- }
15370
- else {
15371
- lopt = {
15372
- style: function (feature) {
15373
- if (feature) {
15374
- return _this._preparePaint(__assign(__assign({}, PAINT), paint(feature)));
15375
- }
15376
- else {
15377
- return _this._preparePaint(__assign(__assign({}, PAINT), { type: 'path' }));
15378
- }
15379
- },
15380
- };
15381
- }
15382
- }
15383
- else {
15384
- lopt = this._createPaintOptions(paint, type);
15385
- }
15386
- lopt.onEachFeature = function (feature, layer) {
15387
- _this._onEachFeature(feature, layer);
15388
- };
15389
- return lopt;
15390
- };
15391
- GeoJsonAdapter.prototype._onEachFeature = function (feature, layer) {
15392
- var _this = this;
15393
- var layer_ = this.layer;
15394
- if (layer_) {
15395
- var def_2 = __assign({ target: this, feature: feature, layer: layer }, createFeaturePositionOptions(feature));
15396
- // @ts-ignore
15397
- layer.options.pane = this.pane;
15398
- this._layers.push(def_2);
15399
- var ok = true;
15400
- if (this._filterFun) {
15401
- ok = this._filterFun(def_2);
15402
- }
15403
- if (ok) {
15404
- var _a = this.options, popup_1 = _a.popup, popupOptions_1 = _a.popupOptions, selectable = _a.selectable, interactive = _a.interactive, selectOnHover = _a.selectOnHover;
15405
- // @ts-ignore
15406
- layer.options.interactive = defined(interactive) ? interactive : true;
15407
- layer_.addLayer(layer);
15408
- if (selectable) {
15409
- if (selectOnHover) {
15410
- layer.on('mouseover', function () {
15411
- _this._selectLayer(def_2, 'hover');
15412
- });
15413
- layer.on('mouseout', function () {
15414
- _this._unSelectLayer(def_2);
15415
- });
15416
- }
15417
- else {
15418
- layer.on('click', function (e) { return _this._selectOnLayerClick(e); }, this);
15419
- }
15420
- }
15421
- this._handleMouseEvents(layer);
15422
- // The timeout is needed to display the popup immediately when adding a layer to the map.
15423
- // Without a timeout, the layer may not yet have a _map object
15424
- setTimeout(function () {
15425
- if (popup_1) {
15426
- _this._openPopup(__assign({ target: _this, layer: layer, feature: feature }, createFeaturePositionOptions(feature)), popupOptions_1, 'api');
15427
- }
15428
- _this._updateTooltip({ layer: layer, feature: feature });
15429
- });
15430
- }
15431
- }
15432
- };
15433
- GeoJsonAdapter.prototype._handleMouseEvents = function (layer) {
15434
- var _this = this;
15435
- var _a = this.options, onClick = _a.onClick, onLayerClick = _a.onLayerClick, onMouseOut = _a.onMouseOut, onMouseOver = _a.onMouseOver;
15436
- // TODO: remove backward compatibility for onLayerClick
15437
- var onClick_ = onClick || onLayerClick;
15438
- if (onClick_) {
15439
- layer.on('click', function (e) {
15440
- var selected = !!_this._getSelected(layer);
15441
- onClick_(__assign({ selected: selected }, _this._createMouseEvent(e)));
15442
- }, this);
15443
- }
15444
- if (onMouseOut) {
15445
- layer.on('mouseout', function (e) {
15446
- onMouseOut(_this._createMouseEvent(e));
15447
- }, this);
15448
- }
15449
- if (onMouseOver) {
15450
- layer.on('mouseover', function (e) {
15451
- onMouseOver(_this._createMouseEvent(e));
15452
- }, this);
15453
- }
15454
- };
15455
- GeoJsonAdapter.prototype._createMouseEvent = function (source) {
15456
- return createMouseEvent({
15457
- layer: this,
15458
- source: source,
15459
- });
15460
- };
15461
- GeoJsonAdapter.prototype._getSelected = function (layer) {
15462
- return this._selectedLayers.find(function (x) { return x.layer === layer; });
15463
- };
15464
- GeoJsonAdapter.prototype._selectOnLayerClick = function (e) {
15465
- leafletSrc.exports.DomEvent.stopPropagation(e);
15466
- var layer = e.target;
15467
- var feature = layer.feature;
15468
- var def = __assign({ target: this, layer: layer, feature: feature }, createFeaturePositionOptions(feature));
15469
- var isSelected = this._getSelected(layer);
15470
- if (isSelected) {
15471
- if (this.options && this.options.unselectOnSecondClick) {
15472
- this._unSelectLayer(isSelected);
15473
- }
15474
- }
15475
- else {
15476
- this._selectLayer(def, 'click', e.latlng);
15477
- }
15478
- };
15479
- GeoJsonAdapter.prototype._selectLayer = function (def, type, latlng) {
15480
- var _this = this;
15481
- var multiselect = this.options.multiselect;
15482
- if (!multiselect) {
15483
- // To unselect layer on another layer click
15484
- this.map._addUnselectCb(function () {
15485
- _this._unSelectLayer(def);
15486
- });
15487
- this._selectedLayers.forEach(function (x) { return _this._unSelectLayer(x); });
15488
- }
15489
- this._selectedLayers.push(def);
15490
- this.selected = true;
15491
- var _a = this.options, selectedPaint = _a.selectedPaint, popupOnSelect = _a.popupOnSelect, popupOptions = _a.popupOptions;
15492
- if (selectedPaint && def.layer) {
15493
- this._setPaint(def, selectedPaint);
15494
- }
15495
- if (popupOnSelect) {
15496
- this._openPopup(def, popupOptions, type, latlng);
15497
- }
15498
- if (this.options.onSelect) {
15499
- var features = def.feature ? [def.feature] : [];
15500
- this.options.onSelect(__assign({ type: type, layer: this, features: features }, createFeaturePositionOptions(features)));
15501
- }
15502
- };
15503
- GeoJsonAdapter.prototype._unSelectLayer = function (def) {
15504
- var index = this._selectedLayers.indexOf(def);
15505
- if (index !== -1) {
15506
- this._selectedLayers.splice(index, 1);
15507
- if (this.options) {
15508
- if (this.options.paint) {
15509
- this._setPaint(def, this.options.paint);
15510
- }
15511
- if (this.options.popupOnSelect && def.layer) {
15512
- this._removePopup(def.layer);
15513
- }
15514
- }
15515
- }
15516
- this.selected = this._selectedLayers.length > 0;
15517
- };
15518
- GeoJsonAdapter.prototype._createDivIcon = function (icon) {
15519
- var toLIconOpt = __rest(icon, []);
15520
- return new leafletSrc.exports.DivIcon(__assign({ className: '' }, toLIconOpt));
15521
- };
15522
- GeoJsonAdapter.prototype._createPaintToLayer = function (icon) {
15523
- var _this = this;
15524
- if (icon && icon.type) {
15525
- if (icon.type === 'icon') {
15526
- var iconClassName = icon.className;
15527
- var html = icon.html;
15528
- if (iconClassName || html) {
15529
- return function (geoJsonPoint, latlng) {
15530
- var divIcon = _this._createDivIcon(icon);
15531
- return new leafletSrc.exports.Marker(latlng, { icon: divIcon });
15532
- };
15533
- }
15534
- }
15535
- else if (icon.type === 'pin') {
15536
- return function (geoJsonPoint, latlng) {
15537
- // const divIcon = this.createDivIcon(icon);
15538
- return new leafletSrc.exports.Marker(latlng);
15539
- };
15540
- }
15541
- }
15542
- return function (geoJsonPoint, latlng) {
15543
- var p = PAINT;
15544
- return new leafletSrc.exports.CircleMarker(latlng, _this._preparePaint(__assign(__assign({}, p), icon)));
15545
- };
15546
- };
15547
- GeoJsonAdapter.prototype._createPaintOptions = function (paintOptions, type) {
15548
- var geoJsonOptions = {};
15549
- var paint = (paintOptions && this._preparePaint(paintOptions)) || {};
15550
- if (paintOptions) {
15551
- geoJsonOptions.style = function () {
15552
- return paint;
15553
- };
15554
- }
15555
- if (type === 'point') {
15556
- geoJsonOptions.pointToLayer = this._createPaintToLayer(paintOptions);
15557
- }
15558
- else if (type === 'line') {
15559
- paint.stroke = true;
15560
- }
15561
- return geoJsonOptions;
15562
- };
15563
- GeoJsonAdapter.prototype._addMapClickListener = function () {
15564
- var map = this.map;
15565
- if (map) {
15566
- var unselectOnClick = this.options.unselectOnClick;
15567
- var uoc = unselectOnClick !== null && unselectOnClick !== void 0 ? unselectOnClick : true;
15568
- if (uoc) {
15569
- map.on('click', this.$unselect);
15570
- }
15571
- }
15572
- };
15573
- GeoJsonAdapter.prototype._removeMapClickListener = function () {
15574
- this.map.off('zoomend', this.$updateTooltip);
15575
- this.map.off('moveend', this.$updateTooltip);
15576
- this.map.off('click', this.$unselect);
15577
- };
15578
- GeoJsonAdapter.prototype._addMapListener = function () {
15579
- var map = this.map;
15580
- if (map) {
15581
- var _a = this.options, labelField = _a.labelField, labelOnHover = _a.labelOnHover;
15582
- this._addMapClickListener();
15583
- if (labelField && !labelOnHover) {
15584
- map.on('zoomend', this.$updateTooltip);
15585
- map.on('moveend', this.$updateTooltip);
15586
- }
15587
- }
15588
- };
15589
- GeoJsonAdapter.prototype._removeMapListener = function () {
15590
- this._removeMapClickListener();
15591
- this.map.off('zoomend', this.$updateTooltip);
15592
- this.map.off('moveend', this.$updateTooltip);
15593
- };
15594
- return GeoJsonAdapter;
15595
- }(BaseAdapter));
15596
-
15597
- function callAjax(src, callback, headers) {
15598
- var xhr = new XMLHttpRequest();
15599
- xhr.open('GET', src);
15600
- xhr.responseType = 'arraybuffer';
15601
- for (var h in headers) {
15602
- xhr.setRequestHeader(h, headers[h]);
15603
- }
15604
- xhr.onload = function () {
15605
- var arrayBufferView = new Uint8Array(this.response);
15606
- var blob = new Blob([arrayBufferView], { type: 'image/png' });
15607
- // @ts-ignore for typedoc
15608
- var urlCreator = window.URL || window.webkitURL;
15609
- var imageUrl = urlCreator.createObjectURL(blob);
15610
- callback(imageUrl);
15611
- };
15612
- xhr.send();
15613
- return function () {
15614
- xhr.abort();
15615
- };
14777
+ function findMostFrequentGeomType(arr) {
14778
+ const counts = {};
14779
+ for (let fry = 0; fry < arr.length; fry++) {
14780
+ counts[arr[fry]] = 1 + (counts[arr[fry]] || 0);
14781
+ }
14782
+ let maxName = '';
14783
+ for (const c in counts) {
14784
+ const maxCount = maxName ? counts[maxName] : 0;
14785
+ if (counts[c] > maxCount) {
14786
+ maxName = c;
14787
+ }
14788
+ }
14789
+ return maxName;
14790
+ }
14791
+ function detectType(geojson) {
14792
+ let geometry;
14793
+ if (geojson.type === 'FeatureCollection') {
14794
+ const featuresTypes = geojson.features.map((f) => f.geometry.type);
14795
+ geometry = findMostFrequentGeomType(featuresTypes);
14796
+ }
14797
+ else if (geojson.type === 'GeometryCollection') {
14798
+ const geometryTypes = geojson.geometries.map((g) => g.type);
14799
+ geometry = findMostFrequentGeomType(geometryTypes);
14800
+ }
14801
+ else if (geojson.type === 'Feature') {
14802
+ geometry = geojson.geometry.type;
14803
+ }
14804
+ else {
14805
+ geometry = geojson.type;
14806
+ }
14807
+ return geometry;
15616
14808
  }
15617
14809
 
15618
- var ImageOverlay = /** @class */ (function (_super) {
15619
- __extends(ImageOverlay, _super);
15620
- function ImageOverlay(imageUrl, bounds, options) {
15621
- var _this = _super.call(this, imageUrl, bounds, options) || this;
15622
- _this._abort = [];
15623
- return _this;
15624
- }
15625
- ImageOverlay.prototype.cancelLoad = function () {
15626
- if (this._abort) {
15627
- this._abort.forEach(function (x) { return x(); });
15628
- this._abort = [];
15629
- }
15630
- };
15631
- ImageOverlay.prototype._initImage = function () {
15632
- // @ts-ignore
15633
- _super.prototype._initImage.call(this);
15634
- // @ts-ignore
15635
- var headers = this.options.headers;
15636
- if (headers) {
15637
- // @ts-ignore
15638
- var img_1 = this._image;
15639
- var src = img_1.src;
15640
- img_1.src = '';
15641
- this._abort.push(callAjax(src, function (response) {
15642
- img_1.src = response;
15643
- }, headers));
15644
- }
15645
- };
15646
- return ImageOverlay;
15647
- }(leafletSrc.exports.ImageOverlay));
15648
-
15649
- /*!
15650
- * leaflet.wms.js
15651
- * A collection of Leaflet utilities for working with Web Mapping services.
15652
- * (c) 2014-2016, Houston Engineering, Inc.
15653
- * MIT License
15654
- */
15655
- /*
15656
- * Overlay:
15657
- * "Single Tile" WMS image overlay that updates with map changes.
15658
- * Portions of wms.Overlay are directly extracted from L.TileLayer.WMS.
15659
- * See Leaflet license.
15660
- */
15661
- var ImageLayer = /** @class */ (function (_super) {
15662
- __extends(ImageLayer, _super);
15663
- function ImageLayer(url, options) {
15664
- var _this = _super.call(this, options) || this;
15665
- _this.defaultWmsParams = {
15666
- service: 'WMS',
15667
- request: 'GetMap',
15668
- version: '1.1.1',
15669
- layers: '',
15670
- styles: '',
15671
- format: 'image/jpeg',
15672
- transparent: false,
15673
- };
15674
- _this.options = {
15675
- crs: null,
15676
- uppercase: false,
15677
- attribution: '',
15678
- opacity: 1,
15679
- isBack: false,
15680
- minZoom: 0,
15681
- pane: 'tilePane',
15682
- headers: null,
15683
- viewPortBuffer: 0,
15684
- setViewDelay: 100,
15685
- };
15686
- _this._url = url;
15687
- // Move WMS parameters to params object
15688
- var params = {};
15689
- var opts = {};
15690
- var opt;
15691
- for (opt in options) {
15692
- if (opt in _this.options) {
15693
- opts[opt] = options[opt];
15694
- }
15695
- else {
15696
- params[opt] = options[opt];
15697
- }
15698
- }
15699
- leafletSrc.exports.Util.setOptions(_this, opts);
15700
- _this.wmsParams = leafletSrc.exports.Util.extend({}, _this.defaultWmsParams, params);
15701
- return _this;
15702
- }
15703
- ImageLayer.prototype.setParams = function (params) {
15704
- leafletSrc.exports.Util.extend(this.wmsParams, params);
15705
- this.update();
15706
- };
15707
- ImageLayer.prototype.getAttribution = function () {
15708
- return this.options.attribution || '';
15709
- };
15710
- ImageLayer.prototype.onAdd = function () {
15711
- this.update();
15712
- return this;
15713
- };
15714
- ImageLayer.prototype.onRemove = function (map) {
15715
- if (this._currentOverlay) {
15716
- this._currentOverlay.cancelLoad();
15717
- map.removeLayer(this._currentOverlay);
15718
- delete this._currentOverlay;
15719
- }
15720
- if (this._currentUrl) {
15721
- delete this._currentUrl;
15722
- }
15723
- return this;
15724
- };
15725
- ImageLayer.prototype.getEvents = function () {
15726
- return {
15727
- moveend: debounce(this.update, this.options.setViewDelay),
15728
- };
15729
- };
15730
- ImageLayer.prototype.update = function () {
15731
- var _this = this;
15732
- if (!this._map) {
15733
- return;
15734
- }
15735
- // Determine image URL and whether it has changed since last update
15736
- this.updateWmsParams();
15737
- var url = this.getImageUrl();
15738
- if (this._currentUrl === url) {
15739
- return;
15740
- }
15741
- this._currentUrl = url;
15742
- // Keep current image overlay in place until new one loads
15743
- // (inspired by esri.leaflet)
15744
- var viewPortBuffer = this.options.viewPortBuffer || 0;
15745
- var bounds = this._map.getBounds().pad(viewPortBuffer);
15746
- var overlay = new ImageOverlay(url, bounds, {
15747
- opacity: 0,
15748
- pane: this.options.pane,
15749
- headers: this.options.headers,
15750
- });
15751
- overlay.addTo(this._map);
15752
- if (this._currentOverlay) {
15753
- this._currentOverlay.cancelLoad();
15754
- }
15755
- overlay.once('load', function () {
15756
- if (!_this._map) {
15757
- return;
15758
- }
15759
- // @ts-ignore
15760
- if (overlay._url !== _this._currentUrl) {
15761
- _this._map.removeLayer(overlay);
15762
- return;
15763
- }
15764
- else if (_this._currentOverlay) {
15765
- _this._map.removeLayer(_this._currentOverlay);
15766
- }
15767
- _this._currentOverlay = overlay;
15768
- overlay.setOpacity(_this.options.opacity !== undefined ? _this.options.opacity : 1);
15769
- if (_this.options.isBack === true) {
15770
- overlay.bringToBack();
15771
- }
15772
- if (_this.options.isBack === false) {
15773
- overlay.bringToFront();
15774
- }
15775
- if (_this.options.zIndex !== undefined) {
15776
- overlay.setZIndex(_this.options.zIndex);
15777
- }
15778
- }, this);
15779
- var _a = this.options, minZoom = _a.minZoom, maxZoom = _a.maxZoom;
15780
- if ((minZoom && this._map.getZoom() < minZoom) ||
15781
- (maxZoom && this._map.getZoom() > maxZoom)) {
15782
- this._map.removeLayer(overlay);
15783
- }
15784
- };
15785
- ImageLayer.prototype.setOpacity = function (opacity) {
15786
- this.options.opacity = opacity;
15787
- if (this._currentOverlay) {
15788
- this._currentOverlay.setOpacity(opacity);
15789
- }
15790
- };
15791
- ImageLayer.prototype.bringToBack = function () {
15792
- this.options.isBack = true;
15793
- if (this._currentOverlay) {
15794
- this._currentOverlay.bringToBack();
15795
- }
15796
- };
15797
- ImageLayer.prototype.bringToFront = function () {
15798
- this.options.isBack = false;
15799
- if (this._currentOverlay) {
15800
- this._currentOverlay.bringToFront();
15801
- }
15802
- };
15803
- ImageLayer.prototype.setZIndex = function (zIndex) {
15804
- this.options.zIndex = zIndex;
15805
- if (this._currentOverlay) {
15806
- this._currentOverlay.setZIndex(zIndex);
15807
- }
15808
- };
15809
- // See L.TileLayer.WMS: onAdd() & getTileUrl()
15810
- ImageLayer.prototype.updateWmsParams = function (map) {
15811
- if (!map) {
15812
- map = this._map;
15813
- }
15814
- // Compute WMS options
15815
- var viewPortBuffer = this.options.viewPortBuffer || 0;
15816
- var bounds = map.getBounds().pad(viewPortBuffer);
15817
- var size = map.getSize();
15818
- if (this.options.viewPortBuffer !== 0) {
15819
- var factor = viewPortBuffer + 1;
15820
- size.x = Math.ceil(size.x * factor);
15821
- size.y = Math.ceil(size.y * factor);
15822
- }
15823
- var wmsVersion = parseFloat(this.wmsParams.version);
15824
- var crs = this.options.crs || map.options.crs;
15825
- var projectionKey = wmsVersion >= 1.3 ? 'crs' : 'srs';
15826
- if (crs) {
15827
- var nw = crs.project(bounds.getNorthWest());
15828
- var se = crs.project(bounds.getSouthEast());
15829
- // Assemble WMS parameter string
15830
- var params = {
15831
- width: size.x,
15832
- height: size.y,
15833
- };
15834
- params[projectionKey] = crs.code;
15835
- params.bbox = (wmsVersion >= 1.3 && crs === leafletSrc.exports.CRS.EPSG4326
15836
- ? [se.y, nw.x, nw.y, se.x]
15837
- : [nw.x, se.y, se.x, nw.y]).join(',');
15838
- leafletSrc.exports.Util.extend(this.wmsParams, params);
15839
- }
15840
- };
15841
- ImageLayer.prototype.getImageUrl = function () {
15842
- var uppercase = this.options.uppercase || false;
15843
- var pstr = leafletSrc.exports.Util.getParamString(this.wmsParams, this._url, uppercase);
15844
- return this._url + pstr;
15845
- };
15846
- return ImageLayer;
15847
- }(leafletSrc.exports.Layer));
15848
-
15849
- var ImageAdapter = /** @class */ (function (_super) {
15850
- __extends(ImageAdapter, _super);
15851
- function ImageAdapter() {
15852
- return _super !== null && _super.apply(this, arguments) || this;
15853
- }
15854
- ImageAdapter.prototype.addLayer = function (options) {
15855
- var url = options && options.url;
15856
- if (url) {
15857
- options = __assign({ transparent: true }, options);
15858
- var updateWmsParamsFromOpt_1 = options.updateWmsParams;
15859
- this.layer = new ImageLayer(url, __assign(__assign(__assign({ pane: this.pane, headers: options.headers, setViewDelay: options.setViewDelay }, options), options.params), options.nativeOptions));
15860
- if (updateWmsParamsFromOpt_1) {
15861
- var updateWmsParams_1 = this.layer.updateWmsParams;
15862
- this.layer.updateWmsParams = function (map) {
15863
- updateWmsParams_1.call(this, map);
15864
- this.wmsParams = updateWmsParamsFromOpt_1(this.wmsParams);
15865
- };
15866
- }
15867
- return this.layer;
15868
- }
15869
- };
15870
- return ImageAdapter;
15871
- }(BaseAdapter));
15872
-
15873
- function makeRemote(Base) {
15874
- return /** @class */ (function (_super) {
15875
- __extends(RemoteTileLayer, _super);
15876
- function RemoteTileLayer() {
15877
- var args = [];
15878
- for (var _i = 0; _i < arguments.length; _i++) {
15879
- args[_i] = arguments[_i];
15880
- }
15881
- var _this = _super.apply(this, args) || this;
15882
- if (_this.options.setViewDelay) {
15883
- // @ts-ignore
15884
- _this._update = debounce(function () {
15885
- var _a;
15886
- var a = [];
15887
- for (var _i = 0; _i < arguments.length; _i++) {
15888
- a[_i] = arguments[_i];
15889
- }
15890
- // @ts-ignore
15891
- (_a = leafletSrc.exports.GridLayer.prototype._update).call.apply(_a, __spreadArray([_this], a, false));
15892
- }, _this.options.setViewDelay);
15893
- }
15894
- return _this;
15895
- }
15896
- RemoteTileLayer.prototype.createTile = function (coords, done) {
15897
- // @ts-ignore
15898
- var url = this.getTileUrl(coords);
15899
- var tile = document.createElement('img');
15900
- tile.abort = callAjax(url, function (response) {
15901
- tile.src = response;
15902
- done(null, tile);
15903
- },
15904
- // @ts-ignore
15905
- this.options.headers);
15906
- if (this.options.crossOrigin || this.options.crossOrigin === '') {
15907
- tile.crossOrigin =
15908
- this.options.crossOrigin === true ? '' : this.options.crossOrigin;
15909
- }
15910
- tile.alt = '';
15911
- tile.setAttribute('role', 'presentation');
15912
- return tile;
15913
- };
15914
- RemoteTileLayer.prototype._abortLoading = function () {
15915
- // @ts-ignore
15916
- var tiles = this._tiles;
15917
- // @ts-ignore
15918
- var tileZoom = this._tileZoom;
15919
- for (var i in tiles) {
15920
- if (tiles[i].coords.z !== tileZoom) {
15921
- var tile = tiles[i].el;
15922
- tile.onload = leafletSrc.exports.Util.falseFn;
15923
- tile.onerror = leafletSrc.exports.Util.falseFn;
15924
- if (!tile.complete) {
15925
- if (tile.abort) {
15926
- tile.abort();
15927
- }
15928
- tile.src = leafletSrc.exports.Util.emptyImageUrl;
15929
- leafletSrc.exports.DomUtil.remove(tile);
15930
- delete tiles[i];
15931
- }
15932
- }
15933
- }
15934
- };
15935
- return RemoteTileLayer;
15936
- }(Base));
14810
+ class BaseAdapter {
14811
+ constructor(map, options) {
14812
+ this.map = map;
14813
+ this.options = options;
14814
+ this.pane = 'order-0';
14815
+ if (options.order !== undefined) {
14816
+ const pane = 'order-' + options.order;
14817
+ let exist = map.getPane(pane);
14818
+ if (!exist) {
14819
+ exist = map.createPane(pane);
14820
+ }
14821
+ exist.style.zIndex = String(Math.round(options.order * 100));
14822
+ this.pane = pane;
14823
+ }
14824
+ }
14825
+ addLayer(options) {
14826
+ Object.assign(this.options, options);
14827
+ return undefined;
14828
+ }
15937
14829
  }
15938
14830
 
15939
- var TileLayerBase = /** @class */ (function (_super) {
15940
- __extends(TileLayerBase, _super);
15941
- function TileLayerBase(urlTemplate, options) {
15942
- var _this = _super.call(this, urlTemplate, options) || this;
15943
- Object.assign(_this.options, options);
15944
- return _this;
15945
- }
15946
- return TileLayerBase;
15947
- }(leafletSrc.exports.TileLayer));
15948
- var TileLayer = makeRemote(TileLayerBase);
15949
-
15950
- var TileAdapter = /** @class */ (function (_super) {
15951
- __extends(TileAdapter, _super);
15952
- function TileAdapter() {
15953
- return _super !== null && _super.apply(this, arguments) || this;
15954
- }
15955
- TileAdapter.prototype.addLayer = function (options) {
15956
- this.options = Object.assign(this.options, options);
15957
- if (options) {
15958
- var url = options.url, opt = __rest(options, ["url"]);
15959
- if (url) {
15960
- var tileLayerOptions = __assign({ pane: this.pane, attribution: opt.attribution, minZoom: opt.minZoom, maxZoom: opt.maxZoom }, opt.nativeOptions);
15961
- if (opt.subdomains) {
15962
- tileLayerOptions.subdomains = opt.subdomains;
15963
- }
15964
- var layer = void 0;
15965
- if (opt.headers) {
15966
- layer = new TileLayer(url, __assign(__assign({}, tileLayerOptions), { headers: opt.headers, setViewDelay: opt.setViewDelay }));
15967
- }
15968
- else {
15969
- layer = new leafletSrc.exports.TileLayer(url, tileLayerOptions);
15970
- }
15971
- return layer;
15972
- }
15973
- }
15974
- };
15975
- return TileAdapter;
15976
- }(BaseAdapter));
15977
-
15978
- var WmsLayerBase = /** @class */ (function (_super) {
15979
- __extends(WmsLayerBase, _super);
15980
- function WmsLayerBase(urlTemplate, options) {
15981
- return _super.call(this, urlTemplate, options) || this;
15982
- }
15983
- return WmsLayerBase;
15984
- }(leafletSrc.exports.TileLayer.WMS));
15985
- var WmsLayer = makeRemote(WmsLayerBase);
15986
-
15987
- var WmsAdapter = /** @class */ (function (_super) {
15988
- __extends(WmsAdapter, _super);
15989
- function WmsAdapter() {
15990
- return _super !== null && _super.apply(this, arguments) || this;
15991
- }
15992
- WmsAdapter.prototype.addLayer = function (options) {
15993
- Object.assign(this.options, options);
15994
- var url = options.url, opt = __rest(options, ["url"]);
15995
- if (url) {
15996
- var layerOptions = __assign({ pane: this.pane, attribution: opt.attribution, minZoom: opt.minZoom, maxZoom: opt.maxZoom, layers: options.layers, format: options.format }, options.nativeOptions);
15997
- var layer = void 0;
15998
- if (opt.headers) {
15999
- layer = new WmsLayer(url, __assign(__assign({}, layerOptions), { headers: opt.headers }));
16000
- }
16001
- else {
16002
- layer = new leafletSrc.exports.TileLayer.WMS(url, layerOptions);
16003
- }
16004
- return layer;
16005
- }
16006
- };
16007
- return WmsAdapter;
16008
- }(BaseAdapter));
16009
-
16010
- var OsmAdapter = /** @class */ (function (_super) {
16011
- __extends(OsmAdapter, _super);
16012
- function OsmAdapter() {
16013
- return _super !== null && _super.apply(this, arguments) || this;
16014
- }
16015
- OsmAdapter.prototype.addLayer = function (options) {
16016
- var url = 'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png';
16017
- 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 }));
16018
- };
16019
- return OsmAdapter;
16020
- }(TileAdapter));
16021
-
16022
- function arrayToBoundsExpression(bounds) {
16023
- var e = bounds;
16024
- // top, left, bottom, right
16025
- return [
16026
- [e[3], e[0]],
16027
- [e[1], e[2]],
16028
- ];
14831
+ class GeoJsonAdapter extends BaseAdapter {
14832
+ constructor(map, options) {
14833
+ super(map, options);
14834
+ this.selected = false;
14835
+ this._layers = [];
14836
+ this._selectedLayers = [];
14837
+ this._filteredLayers = [];
14838
+ this._openedPopup = [];
14839
+ this.$updateTooltip = debounce(() => {
14840
+ this.updateTooltip();
14841
+ }, 300);
14842
+ this.$unselect = () => {
14843
+ this.unselect();
14844
+ };
14845
+ }
14846
+ addLayer(options) {
14847
+ Object.assign(this.options, options);
14848
+ this.paint = options.paint;
14849
+ this.layer = new leafletSrc.exports.FeatureGroup([], {
14850
+ ...options.nativeOptions,
14851
+ pane: this.pane,
14852
+ });
14853
+ this.selectedPaint = options.selectedPaint;
14854
+ options.paint = this.paint;
14855
+ if (options.data) {
14856
+ this.addData(options.data);
14857
+ }
14858
+ this._addMapListener();
14859
+ return this.layer;
14860
+ }
14861
+ beforeRemove() {
14862
+ this._removeMapListener();
14863
+ }
14864
+ select(findFeatureFun) {
14865
+ this.unselect();
14866
+ if (findFeatureFun) {
14867
+ const def = this._layers.filter(findFeatureFun);
14868
+ for (const x of def) {
14869
+ this._selectLayer(x, 'api');
14870
+ }
14871
+ }
14872
+ else if (!this.selected) {
14873
+ this.selected = true;
14874
+ if (this.selectedPaint) {
14875
+ this._setPaintEachLayer(this.selectedPaint);
14876
+ }
14877
+ }
14878
+ }
14879
+ unselect(findFeatureFun) {
14880
+ if (findFeatureFun) {
14881
+ const feature = this._layers.filter(findFeatureFun);
14882
+ feature.forEach((x) => {
14883
+ this._unSelectLayer(x);
14884
+ });
14885
+ }
14886
+ else if (this.selected) {
14887
+ for (const p of this._openedPopup) {
14888
+ this._removePopup(p[0]);
14889
+ }
14890
+ if (this.paint) {
14891
+ this._setPaintEachLayer(this.paint);
14892
+ }
14893
+ this._selectedLayers.length = 0;
14894
+ this.selected = false;
14895
+ }
14896
+ }
14897
+ getSelected() {
14898
+ return this._selectedLayers.map((x) => {
14899
+ return {
14900
+ target: this,
14901
+ feature: x.feature,
14902
+ layer: x,
14903
+ ...createFeaturePositionOptions(x.feature),
14904
+ };
14905
+ });
14906
+ }
14907
+ getFiltered() {
14908
+ return this._filteredLayers;
14909
+ }
14910
+ filter(fun) {
14911
+ // Some optimization
14912
+ this._filterFun = fun;
14913
+ const layer_ = this.layer;
14914
+ const map = layer_ && layer_._map;
14915
+ if (layer_ && map) {
14916
+ layer_.remove();
14917
+ const filteredLayers = [];
14918
+ this._layers.forEach(({ feature, layer }) => {
14919
+ if (layer) {
14920
+ const ok = fun
14921
+ ? fun({
14922
+ target: this,
14923
+ feature,
14924
+ layer,
14925
+ ...createFeaturePositionOptions(feature),
14926
+ })
14927
+ : true;
14928
+ if (ok) {
14929
+ layer_.addLayer(layer);
14930
+ filteredLayers.push({
14931
+ target: this,
14932
+ feature,
14933
+ layer,
14934
+ ...createFeaturePositionOptions(feature),
14935
+ });
14936
+ }
14937
+ else {
14938
+ layer_.removeLayer(layer);
14939
+ }
14940
+ }
14941
+ });
14942
+ this._filteredLayers = filteredLayers;
14943
+ layer_.addTo(map);
14944
+ }
14945
+ return this._filteredLayers;
14946
+ }
14947
+ cleanFilter() {
14948
+ this.filter();
14949
+ }
14950
+ getLayers() {
14951
+ return this._layers.map(({ layer, feature }) => {
14952
+ const visible = layer && !!layer._map;
14953
+ return {
14954
+ feature,
14955
+ layer,
14956
+ visible,
14957
+ target: this,
14958
+ ...createFeaturePositionOptions(feature),
14959
+ };
14960
+ });
14961
+ }
14962
+ clearLayer(cb) {
14963
+ this.unselect();
14964
+ const layer_ = this.layer;
14965
+ if (layer_) {
14966
+ if (cb) {
14967
+ for (let fry = this._layers.length; fry--;) {
14968
+ const def = this._layers[fry];
14969
+ if (def) {
14970
+ const { feature, layer } = def;
14971
+ if (feature && layer) {
14972
+ const exist = cb(feature);
14973
+ if (exist) {
14974
+ layer_.removeLayer(layer);
14975
+ this._layers.splice(fry, 1);
14976
+ }
14977
+ }
14978
+ }
14979
+ }
14980
+ }
14981
+ else {
14982
+ layer_.clearLayers();
14983
+ this._layers = [];
14984
+ }
14985
+ }
14986
+ }
14987
+ setData(data) {
14988
+ this.clearLayer();
14989
+ this.addData(data);
14990
+ }
14991
+ addData(data) {
14992
+ const options = this.options;
14993
+ let geoJsonOptions;
14994
+ if (options) {
14995
+ if (data) {
14996
+ let type;
14997
+ if (!options.type) {
14998
+ const detectedType = detectType(data);
14999
+ type = typeAlias[detectedType];
15000
+ }
15001
+ else {
15002
+ type = options.type;
15003
+ }
15004
+ if (this.type && this.type !== type) {
15005
+ console.warn('no other data type than layer can be added');
15006
+ return;
15007
+ }
15008
+ this.type = type;
15009
+ data = filterGeometries(data, type);
15010
+ if (data) {
15011
+ geoJsonOptions = this._getGeoJsonOptions(options, type);
15012
+ }
15013
+ }
15014
+ new leafletSrc.exports.GeoJSON(data || undefined, geoJsonOptions);
15015
+ }
15016
+ }
15017
+ openPopup(findFeatureFun, options) {
15018
+ if (findFeatureFun) {
15019
+ const def = this._layers.filter(findFeatureFun);
15020
+ def.forEach((x) => {
15021
+ this._openPopup(x, options, 'api');
15022
+ });
15023
+ }
15024
+ }
15025
+ closePopup(findFeatureFun) {
15026
+ const popupToClose = findFeatureFun
15027
+ ? this._openedPopup.filter((x) => findFeatureFun(x[2]))
15028
+ : this._openedPopup;
15029
+ popupToClose.forEach((x) => {
15030
+ this._removePopup(x[0]);
15031
+ });
15032
+ }
15033
+ updateTooltip(layerDef) {
15034
+ if (layerDef) {
15035
+ this._updateTooltip(layerDef);
15036
+ }
15037
+ else {
15038
+ this.getLayers().forEach((x) => this._updateTooltip({ feature: x.feature, layer: x.layer }));
15039
+ }
15040
+ }
15041
+ /** @deprecated use {@link GeoJsonAdapter.getBounds} instead */
15042
+ getExtent() {
15043
+ return this.getBounds();
15044
+ }
15045
+ getBounds() {
15046
+ if (this.layer) {
15047
+ const bounds = this.layer.getBounds();
15048
+ if (bounds.isValid()) {
15049
+ return boundsToArray(bounds);
15050
+ }
15051
+ }
15052
+ }
15053
+ setOpacity(value) {
15054
+ this.options.opacity = value;
15055
+ this.setPaint(this.paint);
15056
+ this.setSelectedPaint(this.selectedPaint);
15057
+ }
15058
+ setPaint(paint) {
15059
+ if (paint) {
15060
+ this.paint = paint;
15061
+ for (const l of this._layers) {
15062
+ this._setPaint(l, paint);
15063
+ }
15064
+ }
15065
+ }
15066
+ setSelectedPaint(paint) {
15067
+ if (paint) {
15068
+ this.selectedPaint = paint;
15069
+ for (const l of this._selectedLayers) {
15070
+ this._setPaint(l, paint);
15071
+ }
15072
+ }
15073
+ }
15074
+ updatePaint(paint) {
15075
+ this.paint = { ...this.paint, ...paint };
15076
+ for (const l of this._layers) {
15077
+ this._setPaint(l, this.paint);
15078
+ }
15079
+ }
15080
+ updateSelectedPaint(paint) {
15081
+ this.selectedPaint = { ...this.selectedPaint, ...paint };
15082
+ for (const l of this._selectedLayers) {
15083
+ this._setPaint(l, this.selectedPaint);
15084
+ }
15085
+ }
15086
+ _updateTooltip(layerDef) {
15087
+ const { feature, layer } = layerDef;
15088
+ if (feature && layer && feature.properties && this.options.labelField) {
15089
+ layer.unbindTooltip();
15090
+ const message = feature.properties[this.options.labelField];
15091
+ if (message !== undefined) {
15092
+ const permanent = !this.options.labelOnHover;
15093
+ layer.bindTooltip(String(message), { permanent, sticky: false });
15094
+ }
15095
+ }
15096
+ }
15097
+ async _openPopup(def, options = {}, type, latLng) {
15098
+ var _a, _b;
15099
+ const { feature, layer } = def;
15100
+ const { minWidth, autoPan, maxWidth, closeButton: closeButton_, } = {
15101
+ minWidth: 300,
15102
+ ...options,
15103
+ };
15104
+ const closeButton = closeButton_ !== null && closeButton_ !== void 0 ? closeButton_ : !this.options.selectOnHover;
15105
+ let popup;
15106
+ const _closeHandlers = [];
15107
+ const onClose = (handler) => {
15108
+ _closeHandlers.push(handler);
15109
+ };
15110
+ const close = () => {
15111
+ if (popup) {
15112
+ this._removePopup(popup);
15113
+ }
15114
+ };
15115
+ let content;
15116
+ if (options.createPopupContent) {
15117
+ content = await options.createPopupContent({
15118
+ layer,
15119
+ feature,
15120
+ target: this,
15121
+ type,
15122
+ close,
15123
+ onClose,
15124
+ ...createFeaturePositionOptions(feature),
15125
+ });
15126
+ }
15127
+ else {
15128
+ content = options.popupContent;
15129
+ }
15130
+ if (content && layer) {
15131
+ const popupOptions = {
15132
+ minWidth,
15133
+ autoPan,
15134
+ // maxWidth,
15135
+ closeButton,
15136
+ closeOnClick: false,
15137
+ autoClose: false,
15138
+ };
15139
+ if (defined(maxWidth)) {
15140
+ popupOptions.maxWidth = maxWidth;
15141
+ }
15142
+ popup = layer.bindPopup(content, popupOptions);
15143
+ const unselectOnClose = (_b = (_a = this.options.popupOptions) === null || _a === void 0 ? void 0 : _a.unselectOnClose) !== null && _b !== void 0 ? _b : true;
15144
+ if (unselectOnClose) {
15145
+ const p = layer.getPopup();
15146
+ p &&
15147
+ p.once('remove', () => {
15148
+ close();
15149
+ }, this);
15150
+ }
15151
+ this._openedPopup.push([popup, _closeHandlers, def]);
15152
+ popup.openPopup(latLng);
15153
+ }
15154
+ }
15155
+ _removePopup(popup) {
15156
+ var _a, _b;
15157
+ const map = this.map;
15158
+ if (map) {
15159
+ popup.closePopup().unbindPopup();
15160
+ const index = this._openedPopup.findIndex((x) => x[0] === popup);
15161
+ if (index !== -1) {
15162
+ const unselectOnClose = (_b = (_a = this.options.popupOptions) === null || _a === void 0 ? void 0 : _a.unselectOnClose) !== null && _b !== void 0 ? _b : true;
15163
+ const [, closeHandlers, def] = this._openedPopup[index];
15164
+ for (const h of closeHandlers) {
15165
+ h(def);
15166
+ }
15167
+ closeHandlers.length = 0;
15168
+ if (unselectOnClose) {
15169
+ this._unSelectLayer(def);
15170
+ }
15171
+ this._openedPopup.splice(index, 1);
15172
+ }
15173
+ }
15174
+ }
15175
+ _setPaintEachLayer(paint) {
15176
+ this._layers.forEach((l) => {
15177
+ this._setPaint(l, paint);
15178
+ });
15179
+ }
15180
+ _setPaint(def, paint) {
15181
+ let style = undefined;
15182
+ const { layer, feature } = def;
15183
+ if (layer && feature) {
15184
+ if (isPaintCallback(paint)) {
15185
+ style = paint(feature);
15186
+ }
15187
+ else if (isPaint(paint)) {
15188
+ style = paint;
15189
+ }
15190
+ if (style) {
15191
+ if (this.type === 'point' && style.type === 'icon') {
15192
+ const marker = layer;
15193
+ const divIcon = this._createDivIcon(style);
15194
+ marker.setIcon(divIcon);
15195
+ }
15196
+ else if ('setStyle' in layer) {
15197
+ layer.setStyle(this._preparePaint(style));
15198
+ }
15199
+ }
15200
+ }
15201
+ }
15202
+ _preparePaint(paint) {
15203
+ if (paint.type !== 'get-paint') {
15204
+ // const path: CircleMarkerOptions | PathOptions = paint as CircleMarkerOptions | PathOptions;
15205
+ // if (path.opacity) {
15206
+ // path.fillOpacity = path.opacity;
15207
+ // }
15208
+ const paintAliases = [
15209
+ // ['color', 'color'],
15210
+ ['color', 'strokeColor'],
15211
+ ['opacity', 'strokeOpacity'],
15212
+ ['stroke', 'stroke'],
15213
+ ['fillColor', 'fillColor'],
15214
+ ['fillOpacity', 'fillOpacity'],
15215
+ ['fill', 'fill'],
15216
+ ['weight', 'weight'],
15217
+ ];
15218
+ const aliases = this.type === 'line'
15219
+ ? [
15220
+ ['color', 'strokeColor'],
15221
+ ['opacity', 'strokeOpacity'],
15222
+ ['weight', 'weight'],
15223
+ ]
15224
+ : paintAliases;
15225
+ const readyPaint = {};
15226
+ if ('radius' in paint && typeof paint.radius === 'number') {
15227
+ readyPaint.radius = paint.radius;
15228
+ }
15229
+ for (const [to, from] of aliases) {
15230
+ let paintProp = paint[from];
15231
+ if (defined(this.options.opacity) &&
15232
+ from.toLowerCase().indexOf('opacity') !== -1) {
15233
+ paintProp = Number(paintProp) * this.options.opacity;
15234
+ }
15235
+ if (paintProp !== undefined) {
15236
+ Object.defineProperty(readyPaint, to, {
15237
+ enumerable: true,
15238
+ value: paintProp,
15239
+ });
15240
+ }
15241
+ }
15242
+ return readyPaint;
15243
+ }
15244
+ return PAINT;
15245
+ }
15246
+ _getGeoJsonOptions(options, type) {
15247
+ const paint = options.paint;
15248
+ let lopt = {};
15249
+ if (typeof paint === 'function') {
15250
+ if (type === 'point') {
15251
+ // TODO: fix types (@geoman-io/leaflet-geoman-free)
15252
+ lopt.pointToLayer = (feature, latLng) => {
15253
+ const iconOpt = paint(feature);
15254
+ const pointToLayer = this._createPaintToLayer(iconOpt);
15255
+ return pointToLayer(feature, latLng);
15256
+ };
15257
+ }
15258
+ else {
15259
+ lopt = {
15260
+ style: (feature) => {
15261
+ if (feature) {
15262
+ return this._preparePaint({ ...PAINT, ...paint(feature) });
15263
+ }
15264
+ else {
15265
+ return this._preparePaint({ ...PAINT, type: 'path' });
15266
+ }
15267
+ },
15268
+ };
15269
+ }
15270
+ }
15271
+ else {
15272
+ lopt = this._createPaintOptions(paint, type);
15273
+ }
15274
+ lopt.onEachFeature = (feature, layer) => {
15275
+ this._onEachFeature(feature, layer);
15276
+ };
15277
+ return lopt;
15278
+ }
15279
+ _onEachFeature(feature, layer) {
15280
+ const layer_ = this.layer;
15281
+ if (layer_) {
15282
+ const def = {
15283
+ target: this,
15284
+ feature,
15285
+ layer,
15286
+ ...createFeaturePositionOptions(feature),
15287
+ };
15288
+ // @ts-ignore
15289
+ layer.options.pane = this.pane;
15290
+ this._layers.push(def);
15291
+ let ok = true;
15292
+ if (this._filterFun) {
15293
+ ok = this._filterFun(def);
15294
+ }
15295
+ if (ok) {
15296
+ const { popup, popupOptions, selectable, interactive, selectOnHover } = this.options;
15297
+ // @ts-ignore
15298
+ layer.options.interactive = defined(interactive) ? interactive : true;
15299
+ layer_.addLayer(layer);
15300
+ if (selectable) {
15301
+ if (selectOnHover) {
15302
+ layer.on('mouseover', () => {
15303
+ this._selectLayer(def, 'hover');
15304
+ });
15305
+ layer.on('mouseout', () => {
15306
+ this._unSelectLayer(def);
15307
+ });
15308
+ }
15309
+ else {
15310
+ layer.on('click', (e) => this._selectOnLayerClick(e), this);
15311
+ }
15312
+ }
15313
+ this._handleMouseEvents(layer);
15314
+ // The timeout is needed to display the popup immediately when adding a layer to the map.
15315
+ // Without a timeout, the layer may not yet have a _map object
15316
+ setTimeout(() => {
15317
+ if (popup) {
15318
+ this._openPopup({
15319
+ target: this,
15320
+ layer,
15321
+ feature,
15322
+ ...createFeaturePositionOptions(feature),
15323
+ }, popupOptions, 'api');
15324
+ }
15325
+ this._updateTooltip({ layer, feature });
15326
+ });
15327
+ }
15328
+ }
15329
+ }
15330
+ _handleMouseEvents(layer) {
15331
+ const { onClick, onLayerClick, onMouseOut, onMouseOver } = this.options;
15332
+ // TODO: remove backward compatibility for onLayerClick
15333
+ const onClick_ = onClick || onLayerClick;
15334
+ if (onClick_) {
15335
+ layer.on('click', (e) => {
15336
+ const selected = !!this._getSelected(layer);
15337
+ onClick_({
15338
+ selected,
15339
+ ...this._createMouseEvent(e),
15340
+ });
15341
+ }, this);
15342
+ }
15343
+ if (onMouseOut) {
15344
+ layer.on('mouseout', (e) => {
15345
+ onMouseOut(this._createMouseEvent(e));
15346
+ }, this);
15347
+ }
15348
+ if (onMouseOver) {
15349
+ layer.on('mouseover', (e) => {
15350
+ onMouseOver(this._createMouseEvent(e));
15351
+ }, this);
15352
+ }
15353
+ }
15354
+ _createMouseEvent(source) {
15355
+ return createMouseEvent({
15356
+ layer: this,
15357
+ source: source,
15358
+ });
15359
+ }
15360
+ _getSelected(layer) {
15361
+ return this._selectedLayers.find((x) => x.layer === layer);
15362
+ }
15363
+ _selectOnLayerClick(e) {
15364
+ leafletSrc.exports.DomEvent.stopPropagation(e);
15365
+ const layer = e.target;
15366
+ const feature = layer.feature;
15367
+ const def = {
15368
+ target: this,
15369
+ layer,
15370
+ feature,
15371
+ ...createFeaturePositionOptions(feature),
15372
+ };
15373
+ const isSelected = this._getSelected(layer);
15374
+ if (isSelected) {
15375
+ if (this.options && this.options.unselectOnSecondClick) {
15376
+ this._unSelectLayer(isSelected);
15377
+ }
15378
+ }
15379
+ else {
15380
+ this._selectLayer(def, 'click', e.latlng);
15381
+ }
15382
+ }
15383
+ _selectLayer(def, type, latlng) {
15384
+ const { multiselect } = this.options;
15385
+ if (!multiselect) {
15386
+ // To unselect layer on another layer click
15387
+ this.map._addUnselectCb(() => {
15388
+ this._unSelectLayer(def);
15389
+ });
15390
+ this._selectedLayers.forEach((x) => this._unSelectLayer(x));
15391
+ }
15392
+ this._selectedLayers.push(def);
15393
+ this.selected = true;
15394
+ const { selectedPaint, popupOnSelect, popupOptions } = this.options;
15395
+ if (selectedPaint && def.layer) {
15396
+ this._setPaint(def, selectedPaint);
15397
+ }
15398
+ if (popupOnSelect) {
15399
+ this._openPopup(def, popupOptions, type, latlng);
15400
+ }
15401
+ if (this.options.onSelect) {
15402
+ const features = def.feature ? [def.feature] : [];
15403
+ this.options.onSelect({
15404
+ type,
15405
+ layer: this,
15406
+ features,
15407
+ ...createFeaturePositionOptions(features),
15408
+ });
15409
+ }
15410
+ }
15411
+ _unSelectLayer(def) {
15412
+ const index = this._selectedLayers.indexOf(def);
15413
+ if (index !== -1) {
15414
+ this._selectedLayers.splice(index, 1);
15415
+ if (this.options) {
15416
+ if (this.options.paint) {
15417
+ this._setPaint(def, this.options.paint);
15418
+ }
15419
+ if (this.options.popupOnSelect && def.layer) {
15420
+ this._removePopup(def.layer);
15421
+ }
15422
+ }
15423
+ }
15424
+ this.selected = this._selectedLayers.length > 0;
15425
+ }
15426
+ _createDivIcon(icon) {
15427
+ const { ...toLIconOpt } = icon;
15428
+ return new leafletSrc.exports.DivIcon({ className: '', ...toLIconOpt });
15429
+ }
15430
+ _createPaintToLayer(icon) {
15431
+ if (icon && icon.type) {
15432
+ if (icon.type === 'icon') {
15433
+ const iconClassName = icon.className;
15434
+ const html = icon.html;
15435
+ if (iconClassName || html) {
15436
+ return (geoJsonPoint, latlng) => {
15437
+ const divIcon = this._createDivIcon(icon);
15438
+ return new leafletSrc.exports.Marker(latlng, { icon: divIcon });
15439
+ };
15440
+ }
15441
+ }
15442
+ else if (icon.type === 'pin') {
15443
+ return (geoJsonPoint, latlng) => {
15444
+ // const divIcon = this.createDivIcon(icon);
15445
+ return new leafletSrc.exports.Marker(latlng);
15446
+ };
15447
+ }
15448
+ }
15449
+ return (geoJsonPoint, latlng) => {
15450
+ const p = PAINT;
15451
+ return new leafletSrc.exports.CircleMarker(latlng, this._preparePaint({ ...p, ...icon }));
15452
+ };
15453
+ }
15454
+ _createPaintOptions(paintOptions, type) {
15455
+ const geoJsonOptions = {};
15456
+ const paint = (paintOptions && this._preparePaint(paintOptions)) || {};
15457
+ if (paintOptions) {
15458
+ geoJsonOptions.style = () => {
15459
+ return paint;
15460
+ };
15461
+ }
15462
+ if (type === 'point') {
15463
+ geoJsonOptions.pointToLayer = this._createPaintToLayer(paintOptions);
15464
+ }
15465
+ else if (type === 'line') {
15466
+ paint.stroke = true;
15467
+ }
15468
+ return geoJsonOptions;
15469
+ }
15470
+ _addMapClickListener() {
15471
+ const map = this.map;
15472
+ if (map) {
15473
+ const { unselectOnClick } = this.options;
15474
+ const uoc = unselectOnClick !== null && unselectOnClick !== void 0 ? unselectOnClick : true;
15475
+ if (uoc) {
15476
+ map.on('click', this.$unselect);
15477
+ }
15478
+ }
15479
+ }
15480
+ _removeMapClickListener() {
15481
+ this.map.off('zoomend', this.$updateTooltip);
15482
+ this.map.off('moveend', this.$updateTooltip);
15483
+ this.map.off('click', this.$unselect);
15484
+ }
15485
+ _addMapListener() {
15486
+ const map = this.map;
15487
+ if (map) {
15488
+ const { labelField, labelOnHover } = this.options;
15489
+ this._addMapClickListener();
15490
+ if (labelField && !labelOnHover) {
15491
+ map.on('zoomend', this.$updateTooltip);
15492
+ map.on('moveend', this.$updateTooltip);
15493
+ }
15494
+ }
15495
+ }
15496
+ _removeMapListener() {
15497
+ this._removeMapClickListener();
15498
+ this.map.off('zoomend', this.$updateTooltip);
15499
+ this.map.off('moveend', this.$updateTooltip);
15500
+ }
15501
+ }
15502
+
15503
+ function callAjax(src, callback, headers) {
15504
+ const xhr = new XMLHttpRequest();
15505
+ xhr.open('GET', src);
15506
+ xhr.responseType = 'arraybuffer';
15507
+ for (const h in headers) {
15508
+ xhr.setRequestHeader(h, headers[h]);
15509
+ }
15510
+ xhr.onload = function () {
15511
+ const arrayBufferView = new Uint8Array(this.response);
15512
+ const blob = new Blob([arrayBufferView], { type: 'image/png' });
15513
+ // @ts-ignore for typedoc
15514
+ const urlCreator = window.URL || window.webkitURL;
15515
+ const imageUrl = urlCreator.createObjectURL(blob);
15516
+ callback(imageUrl);
15517
+ };
15518
+ xhr.send();
15519
+ return () => {
15520
+ xhr.abort();
15521
+ };
15522
+ }
15523
+
15524
+ class ImageOverlay extends leafletSrc.exports.ImageOverlay {
15525
+ constructor(imageUrl, bounds, options) {
15526
+ super(imageUrl, bounds, options);
15527
+ this._abort = [];
15528
+ }
15529
+ cancelLoad() {
15530
+ if (this._abort) {
15531
+ this._abort.forEach((x) => x());
15532
+ this._abort = [];
15533
+ }
15534
+ }
15535
+ _initImage() {
15536
+ // @ts-ignore
15537
+ super._initImage();
15538
+ // @ts-ignore
15539
+ const headers = this.options.headers;
15540
+ if (headers) {
15541
+ // @ts-ignore
15542
+ const img = this._image;
15543
+ const src = img.src;
15544
+ img.src = '';
15545
+ this._abort.push(callAjax(src, (response) => {
15546
+ img.src = response;
15547
+ }, headers));
15548
+ }
15549
+ }
15550
+ }
15551
+
15552
+ /*!
15553
+ * leaflet.wms.js
15554
+ * A collection of Leaflet utilities for working with Web Mapping services.
15555
+ * (c) 2014-2016, Houston Engineering, Inc.
15556
+ * MIT License
15557
+ */
15558
+ /*
15559
+ * Overlay:
15560
+ * "Single Tile" WMS image overlay that updates with map changes.
15561
+ * Portions of wms.Overlay are directly extracted from L.TileLayer.WMS.
15562
+ * See Leaflet license.
15563
+ */
15564
+ class ImageLayer extends leafletSrc.exports.Layer {
15565
+ constructor(url, options) {
15566
+ super(options);
15567
+ this.defaultWmsParams = {
15568
+ service: 'WMS',
15569
+ request: 'GetMap',
15570
+ version: '1.1.1',
15571
+ layers: '',
15572
+ styles: '',
15573
+ format: 'image/jpeg',
15574
+ transparent: false,
15575
+ };
15576
+ this.options = {
15577
+ crs: null,
15578
+ uppercase: false,
15579
+ attribution: '',
15580
+ opacity: 1,
15581
+ isBack: false,
15582
+ minZoom: 0,
15583
+ pane: 'tilePane',
15584
+ headers: null,
15585
+ viewPortBuffer: 0,
15586
+ setViewDelay: 100,
15587
+ };
15588
+ this._url = url;
15589
+ // Move WMS parameters to params object
15590
+ const params = {};
15591
+ const opts = {};
15592
+ let opt;
15593
+ for (opt in options) {
15594
+ if (opt in this.options) {
15595
+ opts[opt] = options[opt];
15596
+ }
15597
+ else {
15598
+ params[opt] = options[opt];
15599
+ }
15600
+ }
15601
+ leafletSrc.exports.Util.setOptions(this, opts);
15602
+ this.wmsParams = leafletSrc.exports.Util.extend({}, this.defaultWmsParams, params);
15603
+ }
15604
+ setParams(params) {
15605
+ leafletSrc.exports.Util.extend(this.wmsParams, params);
15606
+ this.update();
15607
+ }
15608
+ getAttribution() {
15609
+ return this.options.attribution || '';
15610
+ }
15611
+ onAdd() {
15612
+ this.update();
15613
+ return this;
15614
+ }
15615
+ onRemove(map) {
15616
+ if (this._currentOverlay) {
15617
+ this._currentOverlay.cancelLoad();
15618
+ map.removeLayer(this._currentOverlay);
15619
+ delete this._currentOverlay;
15620
+ }
15621
+ if (this._currentUrl) {
15622
+ delete this._currentUrl;
15623
+ }
15624
+ return this;
15625
+ }
15626
+ getEvents() {
15627
+ return {
15628
+ moveend: debounce(this.update, this.options.setViewDelay),
15629
+ };
15630
+ }
15631
+ update() {
15632
+ if (!this._map) {
15633
+ return;
15634
+ }
15635
+ // Determine image URL and whether it has changed since last update
15636
+ this.updateWmsParams();
15637
+ const url = this.getImageUrl();
15638
+ if (this._currentUrl === url) {
15639
+ return;
15640
+ }
15641
+ this._currentUrl = url;
15642
+ // Keep current image overlay in place until new one loads
15643
+ // (inspired by esri.leaflet)
15644
+ const viewPortBuffer = this.options.viewPortBuffer || 0;
15645
+ const bounds = this._map.getBounds().pad(viewPortBuffer);
15646
+ const overlay = new ImageOverlay(url, bounds, {
15647
+ opacity: 0,
15648
+ pane: this.options.pane,
15649
+ headers: this.options.headers,
15650
+ });
15651
+ overlay.addTo(this._map);
15652
+ if (this._currentOverlay) {
15653
+ this._currentOverlay.cancelLoad();
15654
+ }
15655
+ overlay.once('load', () => {
15656
+ if (!this._map) {
15657
+ return;
15658
+ }
15659
+ // @ts-ignore
15660
+ if (overlay._url !== this._currentUrl) {
15661
+ this._map.removeLayer(overlay);
15662
+ return;
15663
+ }
15664
+ else if (this._currentOverlay) {
15665
+ this._map.removeLayer(this._currentOverlay);
15666
+ }
15667
+ this._currentOverlay = overlay;
15668
+ overlay.setOpacity(this.options.opacity !== undefined ? this.options.opacity : 1);
15669
+ if (this.options.isBack === true) {
15670
+ overlay.bringToBack();
15671
+ }
15672
+ if (this.options.isBack === false) {
15673
+ overlay.bringToFront();
15674
+ }
15675
+ if (this.options.zIndex !== undefined) {
15676
+ overlay.setZIndex(this.options.zIndex);
15677
+ }
15678
+ }, this);
15679
+ const { minZoom, maxZoom } = this.options;
15680
+ if ((minZoom && this._map.getZoom() < minZoom) ||
15681
+ (maxZoom && this._map.getZoom() > maxZoom)) {
15682
+ this._map.removeLayer(overlay);
15683
+ }
15684
+ }
15685
+ setOpacity(opacity) {
15686
+ this.options.opacity = opacity;
15687
+ if (this._currentOverlay) {
15688
+ this._currentOverlay.setOpacity(opacity);
15689
+ }
15690
+ }
15691
+ bringToBack() {
15692
+ this.options.isBack = true;
15693
+ if (this._currentOverlay) {
15694
+ this._currentOverlay.bringToBack();
15695
+ }
15696
+ }
15697
+ bringToFront() {
15698
+ this.options.isBack = false;
15699
+ if (this._currentOverlay) {
15700
+ this._currentOverlay.bringToFront();
15701
+ }
15702
+ }
15703
+ setZIndex(zIndex) {
15704
+ this.options.zIndex = zIndex;
15705
+ if (this._currentOverlay) {
15706
+ this._currentOverlay.setZIndex(zIndex);
15707
+ }
15708
+ }
15709
+ // See L.TileLayer.WMS: onAdd() & getTileUrl()
15710
+ updateWmsParams(map) {
15711
+ if (!map) {
15712
+ map = this._map;
15713
+ }
15714
+ // Compute WMS options
15715
+ const viewPortBuffer = this.options.viewPortBuffer || 0;
15716
+ const bounds = map.getBounds().pad(viewPortBuffer);
15717
+ const size = map.getSize();
15718
+ if (this.options.viewPortBuffer !== 0) {
15719
+ const factor = viewPortBuffer + 1;
15720
+ size.x = Math.ceil(size.x * factor);
15721
+ size.y = Math.ceil(size.y * factor);
15722
+ }
15723
+ const wmsVersion = parseFloat(this.wmsParams.version);
15724
+ const crs = this.options.crs || map.options.crs;
15725
+ const projectionKey = wmsVersion >= 1.3 ? 'crs' : 'srs';
15726
+ if (crs) {
15727
+ const nw = crs.project(bounds.getNorthWest());
15728
+ const se = crs.project(bounds.getSouthEast());
15729
+ // Assemble WMS parameter string
15730
+ const params = {
15731
+ width: size.x,
15732
+ height: size.y,
15733
+ };
15734
+ params[projectionKey] = crs.code;
15735
+ params.bbox = (wmsVersion >= 1.3 && crs === leafletSrc.exports.CRS.EPSG4326
15736
+ ? [se.y, nw.x, nw.y, se.x]
15737
+ : [nw.x, se.y, se.x, nw.y]).join(',');
15738
+ leafletSrc.exports.Util.extend(this.wmsParams, params);
15739
+ }
15740
+ }
15741
+ getImageUrl() {
15742
+ const uppercase = this.options.uppercase || false;
15743
+ const pstr = leafletSrc.exports.Util.getParamString(this.wmsParams, this._url, uppercase);
15744
+ return this._url + pstr;
15745
+ }
15746
+ }
15747
+
15748
+ class ImageAdapter extends BaseAdapter {
15749
+ addLayer(options) {
15750
+ const url = options && options.url;
15751
+ if (url) {
15752
+ options = { transparent: true, ...options };
15753
+ const updateWmsParamsFromOpt = options.updateWmsParams;
15754
+ this.layer = new ImageLayer(url, {
15755
+ pane: this.pane,
15756
+ headers: options.headers,
15757
+ setViewDelay: options.setViewDelay,
15758
+ /**
15759
+ * TODO: safe remove, use only options.nativeOptions
15760
+ */
15761
+ ...options,
15762
+ ...options.params,
15763
+ ...options.nativeOptions,
15764
+ });
15765
+ if (updateWmsParamsFromOpt) {
15766
+ const updateWmsParams = this.layer.updateWmsParams;
15767
+ this.layer.updateWmsParams = function (map) {
15768
+ updateWmsParams.call(this, map);
15769
+ this.wmsParams = updateWmsParamsFromOpt(this.wmsParams);
15770
+ };
15771
+ }
15772
+ return this.layer;
15773
+ }
15774
+ }
15775
+ }
15776
+
15777
+ function makeRemote(Base) {
15778
+ return class RemoteTileLayer extends Base {
15779
+ constructor(...args) {
15780
+ super(...args);
15781
+ if (this.options.setViewDelay) {
15782
+ // @ts-ignore
15783
+ this._update = debounce((...a) => {
15784
+ // @ts-ignore
15785
+ leafletSrc.exports.GridLayer.prototype._update.call(this, ...a);
15786
+ }, this.options.setViewDelay);
15787
+ }
15788
+ }
15789
+ createTile(coords, done) {
15790
+ // @ts-ignore
15791
+ const url = this.getTileUrl(coords);
15792
+ const tile = document.createElement('img');
15793
+ tile.abort = callAjax(url, (response) => {
15794
+ tile.src = response;
15795
+ done(null, tile);
15796
+ },
15797
+ // @ts-ignore
15798
+ this.options.headers);
15799
+ if (this.options.crossOrigin || this.options.crossOrigin === '') {
15800
+ tile.crossOrigin =
15801
+ this.options.crossOrigin === true ? '' : this.options.crossOrigin;
15802
+ }
15803
+ tile.alt = '';
15804
+ tile.setAttribute('role', 'presentation');
15805
+ return tile;
15806
+ }
15807
+ _abortLoading() {
15808
+ // @ts-ignore
15809
+ const tiles = this._tiles;
15810
+ // @ts-ignore
15811
+ const tileZoom = this._tileZoom;
15812
+ for (const i in tiles) {
15813
+ if (tiles[i].coords.z !== tileZoom) {
15814
+ const tile = tiles[i].el;
15815
+ tile.onload = leafletSrc.exports.Util.falseFn;
15816
+ tile.onerror = leafletSrc.exports.Util.falseFn;
15817
+ if (!tile.complete) {
15818
+ if (tile.abort) {
15819
+ tile.abort();
15820
+ }
15821
+ tile.src = leafletSrc.exports.Util.emptyImageUrl;
15822
+ leafletSrc.exports.DomUtil.remove(tile);
15823
+ delete tiles[i];
15824
+ }
15825
+ }
15826
+ }
15827
+ }
15828
+ };
15829
+ }
15830
+
15831
+ class TileLayerBase extends leafletSrc.exports.TileLayer {
15832
+ constructor(urlTemplate, options) {
15833
+ super(urlTemplate, options);
15834
+ Object.assign(this.options, options);
15835
+ }
15836
+ }
15837
+ const TileLayer = makeRemote(TileLayerBase);
15838
+
15839
+ class TileAdapter extends BaseAdapter {
15840
+ addLayer(options) {
15841
+ this.options = Object.assign(this.options, options);
15842
+ if (options) {
15843
+ const { url, ...opt } = options;
15844
+ if (url) {
15845
+ const tileLayerOptions = {
15846
+ pane: this.pane,
15847
+ attribution: opt.attribution,
15848
+ minZoom: opt.minZoom,
15849
+ maxZoom: opt.maxZoom,
15850
+ ...opt.nativeOptions,
15851
+ };
15852
+ if (opt.subdomains) {
15853
+ tileLayerOptions.subdomains = opt.subdomains;
15854
+ }
15855
+ let layer;
15856
+ if (opt.headers) {
15857
+ layer = new TileLayer(url, {
15858
+ ...tileLayerOptions,
15859
+ headers: opt.headers,
15860
+ setViewDelay: opt.setViewDelay,
15861
+ });
15862
+ }
15863
+ else {
15864
+ layer = new leafletSrc.exports.TileLayer(url, tileLayerOptions);
15865
+ }
15866
+ return layer;
15867
+ }
15868
+ }
15869
+ }
15870
+ }
15871
+
15872
+ class WmsLayerBase extends leafletSrc.exports.TileLayer.WMS {
15873
+ constructor(urlTemplate, options) {
15874
+ super(urlTemplate, options);
15875
+ }
15876
+ }
15877
+ const WmsLayer = makeRemote(WmsLayerBase);
15878
+
15879
+ class WmsAdapter extends BaseAdapter {
15880
+ addLayer(options) {
15881
+ Object.assign(this.options, options);
15882
+ const { url, ...opt } = options;
15883
+ if (url) {
15884
+ const layerOptions = {
15885
+ pane: this.pane,
15886
+ attribution: opt.attribution,
15887
+ minZoom: opt.minZoom,
15888
+ maxZoom: opt.maxZoom,
15889
+ layers: options.layers,
15890
+ format: options.format,
15891
+ ...options.nativeOptions,
15892
+ };
15893
+ let layer;
15894
+ if (opt.headers) {
15895
+ layer = new WmsLayer(url, { ...layerOptions, headers: opt.headers });
15896
+ }
15897
+ else {
15898
+ layer = new leafletSrc.exports.TileLayer.WMS(url, layerOptions);
15899
+ }
15900
+ return layer;
15901
+ }
15902
+ }
16029
15903
  }
16030
15904
 
16031
- var LeafletMapAdapter$1 = /** @class */ (function () {
16032
- function LeafletMapAdapter() {
16033
- this.options = { target: 'map' };
16034
- this.layerAdapters = LeafletMapAdapter.layerAdapters;
16035
- this.controlAdapters = LeafletMapAdapter.controlAdapters;
16036
- this.emitter = new events.exports.EventEmitter();
16037
- this._unselectCb = [];
16038
- this._universalEvents = [
16039
- 'move',
16040
- 'zoom',
16041
- 'zoomend',
16042
- 'zoomstart',
16043
- 'moveend',
16044
- 'movestart',
16045
- ];
16046
- this._positionEvents = [
16047
- 'mousemove',
16048
- 'mouseout',
16049
- 'mouseover',
16050
- ];
16051
- }
16052
- LeafletMapAdapter.prototype.create = function (options) {
16053
- var _this = this;
16054
- this.options = __assign({}, options);
16055
- if (this.options.target) {
16056
- var _a = this.options, zoom = _a.zoom, center = _a.center, maxZoom = _a.maxZoom, minZoom = _a.minZoom, mb = _a.maxBounds, mapAdapterOptions = _a.mapAdapterOptions;
16057
- this.map =
16058
- this.options.map ||
16059
- new leafletSrc.exports.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));
16060
- // create default pane
16061
- var defPane = this.map.createPane('order-0');
16062
- this.map._addUnselectCb = function (def) {
16063
- _this._addUnselectCb(def);
16064
- };
16065
- defPane.style.zIndex = String(0);
16066
- this.emitter.emit('create', this);
16067
- this._addMapListeners();
16068
- }
16069
- };
16070
- LeafletMapAdapter.prototype.destroy = function () {
16071
- if (this.map) {
16072
- this.map.remove();
16073
- }
16074
- this._stopWatchSizeChangeToUpdateMinZoom();
16075
- };
16076
- LeafletMapAdapter.prototype.getContainer = function () {
16077
- return this.map && this.map.getContainer();
16078
- };
16079
- LeafletMapAdapter.prototype.getControlContainer = function () {
16080
- var controlContainer = this.map && this.map._controlContainer;
16081
- if (controlContainer) {
16082
- return controlContainer;
16083
- }
16084
- throw new Error('Leaflet Map is not initialized yet');
16085
- };
16086
- LeafletMapAdapter.prototype.setCursor = function (cursor) {
16087
- if (this.map) {
16088
- this.map.getContainer().style.cursor = cursor;
16089
- }
16090
- };
16091
- LeafletMapAdapter.prototype.setView = function (lngLatOrOpt, zoom) {
16092
- var map = this.map;
16093
- if (!map)
16094
- return;
16095
- if (Array.isArray(lngLatOrOpt)) {
16096
- var lngLat = lngLatOrOpt;
16097
- var lng = lngLat[0], lat = lngLat[1];
16098
- if (this.map) {
16099
- if (typeof zoom === 'number') {
16100
- this.map.setView([lat, lng], zoom, { animate: false });
16101
- }
16102
- else {
16103
- this.setCenter([lng, lat]);
16104
- }
16105
- }
16106
- }
16107
- else {
16108
- var zoom_1 = lngLatOrOpt.zoom, center = lngLatOrOpt.center, maxBounds = lngLatOrOpt.maxBounds, bounds = lngLatOrOpt.bounds, minZoom = lngLatOrOpt.minZoom, maxZoom = lngLatOrOpt.maxZoom;
16109
- if (center && zoom_1 !== undefined) {
16110
- this.setView(center, zoom_1);
16111
- }
16112
- else {
16113
- if (zoom_1 !== undefined) {
16114
- this.setZoom(zoom_1);
16115
- }
16116
- if (center) {
16117
- this.setCenter(center);
16118
- }
16119
- }
16120
- if (bounds) {
16121
- this.fitBounds(bounds);
16122
- }
16123
- if (maxBounds !== undefined) {
16124
- if (maxBounds) {
16125
- var b = arrayToBoundsExpression(maxBounds);
16126
- map.setMaxBounds(b);
16127
- map.setMinZoom(map.getBoundsZoom(b));
16128
- this._watchSizeChangeToUpdateMinZoom(b);
16129
- }
16130
- else {
16131
- // @ts-ignore `null` works for unset maxBounds, but not in typing
16132
- map.setMaxBounds(null);
16133
- this._stopWatchSizeChangeToUpdateMinZoom();
16134
- }
16135
- }
16136
- if (maxZoom !== undefined) {
16137
- map.setMaxZoom(maxZoom);
16138
- }
16139
- if (minZoom !== undefined) {
16140
- this._stopWatchSizeChangeToUpdateMinZoom();
16141
- map.setMinZoom(minZoom);
16142
- }
16143
- }
16144
- };
16145
- LeafletMapAdapter.prototype.setCenter = function (lngLat) {
16146
- var lng = lngLat[0], lat = lngLat[1];
16147
- if (this.map) {
16148
- this.map.panTo([lat, lng]);
16149
- }
16150
- };
16151
- LeafletMapAdapter.prototype.getCenter = function () {
16152
- var map = this.map;
16153
- if (map) {
16154
- var bounds = map.getBounds();
16155
- var center = bounds.getCenter();
16156
- return [center.lng, center.lat];
16157
- }
16158
- };
16159
- LeafletMapAdapter.prototype.setZoom = function (zoom) {
16160
- if (this.map) {
16161
- this.map.setZoom(zoom);
16162
- }
16163
- };
16164
- LeafletMapAdapter.prototype.getZoom = function () {
16165
- var _a;
16166
- return (_a = (this.map && this.map.getZoom())) !== null && _a !== void 0 ? _a : undefined;
16167
- };
16168
- LeafletMapAdapter.prototype.getBounds = function () {
16169
- if (!this.map)
16170
- return undefined;
16171
- var b = this.map.getBounds();
16172
- var sw = b.getSouthWest();
16173
- var ne = b.getNorthEast();
16174
- return [sw.lng, sw.lat, ne.lng, ne.lat];
16175
- };
16176
- // [west, south, east, north]
16177
- LeafletMapAdapter.prototype.fitBounds = function (bounds, options) {
16178
- if (options === void 0) { options = {}; }
16179
- if (this.map) {
16180
- var maxZoom = options.maxZoom, offset = options.offset, padding = options.padding;
16181
- var opt = {};
16182
- if (maxZoom) {
16183
- opt.maxZoom = maxZoom;
16184
- }
16185
- if (padding) {
16186
- opt.padding = [padding, padding];
16187
- }
16188
- if (offset) {
16189
- opt.padding = offset;
16190
- }
16191
- this.map.fitBounds(arrayToBoundsExpression(bounds), opt);
16192
- }
16193
- };
16194
- LeafletMapAdapter.prototype.getLayerAdapter = function (name) {
16195
- return LeafletMapAdapter.layerAdapters[name];
16196
- };
16197
- LeafletMapAdapter.prototype.createControl = function (control, options) {
16198
- return createControl(control, options, this);
16199
- };
16200
- LeafletMapAdapter.prototype.createButtonControl = function (options) {
16201
- return createButtonControl(options, this);
16202
- };
16203
- LeafletMapAdapter.prototype.addControl = function (control, position) {
16204
- control.options.position = position.replace('-', '');
16205
- if (this.map) {
16206
- this.map.addControl(control);
16207
- return control;
16208
- }
16209
- };
16210
- LeafletMapAdapter.prototype.removeControl = function (control) {
16211
- if (this.map) {
16212
- this.map.removeControl(control);
16213
- }
16214
- };
16215
- LeafletMapAdapter.prototype.removeLayer = function (layer) {
16216
- layer && layer.remove && layer.remove();
16217
- };
16218
- LeafletMapAdapter.prototype.showLayer = function (layer) {
16219
- if (this.map) {
16220
- layer.addTo(this.map);
16221
- }
16222
- };
16223
- LeafletMapAdapter.prototype.hideLayer = function (layer) {
16224
- layer.remove();
16225
- };
16226
- LeafletMapAdapter.prototype.setLayerOpacity = function (layer, value) {
16227
- if ('setOpacity' in layer) {
16228
- layer.setOpacity(value);
16229
- }
16230
- };
16231
- LeafletMapAdapter.prototype.setLayerOrder = function (layer, order, layers) {
16232
- //
16233
- };
16234
- LeafletMapAdapter.prototype.onMapClick = function (evt) {
16235
- var converted = convertMapClickEvent(evt);
16236
- this.emitter.emit('preclick', converted);
16237
- this.emitter.emit('click', converted);
16238
- };
16239
- LeafletMapAdapter.prototype.locate = function (opt, events) {
16240
- var map = this.map;
16241
- if (map) {
16242
- map.locate(opt);
16243
- if (events) {
16244
- var locationfound_1 = events.locationfound, locationerror_1 = events.locationerror;
16245
- var locationFound_1 = function (e) {
16246
- var event = e;
16247
- var lngLat = [event.latlng.lng, event.latlng.lat];
16248
- locationfound_1({ lngLat: lngLat });
16249
- };
16250
- if (locationfound_1 !== undefined) {
16251
- map.on('locationfound', locationFound_1, this);
16252
- }
16253
- if (locationerror_1) {
16254
- map.on('locationerror', locationerror_1, this);
16255
- }
16256
- var stop_1 = function () {
16257
- if (locationfound_1 !== undefined) {
16258
- map.off('locationfound', locationFound_1);
16259
- }
16260
- if (locationerror_1) {
16261
- map.off('locationerror', locationerror_1);
16262
- }
16263
- };
16264
- return { stop: stop_1 };
16265
- }
16266
- }
16267
- var stop = function () { return void 'fake function'; };
16268
- return { stop: stop };
16269
- };
16270
- LeafletMapAdapter.prototype._addUnselectCb = function (cb) {
16271
- for (var _i = 0, _a = this._unselectCb; _i < _a.length; _i++) {
16272
- var p = _a[_i];
16273
- p();
16274
- }
16275
- this._unselectCb.length = 0;
16276
- this._unselectCb.push(cb);
16277
- };
16278
- LeafletMapAdapter.prototype._watchSizeChangeToUpdateMinZoom = function (bounds) {
16279
- this._stopWatchSizeChangeToUpdateMinZoom();
16280
- var container = this.getContainer();
16281
- var map = this.map;
16282
- if (container && map && window.ResizeObserver) {
16283
- this._resizeObserver = new ResizeObserver(function () {
16284
- map.setMinZoom(map.getBoundsZoom(bounds));
16285
- });
16286
- this._resizeObserver.observe(container);
16287
- }
16288
- };
16289
- LeafletMapAdapter.prototype._stopWatchSizeChangeToUpdateMinZoom = function () {
16290
- var map = this.map;
16291
- if (map) {
16292
- map.setMinZoom(0);
16293
- }
16294
- if (this._resizeObserver) {
16295
- this._resizeObserver.disconnect();
16296
- this._resizeObserver = undefined;
16297
- }
16298
- };
16299
- LeafletMapAdapter.prototype._addMapListeners = function () {
16300
- var _this = this;
16301
- var map = this.map;
16302
- if (map) {
16303
- map.on('click', function (evt) {
16304
- _this.onMapClick(evt);
16305
- });
16306
- var _loop_1 = function (e) {
16307
- map.on(e, function () { return _this.emitter.emit(e, _this); }, map);
16308
- };
16309
- for (var _i = 0, _a = this._universalEvents; _i < _a.length; _i++) {
16310
- var e = _a[_i];
16311
- _loop_1(e);
16312
- }
16313
- var _loop_2 = function (e) {
16314
- map.on(e, function (evt) {
16315
- return _this.emitter.emit(e, convertMapClickEvent(evt));
16316
- }, map);
16317
- };
16318
- for (var _b = 0, _c = this._positionEvents; _b < _c.length; _b++) {
16319
- var e = _c[_b];
16320
- _loop_2(e);
16321
- }
16322
- }
16323
- };
16324
- LeafletMapAdapter.layerAdapters = {
16325
- GEOJSON: GeoJsonAdapter,
16326
- IMAGE: ImageAdapter,
16327
- TILE: TileAdapter,
16328
- WMS: WmsAdapter,
16329
- // // MVT: MvtAdapter,
16330
- OSM: OsmAdapter,
16331
- };
16332
- LeafletMapAdapter.controlAdapters = {
16333
- ZOOM: leafletSrc.exports.Control.Zoom,
16334
- ATTRIBUTION: AttributionControl,
16335
- };
16336
- LeafletMapAdapter.Map = leafletSrc.exports.Map;
16337
- return LeafletMapAdapter;
16338
- }());
16339
-
16340
- /**
16341
- * @module leaflet-map-adapter
16342
- */
15905
+ class OsmAdapter extends TileAdapter {
15906
+ addLayer(options) {
15907
+ const url = 'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png';
15908
+ return super.addLayer({
15909
+ name: 'OpenStreetMap',
15910
+ attribution: '&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors',
15911
+ ...options,
15912
+ url,
15913
+ });
15914
+ }
15915
+ }
15916
+
15917
+ function arrayToBoundsExpression(bounds) {
15918
+ const e = bounds;
15919
+ // top, left, bottom, right
15920
+ return [
15921
+ [e[3], e[0]],
15922
+ [e[1], e[2]],
15923
+ ];
15924
+ }
15925
+
15926
+ class LeafletMapAdapter$1 {
15927
+ constructor() {
15928
+ this.options = { target: 'map' };
15929
+ this.layerAdapters = LeafletMapAdapter$1.layerAdapters;
15930
+ this.controlAdapters = LeafletMapAdapter$1.controlAdapters;
15931
+ this.emitter = new events.exports.EventEmitter();
15932
+ this._unselectCb = [];
15933
+ this._universalEvents = [
15934
+ 'move',
15935
+ 'zoom',
15936
+ 'zoomend',
15937
+ 'zoomstart',
15938
+ 'moveend',
15939
+ 'movestart',
15940
+ ];
15941
+ this._positionEvents = [
15942
+ 'mousemove',
15943
+ 'mouseout',
15944
+ 'mouseover',
15945
+ ];
15946
+ }
15947
+ create(options) {
15948
+ this.options = { ...options };
15949
+ if (this.options.target) {
15950
+ const { zoom, center, maxZoom, minZoom, maxBounds: mb, mapAdapterOptions, } = this.options;
15951
+ this.map =
15952
+ this.options.map ||
15953
+ new leafletSrc.exports.Map(this.options.target, {
15954
+ attributionControl: false,
15955
+ zoomControl: false,
15956
+ maxBounds: mb ? arrayToBoundsExpression(mb) : undefined,
15957
+ maxZoom,
15958
+ minZoom,
15959
+ center: center && [center[1], center[0]],
15960
+ zoom,
15961
+ ...mapAdapterOptions,
15962
+ });
15963
+ // create default pane
15964
+ const defPane = this.map.createPane('order-0');
15965
+ this.map._addUnselectCb = (def) => {
15966
+ this._addUnselectCb(def);
15967
+ };
15968
+ defPane.style.zIndex = String(0);
15969
+ this.emitter.emit('create', this);
15970
+ this._addMapListeners();
15971
+ }
15972
+ }
15973
+ destroy() {
15974
+ if (this.map) {
15975
+ this.map.remove();
15976
+ }
15977
+ this._stopWatchSizeChangeToUpdateMinZoom();
15978
+ }
15979
+ getContainer() {
15980
+ return this.map && this.map.getContainer();
15981
+ }
15982
+ getControlContainer() {
15983
+ const controlContainer = this.map && this.map._controlContainer;
15984
+ if (controlContainer) {
15985
+ return controlContainer;
15986
+ }
15987
+ throw new Error('Leaflet Map is not initialized yet');
15988
+ }
15989
+ setCursor(cursor) {
15990
+ if (this.map) {
15991
+ this.map.getContainer().style.cursor = cursor;
15992
+ }
15993
+ }
15994
+ setView(lngLatOrOpt, zoom) {
15995
+ const map = this.map;
15996
+ if (!map)
15997
+ return;
15998
+ if (Array.isArray(lngLatOrOpt)) {
15999
+ const lngLat = lngLatOrOpt;
16000
+ const [lng, lat] = lngLat;
16001
+ if (this.map) {
16002
+ if (typeof zoom === 'number') {
16003
+ this.map.setView([lat, lng], zoom, { animate: false });
16004
+ }
16005
+ else {
16006
+ this.setCenter([lng, lat]);
16007
+ }
16008
+ }
16009
+ }
16010
+ else {
16011
+ const { zoom, center, maxBounds, bounds, minZoom, maxZoom } = lngLatOrOpt;
16012
+ if (center && zoom !== undefined) {
16013
+ this.setView(center, zoom);
16014
+ }
16015
+ else {
16016
+ if (zoom !== undefined) {
16017
+ this.setZoom(zoom);
16018
+ }
16019
+ if (center) {
16020
+ this.setCenter(center);
16021
+ }
16022
+ }
16023
+ if (bounds) {
16024
+ this.fitBounds(bounds);
16025
+ }
16026
+ if (maxBounds !== undefined) {
16027
+ if (maxBounds) {
16028
+ const b = arrayToBoundsExpression(maxBounds);
16029
+ map.setMaxBounds(b);
16030
+ map.setMinZoom(map.getBoundsZoom(b));
16031
+ this._watchSizeChangeToUpdateMinZoom(b);
16032
+ }
16033
+ else {
16034
+ // @ts-ignore `null` works for unset maxBounds, but not in typing
16035
+ map.setMaxBounds(null);
16036
+ this._stopWatchSizeChangeToUpdateMinZoom();
16037
+ }
16038
+ }
16039
+ if (maxZoom !== undefined) {
16040
+ map.setMaxZoom(maxZoom);
16041
+ }
16042
+ if (minZoom !== undefined) {
16043
+ this._stopWatchSizeChangeToUpdateMinZoom();
16044
+ map.setMinZoom(minZoom);
16045
+ }
16046
+ }
16047
+ }
16048
+ setCenter(lngLat) {
16049
+ const [lng, lat] = lngLat;
16050
+ if (this.map) {
16051
+ this.map.panTo([lat, lng]);
16052
+ }
16053
+ }
16054
+ getCenter() {
16055
+ const map = this.map;
16056
+ if (map) {
16057
+ const bounds = map.getBounds();
16058
+ const center = bounds.getCenter();
16059
+ return [center.lng, center.lat];
16060
+ }
16061
+ }
16062
+ setZoom(zoom) {
16063
+ if (this.map) {
16064
+ this.map.setZoom(zoom);
16065
+ }
16066
+ }
16067
+ getZoom() {
16068
+ var _a;
16069
+ return (_a = (this.map && this.map.getZoom())) !== null && _a !== void 0 ? _a : undefined;
16070
+ }
16071
+ getBounds() {
16072
+ if (!this.map)
16073
+ return undefined;
16074
+ const b = this.map.getBounds();
16075
+ const sw = b.getSouthWest();
16076
+ const ne = b.getNorthEast();
16077
+ return [sw.lng, sw.lat, ne.lng, ne.lat];
16078
+ }
16079
+ // [west, south, east, north]
16080
+ fitBounds(bounds, options = {}) {
16081
+ if (this.map) {
16082
+ const { maxZoom, offset, padding } = options;
16083
+ const opt = {};
16084
+ if (maxZoom) {
16085
+ opt.maxZoom = maxZoom;
16086
+ }
16087
+ if (padding) {
16088
+ opt.padding = [padding, padding];
16089
+ }
16090
+ if (offset) {
16091
+ opt.padding = offset;
16092
+ }
16093
+ this.map.fitBounds(arrayToBoundsExpression(bounds), opt);
16094
+ }
16095
+ }
16096
+ getLayerAdapter(name) {
16097
+ return LeafletMapAdapter$1.layerAdapters[name];
16098
+ }
16099
+ createControl(control, options) {
16100
+ return createControl(control, options, this);
16101
+ }
16102
+ createButtonControl(options) {
16103
+ return createButtonControl(options, this);
16104
+ }
16105
+ addControl(control, position) {
16106
+ control.options.position = position.replace('-', '');
16107
+ if (this.map) {
16108
+ this.map.addControl(control);
16109
+ return control;
16110
+ }
16111
+ }
16112
+ removeControl(control) {
16113
+ if (this.map) {
16114
+ this.map.removeControl(control);
16115
+ }
16116
+ }
16117
+ removeLayer(layer) {
16118
+ layer && layer.remove && layer.remove();
16119
+ }
16120
+ showLayer(layer) {
16121
+ if (this.map) {
16122
+ layer.addTo(this.map);
16123
+ }
16124
+ }
16125
+ hideLayer(layer) {
16126
+ layer.remove();
16127
+ }
16128
+ setLayerOpacity(layer, value) {
16129
+ if ('setOpacity' in layer) {
16130
+ layer.setOpacity(value);
16131
+ }
16132
+ }
16133
+ setLayerOrder(layer, order, layers) {
16134
+ //
16135
+ }
16136
+ onMapClick(evt) {
16137
+ const converted = convertMapClickEvent(evt);
16138
+ this.emitter.emit('preclick', converted);
16139
+ this.emitter.emit('click', converted);
16140
+ }
16141
+ locate(opt, events) {
16142
+ const map = this.map;
16143
+ if (map) {
16144
+ map.locate(opt);
16145
+ if (events) {
16146
+ const { locationfound, locationerror } = events;
16147
+ const locationFound = (e) => {
16148
+ const event = e;
16149
+ const lngLat = [event.latlng.lng, event.latlng.lat];
16150
+ locationfound({ lngLat });
16151
+ };
16152
+ if (locationfound !== undefined) {
16153
+ map.on('locationfound', locationFound, this);
16154
+ }
16155
+ if (locationerror) {
16156
+ map.on('locationerror', locationerror, this);
16157
+ }
16158
+ const stop = () => {
16159
+ if (locationfound !== undefined) {
16160
+ map.off('locationfound', locationFound);
16161
+ }
16162
+ if (locationerror) {
16163
+ map.off('locationerror', locationerror);
16164
+ }
16165
+ };
16166
+ return { stop };
16167
+ }
16168
+ }
16169
+ const stop = () => void 'fake function';
16170
+ return { stop };
16171
+ }
16172
+ _addUnselectCb(cb) {
16173
+ for (const p of this._unselectCb) {
16174
+ p();
16175
+ }
16176
+ this._unselectCb.length = 0;
16177
+ this._unselectCb.push(cb);
16178
+ }
16179
+ _watchSizeChangeToUpdateMinZoom(bounds) {
16180
+ this._stopWatchSizeChangeToUpdateMinZoom();
16181
+ const container = this.getContainer();
16182
+ const map = this.map;
16183
+ if (container && map && window.ResizeObserver) {
16184
+ this._resizeObserver = new ResizeObserver(() => {
16185
+ map.setMinZoom(map.getBoundsZoom(bounds));
16186
+ });
16187
+ this._resizeObserver.observe(container);
16188
+ }
16189
+ }
16190
+ _stopWatchSizeChangeToUpdateMinZoom() {
16191
+ const map = this.map;
16192
+ if (map) {
16193
+ map.setMinZoom(0);
16194
+ }
16195
+ if (this._resizeObserver) {
16196
+ this._resizeObserver.disconnect();
16197
+ this._resizeObserver = undefined;
16198
+ }
16199
+ }
16200
+ _addMapListeners() {
16201
+ const map = this.map;
16202
+ if (map) {
16203
+ map.on('click', (evt) => {
16204
+ this.onMapClick(evt);
16205
+ });
16206
+ for (const e of this._universalEvents) {
16207
+ map.on(e, () => this.emitter.emit(e, this), map);
16208
+ }
16209
+ for (const e of this._positionEvents) {
16210
+ map.on(e, (evt) => this.emitter.emit(e, convertMapClickEvent(evt)), map);
16211
+ }
16212
+ }
16213
+ }
16214
+ }
16215
+ LeafletMapAdapter$1.layerAdapters = {
16216
+ GEOJSON: GeoJsonAdapter,
16217
+ IMAGE: ImageAdapter,
16218
+ TILE: TileAdapter,
16219
+ WMS: WmsAdapter,
16220
+ // // MVT: MvtAdapter,
16221
+ OSM: OsmAdapter,
16222
+ };
16223
+ LeafletMapAdapter$1.controlAdapters = {
16224
+ ZOOM: leafletSrc.exports.Control.Zoom,
16225
+ ATTRIBUTION: AttributionControl,
16226
+ };
16227
+ LeafletMapAdapter$1.Map = leafletSrc.exports.Map;
16228
+
16229
+ /**
16230
+ * @module leaflet-map-adapter
16231
+ */
16343
16232
  var LeafletMapAdapter = LeafletMapAdapter$1;
16344
16233
 
16345
16234
  export { LeafletMapAdapter as default };