leaflet-with-dashoffset-canvas-fix 1.9.4
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 +2191 -0
- package/LICENSE +26 -0
- package/README.md +3 -0
- package/package.json +149 -0
- package/src/Leaflet.js +24 -0
- package/src/control/Control.Attribution.js +148 -0
- package/src/control/Control.Layers.js +443 -0
- package/src/control/Control.Scale.js +132 -0
- package/src/control/Control.Zoom.js +146 -0
- package/src/control/Control.js +174 -0
- package/src/control/index.js +17 -0
- package/src/core/Browser.js +220 -0
- package/src/core/Class.js +135 -0
- package/src/core/Events.js +344 -0
- package/src/core/Handler.js +57 -0
- package/src/core/Util.js +241 -0
- package/src/core/index.js +15 -0
- package/src/dom/DomEvent.DoubleTap.js +91 -0
- package/src/dom/DomEvent.Pointer.js +97 -0
- package/src/dom/DomEvent.js +315 -0
- package/src/dom/DomUtil.js +349 -0
- package/src/dom/Draggable.js +220 -0
- package/src/dom/PosAnimation.js +113 -0
- package/src/dom/index.js +9 -0
- package/src/geo/LatLng.js +137 -0
- package/src/geo/LatLngBounds.js +251 -0
- package/src/geo/crs/CRS.EPSG3395.js +20 -0
- package/src/geo/crs/CRS.EPSG3857.js +27 -0
- package/src/geo/crs/CRS.EPSG4326.js +23 -0
- package/src/geo/crs/CRS.Earth.js +33 -0
- package/src/geo/crs/CRS.Simple.js +36 -0
- package/src/geo/crs/CRS.js +139 -0
- package/src/geo/crs/index.js +15 -0
- package/src/geo/index.js +7 -0
- package/src/geo/projection/Projection.LonLat.js +28 -0
- package/src/geo/projection/Projection.Mercator.js +49 -0
- package/src/geo/projection/Projection.SphericalMercator.js +44 -0
- package/src/geo/projection/index.js +26 -0
- package/src/geometry/Bounds.js +219 -0
- package/src/geometry/LineUtil.js +306 -0
- package/src/geometry/Point.js +222 -0
- package/src/geometry/PolyUtil.js +129 -0
- package/src/geometry/Transformation.js +79 -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.svg +1 -0
- package/src/layer/DivOverlay.js +348 -0
- package/src/layer/FeatureGroup.js +94 -0
- package/src/layer/GeoJSON.js +452 -0
- package/src/layer/ImageOverlay.js +270 -0
- package/src/layer/Layer.js +275 -0
- package/src/layer/LayerGroup.js +159 -0
- package/src/layer/Popup.js +506 -0
- package/src/layer/SVGOverlay.js +50 -0
- package/src/layer/Tooltip.js +444 -0
- package/src/layer/VideoOverlay.js +106 -0
- package/src/layer/index.js +24 -0
- package/src/layer/marker/DivIcon.js +74 -0
- package/src/layer/marker/Icon.Default.js +66 -0
- package/src/layer/marker/Icon.js +165 -0
- package/src/layer/marker/Marker.Drag.js +161 -0
- package/src/layer/marker/Marker.js +419 -0
- package/src/layer/marker/index.js +8 -0
- package/src/layer/tile/GridLayer.js +923 -0
- package/src/layer/tile/TileLayer.WMS.js +137 -0
- package/src/layer/tile/TileLayer.js +289 -0
- package/src/layer/tile/index.js +6 -0
- package/src/layer/vector/Canvas.js +493 -0
- package/src/layer/vector/Circle.js +113 -0
- package/src/layer/vector/CircleMarker.js +109 -0
- package/src/layer/vector/Path.js +148 -0
- package/src/layer/vector/Polygon.js +159 -0
- package/src/layer/vector/Polyline.js +307 -0
- package/src/layer/vector/Rectangle.js +57 -0
- package/src/layer/vector/Renderer.getRenderer.js +45 -0
- package/src/layer/vector/Renderer.js +133 -0
- package/src/layer/vector/SVG.Util.js +39 -0
- package/src/layer/vector/SVG.VML.js +144 -0
- package/src/layer/vector/SVG.js +207 -0
- package/src/layer/vector/index.js +14 -0
- package/src/map/Map.js +1751 -0
- package/src/map/handler/Map.BoxZoom.js +152 -0
- package/src/map/handler/Map.DoubleClickZoom.js +55 -0
- package/src/map/handler/Map.Drag.js +235 -0
- package/src/map/handler/Map.Keyboard.js +183 -0
- package/src/map/handler/Map.ScrollWheelZoom.js +91 -0
- package/src/map/handler/Map.TapHold.js +102 -0
- package/src/map/handler/Map.TouchZoom.js +130 -0
- package/src/map/index.js +17 -0
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import * as DomEvent from './DomEvent';
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
* Extends the event handling code with double tap support for mobile browsers.
|
|
5
|
+
*
|
|
6
|
+
* Note: currently most browsers fire native dblclick, with only a few exceptions
|
|
7
|
+
* (see https://github.com/Leaflet/Leaflet/issues/7012#issuecomment-595087386)
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
function makeDblclick(event) {
|
|
11
|
+
// in modern browsers `type` cannot be just overridden:
|
|
12
|
+
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/Getter_only
|
|
13
|
+
var newEvent = {},
|
|
14
|
+
prop, i;
|
|
15
|
+
for (i in event) {
|
|
16
|
+
prop = event[i];
|
|
17
|
+
newEvent[i] = prop && prop.bind ? prop.bind(event) : prop;
|
|
18
|
+
}
|
|
19
|
+
event = newEvent;
|
|
20
|
+
newEvent.type = 'dblclick';
|
|
21
|
+
newEvent.detail = 2;
|
|
22
|
+
newEvent.isTrusted = false;
|
|
23
|
+
newEvent._simulated = true; // for debug purposes
|
|
24
|
+
return newEvent;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
var delay = 200;
|
|
28
|
+
export function addDoubleTapListener(obj, handler) {
|
|
29
|
+
// Most browsers handle double tap natively
|
|
30
|
+
obj.addEventListener('dblclick', handler);
|
|
31
|
+
|
|
32
|
+
// On some platforms the browser doesn't fire native dblclicks for touch events.
|
|
33
|
+
// It seems that in all such cases `detail` property of `click` event is always `1`.
|
|
34
|
+
// So here we rely on that fact to avoid excessive 'dblclick' simulation when not needed.
|
|
35
|
+
var last = 0,
|
|
36
|
+
detail;
|
|
37
|
+
function simDblclick(e) {
|
|
38
|
+
if (e.detail !== 1) {
|
|
39
|
+
detail = e.detail; // keep in sync to avoid false dblclick in some cases
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
if (e.pointerType === 'mouse' ||
|
|
44
|
+
(e.sourceCapabilities && !e.sourceCapabilities.firesTouchEvents)) {
|
|
45
|
+
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// When clicking on an <input>, the browser generates a click on its
|
|
50
|
+
// <label> (and vice versa) triggering two clicks in quick succession.
|
|
51
|
+
// This ignores clicks on elements which are a label with a 'for'
|
|
52
|
+
// attribute (or children of such a label), but not children of
|
|
53
|
+
// a <input>.
|
|
54
|
+
var path = DomEvent.getPropagationPath(e);
|
|
55
|
+
if (path.some(function (el) {
|
|
56
|
+
return el instanceof HTMLLabelElement && el.attributes.for;
|
|
57
|
+
}) &&
|
|
58
|
+
!path.some(function (el) {
|
|
59
|
+
return (
|
|
60
|
+
el instanceof HTMLInputElement ||
|
|
61
|
+
el instanceof HTMLSelectElement
|
|
62
|
+
);
|
|
63
|
+
})
|
|
64
|
+
) {
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
var now = Date.now();
|
|
69
|
+
if (now - last <= delay) {
|
|
70
|
+
detail++;
|
|
71
|
+
if (detail === 2) {
|
|
72
|
+
handler(makeDblclick(e));
|
|
73
|
+
}
|
|
74
|
+
} else {
|
|
75
|
+
detail = 1;
|
|
76
|
+
}
|
|
77
|
+
last = now;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
obj.addEventListener('click', simDblclick);
|
|
81
|
+
|
|
82
|
+
return {
|
|
83
|
+
dblclick: handler,
|
|
84
|
+
simDblclick: simDblclick
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export function removeDoubleTapListener(obj, handlers) {
|
|
89
|
+
obj.removeEventListener('dblclick', handlers.dblclick);
|
|
90
|
+
obj.removeEventListener('click', handlers.simDblclick);
|
|
91
|
+
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import * as DomEvent from './DomEvent';
|
|
2
|
+
import Browser from '../core/Browser';
|
|
3
|
+
import {falseFn} from '../core/Util';
|
|
4
|
+
|
|
5
|
+
/*
|
|
6
|
+
* Extends L.DomEvent to provide touch support for Internet Explorer and Windows-based devices.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
var POINTER_DOWN = Browser.msPointer ? 'MSPointerDown' : 'pointerdown';
|
|
10
|
+
var POINTER_MOVE = Browser.msPointer ? 'MSPointerMove' : 'pointermove';
|
|
11
|
+
var POINTER_UP = Browser.msPointer ? 'MSPointerUp' : 'pointerup';
|
|
12
|
+
var POINTER_CANCEL = Browser.msPointer ? 'MSPointerCancel' : 'pointercancel';
|
|
13
|
+
var pEvent = {
|
|
14
|
+
touchstart : POINTER_DOWN,
|
|
15
|
+
touchmove : POINTER_MOVE,
|
|
16
|
+
touchend : POINTER_UP,
|
|
17
|
+
touchcancel : POINTER_CANCEL
|
|
18
|
+
};
|
|
19
|
+
var handle = {
|
|
20
|
+
touchstart : _onPointerStart,
|
|
21
|
+
touchmove : _handlePointer,
|
|
22
|
+
touchend : _handlePointer,
|
|
23
|
+
touchcancel : _handlePointer
|
|
24
|
+
};
|
|
25
|
+
var _pointers = {};
|
|
26
|
+
var _pointerDocListener = false;
|
|
27
|
+
|
|
28
|
+
// Provides a touch events wrapper for (ms)pointer events.
|
|
29
|
+
// ref https://www.w3.org/TR/pointerevents/ https://www.w3.org/Bugs/Public/show_bug.cgi?id=22890
|
|
30
|
+
|
|
31
|
+
export function addPointerListener(obj, type, handler) {
|
|
32
|
+
if (type === 'touchstart') {
|
|
33
|
+
_addPointerDocListener();
|
|
34
|
+
}
|
|
35
|
+
if (!handle[type]) {
|
|
36
|
+
console.warn('wrong event specified:', type);
|
|
37
|
+
return falseFn;
|
|
38
|
+
}
|
|
39
|
+
handler = handle[type].bind(this, handler);
|
|
40
|
+
obj.addEventListener(pEvent[type], handler, false);
|
|
41
|
+
return handler;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export function removePointerListener(obj, type, handler) {
|
|
45
|
+
if (!pEvent[type]) {
|
|
46
|
+
console.warn('wrong event specified:', type);
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
obj.removeEventListener(pEvent[type], handler, false);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function _globalPointerDown(e) {
|
|
53
|
+
_pointers[e.pointerId] = e;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function _globalPointerMove(e) {
|
|
57
|
+
if (_pointers[e.pointerId]) {
|
|
58
|
+
_pointers[e.pointerId] = e;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function _globalPointerUp(e) {
|
|
63
|
+
delete _pointers[e.pointerId];
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function _addPointerDocListener() {
|
|
67
|
+
// need to keep track of what pointers and how many are active to provide e.touches emulation
|
|
68
|
+
if (!_pointerDocListener) {
|
|
69
|
+
// we listen document as any drags that end by moving the touch off the screen get fired there
|
|
70
|
+
document.addEventListener(POINTER_DOWN, _globalPointerDown, true);
|
|
71
|
+
document.addEventListener(POINTER_MOVE, _globalPointerMove, true);
|
|
72
|
+
document.addEventListener(POINTER_UP, _globalPointerUp, true);
|
|
73
|
+
document.addEventListener(POINTER_CANCEL, _globalPointerUp, true);
|
|
74
|
+
|
|
75
|
+
_pointerDocListener = true;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function _handlePointer(handler, e) {
|
|
80
|
+
if (e.pointerType === (e.MSPOINTER_TYPE_MOUSE || 'mouse')) { return; }
|
|
81
|
+
|
|
82
|
+
e.touches = [];
|
|
83
|
+
for (var i in _pointers) {
|
|
84
|
+
e.touches.push(_pointers[i]);
|
|
85
|
+
}
|
|
86
|
+
e.changedTouches = [e];
|
|
87
|
+
|
|
88
|
+
handler(e);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function _onPointerStart(handler, e) {
|
|
92
|
+
// IE10 specific: MsTouch needs preventDefault. See #2000
|
|
93
|
+
if (e.MSPOINTER_TYPE_TOUCH && e.pointerType === e.MSPOINTER_TYPE_TOUCH) {
|
|
94
|
+
DomEvent.preventDefault(e);
|
|
95
|
+
}
|
|
96
|
+
_handlePointer(handler, e);
|
|
97
|
+
}
|
|
@@ -0,0 +1,315 @@
|
|
|
1
|
+
import {Point} from '../geometry/Point';
|
|
2
|
+
import * as Util from '../core/Util';
|
|
3
|
+
import Browser from '../core/Browser';
|
|
4
|
+
import {addPointerListener, removePointerListener} from './DomEvent.Pointer';
|
|
5
|
+
import {addDoubleTapListener, removeDoubleTapListener} from './DomEvent.DoubleTap';
|
|
6
|
+
import {getScale} from './DomUtil';
|
|
7
|
+
|
|
8
|
+
/*
|
|
9
|
+
* @namespace DomEvent
|
|
10
|
+
* Utility functions to work with the [DOM events](https://developer.mozilla.org/docs/Web/API/Event), used by Leaflet internally.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
// Inspired by John Resig, Dean Edwards and YUI addEvent implementations.
|
|
14
|
+
|
|
15
|
+
// @function on(el: HTMLElement, types: String, fn: Function, context?: Object): this
|
|
16
|
+
// Adds a listener function (`fn`) to a particular DOM event type of the
|
|
17
|
+
// element `el`. You can optionally specify the context of the listener
|
|
18
|
+
// (object the `this` keyword will point to). You can also pass several
|
|
19
|
+
// space-separated types (e.g. `'click dblclick'`).
|
|
20
|
+
|
|
21
|
+
// @alternative
|
|
22
|
+
// @function on(el: HTMLElement, eventMap: Object, context?: Object): this
|
|
23
|
+
// Adds a set of type/listener pairs, e.g. `{click: onClick, mousemove: onMouseMove}`
|
|
24
|
+
export function on(obj, types, fn, context) {
|
|
25
|
+
|
|
26
|
+
if (types && typeof types === 'object') {
|
|
27
|
+
for (var type in types) {
|
|
28
|
+
addOne(obj, type, types[type], fn);
|
|
29
|
+
}
|
|
30
|
+
} else {
|
|
31
|
+
types = Util.splitWords(types);
|
|
32
|
+
|
|
33
|
+
for (var i = 0, len = types.length; i < len; i++) {
|
|
34
|
+
addOne(obj, types[i], fn, context);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return this;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
var eventsKey = '_leaflet_events';
|
|
42
|
+
|
|
43
|
+
// @function off(el: HTMLElement, types: String, fn: Function, context?: Object): this
|
|
44
|
+
// Removes a previously added listener function.
|
|
45
|
+
// Note that if you passed a custom context to on, you must pass the same
|
|
46
|
+
// context to `off` in order to remove the listener.
|
|
47
|
+
|
|
48
|
+
// @alternative
|
|
49
|
+
// @function off(el: HTMLElement, eventMap: Object, context?: Object): this
|
|
50
|
+
// Removes a set of type/listener pairs, e.g. `{click: onClick, mousemove: onMouseMove}`
|
|
51
|
+
|
|
52
|
+
// @alternative
|
|
53
|
+
// @function off(el: HTMLElement, types: String): this
|
|
54
|
+
// Removes all previously added listeners of given types.
|
|
55
|
+
|
|
56
|
+
// @alternative
|
|
57
|
+
// @function off(el: HTMLElement): this
|
|
58
|
+
// Removes all previously added listeners from given HTMLElement
|
|
59
|
+
export function off(obj, types, fn, context) {
|
|
60
|
+
|
|
61
|
+
if (arguments.length === 1) {
|
|
62
|
+
batchRemove(obj);
|
|
63
|
+
delete obj[eventsKey];
|
|
64
|
+
|
|
65
|
+
} else if (types && typeof types === 'object') {
|
|
66
|
+
for (var type in types) {
|
|
67
|
+
removeOne(obj, type, types[type], fn);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
} else {
|
|
71
|
+
types = Util.splitWords(types);
|
|
72
|
+
|
|
73
|
+
if (arguments.length === 2) {
|
|
74
|
+
batchRemove(obj, function (type) {
|
|
75
|
+
return Util.indexOf(types, type) !== -1;
|
|
76
|
+
});
|
|
77
|
+
} else {
|
|
78
|
+
for (var i = 0, len = types.length; i < len; i++) {
|
|
79
|
+
removeOne(obj, types[i], fn, context);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
return this;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function batchRemove(obj, filterFn) {
|
|
88
|
+
for (var id in obj[eventsKey]) {
|
|
89
|
+
var type = id.split(/\d/)[0];
|
|
90
|
+
if (!filterFn || filterFn(type)) {
|
|
91
|
+
removeOne(obj, type, null, null, id);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
var mouseSubst = {
|
|
97
|
+
mouseenter: 'mouseover',
|
|
98
|
+
mouseleave: 'mouseout',
|
|
99
|
+
wheel: !('onwheel' in window) && 'mousewheel'
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
function addOne(obj, type, fn, context) {
|
|
103
|
+
var id = type + Util.stamp(fn) + (context ? '_' + Util.stamp(context) : '');
|
|
104
|
+
|
|
105
|
+
if (obj[eventsKey] && obj[eventsKey][id]) { return this; }
|
|
106
|
+
|
|
107
|
+
var handler = function (e) {
|
|
108
|
+
return fn.call(context || obj, e || window.event);
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
var originalHandler = handler;
|
|
112
|
+
|
|
113
|
+
if (!Browser.touchNative && Browser.pointer && type.indexOf('touch') === 0) {
|
|
114
|
+
// Needs DomEvent.Pointer.js
|
|
115
|
+
handler = addPointerListener(obj, type, handler);
|
|
116
|
+
|
|
117
|
+
} else if (Browser.touch && (type === 'dblclick')) {
|
|
118
|
+
handler = addDoubleTapListener(obj, handler);
|
|
119
|
+
|
|
120
|
+
} else if ('addEventListener' in obj) {
|
|
121
|
+
|
|
122
|
+
if (type === 'touchstart' || type === 'touchmove' || type === 'wheel' || type === 'mousewheel') {
|
|
123
|
+
obj.addEventListener(mouseSubst[type] || type, handler, Browser.passiveEvents ? {passive: false} : false);
|
|
124
|
+
|
|
125
|
+
} else if (type === 'mouseenter' || type === 'mouseleave') {
|
|
126
|
+
handler = function (e) {
|
|
127
|
+
e = e || window.event;
|
|
128
|
+
if (isExternalTarget(obj, e)) {
|
|
129
|
+
originalHandler(e);
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
obj.addEventListener(mouseSubst[type], handler, false);
|
|
133
|
+
|
|
134
|
+
} else {
|
|
135
|
+
obj.addEventListener(type, originalHandler, false);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
} else {
|
|
139
|
+
obj.attachEvent('on' + type, handler);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
obj[eventsKey] = obj[eventsKey] || {};
|
|
143
|
+
obj[eventsKey][id] = handler;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
function removeOne(obj, type, fn, context, id) {
|
|
147
|
+
id = id || type + Util.stamp(fn) + (context ? '_' + Util.stamp(context) : '');
|
|
148
|
+
var handler = obj[eventsKey] && obj[eventsKey][id];
|
|
149
|
+
|
|
150
|
+
if (!handler) { return this; }
|
|
151
|
+
|
|
152
|
+
if (!Browser.touchNative && Browser.pointer && type.indexOf('touch') === 0) {
|
|
153
|
+
removePointerListener(obj, type, handler);
|
|
154
|
+
|
|
155
|
+
} else if (Browser.touch && (type === 'dblclick')) {
|
|
156
|
+
removeDoubleTapListener(obj, handler);
|
|
157
|
+
|
|
158
|
+
} else if ('removeEventListener' in obj) {
|
|
159
|
+
|
|
160
|
+
obj.removeEventListener(mouseSubst[type] || type, handler, false);
|
|
161
|
+
|
|
162
|
+
} else {
|
|
163
|
+
obj.detachEvent('on' + type, handler);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
obj[eventsKey][id] = null;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
// @function stopPropagation(ev: DOMEvent): this
|
|
170
|
+
// Stop the given event from propagation to parent elements. Used inside the listener functions:
|
|
171
|
+
// ```js
|
|
172
|
+
// L.DomEvent.on(div, 'click', function (ev) {
|
|
173
|
+
// L.DomEvent.stopPropagation(ev);
|
|
174
|
+
// });
|
|
175
|
+
// ```
|
|
176
|
+
export function stopPropagation(e) {
|
|
177
|
+
|
|
178
|
+
if (e.stopPropagation) {
|
|
179
|
+
e.stopPropagation();
|
|
180
|
+
} else if (e.originalEvent) { // In case of Leaflet event.
|
|
181
|
+
e.originalEvent._stopped = true;
|
|
182
|
+
} else {
|
|
183
|
+
e.cancelBubble = true;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
return this;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
// @function disableScrollPropagation(el: HTMLElement): this
|
|
190
|
+
// Adds `stopPropagation` to the element's `'wheel'` events (plus browser variants).
|
|
191
|
+
export function disableScrollPropagation(el) {
|
|
192
|
+
addOne(el, 'wheel', stopPropagation);
|
|
193
|
+
return this;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
// @function disableClickPropagation(el: HTMLElement): this
|
|
197
|
+
// Adds `stopPropagation` to the element's `'click'`, `'dblclick'`, `'contextmenu'`,
|
|
198
|
+
// `'mousedown'` and `'touchstart'` events (plus browser variants).
|
|
199
|
+
export function disableClickPropagation(el) {
|
|
200
|
+
on(el, 'mousedown touchstart dblclick contextmenu', stopPropagation);
|
|
201
|
+
el['_leaflet_disable_click'] = true;
|
|
202
|
+
return this;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
// @function preventDefault(ev: DOMEvent): this
|
|
206
|
+
// Prevents the default action of the DOM Event `ev` from happening (such as
|
|
207
|
+
// following a link in the href of the a element, or doing a POST request
|
|
208
|
+
// with page reload when a `<form>` is submitted).
|
|
209
|
+
// Use it inside listener functions.
|
|
210
|
+
export function preventDefault(e) {
|
|
211
|
+
if (e.preventDefault) {
|
|
212
|
+
e.preventDefault();
|
|
213
|
+
} else {
|
|
214
|
+
e.returnValue = false;
|
|
215
|
+
}
|
|
216
|
+
return this;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
// @function stop(ev: DOMEvent): this
|
|
220
|
+
// Does `stopPropagation` and `preventDefault` at the same time.
|
|
221
|
+
export function stop(e) {
|
|
222
|
+
preventDefault(e);
|
|
223
|
+
stopPropagation(e);
|
|
224
|
+
return this;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
// @function getPropagationPath(ev: DOMEvent): Array
|
|
228
|
+
// Compatibility polyfill for [`Event.composedPath()`](https://developer.mozilla.org/en-US/docs/Web/API/Event/composedPath).
|
|
229
|
+
// Returns an array containing the `HTMLElement`s that the given DOM event
|
|
230
|
+
// should propagate to (if not stopped).
|
|
231
|
+
export function getPropagationPath(ev) {
|
|
232
|
+
if (ev.composedPath) {
|
|
233
|
+
return ev.composedPath();
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
var path = [];
|
|
237
|
+
var el = ev.target;
|
|
238
|
+
|
|
239
|
+
while (el) {
|
|
240
|
+
path.push(el);
|
|
241
|
+
el = el.parentNode;
|
|
242
|
+
}
|
|
243
|
+
return path;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
|
|
247
|
+
// @function getMousePosition(ev: DOMEvent, container?: HTMLElement): Point
|
|
248
|
+
// Gets normalized mouse position from a DOM event relative to the
|
|
249
|
+
// `container` (border excluded) or to the whole page if not specified.
|
|
250
|
+
export function getMousePosition(e, container) {
|
|
251
|
+
if (!container) {
|
|
252
|
+
return new Point(e.clientX, e.clientY);
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
var scale = getScale(container),
|
|
256
|
+
offset = scale.boundingClientRect; // left and top values are in page scale (like the event clientX/Y)
|
|
257
|
+
|
|
258
|
+
return new Point(
|
|
259
|
+
// offset.left/top values are in page scale (like clientX/Y),
|
|
260
|
+
// whereas clientLeft/Top (border width) values are the original values (before CSS scale applies).
|
|
261
|
+
(e.clientX - offset.left) / scale.x - container.clientLeft,
|
|
262
|
+
(e.clientY - offset.top) / scale.y - container.clientTop
|
|
263
|
+
);
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
|
|
267
|
+
// except , Safari and
|
|
268
|
+
// We need double the scroll pixels (see #7403 and #4538) for all Browsers
|
|
269
|
+
// except OSX (Mac) -> 3x, Chrome running on Linux 1x
|
|
270
|
+
|
|
271
|
+
var wheelPxFactor =
|
|
272
|
+
(Browser.linux && Browser.chrome) ? window.devicePixelRatio :
|
|
273
|
+
Browser.mac ? window.devicePixelRatio * 3 :
|
|
274
|
+
window.devicePixelRatio > 0 ? 2 * window.devicePixelRatio : 1;
|
|
275
|
+
// @function getWheelDelta(ev: DOMEvent): Number
|
|
276
|
+
// Gets normalized wheel delta from a wheel DOM event, in vertical
|
|
277
|
+
// pixels scrolled (negative if scrolling down).
|
|
278
|
+
// Events from pointing devices without precise scrolling are mapped to
|
|
279
|
+
// a best guess of 60 pixels.
|
|
280
|
+
export function getWheelDelta(e) {
|
|
281
|
+
return (Browser.edge) ? e.wheelDeltaY / 2 : // Don't trust window-geometry-based delta
|
|
282
|
+
(e.deltaY && e.deltaMode === 0) ? -e.deltaY / wheelPxFactor : // Pixels
|
|
283
|
+
(e.deltaY && e.deltaMode === 1) ? -e.deltaY * 20 : // Lines
|
|
284
|
+
(e.deltaY && e.deltaMode === 2) ? -e.deltaY * 60 : // Pages
|
|
285
|
+
(e.deltaX || e.deltaZ) ? 0 : // Skip horizontal/depth wheel events
|
|
286
|
+
e.wheelDelta ? (e.wheelDeltaY || e.wheelDelta) / 2 : // Legacy IE pixels
|
|
287
|
+
(e.detail && Math.abs(e.detail) < 32765) ? -e.detail * 20 : // Legacy Moz lines
|
|
288
|
+
e.detail ? e.detail / -32765 * 60 : // Legacy Moz pages
|
|
289
|
+
0;
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
// check if element really left/entered the event target (for mouseenter/mouseleave)
|
|
293
|
+
export function isExternalTarget(el, e) {
|
|
294
|
+
|
|
295
|
+
var related = e.relatedTarget;
|
|
296
|
+
|
|
297
|
+
if (!related) { return true; }
|
|
298
|
+
|
|
299
|
+
try {
|
|
300
|
+
while (related && (related !== el)) {
|
|
301
|
+
related = related.parentNode;
|
|
302
|
+
}
|
|
303
|
+
} catch (err) {
|
|
304
|
+
return false;
|
|
305
|
+
}
|
|
306
|
+
return (related !== el);
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
// @function addListener(…): this
|
|
310
|
+
// Alias to [`L.DomEvent.on`](#domevent-on)
|
|
311
|
+
export {on as addListener};
|
|
312
|
+
|
|
313
|
+
// @function removeListener(…): this
|
|
314
|
+
// Alias to [`L.DomEvent.off`](#domevent-off)
|
|
315
|
+
export {off as removeListener};
|