maplair 4.0.0-alpha.2 → 4.1.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.
- package/CHANGELOG.md +140 -38
- package/LICENSE +1 -1
- package/README.md +10 -9
- package/dist/esm/Maplair.js +14 -14
- package/dist/esm/control/AttributionControl.js +24 -14
- package/dist/esm/control/AttributionControl.js.map +1 -1
- package/dist/esm/control/ButtonControl.js +9 -11
- package/dist/esm/control/ButtonControl.js.map +1 -1
- package/dist/esm/control/ContextMenu.js +1 -3
- package/dist/esm/control/ContextMenu.js.map +1 -1
- package/dist/esm/control/Control.js +9 -16
- package/dist/esm/control/Control.js.map +1 -1
- package/dist/esm/control/FullscreenControl.js +5 -7
- package/dist/esm/control/FullscreenControl.js.map +1 -1
- package/dist/esm/control/LayersControl.js +144 -35
- package/dist/esm/control/LayersControl.js.map +1 -1
- package/dist/esm/control/LegendControl.js +7 -9
- package/dist/esm/control/LegendControl.js.map +1 -1
- package/dist/esm/control/MiniMapControl.js +14 -16
- package/dist/esm/control/MiniMapControl.js.map +1 -1
- package/dist/esm/control/RotateControl.js +1 -3
- package/dist/esm/control/RotateControl.js.map +1 -1
- package/dist/esm/control/ScaleControl.js +7 -9
- package/dist/esm/control/ScaleControl.js.map +1 -1
- package/dist/esm/control/SearchControl.js +100 -18
- package/dist/esm/control/SearchControl.js.map +1 -1
- package/dist/esm/control/SideBySideControl.js +1 -3
- package/dist/esm/control/SideBySideControl.js.map +1 -1
- package/dist/esm/control/TextControl.js +5 -7
- package/dist/esm/control/TextControl.js.map +1 -1
- package/dist/esm/control/TimeControl.js +408 -0
- package/dist/esm/control/TimeControl.js.map +1 -0
- package/dist/esm/control/ZoomControl.js +5 -7
- package/dist/esm/control/ZoomControl.js.map +1 -1
- package/dist/esm/core/Class.js +28 -37
- package/dist/esm/core/Class.js.map +1 -1
- package/dist/esm/core/Events.js +21 -8
- package/dist/esm/core/Events.js.map +1 -1
- package/dist/esm/core/Handler.js +13 -11
- package/dist/esm/core/Handler.js.map +1 -1
- package/dist/esm/core/Util.js +13 -1
- package/dist/esm/core/Util.js.map +1 -1
- package/dist/esm/dom/DomEvent.DoubleTap.js +25 -22
- package/dist/esm/dom/DomEvent.DoubleTap.js.map +1 -1
- package/dist/esm/dom/DomEvent.PointerEvents.js +2 -16
- package/dist/esm/dom/DomEvent.PointerEvents.js.map +1 -1
- package/dist/esm/dom/DomEvent.js +8 -42
- package/dist/esm/dom/DomEvent.js.map +1 -1
- package/dist/esm/dom/DomUtil.js +14 -68
- package/dist/esm/dom/DomUtil.js.map +1 -1
- package/dist/esm/dom/Draggable.js +17 -18
- package/dist/esm/dom/Draggable.js.map +1 -1
- package/dist/esm/dom/PosAnimation.js +3 -25
- package/dist/esm/dom/PosAnimation.js.map +1 -1
- package/dist/esm/geo/LatLng.js +34 -6
- package/dist/esm/geo/LatLng.js.map +1 -1
- package/dist/esm/geo/LatLngBounds.js +19 -7
- package/dist/esm/geo/LatLngBounds.js.map +1 -1
- package/dist/esm/geo/crs/CRS.js +4 -3
- package/dist/esm/geo/crs/CRS.js.map +1 -1
- package/dist/esm/geo/crs/EPSG3395.js +1 -1
- package/dist/esm/geo/crs/EPSG3395.js.map +1 -1
- package/dist/esm/geo/crs/EPSG3857.js +1 -1
- package/dist/esm/geo/crs/EPSG3857.js.map +1 -1
- package/dist/esm/geo/crs/EPSG4326.js +1 -1
- package/dist/esm/geo/crs/EPSG4326.js.map +1 -1
- package/dist/esm/geo/crs/EarthCRS.js +2 -2
- package/dist/esm/geo/crs/EarthCRS.js.map +1 -1
- package/dist/esm/geo/crs/SimpleCRS.js +1 -1
- package/dist/esm/geo/crs/SimpleCRS.js.map +1 -1
- package/dist/esm/geo/projection/Projection.LonLat.js +3 -3
- package/dist/esm/geo/projection/Projection.LonLat.js.map +1 -1
- package/dist/esm/geo/projection/Projection.Mercator.js +3 -3
- package/dist/esm/geo/projection/Projection.Mercator.js.map +1 -1
- package/dist/esm/geo/projection/Projection.SphericalMercator.js +3 -3
- package/dist/esm/geo/projection/Projection.SphericalMercator.js.map +1 -1
- package/dist/esm/geometry/Bounds.js +19 -7
- package/dist/esm/geometry/Bounds.js.map +1 -1
- package/dist/esm/geometry/LineUtil.js +36 -30
- package/dist/esm/geometry/LineUtil.js.map +1 -1
- package/dist/esm/geometry/Point.js +23 -5
- package/dist/esm/geometry/Point.js.map +1 -1
- package/dist/esm/geometry/PolyUtil.js +9 -28
- package/dist/esm/geometry/PolyUtil.js.map +1 -1
- package/dist/esm/layer/BlanketOverlay.js +6 -8
- package/dist/esm/layer/BlanketOverlay.js.map +1 -1
- package/dist/esm/layer/DivOverlay.js +15 -20
- package/dist/esm/layer/DivOverlay.js.map +1 -1
- package/dist/esm/layer/GeoJSON.js +9 -145
- package/dist/esm/layer/GeoJSON.js.map +1 -1
- package/dist/esm/layer/GeoJSONUtil.js +75 -0
- package/dist/esm/layer/GeoJSONUtil.js.map +1 -0
- package/dist/esm/layer/HeatLayer.js +15 -17
- package/dist/esm/layer/HeatLayer.js.map +1 -1
- package/dist/esm/layer/ImageOverlay.js +20 -26
- package/dist/esm/layer/ImageOverlay.js.map +1 -1
- package/dist/esm/layer/Layer.js +8 -10
- package/dist/esm/layer/Layer.js.map +1 -1
- package/dist/esm/layer/LayerGroup.js +51 -0
- package/dist/esm/layer/LayerGroup.js.map +1 -1
- package/dist/esm/layer/Popup.js +27 -43
- package/dist/esm/layer/Popup.js.map +1 -1
- package/dist/esm/layer/SVGOverlay.js +2 -5
- package/dist/esm/layer/SVGOverlay.js.map +1 -1
- package/dist/esm/layer/Tooltip.js +15 -17
- package/dist/esm/layer/Tooltip.js.map +1 -1
- package/dist/esm/layer/VideoOverlay.js +12 -15
- package/dist/esm/layer/VideoOverlay.js.map +1 -1
- package/dist/esm/layer/marker/DefaultIcon.js +15 -48
- package/dist/esm/layer/marker/DefaultIcon.js.map +1 -1
- package/dist/esm/layer/marker/DivIcon.js +8 -10
- package/dist/esm/layer/marker/DivIcon.js.map +1 -1
- package/dist/esm/layer/marker/Icon.js +9 -12
- package/dist/esm/layer/marker/Icon.js.map +1 -1
- package/dist/esm/layer/marker/Marker.Drag.js +1 -1
- package/dist/esm/layer/marker/Marker.Drag.js.map +1 -1
- package/dist/esm/layer/marker/Marker.Move.js +2 -3
- package/dist/esm/layer/marker/Marker.Move.js.map +1 -1
- package/dist/esm/layer/marker/Marker.js +63 -35
- package/dist/esm/layer/marker/Marker.js.map +1 -1
- package/dist/esm/layer/marker/MarkerClusterGroup.js +302 -0
- package/dist/esm/layer/marker/MarkerClusterGroup.js.map +1 -0
- package/dist/esm/layer/marker/SvgIcon.js +6 -8
- package/dist/esm/layer/marker/SvgIcon.js.map +1 -1
- package/dist/esm/layer/tile/GridLayer.js +86 -98
- package/dist/esm/layer/tile/GridLayer.js.map +1 -1
- package/dist/esm/layer/tile/TileLayer.js +28 -36
- package/dist/esm/layer/tile/TileLayer.js.map +1 -1
- package/dist/esm/layer/tile/WMSTileLayer.js +28 -23
- package/dist/esm/layer/tile/WMSTileLayer.js.map +1 -1
- package/dist/esm/layer/vector/Canvas.js +1 -3
- package/dist/esm/layer/vector/Canvas.js.map +1 -1
- package/dist/esm/layer/vector/Circle.js +2 -2
- package/dist/esm/layer/vector/Circle.js.map +1 -1
- package/dist/esm/layer/vector/CircleMarker.js +17 -7
- package/dist/esm/layer/vector/CircleMarker.js.map +1 -1
- package/dist/esm/layer/vector/Path.DashAnimation.js +2 -3
- package/dist/esm/layer/vector/Path.DashAnimation.js.map +1 -1
- package/dist/esm/layer/vector/Path.js +27 -20
- package/dist/esm/layer/vector/Path.js.map +1 -1
- package/dist/esm/layer/vector/Polygon.js +20 -4
- package/dist/esm/layer/vector/Polygon.js.map +1 -1
- package/dist/esm/layer/vector/Polyline.Decorations.js +2 -2
- package/dist/esm/layer/vector/Polyline.js +24 -8
- package/dist/esm/layer/vector/Polyline.js.map +1 -1
- package/dist/esm/layer/vector/Renderer.getRenderer.js +14 -13
- package/dist/esm/layer/vector/Renderer.getRenderer.js.map +1 -1
- package/dist/esm/layer/vector/SVG.js +5 -5
- package/dist/esm/layer/vector/SVG.js.map +1 -1
- package/dist/esm/map/Map.Rotation.js +15 -11
- package/dist/esm/map/Map.Rotation.js.map +1 -1
- package/dist/esm/map/Map.js +135 -129
- package/dist/esm/map/Map.js.map +1 -1
- package/dist/esm/map/handler/BoxZoomHandler.js +5 -7
- package/dist/esm/map/handler/BoxZoomHandler.js.map +1 -1
- package/dist/esm/map/handler/DisplaceHandler.js +6 -8
- package/dist/esm/map/handler/DisplaceHandler.js.map +1 -1
- package/dist/esm/map/handler/DragHandler.js +20 -20
- package/dist/esm/map/handler/DragHandler.js.map +1 -1
- package/dist/esm/map/handler/KeyboardHandler.js +37 -37
- package/dist/esm/map/handler/KeyboardHandler.js.map +1 -1
- package/dist/esm/map/handler/PinchZoomHandler.js +12 -3
- package/dist/esm/map/handler/PinchZoomHandler.js.map +1 -1
- package/dist/esm/map/handler/ScrollWheelZoomHandler.js +3 -4
- package/dist/esm/map/handler/ScrollWheelZoomHandler.js.map +1 -1
- package/dist/esm/map/handler/TapHoldHandler.js +12 -5
- package/dist/esm/map/handler/TapHoldHandler.js.map +1 -1
- package/dist/esm/package.js +1 -1
- package/dist/maplair-global-src.js +6326 -5625
- package/dist/maplair-global-src.js.map +1 -1
- package/dist/maplair-global.js +3 -3
- package/dist/maplair-global.js.map +1 -1
- package/dist/maplair-src.js +9010 -8290
- package/dist/maplair-src.js.map +1 -1
- package/dist/maplair.css +148 -98
- package/dist/maplair.js +3 -3
- package/dist/maplair.js.map +1 -1
- package/i18n/cs.json +6 -0
- package/i18n/de.json +6 -0
- package/i18n/en.json +6 -0
- package/i18n/es.json +6 -0
- package/i18n/fr.json +6 -0
- package/i18n/hu.json +6 -0
- package/i18n/it.json +6 -0
- package/i18n/rm.json +6 -0
- package/i18n/sk.json +6 -0
- package/i18n/sl.json +6 -0
- package/package.json +12 -14
- package/src/control/AttributionControl.js +25 -18
- package/src/control/ButtonControl.js +9 -11
- package/src/control/ContextMenu.js +3 -5
- package/src/control/Control.js +9 -19
- package/src/control/FullscreenControl.js +5 -7
- package/src/control/LayersControl.js +159 -36
- package/src/control/LegendControl.js +7 -9
- package/src/control/MiniMapControl.js +9 -11
- package/src/control/RotateControl.js +3 -5
- package/src/control/ScaleControl.js +7 -9
- package/src/control/SearchControl.js +104 -21
- package/src/control/SideBySideControl.js +3 -5
- package/src/control/TextControl.js +5 -7
- package/src/control/TimeControl.js +471 -0
- package/src/control/ZoomControl.js +5 -7
- package/src/control/index.js +1 -0
- package/src/core/Class.js +35 -34
- package/src/core/Events.js +22 -3
- package/src/core/Handler.js +14 -12
- package/src/core/Util.js +19 -1
- package/src/core/index.js +0 -1
- package/src/dom/DomEvent.DoubleTap.js +18 -10
- package/src/dom/DomEvent.PointerEvents.js +3 -26
- package/src/dom/DomEvent.js +8 -66
- package/src/dom/DomUtil.js +22 -78
- package/src/dom/Draggable.js +27 -22
- package/src/dom/PosAnimation.js +3 -25
- package/src/dom/index.js +0 -1
- package/src/geo/LatLng.js +40 -4
- package/src/geo/LatLngBounds.js +20 -7
- package/src/geo/crs/CRS.js +4 -3
- package/src/geo/crs/EPSG3395.js +1 -1
- package/src/geo/crs/EPSG3857.js +1 -1
- package/src/geo/crs/EPSG4326.js +1 -1
- package/src/geo/crs/EarthCRS.js +2 -8
- package/src/geo/crs/SimpleCRS.js +1 -1
- package/src/geo/projection/Projection.LonLat.js +3 -3
- package/src/geo/projection/Projection.Mercator.js +3 -3
- package/src/geo/projection/Projection.SphericalMercator.js +3 -3
- package/src/geometry/Bounds.js +20 -7
- package/src/geometry/LineUtil.js +47 -48
- package/src/geometry/Point.js +24 -5
- package/src/geometry/PolyUtil.js +15 -44
- package/src/layer/BlanketOverlay.js +6 -10
- package/src/layer/DivOverlay.js +15 -26
- package/src/layer/GeoJSON.js +7 -205
- package/src/layer/GeoJSONUtil.js +85 -0
- package/src/layer/HeatLayer.js +9 -11
- package/src/layer/ImageOverlay.js +19 -30
- package/src/layer/Layer.js +8 -10
- package/src/layer/LayerGroup.js +71 -0
- package/src/layer/Popup.js +31 -46
- package/src/layer/SVGOverlay.js +1 -5
- package/src/layer/Tooltip.js +15 -19
- package/src/layer/VideoOverlay.js +12 -15
- package/src/layer/marker/DefaultIcon.js +15 -61
- package/src/layer/marker/DivIcon.js +10 -12
- package/src/layer/marker/Icon.js +9 -12
- package/src/layer/marker/Marker.Drag.js +1 -1
- package/src/layer/marker/Marker.Move.js +2 -3
- package/src/layer/marker/Marker.js +83 -41
- package/src/layer/marker/MarkerClusterGroup.js +370 -0
- package/src/layer/marker/SvgIcon.js +7 -9
- package/src/layer/marker/index.js +1 -0
- package/src/layer/tile/GridLayer.js +104 -134
- package/src/layer/tile/TileLayer.js +35 -43
- package/src/layer/tile/WMSTileLayer.js +26 -24
- package/src/layer/vector/Canvas.js +3 -5
- package/src/layer/vector/Circle.js +5 -2
- package/src/layer/vector/CircleMarker.js +17 -6
- package/src/layer/vector/Path.DashAnimation.js +1 -2
- package/src/layer/vector/Path.js +30 -21
- package/src/layer/vector/Polygon.js +28 -5
- package/src/layer/vector/Polyline.js +26 -7
- package/src/layer/vector/Renderer.getRenderer.js +17 -17
- package/src/layer/vector/SVG.js +5 -5
- package/src/map/Map.Rotation.js +19 -11
- package/src/map/Map.js +163 -154
- package/src/map/handler/BoxZoomHandler.js +9 -8
- package/src/map/handler/DisplaceHandler.js +6 -8
- package/src/map/handler/DragHandler.js +26 -29
- package/src/map/handler/KeyboardHandler.js +44 -50
- package/src/map/handler/PinchZoomHandler.js +16 -5
- package/src/map/handler/ScrollWheelZoomHandler.js +6 -4
- package/src/map/handler/TapHoldHandler.js +15 -4
- package/src/map/index.js +1 -1
- package/src/maplair.css +148 -98
- package/dist/esm/core/Browser.js +0 -100
- package/dist/esm/core/Browser.js.map +0 -1
- package/dist/images/layers.svg +0 -1
- package/dist/images/marker-icon.svg +0 -1
- package/dist/images/marker-shadow.svg +0 -1
- package/src/core/Browser.js +0 -110
- package/src/images/layers.svg +0 -1
- package/src/images/marker-icon.svg +0 -1
- package/src/images/marker-shadow.svg +0 -1
|
@@ -45,12 +45,10 @@ import {Bounds} from '../geometry/Bounds.js';
|
|
|
45
45
|
*/
|
|
46
46
|
export class BlanketOverlay extends Layer {
|
|
47
47
|
|
|
48
|
-
static {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
});
|
|
53
|
-
}
|
|
48
|
+
static defaultOptions = {
|
|
49
|
+
padding: 0.1,
|
|
50
|
+
continuous: false,
|
|
51
|
+
};
|
|
54
52
|
|
|
55
53
|
/**
|
|
56
54
|
* @param {BlanketOverlayOptions} [options]
|
|
@@ -97,11 +95,9 @@ export class BlanketOverlay extends Layer {
|
|
|
97
95
|
zoom: this._onZoom,
|
|
98
96
|
moveend: this._onMoveEnd,
|
|
99
97
|
resize: this._resizeContainer,
|
|
100
|
-
zoomend: this._onZoomEnd
|
|
98
|
+
zoomend: this._onZoomEnd,
|
|
99
|
+
zoomanim: this._onAnimZoom
|
|
101
100
|
};
|
|
102
|
-
if (this._zoomAnimated) {
|
|
103
|
-
events.zoomanim = this._onAnimZoom;
|
|
104
|
-
}
|
|
105
101
|
if (this.options.continuous) {
|
|
106
102
|
events.move = this._onMoveEnd;
|
|
107
103
|
}
|
package/src/layer/DivOverlay.js
CHANGED
|
@@ -81,16 +81,14 @@ const layerDivOverlayMethods = {
|
|
|
81
81
|
*/
|
|
82
82
|
export class DivOverlay extends Layer {
|
|
83
83
|
|
|
84
|
-
static {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
});
|
|
93
|
-
}
|
|
84
|
+
static defaultOptions = {
|
|
85
|
+
interactive: false,
|
|
86
|
+
offset: [0, 0],
|
|
87
|
+
className: '',
|
|
88
|
+
pane: undefined,
|
|
89
|
+
overflow: false,
|
|
90
|
+
content: ''
|
|
91
|
+
};
|
|
94
92
|
|
|
95
93
|
/**
|
|
96
94
|
* Instantiates an overlay given an optional `options` object that describes its
|
|
@@ -181,14 +179,12 @@ export class DivOverlay extends Layer {
|
|
|
181
179
|
* @param {MaplairMap} map
|
|
182
180
|
*/
|
|
183
181
|
onAdd(map) {
|
|
184
|
-
this._zoomAnimated = map._zoomAnimated;
|
|
185
|
-
|
|
186
182
|
if (!this._container) {
|
|
187
183
|
this._initLayout();
|
|
188
184
|
}
|
|
189
185
|
|
|
190
186
|
if (map._fadeAnimated) {
|
|
191
|
-
this._container.style.opacity = 0;
|
|
187
|
+
this._container.style.opacity = '0';
|
|
192
188
|
}
|
|
193
189
|
|
|
194
190
|
clearTimeout(this._removeTimeout);
|
|
@@ -205,7 +201,7 @@ export class DivOverlay extends Layer {
|
|
|
205
201
|
this.update();
|
|
206
202
|
|
|
207
203
|
if (map._fadeAnimated) {
|
|
208
|
-
this._container.style.opacity = 1;
|
|
204
|
+
this._container.style.opacity = '1';
|
|
209
205
|
}
|
|
210
206
|
|
|
211
207
|
// A popover is shown on top already, re-showing it would skip the fade animation
|
|
@@ -230,7 +226,7 @@ export class DivOverlay extends Layer {
|
|
|
230
226
|
}
|
|
231
227
|
|
|
232
228
|
if (map._fadeAnimated) {
|
|
233
|
-
this._container.style.opacity = 0;
|
|
229
|
+
this._container.style.opacity = '0';
|
|
234
230
|
this._removeTimeout = setTimeout(() => this._container.remove(), 200);
|
|
235
231
|
} else {
|
|
236
232
|
this._container.remove();
|
|
@@ -330,12 +326,10 @@ export class DivOverlay extends Layer {
|
|
|
330
326
|
getEvents() {
|
|
331
327
|
const events = {
|
|
332
328
|
zoom: this._updatePosition,
|
|
333
|
-
viewreset: this._updatePosition
|
|
329
|
+
viewreset: this._updatePosition,
|
|
330
|
+
zoomanim: this._animateZoom
|
|
334
331
|
};
|
|
335
332
|
|
|
336
|
-
if (this._zoomAnimated) {
|
|
337
|
-
events.zoomanim = this._animateZoom;
|
|
338
|
-
}
|
|
339
333
|
if (this.options.overflow) {
|
|
340
334
|
events.move = this._updatePosition;
|
|
341
335
|
}
|
|
@@ -450,14 +444,9 @@ export class DivOverlay extends Layer {
|
|
|
450
444
|
if (!this._map) { return; }
|
|
451
445
|
|
|
452
446
|
const pos = this._map.latLngToLayerPoint(this._latlng),
|
|
453
|
-
|
|
454
|
-
let offset = new Point(this.options.offset);
|
|
447
|
+
offset = Point.from(this.options.offset);
|
|
455
448
|
|
|
456
|
-
|
|
457
|
-
this._setContainerPosition(pos.add(anchor));
|
|
458
|
-
} else {
|
|
459
|
-
offset = offset.add(pos).add(anchor);
|
|
460
|
-
}
|
|
449
|
+
this._setContainerPosition(pos.add(this._getAnchor()));
|
|
461
450
|
|
|
462
451
|
const bottom = this._containerBottom = -offset.y,
|
|
463
452
|
left = this._containerLeft = -Math.round(this._containerWidth / 2) + offset.x;
|
package/src/layer/GeoJSON.js
CHANGED
|
@@ -1,13 +1,9 @@
|
|
|
1
|
-
import {LayerGroup} from './LayerGroup.js';
|
|
2
1
|
import {FeatureGroup} from './FeatureGroup.js';
|
|
3
|
-
import * as Util from '../core/Util.js';
|
|
4
2
|
import {Marker} from './marker/Marker.js';
|
|
5
|
-
import {Circle} from './vector/Circle.js';
|
|
6
|
-
import {CircleMarker} from './vector/CircleMarker.js';
|
|
7
3
|
import {Polyline} from './vector/Polyline.js';
|
|
8
4
|
import {Polygon} from './vector/Polygon.js';
|
|
9
5
|
import {LatLng} from '../geo/LatLng.js';
|
|
10
|
-
import
|
|
6
|
+
import {latLngToCoords, latLngsToCoords, getFeature, asFeature} from './GeoJSONUtil.js';
|
|
11
7
|
|
|
12
8
|
/** @import {Feature, FeatureCollection, GeoJSON as GeoJSONData, GeoJsonObject, Geometry} from 'geojson' */
|
|
13
9
|
/** @import {Layer, InteractiveLayerOptions} from './Layer.js' */
|
|
@@ -232,6 +228,8 @@ export class GeoJSON extends FeatureGroup {
|
|
|
232
228
|
}, options);
|
|
233
229
|
|
|
234
230
|
if (geoLayer) {
|
|
231
|
+
// so toGeoJSON exports MultiPoint and GeometryCollection members with their own type
|
|
232
|
+
geoLayer.feature = GeoJSON.asFeature(g);
|
|
235
233
|
layers.push(geoLayer);
|
|
236
234
|
}
|
|
237
235
|
}
|
|
@@ -292,10 +290,7 @@ export class GeoJSON extends FeatureGroup {
|
|
|
292
290
|
* @returns {number[]}
|
|
293
291
|
*/
|
|
294
292
|
static latLngToCoords(latlng, precision) {
|
|
295
|
-
|
|
296
|
-
return latlng.alt !== undefined ?
|
|
297
|
-
[Util.formatNum(latlng.lng, precision), Util.formatNum(latlng.lat, precision), Util.formatNum(latlng.alt, precision)] :
|
|
298
|
-
[Util.formatNum(latlng.lng, precision), Util.formatNum(latlng.lat, precision)];
|
|
293
|
+
return latLngToCoords(latlng, precision);
|
|
299
294
|
}
|
|
300
295
|
|
|
301
296
|
/**
|
|
@@ -310,16 +305,7 @@ export class GeoJSON extends FeatureGroup {
|
|
|
310
305
|
* @returns {any[]}
|
|
311
306
|
*/
|
|
312
307
|
static latLngsToCoords(latlngs, levelsDeep, close, precision) {
|
|
313
|
-
|
|
314
|
-
const coords = latlngs.map(latlng => (levelsDeep ?
|
|
315
|
-
GeoJSON.latLngsToCoords(latlng, LineUtil.isFlat(latlng) ? 0 : levelsDeep - 1, close, precision) :
|
|
316
|
-
GeoJSON.latLngToCoords(latlng, precision)));
|
|
317
|
-
|
|
318
|
-
if (!levelsDeep && close && coords.length > 0) {
|
|
319
|
-
coords.push(coords[0].slice());
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
return coords;
|
|
308
|
+
return latLngsToCoords(latlngs, levelsDeep, close, precision);
|
|
323
309
|
}
|
|
324
310
|
|
|
325
311
|
/**
|
|
@@ -329,9 +315,7 @@ export class GeoJSON extends FeatureGroup {
|
|
|
329
315
|
* @returns {Feature}
|
|
330
316
|
*/
|
|
331
317
|
static getFeature(layer, newGeometry) {
|
|
332
|
-
return layer
|
|
333
|
-
{...layer.feature, geometry: newGeometry} :
|
|
334
|
-
GeoJSON.asFeature(newGeometry);
|
|
318
|
+
return getFeature(layer, newGeometry);
|
|
335
319
|
}
|
|
336
320
|
|
|
337
321
|
/**
|
|
@@ -340,189 +324,7 @@ export class GeoJSON extends FeatureGroup {
|
|
|
340
324
|
* @returns {Feature|FeatureCollection}
|
|
341
325
|
*/
|
|
342
326
|
static asFeature(geojson) {
|
|
343
|
-
|
|
344
|
-
return geojson;
|
|
345
|
-
}
|
|
346
|
-
|
|
347
|
-
return {
|
|
348
|
-
type: 'Feature',
|
|
349
|
-
properties: {},
|
|
350
|
-
geometry: geojson
|
|
351
|
-
};
|
|
327
|
+
return asFeature(geojson);
|
|
352
328
|
}
|
|
353
329
|
|
|
354
330
|
}
|
|
355
|
-
|
|
356
|
-
/**
|
|
357
|
-
* Methods of `Marker` (and `CircleMarker`, `Circle`) for GeoJSON.
|
|
358
|
-
* @lends Marker.prototype
|
|
359
|
-
*/
|
|
360
|
-
const PointToGeoJSON = {
|
|
361
|
-
/**
|
|
362
|
-
* Coordinates values are rounded with [`formatNum`](#util-formatnum) to the
|
|
363
|
-
* given `precision`. Returns a [`GeoJSON`](https://en.wikipedia.org/wiki/GeoJSON)
|
|
364
|
-
* representation of the marker (as a GeoJSON `Point` Feature).
|
|
365
|
-
* @group Other methods
|
|
366
|
-
* @param {number|false} [precision]
|
|
367
|
-
* @returns {Feature}
|
|
368
|
-
*/
|
|
369
|
-
toGeoJSON(precision) {
|
|
370
|
-
return GeoJSON.getFeature(this, {
|
|
371
|
-
type: 'Point',
|
|
372
|
-
coordinates: GeoJSON.latLngToCoords(this.getLatLng(), precision)
|
|
373
|
-
});
|
|
374
|
-
}
|
|
375
|
-
};
|
|
376
|
-
/** @typedef {typeof PointToGeoJSON} PointToGeoJSONMethods */
|
|
377
|
-
|
|
378
|
-
/**
|
|
379
|
-
* Methods of `CircleMarker` (and `Circle`) for GeoJSON: `toGeoJSON(precision?)`
|
|
380
|
-
* returns a [`GeoJSON`](https://en.wikipedia.org/wiki/GeoJSON) representation of the
|
|
381
|
-
* circle marker (as a GeoJSON `Point` Feature), with the coordinates values rounded
|
|
382
|
-
* with [`formatNum`](#util-formatnum) function with given `precision`.
|
|
383
|
-
* @typedef {object} CircleMarkerToGeoJSONMethods
|
|
384
|
-
* @extends PointToGeoJSONMethods
|
|
385
|
-
* @lends CircleMarker
|
|
386
|
-
*/
|
|
387
|
-
|
|
388
|
-
Marker.include(PointToGeoJSON);
|
|
389
|
-
Circle.include(PointToGeoJSON);
|
|
390
|
-
CircleMarker.include(PointToGeoJSON);
|
|
391
|
-
|
|
392
|
-
/**
|
|
393
|
-
* Methods of `Polyline` for GeoJSON.
|
|
394
|
-
* @lends Polyline.prototype
|
|
395
|
-
*/
|
|
396
|
-
const polylineToGeoJSON = {
|
|
397
|
-
/**
|
|
398
|
-
* Coordinates values are rounded with [`formatNum`](#util-formatnum) to the
|
|
399
|
-
* given `precision`. Returns a [`GeoJSON`](https://en.wikipedia.org/wiki/GeoJSON)
|
|
400
|
-
* representation of the polyline (as a GeoJSON `LineString` or `MultiLineString`
|
|
401
|
-
* Feature).
|
|
402
|
-
* @param {number|false} [precision]
|
|
403
|
-
* @returns {Feature}
|
|
404
|
-
*/
|
|
405
|
-
toGeoJSON(precision) {
|
|
406
|
-
const multi = !LineUtil.isFlat(this._latlngs);
|
|
407
|
-
|
|
408
|
-
const coords = GeoJSON.latLngsToCoords(this._latlngs, multi ? 1 : 0, false, precision);
|
|
409
|
-
|
|
410
|
-
return GeoJSON.getFeature(this, {
|
|
411
|
-
type: `${multi ? 'Multi' : ''}LineString`,
|
|
412
|
-
coordinates: coords
|
|
413
|
-
});
|
|
414
|
-
}
|
|
415
|
-
};
|
|
416
|
-
/** @typedef {typeof polylineToGeoJSON} PolylineToGeoJSONMethods */
|
|
417
|
-
|
|
418
|
-
Polyline.include(polylineToGeoJSON);
|
|
419
|
-
|
|
420
|
-
/**
|
|
421
|
-
* Methods of `Polygon` for GeoJSON.
|
|
422
|
-
* @lends Polygon.prototype
|
|
423
|
-
*/
|
|
424
|
-
const polygonToGeoJSON = {
|
|
425
|
-
/**
|
|
426
|
-
* Coordinates values are rounded with [`formatNum`](#util-formatnum) to the
|
|
427
|
-
* given `precision`. Returns a [`GeoJSON`](https://en.wikipedia.org/wiki/GeoJSON)
|
|
428
|
-
* representation of the polygon (as a GeoJSON `Polygon` or `MultiPolygon` Feature).
|
|
429
|
-
* @param {number|false} [precision]
|
|
430
|
-
* @returns {Feature}
|
|
431
|
-
*/
|
|
432
|
-
toGeoJSON(precision) {
|
|
433
|
-
const holes = !LineUtil.isFlat(this._latlngs),
|
|
434
|
-
multi = holes && !LineUtil.isFlat(this._latlngs[0]);
|
|
435
|
-
|
|
436
|
-
let coords = GeoJSON.latLngsToCoords(this._latlngs, multi ? 2 : holes ? 1 : 0, true, precision);
|
|
437
|
-
|
|
438
|
-
if (!holes) {
|
|
439
|
-
coords = [coords];
|
|
440
|
-
}
|
|
441
|
-
|
|
442
|
-
return GeoJSON.getFeature(this, {
|
|
443
|
-
type: `${multi ? 'Multi' : ''}Polygon`,
|
|
444
|
-
coordinates: coords
|
|
445
|
-
});
|
|
446
|
-
}
|
|
447
|
-
};
|
|
448
|
-
/** @typedef {typeof polygonToGeoJSON} PolygonToGeoJSONMethods */
|
|
449
|
-
|
|
450
|
-
Polygon.include(polygonToGeoJSON);
|
|
451
|
-
|
|
452
|
-
/**
|
|
453
|
-
* Methods of `LayerGroup` for GeoJSON.
|
|
454
|
-
* @lends LayerGroup.prototype
|
|
455
|
-
*/
|
|
456
|
-
const layerGroupToGeoJSON = {
|
|
457
|
-
/**
|
|
458
|
-
* Returns a GeoJSON `MultiPoint` Feature of the points of the group, used by
|
|
459
|
-
* `toGeoJSON()`.
|
|
460
|
-
* @internal
|
|
461
|
-
* @param {number|false} [precision]
|
|
462
|
-
* @returns {Feature}
|
|
463
|
-
*/
|
|
464
|
-
toMultiPoint(precision) {
|
|
465
|
-
const coords = [];
|
|
466
|
-
|
|
467
|
-
this.eachLayer((layer) => {
|
|
468
|
-
coords.push(layer.toGeoJSON(precision).geometry.coordinates);
|
|
469
|
-
});
|
|
470
|
-
|
|
471
|
-
return GeoJSON.getFeature(this, {
|
|
472
|
-
type: 'MultiPoint',
|
|
473
|
-
coordinates: coords
|
|
474
|
-
});
|
|
475
|
-
},
|
|
476
|
-
|
|
477
|
-
/**
|
|
478
|
-
* Coordinates values are rounded with [`formatNum`](#util-formatnum) to the
|
|
479
|
-
* given `precision`. Returns a [`GeoJSON`](https://en.wikipedia.org/wiki/GeoJSON)
|
|
480
|
-
* representation of the layer group (as a GeoJSON `FeatureCollection`,
|
|
481
|
-
* `GeometryCollection`, or `MultiPoint`).
|
|
482
|
-
* @param {number|false} [precision]
|
|
483
|
-
* @returns {Feature|FeatureCollection}
|
|
484
|
-
*/
|
|
485
|
-
toGeoJSON(precision) {
|
|
486
|
-
|
|
487
|
-
const type = this.feature?.geometry?.type;
|
|
488
|
-
|
|
489
|
-
if (type === 'MultiPoint') {
|
|
490
|
-
return this.toMultiPoint(precision);
|
|
491
|
-
}
|
|
492
|
-
|
|
493
|
-
const isGeometryCollection = type === 'GeometryCollection',
|
|
494
|
-
jsons = [];
|
|
495
|
-
|
|
496
|
-
this.eachLayer((layer) => {
|
|
497
|
-
if (layer.toGeoJSON) {
|
|
498
|
-
const json = layer.toGeoJSON(precision);
|
|
499
|
-
if (isGeometryCollection) {
|
|
500
|
-
jsons.push(json.geometry);
|
|
501
|
-
} else {
|
|
502
|
-
const feature = GeoJSON.asFeature(json);
|
|
503
|
-
// Squash nested feature collections
|
|
504
|
-
if (feature.type === 'FeatureCollection') {
|
|
505
|
-
jsons.push(...feature.features);
|
|
506
|
-
} else {
|
|
507
|
-
jsons.push(feature);
|
|
508
|
-
}
|
|
509
|
-
}
|
|
510
|
-
}
|
|
511
|
-
});
|
|
512
|
-
|
|
513
|
-
if (isGeometryCollection) {
|
|
514
|
-
return GeoJSON.getFeature(this, {
|
|
515
|
-
geometries: jsons,
|
|
516
|
-
type: 'GeometryCollection'
|
|
517
|
-
});
|
|
518
|
-
}
|
|
519
|
-
|
|
520
|
-
return {
|
|
521
|
-
type: 'FeatureCollection',
|
|
522
|
-
features: jsons
|
|
523
|
-
};
|
|
524
|
-
}
|
|
525
|
-
};
|
|
526
|
-
/** @typedef {typeof layerGroupToGeoJSON} LayerGroupToGeoJSONMethods */
|
|
527
|
-
|
|
528
|
-
LayerGroup.include(layerGroupToGeoJSON);
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import * as Util from '../core/Util.js';
|
|
2
|
+
import {LatLng} from '../geo/LatLng.js';
|
|
3
|
+
import * as LineUtil from '../geometry/LineUtil.js';
|
|
4
|
+
|
|
5
|
+
/** @import {Feature, FeatureCollection, GeoJsonObject, Geometry} from 'geojson' */
|
|
6
|
+
/** @import {Layer} from './Layer.js' */
|
|
7
|
+
/** @import {LatLngExpression} from '../geo/LatLng.js' */
|
|
8
|
+
|
|
9
|
+
// Shared by `GeoJSON` and the `toGeoJSON` methods of the layers it creates, which can't import `GeoJSON.js` without a cycle.
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* See `GeoJSON.latLngToCoords()`.
|
|
13
|
+
* @param {LatLngExpression} latlng
|
|
14
|
+
* @param {number|false} [precision]
|
|
15
|
+
* @returns {number[]}
|
|
16
|
+
*/
|
|
17
|
+
export function latLngToCoords(latlng, precision) {
|
|
18
|
+
latlng = LatLng.from(latlng);
|
|
19
|
+
return latlng.alt !== undefined ?
|
|
20
|
+
[Util.formatNum(latlng.lng, precision), Util.formatNum(latlng.lat, precision), Util.formatNum(latlng.alt, precision)] :
|
|
21
|
+
[Util.formatNum(latlng.lng, precision), Util.formatNum(latlng.lat, precision)];
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* See `GeoJSON.latLngsToCoords()`.
|
|
26
|
+
* @param {any[]} latlngs
|
|
27
|
+
* @param {number} [levelsDeep]
|
|
28
|
+
* @param {boolean} [close]
|
|
29
|
+
* @param {number|false} [precision]
|
|
30
|
+
* @returns {any[]}
|
|
31
|
+
*/
|
|
32
|
+
export function latLngsToCoords(latlngs, levelsDeep, close, precision) {
|
|
33
|
+
// Check for flat arrays required to ensure unbalanced arrays are correctly converted in recursion
|
|
34
|
+
const coords = latlngs.map(latlng => (levelsDeep ?
|
|
35
|
+
latLngsToCoords(latlng, LineUtil.isFlat(latlng) ? 0 : levelsDeep - 1, close, precision) :
|
|
36
|
+
latLngToCoords(latlng, precision)));
|
|
37
|
+
|
|
38
|
+
if (!levelsDeep && close && coords.length > 0) {
|
|
39
|
+
coords.push(coords[0].slice());
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return coords;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* See `GeoJSON.getFeature()`.
|
|
47
|
+
* @param {Layer} layer
|
|
48
|
+
* @param {Geometry} newGeometry
|
|
49
|
+
* @returns {Feature}
|
|
50
|
+
*/
|
|
51
|
+
export function getFeature(layer, newGeometry) {
|
|
52
|
+
return layer.feature ?
|
|
53
|
+
{...layer.feature, geometry: newGeometry} :
|
|
54
|
+
asFeature(newGeometry);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* See `GeoJSON.asFeature()`.
|
|
59
|
+
* @param {GeoJsonObject} geojson
|
|
60
|
+
* @returns {Feature|FeatureCollection}
|
|
61
|
+
*/
|
|
62
|
+
export function asFeature(geojson) {
|
|
63
|
+
if (geojson.type === 'Feature' || geojson.type === 'FeatureCollection') {
|
|
64
|
+
return geojson;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
return {
|
|
68
|
+
type: 'Feature',
|
|
69
|
+
properties: {},
|
|
70
|
+
geometry: geojson
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* The GeoJSON `Point` Feature of a layer with `getLatLng()`, for its `toGeoJSON()`.
|
|
76
|
+
* @param {Layer & {getLatLng(): LatLng}} layer
|
|
77
|
+
* @param {number|false} [precision]
|
|
78
|
+
* @returns {Feature}
|
|
79
|
+
*/
|
|
80
|
+
export function pointToGeoJSON(layer, precision) {
|
|
81
|
+
return getFeature(layer, {
|
|
82
|
+
type: 'Point',
|
|
83
|
+
coordinates: latLngToCoords(layer.getLatLng(), precision)
|
|
84
|
+
});
|
|
85
|
+
}
|
package/src/layer/HeatLayer.js
CHANGED
|
@@ -39,17 +39,15 @@ import * as Util from '../core/Util.js';
|
|
|
39
39
|
*/
|
|
40
40
|
export class HeatLayer extends BlanketOverlay {
|
|
41
41
|
|
|
42
|
-
static {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
});
|
|
52
|
-
}
|
|
42
|
+
static defaultOptions = {
|
|
43
|
+
radius: 25,
|
|
44
|
+
blur: 15,
|
|
45
|
+
max: 1,
|
|
46
|
+
maxZoom: undefined,
|
|
47
|
+
minOpacity: 0.05,
|
|
48
|
+
gradient: {0.4: 'blue', 0.6: 'cyan', 0.7: 'lime', 0.8: 'yellow', 1: 'red'},
|
|
49
|
+
pane: 'overlayPane'
|
|
50
|
+
};
|
|
53
51
|
|
|
54
52
|
/**
|
|
55
53
|
* Creates a heatmap of the given points: `LatLng`s or arrays
|
|
@@ -58,19 +58,17 @@ import * as DomUtil from '../dom/DomUtil.js';
|
|
|
58
58
|
*/
|
|
59
59
|
export class ImageOverlay extends Layer {
|
|
60
60
|
|
|
61
|
-
static {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
});
|
|
73
|
-
}
|
|
61
|
+
static defaultOptions = {
|
|
62
|
+
opacity: 1,
|
|
63
|
+
alt: '',
|
|
64
|
+
interactive: false,
|
|
65
|
+
crossOrigin: false,
|
|
66
|
+
errorOverlayUrl: '',
|
|
67
|
+
zIndex: 1,
|
|
68
|
+
className: '',
|
|
69
|
+
pixelated: false,
|
|
70
|
+
decoding: 'auto'
|
|
71
|
+
};
|
|
74
72
|
|
|
75
73
|
/**
|
|
76
74
|
* Instantiates an image overlay object given the URL of the image (or an image
|
|
@@ -214,16 +212,11 @@ export class ImageOverlay extends Layer {
|
|
|
214
212
|
* @returns {Record<string, EventListener>}
|
|
215
213
|
*/
|
|
216
214
|
getEvents() {
|
|
217
|
-
|
|
215
|
+
return {
|
|
218
216
|
zoom: this._reset,
|
|
219
|
-
viewreset: this._reset
|
|
217
|
+
viewreset: this._reset,
|
|
218
|
+
zoomanim: this._animateZoom
|
|
220
219
|
};
|
|
221
|
-
|
|
222
|
-
if (this._zoomAnimated) {
|
|
223
|
-
events.zoomanim = this._animateZoom;
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
return events;
|
|
227
220
|
}
|
|
228
221
|
|
|
229
222
|
/**
|
|
@@ -257,16 +250,12 @@ export class ImageOverlay extends Layer {
|
|
|
257
250
|
}
|
|
258
251
|
|
|
259
252
|
_initImage() {
|
|
260
|
-
const wasElementSupplied = this._url
|
|
253
|
+
const wasElementSupplied = this._url instanceof HTMLImageElement;
|
|
261
254
|
const img = this._image = wasElementSupplied ? this._url : DomUtil.create('img');
|
|
262
255
|
|
|
263
|
-
img.classList.add('maplair-image-layer');
|
|
264
|
-
if (this._zoomAnimated) { img.classList.add('maplair-zoom-animated'); }
|
|
256
|
+
img.classList.add('maplair-image-layer', 'maplair-zoom-animated');
|
|
265
257
|
if (this.options.className) { img.classList.add(...Util.splitWords(this.options.className)); }
|
|
266
258
|
|
|
267
|
-
img.onselectstart = Util.falseFn;
|
|
268
|
-
img.onpointermove = Util.falseFn;
|
|
269
|
-
|
|
270
259
|
img.onload = this.fire.bind(this, 'load');
|
|
271
260
|
img.onerror = this._overlayOnError.bind(this);
|
|
272
261
|
|
|
@@ -291,7 +280,7 @@ export class ImageOverlay extends Layer {
|
|
|
291
280
|
|
|
292
281
|
_animateZoom(e) {
|
|
293
282
|
const scale = this._map.getZoomScale(e.zoom),
|
|
294
|
-
offset = this._map.
|
|
283
|
+
offset = this._map._latLngToNewLayerPoint(this._bounds.getNorthWest(), e.zoom, e.center);
|
|
295
284
|
|
|
296
285
|
DomUtil.setTransform(this._image, offset, scale);
|
|
297
286
|
}
|
|
@@ -310,12 +299,12 @@ export class ImageOverlay extends Layer {
|
|
|
310
299
|
}
|
|
311
300
|
|
|
312
301
|
_updateOpacity() {
|
|
313
|
-
this._image.style.opacity = this.options.opacity
|
|
302
|
+
this._image.style.opacity = `${this.options.opacity}`;
|
|
314
303
|
}
|
|
315
304
|
|
|
316
305
|
_updateZIndex() {
|
|
317
306
|
if (this._image && this.options.zIndex !== undefined && this.options.zIndex !== null) {
|
|
318
|
-
this._image.style.zIndex = this.options.zIndex
|
|
307
|
+
this._image.style.zIndex = `${this.options.zIndex}`;
|
|
319
308
|
}
|
|
320
309
|
}
|
|
321
310
|
|
package/src/layer/Layer.js
CHANGED
|
@@ -249,14 +249,12 @@ const mapLayerMethods = {
|
|
|
249
249
|
*/
|
|
250
250
|
export class Layer extends Evented {
|
|
251
251
|
|
|
252
|
-
static {
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
});
|
|
259
|
-
}
|
|
252
|
+
static defaultOptions = {
|
|
253
|
+
pane: 'overlayPane',
|
|
254
|
+
attribution: null,
|
|
255
|
+
attributionOrder: 0,
|
|
256
|
+
bubblingPointerEvents: true
|
|
257
|
+
};
|
|
260
258
|
|
|
261
259
|
/**
|
|
262
260
|
* Adds the layer to the given map or layer group.
|
|
@@ -354,9 +352,9 @@ export class Layer extends Evented {
|
|
|
354
352
|
*/
|
|
355
353
|
setAttribution(attribution) {
|
|
356
354
|
const control = this._map?.attributionControl;
|
|
357
|
-
control?.
|
|
355
|
+
control?._removeLayer({layer: this});
|
|
358
356
|
Util.setOptions(this, {attribution});
|
|
359
|
-
control?.
|
|
357
|
+
control?._addLayer({layer: this});
|
|
360
358
|
return this;
|
|
361
359
|
}
|
|
362
360
|
|
package/src/layer/LayerGroup.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
|
|
2
2
|
import {Layer} from './Layer.js';
|
|
3
3
|
import * as Util from '../core/Util.js';
|
|
4
|
+
import {getFeature, asFeature} from './GeoJSONUtil.js';
|
|
5
|
+
/** @import {Feature, FeatureCollection} from 'geojson' */
|
|
4
6
|
/** @import {InteractiveLayerOptions} from './Layer.js' */
|
|
5
7
|
/** @import {MaplairMap} from '../map/Map.js' */
|
|
6
8
|
|
|
@@ -157,4 +159,73 @@ export class LayerGroup extends Layer {
|
|
|
157
159
|
getLayerId(layer) {
|
|
158
160
|
return Util.stamp(layer);
|
|
159
161
|
}
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* Returns a GeoJSON `MultiPoint` Feature of the points of the group, used by
|
|
165
|
+
* `toGeoJSON()`.
|
|
166
|
+
* @internal
|
|
167
|
+
* @param {number|false} [precision]
|
|
168
|
+
* @returns {Feature}
|
|
169
|
+
*/
|
|
170
|
+
toMultiPoint(precision) {
|
|
171
|
+
const coords = [];
|
|
172
|
+
|
|
173
|
+
this.eachLayer((layer) => {
|
|
174
|
+
coords.push(layer.toGeoJSON(precision).geometry.coordinates);
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
return getFeature(this, {
|
|
178
|
+
type: 'MultiPoint',
|
|
179
|
+
coordinates: coords
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* Coordinates values are rounded with [`formatNum`](#util-formatnum) to the
|
|
185
|
+
* given `precision`. Returns a [`GeoJSON`](https://en.wikipedia.org/wiki/GeoJSON)
|
|
186
|
+
* representation of the layer group (as a GeoJSON `FeatureCollection`,
|
|
187
|
+
* `GeometryCollection`, or `MultiPoint`).
|
|
188
|
+
* @param {number|false} [precision]
|
|
189
|
+
* @returns {Feature|FeatureCollection}
|
|
190
|
+
*/
|
|
191
|
+
toGeoJSON(precision) {
|
|
192
|
+
|
|
193
|
+
const type = this.feature?.geometry?.type;
|
|
194
|
+
|
|
195
|
+
if (type === 'MultiPoint') {
|
|
196
|
+
return this.toMultiPoint(precision);
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
const isGeometryCollection = type === 'GeometryCollection',
|
|
200
|
+
jsons = [];
|
|
201
|
+
|
|
202
|
+
this.eachLayer((layer) => {
|
|
203
|
+
if (layer.toGeoJSON) {
|
|
204
|
+
const json = layer.toGeoJSON(precision);
|
|
205
|
+
if (isGeometryCollection) {
|
|
206
|
+
jsons.push(json.geometry);
|
|
207
|
+
} else {
|
|
208
|
+
const feature = asFeature(json);
|
|
209
|
+
// Squash nested feature collections
|
|
210
|
+
if (feature.type === 'FeatureCollection') {
|
|
211
|
+
jsons.push(...feature.features);
|
|
212
|
+
} else {
|
|
213
|
+
jsons.push(feature);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
if (isGeometryCollection) {
|
|
220
|
+
return getFeature(this, {
|
|
221
|
+
geometries: jsons,
|
|
222
|
+
type: 'GeometryCollection'
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
return {
|
|
227
|
+
type: 'FeatureCollection',
|
|
228
|
+
features: jsons
|
|
229
|
+
};
|
|
230
|
+
}
|
|
160
231
|
}
|