@nextgis/leaflet-map-adapter 1.18.21 → 1.19.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,19 +1,25 @@
1
- /** Bundle of @nextgis/leaflet-map-adapter; version: 1.18.21; author: NextGIS */
1
+ /** Bundle of @nextgis/leaflet-map-adapter; version: 1.19.0; author: NextGIS */
2
2
  import { EventEmitter } from 'events';
3
3
  import { Control, DomEvent, GeoJSON, DivIcon, Marker, CircleMarker, FeatureGroup, ImageOverlay as ImageOverlay$1, Layer, Util, CRS, GridLayer, DomUtil, TileLayer as TileLayer$1, Map } from 'leaflet';
4
4
  import { defined, debounce as debounce$1 } from '@nextgis/utils';
5
5
  import { isPaintCallback, isPaint } from '@nextgis/paint';
6
6
 
7
- function convertMapClickEvent(evt) {
8
- const coord = evt.containerPoint;
9
- const latLng = evt.latlng;
10
- const { lat, lng } = latLng;
11
- return {
12
- latLng,
13
- lngLat: [lng, lat],
14
- pixel: { left: coord.x, top: coord.y },
15
- source: evt,
16
- };
7
+ class AttributionControl extends Control.Attribution {
8
+ // options: AttributionControlOptions
9
+ constructor(options) {
10
+ super(options);
11
+ const customAttribution = options && options.customAttribution;
12
+ if (customAttribution) {
13
+ let attributions = [];
14
+ if (Array.isArray(customAttribution)) {
15
+ attributions = customAttribution;
16
+ }
17
+ else if (customAttribution) {
18
+ attributions = [customAttribution];
19
+ }
20
+ attributions.forEach((x) => this.addAttribution(x));
21
+ }
22
+ }
17
23
  }
18
24
 
19
25
  function createControl(control, options = {}, map) {
@@ -88,30 +94,45 @@ function createButtonControl(options, map) {
88
94
  }, { bar: true }, map);
89
95
  }
90
96
 
91
- class AttributionControl extends Control.Attribution {
92
- // options: AttributionControlOptions
93
- constructor(options) {
94
- super(options);
95
- const customAttribution = options && options.customAttribution;
96
- if (customAttribution) {
97
- let attributions = [];
98
- if (Array.isArray(customAttribution)) {
99
- attributions = customAttribution;
100
- }
101
- else if (customAttribution) {
102
- attributions = [customAttribution];
103
- }
104
- attributions.forEach((x) => this.addAttribution(x));
105
- }
106
- }
107
- }
108
-
109
97
  function boundsToArray(bounds) {
110
98
  const ne = bounds.getNorthEast();
111
99
  const sw = bounds.getSouthWest();
112
100
  return [sw.lng, sw.lat, ne.lng, ne.lat];
113
101
  }
114
102
 
103
+ function findMostFrequentGeomType(arr) {
104
+ const counts = {};
105
+ for (let fry = 0; fry < arr.length; fry++) {
106
+ counts[arr[fry]] = 1 + (counts[arr[fry]] || 0);
107
+ }
108
+ let maxName = '';
109
+ for (const c in counts) {
110
+ const maxCount = maxName ? counts[maxName] : 0;
111
+ if (counts[c] > maxCount) {
112
+ maxName = c;
113
+ }
114
+ }
115
+ return maxName;
116
+ }
117
+ function detectType(geojson) {
118
+ let geometry;
119
+ if (geojson.type === 'FeatureCollection') {
120
+ const featuresTypes = geojson.features.map((f) => f.geometry.type);
121
+ geometry = findMostFrequentGeomType(featuresTypes);
122
+ }
123
+ else if (geojson.type === 'GeometryCollection') {
124
+ const geometryTypes = geojson.geometries.map((g) => g.type);
125
+ geometry = findMostFrequentGeomType(geometryTypes);
126
+ }
127
+ else if (geojson.type === 'Feature') {
128
+ geometry = geojson.geometry.type;
129
+ }
130
+ else {
131
+ geometry = geojson.type;
132
+ }
133
+ return geometry;
134
+ }
135
+
115
136
  const typeAlias = {
116
137
  Point: 'point',
117
138
  LineString: 'line',
@@ -173,39 +194,6 @@ function createFeaturePositionOptions(features) {
173
194
  };
174
195
  }
175
196
 
176
- function findMostFrequentGeomType(arr) {
177
- const counts = {};
178
- for (let fry = 0; fry < arr.length; fry++) {
179
- counts[arr[fry]] = 1 + (counts[arr[fry]] || 0);
180
- }
181
- let maxName = '';
182
- for (const c in counts) {
183
- const maxCount = maxName ? counts[maxName] : 0;
184
- if (counts[c] > maxCount) {
185
- maxName = c;
186
- }
187
- }
188
- return maxName;
189
- }
190
- function detectType(geojson) {
191
- let geometry;
192
- if (geojson.type === 'FeatureCollection') {
193
- const featuresTypes = geojson.features.map((f) => f.geometry.type);
194
- geometry = findMostFrequentGeomType(featuresTypes);
195
- }
196
- else if (geojson.type === 'GeometryCollection') {
197
- const geometryTypes = geojson.geometries.map((g) => g.type);
198
- geometry = findMostFrequentGeomType(geometryTypes);
199
- }
200
- else if (geojson.type === 'Feature') {
201
- geometry = geojson.geometry.type;
202
- }
203
- else {
204
- geometry = geojson.type;
205
- }
206
- return geometry;
207
- }
208
-
209
197
  class BaseAdapter {
210
198
  constructor(map, options) {
211
199
  this.map = map;
@@ -227,6 +215,18 @@ class BaseAdapter {
227
215
  }
228
216
  }
229
217
 
218
+ function convertMapClickEvent(evt) {
219
+ const coord = evt.containerPoint;
220
+ const latLng = evt.latlng;
221
+ const { lat, lng } = latLng;
222
+ return {
223
+ latLng,
224
+ lngLat: [lng, lat],
225
+ pixel: { left: coord.x, top: coord.y },
226
+ source: evt,
227
+ };
228
+ }
229
+
230
230
  function createMouseEvent({ layer, source, }) {
231
231
  const layer_ = source.target;
232
232
  const feature = layer_.feature;
@@ -1338,6 +1338,18 @@ class TileAdapter extends BaseAdapter {
1338
1338
  }
1339
1339
  }
1340
1340
 
1341
+ class OsmAdapter extends TileAdapter {
1342
+ addLayer(options) {
1343
+ const url = 'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png';
1344
+ return super.addLayer({
1345
+ name: 'OpenStreetMap',
1346
+ attribution: '&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors',
1347
+ ...options,
1348
+ url,
1349
+ });
1350
+ }
1351
+ }
1352
+
1341
1353
  class WmsLayerBase extends TileLayer$1.WMS {
1342
1354
  constructor(urlTemplate, options) {
1343
1355
  super(urlTemplate, options);
@@ -1371,18 +1383,6 @@ class WmsAdapter extends BaseAdapter {
1371
1383
  }
1372
1384
  }
1373
1385
 
1374
- class OsmAdapter extends TileAdapter {
1375
- addLayer(options) {
1376
- const url = 'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png';
1377
- return super.addLayer({
1378
- name: 'OpenStreetMap',
1379
- attribution: '&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors',
1380
- ...options,
1381
- url,
1382
- });
1383
- }
1384
- }
1385
-
1386
1386
  function arrayToBoundsExpression(bounds) {
1387
1387
  const e = bounds;
1388
1388
  // top, left, bottom, right