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,8 +1,7 @@
|
|
|
1
1
|
import { setOptions, stamp } from "../../core/Util.js";
|
|
2
|
-
import
|
|
2
|
+
import { SVG } from "./SVG.js";
|
|
3
3
|
import { Path } from "./Path.js";
|
|
4
4
|
import { Canvas } from "./Canvas.js";
|
|
5
|
-
import { SVG } from "./SVG.js";
|
|
6
5
|
//#region src/layer/vector/Path.DashAnimation.js
|
|
7
6
|
const DASH_SEPARATOR_RE = /[ ,]+/;
|
|
8
7
|
const { _updateStyle: updateSvgStyle } = SVG.prototype, { _fillStroke: fillStroke, _destroyContainer: destroyCanvasContainer } = Canvas.prototype;
|
|
@@ -61,7 +60,7 @@ Canvas.include({
|
|
|
61
60
|
destroyCanvasContainer.call(this);
|
|
62
61
|
},
|
|
63
62
|
_getDashShift(layer) {
|
|
64
|
-
const speed = layer.options.dashSpeed, length = speed && !
|
|
63
|
+
const speed = layer.options.dashSpeed, length = speed && !this._map._prefersReducedMotion() && layer._getDashLength();
|
|
65
64
|
if (!length) return 0;
|
|
66
65
|
this._animatedDashes ??= /* @__PURE__ */ new Set();
|
|
67
66
|
this._animatedDashes.add(layer);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Path.DashAnimation.js","names":["
|
|
1
|
+
{"version":3,"file":"Path.DashAnimation.js","names":["Util.stamp"],"sources":["../../../../src/layer/vector/Path.DashAnimation.js"],"sourcesContent":["import {Path} from './Path.js';\nimport {SVG} from './SVG.js';\nimport {Canvas} from './Canvas.js';\nimport * as Util from '../../core/Util.js';\n\nconst DASH_SEPARATOR_RE = /[ ,]+/;\n\n// The methods extended below\nconst {_updateStyle: updateSvgStyle} = SVG.prototype,\n{_fillStroke: fillStroke, _destroyContainer: destroyCanvasContainer} = Canvas.prototype;\n\n/**\n * Options of `Path` for the animation of dashes. The animation of dashes is an\n * optional feature: import this module to add the `dashSpeed` option to `Path`.\n *\n * ```js\n * import 'maplair/dash-animation';\n *\n * new Polyline(latlngs, {dashArray: '10, 10', dashSpeed: 20}).addTo(map);\n * ```\n *\n * Inspired by the [leaflet-ant-path](https://github.com/rubenspgcavalcante/leaflet-ant-path) plugin.\n * @typedef {object} DashAnimationPathOptions\n * @lends PathOptions\n * @property {number} [dashSpeed=0] Animates the dashes of the `dashArray` along the\n * path (\"marching ants\"), e.g. to show the direction of a flow: the speed in pixels per\n * second, negative for the opposite direction. Not animated with\n * [reduced motion](https://developer.mozilla.org/docs/Web/CSS/@media/prefers-reduced-motion).\n */\n\nPath.include({\n\toptions: {\n\t\tdashSpeed: 0\n\t},\n\n\t// The length of the dash pattern (repeated if it has an odd number of values)\n\t_getDashLength() {\n\t\tconst dashArray = this.options.dashArray,\n\t\tvalues = (Array.isArray(dashArray) ? dashArray : String(dashArray ?? '').split(DASH_SEPARATOR_RE))\n\t\t\t.map(Number).filter(n => !Number.isNaN(n)),\n\t\tlength = values.reduce((sum, value) => sum + value, 0);\n\t\treturn values.length % 2 ? length * 2 : length;\n\t}\n});\n\nSVG.include({\n\t// a CSS animation of the dash offset by the length of the dash pattern\n\t_updateStyle(layer) {\n\t\tupdateSvgStyle.call(this, layer);\n\t\tconst path = layer._path;\n\t\tif (!path) { return; }\n\t\tconst speed = layer.options.dashSpeed,\n\t\tdashLength = layer.options.stroke && speed && layer._getDashLength();\n\t\tpath.classList.toggle('maplair-dash-animated', !!dashLength);\n\t\tif (dashLength) {\n\t\t\tpath.style.setProperty('--maplair-dash-length', `${Math.sign(speed) * dashLength}px`);\n\t\t\tpath.style.setProperty('--maplair-dash-duration', `${dashLength / Math.abs(speed)}s`);\n\t\t}\n\t}\n});\n\nCanvas.include({\n\t// drawing with the dash offset shifted by the time\n\t_fillStroke(ctx, layer) {\n\t\tconst shift = this._getDashShift(layer);\n\t\tif (!shift) {\n\t\t\tfillStroke.call(this, ctx, layer);\n\t\t\treturn;\n\t\t}\n\t\tconst options = layer.options,\n\t\town = Object.hasOwn(options, 'dashOffset'),\n\t\tdashOffset = options.dashOffset;\n\t\tUtil.setOptions(layer, {dashOffset: Number(dashOffset ?? 0) - shift});\n\t\tfillStroke.call(this, ctx, layer);\n\t\tif (own) {\n\t\t\toptions.dashOffset = dashOffset;\n\t\t} else {\n\t\t\tdelete options.dashOffset;\n\t\t}\n\t},\n\n\t_destroyContainer() {\n\t\tcancelAnimationFrame(this._dashFrame);\n\t\tthis._dashFrame = null;\n\t\tdestroyCanvasContainer.call(this);\n\t},\n\n\t// The shift of the dashes of an animated path, and keeps redrawing it\n\t_getDashShift(layer) {\n\t\tconst speed = layer.options.dashSpeed,\n\t\tlength = speed && !this._map._prefersReducedMotion() && layer._getDashLength();\n\t\tif (!length) { return 0; }\n\n\t\tthis._animatedDashes ??= new Set();\n\t\tthis._animatedDashes.add(layer);\n\t\tthis._dashFrame ??= requestAnimationFrame(() => {\n\t\t\tthis._dashFrame = null;\n\t\t\tfor (const animated of this._animatedDashes) {\n\t\t\t\tif (this._layers[Util.stamp(animated)] && animated.options.dashSpeed) {\n\t\t\t\t\tthis._requestRedraw(animated);\n\t\t\t\t}\n\t\t\t}\n\t\t\tthis._animatedDashes.clear();\n\t\t});\n\t\treturn (performance.now() / 1000 * speed) % length;\n\t}\n});\n"],"mappings":";;;;;AAKA,MAAM,oBAAoB;AAG1B,MAAM,EAAC,cAAc,mBAAkB,IAAI,WAC3C,EAAC,aAAa,YAAY,mBAAmB,2BAA0B,OAAO;;;;;;;;;;;;;;;;;;;AAqB9E,KAAK,QAAQ;CACZ,SAAS,EACR,WAAW,EACZ;CAGA,iBAAiB;EAChB,MAAM,YAAY,KAAK,QAAQ,WAC/B,UAAU,MAAM,QAAQ,SAAS,IAAI,YAAY,OAAO,aAAa,EAAE,CAAC,CAAC,MAAM,iBAAiB,EAAA,CAC9F,IAAI,MAAM,CAAC,CAAC,QAAO,MAAK,CAAC,OAAO,MAAM,CAAC,CAAC,GAC1C,SAAS,OAAO,QAAQ,KAAK,UAAU,MAAM,OAAO,CAAC;EACrD,OAAO,OAAO,SAAS,IAAI,SAAS,IAAI;CACzC;AACD,CAAC;AAED,IAAI,QAAQ,EAEX,aAAa,OAAO;CACnB,eAAe,KAAK,MAAM,KAAK;CAC/B,MAAM,OAAO,MAAM;CACnB,IAAI,CAAC,MAAQ;CACb,MAAM,QAAQ,MAAM,QAAQ,WAC5B,aAAa,MAAM,QAAQ,UAAU,SAAS,MAAM,eAAe;CACnE,KAAK,UAAU,OAAO,yBAAyB,CAAC,CAAC,UAAU;CAC3D,IAAI,YAAY;EACf,KAAK,MAAM,YAAY,yBAAyB,GAAG,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layer/vector/Path.js
|
|
4
5
|
/** @import {InteractiveLayerOptions} from '../Layer.js' */
|
|
5
6
|
/** @import {MaplairMap} from '../../map/Map.js' */
|
|
@@ -32,9 +33,11 @@ import { Layer } from "../Layer.js";
|
|
|
32
33
|
* [how the inside of a shape](https://developer.mozilla.org/docs/Web/SVG/Attribute/fill-rule)
|
|
33
34
|
* is determined.
|
|
34
35
|
* @property {string} [className] Custom class name set on an element. Only for SVG renderer.
|
|
36
|
+
* Applied when the element is created; [`setStyle`](#path-setstyle) does not update it
|
|
37
|
+
* afterwards.
|
|
35
38
|
* @property {Renderer} [renderer] Use this specific instance of `Renderer` for this
|
|
36
|
-
* path.
|
|
37
|
-
* If set, it
|
|
39
|
+
* path. If not set, the path uses the map's [renderer](#maplairmapoptions-renderer),
|
|
40
|
+
* which is `SVG` by default. If set, it overrides the `pane` option.
|
|
38
41
|
* @extends InteractiveLayerOptions
|
|
39
42
|
*/
|
|
40
43
|
/**
|
|
@@ -42,24 +45,22 @@ import { Layer } from "../Layer.js";
|
|
|
42
45
|
* overlays (Polygon, Polyline, Circle). Do not use it directly. Extends `Layer`.
|
|
43
46
|
*/
|
|
44
47
|
var Path = class extends Layer {
|
|
45
|
-
static {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
});
|
|
62
|
-
}
|
|
48
|
+
static defaultOptions = {
|
|
49
|
+
stroke: true,
|
|
50
|
+
color: "#3388ff",
|
|
51
|
+
weight: 3,
|
|
52
|
+
opacity: 1,
|
|
53
|
+
lineCap: "round",
|
|
54
|
+
lineJoin: "round",
|
|
55
|
+
dashArray: null,
|
|
56
|
+
dashOffset: null,
|
|
57
|
+
fill: false,
|
|
58
|
+
fillColor: null,
|
|
59
|
+
fillOpacity: .2,
|
|
60
|
+
fillRule: "evenodd",
|
|
61
|
+
interactive: true,
|
|
62
|
+
bubblingPointerEvents: true
|
|
63
|
+
};
|
|
63
64
|
/**
|
|
64
65
|
* Gets the renderer of the path from the map, before it is added.
|
|
65
66
|
* @param {MaplairMap} map
|
|
@@ -94,6 +95,9 @@ var Path = class extends Layer {
|
|
|
94
95
|
}
|
|
95
96
|
/**
|
|
96
97
|
* Changes the appearance of a Path based on the options in the `PathOptions` object.
|
|
98
|
+
* Note that [`className`](#pathoptions-classname) is an exception: it is applied only
|
|
99
|
+
* when the path element is created, so passing it here updates the option but leaves
|
|
100
|
+
* the element's class unchanged.
|
|
97
101
|
* @param {PathOptions} style
|
|
98
102
|
* @returns {this}
|
|
99
103
|
*/
|
|
@@ -128,6 +132,9 @@ var Path = class extends Layer {
|
|
|
128
132
|
getElement() {
|
|
129
133
|
return this._path;
|
|
130
134
|
}
|
|
135
|
+
_createRenderer(options) {
|
|
136
|
+
return new SVG(options);
|
|
137
|
+
}
|
|
131
138
|
_reset() {
|
|
132
139
|
this._project();
|
|
133
140
|
this._update();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Path.js","names":[],"sources":["../../../../src/layer/vector/Path.js"],"sourcesContent":["import {Layer} from '../Layer.js';\nimport * as Util from '../../core/Util.js';\n/** @import {InteractiveLayerOptions} from '../Layer.js' */\n/** @import {MaplairMap} from '../../map/Map.js' */\n/** @import {Renderer} from './Renderer.js' */\n\n/**\n * Options of `Path`, shared by all vector layers.\n * @typedef {object} PathOptions\n * @property {boolean} [stroke=true] Whether to draw stroke along the path. Set it to\n * `false` to disable borders on polygons or circles.\n * @property {string} [color='#3388ff'] Stroke color.\n * @property {number} [weight=3] Stroke width in pixels.\n * @property {number} [opacity=1] Stroke opacity.\n * @property {string} [lineCap='round'] A string that defines\n * [shape to be used at the end](https://developer.mozilla.org/docs/Web/SVG/Attribute/stroke-linecap)\n * of the stroke.\n * @property {string} [lineJoin='round'] A string that defines\n * [shape to be used at the corners](https://developer.mozilla.org/docs/Web/SVG/Attribute/stroke-linejoin)\n * of the stroke.\n * @property {string|null} [dashArray=null] A string that defines the stroke\n * [dash pattern](https://developer.mozilla.org/docs/Web/SVG/Attribute/stroke-dasharray).\n * @property {string|null} [dashOffset=null] A string that defines the\n * [distance into the dash pattern to start the dash](https://developer.mozilla.org/docs/Web/SVG/Attribute/stroke-dashoffset).\n * @property {boolean} [fill=false] Whether to fill the path with color. Set it to\n * `false` to disable filling on polygons or circles. The default depends on the\n * class: `true` for polygons and circles.\n * @property {string|null} [fillColor=null] Fill color. Defaults to the value of the\n * [`color`](#pathoptions-color) option.\n * @property {number} [fillOpacity=0.2] Fill opacity.\n * @property {string} [fillRule='evenodd'] A string that defines\n * [how the inside of a shape](https://developer.mozilla.org/docs/Web/SVG/Attribute/fill-rule)\n * is determined.\n * @property {string} [className] Custom class name set on an element. Only for SVG renderer.\n * @property {Renderer} [renderer] Use this specific instance of `Renderer` for this\n * path.
|
|
1
|
+
{"version":3,"file":"Path.js","names":[],"sources":["../../../../src/layer/vector/Path.js"],"sourcesContent":["import {Layer} from '../Layer.js';\nimport {SVG} from './SVG.js';\nimport * as Util from '../../core/Util.js';\n/** @import {InteractiveLayerOptions} from '../Layer.js' */\n/** @import {MaplairMap} from '../../map/Map.js' */\n/** @import {Renderer} from './Renderer.js' */\n\n/**\n * Options of `Path`, shared by all vector layers.\n * @typedef {object} PathOptions\n * @property {boolean} [stroke=true] Whether to draw stroke along the path. Set it to\n * `false` to disable borders on polygons or circles.\n * @property {string} [color='#3388ff'] Stroke color.\n * @property {number} [weight=3] Stroke width in pixels.\n * @property {number} [opacity=1] Stroke opacity.\n * @property {string} [lineCap='round'] A string that defines\n * [shape to be used at the end](https://developer.mozilla.org/docs/Web/SVG/Attribute/stroke-linecap)\n * of the stroke.\n * @property {string} [lineJoin='round'] A string that defines\n * [shape to be used at the corners](https://developer.mozilla.org/docs/Web/SVG/Attribute/stroke-linejoin)\n * of the stroke.\n * @property {string|null} [dashArray=null] A string that defines the stroke\n * [dash pattern](https://developer.mozilla.org/docs/Web/SVG/Attribute/stroke-dasharray).\n * @property {string|null} [dashOffset=null] A string that defines the\n * [distance into the dash pattern to start the dash](https://developer.mozilla.org/docs/Web/SVG/Attribute/stroke-dashoffset).\n * @property {boolean} [fill=false] Whether to fill the path with color. Set it to\n * `false` to disable filling on polygons or circles. The default depends on the\n * class: `true` for polygons and circles.\n * @property {string|null} [fillColor=null] Fill color. Defaults to the value of the\n * [`color`](#pathoptions-color) option.\n * @property {number} [fillOpacity=0.2] Fill opacity.\n * @property {string} [fillRule='evenodd'] A string that defines\n * [how the inside of a shape](https://developer.mozilla.org/docs/Web/SVG/Attribute/fill-rule)\n * is determined.\n * @property {string} [className] Custom class name set on an element. Only for SVG renderer.\n * Applied when the element is created; [`setStyle`](#path-setstyle) does not update it\n * afterwards.\n * @property {Renderer} [renderer] Use this specific instance of `Renderer` for this\n * path. If not set, the path uses the map's [renderer](#maplairmapoptions-renderer),\n * which is `SVG` by default. If set, it overrides the `pane` option.\n * @extends InteractiveLayerOptions\n */\n\n/**\n * An abstract class that contains options and constants shared between vector\n * overlays (Polygon, Polyline, Circle). Do not use it directly. Extends `Layer`.\n */\nexport class Path extends Layer {\n\n\tstatic defaultOptions = {\n\t\tstroke: true,\n\t\tcolor: '#3388ff',\n\t\tweight: 3,\n\t\topacity: 1,\n\t\tlineCap: 'round',\n\t\tlineJoin: 'round',\n\t\tdashArray: null,\n\t\tdashOffset: null,\n\t\tfill: false,\n\t\tfillColor: null,\n\t\tfillOpacity: 0.2,\n\t\tfillRule: 'evenodd',\n\t\t// className: '',\n\t\tinteractive: true,\n\t\tbubblingPointerEvents: true\n\t};\n\n\t/**\n\t * Gets the renderer of the path from the map, before it is added.\n\t * @param {MaplairMap} map\n\t */\n\tbeforeAdd(map) {\n\t\t// Renderer is set here because we need to call renderer.getEvents\n\t\t// before this.getEvents.\n\t\tthis._renderer = map.getRenderer(this);\n\t}\n\n\t/**\n\t * Adds the path to its renderer.\n\t */\n\tonAdd() {\n\t\tthis._renderer._initPath(this);\n\t\tthis._reset();\n\t\tthis._renderer._addPath(this);\n\t}\n\n\t/**\n\t * Removes the path from its renderer.\n\t */\n\tonRemove() {\n\t\tthis._renderer._removePath(this);\n\t}\n\n\t/**\n\t * Redraws the layer. Sometimes useful after you changed the coordinates that the path uses.\n\t * @returns {this}\n\t */\n\tredraw() {\n\t\tif (this._map) {\n\t\t\tthis._renderer._updatePath(this);\n\t\t}\n\t\treturn this;\n\t}\n\n\t_updateInteractive() {\n\t\tthis._renderer._updateInteractive(this);\n\t}\n\n\t/**\n\t * Changes the appearance of a Path based on the options in the `PathOptions` object.\n\t * Note that [`className`](#pathoptions-classname) is an exception: it is applied only\n\t * when the path element is created, so passing it here updates the option but leaves\n\t * the element's class unchanged.\n\t * @param {PathOptions} style\n\t * @returns {this}\n\t */\n\tsetStyle(style) {\n\t\tUtil.setOptions(this, style);\n\t\tif (this._renderer) {\n\t\t\tthis._renderer._updateStyle(this);\n\t\t\tif (this.options.stroke && style && Object.hasOwn(style, 'weight')) {\n\t\t\t\tthis._updateBounds();\n\t\t\t}\n\t\t}\n\t\treturn this;\n\t}\n\n\t/**\n\t * Brings the layer to the top of all path layers.\n\t * @returns {this}\n\t */\n\tbringToFront() {\n\t\tthis._renderer?._bringToFront(this);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Brings the layer to the bottom of all path layers.\n\t * @returns {this}\n\t */\n\tbringToBack() {\n\t\tthis._renderer?._bringToBack(this);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Returns the SVG `path` element of the layer, if it is rendered by the `SVG` renderer.\n\t * @returns {SVGPathElement|undefined}\n\t */\n\tgetElement() {\n\t\treturn this._path;\n\t}\n\n\t// the renderer of the path if neither the path nor the map has one\n\t_createRenderer(options) {\n\t\treturn new SVG(options);\n\t}\n\n\t_reset() {\n\t\t// defined in child classes\n\t\tthis._project();\n\t\tthis._update();\n\t}\n\n\t_clickTolerance() {\n\t\t// used when doing hit detection for Canvas layers\n\t\treturn (this.options.stroke ? this.options.weight / 2 : 0) +\n\t\t (this._renderer.options.tolerance || 0);\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+CA,IAAa,OAAb,cAA0B,MAAM;CAE/B,OAAO,iBAAiB;EACvB,QAAQ;EACR,OAAO;EACP,QAAQ;EACR,SAAS;EACT,SAAS;EACT,UAAU;EACV,WAAW;EACX,YAAY;EACZ,MAAM;EACN,WAAW;EACX,aAAa;EACb,UAAU;EAEV,aAAa;EACb,uBAAuB;CACxB;;;;;CAMA,UAAU,KAAK;EAGd,KAAK,YAAY,IAAI,YAAY,IAAI;CACtC;;;;CAKA,QAAQ;EACP,KAAK,UAAU,UAAU,IAAI;EAC7B,KAAK,OAAO;EACZ,KAAK,UAAU,SAAS,IAAI;CAC7B;;;;CAKA,WAAW;EACV,KAAK,UAAU,YAAY,IAAI;CAChC;;;;;CAMA,SAAS;EACR,IAAI,KAAK,MACR,KAAK,UAAU,YAAY,IAAI;EAEhC,OAAO;CACR;CAEA,qBAAqB;EACpB,KAAK,UAAU,mBAAmB,IAAI;CACvC;;;;;;;;;CAUA,SAAS,OAAO;EACf,WAAgB,MAAM,KAAK;EAC3B,IAAI,KAAK,WAAW;GACnB,KAAK,UAAU,aAAa,IAAI;GAChC,IAAI,KAAK,QAAQ,UAAU,SAAS,OAAO,OAAO,OAAO,QAAQ,GAChE,KAAK,cAAc;EAErB;EACA,OAAO;CACR;;;;;CAMA,eAAe;EACd,KAAK,WAAW,cAAc,IAAI;EAClC,OAAO;CACR;;;;;CAMA,cAAc;EACb,KAAK,WAAW,aAAa,IAAI;EACjC,OAAO;CACR;;;;;CAMA,aAAa;EACZ,OAAO,KAAK;CACb;CAGA,gBAAgB,SAAS;EACxB,OAAO,IAAI,IAAI,OAAO;CACvB;CAEA,SAAS;EAER,KAAK,SAAS;EACd,KAAK,QAAQ;CACd;CAEA,kBAAkB;EAEjB,QAAQ,KAAK,QAAQ,SAAS,KAAK,QAAQ,SAAS,IAAI,MACrD,KAAK,UAAU,QAAQ,aAAa;CACxC;AACD"}
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { Point } from "../../geometry/Point.js";
|
|
2
2
|
import { Bounds } from "../../geometry/Bounds.js";
|
|
3
3
|
import { LatLng } from "../../geo/LatLng.js";
|
|
4
|
-
import { clipPolygon, polygonCenter } from "../../geometry/PolyUtil.js";
|
|
5
4
|
import { isFlat } from "../../geometry/LineUtil.js";
|
|
5
|
+
import { getFeature, latLngsToCoords } from "../GeoJSONUtil.js";
|
|
6
6
|
import { Polyline } from "./Polyline.js";
|
|
7
|
+
import { clipPolygon, polygonCenter } from "../../geometry/PolyUtil.js";
|
|
7
8
|
//#region src/layer/vector/Polygon.js
|
|
9
|
+
/** @import {Feature} from 'geojson' */
|
|
8
10
|
/** @import {LatLngExpression} from '../../geo/LatLng.js' */
|
|
9
11
|
/** @import {PolylineOptions} from './Polyline.js' */
|
|
10
12
|
/**
|
|
@@ -55,9 +57,7 @@ import { Polyline } from "./Polyline.js";
|
|
|
55
57
|
* ```
|
|
56
58
|
*/
|
|
57
59
|
var Polygon = class Polygon extends Polyline {
|
|
58
|
-
static {
|
|
59
|
-
this.setDefaultOptions({ fill: true });
|
|
60
|
-
}
|
|
60
|
+
static defaultOptions = { fill: true };
|
|
61
61
|
/**
|
|
62
62
|
* Instantiates a polygon object given an array of geographical points (or arrays
|
|
63
63
|
* of them for holes and multi-polygons) and optionally an options object.
|
|
@@ -130,6 +130,22 @@ var Polygon = class Polygon extends Polyline {
|
|
|
130
130
|
}
|
|
131
131
|
return inside || super._containsPoint(p, true);
|
|
132
132
|
}
|
|
133
|
+
/**
|
|
134
|
+
* Coordinates values are rounded with [`formatNum`](#util-formatnum) to the
|
|
135
|
+
* given `precision`. Returns a [`GeoJSON`](https://en.wikipedia.org/wiki/GeoJSON)
|
|
136
|
+
* representation of the polygon (as a GeoJSON `Polygon` or `MultiPolygon` Feature).
|
|
137
|
+
* @param {number|false} [precision]
|
|
138
|
+
* @returns {Feature}
|
|
139
|
+
*/
|
|
140
|
+
toGeoJSON(precision) {
|
|
141
|
+
const holes = !isFlat(this._latlngs), multi = holes && !isFlat(this._latlngs[0]);
|
|
142
|
+
let coords = latLngsToCoords(this._latlngs, multi ? 2 : holes ? 1 : 0, true, precision);
|
|
143
|
+
if (!holes) coords = [coords];
|
|
144
|
+
return getFeature(this, {
|
|
145
|
+
type: `${multi ? "Multi" : ""}Polygon`,
|
|
146
|
+
coordinates: coords
|
|
147
|
+
});
|
|
148
|
+
}
|
|
133
149
|
};
|
|
134
150
|
//#endregion
|
|
135
151
|
export { Polygon };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Polygon.js","names":["PolyUtil.polygonCenter","LineUtil.isFlat","PolyUtil.clipPolygon"],"sources":["../../../../src/layer/vector/Polygon.js"],"sourcesContent":["import {Polyline} from './Polyline.js';\nimport {LatLng} from '../../geo/LatLng.js';\nimport * as LineUtil from '../../geometry/LineUtil.js';\nimport {Point} from '../../geometry/Point.js';\nimport {Bounds} from '../../geometry/Bounds.js';\nimport * as PolyUtil from '../../geometry/PolyUtil.js';\n/** @import {LatLngExpression} from '../../geo/LatLng.js' */\n/** @import {PolylineOptions} from './Polyline.js' */\n\n/**\n * Options of `Polygon`.\n * @typedef {object} PolygonOptions\n * @property {boolean} [fill=true] Whether to fill the polygon with color.\n * @extends PolylineOptions\n */\n\n/**\n * A class for drawing polygon overlays on a map. Extends `Polyline`.\n *\n * Note that points you pass when creating a polygon shouldn't have an additional last\n * point equal to the first one — it's better to filter out such points.\n *\n * @example\n * ```js\n * // create a red polygon from an array of LatLng points\n * const latlngs = [[37, -109.05],[41, -109.03],[41, -102.05],[37, -102.04]];\n *\n * const polygon = new Polygon(latlngs, {color: 'red'}).addTo(map);\n *\n * // zoom the map to the polygon\n * map.fitBounds(polygon.getBounds());\n * ```\n *\n * You can also pass an array of arrays of latlngs, with the first array representing\n * the outer shape and the other arrays representing holes in the outer shape:\n *\n * ```js\n * const latlngs = [\n * [[37, -109.05],[41, -109.03],[41, -102.05],[37, -102.04]], // outer ring\n * [[37.29, -108.58],[40.71, -108.58],[40.71, -102.50],[37.29, -102.50]] // hole\n * ];\n * ```\n *\n * Additionally, you can pass a multi-dimensional array to represent a MultiPolygon shape.\n *\n * ```js\n * const latlngs = [\n * [ // first polygon\n * [[37, -109.05],[41, -109.03],[41, -102.05],[37, -102.04]], // outer ring\n * [[37.29, -108.58],[40.71, -108.58],[40.71, -102.50],[37.29, -102.50]] // hole\n * ],\n * [ // second polygon\n * [[41, -111.03],[45, -111.04],[45, -104.05],[41, -104.05]]\n * ]\n * ];\n * ```\n */\nexport class Polygon extends Polyline {\n\n\tstatic {\n\t\
|
|
1
|
+
{"version":3,"file":"Polygon.js","names":["PolyUtil.polygonCenter","LineUtil.isFlat","PolyUtil.clipPolygon"],"sources":["../../../../src/layer/vector/Polygon.js"],"sourcesContent":["import {Polyline} from './Polyline.js';\nimport {LatLng} from '../../geo/LatLng.js';\nimport * as LineUtil from '../../geometry/LineUtil.js';\nimport {Point} from '../../geometry/Point.js';\nimport {Bounds} from '../../geometry/Bounds.js';\nimport * as PolyUtil from '../../geometry/PolyUtil.js';\nimport {latLngsToCoords, getFeature} from '../GeoJSONUtil.js';\n/** @import {Feature} from 'geojson' */\n/** @import {LatLngExpression} from '../../geo/LatLng.js' */\n/** @import {PolylineOptions} from './Polyline.js' */\n\n/**\n * Options of `Polygon`.\n * @typedef {object} PolygonOptions\n * @property {boolean} [fill=true] Whether to fill the polygon with color.\n * @extends PolylineOptions\n */\n\n/**\n * A class for drawing polygon overlays on a map. Extends `Polyline`.\n *\n * Note that points you pass when creating a polygon shouldn't have an additional last\n * point equal to the first one — it's better to filter out such points.\n *\n * @example\n * ```js\n * // create a red polygon from an array of LatLng points\n * const latlngs = [[37, -109.05],[41, -109.03],[41, -102.05],[37, -102.04]];\n *\n * const polygon = new Polygon(latlngs, {color: 'red'}).addTo(map);\n *\n * // zoom the map to the polygon\n * map.fitBounds(polygon.getBounds());\n * ```\n *\n * You can also pass an array of arrays of latlngs, with the first array representing\n * the outer shape and the other arrays representing holes in the outer shape:\n *\n * ```js\n * const latlngs = [\n * [[37, -109.05],[41, -109.03],[41, -102.05],[37, -102.04]], // outer ring\n * [[37.29, -108.58],[40.71, -108.58],[40.71, -102.50],[37.29, -102.50]] // hole\n * ];\n * ```\n *\n * Additionally, you can pass a multi-dimensional array to represent a MultiPolygon shape.\n *\n * ```js\n * const latlngs = [\n * [ // first polygon\n * [[37, -109.05],[41, -109.03],[41, -102.05],[37, -102.04]], // outer ring\n * [[37.29, -108.58],[40.71, -108.58],[40.71, -102.50],[37.29, -102.50]] // hole\n * ],\n * [ // second polygon\n * [[41, -111.03],[45, -111.04],[45, -104.05],[41, -104.05]]\n * ]\n * ];\n * ```\n */\nexport class Polygon extends Polyline {\n\n\tstatic defaultOptions = {\n\t\tfill: true\n\t};\n\n\t/**\n\t * Instantiates a polygon object given an array of geographical points (or arrays\n\t * of them for holes and multi-polygons) and optionally an options object.\n\t * @overload\n\t * @param {LatLngExpression[]|LatLngExpression[][]|LatLngExpression[][][]} latlngs\n\t * @param {PolygonOptions} [options]\n\t */\n\t/**\n\t * @param {...any} args\n\t */\n\tconstructor(...args) {\n\t\tsuper(...args);\n\t\tthis.callInitHooks(Polygon);\n\t}\n\n\t/**\n\t * Returns `true` if the Polygon has no LatLngs.\n\t * @returns {boolean}\n\t */\n\tisEmpty() {\n\t\treturn !this._latlngs.length || !this._latlngs[0].length;\n\t}\n\n\t/**\n\t * Returns the center ([centroid](http://en.wikipedia.org/wiki/Centroid)) of the Polygon.\n\t * @returns {LatLng}\n\t */\n\tgetCenter() {\n\t\t// throws error when not yet added to map as this center calculation requires projected coordinates\n\t\tif (!this._map) {\n\t\t\tthrow new Error('Must add layer to map before using getCenter()');\n\t\t}\n\t\treturn PolyUtil.polygonCenter(this._defaultShape(), this._map.options.crs);\n\t}\n\n\t_convertLatLngs(latlngs) {\n\t\tconst result = super._convertLatLngs(latlngs),\n\t\tlen = result.length;\n\n\t\t// remove last point if it equals first one\n\t\tif (len >= 2 && result[0] instanceof LatLng && result[0].equals(result[len - 1])) {\n\t\t\tresult.pop();\n\t\t}\n\t\treturn result;\n\t}\n\n\t_setLatLngs(latlngs) {\n\t\tsuper._setLatLngs(latlngs);\n\t\tif (LineUtil.isFlat(this._latlngs)) {\n\t\t\tthis._latlngs = [this._latlngs];\n\t\t}\n\t}\n\n\t_defaultShape() {\n\t\treturn LineUtil.isFlat(this._latlngs[0]) ? this._latlngs[0] : this._latlngs[0][0];\n\t}\n\n\t_clipPoints() {\n\t\t// polygons need a different clipping algorithm so we redefine that\n\n\t\tlet bounds = this._renderer._bounds;\n\t\tconst w = this.options.weight,\n\t\tp = new Point(w, w);\n\n\t\t// increase clip padding by stroke width to avoid stroke on clip edges\n\t\tbounds = new Bounds(bounds.min.subtract(p), bounds.max.add(p));\n\n\t\tthis._parts = [];\n\t\tif (!this._pxBounds || !this._pxBounds.intersects(bounds)) {\n\t\t\treturn;\n\t\t}\n\n\t\tif (this.options.noClip) {\n\t\t\tthis._parts = this._rings;\n\t\t\treturn;\n\t\t}\n\n\t\tfor (const ring of this._rings) {\n\t\t\tconst clipped = PolyUtil.clipPolygon(ring, bounds, true);\n\t\t\tif (clipped.length) {\n\t\t\t\tthis._parts.push(clipped);\n\t\t\t}\n\t\t}\n\t}\n\n\t_updatePath() {\n\t\tthis._renderer._updatePoly(this, true);\n\t}\n\n\t// Needed by the `Canvas` renderer for interactivity\n\t_containsPoint(p) {\n\t\tlet inside = false,\n\t\tpart, p1, p2, i, j, k, len, len2;\n\n\t\tif (!this._pxBounds || !this._pxBounds.contains(p)) { return false; }\n\n\t\t// ray casting algorithm for detecting if point is in polygon\n\t\tfor (i = 0, len = this._parts.length; i < len; i++) {\n\t\t\tpart = this._parts[i];\n\n\t\t\tfor (j = 0, len2 = part.length, k = len2 - 1; j < len2; k = j++) {\n\t\t\t\tp1 = part[j];\n\t\t\t\tp2 = part[k];\n\n\t\t\t\tif (((p1.y > p.y) !== (p2.y > p.y)) && (p.x < (p2.x - p1.x) * (p.y - p1.y) / (p2.y - p1.y) + p1.x)) {\n\t\t\t\t\tinside = !inside;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t// also check if it's on polygon stroke\n\t\treturn inside || super._containsPoint(p, true);\n\t}\n\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 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 = 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 getFeature(this, {\n\t\t\ttype: `${multi ? 'Multi' : ''}Polygon`,\n\t\t\tcoordinates: coords\n\t\t});\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2DA,IAAa,UAAb,MAAa,gBAAgB,SAAS;CAErC,OAAO,iBAAiB,EACvB,MAAM,KACP;;;;;;;;;;;CAYA,YAAY,GAAG,MAAM;EACpB,MAAM,GAAG,IAAI;EACb,KAAK,cAAc,OAAO;CAC3B;;;;;CAMA,UAAU;EACT,OAAO,CAAC,KAAK,SAAS,UAAU,CAAC,KAAK,SAAS,EAAE,CAAC;CACnD;;;;;CAMA,YAAY;EAEX,IAAI,CAAC,KAAK,MACT,MAAM,IAAI,MAAM,gDAAgD;EAEjE,OAAOA,cAAuB,KAAK,cAA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KAAK,KAAK;GACnD,OAAO,KAAK,OAAO;GAEnB,KAAK,IAAI,GAAG,OAAO,KAAK,QAAQ,IAAI,OAAO,GAAG,IAAI,MAAM,IAAI,KAAK;IAChE,KAAK,KAAK;IACV,KAAK,KAAK;IAEV,IAAM,GAAG,IAAI,EAAE,MAAQ,GAAG,IAAI,EAAE,KAAQ,EAAE,KAAK,GAAG,IAAI,GAAG,MAAM,EAAE,IAAI,GAAG,MAAM,GAAG,IAAI,GAAG,KAAK,GAAG,GAC/F,SAAS,CAAC;GAEZ;EACD;EAGA,OAAO,UAAU,MAAM,eAAe,GAAG,IAAI;CAC9C;;;;;;;;CAUA,UAAU,WAAW;EACpB,MAAM,QAAQ,CAACD,OAAgB,KAAK,QAAQ,GAC5C,QAAQ,SAAS,CAACA,OAAgB,KAAK,SAAS,EAAE;EAElD,IAAI,SAAS,gBAAgB,KAAK,UAAU,QAAQ,IAAI,QAAQ,IAAI,GAAG,MAAM,SAAS;EAEtF,IAAI,CAAC,OACJ,SAAS,CAAC,MAAM;EAGjB,OAAO,WAAW,MAAM;GACvB,MAAM,GAAG,QAAQ,UAAU,GAAG;GAC9B,aAAa;EACd,CAAC;CACF;AACD"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { stamp } from "../../core/Util.js";
|
|
2
2
|
import { Point } from "../../geometry/Point.js";
|
|
3
|
-
import { Path } from "./Path.js";
|
|
4
|
-
import { Canvas } from "./Canvas.js";
|
|
5
3
|
import { SVG } from "./SVG.js";
|
|
4
|
+
import { Path } from "./Path.js";
|
|
6
5
|
import { Polyline } from "./Polyline.js";
|
|
6
|
+
import { Canvas } from "./Canvas.js";
|
|
7
7
|
//#region src/layer/vector/Polyline.Decorations.js
|
|
8
8
|
/**
|
|
9
9
|
* Options of `Path` for arrowheads and text along lines (for `Polyline`s and
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { setOptions } from "../../core/Util.js";
|
|
2
2
|
import { Point } from "../../geometry/Point.js";
|
|
3
|
-
import { Path } from "./Path.js";
|
|
4
3
|
import { Bounds } from "../../geometry/Bounds.js";
|
|
4
|
+
import { Path } from "./Path.js";
|
|
5
5
|
import { LatLngBounds } from "../../geo/LatLngBounds.js";
|
|
6
6
|
import { LatLng } from "../../geo/LatLng.js";
|
|
7
7
|
import { _sqClosestPointOnSegment, clipSegment, isFlat, pointToSegmentDistance, polylineCenter, simplify } from "../../geometry/LineUtil.js";
|
|
8
|
+
import { getFeature, latLngsToCoords } from "../GeoJSONUtil.js";
|
|
8
9
|
//#region src/layer/vector/Polyline.js
|
|
10
|
+
/** @import {Feature} from 'geojson' */
|
|
9
11
|
/** @import {LatLngExpression} from '../../geo/LatLng.js' */
|
|
10
12
|
/** @import {PointExpression} from '../../geometry/Point.js' */
|
|
11
13
|
/** @import {PathOptions} from './Path.js' */
|
|
@@ -51,12 +53,10 @@ import { _sqClosestPointOnSegment, clipSegment, isFlat, pointToSegmentDistance,
|
|
|
51
53
|
* ```
|
|
52
54
|
*/
|
|
53
55
|
var Polyline = class Polyline extends Path {
|
|
54
|
-
static {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
});
|
|
59
|
-
}
|
|
56
|
+
static defaultOptions = {
|
|
57
|
+
smoothFactor: .5,
|
|
58
|
+
noClip: false
|
|
59
|
+
};
|
|
60
60
|
/**
|
|
61
61
|
* Instantiates a polyline object given an array of geographical points and
|
|
62
62
|
* optionally an options object. You can create a `Polyline` object with
|
|
@@ -234,6 +234,22 @@ var Polyline = class Polyline extends Path {
|
|
|
234
234
|
}
|
|
235
235
|
return false;
|
|
236
236
|
}
|
|
237
|
+
/**
|
|
238
|
+
* Coordinates values are rounded with [`formatNum`](#util-formatnum) to the
|
|
239
|
+
* given `precision`. Returns a [`GeoJSON`](https://en.wikipedia.org/wiki/GeoJSON)
|
|
240
|
+
* representation of the polyline (as a GeoJSON `LineString` or `MultiLineString`
|
|
241
|
+
* Feature).
|
|
242
|
+
* @param {number|false} [precision]
|
|
243
|
+
* @returns {Feature}
|
|
244
|
+
*/
|
|
245
|
+
toGeoJSON(precision) {
|
|
246
|
+
const multi = !isFlat(this._latlngs);
|
|
247
|
+
const coords = latLngsToCoords(this._latlngs, multi ? 1 : 0, false, precision);
|
|
248
|
+
return getFeature(this, {
|
|
249
|
+
type: `${multi ? "Multi" : ""}LineString`,
|
|
250
|
+
coordinates: coords
|
|
251
|
+
});
|
|
252
|
+
}
|
|
237
253
|
};
|
|
238
254
|
//#endregion
|
|
239
255
|
export { Polyline };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Polyline.js","names":["LineUtil._sqClosestPointOnSegment","LineUtil.polylineCenter","LineUtil.isFlat","LineUtil.clipSegment","LineUtil.simplify","LineUtil.pointToSegmentDistance"],"sources":["../../../../src/layer/vector/Polyline.js"],"sourcesContent":["import {Path} from './Path.js';\nimport * as Util from '../../core/Util.js';\nimport * as LineUtil from '../../geometry/LineUtil.js';\nimport {LatLng} from '../../geo/LatLng.js';\nimport {LatLngBounds} from '../../geo/LatLngBounds.js';\nimport {Bounds} from '../../geometry/Bounds.js';\nimport {Point} from '../../geometry/Point.js';\n/** @import {LatLngExpression} from '../../geo/LatLng.js' */\n/** @import {PointExpression} from '../../geometry/Point.js' */\n/** @import {PathOptions} from './Path.js' */\n\n/**\n * Options of `Polyline`.\n * @typedef {object} PolylineOptions\n * @property {number} [smoothFactor=0.5] How much to simplify the polyline on each zoom\n * level (Douglas–Peucker epsilon, in pixels). Higher values mean faster rendering but\n * less accuracy; lower values mean more accuracy but slower rendering.\n * @property {boolean} [noClip=false] Disable polyline clipping.\n * @extends PathOptions\n */\n\n/**\n * A class for drawing polyline overlays on a map. Extends `Path`.\n *\n * @example\n * ```js\n * // create a red polyline from an array of LatLng points\n * const latlngs = [\n * \t[45.51, -122.68],\n * \t[37.77, -122.43],\n * \t[34.04, -118.2]\n * ];\n *\n * const polyline = new Polyline(latlngs, {color: 'red'}).addTo(map);\n *\n * // zoom the map to the polyline\n * map.fitBounds(polyline.getBounds());\n * ```\n *\n * You can also pass a multi-dimensional array to represent a `MultiPolyline` shape:\n *\n * ```js\n * // create a red polyline from an array of arrays of LatLng points\n * const latlngs = [\n * \t[[45.51, -122.68],\n * \t [37.77, -122.43],\n * \t [34.04, -118.2]],\n * \t[[40.78, -73.91],\n * \t [41.83, -87.62],\n * \t [32.76, -96.72]]\n * ];\n * ```\n */\nexport class Polyline extends Path {\n\n\tstatic {\n\t\tthis.setDefaultOptions({\n\t\t\tsmoothFactor: 0.5,\n\t\t\tnoClip: false\n\t\t});\n\t}\n\n\t/**\n\t * Instantiates a polyline object given an array of geographical points and\n\t * optionally an options object. You can create a `Polyline` object with\n\t * multiple separate lines (`MultiPolyline`) by passing an array of arrays\n\t * of geographic points.\n\t * @param {LatLngExpression[]|LatLngExpression[][]|LatLngExpression[][][]} latlngs\n\t * @param {PolylineOptions} [options]\n\t */\n\tconstructor(latlngs, options) {\n\t\tsuper();\n\t\tUtil.setOptions(this, options);\n\t\tthis._setLatLngs(latlngs);\n\n\t\tthis.callInitHooks(Polyline);\n\t}\n\n\t/**\n\t * Returns an array of the points in the path, or nested arrays of points in case of\n\t * multi-polyline.\n\t * @returns {LatLng[]|LatLng[][]|LatLng[][][]}\n\t */\n\tgetLatLngs() {\n\t\treturn this._latlngs;\n\t}\n\n\t/**\n\t * Replaces all the points in the polyline with the given array of geographical points.\n\t * @param {LatLngExpression[]|LatLngExpression[][]|LatLngExpression[][][]} latlngs\n\t * @returns {this}\n\t */\n\tsetLatLngs(latlngs) {\n\t\tthis._setLatLngs(latlngs);\n\t\treturn this.redraw();\n\t}\n\n\t/**\n\t * Returns `true` if the Polyline has no LatLngs.\n\t * @returns {boolean}\n\t */\n\tisEmpty() {\n\t\treturn !this._latlngs.length;\n\t}\n\n\t/**\n\t * Returns the point closest to `p` on the Polyline, with its `distance` to `p` in\n\t * pixels, or `null` if the polyline is not visible.\n\t * @param {PointExpression} p\n\t * @returns {(Point & {distance: number})|null}\n\t */\n\tclosestLayerPoint(p) {\n\t\tp = Point.from(p);\n\t\tlet minDistance = Infinity,\n\t\tminPoint = null,\n\t\tp1, p2;\n\t\tconst closest = LineUtil._sqClosestPointOnSegment;\n\n\t\tfor (const points of this._parts) {\n\t\t\tfor (let i = 1, len = points.length; i < len; i++) {\n\t\t\t\tp1 = points[i - 1];\n\t\t\t\tp2 = points[i];\n\n\t\t\t\tconst sqDist = closest(p, p1, p2, true);\n\n\t\t\t\tif (sqDist < minDistance) {\n\t\t\t\t\tminDistance = sqDist;\n\t\t\t\t\tminPoint = closest(p, p1, p2);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif (minPoint) {\n\t\t\tminPoint.distance = Math.sqrt(minDistance);\n\t\t}\n\t\treturn minPoint;\n\t}\n\n\t/**\n\t * Returns the center ([centroid](https://en.wikipedia.org/wiki/Centroid)) of the polyline.\n\t * @returns {LatLng}\n\t */\n\tgetCenter() {\n\t\t// throws error when not yet added to map as this center calculation requires projected coordinates\n\t\tif (!this._map) {\n\t\t\tthrow new Error('Must add layer to map before using getCenter()');\n\t\t}\n\t\treturn LineUtil.polylineCenter(this._defaultShape(), this._map.options.crs);\n\t}\n\n\t/**\n\t * Returns the `LatLngBounds` of the path.\n\t * @returns {LatLngBounds}\n\t */\n\tgetBounds() {\n\t\treturn this._bounds;\n\t}\n\n\t/**\n\t * Adds a given point to the polyline. By default, adds to the first ring of\n\t * the polyline in case of a multi-polyline, but can be overridden by passing\n\t * a specific ring as a LatLng array (that you can earlier access with\n\t * [`getLatLngs`](#polyline-getlatlngs)).\n\t * @param {LatLngExpression} latlng\n\t * @param {LatLng[]} [latlngs]\n\t * @returns {this}\n\t */\n\taddLatLng(latlng, latlngs) {\n\t\tlatlngs ??= this._defaultShape();\n\t\tlatlng = new LatLng(latlng);\n\t\tlatlngs.push(latlng);\n\t\tthis._bounds.extend(latlng);\n\t\treturn this.redraw();\n\t}\n\n\t_setLatLngs(latlngs) {\n\t\tthis._bounds = new LatLngBounds();\n\t\tthis._latlngs = this._convertLatLngs(latlngs);\n\t}\n\n\t_defaultShape() {\n\t\treturn LineUtil.isFlat(this._latlngs) ? this._latlngs : this._latlngs[0];\n\t}\n\n\t// recursively convert latlngs input into actual LatLng instances; calculate bounds along the way\n\t_convertLatLngs(latlngs) {\n\t\tconst result = [],\n\t\tflat = LineUtil.isFlat(latlngs);\n\n\t\tfor (let i = 0, len = latlngs.length; i < len; i++) {\n\t\t\tif (flat) {\n\t\t\t\tresult[i] = new LatLng(latlngs[i]);\n\t\t\t\tthis._bounds.extend(result[i]);\n\t\t\t} else {\n\t\t\t\tresult[i] = this._convertLatLngs(latlngs[i]);\n\t\t\t}\n\t\t}\n\n\t\treturn result;\n\t}\n\n\t_project() {\n\t\tconst pxBounds = new Bounds();\n\t\tthis._rings = [];\n\t\tthis._projectLatlngs(this._latlngs, this._rings, pxBounds);\n\n\t\tif (this._bounds.isValid() && pxBounds.isValid()) {\n\t\t\tthis._rawPxBounds = pxBounds;\n\t\t\tthis._updateBounds();\n\t\t}\n\t}\n\n\t_updateBounds() {\n\t\tconst w = this._clickTolerance(),\n\t\tp = new Point(w, w);\n\n\t\tif (!this._rawPxBounds) {\n\t\t\treturn;\n\t\t}\n\n\t\tthis._pxBounds = new Bounds([\n\t\t\tthis._rawPxBounds.min.subtract(p),\n\t\t\tthis._rawPxBounds.max.add(p)\n\t\t]);\n\t}\n\n\t// recursively turns latlngs into a set of rings with projected coordinates\n\t_projectLatlngs(latlngs, result, projectedBounds) {\n\t\tconst flat = latlngs[0] instanceof LatLng;\n\n\t\tif (flat) {\n\t\t\tconst ring = latlngs.map(latlng => this._map.latLngToLayerPoint(latlng));\n\t\t\tring.forEach(r => projectedBounds.extend(r));\n\t\t\tresult.push(ring);\n\t\t} else {\n\t\t\tlatlngs.forEach(latlng => this._projectLatlngs(latlng, result, projectedBounds));\n\t\t}\n\t}\n\n\t// clip polyline by renderer bounds so that we have less to render for performance\n\t_clipPoints() {\n\t\tconst bounds = this._renderer._bounds;\n\n\t\tthis._parts = [];\n\t\tif (!this._pxBounds || !this._pxBounds.intersects(bounds)) {\n\t\t\treturn;\n\t\t}\n\n\t\tif (this.options.noClip) {\n\t\t\tthis._parts = this._rings;\n\t\t\treturn;\n\t\t}\n\n\t\tconst parts = this._parts;\n\t\tlet i, j, k, len, len2, segment, points;\n\n\t\tfor (i = 0, k = 0, len = this._rings.length; i < len; i++) {\n\t\t\tpoints = this._rings[i];\n\n\t\t\tfor (j = 0, len2 = points.length; j < len2 - 1; j++) {\n\t\t\t\tsegment = LineUtil.clipSegment(points[j], points[j + 1], bounds, j, true);\n\n\t\t\t\tif (!segment) { continue; }\n\n\t\t\t\tparts[k] ??= [];\n\t\t\t\tparts[k].push(segment[0]);\n\n\t\t\t\t// if segment goes out of screen, or it's the last one, it's the end of the line part\n\t\t\t\tif ((segment[1] !== points[j + 1]) || (j === len2 - 2)) {\n\t\t\t\t\tparts[k].push(segment[1]);\n\t\t\t\t\tk++;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\t// simplify each clipped part of the polyline for performance\n\t_simplifyPoints() {\n\t\tconst parts = this._parts,\n\t\ttolerance = this.options.smoothFactor;\n\n\t\tfor (let i = 0, len = parts.length; i < len; i++) {\n\t\t\tparts[i] = LineUtil.simplify(parts[i], tolerance);\n\t\t}\n\t}\n\n\t_update() {\n\t\tif (!this._map) { return; }\n\n\t\tthis._clipPoints();\n\t\tthis._simplifyPoints();\n\t\tthis._updatePath();\n\t}\n\n\t_updatePath() {\n\t\tthis._renderer._updatePoly(this);\n\t}\n\n\t// Needed by the `Canvas` renderer for interactivity\n\t_containsPoint(p, closed) {\n\t\tlet i, j, k, len, len2, part;\n\t\tconst w = this._clickTolerance();\n\n\t\tif (!this._pxBounds || !this._pxBounds.contains(p)) { return false; }\n\n\t\t// hit detection for polylines\n\t\tfor (i = 0, len = this._parts.length; i < len; i++) {\n\t\t\tpart = this._parts[i];\n\n\t\t\tfor (j = 0, len2 = part.length, k = len2 - 1; j < len2; k = j++) {\n\t\t\t\tif (!closed && (j === 0)) { continue; }\n\n\t\t\t\tif (LineUtil.pointToSegmentDistance(p, part[k], part[j]) <= w) {\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn false;\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqDA,IAAa,WAAb,MAAa,iBAAiB,KAAK;CAElC;EACC,KAAK,kBAAkB;GACtB,cAAc;GACd,QAAQ;EACT,CAAC;CACF;;;;;;;;;CAUA,YAAY,SAAS,SAAS;EAC7B,MAAM;EACN,WAAgB,MAAM,OAAO;EAC7B,KAAK,YAAY,OAAO;EAExB,KAAK,cAAc,QAAQ;CAC5B;;;;;;CAOA,aAAa;EACZ,OAAO,KAAK;CACb;;;;;;CAOA,WAAW,SAAS;EACnB,KAAK,YAAY,OAAO;EACxB,OAAO,KAAK,OAAO;CACpB;;;;;CAMA,UAAU;EACT,OAAO,CAAC,KAAK,SAAS;CACvB;;;;;;;CAQA,kBAAkB,GAAG;EACpB,IAAI,MAAM,KAAK,CAAC;EAChB,IAAI,cAAc,UAClB,WAAW,MACX,IAAI;EACJ,MAAM,UAAUA;EAEhB,KAAK,MAAM,UAAU,KAAK,QACzB,KAAK,IAAI,IAAI,GAAG,MAAM,OAAO,QAAQ,IAAI,KAAK,KAAK;GAClD,KAAK,OAAO,IAAI;GAChB,KAAK,OAAO;GAEZ,MAAM,SAAS,QAAQ,GAAG,IAAI,IAAI,IAAI;GAEtC,IAAI,SAAS,aAAa;IACzB,cAAc;IACd,WAAW,QAAQ,GAAG,IAAI,EAAE;GAC7B;EACD;EAED,IAAI,UACH,SAAS,WAAW,KAAK,KAAK,WAAW;EAE1C,OAAO;CACR;;;;;CAMA,YAAY;EAEX,IAAI,CAAC,KAAK,MACT,MAAM,IAAI,MAAM,gDAAgD;EAEjE,OAAOC,eAAwB,KAAK,cAAc,GAAG,KAAK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KAAK,gBAAgB;EACrB,KAAK,YAAY;CAClB;CAEA,cAAc;EACb,KAAK,UAAU,YAAY,IAAI;CAChC;CAGA,eAAe,GAAG,QAAQ;EACzB,IAAI,GAAG,GAAG,GAAG,KAAK,MAAM;EACxB,MAAM,IAAI,KAAK,gBAAgB;EAE/B,IAAI,CAAC,KAAK,aAAa,CAAC,KAAK,UAAU,SAAS,CAAC,GAAK,OAAO;EAG7D,KAAK,IAAI,GAAG,MAAM,KAAK,OAAO,QAAQ,IAAI,KAAK,KAAK;GACnD,OAAO,KAAK,OAAO;GAEnB,KAAK,IAAI,GAAG,OAAO,KAAK,QAAQ,IAAI,OAAO,GAAG,IAAI,MAAM,IAAI,KAAK;IAChE,IAAI,CAAC,UAAW,MAAM,GAAM;IAE5B,IAAIC,uBAAgC,GAAG,KAAK,IAAI,KAAK,EAAE,KAAK,GAC3D,OAAO;GAET;EACD;EACA,OAAO;CACR;AACD"}
|
|
1
|
+
{"version":3,"file":"Polyline.js","names":["LineUtil._sqClosestPointOnSegment","LineUtil.polylineCenter","LineUtil.isFlat","LineUtil.clipSegment","LineUtil.simplify","LineUtil.pointToSegmentDistance"],"sources":["../../../../src/layer/vector/Polyline.js"],"sourcesContent":["import {Path} from './Path.js';\nimport * as Util from '../../core/Util.js';\nimport * as LineUtil from '../../geometry/LineUtil.js';\nimport {LatLng} from '../../geo/LatLng.js';\nimport {LatLngBounds} from '../../geo/LatLngBounds.js';\nimport {Bounds} from '../../geometry/Bounds.js';\nimport {Point} from '../../geometry/Point.js';\nimport {latLngsToCoords, getFeature} from '../GeoJSONUtil.js';\n/** @import {Feature} from 'geojson' */\n/** @import {LatLngExpression} from '../../geo/LatLng.js' */\n/** @import {PointExpression} from '../../geometry/Point.js' */\n/** @import {PathOptions} from './Path.js' */\n\n/**\n * Options of `Polyline`.\n * @typedef {object} PolylineOptions\n * @property {number} [smoothFactor=0.5] How much to simplify the polyline on each zoom\n * level (Douglas–Peucker epsilon, in pixels). Higher values mean faster rendering but\n * less accuracy; lower values mean more accuracy but slower rendering.\n * @property {boolean} [noClip=false] Disable polyline clipping.\n * @extends PathOptions\n */\n\n/**\n * A class for drawing polyline overlays on a map. Extends `Path`.\n *\n * @example\n * ```js\n * // create a red polyline from an array of LatLng points\n * const latlngs = [\n * \t[45.51, -122.68],\n * \t[37.77, -122.43],\n * \t[34.04, -118.2]\n * ];\n *\n * const polyline = new Polyline(latlngs, {color: 'red'}).addTo(map);\n *\n * // zoom the map to the polyline\n * map.fitBounds(polyline.getBounds());\n * ```\n *\n * You can also pass a multi-dimensional array to represent a `MultiPolyline` shape:\n *\n * ```js\n * // create a red polyline from an array of arrays of LatLng points\n * const latlngs = [\n * \t[[45.51, -122.68],\n * \t [37.77, -122.43],\n * \t [34.04, -118.2]],\n * \t[[40.78, -73.91],\n * \t [41.83, -87.62],\n * \t [32.76, -96.72]]\n * ];\n * ```\n */\nexport class Polyline extends Path {\n\n\tstatic defaultOptions = {\n\t\tsmoothFactor: 0.5,\n\t\tnoClip: false\n\t};\n\n\t/**\n\t * Instantiates a polyline object given an array of geographical points and\n\t * optionally an options object. You can create a `Polyline` object with\n\t * multiple separate lines (`MultiPolyline`) by passing an array of arrays\n\t * of geographic points.\n\t * @param {LatLngExpression[]|LatLngExpression[][]|LatLngExpression[][][]} latlngs\n\t * @param {PolylineOptions} [options]\n\t */\n\tconstructor(latlngs, options) {\n\t\tsuper();\n\t\tUtil.setOptions(this, options);\n\t\tthis._setLatLngs(latlngs);\n\n\t\tthis.callInitHooks(Polyline);\n\t}\n\n\t/**\n\t * Returns an array of the points in the path, or nested arrays of points in case of\n\t * multi-polyline.\n\t * @returns {LatLng[]|LatLng[][]|LatLng[][][]}\n\t */\n\tgetLatLngs() {\n\t\treturn this._latlngs;\n\t}\n\n\t/**\n\t * Replaces all the points in the polyline with the given array of geographical points.\n\t * @param {LatLngExpression[]|LatLngExpression[][]|LatLngExpression[][][]} latlngs\n\t * @returns {this}\n\t */\n\tsetLatLngs(latlngs) {\n\t\tthis._setLatLngs(latlngs);\n\t\treturn this.redraw();\n\t}\n\n\t/**\n\t * Returns `true` if the Polyline has no LatLngs.\n\t * @returns {boolean}\n\t */\n\tisEmpty() {\n\t\treturn !this._latlngs.length;\n\t}\n\n\t/**\n\t * Returns the point closest to `p` on the Polyline, with its `distance` to `p` in\n\t * pixels, or `null` if the polyline is not visible.\n\t * @param {PointExpression} p\n\t * @returns {(Point & {distance: number})|null}\n\t */\n\tclosestLayerPoint(p) {\n\t\tp = Point.from(p);\n\t\tlet minDistance = Infinity,\n\t\tminPoint = null,\n\t\tp1, p2;\n\t\tconst closest = LineUtil._sqClosestPointOnSegment;\n\n\t\tfor (const points of this._parts) {\n\t\t\tfor (let i = 1, len = points.length; i < len; i++) {\n\t\t\t\tp1 = points[i - 1];\n\t\t\t\tp2 = points[i];\n\n\t\t\t\tconst sqDist = closest(p, p1, p2, true);\n\n\t\t\t\tif (sqDist < minDistance) {\n\t\t\t\t\tminDistance = sqDist;\n\t\t\t\t\tminPoint = closest(p, p1, p2);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif (minPoint) {\n\t\t\tminPoint.distance = Math.sqrt(minDistance);\n\t\t}\n\t\treturn minPoint;\n\t}\n\n\t/**\n\t * Returns the center ([centroid](https://en.wikipedia.org/wiki/Centroid)) of the polyline.\n\t * @returns {LatLng}\n\t */\n\tgetCenter() {\n\t\t// throws error when not yet added to map as this center calculation requires projected coordinates\n\t\tif (!this._map) {\n\t\t\tthrow new Error('Must add layer to map before using getCenter()');\n\t\t}\n\t\treturn LineUtil.polylineCenter(this._defaultShape(), this._map.options.crs);\n\t}\n\n\t/**\n\t * Returns the `LatLngBounds` of the path.\n\t * @returns {LatLngBounds}\n\t */\n\tgetBounds() {\n\t\treturn this._bounds;\n\t}\n\n\t/**\n\t * Adds a given point to the polyline. By default, adds to the first ring of\n\t * the polyline in case of a multi-polyline, but can be overridden by passing\n\t * a specific ring as a LatLng array (that you can earlier access with\n\t * [`getLatLngs`](#polyline-getlatlngs)).\n\t * @param {LatLngExpression} latlng\n\t * @param {LatLng[]} [latlngs]\n\t * @returns {this}\n\t */\n\taddLatLng(latlng, latlngs) {\n\t\tlatlngs ??= this._defaultShape();\n\t\tlatlng = new LatLng(latlng);\n\t\tlatlngs.push(latlng);\n\t\tthis._bounds.extend(latlng);\n\t\treturn this.redraw();\n\t}\n\n\t_setLatLngs(latlngs) {\n\t\tthis._bounds = new LatLngBounds();\n\t\tthis._latlngs = this._convertLatLngs(latlngs);\n\t}\n\n\t_defaultShape() {\n\t\treturn LineUtil.isFlat(this._latlngs) ? this._latlngs : this._latlngs[0];\n\t}\n\n\t// recursively convert latlngs input into actual LatLng instances; calculate bounds along the way\n\t_convertLatLngs(latlngs) {\n\t\tconst result = [],\n\t\tflat = LineUtil.isFlat(latlngs);\n\n\t\tfor (let i = 0, len = latlngs.length; i < len; i++) {\n\t\t\tif (flat) {\n\t\t\t\tresult[i] = new LatLng(latlngs[i]);\n\t\t\t\tthis._bounds.extend(result[i]);\n\t\t\t} else {\n\t\t\t\tresult[i] = this._convertLatLngs(latlngs[i]);\n\t\t\t}\n\t\t}\n\n\t\treturn result;\n\t}\n\n\t_project() {\n\t\tconst pxBounds = new Bounds();\n\t\tthis._rings = [];\n\t\tthis._projectLatlngs(this._latlngs, this._rings, pxBounds);\n\n\t\tif (this._bounds.isValid() && pxBounds.isValid()) {\n\t\t\tthis._rawPxBounds = pxBounds;\n\t\t\tthis._updateBounds();\n\t\t}\n\t}\n\n\t_updateBounds() {\n\t\tconst w = this._clickTolerance(),\n\t\tp = new Point(w, w);\n\n\t\tif (!this._rawPxBounds) {\n\t\t\treturn;\n\t\t}\n\n\t\tthis._pxBounds = new Bounds([\n\t\t\tthis._rawPxBounds.min.subtract(p),\n\t\t\tthis._rawPxBounds.max.add(p)\n\t\t]);\n\t}\n\n\t// recursively turns latlngs into a set of rings with projected coordinates\n\t_projectLatlngs(latlngs, result, projectedBounds) {\n\t\tconst flat = latlngs[0] instanceof LatLng;\n\n\t\tif (flat) {\n\t\t\tconst ring = latlngs.map(latlng => this._map.latLngToLayerPoint(latlng));\n\t\t\tring.forEach(r => projectedBounds.extend(r));\n\t\t\tresult.push(ring);\n\t\t} else {\n\t\t\tlatlngs.forEach(latlng => this._projectLatlngs(latlng, result, projectedBounds));\n\t\t}\n\t}\n\n\t// clip polyline by renderer bounds so that we have less to render for performance\n\t_clipPoints() {\n\t\tconst bounds = this._renderer._bounds;\n\n\t\tthis._parts = [];\n\t\tif (!this._pxBounds || !this._pxBounds.intersects(bounds)) {\n\t\t\treturn;\n\t\t}\n\n\t\tif (this.options.noClip) {\n\t\t\tthis._parts = this._rings;\n\t\t\treturn;\n\t\t}\n\n\t\tconst parts = this._parts;\n\t\tlet i, j, k, len, len2, segment, points;\n\n\t\tfor (i = 0, k = 0, len = this._rings.length; i < len; i++) {\n\t\t\tpoints = this._rings[i];\n\n\t\t\tfor (j = 0, len2 = points.length; j < len2 - 1; j++) {\n\t\t\t\tsegment = LineUtil.clipSegment(points[j], points[j + 1], bounds, j, true);\n\n\t\t\t\tif (!segment) { continue; }\n\n\t\t\t\tparts[k] ??= [];\n\t\t\t\tparts[k].push(segment[0]);\n\n\t\t\t\t// if segment goes out of screen, or it's the last one, it's the end of the line part\n\t\t\t\tif ((segment[1] !== points[j + 1]) || (j === len2 - 2)) {\n\t\t\t\t\tparts[k].push(segment[1]);\n\t\t\t\t\tk++;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\t// simplify each clipped part of the polyline for performance\n\t_simplifyPoints() {\n\t\tconst parts = this._parts,\n\t\ttolerance = this.options.smoothFactor;\n\n\t\tfor (let i = 0, len = parts.length; i < len; i++) {\n\t\t\tparts[i] = LineUtil.simplify(parts[i], tolerance);\n\t\t}\n\t}\n\n\t_update() {\n\t\tif (!this._map) { return; }\n\n\t\tthis._clipPoints();\n\t\tthis._simplifyPoints();\n\t\tthis._updatePath();\n\t}\n\n\t_updatePath() {\n\t\tthis._renderer._updatePoly(this);\n\t}\n\n\t// Needed by the `Canvas` renderer for interactivity\n\t_containsPoint(p, closed) {\n\t\tlet i, j, k, len, len2, part;\n\t\tconst w = this._clickTolerance();\n\n\t\tif (!this._pxBounds || !this._pxBounds.contains(p)) { return false; }\n\n\t\t// hit detection for polylines\n\t\tfor (i = 0, len = this._parts.length; i < len; i++) {\n\t\t\tpart = this._parts[i];\n\n\t\t\tfor (j = 0, len2 = part.length, k = len2 - 1; j < len2; k = j++) {\n\t\t\t\tif (!closed && (j === 0)) { continue; }\n\n\t\t\t\tif (LineUtil.pointToSegmentDistance(p, part[k], part[j]) <= w) {\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn false;\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 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 = latLngsToCoords(this._latlngs, multi ? 1 : 0, false, precision);\n\n\t\treturn getFeature(this, {\n\t\t\ttype: `${multi ? 'Multi' : ''}LineString`,\n\t\t\tcoordinates: coords\n\t\t});\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuDA,IAAa,WAAb,MAAa,iBAAiB,KAAK;CAElC,OAAO,iBAAiB;EACvB,cAAc;EACd,QAAQ;CACT;;;;;;;;;CAUA,YAAY,SAAS,SAAS;EAC7B,MAAM;EACN,WAAgB,MAAM,OAAO;EAC7B,KAAK,YAAY,OAAO;EAExB,KAAK,cAAc,QAAQ;CAC5B;;;;;;CAOA,aAAa;EACZ,OAAO,KAAK;CACb;;;;;;CAOA,WAAW,SAAS;EACnB,KAAK,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AO;CACR;;;;;;;;;CAUA,UAAU,WAAW;EACpB,MAAM,QAAQ,CAACH,OAAgB,KAAK,QAAQ;EAE5C,MAAM,SAAS,gBAAgB,KAAK,UAAU,QAAQ,IAAI,GAAG,OAAO,SAAS;EAE7E,OAAO,WAAW,MAAM;GACvB,MAAM,GAAG,QAAQ,UAAU,GAAG;GAC9B,aAAa;EACd,CAAC;CACF;AACD"}
|
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
import { __exportAll } from "../../_virtual/_rolldown/runtime.js";
|
|
2
|
-
import { Canvas } from "./Canvas.js";
|
|
3
|
-
import { SVG } from "./SVG.js";
|
|
4
2
|
//#region src/layer/vector/Renderer.getRenderer.js
|
|
5
3
|
var Renderer_getRenderer_exports = /* @__PURE__ */ __exportAll({ register: () => register });
|
|
6
4
|
/** @import {MaplairMap} from '../../map/Map.js' */
|
|
@@ -20,22 +18,23 @@ const mapRendererMethods = {
|
|
|
20
18
|
* @returns {Renderer}
|
|
21
19
|
*/
|
|
22
20
|
getRenderer(layer) {
|
|
23
|
-
|
|
24
|
-
if (!renderer) renderer = this._renderer = this._createRenderer();
|
|
21
|
+
const renderer = layer.options.renderer ?? this._getPaneRenderer(layer) ?? this.options.renderer ?? (this._renderer ??= layer._createRenderer());
|
|
25
22
|
if (!this.hasLayer(renderer)) this.addLayer(renderer);
|
|
26
23
|
return renderer;
|
|
27
24
|
},
|
|
28
|
-
_getPaneRenderer(
|
|
25
|
+
_getPaneRenderer(layer) {
|
|
26
|
+
const name = layer.options.pane;
|
|
29
27
|
if (name === "overlayPane" || name === void 0) return;
|
|
30
28
|
let renderer = this._paneRenderers[name];
|
|
31
|
-
if (renderer
|
|
32
|
-
|
|
29
|
+
if (!renderer) {
|
|
30
|
+
const Renderer = this.options.renderer?.constructor;
|
|
31
|
+
renderer = Renderer ? new Renderer({
|
|
32
|
+
...this.options.renderer.options,
|
|
33
|
+
pane: name
|
|
34
|
+
}) : layer._createRenderer({ pane: name });
|
|
33
35
|
this._paneRenderers[name] = renderer;
|
|
34
36
|
}
|
|
35
37
|
return renderer;
|
|
36
|
-
},
|
|
37
|
-
_createRenderer(options) {
|
|
38
|
-
return this.options.preferCanvas && new Canvas(options) || new SVG(options);
|
|
39
38
|
}
|
|
40
39
|
};
|
|
41
40
|
/** @typedef {typeof mapRendererMethods} MapRendererMethods */
|
|
@@ -43,10 +42,9 @@ const mapRendererMethods = {
|
|
|
43
42
|
* Map options of the vector renderers.
|
|
44
43
|
* @typedef {object} RendererMapOptions
|
|
45
44
|
* @lends MaplairMapOptions
|
|
46
|
-
* @property {boolean} [preferCanvas=false] Whether `Path`s should be rendered on a
|
|
47
|
-
* `Canvas` renderer. By default, all `Path`s are rendered in a `SVG` renderer.
|
|
48
45
|
* @property {Renderer} [renderer] The default method for drawing vector layers on the
|
|
49
|
-
* map. `SVG`
|
|
46
|
+
* map. A new `SVG` renderer by default; pass `new Canvas()` to draw them on a canvas
|
|
47
|
+
* instead.
|
|
50
48
|
*/
|
|
51
49
|
/**
|
|
52
50
|
* Registers `getRenderer()` and related methods on the given map class, called by
|
|
@@ -56,6 +54,9 @@ const mapRendererMethods = {
|
|
|
56
54
|
*/
|
|
57
55
|
function register(MaplairMap) {
|
|
58
56
|
MaplairMap.include(mapRendererMethods);
|
|
57
|
+
MaplairMap.addInitHook(function() {
|
|
58
|
+
if (this.options.preferCanvas !== void 0) console.error("MaplairMap: preferCanvas option has been removed. Use renderer: new Canvas() instead.");
|
|
59
|
+
});
|
|
59
60
|
}
|
|
60
61
|
//#endregion
|
|
61
62
|
export { Renderer_getRenderer_exports, register };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Renderer.getRenderer.js","names":[],"sources":["../../../../src/layer/vector/Renderer.getRenderer.js"],"sourcesContent":["
|
|
1
|
+
{"version":3,"file":"Renderer.getRenderer.js","names":[],"sources":["../../../../src/layer/vector/Renderer.getRenderer.js"],"sourcesContent":["/** @import {MaplairMap} from '../../map/Map.js' */\n/** @import {Path} from './Path.js' */\n/** @import {Renderer} from './Renderer.js' */\n\n/**\n * Methods of `MaplairMap` for the renderers of vector layers.\n * @lends MaplairMap.prototype\n */\nconst mapRendererMethods = {\n\t/**\n\t * Returns the instance of `Renderer` that should be used to render the given\n\t * `Path`. It will ensure that the `renderer` options of the map and paths\n\t * are respected, and that the renderers do exist on the map.\n\t * @internal\n\t * @param {Path} layer\n\t * @returns {Renderer}\n\t */\n\tgetRenderer(layer) {\n\t\tconst renderer = layer.options.renderer ?? this._getPaneRenderer(layer) ?? this.options.renderer ??\n\t\t\t(this._renderer ??= layer._createRenderer());\n\n\t\tif (!this.hasLayer(renderer)) {\n\t\t\tthis.addLayer(renderer);\n\t\t}\n\t\treturn renderer;\n\t},\n\n\t_getPaneRenderer(layer) {\n\t\tconst name = layer.options.pane;\n\t\tif (name === 'overlayPane' || name === undefined) {\n\t\t\treturn;\n\t\t}\n\n\t\tlet renderer = this._paneRenderers[name];\n\t\tif (!renderer) {\n\t\t\t// custom panes get a renderer of the same kind as the map's default one, so Canvas maps stay Canvas\n\t\t\tconst Renderer = this.options.renderer?.constructor;\n\t\t\trenderer = Renderer ?\n\t\t\t\tnew Renderer({...this.options.renderer.options, pane: name}) :\n\t\t\t\tlayer._createRenderer({pane: name});\n\t\t\tthis._paneRenderers[name] = renderer;\n\t\t}\n\t\treturn renderer;\n\t}\n};\n/** @typedef {typeof mapRendererMethods} MapRendererMethods */\n\n/**\n * Map options of the vector renderers.\n * @typedef {object} RendererMapOptions\n * @lends MaplairMapOptions\n * @property {Renderer} [renderer] The default method for drawing vector layers on the\n * map. A new `SVG` renderer by default; pass `new Canvas()` to draw them on a canvas\n * instead.\n */\n\n/**\n * Registers `getRenderer()` and related methods on the given map class, called by\n * `MaplairMap` itself.\n * @internal\n * @param {typeof MaplairMap} MaplairMap\n */\nexport function register(MaplairMap) {\n\tMaplairMap.include(mapRendererMethods);\n\tMaplairMap.addInitHook(function () {\n\t\tif (this.options.preferCanvas !== undefined) {\n\t\t\tconsole.error('MaplairMap: preferCanvas option has been removed. Use renderer: new Canvas() instead.');\n\t\t}\n\t});\n}\n"],"mappings":";;;;;;;;;;AAQA,MAAM,qBAAqB;;;;;;;;;CAS1B,YAAY,OAAO;EAClB,MAAM,WAAW,MAAM,QAAQ,YAAY,KAAK,iBAAiB,KAAK,KAAK,KAAK,QAAQ,aACtF,KAAK,cAAc,MAAM,gBAAgB;EAE3C,IAAI,CAAC,KAAK,SAAS,QAAQ,GAC1B,KAAK,SAAS,QAAQ;EAEvB,OAAO;CACR;CAEA,iBAAiB,OAAO;EACvB,MAAM,OAAO,MAAM,QAAQ;EAC3B,IAAI,SAAS,iBAAiB,SAAS,KAAA,GACtC;EAGD,IAAI,WAAW,KAAK,eAAe;EACnC,IAAI,CAAC,UAAU;GAEd,MAAM,WAAW,KAAK,QAAQ,UAAU;GACxC,WAAW,WACV,IAAI,SAAS;IAAC,GAAG,KAAK,QAAQ,SAAS;IAAS,MAAM;GAAI,CAAC,IAC3D,MAAM,gBAAgB,EAAC,MAAM,KAAI,CAAC;GACnC,KAAK,eAAe,QAAQ;EAC7B;EACA,OAAO;CACR;AACD;;;;;;;;;;;;;;;;AAkBA,SAAgB,SAAS,YAAY;CACpC,WAAW,QAAQ,kBAAkB;CACrC,WAAW,YAAY,WAAY;EAClC,IAAI,KAAK,QAAQ,iBAAiB,KAAA,GACjC,QAAQ,MAAM,uFAAuF;CAEvG,CAAC;AACF"}
|
|
@@ -54,8 +54,8 @@ var SVG = class SVG extends Renderer {
|
|
|
54
54
|
const size = super._resizeContainer();
|
|
55
55
|
if (!this._svgSize || !this._svgSize.equals(size)) {
|
|
56
56
|
this._svgSize = size;
|
|
57
|
-
this._container.setAttribute("width", size.x);
|
|
58
|
-
this._container.setAttribute("height", size.y);
|
|
57
|
+
this._container.setAttribute("width", `${size.x}`);
|
|
58
|
+
this._container.setAttribute("height", `${size.y}`);
|
|
59
59
|
}
|
|
60
60
|
const b = this._bounds;
|
|
61
61
|
if (b) this._container.setAttribute("viewBox", [
|
|
@@ -105,8 +105,8 @@ var SVG = class SVG extends Renderer {
|
|
|
105
105
|
if (!path) return;
|
|
106
106
|
if (options.stroke) {
|
|
107
107
|
path.setAttribute("stroke", options.color);
|
|
108
|
-
path.setAttribute("stroke-opacity", options.opacity);
|
|
109
|
-
path.setAttribute("stroke-width", options.weight);
|
|
108
|
+
path.setAttribute("stroke-opacity", `${options.opacity}`);
|
|
109
|
+
path.setAttribute("stroke-width", `${options.weight}`);
|
|
110
110
|
path.setAttribute("stroke-linecap", options.lineCap);
|
|
111
111
|
path.setAttribute("stroke-linejoin", options.lineJoin);
|
|
112
112
|
if (options.dashArray) path.setAttribute("stroke-dasharray", options.dashArray);
|
|
@@ -116,7 +116,7 @@ var SVG = class SVG extends Renderer {
|
|
|
116
116
|
} else path.setAttribute("stroke", "none");
|
|
117
117
|
if (options.fill) {
|
|
118
118
|
path.setAttribute("fill", options.fillColor || options.color);
|
|
119
|
-
path.setAttribute("fill-opacity", options.fillOpacity);
|
|
119
|
+
path.setAttribute("fill-opacity", `${options.fillOpacity}`);
|
|
120
120
|
path.setAttribute("fill-rule", options.fillRule || "evenodd");
|
|
121
121
|
} else path.setAttribute("fill", "none");
|
|
122
122
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SVG.js","names":[],"sources":["../../../../src/layer/vector/SVG.js"],"sourcesContent":["import {Renderer} from './Renderer.js';\nimport * as DomUtil from '../../dom/DomUtil.js';\nimport {splitWords, stamp} from '../../core/Util.js';\n/** @import {Point} from '../../geometry/Point.js' */\n/** @import {RendererOptions} from './Renderer.js' */\n\n/**\n * Allows vector layers to be displayed with [SVG](https://developer.mozilla.org/docs/Web/SVG).\n * Inherits `Renderer`.\n *\n * @example\n * Use SVG by default for all paths in the map:\n *\n * ```js\n * const map = new MaplairMap('map', {\n * \trenderer: new SVG()\n * });\n * ```\n *\n * Use a SVG renderer with extra padding for specific vector geometries:\n *\n * ```js\n * const map = new MaplairMap('map');\n * const myRenderer = new SVG({ padding: 0.5 });\n * const line = new Polyline( coordinates, { renderer: myRenderer } );\n * const circle = new Circle( center, { renderer: myRenderer, radius: 100 } );\n * ```\n */\nexport class SVG extends Renderer {\n\t/**\n\t * Creates a SVG renderer with the given options.\n\t * @overload\n\t * @param {RendererOptions} [options]\n\t */\n\t/**\n\t * @param {...any} args\n\t */\n\tconstructor(...args) {\n\t\tsuper(...args);\n\t\tthis.callInitHooks(SVG);\n\t}\n\n\n\t_initContainer() {\n\t\tthis._container = SVG.create('svg');\n\n\t\t// makes it possible to click through svg root; we'll reset it back in individual paths\n\t\tthis._container.setAttribute('pointer-events', 'none');\n\n\t\tthis._rootGroup = SVG.create('g');\n\t\tthis._container.appendChild(this._rootGroup);\n\t}\n\n\t_destroyContainer() {\n\t\tsuper._destroyContainer();\n\t\tdelete this._rootGroup;\n\t\tdelete this._svgSize;\n\t}\n\n\t_resizeContainer() {\n\t\tconst size = super._resizeContainer();\n\n\t\t// set size of svg-container if changed\n\t\tif (!this._svgSize || !this._svgSize.equals(size)) {\n\t\t\tthis._svgSize = size;\n\t\t\tthis._container.setAttribute('width', size.x);\n\t\t\tthis._container.setAttribute('height', size.y);\n\t\t}\n\n\t\t// Reset the <SVG>'s viewBox as per _update, but skip redrawing paths.\n\t\t// This keeps paths visually aligned when resizing.\n\t\tconst b = this._bounds;\n\t\tif (b) {\n\t\t\tthis._container.setAttribute('viewBox', [b.min.x, b.min.y, size.x, size.y].join(' '));\n\t\t}\n\t}\n\n\t_update() {\n\t\tif (this._map._animatingZoom && this._bounds) { return; }\n\n\t\tconst b = this._bounds,\n\t\tsize = b.getSize();\n\n\t\t// movement: update container viewBox so that we don't have to change coordinates of individual layers\n\t\tthis._container.setAttribute('viewBox', [b.min.x, b.min.y, size.x, size.y].join(' '));\n\n\t\tthis.fire('update');\n\t}\n\n\t// methods below are called by vector layers implementations\n\n\t_initPath(layer) {\n\t\tconst path = layer._path = SVG.create('path');\n\n\t\tif (layer.options.className) {\n\t\t\tpath.classList.add(...splitWords(layer.options.className));\n\t\t}\n\n\t\tif (layer.options.interactive) {\n\t\t\tpath.classList.add('maplair-interactive');\n\t\t}\n\n\t\tthis._updateStyle(layer);\n\t\tthis._layers[stamp(layer)] = layer;\n\t}\n\n\t_updateInteractive(layer) {\n\t\tlayer._path.classList.toggle('maplair-interactive', !!layer.options.interactive);\n\t}\n\n\t_addPath(layer) {\n\t\tif (!this._rootGroup) { this._initContainer(); }\n\t\tthis._rootGroup.appendChild(layer._path);\n\t\tlayer.addInteractiveTarget(layer._path);\n\t}\n\n\t_removePath(layer) {\n\t\tlayer._path.remove();\n\t\tlayer.removeInteractiveTarget(layer._path);\n\t\tdelete this._layers[stamp(layer)];\n\t}\n\n\t_updatePath(layer) {\n\t\tlayer._project();\n\t\tlayer._update();\n\t}\n\n\t_updateStyle(layer) {\n\t\tconst path = layer._path,\n\t\toptions = layer.options;\n\n\t\tif (!path) { return; }\n\n\t\tif (options.stroke) {\n\t\t\tpath.setAttribute('stroke', options.color);\n\t\t\tpath.setAttribute('stroke-opacity', options.opacity);\n\t\t\tpath.setAttribute('stroke-width', options.weight);\n\t\t\tpath.setAttribute('stroke-linecap', options.lineCap);\n\t\t\tpath.setAttribute('stroke-linejoin', options.lineJoin);\n\n\t\t\tif (options.dashArray) {\n\t\t\t\tpath.setAttribute('stroke-dasharray', options.dashArray);\n\t\t\t} else {\n\t\t\t\tpath.removeAttribute('stroke-dasharray');\n\t\t\t}\n\n\t\t\tif (options.dashOffset) {\n\t\t\t\tpath.setAttribute('stroke-dashoffset', options.dashOffset);\n\t\t\t} else {\n\t\t\t\tpath.removeAttribute('stroke-dashoffset');\n\t\t\t}\n\t\t} else {\n\t\t\tpath.setAttribute('stroke', 'none');\n\t\t}\n\n\t\tif (options.fill) {\n\t\t\tpath.setAttribute('fill', options.fillColor || options.color);\n\t\t\tpath.setAttribute('fill-opacity', options.fillOpacity);\n\t\t\tpath.setAttribute('fill-rule', options.fillRule || 'evenodd');\n\t\t} else {\n\t\t\tpath.setAttribute('fill', 'none');\n\t\t}\n\t}\n\n\t_updatePoly(layer, closed) {\n\t\tthis._setPath(layer, SVG.pointsToPath(layer._parts, closed));\n\t}\n\n\t_updateCircle(layer) {\n\t\tconst p = layer._point,\n\t\tr = Math.max(Math.round(layer._pxRadius), 1),\n\t\tr2 = Math.max(Math.round(layer._pxRadiusY), 1) || r,\n\t\tarc = `a${r},${r2} 0 1,0 `;\n\n\t\t// drawing a circle with two half-arcs\n\t\tconst d = layer._empty() ? 'M0 0' :\n\t\t\t`M${p.x - r},${p.y\n\t\t\t}${arc}${r * 2},0 ${\n\t\t\t\tarc}${-r * 2},0 `;\n\n\t\tthis._setPath(layer, d);\n\t}\n\n\t_setPath(layer, path) {\n\t\tlayer._path.setAttribute('d', path);\n\t}\n\n\t// SVG does not have the concept of zIndex so we resort to changing the DOM order of elements\n\t_bringToFront(layer) {\n\t\tDomUtil.toFront(layer._path);\n\t}\n\n\t_bringToBack(layer) {\n\t\tDomUtil.toBack(layer._path);\n\t}\n\n\t/**\n\t * Returns a instance of [SVGElement](https://developer.mozilla.org/docs/Web/API/SVGElement),\n\t * corresponding to the class name passed. For example, using 'line' will return\n\t * an instance of [SVGLineElement](https://developer.mozilla.org/docs/Web/API/SVGLineElement).\n\t * @param {string} name\n\t * @returns {SVGElement}\n\t */\n\tstatic create(name) {\n\t\treturn document.createElementNS('http://www.w3.org/2000/svg', name);\n\t}\n\n\t/**\n\t * Generates a SVG path string for multiple rings, with each ring turning\n\t * into \"M..L..L..\" instructions.\n\t * @param {Point[][]} rings\n\t * @param {boolean} [closed]\n\t * @returns {string}\n\t */\n\tstatic pointsToPath(rings, closed) {\n\t\tconst str = rings.flatMap(points => [\n\t\t\t...points.map((p, j) => `${(j ? 'L' : 'M') + p.x} ${p.y}`),\n\t\t\t// closes the ring for polygons\n\t\t\tclosed ? 'z' : ''\n\t\t]).join('');\n\n\t\t// SVG complains about empty path strings\n\t\treturn str || 'M0 0';\n\t}\n\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4BA,IAAa,MAAb,MAAa,YAAY,SAAS;;;;;;;;;CASjC,YAAY,GAAG,MAAM;EACpB,MAAM,GAAG,IAAI;EACb,KAAK,cAAc,GAAG;CACvB;CAGA,iBAAiB;EAChB,KAAK,aAAa,IAAI,OAAO,KAAK;EAGlC,KAAK,WAAW,aAAa,kBAAkB,MAAM;EAErD,KAAK,aAAa,IAAI,OAAO,GAAG;EAChC,KAAK,WAAW,YAAY,KAAK,UAAU;CAC5C;CAEA,oBAAoB;EACnB,MAAM,kBAAkB;EACxB,OAAO,KAAK;EACZ,OAAO,KAAK;CACb;CAEA,mBAAmB;EAClB,MAAM,OAAO,MAAM,iBAAiB;EAGpC,IAAI,CAAC,KAAK,YAAY,CAAC,KAAK,SAAS,OAAO,IAAI,GAAG;GAClD,KAAK,WAAW;GAChB,KAAK,WAAW,aAAa,SAAS,KAAK,
|
|
1
|
+
{"version":3,"file":"SVG.js","names":[],"sources":["../../../../src/layer/vector/SVG.js"],"sourcesContent":["import {Renderer} from './Renderer.js';\nimport * as DomUtil from '../../dom/DomUtil.js';\nimport {splitWords, stamp} from '../../core/Util.js';\n/** @import {Point} from '../../geometry/Point.js' */\n/** @import {RendererOptions} from './Renderer.js' */\n\n/**\n * Allows vector layers to be displayed with [SVG](https://developer.mozilla.org/docs/Web/SVG).\n * Inherits `Renderer`.\n *\n * @example\n * Use SVG by default for all paths in the map:\n *\n * ```js\n * const map = new MaplairMap('map', {\n * \trenderer: new SVG()\n * });\n * ```\n *\n * Use a SVG renderer with extra padding for specific vector geometries:\n *\n * ```js\n * const map = new MaplairMap('map');\n * const myRenderer = new SVG({ padding: 0.5 });\n * const line = new Polyline( coordinates, { renderer: myRenderer } );\n * const circle = new Circle( center, { renderer: myRenderer, radius: 100 } );\n * ```\n */\nexport class SVG extends Renderer {\n\t/**\n\t * Creates a SVG renderer with the given options.\n\t * @overload\n\t * @param {RendererOptions} [options]\n\t */\n\t/**\n\t * @param {...any} args\n\t */\n\tconstructor(...args) {\n\t\tsuper(...args);\n\t\tthis.callInitHooks(SVG);\n\t}\n\n\n\t_initContainer() {\n\t\tthis._container = SVG.create('svg');\n\n\t\t// makes it possible to click through svg root; we'll reset it back in individual paths\n\t\tthis._container.setAttribute('pointer-events', 'none');\n\n\t\tthis._rootGroup = SVG.create('g');\n\t\tthis._container.appendChild(this._rootGroup);\n\t}\n\n\t_destroyContainer() {\n\t\tsuper._destroyContainer();\n\t\tdelete this._rootGroup;\n\t\tdelete this._svgSize;\n\t}\n\n\t_resizeContainer() {\n\t\tconst size = super._resizeContainer();\n\n\t\t// set size of svg-container if changed\n\t\tif (!this._svgSize || !this._svgSize.equals(size)) {\n\t\t\tthis._svgSize = size;\n\t\t\tthis._container.setAttribute('width', `${size.x}`);\n\t\t\tthis._container.setAttribute('height', `${size.y}`);\n\t\t}\n\n\t\t// Reset the <SVG>'s viewBox as per _update, but skip redrawing paths.\n\t\t// This keeps paths visually aligned when resizing.\n\t\tconst b = this._bounds;\n\t\tif (b) {\n\t\t\tthis._container.setAttribute('viewBox', [b.min.x, b.min.y, size.x, size.y].join(' '));\n\t\t}\n\t}\n\n\t_update() {\n\t\tif (this._map._animatingZoom && this._bounds) { return; }\n\n\t\tconst b = this._bounds,\n\t\tsize = b.getSize();\n\n\t\t// movement: update container viewBox so that we don't have to change coordinates of individual layers\n\t\tthis._container.setAttribute('viewBox', [b.min.x, b.min.y, size.x, size.y].join(' '));\n\n\t\tthis.fire('update');\n\t}\n\n\t// methods below are called by vector layers implementations\n\n\t_initPath(layer) {\n\t\tconst path = layer._path = SVG.create('path');\n\n\t\tif (layer.options.className) {\n\t\t\tpath.classList.add(...splitWords(layer.options.className));\n\t\t}\n\n\t\tif (layer.options.interactive) {\n\t\t\tpath.classList.add('maplair-interactive');\n\t\t}\n\n\t\tthis._updateStyle(layer);\n\t\tthis._layers[stamp(layer)] = layer;\n\t}\n\n\t_updateInteractive(layer) {\n\t\tlayer._path.classList.toggle('maplair-interactive', !!layer.options.interactive);\n\t}\n\n\t_addPath(layer) {\n\t\tif (!this._rootGroup) { this._initContainer(); }\n\t\tthis._rootGroup.appendChild(layer._path);\n\t\tlayer.addInteractiveTarget(layer._path);\n\t}\n\n\t_removePath(layer) {\n\t\tlayer._path.remove();\n\t\tlayer.removeInteractiveTarget(layer._path);\n\t\tdelete this._layers[stamp(layer)];\n\t}\n\n\t_updatePath(layer) {\n\t\tlayer._project();\n\t\tlayer._update();\n\t}\n\n\t_updateStyle(layer) {\n\t\tconst path = layer._path,\n\t\toptions = layer.options;\n\n\t\tif (!path) { return; }\n\n\t\tif (options.stroke) {\n\t\t\tpath.setAttribute('stroke', options.color);\n\t\t\tpath.setAttribute('stroke-opacity', `${options.opacity}`);\n\t\t\tpath.setAttribute('stroke-width', `${options.weight}`);\n\t\t\tpath.setAttribute('stroke-linecap', options.lineCap);\n\t\t\tpath.setAttribute('stroke-linejoin', options.lineJoin);\n\n\t\t\tif (options.dashArray) {\n\t\t\t\tpath.setAttribute('stroke-dasharray', options.dashArray);\n\t\t\t} else {\n\t\t\t\tpath.removeAttribute('stroke-dasharray');\n\t\t\t}\n\n\t\t\tif (options.dashOffset) {\n\t\t\t\tpath.setAttribute('stroke-dashoffset', options.dashOffset);\n\t\t\t} else {\n\t\t\t\tpath.removeAttribute('stroke-dashoffset');\n\t\t\t}\n\t\t} else {\n\t\t\tpath.setAttribute('stroke', 'none');\n\t\t}\n\n\t\tif (options.fill) {\n\t\t\tpath.setAttribute('fill', options.fillColor || options.color);\n\t\t\tpath.setAttribute('fill-opacity', `${options.fillOpacity}`);\n\t\t\tpath.setAttribute('fill-rule', options.fillRule || 'evenodd');\n\t\t} else {\n\t\t\tpath.setAttribute('fill', 'none');\n\t\t}\n\t}\n\n\t_updatePoly(layer, closed) {\n\t\tthis._setPath(layer, SVG.pointsToPath(layer._parts, closed));\n\t}\n\n\t_updateCircle(layer) {\n\t\tconst p = layer._point,\n\t\tr = Math.max(Math.round(layer._pxRadius), 1),\n\t\tr2 = Math.max(Math.round(layer._pxRadiusY), 1) || r,\n\t\tarc = `a${r},${r2} 0 1,0 `;\n\n\t\t// drawing a circle with two half-arcs\n\t\tconst d = layer._empty() ? 'M0 0' :\n\t\t\t`M${p.x - r},${p.y\n\t\t\t}${arc}${r * 2},0 ${\n\t\t\t\tarc}${-r * 2},0 `;\n\n\t\tthis._setPath(layer, d);\n\t}\n\n\t_setPath(layer, path) {\n\t\tlayer._path.setAttribute('d', path);\n\t}\n\n\t// SVG does not have the concept of zIndex so we resort to changing the DOM order of elements\n\t_bringToFront(layer) {\n\t\tDomUtil.toFront(layer._path);\n\t}\n\n\t_bringToBack(layer) {\n\t\tDomUtil.toBack(layer._path);\n\t}\n\n\t/**\n\t * Returns a instance of [SVGElement](https://developer.mozilla.org/docs/Web/API/SVGElement),\n\t * corresponding to the class name passed. For example, using 'line' will return\n\t * an instance of [SVGLineElement](https://developer.mozilla.org/docs/Web/API/SVGLineElement).\n\t * @param {string} name\n\t * @returns {SVGElement}\n\t */\n\tstatic create(name) {\n\t\treturn document.createElementNS('http://www.w3.org/2000/svg', name);\n\t}\n\n\t/**\n\t * Generates a SVG path string for multiple rings, with each ring turning\n\t * into \"M..L..L..\" instructions.\n\t * @param {Point[][]} rings\n\t * @param {boolean} [closed]\n\t * @returns {string}\n\t */\n\tstatic pointsToPath(rings, closed) {\n\t\tconst str = rings.flatMap(points => [\n\t\t\t...points.map((p, j) => `${(j ? 'L' : 'M') + p.x} ${p.y}`),\n\t\t\t// closes the ring for polygons\n\t\t\tclosed ? 'z' : ''\n\t\t]).join('');\n\n\t\t// SVG complains about empty path strings\n\t\treturn str || 'M0 0';\n\t}\n\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4BA,IAAa,MAAb,MAAa,YAAY,SAAS;;;;;;;;;CASjC,YAAY,GAAG,MAAM;EACpB,MAAM,GAAG,IAAI;EACb,KAAK,cAAc,GAAG;CACvB;CAGA,iBAA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AM,IAAI,MAAM,QAChB,IAAI,KAAK,IAAI,KAAK,MAAM,MAAM,SAAS,GAAG,CAAC,GAE3C,MAAM,IAAI,EAAE,GADP,KAAK,IAAI,KAAK,MAAM,MAAM,UAAU,GAAG,CAAC,KAAK,EAChC;EAGlB,MAAM,IAAI,MAAM,OAAO,IAAI,SAC1B,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE,IACd,MAAM,IAAI,EAAE,KACd,MAAM,CAAC,IAAI,EAAE;EAEf,KAAK,SAAS,OAAO,CAAC;CACvB;CAEA,SAAS,OAAO,MAAM;EACrB,MAAM,MAAM,aAAa,KAAK,IAAI;CACnC;CAGA,cAAc,OAAO;EACpB,QAAgB,MAAM,KAAK;CAC5B;CAEA,aAAa,OAAO;EACnB,OAAe,MAAM,KAAK;CAC3B;;;;;;;;CASA,OAAO,OAAO,MAAM;EACnB,OAAO,SAAS,gBAAgB,8BAA8B,IAAI;CACnE;;;;;;;;CASA,OAAO,aAAa,OAAO,QAAQ;EAQlC,OAPY,MAAM,SAAQ,WAAU,CACnC,GAAG,OAAO,KAAK,GAAG,MAAM,IAAI,IAAI,MAAM,OAAO,EAAE,EAAE,GAAG,EAAE,GAAG,GAEzD,SAAS,MAAM,EAChB,CAAC,CAAC,CAAC,KAAK,EAGC,KAAK;CACf;AAED"}
|
|
@@ -1,19 +1,18 @@
|
|
|
1
1
|
import { Point } from "../geometry/Point.js";
|
|
2
|
-
import Browser_default from "../core/Browser.js";
|
|
3
2
|
import { getPointers } from "../dom/DomEvent.PointerEvents.js";
|
|
4
3
|
import { stop } from "../dom/DomEvent.js";
|
|
5
4
|
import { create, getPosition, getScale, setPosition, setTransform } from "../dom/DomUtil.js";
|
|
6
5
|
import { Bounds } from "../geometry/Bounds.js";
|
|
6
|
+
import { BlanketOverlay } from "../layer/BlanketOverlay.js";
|
|
7
7
|
import { DivOverlay } from "../layer/DivOverlay.js";
|
|
8
8
|
import { Popup } from "../layer/Popup.js";
|
|
9
9
|
import { Tooltip } from "../layer/Tooltip.js";
|
|
10
|
-
import { BlanketOverlay } from "../layer/BlanketOverlay.js";
|
|
11
10
|
import { Draggable } from "../dom/Draggable.js";
|
|
12
11
|
import { DragHandler } from "./handler/DragHandler.js";
|
|
13
12
|
import { PinchZoomHandler } from "./handler/PinchZoomHandler.js";
|
|
14
13
|
import { ScrollWheelZoomHandler } from "./handler/ScrollWheelZoomHandler.js";
|
|
15
14
|
import { TapDragZoomHandler } from "./handler/TapDragZoomHandler.js";
|
|
16
|
-
import { MaplairMap } from "./Map.js";
|
|
15
|
+
import { LeafletMap as MaplairMap } from "./Map.js";
|
|
17
16
|
import { MarkerDrag } from "../layer/marker/Marker.Drag.js";
|
|
18
17
|
import { Marker } from "../layer/marker/Marker.js";
|
|
19
18
|
import { GridLayer } from "../layer/tile/GridLayer.js";
|
|
@@ -68,7 +67,7 @@ MaplairMap.include({
|
|
|
68
67
|
if (!this._rotatePane && !bearing) return this;
|
|
69
68
|
if (bearing === from) return this;
|
|
70
69
|
this._stop();
|
|
71
|
-
if (!options?.animate || !this._loaded ||
|
|
70
|
+
if (!options?.animate || !this._loaded || this._prefersReducedMotion()) {
|
|
72
71
|
this._rotate(bearing);
|
|
73
72
|
return this._loaded ? this.fire("movestart").fire("move").fire("moveend") : this;
|
|
74
73
|
}
|
|
@@ -390,8 +389,13 @@ DragHandler.include({ _onDragEnd(e) {
|
|
|
390
389
|
if (noInertia) map.fire("moveend");
|
|
391
390
|
else {
|
|
392
391
|
this._prunePositions(Date.now());
|
|
393
|
-
const direction = this._lastPos.subtract(this._positions[0]), duration = (this._lastTime - this._times[0]) / 1e3, ease = options.easeLinearity, speedVector = direction.multiplyBy(ease / duration), speed = speedVector.distanceTo([0, 0]), limitedSpeed = Math.min(options.inertiaMaxSpeed, speed), limitedSpeedVector = speedVector.multiplyBy(limitedSpeed / speed),
|
|
394
|
-
let offset = limitedSpeedVector.multiplyBy(-decelerationDuration / 2).round();
|
|
392
|
+
const direction = this._lastPos.subtract(this._positions[0]), duration = (this._lastTime - this._times[0]) / 1e3, ease = options.easeLinearity, speedVector = direction.multiplyBy(ease / duration), speed = speedVector.distanceTo([0, 0]), limitedSpeed = Math.min(options.inertiaMaxSpeed, speed), limitedSpeedVector = speedVector.multiplyBy(limitedSpeed / speed), maxOffset = map.getSize().divideBy(2);
|
|
393
|
+
let decelerationDuration = limitedSpeed / (options.inertiaDeceleration * ease), offset = limitedSpeedVector.multiplyBy(-decelerationDuration / 2).round();
|
|
394
|
+
if (map._prefersReducedMotion() && !maxOffset.contains(offset)) {
|
|
395
|
+
const k = Math.min(maxOffset.x / Math.abs(offset.x), maxOffset.y / Math.abs(offset.y));
|
|
396
|
+
offset = offset.multiplyBy(k).round();
|
|
397
|
+
decelerationDuration *= Math.sqrt(k);
|
|
398
|
+
}
|
|
395
399
|
if (!offset.x && !offset.y) map.fire("moveend");
|
|
396
400
|
else {
|
|
397
401
|
offset = map._limitOffset(offset, map.options.maxBounds);
|