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
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GeoJSON.js","names":["Util.formatNum","LineUtil.isFlat"],"sources":["../../../src/layer/GeoJSON.js"],"sourcesContent":["import {LayerGroup} from './LayerGroup.js';\nimport {FeatureGroup} from './FeatureGroup.js';\nimport * as Util from '../core/Util.js';\nimport {Marker} from './marker/Marker.js';\nimport {Circle} from './vector/Circle.js';\nimport {CircleMarker} from './vector/CircleMarker.js';\nimport {Polyline} from './vector/Polyline.js';\nimport {Polygon} from './vector/Polygon.js';\nimport {LatLng} from '../geo/LatLng.js';\nimport * as LineUtil from '../geometry/LineUtil.js';\n\n/** @import {Feature, FeatureCollection, GeoJSON as GeoJSONData, GeoJsonObject, Geometry} from 'geojson' */\n/** @import {Layer, InteractiveLayerOptions} from './Layer.js' */\n/** @import {LatLngExpression} from '../geo/LatLng.js' */\n/** @import {PathOptions} from './vector/Path.js' */\n\n/**\n * Options of `GeoJSON`.\n * @typedef {object} GeoJSONOptions\n * @property {(geoJsonPoint: Feature, latlng: LatLng) => Layer} [pointToLayer] A\n * `Function` defining how GeoJSON points spawn Maplair layers. It is internally\n * called when data is added, passing the GeoJSON point feature and its `LatLng`.\n * The default is to spawn a default `Marker`:\n * ```js\n * function(geoJsonPoint, latlng) {\n * \treturn new Marker(latlng);\n * }\n * ```\n * @property {PathOptions|((geoJsonFeature: Feature) => PathOptions)} [style] A\n * `Function` defining the `Path options` for styling GeoJSON lines and polygons,\n * called internally when data is added.\n * The default value is to not override any defaults:\n * ```js\n * function (geoJsonFeature) {\n * \treturn {}\n * }\n * ```\n * @property {(feature: Feature, layer: Layer) => void} [onEachFeature] A `Function`\n * that will be called once for each created `Feature`, after it has been created and\n * styled. Useful for attaching events and popups to features. It will receive the\n * `feature` as the first argument and its corresponding spawned `layer` from\n * [`asFeature`](#geojson-asFeature) as the second.\n * The default is to do nothing with the newly created layers:\n * ```js\n * function (feature, layer) {}\n * ```\n * @property {(geoJsonFeature: Feature) => boolean} [filter] A `Function` that will be\n * used to decide whether to include a feature or not.\n * The default is to include all features:\n * ```js\n * function (geoJsonFeature) {\n * \treturn true;\n * }\n * ```\n * Note: dynamically changing the `filter` option will have effect only on newly\n * added data. It will _not_ re-evaluate already included features.\n * @property {(coords: number[]) => LatLng} [coordsToLatLng] A `Function` that will be\n * used for converting GeoJSON coordinates to `LatLng`s.\n * The default is the `coordsToLatLng` static method.\n * @property {boolean} [markersInheritOptions=false] Whether default Markers for \"Point\"\n * type Features inherit from group options.\n * @extends InteractiveLayerOptions\n */\n\n/**\n * Properties of layers created from GeoJSON.\n * @typedef {object} GeoJSONLayerProperties\n * @lends Layer\n * @property {Feature} [feature] The GeoJSON feature the layer was created from (by\n * `GeoJSON`).\n */\n\n/**\n * Represents a GeoJSON object or an array of GeoJSON objects. Allows you to parse\n * GeoJSON data and display it on the map. Extends `FeatureGroup`.\n *\n * There are several static functions which can be called without instantiating\n * `GeoJSON`.\n *\n * @example\n * ```js\n * new GeoJSON(data, {\n * \tstyle: function (feature) {\n * \t\treturn {color: feature.properties.color};\n * \t}\n * }).bindPopup(function (layer) {\n * \treturn layer.feature.properties.description;\n * }).addTo(map);\n * ```\n */\nexport class GeoJSON extends FeatureGroup {\n\n\t/**\n\t * Creates a GeoJSON layer. Optionally accepts an object in\n\t * [GeoJSON format](https://tools.ietf.org/html/rfc7946) to display on the map\n\t * (you can alternatively add it later with `addData` method) and an `options` object.\n\t * @param {GeoJSONData|GeoJSONData[]|null} [geojson]\n\t * @param {GeoJSONOptions} [options]\n\t */\n\tconstructor(geojson, options) {\n\t\tsuper(undefined, options);\n\n\t\tif (geojson) {\n\t\t\tthis.addData(geojson);\n\t\t}\n\n\t\tthis.callInitHooks(GeoJSON);\n\t}\n\n\t/**\n\t * Adds a GeoJSON object to the layer.\n\t * @param {GeoJSONData|GeoJSONData[]} geojson\n\t * @returns {this}\n\t */\n\taddData(geojson) {\n\t\tconst features = Array.isArray(geojson) ? geojson : geojson.features;\n\n\t\tif (features) {\n\t\t\tfor (const feature of features) {\n\t\t\t\t// only add this if geometry or geometries are set and not null\n\t\t\t\tif (feature.geometries || feature.geometry || feature.features || feature.coordinates) {\n\t\t\t\t\tthis.addData(feature);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn this;\n\t\t}\n\n\t\tconst options = this.options;\n\n\t\tif (options.filter && !options.filter(geojson)) { return this; }\n\n\t\tconst layer = GeoJSON.geometryToLayer(geojson, options);\n\t\tif (!layer) {\n\t\t\treturn this;\n\t\t}\n\t\tlayer.feature = GeoJSON.asFeature(geojson);\n\n\t\tlayer.defaultOptions = layer.options;\n\t\tthis.resetStyle(layer);\n\n\t\tif (options.onEachFeature) {\n\t\t\toptions.onEachFeature(geojson, layer);\n\t\t}\n\n\t\treturn this.addLayer(layer);\n\t}\n\n\t/**\n\t * Resets the given vector layer's style to the original GeoJSON style, useful for\n\t * resetting style after hover events. If `layer` is omitted, the style of all\n\t * features in the current layer is reset.\n\t * @param {Layer} [layer]\n\t * @returns {this}\n\t */\n\tresetStyle(layer) {\n\t\tif (layer === undefined) {\n\t\t\treturn this.eachLayer(this.resetStyle, this);\n\t\t}\n\t\t// reset any custom styles\n\t\tlayer.options = Object.create(layer.defaultOptions);\n\t\tthis._setLayerStyle(layer, this.options.style);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Changes styles of GeoJSON vector layers with the given style function.\n\t * @param {PathOptions|((geoJsonFeature: Feature) => PathOptions)} style\n\t * @returns {this}\n\t */\n\tsetStyle(style) {\n\t\treturn this.eachLayer(layer => this._setLayerStyle(layer, style));\n\t}\n\n\t_setLayerStyle(layer, style) {\n\t\tif (layer.setStyle) {\n\t\t\tif (typeof style === 'function') {\n\t\t\t\tstyle = style(layer.feature);\n\t\t\t}\n\t\t\tlayer.setStyle(style);\n\t\t}\n\t}\n\n\t/**\n\t * Creates a `Layer` from a given GeoJSON feature. Can use a custom\n\t * [`pointToLayer`](#geojson-pointtolayer) and/or [`coordsToLatLng`](#geojson-coordstolatlng)\n\t * functions if provided as options.\n\t * @param {GeoJsonObject} geojson\n\t * @param {GeoJSONOptions} [options]\n\t * @returns {Layer|null}\n\t */\n\tstatic geometryToLayer(geojson, options) {\n\n\t\tconst geometry = geojson.type === 'Feature' ? geojson.geometry : geojson,\n\t\tcoords = geometry?.coordinates,\n\t\tlayers = [],\n\t\tpointToLayer = options?.pointToLayer,\n\t\t_coordsToLatLng = options?.coordsToLatLng ?? GeoJSON.coordsToLatLng;\n\t\tlet latlng, latlngs;\n\n\t\tif (!coords && !geometry) {\n\t\t\treturn null;\n\t\t}\n\n\t\tswitch (geometry.type) {\n\t\tcase 'Point':\n\t\t\tlatlng = _coordsToLatLng(coords);\n\t\t\treturn GeoJSON._pointToLayer(pointToLayer, geojson, latlng, options);\n\n\t\tcase 'MultiPoint':\n\t\t\tfor (const coord of coords) {\n\t\t\t\tlatlng = _coordsToLatLng(coord);\n\t\t\t\tlayers.push(GeoJSON._pointToLayer(pointToLayer, geojson, latlng, options));\n\t\t\t}\n\t\t\treturn new FeatureGroup(layers);\n\n\t\tcase 'LineString':\n\t\tcase 'MultiLineString':\n\t\t\tlatlngs = GeoJSON.coordsToLatLngs(coords, geometry.type === 'LineString' ? 0 : 1, _coordsToLatLng);\n\t\t\treturn new Polyline(latlngs, options);\n\n\t\tcase 'Polygon':\n\t\tcase 'MultiPolygon':\n\t\t\tlatlngs = GeoJSON.coordsToLatLngs(coords, geometry.type === 'Polygon' ? 1 : 2, _coordsToLatLng);\n\t\t\treturn new Polygon(latlngs, options);\n\n\t\tcase 'GeometryCollection':\n\t\t\tfor (const g of geometry.geometries) {\n\t\t\t\tconst geoLayer = GeoJSON.geometryToLayer({\n\t\t\t\t\tgeometry: g,\n\t\t\t\t\ttype: 'Feature',\n\t\t\t\t\tproperties: geojson.properties\n\t\t\t\t}, options);\n\n\t\t\t\tif (geoLayer) {\n\t\t\t\t\tlayers.push(geoLayer);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn new FeatureGroup(layers);\n\n\t\tcase 'FeatureCollection':\n\t\t\tfor (const f of geometry.features) {\n\t\t\t\tconst featureLayer = GeoJSON.geometryToLayer(f, options);\n\n\t\t\t\tif (featureLayer) {\n\t\t\t\t\tlayers.push(featureLayer);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn new FeatureGroup(layers);\n\n\t\tdefault:\n\t\t\tthrow new Error('Invalid GeoJSON object.');\n\t\t}\n\t}\n\n\tstatic _pointToLayer(pointToLayerFn, geojson, latlng, options) {\n\t\treturn pointToLayerFn ?\n\t\t\tpointToLayerFn(geojson, latlng) :\n\t\t\tnew Marker(latlng, options?.markersInheritOptions && options);\n\t}\n\n\t/**\n\t * Creates a `LatLng` object from an array of 2 numbers (longitude, latitude)\n\t * or 3 numbers (longitude, latitude, altitude) used in GeoJSON for points.\n\t * @param {number[]} coords\n\t * @returns {LatLng}\n\t */\n\tstatic coordsToLatLng(coords) {\n\t\treturn new LatLng(coords[1], coords[0], coords[2]);\n\t}\n\n\t/**\n\t * Creates a multidimensional array of `LatLng`s from a GeoJSON coordinates array.\n\t * `levelsDeep` specifies the nesting level (0 is for an array of points, 1 for an\n\t * array of arrays of points, etc., 0 by default).\n\t * Can use a custom [`coordsToLatLng`](#geojson-coordstolatlng) function.\n\t * @param {any[]} coords\n\t * @param {number} [levelsDeep]\n\t * @param {(coords: number[]) => LatLng} [_coordsToLatLng]\n\t * @returns {any[]}\n\t */\n\tstatic coordsToLatLngs(coords, levelsDeep, _coordsToLatLng) {\n\t\treturn coords.map(coord => (levelsDeep ?\n\t\t\tGeoJSON.coordsToLatLngs(coord, levelsDeep - 1, _coordsToLatLng) :\n\t\t\t(_coordsToLatLng || GeoJSON.coordsToLatLng)(coord)));\n\t}\n\n\t/**\n\t * Reverse of [`coordsToLatLng`](#geojson-coordstolatlng).\n\t * Coordinates values are rounded with [`formatNum`](#util-formatnum) function.\n\t * @param {LatLngExpression} latlng\n\t * @param {number|false} [precision]\n\t * @returns {number[]}\n\t */\n\tstatic latLngToCoords(latlng, precision) {\n\t\tlatlng = LatLng.from(latlng);\n\t\treturn latlng.alt !== undefined ?\n\t\t\t[Util.formatNum(latlng.lng, precision), Util.formatNum(latlng.lat, precision), Util.formatNum(latlng.alt, precision)] :\n\t\t\t[Util.formatNum(latlng.lng, precision), Util.formatNum(latlng.lat, precision)];\n\t}\n\n\t/**\n\t * Reverse of [`coordsToLatLngs`](#geojson-coordstolatlngs).\n\t * `close` determines whether the first point should be appended to the end of the\n\t * array to close the feature, only used when `levelsDeep` is 0. False by default.\n\t * Coordinates values are rounded with [`formatNum`](#util-formatnum) function.\n\t * @param {any[]} latlngs\n\t * @param {number} [levelsDeep]\n\t * @param {boolean} [close]\n\t * @param {number|false} [precision]\n\t * @returns {any[]}\n\t */\n\tstatic latLngsToCoords(latlngs, levelsDeep, close, precision) {\n\t\t// Check for flat arrays required to ensure unbalanced arrays are correctly converted in recursion\n\t\tconst coords = latlngs.map(latlng => (levelsDeep ?\n\t\t\tGeoJSON.latLngsToCoords(latlng, LineUtil.isFlat(latlng) ? 0 : levelsDeep - 1, close, precision) :\n\t\t\tGeoJSON.latLngToCoords(latlng, precision)));\n\n\t\tif (!levelsDeep && close && coords.length > 0) {\n\t\t\tcoords.push(coords[0].slice());\n\t\t}\n\n\t\treturn coords;\n\t}\n\n\t/**\n\t * Returns GeoJSON geometries/features of layer with new GeoJSON geometry.\n\t * @param {Layer} layer\n\t * @param {Geometry} newGeometry\n\t * @returns {Feature}\n\t */\n\tstatic getFeature(layer, newGeometry) {\n\t\treturn layer.feature ?\n\t\t\t{...layer.feature, geometry: newGeometry} :\n\t\t\tGeoJSON.asFeature(newGeometry);\n\t}\n\n\t/**\n\t * Normalize GeoJSON geometries/features into GeoJSON features.\n\t * @param {GeoJsonObject} geojson\n\t * @returns {Feature|FeatureCollection}\n\t */\n\tstatic asFeature(geojson) {\n\t\tif (geojson.type === 'Feature' || geojson.type === 'FeatureCollection') {\n\t\t\treturn geojson;\n\t\t}\n\n\t\treturn {\n\t\t\ttype: 'Feature',\n\t\t\tproperties: {},\n\t\t\tgeometry: geojson\n\t\t};\n\t}\n\n}\n\n/**\n * Methods of `Marker` (and `CircleMarker`, `Circle`) for GeoJSON.\n * @lends Marker.prototype\n */\nconst PointToGeoJSON = {\n\t/**\n\t * Coordinates values are rounded with [`formatNum`](#util-formatnum) to the\n\t * given `precision`. Returns a [`GeoJSON`](https://en.wikipedia.org/wiki/GeoJSON)\n\t * representation of the marker (as a GeoJSON `Point` Feature).\n\t * @group Other methods\n\t * @param {number|false} [precision]\n\t * @returns {Feature}\n\t */\n\ttoGeoJSON(precision) {\n\t\treturn GeoJSON.getFeature(this, {\n\t\t\ttype: 'Point',\n\t\t\tcoordinates: GeoJSON.latLngToCoords(this.getLatLng(), precision)\n\t\t});\n\t}\n};\n/** @typedef {typeof PointToGeoJSON} PointToGeoJSONMethods */\n\n/**\n * Methods of `CircleMarker` (and `Circle`) for GeoJSON: `toGeoJSON(precision?)`\n * returns a [`GeoJSON`](https://en.wikipedia.org/wiki/GeoJSON) representation of the\n * circle marker (as a GeoJSON `Point` Feature), with the coordinates values rounded\n * with [`formatNum`](#util-formatnum) function with given `precision`.\n * @typedef {object} CircleMarkerToGeoJSONMethods\n * @extends PointToGeoJSONMethods\n * @lends CircleMarker\n */\n\nMarker.include(PointToGeoJSON);\nCircle.include(PointToGeoJSON);\nCircleMarker.include(PointToGeoJSON);\n\n/**\n * Methods of `Polyline` for GeoJSON.\n * @lends Polyline.prototype\n */\nconst polylineToGeoJSON = {\n\t/**\n\t * Coordinates values are rounded with [`formatNum`](#util-formatnum) to the\n\t * given `precision`. Returns a [`GeoJSON`](https://en.wikipedia.org/wiki/GeoJSON)\n\t * representation of the polyline (as a GeoJSON `LineString` or `MultiLineString`\n\t * Feature).\n\t * @param {number|false} [precision]\n\t * @returns {Feature}\n\t */\n\ttoGeoJSON(precision) {\n\t\tconst multi = !LineUtil.isFlat(this._latlngs);\n\n\t\tconst coords = GeoJSON.latLngsToCoords(this._latlngs, multi ? 1 : 0, false, precision);\n\n\t\treturn GeoJSON.getFeature(this, {\n\t\t\ttype: `${multi ? 'Multi' : ''}LineString`,\n\t\t\tcoordinates: coords\n\t\t});\n\t}\n};\n/** @typedef {typeof polylineToGeoJSON} PolylineToGeoJSONMethods */\n\nPolyline.include(polylineToGeoJSON);\n\n/**\n * Methods of `Polygon` for GeoJSON.\n * @lends Polygon.prototype\n */\nconst polygonToGeoJSON = {\n\t/**\n\t * Coordinates values are rounded with [`formatNum`](#util-formatnum) to the\n\t * given `precision`. Returns a [`GeoJSON`](https://en.wikipedia.org/wiki/GeoJSON)\n\t * representation of the polygon (as a GeoJSON `Polygon` or `MultiPolygon` Feature).\n\t * @param {number|false} [precision]\n\t * @returns {Feature}\n\t */\n\ttoGeoJSON(precision) {\n\t\tconst holes = !LineUtil.isFlat(this._latlngs),\n\t\tmulti = holes && !LineUtil.isFlat(this._latlngs[0]);\n\n\t\tlet coords = GeoJSON.latLngsToCoords(this._latlngs, multi ? 2 : holes ? 1 : 0, true, precision);\n\n\t\tif (!holes) {\n\t\t\tcoords = [coords];\n\t\t}\n\n\t\treturn GeoJSON.getFeature(this, {\n\t\t\ttype: `${multi ? 'Multi' : ''}Polygon`,\n\t\t\tcoordinates: coords\n\t\t});\n\t}\n};\n/** @typedef {typeof polygonToGeoJSON} PolygonToGeoJSONMethods */\n\nPolygon.include(polygonToGeoJSON);\n\n/**\n * Methods of `LayerGroup` for GeoJSON.\n * @lends LayerGroup.prototype\n */\nconst layerGroupToGeoJSON = {\n\t/**\n\t * Returns a GeoJSON `MultiPoint` Feature of the points of the group, used by\n\t * `toGeoJSON()`.\n\t * @internal\n\t * @param {number|false} [precision]\n\t * @returns {Feature}\n\t */\n\ttoMultiPoint(precision) {\n\t\tconst coords = [];\n\n\t\tthis.eachLayer((layer) => {\n\t\t\tcoords.push(layer.toGeoJSON(precision).geometry.coordinates);\n\t\t});\n\n\t\treturn GeoJSON.getFeature(this, {\n\t\t\ttype: 'MultiPoint',\n\t\t\tcoordinates: coords\n\t\t});\n\t},\n\n\t/**\n\t * Coordinates values are rounded with [`formatNum`](#util-formatnum) to the\n\t * given `precision`. Returns a [`GeoJSON`](https://en.wikipedia.org/wiki/GeoJSON)\n\t * representation of the layer group (as a GeoJSON `FeatureCollection`,\n\t * `GeometryCollection`, or `MultiPoint`).\n\t * @param {number|false} [precision]\n\t * @returns {Feature|FeatureCollection}\n\t */\n\ttoGeoJSON(precision) {\n\n\t\tconst type = this.feature?.geometry?.type;\n\n\t\tif (type === 'MultiPoint') {\n\t\t\treturn this.toMultiPoint(precision);\n\t\t}\n\n\t\tconst isGeometryCollection = type === 'GeometryCollection',\n\t\tjsons = [];\n\n\t\tthis.eachLayer((layer) => {\n\t\t\tif (layer.toGeoJSON) {\n\t\t\t\tconst json = layer.toGeoJSON(precision);\n\t\t\t\tif (isGeometryCollection) {\n\t\t\t\t\tjsons.push(json.geometry);\n\t\t\t\t} else {\n\t\t\t\t\tconst feature = GeoJSON.asFeature(json);\n\t\t\t\t\t// Squash nested feature collections\n\t\t\t\t\tif (feature.type === 'FeatureCollection') {\n\t\t\t\t\t\tjsons.push(...feature.features);\n\t\t\t\t\t} else {\n\t\t\t\t\t\tjsons.push(feature);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\n\t\tif (isGeometryCollection) {\n\t\t\treturn GeoJSON.getFeature(this, {\n\t\t\t\tgeometries: jsons,\n\t\t\t\ttype: 'GeometryCollection'\n\t\t\t});\n\t\t}\n\n\t\treturn {\n\t\t\ttype: 'FeatureCollection',\n\t\t\tfeatures: jsons\n\t\t};\n\t}\n};\n/** @typedef {typeof layerGroupToGeoJSON} LayerGroupToGeoJSONMethods */\n\nLayerGroup.include(layerGroupToGeoJSON);\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0FA,IAAa,UAAb,MAAa,gBAAgB,aAAa;;;;;;;;CASzC,YAAY,SAAS,SAAS;EAC7B,MAAM,KAAA,GAAW,OAAO;EAExB,IAAI,SACH,KAAK,QAAQ,OAAO;EAGrB,KAAK,cAAc,OAAO;CAC3B;;;;;;CAOA,QAAQ,SAAS;EAChB,MAAM,WAAW,MAAM,QAAQ,OAAO,IAAI,UAAU,QAAQ;EAE5D,IAAI,UAAU;GACb,KAAK,MAAM,WAAW,UAErB,IAAI,QAAQ,cAAc,QAAQ,YAAY,QAAQ,YAAY,QAAQ,aACzE,KAAK,QAAQ,OA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,OAAO;IAEpB;GACD;EACD,CAAC;EAED,IAAI,sBACH,OAAO,QAAQ,WAAW,MAAM;GAC/B,YAAY;GACZ,MAAM;EACP,CAAC;EAGF,OAAO;GACN,MAAM;GACN,UAAU;EACX;CACD;AAIoC,CAAC"}
|
|
1
|
+
{"version":3,"file":"GeoJSON.js","names":[],"sources":["../../../src/layer/GeoJSON.js"],"sourcesContent":["import {FeatureGroup} from './FeatureGroup.js';\nimport {Marker} from './marker/Marker.js';\nimport {Polyline} from './vector/Polyline.js';\nimport {Polygon} from './vector/Polygon.js';\nimport {LatLng} from '../geo/LatLng.js';\nimport {latLngToCoords, latLngsToCoords, getFeature, asFeature} from './GeoJSONUtil.js';\n\n/** @import {Feature, FeatureCollection, GeoJSON as GeoJSONData, GeoJsonObject, Geometry} from 'geojson' */\n/** @import {Layer, InteractiveLayerOptions} from './Layer.js' */\n/** @import {LatLngExpression} from '../geo/LatLng.js' */\n/** @import {PathOptions} from './vector/Path.js' */\n\n/**\n * Options of `GeoJSON`.\n * @typedef {object} GeoJSONOptions\n * @property {(geoJsonPoint: Feature, latlng: LatLng) => Layer} [pointToLayer] A\n * `Function` defining how GeoJSON points spawn Maplair layers. It is internally\n * called when data is added, passing the GeoJSON point feature and its `LatLng`.\n * The default is to spawn a default `Marker`:\n * ```js\n * function(geoJsonPoint, latlng) {\n * \treturn new Marker(latlng);\n * }\n * ```\n * @property {PathOptions|((geoJsonFeature: Feature) => PathOptions)} [style] A\n * `Function` defining the `Path options` for styling GeoJSON lines and polygons,\n * called internally when data is added.\n * The default value is to not override any defaults:\n * ```js\n * function (geoJsonFeature) {\n * \treturn {}\n * }\n * ```\n * @property {(feature: Feature, layer: Layer) => void} [onEachFeature] A `Function`\n * that will be called once for each created `Feature`, after it has been created and\n * styled. Useful for attaching events and popups to features. It will receive the\n * `feature` as the first argument and its corresponding spawned `layer` from\n * [`asFeature`](#geojson-asFeature) as the second.\n * The default is to do nothing with the newly created layers:\n * ```js\n * function (feature, layer) {}\n * ```\n * @property {(geoJsonFeature: Feature) => boolean} [filter] A `Function` that will be\n * used to decide whether to include a feature or not.\n * The default is to include all features:\n * ```js\n * function (geoJsonFeature) {\n * \treturn true;\n * }\n * ```\n * Note: dynamically changing the `filter` option will have effect only on newly\n * added data. It will _not_ re-evaluate already included features.\n * @property {(coords: number[]) => LatLng} [coordsToLatLng] A `Function` that will be\n * used for converting GeoJSON coordinates to `LatLng`s.\n * The default is the `coordsToLatLng` static method.\n * @property {boolean} [markersInheritOptions=false] Whether default Markers for \"Point\"\n * type Features inherit from group options.\n * @extends InteractiveLayerOptions\n */\n\n/**\n * Properties of layers created from GeoJSON.\n * @typedef {object} GeoJSONLayerProperties\n * @lends Layer\n * @property {Feature} [feature] The GeoJSON feature the layer was created from (by\n * `GeoJSON`).\n */\n\n/**\n * Represents a GeoJSON object or an array of GeoJSON objects. Allows you to parse\n * GeoJSON data and display it on the map. Extends `FeatureGroup`.\n *\n * There are several static functions which can be called without instantiating\n * `GeoJSON`.\n *\n * @example\n * ```js\n * new GeoJSON(data, {\n * \tstyle: function (feature) {\n * \t\treturn {color: feature.properties.color};\n * \t}\n * }).bindPopup(function (layer) {\n * \treturn layer.feature.properties.description;\n * }).addTo(map);\n * ```\n */\nexport class GeoJSON extends FeatureGroup {\n\n\t/**\n\t * Creates a GeoJSON layer. Optionally accepts an object in\n\t * [GeoJSON format](https://tools.ietf.org/html/rfc7946) to display on the map\n\t * (you can alternatively add it later with `addData` method) and an `options` object.\n\t * @param {GeoJSONData|GeoJSONData[]|null} [geojson]\n\t * @param {GeoJSONOptions} [options]\n\t */\n\tconstructor(geojson, options) {\n\t\tsuper(undefined, options);\n\n\t\tif (geojson) {\n\t\t\tthis.addData(geojson);\n\t\t}\n\n\t\tthis.callInitHooks(GeoJSON);\n\t}\n\n\t/**\n\t * Adds a GeoJSON object to the layer.\n\t * @param {GeoJSONData|GeoJSONData[]} geojson\n\t * @returns {this}\n\t */\n\taddData(geojson) {\n\t\tif (Array.isArray(geojson) || 'features' in geojson) {\n\t\t\tfor (const data of Array.isArray(geojson) ? geojson : geojson.features) {\n\t\t\t\tthis.addData(data);\n\t\t\t}\n\t\t\treturn this;\n\t\t}\n\n\t\tconst options = this.options,\n\t\tfeature = GeoJSON.asFeature(geojson);\n\n\t\t// skips features without a geometry\n\t\tif (!feature.geometry || (options.filter && !options.filter(feature))) { return this; }\n\n\t\tconst layer = GeoJSON.geometryToLayer(feature, options);\n\t\tif (!layer) {\n\t\t\treturn this;\n\t\t}\n\t\tlayer.feature = feature;\n\n\t\tlayer.defaultOptions = layer.options;\n\t\tthis.resetStyle(layer);\n\n\t\tif (options.onEachFeature) {\n\t\t\toptions.onEachFeature(feature, layer);\n\t\t}\n\n\t\treturn this.addLayer(layer);\n\t}\n\n\t/**\n\t * Resets the given vector layer's style to the original GeoJSON style, useful for\n\t * resetting style after hover events. If `layer` is omitted, the style of all\n\t * features in the current layer is reset.\n\t * @param {Layer} [layer]\n\t * @returns {this}\n\t */\n\tresetStyle(layer) {\n\t\tif (layer === undefined) {\n\t\t\treturn this.eachLayer(this.resetStyle, this);\n\t\t}\n\t\t// reset any custom styles\n\t\tlayer.options = Object.create(layer.defaultOptions);\n\t\tthis._setLayerStyle(layer, this.options.style);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Changes styles of GeoJSON vector layers with the given style function.\n\t * @param {PathOptions|((geoJsonFeature: Feature) => PathOptions)} style\n\t * @returns {this}\n\t */\n\tsetStyle(style) {\n\t\treturn this.eachLayer(layer => this._setLayerStyle(layer, style));\n\t}\n\n\t_setLayerStyle(layer, style) {\n\t\tif (layer.setStyle) {\n\t\t\tif (typeof style === 'function') {\n\t\t\t\tstyle = style(layer.feature);\n\t\t\t}\n\t\t\tlayer.setStyle(style);\n\t\t}\n\t}\n\n\t/**\n\t * Creates a `Layer` from a given GeoJSON feature. Can use a custom\n\t * [`pointToLayer`](#geojson-pointtolayer) and/or [`coordsToLatLng`](#geojson-coordstolatlng)\n\t * functions if provided as options.\n\t * @param {GeoJsonObject} geojson\n\t * @param {GeoJSONOptions} [options]\n\t * @returns {Layer|null}\n\t */\n\tstatic geometryToLayer(geojson, options) {\n\n\t\tconst geometry = geojson.type === 'Feature' ? geojson.geometry : geojson,\n\t\tcoords = geometry?.coordinates,\n\t\tlayers = [],\n\t\tpointToLayer = options?.pointToLayer,\n\t\t_coordsToLatLng = options?.coordsToLatLng ?? GeoJSON.coordsToLatLng;\n\t\tlet latlng, latlngs;\n\n\t\tif (!coords && !geometry) {\n\t\t\treturn null;\n\t\t}\n\n\t\tswitch (geometry.type) {\n\t\tcase 'Point':\n\t\t\tlatlng = _coordsToLatLng(coords);\n\t\t\treturn GeoJSON._pointToLayer(pointToLayer, geojson, latlng, options);\n\n\t\tcase 'MultiPoint':\n\t\t\tfor (const coord of coords) {\n\t\t\t\tlatlng = _coordsToLatLng(coord);\n\t\t\t\tlayers.push(GeoJSON._pointToLayer(pointToLayer, geojson, latlng, options));\n\t\t\t}\n\t\t\treturn new FeatureGroup(layers);\n\n\t\tcase 'LineString':\n\t\tcase 'MultiLineString':\n\t\t\tlatlngs = GeoJSON.coordsToLatLngs(coords, geometry.type === 'LineString' ? 0 : 1, _coordsToLatLng);\n\t\t\treturn new Polyline(latlngs, options);\n\n\t\tcase 'Polygon':\n\t\tcase 'MultiPolygon':\n\t\t\tlatlngs = GeoJSON.coordsToLatLngs(coords, geometry.type === 'Polygon' ? 1 : 2, _coordsToLatLng);\n\t\t\treturn new Polygon(latlngs, options);\n\n\t\tcase 'GeometryCollection':\n\t\t\tfor (const g of geometry.geometries) {\n\t\t\t\tconst geoLayer = GeoJSON.geometryToLayer({\n\t\t\t\t\tgeometry: g,\n\t\t\t\t\ttype: 'Feature',\n\t\t\t\t\tproperties: geojson.properties\n\t\t\t\t}, options);\n\n\t\t\t\tif (geoLayer) {\n\t\t\t\t\t// so toGeoJSON exports MultiPoint and GeometryCollection members with their own type\n\t\t\t\t\tgeoLayer.feature = GeoJSON.asFeature(g);\n\t\t\t\t\tlayers.push(geoLayer);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn new FeatureGroup(layers);\n\n\t\tcase 'FeatureCollection':\n\t\t\tfor (const f of geometry.features) {\n\t\t\t\tconst featureLayer = GeoJSON.geometryToLayer(f, options);\n\n\t\t\t\tif (featureLayer) {\n\t\t\t\t\tlayers.push(featureLayer);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn new FeatureGroup(layers);\n\n\t\tdefault:\n\t\t\tthrow new Error('Invalid GeoJSON object.');\n\t\t}\n\t}\n\n\tstatic _pointToLayer(pointToLayerFn, geojson, latlng, options) {\n\t\treturn pointToLayerFn ?\n\t\t\tpointToLayerFn(geojson, latlng) :\n\t\t\tnew Marker(latlng, options?.markersInheritOptions && options);\n\t}\n\n\t/**\n\t * Creates a `LatLng` object from an array of 2 numbers (longitude, latitude)\n\t * or 3 numbers (longitude, latitude, altitude) used in GeoJSON for points.\n\t * @param {number[]} coords\n\t * @returns {LatLng}\n\t */\n\tstatic coordsToLatLng(coords) {\n\t\treturn new LatLng(coords[1], coords[0], coords[2]);\n\t}\n\n\t/**\n\t * Creates a multidimensional array of `LatLng`s from a GeoJSON coordinates array.\n\t * `levelsDeep` specifies the nesting level (0 is for an array of points, 1 for an\n\t * array of arrays of points, etc., 0 by default).\n\t * Can use a custom [`coordsToLatLng`](#geojson-coordstolatlng) function.\n\t * @param {any[]} coords\n\t * @param {number} [levelsDeep]\n\t * @param {(coords: number[]) => LatLng} [_coordsToLatLng]\n\t * @returns {any[]}\n\t */\n\tstatic coordsToLatLngs(coords, levelsDeep, _coordsToLatLng) {\n\t\treturn coords.map(coord => (levelsDeep ?\n\t\t\tGeoJSON.coordsToLatLngs(coord, levelsDeep - 1, _coordsToLatLng) :\n\t\t\t(_coordsToLatLng || GeoJSON.coordsToLatLng)(coord)));\n\t}\n\n\t/**\n\t * Reverse of [`coordsToLatLng`](#geojson-coordstolatlng).\n\t * Coordinates values are rounded with [`formatNum`](#util-formatnum) function.\n\t * @param {LatLngExpression} latlng\n\t * @param {number|false} [precision]\n\t * @returns {number[]}\n\t */\n\tstatic latLngToCoords(latlng, precision) {\n\t\treturn latLngToCoords(latlng, precision);\n\t}\n\n\t/**\n\t * Reverse of [`coordsToLatLngs`](#geojson-coordstolatlngs).\n\t * `close` determines whether the first point should be appended to the end of the\n\t * array to close the feature, only used when `levelsDeep` is 0. False by default.\n\t * Coordinates values are rounded with [`formatNum`](#util-formatnum) function.\n\t * @param {any[]} latlngs\n\t * @param {number} [levelsDeep]\n\t * @param {boolean} [close]\n\t * @param {number|false} [precision]\n\t * @returns {any[]}\n\t */\n\tstatic latLngsToCoords(latlngs, levelsDeep, close, precision) {\n\t\treturn latLngsToCoords(latlngs, levelsDeep, close, precision);\n\t}\n\n\t/**\n\t * Returns GeoJSON geometries/features of layer with new GeoJSON geometry.\n\t * @param {Layer} layer\n\t * @param {Geometry} newGeometry\n\t * @returns {Feature}\n\t */\n\tstatic getFeature(layer, newGeometry) {\n\t\treturn getFeature(layer, newGeometry);\n\t}\n\n\t/**\n\t * Normalize GeoJSON geometries/features into GeoJSON features.\n\t * @param {GeoJsonObject} geojson\n\t * @returns {Feature|FeatureCollection}\n\t */\n\tstatic asFeature(geojson) {\n\t\treturn asFeature(geojson);\n\t}\n\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsFA,IAAa,UAAb,MAAa,gBAAgB,aAAa;;;;;;;;CASzC,YAAY,SAAS,SAAS;EAC7B,MAAM,KAAA,GAAW,OAAO;EAExB,IAAI,SACH,KAAK,QAAQ,OAAO;EAGrB,KAAK,cAAc,OAAO;CAC3B;;;;;;CAOA,QAAQ,SAAS;EAChB,IAAI,MAAM,QAAQ,OAAO,KAAK,cAAc,SAAS;GACpD,KAAK,MAAM,QAAQ,MAAM,QAAQ,OAAO,IAAI,UAAU,QAAQ,UAC7D,KAAK,QAAQ,IAA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C7D,mBAAmB,QAAQ,eAAA,CAAgB,KAAK,CAAE;CACrD;;;;;;;;CASA,OAAO,eAAe,QAAQ,WAAW;EACxC,OAAO,eAAe,QAAQ,SAAS;CACxC;;;;;;;;;;;;CAaA,OAAO,gBAAgB,SAAS,YAAY,OAAO,WAAW;EAC7D,OAAO,gBAAgB,SAAS,YAAY,OAAO,SAAS;CAC7D;;;;;;;CAQA,OAAO,WAAW,OAAO,aAAa;EACrC,OAAO,WAAW,OAAO,WAAW;CACrC;;;;;;CAOA,OAAO,UAAU,SAAS;EACzB,OAAO,UAAU,OAAO;CACzB;AAED"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { formatNum } from "../core/Util.js";
|
|
2
|
+
import { LatLng } from "../geo/LatLng.js";
|
|
3
|
+
import { isFlat } from "../geometry/LineUtil.js";
|
|
4
|
+
// src/layer/GeoJSONUtil.js
|
|
5
|
+
/** @import {Feature, FeatureCollection, GeoJsonObject, Geometry} from 'geojson' */
|
|
6
|
+
/** @import {Layer} from './Layer.js' */
|
|
7
|
+
/** @import {LatLngExpression} from '../geo/LatLng.js' */
|
|
8
|
+
/**
|
|
9
|
+
* See `GeoJSON.latLngToCoords()`.
|
|
10
|
+
* @param {LatLngExpression} latlng
|
|
11
|
+
* @param {number|false} [precision]
|
|
12
|
+
* @returns {number[]}
|
|
13
|
+
*/
|
|
14
|
+
function latLngToCoords(latlng, precision) {
|
|
15
|
+
latlng = LatLng.from(latlng);
|
|
16
|
+
return latlng.alt !== void 0 ? [
|
|
17
|
+
formatNum(latlng.lng, precision),
|
|
18
|
+
formatNum(latlng.lat, precision),
|
|
19
|
+
formatNum(latlng.alt, precision)
|
|
20
|
+
] : [formatNum(latlng.lng, precision), formatNum(latlng.lat, precision)];
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* See `GeoJSON.latLngsToCoords()`.
|
|
24
|
+
* @param {any[]} latlngs
|
|
25
|
+
* @param {number} [levelsDeep]
|
|
26
|
+
* @param {boolean} [close]
|
|
27
|
+
* @param {number|false} [precision]
|
|
28
|
+
* @returns {any[]}
|
|
29
|
+
*/
|
|
30
|
+
function latLngsToCoords(latlngs, levelsDeep, close, precision) {
|
|
31
|
+
const coords = latlngs.map((latlng) => levelsDeep ? latLngsToCoords(latlng, isFlat(latlng) ? 0 : levelsDeep - 1, close, precision) : latLngToCoords(latlng, precision));
|
|
32
|
+
if (!levelsDeep && close && coords.length > 0) coords.push(coords[0].slice());
|
|
33
|
+
return coords;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* See `GeoJSON.getFeature()`.
|
|
37
|
+
* @param {Layer} layer
|
|
38
|
+
* @param {Geometry} newGeometry
|
|
39
|
+
* @returns {Feature}
|
|
40
|
+
*/
|
|
41
|
+
function getFeature(layer, newGeometry) {
|
|
42
|
+
return layer.feature ? {
|
|
43
|
+
...layer.feature,
|
|
44
|
+
geometry: newGeometry
|
|
45
|
+
} : asFeature(newGeometry);
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* See `GeoJSON.asFeature()`.
|
|
49
|
+
* @param {GeoJsonObject} geojson
|
|
50
|
+
* @returns {Feature|FeatureCollection}
|
|
51
|
+
*/
|
|
52
|
+
function asFeature(geojson) {
|
|
53
|
+
if (geojson.type === "Feature" || geojson.type === "FeatureCollection") return geojson;
|
|
54
|
+
return {
|
|
55
|
+
type: "Feature",
|
|
56
|
+
properties: {},
|
|
57
|
+
geometry: geojson
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* The GeoJSON `Point` Feature of a layer with `getLatLng()`, for its `toGeoJSON()`.
|
|
62
|
+
* @param {Layer & {getLatLng(): LatLng}} layer
|
|
63
|
+
* @param {number|false} [precision]
|
|
64
|
+
* @returns {Feature}
|
|
65
|
+
*/
|
|
66
|
+
function pointToGeoJSON(layer, precision) {
|
|
67
|
+
return getFeature(layer, {
|
|
68
|
+
type: "Point",
|
|
69
|
+
coordinates: latLngToCoords(layer.getLatLng(), precision)
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
export { asFeature, getFeature, latLngToCoords, latLngsToCoords, pointToGeoJSON };
|
|
73
|
+
|
|
74
|
+
//# sourceMappingURL=GeoJSONUtil.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GeoJSONUtil.js","names":["Util.formatNum","LineUtil.isFlat"],"sources":["../../../src/layer/GeoJSONUtil.js"],"sourcesContent":["import * as Util from '../core/Util.js';\nimport {LatLng} from '../geo/LatLng.js';\nimport * as LineUtil from '../geometry/LineUtil.js';\n\n/** @import {Feature, FeatureCollection, GeoJsonObject, Geometry} from 'geojson' */\n/** @import {Layer} from './Layer.js' */\n/** @import {LatLngExpression} from '../geo/LatLng.js' */\n\n// Shared by `GeoJSON` and the `toGeoJSON` methods of the layers it creates, which can't import `GeoJSON.js` without a cycle.\n\n/**\n * See `GeoJSON.latLngToCoords()`.\n * @param {LatLngExpression} latlng\n * @param {number|false} [precision]\n * @returns {number[]}\n */\nexport function latLngToCoords(latlng, precision) {\n\tlatlng = LatLng.from(latlng);\n\treturn latlng.alt !== undefined ?\n\t\t[Util.formatNum(latlng.lng, precision), Util.formatNum(latlng.lat, precision), Util.formatNum(latlng.alt, precision)] :\n\t\t[Util.formatNum(latlng.lng, precision), Util.formatNum(latlng.lat, precision)];\n}\n\n/**\n * See `GeoJSON.latLngsToCoords()`.\n * @param {any[]} latlngs\n * @param {number} [levelsDeep]\n * @param {boolean} [close]\n * @param {number|false} [precision]\n * @returns {any[]}\n */\nexport function latLngsToCoords(latlngs, levelsDeep, close, precision) {\n\t// Check for flat arrays required to ensure unbalanced arrays are correctly converted in recursion\n\tconst coords = latlngs.map(latlng => (levelsDeep ?\n\t\tlatLngsToCoords(latlng, LineUtil.isFlat(latlng) ? 0 : levelsDeep - 1, close, precision) :\n\t\tlatLngToCoords(latlng, precision)));\n\n\tif (!levelsDeep && close && coords.length > 0) {\n\t\tcoords.push(coords[0].slice());\n\t}\n\n\treturn coords;\n}\n\n/**\n * See `GeoJSON.getFeature()`.\n * @param {Layer} layer\n * @param {Geometry} newGeometry\n * @returns {Feature}\n */\nexport function getFeature(layer, newGeometry) {\n\treturn layer.feature ?\n\t\t{...layer.feature, geometry: newGeometry} :\n\t\tasFeature(newGeometry);\n}\n\n/**\n * See `GeoJSON.asFeature()`.\n * @param {GeoJsonObject} geojson\n * @returns {Feature|FeatureCollection}\n */\nexport function asFeature(geojson) {\n\tif (geojson.type === 'Feature' || geojson.type === 'FeatureCollection') {\n\t\treturn geojson;\n\t}\n\n\treturn {\n\t\ttype: 'Feature',\n\t\tproperties: {},\n\t\tgeometry: geojson\n\t};\n}\n\n/**\n * The GeoJSON `Point` Feature of a layer with `getLatLng()`, for its `toGeoJSON()`.\n * @param {Layer & {getLatLng(): LatLng}} layer\n * @param {number|false} [precision]\n * @returns {Feature}\n */\nexport function pointToGeoJSON(layer, precision) {\n\treturn getFeature(layer, {\n\t\ttype: 'Point',\n\t\tcoordinates: latLngToCoords(layer.getLatLng(), precision)\n\t});\n}\n"],"mappings":";;;;;;;;;;;;;AAgBA,SAAgB,eAAe,QAAQ,WAAW;CACjD,SAAS,OAAO,KAAK,MAAM;CAC3B,OAAO,OAAO,QAAQ,KAAA,IACrB;EAACA,UAAe,OAAO,KAAK,SAAS;EAAGA,UAAe,OAAO,KAAK,SAAS;EAAGA,UAAe,OAAO,KAAK,SAAS;CAAC,IACpH,CAACA,UAAe,OAAO,KAAK,SAAS,GAAGA,UAAe,OAAO,KAAK,SAAS,CAAC;AAC/E;;;;;;;;;AAUA,SAAgB,gBAAgB,SAAS,YAAY,OAAO,WAAW;CAEtE,MAAM,SAAS,QAAQ,KAAI,WAAW,aACrC,gBAAgB,QAAQC,OAAgB,MAAM,IAAI,IAAI,aAAa,GAAG,OAAO,SAAS,IACtF,eAAe,QAAQ,SAAS,CAAE;CAEnC,IAAI,CAAC,cAAc,SAAS,OAAO,SAAS,GAC3C,OAAO,KAAK,OAAO,EAAE,CAAC,MAAM,CAAC;CAG9B,OAAO;AACR;;;;;;;AAQA,SAAgB,WAAW,OAAO,aAAa;CAC9C,OAAO,MAAM,UACZ;EAAC,GAAG,MAAM;EAAS,UAAU;CAAW,IACxC,UAAU,WAAW;AACvB;;;;;;AAOA,SAAgB,UAAU,SAAS;CAClC,IAAI,QAAQ,SAAS,aAAa,QAAQ,SAAS,qBAClD,OAAO;CAGR,OAAO;EACN,MAAM;EACN,YAAY,CAAC;EACb,UAAU;CACX;AACD;;;;;;;AAQA,SAAgB,eAAe,OAAO,WAAW;CAChD,OAAO,WAAW,OAAO;EACxB,MAAM;EACN,aAAa,eAAe,MAAM,UAAU,GAAG,SAAS;CACzD,CAAC;AACF"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { setOptions } from "../core/Util.js";
|
|
2
2
|
import { BlanketOverlay } from "./BlanketOverlay.js";
|
|
3
|
-
|
|
3
|
+
// src/layer/HeatLayer.js
|
|
4
4
|
/** @import {BlanketOverlayOptions} from './BlanketOverlay.js' */
|
|
5
5
|
/** @import {LatLngExpression} from '../geo/LatLng.js' */
|
|
6
6
|
/**
|
|
@@ -37,23 +37,21 @@ import { BlanketOverlay } from "./BlanketOverlay.js";
|
|
|
37
37
|
* ```
|
|
38
38
|
*/
|
|
39
39
|
var HeatLayer = class HeatLayer extends BlanketOverlay {
|
|
40
|
-
static {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
});
|
|
56
|
-
}
|
|
40
|
+
static defaultOptions = {
|
|
41
|
+
radius: 25,
|
|
42
|
+
blur: 15,
|
|
43
|
+
max: 1,
|
|
44
|
+
maxZoom: void 0,
|
|
45
|
+
minOpacity: .05,
|
|
46
|
+
gradient: {
|
|
47
|
+
.4: "blue",
|
|
48
|
+
.6: "cyan",
|
|
49
|
+
.7: "lime",
|
|
50
|
+
.8: "yellow",
|
|
51
|
+
1: "red"
|
|
52
|
+
},
|
|
53
|
+
pane: "overlayPane"
|
|
54
|
+
};
|
|
57
55
|
/**
|
|
58
56
|
* Creates a heatmap of the given points: `LatLng`s or arrays
|
|
59
57
|
* `[lat, lng, intensity]` (the intensity defaults to `1`).
|
|
@@ -158,7 +156,7 @@ var HeatLayer = class HeatLayer extends BlanketOverlay {
|
|
|
158
156
|
if (!map || !this._bounds) return;
|
|
159
157
|
const ctx = this._ctx, { width, height } = this._container, offset = this._bounds.min, { radius, blur, max, minOpacity } = this.options, r = radius + blur, maxZoom = this.options.maxZoom ?? map.getMaxZoom(), zoomFactor = 1 / 2 ** Math.max(0, Math.min(maxZoom - map.getZoom(), 12)), cellSize = radius / 2, grid = /* @__PURE__ */ new Map();
|
|
160
158
|
for (const latlng of this._latlngs) {
|
|
161
|
-
const point = map.latLngToLayerPoint(latlng).
|
|
159
|
+
const point = map.latLngToLayerPoint(latlng)._round()._subtract(offset);
|
|
162
160
|
if (point.x < -r || point.y < -r || point.x > width + r || point.y > height + r) continue;
|
|
163
161
|
const intensity = (latlng.alt ?? latlng[2] ?? 1) * zoomFactor, key = `${Math.floor(point.x / cellSize)}:${Math.floor(point.y / cellSize)}`, cell = grid.get(key);
|
|
164
162
|
if (cell) {
|
|
@@ -192,7 +190,6 @@ var HeatLayer = class HeatLayer extends BlanketOverlay {
|
|
|
192
190
|
ctx.putImageData(image, 0, 0);
|
|
193
191
|
}
|
|
194
192
|
};
|
|
195
|
-
//#endregion
|
|
196
193
|
export { HeatLayer };
|
|
197
194
|
|
|
198
195
|
//# sourceMappingURL=HeatLayer.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HeatLayer.js","names":[],"sources":["../../../src/layer/HeatLayer.js"],"sourcesContent":["import {BlanketOverlay} from './BlanketOverlay.js';\nimport * as Util from '../core/Util.js';\n/** @import {BlanketOverlayOptions} from './BlanketOverlay.js' */\n/** @import {LatLngExpression} from '../geo/LatLng.js' */\n\n/**\n * Options of `HeatLayer`.\n * @typedef {object} HeatLayerOptions\n * @property {number} [radius=25] The radius of each point in pixels.\n * @property {number} [blur=15] The amount of blur in pixels.\n * @property {number} [max=1] The intensity with the strongest color.\n * @property {number} [maxZoom] The zoom level where the points reach the full\n * intensity; below it, the intensity is halved per zoom level. By default the\n * maximum zoom of the map.\n * @property {number} [minOpacity=0.05] The minimum opacity of the heat.\n * @property {Record<number, string>} [gradient={0.4: 'blue', 0.6: 'cyan', 0.7: 'lime', 0.8: 'yellow', 1: 'red'}]\n * The colors for the intensities from `0` to `1`, any CSS colors.\n * @property {string} [pane='overlayPane'] The map pane of the layer.\n * @extends BlanketOverlayOptions\n */\n\n/**\n * A heatmap of points, each with an optional intensity, drawn on a canvas: the\n * points are drawn as blurred circles adding up, and colored by a gradient.\n * Nearby points are merged into a grid for speed, so that tens of thousands of\n * points stay fast.\n *\n * Inspired by the [Leaflet.heat](https://github.com/Leaflet/Leaflet.heat) plugin\n * and its [simpleheat](https://github.com/mourner/simpleheat) algorithm.\n *\n * @example\n * ```js\n * new HeatLayer([\n * \t[47.27, 11.40, 0.5], // latitude, longitude, intensity\n * \t[47.28, 11.41],\n * \tnew LatLng(47.26, 11.39)\n * ], {radius: 20}).addTo(map);\n * ```\n */\nexport class HeatLayer extends BlanketOverlay {\n\n\tstatic {\n\t\tthis.setDefaultOptions({\n\t\t\tradius: 25,\n\t\t\tblur: 15,\n\t\t\tmax: 1,\n\t\t\tmaxZoom: undefined,\n\t\t\tminOpacity: 0.05,\n\t\t\tgradient: {0.4: 'blue', 0.6: 'cyan', 0.7: 'lime', 0.8: 'yellow', 1: 'red'},\n\t\t\tpane: 'overlayPane'\n\t\t});\n\t}\n\n\t/**\n\t * Creates a heatmap of the given points: `LatLng`s or arrays\n\t * `[lat, lng, intensity]` (the intensity defaults to `1`).\n\t * @param {LatLngExpression[]} [latlngs]\n\t * @param {HeatLayerOptions} [options]\n\t */\n\tconstructor(latlngs, options) {\n\t\tsuper(options);\n\t\tthis._latlngs = latlngs ?? [];\n\t\tthis.callInitHooks(HeatLayer);\n\t}\n\n\t/**\n\t * Replaces the points of the heatmap.\n\t * @param {LatLngExpression[]} latlngs\n\t * @returns {this}\n\t */\n\tsetLatLngs(latlngs) {\n\t\tthis._latlngs = latlngs;\n\t\treturn this.redraw();\n\t}\n\n\t/**\n\t * Adds a point to the heatmap.\n\t * @param {LatLngExpression} latlng\n\t * @returns {this}\n\t */\n\taddLatLng(latlng) {\n\t\tthis._latlngs.push(latlng);\n\t\treturn this.redraw();\n\t}\n\n\t/**\n\t * Returns the points of the heatmap.\n\t * @returns {LatLngExpression[]}\n\t */\n\tgetLatLngs() {\n\t\treturn this._latlngs;\n\t}\n\n\t/**\n\t * Changes the options, e.g. the `radius` or the `gradient`.\n\t * @param {HeatLayerOptions} options\n\t * @returns {this}\n\t */\n\tsetOptions(options) {\n\t\tUtil.setOptions(this, options);\n\t\tthis._circle = this._gradient = null;\n\t\treturn this.redraw();\n\t}\n\n\t/**\n\t * Redraws the heatmap.\n\t * @returns {this}\n\t */\n\tredraw() {\n\t\tif (this._map && this._bounds) {\n\t\t\tcancelAnimationFrame(this._frame);\n\t\t\tthis._frame = requestAnimationFrame(() => this._draw());\n\t\t}\n\t\treturn this;\n\t}\n\n\t_initContainer() {\n\t\tthis._container = document.createElement('canvas');\n\t\tthis._container.classList.add('maplair-heatmap-layer');\n\t\tthis._ctx = this._container.getContext('2d');\n\t}\n\n\t_destroyContainer() {\n\t\tcancelAnimationFrame(this._frame);\n\t\tsuper._destroyContainer();\n\t}\n\n\t_resizeContainer() {\n\t\tconst size = super._resizeContainer();\n\t\tthis._container.width = size.x;\n\t\tthis._container.height = size.y;\n\t\treturn size;\n\t}\n\n\t_onSettled() {\n\t\tthis._draw();\n\t}\n\n\t// A blurred circle, drawn for each point\n\t_getCircle() {\n\t\tif (this._circle) { return this._circle; }\n\t\tconst {radius, blur} = this.options,\n\t\tr = radius + blur,\n\t\tcircle = this._circle = document.createElement('canvas'),\n\t\tctx = circle.getContext('2d');\n\t\tcircle.width = circle.height = r * 2;\n\t\t// the shadow of a circle drawn outside of the canvas\n\t\tctx.shadowOffsetX = ctx.shadowOffsetY = r * 2;\n\t\tctx.shadowBlur = blur;\n\t\tctx.shadowColor = 'black';\n\t\tctx.beginPath();\n\t\tctx.arc(-r, -r, radius, 0, Math.PI * 2, true);\n\t\tctx.closePath();\n\t\tctx.fill();\n\t\treturn circle;\n\t}\n\n\t// The colors of the alpha values 0–255 as RGBA values\n\t_getGradient() {\n\t\tif (this._gradient) { return this._gradient; }\n\t\tconst canvas = document.createElement('canvas'),\n\t\tctx = canvas.getContext('2d'),\n\t\tgradient = ctx.createLinearGradient(0, 0, 0, 256);\n\t\tcanvas.width = 1;\n\t\tcanvas.height = 256;\n\t\tfor (const [stop, color] of Object.entries(this.options.gradient)) {\n\t\t\tgradient.addColorStop(Number(stop), color);\n\t\t}\n\t\tctx.fillStyle = gradient;\n\t\tctx.fillRect(0, 0, 1, 256);\n\t\tthis._gradient = ctx.getImageData(0, 0, 1, 256).data;\n\t\treturn this._gradient;\n\t}\n\n\t_draw() {\n\t\tconst map = this._map;\n\t\tif (!map || !this._bounds) { return; }\n\n\t\tconst ctx = this._ctx,\n\t\t{width, height} = this._container,\n\t\toffset = this._bounds.min,\n\t\t{radius, blur, max, minOpacity} = this.options,\n\t\tr = radius + blur,\n\t\tmaxZoom = this.options.maxZoom ?? map.getMaxZoom(),\n\t\t// halve the intensity per zoom level below maxZoom (at most 12)\n\t\tzoomFactor = 1 / 2 ** Math.max(0, Math.min(maxZoom - map.getZoom(), 12)),\n\t\tcellSize = radius / 2,\n\t\tgrid = new Map();\n\n\t\t// merge the points per grid cell, weighted by their intensity\n\t\tfor (const latlng of this._latlngs) {\n\t\t\tconst point = map.latLngToLayerPoint(latlng).subtract(offset);\n\t\t\tif (point.x < -r || point.y < -r || point.x > width + r || point.y > height + r) { continue; }\n\t\t\tconst intensity = (latlng.alt ?? latlng[2] ?? 1) * zoomFactor,\n\t\t\tkey = `${Math.floor(point.x / cellSize)}:${Math.floor(point.y / cellSize)}`,\n\t\t\tcell = grid.get(key);\n\t\t\tif (cell) {\n\t\t\t\tconst sum = cell.intensity + intensity;\n\t\t\t\tcell.x = (cell.x * cell.intensity + point.x * intensity) / sum;\n\t\t\t\tcell.y = (cell.y * cell.intensity + point.y * intensity) / sum;\n\t\t\t\tcell.intensity = sum;\n\t\t\t} else {\n\t\t\t\tgrid.set(key, {x: point.x, y: point.y, intensity});\n\t\t\t}\n\t\t}\n\n\t\tctx.clearRect(0, 0, width, height);\n\t\tconst circle = this._getCircle();\n\t\tfor (const {x, y, intensity} of grid.values()) {\n\t\t\tctx.globalAlpha = Math.min(Math.max(intensity / max, minOpacity), 1);\n\t\t\tctx.drawImage(circle, x - r, y - r);\n\t\t}\n\t\tctx.globalAlpha = 1;\n\n\t\t// colorize by the alpha values\n\t\tif (!grid.size) { return; }\n\t\tconst image = ctx.getImageData(0, 0, width, height),\n\t\tpixels = image.data,\n\t\tgradient = this._getGradient();\n\t\tfor (let i = 3; i < pixels.length; i += 4) {\n\t\t\tconst j = pixels[i] * 4;\n\t\t\tif (j) {\n\t\t\t\tpixels[i - 3] = gradient[j];\n\t\t\t\tpixels[i - 2] = gradient[j + 1];\n\t\t\t\tpixels[i - 1] = gradient[j + 2];\n\t\t\t}\n\t\t}\n\t\tctx.putImageData(image, 0, 0);\n\t}\n}\n\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuCA,IAAa,YAAb,MAAa,kBAAkB,eAAe;CAE7C;EACC,KAAK,kBAAkB;GACtB,QAAQ;GACR,MAAM;GACN,KAAK;GACL,SAAS,KAAA;GACT,YAAY;GACZ,UAAU;IAAC,IAAK;IAAQ,IAAK;IAAQ,IAAK;IAAQ,IAAK;IAAU,GAAG;GAAK;GACzE,MAAM;EACP,CAAC;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lay.js';\nimport * as Util from '../core/Util.js';\n/** @import {BlanketOverlayOptions} from './BlanketOverlay.js' */\n/** @import {LatLngExpression} from '../geo/LatLng.js' */\n\n/**\n * Options of `HeatLayer`.\n * @typedef {object} HeatLayerOptions\n * @property {number} [radius=25] The radius of each point in pixels.\n * @property {number} [blur=15] The amount of blur in pixels.\n * @property {number} [max=1] The intensity with the strongest color.\n * @property {number} [maxZoom] The zoom level where the points reach the full\n * intensity; below it, the intensity is halved per zoom level. By default the\n * maximum zoom of the map.\n * @property {number} [minOpacity=0.05] The minimum opacity of the heat.\n * @property {Record<number, string>} [gradient={0.4: 'blue', 0.6: 'cyan', 0.7: 'lime', 0.8: 'yellow', 1: 'red'}]\n * The colors for the intensities from `0` to `1`, any CSS colors.\n * @property {string} [pane='overlayPane'] The map pane of the layer.\n * @extends BlanketOverlayOptions\n */\n\n/**\n * A heatmap of points, each with an optional intensity, drawn on a canvas: the\n * points are drawn as blurred circles adding up, and colored by a gradient.\n * Nearby points are merged into a grid for speed, so that tens of thousands of\n * points stay fast.\n *\n * Inspired by the [Leaflet.heat](https://github.com/Leaflet/Leaflet.heat) plugin\n * and its [simpleheat](https://github.com/mourner/simpleheat) algorithm.\n *\n * @example\n * ```js\n * new HeatLayer([\n * \t[47.27, 11.40, 0.5], // latitude, longitude, intensity\n * \t[47.28, 11.41],\n * \tnew LatLng(47.26, 11.39)\n * ], {radius: 20}).addTo(map);\n * ```\n */\nexport class HeatLayer extends BlanketOverlay {\n\n\tstatic defaultOptions = {\n\t\tradius: 25,\n\t\tblur: 15,\n\t\tmax: 1,\n\t\tmaxZoom: undefined,\n\t\tminOpacity: 0.05,\n\t\tgradient: {0.4: 'blue', 0.6: 'cyan', 0.7: 'lime', 0.8: 'yellow', 1: 'red'},\n\t\tpane: 'overlayPane'\n\t};\n\n\t/**\n\t * Creates a heatmap of the given points: `LatLng`s or arrays\n\t * `[lat, lng, intensity]` (the intensity defaults to `1`).\n\t * @param {LatLngExpression[]} [latlngs]\n\t * @param {HeatLayerOptions} [options]\n\t */\n\tconstructor(latlngs, options) {\n\t\tsuper(options);\n\t\tthis._latlngs = latlngs ?? [];\n\t\tthis.callInitHooks(HeatLayer);\n\t}\n\n\t/**\n\t * Replaces the points of the heatmap.\n\t * @param {LatLngExpression[]} latlngs\n\t * @returns {this}\n\t */\n\tsetLatLngs(latlngs) {\n\t\tthis._latlngs = latlngs;\n\t\treturn this.redraw();\n\t}\n\n\t/**\n\t * Adds a point to the heatmap.\n\t * @param {LatLngExpression} latlng\n\t * @returns {this}\n\t */\n\taddLatLng(latlng) {\n\t\tthis._latlngs.push(latlng);\n\t\treturn this.redraw();\n\t}\n\n\t/**\n\t * Returns the points of the heatmap.\n\t * @returns {LatLngExpression[]}\n\t */\n\tgetLatLngs() {\n\t\treturn this._latlngs;\n\t}\n\n\t/**\n\t * Changes the options, e.g. the `radius` or the `gradient`.\n\t * @param {HeatLayerOptions} options\n\t * @returns {this}\n\t */\n\tsetOptions(options) {\n\t\tUtil.setOptions(this, options);\n\t\tthis._circle = this._gradient = null;\n\t\treturn this.redraw();\n\t}\n\n\t/**\n\t * Redraws the heatmap.\n\t * @returns {this}\n\t */\n\tredraw() {\n\t\tif (this._map && this._bounds) {\n\t\t\tcancelAnimationFrame(this._frame);\n\t\t\tthis._frame = requestAnimationFrame(() => this._draw());\n\t\t}\n\t\treturn this;\n\t}\n\n\t_initContainer() {\n\t\tthis._container = document.createElement('canvas');\n\t\tthis._container.classList.add('maplair-heatmap-layer');\n\t\tthis._ctx = this._container.getContext('2d');\n\t}\n\n\t_destroyContainer() {\n\t\tcancelAnimationFrame(this._frame);\n\t\tsuper._destroyContainer();\n\t}\n\n\t_resizeContainer() {\n\t\tconst size = super._resizeContainer();\n\t\tthis._container.width = size.x;\n\t\tthis._container.height = size.y;\n\t\treturn size;\n\t}\n\n\t_onSettled() {\n\t\tthis._draw();\n\t}\n\n\t// A blurred circle, drawn for each point\n\t_getCircle() {\n\t\tif (this._circle) { return this._circle; }\n\t\tconst {radius, blur} = this.options,\n\t\tr = radius + blur,\n\t\tcircle = this._circle = document.createElement('canvas'),\n\t\tctx = circle.getContext('2d');\n\t\tcircle.width = circle.height = r * 2;\n\t\t// the shadow of a circle drawn outside of the canvas\n\t\tctx.shadowOffsetX = ctx.shadowOffsetY = r * 2;\n\t\tctx.shadowBlur = blur;\n\t\tctx.shadowColor = 'black';\n\t\tctx.beginPath();\n\t\tctx.arc(-r, -r, radius, 0, Math.PI * 2, true);\n\t\tctx.closePath();\n\t\tctx.fill();\n\t\treturn circle;\n\t}\n\n\t// The colors of the alpha values 0–255 as RGBA values\n\t_getGradient() {\n\t\tif (this._gradient) { return this._gradient; }\n\t\tconst canvas = document.createElement('canvas'),\n\t\tctx = canvas.getContext('2d'),\n\t\tgradient = ctx.createLinearGradient(0, 0, 0, 256);\n\t\tcanvas.width = 1;\n\t\tcanvas.height = 256;\n\t\tfor (const [stop, color] of Object.entries(this.options.gradient)) {\n\t\t\tgradient.addColorStop(Number(stop), color);\n\t\t}\n\t\tctx.fillStyle = gradient;\n\t\tctx.fillRect(0, 0, 1, 256);\n\t\tthis._gradient = ctx.getImageData(0, 0, 1, 256).data;\n\t\treturn this._gradient;\n\t}\n\n\t_draw() {\n\t\tconst map = this._map;\n\t\tif (!map || !this._bounds) { return; }\n\n\t\tconst ctx = this._ctx,\n\t\t{width, height} = this._container,\n\t\toffset = this._bounds.min,\n\t\t{radius, blur, max, minOpacity} = this.options,\n\t\tr = radius + blur,\n\t\tmaxZoom = this.options.maxZoom ?? map.getMaxZoom(),\n\t\t// halve the intensity per zoom level below maxZoom (at most 12)\n\t\tzoomFactor = 1 / 2 ** Math.max(0, Math.min(maxZoom - map.getZoom(), 12)),\n\t\tcellSize = radius / 2,\n\t\tgrid = new Map();\n\n\t\t// merge the points per grid cell, weighted by their intensity\n\t\tfor (const latlng of this._latlngs) {\n\t\t\tconst point = map.latLngToLayerPoint(latlng)._round()._subtract(offset);\n\t\t\tif (point.x < -r || point.y < -r || point.x > width + r || point.y > height + r) { continue; }\n\t\t\tconst intensity = (latlng.alt ?? latlng[2] ?? 1) * zoomFactor,\n\t\t\tkey = `${Math.floor(point.x / cellSize)}:${Math.floor(point.y / cellSize)}`,\n\t\t\tcell = grid.get(key);\n\t\t\tif (cell) {\n\t\t\t\tconst sum = cell.intensity + intensity;\n\t\t\t\tcell.x = (cell.x * cell.intensity + point.x * intensity) / sum;\n\t\t\t\tcell.y = (cell.y * cell.intensity + point.y * intensity) / sum;\n\t\t\t\tcell.intensity = sum;\n\t\t\t} else {\n\t\t\t\tgrid.set(key, {x: point.x, y: point.y, intensity});\n\t\t\t}\n\t\t}\n\n\t\tctx.clearRect(0, 0, width, height);\n\t\tconst circle = this._getCircle();\n\t\tfor (const {x, y, intensity} of grid.values()) {\n\t\t\tctx.globalAlpha = Math.min(Math.max(intensity / max, minOpacity), 1);\n\t\t\tctx.drawImage(circle, x - r, y - r);\n\t\t}\n\t\tctx.globalAlpha = 1;\n\n\t\t// colorize by the alpha values\n\t\tif (!grid.size) { return; }\n\t\tconst image = ctx.getImageData(0, 0, width, height),\n\t\tpixels = image.data,\n\t\tgradient = this._getGradient();\n\t\tfor (let i = 3; i < pixels.length; i += 4) {\n\t\t\tconst j = pixels[i] * 4;\n\t\t\tif (j) {\n\t\t\t\tpixels[i - 3] = gradient[j];\n\t\t\t\tpixels[i - 2] = gradient[j + 1];\n\t\t\t\tpixels[i - 1] = gradient[j + 2];\n\t\t\t}\n\t\t}\n\t\tctx.putImageData(image, 0, 0);\n\t}\n}\n\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuCA,IAAa,YAAb,MAAa,kBAAkB,eAAe;CAE7C,OAAO,iBAAiB;EACvB,QAAQ;EACR,MAAM;EACN,KAAK;EACL,SAAS,KAAA;EACT,YAAY;EACZ,UAAU;GAAC,IAAK;GAAQ,IAAK;GAAQ,IAAK;GAAQ,IAAK;GAAU,GAAG;EAAK;EACzE,MAAM;CACP;;;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|
import { create, setPosition, setTransform, toBack, toFront } from "../dom/DomUtil.js";
|
|
3
3
|
import { Layer } from "./Layer.js";
|
|
4
4
|
import { Bounds } from "../geometry/Bounds.js";
|
|
5
5
|
import { LatLngBounds } from "../geo/LatLngBounds.js";
|
|
6
|
-
|
|
6
|
+
// src/layer/ImageOverlay.js
|
|
7
7
|
/** @import {InteractiveLayerOptions} from './Layer.js' */
|
|
8
8
|
/** @import {LatLng} from '../geo/LatLng.js' */
|
|
9
9
|
/** @import {LatLngBoundsExpression} from '../geo/LatLngBounds.js' */
|
|
@@ -55,19 +55,17 @@ import { LatLngBounds } from "../geo/LatLngBounds.js";
|
|
|
55
55
|
* @fires error {MaplairEvent} Fired when the ImageOverlay layer fails to load its image.
|
|
56
56
|
*/
|
|
57
57
|
var ImageOverlay = class ImageOverlay extends Layer {
|
|
58
|
-
static {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
});
|
|
70
|
-
}
|
|
58
|
+
static defaultOptions = {
|
|
59
|
+
opacity: 1,
|
|
60
|
+
alt: "",
|
|
61
|
+
interactive: false,
|
|
62
|
+
crossOrigin: false,
|
|
63
|
+
errorOverlayUrl: "",
|
|
64
|
+
zIndex: 1,
|
|
65
|
+
className: "",
|
|
66
|
+
pixelated: false,
|
|
67
|
+
decoding: "auto"
|
|
68
|
+
};
|
|
71
69
|
/**
|
|
72
70
|
* Instantiates an image overlay object given the URL of the image (or an image
|
|
73
71
|
* element) and the geographical bounds it is tied to.
|
|
@@ -173,12 +171,11 @@ var ImageOverlay = class ImageOverlay extends Layer {
|
|
|
173
171
|
* @returns {Record<string, EventListener>}
|
|
174
172
|
*/
|
|
175
173
|
getEvents() {
|
|
176
|
-
|
|
174
|
+
return {
|
|
177
175
|
zoom: this._reset,
|
|
178
|
-
viewreset: this._reset
|
|
176
|
+
viewreset: this._reset,
|
|
177
|
+
zoomanim: this._animateZoom
|
|
179
178
|
};
|
|
180
|
-
if (this._zoomAnimated) events.zoomanim = this._animateZoom;
|
|
181
|
-
return events;
|
|
182
179
|
}
|
|
183
180
|
/**
|
|
184
181
|
* Changes the [zIndex](#imageoverlay-zindex) of the image overlay.
|
|
@@ -208,13 +205,10 @@ var ImageOverlay = class ImageOverlay extends Layer {
|
|
|
208
205
|
return this._image;
|
|
209
206
|
}
|
|
210
207
|
_initImage() {
|
|
211
|
-
const wasElementSupplied = this._url
|
|
208
|
+
const wasElementSupplied = this._url instanceof HTMLImageElement;
|
|
212
209
|
const img = this._image = wasElementSupplied ? this._url : create("img");
|
|
213
|
-
img.classList.add("maplair-image-layer");
|
|
214
|
-
if (this._zoomAnimated) img.classList.add("maplair-zoom-animated");
|
|
210
|
+
img.classList.add("maplair-image-layer", "maplair-zoom-animated");
|
|
215
211
|
if (this.options.className) img.classList.add(...splitWords(this.options.className));
|
|
216
|
-
img.onselectstart = falseFn;
|
|
217
|
-
img.onpointermove = falseFn;
|
|
218
212
|
img.onload = this.fire.bind(this, "load");
|
|
219
213
|
img.onerror = this._overlayOnError.bind(this);
|
|
220
214
|
if (this.options.crossOrigin || this.options.crossOrigin === "") img.crossOrigin = this.options.crossOrigin === true ? "" : this.options.crossOrigin;
|
|
@@ -228,20 +222,20 @@ var ImageOverlay = class ImageOverlay extends Layer {
|
|
|
228
222
|
img.alt = this.options.alt;
|
|
229
223
|
}
|
|
230
224
|
_animateZoom(e) {
|
|
231
|
-
const scale = this._map.getZoomScale(e.zoom), offset = this._map.
|
|
225
|
+
const scale = this._map.getZoomScale(e.zoom), offset = this._map._latLngToNewLayerPoint(this._bounds.getNorthWest(), e.zoom, e.center);
|
|
232
226
|
setTransform(this._image, offset, scale);
|
|
233
227
|
}
|
|
234
228
|
_reset() {
|
|
235
|
-
const image = this._image, bounds = new Bounds(this._map.latLngToLayerPoint(this._bounds.getNorthWest()), this._map.latLngToLayerPoint(this._bounds.getSouthEast())), size = bounds.getSize();
|
|
229
|
+
const image = this._image, bounds = new Bounds(this._map.latLngToLayerPoint(this._bounds.getNorthWest())._round(), this._map.latLngToLayerPoint(this._bounds.getSouthEast())._round()), size = bounds.getSize();
|
|
236
230
|
setPosition(image, bounds.min);
|
|
237
231
|
image.style.width = `${size.x}px`;
|
|
238
232
|
image.style.height = `${size.y}px`;
|
|
239
233
|
}
|
|
240
234
|
_updateOpacity() {
|
|
241
|
-
this._image.style.opacity = this.options.opacity
|
|
235
|
+
this._image.style.opacity = `${this.options.opacity}`;
|
|
242
236
|
}
|
|
243
237
|
_updateZIndex() {
|
|
244
|
-
if (this._image && this.options.zIndex !== void 0 && this.options.zIndex !== null) this._image.style.zIndex = this.options.zIndex
|
|
238
|
+
if (this._image && this.options.zIndex !== void 0 && this.options.zIndex !== null) this._image.style.zIndex = `${this.options.zIndex}`;
|
|
245
239
|
}
|
|
246
240
|
_overlayOnError() {
|
|
247
241
|
this.fire("error");
|
|
@@ -259,7 +253,6 @@ var ImageOverlay = class ImageOverlay extends Layer {
|
|
|
259
253
|
return this._bounds.getCenter();
|
|
260
254
|
}
|
|
261
255
|
};
|
|
262
|
-
//#endregion
|
|
263
256
|
export { ImageOverlay };
|
|
264
257
|
|
|
265
258
|
//# sourceMappingURL=ImageOverlay.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ImageOverlay.js","names":["DomUtil.create","Util.splitWords","Util.falseFn"],"sources":["../../../src/layer/ImageOverlay.js"],"sourcesContent":["import {Layer} from './Layer.js';\nimport * as Util from '../core/Util.js';\nimport {LatLngBounds} from '../geo/LatLngBounds.js';\nimport {Bounds} from '../geometry/Bounds.js';\nimport * as DomUtil from '../dom/DomUtil.js';\n\n/** @import {InteractiveLayerOptions} from './Layer.js' */\n/** @import {LatLng} from '../geo/LatLng.js' */\n/** @import {LatLngBoundsExpression} from '../geo/LatLngBounds.js' */\n/** @import {MaplairMap} from '../map/Map.js' */\n/** @import {EventListener, MaplairEvent} from '../core/Events.js' */\n\n/**\n * Options of `ImageOverlay`.\n * @typedef {object} ImageOverlayOptions\n * @property {number} [opacity=1] The opacity of the image overlay.\n * @property {string} [alt=''] Text for the `alt` attribute of the image (useful for\n * accessibility).\n * @property {boolean} [interactive=false] If `true`, the image overlay will emit\n * [pointer events](#interactivelayeroptions) when clicked or hovered.\n * @property {boolean|string} [crossOrigin=false] Whether the crossOrigin attribute\n * will be added to the image. If a String is provided, the image will have its\n * crossOrigin attribute set to the String provided. This is needed if you want to\n * access image pixel data. Refer to\n * [CORS Settings](https://developer.mozilla.org/en-US/docs/Web/HTML/CORS_settings_attributes)\n * for valid String values.\n * @property {string} [errorOverlayUrl=''] URL to the overlay image to show in place\n * of the overlay that failed to load.\n * @property {number} [zIndex=1] The explicit\n * [zIndex](https://developer.mozilla.org/docs/Web/CSS/CSS_Positioning/Understanding_z_index)\n * of the overlay layer.\n * @property {string} [className=''] A custom class name to assign to the image. Empty\n * by default.\n * @property {boolean} [pixelated=false] Whether to scale the image with\n * nearest-neighbour interpolation (`image-rendering: pixelated`) instead of smoothing\n * it, so that its pixels stay crisp when zoomed in. Useful for raster data, pixel art\n * or scientific imagery.\n * @property {string} [decoding='auto'] Tells the browser whether to decode the image\n * in a synchronous fashion, as per the\n * [`decoding` HTML attribute](https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/decoding).\n * If the image overlay is flickering when being added/removed, set this option to\n * `'sync'`.\n * @extends InteractiveLayerOptions\n */\n\n/**\n * Used to load and display a single image over specific bounds of the map. Extends `Layer`.\n *\n * @example\n * ```js\n * const imageUrl = 'https://maps.lib.utexas.edu/maps/historical/newark_nj_1922.jpg',\n * \timageBounds = [[40.712216, -74.22655], [40.773941, -74.12544]];\n * new ImageOverlay(imageUrl, imageBounds).addTo(map);\n * ```\n *\n * @fires load {MaplairEvent} Fired when the ImageOverlay layer has loaded its image.\n * @fires error {MaplairEvent} Fired when the ImageOverlay layer fails to load its image.\n */\nexport class ImageOverlay extends Layer {\n\n\tstatic {\n\t\tthis.setDefaultOptions({\n\t\t\topacity: 1,\n\t\t\talt: '',\n\t\t\tinteractive: false,\n\t\t\tcrossOrigin: false,\n\t\t\terrorOverlayUrl: '',\n\t\t\tzIndex: 1,\n\t\t\tclassName: '',\n\t\t\tpixelated: false,\n\t\t\tdecoding: 'auto'\n\t\t});\n\t}\n\n\t/**\n\t * Instantiates an image overlay object given the URL of the image (or an image\n\t * element) and the geographical bounds it is tied to.\n\t * @param {string|HTMLImageElement} url\n\t * @param {LatLngBoundsExpression} bounds\n\t * @param {ImageOverlayOptions} [options]\n\t */\n\tconstructor(url, bounds, options) { // (String, LatLngBounds, Object)\n\t\tsuper();\n\t\tthis._url = url;\n\t\tthis._bounds = new LatLngBounds(bounds);\n\n\t\tUtil.setOptions(this, options);\n\n\t\tthis.callInitHooks(ImageOverlay);\n\t}\n\n\t/**\n\t * Adds the image to the map.\n\t * @type {(map: MaplairMap) => void}\n\t */\n\tonAdd() {\n\t\tif (!this._image) {\n\t\t\tthis._initImage();\n\n\t\t\tif (this.options.opacity < 1) {\n\t\t\t\tthis._updateOpacity();\n\t\t\t}\n\t\t}\n\n\t\tif (this.options.interactive) {\n\t\t\tthis._image.classList.add('maplair-interactive');\n\t\t\tthis.addInteractiveTarget(this._image);\n\t\t}\n\t\tthis._image.classList.toggle('maplair-pixelated', !!this.options.pixelated);\n\n\t\tthis.getPane().appendChild(this._image);\n\t\tthis._reset();\n\t}\n\n\t/**\n\t * Removes the image from the map.\n\t * @type {(map: MaplairMap) => void}\n\t */\n\tonRemove() {\n\t\tthis._image.remove();\n\t\tif (this.options.interactive) {\n\t\t\tthis.removeInteractiveTarget(this._image);\n\t\t}\n\t}\n\n\t_updateInteractive() {\n\t\tthis._image.classList.toggle('maplair-interactive', this.options.interactive);\n\t\tif (this.options.interactive) {\n\t\t\tthis.addInteractiveTarget(this._image);\n\t\t} else {\n\t\t\tthis.removeInteractiveTarget(this._image);\n\t\t}\n\t}\n\n\t/**\n\t * Sets the opacity of the overlay.\n\t * @param {number} opacity\n\t * @returns {this}\n\t */\n\tsetOpacity(opacity) {\n\t\tthis.options.opacity = opacity;\n\n\t\tif (this._image) {\n\t\t\tthis._updateOpacity();\n\t\t}\n\t\treturn this;\n\t}\n\n\t/**\n\t * Sets the opacity of the overlay from the given style options, e.g. by\n\t * `FeatureGroup.setStyle()`.\n\t * @param {{opacity?: number}} styleOpts\n\t * @returns {this}\n\t */\n\tsetStyle(styleOpts) {\n\t\tif (styleOpts.opacity) {\n\t\t\tthis.setOpacity(styleOpts.opacity);\n\t\t}\n\t\treturn this;\n\t}\n\n\t/**\n\t * Brings the layer to the top of all overlays.\n\t * @returns {this}\n\t */\n\tbringToFront() {\n\t\tif (this._map) {\n\t\t\tDomUtil.toFront(this._image);\n\t\t}\n\t\treturn this;\n\t}\n\n\t/**\n\t * Brings the layer to the bottom of all overlays.\n\t * @returns {this}\n\t */\n\tbringToBack() {\n\t\tif (this._map) {\n\t\t\tDomUtil.toBack(this._image);\n\t\t}\n\t\treturn this;\n\t}\n\n\t/**\n\t * Changes the URL of the image.\n\t * @param {string} url\n\t * @returns {this}\n\t */\n\tsetUrl(url) {\n\t\tthis._url = url;\n\n\t\tif (this._image) {\n\t\t\tthis._image.src = url;\n\t\t}\n\t\treturn this;\n\t}\n\n\t/**\n\t * Update the bounds that this ImageOverlay covers.\n\t * @param {LatLngBoundsExpression} bounds\n\t * @returns {this}\n\t */\n\tsetBounds(bounds) {\n\t\tthis._bounds = new LatLngBounds(bounds);\n\n\t\tif (this._map) {\n\t\t\tthis._reset();\n\t\t}\n\t\treturn this;\n\t}\n\n\t/**\n\t * Returns the map events the overlay listens to.\n\t * @returns {Record<string, EventListener>}\n\t */\n\tgetEvents() {\n\t\tconst events = {\n\t\t\tzoom: this._reset,\n\t\t\tviewreset: this._reset\n\t\t};\n\n\t\tif (this._zoomAnimated) {\n\t\t\tevents.zoomanim = this._animateZoom;\n\t\t}\n\n\t\treturn events;\n\t}\n\n\t/**\n\t * Changes the [zIndex](#imageoverlay-zindex) of the image overlay.\n\t * @param {number} value\n\t * @returns {this}\n\t */\n\tsetZIndex(value) {\n\t\tthis.options.zIndex = value;\n\t\tthis._updateZIndex();\n\t\treturn this;\n\t}\n\n\t/**\n\t * Get the bounds that this ImageOverlay covers.\n\t * @returns {LatLngBounds}\n\t */\n\tgetBounds() {\n\t\treturn this._bounds;\n\t}\n\n\t/**\n\t * Returns the instance of\n\t * [`HTMLImageElement`](https://developer.mozilla.org/docs/Web/API/HTMLImageElement)\n\t * used by this overlay (`HTMLVideoElement` for `VideoOverlay`, `SVGElement` for\n\t * `SVGOverlay`).\n\t * @returns {HTMLElement|SVGElement}\n\t */\n\tgetElement() {\n\t\treturn this._image;\n\t}\n\n\t_initImage() {\n\t\tconst wasElementSupplied = this._url.tagName === 'IMG';\n\t\tconst img = this._image = wasElementSupplied ? this._url : DomUtil.create('img');\n\n\t\timg.classList.add('maplair-image-layer');\n\t\tif (this._zoomAnimated) { img.classList.add('maplair-zoom-animated'); }\n\t\tif (this.options.className) { img.classList.add(...Util.splitWords(this.options.className)); }\n\n\t\timg.onselectstart = Util.falseFn;\n\t\timg.onpointermove = Util.falseFn;\n\n\t\timg.onload = this.fire.bind(this, 'load');\n\t\timg.onerror = this._overlayOnError.bind(this);\n\n\t\tif (this.options.crossOrigin || this.options.crossOrigin === '') {\n\t\t\timg.crossOrigin = this.options.crossOrigin === true ? '' : this.options.crossOrigin;\n\t\t}\n\n\t\timg.decoding = this.options.decoding;\n\n\t\tif (this.options.zIndex) {\n\t\t\tthis._updateZIndex();\n\t\t}\n\n\t\tif (wasElementSupplied) {\n\t\t\tthis._url = img.src;\n\t\t\treturn;\n\t\t}\n\n\t\timg.src = this._url;\n\t\timg.alt = this.options.alt;\n\t}\n\n\t_animateZoom(e) {\n\t\tconst scale = this._map.getZoomScale(e.zoom),\n\t\toffset = this._map._latLngBoundsToNewLayerBounds(this._bounds, e.zoom, e.center).min;\n\n\t\tDomUtil.setTransform(this._image, offset, scale);\n\t}\n\n\t_reset() {\n\t\tconst image = this._image,\n\t\tbounds = new Bounds(\n\t\t\tthis._map.latLngToLayerPoint(this._bounds.getNorthWest()),\n\t\t\tthis._map.latLngToLayerPoint(this._bounds.getSouthEast())),\n\t\tsize = bounds.getSize();\n\n\t\tDomUtil.setPosition(image, bounds.min);\n\n\t\timage.style.width = `${size.x}px`;\n\t\timage.style.height = `${size.y}px`;\n\t}\n\n\t_updateOpacity() {\n\t\tthis._image.style.opacity = this.options.opacity;\n\t}\n\n\t_updateZIndex() {\n\t\tif (this._image && this.options.zIndex !== undefined && this.options.zIndex !== null) {\n\t\t\tthis._image.style.zIndex = this.options.zIndex;\n\t\t}\n\t}\n\n\t_overlayOnError() {\n\t\tthis.fire('error');\n\n\t\tconst errorUrl = this.options.errorOverlayUrl;\n\t\tif (errorUrl && this._url !== errorUrl) {\n\t\t\tthis._url = errorUrl;\n\t\t\tthis._image.src = errorUrl;\n\t\t}\n\t}\n\n\t/**\n\t * Returns the center of the ImageOverlay.\n\t * @returns {LatLng}\n\t */\n\tgetCenter() {\n\t\treturn this._bounds.getCenter();\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0DA,IAAa,eAAb,MAAa,qBAAqB,MAAM;CAEvC;EACC,KAAK,kBAAkB;GACtB,SAAS;GACT,KAAK;GACL,aAAa;GACb,aAAa;GACb,iBAAiB;GACjB,QAAQ;GACR,WAAW;GACX,WAAW;GACX,UAAU;EACX,CAAC;CACF;;;;;;;;CASA,YAAY,KAAK,QAAQ,SAAS;EACjC,MAAM;EACN,KAAK,OAAO;EACZ,KAAK,UAAU,IAAI,aAAa,MAAM;EAEtC,WAAgB,MAAM,OAAO;EAE7B,KAAK,cAAc,YAAY;CAChC;;;;;CAMA,QAAQ;EACP,IAAI,CAAC,KAAK,QAAQ;GACjB,KAAK,WAAW;GAEhB,IAAI,KAAK,QAAQ,UAAU,GA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K,mBAAmB,KAAK,QAAQ,aAAa,CAAC,CAAC,GAC1D,OAAO,OAAO,QAAQ;EAEtB,YAAoB,OAAO,OAAO,GAAG;EAErC,MAAM,MAAM,QAAS,GAAG,KAAK,EAAE;EAC/B,MAAM,MAAM,SAAS,GAAG,KAAK,EAAE;CAChC;CAEA,iBAAiB;EAChB,KAAK,OAAO,MAAM,UAAU,KAAK,QAAQ;CAC1C;CAEA,gBAAgB;EACf,IAAI,KAAK,UAAU,KAAK,QAAQ,WAAW,KAAA,KAAa,KAAK,QAAQ,WAAW,MAC/E,KAAK,OAAO,MAAM,SAAS,KAAK,QAAQ;CAE1C;CAEA,kBAAkB;EACjB,KAAK,KAAK,OAAO;EAEjB,MAAM,WAAW,KAAK,QAAQ;EAC9B,IAAI,YAAY,KAAK,SAAS,UAAU;GACvC,KAAK,OAAO;GACZ,KAAK,OAAO,MAAM;EACnB;CACD;;;;;CAMA,YAAY;EACX,OAAO,KAAK,QAAQ,UAAU;CAC/B;AACD"}
|
|
1
|
+
{"version":3,"file":"ImageOverlay.js","names":["DomUtil.create","Util.splitWords"],"sources":["../../../src/layer/ImageOverlay.js"],"sourcesContent":["import {Layer} from './Layer.js';\nimport * as Util from '../core/Util.js';\nimport {LatLngBounds} from '../geo/LatLngBounds.js';\nimport {Bounds} from '../geometry/Bounds.js';\nimport * as DomUtil from '../dom/DomUtil.js';\n\n/** @import {InteractiveLayerOptions} from './Layer.js' */\n/** @import {LatLng} from '../geo/LatLng.js' */\n/** @import {LatLngBoundsExpression} from '../geo/LatLngBounds.js' */\n/** @import {MaplairMap} from '../map/Map.js' */\n/** @import {EventListener, MaplairEvent} from '../core/Events.js' */\n\n/**\n * Options of `ImageOverlay`.\n * @typedef {object} ImageOverlayOptions\n * @property {number} [opacity=1] The opacity of the image overlay.\n * @property {string} [alt=''] Text for the `alt` attribute of the image (useful for\n * accessibility).\n * @property {boolean} [interactive=false] If `true`, the image overlay will emit\n * [pointer events](#interactivelayeroptions) when clicked or hovered.\n * @property {boolean|string} [crossOrigin=false] Whether the crossOrigin attribute\n * will be added to the image. If a String is provided, the image will have its\n * crossOrigin attribute set to the String provided. This is needed if you want to\n * access image pixel data. Refer to\n * [CORS Settings](https://developer.mozilla.org/en-US/docs/Web/HTML/CORS_settings_attributes)\n * for valid String values.\n * @property {string} [errorOverlayUrl=''] URL to the overlay image to show in place\n * of the overlay that failed to load.\n * @property {number} [zIndex=1] The explicit\n * [zIndex](https://developer.mozilla.org/docs/Web/CSS/CSS_Positioning/Understanding_z_index)\n * of the overlay layer.\n * @property {string} [className=''] A custom class name to assign to the image. Empty\n * by default.\n * @property {boolean} [pixelated=false] Whether to scale the image with\n * nearest-neighbour interpolation (`image-rendering: pixelated`) instead of smoothing\n * it, so that its pixels stay crisp when zoomed in. Useful for raster data, pixel art\n * or scientific imagery.\n * @property {string} [decoding='auto'] Tells the browser whether to decode the image\n * in a synchronous fashion, as per the\n * [`decoding` HTML attribute](https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/decoding).\n * If the image overlay is flickering when being added/removed, set this option to\n * `'sync'`.\n * @extends InteractiveLayerOptions\n */\n\n/**\n * Used to load and display a single image over specific bounds of the map. Extends `Layer`.\n *\n * @example\n * ```js\n * const imageUrl = 'https://maps.lib.utexas.edu/maps/historical/newark_nj_1922.jpg',\n * \timageBounds = [[40.712216, -74.22655], [40.773941, -74.12544]];\n * new ImageOverlay(imageUrl, imageBounds).addTo(map);\n * ```\n *\n * @fires load {MaplairEvent} Fired when the ImageOverlay layer has loaded its image.\n * @fires error {MaplairEvent} Fired when the ImageOverlay layer fails to load its image.\n */\nexport class ImageOverlay extends Layer {\n\n\tstatic defaultOptions = {\n\t\topacity: 1,\n\t\talt: '',\n\t\tinteractive: false,\n\t\tcrossOrigin: false,\n\t\terrorOverlayUrl: '',\n\t\tzIndex: 1,\n\t\tclassName: '',\n\t\tpixelated: false,\n\t\tdecoding: 'auto'\n\t};\n\n\t/**\n\t * Instantiates an image overlay object given the URL of the image (or an image\n\t * element) and the geographical bounds it is tied to.\n\t * @param {string|HTMLImageElement} url\n\t * @param {LatLngBoundsExpression} bounds\n\t * @param {ImageOverlayOptions} [options]\n\t */\n\tconstructor(url, bounds, options) { // (String, LatLngBounds, Object)\n\t\tsuper();\n\t\tthis._url = url;\n\t\tthis._bounds = new LatLngBounds(bounds);\n\n\t\tUtil.setOptions(this, options);\n\n\t\tthis.callInitHooks(ImageOverlay);\n\t}\n\n\t/**\n\t * Adds the image to the map.\n\t * @type {(map: MaplairMap) => void}\n\t */\n\tonAdd() {\n\t\tif (!this._image) {\n\t\t\tthis._initImage();\n\n\t\t\tif (this.options.opacity < 1) {\n\t\t\t\tthis._updateOpacity();\n\t\t\t}\n\t\t}\n\n\t\tif (this.options.interactive) {\n\t\t\tthis._image.classList.add('maplair-interactive');\n\t\t\tthis.addInteractiveTarget(this._image);\n\t\t}\n\t\tthis._image.classList.toggle('maplair-pixelated', !!this.options.pixelated);\n\n\t\tthis.getPane().appendChild(this._image);\n\t\tthis._reset();\n\t}\n\n\t/**\n\t * Removes the image from the map.\n\t * @type {(map: MaplairMap) => void}\n\t */\n\tonRemove() {\n\t\tthis._image.remove();\n\t\tif (this.options.interactive) {\n\t\t\tthis.removeInteractiveTarget(this._image);\n\t\t}\n\t}\n\n\t_updateInteractive() {\n\t\tthis._image.classList.toggle('maplair-interactive', this.options.interactive);\n\t\tif (this.options.interactive) {\n\t\t\tthis.addInteractiveTarget(this._image);\n\t\t} else {\n\t\t\tthis.removeInteractiveTarget(this._image);\n\t\t}\n\t}\n\n\t/**\n\t * Sets the opacity of the overlay.\n\t * @param {number} opacity\n\t * @returns {this}\n\t */\n\tsetOpacity(opacity) {\n\t\tthis.options.opacity = opacity;\n\n\t\tif (this._image) {\n\t\t\tthis._updateOpacity();\n\t\t}\n\t\treturn this;\n\t}\n\n\t/**\n\t * Sets the opacity of the overlay from the given style options, e.g. by\n\t * `FeatureGroup.setStyle()`.\n\t * @param {{opacity?: number}} styleOpts\n\t * @returns {this}\n\t */\n\tsetStyle(styleOpts) {\n\t\tif (styleOpts.opacity) {\n\t\t\tthis.setOpacity(styleOpts.opacity);\n\t\t}\n\t\treturn this;\n\t}\n\n\t/**\n\t * Brings the layer to the top of all overlays.\n\t * @returns {this}\n\t */\n\tbringToFront() {\n\t\tif (this._map) {\n\t\t\tDomUtil.toFront(this._image);\n\t\t}\n\t\treturn this;\n\t}\n\n\t/**\n\t * Brings the layer to the bottom of all overlays.\n\t * @returns {this}\n\t */\n\tbringToBack() {\n\t\tif (this._map) {\n\t\t\tDomUtil.toBack(this._image);\n\t\t}\n\t\treturn this;\n\t}\n\n\t/**\n\t * Changes the URL of the image.\n\t * @param {string} url\n\t * @returns {this}\n\t */\n\tsetUrl(url) {\n\t\tthis._url = url;\n\n\t\tif (this._image) {\n\t\t\tthis._image.src = url;\n\t\t}\n\t\treturn this;\n\t}\n\n\t/**\n\t * Update the bounds that this ImageOverlay covers.\n\t * @param {LatLngBoundsExpression} bounds\n\t * @returns {this}\n\t */\n\tsetBounds(bounds) {\n\t\tthis._bounds = new LatLngBounds(bounds);\n\n\t\tif (this._map) {\n\t\t\tthis._reset();\n\t\t}\n\t\treturn this;\n\t}\n\n\t/**\n\t * Returns the map events the overlay listens to.\n\t * @returns {Record<string, EventListener>}\n\t */\n\tgetEvents() {\n\t\treturn {\n\t\t\tzoom: this._reset,\n\t\t\tviewreset: this._reset,\n\t\t\tzoomanim: this._animateZoom\n\t\t};\n\t}\n\n\t/**\n\t * Changes the [zIndex](#imageoverlay-zindex) of the image overlay.\n\t * @param {number} value\n\t * @returns {this}\n\t */\n\tsetZIndex(value) {\n\t\tthis.options.zIndex = value;\n\t\tthis._updateZIndex();\n\t\treturn this;\n\t}\n\n\t/**\n\t * Get the bounds that this ImageOverlay covers.\n\t * @returns {LatLngBounds}\n\t */\n\tgetBounds() {\n\t\treturn this._bounds;\n\t}\n\n\t/**\n\t * Returns the instance of\n\t * [`HTMLImageElement`](https://developer.mozilla.org/docs/Web/API/HTMLImageElement)\n\t * used by this overlay (`HTMLVideoElement` for `VideoOverlay`, `SVGElement` for\n\t * `SVGOverlay`).\n\t * @returns {HTMLElement|SVGElement}\n\t */\n\tgetElement() {\n\t\treturn this._image;\n\t}\n\n\t_initImage() {\n\t\tconst wasElementSupplied = this._url instanceof HTMLImageElement;\n\t\tconst img = this._image = wasElementSupplied ? this._url : DomUtil.create('img');\n\n\t\timg.classList.add('maplair-image-layer', 'maplair-zoom-animated');\n\t\tif (this.options.className) { img.classList.add(...Util.splitWords(this.options.className)); }\n\n\t\timg.onload = this.fire.bind(this, 'load');\n\t\timg.onerror = this._overlayOnError.bind(this);\n\n\t\tif (this.options.crossOrigin || this.options.crossOrigin === '') {\n\t\t\timg.crossOrigin = this.options.crossOrigin === true ? '' : this.options.crossOrigin;\n\t\t}\n\n\t\timg.decoding = this.options.decoding;\n\n\t\tif (this.options.zIndex) {\n\t\t\tthis._updateZIndex();\n\t\t}\n\n\t\tif (wasElementSupplied) {\n\t\t\tthis._url = img.src;\n\t\t\treturn;\n\t\t}\n\n\t\timg.src = this._url;\n\t\timg.alt = this.options.alt;\n\t}\n\n\t_animateZoom(e) {\n\t\tconst scale = this._map.getZoomScale(e.zoom),\n\t\toffset = this._map._latLngToNewLayerPoint(this._bounds.getNorthWest(), e.zoom, e.center);\n\n\t\tDomUtil.setTransform(this._image, offset, scale);\n\t}\n\n\t_reset() {\n\t\tconst image = this._image,\n\t\tbounds = new Bounds(\n\t\t\tthis._map.latLngToLayerPoint(this._bounds.getNorthWest())._round(),\n\t\t\tthis._map.latLngToLayerPoint(this._bounds.getSouthEast())._round()),\n\t\tsize = bounds.getSize();\n\n\t\tDomUtil.setPosition(image, bounds.min);\n\n\t\timage.style.width = `${size.x}px`;\n\t\timage.style.height = `${size.y}px`;\n\t}\n\n\t_updateOpacity() {\n\t\tthis._image.style.opacity = `${this.options.opacity}`;\n\t}\n\n\t_updateZIndex() {\n\t\tif (this._image && this.options.zIndex !== undefined && this.options.zIndex !== null) {\n\t\t\tthis._image.style.zIndex = `${this.options.zIndex}`;\n\t\t}\n\t}\n\n\t_overlayOnError() {\n\t\tthis.fire('error');\n\n\t\tconst errorUrl = this.options.errorOverlayUrl;\n\t\tif (errorUrl && this._url !== errorUrl) {\n\t\t\tthis._url = errorUrl;\n\t\t\tthis._image.src = errorUrl;\n\t\t}\n\t}\n\n\t/**\n\t * Returns the center of the ImageOverlay.\n\t * @returns {LatLng}\n\t */\n\tgetCenter() {\n\t\treturn this._bounds.getCenter();\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0DA,IAAa,eAAb,MAAa,qBAAqB,MAAM;CAEvC,OAAO,iBAAiB;EACvB,SAAS;EACT,KAAK;EACL,aAAa;EACb,aAAa;EACb,iBAAiB;EACjB,QAAQ;EACR,WAAW;EACX,WAAW;EACX,UAAU;CACX;;;;;;;;CASA,YAAY,KAAK,QAAQ,SAAS;EACjC,MAAM;EACN,KAAK,OAAO;EACZ,KAAK,UAAU,IAAI,aAAa,MAAM;EAEtC,WAAgB,MAAM,OAAO;EAE7B,KAAK,cAAc,YAAY;CAChC;;;;;CAMA,QAAQ;EACP,IAAI,CAAC,KAAK,QAAQ;GACjB,KAAK,WAAW;GAEhB,IAAI,KAAK,QAAQ,UAAU,GAC1B,KAAK,eAAe;EAEtB;EAEA,IAAI,KAAK,QAAQ,aAAa;GAC7B,KAAK,OAAO,UAAU,IAAI,qBAAqB;GAC/C,KAAK,qBAAqB,KAAK,MAAM;EACtC;EACA,KAAK,OAAO,UAAU,OAAO,qBAAqB,CAAC,CAAC,KAAK,QAAQ,SAAS;EAE1E,KAAK,QAAQ,CAAC,CAAC,YAAY,KAAK,MAAM;EACtC,KAAK,OAAO;CACb;;;;;CAMA,WAAW;EACV,KAAK,OAAO,OAAO;EACnB,IAAI,KAAK,QAAQ,aAChB,KAAK,wBAAwB,KAAK,MAAM;CAE1C;CAEA,qBAAqB;E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AAY,KAAK,SAAS,UAAU;GACvC,KAAK,OAAO;GACZ,KAAK,OAAO,MAAM;EACnB;CACD;;;;;CAMA,YAAY;EACX,OAAO,KAAK,QAAQ,UAAU;CAC/B;AACD"}
|
package/dist/esm/layer/Layer.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { setOptions, stamp } from "../core/Util.js";
|
|
2
2
|
import { Evented } from "../core/Events.js";
|
|
3
|
-
|
|
3
|
+
// src/layer/Layer.js
|
|
4
4
|
/** @import {MaplairMap} from '../map/Map.js' */
|
|
5
5
|
/** @import {LayerGroup} from './LayerGroup.js' */
|
|
6
6
|
/** @import {EventListener, MaplairEvent, MaplairPointerEvent, LayerEvent} from '../core/Events.js' */
|
|
@@ -203,14 +203,12 @@ const mapLayerMethods = {
|
|
|
203
203
|
* @fires remove {MaplairEvent} Fired after the layer is removed from a map.
|
|
204
204
|
*/
|
|
205
205
|
var Layer = class extends Evented {
|
|
206
|
-
static {
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
});
|
|
213
|
-
}
|
|
206
|
+
static defaultOptions = {
|
|
207
|
+
pane: "overlayPane",
|
|
208
|
+
attribution: null,
|
|
209
|
+
attributionOrder: 0,
|
|
210
|
+
bubblingPointerEvents: true
|
|
211
|
+
};
|
|
214
212
|
/**
|
|
215
213
|
* Adds the layer to the given map or layer group.
|
|
216
214
|
* @param {MaplairMap|LayerGroup} map
|
|
@@ -295,9 +293,9 @@ var Layer = class extends Evented {
|
|
|
295
293
|
*/
|
|
296
294
|
setAttribution(attribution) {
|
|
297
295
|
const control = this._map?.attributionControl;
|
|
298
|
-
control?.
|
|
296
|
+
control?._removeLayer({ layer: this });
|
|
299
297
|
setOptions(this, { attribution });
|
|
300
|
-
control?.
|
|
298
|
+
control?._addLayer({ layer: this });
|
|
301
299
|
return this;
|
|
302
300
|
}
|
|
303
301
|
_layerAdd(e) {
|
|
@@ -323,7 +321,6 @@ var Layer = class extends Evented {
|
|
|
323
321
|
MaplairMap.include(mapLayerMethods);
|
|
324
322
|
}
|
|
325
323
|
};
|
|
326
|
-
//#endregion
|
|
327
324
|
export { Layer };
|
|
328
325
|
|
|
329
326
|
//# sourceMappingURL=Layer.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Layer.js","names":["Util.stamp"],"sources":["../../../src/layer/Layer.js"],"sourcesContent":["import {Evented} from '../core/Events.js';\nimport * as Util from '../core/Util.js';\n/** @import {MaplairMap} from '../map/Map.js' */\n/** @import {LayerGroup} from './LayerGroup.js' */\n/** @import {EventListener, MaplairEvent, MaplairPointerEvent, LayerEvent} from '../core/Events.js' */\n\n/**\n * Options of `Layer`, inherited by all layers.\n * @typedef {object} LayerOptions\n * @property {string} [pane='overlayPane'] By default the layer will be added to the\n * map's [overlay pane](#map-pane) (`overlayPane`). Overriding this option will cause the layer\n * to be placed on another pane by default. Not effective if the `renderer` option is\n * set (the `renderer` option will override the `pane` option).\n * @property {string|null} [attribution=null] String to be shown in the attribution\n * control, e.g. \"© OpenStreetMap contributors\". It describes the layer data and is\n * often a legal obligation towards copyright holders and tile providers.\n * @property {number} [attributionOrder=0] The position of the attribution in the\n * attribution control: attributions are sorted by it, then by the order of adding,\n * e.g. `1` keeps a legend last.\n */\n\n/**\n * Options of interactive layers. Some layers can be made interactive - when the user\n * interacts with such a layer, pointer events like `click` and `pointerover` can be\n * handled. Use the [event handling methods](#evented-method) to handle these events.\n * @typedef {object} InteractiveLayerOptions\n * @property {boolean} [interactive=true] If `false`, the layer will not emit pointer\n * events and will act as a part of the underlying map.\n * @property {boolean} [bubblingPointerEvents=true] When `true`, a pointer event on this\n * layer will trigger the same event on the map (unless\n * [`DomEvent.stopPropagation`](#domevent-stoppropagation) is used).\n * @extends LayerOptions\n * @fires Layer#click {MaplairPointerEvent} Fired when the user clicks (or taps) the\n * layer, if it is interactive.\n * @fires Layer#dblclick {MaplairPointerEvent} Fired when the user double-clicks (or\n * double-taps) the layer, if it is interactive.\n * @fires Layer#pointerdown {MaplairPointerEvent} Fired when the user pushes the pointer\n * on the layer, if it is interactive.\n * @fires Layer#pointerup {MaplairPointerEvent} Fired when the user releases the pointer\n * pushed on the layer, if it is interactive.\n * @fires Layer#pointerover {MaplairPointerEvent} Fired when the pointer enters the\n * layer, if it is interactive.\n * @fires Layer#pointerout {MaplairPointerEvent} Fired when the pointer leaves the layer,\n * if it is interactive.\n * @fires Layer#contextmenu {MaplairPointerEvent} Fired when the user right-clicks on\n * the layer, if it is interactive; prevents default browser context menu from showing\n * if there are listeners on this event. Also fired on mobile when the user holds a\n * single touch for a second (also called long press).\n */\n\n/**\n * Methods of `MaplairMap` for layers.\n * @lends MaplairMap.prototype\n * @fires MaplairMap#layeradd {LayerEvent} Fired when a new layer is added to the map.\n * @fires MaplairMap#layerremove {LayerEvent} Fired when some layer is removed from the map.\n * @fires MaplairMap#zoomlevelschange {MaplairEvent} Fired when the number of zoomlevels\n * on the map is changed due to adding or removing a layer.\n */\nconst mapLayerMethods = {\n\t/**\n\t * Adds the given layer to the map.\n\t * @group Methods for layers and controls\n\t * @param {Layer} layer\n\t * @returns {this}\n\t */\n\taddLayer(layer) {\n\t\tif (!layer._layerAdd) {\n\t\t\tthrow new Error('The provided object is not a Layer.');\n\t\t}\n\n\t\tconst id = Util.stamp(layer);\n\t\tif (this._layers[id]) { return this; }\n\t\tthis._layers[id] = layer;\n\n\t\tlayer._mapToAdd = this;\n\n\t\tif (layer.beforeAdd) {\n\t\t\tlayer.beforeAdd(this);\n\t\t}\n\n\t\tthis.whenReady(layer._layerAdd, layer);\n\n\t\treturn this;\n\t},\n\n\t/**\n\t * Removes the given layer from the map.\n\t * @group Methods for layers and controls\n\t * @param {Layer} layer\n\t * @returns {this}\n\t */\n\tremoveLayer(layer) {\n\t\tconst id = Util.stamp(layer);\n\n\t\tif (!this._layers[id]) { return this; }\n\n\t\tif (this._loaded) {\n\t\t\tlayer.onRemove(this);\n\t\t}\n\n\t\tdelete this._layers[id];\n\n\t\tif (this._loaded) {\n\t\t\tthis.fire('layerremove', {layer});\n\t\t\tlayer.fire('remove');\n\t\t}\n\n\t\tlayer._map = layer._mapToAdd = null;\n\n\t\treturn this;\n\t},\n\n\t/**\n\t * Returns `true` if the given layer is currently added to the map.\n\t * @group Methods for layers and controls\n\t * @param {Layer} layer\n\t * @returns {boolean}\n\t */\n\thasLayer(layer) {\n\t\treturn Util.stamp(layer) in this._layers;\n\t},\n\n\t/**\n\t * Iterates over the layers of the map, optionally specifying context of the iterator function.\n\t * ```js\n\t * map.eachLayer(function(layer){\n\t * layer.bindPopup('Hello');\n\t * });\n\t * ```\n\t * @group Methods for layers and controls\n\t * @param {(layer: Layer) => void} method\n\t * @param {object} [context]\n\t * @returns {this}\n\t */\n\teachLayer(method, context) {\n\t\tfor (const layer of Object.values(this._layers)) {\n\t\t\tmethod.call(context, layer);\n\t\t}\n\t\treturn this;\n\t},\n\n\t_addLayers(layers) {\n\t\tlayers = layers ? (Array.isArray(layers) ? layers : [layers]) : [];\n\n\t\tfor (const layer of layers) {\n\t\t\tthis.addLayer(layer);\n\t\t}\n\t},\n\n\t_addZoomLimit(layer) {\n\t\tif (!isNaN(layer.options.maxZoom) || !isNaN(layer.options.minZoom)) {\n\t\t\tthis._zoomBoundLayers[Util.stamp(layer)] = layer;\n\t\t\tthis._updateZoomLevels();\n\t\t}\n\t},\n\n\t_removeZoomLimit(layer) {\n\t\tconst id = Util.stamp(layer);\n\n\t\tif (this._zoomBoundLayers[id]) {\n\t\t\tdelete this._zoomBoundLayers[id];\n\t\t\tthis._updateZoomLevels();\n\t\t}\n\t},\n\n\t_updateZoomLevels() {\n\t\tlet minZoom = Infinity,\n\t\tmaxZoom = -Infinity;\n\t\tconst oldZoomSpan = this._getZoomSpan();\n\n\t\tfor (const l of Object.values(this._zoomBoundLayers)) {\n\t\t\tconst options = l.options;\n\t\t\tminZoom = Math.min(minZoom, options.minZoom ?? Infinity);\n\t\t\tmaxZoom = Math.max(maxZoom, options.maxZoom ?? -Infinity);\n\t\t}\n\n\t\tthis._layersMaxZoom = maxZoom === -Infinity ? undefined : maxZoom;\n\t\tthis._layersMinZoom = minZoom === Infinity ? undefined : minZoom;\n\n\t\tif (oldZoomSpan !== this._getZoomSpan()) {\n\t\t\tthis.fire('zoomlevelschange');\n\t\t}\n\n\t\tif (this.options.maxZoom === undefined && this._layersMaxZoom && this.getZoom() > this._layersMaxZoom) {\n\t\t\tthis.setZoom(this._layersMaxZoom);\n\t\t}\n\t\tif (this.options.minZoom === undefined && this._layersMinZoom && this.getZoom() < this._layersMinZoom) {\n\t\t\tthis.setZoom(this._layersMinZoom);\n\t\t}\n\t}\n};\n/** @typedef {typeof mapLayerMethods} MapLayerMethods */\n\n/**\n * The methods which layers implement, see `Layer`.\n * @typedef {object} LayerExtensionMethods\n * @property {(map: MaplairMap) => void} [onAdd] Should contain code that creates DOM\n * elements for the layer, adds them to `map panes` where they should belong and puts\n * listeners on relevant map events. Called on [`map.addLayer(layer)`](#map-addlayer).\n * @property {(map: MaplairMap) => void} [onRemove] Should contain all clean up code that\n * removes the layer's elements from the DOM and removes listeners previously added in\n * `onAdd`. Called on [`map.removeLayer(layer)`](#map-removelayer).\n * @property {() => Record<string, Function>} [getEvents] Should return an object\n * like `{ viewreset: this._reset }` for [`on`](#evented-on). The event handlers in this\n * object will be automatically added and removed from the map with your layer.\n * @property {() => HTMLElement|string} [getLegend] Should return an element (or a string\n * containing HTML) to be shown on the `LegendControl` whenever the layer is visible.\n * Fire `legendchange` on the layer when the legend changes.\n * @property {(map: MaplairMap) => void} [beforeAdd] Called on\n * [`map.addLayer(layer)`](#map-addlayer), before the layer is added to the map, before\n * events are initialized, without waiting until the map is in a usable state. Use for\n * early initialization only.\n * @lends Layer\n */\n\n/**\n * The base class of all Maplair layers, with the methods they share.\n *\n * Every layer should extend from `Layer` and (re-)implement the following methods:\n *\n * * `onAdd(map: MaplairMap): this` should contain code that creates DOM elements for\n * the layer, adds them to `map panes` where they should belong and puts listeners on\n * relevant map events. Called on [`map.addLayer(layer)`](#map-addlayer).\n * * `onRemove(map: MaplairMap): this` should contain all clean up code that removes the\n * layer's elements from the DOM and removes listeners previously added in `onAdd`.\n * Called on [`map.removeLayer(layer)`](#map-removelayer).\n * * `getEvents(): Object` (optional) should return an object like\n * `{ viewreset: this._reset }` for [`on`](#evented-on). The event handlers in this\n * object will be automatically added and removed from the map with your layer.\n * * `getAttribution(): String` (optional) should return a string containing HTML to be\n * shown on the `Attribution control` whenever the layer is visible.\n * * `getLegend(): HTMLElement|String` (optional) should return an element (or a string\n * containing HTML) to be shown on the `LegendControl` whenever the layer is visible.\n * Fire `legendchange` on the layer when the legend changes.\n * * `beforeAdd(map: MaplairMap): this` (optional) is called on\n * [`map.addLayer(layer)`](#map-addlayer), before the layer is added to the map,\n * before events are initialized, without waiting until the map is in a usable state.\n * Use for early initialization only.\n *\n * @example\n * ```js\n * const layer = new Marker(latlng).addTo(map);\n * layer.addTo(map);\n * layer.remove();\n * ```\n *\n * @fires add {MaplairEvent} Fired after the layer is added to a map.\n * @fires remove {MaplairEvent} Fired after the layer is removed from a map.\n */\nexport class Layer extends Evented {\n\n\tstatic {\n\t\tthis.setDefaultOptions({\n\t\t\tpane: 'overlayPane',\n\t\t\tattribution: null,\n\t\t\tattributionOrder: 0,\n\t\t\tbubblingPointerEvents: true\n\t\t});\n\t}\n\n\t/**\n\t * Adds the layer to the given map or layer group.\n\t * @param {MaplairMap|LayerGroup} map\n\t * @returns {this}\n\t */\n\taddTo(map) {\n\t\tmap.addLayer(this);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Removes the layer from the map it is currently active on.\n\t * @returns {this}\n\t */\n\tremove() {\n\t\treturn this.removeFrom(this._map || this._mapToAdd);\n\t}\n\n\t/**\n\t * Removes the layer from the given map or `LayerGroup`.\n\t * @param {MaplairMap|LayerGroup} obj\n\t * @returns {this}\n\t */\n\tremoveFrom(obj) {\n\t\tobj?.removeLayer(this);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Returns the `HTMLElement` representing the named pane on the map. If `name` is\n\t * omitted, returns the pane for this layer.\n\t * @param {string} [name]\n\t * @returns {HTMLElement}\n\t */\n\tgetPane(name) {\n\t\treturn this._map.getPane(name ? (this.options[name] || name) : this.options.pane);\n\t}\n\n\t/**\n\t * Changes the [`interactive`](#interactivelayeroptions-interactive) option of the\n\t * layer, e.g. to stop a layer from emitting pointer events while it is being edited.\n\t * @param {boolean} interactive\n\t * @returns {this}\n\t */\n\tsetInteractive(interactive) {\n\t\tinteractive = !!interactive;\n\t\tif (this.options.interactive !== interactive) {\n\t\t\tUtil.setOptions(this, {interactive});\n\t\t\tif (this._map) {\n\t\t\t\tthis._updateInteractive();\n\t\t\t}\n\t\t}\n\t\treturn this;\n\t}\n\n\t// Applies a changed `interactive` option to a layer on the map, see `setInteractive()`.\n\t_updateInteractive() {}\n\n\t/**\n\t * Makes `targetEl` a target of pointer events of this layer.\n\t * @internal\n\t * @param {HTMLElement} targetEl\n\t * @returns {this}\n\t */\n\taddInteractiveTarget(targetEl) {\n\t\tthis._map._targets[Util.stamp(targetEl)] = this;\n\t\treturn this;\n\t}\n\n\t/**\n\t * Stops `targetEl` from being a target of pointer events of this layer.\n\t * @internal\n\t * @param {HTMLElement} targetEl\n\t * @returns {this}\n\t */\n\tremoveInteractiveTarget(targetEl) {\n\t\tdelete this._map._targets[Util.stamp(targetEl)];\n\t\treturn this;\n\t}\n\n\t/**\n\t * Used by the `attribution control`, returns the [attribution option](#layeroptions-attribution).\n\t * @returns {string|null}\n\t */\n\tgetAttribution() {\n\t\treturn this.options.attribution;\n\t}\n\n\t/**\n\t * Changes the [attribution option](#layeroptions-attribution), also in the\n\t * attribution control while the layer is on the map.\n\t * @param {string|null} attribution\n\t * @returns {this}\n\t */\n\tsetAttribution(attribution) {\n\t\tconst control = this._map?.attributionControl;\n\t\tcontrol?.removeAttribution(this.getAttribution());\n\t\tUtil.setOptions(this, {attribution});\n\t\tcontrol?.addAttribution(this.getAttribution(), this.options.attributionOrder);\n\t\treturn this;\n\t}\n\n\t_layerAdd(e) {\n\t\tconst map = e.target;\n\n\t\t// check in case layer gets added and then removed before the map is ready\n\t\tif (!map.hasLayer(this)) { return; }\n\n\t\tthis._map = map;\n\t\tthis._zoomAnimated = map._zoomAnimated;\n\n\t\tif (this.getEvents) {\n\t\t\tconst events = this.getEvents();\n\t\t\tmap.on(events, this);\n\t\t\tthis.once('remove', () => map.off(events, this));\n\t\t}\n\n\t\tthis.onAdd(map);\n\n\t\tthis.fire('add');\n\t\tmap.fire('layeradd', {layer: this});\n\t}\n\n\t/**\n\t * Registers this default feature on the map class, called by `MaplairMap` itself.\n\t * @internal\n\t * @param {typeof MaplairMap} MaplairMap\n\t */\n\tstatic register(MaplairMap) {\n\t\tMaplairMap.include(mapLayerMethods);\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0DA,MAAM,kBAAkB;;;;;;;CAOvB,SAAS,OAAO;EACf,IAAI,CAAC,MAAM,WACV,MAAM,IAAI,MAAM,qCAAqC;EAGtD,MAAM,KAAKA,MAAW,KAAK;EAC3B,IAAI,KAAK,QAAQ,KAAO,OAAO;EAC/B,KAAK,QAAQ,MAAM;EAEnB,MAAM,YAAY;EAElB,IAAI,MAAM,WACT,MAAM,UAAU,IAAI;EAGrB,KAAK,UAAU,MAAM,WAAW,KAAK;EAErC,OAAO;CACR;;;;;;;CAQA,YAAY,OAAO;EAClB,MAAM,KAAKA,MAAW,KAAK;EAE3B,IAAI,CAAC,KAAK,QAAQ,KAAO,OAAO;EAEhC,IAAI,KAAK,SACR,MAAM,SAAS,IAAI;EAGpB,OAAO,KAAK,QAAQ;EAEpB,IAAI,KAAK,SAAS;GACjB,KAAK,KAAK,eAAe,EAAC,MAAK,CAAC;GAChC,MAAM,KAAK,QAAQ;EACpB;EAEA,MAAM,OAAO,MAAM,YAAY;EAE/B,OAAO;CACR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BAAgB;EAC5E,OAAO;CACR;CAEA,UAAU,GAAG;EACZ,MAAM,MAAM,EAAE;EAGd,IAAI,CAAC,IAAI,SAAS,IAAI,GAAK;EAE3B,KAAK,OAAO;EACZ,KAAK,gBAAgB,IAAI;EAEzB,IAAI,KAAK,WAAW;GACnB,MAAM,SAAS,KAAK,UAAU;GAC9B,IAAI,GAAG,QAAQ,IAAI;GACnB,KAAK,KAAK,gBAAgB,IAAI,IAAI,QAAQ,IAAI,CAAC;EAChD;EAEA,KAAK,MAAM,GAAG;EAEd,KAAK,KAAK,KAAK;EACf,IAAI,KAAK,YAAY,EAAC,OAAO,KAAI,CAAC;CACnC;;;;;;CAOA,OAAO,SAAS,YAAY;EAC3B,WAAW,QAAQ,eAAe;CACnC;AACD"}
|
|
1
|
+
{"version":3,"file":"Layer.js","names":["Util.stamp"],"sources":["../../../src/layer/Layer.js"],"sourcesContent":["import {Evented} from '../core/Events.js';\nimport * as Util from '../core/Util.js';\n/** @import {MaplairMap} from '../map/Map.js' */\n/** @import {LayerGroup} from './LayerGroup.js' */\n/** @import {EventListener, MaplairEvent, MaplairPointerEvent, LayerEvent} from '../core/Events.js' */\n\n/**\n * Options of `Layer`, inherited by all layers.\n * @typedef {object} LayerOptions\n * @property {string} [pane='overlayPane'] By default the layer will be added to the\n * map's [overlay pane](#map-pane) (`overlayPane`). Overriding this option will cause the layer\n * to be placed on another pane by default. Not effective if the `renderer` option is\n * set (the `renderer` option will override the `pane` option).\n * @property {string|null} [attribution=null] String to be shown in the attribution\n * control, e.g. \"© OpenStreetMap contributors\". It describes the layer data and is\n * often a legal obligation towards copyright holders and tile providers.\n * @property {number} [attributionOrder=0] The position of the attribution in the\n * attribution control: attributions are sorted by it, then by the order of adding,\n * e.g. `1` keeps a legend last.\n */\n\n/**\n * Options of interactive layers. Some layers can be made interactive - when the user\n * interacts with such a layer, pointer events like `click` and `pointerover` can be\n * handled. Use the [event handling methods](#evented-method) to handle these events.\n * @typedef {object} InteractiveLayerOptions\n * @property {boolean} [interactive=true] If `false`, the layer will not emit pointer\n * events and will act as a part of the underlying map.\n * @property {boolean} [bubblingPointerEvents=true] When `true`, a pointer event on this\n * layer will trigger the same event on the map (unless\n * [`DomEvent.stopPropagation`](#domevent-stoppropagation) is used).\n * @extends LayerOptions\n * @fires Layer#click {MaplairPointerEvent} Fired when the user clicks (or taps) the\n * layer, if it is interactive.\n * @fires Layer#dblclick {MaplairPointerEvent} Fired when the user double-clicks (or\n * double-taps) the layer, if it is interactive.\n * @fires Layer#pointerdown {MaplairPointerEvent} Fired when the user pushes the pointer\n * on the layer, if it is interactive.\n * @fires Layer#pointerup {MaplairPointerEvent} Fired when the user releases the pointer\n * pushed on the layer, if it is interactive.\n * @fires Layer#pointerover {MaplairPointerEvent} Fired when the pointer enters the\n * layer, if it is interactive.\n * @fires Layer#pointerout {MaplairPointerEvent} Fired when the pointer leaves the layer,\n * if it is interactive.\n * @fires Layer#contextmenu {MaplairPointerEvent} Fired when the user right-clicks on\n * the layer, if it is interactive; prevents default browser context menu from showing\n * if there are listeners on this event. Also fired on mobile when the user holds a\n * single touch for a second (also called long press).\n */\n\n/**\n * Methods of `MaplairMap` for layers.\n * @lends MaplairMap.prototype\n * @fires MaplairMap#layeradd {LayerEvent} Fired when a new layer is added to the map.\n * @fires MaplairMap#layerremove {LayerEvent} Fired when some layer is removed from the map.\n * @fires MaplairMap#zoomlevelschange {MaplairEvent} Fired when the number of zoomlevels\n * on the map is changed due to adding or removing a layer.\n */\nconst mapLayerMethods = {\n\t/**\n\t * Adds the given layer to the map.\n\t * @group Methods for layers and controls\n\t * @param {Layer} layer\n\t * @returns {this}\n\t */\n\taddLayer(layer) {\n\t\tif (!layer._layerAdd) {\n\t\t\tthrow new Error('The provided object is not a Layer.');\n\t\t}\n\n\t\tconst id = Util.stamp(layer);\n\t\tif (this._layers[id]) { return this; }\n\t\tthis._layers[id] = layer;\n\n\t\tlayer._mapToAdd = this;\n\n\t\tif (layer.beforeAdd) {\n\t\t\tlayer.beforeAdd(this);\n\t\t}\n\n\t\tthis.whenReady(layer._layerAdd, layer);\n\n\t\treturn this;\n\t},\n\n\t/**\n\t * Removes the given layer from the map.\n\t * @group Methods for layers and controls\n\t * @param {Layer} layer\n\t * @returns {this}\n\t */\n\tremoveLayer(layer) {\n\t\tconst id = Util.stamp(layer);\n\n\t\tif (!this._layers[id]) { return this; }\n\n\t\tif (this._loaded) {\n\t\t\tlayer.onRemove(this);\n\t\t}\n\n\t\tdelete this._layers[id];\n\n\t\tif (this._loaded) {\n\t\t\tthis.fire('layerremove', {layer});\n\t\t\tlayer.fire('remove');\n\t\t}\n\n\t\tlayer._map = layer._mapToAdd = null;\n\n\t\treturn this;\n\t},\n\n\t/**\n\t * Returns `true` if the given layer is currently added to the map.\n\t * @group Methods for layers and controls\n\t * @param {Layer} layer\n\t * @returns {boolean}\n\t */\n\thasLayer(layer) {\n\t\treturn Util.stamp(layer) in this._layers;\n\t},\n\n\t/**\n\t * Iterates over the layers of the map, optionally specifying context of the iterator function.\n\t * ```js\n\t * map.eachLayer(function(layer){\n\t * layer.bindPopup('Hello');\n\t * });\n\t * ```\n\t * @group Methods for layers and controls\n\t * @param {(layer: Layer) => void} method\n\t * @param {object} [context]\n\t * @returns {this}\n\t */\n\teachLayer(method, context) {\n\t\tfor (const layer of Object.values(this._layers)) {\n\t\t\tmethod.call(context, layer);\n\t\t}\n\t\treturn this;\n\t},\n\n\t_addLayers(layers) {\n\t\tlayers = layers ? (Array.isArray(layers) ? layers : [layers]) : [];\n\n\t\tfor (const layer of layers) {\n\t\t\tthis.addLayer(layer);\n\t\t}\n\t},\n\n\t_addZoomLimit(layer) {\n\t\tif (!isNaN(layer.options.maxZoom) || !isNaN(layer.options.minZoom)) {\n\t\t\tthis._zoomBoundLayers[Util.stamp(layer)] = layer;\n\t\t\tthis._updateZoomLevels();\n\t\t}\n\t},\n\n\t_removeZoomLimit(layer) {\n\t\tconst id = Util.stamp(layer);\n\n\t\tif (this._zoomBoundLayers[id]) {\n\t\t\tdelete this._zoomBoundLayers[id];\n\t\t\tthis._updateZoomLevels();\n\t\t}\n\t},\n\n\t_updateZoomLevels() {\n\t\tlet minZoom = Infinity,\n\t\tmaxZoom = -Infinity;\n\t\tconst oldZoomSpan = this._getZoomSpan();\n\n\t\tfor (const l of Object.values(this._zoomBoundLayers)) {\n\t\t\tconst options = l.options;\n\t\t\tminZoom = Math.min(minZoom, options.minZoom ?? Infinity);\n\t\t\tmaxZoom = Math.max(maxZoom, options.maxZoom ?? -Infinity);\n\t\t}\n\n\t\tthis._layersMaxZoom = maxZoom === -Infinity ? undefined : maxZoom;\n\t\tthis._layersMinZoom = minZoom === Infinity ? undefined : minZoom;\n\n\t\tif (oldZoomSpan !== this._getZoomSpan()) {\n\t\t\tthis.fire('zoomlevelschange');\n\t\t}\n\n\t\tif (this.options.maxZoom === undefined && this._layersMaxZoom && this.getZoom() > this._layersMaxZoom) {\n\t\t\tthis.setZoom(this._layersMaxZoom);\n\t\t}\n\t\tif (this.options.minZoom === undefined && this._layersMinZoom && this.getZoom() < this._layersMinZoom) {\n\t\t\tthis.setZoom(this._layersMinZoom);\n\t\t}\n\t}\n};\n/** @typedef {typeof mapLayerMethods} MapLayerMethods */\n\n/**\n * The methods which layers implement, see `Layer`.\n * @typedef {object} LayerExtensionMethods\n * @property {(map: MaplairMap) => void} [onAdd] Should contain code that creates DOM\n * elements for the layer, adds them to `map panes` where they should belong and puts\n * listeners on relevant map events. Called on [`map.addLayer(layer)`](#map-addlayer).\n * @property {(map: MaplairMap) => void} [onRemove] Should contain all clean up code that\n * removes the layer's elements from the DOM and removes listeners previously added in\n * `onAdd`. Called on [`map.removeLayer(layer)`](#map-removelayer).\n * @property {() => Record<string, Function>} [getEvents] Should return an object\n * like `{ viewreset: this._reset }` for [`on`](#evented-on). The event handlers in this\n * object will be automatically added and removed from the map with your layer.\n * @property {() => HTMLElement|string} [getLegend] Should return an element (or a string\n * containing HTML) to be shown on the `LegendControl` whenever the layer is visible.\n * Fire `legendchange` on the layer when the legend changes.\n * @property {(map: MaplairMap) => void} [beforeAdd] Called on\n * [`map.addLayer(layer)`](#map-addlayer), before the layer is added to the map, before\n * events are initialized, without waiting until the map is in a usable state. Use for\n * early initialization only.\n * @lends Layer\n */\n\n/**\n * The base class of all Maplair layers, with the methods they share.\n *\n * Every layer should extend from `Layer` and (re-)implement the following methods:\n *\n * * `onAdd(map: MaplairMap): this` should contain code that creates DOM elements for\n * the layer, adds them to `map panes` where they should belong and puts listeners on\n * relevant map events. Called on [`map.addLayer(layer)`](#map-addlayer).\n * * `onRemove(map: MaplairMap): this` should contain all clean up code that removes the\n * layer's elements from the DOM and removes listeners previously added in `onAdd`.\n * Called on [`map.removeLayer(layer)`](#map-removelayer).\n * * `getEvents(): Object` (optional) should return an object like\n * `{ viewreset: this._reset }` for [`on`](#evented-on). The event handlers in this\n * object will be automatically added and removed from the map with your layer.\n * * `getAttribution(): String` (optional) should return a string containing HTML to be\n * shown on the `Attribution control` whenever the layer is visible.\n * * `getLegend(): HTMLElement|String` (optional) should return an element (or a string\n * containing HTML) to be shown on the `LegendControl` whenever the layer is visible.\n * Fire `legendchange` on the layer when the legend changes.\n * * `beforeAdd(map: MaplairMap): this` (optional) is called on\n * [`map.addLayer(layer)`](#map-addlayer), before the layer is added to the map,\n * before events are initialized, without waiting until the map is in a usable state.\n * Use for early initialization only.\n *\n * @example\n * ```js\n * const layer = new Marker(latlng).addTo(map);\n * layer.addTo(map);\n * layer.remove();\n * ```\n *\n * @fires add {MaplairEvent} Fired after the layer is added to a map.\n * @fires remove {MaplairEvent} Fired after the layer is removed from a map.\n */\nexport class Layer extends Evented {\n\n\tstatic defaultOptions = {\n\t\tpane: 'overlayPane',\n\t\tattribution: null,\n\t\tattributionOrder: 0,\n\t\tbubblingPointerEvents: true\n\t};\n\n\t/**\n\t * Adds the layer to the given map or layer group.\n\t * @param {MaplairMap|LayerGroup} map\n\t * @returns {this}\n\t */\n\taddTo(map) {\n\t\tmap.addLayer(this);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Removes the layer from the map it is currently active on.\n\t * @returns {this}\n\t */\n\tremove() {\n\t\treturn this.removeFrom(this._map || this._mapToAdd);\n\t}\n\n\t/**\n\t * Removes the layer from the given map or `LayerGroup`.\n\t * @param {MaplairMap|LayerGroup} obj\n\t * @returns {this}\n\t */\n\tremoveFrom(obj) {\n\t\tobj?.removeLayer(this);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Returns the `HTMLElement` representing the named pane on the map. If `name` is\n\t * omitted, returns the pane for this layer.\n\t * @param {string} [name]\n\t * @returns {HTMLElement}\n\t */\n\tgetPane(name) {\n\t\treturn this._map.getPane(name ? (this.options[name] || name) : this.options.pane);\n\t}\n\n\t/**\n\t * Changes the [`interactive`](#interactivelayeroptions-interactive) option of the\n\t * layer, e.g. to stop a layer from emitting pointer events while it is being edited.\n\t * @param {boolean} interactive\n\t * @returns {this}\n\t */\n\tsetInteractive(interactive) {\n\t\tinteractive = !!interactive;\n\t\tif (this.options.interactive !== interactive) {\n\t\t\tUtil.setOptions(this, {interactive});\n\t\t\tif (this._map) {\n\t\t\t\tthis._updateInteractive();\n\t\t\t}\n\t\t}\n\t\treturn this;\n\t}\n\n\t// Applies a changed `interactive` option to a layer on the map, see `setInteractive()`.\n\t_updateInteractive() {}\n\n\t/**\n\t * Makes `targetEl` a target of pointer events of this layer.\n\t * @internal\n\t * @param {HTMLElement} targetEl\n\t * @returns {this}\n\t */\n\taddInteractiveTarget(targetEl) {\n\t\tthis._map._targets[Util.stamp(targetEl)] = this;\n\t\treturn this;\n\t}\n\n\t/**\n\t * Stops `targetEl` from being a target of pointer events of this layer.\n\t * @internal\n\t * @param {HTMLElement} targetEl\n\t * @returns {this}\n\t */\n\tremoveInteractiveTarget(targetEl) {\n\t\tdelete this._map._targets[Util.stamp(targetEl)];\n\t\treturn this;\n\t}\n\n\t/**\n\t * Used by the `attribution control`, returns the [attribution option](#layeroptions-attribution).\n\t * @returns {string|null}\n\t */\n\tgetAttribution() {\n\t\treturn this.options.attribution;\n\t}\n\n\t/**\n\t * Changes the [attribution option](#layeroptions-attribution), also in the\n\t * attribution control while the layer is on the map.\n\t * @param {string|null} attribution\n\t * @returns {this}\n\t */\n\tsetAttribution(attribution) {\n\t\tconst control = this._map?.attributionControl;\n\t\tcontrol?._removeLayer({layer: this});\n\t\tUtil.setOptions(this, {attribution});\n\t\tcontrol?._addLayer({layer: this});\n\t\treturn this;\n\t}\n\n\t_layerAdd(e) {\n\t\tconst map = e.target;\n\n\t\t// check in case layer gets added and then removed before the map is ready\n\t\tif (!map.hasLayer(this)) { return; }\n\n\t\tthis._map = map;\n\t\tthis._zoomAnimated = map._zoomAnimated;\n\n\t\tif (this.getEvents) {\n\t\t\tconst events = this.getEvents();\n\t\t\tmap.on(events, this);\n\t\t\tthis.once('remove', () => map.off(events, this));\n\t\t}\n\n\t\tthis.onAdd(map);\n\n\t\tthis.fire('add');\n\t\tmap.fire('layeradd', {layer: this});\n\t}\n\n\t/**\n\t * Registers this default feature on the map class, called by `MaplairMap` itself.\n\t * @internal\n\t * @param {typeof MaplairMap} MaplairMap\n\t */\n\tstatic register(MaplairMap) {\n\t\tMaplairMap.include(mapLayerMethods);\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0DA,MAAM,kBAAkB;;;;;;;CAOvB,SAAS,OAAO;EACf,IAAI,CAAC,MAAM,WACV,MAAM,IAAI,MAAM,qCAAqC;EAGtD,MAAM,KAAKA,MAAW,KAAK;EAC3B,IAAI,KAAK,QAAQ,KAAO,OAAO;EAC/B,KAAK,QAAQ,MAAM;EAEnB,MAAM,YAAY;EAElB,IAAI,MAAM,WACT,MAAM,UAAU,IAAI;EAGrB,KAAK,UAAU,MAAM,WAAW,KAAK;EAErC,OAAO;CACR;;;;;;;CAQA,YAAY,OAAO;EAClB,MAAM,KAAKA,MAAW,KAAK;EAE3B,IAAI,CAAC,KAAK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