maplair 4.1.0 → 4.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +60 -0
- package/dist/esm/Maplair.js +5 -4
- package/dist/esm/Maplair.js.map +1 -1
- package/dist/esm/_virtual/_rolldown/runtime.js +1 -2
- package/dist/esm/control/AttributionControl.js +1 -2
- package/dist/esm/control/ButtonControl.js +1 -2
- package/dist/esm/control/ContextMenu.js +1 -2
- package/dist/esm/control/Control.js +1 -2
- package/dist/esm/control/FullscreenControl.js +1 -2
- package/dist/esm/control/LayersControl.js +27 -31
- package/dist/esm/control/LayersControl.js.map +1 -1
- package/dist/esm/control/LegendControl.js +1 -2
- package/dist/esm/control/MiniMapControl.js +1 -2
- package/dist/esm/control/RotateControl.js +1 -2
- package/dist/esm/control/ScaleControl.js +1 -2
- package/dist/esm/control/SearchControl.js +1 -2
- package/dist/esm/control/SideBySideControl.js +1 -2
- package/dist/esm/control/TextControl.js +1 -2
- package/dist/esm/control/TimeControl.js +1 -2
- package/dist/esm/control/ZoomControl.js +18 -29
- package/dist/esm/control/ZoomControl.js.map +1 -1
- package/dist/esm/core/Class.js +2 -9
- package/dist/esm/core/Class.js.map +1 -1
- package/dist/esm/core/Events.js +1 -2
- package/dist/esm/core/Handler.js +10 -3
- package/dist/esm/core/Handler.js.map +1 -1
- package/dist/esm/core/I18n.js +1 -2
- package/dist/esm/core/Util.js +2 -3
- package/dist/esm/core/Util.js.map +1 -1
- package/dist/esm/dom/DomEvent.DoubleTap.js +1 -2
- package/dist/esm/dom/DomEvent.PointerEvents.js +1 -2
- package/dist/esm/dom/DomEvent.js +10 -18
- package/dist/esm/dom/DomEvent.js.map +1 -1
- package/dist/esm/dom/DomUtil.js +1 -2
- package/dist/esm/dom/Draggable.js +4 -3
- package/dist/esm/dom/Draggable.js.map +1 -1
- package/dist/esm/dom/PosAnimation.js +1 -2
- package/dist/esm/geo/LatLng.js +1 -2
- package/dist/esm/geo/LatLngBounds.js +9 -15
- package/dist/esm/geo/LatLngBounds.js.map +1 -1
- package/dist/esm/geo/crs/CRS.js +1 -2
- package/dist/esm/geo/crs/EPSG3395.js +4 -5
- package/dist/esm/geo/crs/EPSG3395.js.map +1 -1
- package/dist/esm/geo/crs/EPSG3857.js +4 -5
- package/dist/esm/geo/crs/EPSG3857.js.map +1 -1
- package/dist/esm/geo/crs/EPSG4326.js +3 -4
- package/dist/esm/geo/crs/EPSG4326.js.map +1 -1
- package/dist/esm/geo/crs/EarthCRS.js +1 -2
- package/dist/esm/geo/crs/SimpleCRS.js +3 -4
- package/dist/esm/geo/crs/SimpleCRS.js.map +1 -1
- package/dist/esm/geo/projection/{Projection.LonLat.js → LonLatProjection.js} +4 -5
- package/dist/esm/geo/projection/LonLatProjection.js.map +1 -0
- package/dist/esm/geo/projection/{Projection.Mercator.js → MercatorProjection.js} +3 -4
- package/dist/esm/geo/projection/MercatorProjection.js.map +1 -0
- package/dist/esm/geo/projection/{Projection.SphericalMercator.js → SphericalMercatorProjection.js} +4 -5
- package/dist/esm/geo/projection/SphericalMercatorProjection.js.map +1 -0
- package/dist/esm/geometry/Bounds.js +10 -14
- package/dist/esm/geometry/Bounds.js.map +1 -1
- package/dist/esm/geometry/LineUtil.js +2 -3
- package/dist/esm/geometry/LineUtil.js.map +1 -1
- package/dist/esm/geometry/Point.js +1 -2
- package/dist/esm/geometry/PolyUtil.js +17 -25
- package/dist/esm/geometry/PolyUtil.js.map +1 -1
- package/dist/esm/geometry/Transformation.js +1 -2
- package/dist/esm/layer/BlanketOverlay.js +1 -2
- package/dist/esm/layer/Classification.js +1 -2
- package/dist/esm/layer/DivOverlay.js +2 -3
- package/dist/esm/layer/DivOverlay.js.map +1 -1
- package/dist/esm/layer/FeatureGroup.js +5 -4
- package/dist/esm/layer/FeatureGroup.js.map +1 -1
- package/dist/esm/layer/GeoJSON.Load.js +1 -2
- package/dist/esm/layer/GeoJSON.js +8 -10
- package/dist/esm/layer/GeoJSON.js.map +1 -1
- package/dist/esm/layer/GeoJSONUtil.js +1 -2
- package/dist/esm/layer/HeatLayer.js +2 -3
- package/dist/esm/layer/HeatLayer.js.map +1 -1
- package/dist/esm/layer/ImageOverlay.js +2 -3
- package/dist/esm/layer/ImageOverlay.js.map +1 -1
- package/dist/esm/layer/Layer.js +1 -2
- package/dist/esm/layer/LayerGroup.js +2 -3
- package/dist/esm/layer/LayerGroup.js.map +1 -1
- package/dist/esm/layer/Popup.js +9 -16
- package/dist/esm/layer/Popup.js.map +1 -1
- package/dist/esm/layer/SVGOverlay.js +1 -2
- package/dist/esm/layer/Tooltip.js +16 -17
- package/dist/esm/layer/Tooltip.js.map +1 -1
- package/dist/esm/layer/VideoOverlay.js +1 -2
- package/dist/esm/layer/marker/DefaultIcon.js +29 -7
- package/dist/esm/layer/marker/DefaultIcon.js.map +1 -1
- package/dist/esm/layer/marker/DivIcon.js +1 -2
- package/dist/esm/layer/marker/Icon.js +2 -2
- package/dist/esm/layer/marker/Icon.js.map +1 -1
- package/dist/esm/layer/marker/Marker.Drag.js +43 -4
- package/dist/esm/layer/marker/Marker.Drag.js.map +1 -1
- package/dist/esm/layer/marker/Marker.Move.js +4 -6
- package/dist/esm/layer/marker/Marker.Move.js.map +1 -1
- package/dist/esm/layer/marker/Marker.js +54 -14
- package/dist/esm/layer/marker/Marker.js.map +1 -1
- package/dist/esm/layer/marker/MarkerClusterGroup.js +1 -2
- package/dist/esm/layer/marker/SvgIcon.js +1 -2
- package/dist/esm/layer/tile/GridLayer.js +4 -4
- package/dist/esm/layer/tile/GridLayer.js.map +1 -1
- package/dist/esm/layer/tile/TileLayer.js +8 -8
- package/dist/esm/layer/tile/TileLayer.js.map +1 -1
- package/dist/esm/layer/tile/WMSTileLayer.js +5 -4
- package/dist/esm/layer/tile/WMSTileLayer.js.map +1 -1
- package/dist/esm/layer/vector/Canvas.js +7 -14
- package/dist/esm/layer/vector/Canvas.js.map +1 -1
- package/dist/esm/layer/vector/Circle.js +4 -3
- package/dist/esm/layer/vector/Circle.js.map +1 -1
- package/dist/esm/layer/vector/CircleMarker.js +2 -3
- package/dist/esm/layer/vector/CircleMarker.js.map +1 -1
- package/dist/esm/layer/vector/Path.DashAnimation.js +1 -2
- package/dist/esm/layer/vector/Path.ZoomStyles.js +1 -2
- package/dist/esm/layer/vector/Path.js +1 -2
- package/dist/esm/layer/vector/Polygon.js +2 -3
- package/dist/esm/layer/vector/Polygon.js.map +1 -1
- package/dist/esm/layer/vector/Polyline.Decorations.js +1 -2
- package/dist/esm/layer/vector/Polyline.js +2 -3
- package/dist/esm/layer/vector/Polyline.js.map +1 -1
- package/dist/esm/layer/vector/Rectangle.js +1 -2
- package/dist/esm/layer/vector/Renderer.getRenderer.js +4 -5
- package/dist/esm/layer/vector/Renderer.getRenderer.js.map +1 -1
- package/dist/esm/layer/vector/Renderer.js +1 -2
- package/dist/esm/layer/vector/SVG.js +7 -4
- package/dist/esm/layer/vector/SVG.js.map +1 -1
- package/dist/esm/map/Hash.js +1 -2
- package/dist/esm/map/Map.Rotation.js +31 -16
- package/dist/esm/map/Map.Rotation.js.map +1 -1
- package/dist/esm/map/Map.js +10 -17
- package/dist/esm/map/Map.js.map +1 -1
- package/dist/esm/map/MapSync.js +1 -2
- package/dist/esm/map/handler/BoxZoomHandler.js +20 -40
- package/dist/esm/map/handler/BoxZoomHandler.js.map +1 -1
- package/dist/esm/map/handler/DisplaceHandler.js +1 -2
- package/dist/esm/map/handler/DoubleClickZoomHandler.js +1 -2
- package/dist/esm/map/handler/DragHandler.js +1 -2
- package/dist/esm/map/handler/KeyboardHandler.js +23 -43
- package/dist/esm/map/handler/KeyboardHandler.js.map +1 -1
- package/dist/esm/map/handler/PinchZoomHandler.js +1 -2
- package/dist/esm/map/handler/ScrollWheelZoomHandler.js +1 -2
- package/dist/esm/map/handler/TapDragZoomHandler.js +1 -2
- package/dist/esm/map/handler/TapHoldHandler.js +1 -2
- package/dist/esm/package.js +2 -3
- package/dist/maplair-global-src.js +487 -613
- 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 +483 -609
- package/dist/maplair-src.js.map +1 -1
- package/dist/maplair.css +1 -1263
- package/dist/maplair.js +2 -2
- package/dist/maplair.js.map +1 -1
- package/package.json +3 -8
- package/src/Maplair.all.js +0 -1
- package/src/control/LayersControl.js +39 -52
- package/src/control/ZoomControl.js +17 -31
- package/src/core/Class.js +5 -14
- package/src/core/Handler.js +11 -1
- package/src/core/Util.js +1 -1
- package/src/dom/DomEvent.js +9 -19
- package/src/dom/Draggable.js +5 -1
- package/src/geo/LatLngBounds.js +8 -15
- package/src/geo/crs/EPSG3395.js +3 -3
- package/src/geo/crs/EPSG3857.js +3 -3
- package/src/geo/crs/EPSG4326.js +2 -2
- package/src/geo/crs/SimpleCRS.js +2 -2
- package/src/geo/index.js +1 -2
- package/src/geo/projection/{Projection.LonLat.js → LonLatProjection.js} +1 -1
- package/src/geo/projection/{Projection.Mercator.js → MercatorProjection.js} +1 -1
- package/src/geo/projection/{Projection.SphericalMercator.js → SphericalMercatorProjection.js} +1 -1
- package/src/geo/projection/index.js +5 -5
- package/src/geometry/Bounds.js +12 -17
- package/src/geometry/LineUtil.js +1 -1
- package/src/geometry/PolyUtil.js +23 -31
- package/src/layer/DivOverlay.js +1 -1
- package/src/layer/FeatureGroup.js +8 -2
- package/src/layer/GeoJSON.js +10 -13
- package/src/layer/HeatLayer.js +1 -1
- package/src/layer/ImageOverlay.js +2 -2
- package/src/layer/LayerGroup.js +1 -1
- package/src/layer/Popup.js +9 -19
- package/src/layer/Tooltip.js +19 -17
- package/src/layer/marker/DefaultIcon.js +33 -5
- package/src/layer/marker/Icon.js +2 -0
- package/src/layer/marker/Marker.Drag.js +53 -5
- package/src/layer/marker/Marker.Move.js +3 -4
- package/src/layer/marker/Marker.js +64 -13
- package/src/layer/tile/GridLayer.js +5 -2
- package/src/layer/tile/TileLayer.js +9 -6
- package/src/layer/tile/WMSTileLayer.js +5 -2
- package/src/layer/vector/Canvas.js +10 -14
- package/src/layer/vector/Circle.js +4 -1
- package/src/layer/vector/CircleMarker.js +2 -1
- package/src/layer/vector/Polygon.js +1 -1
- package/src/layer/vector/Polyline.js +1 -1
- package/src/layer/vector/Renderer.getRenderer.js +4 -3
- package/src/layer/vector/SVG.js +12 -2
- package/src/map/Map.Rotation.js +28 -4
- package/src/map/Map.js +17 -21
- package/src/map/handler/BoxZoomHandler.js +21 -42
- package/src/map/handler/KeyboardHandler.js +34 -53
- package/src/maplair.css +5 -0
- package/dist/esm/geo/projection/Projection.LonLat.js.map +0 -1
- package/dist/esm/geo/projection/Projection.Mercator.js.map +0 -1
- package/dist/esm/geo/projection/Projection.SphericalMercator.js.map +0 -1
- package/dist/esm/geo/projection/index.js +0 -14
- package/dist/esm/geo/projection/index.js.map +0 -1
- package/dist/esm/layer/marker/Marker.Rotation.js +0 -70
- package/dist/esm/layer/marker/Marker.Rotation.js.map +0 -1
- package/src/layer/marker/Marker.Rotation.js +0 -103
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { __exportAll } from "../_virtual/_rolldown/runtime.js";
|
|
2
2
|
import { Point } from "./Point.js";
|
|
3
3
|
import { LatLng } from "../geo/LatLng.js";
|
|
4
|
-
|
|
4
|
+
// src/geometry/LineUtil.js
|
|
5
5
|
var LineUtil_exports = /* @__PURE__ */ __exportAll({
|
|
6
6
|
_getBitCode: () => _getBitCode,
|
|
7
7
|
_getEdgeIntersection: () => _getEdgeIntersection,
|
|
@@ -220,11 +220,10 @@ function _projectRing(latlngs, crs) {
|
|
|
220
220
|
if (!latlngs || latlngs.length === 0) throw new Error("latlngs not passed");
|
|
221
221
|
if (!isFlat(latlngs)) {
|
|
222
222
|
console.warn("latlngs are not flat! Only the first ring will be used");
|
|
223
|
-
|
|
223
|
+
return _projectRing(latlngs[0], crs);
|
|
224
224
|
}
|
|
225
225
|
return latlngs.map((latlng) => crs.project(LatLng.from(latlng)));
|
|
226
226
|
}
|
|
227
|
-
//#endregion
|
|
228
227
|
export { LineUtil_exports, _getBitCode, _getEdgeIntersection, _projectRing, _sqClosestPointOnSegment, clipSegment, closestPointOnSegment, isFlat, pointToSegmentDistance, polylineCenter, simplify };
|
|
229
228
|
|
|
230
229
|
//# 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';\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;C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S,KAAK;CAC5C,MAAM,SAAS,aAAa,SAAS,GAAG,GACxC,MAAM,OAAO;CAEb,IAAI,WAAW;CACf,KAAK,IAAI,IAAI,GAAG,IAAI,KAAK,KACxB,YAAY,OAAO,IAAI,EAAE,CAAC,WAAW,OAAO,EAAE;CAE/C,YAAY;CAGZ,IAAI,SAAS,OAAO;CAEpB,KAAK,IAAI,IAAI,GAAG,OAAO,GAAG,IAAI,KAAK,KAAK;EACvC,MAAM,KAAK,OAAO,IAAI,IACtB,KAAK,OAAO,IACZ,UAAU,GAAG,WAAW,EAAE;EAC1B,QAAQ;EAER,IAAI,OAAO,UAAU;GACpB,MAAM,SAAS,OAAO,YAAY;GAClC,SAAS,IAAI,MACZ,GAAG,IAAI,SAAS,GAAG,IAAI,GAAG,IAC1B,GAAG,IAAI,SAAS,GAAG,IAAI,GAAG,EAC3B;GACA;EACD;CACD;CAEA,OAAO,IAAI,UAAU,MAAM;AAC5B;;;;;;;;AASA,SAAgB,aAAa,SAAS,KAAK;CAC1C,IAAI,CAAC,WAAW,QAAQ,WAAW,GAClC,MAAM,IAAI,MAAM,oBAAoB;CAGrC,IAAI,CAAC,OAAO,OAAO,GAAG;EACrB,QAAQ,KAAK,wDAAwD;EACrE,UAAU,QAAQ;CACnB;CAEA,OAAO,QAAQ,KAAI,WAAU,IAAI,QAAQ,OAAO,KAAK,MAAM,CAAC,CAAC;AAC9D"}
|
|
1
|
+
{"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\treturn _projectRing(latlngs[0], crs);\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,IAAI,KAAK,KACpB,IAAI,QAAQ,IACX,UAAU,KAAK,OAAO,EAAE;CAI1B,OAAO;AACR;AAEA,SAAS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;;;;;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,OAAO,aAAa,QAAQ,IAAI,GAAG;CACpC;CAEA,OAAO,QAAQ,KAAI,WAAU,IAAI,QAAQ,OAAO,KAAK,MAAM,CAAC,CAAC;AAC9D"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { formatNum } from "../core/Util.js";
|
|
2
|
-
|
|
2
|
+
// src/geometry/Point.js
|
|
3
3
|
/**
|
|
4
4
|
* A point in pixels: a `Point`, an array of the form `[x, y]`, or a plain object of
|
|
5
5
|
* the form `{x, y}`. Accepted by all Maplair methods and options which accept `Point`
|
|
@@ -252,7 +252,6 @@ var Point = class Point {
|
|
|
252
252
|
return `Point(${formatNum(this.x)}, ${formatNum(this.y)})`;
|
|
253
253
|
}
|
|
254
254
|
};
|
|
255
|
-
//#endregion
|
|
256
255
|
export { Point };
|
|
257
256
|
|
|
258
257
|
//# sourceMappingURL=Point.js.map
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { __exportAll } from "../_virtual/_rolldown/runtime.js";
|
|
2
2
|
import { Point } from "./Point.js";
|
|
3
3
|
import { LatLng } from "../geo/LatLng.js";
|
|
4
|
-
import {
|
|
5
|
-
|
|
4
|
+
import { _getEdgeIntersection, _projectRing } from "./LineUtil.js";
|
|
5
|
+
// src/geometry/PolyUtil.js
|
|
6
6
|
var PolyUtil_exports = /* @__PURE__ */ __exportAll({
|
|
7
7
|
centroid: () => centroid,
|
|
8
8
|
clipPolygon: () => clipPolygon,
|
|
@@ -23,37 +23,30 @@ var PolyUtil_exports = /* @__PURE__ */ __exportAll({
|
|
|
23
23
|
* @returns {Point[]}
|
|
24
24
|
*/
|
|
25
25
|
function clipPolygon(points, bounds, round) {
|
|
26
|
-
|
|
27
|
-
const edges = [
|
|
26
|
+
for (const edge of [
|
|
28
27
|
1,
|
|
29
28
|
4,
|
|
30
29
|
2,
|
|
31
30
|
8
|
|
32
|
-
]
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
for (
|
|
38
|
-
|
|
39
|
-
b
|
|
40
|
-
if (!(a
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
p._code = _getBitCode(p, bounds);
|
|
44
|
-
clippedPoints.push(p);
|
|
45
|
-
}
|
|
46
|
-
clippedPoints.push(a);
|
|
47
|
-
} else if (!(b._code & edge)) {
|
|
48
|
-
p = _getEdgeIntersection(b, a, edge, bounds, round);
|
|
49
|
-
p._code = _getBitCode(p, bounds);
|
|
50
|
-
clippedPoints.push(p);
|
|
51
|
-
}
|
|
31
|
+
]) {
|
|
32
|
+
if (!points.length) break;
|
|
33
|
+
/** @type {Point[]} */
|
|
34
|
+
const clippedPoints = [];
|
|
35
|
+
let b = points[points.length - 1], bOut = isOutside(b, edge, bounds);
|
|
36
|
+
for (const a of points) {
|
|
37
|
+
const aOut = isOutside(a, edge, bounds);
|
|
38
|
+
if (aOut !== bOut) clippedPoints.push(_getEdgeIntersection(b, a, edge, bounds, round));
|
|
39
|
+
if (!aOut) clippedPoints.push(a);
|
|
40
|
+
b = a;
|
|
41
|
+
bOut = aOut;
|
|
52
42
|
}
|
|
53
43
|
points = clippedPoints;
|
|
54
44
|
}
|
|
55
45
|
return points;
|
|
56
46
|
}
|
|
47
|
+
function isOutside(p, edge, bounds) {
|
|
48
|
+
return edge === 1 ? p.x < bounds.min.x : edge === 2 ? p.x > bounds.max.x : edge === 4 ? p.y < bounds.min.y : p.y > bounds.max.y;
|
|
49
|
+
}
|
|
57
50
|
/**
|
|
58
51
|
* Returns the center ([centroid](http://en.wikipedia.org/wiki/Centroid)) of the passed
|
|
59
52
|
* LatLngs (first ring) from a polygon.
|
|
@@ -90,7 +83,6 @@ function centroid(coords) {
|
|
|
90
83
|
}
|
|
91
84
|
return new LatLng([latSum / len, lngSum / len]);
|
|
92
85
|
}
|
|
93
|
-
//#endregion
|
|
94
86
|
export { PolyUtil_exports, centroid, clipPolygon, polygonCenter };
|
|
95
87
|
|
|
96
88
|
//# sourceMappingURL=PolyUtil.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PolyUtil.js","names":["LineUtil.
|
|
1
|
+
{"version":3,"file":"PolyUtil.js","names":["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\t// left, bottom, right, top\n\tfor (const edge of [1, 4, 2, 8]) {\n\t\tif (!points.length) { break; }\n\n\t\t/** @type {Point[]} */\n\t\tconst clippedPoints = [];\n\t\tlet b = points[points.length - 1],\n\t\tbOut = isOutside(b, edge, bounds);\n\n\t\tfor (const a of points) {\n\t\t\tconst aOut = isOutside(a, edge, bounds);\n\t\t\t// a->b crosses the edge\n\t\t\tif (aOut !== bOut) {\n\t\t\t\tclippedPoints.push(LineUtil._getEdgeIntersection(b, a, edge, bounds, round));\n\t\t\t}\n\t\t\tif (!aOut) {\n\t\t\t\tclippedPoints.push(a);\n\t\t\t}\n\t\t\tb = a;\n\t\t\tbOut = aOut;\n\t\t}\n\t\tpoints = clippedPoints;\n\t}\n\n\treturn points;\n}\n\n// Whether the point is outside the given edge of the bounds; the edge is a `LineUtil` clipping bit code\nfunction isOutside(p, edge, bounds) {\n\treturn edge === 1 ? p.x < bounds.min.x :\n\t\tedge === 2 ? p.x > bounds.max.x :\n\t\tedge === 4 ? p.y < bounds.min.y : p.y > bounds.max.y;\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,YAA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,IAAI,OAAO,KAAK,IAAI,KAAK,CAAC,CAAC,KAAK,MAAM,CAAC;AAClG;;;;;;AAOA,SAAgB,SAAS,QAAQ;CAChC,IAAI,SAAS;CACb,IAAI,SAAS;CACb,IAAI,MAAM;CACV,KAAK,MAAM,SAAS,QAAQ;EAC3B,MAAM,SAAS,OAAO,KAAK,KAAK;EAChC,UAAU,OAAO;EACjB,UAAU,OAAO;EACjB;CACD;CACA,OAAO,IAAI,OAAO,CAAC,SAAS,KAAK,SAAS,GAAG,CAAC;AAC/C"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Point } from "./Point.js";
|
|
2
|
-
|
|
2
|
+
// src/geometry/Transformation.js
|
|
3
3
|
/**
|
|
4
4
|
* Represents an affine transformation: a set of coefficients `a`, `b`, `c`, `d`
|
|
5
5
|
* for transforming a point of a form `(x, y)` into `(a*x + b, c*y + d)` and doing
|
|
@@ -63,7 +63,6 @@ var Transformation = class {
|
|
|
63
63
|
return new Point((point.x / scale - this._b) / this._a, (point.y / scale - this._d) / this._c);
|
|
64
64
|
}
|
|
65
65
|
};
|
|
66
|
-
//#endregion
|
|
67
66
|
export { Transformation };
|
|
68
67
|
|
|
69
68
|
//# sourceMappingURL=Transformation.js.map
|
|
@@ -3,7 +3,7 @@ import { off } from "../dom/DomEvent.js";
|
|
|
3
3
|
import { create, setTransform } from "../dom/DomUtil.js";
|
|
4
4
|
import { Layer } from "./Layer.js";
|
|
5
5
|
import { Bounds } from "../geometry/Bounds.js";
|
|
6
|
-
|
|
6
|
+
// src/layer/BlanketOverlay.js
|
|
7
7
|
/** @import {LayerOptions} from './Layer.js' */
|
|
8
8
|
/** @import {MaplairMap} from '../map/Map.js' */
|
|
9
9
|
/** @import {EventListener} from '../core/Events.js' */
|
|
@@ -132,7 +132,6 @@ var BlanketOverlay = class BlanketOverlay extends Layer {
|
|
|
132
132
|
_onViewReset() {}
|
|
133
133
|
_onSettled() {}
|
|
134
134
|
};
|
|
135
|
-
//#endregion
|
|
136
135
|
export { BlanketOverlay };
|
|
137
136
|
|
|
138
137
|
//# sourceMappingURL=BlanketOverlay.js.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { I18n } from "../core/I18n.js";
|
|
2
|
-
|
|
2
|
+
// src/layer/Classification.js
|
|
3
3
|
/** @import {PathOptions} from './vector/Path.js' */
|
|
4
4
|
/**
|
|
5
5
|
* A class of a `Classification`, given by value or by range.
|
|
@@ -267,7 +267,6 @@ function rangesOf(breaks) {
|
|
|
267
267
|
return range;
|
|
268
268
|
});
|
|
269
269
|
}
|
|
270
|
-
//#endregion
|
|
271
270
|
export { Classification };
|
|
272
271
|
|
|
273
272
|
//# sourceMappingURL=Classification.js.map
|
|
@@ -4,7 +4,7 @@ import { setPosition, toBack, toFront } from "../dom/DomUtil.js";
|
|
|
4
4
|
import { Layer } from "./Layer.js";
|
|
5
5
|
import { LatLng } from "../geo/LatLng.js";
|
|
6
6
|
import { FeatureGroup } from "./FeatureGroup.js";
|
|
7
|
-
|
|
7
|
+
// src/layer/DivOverlay.js
|
|
8
8
|
/** @import {InteractiveLayerOptions} from './Layer.js' */
|
|
9
9
|
/** @import {LatLngExpression} from '../geo/LatLng.js' */
|
|
10
10
|
/** @import {PointExpression} from '../geometry/Point.js' */
|
|
@@ -343,7 +343,7 @@ var DivOverlay = class DivOverlay extends Layer {
|
|
|
343
343
|
}
|
|
344
344
|
_updatePosition() {
|
|
345
345
|
if (!this._map) return;
|
|
346
|
-
const pos = this._map.latLngToLayerPoint(this._latlng), offset = Point.from(this.options.offset);
|
|
346
|
+
const pos = this._map.latLngToLayerPoint(this._latlng)._round(), offset = Point.from(this.options.offset);
|
|
347
347
|
this._setContainerPosition(pos.add(this._getAnchor()));
|
|
348
348
|
const bottom = this._containerBottom = -offset.y, left = this._containerLeft = -Math.round(this._containerWidth / 2) + offset.x;
|
|
349
349
|
if (this.options.overflow) {
|
|
@@ -376,7 +376,6 @@ var DivOverlay = class DivOverlay extends Layer {
|
|
|
376
376
|
Layer.include(layerDivOverlayMethods);
|
|
377
377
|
}
|
|
378
378
|
};
|
|
379
|
-
//#endregion
|
|
380
379
|
export { DivOverlay };
|
|
381
380
|
|
|
382
381
|
//# sourceMappingURL=DivOverlay.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DivOverlay.js","names":[],"sources":["../../../src/layer/DivOverlay.js"],"sourcesContent":["import {Layer} from './Layer.js';\nimport {FeatureGroup} from './FeatureGroup.js';\nimport * as Util from '../core/Util.js';\nimport {LatLng} from '../geo/LatLng.js';\nimport {Point} from '../geometry/Point.js';\nimport * as DomUtil from '../dom/DomUtil.js';\n/** @import {InteractiveLayerOptions} from './Layer.js' */\n/** @import {LatLngExpression} from '../geo/LatLng.js' */\n/** @import {PointExpression} from '../geometry/Point.js' */\n/** @import {MaplairMap} from '../map/Map.js' */\n/** @import {EventListener, MaplairEvent} from '../core/Events.js' */\n\n/**\n * The content of a `DivOverlay` (`Popup`, `Tooltip`): a string rendered as HTML, an\n * `HTMLElement`, or a function receiving the source layer and returning one of them.\n * @typedef {string|HTMLElement|((layer: Layer) => string|HTMLElement)} DivOverlayContent\n */\n\n/**\n * Options of `DivOverlay`.\n * @typedef {object} DivOverlayOptions\n * @property {boolean} [interactive=false] If true, the popup/tooltip will listen to the\n * pointer events.\n * @property {PointExpression} [offset=[0, 0]] The offset of the overlay position.\n * @property {string} [className=''] A custom CSS class name to assign to the overlay.\n * @property {string} [pane] `Map pane` where the overlay will be added.\n * @property {boolean} [overflow=false] Whether the overlay may extend beyond the map\n * container, e.g. a tooltip of a marker near the edge of a small map. The overlay is\n * then shown as [popover](https://developer.mozilla.org/docs/Web/API/Popover_API) in\n * the top layer of the page, above all other content, while remaining in its map pane\n * in the DOM (for styling and events).\n * @property {DivOverlayContent} [content=''] Sets the HTML content of the overlay while\n * initializing. If a function is passed the source layer will be passed to the\n * function. The function should return a `String` or `HTMLElement` to be used in the\n * overlay. String content is rendered as HTML; sanitize untrusted input or pass an\n * `HTMLElement` with safe `textContent` instead.\n * @extends InteractiveLayerOptions\n */\n\n/**\n * Methods of `MaplairMap` for overlays.\n * @lends MaplairMap.prototype\n */\nconst mapDivOverlayMethods = {\n\t_initOverlay(OverlayClass, content, latlng, options) {\n\t\tlet overlay = content;\n\t\tif (!(overlay instanceof OverlayClass)) {\n\t\t\toverlay = new OverlayClass(options).setContent(content);\n\t\t}\n\t\tif (latlng) {\n\t\t\toverlay.setLatLng(latlng);\n\t\t}\n\t\treturn overlay;\n\t}\n};\n/** @typedef {typeof mapDivOverlayMethods} MapDivOverlayMethods */\n\n/**\n * Methods of `Layer` for overlays.\n * @lends Layer.prototype\n */\nconst layerDivOverlayMethods = {\n\t_initOverlay(OverlayClass, old, content, options) {\n\t\tlet overlay = content;\n\t\tif (overlay instanceof OverlayClass) {\n\t\t\tUtil.setOptions(overlay, options);\n\t\t\toverlay._source = this;\n\t\t} else {\n\t\t\toverlay = (old && !options) ? old : new OverlayClass(options, this);\n\t\t\toverlay.setContent(content);\n\t\t}\n\t\treturn overlay;\n\t}\n};\n/** @typedef {typeof layerDivOverlayMethods} LayerDivOverlayMethods */\n\n/**\n * Base model for Popup and Tooltip. Inherit from it for custom overlays like plugins.\n *\n * @fires contentupdate {MaplairEvent} Fired when the content of the overlay is updated.\n */\nexport class DivOverlay extends Layer {\n\n\tstatic defaultOptions = {\n\t\tinteractive: false,\n\t\toffset: [0, 0],\n\t\tclassName: '',\n\t\tpane: undefined,\n\t\toverflow: false,\n\t\tcontent: ''\n\t};\n\n\t/**\n\t * Instantiates an overlay given an optional `options` object that describes its\n\t * appearance and location and an optional `source` object that is used to tag the\n\t * overlay with a reference to the Layer to which it refers.\n\t * @overload\n\t * @param {DivOverlayOptions} [options]\n\t * @param {Layer} [source]\n\t */\n\t/**\n\t * Instantiates an overlay given `latlng` where the overlay will open and an\n\t * optional `options` object that describes its appearance and location.\n\t * @overload\n\t * @param {LatLngExpression} latlng\n\t * @param {DivOverlayOptions} [options]\n\t */\n\t/**\n\t * @param {DivOverlayOptions|LatLngExpression} [options]\n\t * @param {Layer|DivOverlayOptions} [source]\n\t */\n\tconstructor(options, source) {\n\t\tsuper();\n\t\tif (options instanceof LatLng || Array.isArray(options)) {\n\t\t\tthis._latlng = new LatLng(options);\n\t\t\tUtil.setOptions(this, source);\n\t\t} else {\n\t\t\tUtil.setOptions(this, options);\n\t\t\tthis._source = source;\n\t\t}\n\t\tif (this.options.content) {\n\t\t\tthis._content = this.options.content;\n\t\t}\n\n\t\tthis.callInitHooks(DivOverlay);\n\t}\n\n\t/**\n\t * Adds the overlay to the map.\n\t * Alternative to `map.openPopup(popup)`/`.openTooltip(tooltip)`.\n\t * @param {MaplairMap} map\n\t * @returns {this}\n\t */\n\topenOn(map) {\n\t\tmap = arguments.length ? map : this._source._map; // experimental, not the part of public api\n\t\tif (!map.hasLayer(this)) {\n\t\t\tmap.addLayer(this);\n\t\t}\n\t\treturn this;\n\t}\n\n\t/**\n\t * Closes the overlay.\n\t * Alternative to `map.closePopup(popup)`/`.closeTooltip(tooltip)`\n\t * and `layer.closePopup()`/`.closeTooltip()`.\n\t * @returns {this}\n\t */\n\tclose() {\n\t\tthis._map?.removeLayer(this);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Opens or closes the overlay bound to layer depending on its current state.\n\t * Argument may be omitted only for overlay bound to layer.\n\t * Alternative to `layer.togglePopup()`/`.toggleTooltip()`.\n\t * @param {Layer} [layer]\n\t * @returns {this}\n\t */\n\ttoggle(layer) {\n\t\tif (this._map) {\n\t\t\tthis.close();\n\t\t} else {\n\t\t\tif (arguments.length) {\n\t\t\t\tthis._source = layer;\n\t\t\t} else {\n\t\t\t\tlayer = this._source;\n\t\t\t}\n\t\t\tthis._prepareOpen();\n\n\t\t\t// open the overlay on the map\n\t\t\tthis.openOn(layer._map);\n\t\t}\n\t\treturn this;\n\t}\n\n\t/**\n\t * Adds the overlay to the map.\n\t * @param {MaplairMap} map\n\t */\n\tonAdd(map) {\n\t\tif (!this._container) {\n\t\t\tthis._initLayout();\n\t\t}\n\n\t\tif (map._fadeAnimated) {\n\t\t\tthis._container.style.opacity = '0';\n\t\t}\n\n\t\tclearTimeout(this._removeTimeout);\n\t\tthis.getPane().appendChild(this._container);\n\t\tif (this.options.overflow) {\n\t\t\tthis._container.classList.add('maplair-overflow');\n\t\t\tthis._container.popover = 'manual';\n\t\t\tthis._container.showPopover();\n\t\t\t// The map pane does not carry the overlay, it has to follow the page and the map\n\t\t\tthis._onPageChange ??= () => this._updatePosition();\n\t\t\tdocument.addEventListener('scroll', this._onPageChange, {capture: true, passive: true});\n\t\t\twindow.addEventListener('resize', this._onPageChange, {passive: true});\n\t\t}\n\t\tthis.update();\n\n\t\tif (map._fadeAnimated) {\n\t\t\tthis._container.style.opacity = '1';\n\t\t}\n\n\t\t// A popover is shown on top already, re-showing it would skip the fade animation\n\t\tif (!this.options.overflow) {\n\t\t\tthis.bringToFront();\n\t\t}\n\n\t\tif (this.options.interactive) {\n\t\t\tthis._container.classList.add('maplair-interactive');\n\t\t\tthis.addInteractiveTarget(this._container);\n\t\t}\n\t}\n\n\t/**\n\t * Removes the overlay from the map.\n\t * @param {MaplairMap} map\n\t */\n\tonRemove(map) {\n\t\tif (this.options.overflow) {\n\t\t\tdocument.removeEventListener('scroll', this._onPageChange, {capture: true});\n\t\t\twindow.removeEventListener('resize', this._onPageChange);\n\t\t}\n\n\t\tif (map._fadeAnimated) {\n\t\t\tthis._container.style.opacity = '0';\n\t\t\tthis._removeTimeout = setTimeout(() => this._container.remove(), 200);\n\t\t} else {\n\t\t\tthis._container.remove();\n\t\t}\n\n\t\tif (this.options.interactive) {\n\t\t\tthis._container.classList.remove('maplair-interactive');\n\t\t\tthis.removeInteractiveTarget(this._container);\n\t\t}\n\t}\n\n\t_updateInteractive() {\n\t\tthis._container.classList.toggle('maplair-interactive', this.options.interactive);\n\t\tif (this.options.interactive) {\n\t\t\tthis.addInteractiveTarget(this._container);\n\t\t} else {\n\t\t\tthis.removeInteractiveTarget(this._container);\n\t\t}\n\t}\n\n\t/**\n\t * Returns the geographical point of the overlay.\n\t * @returns {LatLng}\n\t */\n\tgetLatLng() {\n\t\treturn this._latlng;\n\t}\n\n\t/**\n\t * Sets the geographical point where the overlay will open.\n\t * @param {LatLngExpression} latlng\n\t * @returns {this}\n\t */\n\tsetLatLng(latlng) {\n\t\tthis._latlng = new LatLng(latlng);\n\t\tif (this._map) {\n\t\t\tthis._updatePosition();\n\t\t\tthis._adjustPan();\n\t\t}\n\t\treturn this;\n\t}\n\n\t/**\n\t * Returns the content of the overlay.\n\t * @returns {DivOverlayContent}\n\t */\n\tgetContent() {\n\t\treturn this._content;\n\t}\n\n\t/**\n\t * Sets the HTML content of the overlay. A `String` argument is rendered as\n\t * HTML; if it may contain untrusted input, sanitize it (e.g. with DOMPurify)\n\t * or pass an `HTMLElement` with safe `textContent` instead. If a function is\n\t * passed the source layer will be passed to the function. The function should\n\t * return a `String` or `HTMLElement` to be used in the overlay.\n\t * @param {DivOverlayContent} content\n\t * @returns {this}\n\t */\n\tsetContent(content) {\n\t\tthis._content = content;\n\t\tthis.update();\n\t\treturn this;\n\t}\n\n\t/**\n\t * Returns the HTML container of the overlay.\n\t * @returns {HTMLElement}\n\t */\n\tgetElement() {\n\t\treturn this._container;\n\t}\n\n\t/**\n\t * Updates the overlay content, layout and position. Useful for updating the\n\t * overlay after something inside changed, e.g. image loaded.\n\t * @returns {void}\n\t */\n\tupdate() {\n\t\tif (!this._map) { return; }\n\n\t\tthis._container.style.visibility = 'hidden';\n\n\t\tthis._updateContent();\n\t\tthis._updateLayout();\n\t\tthis._updatePosition();\n\n\t\tthis._container.style.visibility = '';\n\n\t\tthis._adjustPan();\n\t}\n\n\t/**\n\t * Returns the map events the overlay listens to.\n\t * @returns {Record<string, EventListener>}\n\t */\n\tgetEvents() {\n\t\tconst events = {\n\t\t\tzoom: this._updatePosition,\n\t\t\tviewreset: this._updatePosition,\n\t\t\tzoomanim: this._animateZoom\n\t\t};\n\n\t\tif (this.options.overflow) {\n\t\t\tevents.move = this._updatePosition;\n\t\t}\n\t\treturn events;\n\t}\n\n\t/**\n\t * Returns `true` when the overlay is visible on the map.\n\t * @returns {boolean}\n\t */\n\tisOpen() {\n\t\treturn !!this._map && this._map.hasLayer(this);\n\t}\n\n\t/**\n\t * Brings this overlay in front of other overlays (in the same map pane).\n\t * @returns {this}\n\t */\n\tbringToFront() {\n\t\tif (this._map) {\n\t\t\tDomUtil.toFront(this._container);\n\t\t\tthis._restackPopovers();\n\t\t}\n\t\treturn this;\n\t}\n\n\t/**\n\t * Brings this overlay to the back of other overlays (in the same map pane).\n\t * @returns {this}\n\t */\n\tbringToBack() {\n\t\tif (this._map) {\n\t\t\tDomUtil.toBack(this._container);\n\t\t\tthis._restackPopovers();\n\t\t}\n\t\treturn this;\n\t}\n\n\t// Popovers are stacked in the order they are shown, not in DOM order. Moving\n\t// a popover in the DOM hides it, so (re-)show the overflowing overlays of\n\t// the pane in DOM order.\n\t_restackPopovers() {\n\t\tif (!this.options.overflow) { return; }\n\t\tfor (const el of this.getPane().children) {\n\t\t\tif (!el.classList.contains('maplair-overflow')) { continue; }\n\t\t\tif (el.matches(':popover-open')) {\n\t\t\t\tel.hidePopover();\n\t\t\t}\n\t\t\tel.showPopover();\n\t\t}\n\t}\n\n\t// prepare bound overlay to open: update latlng pos / content source (for FeatureGroup)\n\t_prepareOpen(latlng) {\n\t\tlet source = this._source;\n\t\tif (!source._map) { return false; }\n\n\t\tif (source instanceof FeatureGroup) {\n\t\t\tsource = null;\n\t\t\tfor (const layer of Object.values(this._source._layers)) {\n\t\t\t\tif (layer._map) {\n\t\t\t\t\tsource = layer;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (!source) { return false; } // Unable to get source layer.\n\n\t\t\t// set overlay source to this layer\n\t\t\tthis._source = source;\n\t\t}\n\n\t\tif (!latlng) {\n\t\t\tif (source.getCenter) {\n\t\t\t\tlatlng = source.getCenter();\n\t\t\t} else if (source.getLatLng) {\n\t\t\t\tlatlng = source.getLatLng();\n\t\t\t} else if (source.getBounds) {\n\t\t\t\tlatlng = source.getBounds().getCenter();\n\t\t\t} else {\n\t\t\t\tthrow new Error('Unable to get source layer LatLng.');\n\t\t\t}\n\t\t}\n\t\tthis.setLatLng(latlng);\n\n\t\tif (this._map) {\n\t\t\t// update the overlay (content, layout, etc...)\n\t\t\tthis.update();\n\t\t}\n\n\t\treturn true;\n\t}\n\n\t_updateContent() {\n\t\tif (!this._content) { return; }\n\n\t\tconst node = this._contentNode;\n\t\tconst content = (typeof this._content === 'function') ? this._content(this._source ?? this) : this._content;\n\n\t\tif (typeof content === 'string') {\n\t\t\tnode.innerHTML = content;\n\t\t} else {\n\t\t\twhile (node.hasChildNodes()) {\n\t\t\t\tnode.removeChild(node.firstChild);\n\t\t\t}\n\t\t\tnode.appendChild(content);\n\t\t}\n\n\t\tthis.fire('contentupdate');\n\t}\n\n\t_updatePosition() {\n\t\tif (!this._map) { return; }\n\n\t\tconst pos = this._map.latLngToLayerPoint(this._latlng),\n\t\toffset = Point.from(this.options.offset);\n\n\t\tthis._setContainerPosition(pos.add(this._getAnchor()));\n\n\t\tconst bottom = this._containerBottom = -offset.y,\n\t\tleft = this._containerLeft = -Math.round(this._containerWidth / 2) + offset.x;\n\n\t\t// bottom position the overlay in case the height of the overlay changes (images loading etc)\n\t\tif (this.options.overflow) {\n\t\t\t// relative to the top of the viewport instead of the pane origin\n\t\t\tthis._container.style.top = 'auto';\n\t\t\tthis._container.style.bottom = `calc(100% + ${bottom}px)`;\n\t\t} else {\n\t\t\tthis._container.style.bottom = `${bottom}px`;\n\t\t}\n\t\tthis._container.style.left = `${left}px`;\n\t}\n\n\t// Positions the container at the given layer point. An overflowing overlay\n\t// lives in the top layer of the page, so it is positioned in viewport coordinates.\n\t_setContainerPosition(pos) {\n\t\tthis._containerPos = pos;\n\t\tif (this.options.overflow) {\n\t\t\tconst mapContainer = this._map._container,\n\t\t\trect = mapContainer.getBoundingClientRect();\n\t\t\tpos = this._map.layerPointToContainerPoint(pos)\n\t\t\t\t._add(new Point(rect.left + mapContainer.clientLeft, rect.top + mapContainer.clientTop));\n\t\t}\n\t\tDomUtil.setPosition(this._container, pos);\n\t}\n\n\t// Returns the layer point the container was positioned at, see `_setContainerPosition`.\n\t_getContainerPosition() {\n\t\treturn this._containerPos ?? new Point(0, 0);\n\t}\n\n\t_getAnchor() {\n\t\treturn [0, 0];\n\t}\n\n\t/**\n\t * Registers this default feature on the map class, called by `MaplairMap` itself.\n\t * @internal\n\t * @param {typeof MaplairMap} MaplairMap\n\t */\n\tstatic register(MaplairMap) {\n\t\tMaplairMap.include(mapDivOverlayMethods);\n\n\t\tLayer.include(layerDivOverlayMethods);\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2CA,MAAM,uBAAuB,EAC5B,aAAa,cAAc,SAAS,QAAQ,SAAS;CACpD,IAAI,UAAU;CACd,IAAI,EAAE,mBAAmB,eACxB,UAAU,IAAI,aAAa,OAAO,CAAC,CAAC,WAAW,OAAO;CAEvD,IAAI,QACH,QAAQ,UAAU,MAAM;CAEzB,OAAO;AACR,EACD;;;;;;AAOA,MAAM,yBAAyB,EAC9B,aAAa,cAAc,KAAK,SAAS,SAAS;CACjD,IAAI,UAAU;CACd,IAAI,mBAAmB,cAAc;EACpC,WAAgB,SAAS,OAAO;EAChC,QAAQ,UAAU;CACnB,OAAO;EACN,UAAW,OAAO,CAAC,UAAW,MAAM,IAAI,aAAa,SAAS,IAAI;EAClE,QAAQ,WAAW,OAAO;CAC3B;CACA,OAAO;AACR,EACD;;;;;;;AAQA,IAAa,aAAb,MAAa,mBAAmB,MAAM;CAErC,OAAO,iBAAiB;EACvB,aAAa;EACb,QAAQ,CAAC,GAAG,CAAC;EACb,WAAW;EACX,MAAM,KAAA;EACN,UAAU;EACV,SAAS;CACV;;;;;;;;;;;;;;;;;;;;CAqBA,YAAY,SAAS,QAA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AwB;EACvB,OAAO,KAAK,iBAAiB,IAAI,MAAM,GAAG,CAAC;CAC5C;CAEA,aAAa;EACZ,OAAO,CAAC,GAAG,CAAC;CACb;;;;;;CAOA,OAAO,SAAS,YAAY;EAC3B,WAAW,QAAQ,oBAAoB;EAEvC,MAAM,QAAQ,sBAAsB;CACrC;AACD"}
|
|
1
|
+
{"version":3,"file":"DivOverlay.js","names":[],"sources":["../../../src/layer/DivOverlay.js"],"sourcesContent":["import {Layer} from './Layer.js';\nimport {FeatureGroup} from './FeatureGroup.js';\nimport * as Util from '../core/Util.js';\nimport {LatLng} from '../geo/LatLng.js';\nimport {Point} from '../geometry/Point.js';\nimport * as DomUtil from '../dom/DomUtil.js';\n/** @import {InteractiveLayerOptions} from './Layer.js' */\n/** @import {LatLngExpression} from '../geo/LatLng.js' */\n/** @import {PointExpression} from '../geometry/Point.js' */\n/** @import {MaplairMap} from '../map/Map.js' */\n/** @import {EventListener, MaplairEvent} from '../core/Events.js' */\n\n/**\n * The content of a `DivOverlay` (`Popup`, `Tooltip`): a string rendered as HTML, an\n * `HTMLElement`, or a function receiving the source layer and returning one of them.\n * @typedef {string|HTMLElement|((layer: Layer) => string|HTMLElement)} DivOverlayContent\n */\n\n/**\n * Options of `DivOverlay`.\n * @typedef {object} DivOverlayOptions\n * @property {boolean} [interactive=false] If true, the popup/tooltip will listen to the\n * pointer events.\n * @property {PointExpression} [offset=[0, 0]] The offset of the overlay position.\n * @property {string} [className=''] A custom CSS class name to assign to the overlay.\n * @property {string} [pane] `Map pane` where the overlay will be added.\n * @property {boolean} [overflow=false] Whether the overlay may extend beyond the map\n * container, e.g. a tooltip of a marker near the edge of a small map. The overlay is\n * then shown as [popover](https://developer.mozilla.org/docs/Web/API/Popover_API) in\n * the top layer of the page, above all other content, while remaining in its map pane\n * in the DOM (for styling and events).\n * @property {DivOverlayContent} [content=''] Sets the HTML content of the overlay while\n * initializing. If a function is passed the source layer will be passed to the\n * function. The function should return a `String` or `HTMLElement` to be used in the\n * overlay. String content is rendered as HTML; sanitize untrusted input or pass an\n * `HTMLElement` with safe `textContent` instead.\n * @extends InteractiveLayerOptions\n */\n\n/**\n * Methods of `MaplairMap` for overlays.\n * @lends MaplairMap.prototype\n */\nconst mapDivOverlayMethods = {\n\t_initOverlay(OverlayClass, content, latlng, options) {\n\t\tlet overlay = content;\n\t\tif (!(overlay instanceof OverlayClass)) {\n\t\t\toverlay = new OverlayClass(options).setContent(content);\n\t\t}\n\t\tif (latlng) {\n\t\t\toverlay.setLatLng(latlng);\n\t\t}\n\t\treturn overlay;\n\t}\n};\n/** @typedef {typeof mapDivOverlayMethods} MapDivOverlayMethods */\n\n/**\n * Methods of `Layer` for overlays.\n * @lends Layer.prototype\n */\nconst layerDivOverlayMethods = {\n\t_initOverlay(OverlayClass, old, content, options) {\n\t\tlet overlay = content;\n\t\tif (overlay instanceof OverlayClass) {\n\t\t\tUtil.setOptions(overlay, options);\n\t\t\toverlay._source = this;\n\t\t} else {\n\t\t\toverlay = (old && !options) ? old : new OverlayClass(options, this);\n\t\t\toverlay.setContent(content);\n\t\t}\n\t\treturn overlay;\n\t}\n};\n/** @typedef {typeof layerDivOverlayMethods} LayerDivOverlayMethods */\n\n/**\n * Base model for Popup and Tooltip. Inherit from it for custom overlays like plugins.\n *\n * @fires contentupdate {MaplairEvent} Fired when the content of the overlay is updated.\n */\nexport class DivOverlay extends Layer {\n\n\tstatic defaultOptions = {\n\t\tinteractive: false,\n\t\toffset: [0, 0],\n\t\tclassName: '',\n\t\tpane: undefined,\n\t\toverflow: false,\n\t\tcontent: ''\n\t};\n\n\t/**\n\t * Instantiates an overlay given an optional `options` object that describes its\n\t * appearance and location and an optional `source` object that is used to tag the\n\t * overlay with a reference to the Layer to which it refers.\n\t * @overload\n\t * @param {DivOverlayOptions} [options]\n\t * @param {Layer} [source]\n\t */\n\t/**\n\t * Instantiates an overlay given `latlng` where the overlay will open and an\n\t * optional `options` object that describes its appearance and location.\n\t * @overload\n\t * @param {LatLngExpression} latlng\n\t * @param {DivOverlayOptions} [options]\n\t */\n\t/**\n\t * @param {DivOverlayOptions|LatLngExpression} [options]\n\t * @param {Layer|DivOverlayOptions} [source]\n\t */\n\tconstructor(options, source) {\n\t\tsuper();\n\t\tif (options instanceof LatLng || Array.isArray(options)) {\n\t\t\tthis._latlng = new LatLng(options);\n\t\t\tUtil.setOptions(this, source);\n\t\t} else {\n\t\t\tUtil.setOptions(this, options);\n\t\t\tthis._source = source;\n\t\t}\n\t\tif (this.options.content) {\n\t\t\tthis._content = this.options.content;\n\t\t}\n\n\t\tthis.callInitHooks(DivOverlay);\n\t}\n\n\t/**\n\t * Adds the overlay to the map.\n\t * Alternative to `map.openPopup(popup)`/`.openTooltip(tooltip)`.\n\t * @param {MaplairMap} map\n\t * @returns {this}\n\t */\n\topenOn(map) {\n\t\tmap = arguments.length ? map : this._source._map; // experimental, not the part of public api\n\t\tif (!map.hasLayer(this)) {\n\t\t\tmap.addLayer(this);\n\t\t}\n\t\treturn this;\n\t}\n\n\t/**\n\t * Closes the overlay.\n\t * Alternative to `map.closePopup(popup)`/`.closeTooltip(tooltip)`\n\t * and `layer.closePopup()`/`.closeTooltip()`.\n\t * @returns {this}\n\t */\n\tclose() {\n\t\tthis._map?.removeLayer(this);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Opens or closes the overlay bound to layer depending on its current state.\n\t * Argument may be omitted only for overlay bound to layer.\n\t * Alternative to `layer.togglePopup()`/`.toggleTooltip()`.\n\t * @param {Layer} [layer]\n\t * @returns {this}\n\t */\n\ttoggle(layer) {\n\t\tif (this._map) {\n\t\t\tthis.close();\n\t\t} else {\n\t\t\tif (arguments.length) {\n\t\t\t\tthis._source = layer;\n\t\t\t} else {\n\t\t\t\tlayer = this._source;\n\t\t\t}\n\t\t\tthis._prepareOpen();\n\n\t\t\t// open the overlay on the map\n\t\t\tthis.openOn(layer._map);\n\t\t}\n\t\treturn this;\n\t}\n\n\t/**\n\t * Adds the overlay to the map.\n\t * @param {MaplairMap} map\n\t */\n\tonAdd(map) {\n\t\tif (!this._container) {\n\t\t\tthis._initLayout();\n\t\t}\n\n\t\tif (map._fadeAnimated) {\n\t\t\tthis._container.style.opacity = '0';\n\t\t}\n\n\t\tclearTimeout(this._removeTimeout);\n\t\tthis.getPane().appendChild(this._container);\n\t\tif (this.options.overflow) {\n\t\t\tthis._container.classList.add('maplair-overflow');\n\t\t\tthis._container.popover = 'manual';\n\t\t\tthis._container.showPopover();\n\t\t\t// The map pane does not carry the overlay, it has to follow the page and the map\n\t\t\tthis._onPageChange ??= () => this._updatePosition();\n\t\t\tdocument.addEventListener('scroll', this._onPageChange, {capture: true, passive: true});\n\t\t\twindow.addEventListener('resize', this._onPageChange, {passive: true});\n\t\t}\n\t\tthis.update();\n\n\t\tif (map._fadeAnimated) {\n\t\t\tthis._container.style.opacity = '1';\n\t\t}\n\n\t\t// A popover is shown on top already, re-showing it would skip the fade animation\n\t\tif (!this.options.overflow) {\n\t\t\tthis.bringToFront();\n\t\t}\n\n\t\tif (this.options.interactive) {\n\t\t\tthis._container.classList.add('maplair-interactive');\n\t\t\tthis.addInteractiveTarget(this._container);\n\t\t}\n\t}\n\n\t/**\n\t * Removes the overlay from the map.\n\t * @param {MaplairMap} map\n\t */\n\tonRemove(map) {\n\t\tif (this.options.overflow) {\n\t\t\tdocument.removeEventListener('scroll', this._onPageChange, {capture: true});\n\t\t\twindow.removeEventListener('resize', this._onPageChange);\n\t\t}\n\n\t\tif (map._fadeAnimated) {\n\t\t\tthis._container.style.opacity = '0';\n\t\t\tthis._removeTimeout = setTimeout(() => this._container.remove(), 200);\n\t\t} else {\n\t\t\tthis._container.remove();\n\t\t}\n\n\t\tif (this.options.interactive) {\n\t\t\tthis._container.classList.remove('maplair-interactive');\n\t\t\tthis.removeInteractiveTarget(this._container);\n\t\t}\n\t}\n\n\t_updateInteractive() {\n\t\tthis._container.classList.toggle('maplair-interactive', this.options.interactive);\n\t\tif (this.options.interactive) {\n\t\t\tthis.addInteractiveTarget(this._container);\n\t\t} else {\n\t\t\tthis.removeInteractiveTarget(this._container);\n\t\t}\n\t}\n\n\t/**\n\t * Returns the geographical point of the overlay.\n\t * @returns {LatLng}\n\t */\n\tgetLatLng() {\n\t\treturn this._latlng;\n\t}\n\n\t/**\n\t * Sets the geographical point where the overlay will open.\n\t * @param {LatLngExpression} latlng\n\t * @returns {this}\n\t */\n\tsetLatLng(latlng) {\n\t\tthis._latlng = new LatLng(latlng);\n\t\tif (this._map) {\n\t\t\tthis._updatePosition();\n\t\t\tthis._adjustPan();\n\t\t}\n\t\treturn this;\n\t}\n\n\t/**\n\t * Returns the content of the overlay.\n\t * @returns {DivOverlayContent}\n\t */\n\tgetContent() {\n\t\treturn this._content;\n\t}\n\n\t/**\n\t * Sets the HTML content of the overlay. A `String` argument is rendered as\n\t * HTML; if it may contain untrusted input, sanitize it (e.g. with DOMPurify)\n\t * or pass an `HTMLElement` with safe `textContent` instead. If a function is\n\t * passed the source layer will be passed to the function. The function should\n\t * return a `String` or `HTMLElement` to be used in the overlay.\n\t * @param {DivOverlayContent} content\n\t * @returns {this}\n\t */\n\tsetContent(content) {\n\t\tthis._content = content;\n\t\tthis.update();\n\t\treturn this;\n\t}\n\n\t/**\n\t * Returns the HTML container of the overlay.\n\t * @returns {HTMLElement}\n\t */\n\tgetElement() {\n\t\treturn this._container;\n\t}\n\n\t/**\n\t * Updates the overlay content, layout and position. Useful for updating the\n\t * overlay after something inside changed, e.g. image loaded.\n\t * @returns {void}\n\t */\n\tupdate() {\n\t\tif (!this._map) { return; }\n\n\t\tthis._container.style.visibility = 'hidden';\n\n\t\tthis._updateContent();\n\t\tthis._updateLayout();\n\t\tthis._updatePosition();\n\n\t\tthis._container.style.visibility = '';\n\n\t\tthis._adjustPan();\n\t}\n\n\t/**\n\t * Returns the map events the overlay listens to.\n\t * @returns {Record<string, EventListener>}\n\t */\n\tgetEvents() {\n\t\tconst events = {\n\t\t\tzoom: this._updatePosition,\n\t\t\tviewreset: this._updatePosition,\n\t\t\tzoomanim: this._animateZoom\n\t\t};\n\n\t\tif (this.options.overflow) {\n\t\t\tevents.move = this._updatePosition;\n\t\t}\n\t\treturn events;\n\t}\n\n\t/**\n\t * Returns `true` when the overlay is visible on the map.\n\t * @returns {boolean}\n\t */\n\tisOpen() {\n\t\treturn !!this._map && this._map.hasLayer(this);\n\t}\n\n\t/**\n\t * Brings this overlay in front of other overlays (in the same map pane).\n\t * @returns {this}\n\t */\n\tbringToFront() {\n\t\tif (this._map) {\n\t\t\tDomUtil.toFront(this._container);\n\t\t\tthis._restackPopovers();\n\t\t}\n\t\treturn this;\n\t}\n\n\t/**\n\t * Brings this overlay to the back of other overlays (in the same map pane).\n\t * @returns {this}\n\t */\n\tbringToBack() {\n\t\tif (this._map) {\n\t\t\tDomUtil.toBack(this._container);\n\t\t\tthis._restackPopovers();\n\t\t}\n\t\treturn this;\n\t}\n\n\t// Popovers are stacked in the order they are shown, not in DOM order. Moving\n\t// a popover in the DOM hides it, so (re-)show the overflowing overlays of\n\t// the pane in DOM order.\n\t_restackPopovers() {\n\t\tif (!this.options.overflow) { return; }\n\t\tfor (const el of this.getPane().children) {\n\t\t\tif (!el.classList.contains('maplair-overflow')) { continue; }\n\t\t\tif (el.matches(':popover-open')) {\n\t\t\t\tel.hidePopover();\n\t\t\t}\n\t\t\tel.showPopover();\n\t\t}\n\t}\n\n\t// prepare bound overlay to open: update latlng pos / content source (for FeatureGroup)\n\t_prepareOpen(latlng) {\n\t\tlet source = this._source;\n\t\tif (!source._map) { return false; }\n\n\t\tif (source instanceof FeatureGroup) {\n\t\t\tsource = null;\n\t\t\tfor (const layer of Object.values(this._source._layers)) {\n\t\t\t\tif (layer._map) {\n\t\t\t\t\tsource = layer;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (!source) { return false; } // Unable to get source layer.\n\n\t\t\t// set overlay source to this layer\n\t\t\tthis._source = source;\n\t\t}\n\n\t\tif (!latlng) {\n\t\t\tif (source.getCenter) {\n\t\t\t\tlatlng = source.getCenter();\n\t\t\t} else if (source.getLatLng) {\n\t\t\t\tlatlng = source.getLatLng();\n\t\t\t} else if (source.getBounds) {\n\t\t\t\tlatlng = source.getBounds().getCenter();\n\t\t\t} else {\n\t\t\t\tthrow new Error('Unable to get source layer LatLng.');\n\t\t\t}\n\t\t}\n\t\tthis.setLatLng(latlng);\n\n\t\tif (this._map) {\n\t\t\t// update the overlay (content, layout, etc...)\n\t\t\tthis.update();\n\t\t}\n\n\t\treturn true;\n\t}\n\n\t_updateContent() {\n\t\tif (!this._content) { return; }\n\n\t\tconst node = this._contentNode;\n\t\tconst content = (typeof this._content === 'function') ? this._content(this._source ?? this) : this._content;\n\n\t\tif (typeof content === 'string') {\n\t\t\tnode.innerHTML = content;\n\t\t} else {\n\t\t\twhile (node.hasChildNodes()) {\n\t\t\t\tnode.removeChild(node.firstChild);\n\t\t\t}\n\t\t\tnode.appendChild(content);\n\t\t}\n\n\t\tthis.fire('contentupdate');\n\t}\n\n\t_updatePosition() {\n\t\tif (!this._map) { return; }\n\n\t\tconst pos = this._map.latLngToLayerPoint(this._latlng)._round(),\n\t\toffset = Point.from(this.options.offset);\n\n\t\tthis._setContainerPosition(pos.add(this._getAnchor()));\n\n\t\tconst bottom = this._containerBottom = -offset.y,\n\t\tleft = this._containerLeft = -Math.round(this._containerWidth / 2) + offset.x;\n\n\t\t// bottom position the overlay in case the height of the overlay changes (images loading etc)\n\t\tif (this.options.overflow) {\n\t\t\t// relative to the top of the viewport instead of the pane origin\n\t\t\tthis._container.style.top = 'auto';\n\t\t\tthis._container.style.bottom = `calc(100% + ${bottom}px)`;\n\t\t} else {\n\t\t\tthis._container.style.bottom = `${bottom}px`;\n\t\t}\n\t\tthis._container.style.left = `${left}px`;\n\t}\n\n\t// Positions the container at the given layer point. An overflowing overlay\n\t// lives in the top layer of the page, so it is positioned in viewport coordinates.\n\t_setContainerPosition(pos) {\n\t\tthis._containerPos = pos;\n\t\tif (this.options.overflow) {\n\t\t\tconst mapContainer = this._map._container,\n\t\t\trect = mapContainer.getBoundingClientRect();\n\t\t\tpos = this._map.layerPointToContainerPoint(pos)\n\t\t\t\t._add(new Point(rect.left + mapContainer.clientLeft, rect.top + mapContainer.clientTop));\n\t\t}\n\t\tDomUtil.setPosition(this._container, pos);\n\t}\n\n\t// Returns the layer point the container was positioned at, see `_setContainerPosition`.\n\t_getContainerPosition() {\n\t\treturn this._containerPos ?? new Point(0, 0);\n\t}\n\n\t_getAnchor() {\n\t\treturn [0, 0];\n\t}\n\n\t/**\n\t * Registers this default feature on the map class, called by `MaplairMap` itself.\n\t * @internal\n\t * @param {typeof MaplairMap} MaplairMap\n\t */\n\tstatic register(MaplairMap) {\n\t\tMaplairMap.include(mapDivOverlayMethods);\n\n\t\tLayer.include(layerDivOverlayMethods);\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2CA,MAAM,uBAAuB,EAC5B,aAAa,cAAc,SAAS,QAAQ,SAAS;CACpD,IAAI,UAAU;CACd,IAAI,EAAE,mBAAmB,eACxB,UAAU,IAAI,aAAa,OAAO,CAAC,CAAC,WAAW,OAAO;CAEvD,IAAI,QACH,QAAQ,UAAU,MAAM;CAEzB,OAAO;AACR,EACD;;;;;;AAOA,MAAM,yBAAyB,EAC9B,aAAa,cAAc,KAAK,SAAS,SAAS;CACjD,IAAI,UAAU;CACd,IAAI,mBAAmB,cAAc;EACpC,WAAgB,SAAS,OAAO;EAChC,QAAQ,UAAU;CACnB,OAAO;EACN,UAAW,OAAO,CAAC,UAAW,MAAM,IAAI,aAAa,SAAS,IAAI;EAClE,QAAQ,WAAW,OAAO;CAC3B;CACA,OAAO;AACR,EACD;;;;;;;AAQA,IAAa,aAAb,MAAa,mBAAmB,MAAM;CAErC,OAAO,iBAAiB;EACvB,aAAa;EACb,QAAQ,CAAC,GAAG,CAAC;EACb,WAAW;EACX,MAAM,KAAA;EACN,UAAU;EACV,SAAS;CACV;;;;;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S,CAAC;EACzF;EACA,YAAoB,KAAK,YAAY,GAAG;CACzC;CAGA,wBAAwB;EACvB,OAAO,KAAK,iBAAiB,IAAI,MAAM,GAAG,CAAC;CAC5C;CAEA,aAAa;EACZ,OAAO,CAAC,GAAG,CAAC;CACb;;;;;;CAOA,OAAO,SAAS,YAAY;EAC3B,WAAW,QAAQ,oBAAoB;EAEvC,MAAM,QAAQ,sBAAsB;CACrC;AACD"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { setOptions } from "../core/Util.js";
|
|
2
2
|
import { LatLngBounds } from "../geo/LatLngBounds.js";
|
|
3
3
|
import { LayerGroup } from "./LayerGroup.js";
|
|
4
|
-
|
|
4
|
+
// src/layer/FeatureGroup.js
|
|
5
5
|
/** @import {Layer, InteractiveLayerOptions} from './Layer.js' */
|
|
6
6
|
/** @import {LayerEvent} from '../core/Events.js' */
|
|
7
7
|
/** @import {PathOptions} from './vector/Path.js' */
|
|
@@ -96,16 +96,17 @@ var FeatureGroup = class FeatureGroup extends LayerGroup {
|
|
|
96
96
|
}
|
|
97
97
|
/**
|
|
98
98
|
* Returns the `LatLngBounds` of the feature group (created from bounds and
|
|
99
|
-
* coordinates of its children).
|
|
99
|
+
* coordinates of its children, including the layers of nested layer groups).
|
|
100
100
|
* @returns {LatLngBounds}
|
|
101
101
|
*/
|
|
102
102
|
getBounds() {
|
|
103
103
|
const bounds = new LatLngBounds();
|
|
104
|
-
for (const layer of Object.values(this._layers))
|
|
104
|
+
for (const layer of Object.values(this._layers)) if (layer.getBounds) bounds.extend(layer.getBounds());
|
|
105
|
+
else if (layer.getLatLng) bounds.extend(layer.getLatLng());
|
|
106
|
+
else if (layer instanceof LayerGroup) bounds.extend(FeatureGroup.prototype.getBounds.call(layer));
|
|
105
107
|
return bounds;
|
|
106
108
|
}
|
|
107
109
|
};
|
|
108
|
-
//#endregion
|
|
109
110
|
export { FeatureGroup };
|
|
110
111
|
|
|
111
112
|
//# sourceMappingURL=FeatureGroup.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FeatureGroup.js","names":[],"sources":["../../../src/layer/FeatureGroup.js"],"sourcesContent":["import {LayerGroup} from './LayerGroup.js';\nimport {LatLngBounds} from '../geo/LatLngBounds.js';\nimport * as Util from '../core/Util.js';\n/** @import {Layer, InteractiveLayerOptions} from './Layer.js' */\n/** @import {LayerEvent} from '../core/Events.js' */\n/** @import {PathOptions} from './vector/Path.js' */\n\n/**\n * Extended `LayerGroup` that makes it easier to do the same thing to all its member layers:\n * * [`bindPopup`](#layer-bindpopup) binds a popup to all of the layers at once\n * (likewise with [`bindTooltip`](#layer-bindtooltip))\n * * Events are propagated to the `FeatureGroup`, so if the group has an event\n * handler, it will handle events from any of the layers. This includes pointer\n * events and custom events.\n * * Has `layeradd` and `layerremove` events\n *\n * @example\n * ```js\n * new FeatureGroup([marker1, marker2, polyline])\n * \t.bindPopup('Hello world!')\n * \t.on('click', function() { alert('Clicked on a member of the group!'); })\n * \t.addTo(map);\n * ```\n *\n * @fires layeradd {LayerEvent} Fired when a layer is added to this `FeatureGroup`.\n * @fires layerremove {LayerEvent} Fired when a layer is removed from this `FeatureGroup`.\n */\nexport class FeatureGroup extends LayerGroup {\n\t/**\n\t * Creates a feature group, optionally given an initial set of layers and an\n\t * `options` object.\n\t * @overload\n\t * @param {Layer[]} [layers]\n\t * @param {InteractiveLayerOptions} [options]\n\t */\n\t/**\n\t * @param {...any} args\n\t */\n\tconstructor(...args) {\n\t\tsuper(...args);\n\t\tthis.callInitHooks(FeatureGroup);\n\t}\n\n\t/**\n\t * Adds the given layer to the group.\n\t * @param {Layer} layer\n\t * @returns {this}\n\t */\n\taddLayer(layer) {\n\t\tif (this.hasLayer(layer)) {\n\t\t\treturn this;\n\t\t}\n\n\t\tlayer.addEventParent(this);\n\n\t\tsuper.addLayer(layer);\n\n\t\treturn this.fire('layeradd', {layer});\n\t}\n\n\t/**\n\t * Removes the given layer, or the layer with the given internal ID, from the group.\n\t * @param {Layer|number} layer\n\t * @returns {this}\n\t */\n\tremoveLayer(layer) {\n\t\tif (!this.hasLayer(layer)) {\n\t\t\treturn this;\n\t\t}\n\t\tif (layer in this._layers) {\n\t\t\tlayer = this._layers[layer];\n\t\t}\n\n\t\tlayer.removeEventParent(this);\n\n\t\tsuper.removeLayer(layer);\n\n\t\treturn this.fire('layerremove', {layer});\n\t}\n\n\t/**\n\t * Sets the given path options to each layer of the group that has a `setStyle` method.\n\t * @param {PathOptions} style\n\t * @returns {this}\n\t */\n\tsetStyle(style) {\n\t\treturn this.eachLayer(l => l.setStyle?.(style));\n\t}\n\n\t/**\n\t * Changes the `interactive` option of each layer of the group.\n\t * @param {boolean} interactive\n\t * @returns {this}\n\t */\n\tsetInteractive(interactive) {\n\t\tUtil.setOptions(this, {interactive: !!interactive});\n\t\treturn this.eachLayer(l => l.setInteractive?.(interactive));\n\t}\n\n\t/**\n\t * Brings the layer group to the top of all other layers.\n\t * @returns {this}\n\t */\n\tbringToFront() {\n\t\treturn this.eachLayer(l => l.bringToFront?.());\n\t}\n\n\t/**\n\t * Brings the layer group to the back of all other layers.\n\t * @returns {this}\n\t */\n\tbringToBack() {\n\t\treturn this.eachLayer(l => l.bringToBack?.());\n\t}\n\n\t/**\n\t * Returns the `LatLngBounds` of the feature group (created from bounds and\n\t * coordinates of its children).\n\t * @returns {LatLngBounds}\n\t */\n\tgetBounds() {\n\t\tconst bounds = new LatLngBounds();\n\n\t\tfor (const layer of Object.values(this._layers)) {\n\t\t\tbounds.extend(layer.getBounds
|
|
1
|
+
{"version":3,"file":"FeatureGroup.js","names":[],"sources":["../../../src/layer/FeatureGroup.js"],"sourcesContent":["import {LayerGroup} from './LayerGroup.js';\nimport {LatLngBounds} from '../geo/LatLngBounds.js';\nimport * as Util from '../core/Util.js';\n/** @import {Layer, InteractiveLayerOptions} from './Layer.js' */\n/** @import {LayerEvent} from '../core/Events.js' */\n/** @import {PathOptions} from './vector/Path.js' */\n\n/**\n * Extended `LayerGroup` that makes it easier to do the same thing to all its member layers:\n * * [`bindPopup`](#layer-bindpopup) binds a popup to all of the layers at once\n * (likewise with [`bindTooltip`](#layer-bindtooltip))\n * * Events are propagated to the `FeatureGroup`, so if the group has an event\n * handler, it will handle events from any of the layers. This includes pointer\n * events and custom events.\n * * Has `layeradd` and `layerremove` events\n *\n * @example\n * ```js\n * new FeatureGroup([marker1, marker2, polyline])\n * \t.bindPopup('Hello world!')\n * \t.on('click', function() { alert('Clicked on a member of the group!'); })\n * \t.addTo(map);\n * ```\n *\n * @fires layeradd {LayerEvent} Fired when a layer is added to this `FeatureGroup`.\n * @fires layerremove {LayerEvent} Fired when a layer is removed from this `FeatureGroup`.\n */\nexport class FeatureGroup extends LayerGroup {\n\t/**\n\t * Creates a feature group, optionally given an initial set of layers and an\n\t * `options` object.\n\t * @overload\n\t * @param {Layer[]} [layers]\n\t * @param {InteractiveLayerOptions} [options]\n\t */\n\t/**\n\t * @param {...any} args\n\t */\n\tconstructor(...args) {\n\t\tsuper(...args);\n\t\tthis.callInitHooks(FeatureGroup);\n\t}\n\n\t/**\n\t * Adds the given layer to the group.\n\t * @param {Layer} layer\n\t * @returns {this}\n\t */\n\taddLayer(layer) {\n\t\tif (this.hasLayer(layer)) {\n\t\t\treturn this;\n\t\t}\n\n\t\tlayer.addEventParent(this);\n\n\t\tsuper.addLayer(layer);\n\n\t\treturn this.fire('layeradd', {layer});\n\t}\n\n\t/**\n\t * Removes the given layer, or the layer with the given internal ID, from the group.\n\t * @param {Layer|number} layer\n\t * @returns {this}\n\t */\n\tremoveLayer(layer) {\n\t\tif (!this.hasLayer(layer)) {\n\t\t\treturn this;\n\t\t}\n\t\tif (layer in this._layers) {\n\t\t\tlayer = this._layers[layer];\n\t\t}\n\n\t\tlayer.removeEventParent(this);\n\n\t\tsuper.removeLayer(layer);\n\n\t\treturn this.fire('layerremove', {layer});\n\t}\n\n\t/**\n\t * Sets the given path options to each layer of the group that has a `setStyle` method.\n\t * @param {PathOptions} style\n\t * @returns {this}\n\t */\n\tsetStyle(style) {\n\t\treturn this.eachLayer(l => l.setStyle?.(style));\n\t}\n\n\t/**\n\t * Changes the `interactive` option of each layer of the group.\n\t * @param {boolean} interactive\n\t * @returns {this}\n\t */\n\tsetInteractive(interactive) {\n\t\tUtil.setOptions(this, {interactive: !!interactive});\n\t\treturn this.eachLayer(l => l.setInteractive?.(interactive));\n\t}\n\n\t/**\n\t * Brings the layer group to the top of all other layers.\n\t * @returns {this}\n\t */\n\tbringToFront() {\n\t\treturn this.eachLayer(l => l.bringToFront?.());\n\t}\n\n\t/**\n\t * Brings the layer group to the back of all other layers.\n\t * @returns {this}\n\t */\n\tbringToBack() {\n\t\treturn this.eachLayer(l => l.bringToBack?.());\n\t}\n\n\t/**\n\t * Returns the `LatLngBounds` of the feature group (created from bounds and\n\t * coordinates of its children, including the layers of nested layer groups).\n\t * @returns {LatLngBounds}\n\t */\n\tgetBounds() {\n\t\tconst bounds = new LatLngBounds();\n\n\t\tfor (const layer of Object.values(this._layers)) {\n\t\t\tif (layer.getBounds) {\n\t\t\t\tbounds.extend(layer.getBounds());\n\t\t\t} else if (layer.getLatLng) {\n\t\t\t\tbounds.extend(layer.getLatLng());\n\t\t\t} else if (layer instanceof LayerGroup) {\n\t\t\t\tbounds.extend(FeatureGroup.prototype.getBounds.call(layer));\n\t\t\t}\n\t\t}\n\t\treturn bounds;\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AA2BA,IAAa,eAAb,MAAa,qBAAqB,WAAW;;;;;;;;;;;CAW5C,YAAY,GAAG,MAAM;EACpB,MAAM,GAAG,IAAI;EACb,KAAK,cAAc,YAAY;CAChC;;;;;;CAOA,SAAS,OAAO;EACf,IAAI,KAAK,SAAS,KAAK,GACtB,OAAO;EAGR,MAAM,eAAe,IAAI;EAEzB,MAAM,SAAS,KAAK;EAEpB,OAAO,KAAK,KAAK,YAAY,EAAC,MAAK,CAAC;CACrC;;;;;;CAOA,YAAY,OAAO;EAClB,IAAI,CAAC,KAAK,SAAS,KAAK,GACvB,OAAO;EAER,IAAI,SAAS,KAAK,SACjB,QAAQ,KAAK,QAAQ;EAGtB,MAAM,kBAAkB,IAAI;EAE5B,MAAM,YAAY,KAAK;EAEvB,OAAO,KAAK,KAAK,eAAe,EAAC,MAAK,CAAC;CACxC;;;;;;CAOA,SAAS,OAAO;EACf,OAAO,KAAK,WAAU,MAAK,EAAE,WAAW,KAAK,CAAC;CAC/C;;;;;;CAOA,eAAe,aAAa;EAC3B,WAAgB,MAAM,EAAC,aAAa,CAAC,CAAC,YAAW,CAAC;EAClD,OAAO,KAAK,WAAU,MAAK,EAAE,iBAAiB,WAAW,CAAC;CAC3D;;;;;CAMA,eAAe;EACd,OAAO,KAAK,WAAU,MAAK,EAAE,eAAe,CAAC;CAC9C;;;;;CAMA,cAAc;EACb,OAAO,KAAK,WAAU,MAAK,EAAE,cAAc,CAAC;CAC7C;;;;;;CAOA,YAAY;EACX,MAAM,SAAS,IAAI,aAAa;EAEhC,KAAK,MAAM,SAAS,OAAO,OAAO,KAAK,OAAO,GAC7C,IAAI,MAAM,WACT,OAAO,OAAO,MAAM,UAAU,CAAC;OACzB,IAAI,MAAM,WAChB,OAAO,OAAO,MAAM,UAAU,CAAC;OACzB,IAAI,iBAAiB,YAC3B,OAAO,OAAO,aAAa,UAAU,UAAU,KAAK,KAAK,CAAC;EAG5D,OAAO;CACR;AACD"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { GeoJSON } from "./GeoJSON.js";
|
|
2
|
-
|
|
2
|
+
// src/layer/GeoJSON.Load.js
|
|
3
3
|
/** @import {GeoJsonObject} from 'geojson' */
|
|
4
4
|
/** @import {MaplairEvent} from '../core/Events.js' */
|
|
5
5
|
/**
|
|
@@ -56,6 +56,5 @@ load(source, fetchOptions = this.options.fetchOptions) {
|
|
|
56
56
|
GeoJSON.addInitHook(function() {
|
|
57
57
|
if (this.options.url) this.load(this.options.url).catch(() => {});
|
|
58
58
|
});
|
|
59
|
-
//#endregion
|
|
60
59
|
|
|
61
60
|
//# sourceMappingURL=GeoJSON.Load.js.map
|
|
@@ -4,7 +4,7 @@ import { FeatureGroup } from "./FeatureGroup.js";
|
|
|
4
4
|
import { Polyline } from "./vector/Polyline.js";
|
|
5
5
|
import { Polygon } from "./vector/Polygon.js";
|
|
6
6
|
import { Marker } from "./marker/Marker.js";
|
|
7
|
-
|
|
7
|
+
// src/layer/GeoJSON.js
|
|
8
8
|
/** @import {Feature, FeatureCollection, GeoJSON as GeoJSONData, GeoJsonObject, Geometry} from 'geojson' */
|
|
9
9
|
/** @import {Layer, InteractiveLayerOptions} from './Layer.js' */
|
|
10
10
|
/** @import {LatLngExpression} from '../geo/LatLng.js' */
|
|
@@ -100,19 +100,18 @@ var GeoJSON = class GeoJSON extends FeatureGroup {
|
|
|
100
100
|
* @returns {this}
|
|
101
101
|
*/
|
|
102
102
|
addData(geojson) {
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
for (const feature of features) if (feature.geometries || feature.geometry || feature.features || feature.coordinates) this.addData(feature);
|
|
103
|
+
if (Array.isArray(geojson) || "features" in geojson) {
|
|
104
|
+
for (const data of Array.isArray(geojson) ? geojson : geojson.features) this.addData(data);
|
|
106
105
|
return this;
|
|
107
106
|
}
|
|
108
|
-
const options = this.options;
|
|
109
|
-
if (options.filter && !options.filter(
|
|
110
|
-
const layer = GeoJSON.geometryToLayer(
|
|
107
|
+
const options = this.options, feature = GeoJSON.asFeature(geojson);
|
|
108
|
+
if (!feature.geometry || options.filter && !options.filter(feature)) return this;
|
|
109
|
+
const layer = GeoJSON.geometryToLayer(feature, options);
|
|
111
110
|
if (!layer) return this;
|
|
112
|
-
layer.feature =
|
|
111
|
+
layer.feature = feature;
|
|
113
112
|
layer.defaultOptions = layer.options;
|
|
114
113
|
this.resetStyle(layer);
|
|
115
|
-
if (options.onEachFeature) options.onEachFeature(
|
|
114
|
+
if (options.onEachFeature) options.onEachFeature(feature, layer);
|
|
116
115
|
return this.addLayer(layer);
|
|
117
116
|
}
|
|
118
117
|
/**
|
|
@@ -261,7 +260,6 @@ var GeoJSON = class GeoJSON extends FeatureGroup {
|
|
|
261
260
|
return asFeature(geojson);
|
|
262
261
|
}
|
|
263
262
|
};
|
|
264
|
-
//#endregion
|
|
265
263
|
export { GeoJSON };
|
|
266
264
|
|
|
267
265
|
//# sourceMappingURL=GeoJSON.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GeoJSON.js","names":[],"sources":["../../../src/layer/GeoJSON.js"],"sourcesContent":["import {FeatureGroup} from './FeatureGroup.js';\nimport {Marker} from './marker/Marker.js';\nimport {Polyline} from './vector/Polyline.js';\nimport {Polygon} from './vector/Polygon.js';\nimport {LatLng} from '../geo/LatLng.js';\nimport {latLngToCoords, latLngsToCoords, getFeature, asFeature} from './GeoJSONUtil.js';\n\n/** @import {Feature, FeatureCollection, GeoJSON as GeoJSONData, GeoJsonObject, Geometry} from 'geojson' */\n/** @import {Layer, InteractiveLayerOptions} from './Layer.js' */\n/** @import {LatLngExpression} from '../geo/LatLng.js' */\n/** @import {PathOptions} from './vector/Path.js' */\n\n/**\n * Options of `GeoJSON`.\n * @typedef {object} GeoJSONOptions\n * @property {(geoJsonPoint: Feature, latlng: LatLng) => Layer} [pointToLayer] A\n * `Function` defining how GeoJSON points spawn Maplair layers. It is internally\n * called when data is added, passing the GeoJSON point feature and its `LatLng`.\n * The default is to spawn a default `Marker`:\n * ```js\n * function(geoJsonPoint, latlng) {\n * \treturn new Marker(latlng);\n * }\n * ```\n * @property {PathOptions|((geoJsonFeature: Feature) => PathOptions)} [style] A\n * `Function` defining the `Path options` for styling GeoJSON lines and polygons,\n * called internally when data is added.\n * The default value is to not override any defaults:\n * ```js\n * function (geoJsonFeature) {\n * \treturn {}\n * }\n * ```\n * @property {(feature: Feature, layer: Layer) => void} [onEachFeature] A `Function`\n * that will be called once for each created `Feature`, after it has been created and\n * styled. Useful for attaching events and popups to features. It will receive the\n * `feature` as the first argument and its corresponding spawned `layer` from\n * [`asFeature`](#geojson-asFeature) as the second.\n * The default is to do nothing with the newly created layers:\n * ```js\n * function (feature, layer) {}\n * ```\n * @property {(geoJsonFeature: Feature) => boolean} [filter] A `Function` that will be\n * used to decide whether to include a feature or not.\n * The default is to include all features:\n * ```js\n * function (geoJsonFeature) {\n * \treturn true;\n * }\n * ```\n * Note: dynamically changing the `filter` option will have effect only on newly\n * added data. It will _not_ re-evaluate already included features.\n * @property {(coords: number[]) => LatLng} [coordsToLatLng] A `Function` that will be\n * used for converting GeoJSON coordinates to `LatLng`s.\n * The default is the `coordsToLatLng` static method.\n * @property {boolean} [markersInheritOptions=false] Whether default Markers for \"Point\"\n * type Features inherit from group options.\n * @extends InteractiveLayerOptions\n */\n\n/**\n * Properties of layers created from GeoJSON.\n * @typedef {object} GeoJSONLayerProperties\n * @lends Layer\n * @property {Feature} [feature] The GeoJSON feature the layer was created from (by\n * `GeoJSON`).\n */\n\n/**\n * Represents a GeoJSON object or an array of GeoJSON objects. Allows you to parse\n * GeoJSON data and display it on the map. Extends `FeatureGroup`.\n *\n * There are several static functions which can be called without instantiating\n * `GeoJSON`.\n *\n * @example\n * ```js\n * new GeoJSON(data, {\n * \tstyle: function (feature) {\n * \t\treturn {color: feature.properties.color};\n * \t}\n * }).bindPopup(function (layer) {\n * \treturn layer.feature.properties.description;\n * }).addTo(map);\n * ```\n */\nexport class GeoJSON extends FeatureGroup {\n\n\t/**\n\t * Creates a GeoJSON layer. Optionally accepts an object in\n\t * [GeoJSON format](https://tools.ietf.org/html/rfc7946) to display on the map\n\t * (you can alternatively add it later with `addData` method) and an `options` object.\n\t * @param {GeoJSONData|GeoJSONData[]|null} [geojson]\n\t * @param {GeoJSONOptions} [options]\n\t */\n\tconstructor(geojson, options) {\n\t\tsuper(undefined, options);\n\n\t\tif (geojson) {\n\t\t\tthis.addData(geojson);\n\t\t}\n\n\t\tthis.callInitHooks(GeoJSON);\n\t}\n\n\t/**\n\t * Adds a GeoJSON object to the layer.\n\t * @param {GeoJSONData|GeoJSONData[]} geojson\n\t * @returns {this}\n\t */\n\taddData(geojson) {\n\t\tconst features = Array.isArray(geojson) ? geojson : geojson.features;\n\n\t\tif (features) {\n\t\t\tfor (const feature of features) {\n\t\t\t\t// only add this if geometry or geometries are set and not null\n\t\t\t\tif (feature.geometries || feature.geometry || feature.features || feature.coordinates) {\n\t\t\t\t\tthis.addData(feature);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn this;\n\t\t}\n\n\t\tconst options = this.options;\n\n\t\tif (options.filter && !options.filter(geojson)) { return this; }\n\n\t\tconst layer = GeoJSON.geometryToLayer(geojson, options);\n\t\tif (!layer) {\n\t\t\treturn this;\n\t\t}\n\t\tlayer.feature = GeoJSON.asFeature(geojson);\n\n\t\tlayer.defaultOptions = layer.options;\n\t\tthis.resetStyle(layer);\n\n\t\tif (options.onEachFeature) {\n\t\t\toptions.onEachFeature(geojson, layer);\n\t\t}\n\n\t\treturn this.addLayer(layer);\n\t}\n\n\t/**\n\t * Resets the given vector layer's style to the original GeoJSON style, useful for\n\t * resetting style after hover events. If `layer` is omitted, the style of all\n\t * features in the current layer is reset.\n\t * @param {Layer} [layer]\n\t * @returns {this}\n\t */\n\tresetStyle(layer) {\n\t\tif (layer === undefined) {\n\t\t\treturn this.eachLayer(this.resetStyle, this);\n\t\t}\n\t\t// reset any custom styles\n\t\tlayer.options = Object.create(layer.defaultOptions);\n\t\tthis._setLayerStyle(layer, this.options.style);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Changes styles of GeoJSON vector layers with the given style function.\n\t * @param {PathOptions|((geoJsonFeature: Feature) => PathOptions)} style\n\t * @returns {this}\n\t */\n\tsetStyle(style) {\n\t\treturn this.eachLayer(layer => this._setLayerStyle(layer, style));\n\t}\n\n\t_setLayerStyle(layer, style) {\n\t\tif (layer.setStyle) {\n\t\t\tif (typeof style === 'function') {\n\t\t\t\tstyle = style(layer.feature);\n\t\t\t}\n\t\t\tlayer.setStyle(style);\n\t\t}\n\t}\n\n\t/**\n\t * Creates a `Layer` from a given GeoJSON feature. Can use a custom\n\t * [`pointToLayer`](#geojson-pointtolayer) and/or [`coordsToLatLng`](#geojson-coordstolatlng)\n\t * functions if provided as options.\n\t * @param {GeoJsonObject} geojson\n\t * @param {GeoJSONOptions} [options]\n\t * @returns {Layer|null}\n\t */\n\tstatic geometryToLayer(geojson, options) {\n\n\t\tconst geometry = geojson.type === 'Feature' ? geojson.geometry : geojson,\n\t\tcoords = geometry?.coordinates,\n\t\tlayers = [],\n\t\tpointToLayer = options?.pointToLayer,\n\t\t_coordsToLatLng = options?.coordsToLatLng ?? GeoJSON.coordsToLatLng;\n\t\tlet latlng, latlngs;\n\n\t\tif (!coords && !geometry) {\n\t\t\treturn null;\n\t\t}\n\n\t\tswitch (geometry.type) {\n\t\tcase 'Point':\n\t\t\tlatlng = _coordsToLatLng(coords);\n\t\t\treturn GeoJSON._pointToLayer(pointToLayer, geojson, latlng, options);\n\n\t\tcase 'MultiPoint':\n\t\t\tfor (const coord of coords) {\n\t\t\t\tlatlng = _coordsToLatLng(coord);\n\t\t\t\tlayers.push(GeoJSON._pointToLayer(pointToLayer, geojson, latlng, options));\n\t\t\t}\n\t\t\treturn new FeatureGroup(layers);\n\n\t\tcase 'LineString':\n\t\tcase 'MultiLineString':\n\t\t\tlatlngs = GeoJSON.coordsToLatLngs(coords, geometry.type === 'LineString' ? 0 : 1, _coordsToLatLng);\n\t\t\treturn new Polyline(latlngs, options);\n\n\t\tcase 'Polygon':\n\t\tcase 'MultiPolygon':\n\t\t\tlatlngs = GeoJSON.coordsToLatLngs(coords, geometry.type === 'Polygon' ? 1 : 2, _coordsToLatLng);\n\t\t\treturn new Polygon(latlngs, options);\n\n\t\tcase 'GeometryCollection':\n\t\t\tfor (const g of geometry.geometries) {\n\t\t\t\tconst geoLayer = GeoJSON.geometryToLayer({\n\t\t\t\t\tgeometry: g,\n\t\t\t\t\ttype: 'Feature',\n\t\t\t\t\tproperties: geojson.properties\n\t\t\t\t}, options);\n\n\t\t\t\tif (geoLayer) {\n\t\t\t\t\t// so toGeoJSON exports MultiPoint and GeometryCollection members with their own type\n\t\t\t\t\tgeoLayer.feature = GeoJSON.asFeature(g);\n\t\t\t\t\tlayers.push(geoLayer);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn new FeatureGroup(layers);\n\n\t\tcase 'FeatureCollection':\n\t\t\tfor (const f of geometry.features) {\n\t\t\t\tconst featureLayer = GeoJSON.geometryToLayer(f, options);\n\n\t\t\t\tif (featureLayer) {\n\t\t\t\t\tlayers.push(featureLayer);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn new FeatureGroup(layers);\n\n\t\tdefault:\n\t\t\tthrow new Error('Invalid GeoJSON object.');\n\t\t}\n\t}\n\n\tstatic _pointToLayer(pointToLayerFn, geojson, latlng, options) {\n\t\treturn pointToLayerFn ?\n\t\t\tpointToLayerFn(geojson, latlng) :\n\t\t\tnew Marker(latlng, options?.markersInheritOptions && options);\n\t}\n\n\t/**\n\t * Creates a `LatLng` object from an array of 2 numbers (longitude, latitude)\n\t * or 3 numbers (longitude, latitude, altitude) used in GeoJSON for points.\n\t * @param {number[]} coords\n\t * @returns {LatLng}\n\t */\n\tstatic coordsToLatLng(coords) {\n\t\treturn new LatLng(coords[1], coords[0], coords[2]);\n\t}\n\n\t/**\n\t * Creates a multidimensional array of `LatLng`s from a GeoJSON coordinates array.\n\t * `levelsDeep` specifies the nesting level (0 is for an array of points, 1 for an\n\t * array of arrays of points, etc., 0 by default).\n\t * Can use a custom [`coordsToLatLng`](#geojson-coordstolatlng) function.\n\t * @param {any[]} coords\n\t * @param {number} [levelsDeep]\n\t * @param {(coords: number[]) => LatLng} [_coordsToLatLng]\n\t * @returns {any[]}\n\t */\n\tstatic coordsToLatLngs(coords, levelsDeep, _coordsToLatLng) {\n\t\treturn coords.map(coord => (levelsDeep ?\n\t\t\tGeoJSON.coordsToLatLngs(coord, levelsDeep - 1, _coordsToLatLng) :\n\t\t\t(_coordsToLatLng || GeoJSON.coordsToLatLng)(coord)));\n\t}\n\n\t/**\n\t * Reverse of [`coordsToLatLng`](#geojson-coordstolatlng).\n\t * Coordinates values are rounded with [`formatNum`](#util-formatnum) function.\n\t * @param {LatLngExpression} latlng\n\t * @param {number|false} [precision]\n\t * @returns {number[]}\n\t */\n\tstatic latLngToCoords(latlng, precision) {\n\t\treturn latLngToCoords(latlng, precision);\n\t}\n\n\t/**\n\t * Reverse of [`coordsToLatLngs`](#geojson-coordstolatlngs).\n\t * `close` determines whether the first point should be appended to the end of the\n\t * array to close the feature, only used when `levelsDeep` is 0. False by default.\n\t * Coordinates values are rounded with [`formatNum`](#util-formatnum) function.\n\t * @param {any[]} latlngs\n\t * @param {number} [levelsDeep]\n\t * @param {boolean} [close]\n\t * @param {number|false} [precision]\n\t * @returns {any[]}\n\t */\n\tstatic latLngsToCoords(latlngs, levelsDeep, close, precision) {\n\t\treturn latLngsToCoords(latlngs, levelsDeep, close, precision);\n\t}\n\n\t/**\n\t * Returns GeoJSON geometries/features of layer with new GeoJSON geometry.\n\t * @param {Layer} layer\n\t * @param {Geometry} newGeometry\n\t * @returns {Feature}\n\t */\n\tstatic getFeature(layer, newGeometry) {\n\t\treturn getFeature(layer, newGeometry);\n\t}\n\n\t/**\n\t * Normalize GeoJSON geometries/features into GeoJSON features.\n\t * @param {GeoJsonObject} geojson\n\t * @returns {Feature|FeatureCollection}\n\t */\n\tstatic asFeature(geojson) {\n\t\treturn asFeature(geojson);\n\t}\n\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsFA,IAAa,UAAb,MAAa,gBAAgB,aAAa;;;;;;;;CASzC,YAAY,SAAS,SAAS;EAC7B,MAAM,KAAA,GAAW,OAAO;EAExB,IAAI,SACH,KAAK,QAAQ,OAAO;EAGrB,KAAK,cAAc,OAAO;CAC3B;;;;;;CAOA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AAO,IAAI,OAAO,EAAE;CAClD;;;;;;;;;;;CAYA,OAAO,gBAAgB,QAAQ,YAAY,iBAAiB;EAC3D,OAAO,OAAO,KAAI,UAAU,aAC3B,QAAQ,gBAAgB,OAAO,aAAa,GAAG,eAAe,KAC7D,mBAAmB,QAAQ,eAAA,CAAgB,KAAK,CAAE;CACrD;;;;;;;;CASA,OAAO,eAAe,QAAQ,WAAW;EACxC,OAAO,eAAe,QAAQ,SAAS;CACxC;;;;;;;;;;;;CAaA,OAAO,gBAAgB,SAAS,YAAY,OAAO,WAAW;EAC7D,OAAO,gBAAgB,SAAS,YAAY,OAAO,SAAS;CAC7D;;;;;;;CAQA,OAAO,WAAW,OAAO,aAAa;EACrC,OAAO,WAAW,OAAO,WAAW;CACrC;;;;;;CAOA,OAAO,UAAU,SAAS;EACzB,OAAO,UAAU,OAAO;CACzB;AAED"}
|
|
1
|
+
{"version":3,"file":"GeoJSON.js","names":[],"sources":["../../../src/layer/GeoJSON.js"],"sourcesContent":["import {FeatureGroup} from './FeatureGroup.js';\nimport {Marker} from './marker/Marker.js';\nimport {Polyline} from './vector/Polyline.js';\nimport {Polygon} from './vector/Polygon.js';\nimport {LatLng} from '../geo/LatLng.js';\nimport {latLngToCoords, latLngsToCoords, getFeature, asFeature} from './GeoJSONUtil.js';\n\n/** @import {Feature, FeatureCollection, GeoJSON as GeoJSONData, GeoJsonObject, Geometry} from 'geojson' */\n/** @import {Layer, InteractiveLayerOptions} from './Layer.js' */\n/** @import {LatLngExpression} from '../geo/LatLng.js' */\n/** @import {PathOptions} from './vector/Path.js' */\n\n/**\n * Options of `GeoJSON`.\n * @typedef {object} GeoJSONOptions\n * @property {(geoJsonPoint: Feature, latlng: LatLng) => Layer} [pointToLayer] A\n * `Function` defining how GeoJSON points spawn Maplair layers. It is internally\n * called when data is added, passing the GeoJSON point feature and its `LatLng`.\n * The default is to spawn a default `Marker`:\n * ```js\n * function(geoJsonPoint, latlng) {\n * \treturn new Marker(latlng);\n * }\n * ```\n * @property {PathOptions|((geoJsonFeature: Feature) => PathOptions)} [style] A\n * `Function` defining the `Path options` for styling GeoJSON lines and polygons,\n * called internally when data is added.\n * The default value is to not override any defaults:\n * ```js\n * function (geoJsonFeature) {\n * \treturn {}\n * }\n * ```\n * @property {(feature: Feature, layer: Layer) => void} [onEachFeature] A `Function`\n * that will be called once for each created `Feature`, after it has been created and\n * styled. Useful for attaching events and popups to features. It will receive the\n * `feature` as the first argument and its corresponding spawned `layer` from\n * [`asFeature`](#geojson-asFeature) as the second.\n * The default is to do nothing with the newly created layers:\n * ```js\n * function (feature, layer) {}\n * ```\n * @property {(geoJsonFeature: Feature) => boolean} [filter] A `Function` that will be\n * used to decide whether to include a feature or not.\n * The default is to include all features:\n * ```js\n * function (geoJsonFeature) {\n * \treturn true;\n * }\n * ```\n * Note: dynamically changing the `filter` option will have effect only on newly\n * added data. It will _not_ re-evaluate already included features.\n * @property {(coords: number[]) => LatLng} [coordsToLatLng] A `Function` that will be\n * used for converting GeoJSON coordinates to `LatLng`s.\n * The default is the `coordsToLatLng` static method.\n * @property {boolean} [markersInheritOptions=false] Whether default Markers for \"Point\"\n * type Features inherit from group options.\n * @extends InteractiveLayerOptions\n */\n\n/**\n * Properties of layers created from GeoJSON.\n * @typedef {object} GeoJSONLayerProperties\n * @lends Layer\n * @property {Feature} [feature] The GeoJSON feature the layer was created from (by\n * `GeoJSON`).\n */\n\n/**\n * Represents a GeoJSON object or an array of GeoJSON objects. Allows you to parse\n * GeoJSON data and display it on the map. Extends `FeatureGroup`.\n *\n * There are several static functions which can be called without instantiating\n * `GeoJSON`.\n *\n * @example\n * ```js\n * new GeoJSON(data, {\n * \tstyle: function (feature) {\n * \t\treturn {color: feature.properties.color};\n * \t}\n * }).bindPopup(function (layer) {\n * \treturn layer.feature.properties.description;\n * }).addTo(map);\n * ```\n */\nexport class GeoJSON extends FeatureGroup {\n\n\t/**\n\t * Creates a GeoJSON layer. Optionally accepts an object in\n\t * [GeoJSON format](https://tools.ietf.org/html/rfc7946) to display on the map\n\t * (you can alternatively add it later with `addData` method) and an `options` object.\n\t * @param {GeoJSONData|GeoJSONData[]|null} [geojson]\n\t * @param {GeoJSONOptions} [options]\n\t */\n\tconstructor(geojson, options) {\n\t\tsuper(undefined, options);\n\n\t\tif (geojson) {\n\t\t\tthis.addData(geojson);\n\t\t}\n\n\t\tthis.callInitHooks(GeoJSON);\n\t}\n\n\t/**\n\t * Adds a GeoJSON object to the layer.\n\t * @param {GeoJSONData|GeoJSONData[]} geojson\n\t * @returns {this}\n\t */\n\taddData(geojson) {\n\t\tif (Array.isArray(geojson) || 'features' in geojson) {\n\t\t\tfor (const data of Array.isArray(geojson) ? geojson : geojson.features) {\n\t\t\t\tthis.addData(data);\n\t\t\t}\n\t\t\treturn this;\n\t\t}\n\n\t\tconst options = this.options,\n\t\tfeature = GeoJSON.asFeature(geojson);\n\n\t\t// skips features without a geometry\n\t\tif (!feature.geometry || (options.filter && !options.filter(feature))) { return this; }\n\n\t\tconst layer = GeoJSON.geometryToLayer(feature, options);\n\t\tif (!layer) {\n\t\t\treturn this;\n\t\t}\n\t\tlayer.feature = feature;\n\n\t\tlayer.defaultOptions = layer.options;\n\t\tthis.resetStyle(layer);\n\n\t\tif (options.onEachFeature) {\n\t\t\toptions.onEachFeature(feature, layer);\n\t\t}\n\n\t\treturn this.addLayer(layer);\n\t}\n\n\t/**\n\t * Resets the given vector layer's style to the original GeoJSON style, useful for\n\t * resetting style after hover events. If `layer` is omitted, the style of all\n\t * features in the current layer is reset.\n\t * @param {Layer} [layer]\n\t * @returns {this}\n\t */\n\tresetStyle(layer) {\n\t\tif (layer === undefined) {\n\t\t\treturn this.eachLayer(this.resetStyle, this);\n\t\t}\n\t\t// reset any custom styles\n\t\tlayer.options = Object.create(layer.defaultOptions);\n\t\tthis._setLayerStyle(layer, this.options.style);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Changes styles of GeoJSON vector layers with the given style function.\n\t * @param {PathOptions|((geoJsonFeature: Feature) => PathOptions)} style\n\t * @returns {this}\n\t */\n\tsetStyle(style) {\n\t\treturn this.eachLayer(layer => this._setLayerStyle(layer, style));\n\t}\n\n\t_setLayerStyle(layer, style) {\n\t\tif (layer.setStyle) {\n\t\t\tif (typeof style === 'function') {\n\t\t\t\tstyle = style(layer.feature);\n\t\t\t}\n\t\t\tlayer.setStyle(style);\n\t\t}\n\t}\n\n\t/**\n\t * Creates a `Layer` from a given GeoJSON feature. Can use a custom\n\t * [`pointToLayer`](#geojson-pointtolayer) and/or [`coordsToLatLng`](#geojson-coordstolatlng)\n\t * functions if provided as options.\n\t * @param {GeoJsonObject} geojson\n\t * @param {GeoJSONOptions} [options]\n\t * @returns {Layer|null}\n\t */\n\tstatic geometryToLayer(geojson, options) {\n\n\t\tconst geometry = geojson.type === 'Feature' ? geojson.geometry : geojson,\n\t\tcoords = geometry?.coordinates,\n\t\tlayers = [],\n\t\tpointToLayer = options?.pointToLayer,\n\t\t_coordsToLatLng = options?.coordsToLatLng ?? GeoJSON.coordsToLatLng;\n\t\tlet latlng, latlngs;\n\n\t\tif (!coords && !geometry) {\n\t\t\treturn null;\n\t\t}\n\n\t\tswitch (geometry.type) {\n\t\tcase 'Point':\n\t\t\tlatlng = _coordsToLatLng(coords);\n\t\t\treturn GeoJSON._pointToLayer(pointToLayer, geojson, latlng, options);\n\n\t\tcase 'MultiPoint':\n\t\t\tfor (const coord of coords) {\n\t\t\t\tlatlng = _coordsToLatLng(coord);\n\t\t\t\tlayers.push(GeoJSON._pointToLayer(pointToLayer, geojson, latlng, options));\n\t\t\t}\n\t\t\treturn new FeatureGroup(layers);\n\n\t\tcase 'LineString':\n\t\tcase 'MultiLineString':\n\t\t\tlatlngs = GeoJSON.coordsToLatLngs(coords, geometry.type === 'LineString' ? 0 : 1, _coordsToLatLng);\n\t\t\treturn new Polyline(latlngs, options);\n\n\t\tcase 'Polygon':\n\t\tcase 'MultiPolygon':\n\t\t\tlatlngs = GeoJSON.coordsToLatLngs(coords, geometry.type === 'Polygon' ? 1 : 2, _coordsToLatLng);\n\t\t\treturn new Polygon(latlngs, options);\n\n\t\tcase 'GeometryCollection':\n\t\t\tfor (const g of geometry.geometries) {\n\t\t\t\tconst geoLayer = GeoJSON.geometryToLayer({\n\t\t\t\t\tgeometry: g,\n\t\t\t\t\ttype: 'Feature',\n\t\t\t\t\tproperties: geojson.properties\n\t\t\t\t}, options);\n\n\t\t\t\tif (geoLayer) {\n\t\t\t\t\t// so toGeoJSON exports MultiPoint and GeometryCollection members with their own type\n\t\t\t\t\tgeoLayer.feature = GeoJSON.asFeature(g);\n\t\t\t\t\tlayers.push(geoLayer);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn new FeatureGroup(layers);\n\n\t\tcase 'FeatureCollection':\n\t\t\tfor (const f of geometry.features) {\n\t\t\t\tconst featureLayer = GeoJSON.geometryToLayer(f, options);\n\n\t\t\t\tif (featureLayer) {\n\t\t\t\t\tlayers.push(featureLayer);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn new FeatureGroup(layers);\n\n\t\tdefault:\n\t\t\tthrow new Error('Invalid GeoJSON object.');\n\t\t}\n\t}\n\n\tstatic _pointToLayer(pointToLayerFn, geojson, latlng, options) {\n\t\treturn pointToLayerFn ?\n\t\t\tpointToLayerFn(geojson, latlng) :\n\t\t\tnew Marker(latlng, options?.markersInheritOptions && options);\n\t}\n\n\t/**\n\t * Creates a `LatLng` object from an array of 2 numbers (longitude, latitude)\n\t * or 3 numbers (longitude, latitude, altitude) used in GeoJSON for points.\n\t * @param {number[]} coords\n\t * @returns {LatLng}\n\t */\n\tstatic coordsToLatLng(coords) {\n\t\treturn new LatLng(coords[1], coords[0], coords[2]);\n\t}\n\n\t/**\n\t * Creates a multidimensional array of `LatLng`s from a GeoJSON coordinates array.\n\t * `levelsDeep` specifies the nesting level (0 is for an array of points, 1 for an\n\t * array of arrays of points, etc., 0 by default).\n\t * Can use a custom [`coordsToLatLng`](#geojson-coordstolatlng) function.\n\t * @param {any[]} coords\n\t * @param {number} [levelsDeep]\n\t * @param {(coords: number[]) => LatLng} [_coordsToLatLng]\n\t * @returns {any[]}\n\t */\n\tstatic coordsToLatLngs(coords, levelsDeep, _coordsToLatLng) {\n\t\treturn coords.map(coord => (levelsDeep ?\n\t\t\tGeoJSON.coordsToLatLngs(coord, levelsDeep - 1, _coordsToLatLng) :\n\t\t\t(_coordsToLatLng || GeoJSON.coordsToLatLng)(coord)));\n\t}\n\n\t/**\n\t * Reverse of [`coordsToLatLng`](#geojson-coordstolatlng).\n\t * Coordinates values are rounded with [`formatNum`](#util-formatnum) function.\n\t * @param {LatLngExpression} latlng\n\t * @param {number|false} [precision]\n\t * @returns {number[]}\n\t */\n\tstatic latLngToCoords(latlng, precision) {\n\t\treturn latLngToCoords(latlng, precision);\n\t}\n\n\t/**\n\t * Reverse of [`coordsToLatLngs`](#geojson-coordstolatlngs).\n\t * `close` determines whether the first point should be appended to the end of the\n\t * array to close the feature, only used when `levelsDeep` is 0. False by default.\n\t * Coordinates values are rounded with [`formatNum`](#util-formatnum) function.\n\t * @param {any[]} latlngs\n\t * @param {number} [levelsDeep]\n\t * @param {boolean} [close]\n\t * @param {number|false} [precision]\n\t * @returns {any[]}\n\t */\n\tstatic latLngsToCoords(latlngs, levelsDeep, close, precision) {\n\t\treturn latLngsToCoords(latlngs, levelsDeep, close, precision);\n\t}\n\n\t/**\n\t * Returns GeoJSON geometries/features of layer with new GeoJSON geometry.\n\t * @param {Layer} layer\n\t * @param {Geometry} newGeometry\n\t * @returns {Feature}\n\t */\n\tstatic getFeature(layer, newGeometry) {\n\t\treturn getFeature(layer, newGeometry);\n\t}\n\n\t/**\n\t * Normalize GeoJSON geometries/features into GeoJSON features.\n\t * @param {GeoJsonObject} geojson\n\t * @returns {Feature|FeatureCollection}\n\t */\n\tstatic asFeature(geojson) {\n\t\treturn asFeature(geojson);\n\t}\n\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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ACD;CAEA,OAAO,cAAc,gBAAgB,SAAS,QAAQ,SAAS;EAC9D,OAAO,iBACN,eAAe,SAAS,MAAM,IAC9B,IAAI,OAAO,QAAQ,SAAS,yBAAyB,OAAO;CAC9D;;;;;;;CAQA,OAAO,eAAe,QAAQ;EAC7B,OAAO,IAAI,OAAO,OAAO,IAAI,OAAO,IAAI,OAAO,EAAE;CAClD;;;;;;;;;;;CAYA,OAAO,gBAAgB,QAAQ,YAAY,iBAAiB;EAC3D,OAAO,OAAO,KAAI,UAAU,aAC3B,QAAQ,gBAAgB,OAAO,aAAa,GAAG,eAAe,KAC7D,mBAAmB,QAAQ,eAAA,CAAgB,KAAK,CAAE;CACrD;;;;;;;;CASA,OAAO,eAAe,QAAQ,WAAW;EACxC,OAAO,eAAe,QAAQ,SAAS;CACxC;;;;;;;;;;;;CAaA,OAAO,gBAAgB,SAAS,YAAY,OAAO,WAAW;EAC7D,OAAO,gBAAgB,SAAS,YAAY,OAAO,SAAS;CAC7D;;;;;;;CAQA,OAAO,WAAW,OAAO,aAAa;EACrC,OAAO,WAAW,OAAO,WAAW;CACrC;;;;;;CAOA,OAAO,UAAU,SAAS;EACzB,OAAO,UAAU,OAAO;CACzB;AAED"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { formatNum } from "../core/Util.js";
|
|
2
2
|
import { LatLng } from "../geo/LatLng.js";
|
|
3
3
|
import { isFlat } from "../geometry/LineUtil.js";
|
|
4
|
-
|
|
4
|
+
// src/layer/GeoJSONUtil.js
|
|
5
5
|
/** @import {Feature, FeatureCollection, GeoJsonObject, Geometry} from 'geojson' */
|
|
6
6
|
/** @import {Layer} from './Layer.js' */
|
|
7
7
|
/** @import {LatLngExpression} from '../geo/LatLng.js' */
|
|
@@ -69,7 +69,6 @@ function pointToGeoJSON(layer, precision) {
|
|
|
69
69
|
coordinates: latLngToCoords(layer.getLatLng(), precision)
|
|
70
70
|
});
|
|
71
71
|
}
|
|
72
|
-
//#endregion
|
|
73
72
|
export { asFeature, getFeature, latLngToCoords, latLngsToCoords, pointToGeoJSON };
|
|
74
73
|
|
|
75
74
|
//# sourceMappingURL=GeoJSONUtil.js.map
|