maplair 4.0.0-alpha.2 → 4.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +140 -38
- package/LICENSE +1 -1
- package/README.md +10 -9
- package/dist/esm/Maplair.js +14 -14
- package/dist/esm/control/AttributionControl.js +24 -14
- package/dist/esm/control/AttributionControl.js.map +1 -1
- package/dist/esm/control/ButtonControl.js +9 -11
- package/dist/esm/control/ButtonControl.js.map +1 -1
- package/dist/esm/control/ContextMenu.js +1 -3
- package/dist/esm/control/ContextMenu.js.map +1 -1
- package/dist/esm/control/Control.js +9 -16
- package/dist/esm/control/Control.js.map +1 -1
- package/dist/esm/control/FullscreenControl.js +5 -7
- package/dist/esm/control/FullscreenControl.js.map +1 -1
- package/dist/esm/control/LayersControl.js +144 -35
- package/dist/esm/control/LayersControl.js.map +1 -1
- package/dist/esm/control/LegendControl.js +7 -9
- package/dist/esm/control/LegendControl.js.map +1 -1
- package/dist/esm/control/MiniMapControl.js +14 -16
- package/dist/esm/control/MiniMapControl.js.map +1 -1
- package/dist/esm/control/RotateControl.js +1 -3
- package/dist/esm/control/RotateControl.js.map +1 -1
- package/dist/esm/control/ScaleControl.js +7 -9
- package/dist/esm/control/ScaleControl.js.map +1 -1
- package/dist/esm/control/SearchControl.js +100 -18
- package/dist/esm/control/SearchControl.js.map +1 -1
- package/dist/esm/control/SideBySideControl.js +1 -3
- package/dist/esm/control/SideBySideControl.js.map +1 -1
- package/dist/esm/control/TextControl.js +5 -7
- package/dist/esm/control/TextControl.js.map +1 -1
- package/dist/esm/control/TimeControl.js +408 -0
- package/dist/esm/control/TimeControl.js.map +1 -0
- package/dist/esm/control/ZoomControl.js +5 -7
- package/dist/esm/control/ZoomControl.js.map +1 -1
- package/dist/esm/core/Class.js +28 -37
- package/dist/esm/core/Class.js.map +1 -1
- package/dist/esm/core/Events.js +21 -8
- package/dist/esm/core/Events.js.map +1 -1
- package/dist/esm/core/Handler.js +13 -11
- package/dist/esm/core/Handler.js.map +1 -1
- package/dist/esm/core/Util.js +13 -1
- package/dist/esm/core/Util.js.map +1 -1
- package/dist/esm/dom/DomEvent.DoubleTap.js +25 -22
- package/dist/esm/dom/DomEvent.DoubleTap.js.map +1 -1
- package/dist/esm/dom/DomEvent.PointerEvents.js +2 -16
- package/dist/esm/dom/DomEvent.PointerEvents.js.map +1 -1
- package/dist/esm/dom/DomEvent.js +8 -42
- package/dist/esm/dom/DomEvent.js.map +1 -1
- package/dist/esm/dom/DomUtil.js +14 -68
- package/dist/esm/dom/DomUtil.js.map +1 -1
- package/dist/esm/dom/Draggable.js +17 -18
- package/dist/esm/dom/Draggable.js.map +1 -1
- package/dist/esm/dom/PosAnimation.js +3 -25
- package/dist/esm/dom/PosAnimation.js.map +1 -1
- package/dist/esm/geo/LatLng.js +34 -6
- package/dist/esm/geo/LatLng.js.map +1 -1
- package/dist/esm/geo/LatLngBounds.js +19 -7
- package/dist/esm/geo/LatLngBounds.js.map +1 -1
- package/dist/esm/geo/crs/CRS.js +4 -3
- package/dist/esm/geo/crs/CRS.js.map +1 -1
- package/dist/esm/geo/crs/EPSG3395.js +1 -1
- package/dist/esm/geo/crs/EPSG3395.js.map +1 -1
- package/dist/esm/geo/crs/EPSG3857.js +1 -1
- package/dist/esm/geo/crs/EPSG3857.js.map +1 -1
- package/dist/esm/geo/crs/EPSG4326.js +1 -1
- package/dist/esm/geo/crs/EPSG4326.js.map +1 -1
- package/dist/esm/geo/crs/EarthCRS.js +2 -2
- package/dist/esm/geo/crs/EarthCRS.js.map +1 -1
- package/dist/esm/geo/crs/SimpleCRS.js +1 -1
- package/dist/esm/geo/crs/SimpleCRS.js.map +1 -1
- package/dist/esm/geo/projection/Projection.LonLat.js +3 -3
- package/dist/esm/geo/projection/Projection.LonLat.js.map +1 -1
- package/dist/esm/geo/projection/Projection.Mercator.js +3 -3
- package/dist/esm/geo/projection/Projection.Mercator.js.map +1 -1
- package/dist/esm/geo/projection/Projection.SphericalMercator.js +3 -3
- package/dist/esm/geo/projection/Projection.SphericalMercator.js.map +1 -1
- package/dist/esm/geometry/Bounds.js +19 -7
- package/dist/esm/geometry/Bounds.js.map +1 -1
- package/dist/esm/geometry/LineUtil.js +36 -30
- package/dist/esm/geometry/LineUtil.js.map +1 -1
- package/dist/esm/geometry/Point.js +23 -5
- package/dist/esm/geometry/Point.js.map +1 -1
- package/dist/esm/geometry/PolyUtil.js +9 -28
- package/dist/esm/geometry/PolyUtil.js.map +1 -1
- package/dist/esm/layer/BlanketOverlay.js +6 -8
- package/dist/esm/layer/BlanketOverlay.js.map +1 -1
- package/dist/esm/layer/DivOverlay.js +15 -20
- package/dist/esm/layer/DivOverlay.js.map +1 -1
- package/dist/esm/layer/GeoJSON.js +9 -145
- package/dist/esm/layer/GeoJSON.js.map +1 -1
- package/dist/esm/layer/GeoJSONUtil.js +75 -0
- package/dist/esm/layer/GeoJSONUtil.js.map +1 -0
- package/dist/esm/layer/HeatLayer.js +15 -17
- package/dist/esm/layer/HeatLayer.js.map +1 -1
- package/dist/esm/layer/ImageOverlay.js +20 -26
- package/dist/esm/layer/ImageOverlay.js.map +1 -1
- package/dist/esm/layer/Layer.js +8 -10
- package/dist/esm/layer/Layer.js.map +1 -1
- package/dist/esm/layer/LayerGroup.js +51 -0
- package/dist/esm/layer/LayerGroup.js.map +1 -1
- package/dist/esm/layer/Popup.js +27 -43
- package/dist/esm/layer/Popup.js.map +1 -1
- package/dist/esm/layer/SVGOverlay.js +2 -5
- package/dist/esm/layer/SVGOverlay.js.map +1 -1
- package/dist/esm/layer/Tooltip.js +15 -17
- package/dist/esm/layer/Tooltip.js.map +1 -1
- package/dist/esm/layer/VideoOverlay.js +12 -15
- package/dist/esm/layer/VideoOverlay.js.map +1 -1
- package/dist/esm/layer/marker/DefaultIcon.js +15 -48
- package/dist/esm/layer/marker/DefaultIcon.js.map +1 -1
- package/dist/esm/layer/marker/DivIcon.js +8 -10
- package/dist/esm/layer/marker/DivIcon.js.map +1 -1
- package/dist/esm/layer/marker/Icon.js +9 -12
- package/dist/esm/layer/marker/Icon.js.map +1 -1
- package/dist/esm/layer/marker/Marker.Drag.js +1 -1
- package/dist/esm/layer/marker/Marker.Drag.js.map +1 -1
- package/dist/esm/layer/marker/Marker.Move.js +2 -3
- package/dist/esm/layer/marker/Marker.Move.js.map +1 -1
- package/dist/esm/layer/marker/Marker.js +63 -35
- package/dist/esm/layer/marker/Marker.js.map +1 -1
- package/dist/esm/layer/marker/MarkerClusterGroup.js +302 -0
- package/dist/esm/layer/marker/MarkerClusterGroup.js.map +1 -0
- package/dist/esm/layer/marker/SvgIcon.js +6 -8
- package/dist/esm/layer/marker/SvgIcon.js.map +1 -1
- package/dist/esm/layer/tile/GridLayer.js +86 -98
- package/dist/esm/layer/tile/GridLayer.js.map +1 -1
- package/dist/esm/layer/tile/TileLayer.js +28 -36
- package/dist/esm/layer/tile/TileLayer.js.map +1 -1
- package/dist/esm/layer/tile/WMSTileLayer.js +28 -23
- package/dist/esm/layer/tile/WMSTileLayer.js.map +1 -1
- package/dist/esm/layer/vector/Canvas.js +1 -3
- package/dist/esm/layer/vector/Canvas.js.map +1 -1
- package/dist/esm/layer/vector/Circle.js +2 -2
- package/dist/esm/layer/vector/Circle.js.map +1 -1
- package/dist/esm/layer/vector/CircleMarker.js +17 -7
- package/dist/esm/layer/vector/CircleMarker.js.map +1 -1
- package/dist/esm/layer/vector/Path.DashAnimation.js +2 -3
- package/dist/esm/layer/vector/Path.DashAnimation.js.map +1 -1
- package/dist/esm/layer/vector/Path.js +27 -20
- package/dist/esm/layer/vector/Path.js.map +1 -1
- package/dist/esm/layer/vector/Polygon.js +20 -4
- package/dist/esm/layer/vector/Polygon.js.map +1 -1
- package/dist/esm/layer/vector/Polyline.Decorations.js +2 -2
- package/dist/esm/layer/vector/Polyline.js +24 -8
- package/dist/esm/layer/vector/Polyline.js.map +1 -1
- package/dist/esm/layer/vector/Renderer.getRenderer.js +14 -13
- package/dist/esm/layer/vector/Renderer.getRenderer.js.map +1 -1
- package/dist/esm/layer/vector/SVG.js +5 -5
- package/dist/esm/layer/vector/SVG.js.map +1 -1
- package/dist/esm/map/Map.Rotation.js +15 -11
- package/dist/esm/map/Map.Rotation.js.map +1 -1
- package/dist/esm/map/Map.js +135 -129
- package/dist/esm/map/Map.js.map +1 -1
- package/dist/esm/map/handler/BoxZoomHandler.js +5 -7
- package/dist/esm/map/handler/BoxZoomHandler.js.map +1 -1
- package/dist/esm/map/handler/DisplaceHandler.js +6 -8
- package/dist/esm/map/handler/DisplaceHandler.js.map +1 -1
- package/dist/esm/map/handler/DragHandler.js +20 -20
- package/dist/esm/map/handler/DragHandler.js.map +1 -1
- package/dist/esm/map/handler/KeyboardHandler.js +37 -37
- package/dist/esm/map/handler/KeyboardHandler.js.map +1 -1
- package/dist/esm/map/handler/PinchZoomHandler.js +12 -3
- package/dist/esm/map/handler/PinchZoomHandler.js.map +1 -1
- package/dist/esm/map/handler/ScrollWheelZoomHandler.js +3 -4
- package/dist/esm/map/handler/ScrollWheelZoomHandler.js.map +1 -1
- package/dist/esm/map/handler/TapHoldHandler.js +12 -5
- package/dist/esm/map/handler/TapHoldHandler.js.map +1 -1
- package/dist/esm/package.js +1 -1
- package/dist/maplair-global-src.js +6326 -5625
- package/dist/maplair-global-src.js.map +1 -1
- package/dist/maplair-global.js +3 -3
- package/dist/maplair-global.js.map +1 -1
- package/dist/maplair-src.js +9010 -8290
- package/dist/maplair-src.js.map +1 -1
- package/dist/maplair.css +148 -98
- package/dist/maplair.js +3 -3
- package/dist/maplair.js.map +1 -1
- package/i18n/cs.json +6 -0
- package/i18n/de.json +6 -0
- package/i18n/en.json +6 -0
- package/i18n/es.json +6 -0
- package/i18n/fr.json +6 -0
- package/i18n/hu.json +6 -0
- package/i18n/it.json +6 -0
- package/i18n/rm.json +6 -0
- package/i18n/sk.json +6 -0
- package/i18n/sl.json +6 -0
- package/package.json +12 -14
- package/src/control/AttributionControl.js +25 -18
- package/src/control/ButtonControl.js +9 -11
- package/src/control/ContextMenu.js +3 -5
- package/src/control/Control.js +9 -19
- package/src/control/FullscreenControl.js +5 -7
- package/src/control/LayersControl.js +159 -36
- package/src/control/LegendControl.js +7 -9
- package/src/control/MiniMapControl.js +9 -11
- package/src/control/RotateControl.js +3 -5
- package/src/control/ScaleControl.js +7 -9
- package/src/control/SearchControl.js +104 -21
- package/src/control/SideBySideControl.js +3 -5
- package/src/control/TextControl.js +5 -7
- package/src/control/TimeControl.js +471 -0
- package/src/control/ZoomControl.js +5 -7
- package/src/control/index.js +1 -0
- package/src/core/Class.js +35 -34
- package/src/core/Events.js +22 -3
- package/src/core/Handler.js +14 -12
- package/src/core/Util.js +19 -1
- package/src/core/index.js +0 -1
- package/src/dom/DomEvent.DoubleTap.js +18 -10
- package/src/dom/DomEvent.PointerEvents.js +3 -26
- package/src/dom/DomEvent.js +8 -66
- package/src/dom/DomUtil.js +22 -78
- package/src/dom/Draggable.js +27 -22
- package/src/dom/PosAnimation.js +3 -25
- package/src/dom/index.js +0 -1
- package/src/geo/LatLng.js +40 -4
- package/src/geo/LatLngBounds.js +20 -7
- package/src/geo/crs/CRS.js +4 -3
- package/src/geo/crs/EPSG3395.js +1 -1
- package/src/geo/crs/EPSG3857.js +1 -1
- package/src/geo/crs/EPSG4326.js +1 -1
- package/src/geo/crs/EarthCRS.js +2 -8
- package/src/geo/crs/SimpleCRS.js +1 -1
- package/src/geo/projection/Projection.LonLat.js +3 -3
- package/src/geo/projection/Projection.Mercator.js +3 -3
- package/src/geo/projection/Projection.SphericalMercator.js +3 -3
- package/src/geometry/Bounds.js +20 -7
- package/src/geometry/LineUtil.js +47 -48
- package/src/geometry/Point.js +24 -5
- package/src/geometry/PolyUtil.js +15 -44
- package/src/layer/BlanketOverlay.js +6 -10
- package/src/layer/DivOverlay.js +15 -26
- package/src/layer/GeoJSON.js +7 -205
- package/src/layer/GeoJSONUtil.js +85 -0
- package/src/layer/HeatLayer.js +9 -11
- package/src/layer/ImageOverlay.js +19 -30
- package/src/layer/Layer.js +8 -10
- package/src/layer/LayerGroup.js +71 -0
- package/src/layer/Popup.js +31 -46
- package/src/layer/SVGOverlay.js +1 -5
- package/src/layer/Tooltip.js +15 -19
- package/src/layer/VideoOverlay.js +12 -15
- package/src/layer/marker/DefaultIcon.js +15 -61
- package/src/layer/marker/DivIcon.js +10 -12
- package/src/layer/marker/Icon.js +9 -12
- package/src/layer/marker/Marker.Drag.js +1 -1
- package/src/layer/marker/Marker.Move.js +2 -3
- package/src/layer/marker/Marker.js +83 -41
- package/src/layer/marker/MarkerClusterGroup.js +370 -0
- package/src/layer/marker/SvgIcon.js +7 -9
- package/src/layer/marker/index.js +1 -0
- package/src/layer/tile/GridLayer.js +104 -134
- package/src/layer/tile/TileLayer.js +35 -43
- package/src/layer/tile/WMSTileLayer.js +26 -24
- package/src/layer/vector/Canvas.js +3 -5
- package/src/layer/vector/Circle.js +5 -2
- package/src/layer/vector/CircleMarker.js +17 -6
- package/src/layer/vector/Path.DashAnimation.js +1 -2
- package/src/layer/vector/Path.js +30 -21
- package/src/layer/vector/Polygon.js +28 -5
- package/src/layer/vector/Polyline.js +26 -7
- package/src/layer/vector/Renderer.getRenderer.js +17 -17
- package/src/layer/vector/SVG.js +5 -5
- package/src/map/Map.Rotation.js +19 -11
- package/src/map/Map.js +163 -154
- package/src/map/handler/BoxZoomHandler.js +9 -8
- package/src/map/handler/DisplaceHandler.js +6 -8
- package/src/map/handler/DragHandler.js +26 -29
- package/src/map/handler/KeyboardHandler.js +44 -50
- package/src/map/handler/PinchZoomHandler.js +16 -5
- package/src/map/handler/ScrollWheelZoomHandler.js +6 -4
- package/src/map/handler/TapHoldHandler.js +15 -4
- package/src/map/index.js +1 -1
- package/src/maplair.css +148 -98
- package/dist/esm/core/Browser.js +0 -100
- package/dist/esm/core/Browser.js.map +0 -1
- package/dist/images/layers.svg +0 -1
- package/dist/images/marker-icon.svg +0 -1
- package/dist/images/marker-shadow.svg +0 -1
- package/src/core/Browser.js +0 -110
- package/src/images/layers.svg +0 -1
- package/src/images/marker-icon.svg +0 -1
- package/src/images/marker-shadow.svg +0 -1
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import { __exportAll } from "../_virtual/_rolldown/runtime.js";
|
|
2
2
|
import { Point } from "./Point.js";
|
|
3
|
-
import { LatLngBounds } from "../geo/LatLngBounds.js";
|
|
4
3
|
import { LatLng } from "../geo/LatLng.js";
|
|
5
|
-
import { centroid } from "./PolyUtil.js";
|
|
6
4
|
//#region src/geometry/LineUtil.js
|
|
7
5
|
var LineUtil_exports = /* @__PURE__ */ __exportAll({
|
|
8
6
|
_getBitCode: () => _getBitCode,
|
|
9
7
|
_getEdgeIntersection: () => _getEdgeIntersection,
|
|
8
|
+
_projectRing: () => _projectRing,
|
|
10
9
|
_sqClosestPointOnSegment: () => _sqClosestPointOnSegment,
|
|
11
10
|
clipSegment: () => clipSegment,
|
|
12
11
|
closestPointOnSegment: () => closestPointOnSegment,
|
|
@@ -107,13 +106,20 @@ let _lastCode;
|
|
|
107
106
|
* @returns {[Point, Point]|false}
|
|
108
107
|
*/
|
|
109
108
|
function clipSegment(a, b, bounds, useLastCode, round) {
|
|
109
|
+
const a0 = a, b0 = b;
|
|
110
110
|
let codeA = useLastCode ? _lastCode : _getBitCode(a, bounds), codeB = _getBitCode(b, bounds), codeOut, p, newCode;
|
|
111
111
|
_lastCode = codeB;
|
|
112
112
|
while (true) {
|
|
113
|
-
if (!(codeA | codeB))
|
|
113
|
+
if (!(codeA | codeB)) {
|
|
114
|
+
if (round) {
|
|
115
|
+
if (a !== a0) a = a.round();
|
|
116
|
+
if (b !== b0) b = b.round();
|
|
117
|
+
}
|
|
118
|
+
return [a, b];
|
|
119
|
+
}
|
|
114
120
|
if (codeA & codeB) return false;
|
|
115
121
|
codeOut = codeA || codeB;
|
|
116
|
-
p = _getEdgeIntersection(a, b, codeOut, bounds
|
|
122
|
+
p = _getEdgeIntersection(a, b, codeOut, bounds);
|
|
117
123
|
newCode = _getBitCode(p, bounds);
|
|
118
124
|
if (codeOut === codeA) {
|
|
119
125
|
a = p;
|
|
@@ -187,38 +193,38 @@ function isFlat(latlngs) {
|
|
|
187
193
|
* @returns {LatLng}
|
|
188
194
|
*/
|
|
189
195
|
function polylineCenter(latlngs, crs) {
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
const bounds = new LatLngBounds(latlngs);
|
|
198
|
-
if (bounds.getNorthWest().distanceTo(bounds.getSouthWest()) * bounds.getNorthEast().distanceTo(bounds.getNorthWest()) < 1700) centroidLatLng = centroid(latlngs);
|
|
199
|
-
const len = latlngs.length;
|
|
200
|
-
const points = [];
|
|
201
|
-
for (i = 0; i < len; i++) {
|
|
202
|
-
const latlng = new LatLng(latlngs[i]);
|
|
203
|
-
points.push(crs.project(new LatLng([latlng.lat - centroidLatLng.lat, latlng.lng - centroidLatLng.lng])));
|
|
204
|
-
}
|
|
205
|
-
for (i = 0, halfDist = 0; i < len - 1; i++) halfDist += points[i].distanceTo(points[i + 1]) / 2;
|
|
206
|
-
if (halfDist === 0) center = points[0];
|
|
207
|
-
else for (i = 0, dist = 0; i < len - 1; i++) {
|
|
208
|
-
p1 = points[i];
|
|
209
|
-
p2 = points[i + 1];
|
|
210
|
-
segDist = p1.distanceTo(p2);
|
|
196
|
+
const points = _projectRing(latlngs, crs), len = points.length;
|
|
197
|
+
let halfDist = 0;
|
|
198
|
+
for (let i = 1; i < len; i++) halfDist += points[i - 1].distanceTo(points[i]);
|
|
199
|
+
halfDist /= 2;
|
|
200
|
+
let center = points[0];
|
|
201
|
+
for (let i = 1, dist = 0; i < len; i++) {
|
|
202
|
+
const p1 = points[i - 1], p2 = points[i], segDist = p1.distanceTo(p2);
|
|
211
203
|
dist += segDist;
|
|
212
204
|
if (dist > halfDist) {
|
|
213
|
-
ratio = (dist - halfDist) / segDist;
|
|
214
|
-
center =
|
|
205
|
+
const ratio = (dist - halfDist) / segDist;
|
|
206
|
+
center = new Point(p2.x - ratio * (p2.x - p1.x), p2.y - ratio * (p2.y - p1.y));
|
|
215
207
|
break;
|
|
216
208
|
}
|
|
217
209
|
}
|
|
218
|
-
|
|
219
|
-
|
|
210
|
+
return crs.unproject(center);
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* Projects the first ring of the given latlngs.
|
|
214
|
+
* @internal
|
|
215
|
+
* @param {LatLngExpression[]|LatLngExpression[][]} latlngs
|
|
216
|
+
* @param {typeof CRS} crs
|
|
217
|
+
* @returns {Point[]}
|
|
218
|
+
*/
|
|
219
|
+
function _projectRing(latlngs, crs) {
|
|
220
|
+
if (!latlngs || latlngs.length === 0) throw new Error("latlngs not passed");
|
|
221
|
+
if (!isFlat(latlngs)) {
|
|
222
|
+
console.warn("latlngs are not flat! Only the first ring will be used");
|
|
223
|
+
latlngs = latlngs[0];
|
|
224
|
+
}
|
|
225
|
+
return latlngs.map((latlng) => crs.project(LatLng.from(latlng)));
|
|
220
226
|
}
|
|
221
227
|
//#endregion
|
|
222
|
-
export { LineUtil_exports, _getBitCode, _getEdgeIntersection, _sqClosestPointOnSegment, clipSegment, closestPointOnSegment, isFlat, pointToSegmentDistance, polylineCenter, simplify };
|
|
228
|
+
export { LineUtil_exports, _getBitCode, _getEdgeIntersection, _projectRing, _sqClosestPointOnSegment, clipSegment, closestPointOnSegment, isFlat, pointToSegmentDistance, polylineCenter, simplify };
|
|
223
229
|
|
|
224
230
|
//# sourceMappingURL=LineUtil.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LineUtil.js","names":[],"sources":["../../../src/geometry/LineUtil.js"],"sourcesContent":["import {Point} from './Point.js';\nimport {LatLng} from '../geo/LatLng.js';\nimport {centroid} from './PolyUtil.js';\nimport {LatLngBounds} from '../geo/LatLngBounds.js';\n/** @import {LatLngExpression} from '../geo/LatLng.js' */\n/** @import {Bounds} from './Bounds.js' */\n/** @import {CRS} from '../geo/crs/CRS.js' */\n\n// LineUtil: various utility functions for polyline points processing, used by Maplair\n// internally to make polylines lightning-fast.\n\n// Simplify polyline with vertex reduction and Douglas-Peucker simplification.\n// Improves rendering performance dramatically by lessening the number of points to draw.\n\n/**\n * Dramatically reduces the number of points in a polyline while retaining\n * its shape and returns a new array of simplified points, using the\n * [Ramer-Douglas-Peucker algorithm](https://en.wikipedia.org/wiki/Ramer-Douglas-Peucker_algorithm).\n * Used for a huge performance boost when processing/displaying Maplair polylines for\n * each zoom level and also reducing visual noise. tolerance affects the amount of\n * simplification (lesser value means higher quality but slower and with more points).\n * Also released as a separated micro-library\n * [Simplify.js](https://mourner.github.io/simplify-js/).\n * @param {Point[]} points\n * @param {number} tolerance\n * @returns {Point[]}\n */\nexport function simplify(points, tolerance) {\n\tif (!tolerance || !points.length) {\n\t\treturn points.slice();\n\t}\n\n\tconst sqTolerance = tolerance * tolerance;\n\n\t// stage 1: vertex reduction\n\tpoints = _reducePoints(points, sqTolerance);\n\n\t// stage 2: Douglas-Peucker simplification\n\tpoints = _simplifyDP(points, sqTolerance);\n\n\treturn points;\n}\n\n/**\n * Returns the distance between point `p` and segment `p1` to `p2`.\n * @param {Point} p\n * @param {Point} p1\n * @param {Point} p2\n * @returns {number}\n */\nexport function pointToSegmentDistance(p, p1, p2) {\n\treturn Math.sqrt(_sqClosestPointOnSegment(p, p1, p2, true));\n}\n\n/**\n * Returns the closest point from a point `p` on a segment `p1` to `p2`.\n * @param {Point} p\n * @param {Point} p1\n * @param {Point} p2\n * @returns {Point}\n */\nexport function closestPointOnSegment(p, p1, p2) {\n\treturn _sqClosestPointOnSegment(p, p1, p2);\n}\n\n// Ramer-Douglas-Peucker simplification, see https://en.wikipedia.org/wiki/Ramer-Douglas-Peucker_algorithm\nfunction _simplifyDP(points, sqTolerance) {\n\n\tconst len = points.length,\n\tmarkers = new Uint8Array(len);\n\tmarkers[0] = markers[len - 1] = 1;\n\n\t_simplifyDPStep(points, markers, sqTolerance, 0, len - 1);\n\n\tlet i;\n\tconst newPoints = [];\n\n\tfor (i = 0; i < len; i++) {\n\t\tif (markers[i]) {\n\t\t\tnewPoints.push(points[i]);\n\t\t}\n\t}\n\n\treturn newPoints;\n}\n\nfunction _simplifyDPStep(points, markers, sqTolerance, first, last) {\n\n\tlet maxSqDist = 0,\n\tindex, i, sqDist;\n\n\tfor (i = first + 1; i <= last - 1; i++) {\n\t\tsqDist = _sqClosestPointOnSegment(points[i], points[first], points[last], true);\n\n\t\tif (sqDist > maxSqDist) {\n\t\t\tindex = i;\n\t\t\tmaxSqDist = sqDist;\n\t\t}\n\t}\n\n\tif (maxSqDist > sqTolerance) {\n\t\tmarkers[index] = 1;\n\n\t\t_simplifyDPStep(points, markers, sqTolerance, first, index);\n\t\t_simplifyDPStep(points, markers, sqTolerance, index, last);\n\t}\n}\n\n// reduce points that are too close to each other to a single point\nfunction _reducePoints(points, sqTolerance) {\n\tconst reducedPoints = [points[0]];\n\tlet prev = 0;\n\n\tfor (let i = 1; i < points.length; i++) {\n\t\tif (_sqDist(points[i], points[prev]) > sqTolerance) {\n\t\t\treducedPoints.push(points[i]);\n\t\t\tprev = i;\n\t\t}\n\t}\n\tif (prev < points.length - 1) {\n\t\treducedPoints.push(points[points.length - 1]);\n\t}\n\treturn reducedPoints;\n}\n\nlet _lastCode;\n\n/**\n * Clips the segment a to b by rectangular bounds with the\n * [Cohen-Sutherland algorithm](https://en.wikipedia.org/wiki/Cohen%E2%80%93Sutherland_algorithm)\n * (modifying the segment points directly!). Used by Maplair to only show polyline\n * points that are on the screen or near, increasing performance. Returns `false` if\n * the segment is outside of the bounds.\n * @param {Point} a\n * @param {Point} b\n * @param {Bounds} bounds\n * @param {boolean} [useLastCode]\n * @param {boolean} [round]\n * @returns {[Point, Point]|false}\n */\nexport function clipSegment(a, b, bounds, useLastCode, round) {\n\tlet codeA = useLastCode ? _lastCode : _getBitCode(a, bounds),\n\tcodeB = _getBitCode(b, bounds),\n\n\tcodeOut, p, newCode;\n\n\t// save 2nd code to avoid calculating it on the next segment\n\t_lastCode = codeB;\n\n\twhile (true) {\n\t\t// if a,b is inside the clip window (trivial accept)\n\t\tif (!(codeA | codeB)) {\n\t\t\treturn [a, b];\n\t\t}\n\n\t\t// if a,b is outside the clip window (trivial reject)\n\t\tif (codeA & codeB) {\n\t\t\treturn false;\n\t\t}\n\n\t\t// other cases\n\t\tcodeOut = codeA || codeB;\n\t\tp = _getEdgeIntersection(a, b, codeOut, bounds, round);\n\t\tnewCode = _getBitCode(p, bounds);\n\n\t\tif (codeOut === codeA) {\n\t\t\ta = p;\n\t\t\tcodeA = newCode;\n\t\t} else {\n\t\t\tb = p;\n\t\t\tcodeB = newCode;\n\t\t}\n\t}\n}\n\nexport function _getEdgeIntersection(a, b, code, bounds, round) {\n\tconst dx = b.x - a.x,\n\tdy = b.y - a.y,\n\tmin = bounds.min,\n\tmax = bounds.max;\n\tlet x, y;\n\n\tif (code & 8) { // top\n\t\tx = a.x + dx * (max.y - a.y) / dy;\n\t\ty = max.y;\n\n\t} else if (code & 4) { // bottom\n\t\tx = a.x + dx * (min.y - a.y) / dy;\n\t\ty = min.y;\n\n\t} else if (code & 2) { // right\n\t\tx = max.x;\n\t\ty = a.y + dy * (max.x - a.x) / dx;\n\n\t} else if (code & 1) { // left\n\t\tx = min.x;\n\t\ty = a.y + dy * (min.x - a.x) / dx;\n\t}\n\n\treturn new Point(x, y, round);\n}\n\nexport function _getBitCode(p, bounds) {\n\tlet code = 0;\n\n\tif (p.x < bounds.min.x) { // left\n\t\tcode |= 1;\n\t} else if (p.x > bounds.max.x) { // right\n\t\tcode |= 2;\n\t}\n\n\tif (p.y < bounds.min.y) { // bottom\n\t\tcode |= 4;\n\t} else if (p.y > bounds.max.y) { // top\n\t\tcode |= 8;\n\t}\n\n\treturn code;\n}\n\n// square distance (to avoid unnecessary Math.sqrt calls)\nfunction _sqDist(p1, p2) {\n\tconst dx = p2.x - p1.x,\n\tdy = p2.y - p1.y;\n\treturn dx * dx + dy * dy;\n}\n\n// return closest point on segment or distance to that point\nexport function _sqClosestPointOnSegment(p, p1, p2, sqDist) {\n\tlet x = p1.x,\n\ty = p1.y,\n\tdx = p2.x - x,\n\tdy = p2.y - y,\n\tt;\n\tconst dot = dx * dx + dy * dy;\n\n\tif (dot > 0) {\n\t\tt = ((p.x - x) * dx + (p.y - y) * dy) / dot;\n\n\t\tif (t > 1) {\n\t\t\tx = p2.x;\n\t\t\ty = p2.y;\n\t\t} else if (t > 0) {\n\t\t\tx += dx * t;\n\t\t\ty += dy * t;\n\t\t}\n\t}\n\n\tdx = p.x - x;\n\tdy = p.y - y;\n\n\treturn sqDist ? dx * dx + dy * dy : new Point(x, y);\n}\n\n\n/**\n * Returns true if `latlngs` is a flat array, false is nested.\n * @param {LatLngExpression[]|LatLngExpression[][]} latlngs\n * @returns {boolean}\n */\nexport function isFlat(latlngs) {\n\treturn !Array.isArray(latlngs[0]) || (typeof latlngs[0][0] !== 'object' && typeof latlngs[0][0] !== 'undefined');\n}\n\n/**\n * Returns the center ([centroid](http://en.wikipedia.org/wiki/Centroid)) of the passed\n * LatLngs (first ring) from a polyline.\n * @param {LatLngExpression[]|LatLngExpression[][]} latlngs\n * @param {typeof CRS} crs\n * @returns {LatLng}\n */\nexport function polylineCenter(latlngs, crs) {\n\tlet i, halfDist, segDist, dist, p1, p2, ratio, center;\n\n\tif (!latlngs || latlngs.length === 0) {\n\t\tthrow new Error('latlngs not passed');\n\t}\n\n\tif (!isFlat(latlngs)) {\n\t\tconsole.warn('latlngs are not flat! Only the first ring will be used');\n\t\tlatlngs = latlngs[0];\n\t}\n\n\tlet centroidLatLng = new LatLng([0, 0]);\n\n\tconst bounds = new LatLngBounds(latlngs);\n\tconst areaBounds = bounds.getNorthWest().distanceTo(bounds.getSouthWest()) * bounds.getNorthEast().distanceTo(bounds.getNorthWest());\n\t// tests showed that below 1700 rounding errors are happening\n\tif (areaBounds < 1700) {\n\t\t// getting a inexact center, to move the latlngs near to [0, 0] to prevent rounding errors\n\t\tcentroidLatLng = centroid(latlngs);\n\t}\n\n\tconst len = latlngs.length;\n\tconst points = [];\n\tfor (i = 0; i < len; i++) {\n\t\tconst latlng = new LatLng(latlngs[i]);\n\t\tpoints.push(crs.project(new LatLng([latlng.lat - centroidLatLng.lat, latlng.lng - centroidLatLng.lng])));\n\t}\n\n\tfor (i = 0, halfDist = 0; i < len - 1; i++) {\n\t\thalfDist += points[i].distanceTo(points[i + 1]) / 2;\n\t}\n\n\t// The line is so small in the current view that all points are on the same pixel.\n\tif (halfDist === 0) {\n\t\tcenter = points[0];\n\t} else {\n\t\tfor (i = 0, dist = 0; i < len - 1; i++) {\n\t\t\tp1 = points[i];\n\t\t\tp2 = points[i + 1];\n\t\t\tsegDist = p1.distanceTo(p2);\n\t\t\tdist += segDist;\n\n\t\t\tif (dist > halfDist) {\n\t\t\t\tratio = (dist - halfDist) / segDist;\n\t\t\t\tcenter = [\n\t\t\t\t\tp2.x - ratio * (p2.x - p1.x),\n\t\t\t\t\tp2.y - ratio * (p2.y - p1.y)\n\t\t\t\t];\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n\tconst latlngCenter = crs.unproject(new Point(center));\n\treturn new LatLng([latlngCenter.lat + centroidLatLng.lat, latlngCenter.lng + centroidLatLng.lng]);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2BA,SAAgB,SAAS,QAAQ,WAAW;CAC3C,IAAI,CAAC,aAAa,CAAC,OAAO,QACzB,OAAO,OAAO,MAAM;CAGrB,MAAM,cAAc,YAAY;CAGhC,SAAS,cAAc,QAAQ,WAAW;CAG1C,SAAS,YAAY,QAAQ,WAAW;CAExC,OAAO;AACR;;;;;;;;AASA,SAAgB,uBAAuB,GAAG,IAAI,IAAI;CACjD,OAAO,KAAK,KAAK,yBAAyB,GAAG,IAAI,IAAI,IAAI,CAAC;AAC3D;;;;;;;;AASA,SAAgB,sBAAsB,GAAG,IAAI,IAAI;CAChD,OAAO,yBAA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CAAC,IAAI,OAAO,aAAa,CAAC,CAAC,WAAW,OAAO,aAAa,CAAC,IAElH,MAEhB,iBAAiB,SAAS,OAAO;CAGlC,MAAM,MAAM,QAAQ;CACpB,MAAM,SAAS,CAAC;CAChB,KAAK,IAAI,GAAG,IAAI,KAAK,KAAK;EACzB,MAAM,SAAS,IAAI,OAAO,QAAQ,EAAE;EACpC,OAAO,KAAK,IAAI,QAAQ,IAAI,OAAO,CAAC,OAAO,MAAM,eAAe,KAAK,OAAO,MAAM,eAAe,GAAG,CAAC,CAAC,CAAC;CACxG;CAEA,KAAK,IAAI,GAAG,WAAW,GAAG,IAAI,MAAM,GAAG,KACtC,YAAY,OAAO,EAAE,CAAC,WAAW,OAAO,IAAI,EAAE,IAAI;CAInD,IAAI,aAAa,GAChB,SAAS,OAAO;MAEhB,KAAK,IAAI,GAAG,OAAO,GAAG,IAAI,MAAM,GAAG,KAAK;EACvC,KAAK,OAAO;EACZ,KAAK,OAAO,IAAI;EAChB,UAAU,GAAG,WAAW,EAAE;EAC1B,QAAQ;EAER,IAAI,OAAO,UAAU;GACpB,SAAS,OAAO,YAAY;GAC5B,SAAS,CACR,GAAG,IAAI,SAAS,GAAG,IAAI,GAAG,IAC1B,GAAG,IAAI,SAAS,GAAG,IAAI,GAAG,EAC3B;GACA;EACD;CACD;CAGD,MAAM,eAAe,IAAI,UAAU,IAAI,MAAM,MAAM,CAAC;CACpD,OAAO,IAAI,OAAO,CAAC,aAAa,MAAM,eAAe,KAAK,aAAa,MAAM,eAAe,GAAG,CAAC;AACjG"}
|
|
1
|
+
{"version":3,"file":"LineUtil.js","names":[],"sources":["../../../src/geometry/LineUtil.js"],"sourcesContent":["import {Point} from './Point.js';\nimport {LatLng} from '../geo/LatLng.js';\n/** @import {LatLngExpression} from '../geo/LatLng.js' */\n/** @import {Bounds} from './Bounds.js' */\n/** @import {CRS} from '../geo/crs/CRS.js' */\n\n// LineUtil: various utility functions for polyline points processing, used by Maplair\n// internally to make polylines lightning-fast.\n\n// Simplify polyline with vertex reduction and Douglas-Peucker simplification.\n// Improves rendering performance dramatically by lessening the number of points to draw.\n\n/**\n * Dramatically reduces the number of points in a polyline while retaining\n * its shape and returns a new array of simplified points, using the\n * [Ramer-Douglas-Peucker algorithm](https://en.wikipedia.org/wiki/Ramer-Douglas-Peucker_algorithm).\n * Used for a huge performance boost when processing/displaying Maplair polylines for\n * each zoom level and also reducing visual noise. tolerance affects the amount of\n * simplification (lesser value means higher quality but slower and with more points).\n * Also released as a separated micro-library\n * [Simplify.js](https://mourner.github.io/simplify-js/).\n * @param {Point[]} points\n * @param {number} tolerance\n * @returns {Point[]}\n */\nexport function simplify(points, tolerance) {\n\tif (!tolerance || !points.length) {\n\t\treturn points.slice();\n\t}\n\n\tconst sqTolerance = tolerance * tolerance;\n\n\t// stage 1: vertex reduction\n\tpoints = _reducePoints(points, sqTolerance);\n\n\t// stage 2: Douglas-Peucker simplification\n\tpoints = _simplifyDP(points, sqTolerance);\n\n\treturn points;\n}\n\n/**\n * Returns the distance between point `p` and segment `p1` to `p2`.\n * @param {Point} p\n * @param {Point} p1\n * @param {Point} p2\n * @returns {number}\n */\nexport function pointToSegmentDistance(p, p1, p2) {\n\treturn Math.sqrt(_sqClosestPointOnSegment(p, p1, p2, true));\n}\n\n/**\n * Returns the closest point from a point `p` on a segment `p1` to `p2`.\n * @param {Point} p\n * @param {Point} p1\n * @param {Point} p2\n * @returns {Point}\n */\nexport function closestPointOnSegment(p, p1, p2) {\n\treturn _sqClosestPointOnSegment(p, p1, p2);\n}\n\n// Ramer-Douglas-Peucker simplification, see https://en.wikipedia.org/wiki/Ramer-Douglas-Peucker_algorithm\nfunction _simplifyDP(points, sqTolerance) {\n\n\tconst len = points.length,\n\tmarkers = new Uint8Array(len);\n\tmarkers[0] = markers[len - 1] = 1;\n\n\t_simplifyDPStep(points, markers, sqTolerance, 0, len - 1);\n\n\tlet i;\n\tconst newPoints = [];\n\n\tfor (i = 0; i < len; i++) {\n\t\tif (markers[i]) {\n\t\t\tnewPoints.push(points[i]);\n\t\t}\n\t}\n\n\treturn newPoints;\n}\n\nfunction _simplifyDPStep(points, markers, sqTolerance, first, last) {\n\n\tlet maxSqDist = 0,\n\tindex, i, sqDist;\n\n\tfor (i = first + 1; i <= last - 1; i++) {\n\t\tsqDist = _sqClosestPointOnSegment(points[i], points[first], points[last], true);\n\n\t\tif (sqDist > maxSqDist) {\n\t\t\tindex = i;\n\t\t\tmaxSqDist = sqDist;\n\t\t}\n\t}\n\n\tif (maxSqDist > sqTolerance) {\n\t\tmarkers[index] = 1;\n\n\t\t_simplifyDPStep(points, markers, sqTolerance, first, index);\n\t\t_simplifyDPStep(points, markers, sqTolerance, index, last);\n\t}\n}\n\n// reduce points that are too close to each other to a single point\nfunction _reducePoints(points, sqTolerance) {\n\tconst reducedPoints = [points[0]];\n\tlet prev = 0;\n\n\tfor (let i = 1; i < points.length; i++) {\n\t\tif (_sqDist(points[i], points[prev]) > sqTolerance) {\n\t\t\treducedPoints.push(points[i]);\n\t\t\tprev = i;\n\t\t}\n\t}\n\tif (prev < points.length - 1) {\n\t\treducedPoints.push(points[points.length - 1]);\n\t}\n\treturn reducedPoints;\n}\n\nlet _lastCode;\n\n/**\n * Clips the segment a to b by rectangular bounds with the\n * [Cohen-Sutherland algorithm](https://en.wikipedia.org/wiki/Cohen%E2%80%93Sutherland_algorithm)\n * (modifying the segment points directly!). Used by Maplair to only show polyline\n * points that are on the screen or near, increasing performance. Returns `false` if\n * the segment is outside of the bounds.\n * @param {Point} a\n * @param {Point} b\n * @param {Bounds} bounds\n * @param {boolean} [useLastCode]\n * @param {boolean} [round]\n * @returns {[Point, Point]|false}\n */\nexport function clipSegment(a, b, bounds, useLastCode, round) {\n\tconst a0 = a, b0 = b;\n\tlet codeA = useLastCode ? _lastCode : _getBitCode(a, bounds),\n\tcodeB = _getBitCode(b, bounds),\n\n\tcodeOut, p, newCode;\n\n\t// save 2nd code to avoid calculating it on the next segment\n\t_lastCode = codeB;\n\n\twhile (true) {\n\t\t// if a,b is inside the clip window (trivial accept)\n\t\tif (!(codeA | codeB)) {\n\t\t\t// round only the endpoints that were replaced by a clipped intersection;\n\t\t\t// rounding while iterating can push a point back outside and loop forever\n\t\t\tif (round) {\n\t\t\t\tif (a !== a0) { a = a.round(); }\n\t\t\t\tif (b !== b0) { b = b.round(); }\n\t\t\t}\n\t\t\treturn [a, b];\n\t\t}\n\n\t\t// if a,b is outside the clip window (trivial reject)\n\t\tif (codeA & codeB) {\n\t\t\treturn false;\n\t\t}\n\n\t\t// other cases\n\t\tcodeOut = codeA || codeB;\n\t\tp = _getEdgeIntersection(a, b, codeOut, bounds);\n\t\tnewCode = _getBitCode(p, bounds);\n\n\t\tif (codeOut === codeA) {\n\t\t\ta = p;\n\t\t\tcodeA = newCode;\n\t\t} else {\n\t\t\tb = p;\n\t\t\tcodeB = newCode;\n\t\t}\n\t}\n}\n\nexport function _getEdgeIntersection(a, b, code, bounds, round) {\n\tconst dx = b.x - a.x,\n\tdy = b.y - a.y,\n\tmin = bounds.min,\n\tmax = bounds.max;\n\tlet x, y;\n\n\tif (code & 8) { // top\n\t\tx = a.x + dx * (max.y - a.y) / dy;\n\t\ty = max.y;\n\n\t} else if (code & 4) { // bottom\n\t\tx = a.x + dx * (min.y - a.y) / dy;\n\t\ty = min.y;\n\n\t} else if (code & 2) { // right\n\t\tx = max.x;\n\t\ty = a.y + dy * (max.x - a.x) / dx;\n\n\t} else if (code & 1) { // left\n\t\tx = min.x;\n\t\ty = a.y + dy * (min.x - a.x) / dx;\n\t}\n\n\treturn new Point(x, y, round);\n}\n\nexport function _getBitCode(p, bounds) {\n\tlet code = 0;\n\n\tif (p.x < bounds.min.x) { // left\n\t\tcode |= 1;\n\t} else if (p.x > bounds.max.x) { // right\n\t\tcode |= 2;\n\t}\n\n\tif (p.y < bounds.min.y) { // bottom\n\t\tcode |= 4;\n\t} else if (p.y > bounds.max.y) { // top\n\t\tcode |= 8;\n\t}\n\n\treturn code;\n}\n\n// square distance (to avoid unnecessary Math.sqrt calls)\nfunction _sqDist(p1, p2) {\n\tconst dx = p2.x - p1.x,\n\tdy = p2.y - p1.y;\n\treturn dx * dx + dy * dy;\n}\n\n// return closest point on segment or distance to that point\nexport function _sqClosestPointOnSegment(p, p1, p2, sqDist) {\n\tlet x = p1.x,\n\ty = p1.y,\n\tdx = p2.x - x,\n\tdy = p2.y - y,\n\tt;\n\tconst dot = dx * dx + dy * dy;\n\n\tif (dot > 0) {\n\t\tt = ((p.x - x) * dx + (p.y - y) * dy) / dot;\n\n\t\tif (t > 1) {\n\t\t\tx = p2.x;\n\t\t\ty = p2.y;\n\t\t} else if (t > 0) {\n\t\t\tx += dx * t;\n\t\t\ty += dy * t;\n\t\t}\n\t}\n\n\tdx = p.x - x;\n\tdy = p.y - y;\n\n\treturn sqDist ? dx * dx + dy * dy : new Point(x, y);\n}\n\n\n/**\n * Returns true if `latlngs` is a flat array, false is nested.\n * @param {LatLngExpression[]|LatLngExpression[][]} latlngs\n * @returns {boolean}\n */\nexport function isFlat(latlngs) {\n\treturn !Array.isArray(latlngs[0]) || (typeof latlngs[0][0] !== 'object' && typeof latlngs[0][0] !== 'undefined');\n}\n\n/**\n * Returns the center ([centroid](http://en.wikipedia.org/wiki/Centroid)) of the passed\n * LatLngs (first ring) from a polyline.\n * @param {LatLngExpression[]|LatLngExpression[][]} latlngs\n * @param {typeof CRS} crs\n * @returns {LatLng}\n */\nexport function polylineCenter(latlngs, crs) {\n\tconst points = _projectRing(latlngs, crs),\n\tlen = points.length;\n\n\tlet halfDist = 0;\n\tfor (let i = 1; i < len; i++) {\n\t\thalfDist += points[i - 1].distanceTo(points[i]);\n\t}\n\thalfDist /= 2;\n\n\t// if the line has zero length, the loop below never finds a segment and the first point is the center\n\tlet center = points[0];\n\n\tfor (let i = 1, dist = 0; i < len; i++) {\n\t\tconst p1 = points[i - 1],\n\t\tp2 = points[i],\n\t\tsegDist = p1.distanceTo(p2);\n\t\tdist += segDist;\n\n\t\tif (dist > halfDist) {\n\t\t\tconst ratio = (dist - halfDist) / segDist;\n\t\t\tcenter = new Point(\n\t\t\t\tp2.x - ratio * (p2.x - p1.x),\n\t\t\t\tp2.y - ratio * (p2.y - p1.y)\n\t\t\t);\n\t\t\tbreak;\n\t\t}\n\t}\n\n\treturn crs.unproject(center);\n}\n\n/**\n * Projects the first ring of the given latlngs.\n * @internal\n * @param {LatLngExpression[]|LatLngExpression[][]} latlngs\n * @param {typeof CRS} crs\n * @returns {Point[]}\n */\nexport function _projectRing(latlngs, crs) {\n\tif (!latlngs || latlngs.length === 0) {\n\t\tthrow new Error('latlngs not passed');\n\t}\n\n\tif (!isFlat(latlngs)) {\n\t\tconsole.warn('latlngs are not flat! Only the first ring will be used');\n\t\tlatlngs = latlngs[0];\n\t}\n\n\treturn latlngs.map(latlng => crs.project(LatLng.from(latlng)));\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyBA,SAAgB,SAAS,QAAQ,WAAW;CAC3C,IAAI,CAAC,aAAa,CAAC,OAAO,QACzB,OAAO,OAAO,MAAM;CAGrB,MAAM,cAAc,YAAY;CAGhC,SAAS,cAAc,QAAQ,WAAW;CAG1C,SAAS,YAAY,QAAQ,WAAW;CAExC,OAAO;AACR;;;;;;;;AASA,SAAgB,uBAAuB,GAAG,IAAI,IAAI;CACjD,OAAO,KAAK,KAAK,yBAAyB,GAAG,IAAI,IAAI,IAAI,CAAC;AAC3D;;;;;;;;AASA,SAAgB,sBAAsB,GAAG,IAAI,IAAI;CAChD,OAAO,yBAAyB,GAAG,IAAI,EAAE;AAC1C;AAGA,SAAS,YAAY,QAAQ,aAAa;CAEzC,MAAM,MAAM,OAAO,QACnB,UAAU,IAAI,WAAW,GAAG;CAC5B,QAAQ,KAAK,QAAQ,MAAM,KAAK;CAEhC,gBAAgB,QAAQ,SAAS,aAAa,GAAG,MAAM,CAAC;CAExD,IAAI;CACJ,MAAM,YAAY,CAAC;CAEnB,KAAK,IAAI,GAAG,I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I,SAAS,GAAG,IAAI,GAAG,EAC3B;GACA;EACD;CACD;CAEA,OAAO,IAAI,UAAU,MAAM;AAC5B;;;;;;;;AASA,SAAgB,aAAa,SAAS,KAAK;CAC1C,IAAI,CAAC,WAAW,QAAQ,WAAW,GAClC,MAAM,IAAI,MAAM,oBAAoB;CAGrC,IAAI,CAAC,OAAO,OAAO,GAAG;EACrB,QAAQ,KAAK,wDAAwD;EACrE,UAAU,QAAQ;CACnB;CAEA,OAAO,QAAQ,KAAI,WAAU,IAAI,QAAQ,OAAO,KAAK,MAAM,CAAC,CAAC;AAC9D"}
|
|
@@ -64,6 +64,24 @@ var Point = class Point {
|
|
|
64
64
|
this.y = round ? Math.round(_y) : _y;
|
|
65
65
|
}
|
|
66
66
|
/**
|
|
67
|
+
* Returns the given `Point` object as it is (unless `round` is set), or else a new
|
|
68
|
+
* `Point` object created from the given arguments (the same as of the constructor) —
|
|
69
|
+
* unlike the constructor, which always creates a new object.
|
|
70
|
+
*
|
|
71
|
+
* @example
|
|
72
|
+
* ```js
|
|
73
|
+
* Point.from(point) === point; // true
|
|
74
|
+
* Point.from([200, 300]); // Point(200, 300)
|
|
75
|
+
* ```
|
|
76
|
+
* @param {number|PointExpression} x The `x` coordinate, or the coordinates.
|
|
77
|
+
* @param {number} [y] The `y` coordinate.
|
|
78
|
+
* @param {boolean} [round]
|
|
79
|
+
* @returns {Point}
|
|
80
|
+
*/
|
|
81
|
+
static from(x, y, round) {
|
|
82
|
+
return x instanceof Point && !round ? x : new Point(x, y, round);
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
67
85
|
* Returns `true` if the Point object can be properly initialized with the given
|
|
68
86
|
* arguments (the same as of the constructor).
|
|
69
87
|
* @param {any} x
|
|
@@ -82,7 +100,7 @@ var Point = class Point {
|
|
|
82
100
|
* @returns {Point}
|
|
83
101
|
*/
|
|
84
102
|
add(point) {
|
|
85
|
-
return new Point(this)._add(
|
|
103
|
+
return new Point(this)._add(Point.from(point));
|
|
86
104
|
}
|
|
87
105
|
_add(point) {
|
|
88
106
|
this.x += point.x;
|
|
@@ -95,7 +113,7 @@ var Point = class Point {
|
|
|
95
113
|
* @returns {Point}
|
|
96
114
|
*/
|
|
97
115
|
subtract(point) {
|
|
98
|
-
return new Point(this)._subtract(
|
|
116
|
+
return new Point(this)._subtract(Point.from(point));
|
|
99
117
|
}
|
|
100
118
|
_subtract(point) {
|
|
101
119
|
this.x -= point.x;
|
|
@@ -203,7 +221,7 @@ var Point = class Point {
|
|
|
203
221
|
* @returns {number}
|
|
204
222
|
*/
|
|
205
223
|
distanceTo(point) {
|
|
206
|
-
point =
|
|
224
|
+
point = Point.from(point);
|
|
207
225
|
const x = point.x - this.x, y = point.y - this.y;
|
|
208
226
|
return Math.sqrt(x * x + y * y);
|
|
209
227
|
}
|
|
@@ -213,7 +231,7 @@ var Point = class Point {
|
|
|
213
231
|
* @returns {boolean}
|
|
214
232
|
*/
|
|
215
233
|
equals(point) {
|
|
216
|
-
point =
|
|
234
|
+
point = Point.from(point);
|
|
217
235
|
return point.x === this.x && point.y === this.y;
|
|
218
236
|
}
|
|
219
237
|
/**
|
|
@@ -223,7 +241,7 @@ var Point = class Point {
|
|
|
223
241
|
* @returns {boolean}
|
|
224
242
|
*/
|
|
225
243
|
contains(point) {
|
|
226
|
-
point =
|
|
244
|
+
point = Point.from(point);
|
|
227
245
|
return Math.abs(point.x) <= Math.abs(this.x) && Math.abs(point.y) <= Math.abs(this.y);
|
|
228
246
|
}
|
|
229
247
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Point.js","names":[],"sources":["../../../src/geometry/Point.js"],"sourcesContent":["import {formatNum} from '../core/Util.js';\n\n/**\n * A point in pixels: a `Point`, an array of the form `[x, y]`, or a plain object of\n * the form `{x, y}`. Accepted by all Maplair methods and options which accept `Point`\n * objects (unless noted otherwise).\n * @typedef {Point|[number, number]|number[]|{x: number, y: number}} PointExpression\n */\n\n/**\n * Represents a point with `x` and `y` coordinates in pixels.\n *\n * @example\n * ```js\n * const point = new Point(200, 300);\n * ```\n *\n * All Maplair methods and options that accept `Point` objects also accept them in a\n * simple Array form (unless noted otherwise), so these lines are equivalent:\n *\n * ```js\n * map.panBy([200, 300]);\n * map.panBy(new Point(200, 300));\n * ```\n *\n * Note that `Point` does not inherit from Maplair's `Class` object,\n * which means new classes can't inherit from it, and new methods\n * can't be added to it with the `include` function.\n */\nexport class Point {\n\t/**\n\t * Creates a Point object with the given `x` and `y` coordinates. If optional `round`\n\t * is set to true, rounds the `x` and `y` values. Alternatively, expects a Point\n\t * object, an array of the form `[x, y]` or a plain object of the form `{x, y}`\n\t * instead.\n\t * @param {number|PointExpression} x The `x` coordinate, or the coordinates.\n\t * @param {number} [y] The `y` coordinate.\n\t * @param {boolean} [round]\n\t */\n\tconstructor(x, y, round) {\n\n\t\tconst valid = Point.validate(x, y);\n\t\tif (!valid) {\n\t\t\tthrow new Error(`Invalid Point object: (${x}, ${y})`);\n\t\t}\n\n\t\tlet _x, _y;\n\t\tif (x instanceof Point) {\n\t\t\t_x = x.x;\n\t\t\t_y = x.y;\n\t\t} else if (Array.isArray(x)) {\n\t\t\t_x = x[0];\n\t\t\t_y = x[1];\n\t\t} else if (typeof x === 'object' && 'x' in x && 'y' in x) {\n\t\t\t_x = x.x;\n\t\t\t_y = x.y;\n\t\t} else {\n\t\t\t_x = x;\n\t\t\t_y = y;\n\t\t}\n\n\t\t/**\n\t\t * The `x` coordinate of the point.\n\t\t * @type {number}\n\t\t */\n\t\tthis.x = (round ? Math.round(_x) : _x);\n\t\t/**\n\t\t * The `y` coordinate of the point.\n\t\t * @type {number}\n\t\t */\n\t\tthis.y = (round ? Math.round(_y) : _y);\n\t}\n\n\t/**\n\t * Returns `true` if the Point object can be properly initialized with the given\n\t * arguments (the same as of the constructor).\n\t * @param {any} x\n\t * @param {any} [y]\n\t * @returns {boolean}\n\t */\n\tstatic validate(x, y) {\n\t\tif (x instanceof Point || Array.isArray(x)) {\n\t\t\treturn true;\n\t\t} else if (x && typeof x === 'object' && 'x' in x && 'y' in x) {\n\t\t\treturn true;\n\t\t} else if ((x || x === 0) && (y || y === 0)) {\n\t\t\treturn true;\n\t\t}\n\t\treturn false;\n\t}\n\n\t/**\n\t * Returns the result of addition of the current and the given points.\n\t * @param {PointExpression} point\n\t * @returns {Point}\n\t */\n\tadd(point) {\n\t\t// non-destructive, returns a new point\n\t\treturn new Point(this)._add(new Point(point));\n\t}\n\n\t_add(point) {\n\t\t// destructive, used directly for performance in situations where it's safe to modify existing point\n\t\tthis.x += point.x;\n\t\tthis.y += point.y;\n\t\treturn this;\n\t}\n\n\t/**\n\t * Returns the result of subtraction of the given point from the current.\n\t * @param {PointExpression} point\n\t * @returns {Point}\n\t */\n\tsubtract(point) {\n\t\treturn new Point(this)._subtract(new Point(point));\n\t}\n\n\t_subtract(point) {\n\t\tthis.x -= point.x;\n\t\tthis.y -= point.y;\n\t\treturn this;\n\t}\n\n\t/**\n\t * Returns the result of division of the current point by the given number.\n\t * @param {number} num\n\t * @returns {Point}\n\t */\n\tdivideBy(num) {\n\t\treturn new Point(this)._divideBy(num);\n\t}\n\n\t_divideBy(num) {\n\t\tthis.x /= num;\n\t\tthis.y /= num;\n\t\treturn this;\n\t}\n\n\t/**\n\t * Returns the result of multiplication of the current point by the given number.\n\t * @param {number} num\n\t * @returns {Point}\n\t */\n\tmultiplyBy(num) {\n\t\treturn new Point(this)._multiplyBy(num);\n\t}\n\n\t_multiplyBy(num) {\n\t\tthis.x *= num;\n\t\tthis.y *= num;\n\t\treturn this;\n\t}\n\n\t/**\n\t * Multiply each coordinate of the current point by each coordinate of\n\t * `scale`. In linear algebra terms, multiply the point by the\n\t * [scaling matrix](https://en.wikipedia.org/wiki/Scaling_%28geometry%29#Matrix_representation)\n\t * defined by `scale`.\n\t * @param {Point} point The scale.\n\t * @returns {Point}\n\t */\n\tscaleBy(point) {\n\t\treturn new Point(this.x * point.x, this.y * point.y);\n\t}\n\n\t/**\n\t * Inverse of `scaleBy`. Divide each coordinate of the current point by\n\t * each coordinate of `scale`.\n\t * @param {Point} point The scale.\n\t * @returns {Point}\n\t */\n\tunscaleBy(point) {\n\t\treturn new Point(this.x / point.x, this.y / point.y);\n\t}\n\n\t/**\n\t * Returns a copy of the current point with rounded coordinates.\n\t * @returns {Point}\n\t */\n\tround() {\n\t\treturn new Point(this)._round();\n\t}\n\n\t_round() {\n\t\tthis.x = Math.round(this.x);\n\t\tthis.y = Math.round(this.y);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Returns a copy of the current point with floored coordinates (rounded down).\n\t * @returns {Point}\n\t */\n\tfloor() {\n\t\treturn new Point(this)._floor();\n\t}\n\n\t_floor() {\n\t\tthis.x = Math.floor(this.x);\n\t\tthis.y = Math.floor(this.y);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Returns a copy of the current point with ceiled coordinates (rounded up).\n\t * @returns {Point}\n\t */\n\tceil() {\n\t\treturn new Point(this)._ceil();\n\t}\n\n\t_ceil() {\n\t\tthis.x = Math.ceil(this.x);\n\t\tthis.y = Math.ceil(this.y);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Returns a copy of the current point with truncated coordinates (rounded towards\n\t * zero).\n\t * @returns {Point}\n\t */\n\ttrunc() {\n\t\treturn new Point(this)._trunc();\n\t}\n\n\t_trunc() {\n\t\tthis.x = Math.trunc(this.x);\n\t\tthis.y = Math.trunc(this.y);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Returns the cartesian distance between the current and the given points.\n\t * @param {PointExpression} point\n\t * @returns {number}\n\t */\n\tdistanceTo(point) {\n\t\tpoint = new Point(point);\n\n\t\tconst x = point.x - this.x,\n\t\ty = point.y - this.y;\n\n\t\treturn Math.sqrt(x * x + y * y);\n\t}\n\n\t/**\n\t * Returns `true` if the given point has the same coordinates.\n\t * @param {PointExpression} point\n\t * @returns {boolean}\n\t */\n\tequals(point) {\n\t\tpoint = new Point(point);\n\n\t\treturn point.x === this.x &&\n\t\t point.y === this.y;\n\t}\n\n\t/**\n\t * Returns `true` if both coordinates of the given point are less than the\n\t * corresponding current point coordinates (in absolute values).\n\t * @param {PointExpression} point\n\t * @returns {boolean}\n\t */\n\tcontains(point) {\n\t\tpoint = new Point(point);\n\n\t\treturn Math.abs(point.x) <= Math.abs(this.x) &&\n\t\t Math.abs(point.y) <= Math.abs(this.y);\n\t}\n\n\t/**\n\t * Returns a string representation of the point for debugging purposes.\n\t * @returns {string}\n\t */\n\ttoString() {\n\t\treturn `Point(${formatNum(this.x)}, ${formatNum(this.y)})`;\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6BA,IAAa,QAAb,MAAa,MAAM;;;;;;;;;;CAUlB,YAAY,GAAG,GAAG,OAAO;EAGxB,IAAI,CADU,MAAM,SAAS,GAAG,CACvB,GACR,MAAM,IAAI,MAAM,0BAA0B,EAAE,IAAI,EAAE,EAAE;EAGrD,IAAI,IAAI;EACR,IAAI,aAAa,OAAO;GACvB,KAAK,EAAE;GACP,KAAK,EAAE;EACR,OAAO,IAAI,MAAM,QAAQ,CAAC,GAAG;GAC5B,KAAK,EAAE;GACP,KAAK,EAAE;EACR,OAAO,IAAI,OAAO,MAAM,YAAY,OAAO,KAAK,OAAO,GAAG;GACzD,KAAK,EAAE;GACP,KAAK,EAAE;EACR,OAAO;GACN,KAAK;GACL,KAAK;EACN;;;;;EAMA,KAAK,IAAK,QAAQ,KAAK,MAAM,EAAE,IAAI;;;;;EAKnC,KAAK,IAAK,QAAQ,KAAK,MAAM,EAAE,IAAI;CACpC;;;;;;;;CASA,OAAO,SAAS,GAAG,GAAG;EACrB,IAAI,aAAa,SAAS,MAAM,QAAQ,CAAC,GACxC,OAAO;OACD,IAAI,KAAK,OAAO,MAAM,YAAY,OAAO,KAAK,OAAO,GAC3D,OAAO;OACD,KAAK,KAAK,MAAM,OAAO,KAAK,MAAM,IACxC,OAAO;EAER,OAAO;CACR;;;;;;CAOA,IAAI,OAAO;EAEV,OAAO,IAAI,MAAM,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O,IAAI,MAAM,IAAI,CAAC,CAAC,MAAM;CAC9B;CAEA,QAAQ;EACP,KAAK,IAAI,KAAK,KAAK,KAAK,CAAC;EACzB,KAAK,IAAI,KAAK,KAAK,KAAK,CAAC;EACzB,OAAO;CACR;;;;;;CAOA,QAAQ;EACP,OAAO,IAAI,MAAM,IAAI,CAAC,CAAC,OAAO;CAC/B;CAEA,SAAS;EACR,KAAK,IAAI,KAAK,MAAM,KAAK,CAAC;EAC1B,KAAK,IAAI,KAAK,MAAM,KAAK,CAAC;EAC1B,OAAO;CACR;;;;;;CAOA,WAAW,OAAO;EACjB,QAAQ,IAAI,MAAM,KAAK;EAEvB,MAAM,IAAI,MAAM,IAAI,KAAK,GACzB,IAAI,MAAM,IAAI,KAAK;EAEnB,OAAO,KAAK,KAAK,IAAI,IAAI,IAAI,CAAC;CAC/B;;;;;;CAOA,OAAO,OAAO;EACb,QAAQ,IAAI,MAAM,KAAK;EAEvB,OAAO,MAAM,MAAM,KAAK,KACjB,MAAM,MAAM,KAAK;CACzB;;;;;;;CAQA,SAAS,OAAO;EACf,QAAQ,IAAI,MAAM,KAAK;EAEvB,OAAO,KAAK,IAAI,MAAM,CAAC,KAAK,KAAK,IAAI,KAAK,CAAC,KACpC,KAAK,IAAI,MAAM,CAAC,KAAK,KAAK,IAAI,KAAK,CAAC;CAC5C;;;;;CAMA,WAAW;EACV,OAAO,SAAS,UAAU,KAAK,CAAC,EAAE,IAAI,UAAU,KAAK,CAAC,EAAE;CACzD;AACD"}
|
|
1
|
+
{"version":3,"file":"Point.js","names":[],"sources":["../../../src/geometry/Point.js"],"sourcesContent":["import {formatNum} from '../core/Util.js';\n\n/**\n * A point in pixels: a `Point`, an array of the form `[x, y]`, or a plain object of\n * the form `{x, y}`. Accepted by all Maplair methods and options which accept `Point`\n * objects (unless noted otherwise).\n * @typedef {Point|[number, number]|number[]|{x: number, y: number}} PointExpression\n */\n\n/**\n * Represents a point with `x` and `y` coordinates in pixels.\n *\n * @example\n * ```js\n * const point = new Point(200, 300);\n * ```\n *\n * All Maplair methods and options that accept `Point` objects also accept them in a\n * simple Array form (unless noted otherwise), so these lines are equivalent:\n *\n * ```js\n * map.panBy([200, 300]);\n * map.panBy(new Point(200, 300));\n * ```\n *\n * Note that `Point` does not inherit from Maplair's `Class` object,\n * which means new classes can't inherit from it, and new methods\n * can't be added to it with the `include` function.\n */\nexport class Point {\n\t/**\n\t * Creates a Point object with the given `x` and `y` coordinates. If optional `round`\n\t * is set to true, rounds the `x` and `y` values. Alternatively, expects a Point\n\t * object, an array of the form `[x, y]` or a plain object of the form `{x, y}`\n\t * instead.\n\t * @param {number|PointExpression} x The `x` coordinate, or the coordinates.\n\t * @param {number} [y] The `y` coordinate.\n\t * @param {boolean} [round]\n\t */\n\tconstructor(x, y, round) {\n\n\t\tconst valid = Point.validate(x, y);\n\t\tif (!valid) {\n\t\t\tthrow new Error(`Invalid Point object: (${x}, ${y})`);\n\t\t}\n\n\t\tlet _x, _y;\n\t\tif (x instanceof Point) {\n\t\t\t_x = x.x;\n\t\t\t_y = x.y;\n\t\t} else if (Array.isArray(x)) {\n\t\t\t_x = x[0];\n\t\t\t_y = x[1];\n\t\t} else if (typeof x === 'object' && 'x' in x && 'y' in x) {\n\t\t\t_x = x.x;\n\t\t\t_y = x.y;\n\t\t} else {\n\t\t\t_x = x;\n\t\t\t_y = y;\n\t\t}\n\n\t\t/**\n\t\t * The `x` coordinate of the point.\n\t\t * @type {number}\n\t\t */\n\t\tthis.x = (round ? Math.round(_x) : _x);\n\t\t/**\n\t\t * The `y` coordinate of the point.\n\t\t * @type {number}\n\t\t */\n\t\tthis.y = (round ? Math.round(_y) : _y);\n\t}\n\n\t/**\n\t * Returns the given `Point` object as it is (unless `round` is set), or else a new\n\t * `Point` object created from the given arguments (the same as of the constructor) —\n\t * unlike the constructor, which always creates a new object.\n\t *\n\t * @example\n\t * ```js\n\t * Point.from(point) === point; // true\n\t * Point.from([200, 300]); // Point(200, 300)\n\t * ```\n\t * @param {number|PointExpression} x The `x` coordinate, or the coordinates.\n\t * @param {number} [y] The `y` coordinate.\n\t * @param {boolean} [round]\n\t * @returns {Point}\n\t */\n\tstatic from(x, y, round) {\n\t\treturn x instanceof Point && !round ? x : new Point(x, y, round);\n\t}\n\n\t/**\n\t * Returns `true` if the Point object can be properly initialized with the given\n\t * arguments (the same as of the constructor).\n\t * @param {any} x\n\t * @param {any} [y]\n\t * @returns {boolean}\n\t */\n\tstatic validate(x, y) {\n\t\tif (x instanceof Point || Array.isArray(x)) {\n\t\t\treturn true;\n\t\t} else if (x && typeof x === 'object' && 'x' in x && 'y' in x) {\n\t\t\treturn true;\n\t\t} else if ((x || x === 0) && (y || y === 0)) {\n\t\t\treturn true;\n\t\t}\n\t\treturn false;\n\t}\n\n\t/**\n\t * Returns the result of addition of the current and the given points.\n\t * @param {PointExpression} point\n\t * @returns {Point}\n\t */\n\tadd(point) {\n\t\t// non-destructive, returns a new point\n\t\treturn new Point(this)._add(Point.from(point));\n\t}\n\n\t_add(point) {\n\t\t// destructive, used directly for performance in situations where it's safe to modify existing point\n\t\tthis.x += point.x;\n\t\tthis.y += point.y;\n\t\treturn this;\n\t}\n\n\t/**\n\t * Returns the result of subtraction of the given point from the current.\n\t * @param {PointExpression} point\n\t * @returns {Point}\n\t */\n\tsubtract(point) {\n\t\treturn new Point(this)._subtract(Point.from(point));\n\t}\n\n\t_subtract(point) {\n\t\tthis.x -= point.x;\n\t\tthis.y -= point.y;\n\t\treturn this;\n\t}\n\n\t/**\n\t * Returns the result of division of the current point by the given number.\n\t * @param {number} num\n\t * @returns {Point}\n\t */\n\tdivideBy(num) {\n\t\treturn new Point(this)._divideBy(num);\n\t}\n\n\t_divideBy(num) {\n\t\tthis.x /= num;\n\t\tthis.y /= num;\n\t\treturn this;\n\t}\n\n\t/**\n\t * Returns the result of multiplication of the current point by the given number.\n\t * @param {number} num\n\t * @returns {Point}\n\t */\n\tmultiplyBy(num) {\n\t\treturn new Point(this)._multiplyBy(num);\n\t}\n\n\t_multiplyBy(num) {\n\t\tthis.x *= num;\n\t\tthis.y *= num;\n\t\treturn this;\n\t}\n\n\t/**\n\t * Multiply each coordinate of the current point by each coordinate of\n\t * `scale`. In linear algebra terms, multiply the point by the\n\t * [scaling matrix](https://en.wikipedia.org/wiki/Scaling_%28geometry%29#Matrix_representation)\n\t * defined by `scale`.\n\t * @param {Point} point The scale.\n\t * @returns {Point}\n\t */\n\tscaleBy(point) {\n\t\treturn new Point(this.x * point.x, this.y * point.y);\n\t}\n\n\t/**\n\t * Inverse of `scaleBy`. Divide each coordinate of the current point by\n\t * each coordinate of `scale`.\n\t * @param {Point} point The scale.\n\t * @returns {Point}\n\t */\n\tunscaleBy(point) {\n\t\treturn new Point(this.x / point.x, this.y / point.y);\n\t}\n\n\t/**\n\t * Returns a copy of the current point with rounded coordinates.\n\t * @returns {Point}\n\t */\n\tround() {\n\t\treturn new Point(this)._round();\n\t}\n\n\t_round() {\n\t\tthis.x = Math.round(this.x);\n\t\tthis.y = Math.round(this.y);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Returns a copy of the current point with floored coordinates (rounded down).\n\t * @returns {Point}\n\t */\n\tfloor() {\n\t\treturn new Point(this)._floor();\n\t}\n\n\t_floor() {\n\t\tthis.x = Math.floor(this.x);\n\t\tthis.y = Math.floor(this.y);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Returns a copy of the current point with ceiled coordinates (rounded up).\n\t * @returns {Point}\n\t */\n\tceil() {\n\t\treturn new Point(this)._ceil();\n\t}\n\n\t_ceil() {\n\t\tthis.x = Math.ceil(this.x);\n\t\tthis.y = Math.ceil(this.y);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Returns a copy of the current point with truncated coordinates (rounded towards\n\t * zero).\n\t * @returns {Point}\n\t */\n\ttrunc() {\n\t\treturn new Point(this)._trunc();\n\t}\n\n\t_trunc() {\n\t\tthis.x = Math.trunc(this.x);\n\t\tthis.y = Math.trunc(this.y);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Returns the cartesian distance between the current and the given points.\n\t * @param {PointExpression} point\n\t * @returns {number}\n\t */\n\tdistanceTo(point) {\n\t\tpoint = Point.from(point);\n\n\t\tconst x = point.x - this.x,\n\t\ty = point.y - this.y;\n\n\t\treturn Math.sqrt(x * x + y * y);\n\t}\n\n\t/**\n\t * Returns `true` if the given point has the same coordinates.\n\t * @param {PointExpression} point\n\t * @returns {boolean}\n\t */\n\tequals(point) {\n\t\tpoint = Point.from(point);\n\n\t\treturn point.x === this.x &&\n\t\t point.y === this.y;\n\t}\n\n\t/**\n\t * Returns `true` if both coordinates of the given point are less than the\n\t * corresponding current point coordinates (in absolute values).\n\t * @param {PointExpression} point\n\t * @returns {boolean}\n\t */\n\tcontains(point) {\n\t\tpoint = Point.from(point);\n\n\t\treturn Math.abs(point.x) <= Math.abs(this.x) &&\n\t\t Math.abs(point.y) <= Math.abs(this.y);\n\t}\n\n\t/**\n\t * Returns a string representation of the point for debugging purposes.\n\t * @returns {string}\n\t */\n\ttoString() {\n\t\treturn `Point(${formatNum(this.x)}, ${formatNum(this.y)})`;\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6BA,IAAa,QAAb,MAAa,MAAM;;;;;;;;;;CAUlB,YAAY,GAAG,GAAG,OAAO;EAGxB,IAAI,CADU,MAAM,SAAS,GAAG,CACvB,GACR,MAAM,IAAI,MAAM,0BAA0B,EAAE,IAAI,EAAE,EAAE;EAGrD,IAAI,IAAI;EACR,IAAI,aAAa,OAAO;GACvB,KAAK,EAAE;GACP,KAAK,EAAE;EACR,OAAO,IAAI,MAAM,QAAQ,CAAC,GAAG;GAC5B,KAAK,EAAE;GACP,KAAK,EAAE;EACR,OAAO,IAAI,OAAO,MAAM,YAAY,OAAO,KAAK,OAAO,GAAG;GACzD,KAAK,EAAE;GACP,KAAK,EAAE;EACR,OAAO;GACN,KAAK;GACL,KAAK;EACN;;;;;EAMA,KAAK,IAAK,QAAQ,KAAK,MAAM,EAAE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,CAAC,KACpC,KAAK,IAAI,MAAM,CAAC,KAAK,KAAK,IAAI,KAAK,CAAC;CAC5C;;;;;CAMA,WAAW;EACV,OAAO,SAAS,UAAU,KAAK,CAAC,EAAE,IAAI,UAAU,KAAK,CAAC,EAAE;CACzD;AACD"}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { __exportAll } from "../_virtual/_rolldown/runtime.js";
|
|
2
2
|
import { Point } from "./Point.js";
|
|
3
|
-
import { LatLngBounds } from "../geo/LatLngBounds.js";
|
|
4
3
|
import { LatLng } from "../geo/LatLng.js";
|
|
5
|
-
import { _getBitCode, _getEdgeIntersection,
|
|
4
|
+
import { _getBitCode, _getEdgeIntersection, _projectRing } from "./LineUtil.js";
|
|
6
5
|
//#region src/geometry/PolyUtil.js
|
|
7
6
|
var PolyUtil_exports = /* @__PURE__ */ __exportAll({
|
|
8
7
|
centroid: () => centroid,
|
|
@@ -63,34 +62,16 @@ function clipPolygon(points, bounds, round) {
|
|
|
63
62
|
* @returns {LatLng}
|
|
64
63
|
*/
|
|
65
64
|
function polygonCenter(latlngs, crs) {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
}
|
|
72
|
-
let centroidLatLng = new LatLng([0, 0]);
|
|
73
|
-
const bounds = new LatLngBounds(latlngs);
|
|
74
|
-
if (bounds.getNorthWest().distanceTo(bounds.getSouthWest()) * bounds.getNorthEast().distanceTo(bounds.getNorthWest()) < 1700) centroidLatLng = centroid(latlngs);
|
|
75
|
-
const len = latlngs.length;
|
|
76
|
-
const points = [];
|
|
77
|
-
for (i = 0; i < len; i++) {
|
|
78
|
-
const latlng = new LatLng(latlngs[i]);
|
|
79
|
-
points.push(crs.project(new LatLng([latlng.lat - centroidLatLng.lat, latlng.lng - centroidLatLng.lng])));
|
|
80
|
-
}
|
|
81
|
-
area = x = y = 0;
|
|
82
|
-
for (i = 0, j = len - 1; i < len; j = i++) {
|
|
83
|
-
p1 = points[i];
|
|
84
|
-
p2 = points[j];
|
|
85
|
-
f = p1.y * p2.x - p2.y * p1.x;
|
|
65
|
+
const points = _projectRing(latlngs, crs), origin = new Point(points[0]), len = points.length;
|
|
66
|
+
for (const p of points) p._subtract(origin);
|
|
67
|
+
let area = 0, x = 0, y = 0;
|
|
68
|
+
for (let i = 0, j = len - 1; i < len; j = i++) {
|
|
69
|
+
const p1 = points[i], p2 = points[j], f = p1.y * p2.x - p2.y * p1.x;
|
|
86
70
|
x += (p1.x + p2.x) * f;
|
|
87
71
|
y += (p1.y + p2.y) * f;
|
|
88
|
-
area += f
|
|
72
|
+
area += f;
|
|
89
73
|
}
|
|
90
|
-
|
|
91
|
-
else center = [x / area, y / area];
|
|
92
|
-
const latlngCenter = crs.unproject(new Point(center));
|
|
93
|
-
return new LatLng([latlngCenter.lat + centroidLatLng.lat, latlngCenter.lng + centroidLatLng.lng]);
|
|
74
|
+
return crs.unproject(area === 0 ? origin : new Point(x / (3 * area), y / (3 * area))._add(origin));
|
|
94
75
|
}
|
|
95
76
|
/**
|
|
96
77
|
* Returns the 'center of mass' of the passed LatLngs.
|
|
@@ -102,7 +83,7 @@ function centroid(coords) {
|
|
|
102
83
|
let lngSum = 0;
|
|
103
84
|
let len = 0;
|
|
104
85
|
for (const coord of coords) {
|
|
105
|
-
const latlng =
|
|
86
|
+
const latlng = LatLng.from(coord);
|
|
106
87
|
latSum += latlng.lat;
|
|
107
88
|
lngSum += latlng.lng;
|
|
108
89
|
len++;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PolyUtil.js","names":["LineUtil._getBitCode","LineUtil._getEdgeIntersection","LineUtil.
|
|
1
|
+
{"version":3,"file":"PolyUtil.js","names":["LineUtil._getBitCode","LineUtil._getEdgeIntersection","LineUtil._projectRing"],"sources":["../../../src/geometry/PolyUtil.js"],"sourcesContent":["import * as LineUtil from './LineUtil.js';\nimport {LatLng} from '../geo/LatLng.js';\nimport {Point} from './Point.js';\n/** @import {LatLngExpression} from '../geo/LatLng.js' */\n/** @import {Bounds} from './Bounds.js' */\n/** @import {CRS} from '../geo/crs/CRS.js' */\n\n// PolyUtil: various utility functions for polygon geometries.\n\n/**\n * Clips the polygon geometry defined by the given `points` by the given bounds (using\n * the [Sutherland-Hodgman algorithm](https://en.wikipedia.org/wiki/Sutherland%E2%80%93Hodgman_algorithm)).\n * Used by Maplair to only show polygon points that are on the screen or near, increasing\n * performance. Note that polygon points needs different algorithm for clipping\n * than polyline, so there's a separate method for it.\n * @param {Point[]} points\n * @param {Bounds} bounds\n * @param {boolean} [round]\n * @returns {Point[]}\n */\nexport function clipPolygon(points, bounds, round) {\n\tlet clippedPoints,\n\ti, j, k,\n\ta, b,\n\tlen, edge, p;\n\tconst edges = [1, 4, 2, 8];\n\n\tfor (i = 0, len = points.length; i < len; i++) {\n\t\tpoints[i]._code = LineUtil._getBitCode(points[i], bounds);\n\t}\n\n\t// for each edge (left, bottom, right, top)\n\tfor (k = 0; k < 4; k++) {\n\t\tedge = edges[k];\n\t\tclippedPoints = [];\n\n\t\tfor (i = 0, len = points.length, j = len - 1; i < len; j = i++) {\n\t\t\ta = points[i];\n\t\t\tb = points[j];\n\n\t\t\t// if a is inside the clip window\n\t\t\tif (!(a._code & edge)) {\n\t\t\t\t// if b is outside the clip window (a->b goes out of screen)\n\t\t\t\tif (b._code & edge) {\n\t\t\t\t\tp = LineUtil._getEdgeIntersection(b, a, edge, bounds, round);\n\t\t\t\t\tp._code = LineUtil._getBitCode(p, bounds);\n\t\t\t\t\tclippedPoints.push(p);\n\t\t\t\t}\n\t\t\t\tclippedPoints.push(a);\n\n\t\t\t// else if b is inside the clip window (a->b enters the screen)\n\t\t\t} else if (!(b._code & edge)) {\n\t\t\t\tp = LineUtil._getEdgeIntersection(b, a, edge, bounds, round);\n\t\t\t\tp._code = LineUtil._getBitCode(p, bounds);\n\t\t\t\tclippedPoints.push(p);\n\t\t\t}\n\t\t}\n\t\tpoints = clippedPoints;\n\t}\n\n\treturn points;\n}\n\n/**\n * Returns the center ([centroid](http://en.wikipedia.org/wiki/Centroid)) of the passed\n * LatLngs (first ring) from a polygon.\n * @param {LatLngExpression[]|LatLngExpression[][]} latlngs\n * @param {typeof CRS} crs\n * @returns {LatLng}\n */\nexport function polygonCenter(latlngs, crs) {\n\t// points relative to the first one, to avoid floating point errors on tiny polygons with large projected coordinates\n\tconst points = LineUtil._projectRing(latlngs, crs),\n\torigin = new Point(points[0]),\n\tlen = points.length;\n\n\tfor (const p of points) { p._subtract(origin); }\n\n\tlet area = 0, x = 0, y = 0;\n\n\t// polygon centroid algorithm\n\tfor (let i = 0, j = len - 1; i < len; j = i++) {\n\t\tconst p1 = points[i],\n\t\tp2 = points[j],\n\t\tf = p1.y * p2.x - p2.y * p1.x;\n\n\t\tx += (p1.x + p2.x) * f;\n\t\ty += (p1.y + p2.y) * f;\n\t\tarea += f;\n\t}\n\n\t// area is 0 when the polygon is so small that all points are on the same pixel\n\treturn crs.unproject(area === 0 ? origin : new Point(x / (3 * area), y / (3 * area))._add(origin));\n}\n\n/**\n * Returns the 'center of mass' of the passed LatLngs.\n * @param {LatLngExpression[]} coords\n * @returns {LatLng}\n */\nexport function centroid(coords) {\n\tlet latSum = 0;\n\tlet lngSum = 0;\n\tlet len = 0;\n\tfor (const coord of coords) {\n\t\tconst latlng = LatLng.from(coord);\n\t\tlatSum += latlng.lat;\n\t\tlngSum += latlng.lng;\n\t\tlen++;\n\t}\n\treturn new LatLng([latSum / len, lngSum / len]);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAoBA,SAAgB,YAAY,QAAQ,QAAQ,OAAO;CAClD,IAAI,eACJ,GAAG,GAAG,GACN,GAAG,GACH,KAAK,MAAM;CACX,MAAM,QAAQ;EAAC;EAAG;EAAG;EAAG;CAAC;CAEzB,KAAK,IAAI,GAAG,MAAM,OAAO,QAAQ,IAAI,KAAK,KACzC,OAAO,EAAE,CAAC,QAAQA,YAAqB,OAAO,IAAI,MAAM;CAIzD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;;;;AAOA,SAAgB,SAAS,QAAQ;CAChC,IAAI,SAAS;CACb,IAAI,SAAS;CACb,IAAI,MAAM;CACV,KAAK,MAAM,SAAS,QAAQ;EAC3B,MAAM,SAAS,OAAO,KAAK,KAAK;EAChC,UAAU,OAAO;EACjB,UAAU,OAAO;EACjB;CACD;CACA,OAAO,IAAI,OAAO,CAAC,SAAS,KAAK,SAAS,GAAG,CAAC;AAC/C"}
|
|
@@ -43,12 +43,10 @@ import { Bounds } from "../geometry/Bounds.js";
|
|
|
43
43
|
* state change (including *during* pan/zoom animations).
|
|
44
44
|
*/
|
|
45
45
|
var BlanketOverlay = class BlanketOverlay extends Layer {
|
|
46
|
-
static {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
});
|
|
51
|
-
}
|
|
46
|
+
static defaultOptions = {
|
|
47
|
+
padding: .1,
|
|
48
|
+
continuous: false
|
|
49
|
+
};
|
|
52
50
|
/**
|
|
53
51
|
* @param {BlanketOverlayOptions} [options]
|
|
54
52
|
*/
|
|
@@ -87,9 +85,9 @@ var BlanketOverlay = class BlanketOverlay extends Layer {
|
|
|
87
85
|
zoom: this._onZoom,
|
|
88
86
|
moveend: this._onMoveEnd,
|
|
89
87
|
resize: this._resizeContainer,
|
|
90
|
-
zoomend: this._onZoomEnd
|
|
88
|
+
zoomend: this._onZoomEnd,
|
|
89
|
+
zoomanim: this._onAnimZoom
|
|
91
90
|
};
|
|
92
|
-
if (this._zoomAnimated) events.zoomanim = this._onAnimZoom;
|
|
93
91
|
if (this.options.continuous) events.move = this._onMoveEnd;
|
|
94
92
|
return events;
|
|
95
93
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BlanketOverlay.js","names":["DomUtil.create"],"sources":["../../../src/layer/BlanketOverlay.js"],"sourcesContent":["import {Layer} from './Layer.js';\nimport * as DomUtil from '../dom/DomUtil.js';\nimport * as Util from '../core/Util.js';\nimport * as DomEvent from '../dom/DomEvent.js';\nimport {Bounds} from '../geometry/Bounds.js';\n/** @import {LayerOptions} from './Layer.js' */\n/** @import {MaplairMap} from '../map/Map.js' */\n/** @import {EventListener} from '../core/Events.js' */\n\n/**\n * Options of `BlanketOverlay`.\n * @typedef {object} BlanketOverlayOptions\n * @property {number} [padding=0.1] How much to extend the clip area around the map\n * view (relative to its size) e.g. 0.1 would be 10% of map view in each direction.\n * @property {boolean} [continuous=false] When `false`, the blanket will update its\n * position only when the map state settles (*after* a pan/zoom animation). When\n * `true`, it will update when the map state changes (*during* pan/zoom animations).\n * @extends LayerOptions\n */\n\n/**\n * Represents an HTML element that covers (\"blankets\") the entire surface\n * of the map.\n *\n * Do not use this class directly. It's meant for `Renderer`, and for plugins\n * that rely on one single HTML element.\n *\n * Subclasses must define the following methods:\n *\n * * `_initContainer()` must initialize the HTML element to use as blanket, and store\n * it as `this._container`. The base implementation creates a blank `<div>`.\n * * `_destroyContainer()` must destroy the HTML element in `this._container` and free\n * any other resources. The base implementation destroys the element and removes\n * any event handlers attached to it.\n * * `_resizeContainer(): Point`: the base implementation resizes the container\n * (based on the map's size and taking into account the padding), returning the new\n * size in CSS pixels. Subclass implementations shall reset container parameters and\n * data structures as needed.\n * * `_onZoomEnd(ev?: PointerEvent)` (optional) runs on the map's `zoomend` event.\n * * `_onViewReset(ev?: PointerEvent)` (optional) runs on the map's `viewreset` event.\n * * `_onSettled()` runs whenever the map state settles after changing (at the end of\n * pan/zoom animations, etc). This should trigger the bulk of any rendering logic.\n * If the `continuous` option is set to `true`, then this also runs on any map\n * state change (including *during* pan/zoom animations).\n */\nexport class BlanketOverlay extends Layer {\n\n\tstatic {\n\t\
|
|
1
|
+
{"version":3,"file":"BlanketOverlay.js","names":["DomUtil.create"],"sources":["../../../src/layer/BlanketOverlay.js"],"sourcesContent":["import {Layer} from './Layer.js';\nimport * as DomUtil from '../dom/DomUtil.js';\nimport * as Util from '../core/Util.js';\nimport * as DomEvent from '../dom/DomEvent.js';\nimport {Bounds} from '../geometry/Bounds.js';\n/** @import {LayerOptions} from './Layer.js' */\n/** @import {MaplairMap} from '../map/Map.js' */\n/** @import {EventListener} from '../core/Events.js' */\n\n/**\n * Options of `BlanketOverlay`.\n * @typedef {object} BlanketOverlayOptions\n * @property {number} [padding=0.1] How much to extend the clip area around the map\n * view (relative to its size) e.g. 0.1 would be 10% of map view in each direction.\n * @property {boolean} [continuous=false] When `false`, the blanket will update its\n * position only when the map state settles (*after* a pan/zoom animation). When\n * `true`, it will update when the map state changes (*during* pan/zoom animations).\n * @extends LayerOptions\n */\n\n/**\n * Represents an HTML element that covers (\"blankets\") the entire surface\n * of the map.\n *\n * Do not use this class directly. It's meant for `Renderer`, and for plugins\n * that rely on one single HTML element.\n *\n * Subclasses must define the following methods:\n *\n * * `_initContainer()` must initialize the HTML element to use as blanket, and store\n * it as `this._container`. The base implementation creates a blank `<div>`.\n * * `_destroyContainer()` must destroy the HTML element in `this._container` and free\n * any other resources. The base implementation destroys the element and removes\n * any event handlers attached to it.\n * * `_resizeContainer(): Point`: the base implementation resizes the container\n * (based on the map's size and taking into account the padding), returning the new\n * size in CSS pixels. Subclass implementations shall reset container parameters and\n * data structures as needed.\n * * `_onZoomEnd(ev?: PointerEvent)` (optional) runs on the map's `zoomend` event.\n * * `_onViewReset(ev?: PointerEvent)` (optional) runs on the map's `viewreset` event.\n * * `_onSettled()` runs whenever the map state settles after changing (at the end of\n * pan/zoom animations, etc). This should trigger the bulk of any rendering logic.\n * If the `continuous` option is set to `true`, then this also runs on any map\n * state change (including *during* pan/zoom animations).\n */\nexport class BlanketOverlay extends Layer {\n\n\tstatic defaultOptions = {\n\t\tpadding: 0.1,\n\t\tcontinuous: false,\n\t};\n\n\t/**\n\t * @param {BlanketOverlayOptions} [options]\n\t */\n\tconstructor(options) {\n\t\tsuper();\n\t\tUtil.setOptions(this, options);\n\n\t\tthis.callInitHooks(BlanketOverlay);\n\t}\n\n\t/**\n\t * Adds the blanket to the map.\n\t * @type {(map: MaplairMap) => void}\n\t */\n\tonAdd() {\n\t\tif (!this._container) {\n\t\t\tthis._initContainer(); // defined by renderer implementations\n\n\t\t\t// always keep transform-origin as 0 0, #8794\n\t\t\tthis._container.classList.add('maplair-zoom-animated');\n\t\t}\n\n\t\tthis.getPane().appendChild(this._container);\n\t\tthis._resizeContainer();\n\t\tthis._onMoveEnd();\n\t}\n\n\t/**\n\t * Removes the blanket from the map.\n\t * @type {(map: MaplairMap) => void}\n\t */\n\tonRemove() {\n\t\tthis._destroyContainer();\n\t}\n\n\t/**\n\t * Returns the map events the blanket listens to.\n\t * @returns {Record<string, EventListener>}\n\t */\n\tgetEvents() {\n\t\tconst events = {\n\t\t\tviewreset: this._reset,\n\t\t\tzoom: this._onZoom,\n\t\t\tmoveend: this._onMoveEnd,\n\t\t\tresize: this._resizeContainer,\n\t\t\tzoomend: this._onZoomEnd,\n\t\t\tzoomanim: this._onAnimZoom\n\t\t};\n\t\tif (this.options.continuous) {\n\t\t\tevents.move = this._onMoveEnd;\n\t\t}\n\t\treturn events;\n\t}\n\n\t_onAnimZoom(ev) {\n\t\tthis._updateTransform(ev.center, ev.zoom);\n\t}\n\n\t_onZoom() {\n\t\tthis._updateTransform(this._map.getCenter(), this._map.getZoom());\n\t}\n\n\t_updateTransform(center, zoom) {\n\t\tconst scale = this._map.getZoomScale(zoom, this._zoom),\n\t\tviewHalf = this._map.getSize().multiplyBy(0.5 + this.options.padding),\n\t\tcurrentCenterPoint = this._map.project(this._center, zoom),\n\t\ttopLeftOffset = viewHalf.multiplyBy(-scale)._add(currentCenterPoint)\n\t\t\t._subtract(this._map._getNewPixelOrigin(center, zoom))\n\t\t\t._round();\n\n\t\tDomUtil.setTransform(this._container, topLeftOffset, scale);\n\t}\n\n\t_onMoveEnd(ev) {\n\t\t// Update pixel bounds of renderer container (for positioning/sizing/clipping later)\n\t\tconst p = this.options.padding,\n\t\tsize = this._map.getSize(),\n\t\tmin = this._map.containerPointToLayerPoint(size.multiplyBy(-p)).round();\n\n\t\tthis._bounds = new Bounds(min, min.add(size.multiplyBy(1 + p * 2)).round());\n\n\t\tthis._center = this._map.getCenter();\n\t\tthis._zoom = this._map.getZoom();\n\t\tthis._updateTransform(this._center, this._zoom);\n\n\t\tthis._onSettled(ev);\n\t}\n\n\t_reset() {\n\t\tthis._onSettled();\n\t\tthis._updateTransform(this._center, this._zoom);\n\t\tthis._onViewReset();\n\t}\n\n\t// Subclass interface, see the class description.\n\t_initContainer() {\n\t\tthis._container = DomUtil.create('div');\n\t}\n\t_destroyContainer() {\n\t\tDomEvent.off(this._container);\n\t\tthis._container.remove();\n\t\tdelete this._container;\n\t}\n\t_resizeContainer() {\n\t\tconst p = this.options.padding,\n\t\tsize = this._map.getSize().multiplyBy(1 + p * 2).round();\n\t\tthis._container.style.width = `${size.x}px`;\n\t\tthis._container.style.height = `${size.y}px`;\n\t\treturn size;\n\t}\n\t_onZoomEnd() {}\n\t_onViewReset() {}\n\t_onSettled() {}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6CA,IAAa,iBAAb,MAAa,uBAAuB,MAAM;CAEzC,OAAO,iBAAiB;EACvB,SAAS;EACT,YAAY;CACb;;;;CAKA,YAAY,SAAS;EACpB,MAAM;EACN,WAAgB,MAAM,OAAO;EAE7B,KAAK,cAAc,cAAc;CAClC;;;;;CAMA,QAAQ;EACP,IAAI,CAAC,KAAK,YAAY;GACrB,KAAK,eAAe;GAGpB,KAAK,WAAW,UAAU,IAAI,uBAAuB;EACtD;EAEA,KAAK,QAAQ,CAAC,CAAC,YAAY,KAAK,UAAU;EAC1C,KAAK,iBAAiB;EACtB,KAAK,WAAW;CACjB;;;;;CAMA,WAAW;EACV,KAAK,kBAAkB;CACxB;;;;;CAMA,YAAY;EACX,MAAM,SAAS;GACd,WAAW,KAAK;GAChB,MAAM,KAAK;GACX,SAAS,KAAK;GACd,QAAQ,KAAK;GACb,SAAS,KAAK;GACd,UAAU,KAAK;EAChB;EACA,IAAI,KAAK,QAAQ,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B,OAAO,KAAK;CACb;CACA,mBAAmB;EAClB,MAAM,IAAI,KAAK,QAAQ,SACvB,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,WAAW,IAAI,IAAI,CAAC,CAAC,CAAC,MAAM;EACvD,KAAK,WAAW,MAAM,QAAQ,GAAG,KAAK,EAAE;EACxC,KAAK,WAAW,MAAM,SAAS,GAAG,KAAK,EAAE;EACzC,OAAO;CACR;CACA,aAAa,CAAC;CACd,eAAe,CAAC;CAChB,aAAa,CAAC;AACf"}
|
|
@@ -68,16 +68,14 @@ const layerDivOverlayMethods = { _initOverlay(OverlayClass, old, content, option
|
|
|
68
68
|
* @fires contentupdate {MaplairEvent} Fired when the content of the overlay is updated.
|
|
69
69
|
*/
|
|
70
70
|
var DivOverlay = class DivOverlay extends Layer {
|
|
71
|
-
static {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
});
|
|
80
|
-
}
|
|
71
|
+
static defaultOptions = {
|
|
72
|
+
interactive: false,
|
|
73
|
+
offset: [0, 0],
|
|
74
|
+
className: "",
|
|
75
|
+
pane: void 0,
|
|
76
|
+
overflow: false,
|
|
77
|
+
content: ""
|
|
78
|
+
};
|
|
81
79
|
/**
|
|
82
80
|
* Instantiates an overlay given an optional `options` object that describes its
|
|
83
81
|
* appearance and location and an optional `source` object that is used to tag the
|
|
@@ -152,9 +150,8 @@ var DivOverlay = class DivOverlay extends Layer {
|
|
|
152
150
|
* @param {MaplairMap} map
|
|
153
151
|
*/
|
|
154
152
|
onAdd(map) {
|
|
155
|
-
this._zoomAnimated = map._zoomAnimated;
|
|
156
153
|
if (!this._container) this._initLayout();
|
|
157
|
-
if (map._fadeAnimated) this._container.style.opacity = 0;
|
|
154
|
+
if (map._fadeAnimated) this._container.style.opacity = "0";
|
|
158
155
|
clearTimeout(this._removeTimeout);
|
|
159
156
|
this.getPane().appendChild(this._container);
|
|
160
157
|
if (this.options.overflow) {
|
|
@@ -169,7 +166,7 @@ var DivOverlay = class DivOverlay extends Layer {
|
|
|
169
166
|
window.addEventListener("resize", this._onPageChange, { passive: true });
|
|
170
167
|
}
|
|
171
168
|
this.update();
|
|
172
|
-
if (map._fadeAnimated) this._container.style.opacity = 1;
|
|
169
|
+
if (map._fadeAnimated) this._container.style.opacity = "1";
|
|
173
170
|
if (!this.options.overflow) this.bringToFront();
|
|
174
171
|
if (this.options.interactive) {
|
|
175
172
|
this._container.classList.add("maplair-interactive");
|
|
@@ -186,7 +183,7 @@ var DivOverlay = class DivOverlay extends Layer {
|
|
|
186
183
|
window.removeEventListener("resize", this._onPageChange);
|
|
187
184
|
}
|
|
188
185
|
if (map._fadeAnimated) {
|
|
189
|
-
this._container.style.opacity = 0;
|
|
186
|
+
this._container.style.opacity = "0";
|
|
190
187
|
this._removeTimeout = setTimeout(() => this._container.remove(), 200);
|
|
191
188
|
} else this._container.remove();
|
|
192
189
|
if (this.options.interactive) {
|
|
@@ -268,9 +265,9 @@ var DivOverlay = class DivOverlay extends Layer {
|
|
|
268
265
|
getEvents() {
|
|
269
266
|
const events = {
|
|
270
267
|
zoom: this._updatePosition,
|
|
271
|
-
viewreset: this._updatePosition
|
|
268
|
+
viewreset: this._updatePosition,
|
|
269
|
+
zoomanim: this._animateZoom
|
|
272
270
|
};
|
|
273
|
-
if (this._zoomAnimated) events.zoomanim = this._animateZoom;
|
|
274
271
|
if (this.options.overflow) events.move = this._updatePosition;
|
|
275
272
|
return events;
|
|
276
273
|
}
|
|
@@ -346,10 +343,8 @@ var DivOverlay = class DivOverlay extends Layer {
|
|
|
346
343
|
}
|
|
347
344
|
_updatePosition() {
|
|
348
345
|
if (!this._map) return;
|
|
349
|
-
const pos = this._map.latLngToLayerPoint(this._latlng),
|
|
350
|
-
|
|
351
|
-
if (this._zoomAnimated || this.options.overflow) this._setContainerPosition(pos.add(anchor));
|
|
352
|
-
else offset = offset.add(pos).add(anchor);
|
|
346
|
+
const pos = this._map.latLngToLayerPoint(this._latlng), offset = Point.from(this.options.offset);
|
|
347
|
+
this._setContainerPosition(pos.add(this._getAnchor()));
|
|
353
348
|
const bottom = this._containerBottom = -offset.y, left = this._containerLeft = -Math.round(this._containerWidth / 2) + offset.x;
|
|
354
349
|
if (this.options.overflow) {
|
|
355
350
|
this._container.style.top = "auto";
|