leaflet-rotate 0.2.1 → 0.2.3
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/dist/leaflet-rotate-src.js +364 -211
- package/dist/leaflet-rotate-src.js.map +1 -1
- package/dist/leaflet-rotate.js +364 -211
- package/dist/leaflet-rotate.js.map +1 -1
- package/package.json +1 -1
- package/src/control/Rotate.js +42 -41
- package/src/dom/DomUtil.js +32 -2
- package/src/dom/Draggable.js +7 -0
- package/src/geo/LatLngBounds.js +13 -0
- package/src/geometry/Bounds.js +13 -0
- package/src/geometry/Point.js +5 -0
- package/src/index.js +16 -3
- package/src/layer/DivOverlay.js +11 -4
- package/src/layer/Popup.js +6 -6
- package/src/layer/marker/Marker.js +29 -17
- package/src/layer/tile/GridLayer.js +6 -0
- package/src/layer/vector/Renderer.js +83 -13
- package/src/map/Map.js +6 -1
- package/src/map/handler/CompassBearing.js +52 -11
- package/src/map/handler/ContainerMutation.js +23 -24
- package/src/map/handler/ShiftKeyRotate.js +11 -10
- package/src/map/handler/TouchGestures.js +20 -10
- package/src/map/handler/TouchRotate.js +10 -8
- package/src/map/handler/TouchZoom.js +20 -15
- package/test/index.html +2 -1
- package/src/layer/vector/Canvas.js +0 -28
- package/src/layer/vector/SVG.js +0 -18
|
@@ -8,30 +8,71 @@ L.Map.CompassBearing = L.Handler.extend({
|
|
|
8
8
|
|
|
9
9
|
initialize: function(map) {
|
|
10
10
|
this._map = map;
|
|
11
|
-
|
|
11
|
+
/** @see https://caniuse.com/?search=DeviceOrientation */
|
|
12
|
+
if ('ondeviceorientationabsolute' in window) {
|
|
13
|
+
this.__deviceOrientationEvent = 'deviceorientationabsolute';
|
|
14
|
+
} else if('ondeviceorientation' in window) {
|
|
15
|
+
this.__deviceOrientationEvent = 'deviceorientation';
|
|
16
|
+
}
|
|
17
|
+
this._throttled = L.Util.throttle(this._onDeviceOrientation, 100, this);
|
|
12
18
|
},
|
|
13
19
|
|
|
14
20
|
addHooks: function() {
|
|
15
|
-
if (this._map._rotate &&
|
|
16
|
-
L.DomEvent.on(window,
|
|
21
|
+
if (this._map._rotate && this.__deviceOrientationEvent) {
|
|
22
|
+
L.DomEvent.on(window, this.__deviceOrientationEvent, this._throttled, this);
|
|
23
|
+
} else {
|
|
24
|
+
// L.Map.CompassBearing handler will be automatically
|
|
25
|
+
// disabled if device orientation is not supported.
|
|
26
|
+
this.disable();
|
|
17
27
|
}
|
|
18
28
|
},
|
|
19
29
|
|
|
20
30
|
removeHooks: function() {
|
|
21
|
-
if (this._map._rotate &&
|
|
22
|
-
L.DomEvent.off(window,
|
|
31
|
+
if (this._map._rotate && this.__deviceOrientationEvent) {
|
|
32
|
+
L.DomEvent.off(window, this.__deviceOrientationEvent, this._throttled, this);
|
|
23
33
|
}
|
|
24
34
|
},
|
|
25
35
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
36
|
+
/**
|
|
37
|
+
* `DeviceOrientationEvent.absolute` - Indicates whether the device is providing absolute
|
|
38
|
+
* orientation values (relatives to Magnetic North) or
|
|
39
|
+
* using some arbitrary frame determined by the device.
|
|
40
|
+
*
|
|
41
|
+
* `DeviceOrientationEvent.alpha` - Returns the rotation of the device around the Z axis;
|
|
42
|
+
* that is, the number of degrees by which the device is
|
|
43
|
+
* being twisted around the center of the screen.
|
|
44
|
+
*
|
|
45
|
+
* `window.orientation` - Returns the screen orientation in degrees (in 90-degree increments)
|
|
46
|
+
* of the viewport relative to the device's natural orientation.
|
|
47
|
+
* Its only possible values are -90, 0, 90, and 180. Positive
|
|
48
|
+
* values are counterclockwise; negative values are clockwise.
|
|
49
|
+
*
|
|
50
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/DeviceOrientationEvent/absolute
|
|
51
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/DeviceOrientationEvent/alpha
|
|
52
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/Window/orientation
|
|
53
|
+
*/
|
|
54
|
+
_onDeviceOrientation: function(e) {
|
|
55
|
+
var angle = e.webkitCompassHeading || e.alpha;
|
|
56
|
+
var deviceOrientation = 0;
|
|
57
|
+
|
|
58
|
+
// Safari iOS
|
|
59
|
+
if (!e.absolute && e.webkitCompassHeading) {
|
|
60
|
+
angle = 360 - angle;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// Older browsers
|
|
64
|
+
if (!e.absolute && 'undefined' !== typeof window.orientation) {
|
|
65
|
+
deviceOrientation = window.orientation;
|
|
29
66
|
}
|
|
67
|
+
|
|
68
|
+
this._map.setBearing(angle - deviceOrientation);
|
|
30
69
|
},
|
|
31
70
|
|
|
32
71
|
});
|
|
33
72
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
73
|
+
/**
|
|
74
|
+
* Add Compass bearing handler to L.Map (disabled unless `window.DeviceOrientationEvent` is set).
|
|
75
|
+
*
|
|
76
|
+
* @property {L.Map.CompassBearing} compassBearing
|
|
77
|
+
*/
|
|
37
78
|
L.Map.addInitHook('addHandler', 'compassBearing', L.Map.CompassBearing);
|
|
@@ -4,14 +4,23 @@
|
|
|
4
4
|
* @typedef L.Map.ContainerMutation
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
/**
|
|
8
|
+
* @TODO check again this file after leaflet v1.9.3 (eg. L.Browser.mutation).
|
|
9
|
+
* Mutation Observer support will likely be added by default in next releases.
|
|
10
|
+
*/
|
|
11
|
+
|
|
9
12
|
L.Map.mergeOptions({
|
|
10
13
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
14
|
+
/**
|
|
15
|
+
* Whether the map uses mutation observers to
|
|
16
|
+
* detect changes in its container and trigger
|
|
17
|
+
* `invalidateSize`. Disabled by default due to
|
|
18
|
+
* support not being available in all web browsers.
|
|
19
|
+
*
|
|
20
|
+
* @type {Boolean}
|
|
21
|
+
*
|
|
22
|
+
* @see https://developer.mozilla.org/docs/Web/API/MutationObserver
|
|
23
|
+
*/
|
|
15
24
|
trackContainerMutation: false
|
|
16
25
|
|
|
17
26
|
});
|
|
@@ -19,15 +28,10 @@ L.Map.mergeOptions({
|
|
|
19
28
|
L.Map.ContainerMutation = L.Handler.extend({
|
|
20
29
|
|
|
21
30
|
addHooks: function() {
|
|
22
|
-
|
|
23
|
-
// if (!L.Browser.mutation) {
|
|
24
|
-
// return;
|
|
25
|
-
// }
|
|
26
|
-
|
|
31
|
+
// if (!L.Browser.mutation) { return; }
|
|
27
32
|
if (!this._observer) {
|
|
28
|
-
this._observer = new MutationObserver(L.Util.bind(this.
|
|
33
|
+
this._observer = new MutationObserver(L.Util.bind(this._map.invalidateSize, this._map));
|
|
29
34
|
}
|
|
30
|
-
|
|
31
35
|
this._observer.observe(this._map.getContainer(), {
|
|
32
36
|
childList: false,
|
|
33
37
|
attributes: true,
|
|
@@ -38,20 +42,15 @@ L.Map.ContainerMutation = L.Handler.extend({
|
|
|
38
42
|
},
|
|
39
43
|
|
|
40
44
|
removeHooks: function() {
|
|
41
|
-
|
|
42
|
-
// if (!L.Browser.mutation) {
|
|
43
|
-
// return;
|
|
44
|
-
// }
|
|
45
|
+
// if (!L.Browser.mutation) { return; }
|
|
45
46
|
this._observer.disconnect();
|
|
46
47
|
},
|
|
47
48
|
|
|
48
|
-
_onMutation: function() {
|
|
49
|
-
this._map.invalidateSize();
|
|
50
|
-
},
|
|
51
|
-
|
|
52
49
|
});
|
|
53
50
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
51
|
+
/**
|
|
52
|
+
* Add Container mutation handler to L.Map (disabled unless `trackContainerMutation` is set).
|
|
53
|
+
*
|
|
54
|
+
* @property {L.Map.ContainerMutation} trackContainerMutation
|
|
55
|
+
*/
|
|
57
56
|
L.Map.addInitHook('addHandler', 'trackContainerMutation', L.Map.ContainerMutation);
|
|
@@ -1,17 +1,16 @@
|
|
|
1
1
|
|
|
2
2
|
/**
|
|
3
|
-
* Rotates the map on shift key +
|
|
3
|
+
* Rotates the map on shift key + mousewheel scrolling (desktop).
|
|
4
4
|
*
|
|
5
5
|
* @typedef L.Map.ShiftKeyRotate
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
// @namespace Map
|
|
9
|
-
// @section Interaction Options
|
|
10
8
|
L.Map.mergeOptions({
|
|
11
9
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
10
|
+
/**
|
|
11
|
+
* Whether the map can be rotated with shift + wheel scroll
|
|
12
|
+
* @type {Boolean}
|
|
13
|
+
*/
|
|
15
14
|
shiftKeyRotate: true,
|
|
16
15
|
|
|
17
16
|
});
|
|
@@ -41,12 +40,14 @@ L.Map.ShiftKeyRotate = L.Handler.extend({
|
|
|
41
40
|
|
|
42
41
|
});
|
|
43
42
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
43
|
+
/**
|
|
44
|
+
* Add ShiftKey handler to L.Map (enabled unless `shiftKeyRotate` is unset).
|
|
45
|
+
*
|
|
46
|
+
* @property {L.Map.ShiftKeyRotate} shiftKeyRotate
|
|
47
|
+
*/
|
|
47
48
|
L.Map.addInitHook('addHandler', 'shiftKeyRotate', L.Map.ShiftKeyRotate);
|
|
48
49
|
|
|
49
|
-
// decrease
|
|
50
|
+
// decrease `scrollWheelZoom` handler priority over `shiftKeyRotate` handler
|
|
50
51
|
L.Map.addInitHook(function() {
|
|
51
52
|
if (this.scrollWheelZoom.enabled() && this.shiftKeyRotate.enabled()) {
|
|
52
53
|
this.scrollWheelZoom.disable();
|
|
@@ -7,13 +7,15 @@
|
|
|
7
7
|
* @typedef L.Map.TouchGestures
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
// @namespace Map
|
|
11
|
-
// @section Interaction Options
|
|
12
10
|
L.Map.mergeOptions({
|
|
13
11
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
12
|
+
/**
|
|
13
|
+
* Set it to false if you don't want the map to
|
|
14
|
+
* zoom beyond min/max zoom and then bounce back
|
|
15
|
+
* when pinch-zooming.
|
|
16
|
+
*
|
|
17
|
+
* @type {Boolean}
|
|
18
|
+
*/
|
|
17
19
|
bounceAtZoomLimits: true,
|
|
18
20
|
|
|
19
21
|
});
|
|
@@ -92,8 +94,14 @@ L.Map.TouchGestures = L.Handler.extend({
|
|
|
92
94
|
var bearingDelta = (theta - this._startTheta) * L.DomUtil.RAD_TO_DEG;
|
|
93
95
|
if (vector.y < 0) { bearingDelta += 180; }
|
|
94
96
|
if (bearingDelta) {
|
|
95
|
-
|
|
96
|
-
|
|
97
|
+
/**
|
|
98
|
+
* @TODO the pivot should be the last touch point,
|
|
99
|
+
* but zoomAnimation manages to overwrite the rotate
|
|
100
|
+
* pane position. Maybe related to #3529.
|
|
101
|
+
*
|
|
102
|
+
* @see https://github.com/Leaflet/Leaflet/pull/3529
|
|
103
|
+
* @see https://github.com/fnicollet/Leaflet/commit/a77af51a6b10f308d1b9a16552091d1d0aee8834
|
|
104
|
+
*/
|
|
97
105
|
map.setBearing(this._startBearing - bearingDelta);
|
|
98
106
|
}
|
|
99
107
|
}
|
|
@@ -161,7 +169,9 @@ L.Map.TouchGestures = L.Handler.extend({
|
|
|
161
169
|
|
|
162
170
|
});
|
|
163
171
|
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
172
|
+
/**
|
|
173
|
+
* Add Touch Gestures handler (enabled unless `touchGestures` is unset).
|
|
174
|
+
*
|
|
175
|
+
* @property {L.Map.TouchGestures} touchGestures
|
|
176
|
+
*/
|
|
167
177
|
L.Map.addInitHook('addHandler', 'touchGestures', L.Map.TouchGestures);
|
|
@@ -4,13 +4,13 @@
|
|
|
4
4
|
* @typedef L.Map.TouchRotate
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
// @namespace Map
|
|
8
|
-
// @section Interaction Options
|
|
9
7
|
L.Map.mergeOptions({
|
|
10
8
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
9
|
+
/**
|
|
10
|
+
* Whether the map can be rotated with a two-finger rotation gesture
|
|
11
|
+
*
|
|
12
|
+
* @type {Boolean}
|
|
13
|
+
*/
|
|
14
14
|
touchRotate: false,
|
|
15
15
|
|
|
16
16
|
});
|
|
@@ -28,7 +28,9 @@ L.Map.TouchRotate = L.Handler.extend({
|
|
|
28
28
|
|
|
29
29
|
});
|
|
30
30
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
31
|
+
/**
|
|
32
|
+
* Add Touch Rotate handler (disabled unless `touchGestures` is set).
|
|
33
|
+
*
|
|
34
|
+
* @property {L.Map.TouchGestures} touchGestures
|
|
35
|
+
*/
|
|
34
36
|
L.Map.addInitHook('addHandler', 'touchRotate', L.Map.TouchRotate);
|
|
@@ -6,25 +6,28 @@
|
|
|
6
6
|
* @external L.Map.TouchZoom
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
// @namespace Map
|
|
10
|
-
// @section Interaction Options
|
|
11
9
|
L.Map.mergeOptions({
|
|
12
10
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
11
|
+
/**
|
|
12
|
+
* Whether the map can be zoomed by touch-dragging
|
|
13
|
+
* with two fingers. If passed `'center'`, it will
|
|
14
|
+
* zoom to the center of the view regardless of
|
|
15
|
+
* where the touch events (fingers) were. Enabled
|
|
16
|
+
* for touch-capable web browsers.
|
|
17
|
+
*
|
|
18
|
+
* @type {(Boolean|String)}
|
|
19
|
+
*/
|
|
19
20
|
touchZoom: L.Browser.touch,
|
|
20
21
|
|
|
21
22
|
/**
|
|
22
23
|
* @TODO check if this is a duplicate of `L.Map.TouchGestures::bounceAtZoomLimits`
|
|
24
|
+
*
|
|
25
|
+
* Set it to false if you don't want the map to
|
|
26
|
+
* zoom beyond min/max zoom and then bounce back
|
|
27
|
+
* when pinch-zooming.
|
|
28
|
+
*
|
|
29
|
+
* @type {Boolean}
|
|
23
30
|
*/
|
|
24
|
-
|
|
25
|
-
// @option bounceAtZoomLimits: Boolean = true
|
|
26
|
-
// Set it to false if you don't want the map to zoom beyond min/max zoom
|
|
27
|
-
// and then bounce back when pinch-zooming.
|
|
28
31
|
bounceAtZoomLimits: false,
|
|
29
32
|
|
|
30
33
|
});
|
|
@@ -44,7 +47,9 @@ L.Map.TouchZoom = L.Handler.extend({
|
|
|
44
47
|
|
|
45
48
|
});
|
|
46
49
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
+
/**
|
|
51
|
+
* Add Touch Zoom handler (disabled unless `L.Browser.touch` is set).
|
|
52
|
+
*
|
|
53
|
+
* @property {L.Map.TouchGestures} touchGestures
|
|
54
|
+
*/
|
|
50
55
|
L.Map.addInitHook('addHandler', 'touchZoom', L.Map.TouchZoom);
|
package/test/index.html
CHANGED
|
@@ -79,6 +79,7 @@
|
|
|
79
79
|
layers: [esri],
|
|
80
80
|
// worldCopyJump: true,
|
|
81
81
|
// preferCanvas: false,
|
|
82
|
+
zoomAnimation: false, /* DEBUG: L.Renderer._updateTransform() */
|
|
82
83
|
rotate: true,
|
|
83
84
|
rotateControl: {
|
|
84
85
|
closeOnZeroBearing: false,
|
|
@@ -87,7 +88,7 @@
|
|
|
87
88
|
bearing: 30,
|
|
88
89
|
// attributionControl: false,
|
|
89
90
|
// zoomControl: false,
|
|
90
|
-
|
|
91
|
+
compassBearing: true,
|
|
91
92
|
// trackContainerMutation: false,
|
|
92
93
|
// shiftKeyRotate: false,
|
|
93
94
|
// touchGestures: true,
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @external L.Canvas
|
|
3
|
-
*
|
|
4
|
-
* @see https://github.com/Leaflet/Leaflet/tree/v1.9.3/src/layer/vector/Canvas.js
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
const canvasProto = L.extend({}, L.Canvas.prototype);
|
|
8
|
-
|
|
9
|
-
L.Canvas.include({
|
|
10
|
-
|
|
11
|
-
// onAdd: function() {
|
|
12
|
-
// canvasProto.onAdd.apply(this, arguments);
|
|
13
|
-
// // When rotating the canvas itself, it is cleared by some weird reason, so redraw.
|
|
14
|
-
// this._map.on('rotate', this._redraw, this);
|
|
15
|
-
// },
|
|
16
|
-
|
|
17
|
-
// onRemove: function() {
|
|
18
|
-
// canvasProto.onRemove.apply(this, arguments);
|
|
19
|
-
// this._map.off('rotate', this._redraw, this);
|
|
20
|
-
// },
|
|
21
|
-
|
|
22
|
-
// _update: function() {
|
|
23
|
-
// canvasProto._update.apply(this, arguments);
|
|
24
|
-
// // Tell paths to redraw themselves
|
|
25
|
-
// this.fire('update')
|
|
26
|
-
// },
|
|
27
|
-
|
|
28
|
-
});
|
package/src/layer/vector/SVG.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @external L.SVG
|
|
3
|
-
*
|
|
4
|
-
* @see https://github.com/Leaflet/Leaflet/tree/v1.9.3/src/layer/vector/SVG.js
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
const svgProto = L.extend({}, L.SVG.prototype);
|
|
8
|
-
|
|
9
|
-
L.SVG.include({
|
|
10
|
-
|
|
11
|
-
// _update: function() {
|
|
12
|
-
// svgProto._update.apply(this, arguments);
|
|
13
|
-
// if (this._map._rotate) {
|
|
14
|
-
// this.fire('update');
|
|
15
|
-
// }
|
|
16
|
-
// },
|
|
17
|
-
|
|
18
|
-
});
|