maplair 4.0.0-alpha.1
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 +2804 -0
- package/LICENSE +27 -0
- package/README.md +40 -0
- package/dist/esm/Maplair.js +71 -0
- package/dist/esm/Maplair.js.map +1 -0
- package/dist/esm/_virtual/_rolldown/runtime.js +13 -0
- package/dist/esm/control/AttributionControl.js +79 -0
- package/dist/esm/control/AttributionControl.js.map +1 -0
- package/dist/esm/control/Control.js +81 -0
- package/dist/esm/control/Control.js.map +1 -0
- package/dist/esm/control/LayersControl.js +220 -0
- package/dist/esm/control/LayersControl.js.map +1 -0
- package/dist/esm/control/ScaleControl.js +72 -0
- package/dist/esm/control/ScaleControl.js.map +1 -0
- package/dist/esm/control/ZoomControl.js +86 -0
- package/dist/esm/control/ZoomControl.js.map +1 -0
- package/dist/esm/core/Browser.js +31 -0
- package/dist/esm/core/Browser.js.map +1 -0
- package/dist/esm/core/Class.js +52 -0
- package/dist/esm/core/Class.js.map +1 -0
- package/dist/esm/core/Events.js +149 -0
- package/dist/esm/core/Events.js.map +1 -0
- package/dist/esm/core/Handler.js +32 -0
- package/dist/esm/core/Handler.js.map +1 -0
- package/dist/esm/core/I18n.js +36 -0
- package/dist/esm/core/I18n.js.map +1 -0
- package/dist/esm/core/Util.js +71 -0
- package/dist/esm/core/Util.js.map +1 -0
- package/dist/esm/dom/DomEvent.DoubleTap.js +74 -0
- package/dist/esm/dom/DomEvent.DoubleTap.js.map +1 -0
- package/dist/esm/dom/DomEvent.PointerEvents.js +46 -0
- package/dist/esm/dom/DomEvent.PointerEvents.js.map +1 -0
- package/dist/esm/dom/DomEvent.js +135 -0
- package/dist/esm/dom/DomEvent.js.map +1 -0
- package/dist/esm/dom/DomUtil.js +107 -0
- package/dist/esm/dom/DomUtil.js.map +1 -0
- package/dist/esm/dom/Draggable.js +107 -0
- package/dist/esm/dom/Draggable.js.map +1 -0
- package/dist/esm/dom/PosAnimation.js +56 -0
- package/dist/esm/dom/PosAnimation.js.map +1 -0
- package/dist/esm/geo/LatLng.js +65 -0
- package/dist/esm/geo/LatLng.js.map +1 -0
- package/dist/esm/geo/LatLngBounds.js +114 -0
- package/dist/esm/geo/LatLngBounds.js.map +1 -0
- package/dist/esm/geo/crs/CRS.js +51 -0
- package/dist/esm/geo/crs/CRS.js.map +1 -0
- package/dist/esm/geo/crs/EPSG3395.js +16 -0
- package/dist/esm/geo/crs/EPSG3395.js.map +1 -0
- package/dist/esm/geo/crs/EPSG3857.js +19 -0
- package/dist/esm/geo/crs/EPSG3857.js.map +1 -0
- package/dist/esm/geo/crs/EPSG4326.js +13 -0
- package/dist/esm/geo/crs/EPSG4326.js.map +1 -0
- package/dist/esm/geo/crs/EarthCRS.js +14 -0
- package/dist/esm/geo/crs/EarthCRS.js.map +1 -0
- package/dist/esm/geo/crs/SimpleCRS.js +23 -0
- package/dist/esm/geo/crs/SimpleCRS.js.map +1 -0
- package/dist/esm/geo/projection/Projection.LonLat.js +19 -0
- package/dist/esm/geo/projection/Projection.LonLat.js.map +1 -0
- package/dist/esm/geo/projection/Projection.Mercator.js +33 -0
- package/dist/esm/geo/projection/Projection.Mercator.js.map +1 -0
- package/dist/esm/geo/projection/Projection.SphericalMercator.js +27 -0
- package/dist/esm/geo/projection/Projection.SphericalMercator.js.map +1 -0
- package/dist/esm/geo/projection/index.js +14 -0
- package/dist/esm/geo/projection/index.js.map +1 -0
- package/dist/esm/geometry/Bounds.js +91 -0
- package/dist/esm/geometry/Bounds.js.map +1 -0
- package/dist/esm/geometry/LineUtil.js +169 -0
- package/dist/esm/geometry/LineUtil.js.map +1 -0
- package/dist/esm/geometry/Point.js +119 -0
- package/dist/esm/geometry/Point.js.map +1 -0
- package/dist/esm/geometry/PolyUtil.js +89 -0
- package/dist/esm/geometry/PolyUtil.js.map +1 -0
- package/dist/esm/geometry/Transformation.js +34 -0
- package/dist/esm/geometry/Transformation.js.map +1 -0
- package/dist/esm/layer/BlanketOverlay.js +87 -0
- package/dist/esm/layer/BlanketOverlay.js.map +1 -0
- package/dist/esm/layer/DivOverlay.js +192 -0
- package/dist/esm/layer/DivOverlay.js.map +1 -0
- package/dist/esm/layer/FeatureGroup.js +40 -0
- package/dist/esm/layer/FeatureGroup.js.map +1 -0
- package/dist/esm/layer/GeoJSON.js +192 -0
- package/dist/esm/layer/GeoJSON.js.map +1 -0
- package/dist/esm/layer/ImageOverlay.js +140 -0
- package/dist/esm/layer/ImageOverlay.js.map +1 -0
- package/dist/esm/layer/Layer.js +119 -0
- package/dist/esm/layer/Layer.js.map +1 -0
- package/dist/esm/layer/LayerGroup.js +58 -0
- package/dist/esm/layer/LayerGroup.js.map +1 -0
- package/dist/esm/layer/Popup.js +224 -0
- package/dist/esm/layer/Popup.js.map +1 -0
- package/dist/esm/layer/SVGOverlay.js +21 -0
- package/dist/esm/layer/SVGOverlay.js.map +1 -0
- package/dist/esm/layer/Tooltip.js +228 -0
- package/dist/esm/layer/Tooltip.js.map +1 -0
- package/dist/esm/layer/VideoOverlay.js +54 -0
- package/dist/esm/layer/VideoOverlay.js.map +1 -0
- package/dist/esm/layer/marker/DefaultIcon.js +50 -0
- package/dist/esm/layer/marker/DefaultIcon.js.map +1 -0
- package/dist/esm/layer/marker/DivIcon.js +37 -0
- package/dist/esm/layer/marker/DivIcon.js.map +1 -0
- package/dist/esm/layer/marker/Icon.js +65 -0
- package/dist/esm/layer/marker/Icon.js.map +1 -0
- package/dist/esm/layer/marker/Marker.Drag.js +77 -0
- package/dist/esm/layer/marker/Marker.Drag.js.map +1 -0
- package/dist/esm/layer/marker/Marker.js +235 -0
- package/dist/esm/layer/marker/Marker.js.map +1 -0
- package/dist/esm/layer/tile/GridLayer.js +447 -0
- package/dist/esm/layer/tile/GridLayer.js.map +1 -0
- package/dist/esm/layer/tile/TileLayer.js +139 -0
- package/dist/esm/layer/tile/TileLayer.js.map +1 -0
- package/dist/esm/layer/tile/WMSTileLayer.js +68 -0
- package/dist/esm/layer/tile/WMSTileLayer.js.map +1 -0
- package/dist/esm/layer/vector/Canvas.js +292 -0
- package/dist/esm/layer/vector/Canvas.js.map +1 -0
- package/dist/esm/layer/vector/Circle.js +35 -0
- package/dist/esm/layer/vector/Circle.js.map +1 -0
- package/dist/esm/layer/vector/CircleMarker.js +69 -0
- package/dist/esm/layer/vector/CircleMarker.js.map +1 -0
- package/dist/esm/layer/vector/Path.js +68 -0
- package/dist/esm/layer/vector/Path.js.map +1 -0
- package/dist/esm/layer/vector/Polygon.js +70 -0
- package/dist/esm/layer/vector/Polygon.js.map +1 -0
- package/dist/esm/layer/vector/Polyline.js +152 -0
- package/dist/esm/layer/vector/Polyline.js.map +1 -0
- package/dist/esm/layer/vector/Rectangle.js +25 -0
- package/dist/esm/layer/vector/Rectangle.js.map +1 -0
- package/dist/esm/layer/vector/Renderer.getRenderer.js +31 -0
- package/dist/esm/layer/vector/Renderer.getRenderer.js.map +1 -0
- package/dist/esm/layer/vector/Renderer.js +39 -0
- package/dist/esm/layer/vector/Renderer.js.map +1 -0
- package/dist/esm/layer/vector/SVG.js +115 -0
- package/dist/esm/layer/vector/SVG.js.map +1 -0
- package/dist/esm/map/Map.js +844 -0
- package/dist/esm/map/Map.js.map +1 -0
- package/dist/esm/map/handler/BoxZoomHandler.js +105 -0
- package/dist/esm/map/handler/BoxZoomHandler.js.map +1 -0
- package/dist/esm/map/handler/DoubleClickZoomHandler.js +27 -0
- package/dist/esm/map/handler/DoubleClickZoomHandler.js.map +1 -0
- package/dist/esm/map/handler/DragHandler.js +133 -0
- package/dist/esm/map/handler/DragHandler.js.map +1 -0
- package/dist/esm/map/handler/KeyboardHandler.js +117 -0
- package/dist/esm/map/handler/KeyboardHandler.js.map +1 -0
- package/dist/esm/map/handler/PinchZoomHandler.js +96 -0
- package/dist/esm/map/handler/PinchZoomHandler.js.map +1 -0
- package/dist/esm/map/handler/ScrollWheelZoomHandler.js +50 -0
- package/dist/esm/map/handler/ScrollWheelZoomHandler.js.map +1 -0
- package/dist/esm/map/handler/TapHoldHandler.js +77 -0
- package/dist/esm/map/handler/TapHoldHandler.js.map +1 -0
- package/dist/esm/package.js +6 -0
- package/dist/esm/package.js.map +1 -0
- package/dist/images/layers.svg +1 -0
- package/dist/images/logo.svg +1 -0
- package/dist/images/marker-icon.svg +1 -0
- package/dist/images/marker-shadow.svg +1 -0
- package/dist/maplair-global-src.js +6810 -0
- package/dist/maplair-global-src.js.map +1 -0
- package/dist/maplair-global.js +12 -0
- package/dist/maplair-global.js.map +1 -0
- package/dist/maplair-src.js +6704 -0
- package/dist/maplair-src.js.map +1 -0
- package/dist/maplair.css +730 -0
- package/dist/maplair.js +7 -0
- package/dist/maplair.js.map +1 -0
- package/i18n/cs.json +12 -0
- package/i18n/de.json +12 -0
- package/i18n/en.json +12 -0
- package/i18n/es.json +12 -0
- package/i18n/fr.json +12 -0
- package/i18n/hu.json +12 -0
- package/i18n/it.json +12 -0
- package/i18n/rm.json +12 -0
- package/i18n/sk.json +12 -0
- package/i18n/sl.json +12 -0
- package/package.json +87 -0
- package/src/Maplair.js +24 -0
- package/src/control/AttributionControl.js +147 -0
- package/src/control/Control.js +174 -0
- package/src/control/LayersControl.js +444 -0
- package/src/control/ScaleControl.js +141 -0
- package/src/control/ZoomControl.js +147 -0
- package/src/control/index.js +5 -0
- package/src/core/Browser.js +75 -0
- package/src/core/Class.js +97 -0
- package/src/core/Events.js +334 -0
- package/src/core/Handler.js +59 -0
- package/src/core/I18n.js +76 -0
- package/src/core/Util.js +122 -0
- package/src/core/index.js +8 -0
- package/src/dom/DomEvent.DoubleTap.js +120 -0
- package/src/dom/DomEvent.PointerEvents.js +75 -0
- package/src/dom/DomEvent.js +282 -0
- package/src/dom/DomUtil.js +175 -0
- package/src/dom/Draggable.js +204 -0
- package/src/dom/PosAnimation.js +115 -0
- package/src/dom/index.js +9 -0
- package/src/geo/LatLng.js +163 -0
- package/src/geo/LatLngBounds.js +260 -0
- package/src/geo/crs/CRS.js +143 -0
- package/src/geo/crs/EPSG3395.js +19 -0
- package/src/geo/crs/EPSG3857.js +26 -0
- package/src/geo/crs/EPSG4326.js +21 -0
- package/src/geo/crs/EarthCRS.js +32 -0
- package/src/geo/crs/SimpleCRS.js +35 -0
- package/src/geo/crs/index.js +6 -0
- package/src/geo/index.js +7 -0
- package/src/geo/projection/Projection.LonLat.js +30 -0
- package/src/geo/projection/Projection.Mercator.js +53 -0
- package/src/geo/projection/Projection.SphericalMercator.js +46 -0
- package/src/geo/projection/index.js +26 -0
- package/src/geometry/Bounds.js +222 -0
- package/src/geometry/LineUtil.js +299 -0
- package/src/geometry/Point.js +239 -0
- package/src/geometry/PolyUtil.js +129 -0
- package/src/geometry/Transformation.js +67 -0
- package/src/geometry/index.js +8 -0
- package/src/images/layers.svg +1 -0
- package/src/images/logo.svg +1 -0
- package/src/images/marker-icon.svg +1 -0
- package/src/images/marker-shadow.svg +1 -0
- package/src/layer/BlanketOverlay.js +171 -0
- package/src/layer/DivOverlay.js +353 -0
- package/src/layer/FeatureGroup.js +93 -0
- package/src/layer/GeoJSON.js +432 -0
- package/src/layer/ImageOverlay.js +279 -0
- package/src/layer/Layer.js +273 -0
- package/src/layer/LayerGroup.js +129 -0
- package/src/layer/Popup.js +528 -0
- package/src/layer/SVGOverlay.js +47 -0
- package/src/layer/Tooltip.js +469 -0
- package/src/layer/VideoOverlay.js +111 -0
- package/src/layer/index.js +18 -0
- package/src/layer/marker/DefaultIcon.js +79 -0
- package/src/layer/marker/DivIcon.js +76 -0
- package/src/layer/marker/Icon.js +164 -0
- package/src/layer/marker/Marker.Drag.js +161 -0
- package/src/layer/marker/Marker.js +465 -0
- package/src/layer/marker/index.js +5 -0
- package/src/layer/tile/GridLayer.js +901 -0
- package/src/layer/tile/TileLayer.js +299 -0
- package/src/layer/tile/WMSTileLayer.js +133 -0
- package/src/layer/tile/index.js +3 -0
- package/src/layer/vector/Canvas.js +479 -0
- package/src/layer/vector/Circle.js +87 -0
- package/src/layer/vector/CircleMarker.js +110 -0
- package/src/layer/vector/Path.js +145 -0
- package/src/layer/vector/Polygon.js +160 -0
- package/src/layer/vector/Polyline.js +296 -0
- package/src/layer/vector/Rectangle.js +52 -0
- package/src/layer/vector/Renderer.getRenderer.js +48 -0
- package/src/layer/vector/Renderer.js +75 -0
- package/src/layer/vector/SVG.js +216 -0
- package/src/layer/vector/index.js +10 -0
- package/src/map/Map.js +1830 -0
- package/src/map/handler/BoxZoomHandler.js +156 -0
- package/src/map/handler/DoubleClickZoomHandler.js +62 -0
- package/src/map/handler/DragHandler.js +240 -0
- package/src/map/handler/KeyboardHandler.js +188 -0
- package/src/map/handler/PinchZoomHandler.js +157 -0
- package/src/map/handler/ScrollWheelZoomHandler.js +98 -0
- package/src/map/handler/TapHoldHandler.js +111 -0
- package/src/map/index.js +8 -0
- package/src/maplair.css +730 -0
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import {Layer} from '../Layer.js';
|
|
2
|
+
import * as Util from '../../core/Util.js';
|
|
3
|
+
|
|
4
|
+
/*
|
|
5
|
+
* @class Path
|
|
6
|
+
* @inherits Interactive layer
|
|
7
|
+
*
|
|
8
|
+
* An abstract class that contains options and constants shared between vector
|
|
9
|
+
* overlays (Polygon, Polyline, Circle). Do not use it directly. Extends `Layer`.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
export class Path extends Layer {
|
|
13
|
+
|
|
14
|
+
static {
|
|
15
|
+
// @section
|
|
16
|
+
// @aka Path options
|
|
17
|
+
this.setDefaultOptions({
|
|
18
|
+
// @option stroke: Boolean = true
|
|
19
|
+
// Whether to draw stroke along the path. Set it to `false` to disable borders on polygons or circles.
|
|
20
|
+
stroke: true,
|
|
21
|
+
|
|
22
|
+
// @option color: String = '#3388ff'
|
|
23
|
+
// Stroke color
|
|
24
|
+
color: '#3388ff',
|
|
25
|
+
|
|
26
|
+
// @option weight: Number = 3
|
|
27
|
+
// Stroke width in pixels
|
|
28
|
+
weight: 3,
|
|
29
|
+
|
|
30
|
+
// @option opacity: Number = 1.0
|
|
31
|
+
// Stroke opacity
|
|
32
|
+
opacity: 1,
|
|
33
|
+
|
|
34
|
+
// @option lineCap: String= 'round'
|
|
35
|
+
// A string that defines [shape to be used at the end](https://developer.mozilla.org/docs/Web/SVG/Attribute/stroke-linecap) of the stroke.
|
|
36
|
+
lineCap: 'round',
|
|
37
|
+
|
|
38
|
+
// @option lineJoin: String = 'round'
|
|
39
|
+
// A string that defines [shape to be used at the corners](https://developer.mozilla.org/docs/Web/SVG/Attribute/stroke-linejoin) of the stroke.
|
|
40
|
+
lineJoin: 'round',
|
|
41
|
+
|
|
42
|
+
// @option dashArray: String = null
|
|
43
|
+
// A string that defines the stroke [dash pattern](https://developer.mozilla.org/docs/Web/SVG/Attribute/stroke-dasharray).
|
|
44
|
+
dashArray: null,
|
|
45
|
+
|
|
46
|
+
// @option dashOffset: String = null
|
|
47
|
+
// A string that defines the [distance into the dash pattern to start the dash](https://developer.mozilla.org/docs/Web/SVG/Attribute/stroke-dashoffset).
|
|
48
|
+
dashOffset: null,
|
|
49
|
+
|
|
50
|
+
// @option fill: Boolean = depends
|
|
51
|
+
// Whether to fill the path with color. Set it to `false` to disable filling on polygons or circles.
|
|
52
|
+
fill: false,
|
|
53
|
+
|
|
54
|
+
// @option fillColor: String = *
|
|
55
|
+
// Fill color. Defaults to the value of the [`color`](#path-color) option
|
|
56
|
+
fillColor: null,
|
|
57
|
+
|
|
58
|
+
// @option fillOpacity: Number = 0.2
|
|
59
|
+
// Fill opacity.
|
|
60
|
+
fillOpacity: 0.2,
|
|
61
|
+
|
|
62
|
+
// @option fillRule: String = 'evenodd'
|
|
63
|
+
// A string that defines [how the inside of a shape](https://developer.mozilla.org/docs/Web/SVG/Attribute/fill-rule) is determined.
|
|
64
|
+
fillRule: 'evenodd',
|
|
65
|
+
|
|
66
|
+
// className: '',
|
|
67
|
+
|
|
68
|
+
// Option inherited from "Interactive layer" abstract class
|
|
69
|
+
interactive: true,
|
|
70
|
+
|
|
71
|
+
// @option bubblingPointerEvents: Boolean = true
|
|
72
|
+
// When `true`, a pointer event on this path will trigger the same event on the map
|
|
73
|
+
// (unless [`DomEvent.stopPropagation`](#domevent-stoppropagation) is used).
|
|
74
|
+
bubblingPointerEvents: true
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
beforeAdd(map) {
|
|
79
|
+
// Renderer is set here because we need to call renderer.getEvents
|
|
80
|
+
// before this.getEvents.
|
|
81
|
+
this._renderer = map.getRenderer(this);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
onAdd() {
|
|
85
|
+
this._renderer._initPath(this);
|
|
86
|
+
this._reset();
|
|
87
|
+
this._renderer._addPath(this);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
onRemove() {
|
|
91
|
+
this._renderer._removePath(this);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// @method redraw(): this
|
|
95
|
+
// Redraws the layer. Sometimes useful after you changed the coordinates that the path uses.
|
|
96
|
+
redraw() {
|
|
97
|
+
if (this._map) {
|
|
98
|
+
this._renderer._updatePath(this);
|
|
99
|
+
}
|
|
100
|
+
return this;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// @method setStyle(style: Path options): this
|
|
104
|
+
// Changes the appearance of a Path based on the options in the `Path options` object.
|
|
105
|
+
setStyle(style) {
|
|
106
|
+
Util.setOptions(this, style);
|
|
107
|
+
if (this._renderer) {
|
|
108
|
+
this._renderer._updateStyle(this);
|
|
109
|
+
if (this.options.stroke && style && Object.hasOwn(style, 'weight')) {
|
|
110
|
+
this._updateBounds();
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
return this;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// @method bringToFront(): this
|
|
117
|
+
// Brings the layer to the top of all path layers.
|
|
118
|
+
bringToFront() {
|
|
119
|
+
this._renderer?._bringToFront(this);
|
|
120
|
+
return this;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// @method bringToBack(): this
|
|
124
|
+
// Brings the layer to the bottom of all path layers.
|
|
125
|
+
bringToBack() {
|
|
126
|
+
this._renderer?._bringToBack(this);
|
|
127
|
+
return this;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
getElement() {
|
|
131
|
+
return this._path;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
_reset() {
|
|
135
|
+
// defined in child classes
|
|
136
|
+
this._project();
|
|
137
|
+
this._update();
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
_clickTolerance() {
|
|
141
|
+
// used when doing hit detection for Canvas layers
|
|
142
|
+
return (this.options.stroke ? this.options.weight / 2 : 0) +
|
|
143
|
+
(this._renderer.options.tolerance || 0);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import {Polyline} from './Polyline.js';
|
|
2
|
+
import {LatLng} from '../../geo/LatLng.js';
|
|
3
|
+
import * as LineUtil from '../../geometry/LineUtil.js';
|
|
4
|
+
import {Point} from '../../geometry/Point.js';
|
|
5
|
+
import {Bounds} from '../../geometry/Bounds.js';
|
|
6
|
+
import * as PolyUtil from '../../geometry/PolyUtil.js';
|
|
7
|
+
|
|
8
|
+
/*
|
|
9
|
+
* @class Polygon
|
|
10
|
+
* @inherits Polyline
|
|
11
|
+
*
|
|
12
|
+
* A class for drawing polygon overlays on a map. Extends `Polyline`.
|
|
13
|
+
*
|
|
14
|
+
* Note that points you pass when creating a polygon shouldn't have an additional last point equal to the first one — it's better to filter out such points.
|
|
15
|
+
*
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
*
|
|
19
|
+
* ```js
|
|
20
|
+
* // create a red polygon from an array of LatLng points
|
|
21
|
+
* const latlngs = [[37, -109.05],[41, -109.03],[41, -102.05],[37, -102.04]];
|
|
22
|
+
*
|
|
23
|
+
* const polygon = new Polygon(latlngs, {color: 'red'}).addTo(map);
|
|
24
|
+
*
|
|
25
|
+
* // zoom the map to the polygon
|
|
26
|
+
* map.fitBounds(polygon.getBounds());
|
|
27
|
+
* ```
|
|
28
|
+
*
|
|
29
|
+
* You can also pass an array of arrays of latlngs, with the first array representing the outer shape and the other arrays representing holes in the outer shape:
|
|
30
|
+
*
|
|
31
|
+
* ```js
|
|
32
|
+
* const latlngs = [
|
|
33
|
+
* [[37, -109.05],[41, -109.03],[41, -102.05],[37, -102.04]], // outer ring
|
|
34
|
+
* [[37.29, -108.58],[40.71, -108.58],[40.71, -102.50],[37.29, -102.50]] // hole
|
|
35
|
+
* ];
|
|
36
|
+
* ```
|
|
37
|
+
*
|
|
38
|
+
* Additionally, you can pass a multi-dimensional array to represent a MultiPolygon shape.
|
|
39
|
+
*
|
|
40
|
+
* ```js
|
|
41
|
+
* const latlngs = [
|
|
42
|
+
* [ // first polygon
|
|
43
|
+
* [[37, -109.05],[41, -109.03],[41, -102.05],[37, -102.04]], // outer ring
|
|
44
|
+
* [[37.29, -108.58],[40.71, -108.58],[40.71, -102.50],[37.29, -102.50]] // hole
|
|
45
|
+
* ],
|
|
46
|
+
* [ // second polygon
|
|
47
|
+
* [[41, -111.03],[45, -111.04],[45, -104.05],[41, -104.05]]
|
|
48
|
+
* ]
|
|
49
|
+
* ];
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
52
|
+
|
|
53
|
+
// @constructor Polygon(latlngs: LatLng[], options?: Polyline options)
|
|
54
|
+
export class Polygon extends Polyline {
|
|
55
|
+
|
|
56
|
+
static {
|
|
57
|
+
this.setDefaultOptions({
|
|
58
|
+
fill: true
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
constructor(...args) {
|
|
63
|
+
super(...args);
|
|
64
|
+
this.callInitHooks(Polygon);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
isEmpty() {
|
|
68
|
+
return !this._latlngs.length || !this._latlngs[0].length;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// @method getCenter(): LatLng
|
|
72
|
+
// Returns the center ([centroid](http://en.wikipedia.org/wiki/Centroid)) of the Polygon.
|
|
73
|
+
getCenter() {
|
|
74
|
+
// throws error when not yet added to map as this center calculation requires projected coordinates
|
|
75
|
+
if (!this._map) {
|
|
76
|
+
throw new Error('Must add layer to map before using getCenter()');
|
|
77
|
+
}
|
|
78
|
+
return PolyUtil.polygonCenter(this._defaultShape(), this._map.options.crs);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
_convertLatLngs(latlngs) {
|
|
82
|
+
const result = super._convertLatLngs(latlngs),
|
|
83
|
+
len = result.length;
|
|
84
|
+
|
|
85
|
+
// remove last point if it equals first one
|
|
86
|
+
if (len >= 2 && result[0] instanceof LatLng && result[0].equals(result[len - 1])) {
|
|
87
|
+
result.pop();
|
|
88
|
+
}
|
|
89
|
+
return result;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
_setLatLngs(latlngs) {
|
|
93
|
+
super._setLatLngs(latlngs);
|
|
94
|
+
if (LineUtil.isFlat(this._latlngs)) {
|
|
95
|
+
this._latlngs = [this._latlngs];
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
_defaultShape() {
|
|
100
|
+
return LineUtil.isFlat(this._latlngs[0]) ? this._latlngs[0] : this._latlngs[0][0];
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
_clipPoints() {
|
|
104
|
+
// polygons need a different clipping algorithm so we redefine that
|
|
105
|
+
|
|
106
|
+
let bounds = this._renderer._bounds;
|
|
107
|
+
const w = this.options.weight,
|
|
108
|
+
p = new Point(w, w);
|
|
109
|
+
|
|
110
|
+
// increase clip padding by stroke width to avoid stroke on clip edges
|
|
111
|
+
bounds = new Bounds(bounds.min.subtract(p), bounds.max.add(p));
|
|
112
|
+
|
|
113
|
+
this._parts = [];
|
|
114
|
+
if (!this._pxBounds || !this._pxBounds.intersects(bounds)) {
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
if (this.options.noClip) {
|
|
119
|
+
this._parts = this._rings;
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
for (const ring of this._rings) {
|
|
124
|
+
const clipped = PolyUtil.clipPolygon(ring, bounds, true);
|
|
125
|
+
if (clipped.length) {
|
|
126
|
+
this._parts.push(clipped);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
_updatePath() {
|
|
132
|
+
this._renderer._updatePoly(this, true);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
// Needed by the `Canvas` renderer for interactivity
|
|
136
|
+
_containsPoint(p) {
|
|
137
|
+
let inside = false,
|
|
138
|
+
part, p1, p2, i, j, k, len, len2;
|
|
139
|
+
|
|
140
|
+
if (!this._pxBounds || !this._pxBounds.contains(p)) { return false; }
|
|
141
|
+
|
|
142
|
+
// ray casting algorithm for detecting if point is in polygon
|
|
143
|
+
for (i = 0, len = this._parts.length; i < len; i++) {
|
|
144
|
+
part = this._parts[i];
|
|
145
|
+
|
|
146
|
+
for (j = 0, len2 = part.length, k = len2 - 1; j < len2; k = j++) {
|
|
147
|
+
p1 = part[j];
|
|
148
|
+
p2 = part[k];
|
|
149
|
+
|
|
150
|
+
if (((p1.y > p.y) !== (p2.y > p.y)) && (p.x < (p2.x - p1.x) * (p.y - p1.y) / (p2.y - p1.y) + p1.x)) {
|
|
151
|
+
inside = !inside;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
// also check if it's on polygon stroke
|
|
157
|
+
return inside || super._containsPoint(p, true);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
}
|
|
@@ -0,0 +1,296 @@
|
|
|
1
|
+
import {Path} from './Path.js';
|
|
2
|
+
import * as Util from '../../core/Util.js';
|
|
3
|
+
import * as LineUtil from '../../geometry/LineUtil.js';
|
|
4
|
+
import {LatLng} from '../../geo/LatLng.js';
|
|
5
|
+
import {LatLngBounds} from '../../geo/LatLngBounds.js';
|
|
6
|
+
import {Bounds} from '../../geometry/Bounds.js';
|
|
7
|
+
import {Point} from '../../geometry/Point.js';
|
|
8
|
+
|
|
9
|
+
/*
|
|
10
|
+
* @class Polyline
|
|
11
|
+
* @inherits Path
|
|
12
|
+
*
|
|
13
|
+
* A class for drawing polyline overlays on a map. Extends `Path`.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
*
|
|
17
|
+
* ```js
|
|
18
|
+
* // create a red polyline from an array of LatLng points
|
|
19
|
+
* const latlngs = [
|
|
20
|
+
* [45.51, -122.68],
|
|
21
|
+
* [37.77, -122.43],
|
|
22
|
+
* [34.04, -118.2]
|
|
23
|
+
* ];
|
|
24
|
+
*
|
|
25
|
+
* const polyline = new Polyline(latlngs, {color: 'red'}).addTo(map);
|
|
26
|
+
*
|
|
27
|
+
* // zoom the map to the polyline
|
|
28
|
+
* map.fitBounds(polyline.getBounds());
|
|
29
|
+
* ```
|
|
30
|
+
*
|
|
31
|
+
* You can also pass a multi-dimensional array to represent a `MultiPolyline` shape:
|
|
32
|
+
*
|
|
33
|
+
* ```js
|
|
34
|
+
* // create a red polyline from an array of arrays of LatLng points
|
|
35
|
+
* const latlngs = [
|
|
36
|
+
* [[45.51, -122.68],
|
|
37
|
+
* [37.77, -122.43],
|
|
38
|
+
* [34.04, -118.2]],
|
|
39
|
+
* [[40.78, -73.91],
|
|
40
|
+
* [41.83, -87.62],
|
|
41
|
+
* [32.76, -96.72]]
|
|
42
|
+
* ];
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
|
|
46
|
+
// @constructor Polyline(latlngs: LatLng[], options?: Polyline options)
|
|
47
|
+
// Instantiates a polyline object given an array of geographical points and
|
|
48
|
+
// optionally an options object. You can create a `Polyline` object with
|
|
49
|
+
// multiple separate lines (`MultiPolyline`) by passing an array of arrays
|
|
50
|
+
// of geographic points.
|
|
51
|
+
export class Polyline extends Path {
|
|
52
|
+
|
|
53
|
+
static {
|
|
54
|
+
// @section
|
|
55
|
+
// @aka Polyline options
|
|
56
|
+
this.setDefaultOptions({
|
|
57
|
+
// @option smoothFactor: Number = 0.5
|
|
58
|
+
// How much to simplify the polyline on each zoom level (Douglas–Peucker
|
|
59
|
+
// epsilon, in pixels). Higher values mean faster rendering but less
|
|
60
|
+
// accuracy; lower values mean more accuracy but slower rendering.
|
|
61
|
+
smoothFactor: 0.5,
|
|
62
|
+
|
|
63
|
+
// @option noClip: Boolean = false
|
|
64
|
+
// Disable polyline clipping.
|
|
65
|
+
noClip: false
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
constructor(latlngs, options) {
|
|
70
|
+
super();
|
|
71
|
+
Util.setOptions(this, options);
|
|
72
|
+
this._setLatLngs(latlngs);
|
|
73
|
+
|
|
74
|
+
this.callInitHooks(Polyline);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// @method getLatLngs(): LatLng[]
|
|
78
|
+
// Returns an array of the points in the path, or nested arrays of points in case of multi-polyline.
|
|
79
|
+
getLatLngs() {
|
|
80
|
+
return this._latlngs;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// @method setLatLngs(latlngs: LatLng[]): this
|
|
84
|
+
// Replaces all the points in the polyline with the given array of geographical points.
|
|
85
|
+
setLatLngs(latlngs) {
|
|
86
|
+
this._setLatLngs(latlngs);
|
|
87
|
+
return this.redraw();
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// @method isEmpty(): Boolean
|
|
91
|
+
// Returns `true` if the Polyline has no LatLngs.
|
|
92
|
+
isEmpty() {
|
|
93
|
+
return !this._latlngs.length;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// @method closestLayerPoint(p: Point): Point
|
|
97
|
+
// Returns the point closest to `p` on the Polyline.
|
|
98
|
+
closestLayerPoint(p) {
|
|
99
|
+
p = new Point(p);
|
|
100
|
+
let minDistance = Infinity,
|
|
101
|
+
minPoint = null,
|
|
102
|
+
p1, p2;
|
|
103
|
+
const closest = LineUtil._sqClosestPointOnSegment;
|
|
104
|
+
|
|
105
|
+
for (const points of this._parts) {
|
|
106
|
+
for (let i = 1, len = points.length; i < len; i++) {
|
|
107
|
+
p1 = points[i - 1];
|
|
108
|
+
p2 = points[i];
|
|
109
|
+
|
|
110
|
+
const sqDist = closest(p, p1, p2, true);
|
|
111
|
+
|
|
112
|
+
if (sqDist < minDistance) {
|
|
113
|
+
minDistance = sqDist;
|
|
114
|
+
minPoint = closest(p, p1, p2);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
if (minPoint) {
|
|
119
|
+
minPoint.distance = Math.sqrt(minDistance);
|
|
120
|
+
}
|
|
121
|
+
return minPoint;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// @method getCenter(): LatLng
|
|
125
|
+
// Returns the center ([centroid](https://en.wikipedia.org/wiki/Centroid)) of the polyline.
|
|
126
|
+
getCenter() {
|
|
127
|
+
// throws error when not yet added to map as this center calculation requires projected coordinates
|
|
128
|
+
if (!this._map) {
|
|
129
|
+
throw new Error('Must add layer to map before using getCenter()');
|
|
130
|
+
}
|
|
131
|
+
return LineUtil.polylineCenter(this._defaultShape(), this._map.options.crs);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// @method getBounds(): LatLngBounds
|
|
135
|
+
// Returns the `LatLngBounds` of the path.
|
|
136
|
+
getBounds() {
|
|
137
|
+
return this._bounds;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// @method addLatLng(latlng: LatLng, latlngs?: LatLng[]): this
|
|
141
|
+
// Adds a given point to the polyline. By default, adds to the first ring of
|
|
142
|
+
// the polyline in case of a multi-polyline, but can be overridden by passing
|
|
143
|
+
// a specific ring as a LatLng array (that you can earlier access with [`getLatLngs`](#polyline-getlatlngs)).
|
|
144
|
+
addLatLng(latlng, latlngs) {
|
|
145
|
+
latlngs ??= this._defaultShape();
|
|
146
|
+
latlng = new LatLng(latlng);
|
|
147
|
+
latlngs.push(latlng);
|
|
148
|
+
this._bounds.extend(latlng);
|
|
149
|
+
return this.redraw();
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
_setLatLngs(latlngs) {
|
|
153
|
+
this._bounds = new LatLngBounds();
|
|
154
|
+
this._latlngs = this._convertLatLngs(latlngs);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
_defaultShape() {
|
|
158
|
+
return LineUtil.isFlat(this._latlngs) ? this._latlngs : this._latlngs[0];
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
// recursively convert latlngs input into actual LatLng instances; calculate bounds along the way
|
|
162
|
+
_convertLatLngs(latlngs) {
|
|
163
|
+
const result = [],
|
|
164
|
+
flat = LineUtil.isFlat(latlngs);
|
|
165
|
+
|
|
166
|
+
for (let i = 0, len = latlngs.length; i < len; i++) {
|
|
167
|
+
if (flat) {
|
|
168
|
+
result[i] = new LatLng(latlngs[i]);
|
|
169
|
+
this._bounds.extend(result[i]);
|
|
170
|
+
} else {
|
|
171
|
+
result[i] = this._convertLatLngs(latlngs[i]);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
return result;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
_project() {
|
|
179
|
+
const pxBounds = new Bounds();
|
|
180
|
+
this._rings = [];
|
|
181
|
+
this._projectLatlngs(this._latlngs, this._rings, pxBounds);
|
|
182
|
+
|
|
183
|
+
if (this._bounds.isValid() && pxBounds.isValid()) {
|
|
184
|
+
this._rawPxBounds = pxBounds;
|
|
185
|
+
this._updateBounds();
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
_updateBounds() {
|
|
190
|
+
const w = this._clickTolerance(),
|
|
191
|
+
p = new Point(w, w);
|
|
192
|
+
|
|
193
|
+
if (!this._rawPxBounds) {
|
|
194
|
+
return;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
this._pxBounds = new Bounds([
|
|
198
|
+
this._rawPxBounds.min.subtract(p),
|
|
199
|
+
this._rawPxBounds.max.add(p)
|
|
200
|
+
]);
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
// recursively turns latlngs into a set of rings with projected coordinates
|
|
204
|
+
_projectLatlngs(latlngs, result, projectedBounds) {
|
|
205
|
+
const flat = latlngs[0] instanceof LatLng;
|
|
206
|
+
|
|
207
|
+
if (flat) {
|
|
208
|
+
const ring = latlngs.map(latlng => this._map.latLngToLayerPoint(latlng));
|
|
209
|
+
ring.forEach(r => projectedBounds.extend(r));
|
|
210
|
+
result.push(ring);
|
|
211
|
+
} else {
|
|
212
|
+
latlngs.forEach(latlng => this._projectLatlngs(latlng, result, projectedBounds));
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
// clip polyline by renderer bounds so that we have less to render for performance
|
|
217
|
+
_clipPoints() {
|
|
218
|
+
const bounds = this._renderer._bounds;
|
|
219
|
+
|
|
220
|
+
this._parts = [];
|
|
221
|
+
if (!this._pxBounds || !this._pxBounds.intersects(bounds)) {
|
|
222
|
+
return;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
if (this.options.noClip) {
|
|
226
|
+
this._parts = this._rings;
|
|
227
|
+
return;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
const parts = this._parts;
|
|
231
|
+
let i, j, k, len, len2, segment, points;
|
|
232
|
+
|
|
233
|
+
for (i = 0, k = 0, len = this._rings.length; i < len; i++) {
|
|
234
|
+
points = this._rings[i];
|
|
235
|
+
|
|
236
|
+
for (j = 0, len2 = points.length; j < len2 - 1; j++) {
|
|
237
|
+
segment = LineUtil.clipSegment(points[j], points[j + 1], bounds, j, true);
|
|
238
|
+
|
|
239
|
+
if (!segment) { continue; }
|
|
240
|
+
|
|
241
|
+
parts[k] ??= [];
|
|
242
|
+
parts[k].push(segment[0]);
|
|
243
|
+
|
|
244
|
+
// if segment goes out of screen, or it's the last one, it's the end of the line part
|
|
245
|
+
if ((segment[1] !== points[j + 1]) || (j === len2 - 2)) {
|
|
246
|
+
parts[k].push(segment[1]);
|
|
247
|
+
k++;
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
// simplify each clipped part of the polyline for performance
|
|
254
|
+
_simplifyPoints() {
|
|
255
|
+
const parts = this._parts,
|
|
256
|
+
tolerance = this.options.smoothFactor;
|
|
257
|
+
|
|
258
|
+
for (let i = 0, len = parts.length; i < len; i++) {
|
|
259
|
+
parts[i] = LineUtil.simplify(parts[i], tolerance);
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
_update() {
|
|
264
|
+
if (!this._map) { return; }
|
|
265
|
+
|
|
266
|
+
this._clipPoints();
|
|
267
|
+
this._simplifyPoints();
|
|
268
|
+
this._updatePath();
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
_updatePath() {
|
|
272
|
+
this._renderer._updatePoly(this);
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
// Needed by the `Canvas` renderer for interactivity
|
|
276
|
+
_containsPoint(p, closed) {
|
|
277
|
+
let i, j, k, len, len2, part;
|
|
278
|
+
const w = this._clickTolerance();
|
|
279
|
+
|
|
280
|
+
if (!this._pxBounds || !this._pxBounds.contains(p)) { return false; }
|
|
281
|
+
|
|
282
|
+
// hit detection for polylines
|
|
283
|
+
for (i = 0, len = this._parts.length; i < len; i++) {
|
|
284
|
+
part = this._parts[i];
|
|
285
|
+
|
|
286
|
+
for (j = 0, len2 = part.length, k = len2 - 1; j < len2; k = j++) {
|
|
287
|
+
if (!closed && (j === 0)) { continue; }
|
|
288
|
+
|
|
289
|
+
if (LineUtil.pointToSegmentDistance(p, part[k], part[j]) <= w) {
|
|
290
|
+
return true;
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
return false;
|
|
295
|
+
}
|
|
296
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import {Polygon} from './Polygon.js';
|
|
2
|
+
import {LatLngBounds} from '../../geo/LatLngBounds.js';
|
|
3
|
+
|
|
4
|
+
/*
|
|
5
|
+
* Rectangle extends Polygon and creates a rectangle when passed a LatLngBounds object.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/*
|
|
9
|
+
* @class Rectangle
|
|
10
|
+
* @inherits Polygon
|
|
11
|
+
*
|
|
12
|
+
* A class for drawing rectangle overlays on a map. Extends `Polygon`.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
*
|
|
16
|
+
* ```js
|
|
17
|
+
* // define rectangle geographical bounds
|
|
18
|
+
* const bounds = [[54.559322, -5.767822], [56.1210604, -3.021240]];
|
|
19
|
+
*
|
|
20
|
+
* // create an orange rectangle
|
|
21
|
+
* new Rectangle(bounds, {color: "#ff7800", weight: 1}).addTo(map);
|
|
22
|
+
*
|
|
23
|
+
* // zoom the map to the rectangle bounds
|
|
24
|
+
* map.fitBounds(bounds);
|
|
25
|
+
* ```
|
|
26
|
+
*
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
// @constructor Rectangle(latLngBounds: LatLngBounds, options?: Polyline options)
|
|
30
|
+
export class Rectangle extends Polygon {
|
|
31
|
+
constructor(latLngBounds, options) {
|
|
32
|
+
super(Rectangle._boundsToLatLngs(latLngBounds), options);
|
|
33
|
+
|
|
34
|
+
this.callInitHooks(Rectangle);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// @method setBounds(latLngBounds: LatLngBounds): this
|
|
38
|
+
// Redraws the rectangle with the passed bounds.
|
|
39
|
+
setBounds(latLngBounds) {
|
|
40
|
+
return this.setLatLngs(Rectangle._boundsToLatLngs(latLngBounds));
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
static _boundsToLatLngs(latLngBounds) {
|
|
44
|
+
latLngBounds = new LatLngBounds(latLngBounds);
|
|
45
|
+
return [
|
|
46
|
+
latLngBounds.getSouthWest(),
|
|
47
|
+
latLngBounds.getNorthWest(),
|
|
48
|
+
latLngBounds.getNorthEast(),
|
|
49
|
+
latLngBounds.getSouthEast()
|
|
50
|
+
];
|
|
51
|
+
}
|
|
52
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import {Canvas} from './Canvas.js';
|
|
2
|
+
import {SVG} from './SVG.js';
|
|
3
|
+
|
|
4
|
+
// Registers `getRenderer()` and related methods on the given map class, called by `MaplairMap` itself.
|
|
5
|
+
export function register(MaplairMap) {
|
|
6
|
+
MaplairMap.include({
|
|
7
|
+
// @namespace MaplairMap; @method getRenderer(layer: Path): Renderer
|
|
8
|
+
// Returns the instance of `Renderer` that should be used to render the given
|
|
9
|
+
// `Path`. It will ensure that the `renderer` options of the map and paths
|
|
10
|
+
// are respected, and that the renderers do exist on the map.
|
|
11
|
+
getRenderer(layer) {
|
|
12
|
+
// @namespace Path; @option renderer: Renderer
|
|
13
|
+
// Use this specific instance of `Renderer` for this path. Takes
|
|
14
|
+
// precedence over the map's [default renderer](#map-renderer).
|
|
15
|
+
// If set, it will override the `pane` option of the path.
|
|
16
|
+
let renderer = layer.options.renderer ?? this._getPaneRenderer(layer.options.pane) ?? this.options.renderer ?? this._renderer;
|
|
17
|
+
|
|
18
|
+
if (!renderer) {
|
|
19
|
+
renderer = this._renderer = this._createRenderer();
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
if (!this.hasLayer(renderer)) {
|
|
23
|
+
this.addLayer(renderer);
|
|
24
|
+
}
|
|
25
|
+
return renderer;
|
|
26
|
+
},
|
|
27
|
+
|
|
28
|
+
_getPaneRenderer(name) {
|
|
29
|
+
if (name === 'overlayPane' || name === undefined) {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
let renderer = this._paneRenderers[name];
|
|
34
|
+
if (renderer === undefined) {
|
|
35
|
+
renderer = this._createRenderer({pane: name});
|
|
36
|
+
this._paneRenderers[name] = renderer;
|
|
37
|
+
}
|
|
38
|
+
return renderer;
|
|
39
|
+
},
|
|
40
|
+
|
|
41
|
+
_createRenderer(options) {
|
|
42
|
+
// @namespace MaplairMap; @option preferCanvas: Boolean = false
|
|
43
|
+
// Whether `Path`s should be rendered on a `Canvas` renderer.
|
|
44
|
+
// By default, all `Path`s are rendered in a `SVG` renderer.
|
|
45
|
+
return (this.options.preferCanvas && new Canvas(options)) || new SVG(options);
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
}
|