maplair 4.0.0 → 4.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +118 -0
- package/dist/esm/Maplair.js +14 -14
- package/dist/esm/control/AttributionControl.js +24 -14
- package/dist/esm/control/AttributionControl.js.map +1 -1
- package/dist/esm/control/ButtonControl.js +9 -11
- package/dist/esm/control/ButtonControl.js.map +1 -1
- package/dist/esm/control/ContextMenu.js +1 -3
- package/dist/esm/control/ContextMenu.js.map +1 -1
- package/dist/esm/control/Control.js +9 -16
- package/dist/esm/control/Control.js.map +1 -1
- package/dist/esm/control/FullscreenControl.js +5 -7
- package/dist/esm/control/FullscreenControl.js.map +1 -1
- package/dist/esm/control/LayersControl.js +144 -35
- package/dist/esm/control/LayersControl.js.map +1 -1
- package/dist/esm/control/LegendControl.js +7 -9
- package/dist/esm/control/LegendControl.js.map +1 -1
- package/dist/esm/control/MiniMapControl.js +14 -16
- package/dist/esm/control/MiniMapControl.js.map +1 -1
- package/dist/esm/control/RotateControl.js +1 -3
- package/dist/esm/control/RotateControl.js.map +1 -1
- package/dist/esm/control/ScaleControl.js +7 -9
- package/dist/esm/control/ScaleControl.js.map +1 -1
- package/dist/esm/control/SearchControl.js +99 -17
- package/dist/esm/control/SearchControl.js.map +1 -1
- package/dist/esm/control/SideBySideControl.js +1 -3
- package/dist/esm/control/SideBySideControl.js.map +1 -1
- package/dist/esm/control/TextControl.js +5 -7
- package/dist/esm/control/TextControl.js.map +1 -1
- package/dist/esm/control/TimeControl.js +408 -0
- package/dist/esm/control/TimeControl.js.map +1 -0
- package/dist/esm/control/ZoomControl.js +5 -7
- package/dist/esm/control/ZoomControl.js.map +1 -1
- package/dist/esm/core/Class.js +28 -37
- package/dist/esm/core/Class.js.map +1 -1
- package/dist/esm/core/Events.js +21 -8
- package/dist/esm/core/Events.js.map +1 -1
- package/dist/esm/core/Handler.js +13 -11
- package/dist/esm/core/Handler.js.map +1 -1
- package/dist/esm/core/Util.js +13 -1
- package/dist/esm/core/Util.js.map +1 -1
- package/dist/esm/dom/DomEvent.DoubleTap.js +25 -22
- package/dist/esm/dom/DomEvent.DoubleTap.js.map +1 -1
- package/dist/esm/dom/DomEvent.PointerEvents.js +2 -16
- package/dist/esm/dom/DomEvent.PointerEvents.js.map +1 -1
- package/dist/esm/dom/DomEvent.js +8 -42
- package/dist/esm/dom/DomEvent.js.map +1 -1
- package/dist/esm/dom/DomUtil.js +14 -68
- package/dist/esm/dom/DomUtil.js.map +1 -1
- package/dist/esm/dom/Draggable.js +17 -18
- package/dist/esm/dom/Draggable.js.map +1 -1
- package/dist/esm/dom/PosAnimation.js +3 -25
- package/dist/esm/dom/PosAnimation.js.map +1 -1
- package/dist/esm/geo/LatLng.js +15 -5
- package/dist/esm/geo/LatLng.js.map +1 -1
- package/dist/esm/geo/crs/EPSG3395.js +1 -1
- package/dist/esm/geo/crs/EPSG3395.js.map +1 -1
- package/dist/esm/geo/crs/EPSG3857.js +1 -1
- package/dist/esm/geo/crs/EPSG3857.js.map +1 -1
- package/dist/esm/geo/crs/EPSG4326.js +1 -1
- package/dist/esm/geo/crs/EPSG4326.js.map +1 -1
- package/dist/esm/geo/crs/EarthCRS.js +2 -2
- package/dist/esm/geo/crs/EarthCRS.js.map +1 -1
- package/dist/esm/geo/crs/SimpleCRS.js +1 -1
- package/dist/esm/geo/crs/SimpleCRS.js.map +1 -1
- package/dist/esm/geo/projection/Projection.LonLat.js +1 -1
- package/dist/esm/geo/projection/Projection.LonLat.js.map +1 -1
- package/dist/esm/geo/projection/Projection.Mercator.js +1 -1
- package/dist/esm/geo/projection/Projection.Mercator.js.map +1 -1
- package/dist/esm/geo/projection/Projection.SphericalMercator.js +1 -1
- package/dist/esm/geo/projection/Projection.SphericalMercator.js.map +1 -1
- package/dist/esm/geometry/LineUtil.js +36 -30
- package/dist/esm/geometry/LineUtil.js.map +1 -1
- package/dist/esm/geometry/PolyUtil.js +8 -27
- package/dist/esm/geometry/PolyUtil.js.map +1 -1
- package/dist/esm/layer/BlanketOverlay.js +6 -8
- package/dist/esm/layer/BlanketOverlay.js.map +1 -1
- package/dist/esm/layer/DivOverlay.js +15 -20
- package/dist/esm/layer/DivOverlay.js.map +1 -1
- package/dist/esm/layer/GeoJSON.js +9 -145
- package/dist/esm/layer/GeoJSON.js.map +1 -1
- package/dist/esm/layer/GeoJSONUtil.js +75 -0
- package/dist/esm/layer/GeoJSONUtil.js.map +1 -0
- package/dist/esm/layer/HeatLayer.js +15 -17
- package/dist/esm/layer/HeatLayer.js.map +1 -1
- package/dist/esm/layer/ImageOverlay.js +20 -26
- package/dist/esm/layer/ImageOverlay.js.map +1 -1
- package/dist/esm/layer/Layer.js +8 -10
- package/dist/esm/layer/Layer.js.map +1 -1
- package/dist/esm/layer/LayerGroup.js +51 -0
- package/dist/esm/layer/LayerGroup.js.map +1 -1
- package/dist/esm/layer/Popup.js +26 -42
- package/dist/esm/layer/Popup.js.map +1 -1
- package/dist/esm/layer/SVGOverlay.js +2 -5
- package/dist/esm/layer/SVGOverlay.js.map +1 -1
- package/dist/esm/layer/Tooltip.js +15 -17
- package/dist/esm/layer/Tooltip.js.map +1 -1
- package/dist/esm/layer/VideoOverlay.js +12 -15
- package/dist/esm/layer/VideoOverlay.js.map +1 -1
- package/dist/esm/layer/marker/DefaultIcon.js +15 -48
- package/dist/esm/layer/marker/DefaultIcon.js.map +1 -1
- package/dist/esm/layer/marker/DivIcon.js +7 -9
- package/dist/esm/layer/marker/DivIcon.js.map +1 -1
- package/dist/esm/layer/marker/Icon.js +7 -10
- package/dist/esm/layer/marker/Icon.js.map +1 -1
- package/dist/esm/layer/marker/Marker.Drag.js +1 -1
- package/dist/esm/layer/marker/Marker.Drag.js.map +1 -1
- package/dist/esm/layer/marker/Marker.Move.js +1 -2
- package/dist/esm/layer/marker/Marker.Move.js.map +1 -1
- package/dist/esm/layer/marker/Marker.js +61 -33
- package/dist/esm/layer/marker/Marker.js.map +1 -1
- package/dist/esm/layer/marker/MarkerClusterGroup.js +302 -0
- package/dist/esm/layer/marker/MarkerClusterGroup.js.map +1 -0
- package/dist/esm/layer/marker/SvgIcon.js +6 -8
- package/dist/esm/layer/marker/SvgIcon.js.map +1 -1
- package/dist/esm/layer/tile/GridLayer.js +85 -97
- package/dist/esm/layer/tile/GridLayer.js.map +1 -1
- package/dist/esm/layer/tile/TileLayer.js +28 -36
- package/dist/esm/layer/tile/TileLayer.js.map +1 -1
- package/dist/esm/layer/tile/WMSTileLayer.js +28 -23
- package/dist/esm/layer/tile/WMSTileLayer.js.map +1 -1
- package/dist/esm/layer/vector/Canvas.js +1 -3
- package/dist/esm/layer/vector/Canvas.js.map +1 -1
- package/dist/esm/layer/vector/Circle.js +2 -2
- package/dist/esm/layer/vector/Circle.js.map +1 -1
- package/dist/esm/layer/vector/CircleMarker.js +17 -7
- package/dist/esm/layer/vector/CircleMarker.js.map +1 -1
- package/dist/esm/layer/vector/Path.DashAnimation.js +2 -3
- package/dist/esm/layer/vector/Path.DashAnimation.js.map +1 -1
- package/dist/esm/layer/vector/Path.js +27 -20
- package/dist/esm/layer/vector/Path.js.map +1 -1
- package/dist/esm/layer/vector/Polygon.js +20 -4
- package/dist/esm/layer/vector/Polygon.js.map +1 -1
- package/dist/esm/layer/vector/Polyline.Decorations.js +2 -2
- package/dist/esm/layer/vector/Polyline.js +23 -7
- package/dist/esm/layer/vector/Polyline.js.map +1 -1
- package/dist/esm/layer/vector/Renderer.getRenderer.js +14 -13
- package/dist/esm/layer/vector/Renderer.getRenderer.js.map +1 -1
- package/dist/esm/layer/vector/SVG.js +5 -5
- package/dist/esm/layer/vector/SVG.js.map +1 -1
- package/dist/esm/map/Map.Rotation.js +10 -6
- package/dist/esm/map/Map.Rotation.js.map +1 -1
- package/dist/esm/map/Map.js +116 -110
- package/dist/esm/map/Map.js.map +1 -1
- package/dist/esm/map/handler/BoxZoomHandler.js +5 -7
- package/dist/esm/map/handler/BoxZoomHandler.js.map +1 -1
- package/dist/esm/map/handler/DisplaceHandler.js +6 -8
- package/dist/esm/map/handler/DisplaceHandler.js.map +1 -1
- package/dist/esm/map/handler/DragHandler.js +19 -19
- package/dist/esm/map/handler/DragHandler.js.map +1 -1
- package/dist/esm/map/handler/KeyboardHandler.js +35 -35
- package/dist/esm/map/handler/KeyboardHandler.js.map +1 -1
- package/dist/esm/map/handler/PinchZoomHandler.js +12 -3
- package/dist/esm/map/handler/PinchZoomHandler.js.map +1 -1
- package/dist/esm/map/handler/ScrollWheelZoomHandler.js +3 -4
- package/dist/esm/map/handler/ScrollWheelZoomHandler.js.map +1 -1
- package/dist/esm/map/handler/TapHoldHandler.js +12 -5
- package/dist/esm/map/handler/TapHoldHandler.js.map +1 -1
- package/dist/esm/package.js +1 -1
- package/dist/maplair-global-src.js +8009 -7369
- package/dist/maplair-global-src.js.map +1 -1
- package/dist/maplair-global.js +2 -2
- package/dist/maplair-global.js.map +1 -1
- package/dist/maplair-src.js +10040 -9381
- package/dist/maplair-src.js.map +1 -1
- package/dist/maplair.css +148 -98
- package/dist/maplair.js +2 -2
- package/dist/maplair.js.map +1 -1
- package/i18n/cs.json +6 -0
- package/i18n/de.json +6 -0
- package/i18n/en.json +6 -0
- package/i18n/es.json +6 -0
- package/i18n/fr.json +6 -0
- package/i18n/hu.json +6 -0
- package/i18n/it.json +6 -0
- package/i18n/rm.json +6 -0
- package/i18n/sk.json +6 -0
- package/i18n/sl.json +6 -0
- package/package.json +9 -11
- package/src/control/AttributionControl.js +25 -18
- package/src/control/ButtonControl.js +9 -11
- package/src/control/ContextMenu.js +3 -5
- package/src/control/Control.js +9 -19
- package/src/control/FullscreenControl.js +5 -7
- package/src/control/LayersControl.js +159 -36
- package/src/control/LegendControl.js +7 -9
- package/src/control/MiniMapControl.js +9 -11
- package/src/control/RotateControl.js +3 -5
- package/src/control/ScaleControl.js +7 -9
- package/src/control/SearchControl.js +102 -19
- package/src/control/SideBySideControl.js +3 -5
- package/src/control/TextControl.js +5 -7
- package/src/control/TimeControl.js +471 -0
- package/src/control/ZoomControl.js +5 -7
- package/src/control/index.js +1 -0
- package/src/core/Class.js +35 -34
- package/src/core/Events.js +22 -3
- package/src/core/Handler.js +14 -12
- package/src/core/Util.js +19 -1
- package/src/core/index.js +0 -1
- package/src/dom/DomEvent.DoubleTap.js +18 -10
- package/src/dom/DomEvent.PointerEvents.js +3 -26
- package/src/dom/DomEvent.js +8 -66
- package/src/dom/DomUtil.js +22 -78
- package/src/dom/Draggable.js +27 -22
- package/src/dom/PosAnimation.js +3 -25
- package/src/dom/index.js +0 -1
- package/src/geo/LatLng.js +20 -3
- package/src/geo/crs/EPSG3395.js +1 -1
- package/src/geo/crs/EPSG3857.js +1 -1
- package/src/geo/crs/EPSG4326.js +1 -1
- package/src/geo/crs/EarthCRS.js +2 -8
- package/src/geo/crs/SimpleCRS.js +1 -1
- package/src/geo/projection/Projection.LonLat.js +1 -1
- package/src/geo/projection/Projection.Mercator.js +1 -1
- package/src/geo/projection/Projection.SphericalMercator.js +1 -1
- package/src/geometry/LineUtil.js +47 -48
- package/src/geometry/PolyUtil.js +14 -43
- package/src/layer/BlanketOverlay.js +6 -10
- package/src/layer/DivOverlay.js +15 -26
- package/src/layer/GeoJSON.js +7 -205
- package/src/layer/GeoJSONUtil.js +85 -0
- package/src/layer/HeatLayer.js +9 -11
- package/src/layer/ImageOverlay.js +19 -30
- package/src/layer/Layer.js +8 -10
- package/src/layer/LayerGroup.js +71 -0
- package/src/layer/Popup.js +28 -43
- package/src/layer/SVGOverlay.js +1 -5
- package/src/layer/Tooltip.js +15 -19
- package/src/layer/VideoOverlay.js +12 -15
- package/src/layer/marker/DefaultIcon.js +15 -61
- package/src/layer/marker/DivIcon.js +9 -11
- package/src/layer/marker/Icon.js +7 -10
- package/src/layer/marker/Marker.Drag.js +1 -1
- package/src/layer/marker/Marker.Move.js +1 -2
- package/src/layer/marker/Marker.js +81 -39
- package/src/layer/marker/MarkerClusterGroup.js +370 -0
- package/src/layer/marker/SvgIcon.js +7 -9
- package/src/layer/marker/index.js +1 -0
- package/src/layer/tile/GridLayer.js +103 -133
- package/src/layer/tile/TileLayer.js +35 -43
- package/src/layer/tile/WMSTileLayer.js +26 -24
- package/src/layer/vector/Canvas.js +3 -5
- package/src/layer/vector/Circle.js +5 -2
- package/src/layer/vector/CircleMarker.js +17 -6
- package/src/layer/vector/Path.DashAnimation.js +1 -2
- package/src/layer/vector/Path.js +30 -21
- package/src/layer/vector/Polygon.js +28 -5
- package/src/layer/vector/Polyline.js +25 -6
- package/src/layer/vector/Renderer.getRenderer.js +17 -17
- package/src/layer/vector/SVG.js +5 -5
- package/src/map/Map.Rotation.js +12 -4
- package/src/map/Map.js +142 -133
- package/src/map/handler/BoxZoomHandler.js +9 -8
- package/src/map/handler/DisplaceHandler.js +6 -8
- package/src/map/handler/DragHandler.js +25 -28
- package/src/map/handler/KeyboardHandler.js +42 -48
- package/src/map/handler/PinchZoomHandler.js +16 -5
- package/src/map/handler/ScrollWheelZoomHandler.js +6 -4
- package/src/map/handler/TapHoldHandler.js +15 -4
- package/src/map/index.js +1 -1
- package/src/maplair.css +148 -98
- package/dist/esm/core/Browser.js +0 -100
- package/dist/esm/core/Browser.js.map +0 -1
- package/dist/images/layers.svg +0 -1
- package/dist/images/marker-icon.svg +0 -1
- package/dist/images/marker-shadow.svg +0 -1
- package/src/core/Browser.js +0 -110
- package/src/images/layers.svg +0 -1
- package/src/images/marker-icon.svg +0 -1
- package/src/images/marker-shadow.svg +0 -1
package/src/geo/LatLng.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import * as Util from '../core/Util.js';
|
|
2
|
-
import {EarthCRS} from './crs/EarthCRS.js';
|
|
3
2
|
import {LatLngBounds} from './LatLngBounds.js';
|
|
4
3
|
|
|
5
4
|
// a coordinate in decimal degrees, with an optional degree sign
|
|
@@ -229,7 +228,7 @@ export class LatLng {
|
|
|
229
228
|
* @returns {number}
|
|
230
229
|
*/
|
|
231
230
|
distanceTo(other) {
|
|
232
|
-
return
|
|
231
|
+
return haversineDistance(this, LatLng.from(other), 6371000);
|
|
233
232
|
}
|
|
234
233
|
|
|
235
234
|
/**
|
|
@@ -238,7 +237,7 @@ export class LatLng {
|
|
|
238
237
|
* @returns {LatLng}
|
|
239
238
|
*/
|
|
240
239
|
wrap() {
|
|
241
|
-
return
|
|
240
|
+
return new LatLng(this.lat, Util.wrapNum(this.lng, [-180, 180], true), this.alt);
|
|
242
241
|
}
|
|
243
242
|
|
|
244
243
|
/**
|
|
@@ -257,3 +256,21 @@ export class LatLng {
|
|
|
257
256
|
}
|
|
258
257
|
|
|
259
258
|
};
|
|
259
|
+
|
|
260
|
+
/**
|
|
261
|
+
* The great-circle distance on a sphere of radius `R`, shared with `EarthCRS.distance()`.
|
|
262
|
+
* @param {LatLng} latlng1
|
|
263
|
+
* @param {LatLng} latlng2
|
|
264
|
+
* @param {number} R
|
|
265
|
+
* @returns {number}
|
|
266
|
+
*/
|
|
267
|
+
export function haversineDistance(latlng1, latlng2, R) {
|
|
268
|
+
const rad = Math.PI / 180,
|
|
269
|
+
lat1 = latlng1.lat * rad,
|
|
270
|
+
lat2 = latlng2.lat * rad,
|
|
271
|
+
sinDLat = Math.sin((latlng2.lat - latlng1.lat) * rad / 2),
|
|
272
|
+
sinDLon = Math.sin((latlng2.lng - latlng1.lng) * rad / 2),
|
|
273
|
+
a = sinDLat * sinDLat + Math.cos(lat1) * Math.cos(lat2) * sinDLon * sinDLon,
|
|
274
|
+
c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
|
|
275
|
+
return R * c;
|
|
276
|
+
}
|
package/src/geo/crs/EPSG3395.js
CHANGED
|
@@ -12,7 +12,7 @@ export class EPSG3395 extends EarthCRS {
|
|
|
12
12
|
/** @type {Projection} */
|
|
13
13
|
static projection = Mercator;
|
|
14
14
|
/** @type {Transformation} */
|
|
15
|
-
static transformation = (() => {
|
|
15
|
+
static transformation = /* @__PURE__ */ (() => {
|
|
16
16
|
const scale = 0.5 / (Math.PI * Mercator.R);
|
|
17
17
|
return new Transformation(scale, 0.5, -scale, 0.5);
|
|
18
18
|
})();
|
package/src/geo/crs/EPSG3857.js
CHANGED
|
@@ -14,7 +14,7 @@ export class EPSG3857 extends EarthCRS {
|
|
|
14
14
|
/** @type {Projection} */
|
|
15
15
|
static projection = SphericalMercator;
|
|
16
16
|
/** @type {Transformation} */
|
|
17
|
-
static transformation = (() => {
|
|
17
|
+
static transformation = /* @__PURE__ */ (() => {
|
|
18
18
|
const scale = 0.5 / (Math.PI * SphericalMercator.R);
|
|
19
19
|
return new Transformation(scale, 0.5, -scale, 0.5);
|
|
20
20
|
})();
|
package/src/geo/crs/EPSG4326.js
CHANGED
|
@@ -19,5 +19,5 @@ export class EPSG4326 extends EarthCRS {
|
|
|
19
19
|
/** @type {Projection} */
|
|
20
20
|
static projection = LonLat;
|
|
21
21
|
/** @type {Transformation} */
|
|
22
|
-
static transformation = new Transformation(1 / 180, 1, -1 / 180, 0.5);
|
|
22
|
+
static transformation = /* @__PURE__ */ new Transformation(1 / 180, 1, -1 / 180, 0.5);
|
|
23
23
|
}
|
package/src/geo/crs/EarthCRS.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import {CRS} from './CRS.js';
|
|
2
|
+
import {haversineDistance} from '../LatLng.js';
|
|
2
3
|
/** @import {LatLng} from '../LatLng.js' */
|
|
3
4
|
|
|
4
5
|
/**
|
|
@@ -30,13 +31,6 @@ export class EarthCRS extends CRS {
|
|
|
30
31
|
* @returns {number}
|
|
31
32
|
*/
|
|
32
33
|
static distance(latlng1, latlng2) {
|
|
33
|
-
|
|
34
|
-
lat1 = latlng1.lat * rad,
|
|
35
|
-
lat2 = latlng2.lat * rad,
|
|
36
|
-
sinDLat = Math.sin((latlng2.lat - latlng1.lat) * rad / 2),
|
|
37
|
-
sinDLon = Math.sin((latlng2.lng - latlng1.lng) * rad / 2),
|
|
38
|
-
a = sinDLat * sinDLat + Math.cos(lat1) * Math.cos(lat2) * sinDLon * sinDLon,
|
|
39
|
-
c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
|
|
40
|
-
return this.R * c;
|
|
34
|
+
return haversineDistance(latlng1, latlng2, this.R);
|
|
41
35
|
}
|
|
42
36
|
}
|
package/src/geo/crs/SimpleCRS.js
CHANGED
|
@@ -14,7 +14,7 @@ export class SimpleCRS extends CRS {
|
|
|
14
14
|
/** @type {Projection} */
|
|
15
15
|
static projection = LonLat;
|
|
16
16
|
/** @type {Transformation} */
|
|
17
|
-
static transformation = new Transformation(1, 0, -1, 0);
|
|
17
|
+
static transformation = /* @__PURE__ */ new Transformation(1, 0, -1, 0);
|
|
18
18
|
|
|
19
19
|
/**
|
|
20
20
|
* Returns `2^zoom`.
|
|
@@ -15,7 +15,7 @@ export const Mercator = {
|
|
|
15
15
|
R: earthRadius,
|
|
16
16
|
R_MINOR: 6356752.314245179,
|
|
17
17
|
|
|
18
|
-
bounds: new Bounds([-20037508.34279, -15496570.73972], [20037508.34279, 18764656.23138]),
|
|
18
|
+
bounds: /* @__PURE__ */ new Bounds([-20037508.34279, -15496570.73972], [20037508.34279, 18764656.23138]),
|
|
19
19
|
|
|
20
20
|
project(latlng) {
|
|
21
21
|
latlng = LatLng.from(latlng);
|
package/src/geometry/LineUtil.js
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import {Point} from './Point.js';
|
|
2
2
|
import {LatLng} from '../geo/LatLng.js';
|
|
3
|
-
import {centroid} from './PolyUtil.js';
|
|
4
|
-
import {LatLngBounds} from '../geo/LatLngBounds.js';
|
|
5
3
|
/** @import {LatLngExpression} from '../geo/LatLng.js' */
|
|
6
4
|
/** @import {Bounds} from './Bounds.js' */
|
|
7
5
|
/** @import {CRS} from '../geo/crs/CRS.js' */
|
|
@@ -139,6 +137,7 @@ let _lastCode;
|
|
|
139
137
|
* @returns {[Point, Point]|false}
|
|
140
138
|
*/
|
|
141
139
|
export function clipSegment(a, b, bounds, useLastCode, round) {
|
|
140
|
+
const a0 = a, b0 = b;
|
|
142
141
|
let codeA = useLastCode ? _lastCode : _getBitCode(a, bounds),
|
|
143
142
|
codeB = _getBitCode(b, bounds),
|
|
144
143
|
|
|
@@ -150,6 +149,12 @@ export function clipSegment(a, b, bounds, useLastCode, round) {
|
|
|
150
149
|
while (true) {
|
|
151
150
|
// if a,b is inside the clip window (trivial accept)
|
|
152
151
|
if (!(codeA | codeB)) {
|
|
152
|
+
// round only the endpoints that were replaced by a clipped intersection;
|
|
153
|
+
// rounding while iterating can push a point back outside and loop forever
|
|
154
|
+
if (round) {
|
|
155
|
+
if (a !== a0) { a = a.round(); }
|
|
156
|
+
if (b !== b0) { b = b.round(); }
|
|
157
|
+
}
|
|
153
158
|
return [a, b];
|
|
154
159
|
}
|
|
155
160
|
|
|
@@ -160,7 +165,7 @@ export function clipSegment(a, b, bounds, useLastCode, round) {
|
|
|
160
165
|
|
|
161
166
|
// other cases
|
|
162
167
|
codeOut = codeA || codeB;
|
|
163
|
-
p = _getEdgeIntersection(a, b, codeOut, bounds
|
|
168
|
+
p = _getEdgeIntersection(a, b, codeOut, bounds);
|
|
164
169
|
newCode = _getBitCode(p, bounds);
|
|
165
170
|
|
|
166
171
|
if (codeOut === codeA) {
|
|
@@ -270,8 +275,45 @@ export function isFlat(latlngs) {
|
|
|
270
275
|
* @returns {LatLng}
|
|
271
276
|
*/
|
|
272
277
|
export function polylineCenter(latlngs, crs) {
|
|
273
|
-
|
|
278
|
+
const points = _projectRing(latlngs, crs),
|
|
279
|
+
len = points.length;
|
|
280
|
+
|
|
281
|
+
let halfDist = 0;
|
|
282
|
+
for (let i = 1; i < len; i++) {
|
|
283
|
+
halfDist += points[i - 1].distanceTo(points[i]);
|
|
284
|
+
}
|
|
285
|
+
halfDist /= 2;
|
|
286
|
+
|
|
287
|
+
// if the line has zero length, the loop below never finds a segment and the first point is the center
|
|
288
|
+
let center = points[0];
|
|
289
|
+
|
|
290
|
+
for (let i = 1, dist = 0; i < len; i++) {
|
|
291
|
+
const p1 = points[i - 1],
|
|
292
|
+
p2 = points[i],
|
|
293
|
+
segDist = p1.distanceTo(p2);
|
|
294
|
+
dist += segDist;
|
|
295
|
+
|
|
296
|
+
if (dist > halfDist) {
|
|
297
|
+
const ratio = (dist - halfDist) / segDist;
|
|
298
|
+
center = new Point(
|
|
299
|
+
p2.x - ratio * (p2.x - p1.x),
|
|
300
|
+
p2.y - ratio * (p2.y - p1.y)
|
|
301
|
+
);
|
|
302
|
+
break;
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
return crs.unproject(center);
|
|
307
|
+
}
|
|
274
308
|
|
|
309
|
+
/**
|
|
310
|
+
* Projects the first ring of the given latlngs.
|
|
311
|
+
* @internal
|
|
312
|
+
* @param {LatLngExpression[]|LatLngExpression[][]} latlngs
|
|
313
|
+
* @param {typeof CRS} crs
|
|
314
|
+
* @returns {Point[]}
|
|
315
|
+
*/
|
|
316
|
+
export function _projectRing(latlngs, crs) {
|
|
275
317
|
if (!latlngs || latlngs.length === 0) {
|
|
276
318
|
throw new Error('latlngs not passed');
|
|
277
319
|
}
|
|
@@ -281,48 +323,5 @@ export function polylineCenter(latlngs, crs) {
|
|
|
281
323
|
latlngs = latlngs[0];
|
|
282
324
|
}
|
|
283
325
|
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
const bounds = new LatLngBounds(latlngs);
|
|
287
|
-
const areaBounds = bounds.getNorthWest().distanceTo(bounds.getSouthWest()) * bounds.getNorthEast().distanceTo(bounds.getNorthWest());
|
|
288
|
-
// tests showed that below 1700 rounding errors are happening
|
|
289
|
-
if (areaBounds < 1700) {
|
|
290
|
-
// getting a inexact center, to move the latlngs near to [0, 0] to prevent rounding errors
|
|
291
|
-
centroidLatLng = centroid(latlngs);
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
const len = latlngs.length;
|
|
295
|
-
const points = [];
|
|
296
|
-
for (i = 0; i < len; i++) {
|
|
297
|
-
const latlng = new LatLng(latlngs[i]);
|
|
298
|
-
points.push(crs.project(new LatLng([latlng.lat - centroidLatLng.lat, latlng.lng - centroidLatLng.lng])));
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
for (i = 0, halfDist = 0; i < len - 1; i++) {
|
|
302
|
-
halfDist += points[i].distanceTo(points[i + 1]) / 2;
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
// The line is so small in the current view that all points are on the same pixel.
|
|
306
|
-
if (halfDist === 0) {
|
|
307
|
-
center = points[0];
|
|
308
|
-
} else {
|
|
309
|
-
for (i = 0, dist = 0; i < len - 1; i++) {
|
|
310
|
-
p1 = points[i];
|
|
311
|
-
p2 = points[i + 1];
|
|
312
|
-
segDist = p1.distanceTo(p2);
|
|
313
|
-
dist += segDist;
|
|
314
|
-
|
|
315
|
-
if (dist > halfDist) {
|
|
316
|
-
ratio = (dist - halfDist) / segDist;
|
|
317
|
-
center = [
|
|
318
|
-
p2.x - ratio * (p2.x - p1.x),
|
|
319
|
-
p2.y - ratio * (p2.y - p1.y)
|
|
320
|
-
];
|
|
321
|
-
break;
|
|
322
|
-
}
|
|
323
|
-
}
|
|
324
|
-
}
|
|
325
|
-
|
|
326
|
-
const latlngCenter = crs.unproject(new Point(center));
|
|
327
|
-
return new LatLng([latlngCenter.lat + centroidLatLng.lat, latlngCenter.lng + centroidLatLng.lng]);
|
|
326
|
+
return latlngs.map(latlng => crs.project(LatLng.from(latlng)));
|
|
328
327
|
}
|
package/src/geometry/PolyUtil.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import * as LineUtil from './LineUtil.js';
|
|
2
2
|
import {LatLng} from '../geo/LatLng.js';
|
|
3
3
|
import {Point} from './Point.js';
|
|
4
|
-
import {LatLngBounds} from '../geo/LatLngBounds.js';
|
|
5
4
|
/** @import {LatLngExpression} from '../geo/LatLng.js' */
|
|
6
5
|
/** @import {Bounds} from './Bounds.js' */
|
|
7
6
|
/** @import {CRS} from '../geo/crs/CRS.js' */
|
|
@@ -70,56 +69,28 @@ export function clipPolygon(points, bounds, round) {
|
|
|
70
69
|
* @returns {LatLng}
|
|
71
70
|
*/
|
|
72
71
|
export function polygonCenter(latlngs, crs) {
|
|
73
|
-
|
|
72
|
+
// points relative to the first one, to avoid floating point errors on tiny polygons with large projected coordinates
|
|
73
|
+
const points = LineUtil._projectRing(latlngs, crs),
|
|
74
|
+
origin = new Point(points[0]),
|
|
75
|
+
len = points.length;
|
|
74
76
|
|
|
75
|
-
|
|
76
|
-
throw new Error('latlngs not passed');
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
if (!LineUtil.isFlat(latlngs)) {
|
|
80
|
-
console.warn('latlngs are not flat! Only the first ring will be used');
|
|
81
|
-
latlngs = latlngs[0];
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
let centroidLatLng = new LatLng([0, 0]);
|
|
85
|
-
|
|
86
|
-
const bounds = new LatLngBounds(latlngs);
|
|
87
|
-
const areaBounds = bounds.getNorthWest().distanceTo(bounds.getSouthWest()) * bounds.getNorthEast().distanceTo(bounds.getNorthWest());
|
|
88
|
-
// tests showed that below 1700 rounding errors are happening
|
|
89
|
-
if (areaBounds < 1700) {
|
|
90
|
-
// getting a inexact center, to move the latlngs near to [0, 0] to prevent rounding errors
|
|
91
|
-
centroidLatLng = centroid(latlngs);
|
|
92
|
-
}
|
|
77
|
+
for (const p of points) { p._subtract(origin); }
|
|
93
78
|
|
|
94
|
-
|
|
95
|
-
const points = [];
|
|
96
|
-
for (i = 0; i < len; i++) {
|
|
97
|
-
const latlng = new LatLng(latlngs[i]);
|
|
98
|
-
points.push(crs.project(new LatLng([latlng.lat - centroidLatLng.lat, latlng.lng - centroidLatLng.lng])));
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
area = x = y = 0;
|
|
102
|
-
|
|
103
|
-
// polygon centroid algorithm;
|
|
104
|
-
for (i = 0, j = len - 1; i < len; j = i++) {
|
|
105
|
-
p1 = points[i];
|
|
106
|
-
p2 = points[j];
|
|
79
|
+
let area = 0, x = 0, y = 0;
|
|
107
80
|
|
|
81
|
+
// polygon centroid algorithm
|
|
82
|
+
for (let i = 0, j = len - 1; i < len; j = i++) {
|
|
83
|
+
const p1 = points[i],
|
|
84
|
+
p2 = points[j],
|
|
108
85
|
f = p1.y * p2.x - p2.y * p1.x;
|
|
86
|
+
|
|
109
87
|
x += (p1.x + p2.x) * f;
|
|
110
88
|
y += (p1.y + p2.y) * f;
|
|
111
|
-
area += f
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
if (area === 0) {
|
|
115
|
-
// Polygon is so small that all points are on same pixel.
|
|
116
|
-
center = points[0];
|
|
117
|
-
} else {
|
|
118
|
-
center = [x / area, y / area];
|
|
89
|
+
area += f;
|
|
119
90
|
}
|
|
120
91
|
|
|
121
|
-
|
|
122
|
-
return new
|
|
92
|
+
// area is 0 when the polygon is so small that all points are on the same pixel
|
|
93
|
+
return crs.unproject(area === 0 ? origin : new Point(x / (3 * area), y / (3 * area))._add(origin));
|
|
123
94
|
}
|
|
124
95
|
|
|
125
96
|
/**
|
|
@@ -45,12 +45,10 @@ import {Bounds} from '../geometry/Bounds.js';
|
|
|
45
45
|
*/
|
|
46
46
|
export class BlanketOverlay extends Layer {
|
|
47
47
|
|
|
48
|
-
static {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
});
|
|
53
|
-
}
|
|
48
|
+
static defaultOptions = {
|
|
49
|
+
padding: 0.1,
|
|
50
|
+
continuous: false,
|
|
51
|
+
};
|
|
54
52
|
|
|
55
53
|
/**
|
|
56
54
|
* @param {BlanketOverlayOptions} [options]
|
|
@@ -97,11 +95,9 @@ export class BlanketOverlay extends Layer {
|
|
|
97
95
|
zoom: this._onZoom,
|
|
98
96
|
moveend: this._onMoveEnd,
|
|
99
97
|
resize: this._resizeContainer,
|
|
100
|
-
zoomend: this._onZoomEnd
|
|
98
|
+
zoomend: this._onZoomEnd,
|
|
99
|
+
zoomanim: this._onAnimZoom
|
|
101
100
|
};
|
|
102
|
-
if (this._zoomAnimated) {
|
|
103
|
-
events.zoomanim = this._onAnimZoom;
|
|
104
|
-
}
|
|
105
101
|
if (this.options.continuous) {
|
|
106
102
|
events.move = this._onMoveEnd;
|
|
107
103
|
}
|
package/src/layer/DivOverlay.js
CHANGED
|
@@ -81,16 +81,14 @@ const layerDivOverlayMethods = {
|
|
|
81
81
|
*/
|
|
82
82
|
export class DivOverlay extends Layer {
|
|
83
83
|
|
|
84
|
-
static {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
});
|
|
93
|
-
}
|
|
84
|
+
static defaultOptions = {
|
|
85
|
+
interactive: false,
|
|
86
|
+
offset: [0, 0],
|
|
87
|
+
className: '',
|
|
88
|
+
pane: undefined,
|
|
89
|
+
overflow: false,
|
|
90
|
+
content: ''
|
|
91
|
+
};
|
|
94
92
|
|
|
95
93
|
/**
|
|
96
94
|
* Instantiates an overlay given an optional `options` object that describes its
|
|
@@ -181,14 +179,12 @@ export class DivOverlay extends Layer {
|
|
|
181
179
|
* @param {MaplairMap} map
|
|
182
180
|
*/
|
|
183
181
|
onAdd(map) {
|
|
184
|
-
this._zoomAnimated = map._zoomAnimated;
|
|
185
|
-
|
|
186
182
|
if (!this._container) {
|
|
187
183
|
this._initLayout();
|
|
188
184
|
}
|
|
189
185
|
|
|
190
186
|
if (map._fadeAnimated) {
|
|
191
|
-
this._container.style.opacity = 0;
|
|
187
|
+
this._container.style.opacity = '0';
|
|
192
188
|
}
|
|
193
189
|
|
|
194
190
|
clearTimeout(this._removeTimeout);
|
|
@@ -205,7 +201,7 @@ export class DivOverlay extends Layer {
|
|
|
205
201
|
this.update();
|
|
206
202
|
|
|
207
203
|
if (map._fadeAnimated) {
|
|
208
|
-
this._container.style.opacity = 1;
|
|
204
|
+
this._container.style.opacity = '1';
|
|
209
205
|
}
|
|
210
206
|
|
|
211
207
|
// A popover is shown on top already, re-showing it would skip the fade animation
|
|
@@ -230,7 +226,7 @@ export class DivOverlay extends Layer {
|
|
|
230
226
|
}
|
|
231
227
|
|
|
232
228
|
if (map._fadeAnimated) {
|
|
233
|
-
this._container.style.opacity = 0;
|
|
229
|
+
this._container.style.opacity = '0';
|
|
234
230
|
this._removeTimeout = setTimeout(() => this._container.remove(), 200);
|
|
235
231
|
} else {
|
|
236
232
|
this._container.remove();
|
|
@@ -330,12 +326,10 @@ export class DivOverlay extends Layer {
|
|
|
330
326
|
getEvents() {
|
|
331
327
|
const events = {
|
|
332
328
|
zoom: this._updatePosition,
|
|
333
|
-
viewreset: this._updatePosition
|
|
329
|
+
viewreset: this._updatePosition,
|
|
330
|
+
zoomanim: this._animateZoom
|
|
334
331
|
};
|
|
335
332
|
|
|
336
|
-
if (this._zoomAnimated) {
|
|
337
|
-
events.zoomanim = this._animateZoom;
|
|
338
|
-
}
|
|
339
333
|
if (this.options.overflow) {
|
|
340
334
|
events.move = this._updatePosition;
|
|
341
335
|
}
|
|
@@ -450,14 +444,9 @@ export class DivOverlay extends Layer {
|
|
|
450
444
|
if (!this._map) { return; }
|
|
451
445
|
|
|
452
446
|
const pos = this._map.latLngToLayerPoint(this._latlng),
|
|
453
|
-
|
|
454
|
-
let offset = Point.from(this.options.offset);
|
|
447
|
+
offset = Point.from(this.options.offset);
|
|
455
448
|
|
|
456
|
-
|
|
457
|
-
this._setContainerPosition(pos.add(anchor));
|
|
458
|
-
} else {
|
|
459
|
-
offset = offset.add(pos).add(anchor);
|
|
460
|
-
}
|
|
449
|
+
this._setContainerPosition(pos.add(this._getAnchor()));
|
|
461
450
|
|
|
462
451
|
const bottom = this._containerBottom = -offset.y,
|
|
463
452
|
left = this._containerLeft = -Math.round(this._containerWidth / 2) + offset.x;
|