maplair 4.0.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 +178 -0
- package/dist/esm/Maplair.js +18 -17
- package/dist/esm/Maplair.js.map +1 -1
- package/dist/esm/_virtual/_rolldown/runtime.js +1 -2
- package/dist/esm/control/AttributionControl.js +25 -16
- package/dist/esm/control/AttributionControl.js.map +1 -1
- package/dist/esm/control/ButtonControl.js +10 -13
- package/dist/esm/control/ButtonControl.js.map +1 -1
- package/dist/esm/control/ContextMenu.js +2 -5
- package/dist/esm/control/ContextMenu.js.map +1 -1
- package/dist/esm/control/Control.js +10 -18
- package/dist/esm/control/Control.js.map +1 -1
- package/dist/esm/control/FullscreenControl.js +6 -9
- package/dist/esm/control/FullscreenControl.js.map +1 -1
- package/dist/esm/control/LayersControl.js +170 -65
- package/dist/esm/control/LayersControl.js.map +1 -1
- package/dist/esm/control/LegendControl.js +8 -11
- package/dist/esm/control/LegendControl.js.map +1 -1
- package/dist/esm/control/MiniMapControl.js +15 -18
- package/dist/esm/control/MiniMapControl.js.map +1 -1
- package/dist/esm/control/RotateControl.js +2 -5
- package/dist/esm/control/RotateControl.js.map +1 -1
- package/dist/esm/control/ScaleControl.js +8 -11
- package/dist/esm/control/ScaleControl.js.map +1 -1
- package/dist/esm/control/SearchControl.js +100 -19
- package/dist/esm/control/SearchControl.js.map +1 -1
- package/dist/esm/control/SideBySideControl.js +2 -5
- package/dist/esm/control/SideBySideControl.js.map +1 -1
- package/dist/esm/control/TextControl.js +6 -9
- package/dist/esm/control/TextControl.js.map +1 -1
- package/dist/esm/control/TimeControl.js +407 -0
- package/dist/esm/control/TimeControl.js.map +1 -0
- package/dist/esm/control/ZoomControl.js +23 -36
- package/dist/esm/control/ZoomControl.js.map +1 -1
- package/dist/esm/core/Class.js +28 -44
- package/dist/esm/core/Class.js.map +1 -1
- package/dist/esm/core/Events.js +22 -10
- package/dist/esm/core/Events.js.map +1 -1
- package/dist/esm/core/Handler.js +23 -14
- package/dist/esm/core/Handler.js.map +1 -1
- package/dist/esm/core/I18n.js +1 -2
- package/dist/esm/core/Util.js +15 -4
- package/dist/esm/core/Util.js.map +1 -1
- package/dist/esm/dom/DomEvent.DoubleTap.js +26 -24
- package/dist/esm/dom/DomEvent.DoubleTap.js.map +1 -1
- package/dist/esm/dom/DomEvent.PointerEvents.js +3 -18
- package/dist/esm/dom/DomEvent.PointerEvents.js.map +1 -1
- package/dist/esm/dom/DomEvent.js +18 -60
- package/dist/esm/dom/DomEvent.js.map +1 -1
- package/dist/esm/dom/DomUtil.js +15 -70
- package/dist/esm/dom/DomUtil.js.map +1 -1
- package/dist/esm/dom/Draggable.js +21 -21
- package/dist/esm/dom/Draggable.js.map +1 -1
- package/dist/esm/dom/PosAnimation.js +4 -27
- package/dist/esm/dom/PosAnimation.js.map +1 -1
- package/dist/esm/geo/LatLng.js +16 -7
- package/dist/esm/geo/LatLng.js.map +1 -1
- 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 +5 -6
- package/dist/esm/geo/crs/EPSG3395.js.map +1 -1
- package/dist/esm/geo/crs/EPSG3857.js +5 -6
- package/dist/esm/geo/crs/EPSG3857.js.map +1 -1
- package/dist/esm/geo/crs/EPSG4326.js +4 -5
- package/dist/esm/geo/crs/EPSG4326.js.map +1 -1
- package/dist/esm/geo/crs/EarthCRS.js +3 -4
- package/dist/esm/geo/crs/EarthCRS.js.map +1 -1
- package/dist/esm/geo/crs/SimpleCRS.js +4 -5
- package/dist/esm/geo/crs/SimpleCRS.js.map +1 -1
- package/dist/esm/geo/projection/{Projection.LonLat.js → LonLatProjection.js} +5 -6
- package/dist/esm/geo/projection/LonLatProjection.js.map +1 -0
- package/dist/esm/geo/projection/{Projection.Mercator.js → MercatorProjection.js} +4 -5
- package/dist/esm/geo/projection/MercatorProjection.js.map +1 -0
- package/dist/esm/geo/projection/{Projection.SphericalMercator.js → SphericalMercatorProjection.js} +5 -6
- 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 +37 -32
- package/dist/esm/geometry/LineUtil.js.map +1 -1
- package/dist/esm/geometry/Point.js +1 -2
- package/dist/esm/geometry/PolyUtil.js +24 -51
- package/dist/esm/geometry/PolyUtil.js.map +1 -1
- package/dist/esm/geometry/Transformation.js +1 -2
- package/dist/esm/layer/BlanketOverlay.js +7 -10
- package/dist/esm/layer/BlanketOverlay.js.map +1 -1
- package/dist/esm/layer/Classification.js +1 -2
- package/dist/esm/layer/DivOverlay.js +16 -22
- 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 +17 -155
- package/dist/esm/layer/GeoJSON.js.map +1 -1
- package/dist/esm/layer/GeoJSONUtil.js +74 -0
- package/dist/esm/layer/GeoJSONUtil.js.map +1 -0
- package/dist/esm/layer/HeatLayer.js +17 -20
- package/dist/esm/layer/HeatLayer.js.map +1 -1
- package/dist/esm/layer/ImageOverlay.js +22 -29
- package/dist/esm/layer/ImageOverlay.js.map +1 -1
- package/dist/esm/layer/Layer.js +9 -12
- package/dist/esm/layer/Layer.js.map +1 -1
- package/dist/esm/layer/LayerGroup.js +53 -3
- package/dist/esm/layer/LayerGroup.js.map +1 -1
- package/dist/esm/layer/Popup.js +35 -58
- package/dist/esm/layer/Popup.js.map +1 -1
- package/dist/esm/layer/SVGOverlay.js +3 -7
- package/dist/esm/layer/SVGOverlay.js.map +1 -1
- package/dist/esm/layer/Tooltip.js +31 -34
- package/dist/esm/layer/Tooltip.js.map +1 -1
- package/dist/esm/layer/VideoOverlay.js +13 -17
- package/dist/esm/layer/VideoOverlay.js.map +1 -1
- package/dist/esm/layer/marker/DefaultIcon.js +38 -49
- package/dist/esm/layer/marker/DefaultIcon.js.map +1 -1
- package/dist/esm/layer/marker/DivIcon.js +8 -11
- package/dist/esm/layer/marker/DivIcon.js.map +1 -1
- package/dist/esm/layer/marker/Icon.js +9 -12
- package/dist/esm/layer/marker/Icon.js.map +1 -1
- package/dist/esm/layer/marker/Marker.Drag.js +44 -5
- package/dist/esm/layer/marker/Marker.Drag.js.map +1 -1
- package/dist/esm/layer/marker/Marker.Move.js +5 -8
- package/dist/esm/layer/marker/Marker.Move.js.map +1 -1
- package/dist/esm/layer/marker/Marker.js +115 -47
- package/dist/esm/layer/marker/Marker.js.map +1 -1
- package/dist/esm/layer/marker/MarkerClusterGroup.js +301 -0
- package/dist/esm/layer/marker/MarkerClusterGroup.js.map +1 -0
- package/dist/esm/layer/marker/SvgIcon.js +7 -10
- package/dist/esm/layer/marker/SvgIcon.js.map +1 -1
- package/dist/esm/layer/tile/GridLayer.js +89 -101
- package/dist/esm/layer/tile/GridLayer.js.map +1 -1
- package/dist/esm/layer/tile/TileLayer.js +36 -44
- package/dist/esm/layer/tile/TileLayer.js.map +1 -1
- package/dist/esm/layer/tile/WMSTileLayer.js +33 -27
- package/dist/esm/layer/tile/WMSTileLayer.js.map +1 -1
- package/dist/esm/layer/vector/Canvas.js +8 -17
- package/dist/esm/layer/vector/Canvas.js.map +1 -1
- package/dist/esm/layer/vector/Circle.js +6 -5
- package/dist/esm/layer/vector/Circle.js.map +1 -1
- package/dist/esm/layer/vector/CircleMarker.js +19 -10
- package/dist/esm/layer/vector/CircleMarker.js.map +1 -1
- package/dist/esm/layer/vector/Path.DashAnimation.js +3 -5
- package/dist/esm/layer/vector/Path.DashAnimation.js.map +1 -1
- package/dist/esm/layer/vector/Path.ZoomStyles.js +1 -2
- package/dist/esm/layer/vector/Path.js +28 -22
- package/dist/esm/layer/vector/Path.js.map +1 -1
- package/dist/esm/layer/vector/Polygon.js +22 -7
- package/dist/esm/layer/vector/Polygon.js.map +1 -1
- package/dist/esm/layer/vector/Polyline.Decorations.js +3 -4
- package/dist/esm/layer/vector/Polyline.js +25 -10
- 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 +17 -17
- 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 +12 -9
- 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 +41 -22
- package/dist/esm/map/Map.Rotation.js.map +1 -1
- package/dist/esm/map/Map.js +125 -126
- package/dist/esm/map/Map.js.map +1 -1
- package/dist/esm/map/MapSync.js +1 -2
- package/dist/esm/map/handler/BoxZoomHandler.js +25 -47
- package/dist/esm/map/handler/BoxZoomHandler.js.map +1 -1
- package/dist/esm/map/handler/DisplaceHandler.js +7 -10
- package/dist/esm/map/handler/DisplaceHandler.js.map +1 -1
- package/dist/esm/map/handler/DoubleClickZoomHandler.js +1 -2
- package/dist/esm/map/handler/DragHandler.js +20 -21
- package/dist/esm/map/handler/DragHandler.js.map +1 -1
- package/dist/esm/map/handler/KeyboardHandler.js +48 -68
- package/dist/esm/map/handler/KeyboardHandler.js.map +1 -1
- package/dist/esm/map/handler/PinchZoomHandler.js +13 -5
- package/dist/esm/map/handler/PinchZoomHandler.js.map +1 -1
- package/dist/esm/map/handler/ScrollWheelZoomHandler.js +4 -6
- package/dist/esm/map/handler/ScrollWheelZoomHandler.js.map +1 -1
- package/dist/esm/map/handler/TapDragZoomHandler.js +1 -2
- package/dist/esm/map/handler/TapHoldHandler.js +13 -7
- package/dist/esm/map/handler/TapHoldHandler.js.map +1 -1
- package/dist/esm/package.js +2 -3
- package/dist/maplair-global-src.js +6495 -5981
- 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 +6206 -5673
- package/dist/maplair-src.js.map +1 -1
- package/dist/maplair.css +1 -1213
- 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 +11 -18
- package/src/Maplair.all.js +0 -1
- 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 +196 -86
- 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 +22 -38
- package/src/control/index.js +1 -0
- package/src/core/Class.js +37 -45
- package/src/core/Events.js +22 -3
- package/src/core/Handler.js +25 -13
- package/src/core/Util.js +20 -2
- 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 +17 -85
- package/src/dom/DomUtil.js +22 -78
- package/src/dom/Draggable.js +32 -23
- package/src/dom/PosAnimation.js +3 -25
- package/src/dom/index.js +0 -1
- package/src/geo/LatLng.js +20 -3
- package/src/geo/LatLngBounds.js +8 -15
- package/src/geo/crs/EPSG3395.js +4 -4
- package/src/geo/crs/EPSG3857.js +4 -4
- package/src/geo/crs/EPSG4326.js +3 -3
- package/src/geo/crs/EarthCRS.js +2 -8
- package/src/geo/crs/SimpleCRS.js +3 -3
- package/src/geo/index.js +1 -2
- package/src/geo/projection/{Projection.LonLat.js → LonLatProjection.js} +2 -2
- package/src/geo/projection/{Projection.Mercator.js → MercatorProjection.js} +2 -2
- package/src/geo/projection/{Projection.SphericalMercator.js → SphericalMercatorProjection.js} +2 -2
- package/src/geo/projection/index.js +5 -5
- package/src/geometry/Bounds.js +12 -17
- package/src/geometry/LineUtil.js +48 -49
- package/src/geometry/PolyUtil.js +39 -76
- package/src/layer/BlanketOverlay.js +6 -10
- package/src/layer/DivOverlay.js +16 -27
- package/src/layer/FeatureGroup.js +8 -2
- package/src/layer/GeoJSON.js +17 -218
- package/src/layer/GeoJSONUtil.js +85 -0
- package/src/layer/HeatLayer.js +10 -12
- package/src/layer/ImageOverlay.js +21 -32
- package/src/layer/Layer.js +8 -10
- package/src/layer/LayerGroup.js +72 -1
- package/src/layer/Popup.js +37 -62
- package/src/layer/SVGOverlay.js +1 -5
- package/src/layer/Tooltip.js +34 -36
- package/src/layer/VideoOverlay.js +12 -15
- package/src/layer/marker/DefaultIcon.js +40 -58
- package/src/layer/marker/DivIcon.js +9 -11
- package/src/layer/marker/Icon.js +9 -10
- package/src/layer/marker/Marker.Drag.js +54 -6
- package/src/layer/marker/Marker.Move.js +4 -6
- package/src/layer/marker/Marker.js +145 -52
- 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 +108 -135
- package/src/layer/tile/TileLayer.js +44 -49
- package/src/layer/tile/WMSTileLayer.js +31 -26
- package/src/layer/vector/Canvas.js +13 -19
- package/src/layer/vector/Circle.js +9 -3
- package/src/layer/vector/CircleMarker.js +19 -7
- package/src/layer/vector/Path.DashAnimation.js +1 -2
- package/src/layer/vector/Path.js +30 -21
- package/src/layer/vector/Polygon.js +29 -6
- package/src/layer/vector/Polyline.js +26 -7
- package/src/layer/vector/Renderer.getRenderer.js +20 -19
- package/src/layer/vector/SVG.js +17 -7
- package/src/map/Map.Rotation.js +40 -8
- package/src/map/Map.js +158 -153
- package/src/map/handler/BoxZoomHandler.js +30 -50
- package/src/map/handler/DisplaceHandler.js +6 -8
- package/src/map/handler/DragHandler.js +25 -28
- package/src/map/handler/KeyboardHandler.js +65 -90
- 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 +153 -98
- package/dist/esm/core/Browser.js +0 -100
- package/dist/esm/core/Browser.js.map +0 -1
- 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/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/layer/marker/Marker.Rotation.js +0 -103
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import {TileLayer} from './TileLayer.js';
|
|
2
|
-
import Browser from '../../core/Browser.js';
|
|
3
2
|
import {EPSG4326} from '../../geo/crs/EPSG4326.js';
|
|
4
3
|
import {Bounds} from '../../geometry/Bounds.js';
|
|
5
4
|
/** @import {CRS} from '../../geo/crs/CRS.js' */
|
|
@@ -44,23 +43,24 @@ import {Bounds} from '../../geometry/Bounds.js';
|
|
|
44
43
|
*/
|
|
45
44
|
export class WMSTileLayer extends TileLayer {
|
|
46
45
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
46
|
+
/**
|
|
47
|
+
* The default WMS parameters, which the options override, see `WMSTileLayerOptions`.
|
|
48
|
+
* @type {Record<string, any>}
|
|
49
|
+
*/
|
|
50
|
+
static defaultWmsParams = {
|
|
51
|
+
service: 'WMS',
|
|
52
|
+
request: 'GetMap',
|
|
53
|
+
layers: '',
|
|
54
|
+
styles: '',
|
|
55
|
+
format: 'image/jpeg',
|
|
56
|
+
transparent: false,
|
|
57
|
+
version: '1.1.1'
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
static defaultOptions = {
|
|
61
|
+
crs: null,
|
|
62
|
+
uppercase: false
|
|
63
|
+
};
|
|
64
64
|
|
|
65
65
|
/**
|
|
66
66
|
* Instantiates a WMS tile layer object given a base URL of the WMS service and a WMS
|
|
@@ -72,11 +72,11 @@ export class WMSTileLayer extends TileLayer {
|
|
|
72
72
|
constructor(url, options) {
|
|
73
73
|
super(url, options);
|
|
74
74
|
|
|
75
|
-
const wmsParams = {...
|
|
75
|
+
const wmsParams = {...WMSTileLayer.defaultWmsParams};
|
|
76
76
|
|
|
77
77
|
// Options that are unknown in the prototype chain are considered WMS params.
|
|
78
78
|
for (const [key, value] of Object.entries(options)) {
|
|
79
|
-
if (!(key in WMSTileLayer.
|
|
79
|
+
if (!(key in WMSTileLayer.defaultOptions)) {
|
|
80
80
|
wmsParams[key] = value;
|
|
81
81
|
}
|
|
82
82
|
}
|
|
@@ -93,7 +93,7 @@ export class WMSTileLayer extends TileLayer {
|
|
|
93
93
|
|
|
94
94
|
// The size of the requested images: the tile size, doubled on retina displays with `detectRetina`.
|
|
95
95
|
_updateWmsSize() {
|
|
96
|
-
const realRetina = this.options.detectRetina &&
|
|
96
|
+
const realRetina = this.options.detectRetina && window.devicePixelRatio > 1 ? 2 : 1;
|
|
97
97
|
const tileSize = this.getTileSize();
|
|
98
98
|
|
|
99
99
|
this.wmsParams.width = tileSize.x * realRetina;
|
|
@@ -120,8 +120,9 @@ export class WMSTileLayer extends TileLayer {
|
|
|
120
120
|
this._crs = this.options.crs ?? this._map.options.crs;
|
|
121
121
|
this._wmsVersion = parseFloat(this.wmsParams.version);
|
|
122
122
|
|
|
123
|
-
|
|
124
|
-
this.wmsParams
|
|
123
|
+
delete this.wmsParams.srs;
|
|
124
|
+
delete this.wmsParams.crs;
|
|
125
|
+
this.wmsParams[this._wmsVersion >= 1.3 ? 'crs' : 'srs'] = this._crs.code;
|
|
125
126
|
}
|
|
126
127
|
|
|
127
128
|
/**
|
|
@@ -151,9 +152,9 @@ export class WMSTileLayer extends TileLayer {
|
|
|
151
152
|
bbox = (this._wmsVersion >= 1.3 && this._crs === EPSG4326 ?
|
|
152
153
|
[min.y, min.x, max.y, max.x] :
|
|
153
154
|
[min.x, min.y, max.x, max.y]).join(',');
|
|
154
|
-
const url = new URL(super.getTileUrl(coords));
|
|
155
|
+
const url = new URL(super.getTileUrl(coords), document.baseURI);
|
|
155
156
|
for (const [k, v] of Object.entries({...this.wmsParams, bbox})) {
|
|
156
|
-
url.searchParams.append(this.options.uppercase ? k.toUpperCase() : k, v);
|
|
157
|
+
url.searchParams.append(this.options.uppercase ? k.toUpperCase() : k, `${v}`);
|
|
157
158
|
}
|
|
158
159
|
return url.toString();
|
|
159
160
|
}
|
|
@@ -189,7 +190,8 @@ export class WMSTileLayer extends TileLayer {
|
|
|
189
190
|
|
|
190
191
|
/**
|
|
191
192
|
* Merges an object with the new parameters and re-requests tiles on the current screen
|
|
192
|
-
* (unless `noRedraw` was set to true).
|
|
193
|
+
* (unless `noRedraw` was set to true). The current tiles stay visible until the new
|
|
194
|
+
* tiles have loaded, to avoid flickering.
|
|
193
195
|
* @param {Record<string, any>} params
|
|
194
196
|
* @param {boolean} [noRedraw]
|
|
195
197
|
* @returns {this}
|
|
@@ -198,7 +200,10 @@ export class WMSTileLayer extends TileLayer {
|
|
|
198
200
|
|
|
199
201
|
Object.assign(this.wmsParams, params);
|
|
200
202
|
|
|
203
|
+
if (this._map) { this._updateCrs(); }
|
|
204
|
+
|
|
201
205
|
if (!noRedraw) {
|
|
206
|
+
this._keepCurrentTiles();
|
|
202
207
|
this.redraw();
|
|
203
208
|
}
|
|
204
209
|
|
|
@@ -40,11 +40,9 @@ const DASH_SEPARATOR_RE = /[, ]+/;
|
|
|
40
40
|
*/
|
|
41
41
|
export class Canvas extends Renderer {
|
|
42
42
|
|
|
43
|
-
static {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
});
|
|
47
|
-
}
|
|
43
|
+
static defaultOptions = {
|
|
44
|
+
tolerance: 0
|
|
45
|
+
};
|
|
48
46
|
|
|
49
47
|
/**
|
|
50
48
|
* Creates a Canvas renderer with the given options.
|
|
@@ -225,9 +223,9 @@ export class Canvas extends Renderer {
|
|
|
225
223
|
if (typeof layer.options.dashArray === 'string') {
|
|
226
224
|
const parts = layer.options.dashArray.split(DASH_SEPARATOR_RE);
|
|
227
225
|
// Ignore dash array containing invalid lengths
|
|
228
|
-
layer.
|
|
226
|
+
layer._dashArray = parts.map(n => Number(n)).filter(n => !isNaN(n));
|
|
229
227
|
} else {
|
|
230
|
-
layer.
|
|
228
|
+
layer._dashArray = layer.options.dashArray;
|
|
231
229
|
}
|
|
232
230
|
}
|
|
233
231
|
|
|
@@ -329,21 +327,17 @@ export class Canvas extends Renderer {
|
|
|
329
327
|
|
|
330
328
|
if (!this._drawing || layer._empty()) { return; }
|
|
331
329
|
|
|
332
|
-
const
|
|
330
|
+
const {x, y} = layer._point,
|
|
333
331
|
ctx = this._ctx,
|
|
334
332
|
r = Math.max(Math.round(layer._pxRadius), 1),
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
if (s !== 1) {
|
|
338
|
-
ctx.save();
|
|
339
|
-
ctx.scale(1, s);
|
|
340
|
-
}
|
|
333
|
+
ry = Math.max(Math.round(layer._pxRadiusY), 1) || r;
|
|
341
334
|
|
|
342
335
|
ctx.beginPath();
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
336
|
+
// arc is faster for circles in Chrome and Firefox, ellipse for everything else
|
|
337
|
+
if (ry === r) {
|
|
338
|
+
ctx.arc(x, y, r, 0, Math.PI * 2);
|
|
339
|
+
} else {
|
|
340
|
+
ctx.ellipse(x, y, r, ry, 0, 0, Math.PI * 2);
|
|
347
341
|
}
|
|
348
342
|
|
|
349
343
|
this._fillStroke(ctx, layer);
|
|
@@ -360,7 +354,7 @@ export class Canvas extends Renderer {
|
|
|
360
354
|
|
|
361
355
|
if (options.stroke && options.weight !== 0) {
|
|
362
356
|
ctx.lineDashOffset = Number(options.dashOffset ?? 0);
|
|
363
|
-
ctx.setLineDash(
|
|
357
|
+
ctx.setLineDash(layer._dashArray ?? []);
|
|
364
358
|
ctx.globalAlpha = options.opacity;
|
|
365
359
|
ctx.lineWidth = options.weight;
|
|
366
360
|
ctx.strokeStyle = options.color;
|
|
@@ -41,10 +41,13 @@ export class Circle extends CircleMarker {
|
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
/**
|
|
44
|
-
* Returns the `LatLngBounds` of the path.
|
|
44
|
+
* Returns the `LatLngBounds` of the path. When the circle isn't on a map, they're
|
|
45
|
+
* approximated on a sphere.
|
|
45
46
|
* @returns {LatLngBounds}
|
|
46
47
|
*/
|
|
47
48
|
getBounds() {
|
|
49
|
+
if (!this._map) { return this._latlng.toBounds(this._radius * 2); }
|
|
50
|
+
|
|
48
51
|
const half = [this._pxRadius, this._pxRadiusY ?? this._pxRadius];
|
|
49
52
|
|
|
50
53
|
return new LatLngBounds(
|
|
@@ -66,8 +69,11 @@ export class Circle extends CircleMarker {
|
|
|
66
69
|
bottom = map.project([lat - latR, lng]),
|
|
67
70
|
p = top.add(bottom).divideBy(2),
|
|
68
71
|
lat2 = map.unproject(p).lat;
|
|
69
|
-
|
|
70
|
-
|
|
72
|
+
// Longitude span from the haversine form of the spherical law of cosines. The plain acos() form
|
|
73
|
+
// loses precision for radii of about a metre and less, where cos(latR) is too close to 1 (#6120).
|
|
74
|
+
let lngR = 2 * Math.asin(Math.sqrt(
|
|
75
|
+
(Math.sin(latR * d / 2) ** 2 - Math.sin((lat2 - lat) * d / 2) ** 2) /
|
|
76
|
+
(Math.cos(lat * d) * Math.cos(lat2 * d)))) / d;
|
|
71
77
|
|
|
72
78
|
if (isNaN(lngR) || lngR === 0) {
|
|
73
79
|
lngR = latR / Math.cos(Math.PI / 180 * lat); // Fallback for edge case, #2425
|
|
@@ -2,6 +2,8 @@ import {Path} from './Path.js';
|
|
|
2
2
|
import * as Util from '../../core/Util.js';
|
|
3
3
|
import {LatLng} from '../../geo/LatLng.js';
|
|
4
4
|
import {Bounds} from '../../geometry/Bounds.js';
|
|
5
|
+
import {pointToGeoJSON} from '../GeoJSONUtil.js';
|
|
6
|
+
/** @import {Feature} from 'geojson' */
|
|
5
7
|
/** @import {LatLngExpression} from '../../geo/LatLng.js' */
|
|
6
8
|
/** @import {MaplairEvent} from '../../core/Events.js' */
|
|
7
9
|
/** @import {PathOptions} from './Path.js' */
|
|
@@ -32,12 +34,10 @@ import {Bounds} from '../../geometry/Bounds.js';
|
|
|
32
34
|
*/
|
|
33
35
|
export class CircleMarker extends Path {
|
|
34
36
|
|
|
35
|
-
static {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
});
|
|
40
|
-
}
|
|
37
|
+
static defaultOptions = {
|
|
38
|
+
fill: true,
|
|
39
|
+
radius: 10
|
|
40
|
+
};
|
|
41
41
|
|
|
42
42
|
/**
|
|
43
43
|
* Instantiates a circle marker object given a geographical point, and an optional
|
|
@@ -107,7 +107,8 @@ export class CircleMarker extends Path {
|
|
|
107
107
|
}
|
|
108
108
|
|
|
109
109
|
_project() {
|
|
110
|
-
|
|
110
|
+
// snapped to whole pixels: subpixel precision is invisible on markers but slows down rendering many of them
|
|
111
|
+
this._point = this._map.latLngToLayerPoint(this._latlng)._round();
|
|
111
112
|
this._pxRadius = this._radius;
|
|
112
113
|
this._updateBounds();
|
|
113
114
|
}
|
|
@@ -138,4 +139,15 @@ export class CircleMarker extends Path {
|
|
|
138
139
|
_containsPoint(p) {
|
|
139
140
|
return p.distanceTo(this._point) <= this._pxRadius + this._clickTolerance();
|
|
140
141
|
}
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Coordinates values are rounded with [`formatNum`](#util-formatnum) to the
|
|
145
|
+
* given `precision`. Returns a [`GeoJSON`](https://en.wikipedia.org/wiki/GeoJSON)
|
|
146
|
+
* representation of the circle marker (as a GeoJSON `Point` Feature).
|
|
147
|
+
* @param {number|false} [precision]
|
|
148
|
+
* @returns {Feature}
|
|
149
|
+
*/
|
|
150
|
+
toGeoJSON(precision) {
|
|
151
|
+
return pointToGeoJSON(this, precision);
|
|
152
|
+
}
|
|
141
153
|
}
|
|
@@ -2,7 +2,6 @@ import {Path} from './Path.js';
|
|
|
2
2
|
import {SVG} from './SVG.js';
|
|
3
3
|
import {Canvas} from './Canvas.js';
|
|
4
4
|
import * as Util from '../../core/Util.js';
|
|
5
|
-
import Browser from '../../core/Browser.js';
|
|
6
5
|
|
|
7
6
|
const DASH_SEPARATOR_RE = /[ ,]+/;
|
|
8
7
|
|
|
@@ -89,7 +88,7 @@ Canvas.include({
|
|
|
89
88
|
// The shift of the dashes of an animated path, and keeps redrawing it
|
|
90
89
|
_getDashShift(layer) {
|
|
91
90
|
const speed = layer.options.dashSpeed,
|
|
92
|
-
length = speed && !
|
|
91
|
+
length = speed && !this._map._prefersReducedMotion() && layer._getDashLength();
|
|
93
92
|
if (!length) { return 0; }
|
|
94
93
|
|
|
95
94
|
this._animatedDashes ??= new Set();
|
package/src/layer/vector/Path.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import {Layer} from '../Layer.js';
|
|
2
|
+
import {SVG} from './SVG.js';
|
|
2
3
|
import * as Util from '../../core/Util.js';
|
|
3
4
|
/** @import {InteractiveLayerOptions} from '../Layer.js' */
|
|
4
5
|
/** @import {MaplairMap} from '../../map/Map.js' */
|
|
@@ -32,9 +33,11 @@ import * as Util from '../../core/Util.js';
|
|
|
32
33
|
* [how the inside of a shape](https://developer.mozilla.org/docs/Web/SVG/Attribute/fill-rule)
|
|
33
34
|
* is determined.
|
|
34
35
|
* @property {string} [className] Custom class name set on an element. Only for SVG renderer.
|
|
36
|
+
* Applied when the element is created; [`setStyle`](#path-setstyle) does not update it
|
|
37
|
+
* afterwards.
|
|
35
38
|
* @property {Renderer} [renderer] Use this specific instance of `Renderer` for this
|
|
36
|
-
* path.
|
|
37
|
-
* If set, it
|
|
39
|
+
* path. If not set, the path uses the map's [renderer](#maplairmapoptions-renderer),
|
|
40
|
+
* which is `SVG` by default. If set, it overrides the `pane` option.
|
|
38
41
|
* @extends InteractiveLayerOptions
|
|
39
42
|
*/
|
|
40
43
|
|
|
@@ -44,25 +47,23 @@ import * as Util from '../../core/Util.js';
|
|
|
44
47
|
*/
|
|
45
48
|
export class Path extends Layer {
|
|
46
49
|
|
|
47
|
-
static {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
});
|
|
65
|
-
}
|
|
50
|
+
static defaultOptions = {
|
|
51
|
+
stroke: true,
|
|
52
|
+
color: '#3388ff',
|
|
53
|
+
weight: 3,
|
|
54
|
+
opacity: 1,
|
|
55
|
+
lineCap: 'round',
|
|
56
|
+
lineJoin: 'round',
|
|
57
|
+
dashArray: null,
|
|
58
|
+
dashOffset: null,
|
|
59
|
+
fill: false,
|
|
60
|
+
fillColor: null,
|
|
61
|
+
fillOpacity: 0.2,
|
|
62
|
+
fillRule: 'evenodd',
|
|
63
|
+
// className: '',
|
|
64
|
+
interactive: true,
|
|
65
|
+
bubblingPointerEvents: true
|
|
66
|
+
};
|
|
66
67
|
|
|
67
68
|
/**
|
|
68
69
|
* Gets the renderer of the path from the map, before it is added.
|
|
@@ -107,6 +108,9 @@ export class Path extends Layer {
|
|
|
107
108
|
|
|
108
109
|
/**
|
|
109
110
|
* Changes the appearance of a Path based on the options in the `PathOptions` object.
|
|
111
|
+
* Note that [`className`](#pathoptions-classname) is an exception: it is applied only
|
|
112
|
+
* when the path element is created, so passing it here updates the option but leaves
|
|
113
|
+
* the element's class unchanged.
|
|
110
114
|
* @param {PathOptions} style
|
|
111
115
|
* @returns {this}
|
|
112
116
|
*/
|
|
@@ -147,6 +151,11 @@ export class Path extends Layer {
|
|
|
147
151
|
return this._path;
|
|
148
152
|
}
|
|
149
153
|
|
|
154
|
+
// the renderer of the path if neither the path nor the map has one
|
|
155
|
+
_createRenderer(options) {
|
|
156
|
+
return new SVG(options);
|
|
157
|
+
}
|
|
158
|
+
|
|
150
159
|
_reset() {
|
|
151
160
|
// defined in child classes
|
|
152
161
|
this._project();
|
|
@@ -4,6 +4,8 @@ import * as LineUtil from '../../geometry/LineUtil.js';
|
|
|
4
4
|
import {Point} from '../../geometry/Point.js';
|
|
5
5
|
import {Bounds} from '../../geometry/Bounds.js';
|
|
6
6
|
import * as PolyUtil from '../../geometry/PolyUtil.js';
|
|
7
|
+
import {latLngsToCoords, getFeature} from '../GeoJSONUtil.js';
|
|
8
|
+
/** @import {Feature} from 'geojson' */
|
|
7
9
|
/** @import {LatLngExpression} from '../../geo/LatLng.js' */
|
|
8
10
|
/** @import {PolylineOptions} from './Polyline.js' */
|
|
9
11
|
|
|
@@ -57,11 +59,9 @@ import * as PolyUtil from '../../geometry/PolyUtil.js';
|
|
|
57
59
|
*/
|
|
58
60
|
export class Polygon extends Polyline {
|
|
59
61
|
|
|
60
|
-
static {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
});
|
|
64
|
-
}
|
|
62
|
+
static defaultOptions = {
|
|
63
|
+
fill: true
|
|
64
|
+
};
|
|
65
65
|
|
|
66
66
|
/**
|
|
67
67
|
* Instantiates a polygon object given an array of geographical points (or arrays
|
|
@@ -141,7 +141,7 @@ export class Polygon extends Polyline {
|
|
|
141
141
|
}
|
|
142
142
|
|
|
143
143
|
for (const ring of this._rings) {
|
|
144
|
-
const clipped = PolyUtil.clipPolygon(ring, bounds
|
|
144
|
+
const clipped = PolyUtil.clipPolygon(ring, bounds);
|
|
145
145
|
if (clipped.length) {
|
|
146
146
|
this._parts.push(clipped);
|
|
147
147
|
}
|
|
@@ -177,4 +177,27 @@ export class Polygon extends Polyline {
|
|
|
177
177
|
return inside || super._containsPoint(p, true);
|
|
178
178
|
}
|
|
179
179
|
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* Coordinates values are rounded with [`formatNum`](#util-formatnum) to the
|
|
183
|
+
* given `precision`. Returns a [`GeoJSON`](https://en.wikipedia.org/wiki/GeoJSON)
|
|
184
|
+
* representation of the polygon (as a GeoJSON `Polygon` or `MultiPolygon` Feature).
|
|
185
|
+
* @param {number|false} [precision]
|
|
186
|
+
* @returns {Feature}
|
|
187
|
+
*/
|
|
188
|
+
toGeoJSON(precision) {
|
|
189
|
+
const holes = !LineUtil.isFlat(this._latlngs),
|
|
190
|
+
multi = holes && !LineUtil.isFlat(this._latlngs[0]);
|
|
191
|
+
|
|
192
|
+
let coords = latLngsToCoords(this._latlngs, multi ? 2 : holes ? 1 : 0, true, precision);
|
|
193
|
+
|
|
194
|
+
if (!holes) {
|
|
195
|
+
coords = [coords];
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
return getFeature(this, {
|
|
199
|
+
type: `${multi ? 'Multi' : ''}Polygon`,
|
|
200
|
+
coordinates: coords
|
|
201
|
+
});
|
|
202
|
+
}
|
|
180
203
|
}
|
|
@@ -5,6 +5,8 @@ import {LatLng} from '../../geo/LatLng.js';
|
|
|
5
5
|
import {LatLngBounds} from '../../geo/LatLngBounds.js';
|
|
6
6
|
import {Bounds} from '../../geometry/Bounds.js';
|
|
7
7
|
import {Point} from '../../geometry/Point.js';
|
|
8
|
+
import {latLngsToCoords, getFeature} from '../GeoJSONUtil.js';
|
|
9
|
+
/** @import {Feature} from 'geojson' */
|
|
8
10
|
/** @import {LatLngExpression} from '../../geo/LatLng.js' */
|
|
9
11
|
/** @import {PointExpression} from '../../geometry/Point.js' */
|
|
10
12
|
/** @import {PathOptions} from './Path.js' */
|
|
@@ -53,12 +55,10 @@ import {Point} from '../../geometry/Point.js';
|
|
|
53
55
|
*/
|
|
54
56
|
export class Polyline extends Path {
|
|
55
57
|
|
|
56
|
-
static {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
});
|
|
61
|
-
}
|
|
58
|
+
static defaultOptions = {
|
|
59
|
+
smoothFactor: 0.5,
|
|
60
|
+
noClip: false
|
|
61
|
+
};
|
|
62
62
|
|
|
63
63
|
/**
|
|
64
64
|
* Instantiates a polyline object given an array of geographical points and
|
|
@@ -257,7 +257,7 @@ export class Polyline extends Path {
|
|
|
257
257
|
points = this._rings[i];
|
|
258
258
|
|
|
259
259
|
for (j = 0, len2 = points.length; j < len2 - 1; j++) {
|
|
260
|
-
segment = LineUtil.clipSegment(points[j], points[j + 1], bounds, j
|
|
260
|
+
segment = LineUtil.clipSegment(points[j], points[j + 1], bounds, j);
|
|
261
261
|
|
|
262
262
|
if (!segment) { continue; }
|
|
263
263
|
|
|
@@ -316,4 +316,23 @@ export class Polyline extends Path {
|
|
|
316
316
|
}
|
|
317
317
|
return false;
|
|
318
318
|
}
|
|
319
|
+
|
|
320
|
+
/**
|
|
321
|
+
* Coordinates values are rounded with [`formatNum`](#util-formatnum) to the
|
|
322
|
+
* given `precision`. Returns a [`GeoJSON`](https://en.wikipedia.org/wiki/GeoJSON)
|
|
323
|
+
* representation of the polyline (as a GeoJSON `LineString` or `MultiLineString`
|
|
324
|
+
* Feature).
|
|
325
|
+
* @param {number|false} [precision]
|
|
326
|
+
* @returns {Feature}
|
|
327
|
+
*/
|
|
328
|
+
toGeoJSON(precision) {
|
|
329
|
+
const multi = !LineUtil.isFlat(this._latlngs);
|
|
330
|
+
|
|
331
|
+
const coords = latLngsToCoords(this._latlngs, multi ? 1 : 0, false, precision);
|
|
332
|
+
|
|
333
|
+
return getFeature(this, {
|
|
334
|
+
type: `${multi ? 'Multi' : ''}LineString`,
|
|
335
|
+
coordinates: coords
|
|
336
|
+
});
|
|
337
|
+
}
|
|
319
338
|
}
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import {Canvas} from './Canvas.js';
|
|
2
|
-
import {SVG} from './SVG.js';
|
|
3
1
|
/** @import {MaplairMap} from '../../map/Map.js' */
|
|
4
2
|
/** @import {Path} from './Path.js' */
|
|
5
3
|
/** @import {Renderer} from './Renderer.js' */
|
|
@@ -15,36 +13,35 @@ const mapRendererMethods = {
|
|
|
15
13
|
* are respected, and that the renderers do exist on the map.
|
|
16
14
|
* @internal
|
|
17
15
|
* @param {Path} layer
|
|
18
|
-
* @returns {Renderer}
|
|
16
|
+
* @returns {Renderer|undefined}
|
|
19
17
|
*/
|
|
20
18
|
getRenderer(layer) {
|
|
21
|
-
|
|
19
|
+
const renderer = layer.options.renderer ?? this._getPaneRenderer(layer) ?? this.options.renderer ??
|
|
20
|
+
(this._renderer ??= layer._createRenderer?.());
|
|
22
21
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
if (!this.hasLayer(renderer)) {
|
|
22
|
+
// a non-Path layer (e.g. a marker cluster group of a plugin) has no renderer of its own
|
|
23
|
+
if (renderer && !this.hasLayer(renderer)) {
|
|
28
24
|
this.addLayer(renderer);
|
|
29
25
|
}
|
|
30
26
|
return renderer;
|
|
31
27
|
},
|
|
32
28
|
|
|
33
|
-
_getPaneRenderer(
|
|
29
|
+
_getPaneRenderer(layer) {
|
|
30
|
+
const name = layer.options.pane;
|
|
34
31
|
if (name === 'overlayPane' || name === undefined) {
|
|
35
32
|
return;
|
|
36
33
|
}
|
|
37
34
|
|
|
38
35
|
let renderer = this._paneRenderers[name];
|
|
39
|
-
if (renderer
|
|
40
|
-
renderer
|
|
36
|
+
if (!renderer) {
|
|
37
|
+
// custom panes get a renderer of the same kind as the map's default one, so Canvas maps stay Canvas
|
|
38
|
+
const Renderer = this.options.renderer?.constructor;
|
|
39
|
+
renderer = Renderer ?
|
|
40
|
+
new Renderer({...this.options.renderer.options, pane: name}) :
|
|
41
|
+
layer._createRenderer({pane: name});
|
|
41
42
|
this._paneRenderers[name] = renderer;
|
|
42
43
|
}
|
|
43
44
|
return renderer;
|
|
44
|
-
},
|
|
45
|
-
|
|
46
|
-
_createRenderer(options) {
|
|
47
|
-
return (this.options.preferCanvas && new Canvas(options)) || new SVG(options);
|
|
48
45
|
}
|
|
49
46
|
};
|
|
50
47
|
/** @typedef {typeof mapRendererMethods} MapRendererMethods */
|
|
@@ -53,10 +50,9 @@ const mapRendererMethods = {
|
|
|
53
50
|
* Map options of the vector renderers.
|
|
54
51
|
* @typedef {object} RendererMapOptions
|
|
55
52
|
* @lends MaplairMapOptions
|
|
56
|
-
* @property {boolean} [preferCanvas=false] Whether `Path`s should be rendered on a
|
|
57
|
-
* `Canvas` renderer. By default, all `Path`s are rendered in a `SVG` renderer.
|
|
58
53
|
* @property {Renderer} [renderer] The default method for drawing vector layers on the
|
|
59
|
-
* map. `SVG`
|
|
54
|
+
* map. A new `SVG` renderer by default; pass `new Canvas()` to draw them on a canvas
|
|
55
|
+
* instead.
|
|
60
56
|
*/
|
|
61
57
|
|
|
62
58
|
/**
|
|
@@ -67,4 +63,9 @@ const mapRendererMethods = {
|
|
|
67
63
|
*/
|
|
68
64
|
export function register(MaplairMap) {
|
|
69
65
|
MaplairMap.include(mapRendererMethods);
|
|
66
|
+
MaplairMap.addInitHook(function () {
|
|
67
|
+
if (this.options.preferCanvas !== undefined) {
|
|
68
|
+
console.error('MaplairMap: preferCanvas option has been removed. Use renderer: new Canvas() instead.');
|
|
69
|
+
}
|
|
70
|
+
});
|
|
70
71
|
}
|
package/src/layer/vector/SVG.js
CHANGED
|
@@ -63,8 +63,8 @@ export class SVG extends Renderer {
|
|
|
63
63
|
// set size of svg-container if changed
|
|
64
64
|
if (!this._svgSize || !this._svgSize.equals(size)) {
|
|
65
65
|
this._svgSize = size;
|
|
66
|
-
this._container.setAttribute('width', size.x);
|
|
67
|
-
this._container.setAttribute('height', size.y);
|
|
66
|
+
this._container.setAttribute('width', `${size.x}`);
|
|
67
|
+
this._container.setAttribute('height', `${size.y}`);
|
|
68
68
|
}
|
|
69
69
|
|
|
70
70
|
// Reset the <SVG>'s viewBox as per _update, but skip redrawing paths.
|
|
@@ -133,8 +133,8 @@ export class SVG extends Renderer {
|
|
|
133
133
|
|
|
134
134
|
if (options.stroke) {
|
|
135
135
|
path.setAttribute('stroke', options.color);
|
|
136
|
-
path.setAttribute('stroke-opacity', options.opacity);
|
|
137
|
-
path.setAttribute('stroke-width', options.weight);
|
|
136
|
+
path.setAttribute('stroke-opacity', `${options.opacity}`);
|
|
137
|
+
path.setAttribute('stroke-width', `${options.weight}`);
|
|
138
138
|
path.setAttribute('stroke-linecap', options.lineCap);
|
|
139
139
|
path.setAttribute('stroke-linejoin', options.lineJoin);
|
|
140
140
|
|
|
@@ -155,7 +155,7 @@ export class SVG extends Renderer {
|
|
|
155
155
|
|
|
156
156
|
if (options.fill) {
|
|
157
157
|
path.setAttribute('fill', options.fillColor || options.color);
|
|
158
|
-
path.setAttribute('fill-opacity', options.fillOpacity);
|
|
158
|
+
path.setAttribute('fill-opacity', `${options.fillOpacity}`);
|
|
159
159
|
path.setAttribute('fill-rule', options.fillRule || 'evenodd');
|
|
160
160
|
} else {
|
|
161
161
|
path.setAttribute('fill', 'none');
|
|
@@ -174,7 +174,7 @@ export class SVG extends Renderer {
|
|
|
174
174
|
|
|
175
175
|
// drawing a circle with two half-arcs
|
|
176
176
|
const d = layer._empty() ? 'M0 0' :
|
|
177
|
-
`M${p.x - r},${p.y
|
|
177
|
+
`M${num(p.x - r)},${num(p.y)
|
|
178
178
|
}${arc}${r * 2},0 ${
|
|
179
179
|
arc}${-r * 2},0 `;
|
|
180
180
|
|
|
@@ -214,7 +214,7 @@ export class SVG extends Renderer {
|
|
|
214
214
|
*/
|
|
215
215
|
static pointsToPath(rings, closed) {
|
|
216
216
|
const str = rings.flatMap(points => [
|
|
217
|
-
...points.map((p, j) => `${(j ? 'L' : 'M') + p.x} ${p.y}`),
|
|
217
|
+
...points.map((p, j) => `${(j ? 'L' : 'M') + num(p.x)} ${num(p.y)}`),
|
|
218
218
|
// closes the ring for polygons
|
|
219
219
|
closed ? 'z' : ''
|
|
220
220
|
]).join('');
|
|
@@ -224,3 +224,13 @@ export class SVG extends Renderer {
|
|
|
224
224
|
}
|
|
225
225
|
|
|
226
226
|
}
|
|
227
|
+
|
|
228
|
+
// Formats a pixel coordinate with 0.1px precision. Built from integer parts because V8 stringifies small integers
|
|
229
|
+
// much faster than fractional numbers, and path strings with many vertices are rebuilt on every redraw.
|
|
230
|
+
function num(v) {
|
|
231
|
+
const n = Math.round(v * 10),
|
|
232
|
+
a = n < 0 ? -n : n,
|
|
233
|
+
i = Math.floor(a / 10),
|
|
234
|
+
d = a - i * 10;
|
|
235
|
+
return (n < 0 ? '-' : '') + (d ? `${i}.${d}` : i);
|
|
236
|
+
}
|