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,465 @@
|
|
|
1
|
+
import {Layer} from '../Layer.js';
|
|
2
|
+
import {DefaultIcon} from './DefaultIcon.js';
|
|
3
|
+
import * as Util from '../../core/Util.js';
|
|
4
|
+
import {LatLng} from '../../geo/LatLng.js';
|
|
5
|
+
import {Point} from '../../geometry/Point.js';
|
|
6
|
+
import * as DomUtil from '../../dom/DomUtil.js';
|
|
7
|
+
import * as DomEvent from '../../dom/DomEvent.js';
|
|
8
|
+
import {MarkerDrag} from './Marker.Drag.js';
|
|
9
|
+
|
|
10
|
+
/*
|
|
11
|
+
* @class Marker
|
|
12
|
+
* @inherits Interactive layer
|
|
13
|
+
* Marker is used to display clickable/draggable icons on the map. Extends `Layer`.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
*
|
|
17
|
+
* ```js
|
|
18
|
+
* new Marker([50.5, 30.5]).addTo(map);
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
// @constructor Marker(latlng: LatLng, options? : Marker options)
|
|
23
|
+
// Instantiates a Marker object given a geographical point and optionally an options object.
|
|
24
|
+
export class Marker extends Layer {
|
|
25
|
+
|
|
26
|
+
static {
|
|
27
|
+
// @section
|
|
28
|
+
// @aka Marker options
|
|
29
|
+
this.setDefaultOptions({
|
|
30
|
+
// @option icon: Icon = *
|
|
31
|
+
// Icon instance to use for rendering the marker.
|
|
32
|
+
// See [Icon documentation](#Icon) for details on how to customize the marker icon.
|
|
33
|
+
// If not specified, a common instance of `DefaultIcon` is used.
|
|
34
|
+
icon: new DefaultIcon(),
|
|
35
|
+
|
|
36
|
+
// Option inherited from "Interactive layer" abstract class
|
|
37
|
+
interactive: true,
|
|
38
|
+
|
|
39
|
+
// @option keyboard: Boolean = true
|
|
40
|
+
// Whether the marker can be tabbed to with a keyboard and clicked by pressing enter.
|
|
41
|
+
keyboard: true,
|
|
42
|
+
|
|
43
|
+
// @option title: String = ''
|
|
44
|
+
// Text for the browser tooltip that appear on marker hover (no tooltip by default).
|
|
45
|
+
// [Useful for accessibility](https://maplair.org/examples/accessibility/#markers-must-be-labelled).
|
|
46
|
+
title: '',
|
|
47
|
+
|
|
48
|
+
// @option alt: String = 'Marker'
|
|
49
|
+
// Text for the `alt` attribute of the icon image.
|
|
50
|
+
// [Useful for accessibility](https://maplair.org/examples/accessibility/#markers-must-be-labelled).
|
|
51
|
+
alt: 'Marker',
|
|
52
|
+
|
|
53
|
+
// @option zIndexOffset: Number = 0
|
|
54
|
+
// By default, marker images zIndex is set automatically based on its latitude. Use this option if you want to put the marker on top of all others (or below), specifying a high value like `1000` (or high negative value, respectively).
|
|
55
|
+
zIndexOffset: 0,
|
|
56
|
+
|
|
57
|
+
// @option opacity: Number = 1.0
|
|
58
|
+
// The opacity of the marker.
|
|
59
|
+
opacity: 1,
|
|
60
|
+
|
|
61
|
+
// @option riseOnHover: Boolean = false
|
|
62
|
+
// If `true`, the marker will get on top of others when you hover the pointer over it.
|
|
63
|
+
riseOnHover: false,
|
|
64
|
+
|
|
65
|
+
// @option riseOffset: Number = 250
|
|
66
|
+
// The z-index offset used for the `riseOnHover` feature.
|
|
67
|
+
riseOffset: 250,
|
|
68
|
+
|
|
69
|
+
// @option pane: String = 'markerPane'
|
|
70
|
+
// `Map pane` where the markers icon will be added.
|
|
71
|
+
pane: 'markerPane',
|
|
72
|
+
|
|
73
|
+
// @option shadowPane: String = 'shadowPane'
|
|
74
|
+
// `Map pane` where the markers shadow will be added.
|
|
75
|
+
shadowPane: 'shadowPane',
|
|
76
|
+
|
|
77
|
+
// @option shadow: Boolean = true
|
|
78
|
+
// Whether to show the shadow of the marker's icon. Each shadow is an
|
|
79
|
+
// additional element on the page, so disabling shadows noticeably reduces
|
|
80
|
+
// the browser's rendering work when showing many markers (e.g. several
|
|
81
|
+
// thousands), especially while panning and zooming. To disable shadows
|
|
82
|
+
// for all markers, use `Marker.mergeOptions({shadow: false})`.
|
|
83
|
+
shadow: true,
|
|
84
|
+
|
|
85
|
+
// @option bubblingPointerEvents: Boolean = false
|
|
86
|
+
// When `true`, a pointer event on this marker will trigger the same event on the map
|
|
87
|
+
// (unless [`DomEvent.stopPropagation`](#domevent-stoppropagation) is used).
|
|
88
|
+
bubblingPointerEvents: false,
|
|
89
|
+
|
|
90
|
+
// @option autoPanOnFocus: Boolean = true
|
|
91
|
+
// When `true`, the map will pan whenever the marker is focused (via
|
|
92
|
+
// e.g. pressing `tab` on the keyboard) to ensure the marker is
|
|
93
|
+
// visible within the map's bounds
|
|
94
|
+
autoPanOnFocus: true,
|
|
95
|
+
|
|
96
|
+
// @section Draggable marker options
|
|
97
|
+
// @option draggable: Boolean = false
|
|
98
|
+
// Whether the marker is draggable with pointer or not.
|
|
99
|
+
draggable: false,
|
|
100
|
+
|
|
101
|
+
// @option autoPan: Boolean = false
|
|
102
|
+
// Whether to pan the map when dragging this marker near its edge or not.
|
|
103
|
+
autoPan: false,
|
|
104
|
+
|
|
105
|
+
// @option autoPanPadding: Point = Point(50, 50)
|
|
106
|
+
// Distance (in pixels to the left/right and to the top/bottom) of the
|
|
107
|
+
// map edge to start panning the map.
|
|
108
|
+
autoPanPadding: [50, 50],
|
|
109
|
+
|
|
110
|
+
// @option autoPanSpeed: Number = 10
|
|
111
|
+
// Number of pixels the map should pan by.
|
|
112
|
+
autoPanSpeed: 10
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/* @section
|
|
117
|
+
*
|
|
118
|
+
* In addition to [shared layer methods](#Layer) like `addTo()` and `remove()` and [popup methods](#Popup) like bindPopup() you can also use the following methods:
|
|
119
|
+
*/
|
|
120
|
+
|
|
121
|
+
constructor(latlng, options) {
|
|
122
|
+
super();
|
|
123
|
+
Util.setOptions(this, options);
|
|
124
|
+
this._latlng = new LatLng(latlng);
|
|
125
|
+
|
|
126
|
+
this.callInitHooks(Marker);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
onAdd(map) {
|
|
130
|
+
this._zoomAnimated = this._zoomAnimated && map.options.markerZoomAnimation;
|
|
131
|
+
|
|
132
|
+
if (this._zoomAnimated) {
|
|
133
|
+
map.on('zoomanim', this._animateZoom, this);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
this._initIcon();
|
|
137
|
+
this.update();
|
|
138
|
+
|
|
139
|
+
if (map.options.markerCulling) {
|
|
140
|
+
this._updateCulling();
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
onRemove(map) {
|
|
145
|
+
if (this.dragging?.enabled()) {
|
|
146
|
+
this.options.draggable = true;
|
|
147
|
+
this.dragging.removeHooks();
|
|
148
|
+
}
|
|
149
|
+
delete this.dragging;
|
|
150
|
+
|
|
151
|
+
if (this._zoomAnimated) {
|
|
152
|
+
map.off('zoomanim', this._animateZoom, this);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
this._removeIcon();
|
|
156
|
+
this._removeShadow();
|
|
157
|
+
this._culled = false;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
getEvents() {
|
|
161
|
+
const events = {
|
|
162
|
+
zoom: this.update,
|
|
163
|
+
viewreset: this.update
|
|
164
|
+
};
|
|
165
|
+
if (this._map?.options.markerCulling) {
|
|
166
|
+
events.moveend = this._updateCulling;
|
|
167
|
+
}
|
|
168
|
+
return events;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
// @method getLatLng: LatLng
|
|
172
|
+
// Returns the current geographical position of the marker.
|
|
173
|
+
getLatLng() {
|
|
174
|
+
return this._latlng;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
// @method setLatLng(latlng: LatLng): this
|
|
178
|
+
// Changes the marker position to the given point.
|
|
179
|
+
setLatLng(latlng) {
|
|
180
|
+
const oldLatLng = this._latlng;
|
|
181
|
+
this._latlng = new LatLng(latlng);
|
|
182
|
+
if (this._map?.options.markerCulling) {
|
|
183
|
+
this._updateCulling();
|
|
184
|
+
}
|
|
185
|
+
this.update();
|
|
186
|
+
|
|
187
|
+
// @event move: Event
|
|
188
|
+
// Fired when the marker is moved via [`setLatLng`](#marker-setlatlng) or by [dragging](#marker-dragging). Old and new coordinates are included in event arguments as `oldLatLng`, `latlng`.
|
|
189
|
+
return this.fire('move', {oldLatLng, latlng: this._latlng});
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
// @method setZIndexOffset(offset: Number): this
|
|
193
|
+
// Changes the [zIndex offset](#marker-zindexoffset) of the marker.
|
|
194
|
+
setZIndexOffset(offset) {
|
|
195
|
+
this.options.zIndexOffset = offset;
|
|
196
|
+
return this.update();
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
// @method getIcon: Icon
|
|
200
|
+
// Returns the current icon used by the marker
|
|
201
|
+
getIcon() {
|
|
202
|
+
return this.options.icon;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
// @method setIcon(icon: Icon): this
|
|
206
|
+
// Changes the marker icon.
|
|
207
|
+
setIcon(icon) {
|
|
208
|
+
|
|
209
|
+
this.options.icon = icon;
|
|
210
|
+
|
|
211
|
+
if (this._map) {
|
|
212
|
+
this._initIcon();
|
|
213
|
+
this.update();
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
if (this._popup) {
|
|
217
|
+
this.bindPopup(this._popup, this._popup.options);
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
return this;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
// @method getElement(): HTMLElement
|
|
224
|
+
// Returns the instance of [`HTMLElement`](https://developer.mozilla.org/docs/Web/API/HTMLElement)
|
|
225
|
+
// used by Marker layer.
|
|
226
|
+
getElement() {
|
|
227
|
+
return this._icon;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
update() {
|
|
231
|
+
|
|
232
|
+
if (this._icon && this._map && !this._culled) {
|
|
233
|
+
const pos = this._map.latLngToLayerPoint(this._latlng).round();
|
|
234
|
+
this._setPos(pos);
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
return this;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
_initIcon() {
|
|
241
|
+
const options = this.options,
|
|
242
|
+
classToAdd = `maplair-zoom-${this._zoomAnimated ? 'animated' : 'hide'}`;
|
|
243
|
+
|
|
244
|
+
const icon = options.icon.createIcon(this._icon);
|
|
245
|
+
let addIcon = false;
|
|
246
|
+
|
|
247
|
+
// if we're not reusing the icon, remove the old one and init new one
|
|
248
|
+
if (icon !== this._icon) {
|
|
249
|
+
if (this._icon) {
|
|
250
|
+
this._removeIcon();
|
|
251
|
+
}
|
|
252
|
+
addIcon = true;
|
|
253
|
+
|
|
254
|
+
if (options.title) {
|
|
255
|
+
icon.title = options.title;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
if (icon.tagName === 'IMG') {
|
|
259
|
+
icon.alt = options.alt ?? '';
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
icon.classList.add(classToAdd);
|
|
264
|
+
|
|
265
|
+
if (options.keyboard) {
|
|
266
|
+
icon.tabIndex = '0';
|
|
267
|
+
icon.setAttribute('role', 'button');
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
this._icon = icon;
|
|
271
|
+
|
|
272
|
+
if (options.riseOnHover) {
|
|
273
|
+
this.on({
|
|
274
|
+
pointerover: this._bringToFront,
|
|
275
|
+
pointerout: this._resetZIndex
|
|
276
|
+
});
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
if (this.options.autoPanOnFocus) {
|
|
280
|
+
DomEvent.on(icon, 'focus', this._panOnFocus, this);
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
const newShadow = options.shadow ? options.icon.createShadow(this._shadow) : null;
|
|
284
|
+
let addShadow = false;
|
|
285
|
+
|
|
286
|
+
if (newShadow !== this._shadow) {
|
|
287
|
+
this._removeShadow();
|
|
288
|
+
addShadow = true;
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
if (newShadow) {
|
|
292
|
+
newShadow.classList.add(classToAdd);
|
|
293
|
+
newShadow.alt = '';
|
|
294
|
+
}
|
|
295
|
+
this._shadow = newShadow;
|
|
296
|
+
|
|
297
|
+
|
|
298
|
+
if (options.opacity < 1) {
|
|
299
|
+
this._updateOpacity();
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
|
|
303
|
+
if (addIcon) {
|
|
304
|
+
this.getPane().appendChild(this._icon);
|
|
305
|
+
}
|
|
306
|
+
this._initInteraction();
|
|
307
|
+
if (newShadow && addShadow) {
|
|
308
|
+
this.getPane(options.shadowPane).appendChild(this._shadow);
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
_removeIcon() {
|
|
313
|
+
if (this.options.riseOnHover) {
|
|
314
|
+
this.off({
|
|
315
|
+
pointerover: this._bringToFront,
|
|
316
|
+
pointerout: this._resetZIndex
|
|
317
|
+
});
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
if (this.options.autoPanOnFocus) {
|
|
321
|
+
DomEvent.off(this._icon, 'focus', this._panOnFocus, this);
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
this._icon.remove();
|
|
325
|
+
this.removeInteractiveTarget(this._icon);
|
|
326
|
+
|
|
327
|
+
this._icon = null;
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
// With the map's `markerCulling` option, takes the icon and shadow of a marker
|
|
331
|
+
// far outside of the map view off the page (and puts them back when needed),
|
|
332
|
+
// so that the browser doesn't need to render, and the marker doesn't need
|
|
333
|
+
// to reposition, them while panning and zooming.
|
|
334
|
+
_updateCulling() {
|
|
335
|
+
if (!this._icon || !this._map) { return; }
|
|
336
|
+
|
|
337
|
+
const visible = this._map.getBounds().pad(0.5).contains(this._latlng) ||
|
|
338
|
+
!!this.dragging?._draggable?._moving ||
|
|
339
|
+
this._icon.contains(document.activeElement);
|
|
340
|
+
|
|
341
|
+
if (visible === !this._culled) { return; }
|
|
342
|
+
this._culled = !visible;
|
|
343
|
+
|
|
344
|
+
if (visible) {
|
|
345
|
+
this.getPane().appendChild(this._icon);
|
|
346
|
+
if (this._shadow) {
|
|
347
|
+
this.getPane(this.options.shadowPane).appendChild(this._shadow);
|
|
348
|
+
}
|
|
349
|
+
this.update();
|
|
350
|
+
} else {
|
|
351
|
+
this._icon.remove();
|
|
352
|
+
this._shadow?.remove();
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
_removeShadow() {
|
|
357
|
+
this._shadow?.remove();
|
|
358
|
+
this._shadow = null;
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
_setPos(pos) {
|
|
362
|
+
|
|
363
|
+
if (this._icon) {
|
|
364
|
+
DomUtil.setPosition(this._icon, pos);
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
if (this._shadow) {
|
|
368
|
+
DomUtil.setPosition(this._shadow, pos);
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
this._zIndex = pos.y + this.options.zIndexOffset;
|
|
372
|
+
|
|
373
|
+
this._resetZIndex();
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
_updateZIndex(offset) {
|
|
377
|
+
const zIndex = String(this._zIndex + offset);
|
|
378
|
+
if (this._icon && this._icon.style.zIndex !== zIndex) {
|
|
379
|
+
this._icon.style.zIndex = zIndex;
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
_animateZoom(opt) {
|
|
384
|
+
if (this._culled) { return; }
|
|
385
|
+
const pos = this._map._latLngToNewLayerPoint(this._latlng, opt.zoom, opt.center).round();
|
|
386
|
+
|
|
387
|
+
this._setPos(pos);
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
_initInteraction() {
|
|
391
|
+
|
|
392
|
+
if (!this.options.interactive) { return; }
|
|
393
|
+
|
|
394
|
+
this._icon.classList.add('maplair-interactive');
|
|
395
|
+
|
|
396
|
+
this.addInteractiveTarget(this._icon);
|
|
397
|
+
|
|
398
|
+
if (MarkerDrag) {
|
|
399
|
+
let draggable = this.options.draggable;
|
|
400
|
+
if (this.dragging) {
|
|
401
|
+
draggable = this.dragging.enabled();
|
|
402
|
+
this.dragging.disable();
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
this.dragging = new MarkerDrag(this);
|
|
406
|
+
|
|
407
|
+
if (draggable) {
|
|
408
|
+
this.dragging.enable();
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
// @method setOpacity(opacity: Number): this
|
|
414
|
+
// Changes the opacity of the marker.
|
|
415
|
+
setOpacity(opacity) {
|
|
416
|
+
this.options.opacity = opacity;
|
|
417
|
+
if (this._map) {
|
|
418
|
+
this._updateOpacity();
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
return this;
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
_updateOpacity() {
|
|
425
|
+
const opacity = this.options.opacity;
|
|
426
|
+
|
|
427
|
+
if (this._icon) {
|
|
428
|
+
this._icon.style.opacity = opacity;
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
if (this._shadow) {
|
|
432
|
+
this._shadow.style.opacity = opacity;
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
_bringToFront() {
|
|
437
|
+
this._updateZIndex(this.options.riseOffset);
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
_resetZIndex() {
|
|
441
|
+
this._updateZIndex(0);
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
_panOnFocus() {
|
|
445
|
+
const map = this._map;
|
|
446
|
+
if (!map) { return; }
|
|
447
|
+
|
|
448
|
+
const iconOpts = this.options.icon.options;
|
|
449
|
+
const size = iconOpts.iconSize ? new Point(iconOpts.iconSize) : new Point(0, 0);
|
|
450
|
+
const anchor = iconOpts.iconAnchor ? new Point(iconOpts.iconAnchor) : new Point(0, 0);
|
|
451
|
+
|
|
452
|
+
map.panInside(this._latlng, {
|
|
453
|
+
paddingTopLeft: anchor,
|
|
454
|
+
paddingBottomRight: size.subtract(anchor)
|
|
455
|
+
});
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
_getPopupAnchor() {
|
|
459
|
+
return this.options.icon.options.popupAnchor;
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
_getTooltipAnchor() {
|
|
463
|
+
return this.options.icon.options.tooltipAnchor;
|
|
464
|
+
}
|
|
465
|
+
}
|