leaflet-rotate 0.1.4 → 0.2.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/README.md +2 -2
- package/build/rollup.config.js +4 -4
- package/dist/leaflet-rotate-src.js +744 -329
- package/dist/leaflet-rotate-src.js.map +1 -1
- package/dist/leaflet-rotate.js +1760 -1
- package/dist/leaflet-rotate.js.map +1 -1
- package/lib/debug.js +253 -21
- package/lib/debug.min.js +1 -9
- package/package.json +10 -7
- package/src/control/Rotate.js +10 -7
- package/src/dom/DomUtil.js +8 -5
- package/src/dom/Draggable.js +8 -5
- package/src/geometry/Point.js +22 -18
- package/src/index.js +5 -3
- package/src/layer/DivOverlay.js +14 -22
- package/src/layer/Popup.js +30 -10
- package/src/layer/Tooltip.js +10 -7
- package/src/layer/marker/Icon.js +5 -2
- package/src/layer/marker/Marker.js +52 -43
- package/src/layer/tile/GridLayer.js +7 -16
- package/src/layer/vector/Canvas.js +18 -15
- package/src/layer/vector/Renderer.js +23 -32
- package/src/layer/vector/SVG.js +10 -7
- package/src/map/Map.js +462 -96
- package/src/map/handler/CompassBearing.js +7 -11
- package/src/map/handler/ContainerMutation.js +12 -8
- package/src/map/handler/ShiftKeyRotate.js +5 -2
- package/src/map/handler/TouchGestures.js +16 -11
- package/src/map/handler/TouchRotate.js +4 -2
- package/src/map/handler/TouchZoom.js +16 -4
- package/test/index.html +30 -6
- package/build/rollup.config.min.js +0 -2
- package/src/map/handler/ShiftKeyRotate.min.js +0 -1
|
@@ -1,34 +1,30 @@
|
|
|
1
|
-
|
|
2
|
-
*
|
|
1
|
+
/**
|
|
2
|
+
* Rotates the map according to a smartphone's compass.
|
|
3
|
+
*
|
|
4
|
+
* @typedef L.Map.CompassBearing
|
|
3
5
|
*/
|
|
4
6
|
|
|
5
7
|
L.Map.CompassBearing = L.Handler.extend({
|
|
6
8
|
|
|
7
9
|
initialize: function(map) {
|
|
8
|
-
if (!window.DeviceOrientationEvent) {
|
|
9
|
-
this._capable = false;
|
|
10
|
-
return;
|
|
11
|
-
}
|
|
12
|
-
this._capable = true;
|
|
13
10
|
this._map = map;
|
|
14
|
-
|
|
15
11
|
this._throttled = L.Util.throttle(this._onDeviceOrientation, 1000, this);
|
|
16
12
|
},
|
|
17
13
|
|
|
18
14
|
addHooks: function() {
|
|
19
|
-
if (this.
|
|
15
|
+
if (this._map._rotate && window.DeviceOrientationEvent) {
|
|
20
16
|
L.DomEvent.on(window, 'deviceorientation', this._throttled, this);
|
|
21
17
|
}
|
|
22
18
|
},
|
|
23
19
|
|
|
24
20
|
removeHooks: function() {
|
|
25
|
-
if (this.
|
|
21
|
+
if (this._map._rotate && window.DeviceOrientationEvent) {
|
|
26
22
|
L.DomEvent.off(window, 'deviceorientation', this._throttled, this);
|
|
27
23
|
}
|
|
28
24
|
},
|
|
29
25
|
|
|
30
26
|
_onDeviceOrientation: function(event) {
|
|
31
|
-
if (event.alpha !== null) {
|
|
27
|
+
if (event.alpha !== null && window.orientation !== undefined) {
|
|
32
28
|
this._map.setBearing(event.alpha - window.orientation);
|
|
33
29
|
}
|
|
34
30
|
},
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
*
|
|
1
|
+
/**
|
|
2
|
+
* Triggers `invalidateResize` when the map's DOM container mutates.
|
|
3
|
+
*
|
|
4
|
+
* @typedef L.Map.ContainerMutation
|
|
3
5
|
*/
|
|
4
6
|
|
|
5
7
|
// @namespace Map
|
|
@@ -17,9 +19,10 @@ L.Map.mergeOptions({
|
|
|
17
19
|
L.Map.ContainerMutation = L.Handler.extend({
|
|
18
20
|
|
|
19
21
|
addHooks: function() {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
22
|
+
/** @TODO check again this property. Will likely be added in future releases (leaflet > v1.9.3) */
|
|
23
|
+
// if (!L.Browser.mutation) {
|
|
24
|
+
// return;
|
|
25
|
+
// }
|
|
23
26
|
|
|
24
27
|
if (!this._observer) {
|
|
25
28
|
this._observer = new MutationObserver(L.Util.bind(this._onMutation, this));
|
|
@@ -35,9 +38,10 @@ L.Map.ContainerMutation = L.Handler.extend({
|
|
|
35
38
|
},
|
|
36
39
|
|
|
37
40
|
removeHooks: function() {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
+
/** @TODO check again this property. Will likely be added in future releases (leaflet > v1.9.3) */
|
|
42
|
+
// if (!L.Browser.mutation) {
|
|
43
|
+
// return;
|
|
44
|
+
// }
|
|
41
45
|
this._observer.disconnect();
|
|
42
46
|
},
|
|
43
47
|
|
|
@@ -1,5 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
*
|
|
1
|
+
/**
|
|
2
|
+
* TouchGestures is both TouchZoom plus TouchRotate
|
|
3
|
+
*
|
|
4
|
+
* @see https://github.com/fnicollet/Leaflet/commit/a77af51a6b10f308d1b9a16552091d1d0aee8834
|
|
5
|
+
* @see https://github.com/Leaflet/Leaflet/blob/v1.9.3/src/map/handler/Map.TouchZoom.js
|
|
6
|
+
*
|
|
7
|
+
* @typedef L.Map.TouchGestures
|
|
3
8
|
*/
|
|
4
9
|
|
|
5
10
|
// @namespace Map
|
|
@@ -63,11 +68,11 @@ L.Map.TouchGestures = L.Handler.extend({
|
|
|
63
68
|
|
|
64
69
|
this._moved = false;
|
|
65
70
|
|
|
66
|
-
map.
|
|
71
|
+
map._stop();
|
|
67
72
|
|
|
68
73
|
L.DomEvent
|
|
69
74
|
.on(document, 'touchmove', this._onTouchMove, this)
|
|
70
|
-
.on(document, 'touchend', this._onTouchEnd, this);
|
|
75
|
+
.on(document, 'touchend touchcancel', this._onTouchEnd, this);
|
|
71
76
|
|
|
72
77
|
L.DomEvent.preventDefault(e);
|
|
73
78
|
},
|
|
@@ -118,20 +123,20 @@ L.Map.TouchGestures = L.Handler.extend({
|
|
|
118
123
|
}
|
|
119
124
|
|
|
120
125
|
if (!this._moved) {
|
|
121
|
-
map._moveStart(true);
|
|
126
|
+
map._moveStart(true, false);
|
|
122
127
|
this._moved = true;
|
|
123
128
|
}
|
|
124
129
|
|
|
125
130
|
L.Util.cancelAnimFrame(this._animRequest);
|
|
126
131
|
|
|
127
|
-
var moveFn =
|
|
132
|
+
var moveFn = map._move.bind(map, this._center, this._zoom, { pinch: true, round: false }, undefined);
|
|
128
133
|
this._animRequest = L.Util.requestAnimFrame(moveFn, this, true);
|
|
129
134
|
|
|
130
135
|
L.DomEvent.preventDefault(e);
|
|
131
136
|
},
|
|
132
137
|
|
|
133
138
|
_onTouchEnd: function() {
|
|
134
|
-
if (!this._moved || !this._zooming) {
|
|
139
|
+
if (!this._moved || !(this._zooming || this._rotating)) {
|
|
135
140
|
this._zooming = false;
|
|
136
141
|
return;
|
|
137
142
|
}
|
|
@@ -141,13 +146,13 @@ L.Map.TouchGestures = L.Handler.extend({
|
|
|
141
146
|
L.Util.cancelAnimFrame(this._animRequest);
|
|
142
147
|
|
|
143
148
|
L.DomEvent
|
|
144
|
-
.off(document, 'touchmove', this._onTouchMove)
|
|
145
|
-
.off(document, 'touchend', this._onTouchEnd);
|
|
149
|
+
.off(document, 'touchmove', this._onTouchMove, this)
|
|
150
|
+
.off(document, 'touchend touchcancel', this._onTouchEnd, this);
|
|
146
151
|
|
|
147
152
|
if (this.zoom) {
|
|
148
|
-
// Pinch updates GridLayers' levels only when
|
|
153
|
+
// Pinch updates GridLayers' levels only when zoomSnap is off, so zoomSnap becomes noUpdate.
|
|
149
154
|
if (this._map.options.zoomAnimation) {
|
|
150
|
-
this._map._animateZoom(this._center, this._map._limitZoom(this._zoom), true, this._map.options.
|
|
155
|
+
this._map._animateZoom(this._center, this._map._limitZoom(this._zoom), true, this._map.options.zoomSnap);
|
|
151
156
|
} else {
|
|
152
157
|
this._map._resetView(this._center, this._map._limitZoom(this._zoom));
|
|
153
158
|
}
|
|
@@ -1,5 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
*
|
|
1
|
+
/**
|
|
2
|
+
* Adds pinch zoom rotation on mobile browsers
|
|
3
|
+
*
|
|
4
|
+
* @see https://github.com/Leaflet/Leaflet/blob/v1.9.3/src/map/handler/Map.TouchZoom.js
|
|
5
|
+
*
|
|
6
|
+
* @external L.Map.TouchZoom
|
|
3
7
|
*/
|
|
4
8
|
|
|
5
9
|
// @namespace Map
|
|
@@ -11,10 +15,18 @@ L.Map.mergeOptions({
|
|
|
11
15
|
// Whether the map can be zoomed by touch-dragging with two fingers. If
|
|
12
16
|
// passed `'center'`, it will zoom to the center of the view regardless of
|
|
13
17
|
// where the touch events (fingers) were. Enabled for touch-capable web
|
|
14
|
-
// browsers
|
|
15
|
-
touchZoom: L.Browser.touch
|
|
18
|
+
// browsers.
|
|
19
|
+
touchZoom: L.Browser.touch,
|
|
16
20
|
|
|
21
|
+
/**
|
|
22
|
+
* @TODO check if this is a duplicate of `L.Map.TouchGestures::bounceAtZoomLimits`
|
|
23
|
+
*/
|
|
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.
|
|
17
28
|
bounceAtZoomLimits: false,
|
|
29
|
+
|
|
18
30
|
});
|
|
19
31
|
|
|
20
32
|
L.Map.TouchZoom = L.Handler.extend({
|
package/test/index.html
CHANGED
|
@@ -7,8 +7,8 @@
|
|
|
7
7
|
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
|
|
8
8
|
|
|
9
9
|
<!-- Leaflet JS / CSS -->
|
|
10
|
-
<script src="https://unpkg.com/leaflet@1.
|
|
11
|
-
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.
|
|
10
|
+
<script src="https://unpkg.com/leaflet@1.9/dist/leaflet-src.js"></script>
|
|
11
|
+
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.9/dist/leaflet.css">
|
|
12
12
|
|
|
13
13
|
<!-- Leaflet-Rotate -->
|
|
14
14
|
<script src="../dist/leaflet-rotate-src.js"></script>
|
|
@@ -26,6 +26,11 @@
|
|
|
26
26
|
border: 1px solid #ccc;
|
|
27
27
|
max-height: 50vh;
|
|
28
28
|
}
|
|
29
|
+
/* TODO: fix incorrect map corners position when map has some margin */
|
|
30
|
+
html, body {
|
|
31
|
+
/* margin: 0; */
|
|
32
|
+
/* padding: 0; */
|
|
33
|
+
}
|
|
29
34
|
</style>
|
|
30
35
|
</head>
|
|
31
36
|
|
|
@@ -58,12 +63,14 @@
|
|
|
58
63
|
maxZoom: 24,
|
|
59
64
|
maxNativeZoom: 18,
|
|
60
65
|
attribution: 'Tiles © Esri — Source: Esri, i-cubed, USDA, USGS, AEX, GeoEye, Getmapping, Aerogrid, IGN, IGP, UPR-EGP, and the GIS User Community',
|
|
66
|
+
// noWrap: true
|
|
61
67
|
});
|
|
62
68
|
|
|
63
69
|
var osm = L.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
|
|
64
70
|
maxZoom: 24,
|
|
65
71
|
maxNativeZoom: 19,
|
|
66
72
|
attribution: '© <a href="http://openstreetmap.org/copyright">OpenStreetMap</a> contributors',
|
|
73
|
+
// noWrap: true
|
|
67
74
|
});
|
|
68
75
|
|
|
69
76
|
var map = L.map('map', {
|
|
@@ -71,17 +78,34 @@
|
|
|
71
78
|
zoom: 2,
|
|
72
79
|
layers: [esri],
|
|
73
80
|
// worldCopyJump: true,
|
|
81
|
+
// preferCanvas: false,
|
|
74
82
|
rotate: true,
|
|
75
|
-
touchRotate: true,
|
|
76
83
|
rotateControl: {
|
|
77
|
-
closeOnZeroBearing: false
|
|
84
|
+
closeOnZeroBearing: false,
|
|
85
|
+
// position: 'bottomleft',
|
|
78
86
|
},
|
|
79
87
|
bearing: 30,
|
|
88
|
+
// attributionControl: false,
|
|
89
|
+
// zoomControl: false,
|
|
90
|
+
// compassBearing: false,
|
|
91
|
+
// trackContainerMutation: false,
|
|
92
|
+
// shiftKeyRotate: false,
|
|
93
|
+
// touchGestures: true,
|
|
94
|
+
touchRotate: true,
|
|
95
|
+
// touchZoom: true
|
|
80
96
|
});
|
|
81
97
|
|
|
82
|
-
// map.setBearing(
|
|
98
|
+
// map.setBearing(90);
|
|
83
99
|
// map.touchRotate.enable();
|
|
84
100
|
|
|
101
|
+
// map.touchZoom.disable()
|
|
102
|
+
// map.compassBearing.disable()
|
|
103
|
+
// map.touchGestures.enable()
|
|
104
|
+
|
|
105
|
+
// map.zoomControl.setPosition('bottomleft');
|
|
106
|
+
// map.rotateControl.setPosition('bottomleft');
|
|
107
|
+
// map.setMaxBounds([[-90,-180], [90,180]]);
|
|
108
|
+
|
|
85
109
|
var layers = L.control.layers({
|
|
86
110
|
'Empty': L.tileLayer(''),
|
|
87
111
|
'Streets': osm,
|
|
@@ -127,4 +151,4 @@
|
|
|
127
151
|
|
|
128
152
|
</body>
|
|
129
153
|
|
|
130
|
-
</html>
|
|
154
|
+
</html>
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
'use strict';import{terser}from"rollup-plugin-terser";import resolve from"rollup-plugin-node-resolve";import commonJS from"rollup-plugin-commonjs";let plugin=require("../package.json");let input="src/index.js";let output={file:"dist/"+plugin.name+"-src.js",format:"umd",sourcemap:true,name:plugin.name};let plugins=[resolve(),commonJS({include:"../node_modules/**"})];
|
|
2
|
-
export default[{input:input,output:output,plugins:plugins},{input:input,output:Object.assign({},output,{file:"dist/"+plugin.name+".js"}),plugins:plugins.concat(terser())}];
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
L.Map.mergeOptions({shiftKeyRotate:!0}),L.Map.ShiftKeyRotate=L.Handler.extend({addHooks:function(){L.DomEvent.on(this._map._container,"wheel",this._handleShiftScroll,this),this._map.shiftKeyRotate.rotate=!0},removeHooks:function(){L.DomEvent.off(this._map._container,"wheel",this._handleShiftScroll,this),this._map.shiftKeyRotate.rotate=!1},_handleShiftScroll:function(e){e.shiftKey?(e.preventDefault(),this._map.scrollWheelZoom.disable(),this._map.setBearing(this._map._bearing*L.DomUtil.RAD_TO_DEG+5*Math.sign(e.deltaY))):this._map.scrollWheelZoom.enable()}}),L.Map.addInitHook("addHandler","shiftKeyRotate",L.Map.ShiftKeyRotate),L.Map.addInitHook((function(){this.scrollWheelZoom.enabled()&&this.shiftKeyRotate.enabled()&&(this.scrollWheelZoom.disable(),this.scrollWheelZoom.enable())}));
|