maplair 4.0.0 → 4.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +118 -0
- package/dist/esm/Maplair.js +14 -14
- package/dist/esm/control/AttributionControl.js +24 -14
- package/dist/esm/control/AttributionControl.js.map +1 -1
- package/dist/esm/control/ButtonControl.js +9 -11
- package/dist/esm/control/ButtonControl.js.map +1 -1
- package/dist/esm/control/ContextMenu.js +1 -3
- package/dist/esm/control/ContextMenu.js.map +1 -1
- package/dist/esm/control/Control.js +9 -16
- package/dist/esm/control/Control.js.map +1 -1
- package/dist/esm/control/FullscreenControl.js +5 -7
- package/dist/esm/control/FullscreenControl.js.map +1 -1
- package/dist/esm/control/LayersControl.js +144 -35
- package/dist/esm/control/LayersControl.js.map +1 -1
- package/dist/esm/control/LegendControl.js +7 -9
- package/dist/esm/control/LegendControl.js.map +1 -1
- package/dist/esm/control/MiniMapControl.js +14 -16
- package/dist/esm/control/MiniMapControl.js.map +1 -1
- package/dist/esm/control/RotateControl.js +1 -3
- package/dist/esm/control/RotateControl.js.map +1 -1
- package/dist/esm/control/ScaleControl.js +7 -9
- package/dist/esm/control/ScaleControl.js.map +1 -1
- package/dist/esm/control/SearchControl.js +99 -17
- package/dist/esm/control/SearchControl.js.map +1 -1
- package/dist/esm/control/SideBySideControl.js +1 -3
- package/dist/esm/control/SideBySideControl.js.map +1 -1
- package/dist/esm/control/TextControl.js +5 -7
- package/dist/esm/control/TextControl.js.map +1 -1
- package/dist/esm/control/TimeControl.js +408 -0
- package/dist/esm/control/TimeControl.js.map +1 -0
- package/dist/esm/control/ZoomControl.js +5 -7
- package/dist/esm/control/ZoomControl.js.map +1 -1
- package/dist/esm/core/Class.js +28 -37
- package/dist/esm/core/Class.js.map +1 -1
- package/dist/esm/core/Events.js +21 -8
- package/dist/esm/core/Events.js.map +1 -1
- package/dist/esm/core/Handler.js +13 -11
- package/dist/esm/core/Handler.js.map +1 -1
- package/dist/esm/core/Util.js +13 -1
- package/dist/esm/core/Util.js.map +1 -1
- package/dist/esm/dom/DomEvent.DoubleTap.js +25 -22
- package/dist/esm/dom/DomEvent.DoubleTap.js.map +1 -1
- package/dist/esm/dom/DomEvent.PointerEvents.js +2 -16
- package/dist/esm/dom/DomEvent.PointerEvents.js.map +1 -1
- package/dist/esm/dom/DomEvent.js +8 -42
- package/dist/esm/dom/DomEvent.js.map +1 -1
- package/dist/esm/dom/DomUtil.js +14 -68
- package/dist/esm/dom/DomUtil.js.map +1 -1
- package/dist/esm/dom/Draggable.js +17 -18
- package/dist/esm/dom/Draggable.js.map +1 -1
- package/dist/esm/dom/PosAnimation.js +3 -25
- package/dist/esm/dom/PosAnimation.js.map +1 -1
- package/dist/esm/geo/LatLng.js +15 -5
- package/dist/esm/geo/LatLng.js.map +1 -1
- package/dist/esm/geo/crs/EPSG3395.js +1 -1
- package/dist/esm/geo/crs/EPSG3395.js.map +1 -1
- package/dist/esm/geo/crs/EPSG3857.js +1 -1
- package/dist/esm/geo/crs/EPSG3857.js.map +1 -1
- package/dist/esm/geo/crs/EPSG4326.js +1 -1
- package/dist/esm/geo/crs/EPSG4326.js.map +1 -1
- package/dist/esm/geo/crs/EarthCRS.js +2 -2
- package/dist/esm/geo/crs/EarthCRS.js.map +1 -1
- package/dist/esm/geo/crs/SimpleCRS.js +1 -1
- package/dist/esm/geo/crs/SimpleCRS.js.map +1 -1
- package/dist/esm/geo/projection/Projection.LonLat.js +1 -1
- package/dist/esm/geo/projection/Projection.LonLat.js.map +1 -1
- package/dist/esm/geo/projection/Projection.Mercator.js +1 -1
- package/dist/esm/geo/projection/Projection.Mercator.js.map +1 -1
- package/dist/esm/geo/projection/Projection.SphericalMercator.js +1 -1
- package/dist/esm/geo/projection/Projection.SphericalMercator.js.map +1 -1
- package/dist/esm/geometry/LineUtil.js +36 -30
- package/dist/esm/geometry/LineUtil.js.map +1 -1
- package/dist/esm/geometry/PolyUtil.js +8 -27
- package/dist/esm/geometry/PolyUtil.js.map +1 -1
- package/dist/esm/layer/BlanketOverlay.js +6 -8
- package/dist/esm/layer/BlanketOverlay.js.map +1 -1
- package/dist/esm/layer/DivOverlay.js +15 -20
- package/dist/esm/layer/DivOverlay.js.map +1 -1
- package/dist/esm/layer/GeoJSON.js +9 -145
- package/dist/esm/layer/GeoJSON.js.map +1 -1
- package/dist/esm/layer/GeoJSONUtil.js +75 -0
- package/dist/esm/layer/GeoJSONUtil.js.map +1 -0
- package/dist/esm/layer/HeatLayer.js +15 -17
- package/dist/esm/layer/HeatLayer.js.map +1 -1
- package/dist/esm/layer/ImageOverlay.js +20 -26
- package/dist/esm/layer/ImageOverlay.js.map +1 -1
- package/dist/esm/layer/Layer.js +8 -10
- package/dist/esm/layer/Layer.js.map +1 -1
- package/dist/esm/layer/LayerGroup.js +51 -0
- package/dist/esm/layer/LayerGroup.js.map +1 -1
- package/dist/esm/layer/Popup.js +26 -42
- package/dist/esm/layer/Popup.js.map +1 -1
- package/dist/esm/layer/SVGOverlay.js +2 -5
- package/dist/esm/layer/SVGOverlay.js.map +1 -1
- package/dist/esm/layer/Tooltip.js +15 -17
- package/dist/esm/layer/Tooltip.js.map +1 -1
- package/dist/esm/layer/VideoOverlay.js +12 -15
- package/dist/esm/layer/VideoOverlay.js.map +1 -1
- package/dist/esm/layer/marker/DefaultIcon.js +15 -48
- package/dist/esm/layer/marker/DefaultIcon.js.map +1 -1
- package/dist/esm/layer/marker/DivIcon.js +7 -9
- package/dist/esm/layer/marker/DivIcon.js.map +1 -1
- package/dist/esm/layer/marker/Icon.js +7 -10
- package/dist/esm/layer/marker/Icon.js.map +1 -1
- package/dist/esm/layer/marker/Marker.Drag.js +1 -1
- package/dist/esm/layer/marker/Marker.Drag.js.map +1 -1
- package/dist/esm/layer/marker/Marker.Move.js +1 -2
- package/dist/esm/layer/marker/Marker.Move.js.map +1 -1
- package/dist/esm/layer/marker/Marker.js +61 -33
- package/dist/esm/layer/marker/Marker.js.map +1 -1
- package/dist/esm/layer/marker/MarkerClusterGroup.js +302 -0
- package/dist/esm/layer/marker/MarkerClusterGroup.js.map +1 -0
- package/dist/esm/layer/marker/SvgIcon.js +6 -8
- package/dist/esm/layer/marker/SvgIcon.js.map +1 -1
- package/dist/esm/layer/tile/GridLayer.js +85 -97
- package/dist/esm/layer/tile/GridLayer.js.map +1 -1
- package/dist/esm/layer/tile/TileLayer.js +28 -36
- package/dist/esm/layer/tile/TileLayer.js.map +1 -1
- package/dist/esm/layer/tile/WMSTileLayer.js +28 -23
- package/dist/esm/layer/tile/WMSTileLayer.js.map +1 -1
- package/dist/esm/layer/vector/Canvas.js +1 -3
- package/dist/esm/layer/vector/Canvas.js.map +1 -1
- package/dist/esm/layer/vector/Circle.js +2 -2
- package/dist/esm/layer/vector/Circle.js.map +1 -1
- package/dist/esm/layer/vector/CircleMarker.js +17 -7
- package/dist/esm/layer/vector/CircleMarker.js.map +1 -1
- package/dist/esm/layer/vector/Path.DashAnimation.js +2 -3
- package/dist/esm/layer/vector/Path.DashAnimation.js.map +1 -1
- package/dist/esm/layer/vector/Path.js +27 -20
- package/dist/esm/layer/vector/Path.js.map +1 -1
- package/dist/esm/layer/vector/Polygon.js +20 -4
- package/dist/esm/layer/vector/Polygon.js.map +1 -1
- package/dist/esm/layer/vector/Polyline.Decorations.js +2 -2
- package/dist/esm/layer/vector/Polyline.js +23 -7
- package/dist/esm/layer/vector/Polyline.js.map +1 -1
- package/dist/esm/layer/vector/Renderer.getRenderer.js +14 -13
- package/dist/esm/layer/vector/Renderer.getRenderer.js.map +1 -1
- package/dist/esm/layer/vector/SVG.js +5 -5
- package/dist/esm/layer/vector/SVG.js.map +1 -1
- package/dist/esm/map/Map.Rotation.js +10 -6
- package/dist/esm/map/Map.Rotation.js.map +1 -1
- package/dist/esm/map/Map.js +116 -110
- package/dist/esm/map/Map.js.map +1 -1
- package/dist/esm/map/handler/BoxZoomHandler.js +5 -7
- package/dist/esm/map/handler/BoxZoomHandler.js.map +1 -1
- package/dist/esm/map/handler/DisplaceHandler.js +6 -8
- package/dist/esm/map/handler/DisplaceHandler.js.map +1 -1
- package/dist/esm/map/handler/DragHandler.js +19 -19
- package/dist/esm/map/handler/DragHandler.js.map +1 -1
- package/dist/esm/map/handler/KeyboardHandler.js +35 -35
- package/dist/esm/map/handler/KeyboardHandler.js.map +1 -1
- package/dist/esm/map/handler/PinchZoomHandler.js +12 -3
- package/dist/esm/map/handler/PinchZoomHandler.js.map +1 -1
- package/dist/esm/map/handler/ScrollWheelZoomHandler.js +3 -4
- package/dist/esm/map/handler/ScrollWheelZoomHandler.js.map +1 -1
- package/dist/esm/map/handler/TapHoldHandler.js +12 -5
- package/dist/esm/map/handler/TapHoldHandler.js.map +1 -1
- package/dist/esm/package.js +1 -1
- package/dist/maplair-global-src.js +8009 -7369
- 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 +10040 -9381
- package/dist/maplair-src.js.map +1 -1
- package/dist/maplair.css +148 -98
- 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 +9 -11
- package/src/control/AttributionControl.js +25 -18
- package/src/control/ButtonControl.js +9 -11
- package/src/control/ContextMenu.js +3 -5
- package/src/control/Control.js +9 -19
- package/src/control/FullscreenControl.js +5 -7
- package/src/control/LayersControl.js +159 -36
- package/src/control/LegendControl.js +7 -9
- package/src/control/MiniMapControl.js +9 -11
- package/src/control/RotateControl.js +3 -5
- package/src/control/ScaleControl.js +7 -9
- package/src/control/SearchControl.js +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 +5 -7
- package/src/control/index.js +1 -0
- package/src/core/Class.js +35 -34
- package/src/core/Events.js +22 -3
- package/src/core/Handler.js +14 -12
- package/src/core/Util.js +19 -1
- package/src/core/index.js +0 -1
- package/src/dom/DomEvent.DoubleTap.js +18 -10
- package/src/dom/DomEvent.PointerEvents.js +3 -26
- package/src/dom/DomEvent.js +8 -66
- package/src/dom/DomUtil.js +22 -78
- package/src/dom/Draggable.js +27 -22
- package/src/dom/PosAnimation.js +3 -25
- package/src/dom/index.js +0 -1
- package/src/geo/LatLng.js +20 -3
- package/src/geo/crs/EPSG3395.js +1 -1
- package/src/geo/crs/EPSG3857.js +1 -1
- package/src/geo/crs/EPSG4326.js +1 -1
- package/src/geo/crs/EarthCRS.js +2 -8
- package/src/geo/crs/SimpleCRS.js +1 -1
- package/src/geo/projection/Projection.LonLat.js +1 -1
- package/src/geo/projection/Projection.Mercator.js +1 -1
- package/src/geo/projection/Projection.SphericalMercator.js +1 -1
- package/src/geometry/LineUtil.js +47 -48
- package/src/geometry/PolyUtil.js +14 -43
- package/src/layer/BlanketOverlay.js +6 -10
- package/src/layer/DivOverlay.js +15 -26
- package/src/layer/GeoJSON.js +7 -205
- package/src/layer/GeoJSONUtil.js +85 -0
- package/src/layer/HeatLayer.js +9 -11
- package/src/layer/ImageOverlay.js +19 -30
- package/src/layer/Layer.js +8 -10
- package/src/layer/LayerGroup.js +71 -0
- package/src/layer/Popup.js +28 -43
- package/src/layer/SVGOverlay.js +1 -5
- package/src/layer/Tooltip.js +15 -19
- package/src/layer/VideoOverlay.js +12 -15
- package/src/layer/marker/DefaultIcon.js +15 -61
- package/src/layer/marker/DivIcon.js +9 -11
- package/src/layer/marker/Icon.js +7 -10
- package/src/layer/marker/Marker.Drag.js +1 -1
- package/src/layer/marker/Marker.Move.js +1 -2
- package/src/layer/marker/Marker.js +81 -39
- 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 +103 -133
- package/src/layer/tile/TileLayer.js +35 -43
- package/src/layer/tile/WMSTileLayer.js +26 -24
- package/src/layer/vector/Canvas.js +3 -5
- package/src/layer/vector/Circle.js +5 -2
- package/src/layer/vector/CircleMarker.js +17 -6
- package/src/layer/vector/Path.DashAnimation.js +1 -2
- package/src/layer/vector/Path.js +30 -21
- package/src/layer/vector/Polygon.js +28 -5
- package/src/layer/vector/Polyline.js +25 -6
- package/src/layer/vector/Renderer.getRenderer.js +17 -17
- package/src/layer/vector/SVG.js +5 -5
- package/src/map/Map.Rotation.js +12 -4
- package/src/map/Map.js +142 -133
- package/src/map/handler/BoxZoomHandler.js +9 -8
- package/src/map/handler/DisplaceHandler.js +6 -8
- package/src/map/handler/DragHandler.js +25 -28
- package/src/map/handler/KeyboardHandler.js +42 -48
- package/src/map/handler/PinchZoomHandler.js +16 -5
- package/src/map/handler/ScrollWheelZoomHandler.js +6 -4
- package/src/map/handler/TapHoldHandler.js +15 -4
- package/src/map/index.js +1 -1
- package/src/maplair.css +148 -98
- package/dist/esm/core/Browser.js +0 -100
- package/dist/esm/core/Browser.js.map +0 -1
- package/dist/images/layers.svg +0 -1
- package/dist/images/marker-icon.svg +0 -1
- package/dist/images/marker-shadow.svg +0 -1
- package/src/core/Browser.js +0 -110
- package/src/images/layers.svg +0 -1
- package/src/images/marker-icon.svg +0 -1
- package/src/images/marker-shadow.svg +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EPSG4326.js","names":[],"sources":["../../../../src/geo/crs/EPSG4326.js"],"sourcesContent":["import {EarthCRS} from './EarthCRS.js';\nimport {LonLat} from '../projection/Projection.LonLat.js';\nimport {Transformation} from '../../geometry/Transformation.js';\n/** @import {Projection} from '../projection/index.js' */\n\n/**\n * A common CRS among GIS enthusiasts. Uses simple Equirectangular projection.\n *\n * Maplair complies with the\n * [TMS coordinate scheme for EPSG:4326](https://wiki.osgeo.org/wiki/Tile_Map_Service_Specification#global-geodetic).\n * If you are using a `TileLayer` with this CRS, ensure that there are two 256x256\n * pixel tiles covering the whole earth at zoom level zero, and that the tile\n * coordinate origin is (-180,+90), or (-180,-90) for `TileLayer`s with\n * [the `tms` option](#tilelayer-tms) set.\n */\nexport class EPSG4326 extends EarthCRS {\n\t/** @type {string} */\n\tstatic code = 'EPSG:4326';\n\t/** @type {Projection} */\n\tstatic projection = LonLat;\n\t/** @type {Transformation} */\n\tstatic transformation = new Transformation(1 / 180, 1, -1 / 180, 0.5);\n}\n"],"mappings":";;;;;;;;;;;;;;;AAeA,IAAa,WAAb,cAA8B,SAAS;;CAEtC,OAAO,OAAO;;CAEd,OAAO,aAAa;;CAEpB,OAAO,
|
|
1
|
+
{"version":3,"file":"EPSG4326.js","names":[],"sources":["../../../../src/geo/crs/EPSG4326.js"],"sourcesContent":["import {EarthCRS} from './EarthCRS.js';\nimport {LonLat} from '../projection/Projection.LonLat.js';\nimport {Transformation} from '../../geometry/Transformation.js';\n/** @import {Projection} from '../projection/index.js' */\n\n/**\n * A common CRS among GIS enthusiasts. Uses simple Equirectangular projection.\n *\n * Maplair complies with the\n * [TMS coordinate scheme for EPSG:4326](https://wiki.osgeo.org/wiki/Tile_Map_Service_Specification#global-geodetic).\n * If you are using a `TileLayer` with this CRS, ensure that there are two 256x256\n * pixel tiles covering the whole earth at zoom level zero, and that the tile\n * coordinate origin is (-180,+90), or (-180,-90) for `TileLayer`s with\n * [the `tms` option](#tilelayer-tms) set.\n */\nexport class EPSG4326 extends EarthCRS {\n\t/** @type {string} */\n\tstatic code = 'EPSG:4326';\n\t/** @type {Projection} */\n\tstatic projection = LonLat;\n\t/** @type {Transformation} */\n\tstatic transformation = /* @__PURE__ */ new Transformation(1 / 180, 1, -1 / 180, 0.5);\n}\n"],"mappings":";;;;;;;;;;;;;;;AAeA,IAAa,WAAb,cAA8B,SAAS;;CAEtC,OAAO,OAAO;;CAEd,OAAO,aAAa;;CAEpB,OAAO,iCAAiC,IAAI,eAAe,IAAI,KAAK,GAAG,KAAK,KAAK,EAAG;AACrF"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { haversineDistance } from "../LatLng.js";
|
|
1
2
|
import { CRS } from "./CRS.js";
|
|
2
3
|
//#region src/geo/crs/EarthCRS.js
|
|
3
4
|
/** @import {LatLng} from '../LatLng.js' */
|
|
@@ -28,8 +29,7 @@ var EarthCRS = class extends CRS {
|
|
|
28
29
|
* @returns {number}
|
|
29
30
|
*/
|
|
30
31
|
static distance(latlng1, latlng2) {
|
|
31
|
-
|
|
32
|
-
return this.R * c;
|
|
32
|
+
return haversineDistance(latlng1, latlng2, this.R);
|
|
33
33
|
}
|
|
34
34
|
};
|
|
35
35
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EarthCRS.js","names":[],"sources":["../../../../src/geo/crs/EarthCRS.js"],"sourcesContent":["import {CRS} from './CRS.js';\n/** @import {LatLng} from '../LatLng.js' */\n\n/**\n * Serves as the base for CRS that are global such that they cover the earth.\n * Can only be used as the base for other CRS and cannot be used directly,\n * since it does not have a `code`, `projection` or `transformation`. `distance()` returns\n * meters.\n */\nexport class EarthCRS extends CRS {\n\t/**\n\t * The range around which the longitude axis wraps.\n\t * @type {[number, number]}\n\t */\n\tstatic wrapLng = [-180, 180];\n\n\t/**\n\t * Mean Earth Radius in meters, as recommended for use by\n\t * the International Union of Geodesy and Geophysics,\n\t * see https://rosettacode.org/wiki/Haversine_formula\n\t * @type {number}\n\t */\n\tstatic R = 6371000;\n\n\t/**\n\t * Returns the distance in meters between two geographical points using the\n\t * Haversine approximation.\n\t * @param {LatLng} latlng1\n\t * @param {LatLng} latlng2\n\t * @returns {number}\n\t */\n\tstatic distance(latlng1, latlng2) {\n\t\
|
|
1
|
+
{"version":3,"file":"EarthCRS.js","names":[],"sources":["../../../../src/geo/crs/EarthCRS.js"],"sourcesContent":["import {CRS} from './CRS.js';\nimport {haversineDistance} from '../LatLng.js';\n/** @import {LatLng} from '../LatLng.js' */\n\n/**\n * Serves as the base for CRS that are global such that they cover the earth.\n * Can only be used as the base for other CRS and cannot be used directly,\n * since it does not have a `code`, `projection` or `transformation`. `distance()` returns\n * meters.\n */\nexport class EarthCRS extends CRS {\n\t/**\n\t * The range around which the longitude axis wraps.\n\t * @type {[number, number]}\n\t */\n\tstatic wrapLng = [-180, 180];\n\n\t/**\n\t * Mean Earth Radius in meters, as recommended for use by\n\t * the International Union of Geodesy and Geophysics,\n\t * see https://rosettacode.org/wiki/Haversine_formula\n\t * @type {number}\n\t */\n\tstatic R = 6371000;\n\n\t/**\n\t * Returns the distance in meters between two geographical points using the\n\t * Haversine approximation.\n\t * @param {LatLng} latlng1\n\t * @param {LatLng} latlng2\n\t * @returns {number}\n\t */\n\tstatic distance(latlng1, latlng2) {\n\t\treturn haversineDistance(latlng1, latlng2, this.R);\n\t}\n}\n"],"mappings":";;;;;;;;;;AAUA,IAAa,WAAb,cAA8B,IAAI;;;;;CAKjC,OAAO,UAAU,CAAC,MAAM,GAAG;;;;;;;CAQ3B,OAAO,IAAI;;;;;;;;CASX,OAAO,SAAS,SAAS,SAAS;EACjC,OAAO,kBAAkB,SAAS,SAAS,KAAK,CAAC;CAClD;AACD"}
|
|
@@ -14,7 +14,7 @@ var SimpleCRS = class extends CRS {
|
|
|
14
14
|
/** @type {Projection} */
|
|
15
15
|
static projection = LonLat;
|
|
16
16
|
/** @type {Transformation} */
|
|
17
|
-
static transformation = new Transformation(1, 0, -1, 0);
|
|
17
|
+
static transformation = /* @__PURE__ */ new Transformation(1, 0, -1, 0);
|
|
18
18
|
/**
|
|
19
19
|
* Returns `2^zoom`.
|
|
20
20
|
* @param {number} zoom
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SimpleCRS.js","names":[],"sources":["../../../../src/geo/crs/SimpleCRS.js"],"sourcesContent":["import {CRS} from './CRS.js';\nimport {LonLat} from '../projection/Projection.LonLat.js';\nimport {Transformation} from '../../geometry/Transformation.js';\n/** @import {LatLng} from '../LatLng.js' */\n/** @import {Projection} from '../projection/index.js' */\n\n/**\n * A simple CRS that maps longitude and latitude into `x` and `y` directly.\n * May be used for maps of flat surfaces (e.g. game maps). Note that the `y`\n * axis should still be inverted (going from bottom to top). `distance()` returns\n * simple euclidean distance.\n */\nexport class SimpleCRS extends CRS {\n\t/** @type {Projection} */\n\tstatic projection = LonLat;\n\t/** @type {Transformation} */\n\tstatic transformation = new Transformation(1, 0, -1, 0);\n\n\t/**\n\t * Returns `2^zoom`.\n\t * @param {number} zoom\n\t * @returns {number}\n\t */\n\tstatic scale(zoom) {\n\t\treturn 2 ** zoom;\n\t}\n\n\t/**\n\t * Inverse of `scale()`.\n\t * @param {number} scale\n\t * @returns {number}\n\t */\n\tstatic zoom(scale) {\n\t\treturn Math.log(scale) / Math.LN2;\n\t}\n\n\t/**\n\t * Returns the euclidean distance between two points.\n\t * @param {LatLng} latlng1\n\t * @param {LatLng} latlng2\n\t * @returns {number}\n\t */\n\tstatic distance(latlng1, latlng2) {\n\t\tconst dx = latlng2.lng - latlng1.lng,\n\t\tdy = latlng2.lat - latlng1.lat;\n\n\t\treturn Math.sqrt(dx * dx + dy * dy);\n\t}\n\n\t/** @type {boolean} */\n\tstatic infinite = true;\n}\n"],"mappings":";;;;;;;;;;;;AAYA,IAAa,YAAb,cAA+B,IAAI;;CAElC,OAAO,aAAa;;CAEpB,OAAO,
|
|
1
|
+
{"version":3,"file":"SimpleCRS.js","names":[],"sources":["../../../../src/geo/crs/SimpleCRS.js"],"sourcesContent":["import {CRS} from './CRS.js';\nimport {LonLat} from '../projection/Projection.LonLat.js';\nimport {Transformation} from '../../geometry/Transformation.js';\n/** @import {LatLng} from '../LatLng.js' */\n/** @import {Projection} from '../projection/index.js' */\n\n/**\n * A simple CRS that maps longitude and latitude into `x` and `y` directly.\n * May be used for maps of flat surfaces (e.g. game maps). Note that the `y`\n * axis should still be inverted (going from bottom to top). `distance()` returns\n * simple euclidean distance.\n */\nexport class SimpleCRS extends CRS {\n\t/** @type {Projection} */\n\tstatic projection = LonLat;\n\t/** @type {Transformation} */\n\tstatic transformation = /* @__PURE__ */ new Transformation(1, 0, -1, 0);\n\n\t/**\n\t * Returns `2^zoom`.\n\t * @param {number} zoom\n\t * @returns {number}\n\t */\n\tstatic scale(zoom) {\n\t\treturn 2 ** zoom;\n\t}\n\n\t/**\n\t * Inverse of `scale()`.\n\t * @param {number} scale\n\t * @returns {number}\n\t */\n\tstatic zoom(scale) {\n\t\treturn Math.log(scale) / Math.LN2;\n\t}\n\n\t/**\n\t * Returns the euclidean distance between two points.\n\t * @param {LatLng} latlng1\n\t * @param {LatLng} latlng2\n\t * @returns {number}\n\t */\n\tstatic distance(latlng1, latlng2) {\n\t\tconst dx = latlng2.lng - latlng1.lng,\n\t\tdy = latlng2.lat - latlng1.lat;\n\n\t\treturn Math.sqrt(dx * dx + dy * dy);\n\t}\n\n\t/** @type {boolean} */\n\tstatic infinite = true;\n}\n"],"mappings":";;;;;;;;;;;;AAYA,IAAa,YAAb,cAA+B,IAAI;;CAElC,OAAO,aAAa;;CAEpB,OAAO,iCAAiC,IAAI,eAAe,GAAG,GAAG,IAAI,CAAC;;;;;;CAOtE,OAAO,MAAM,MAAM;EAClB,OAAO,KAAK;CACb;;;;;;CAOA,OAAO,KAAK,OAAO;EAClB,OAAO,KAAK,IAAI,KAAK,IAAI,KAAK;CAC/B;;;;;;;CAQA,OAAO,SAAS,SAAS,SAAS;EACjC,MAAM,KAAK,QAAQ,MAAM,QAAQ,KACjC,KAAK,QAAQ,MAAM,QAAQ;EAE3B,OAAO,KAAK,KAAK,KAAK,KAAK,KAAK,EAAE;CACnC;;CAGA,OAAO,WAAW;AACnB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Projection.LonLat.js","names":[],"sources":["../../../../src/geo/projection/Projection.LonLat.js"],"sourcesContent":["import {LatLng} from '../LatLng.js';\nimport {Bounds} from '../../geometry/Bounds.js';\nimport {Point} from '../../geometry/Point.js';\n\n/** @import {Projection} from './index.js' */\n\n/**\n * Equirectangular, or Plate Carree projection — the most simple projection,\n * mostly used by GIS enthusiasts. Directly maps `x` as longitude, and `y` as\n * latitude. Also suitable for flat worlds, e.g. game maps. Used by the\n * `EPSG4326` and `SimpleCRS` CRS.\n * @type {Projection}\n */\nexport const LonLat = {\n\tproject(latlng) {\n\t\tlatlng = LatLng.from(latlng);\n\t\treturn new Point(latlng.lng, latlng.lat);\n\t},\n\n\tunproject(point) {\n\t\tpoint = Point.from(point);\n\t\treturn new LatLng(point.y, point.x);\n\t},\n\n\tbounds: new Bounds([-180, -90], [180, 90])\n};\n"],"mappings":";;;;;;;;;;;;AAaA,MAAa,SAAS;CACrB,QAAQ,QAAQ;EACf,SAAS,OAAO,KAAK,MAAM;EAC3B,OAAO,IAAI,MAAM,OAAO,KAAK,OAAO,GAAG;CACxC;CAEA,UAAU,OAAO;EAChB,QAAQ,MAAM,KAAK,KAAK;EACxB,OAAO,IAAI,OAAO,MAAM,GAAG,MAAM,CAAC;CACnC;CAEA,
|
|
1
|
+
{"version":3,"file":"Projection.LonLat.js","names":[],"sources":["../../../../src/geo/projection/Projection.LonLat.js"],"sourcesContent":["import {LatLng} from '../LatLng.js';\nimport {Bounds} from '../../geometry/Bounds.js';\nimport {Point} from '../../geometry/Point.js';\n\n/** @import {Projection} from './index.js' */\n\n/**\n * Equirectangular, or Plate Carree projection — the most simple projection,\n * mostly used by GIS enthusiasts. Directly maps `x` as longitude, and `y` as\n * latitude. Also suitable for flat worlds, e.g. game maps. Used by the\n * `EPSG4326` and `SimpleCRS` CRS.\n * @type {Projection}\n */\nexport const LonLat = {\n\tproject(latlng) {\n\t\tlatlng = LatLng.from(latlng);\n\t\treturn new Point(latlng.lng, latlng.lat);\n\t},\n\n\tunproject(point) {\n\t\tpoint = Point.from(point);\n\t\treturn new LatLng(point.y, point.x);\n\t},\n\n\tbounds: /* @__PURE__ */ new Bounds([-180, -90], [180, 90])\n};\n"],"mappings":";;;;;;;;;;;;AAaA,MAAa,SAAS;CACrB,QAAQ,QAAQ;EACf,SAAS,OAAO,KAAK,MAAM;EAC3B,OAAO,IAAI,MAAM,OAAO,KAAK,OAAO,GAAG;CACxC;CAEA,UAAU,OAAO;EAChB,QAAQ,MAAM,KAAK,KAAK;EACxB,OAAO,IAAI,OAAO,MAAM,GAAG,MAAM,CAAC;CACnC;CAEA,wBAAwB,IAAI,OAAO,CAAC,MAAM,GAAG,GAAG,CAAC,KAAK,EAAE,CAAC;AAC1D"}
|
|
@@ -9,7 +9,7 @@ import { LatLng } from "../LatLng.js";
|
|
|
9
9
|
const Mercator = {
|
|
10
10
|
R: 6378137,
|
|
11
11
|
R_MINOR: 6356752.314245179,
|
|
12
|
-
bounds: new Bounds([-20037508.34279, -15496570.73972], [20037508.34279, 18764656.23138]),
|
|
12
|
+
bounds: /* @__PURE__ */ new Bounds([-20037508.34279, -15496570.73972], [20037508.34279, 18764656.23138]),
|
|
13
13
|
project(latlng) {
|
|
14
14
|
latlng = LatLng.from(latlng);
|
|
15
15
|
const d = Math.PI / 180, r = this.R, tmp = this.R_MINOR / r, e = Math.sqrt(1 - tmp * tmp);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Projection.Mercator.js","names":[],"sources":["../../../../src/geo/projection/Projection.Mercator.js"],"sourcesContent":["import {LatLng} from '../LatLng.js';\nimport {Bounds} from '../../geometry/Bounds.js';\nimport {Point} from '../../geometry/Point.js';\n\n/** @import {Projection} from './index.js' */\n\nconst earthRadius = 6378137;\n\n/**\n * Elliptical Mercator projection — more complex than Spherical Mercator. Assumes that\n * Earth is an ellipsoid. Used by the EPSG:3395 CRS.\n * @type {Projection & {R: number, R_MINOR: number}}\n */\nexport const Mercator = {\n\tR: earthRadius,\n\tR_MINOR: 6356752.314245179,\n\n\tbounds: new Bounds([-20037508.34279, -15496570.73972], [20037508.34279, 18764656.23138]),\n\n\tproject(latlng) {\n\t\tlatlng = LatLng.from(latlng);\n\t\tconst d = Math.PI / 180,\n\t\tr = this.R,\n\t\ttmp = this.R_MINOR / r,\n\t\te = Math.sqrt(1 - tmp * tmp);\n\t\tlet y = latlng.lat * d;\n\t\tconst con = e * Math.sin(y);\n\n\t\tconst ts = Math.tan(Math.PI / 4 - y / 2) / ((1 - con) / (1 + con)) ** (e / 2);\n\t\ty = -r * Math.log(Math.max(ts, 1E-10));\n\n\t\treturn new Point(latlng.lng * d * r, y);\n\t},\n\n\tunproject(point) {\n\t\tpoint = Point.from(point);\n\t\tconst d = 180 / Math.PI,\n\t\tr = this.R,\n\t\ttmp = this.R_MINOR / r,\n\t\te = Math.sqrt(1 - tmp * tmp),\n\t\tts = Math.exp(-point.y / r);\n\t\tlet phi = Math.PI / 2 - 2 * Math.atan(ts);\n\n\t\tfor (let i = 0, dphi = 0.1, con; i < 15 && Math.abs(dphi) > 1e-7; i++) {\n\t\t\tcon = e * Math.sin(phi);\n\t\t\tcon = ((1 - con) / (1 + con)) ** (e / 2);\n\t\t\tdphi = Math.PI / 2 - 2 * Math.atan(ts * con) - phi;\n\t\t\tphi += dphi;\n\t\t}\n\n\t\treturn new LatLng(phi * d, point.x * d / r);\n\t}\n};\n"],"mappings":";;;;;;;;AAaA,MAAa,WAAW;CACvB,GAAG;CACH,SAAS;CAET,
|
|
1
|
+
{"version":3,"file":"Projection.Mercator.js","names":[],"sources":["../../../../src/geo/projection/Projection.Mercator.js"],"sourcesContent":["import {LatLng} from '../LatLng.js';\nimport {Bounds} from '../../geometry/Bounds.js';\nimport {Point} from '../../geometry/Point.js';\n\n/** @import {Projection} from './index.js' */\n\nconst earthRadius = 6378137;\n\n/**\n * Elliptical Mercator projection — more complex than Spherical Mercator. Assumes that\n * Earth is an ellipsoid. Used by the EPSG:3395 CRS.\n * @type {Projection & {R: number, R_MINOR: number}}\n */\nexport const Mercator = {\n\tR: earthRadius,\n\tR_MINOR: 6356752.314245179,\n\n\tbounds: /* @__PURE__ */ new Bounds([-20037508.34279, -15496570.73972], [20037508.34279, 18764656.23138]),\n\n\tproject(latlng) {\n\t\tlatlng = LatLng.from(latlng);\n\t\tconst d = Math.PI / 180,\n\t\tr = this.R,\n\t\ttmp = this.R_MINOR / r,\n\t\te = Math.sqrt(1 - tmp * tmp);\n\t\tlet y = latlng.lat * d;\n\t\tconst con = e * Math.sin(y);\n\n\t\tconst ts = Math.tan(Math.PI / 4 - y / 2) / ((1 - con) / (1 + con)) ** (e / 2);\n\t\ty = -r * Math.log(Math.max(ts, 1E-10));\n\n\t\treturn new Point(latlng.lng * d * r, y);\n\t},\n\n\tunproject(point) {\n\t\tpoint = Point.from(point);\n\t\tconst d = 180 / Math.PI,\n\t\tr = this.R,\n\t\ttmp = this.R_MINOR / r,\n\t\te = Math.sqrt(1 - tmp * tmp),\n\t\tts = Math.exp(-point.y / r);\n\t\tlet phi = Math.PI / 2 - 2 * Math.atan(ts);\n\n\t\tfor (let i = 0, dphi = 0.1, con; i < 15 && Math.abs(dphi) > 1e-7; i++) {\n\t\t\tcon = e * Math.sin(phi);\n\t\t\tcon = ((1 - con) / (1 + con)) ** (e / 2);\n\t\t\tdphi = Math.PI / 2 - 2 * Math.atan(ts * con) - phi;\n\t\t\tphi += dphi;\n\t\t}\n\n\t\treturn new LatLng(phi * d, point.x * d / r);\n\t}\n};\n"],"mappings":";;;;;;;;AAaA,MAAa,WAAW;CACvB,GAAG;CACH,SAAS;CAET,wBAAwB,IAAI,OAAO,CAAC,iBAAiB,eAAe,GAAG,CAAC,gBAAgB,cAAc,CAAC;CAEvG,QAAQ,QAAQ;EACf,SAAS,OAAO,KAAK,MAAM;EAC3B,MAAM,IAAI,KAAK,KAAK,KACpB,IAAI,KAAK,GACT,MAAM,KAAK,UAAU,GACrB,IAAI,KAAK,KAAK,IAAI,MAAM,GAAG;EAC3B,IAAI,IAAI,OAAO,MAAM;EACrB,MAAM,MAAM,IAAI,KAAK,IAAI,CAAC;EAE1B,MAAM,KAAK,KAAK,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,MAAM,IAAI,QAAQ,IAAI,UAAU,IAAI;EAC3E,IAAI,CAAC,IAAI,KAAK,IAAI,KAAK,IAAI,IAAI,KAAK,CAAC;EAErC,OAAO,IAAI,MAAM,OAAO,MAAM,IAAI,GAAG,CAAC;CACvC;CAEA,UAAU,OAAO;EAChB,QAAQ,MAAM,KAAK,KAAK;EACxB,MAAM,IAAI,MAAM,KAAK,IACrB,IAAI,KAAK,GACT,MAAM,KAAK,UAAU,GACrB,IAAI,KAAK,KAAK,IAAI,MAAM,GAAG,GAC3B,KAAK,KAAK,IAAI,CAAC,MAAM,IAAI,CAAC;EAC1B,IAAI,MAAM,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,EAAE;EAExC,KAAK,IAAI,IAAI,GAAG,OAAO,IAAK,KAAK,IAAI,MAAM,KAAK,IAAI,IAAI,IAAI,MAAM,KAAK;GACtE,MAAM,IAAI,KAAK,IAAI,GAAG;GACtB,QAAQ,IAAI,QAAQ,IAAI,UAAU,IAAI;GACtC,OAAO,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,KAAK,GAAG,IAAI;GAC/C,OAAO;EACR;EAEA,OAAO,IAAI,OAAO,MAAM,GAAG,MAAM,IAAI,IAAI,CAAC;CAC3C;AACD"}
|
|
@@ -23,7 +23,7 @@ const SphericalMercator = {
|
|
|
23
23
|
const d = 180 / Math.PI;
|
|
24
24
|
return new LatLng((2 * Math.atan(Math.exp(point.y / this.R)) - Math.PI / 2) * d, point.x * d / this.R);
|
|
25
25
|
},
|
|
26
|
-
bounds: (() => {
|
|
26
|
+
bounds: /* @__PURE__ */ (() => {
|
|
27
27
|
const d = earthRadius * Math.PI;
|
|
28
28
|
return new Bounds([-d, -d], [d, d]);
|
|
29
29
|
})()
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Projection.SphericalMercator.js","names":[],"sources":["../../../../src/geo/projection/Projection.SphericalMercator.js"],"sourcesContent":["import {LatLng} from '../LatLng.js';\nimport {Bounds} from '../../geometry/Bounds.js';\nimport {Point} from '../../geometry/Point.js';\n\n/** @import {Projection} from './index.js' */\n\nconst earthRadius = 6378137;\n\n/**\n * Spherical Mercator projection — the most common projection for online maps,\n * used by almost all free and commercial tile providers. Assumes that Earth is\n * a sphere. Used by the `EPSG:3857` CRS.\n * @type {Projection & {R: number, MAX_LATITUDE: number}}\n */\nexport const SphericalMercator = {\n\n\tR: earthRadius,\n\tMAX_LATITUDE: 85.0511287798,\n\n\tproject(latlng) {\n\t\tlatlng = LatLng.from(latlng);\n\t\tconst d = Math.PI / 180,\n\t\tmax = this.MAX_LATITUDE,\n\t\tlat = Math.max(Math.min(max, latlng.lat), -max),\n\t\tsin = Math.sin(lat * d);\n\n\t\treturn new Point(\n\t\t\tthis.R * latlng.lng * d,\n\t\t\tthis.R * Math.log((1 + sin) / (1 - sin)) / 2);\n\t},\n\n\tunproject(point) {\n\t\tpoint = Point.from(point);\n\t\tconst d = 180 / Math.PI;\n\n\t\treturn new LatLng(\n\t\t\t(2 * Math.atan(Math.exp(point.y / this.R)) - (Math.PI / 2)) * d,\n\t\t\tpoint.x * d / this.R);\n\t},\n\n\tbounds: (() => {\n\t\tconst d = earthRadius * Math.PI;\n\t\treturn new Bounds([-d, -d], [d, d]);\n\t})()\n};\n"],"mappings":";;;;;AAMA,MAAM,cAAc;;;;;;;AAQpB,MAAa,oBAAoB;CAEhC,GAAG;CACH,cAAc;CAEd,QAAQ,QAAQ;EACf,SAAS,OAAO,KAAK,MAAM;EAC3B,MAAM,IAAI,KAAK,KAAK,KACpB,MAAM,KAAK,cACX,MAAM,KAAK,IAAI,KAAK,IAAI,KAAK,OAAO,GAAG,GAAG,CAAC,GAAG,GAC9C,MAAM,KAAK,IAAI,MAAM,CAAC;EAEtB,OAAO,IAAI,MACV,KAAK,IAAI,OAAO,MAAM,GACtB,KAAK,IAAI,KAAK,KAAK,IAAI,QAAQ,IAAI,IAAI,IAAI,CAAC;CAC9C;CAEA,UAAU,OAAO;EAChB,QAAQ,MAAM,KAAK,KAAK;EACxB,MAAM,IAAI,MAAM,KAAK;EAErB,OAAO,IAAI,QACT,IAAI,KAAK,KAAK,KAAK,IAAI,MAAM,IAAI,KAAK,CAAC,CAAC,IAAK,KAAK,KAAK,KAAM,GAC9D,MAAM,IAAI,IAAI,KAAK,CAAC;CACtB;CAEA,
|
|
1
|
+
{"version":3,"file":"Projection.SphericalMercator.js","names":[],"sources":["../../../../src/geo/projection/Projection.SphericalMercator.js"],"sourcesContent":["import {LatLng} from '../LatLng.js';\nimport {Bounds} from '../../geometry/Bounds.js';\nimport {Point} from '../../geometry/Point.js';\n\n/** @import {Projection} from './index.js' */\n\nconst earthRadius = 6378137;\n\n/**\n * Spherical Mercator projection — the most common projection for online maps,\n * used by almost all free and commercial tile providers. Assumes that Earth is\n * a sphere. Used by the `EPSG:3857` CRS.\n * @type {Projection & {R: number, MAX_LATITUDE: number}}\n */\nexport const SphericalMercator = {\n\n\tR: earthRadius,\n\tMAX_LATITUDE: 85.0511287798,\n\n\tproject(latlng) {\n\t\tlatlng = LatLng.from(latlng);\n\t\tconst d = Math.PI / 180,\n\t\tmax = this.MAX_LATITUDE,\n\t\tlat = Math.max(Math.min(max, latlng.lat), -max),\n\t\tsin = Math.sin(lat * d);\n\n\t\treturn new Point(\n\t\t\tthis.R * latlng.lng * d,\n\t\t\tthis.R * Math.log((1 + sin) / (1 - sin)) / 2);\n\t},\n\n\tunproject(point) {\n\t\tpoint = Point.from(point);\n\t\tconst d = 180 / Math.PI;\n\n\t\treturn new LatLng(\n\t\t\t(2 * Math.atan(Math.exp(point.y / this.R)) - (Math.PI / 2)) * d,\n\t\t\tpoint.x * d / this.R);\n\t},\n\n\tbounds: /* @__PURE__ */ (() => {\n\t\tconst d = earthRadius * Math.PI;\n\t\treturn new Bounds([-d, -d], [d, d]);\n\t})()\n};\n"],"mappings":";;;;;AAMA,MAAM,cAAc;;;;;;;AAQpB,MAAa,oBAAoB;CAEhC,GAAG;CACH,cAAc;CAEd,QAAQ,QAAQ;EACf,SAAS,OAAO,KAAK,MAAM;EAC3B,MAAM,IAAI,KAAK,KAAK,KACpB,MAAM,KAAK,cACX,MAAM,KAAK,IAAI,KAAK,IAAI,KAAK,OAAO,GAAG,GAAG,CAAC,GAAG,GAC9C,MAAM,KAAK,IAAI,MAAM,CAAC;EAEtB,OAAO,IAAI,MACV,KAAK,IAAI,OAAO,MAAM,GACtB,KAAK,IAAI,KAAK,KAAK,IAAI,QAAQ,IAAI,IAAI,IAAI,CAAC;CAC9C;CAEA,UAAU,OAAO;EAChB,QAAQ,MAAM,KAAK,KAAK;EACxB,MAAM,IAAI,MAAM,KAAK;EAErB,OAAO,IAAI,QACT,IAAI,KAAK,KAAK,KAAK,IAAI,MAAM,IAAI,KAAK,CAAC,CAAC,IAAK,KAAK,KAAK,KAAM,GAC9D,MAAM,IAAI,IAAI,KAAK,CAAC;CACtB;CAEA,QAAwB,uBAAO;EAC9B,MAAM,IAAI,cAAc,KAAK;EAC7B,OAAO,IAAI,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;CACnC,EAAA,CAAG;AACJ"}
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import { __exportAll } from "../_virtual/_rolldown/runtime.js";
|
|
2
2
|
import { Point } from "./Point.js";
|
|
3
|
-
import { LatLngBounds } from "../geo/LatLngBounds.js";
|
|
4
3
|
import { LatLng } from "../geo/LatLng.js";
|
|
5
|
-
import { centroid } from "./PolyUtil.js";
|
|
6
4
|
//#region src/geometry/LineUtil.js
|
|
7
5
|
var LineUtil_exports = /* @__PURE__ */ __exportAll({
|
|
8
6
|
_getBitCode: () => _getBitCode,
|
|
9
7
|
_getEdgeIntersection: () => _getEdgeIntersection,
|
|
8
|
+
_projectRing: () => _projectRing,
|
|
10
9
|
_sqClosestPointOnSegment: () => _sqClosestPointOnSegment,
|
|
11
10
|
clipSegment: () => clipSegment,
|
|
12
11
|
closestPointOnSegment: () => closestPointOnSegment,
|
|
@@ -107,13 +106,20 @@ let _lastCode;
|
|
|
107
106
|
* @returns {[Point, Point]|false}
|
|
108
107
|
*/
|
|
109
108
|
function clipSegment(a, b, bounds, useLastCode, round) {
|
|
109
|
+
const a0 = a, b0 = b;
|
|
110
110
|
let codeA = useLastCode ? _lastCode : _getBitCode(a, bounds), codeB = _getBitCode(b, bounds), codeOut, p, newCode;
|
|
111
111
|
_lastCode = codeB;
|
|
112
112
|
while (true) {
|
|
113
|
-
if (!(codeA | codeB))
|
|
113
|
+
if (!(codeA | codeB)) {
|
|
114
|
+
if (round) {
|
|
115
|
+
if (a !== a0) a = a.round();
|
|
116
|
+
if (b !== b0) b = b.round();
|
|
117
|
+
}
|
|
118
|
+
return [a, b];
|
|
119
|
+
}
|
|
114
120
|
if (codeA & codeB) return false;
|
|
115
121
|
codeOut = codeA || codeB;
|
|
116
|
-
p = _getEdgeIntersection(a, b, codeOut, bounds
|
|
122
|
+
p = _getEdgeIntersection(a, b, codeOut, bounds);
|
|
117
123
|
newCode = _getBitCode(p, bounds);
|
|
118
124
|
if (codeOut === codeA) {
|
|
119
125
|
a = p;
|
|
@@ -187,38 +193,38 @@ function isFlat(latlngs) {
|
|
|
187
193
|
* @returns {LatLng}
|
|
188
194
|
*/
|
|
189
195
|
function polylineCenter(latlngs, crs) {
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
const bounds = new LatLngBounds(latlngs);
|
|
198
|
-
if (bounds.getNorthWest().distanceTo(bounds.getSouthWest()) * bounds.getNorthEast().distanceTo(bounds.getNorthWest()) < 1700) centroidLatLng = centroid(latlngs);
|
|
199
|
-
const len = latlngs.length;
|
|
200
|
-
const points = [];
|
|
201
|
-
for (i = 0; i < len; i++) {
|
|
202
|
-
const latlng = new LatLng(latlngs[i]);
|
|
203
|
-
points.push(crs.project(new LatLng([latlng.lat - centroidLatLng.lat, latlng.lng - centroidLatLng.lng])));
|
|
204
|
-
}
|
|
205
|
-
for (i = 0, halfDist = 0; i < len - 1; i++) halfDist += points[i].distanceTo(points[i + 1]) / 2;
|
|
206
|
-
if (halfDist === 0) center = points[0];
|
|
207
|
-
else for (i = 0, dist = 0; i < len - 1; i++) {
|
|
208
|
-
p1 = points[i];
|
|
209
|
-
p2 = points[i + 1];
|
|
210
|
-
segDist = p1.distanceTo(p2);
|
|
196
|
+
const points = _projectRing(latlngs, crs), len = points.length;
|
|
197
|
+
let halfDist = 0;
|
|
198
|
+
for (let i = 1; i < len; i++) halfDist += points[i - 1].distanceTo(points[i]);
|
|
199
|
+
halfDist /= 2;
|
|
200
|
+
let center = points[0];
|
|
201
|
+
for (let i = 1, dist = 0; i < len; i++) {
|
|
202
|
+
const p1 = points[i - 1], p2 = points[i], segDist = p1.distanceTo(p2);
|
|
211
203
|
dist += segDist;
|
|
212
204
|
if (dist > halfDist) {
|
|
213
|
-
ratio = (dist - halfDist) / segDist;
|
|
214
|
-
center =
|
|
205
|
+
const ratio = (dist - halfDist) / segDist;
|
|
206
|
+
center = new Point(p2.x - ratio * (p2.x - p1.x), p2.y - ratio * (p2.y - p1.y));
|
|
215
207
|
break;
|
|
216
208
|
}
|
|
217
209
|
}
|
|
218
|
-
|
|
219
|
-
|
|
210
|
+
return crs.unproject(center);
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* Projects the first ring of the given latlngs.
|
|
214
|
+
* @internal
|
|
215
|
+
* @param {LatLngExpression[]|LatLngExpression[][]} latlngs
|
|
216
|
+
* @param {typeof CRS} crs
|
|
217
|
+
* @returns {Point[]}
|
|
218
|
+
*/
|
|
219
|
+
function _projectRing(latlngs, crs) {
|
|
220
|
+
if (!latlngs || latlngs.length === 0) throw new Error("latlngs not passed");
|
|
221
|
+
if (!isFlat(latlngs)) {
|
|
222
|
+
console.warn("latlngs are not flat! Only the first ring will be used");
|
|
223
|
+
latlngs = latlngs[0];
|
|
224
|
+
}
|
|
225
|
+
return latlngs.map((latlng) => crs.project(LatLng.from(latlng)));
|
|
220
226
|
}
|
|
221
227
|
//#endregion
|
|
222
|
-
export { LineUtil_exports, _getBitCode, _getEdgeIntersection, _sqClosestPointOnSegment, clipSegment, closestPointOnSegment, isFlat, pointToSegmentDistance, polylineCenter, simplify };
|
|
228
|
+
export { LineUtil_exports, _getBitCode, _getEdgeIntersection, _projectRing, _sqClosestPointOnSegment, clipSegment, closestPointOnSegment, isFlat, pointToSegmentDistance, polylineCenter, simplify };
|
|
223
229
|
|
|
224
230
|
//# sourceMappingURL=LineUtil.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LineUtil.js","names":[],"sources":["../../../src/geometry/LineUtil.js"],"sourcesContent":["import {Point} from './Point.js';\nimport {LatLng} from '../geo/LatLng.js';\nimport {centroid} from './PolyUtil.js';\nimport {LatLngBounds} from '../geo/LatLngBounds.js';\n/** @import {LatLngExpression} from '../geo/LatLng.js' */\n/** @import {Bounds} from './Bounds.js' */\n/** @import {CRS} from '../geo/crs/CRS.js' */\n\n// LineUtil: various utility functions for polyline points processing, used by Maplair\n// internally to make polylines lightning-fast.\n\n// Simplify polyline with vertex reduction and Douglas-Peucker simplification.\n// Improves rendering performance dramatically by lessening the number of points to draw.\n\n/**\n * Dramatically reduces the number of points in a polyline while retaining\n * its shape and returns a new array of simplified points, using the\n * [Ramer-Douglas-Peucker algorithm](https://en.wikipedia.org/wiki/Ramer-Douglas-Peucker_algorithm).\n * Used for a huge performance boost when processing/displaying Maplair polylines for\n * each zoom level and also reducing visual noise. tolerance affects the amount of\n * simplification (lesser value means higher quality but slower and with more points).\n * Also released as a separated micro-library\n * [Simplify.js](https://mourner.github.io/simplify-js/).\n * @param {Point[]} points\n * @param {number} tolerance\n * @returns {Point[]}\n */\nexport function simplify(points, tolerance) {\n\tif (!tolerance || !points.length) {\n\t\treturn points.slice();\n\t}\n\n\tconst sqTolerance = tolerance * tolerance;\n\n\t// stage 1: vertex reduction\n\tpoints = _reducePoints(points, sqTolerance);\n\n\t// stage 2: Douglas-Peucker simplification\n\tpoints = _simplifyDP(points, sqTolerance);\n\n\treturn points;\n}\n\n/**\n * Returns the distance between point `p` and segment `p1` to `p2`.\n * @param {Point} p\n * @param {Point} p1\n * @param {Point} p2\n * @returns {number}\n */\nexport function pointToSegmentDistance(p, p1, p2) {\n\treturn Math.sqrt(_sqClosestPointOnSegment(p, p1, p2, true));\n}\n\n/**\n * Returns the closest point from a point `p` on a segment `p1` to `p2`.\n * @param {Point} p\n * @param {Point} p1\n * @param {Point} p2\n * @returns {Point}\n */\nexport function closestPointOnSegment(p, p1, p2) {\n\treturn _sqClosestPointOnSegment(p, p1, p2);\n}\n\n// Ramer-Douglas-Peucker simplification, see https://en.wikipedia.org/wiki/Ramer-Douglas-Peucker_algorithm\nfunction _simplifyDP(points, sqTolerance) {\n\n\tconst len = points.length,\n\tmarkers = new Uint8Array(len);\n\tmarkers[0] = markers[len - 1] = 1;\n\n\t_simplifyDPStep(points, markers, sqTolerance, 0, len - 1);\n\n\tlet i;\n\tconst newPoints = [];\n\n\tfor (i = 0; i < len; i++) {\n\t\tif (markers[i]) {\n\t\t\tnewPoints.push(points[i]);\n\t\t}\n\t}\n\n\treturn newPoints;\n}\n\nfunction _simplifyDPStep(points, markers, sqTolerance, first, last) {\n\n\tlet maxSqDist = 0,\n\tindex, i, sqDist;\n\n\tfor (i = first + 1; i <= last - 1; i++) {\n\t\tsqDist = _sqClosestPointOnSegment(points[i], points[first], points[last], true);\n\n\t\tif (sqDist > maxSqDist) {\n\t\t\tindex = i;\n\t\t\tmaxSqDist = sqDist;\n\t\t}\n\t}\n\n\tif (maxSqDist > sqTolerance) {\n\t\tmarkers[index] = 1;\n\n\t\t_simplifyDPStep(points, markers, sqTolerance, first, index);\n\t\t_simplifyDPStep(points, markers, sqTolerance, index, last);\n\t}\n}\n\n// reduce points that are too close to each other to a single point\nfunction _reducePoints(points, sqTolerance) {\n\tconst reducedPoints = [points[0]];\n\tlet prev = 0;\n\n\tfor (let i = 1; i < points.length; i++) {\n\t\tif (_sqDist(points[i], points[prev]) > sqTolerance) {\n\t\t\treducedPoints.push(points[i]);\n\t\t\tprev = i;\n\t\t}\n\t}\n\tif (prev < points.length - 1) {\n\t\treducedPoints.push(points[points.length - 1]);\n\t}\n\treturn reducedPoints;\n}\n\nlet _lastCode;\n\n/**\n * Clips the segment a to b by rectangular bounds with the\n * [Cohen-Sutherland algorithm](https://en.wikipedia.org/wiki/Cohen%E2%80%93Sutherland_algorithm)\n * (modifying the segment points directly!). Used by Maplair to only show polyline\n * points that are on the screen or near, increasing performance. Returns `false` if\n * the segment is outside of the bounds.\n * @param {Point} a\n * @param {Point} b\n * @param {Bounds} bounds\n * @param {boolean} [useLastCode]\n * @param {boolean} [round]\n * @returns {[Point, Point]|false}\n */\nexport function clipSegment(a, b, bounds, useLastCode, round) {\n\tlet codeA = useLastCode ? _lastCode : _getBitCode(a, bounds),\n\tcodeB = _getBitCode(b, bounds),\n\n\tcodeOut, p, newCode;\n\n\t// save 2nd code to avoid calculating it on the next segment\n\t_lastCode = codeB;\n\n\twhile (true) {\n\t\t// if a,b is inside the clip window (trivial accept)\n\t\tif (!(codeA | codeB)) {\n\t\t\treturn [a, b];\n\t\t}\n\n\t\t// if a,b is outside the clip window (trivial reject)\n\t\tif (codeA & codeB) {\n\t\t\treturn false;\n\t\t}\n\n\t\t// other cases\n\t\tcodeOut = codeA || codeB;\n\t\tp = _getEdgeIntersection(a, b, codeOut, bounds, round);\n\t\tnewCode = _getBitCode(p, bounds);\n\n\t\tif (codeOut === codeA) {\n\t\t\ta = p;\n\t\t\tcodeA = newCode;\n\t\t} else {\n\t\t\tb = p;\n\t\t\tcodeB = newCode;\n\t\t}\n\t}\n}\n\nexport function _getEdgeIntersection(a, b, code, bounds, round) {\n\tconst dx = b.x - a.x,\n\tdy = b.y - a.y,\n\tmin = bounds.min,\n\tmax = bounds.max;\n\tlet x, y;\n\n\tif (code & 8) { // top\n\t\tx = a.x + dx * (max.y - a.y) / dy;\n\t\ty = max.y;\n\n\t} else if (code & 4) { // bottom\n\t\tx = a.x + dx * (min.y - a.y) / dy;\n\t\ty = min.y;\n\n\t} else if (code & 2) { // right\n\t\tx = max.x;\n\t\ty = a.y + dy * (max.x - a.x) / dx;\n\n\t} else if (code & 1) { // left\n\t\tx = min.x;\n\t\ty = a.y + dy * (min.x - a.x) / dx;\n\t}\n\n\treturn new Point(x, y, round);\n}\n\nexport function _getBitCode(p, bounds) {\n\tlet code = 0;\n\n\tif (p.x < bounds.min.x) { // left\n\t\tcode |= 1;\n\t} else if (p.x > bounds.max.x) { // right\n\t\tcode |= 2;\n\t}\n\n\tif (p.y < bounds.min.y) { // bottom\n\t\tcode |= 4;\n\t} else if (p.y > bounds.max.y) { // top\n\t\tcode |= 8;\n\t}\n\n\treturn code;\n}\n\n// square distance (to avoid unnecessary Math.sqrt calls)\nfunction _sqDist(p1, p2) {\n\tconst dx = p2.x - p1.x,\n\tdy = p2.y - p1.y;\n\treturn dx * dx + dy * dy;\n}\n\n// return closest point on segment or distance to that point\nexport function _sqClosestPointOnSegment(p, p1, p2, sqDist) {\n\tlet x = p1.x,\n\ty = p1.y,\n\tdx = p2.x - x,\n\tdy = p2.y - y,\n\tt;\n\tconst dot = dx * dx + dy * dy;\n\n\tif (dot > 0) {\n\t\tt = ((p.x - x) * dx + (p.y - y) * dy) / dot;\n\n\t\tif (t > 1) {\n\t\t\tx = p2.x;\n\t\t\ty = p2.y;\n\t\t} else if (t > 0) {\n\t\t\tx += dx * t;\n\t\t\ty += dy * t;\n\t\t}\n\t}\n\n\tdx = p.x - x;\n\tdy = p.y - y;\n\n\treturn sqDist ? dx * dx + dy * dy : new Point(x, y);\n}\n\n\n/**\n * Returns true if `latlngs` is a flat array, false is nested.\n * @param {LatLngExpression[]|LatLngExpression[][]} latlngs\n * @returns {boolean}\n */\nexport function isFlat(latlngs) {\n\treturn !Array.isArray(latlngs[0]) || (typeof latlngs[0][0] !== 'object' && typeof latlngs[0][0] !== 'undefined');\n}\n\n/**\n * Returns the center ([centroid](http://en.wikipedia.org/wiki/Centroid)) of the passed\n * LatLngs (first ring) from a polyline.\n * @param {LatLngExpression[]|LatLngExpression[][]} latlngs\n * @param {typeof CRS} crs\n * @returns {LatLng}\n */\nexport function polylineCenter(latlngs, crs) {\n\tlet i, halfDist, segDist, dist, p1, p2, ratio, center;\n\n\tif (!latlngs || latlngs.length === 0) {\n\t\tthrow new Error('latlngs not passed');\n\t}\n\n\tif (!isFlat(latlngs)) {\n\t\tconsole.warn('latlngs are not flat! Only the first ring will be used');\n\t\tlatlngs = latlngs[0];\n\t}\n\n\tlet centroidLatLng = new LatLng([0, 0]);\n\n\tconst bounds = new LatLngBounds(latlngs);\n\tconst areaBounds = bounds.getNorthWest().distanceTo(bounds.getSouthWest()) * bounds.getNorthEast().distanceTo(bounds.getNorthWest());\n\t// tests showed that below 1700 rounding errors are happening\n\tif (areaBounds < 1700) {\n\t\t// getting a inexact center, to move the latlngs near to [0, 0] to prevent rounding errors\n\t\tcentroidLatLng = centroid(latlngs);\n\t}\n\n\tconst len = latlngs.length;\n\tconst points = [];\n\tfor (i = 0; i < len; i++) {\n\t\tconst latlng = new LatLng(latlngs[i]);\n\t\tpoints.push(crs.project(new LatLng([latlng.lat - centroidLatLng.lat, latlng.lng - centroidLatLng.lng])));\n\t}\n\n\tfor (i = 0, halfDist = 0; i < len - 1; i++) {\n\t\thalfDist += points[i].distanceTo(points[i + 1]) / 2;\n\t}\n\n\t// The line is so small in the current view that all points are on the same pixel.\n\tif (halfDist === 0) {\n\t\tcenter = points[0];\n\t} else {\n\t\tfor (i = 0, dist = 0; i < len - 1; i++) {\n\t\t\tp1 = points[i];\n\t\t\tp2 = points[i + 1];\n\t\t\tsegDist = p1.distanceTo(p2);\n\t\t\tdist += segDist;\n\n\t\t\tif (dist > halfDist) {\n\t\t\t\tratio = (dist - halfDist) / segDist;\n\t\t\t\tcenter = [\n\t\t\t\t\tp2.x - ratio * (p2.x - p1.x),\n\t\t\t\t\tp2.y - ratio * (p2.y - p1.y)\n\t\t\t\t];\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n\tconst latlngCenter = crs.unproject(new Point(center));\n\treturn new LatLng([latlngCenter.lat + centroidLatLng.lat, latlngCenter.lng + centroidLatLng.lng]);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2BA,SAAgB,SAAS,QAAQ,WAAW;CAC3C,IAAI,CAAC,aAAa,CAAC,OAAO,QACzB,OAAO,OAAO,MAAM;CAGrB,MAAM,cAAc,YAAY;CAGhC,SAAS,cAAc,QAAQ,WAAW;CAG1C,SAAS,YAAY,QAAQ,WAAW;CAExC,OAAO;AACR;;;;;;;;AASA,SAAgB,uBAAuB,GAAG,IAAI,IAAI;CACjD,OAAO,KAAK,KAAK,yBAAyB,GAAG,IAAI,IAAI,IAAI,CAAC;AAC3D;;;;;;;;AASA,SAAgB,sBAAsB,GAAG,IAAI,IAAI;CAChD,OAAO,yBAAyB,GAAG,IAAI,EAAE;AAC1C;AAGA,SAAS,YAAY,QAAQ,aAAa;CAEzC,MAAM,MAAM,OAAO,QACnB,UAAU,IAAI,WAAW,GAAG;CAC5B,QAAQ,KAAK,QAAQ,MAAM,KAAK;CAEhC,gBAAgB,QAAQ,SAAS,aAAa,GAAG,MAAM,CAAC;CAExD,IAAI;CACJ,MAAM,YAAY,CAAC;CAEnB,KAAK,IAAI,GAAG,IAAI,KAAK,KACpB,IAAI,QAAQ,IACX,UAAU,KAAK,OAAO,EAAE;CAI1B,OAAO;AACR;AAEA,SAAS,gBAAgB,QAAQ,SAAS,aAAa,OAAO,MAAM;CAEnE,IAAI,YAAY,GAChB,OAAO,GAAG;CAEV,KAAK,IAAI,QAAQ,GAAG,KAAK,OAAO,GAAG,KAAK;EACvC,SAAS,yBAAyB,OAAO,IAAI,OAAO,QAAQ,OAAO,OAAO,IAAI;EAE9E,IAAI,SAAS,WA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AO;EACZ,KAAK,OAAO,IAAI;EAChB,UAAU,GAAG,WAAW,EAAE;EAC1B,QAAQ;EAER,IAAI,OAAO,UAAU;GACpB,SAAS,OAAO,YAAY;GAC5B,SAAS,CACR,GAAG,IAAI,SAAS,GAAG,IAAI,GAAG,IAC1B,GAAG,IAAI,SAAS,GAAG,IAAI,GAAG,EAC3B;GACA;EACD;CACD;CAGD,MAAM,eAAe,IAAI,UAAU,IAAI,MAAM,MAAM,CAAC;CACpD,OAAO,IAAI,OAAO,CAAC,aAAa,MAAM,eAAe,KAAK,aAAa,MAAM,eAAe,GAAG,CAAC;AACjG"}
|
|
1
|
+
{"version":3,"file":"LineUtil.js","names":[],"sources":["../../../src/geometry/LineUtil.js"],"sourcesContent":["import {Point} from './Point.js';\nimport {LatLng} from '../geo/LatLng.js';\n/** @import {LatLngExpression} from '../geo/LatLng.js' */\n/** @import {Bounds} from './Bounds.js' */\n/** @import {CRS} from '../geo/crs/CRS.js' */\n\n// LineUtil: various utility functions for polyline points processing, used by Maplair\n// internally to make polylines lightning-fast.\n\n// Simplify polyline with vertex reduction and Douglas-Peucker simplification.\n// Improves rendering performance dramatically by lessening the number of points to draw.\n\n/**\n * Dramatically reduces the number of points in a polyline while retaining\n * its shape and returns a new array of simplified points, using the\n * [Ramer-Douglas-Peucker algorithm](https://en.wikipedia.org/wiki/Ramer-Douglas-Peucker_algorithm).\n * Used for a huge performance boost when processing/displaying Maplair polylines for\n * each zoom level and also reducing visual noise. tolerance affects the amount of\n * simplification (lesser value means higher quality but slower and with more points).\n * Also released as a separated micro-library\n * [Simplify.js](https://mourner.github.io/simplify-js/).\n * @param {Point[]} points\n * @param {number} tolerance\n * @returns {Point[]}\n */\nexport function simplify(points, tolerance) {\n\tif (!tolerance || !points.length) {\n\t\treturn points.slice();\n\t}\n\n\tconst sqTolerance = tolerance * tolerance;\n\n\t// stage 1: vertex reduction\n\tpoints = _reducePoints(points, sqTolerance);\n\n\t// stage 2: Douglas-Peucker simplification\n\tpoints = _simplifyDP(points, sqTolerance);\n\n\treturn points;\n}\n\n/**\n * Returns the distance between point `p` and segment `p1` to `p2`.\n * @param {Point} p\n * @param {Point} p1\n * @param {Point} p2\n * @returns {number}\n */\nexport function pointToSegmentDistance(p, p1, p2) {\n\treturn Math.sqrt(_sqClosestPointOnSegment(p, p1, p2, true));\n}\n\n/**\n * Returns the closest point from a point `p` on a segment `p1` to `p2`.\n * @param {Point} p\n * @param {Point} p1\n * @param {Point} p2\n * @returns {Point}\n */\nexport function closestPointOnSegment(p, p1, p2) {\n\treturn _sqClosestPointOnSegment(p, p1, p2);\n}\n\n// Ramer-Douglas-Peucker simplification, see https://en.wikipedia.org/wiki/Ramer-Douglas-Peucker_algorithm\nfunction _simplifyDP(points, sqTolerance) {\n\n\tconst len = points.length,\n\tmarkers = new Uint8Array(len);\n\tmarkers[0] = markers[len - 1] = 1;\n\n\t_simplifyDPStep(points, markers, sqTolerance, 0, len - 1);\n\n\tlet i;\n\tconst newPoints = [];\n\n\tfor (i = 0; i < len; i++) {\n\t\tif (markers[i]) {\n\t\t\tnewPoints.push(points[i]);\n\t\t}\n\t}\n\n\treturn newPoints;\n}\n\nfunction _simplifyDPStep(points, markers, sqTolerance, first, last) {\n\n\tlet maxSqDist = 0,\n\tindex, i, sqDist;\n\n\tfor (i = first + 1; i <= last - 1; i++) {\n\t\tsqDist = _sqClosestPointOnSegment(points[i], points[first], points[last], true);\n\n\t\tif (sqDist > maxSqDist) {\n\t\t\tindex = i;\n\t\t\tmaxSqDist = sqDist;\n\t\t}\n\t}\n\n\tif (maxSqDist > sqTolerance) {\n\t\tmarkers[index] = 1;\n\n\t\t_simplifyDPStep(points, markers, sqTolerance, first, index);\n\t\t_simplifyDPStep(points, markers, sqTolerance, index, last);\n\t}\n}\n\n// reduce points that are too close to each other to a single point\nfunction _reducePoints(points, sqTolerance) {\n\tconst reducedPoints = [points[0]];\n\tlet prev = 0;\n\n\tfor (let i = 1; i < points.length; i++) {\n\t\tif (_sqDist(points[i], points[prev]) > sqTolerance) {\n\t\t\treducedPoints.push(points[i]);\n\t\t\tprev = i;\n\t\t}\n\t}\n\tif (prev < points.length - 1) {\n\t\treducedPoints.push(points[points.length - 1]);\n\t}\n\treturn reducedPoints;\n}\n\nlet _lastCode;\n\n/**\n * Clips the segment a to b by rectangular bounds with the\n * [Cohen-Sutherland algorithm](https://en.wikipedia.org/wiki/Cohen%E2%80%93Sutherland_algorithm)\n * (modifying the segment points directly!). Used by Maplair to only show polyline\n * points that are on the screen or near, increasing performance. Returns `false` if\n * the segment is outside of the bounds.\n * @param {Point} a\n * @param {Point} b\n * @param {Bounds} bounds\n * @param {boolean} [useLastCode]\n * @param {boolean} [round]\n * @returns {[Point, Point]|false}\n */\nexport function clipSegment(a, b, bounds, useLastCode, round) {\n\tconst a0 = a, b0 = b;\n\tlet codeA = useLastCode ? _lastCode : _getBitCode(a, bounds),\n\tcodeB = _getBitCode(b, bounds),\n\n\tcodeOut, p, newCode;\n\n\t// save 2nd code to avoid calculating it on the next segment\n\t_lastCode = codeB;\n\n\twhile (true) {\n\t\t// if a,b is inside the clip window (trivial accept)\n\t\tif (!(codeA | codeB)) {\n\t\t\t// round only the endpoints that were replaced by a clipped intersection;\n\t\t\t// rounding while iterating can push a point back outside and loop forever\n\t\t\tif (round) {\n\t\t\t\tif (a !== a0) { a = a.round(); }\n\t\t\t\tif (b !== b0) { b = b.round(); }\n\t\t\t}\n\t\t\treturn [a, b];\n\t\t}\n\n\t\t// if a,b is outside the clip window (trivial reject)\n\t\tif (codeA & codeB) {\n\t\t\treturn false;\n\t\t}\n\n\t\t// other cases\n\t\tcodeOut = codeA || codeB;\n\t\tp = _getEdgeIntersection(a, b, codeOut, bounds);\n\t\tnewCode = _getBitCode(p, bounds);\n\n\t\tif (codeOut === codeA) {\n\t\t\ta = p;\n\t\t\tcodeA = newCode;\n\t\t} else {\n\t\t\tb = p;\n\t\t\tcodeB = newCode;\n\t\t}\n\t}\n}\n\nexport function _getEdgeIntersection(a, b, code, bounds, round) {\n\tconst dx = b.x - a.x,\n\tdy = b.y - a.y,\n\tmin = bounds.min,\n\tmax = bounds.max;\n\tlet x, y;\n\n\tif (code & 8) { // top\n\t\tx = a.x + dx * (max.y - a.y) / dy;\n\t\ty = max.y;\n\n\t} else if (code & 4) { // bottom\n\t\tx = a.x + dx * (min.y - a.y) / dy;\n\t\ty = min.y;\n\n\t} else if (code & 2) { // right\n\t\tx = max.x;\n\t\ty = a.y + dy * (max.x - a.x) / dx;\n\n\t} else if (code & 1) { // left\n\t\tx = min.x;\n\t\ty = a.y + dy * (min.x - a.x) / dx;\n\t}\n\n\treturn new Point(x, y, round);\n}\n\nexport function _getBitCode(p, bounds) {\n\tlet code = 0;\n\n\tif (p.x < bounds.min.x) { // left\n\t\tcode |= 1;\n\t} else if (p.x > bounds.max.x) { // right\n\t\tcode |= 2;\n\t}\n\n\tif (p.y < bounds.min.y) { // bottom\n\t\tcode |= 4;\n\t} else if (p.y > bounds.max.y) { // top\n\t\tcode |= 8;\n\t}\n\n\treturn code;\n}\n\n// square distance (to avoid unnecessary Math.sqrt calls)\nfunction _sqDist(p1, p2) {\n\tconst dx = p2.x - p1.x,\n\tdy = p2.y - p1.y;\n\treturn dx * dx + dy * dy;\n}\n\n// return closest point on segment or distance to that point\nexport function _sqClosestPointOnSegment(p, p1, p2, sqDist) {\n\tlet x = p1.x,\n\ty = p1.y,\n\tdx = p2.x - x,\n\tdy = p2.y - y,\n\tt;\n\tconst dot = dx * dx + dy * dy;\n\n\tif (dot > 0) {\n\t\tt = ((p.x - x) * dx + (p.y - y) * dy) / dot;\n\n\t\tif (t > 1) {\n\t\t\tx = p2.x;\n\t\t\ty = p2.y;\n\t\t} else if (t > 0) {\n\t\t\tx += dx * t;\n\t\t\ty += dy * t;\n\t\t}\n\t}\n\n\tdx = p.x - x;\n\tdy = p.y - y;\n\n\treturn sqDist ? dx * dx + dy * dy : new Point(x, y);\n}\n\n\n/**\n * Returns true if `latlngs` is a flat array, false is nested.\n * @param {LatLngExpression[]|LatLngExpression[][]} latlngs\n * @returns {boolean}\n */\nexport function isFlat(latlngs) {\n\treturn !Array.isArray(latlngs[0]) || (typeof latlngs[0][0] !== 'object' && typeof latlngs[0][0] !== 'undefined');\n}\n\n/**\n * Returns the center ([centroid](http://en.wikipedia.org/wiki/Centroid)) of the passed\n * LatLngs (first ring) from a polyline.\n * @param {LatLngExpression[]|LatLngExpression[][]} latlngs\n * @param {typeof CRS} crs\n * @returns {LatLng}\n */\nexport function polylineCenter(latlngs, crs) {\n\tconst points = _projectRing(latlngs, crs),\n\tlen = points.length;\n\n\tlet halfDist = 0;\n\tfor (let i = 1; i < len; i++) {\n\t\thalfDist += points[i - 1].distanceTo(points[i]);\n\t}\n\thalfDist /= 2;\n\n\t// if the line has zero length, the loop below never finds a segment and the first point is the center\n\tlet center = points[0];\n\n\tfor (let i = 1, dist = 0; i < len; i++) {\n\t\tconst p1 = points[i - 1],\n\t\tp2 = points[i],\n\t\tsegDist = p1.distanceTo(p2);\n\t\tdist += segDist;\n\n\t\tif (dist > halfDist) {\n\t\t\tconst ratio = (dist - halfDist) / segDist;\n\t\t\tcenter = new Point(\n\t\t\t\tp2.x - ratio * (p2.x - p1.x),\n\t\t\t\tp2.y - ratio * (p2.y - p1.y)\n\t\t\t);\n\t\t\tbreak;\n\t\t}\n\t}\n\n\treturn crs.unproject(center);\n}\n\n/**\n * Projects the first ring of the given latlngs.\n * @internal\n * @param {LatLngExpression[]|LatLngExpression[][]} latlngs\n * @param {typeof CRS} crs\n * @returns {Point[]}\n */\nexport function _projectRing(latlngs, crs) {\n\tif (!latlngs || latlngs.length === 0) {\n\t\tthrow new Error('latlngs not passed');\n\t}\n\n\tif (!isFlat(latlngs)) {\n\t\tconsole.warn('latlngs are not flat! Only the first ring will be used');\n\t\tlatlngs = latlngs[0];\n\t}\n\n\treturn latlngs.map(latlng => crs.project(LatLng.from(latlng)));\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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AC/B,OAAO,CAAC,MAAM,QAAQ,QAAQ,EAAE,KAAM,OAAO,QAAQ,EAAE,CAAC,OAAO,YAAY,OAAO,QAAQ,EAAE,CAAC,OAAO;AACrG;;;;;;;;AASA,SAAgB,eAAe,SAAS,KAAK;CAC5C,MAAM,SAAS,aAAa,SAAS,GAAG,GACxC,MAAM,OAAO;CAEb,IAAI,WAAW;CACf,KAAK,IAAI,IAAI,GAAG,IAAI,KAAK,KACxB,YAAY,OAAO,IAAI,EAAE,CAAC,WAAW,OAAO,EAAE;CAE/C,YAAY;CAGZ,IAAI,SAAS,OAAO;CAEpB,KAAK,IAAI,IAAI,GAAG,OAAO,GAAG,IAAI,KAAK,KAAK;EACvC,MAAM,KAAK,OAAO,IAAI,IACtB,KAAK,OAAO,IACZ,UAAU,GAAG,WAAW,EAAE;EAC1B,QAAQ;EAER,IAAI,OAAO,UAAU;GACpB,MAAM,SAAS,OAAO,YAAY;GAClC,SAAS,IAAI,MACZ,GAAG,IAAI,SAAS,GAAG,IAAI,GAAG,IAC1B,GAAG,IAAI,SAAS,GAAG,IAAI,GAAG,EAC3B;GACA;EACD;CACD;CAEA,OAAO,IAAI,UAAU,MAAM;AAC5B;;;;;;;;AASA,SAAgB,aAAa,SAAS,KAAK;CAC1C,IAAI,CAAC,WAAW,QAAQ,WAAW,GAClC,MAAM,IAAI,MAAM,oBAAoB;CAGrC,IAAI,CAAC,OAAO,OAAO,GAAG;EACrB,QAAQ,KAAK,wDAAwD;EACrE,UAAU,QAAQ;CACnB;CAEA,OAAO,QAAQ,KAAI,WAAU,IAAI,QAAQ,OAAO,KAAK,MAAM,CAAC,CAAC;AAC9D"}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { __exportAll } from "../_virtual/_rolldown/runtime.js";
|
|
2
2
|
import { Point } from "./Point.js";
|
|
3
|
-
import { LatLngBounds } from "../geo/LatLngBounds.js";
|
|
4
3
|
import { LatLng } from "../geo/LatLng.js";
|
|
5
|
-
import { _getBitCode, _getEdgeIntersection,
|
|
4
|
+
import { _getBitCode, _getEdgeIntersection, _projectRing } from "./LineUtil.js";
|
|
6
5
|
//#region src/geometry/PolyUtil.js
|
|
7
6
|
var PolyUtil_exports = /* @__PURE__ */ __exportAll({
|
|
8
7
|
centroid: () => centroid,
|
|
@@ -63,34 +62,16 @@ function clipPolygon(points, bounds, round) {
|
|
|
63
62
|
* @returns {LatLng}
|
|
64
63
|
*/
|
|
65
64
|
function polygonCenter(latlngs, crs) {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
}
|
|
72
|
-
let centroidLatLng = new LatLng([0, 0]);
|
|
73
|
-
const bounds = new LatLngBounds(latlngs);
|
|
74
|
-
if (bounds.getNorthWest().distanceTo(bounds.getSouthWest()) * bounds.getNorthEast().distanceTo(bounds.getNorthWest()) < 1700) centroidLatLng = centroid(latlngs);
|
|
75
|
-
const len = latlngs.length;
|
|
76
|
-
const points = [];
|
|
77
|
-
for (i = 0; i < len; i++) {
|
|
78
|
-
const latlng = new LatLng(latlngs[i]);
|
|
79
|
-
points.push(crs.project(new LatLng([latlng.lat - centroidLatLng.lat, latlng.lng - centroidLatLng.lng])));
|
|
80
|
-
}
|
|
81
|
-
area = x = y = 0;
|
|
82
|
-
for (i = 0, j = len - 1; i < len; j = i++) {
|
|
83
|
-
p1 = points[i];
|
|
84
|
-
p2 = points[j];
|
|
85
|
-
f = p1.y * p2.x - p2.y * p1.x;
|
|
65
|
+
const points = _projectRing(latlngs, crs), origin = new Point(points[0]), len = points.length;
|
|
66
|
+
for (const p of points) p._subtract(origin);
|
|
67
|
+
let area = 0, x = 0, y = 0;
|
|
68
|
+
for (let i = 0, j = len - 1; i < len; j = i++) {
|
|
69
|
+
const p1 = points[i], p2 = points[j], f = p1.y * p2.x - p2.y * p1.x;
|
|
86
70
|
x += (p1.x + p2.x) * f;
|
|
87
71
|
y += (p1.y + p2.y) * f;
|
|
88
|
-
area += f
|
|
72
|
+
area += f;
|
|
89
73
|
}
|
|
90
|
-
|
|
91
|
-
else center = [x / area, y / area];
|
|
92
|
-
const latlngCenter = crs.unproject(new Point(center));
|
|
93
|
-
return new LatLng([latlngCenter.lat + centroidLatLng.lat, latlngCenter.lng + centroidLatLng.lng]);
|
|
74
|
+
return crs.unproject(area === 0 ? origin : new Point(x / (3 * area), y / (3 * area))._add(origin));
|
|
94
75
|
}
|
|
95
76
|
/**
|
|
96
77
|
* Returns the 'center of mass' of the passed LatLngs.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PolyUtil.js","names":["LineUtil._getBitCode","LineUtil._getEdgeIntersection","LineUtil.
|
|
1
|
+
{"version":3,"file":"PolyUtil.js","names":["LineUtil._getBitCode","LineUtil._getEdgeIntersection","LineUtil._projectRing"],"sources":["../../../src/geometry/PolyUtil.js"],"sourcesContent":["import * as LineUtil from './LineUtil.js';\nimport {LatLng} from '../geo/LatLng.js';\nimport {Point} from './Point.js';\n/** @import {LatLngExpression} from '../geo/LatLng.js' */\n/** @import {Bounds} from './Bounds.js' */\n/** @import {CRS} from '../geo/crs/CRS.js' */\n\n// PolyUtil: various utility functions for polygon geometries.\n\n/**\n * Clips the polygon geometry defined by the given `points` by the given bounds (using\n * the [Sutherland-Hodgman algorithm](https://en.wikipedia.org/wiki/Sutherland%E2%80%93Hodgman_algorithm)).\n * Used by Maplair to only show polygon points that are on the screen or near, increasing\n * performance. Note that polygon points needs different algorithm for clipping\n * than polyline, so there's a separate method for it.\n * @param {Point[]} points\n * @param {Bounds} bounds\n * @param {boolean} [round]\n * @returns {Point[]}\n */\nexport function clipPolygon(points, bounds, round) {\n\tlet clippedPoints,\n\ti, j, k,\n\ta, b,\n\tlen, edge, p;\n\tconst edges = [1, 4, 2, 8];\n\n\tfor (i = 0, len = points.length; i < len; i++) {\n\t\tpoints[i]._code = LineUtil._getBitCode(points[i], bounds);\n\t}\n\n\t// for each edge (left, bottom, right, top)\n\tfor (k = 0; k < 4; k++) {\n\t\tedge = edges[k];\n\t\tclippedPoints = [];\n\n\t\tfor (i = 0, len = points.length, j = len - 1; i < len; j = i++) {\n\t\t\ta = points[i];\n\t\t\tb = points[j];\n\n\t\t\t// if a is inside the clip window\n\t\t\tif (!(a._code & edge)) {\n\t\t\t\t// if b is outside the clip window (a->b goes out of screen)\n\t\t\t\tif (b._code & edge) {\n\t\t\t\t\tp = LineUtil._getEdgeIntersection(b, a, edge, bounds, round);\n\t\t\t\t\tp._code = LineUtil._getBitCode(p, bounds);\n\t\t\t\t\tclippedPoints.push(p);\n\t\t\t\t}\n\t\t\t\tclippedPoints.push(a);\n\n\t\t\t// else if b is inside the clip window (a->b enters the screen)\n\t\t\t} else if (!(b._code & edge)) {\n\t\t\t\tp = LineUtil._getEdgeIntersection(b, a, edge, bounds, round);\n\t\t\t\tp._code = LineUtil._getBitCode(p, bounds);\n\t\t\t\tclippedPoints.push(p);\n\t\t\t}\n\t\t}\n\t\tpoints = clippedPoints;\n\t}\n\n\treturn points;\n}\n\n/**\n * Returns the center ([centroid](http://en.wikipedia.org/wiki/Centroid)) of the passed\n * LatLngs (first ring) from a polygon.\n * @param {LatLngExpression[]|LatLngExpression[][]} latlngs\n * @param {typeof CRS} crs\n * @returns {LatLng}\n */\nexport function polygonCenter(latlngs, crs) {\n\t// points relative to the first one, to avoid floating point errors on tiny polygons with large projected coordinates\n\tconst points = LineUtil._projectRing(latlngs, crs),\n\torigin = new Point(points[0]),\n\tlen = points.length;\n\n\tfor (const p of points) { p._subtract(origin); }\n\n\tlet area = 0, x = 0, y = 0;\n\n\t// polygon centroid algorithm\n\tfor (let i = 0, j = len - 1; i < len; j = i++) {\n\t\tconst p1 = points[i],\n\t\tp2 = points[j],\n\t\tf = p1.y * p2.x - p2.y * p1.x;\n\n\t\tx += (p1.x + p2.x) * f;\n\t\ty += (p1.y + p2.y) * f;\n\t\tarea += f;\n\t}\n\n\t// area is 0 when the polygon is so small that all points are on the same pixel\n\treturn crs.unproject(area === 0 ? origin : new Point(x / (3 * area), y / (3 * area))._add(origin));\n}\n\n/**\n * Returns the 'center of mass' of the passed LatLngs.\n * @param {LatLngExpression[]} coords\n * @returns {LatLng}\n */\nexport function centroid(coords) {\n\tlet latSum = 0;\n\tlet lngSum = 0;\n\tlet len = 0;\n\tfor (const coord of coords) {\n\t\tconst latlng = LatLng.from(coord);\n\t\tlatSum += latlng.lat;\n\t\tlngSum += latlng.lng;\n\t\tlen++;\n\t}\n\treturn new LatLng([latSum / len, lngSum / len]);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAoBA,SAAgB,YAAY,QAAQ,QAAQ,OAAO;CAClD,IAAI,eACJ,GAAG,GAAG,GACN,GAAG,GACH,KAAK,MAAM;CACX,MAAM,QAAQ;EAAC;EAAG;EAAG;EAAG;CAAC;CAEzB,KAAK,IAAI,GAAG,MAAM,OAAO,QAAQ,IAAI,KAAK,KACzC,OAAO,EAAE,CAAC,QAAQA,YAAqB,OAAO,IAAI,MAAM;CAIzD,KAAK,IAAI,GAAG,IAAI,GAAG,KAAK;EACvB,OAAO,MAAM;EACb,gBAAgB,CAAC;EAEjB,KAAK,IAAI,GAAG,MAAM,OAAO,QAAQ,IAAI,MAAM,GAAG,IAAI,KAAK,IAAI,KAAK;GAC/D,IAAI,OAAO;GACX,IAAI,OAAO;GAGX,IAAI,EAAE,EAAE,QAAQ,OAAO;IAEtB,IAAI,EAAE,QAAQ,MAAM;KACnB,IAAIC,qBAA8B,GAAG,GAAG,MAAM,QAAQ,KAAK;KAC3D,EAAE,QAAQD,YAAqB,GAAG,MAAM;KACxC,cAAc,KAAK,CAAC;IACrB;IACA,cAAc,KAAK,CAAC;GAGrB,OAAO,IAAI,EAAE,EAAE,QAAQ,OAAO;IAC7B,IAAIC,qBAA8B,GAAG,GAAG,MAAM,QAAQ,KAAK;IAC3D,EAAE,QAAQD,YAAqB,GAAG,MAAM;IACxC,cAAc,KAAK,CAAC;GACrB;EACD;EACA,SAAS;CACV;CAEA,OAAO;AACR;;;;;;;;AASA,SAAgB,cAAc,SAAS,KAAK;CAE3C,MAAM,SAASE,aAAsB,SAAS,GAAG,GACjD,SAAS,IAAI,MAAM,OAAO,EAAE,GAC5B,MAAM,OAAO;CAEb,KAAK,MAAM,KAAK,QAAU,EAAE,UAAU,MAAM;CAE5C,IAAI,OAAO,GAAG,IAAI,GAAG,IAAI;CAGzB,KAAK,IAAI,IAAI,GAAG,IAAI,MAAM,GAAG,IAAI,KAAK,IAAI,KAAK;EAC9C,MAAM,KAAK,OAAO,IAClB,KAAK,OAAO,IACZ,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG;EAE5B,MAAM,GAAG,IAAI,GAAG,KAAK;EACrB,MAAM,GAAG,IAAI,GAAG,KAAK;EACrB,QAAQ;CACT;CAGA,OAAO,IAAI,UAAU,SAAS,IAAI,SAAS,IAAI,MAAM,KAAK,IAAI,OAAO,KAAK,IAAI,KAAK,CAAC,CAAC,KAAK,MAAM,CAAC;AAClG;;;;;;AAOA,SAAgB,SAAS,QAAQ;CAChC,IAAI,SAAS;CACb,IAAI,SAAS;CACb,IAAI,MAAM;CACV,KAAK,MAAM,SAAS,QAAQ;EAC3B,MAAM,SAAS,OAAO,KAAK,KAAK;EAChC,UAAU,OAAO;EACjB,UAAU,OAAO;EACjB;CACD;CACA,OAAO,IAAI,OAAO,CAAC,SAAS,KAAK,SAAS,GAAG,CAAC;AAC/C"}
|
|
@@ -43,12 +43,10 @@ import { Bounds } from "../geometry/Bounds.js";
|
|
|
43
43
|
* state change (including *during* pan/zoom animations).
|
|
44
44
|
*/
|
|
45
45
|
var BlanketOverlay = class BlanketOverlay extends Layer {
|
|
46
|
-
static {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
});
|
|
51
|
-
}
|
|
46
|
+
static defaultOptions = {
|
|
47
|
+
padding: .1,
|
|
48
|
+
continuous: false
|
|
49
|
+
};
|
|
52
50
|
/**
|
|
53
51
|
* @param {BlanketOverlayOptions} [options]
|
|
54
52
|
*/
|
|
@@ -87,9 +85,9 @@ var BlanketOverlay = class BlanketOverlay extends Layer {
|
|
|
87
85
|
zoom: this._onZoom,
|
|
88
86
|
moveend: this._onMoveEnd,
|
|
89
87
|
resize: this._resizeContainer,
|
|
90
|
-
zoomend: this._onZoomEnd
|
|
88
|
+
zoomend: this._onZoomEnd,
|
|
89
|
+
zoomanim: this._onAnimZoom
|
|
91
90
|
};
|
|
92
|
-
if (this._zoomAnimated) events.zoomanim = this._onAnimZoom;
|
|
93
91
|
if (this.options.continuous) events.move = this._onMoveEnd;
|
|
94
92
|
return events;
|
|
95
93
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BlanketOverlay.js","names":["DomUtil.create"],"sources":["../../../src/layer/BlanketOverlay.js"],"sourcesContent":["import {Layer} from './Layer.js';\nimport * as DomUtil from '../dom/DomUtil.js';\nimport * as Util from '../core/Util.js';\nimport * as DomEvent from '../dom/DomEvent.js';\nimport {Bounds} from '../geometry/Bounds.js';\n/** @import {LayerOptions} from './Layer.js' */\n/** @import {MaplairMap} from '../map/Map.js' */\n/** @import {EventListener} from '../core/Events.js' */\n\n/**\n * Options of `BlanketOverlay`.\n * @typedef {object} BlanketOverlayOptions\n * @property {number} [padding=0.1] How much to extend the clip area around the map\n * view (relative to its size) e.g. 0.1 would be 10% of map view in each direction.\n * @property {boolean} [continuous=false] When `false`, the blanket will update its\n * position only when the map state settles (*after* a pan/zoom animation). When\n * `true`, it will update when the map state changes (*during* pan/zoom animations).\n * @extends LayerOptions\n */\n\n/**\n * Represents an HTML element that covers (\"blankets\") the entire surface\n * of the map.\n *\n * Do not use this class directly. It's meant for `Renderer`, and for plugins\n * that rely on one single HTML element.\n *\n * Subclasses must define the following methods:\n *\n * * `_initContainer()` must initialize the HTML element to use as blanket, and store\n * it as `this._container`. The base implementation creates a blank `<div>`.\n * * `_destroyContainer()` must destroy the HTML element in `this._container` and free\n * any other resources. The base implementation destroys the element and removes\n * any event handlers attached to it.\n * * `_resizeContainer(): Point`: the base implementation resizes the container\n * (based on the map's size and taking into account the padding), returning the new\n * size in CSS pixels. Subclass implementations shall reset container parameters and\n * data structures as needed.\n * * `_onZoomEnd(ev?: PointerEvent)` (optional) runs on the map's `zoomend` event.\n * * `_onViewReset(ev?: PointerEvent)` (optional) runs on the map's `viewreset` event.\n * * `_onSettled()` runs whenever the map state settles after changing (at the end of\n * pan/zoom animations, etc). This should trigger the bulk of any rendering logic.\n * If the `continuous` option is set to `true`, then this also runs on any map\n * state change (including *during* pan/zoom animations).\n */\nexport class BlanketOverlay extends Layer {\n\n\tstatic {\n\t\
|
|
1
|
+
{"version":3,"file":"BlanketOverlay.js","names":["DomUtil.create"],"sources":["../../../src/layer/BlanketOverlay.js"],"sourcesContent":["import {Layer} from './Layer.js';\nimport * as DomUtil from '../dom/DomUtil.js';\nimport * as Util from '../core/Util.js';\nimport * as DomEvent from '../dom/DomEvent.js';\nimport {Bounds} from '../geometry/Bounds.js';\n/** @import {LayerOptions} from './Layer.js' */\n/** @import {MaplairMap} from '../map/Map.js' */\n/** @import {EventListener} from '../core/Events.js' */\n\n/**\n * Options of `BlanketOverlay`.\n * @typedef {object} BlanketOverlayOptions\n * @property {number} [padding=0.1] How much to extend the clip area around the map\n * view (relative to its size) e.g. 0.1 would be 10% of map view in each direction.\n * @property {boolean} [continuous=false] When `false`, the blanket will update its\n * position only when the map state settles (*after* a pan/zoom animation). When\n * `true`, it will update when the map state changes (*during* pan/zoom animations).\n * @extends LayerOptions\n */\n\n/**\n * Represents an HTML element that covers (\"blankets\") the entire surface\n * of the map.\n *\n * Do not use this class directly. It's meant for `Renderer`, and for plugins\n * that rely on one single HTML element.\n *\n * Subclasses must define the following methods:\n *\n * * `_initContainer()` must initialize the HTML element to use as blanket, and store\n * it as `this._container`. The base implementation creates a blank `<div>`.\n * * `_destroyContainer()` must destroy the HTML element in `this._container` and free\n * any other resources. The base implementation destroys the element and removes\n * any event handlers attached to it.\n * * `_resizeContainer(): Point`: the base implementation resizes the container\n * (based on the map's size and taking into account the padding), returning the new\n * size in CSS pixels. Subclass implementations shall reset container parameters and\n * data structures as needed.\n * * `_onZoomEnd(ev?: PointerEvent)` (optional) runs on the map's `zoomend` event.\n * * `_onViewReset(ev?: PointerEvent)` (optional) runs on the map's `viewreset` event.\n * * `_onSettled()` runs whenever the map state settles after changing (at the end of\n * pan/zoom animations, etc). This should trigger the bulk of any rendering logic.\n * If the `continuous` option is set to `true`, then this also runs on any map\n * state change (including *during* pan/zoom animations).\n */\nexport class BlanketOverlay extends Layer {\n\n\tstatic defaultOptions = {\n\t\tpadding: 0.1,\n\t\tcontinuous: false,\n\t};\n\n\t/**\n\t * @param {BlanketOverlayOptions} [options]\n\t */\n\tconstructor(options) {\n\t\tsuper();\n\t\tUtil.setOptions(this, options);\n\n\t\tthis.callInitHooks(BlanketOverlay);\n\t}\n\n\t/**\n\t * Adds the blanket to the map.\n\t * @type {(map: MaplairMap) => void}\n\t */\n\tonAdd() {\n\t\tif (!this._container) {\n\t\t\tthis._initContainer(); // defined by renderer implementations\n\n\t\t\t// always keep transform-origin as 0 0, #8794\n\t\t\tthis._container.classList.add('maplair-zoom-animated');\n\t\t}\n\n\t\tthis.getPane().appendChild(this._container);\n\t\tthis._resizeContainer();\n\t\tthis._onMoveEnd();\n\t}\n\n\t/**\n\t * Removes the blanket from the map.\n\t * @type {(map: MaplairMap) => void}\n\t */\n\tonRemove() {\n\t\tthis._destroyContainer();\n\t}\n\n\t/**\n\t * Returns the map events the blanket listens to.\n\t * @returns {Record<string, EventListener>}\n\t */\n\tgetEvents() {\n\t\tconst events = {\n\t\t\tviewreset: this._reset,\n\t\t\tzoom: this._onZoom,\n\t\t\tmoveend: this._onMoveEnd,\n\t\t\tresize: this._resizeContainer,\n\t\t\tzoomend: this._onZoomEnd,\n\t\t\tzoomanim: this._onAnimZoom\n\t\t};\n\t\tif (this.options.continuous) {\n\t\t\tevents.move = this._onMoveEnd;\n\t\t}\n\t\treturn events;\n\t}\n\n\t_onAnimZoom(ev) {\n\t\tthis._updateTransform(ev.center, ev.zoom);\n\t}\n\n\t_onZoom() {\n\t\tthis._updateTransform(this._map.getCenter(), this._map.getZoom());\n\t}\n\n\t_updateTransform(center, zoom) {\n\t\tconst scale = this._map.getZoomScale(zoom, this._zoom),\n\t\tviewHalf = this._map.getSize().multiplyBy(0.5 + this.options.padding),\n\t\tcurrentCenterPoint = this._map.project(this._center, zoom),\n\t\ttopLeftOffset = viewHalf.multiplyBy(-scale)._add(currentCenterPoint)\n\t\t\t._subtract(this._map._getNewPixelOrigin(center, zoom))\n\t\t\t._round();\n\n\t\tDomUtil.setTransform(this._container, topLeftOffset, scale);\n\t}\n\n\t_onMoveEnd(ev) {\n\t\t// Update pixel bounds of renderer container (for positioning/sizing/clipping later)\n\t\tconst p = this.options.padding,\n\t\tsize = this._map.getSize(),\n\t\tmin = this._map.containerPointToLayerPoint(size.multiplyBy(-p)).round();\n\n\t\tthis._bounds = new Bounds(min, min.add(size.multiplyBy(1 + p * 2)).round());\n\n\t\tthis._center = this._map.getCenter();\n\t\tthis._zoom = this._map.getZoom();\n\t\tthis._updateTransform(this._center, this._zoom);\n\n\t\tthis._onSettled(ev);\n\t}\n\n\t_reset() {\n\t\tthis._onSettled();\n\t\tthis._updateTransform(this._center, this._zoom);\n\t\tthis._onViewReset();\n\t}\n\n\t// Subclass interface, see the class description.\n\t_initContainer() {\n\t\tthis._container = DomUtil.create('div');\n\t}\n\t_destroyContainer() {\n\t\tDomEvent.off(this._container);\n\t\tthis._container.remove();\n\t\tdelete this._container;\n\t}\n\t_resizeContainer() {\n\t\tconst p = this.options.padding,\n\t\tsize = this._map.getSize().multiplyBy(1 + p * 2).round();\n\t\tthis._container.style.width = `${size.x}px`;\n\t\tthis._container.style.height = `${size.y}px`;\n\t\treturn size;\n\t}\n\t_onZoomEnd() {}\n\t_onViewReset() {}\n\t_onSettled() {}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;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d,MAAM,IAAI,KAAK,QAAQ,SACvB,OAAO,KAAK,KAAK,QAAQ,GACzB,MAAM,KAAK,KAAK,2BAA2B,KAAK,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM;EAEtE,KAAK,UAAU,IAAI,OAAO,KAAK,IAAI,IAAI,KAAK,WAAW,IAAI,IAAI,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC;EAE1E,KAAK,UAAU,KAAK,KAAK,UAAU;EACnC,KAAK,QAAQ,KAAK,KAAK,QAAQ;EAC/B,KAAK,iBAAiB,KAAK,SAAS,KAAK,KAAK;EAE9C,KAAK,WAAW,EAAE;CACnB;CAEA,SAAS;EACR,KAAK,WAAW;EAChB,KAAK,iBAAiB,KAAK,SAAS,KAAK,KAAK;EAC9C,KAAK,aAAa;CACnB;CAGA,iBAAiB;EAChB,KAAK,aAAaA,OAAe,KAAK;CACvC;CACA,oBAAoB;EACnB,IAAa,KAAK,UAAU;EAC5B,KAAK,WAAW,OAAO;EACvB,OAAO,KAAK;CACb;CACA,mBAAmB;EAClB,MAAM,IAAI,KAAK,QAAQ,SACvB,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,WAAW,IAAI,IAAI,CAAC,CAAC,CAAC,MAAM;EACvD,KAAK,WAAW,MAAM,QAAQ,GAAG,KAAK,EAAE;EACxC,KAAK,WAAW,MAAM,SAAS,GAAG,KAAK,EAAE;EACzC,OAAO;CACR;CACA,aAAa,CAAC;CACd,eAAe,CAAC;CAChB,aAAa,CAAC;AACf"}
|
|
@@ -68,16 +68,14 @@ const layerDivOverlayMethods = { _initOverlay(OverlayClass, old, content, option
|
|
|
68
68
|
* @fires contentupdate {MaplairEvent} Fired when the content of the overlay is updated.
|
|
69
69
|
*/
|
|
70
70
|
var DivOverlay = class DivOverlay extends Layer {
|
|
71
|
-
static {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
});
|
|
80
|
-
}
|
|
71
|
+
static defaultOptions = {
|
|
72
|
+
interactive: false,
|
|
73
|
+
offset: [0, 0],
|
|
74
|
+
className: "",
|
|
75
|
+
pane: void 0,
|
|
76
|
+
overflow: false,
|
|
77
|
+
content: ""
|
|
78
|
+
};
|
|
81
79
|
/**
|
|
82
80
|
* Instantiates an overlay given an optional `options` object that describes its
|
|
83
81
|
* appearance and location and an optional `source` object that is used to tag the
|
|
@@ -152,9 +150,8 @@ var DivOverlay = class DivOverlay extends Layer {
|
|
|
152
150
|
* @param {MaplairMap} map
|
|
153
151
|
*/
|
|
154
152
|
onAdd(map) {
|
|
155
|
-
this._zoomAnimated = map._zoomAnimated;
|
|
156
153
|
if (!this._container) this._initLayout();
|
|
157
|
-
if (map._fadeAnimated) this._container.style.opacity = 0;
|
|
154
|
+
if (map._fadeAnimated) this._container.style.opacity = "0";
|
|
158
155
|
clearTimeout(this._removeTimeout);
|
|
159
156
|
this.getPane().appendChild(this._container);
|
|
160
157
|
if (this.options.overflow) {
|
|
@@ -169,7 +166,7 @@ var DivOverlay = class DivOverlay extends Layer {
|
|
|
169
166
|
window.addEventListener("resize", this._onPageChange, { passive: true });
|
|
170
167
|
}
|
|
171
168
|
this.update();
|
|
172
|
-
if (map._fadeAnimated) this._container.style.opacity = 1;
|
|
169
|
+
if (map._fadeAnimated) this._container.style.opacity = "1";
|
|
173
170
|
if (!this.options.overflow) this.bringToFront();
|
|
174
171
|
if (this.options.interactive) {
|
|
175
172
|
this._container.classList.add("maplair-interactive");
|
|
@@ -186,7 +183,7 @@ var DivOverlay = class DivOverlay extends Layer {
|
|
|
186
183
|
window.removeEventListener("resize", this._onPageChange);
|
|
187
184
|
}
|
|
188
185
|
if (map._fadeAnimated) {
|
|
189
|
-
this._container.style.opacity = 0;
|
|
186
|
+
this._container.style.opacity = "0";
|
|
190
187
|
this._removeTimeout = setTimeout(() => this._container.remove(), 200);
|
|
191
188
|
} else this._container.remove();
|
|
192
189
|
if (this.options.interactive) {
|
|
@@ -268,9 +265,9 @@ var DivOverlay = class DivOverlay extends Layer {
|
|
|
268
265
|
getEvents() {
|
|
269
266
|
const events = {
|
|
270
267
|
zoom: this._updatePosition,
|
|
271
|
-
viewreset: this._updatePosition
|
|
268
|
+
viewreset: this._updatePosition,
|
|
269
|
+
zoomanim: this._animateZoom
|
|
272
270
|
};
|
|
273
|
-
if (this._zoomAnimated) events.zoomanim = this._animateZoom;
|
|
274
271
|
if (this.options.overflow) events.move = this._updatePosition;
|
|
275
272
|
return events;
|
|
276
273
|
}
|
|
@@ -346,10 +343,8 @@ var DivOverlay = class DivOverlay extends Layer {
|
|
|
346
343
|
}
|
|
347
344
|
_updatePosition() {
|
|
348
345
|
if (!this._map) return;
|
|
349
|
-
const pos = this._map.latLngToLayerPoint(this._latlng),
|
|
350
|
-
|
|
351
|
-
if (this._zoomAnimated || this.options.overflow) this._setContainerPosition(pos.add(anchor));
|
|
352
|
-
else offset = offset.add(pos).add(anchor);
|
|
346
|
+
const pos = this._map.latLngToLayerPoint(this._latlng), offset = Point.from(this.options.offset);
|
|
347
|
+
this._setContainerPosition(pos.add(this._getAnchor()));
|
|
353
348
|
const bottom = this._containerBottom = -offset.y, left = this._containerLeft = -Math.round(this._containerWidth / 2) + offset.x;
|
|
354
349
|
if (this.options.overflow) {
|
|
355
350
|
this._container.style.top = "auto";
|