maplair 4.0.0 → 4.2.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 +178 -0
- package/dist/esm/Maplair.js +18 -17
- package/dist/esm/Maplair.js.map +1 -1
- package/dist/esm/_virtual/_rolldown/runtime.js +1 -2
- package/dist/esm/control/AttributionControl.js +25 -16
- package/dist/esm/control/AttributionControl.js.map +1 -1
- package/dist/esm/control/ButtonControl.js +10 -13
- package/dist/esm/control/ButtonControl.js.map +1 -1
- package/dist/esm/control/ContextMenu.js +2 -5
- package/dist/esm/control/ContextMenu.js.map +1 -1
- package/dist/esm/control/Control.js +10 -18
- package/dist/esm/control/Control.js.map +1 -1
- package/dist/esm/control/FullscreenControl.js +6 -9
- package/dist/esm/control/FullscreenControl.js.map +1 -1
- package/dist/esm/control/LayersControl.js +170 -65
- package/dist/esm/control/LayersControl.js.map +1 -1
- package/dist/esm/control/LegendControl.js +8 -11
- package/dist/esm/control/LegendControl.js.map +1 -1
- package/dist/esm/control/MiniMapControl.js +15 -18
- package/dist/esm/control/MiniMapControl.js.map +1 -1
- package/dist/esm/control/RotateControl.js +2 -5
- package/dist/esm/control/RotateControl.js.map +1 -1
- package/dist/esm/control/ScaleControl.js +8 -11
- package/dist/esm/control/ScaleControl.js.map +1 -1
- package/dist/esm/control/SearchControl.js +100 -19
- package/dist/esm/control/SearchControl.js.map +1 -1
- package/dist/esm/control/SideBySideControl.js +2 -5
- package/dist/esm/control/SideBySideControl.js.map +1 -1
- package/dist/esm/control/TextControl.js +6 -9
- package/dist/esm/control/TextControl.js.map +1 -1
- package/dist/esm/control/TimeControl.js +407 -0
- package/dist/esm/control/TimeControl.js.map +1 -0
- package/dist/esm/control/ZoomControl.js +23 -36
- package/dist/esm/control/ZoomControl.js.map +1 -1
- package/dist/esm/core/Class.js +28 -44
- package/dist/esm/core/Class.js.map +1 -1
- package/dist/esm/core/Events.js +22 -10
- package/dist/esm/core/Events.js.map +1 -1
- package/dist/esm/core/Handler.js +23 -14
- package/dist/esm/core/Handler.js.map +1 -1
- package/dist/esm/core/I18n.js +1 -2
- package/dist/esm/core/Util.js +15 -4
- package/dist/esm/core/Util.js.map +1 -1
- package/dist/esm/dom/DomEvent.DoubleTap.js +26 -24
- package/dist/esm/dom/DomEvent.DoubleTap.js.map +1 -1
- package/dist/esm/dom/DomEvent.PointerEvents.js +3 -18
- package/dist/esm/dom/DomEvent.PointerEvents.js.map +1 -1
- package/dist/esm/dom/DomEvent.js +18 -60
- package/dist/esm/dom/DomEvent.js.map +1 -1
- package/dist/esm/dom/DomUtil.js +15 -70
- package/dist/esm/dom/DomUtil.js.map +1 -1
- package/dist/esm/dom/Draggable.js +21 -21
- package/dist/esm/dom/Draggable.js.map +1 -1
- package/dist/esm/dom/PosAnimation.js +4 -27
- package/dist/esm/dom/PosAnimation.js.map +1 -1
- package/dist/esm/geo/LatLng.js +16 -7
- package/dist/esm/geo/LatLng.js.map +1 -1
- package/dist/esm/geo/LatLngBounds.js +9 -15
- package/dist/esm/geo/LatLngBounds.js.map +1 -1
- package/dist/esm/geo/crs/CRS.js +1 -2
- package/dist/esm/geo/crs/EPSG3395.js +5 -6
- package/dist/esm/geo/crs/EPSG3395.js.map +1 -1
- package/dist/esm/geo/crs/EPSG3857.js +5 -6
- package/dist/esm/geo/crs/EPSG3857.js.map +1 -1
- package/dist/esm/geo/crs/EPSG4326.js +4 -5
- package/dist/esm/geo/crs/EPSG4326.js.map +1 -1
- package/dist/esm/geo/crs/EarthCRS.js +3 -4
- package/dist/esm/geo/crs/EarthCRS.js.map +1 -1
- package/dist/esm/geo/crs/SimpleCRS.js +4 -5
- package/dist/esm/geo/crs/SimpleCRS.js.map +1 -1
- package/dist/esm/geo/projection/{Projection.LonLat.js → LonLatProjection.js} +5 -6
- package/dist/esm/geo/projection/LonLatProjection.js.map +1 -0
- package/dist/esm/geo/projection/{Projection.Mercator.js → MercatorProjection.js} +4 -5
- package/dist/esm/geo/projection/MercatorProjection.js.map +1 -0
- package/dist/esm/geo/projection/{Projection.SphericalMercator.js → SphericalMercatorProjection.js} +5 -6
- package/dist/esm/geo/projection/SphericalMercatorProjection.js.map +1 -0
- package/dist/esm/geometry/Bounds.js +10 -14
- package/dist/esm/geometry/Bounds.js.map +1 -1
- package/dist/esm/geometry/LineUtil.js +37 -32
- package/dist/esm/geometry/LineUtil.js.map +1 -1
- package/dist/esm/geometry/Point.js +1 -2
- package/dist/esm/geometry/PolyUtil.js +24 -51
- package/dist/esm/geometry/PolyUtil.js.map +1 -1
- package/dist/esm/geometry/Transformation.js +1 -2
- package/dist/esm/layer/BlanketOverlay.js +7 -10
- package/dist/esm/layer/BlanketOverlay.js.map +1 -1
- package/dist/esm/layer/Classification.js +1 -2
- package/dist/esm/layer/DivOverlay.js +16 -22
- package/dist/esm/layer/DivOverlay.js.map +1 -1
- package/dist/esm/layer/FeatureGroup.js +5 -4
- package/dist/esm/layer/FeatureGroup.js.map +1 -1
- package/dist/esm/layer/GeoJSON.Load.js +1 -2
- package/dist/esm/layer/GeoJSON.js +17 -155
- package/dist/esm/layer/GeoJSON.js.map +1 -1
- package/dist/esm/layer/GeoJSONUtil.js +74 -0
- package/dist/esm/layer/GeoJSONUtil.js.map +1 -0
- package/dist/esm/layer/HeatLayer.js +17 -20
- package/dist/esm/layer/HeatLayer.js.map +1 -1
- package/dist/esm/layer/ImageOverlay.js +22 -29
- package/dist/esm/layer/ImageOverlay.js.map +1 -1
- package/dist/esm/layer/Layer.js +9 -12
- package/dist/esm/layer/Layer.js.map +1 -1
- package/dist/esm/layer/LayerGroup.js +53 -3
- package/dist/esm/layer/LayerGroup.js.map +1 -1
- package/dist/esm/layer/Popup.js +35 -58
- package/dist/esm/layer/Popup.js.map +1 -1
- package/dist/esm/layer/SVGOverlay.js +3 -7
- package/dist/esm/layer/SVGOverlay.js.map +1 -1
- package/dist/esm/layer/Tooltip.js +31 -34
- package/dist/esm/layer/Tooltip.js.map +1 -1
- package/dist/esm/layer/VideoOverlay.js +13 -17
- package/dist/esm/layer/VideoOverlay.js.map +1 -1
- package/dist/esm/layer/marker/DefaultIcon.js +38 -49
- package/dist/esm/layer/marker/DefaultIcon.js.map +1 -1
- package/dist/esm/layer/marker/DivIcon.js +8 -11
- 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 +44 -5
- package/dist/esm/layer/marker/Marker.Drag.js.map +1 -1
- package/dist/esm/layer/marker/Marker.Move.js +5 -8
- package/dist/esm/layer/marker/Marker.Move.js.map +1 -1
- package/dist/esm/layer/marker/Marker.js +115 -47
- package/dist/esm/layer/marker/Marker.js.map +1 -1
- package/dist/esm/layer/marker/MarkerClusterGroup.js +301 -0
- package/dist/esm/layer/marker/MarkerClusterGroup.js.map +1 -0
- package/dist/esm/layer/marker/SvgIcon.js +7 -10
- package/dist/esm/layer/marker/SvgIcon.js.map +1 -1
- package/dist/esm/layer/tile/GridLayer.js +89 -101
- package/dist/esm/layer/tile/GridLayer.js.map +1 -1
- package/dist/esm/layer/tile/TileLayer.js +36 -44
- package/dist/esm/layer/tile/TileLayer.js.map +1 -1
- package/dist/esm/layer/tile/WMSTileLayer.js +33 -27
- package/dist/esm/layer/tile/WMSTileLayer.js.map +1 -1
- package/dist/esm/layer/vector/Canvas.js +8 -17
- package/dist/esm/layer/vector/Canvas.js.map +1 -1
- package/dist/esm/layer/vector/Circle.js +6 -5
- package/dist/esm/layer/vector/Circle.js.map +1 -1
- package/dist/esm/layer/vector/CircleMarker.js +19 -10
- package/dist/esm/layer/vector/CircleMarker.js.map +1 -1
- package/dist/esm/layer/vector/Path.DashAnimation.js +3 -5
- package/dist/esm/layer/vector/Path.DashAnimation.js.map +1 -1
- package/dist/esm/layer/vector/Path.ZoomStyles.js +1 -2
- package/dist/esm/layer/vector/Path.js +28 -22
- package/dist/esm/layer/vector/Path.js.map +1 -1
- package/dist/esm/layer/vector/Polygon.js +22 -7
- package/dist/esm/layer/vector/Polygon.js.map +1 -1
- package/dist/esm/layer/vector/Polyline.Decorations.js +3 -4
- package/dist/esm/layer/vector/Polyline.js +25 -10
- package/dist/esm/layer/vector/Polyline.js.map +1 -1
- package/dist/esm/layer/vector/Rectangle.js +1 -2
- package/dist/esm/layer/vector/Renderer.getRenderer.js +17 -17
- package/dist/esm/layer/vector/Renderer.getRenderer.js.map +1 -1
- package/dist/esm/layer/vector/Renderer.js +1 -2
- package/dist/esm/layer/vector/SVG.js +12 -9
- package/dist/esm/layer/vector/SVG.js.map +1 -1
- package/dist/esm/map/Hash.js +1 -2
- package/dist/esm/map/Map.Rotation.js +41 -22
- package/dist/esm/map/Map.Rotation.js.map +1 -1
- package/dist/esm/map/Map.js +125 -126
- package/dist/esm/map/Map.js.map +1 -1
- package/dist/esm/map/MapSync.js +1 -2
- package/dist/esm/map/handler/BoxZoomHandler.js +25 -47
- package/dist/esm/map/handler/BoxZoomHandler.js.map +1 -1
- package/dist/esm/map/handler/DisplaceHandler.js +7 -10
- package/dist/esm/map/handler/DisplaceHandler.js.map +1 -1
- package/dist/esm/map/handler/DoubleClickZoomHandler.js +1 -2
- package/dist/esm/map/handler/DragHandler.js +20 -21
- package/dist/esm/map/handler/DragHandler.js.map +1 -1
- package/dist/esm/map/handler/KeyboardHandler.js +48 -68
- package/dist/esm/map/handler/KeyboardHandler.js.map +1 -1
- package/dist/esm/map/handler/PinchZoomHandler.js +13 -5
- package/dist/esm/map/handler/PinchZoomHandler.js.map +1 -1
- package/dist/esm/map/handler/ScrollWheelZoomHandler.js +4 -6
- package/dist/esm/map/handler/ScrollWheelZoomHandler.js.map +1 -1
- package/dist/esm/map/handler/TapDragZoomHandler.js +1 -2
- package/dist/esm/map/handler/TapHoldHandler.js +13 -7
- package/dist/esm/map/handler/TapHoldHandler.js.map +1 -1
- package/dist/esm/package.js +2 -3
- package/dist/maplair-global-src.js +6495 -5981
- package/dist/maplair-global-src.js.map +1 -1
- package/dist/maplair-global.js +2 -2
- package/dist/maplair-global.js.map +1 -1
- package/dist/maplair-src.js +6206 -5673
- package/dist/maplair-src.js.map +1 -1
- package/dist/maplair.css +1 -1213
- package/dist/maplair.js +2 -2
- 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 +11 -18
- package/src/Maplair.all.js +0 -1
- 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 +196 -86
- 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 +102 -19
- 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 +22 -38
- package/src/control/index.js +1 -0
- package/src/core/Class.js +37 -45
- package/src/core/Events.js +22 -3
- package/src/core/Handler.js +25 -13
- package/src/core/Util.js +20 -2
- 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 +17 -85
- package/src/dom/DomUtil.js +22 -78
- package/src/dom/Draggable.js +32 -23
- package/src/dom/PosAnimation.js +3 -25
- package/src/dom/index.js +0 -1
- package/src/geo/LatLng.js +20 -3
- package/src/geo/LatLngBounds.js +8 -15
- package/src/geo/crs/EPSG3395.js +4 -4
- package/src/geo/crs/EPSG3857.js +4 -4
- package/src/geo/crs/EPSG4326.js +3 -3
- package/src/geo/crs/EarthCRS.js +2 -8
- package/src/geo/crs/SimpleCRS.js +3 -3
- package/src/geo/index.js +1 -2
- package/src/geo/projection/{Projection.LonLat.js → LonLatProjection.js} +2 -2
- package/src/geo/projection/{Projection.Mercator.js → MercatorProjection.js} +2 -2
- package/src/geo/projection/{Projection.SphericalMercator.js → SphericalMercatorProjection.js} +2 -2
- package/src/geo/projection/index.js +5 -5
- package/src/geometry/Bounds.js +12 -17
- package/src/geometry/LineUtil.js +48 -49
- package/src/geometry/PolyUtil.js +39 -76
- package/src/layer/BlanketOverlay.js +6 -10
- package/src/layer/DivOverlay.js +16 -27
- package/src/layer/FeatureGroup.js +8 -2
- package/src/layer/GeoJSON.js +17 -218
- package/src/layer/GeoJSONUtil.js +85 -0
- package/src/layer/HeatLayer.js +10 -12
- package/src/layer/ImageOverlay.js +21 -32
- package/src/layer/Layer.js +8 -10
- package/src/layer/LayerGroup.js +72 -1
- package/src/layer/Popup.js +37 -62
- package/src/layer/SVGOverlay.js +1 -5
- package/src/layer/Tooltip.js +34 -36
- package/src/layer/VideoOverlay.js +12 -15
- package/src/layer/marker/DefaultIcon.js +40 -58
- package/src/layer/marker/DivIcon.js +9 -11
- package/src/layer/marker/Icon.js +9 -10
- package/src/layer/marker/Marker.Drag.js +54 -6
- package/src/layer/marker/Marker.Move.js +4 -6
- package/src/layer/marker/Marker.js +145 -52
- 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 +108 -135
- package/src/layer/tile/TileLayer.js +44 -49
- package/src/layer/tile/WMSTileLayer.js +31 -26
- package/src/layer/vector/Canvas.js +13 -19
- package/src/layer/vector/Circle.js +9 -3
- package/src/layer/vector/CircleMarker.js +19 -7
- package/src/layer/vector/Path.DashAnimation.js +1 -2
- package/src/layer/vector/Path.js +30 -21
- package/src/layer/vector/Polygon.js +29 -6
- package/src/layer/vector/Polyline.js +26 -7
- package/src/layer/vector/Renderer.getRenderer.js +20 -19
- package/src/layer/vector/SVG.js +17 -7
- package/src/map/Map.Rotation.js +40 -8
- package/src/map/Map.js +158 -153
- package/src/map/handler/BoxZoomHandler.js +30 -50
- package/src/map/handler/DisplaceHandler.js +6 -8
- package/src/map/handler/DragHandler.js +25 -28
- package/src/map/handler/KeyboardHandler.js +65 -90
- 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 +153 -98
- package/dist/esm/core/Browser.js +0 -100
- package/dist/esm/core/Browser.js.map +0 -1
- package/dist/esm/geo/projection/Projection.LonLat.js.map +0 -1
- package/dist/esm/geo/projection/Projection.Mercator.js.map +0 -1
- package/dist/esm/geo/projection/Projection.SphericalMercator.js.map +0 -1
- package/dist/esm/geo/projection/index.js +0 -14
- package/dist/esm/geo/projection/index.js.map +0 -1
- package/dist/esm/layer/marker/Marker.Rotation.js +0 -70
- package/dist/esm/layer/marker/Marker.Rotation.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
- package/src/layer/marker/Marker.Rotation.js +0 -103
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' */
|
|
@@ -113,33 +109,30 @@ export class GeoJSON extends FeatureGroup {
|
|
|
113
109
|
* @returns {this}
|
|
114
110
|
*/
|
|
115
111
|
addData(geojson) {
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
for (const feature of features) {
|
|
120
|
-
// only add this if geometry or geometries are set and not null
|
|
121
|
-
if (feature.geometries || feature.geometry || feature.features || feature.coordinates) {
|
|
122
|
-
this.addData(feature);
|
|
123
|
-
}
|
|
112
|
+
if (Array.isArray(geojson) || 'features' in geojson) {
|
|
113
|
+
for (const data of Array.isArray(geojson) ? geojson : geojson.features) {
|
|
114
|
+
this.addData(data);
|
|
124
115
|
}
|
|
125
116
|
return this;
|
|
126
117
|
}
|
|
127
118
|
|
|
128
|
-
const options = this.options
|
|
119
|
+
const options = this.options,
|
|
120
|
+
feature = GeoJSON.asFeature(geojson);
|
|
129
121
|
|
|
130
|
-
|
|
122
|
+
// skips features without a geometry
|
|
123
|
+
if (!feature.geometry || (options.filter && !options.filter(feature))) { return this; }
|
|
131
124
|
|
|
132
|
-
const layer = GeoJSON.geometryToLayer(
|
|
125
|
+
const layer = GeoJSON.geometryToLayer(feature, options);
|
|
133
126
|
if (!layer) {
|
|
134
127
|
return this;
|
|
135
128
|
}
|
|
136
|
-
layer.feature =
|
|
129
|
+
layer.feature = feature;
|
|
137
130
|
|
|
138
131
|
layer.defaultOptions = layer.options;
|
|
139
132
|
this.resetStyle(layer);
|
|
140
133
|
|
|
141
134
|
if (options.onEachFeature) {
|
|
142
|
-
options.onEachFeature(
|
|
135
|
+
options.onEachFeature(feature, layer);
|
|
143
136
|
}
|
|
144
137
|
|
|
145
138
|
return this.addLayer(layer);
|
|
@@ -232,6 +225,8 @@ export class GeoJSON extends FeatureGroup {
|
|
|
232
225
|
}, options);
|
|
233
226
|
|
|
234
227
|
if (geoLayer) {
|
|
228
|
+
// so toGeoJSON exports MultiPoint and GeometryCollection members with their own type
|
|
229
|
+
geoLayer.feature = GeoJSON.asFeature(g);
|
|
235
230
|
layers.push(geoLayer);
|
|
236
231
|
}
|
|
237
232
|
}
|
|
@@ -292,10 +287,7 @@ export class GeoJSON extends FeatureGroup {
|
|
|
292
287
|
* @returns {number[]}
|
|
293
288
|
*/
|
|
294
289
|
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)];
|
|
290
|
+
return latLngToCoords(latlng, precision);
|
|
299
291
|
}
|
|
300
292
|
|
|
301
293
|
/**
|
|
@@ -310,16 +302,7 @@ export class GeoJSON extends FeatureGroup {
|
|
|
310
302
|
* @returns {any[]}
|
|
311
303
|
*/
|
|
312
304
|
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;
|
|
305
|
+
return latLngsToCoords(latlngs, levelsDeep, close, precision);
|
|
323
306
|
}
|
|
324
307
|
|
|
325
308
|
/**
|
|
@@ -329,9 +312,7 @@ export class GeoJSON extends FeatureGroup {
|
|
|
329
312
|
* @returns {Feature}
|
|
330
313
|
*/
|
|
331
314
|
static getFeature(layer, newGeometry) {
|
|
332
|
-
return layer
|
|
333
|
-
{...layer.feature, geometry: newGeometry} :
|
|
334
|
-
GeoJSON.asFeature(newGeometry);
|
|
315
|
+
return getFeature(layer, newGeometry);
|
|
335
316
|
}
|
|
336
317
|
|
|
337
318
|
/**
|
|
@@ -340,189 +321,7 @@ export class GeoJSON extends FeatureGroup {
|
|
|
340
321
|
* @returns {Feature|FeatureCollection}
|
|
341
322
|
*/
|
|
342
323
|
static asFeature(geojson) {
|
|
343
|
-
|
|
344
|
-
return geojson;
|
|
345
|
-
}
|
|
346
|
-
|
|
347
|
-
return {
|
|
348
|
-
type: 'Feature',
|
|
349
|
-
properties: {},
|
|
350
|
-
geometry: geojson
|
|
351
|
-
};
|
|
324
|
+
return asFeature(geojson);
|
|
352
325
|
}
|
|
353
326
|
|
|
354
327
|
}
|
|
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
|
|
@@ -189,7 +187,7 @@ export class HeatLayer extends BlanketOverlay {
|
|
|
189
187
|
|
|
190
188
|
// merge the points per grid cell, weighted by their intensity
|
|
191
189
|
for (const latlng of this._latlngs) {
|
|
192
|
-
const point = map.latLngToLayerPoint(latlng).
|
|
190
|
+
const point = map.latLngToLayerPoint(latlng)._round()._subtract(offset);
|
|
193
191
|
if (point.x < -r || point.y < -r || point.x > width + r || point.y > height + r) { continue; }
|
|
194
192
|
const intensity = (latlng.alt ?? latlng[2] ?? 1) * zoomFactor,
|
|
195
193
|
key = `${Math.floor(point.x / cellSize)}:${Math.floor(point.y / cellSize)}`,
|
|
@@ -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
|
}
|
|
@@ -299,8 +288,8 @@ export class ImageOverlay extends Layer {
|
|
|
299
288
|
_reset() {
|
|
300
289
|
const image = this._image,
|
|
301
290
|
bounds = new Bounds(
|
|
302
|
-
this._map.latLngToLayerPoint(this._bounds.getNorthWest()),
|
|
303
|
-
this._map.latLngToLayerPoint(this._bounds.getSouthEast())),
|
|
291
|
+
this._map.latLngToLayerPoint(this._bounds.getNorthWest())._round(),
|
|
292
|
+
this._map.latLngToLayerPoint(this._bounds.getSouthEast())._round()),
|
|
304
293
|
size = bounds.getSize();
|
|
305
294
|
|
|
306
295
|
DomUtil.setPosition(image, bounds.min);
|
|
@@ -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
|
|
|
@@ -58,7 +60,7 @@ export class LayerGroup extends Layer {
|
|
|
58
60
|
* @returns {this}
|
|
59
61
|
*/
|
|
60
62
|
removeLayer(layer) {
|
|
61
|
-
const id = layer
|
|
63
|
+
const id = typeof layer === 'number' ? layer : this.getLayerId(layer);
|
|
62
64
|
|
|
63
65
|
if (this._map && this._layers[id]) {
|
|
64
66
|
this._map.removeLayer(this._layers[id]);
|
|
@@ -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
|
}
|