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,76 @@
|
|
|
1
|
+
import {Icon} from './Icon.js';
|
|
2
|
+
import {Point} from '../../geometry/Point.js';
|
|
3
|
+
|
|
4
|
+
/*
|
|
5
|
+
* @class DivIcon
|
|
6
|
+
* @inherits Icon
|
|
7
|
+
*
|
|
8
|
+
* Represents a lightweight icon for markers that uses a simple `<div>`
|
|
9
|
+
* element instead of an image. Inherits from `Icon` but ignores the `iconUrl` and shadow options.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```js
|
|
13
|
+
* const myIcon = new DivIcon({className: 'my-div-icon'});
|
|
14
|
+
* // you can set .my-div-icon styles in CSS
|
|
15
|
+
*
|
|
16
|
+
* new Marker([50.505, 30.57], {icon: myIcon}).addTo(map);
|
|
17
|
+
* ```
|
|
18
|
+
*
|
|
19
|
+
* By default, it has a 'maplair-div-icon' CSS class and is styled as a little white square with a shadow.
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
// @constructor DivIcon(options: DivIcon options)
|
|
23
|
+
// Creates a `DivIcon` instance with the given options.
|
|
24
|
+
export class DivIcon extends Icon {
|
|
25
|
+
|
|
26
|
+
static {
|
|
27
|
+
this.setDefaultOptions({
|
|
28
|
+
// @section
|
|
29
|
+
// @aka DivIcon options
|
|
30
|
+
iconSize: [12, 12], // also can be set through CSS
|
|
31
|
+
|
|
32
|
+
// iconAnchor: (Point),
|
|
33
|
+
// popupAnchor: (Point),
|
|
34
|
+
|
|
35
|
+
// @option html: String|HTMLElement = ''
|
|
36
|
+
// Custom HTML code to put inside the div element, empty by default. Alternatively,
|
|
37
|
+
// an instance of `HTMLElement`.
|
|
38
|
+
html: false,
|
|
39
|
+
|
|
40
|
+
// @option bgPos: Point = [0, 0]
|
|
41
|
+
// Optional relative position of the background, in pixels
|
|
42
|
+
bgPos: null,
|
|
43
|
+
|
|
44
|
+
className: 'maplair-div-icon'
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
constructor(...args) {
|
|
49
|
+
super(...args);
|
|
50
|
+
this.callInitHooks(DivIcon);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
createIcon(oldIcon) {
|
|
54
|
+
const div = (oldIcon && oldIcon.tagName === 'DIV') ? oldIcon : document.createElement('div'),
|
|
55
|
+
options = this.options;
|
|
56
|
+
|
|
57
|
+
if (options.html instanceof Element) {
|
|
58
|
+
div.replaceChildren();
|
|
59
|
+
div.appendChild(options.html);
|
|
60
|
+
} else {
|
|
61
|
+
div.innerHTML = options.html !== false ? options.html : '';
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
if (options.bgPos) {
|
|
65
|
+
const bgPos = new Point(options.bgPos);
|
|
66
|
+
div.style.backgroundPosition = `${-bgPos.x}px ${-bgPos.y}px`;
|
|
67
|
+
}
|
|
68
|
+
this._setIconStyles(div, 'icon');
|
|
69
|
+
|
|
70
|
+
return div;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
createShadow() {
|
|
74
|
+
return null;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import {Class} from '../../core/Class.js';
|
|
2
|
+
import {setOptions} from '../../core/Util.js';
|
|
3
|
+
import {Point} from '../../geometry/Point.js';
|
|
4
|
+
import Browser from '../../core/Browser.js';
|
|
5
|
+
|
|
6
|
+
/*
|
|
7
|
+
* @class Icon
|
|
8
|
+
*
|
|
9
|
+
* Represents an icon to provide when creating a marker.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
*
|
|
13
|
+
* ```js
|
|
14
|
+
* const myIcon = new Icon({
|
|
15
|
+
* iconUrl: 'my-icon.png',
|
|
16
|
+
* iconRetinaUrl: 'my-icon@2x.png',
|
|
17
|
+
* iconSize: [38, 95],
|
|
18
|
+
* iconAnchor: [22, 94],
|
|
19
|
+
* popupAnchor: [-3, -76],
|
|
20
|
+
* shadowUrl: 'my-icon-shadow.png',
|
|
21
|
+
* shadowRetinaUrl: 'my-icon-shadow@2x.png',
|
|
22
|
+
* shadowSize: [68, 95],
|
|
23
|
+
* shadowAnchor: [22, 94]
|
|
24
|
+
* });
|
|
25
|
+
*
|
|
26
|
+
* new Marker([50.505, 30.57], {icon: myIcon}).addTo(map);
|
|
27
|
+
* ```
|
|
28
|
+
*
|
|
29
|
+
* `DefaultIcon` extends `Icon` and is the blue icon Maplair uses for markers by default.
|
|
30
|
+
*
|
|
31
|
+
*/
|
|
32
|
+
|
|
33
|
+
// @constructor Icon(options: Icon options)
|
|
34
|
+
// Creates an icon instance with the given options.
|
|
35
|
+
export class Icon extends Class {
|
|
36
|
+
|
|
37
|
+
static {
|
|
38
|
+
/* @section
|
|
39
|
+
* @aka Icon options
|
|
40
|
+
*
|
|
41
|
+
* @option iconUrl: String = null
|
|
42
|
+
* **(required)** The URL to the icon image (absolute or relative to your script path).
|
|
43
|
+
*
|
|
44
|
+
* @option iconRetinaUrl: String = null
|
|
45
|
+
* The URL to a retina sized version of the icon image (absolute or relative to your
|
|
46
|
+
* script path). Used for Retina screen devices.
|
|
47
|
+
*
|
|
48
|
+
* @option iconSize: Point = null
|
|
49
|
+
* Size of the icon image in pixels.
|
|
50
|
+
*
|
|
51
|
+
* @option iconAnchor: Point = null
|
|
52
|
+
* The coordinates of the "tip" of the icon (relative to its top left corner). The icon
|
|
53
|
+
* will be aligned so that this point is at the marker's geographical location. Centered
|
|
54
|
+
* by default if size is specified, also can be set in CSS with negative margins.
|
|
55
|
+
*
|
|
56
|
+
* @option popupAnchor: Point = [0, 0]
|
|
57
|
+
* The coordinates of the point from which popups will "open", relative to the icon anchor.
|
|
58
|
+
*
|
|
59
|
+
* @option tooltipAnchor: Point = [0, 0]
|
|
60
|
+
* The coordinates of the point from which tooltips will "open", relative to the icon anchor.
|
|
61
|
+
*
|
|
62
|
+
* @option shadowUrl: String = null
|
|
63
|
+
* The URL to the icon shadow image. If not specified, no shadow image will be created.
|
|
64
|
+
*
|
|
65
|
+
* @option shadowRetinaUrl: String = null
|
|
66
|
+
*
|
|
67
|
+
* @option shadowSize: Point = null
|
|
68
|
+
* Size of the shadow image in pixels.
|
|
69
|
+
*
|
|
70
|
+
* @option shadowAnchor: Point = null
|
|
71
|
+
* The coordinates of the "tip" of the shadow (relative to its top left corner) (the same
|
|
72
|
+
* as iconAnchor if not specified).
|
|
73
|
+
*
|
|
74
|
+
* @option className: String = ''
|
|
75
|
+
* A custom class name to assign to both icon and shadow images. Empty by default.
|
|
76
|
+
*/
|
|
77
|
+
this.setDefaultOptions({
|
|
78
|
+
popupAnchor: [0, 0],
|
|
79
|
+
tooltipAnchor: [0, 0],
|
|
80
|
+
|
|
81
|
+
// @option crossOrigin: Boolean|String = false
|
|
82
|
+
// Whether the crossOrigin attribute will be added to the tiles.
|
|
83
|
+
// If a String is provided, all tiles will have their crossOrigin attribute set to the String provided. This is needed if you want to access tile pixel data.
|
|
84
|
+
// Refer to [CORS Settings](https://developer.mozilla.org/en-US/docs/Web/HTML/CORS_settings_attributes) for valid String values.
|
|
85
|
+
crossOrigin: false
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
constructor(options) {
|
|
90
|
+
super();
|
|
91
|
+
setOptions(this, options);
|
|
92
|
+
|
|
93
|
+
this.callInitHooks(Icon);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// @method createIcon(oldIcon?: HTMLElement): HTMLElement
|
|
97
|
+
// Called internally when the icon has to be shown, returns a `<img>` HTML element
|
|
98
|
+
// styled according to the options.
|
|
99
|
+
createIcon(oldIcon) {
|
|
100
|
+
return this._createIcon('icon', oldIcon);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// @method createShadow(oldIcon?: HTMLElement): HTMLElement
|
|
104
|
+
// As `createIcon`, but for the shadow beneath it.
|
|
105
|
+
createShadow(oldIcon) {
|
|
106
|
+
return this._createIcon('shadow', oldIcon);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
_createIcon(name, oldIcon) {
|
|
110
|
+
const src = this._getIconUrl(name);
|
|
111
|
+
|
|
112
|
+
if (!src) {
|
|
113
|
+
if (name === 'icon') {
|
|
114
|
+
throw new Error('iconUrl not set in Icon options (see the docs).');
|
|
115
|
+
}
|
|
116
|
+
return null;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
const img = this._createImg(src, oldIcon && oldIcon.tagName === 'IMG' ? oldIcon : null);
|
|
120
|
+
this._setIconStyles(img, name);
|
|
121
|
+
|
|
122
|
+
if (this.options.crossOrigin || this.options.crossOrigin === '') {
|
|
123
|
+
img.crossOrigin = this.options.crossOrigin === true ? '' : this.options.crossOrigin;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
return img;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
_setIconStyles(img, name) {
|
|
130
|
+
const options = this.options;
|
|
131
|
+
let sizeOption = options[`${name}Size`];
|
|
132
|
+
|
|
133
|
+
if (typeof sizeOption === 'number') {
|
|
134
|
+
sizeOption = [sizeOption, sizeOption];
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
const size = Point.validate(sizeOption) && new Point(sizeOption);
|
|
138
|
+
|
|
139
|
+
const anchorPosition = name === 'shadow' && options.shadowAnchor || options.iconAnchor || size && size.divideBy(2, true);
|
|
140
|
+
const anchor = Point.validate(anchorPosition) && new Point(anchorPosition);
|
|
141
|
+
|
|
142
|
+
img.className = `maplair-marker-${name} ${options.className || ''}`;
|
|
143
|
+
|
|
144
|
+
if (anchor) {
|
|
145
|
+
img.style.marginLeft = `${-anchor.x}px`;
|
|
146
|
+
img.style.marginTop = `${-anchor.y}px`;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
if (size) {
|
|
150
|
+
img.style.width = `${size.x}px`;
|
|
151
|
+
img.style.height = `${size.y}px`;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
_createImg(src, el) {
|
|
156
|
+
el ??= document.createElement('img');
|
|
157
|
+
el.src = src;
|
|
158
|
+
return el;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
_getIconUrl(name) {
|
|
162
|
+
return Browser.retina && this.options[`${name}RetinaUrl`] || this.options[`${name}Url`];
|
|
163
|
+
}
|
|
164
|
+
}
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
import {Handler} from '../../core/Handler.js';
|
|
2
|
+
import * as DomUtil from '../../dom/DomUtil.js';
|
|
3
|
+
import {Draggable} from '../../dom/Draggable.js';
|
|
4
|
+
import {Bounds} from '../../geometry/Bounds.js';
|
|
5
|
+
import {Point} from '../../geometry/Point.js';
|
|
6
|
+
|
|
7
|
+
/*
|
|
8
|
+
* Handler.MarkerDrag is used internally by Marker to make the markers draggable.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
/* @namespace Marker
|
|
13
|
+
* @section Interaction handlers
|
|
14
|
+
*
|
|
15
|
+
* Interaction handlers are properties of a marker instance that allow you to control interaction behavior in runtime, enabling or disabling certain features such as dragging (see `Handler` methods). Example:
|
|
16
|
+
*
|
|
17
|
+
* ```js
|
|
18
|
+
* marker.dragging.disable();
|
|
19
|
+
* ```
|
|
20
|
+
*
|
|
21
|
+
* @property dragging: Handler
|
|
22
|
+
* Marker dragging handler. Only valid when the marker is on the map (Otherwise set [`marker.options.draggable`](#marker-draggable)).
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
export class MarkerDrag extends Handler {
|
|
26
|
+
constructor(marker) {
|
|
27
|
+
super(marker._map);
|
|
28
|
+
this._marker = marker;
|
|
29
|
+
|
|
30
|
+
this.callInitHooks(MarkerDrag);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
addHooks() {
|
|
34
|
+
const icon = this._marker._icon;
|
|
35
|
+
|
|
36
|
+
if (!this._draggable) {
|
|
37
|
+
this._draggable = new Draggable(icon, icon, true);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
this._draggable.on({
|
|
41
|
+
dragstart: this._onDragStart,
|
|
42
|
+
predrag: this._onPreDrag,
|
|
43
|
+
drag: this._onDrag,
|
|
44
|
+
dragend: this._onDragEnd
|
|
45
|
+
}, this).enable();
|
|
46
|
+
|
|
47
|
+
icon.classList.add('maplair-marker-draggable');
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
removeHooks() {
|
|
51
|
+
this._draggable.off({
|
|
52
|
+
dragstart: this._onDragStart,
|
|
53
|
+
predrag: this._onPreDrag,
|
|
54
|
+
drag: this._onDrag,
|
|
55
|
+
dragend: this._onDragEnd
|
|
56
|
+
}, this).disable();
|
|
57
|
+
|
|
58
|
+
this._marker._icon?.classList.remove('maplair-marker-draggable');
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
moved() {
|
|
62
|
+
return this._draggable?._moved;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
_adjustPan(e) {
|
|
66
|
+
const marker = this._marker,
|
|
67
|
+
map = marker._map,
|
|
68
|
+
speed = this._marker.options.autoPanSpeed,
|
|
69
|
+
padding = this._marker.options.autoPanPadding,
|
|
70
|
+
iconPos = DomUtil.getPosition(marker._icon),
|
|
71
|
+
bounds = map.getPixelBounds(),
|
|
72
|
+
origin = map.getPixelOrigin();
|
|
73
|
+
|
|
74
|
+
const panBounds = new Bounds(
|
|
75
|
+
bounds.min._subtract(origin).add(padding),
|
|
76
|
+
bounds.max._subtract(origin).subtract(padding)
|
|
77
|
+
);
|
|
78
|
+
|
|
79
|
+
if (!panBounds.contains(iconPos)) {
|
|
80
|
+
// Compute incremental movement
|
|
81
|
+
const movement = new Point(
|
|
82
|
+
(Math.max(panBounds.max.x, iconPos.x) - panBounds.max.x) / (bounds.max.x - panBounds.max.x) -
|
|
83
|
+
(Math.min(panBounds.min.x, iconPos.x) - panBounds.min.x) / (bounds.min.x - panBounds.min.x),
|
|
84
|
+
|
|
85
|
+
(Math.max(panBounds.max.y, iconPos.y) - panBounds.max.y) / (bounds.max.y - panBounds.max.y) -
|
|
86
|
+
(Math.min(panBounds.min.y, iconPos.y) - panBounds.min.y) / (bounds.min.y - panBounds.min.y)
|
|
87
|
+
).multiplyBy(speed);
|
|
88
|
+
|
|
89
|
+
map.panBy(movement, {animate: false});
|
|
90
|
+
|
|
91
|
+
this._draggable._newPos._add(movement);
|
|
92
|
+
this._draggable._startPos._add(movement);
|
|
93
|
+
|
|
94
|
+
DomUtil.setPosition(marker._icon, this._draggable._newPos);
|
|
95
|
+
this._onDrag(e);
|
|
96
|
+
|
|
97
|
+
this._panRequest = requestAnimationFrame(this._adjustPan.bind(this, e));
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
_onDragStart() {
|
|
102
|
+
// @section Dragging events
|
|
103
|
+
// @event dragstart: Event
|
|
104
|
+
// Fired when the user starts dragging the marker.
|
|
105
|
+
|
|
106
|
+
// @event movestart: Event
|
|
107
|
+
// Fired when the marker starts moving (because of dragging).
|
|
108
|
+
|
|
109
|
+
this._oldLatLng = this._marker.getLatLng();
|
|
110
|
+
|
|
111
|
+
// When using ES6 imports it could not be set when `Popup` was not imported as well
|
|
112
|
+
this._marker.closePopup?.();
|
|
113
|
+
|
|
114
|
+
this._marker
|
|
115
|
+
.fire('movestart')
|
|
116
|
+
.fire('dragstart');
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
_onPreDrag(e) {
|
|
120
|
+
if (this._marker.options.autoPan) {
|
|
121
|
+
cancelAnimationFrame(this._panRequest);
|
|
122
|
+
this._panRequest = requestAnimationFrame(this._adjustPan.bind(this, e));
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
_onDrag(e) {
|
|
127
|
+
const marker = this._marker,
|
|
128
|
+
shadow = marker._shadow,
|
|
129
|
+
iconPos = DomUtil.getPosition(marker._icon),
|
|
130
|
+
latlng = marker._map.layerPointToLatLng(iconPos);
|
|
131
|
+
|
|
132
|
+
// update shadow position
|
|
133
|
+
if (shadow) {
|
|
134
|
+
DomUtil.setPosition(shadow, iconPos);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
marker._latlng = latlng;
|
|
138
|
+
e.latlng = latlng;
|
|
139
|
+
e.oldLatLng = this._oldLatLng;
|
|
140
|
+
|
|
141
|
+
// @event drag: Event
|
|
142
|
+
// Fired repeatedly while the user drags the marker.
|
|
143
|
+
marker
|
|
144
|
+
.fire('move', e)
|
|
145
|
+
.fire('drag', e);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
_onDragEnd(e) {
|
|
149
|
+
// @event dragend: DragEndEvent
|
|
150
|
+
// Fired when the user stops dragging the marker.
|
|
151
|
+
|
|
152
|
+
cancelAnimationFrame(this._panRequest);
|
|
153
|
+
|
|
154
|
+
// @event moveend: Event
|
|
155
|
+
// Fired when the marker stops moving (because of dragging).
|
|
156
|
+
delete this._oldLatLng;
|
|
157
|
+
this._marker
|
|
158
|
+
.fire('moveend')
|
|
159
|
+
.fire('dragend', e);
|
|
160
|
+
}
|
|
161
|
+
}
|