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,479 @@
|
|
|
1
|
+
import {Renderer} from './Renderer.js';
|
|
2
|
+
import * as DomEvent from '../../dom/DomEvent.js';
|
|
3
|
+
import * as Util from '../../core/Util.js';
|
|
4
|
+
import {Bounds} from '../../geometry/Bounds.js';
|
|
5
|
+
|
|
6
|
+
const DASH_SEPARATOR_RE = /[, ]+/;
|
|
7
|
+
|
|
8
|
+
/*
|
|
9
|
+
* @class Canvas
|
|
10
|
+
* @inherits Renderer
|
|
11
|
+
*
|
|
12
|
+
* Allows vector layers to be displayed with [`<canvas>`](https://developer.mozilla.org/docs/Web/API/Canvas_API).
|
|
13
|
+
* Inherits `Renderer`.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
*
|
|
17
|
+
* Use Canvas by default for all paths in the map:
|
|
18
|
+
*
|
|
19
|
+
* ```js
|
|
20
|
+
* const map = new MaplairMap('map', {
|
|
21
|
+
* renderer: new Canvas()
|
|
22
|
+
* });
|
|
23
|
+
* ```
|
|
24
|
+
*
|
|
25
|
+
* Use a Canvas renderer with extra padding for specific vector geometries:
|
|
26
|
+
*
|
|
27
|
+
* ```js
|
|
28
|
+
* const map = new MaplairMap('map');
|
|
29
|
+
* const myRenderer = new Canvas({ padding: 0.5 });
|
|
30
|
+
* const line = new Polyline( coordinates, { renderer: myRenderer } );
|
|
31
|
+
* const circle = new Circle( center, { renderer: myRenderer, radius: 100 } );
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
|
|
35
|
+
// @constructor Canvas(options?: Renderer options)
|
|
36
|
+
// Creates a Canvas renderer with the given options.
|
|
37
|
+
export class Canvas extends Renderer {
|
|
38
|
+
|
|
39
|
+
static {
|
|
40
|
+
// @section
|
|
41
|
+
// @aka Canvas options
|
|
42
|
+
this.setDefaultOptions({
|
|
43
|
+
// @option tolerance: Number = 0
|
|
44
|
+
// How much to extend the click tolerance around a path/object on the map.
|
|
45
|
+
tolerance: 0
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
constructor(...args) {
|
|
50
|
+
super(...args);
|
|
51
|
+
this.callInitHooks(Canvas);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
getEvents() {
|
|
55
|
+
const events = super.getEvents();
|
|
56
|
+
events.viewprereset = this._onViewPreReset;
|
|
57
|
+
return events;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
_onViewPreReset() {
|
|
61
|
+
// Set a flag so that a viewprereset+moveend+viewreset only updates&redraws once
|
|
62
|
+
this._postponeUpdatePaths = true;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
onAdd(map) {
|
|
66
|
+
super.onAdd(map);
|
|
67
|
+
|
|
68
|
+
// Redraw vectors since canvas is cleared upon removal,
|
|
69
|
+
// in case of removing the renderer itself from the map.
|
|
70
|
+
this._draw();
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
onRemove() {
|
|
74
|
+
super.onRemove();
|
|
75
|
+
|
|
76
|
+
clearTimeout(this._pointerHoverThrottleTimeout);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
_initContainer() {
|
|
80
|
+
const container = this._container = document.createElement('canvas');
|
|
81
|
+
|
|
82
|
+
DomEvent.on(container, 'pointermove', this._onPointerMove, this);
|
|
83
|
+
DomEvent.on(container, 'click dblclick pointerdown pointerup contextmenu', this._onClick, this);
|
|
84
|
+
DomEvent.on(container, 'pointerout', this._handlePointerOut, this);
|
|
85
|
+
container['_maplair_disable_events'] = true;
|
|
86
|
+
|
|
87
|
+
this._ctx = container.getContext('2d');
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
_destroyContainer() {
|
|
91
|
+
cancelAnimationFrame(this._redrawRequest);
|
|
92
|
+
this._redrawRequest = null;
|
|
93
|
+
delete this._ctx;
|
|
94
|
+
super._destroyContainer();
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
_resizeContainer() {
|
|
98
|
+
const size = super._resizeContainer();
|
|
99
|
+
const m = this._ctxScale = window.devicePixelRatio;
|
|
100
|
+
|
|
101
|
+
// set canvas size (also clearing it); use double size on retina
|
|
102
|
+
this._container.width = m * size.x;
|
|
103
|
+
this._container.height = m * size.y;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
_updatePaths() {
|
|
107
|
+
if (this._postponeUpdatePaths) { return; }
|
|
108
|
+
|
|
109
|
+
this._redrawBounds = null;
|
|
110
|
+
for (const layer of Object.values(this._layers)) {
|
|
111
|
+
layer._update();
|
|
112
|
+
}
|
|
113
|
+
this._redraw();
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
_update() {
|
|
117
|
+
if (this._map._animatingZoom && this._bounds) { return; }
|
|
118
|
+
|
|
119
|
+
const b = this._bounds,
|
|
120
|
+
s = this._ctxScale;
|
|
121
|
+
|
|
122
|
+
// translate so we use the same path coordinates after canvas element moves
|
|
123
|
+
this._ctx.setTransform(
|
|
124
|
+
s, 0, 0, s,
|
|
125
|
+
-b.min.x * s,
|
|
126
|
+
-b.min.y * s);
|
|
127
|
+
|
|
128
|
+
// Tell paths to redraw themselves
|
|
129
|
+
this.fire('update');
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
_reset() {
|
|
133
|
+
super._reset();
|
|
134
|
+
|
|
135
|
+
if (this._postponeUpdatePaths) {
|
|
136
|
+
this._postponeUpdatePaths = false;
|
|
137
|
+
this._updatePaths();
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
_initPath(layer) {
|
|
142
|
+
this._updateDashArray(layer);
|
|
143
|
+
this._layers[Util.stamp(layer)] = layer;
|
|
144
|
+
|
|
145
|
+
const order = layer._order = {
|
|
146
|
+
layer,
|
|
147
|
+
prev: this._drawLast,
|
|
148
|
+
next: null
|
|
149
|
+
};
|
|
150
|
+
if (this._drawLast) { this._drawLast.next = order; }
|
|
151
|
+
this._drawLast = order;
|
|
152
|
+
this._drawFirst ??= this._drawLast;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
_addPath(layer) {
|
|
156
|
+
this._requestRedraw(layer);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
_removePath(layer) {
|
|
160
|
+
const order = layer._order;
|
|
161
|
+
const next = order.next;
|
|
162
|
+
const prev = order.prev;
|
|
163
|
+
|
|
164
|
+
if (next) {
|
|
165
|
+
next.prev = prev;
|
|
166
|
+
} else {
|
|
167
|
+
this._drawLast = prev;
|
|
168
|
+
}
|
|
169
|
+
if (prev) {
|
|
170
|
+
prev.next = next;
|
|
171
|
+
} else {
|
|
172
|
+
this._drawFirst = next;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
delete layer._order;
|
|
176
|
+
|
|
177
|
+
delete this._layers[Util.stamp(layer)];
|
|
178
|
+
|
|
179
|
+
this._requestRedraw(layer);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
_updatePath(layer) {
|
|
183
|
+
// Redraw the union of the layer's old pixel
|
|
184
|
+
// bounds and the new pixel bounds.
|
|
185
|
+
this._extendRedrawBounds(layer);
|
|
186
|
+
layer._project();
|
|
187
|
+
layer._update();
|
|
188
|
+
// The redraw will extend the redraw bounds
|
|
189
|
+
// with the new pixel bounds.
|
|
190
|
+
this._requestRedraw(layer);
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
_updateStyle(layer) {
|
|
194
|
+
this._updateDashArray(layer);
|
|
195
|
+
this._requestRedraw(layer);
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
_updateDashArray(layer) {
|
|
199
|
+
if (typeof layer.options.dashArray === 'string') {
|
|
200
|
+
const parts = layer.options.dashArray.split(DASH_SEPARATOR_RE);
|
|
201
|
+
// Ignore dash array containing invalid lengths
|
|
202
|
+
layer.options._dashArray = parts.map(n => Number(n)).filter(n => !isNaN(n));
|
|
203
|
+
} else {
|
|
204
|
+
layer.options._dashArray = layer.options.dashArray;
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
_requestRedraw(layer) {
|
|
209
|
+
if (!this._map) { return; }
|
|
210
|
+
|
|
211
|
+
this._extendRedrawBounds(layer);
|
|
212
|
+
this._redrawRequest ??= requestAnimationFrame(this._redraw.bind(this));
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
_extendRedrawBounds(layer) {
|
|
216
|
+
if (layer._pxBounds) {
|
|
217
|
+
const padding = (layer.options.weight ?? 0) + 1;
|
|
218
|
+
this._redrawBounds ??= new Bounds();
|
|
219
|
+
this._redrawBounds.extend(layer._pxBounds.min.subtract([padding, padding]));
|
|
220
|
+
this._redrawBounds.extend(layer._pxBounds.max.add([padding, padding]));
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
_redraw() {
|
|
225
|
+
this._redrawRequest = null;
|
|
226
|
+
|
|
227
|
+
if (this._redrawBounds) {
|
|
228
|
+
this._redrawBounds.min._floor();
|
|
229
|
+
this._redrawBounds.max._ceil();
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
this._clear(); // clear layers in redraw bounds
|
|
233
|
+
this._draw(); // draw layers
|
|
234
|
+
|
|
235
|
+
this._redrawBounds = null;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
_clear() {
|
|
239
|
+
const bounds = this._redrawBounds;
|
|
240
|
+
if (bounds) {
|
|
241
|
+
const size = bounds.getSize();
|
|
242
|
+
this._ctx.clearRect(bounds.min.x, bounds.min.y, size.x, size.y);
|
|
243
|
+
} else {
|
|
244
|
+
this._ctx.save();
|
|
245
|
+
this._ctx.setTransform(1, 0, 0, 1, 0, 0);
|
|
246
|
+
this._ctx.clearRect(0, 0, this._container.width, this._container.height);
|
|
247
|
+
this._ctx.restore();
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
_draw() {
|
|
252
|
+
let layer;
|
|
253
|
+
const bounds = this._redrawBounds;
|
|
254
|
+
this._ctx.save();
|
|
255
|
+
if (bounds) {
|
|
256
|
+
const size = bounds.getSize();
|
|
257
|
+
this._ctx.beginPath();
|
|
258
|
+
this._ctx.rect(bounds.min.x, bounds.min.y, size.x, size.y);
|
|
259
|
+
this._ctx.clip();
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
this._drawing = true;
|
|
263
|
+
|
|
264
|
+
for (let order = this._drawFirst; order; order = order.next) {
|
|
265
|
+
layer = order.layer;
|
|
266
|
+
if (!bounds || (layer._pxBounds && layer._pxBounds.intersects(bounds))) {
|
|
267
|
+
layer._updatePath();
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
this._drawing = false;
|
|
272
|
+
|
|
273
|
+
this._ctx.restore(); // Restore state before clipping.
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
_updatePoly(layer, closed) {
|
|
277
|
+
if (!this._drawing) { return; }
|
|
278
|
+
|
|
279
|
+
const parts = layer._parts,
|
|
280
|
+
ctx = this._ctx;
|
|
281
|
+
|
|
282
|
+
if (!parts.length) { return; }
|
|
283
|
+
|
|
284
|
+
ctx.beginPath();
|
|
285
|
+
|
|
286
|
+
parts.forEach((p0) => {
|
|
287
|
+
p0.forEach((p, j) => {
|
|
288
|
+
ctx[j ? 'lineTo' : 'moveTo'](p.x, p.y);
|
|
289
|
+
});
|
|
290
|
+
if (closed) {
|
|
291
|
+
ctx.closePath();
|
|
292
|
+
}
|
|
293
|
+
});
|
|
294
|
+
|
|
295
|
+
this._fillStroke(ctx, layer);
|
|
296
|
+
|
|
297
|
+
// TODO optimization: 1 fill/stroke for all features with equal style instead of 1 for each feature
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
_updateCircle(layer) {
|
|
301
|
+
|
|
302
|
+
if (!this._drawing || layer._empty()) { return; }
|
|
303
|
+
|
|
304
|
+
const p = layer._point,
|
|
305
|
+
ctx = this._ctx,
|
|
306
|
+
r = Math.max(Math.round(layer._pxRadius), 1),
|
|
307
|
+
s = (Math.max(Math.round(layer._pxRadiusY), 1) || r) / r;
|
|
308
|
+
|
|
309
|
+
if (s !== 1) {
|
|
310
|
+
ctx.save();
|
|
311
|
+
ctx.scale(1, s);
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
ctx.beginPath();
|
|
315
|
+
ctx.arc(p.x, p.y / s, r, 0, Math.PI * 2, false);
|
|
316
|
+
|
|
317
|
+
if (s !== 1) {
|
|
318
|
+
ctx.restore();
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
this._fillStroke(ctx, layer);
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
_fillStroke(ctx, layer) {
|
|
325
|
+
const options = layer.options;
|
|
326
|
+
|
|
327
|
+
if (options.fill) {
|
|
328
|
+
ctx.globalAlpha = options.fillOpacity;
|
|
329
|
+
ctx.fillStyle = options.fillColor ?? options.color;
|
|
330
|
+
ctx.fill(options.fillRule || 'evenodd');
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
if (options.stroke && options.weight !== 0) {
|
|
334
|
+
ctx.lineDashOffset = Number(options.dashOffset ?? 0);
|
|
335
|
+
ctx.setLineDash(options._dashArray ?? []);
|
|
336
|
+
ctx.globalAlpha = options.opacity;
|
|
337
|
+
ctx.lineWidth = options.weight;
|
|
338
|
+
ctx.strokeStyle = options.color;
|
|
339
|
+
ctx.lineCap = options.lineCap;
|
|
340
|
+
ctx.lineJoin = options.lineJoin;
|
|
341
|
+
ctx.stroke();
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
// Canvas obviously doesn't have pointer events for individual drawn objects,
|
|
346
|
+
// so we emulate that by calculating what's under the pointer on pointermove/click manually
|
|
347
|
+
|
|
348
|
+
_onClick(e) {
|
|
349
|
+
const point = this._map.pointerEventToLayerPoint(e);
|
|
350
|
+
let layer, clickedLayer;
|
|
351
|
+
|
|
352
|
+
for (let order = this._drawFirst; order; order = order.next) {
|
|
353
|
+
layer = order.layer;
|
|
354
|
+
if (layer.options.interactive && layer._containsPoint(point)) {
|
|
355
|
+
if (!(e.type === 'click' || e.type === 'preclick') || !this._map._draggableMoved(layer)) {
|
|
356
|
+
clickedLayer = layer;
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
this._fireEvent(clickedLayer ? [clickedLayer] : false, e);
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
_onPointerMove(e) {
|
|
364
|
+
if (!this._map || this._map.dragging.moving() || this._map._animatingZoom) { return; }
|
|
365
|
+
|
|
366
|
+
const point = this._map.pointerEventToLayerPoint(e);
|
|
367
|
+
this._handlePointerHover(e, point);
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
|
|
371
|
+
_handlePointerOut(e) {
|
|
372
|
+
const layer = this._hoveredLayer;
|
|
373
|
+
if (layer) {
|
|
374
|
+
// if we're leaving the layer, fire pointerout
|
|
375
|
+
this._container.classList.remove('maplair-interactive');
|
|
376
|
+
this._fireEvent([layer], e, 'pointerout');
|
|
377
|
+
this._hoveredLayer = null;
|
|
378
|
+
this._pointerHoverThrottled = false;
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
_handlePointerHover(e, point) {
|
|
383
|
+
if (this._pointerHoverThrottled) {
|
|
384
|
+
return;
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
let layer, candidateHoveredLayer;
|
|
388
|
+
|
|
389
|
+
for (let order = this._drawFirst; order; order = order.next) {
|
|
390
|
+
layer = order.layer;
|
|
391
|
+
if (layer.options.interactive && layer._containsPoint(point)) {
|
|
392
|
+
candidateHoveredLayer = layer;
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
if (candidateHoveredLayer !== this._hoveredLayer) {
|
|
397
|
+
this._handlePointerOut(e);
|
|
398
|
+
|
|
399
|
+
if (candidateHoveredLayer) {
|
|
400
|
+
this._container.classList.add('maplair-interactive'); // change cursor
|
|
401
|
+
this._fireEvent([candidateHoveredLayer], e, 'pointerover');
|
|
402
|
+
this._hoveredLayer = candidateHoveredLayer;
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
this._fireEvent(this._hoveredLayer ? [this._hoveredLayer] : false, e);
|
|
407
|
+
|
|
408
|
+
this._pointerHoverThrottled = true;
|
|
409
|
+
this._pointerHoverThrottleTimeout = setTimeout((() => {
|
|
410
|
+
this._pointerHoverThrottled = false;
|
|
411
|
+
}), 32);
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
_fireEvent(layers, e, type) {
|
|
415
|
+
this._map._fireDOMEvent(e, type || e.type, layers);
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
_bringToFront(layer) {
|
|
419
|
+
const order = layer._order;
|
|
420
|
+
|
|
421
|
+
if (!order) { return; }
|
|
422
|
+
|
|
423
|
+
const next = order.next;
|
|
424
|
+
const prev = order.prev;
|
|
425
|
+
|
|
426
|
+
if (next) {
|
|
427
|
+
next.prev = prev;
|
|
428
|
+
} else {
|
|
429
|
+
// Already last
|
|
430
|
+
return;
|
|
431
|
+
}
|
|
432
|
+
if (prev) {
|
|
433
|
+
prev.next = next;
|
|
434
|
+
} else if (next) {
|
|
435
|
+
// Update first entry unless this is the
|
|
436
|
+
// single entry
|
|
437
|
+
this._drawFirst = next;
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
order.prev = this._drawLast;
|
|
441
|
+
this._drawLast.next = order;
|
|
442
|
+
|
|
443
|
+
order.next = null;
|
|
444
|
+
this._drawLast = order;
|
|
445
|
+
|
|
446
|
+
this._requestRedraw(layer);
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
_bringToBack(layer) {
|
|
450
|
+
const order = layer._order;
|
|
451
|
+
|
|
452
|
+
if (!order) { return; }
|
|
453
|
+
|
|
454
|
+
const next = order.next;
|
|
455
|
+
const prev = order.prev;
|
|
456
|
+
|
|
457
|
+
if (prev) {
|
|
458
|
+
prev.next = next;
|
|
459
|
+
} else {
|
|
460
|
+
// Already first
|
|
461
|
+
return;
|
|
462
|
+
}
|
|
463
|
+
if (next) {
|
|
464
|
+
next.prev = prev;
|
|
465
|
+
} else if (prev) {
|
|
466
|
+
// Update last entry unless this is the
|
|
467
|
+
// single entry
|
|
468
|
+
this._drawLast = prev;
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
order.prev = null;
|
|
472
|
+
|
|
473
|
+
order.next = this._drawFirst;
|
|
474
|
+
this._drawFirst.prev = order;
|
|
475
|
+
this._drawFirst = order;
|
|
476
|
+
|
|
477
|
+
this._requestRedraw(layer);
|
|
478
|
+
}
|
|
479
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import {CircleMarker} from './CircleMarker.js';
|
|
2
|
+
import {LatLngBounds} from '../../geo/LatLngBounds.js';
|
|
3
|
+
import {EarthCRS} from '../../geo/crs/EarthCRS.js';
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
/*
|
|
7
|
+
* @class Circle
|
|
8
|
+
* @inherits CircleMarker
|
|
9
|
+
*
|
|
10
|
+
* A class for drawing circle overlays on a map with radius specified in meters. Extends `CircleMarker`.
|
|
11
|
+
*
|
|
12
|
+
* It's an approximation and starts to diverge from a real circle closer to poles (due to projection distortion).
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
*
|
|
16
|
+
* ```js
|
|
17
|
+
* new Circle([50.5, 30.5], {radius: 200}).addTo(map);
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
// @constructor Circle(latlng: LatLng, options?: Circle options)
|
|
22
|
+
// Instantiates a circle object given a geographical point, and an options object
|
|
23
|
+
// which contains the circle radius.
|
|
24
|
+
export class Circle extends CircleMarker {
|
|
25
|
+
|
|
26
|
+
constructor(latlng, options) {
|
|
27
|
+
super(latlng, options);
|
|
28
|
+
|
|
29
|
+
if (isNaN(this.options.radius)) { throw new Error('Circle radius cannot be NaN'); }
|
|
30
|
+
|
|
31
|
+
// @section
|
|
32
|
+
// @aka Circle options
|
|
33
|
+
// @option radius: Number; Radius of the circle, in meters.
|
|
34
|
+
|
|
35
|
+
this.callInitHooks(Circle);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// @method setRadius(radius: Number): this
|
|
39
|
+
// Sets the radius of a circle. Units are in meters.
|
|
40
|
+
// @method getRadius(): Number
|
|
41
|
+
// Returns the current radius of a circle. Units are in meters.
|
|
42
|
+
|
|
43
|
+
// @method getBounds(): LatLngBounds
|
|
44
|
+
// Returns the `LatLngBounds` of the path.
|
|
45
|
+
getBounds() {
|
|
46
|
+
const half = [this._pxRadius, this._pxRadiusY ?? this._pxRadius];
|
|
47
|
+
|
|
48
|
+
return new LatLngBounds(
|
|
49
|
+
this._map.layerPointToLatLng(this._point.subtract(half)),
|
|
50
|
+
this._map.layerPointToLatLng(this._point.add(half)));
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
_project() {
|
|
54
|
+
|
|
55
|
+
const lng = this._latlng.lng,
|
|
56
|
+
lat = this._latlng.lat,
|
|
57
|
+
map = this._map,
|
|
58
|
+
crs = map.options.crs;
|
|
59
|
+
|
|
60
|
+
if (crs.distance === EarthCRS.distance) {
|
|
61
|
+
const d = Math.PI / 180,
|
|
62
|
+
latR = (this._radius / EarthCRS.R) / d,
|
|
63
|
+
top = map.project([lat + latR, lng]),
|
|
64
|
+
bottom = map.project([lat - latR, lng]),
|
|
65
|
+
p = top.add(bottom).divideBy(2),
|
|
66
|
+
lat2 = map.unproject(p).lat;
|
|
67
|
+
let lngR = Math.acos((Math.cos(latR * d) - Math.sin(lat * d) * Math.sin(lat2 * d)) /
|
|
68
|
+
(Math.cos(lat * d) * Math.cos(lat2 * d))) / d;
|
|
69
|
+
|
|
70
|
+
if (isNaN(lngR) || lngR === 0) {
|
|
71
|
+
lngR = latR / Math.cos(Math.PI / 180 * lat); // Fallback for edge case, #2425
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
this._point = p.subtract(map.getPixelOrigin());
|
|
75
|
+
this._pxRadius = isNaN(lngR) ? 0 : p.x - map.project([lat2, lng - lngR]).x;
|
|
76
|
+
this._pxRadiusY = p.y - top.y;
|
|
77
|
+
|
|
78
|
+
} else {
|
|
79
|
+
const latlng2 = crs.unproject(crs.project(this._latlng).subtract([this._radius, 0]));
|
|
80
|
+
|
|
81
|
+
this._point = map.latLngToLayerPoint(this._latlng);
|
|
82
|
+
this._pxRadius = Math.abs(this._point.x - map.latLngToLayerPoint(latlng2).x);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
this._updateBounds();
|
|
86
|
+
}
|
|
87
|
+
}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import {Path} from './Path.js';
|
|
2
|
+
import * as Util from '../../core/Util.js';
|
|
3
|
+
import {LatLng} from '../../geo/LatLng.js';
|
|
4
|
+
import {Bounds} from '../../geometry/Bounds.js';
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
/*
|
|
8
|
+
* @class CircleMarker
|
|
9
|
+
* @inherits Path
|
|
10
|
+
*
|
|
11
|
+
* A circle of a fixed size with radius specified in CSS pixels. Extends `Path`.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
// @constructor CircleMarker(latlng: LatLng, options?: CircleMarker options)
|
|
15
|
+
// Instantiates a circle marker object given a geographical point, and an optional options object.
|
|
16
|
+
export class CircleMarker extends Path {
|
|
17
|
+
|
|
18
|
+
static {
|
|
19
|
+
// @section
|
|
20
|
+
// @aka CircleMarker options
|
|
21
|
+
this.setDefaultOptions({
|
|
22
|
+
fill: true,
|
|
23
|
+
|
|
24
|
+
// @option radius: Number = 10
|
|
25
|
+
// Radius of the circle marker, in CSS pixels
|
|
26
|
+
radius: 10
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
constructor(latlng, options) {
|
|
31
|
+
super();
|
|
32
|
+
Util.setOptions(this, options);
|
|
33
|
+
this._latlng = new LatLng(latlng);
|
|
34
|
+
this._radius = this.options.radius;
|
|
35
|
+
|
|
36
|
+
this.callInitHooks(CircleMarker);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// @method setLatLng(latLng: LatLng): this
|
|
40
|
+
// Sets the position of a circle marker to a new location.
|
|
41
|
+
setLatLng(latlng) {
|
|
42
|
+
const oldLatLng = this._latlng;
|
|
43
|
+
this._latlng = new LatLng(latlng);
|
|
44
|
+
this.redraw();
|
|
45
|
+
|
|
46
|
+
// @event move: Event
|
|
47
|
+
// Fired when the marker is moved via [`setLatLng`](#circlemarker-setlatlng). Old and new coordinates are included in event arguments as `oldLatLng`, `latlng`.
|
|
48
|
+
return this.fire('move', {oldLatLng, latlng: this._latlng});
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// @method getLatLng(): LatLng
|
|
52
|
+
// Returns the current geographical position of the circle marker
|
|
53
|
+
getLatLng() {
|
|
54
|
+
return this._latlng;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// @method setRadius(radius: Number): this
|
|
58
|
+
// Sets the radius of a circle marker. Units are in CSS pixels.
|
|
59
|
+
setRadius(radius) {
|
|
60
|
+
this.options.radius = this._radius = radius;
|
|
61
|
+
return this.redraw();
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// @method getRadius(): Number
|
|
65
|
+
// Returns the current radius of the circle. Units are in CSS pixels.
|
|
66
|
+
getRadius() {
|
|
67
|
+
return this._radius;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
setStyle(options) {
|
|
71
|
+
super.setStyle(options);
|
|
72
|
+
if (options?.radius !== undefined) {
|
|
73
|
+
this.setRadius(options.radius);
|
|
74
|
+
}
|
|
75
|
+
return this;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
_project() {
|
|
79
|
+
this._point = this._map.latLngToLayerPoint(this._latlng);
|
|
80
|
+
this._pxRadius = this._radius;
|
|
81
|
+
this._updateBounds();
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
_updateBounds() {
|
|
85
|
+
const r = this._pxRadius,
|
|
86
|
+
r2 = this._pxRadiusY ?? r,
|
|
87
|
+
w = this._clickTolerance(),
|
|
88
|
+
p = [r + w, r2 + w];
|
|
89
|
+
this._pxBounds = new Bounds(this._point.subtract(p), this._point.add(p));
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
_update() {
|
|
93
|
+
if (this._map) {
|
|
94
|
+
this._updatePath();
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
_updatePath() {
|
|
99
|
+
this._renderer._updateCircle(this);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
_empty() {
|
|
103
|
+
return this._pxRadius && !this._renderer._bounds.intersects(this._pxBounds);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// Needed by the `Canvas` renderer for interactivity
|
|
107
|
+
_containsPoint(p) {
|
|
108
|
+
return p.distanceTo(this._point) <= this._pxRadius + this._clickTolerance();
|
|
109
|
+
}
|
|
110
|
+
}
|