leaflet-rotate 0.1.3 → 0.2.0
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 +3 -3
- package/build/rollup.config.js +4 -4
- package/dist/leaflet-rotate-src.js +626 -311
- package/dist/leaflet-rotate-src.js.map +1 -1
- package/dist/leaflet-rotate.js +1660 -1
- package/dist/leaflet-rotate.js.map +1 -1
- package/lib/debug.js +219 -25
- package/lib/debug.min.js +1 -9
- package/package.json +10 -7
- package/src/control/Rotate.js +10 -7
- package/src/dom/DomUtil.js +4 -1
- 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 +13 -21
- 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 +42 -37
- package/src/layer/tile/GridLayer.js +5 -14
- package/src/layer/vector/Canvas.js +18 -15
- package/src/layer/vector/Renderer.js +21 -30
- package/src/layer/vector/SVG.js +10 -7
- package/src/map/Map.js +363 -93
- package/src/map/handler/CompassBearing.js +7 -11
- package/src/map/handler/ContainerMutation.js +12 -8
- package/src/map/handler/ShiftKeyRotate.js +6 -3
- 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 +29 -6
- package/build/rollup.config.min.js +0 -2
package/src/layer/Popup.js
CHANGED
|
@@ -1,25 +1,41 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* L.Popup
|
|
2
|
+
* @external L.Popup
|
|
3
|
+
*
|
|
4
|
+
* @see https://github.com/Leaflet/Leaflet/tree/v1.9.3/src/layer/Popup.js
|
|
3
5
|
*/
|
|
6
|
+
|
|
4
7
|
const popupProto = L.extend({}, L.Popup.prototype);
|
|
5
8
|
|
|
6
9
|
L.Popup.include({
|
|
7
10
|
|
|
8
11
|
_animateZoom: function(e) {
|
|
9
|
-
|
|
10
|
-
|
|
12
|
+
// 0. update anchor (leaflet v1.9.3)
|
|
13
|
+
popupProto._animateZoom.call(this, e);
|
|
14
|
+
// 1. subtract anchor
|
|
15
|
+
// 2. rotate element
|
|
16
|
+
// 3. restore anchor
|
|
17
|
+
if (this._map && this._map._rotate) {
|
|
18
|
+
var anchor = this._getAnchor();
|
|
19
|
+
var pos = L.DomUtil.getPosition(this._container).subtract(anchor);
|
|
20
|
+
L.DomUtil.setPosition(this._container, this._map.rotatedPointToMapPanePoint(pos).add(anchor));
|
|
11
21
|
}
|
|
12
|
-
var pos = this._map._latLngToNewLayerPoint(this._latlng, e.zoom, e.center),
|
|
13
|
-
anchor = this._getAnchor();
|
|
14
|
-
|
|
15
|
-
pos = this._map.rotatedPointToMapPanePoint(pos);
|
|
16
|
-
|
|
17
|
-
L.DomUtil.setPosition(this._container, pos.add(anchor));
|
|
18
22
|
},
|
|
19
23
|
|
|
24
|
+
/**
|
|
25
|
+
* Hot fix for L.Popup.mergeOptions({ keepInView: true, });
|
|
26
|
+
*
|
|
27
|
+
* @see https://github.com/fnicollet/Leaflet/pull/21
|
|
28
|
+
*/
|
|
20
29
|
_adjustPan: function() {
|
|
21
30
|
if (!this.options.autoPan || (this._map._panAnim && this._map._panAnim._inProgress)) { return; }
|
|
22
31
|
|
|
32
|
+
// We can endlessly recurse if keepInView is set and the view resets.
|
|
33
|
+
// Let's guard against that by exiting early if we're responding to our own autopan.
|
|
34
|
+
if (this._autopanning) {
|
|
35
|
+
this._autopanning = false;
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
|
|
23
39
|
var map = this._map,
|
|
24
40
|
marginBottom = parseInt(L.DomUtil.getStyle(this._container, 'marginBottom'), 10) || 0,
|
|
25
41
|
containerHeight = this._container.offsetHeight + marginBottom,
|
|
@@ -29,7 +45,7 @@ L.Popup.include({
|
|
|
29
45
|
layerPos._add(L.DomUtil.getPosition(this._container));
|
|
30
46
|
|
|
31
47
|
// var containerPos = map.layerPointToContainerPoint(layerPos);
|
|
32
|
-
|
|
48
|
+
/** @TODO use popupProto._adjustPan */
|
|
33
49
|
var containerPos = layerPos._add(this._map._getMapPanePos()),
|
|
34
50
|
padding = L.point(this.options.autoPanPadding),
|
|
35
51
|
paddingTL = L.point(this.options.autoPanPaddingTopLeft || padding),
|
|
@@ -56,6 +72,10 @@ L.Popup.include({
|
|
|
56
72
|
// @event autopanstart: Event
|
|
57
73
|
// Fired when the map starts autopanning when opening a popup.
|
|
58
74
|
if (dx || dy) {
|
|
75
|
+
// Track that we're autopanning, as this function will be re-ran on moveend
|
|
76
|
+
if (this.options.keepInView) {
|
|
77
|
+
this._autopanning = true;
|
|
78
|
+
}
|
|
59
79
|
map
|
|
60
80
|
.fire('autopanstart')
|
|
61
81
|
.panBy([dx, dy]);
|
package/src/layer/Tooltip.js
CHANGED
|
@@ -1,25 +1,28 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* L.Tooltip
|
|
2
|
+
* @external L.Tooltip
|
|
3
|
+
*
|
|
4
|
+
* @see https://github.com/Leaflet/Leaflet/tree/v1.9.3/src/layer/Tooltip.js
|
|
3
5
|
*/
|
|
6
|
+
|
|
4
7
|
const tooltipProto = L.extend({}, L.Tooltip.prototype);
|
|
5
8
|
|
|
6
9
|
L.Tooltip.include({
|
|
7
10
|
|
|
8
|
-
|
|
11
|
+
_animateZoom: function(e) {
|
|
9
12
|
if (!this._map._rotate) {
|
|
10
|
-
return tooltipProto.
|
|
13
|
+
return tooltipProto._animateZoom.call(this, e);
|
|
11
14
|
}
|
|
12
|
-
var pos = this._map.
|
|
15
|
+
var pos = this._map._latLngToNewLayerPoint(this._latlng, e.zoom, e.center);
|
|
13
16
|
|
|
14
17
|
pos = this._map.rotatedPointToMapPanePoint(pos);
|
|
15
18
|
this._setPosition(pos);
|
|
16
19
|
},
|
|
17
20
|
|
|
18
|
-
|
|
21
|
+
_updatePosition: function() {
|
|
19
22
|
if (!this._map._rotate) {
|
|
20
|
-
return tooltipProto.
|
|
23
|
+
return tooltipProto._updatePosition.call(this);
|
|
21
24
|
}
|
|
22
|
-
var pos = this._map.
|
|
25
|
+
var pos = this._map.latLngToLayerPoint(this._latlng);
|
|
23
26
|
|
|
24
27
|
pos = this._map.rotatedPointToMapPanePoint(pos);
|
|
25
28
|
this._setPosition(pos);
|
package/src/layer/marker/Icon.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* L.Icon
|
|
2
|
+
* @external L.Icon
|
|
3
|
+
*
|
|
4
|
+
* @see https://github.com/Leaflet/Leaflet/tree/v1.9.3/src/layer/marker/Icon.js
|
|
3
5
|
*/
|
|
6
|
+
|
|
4
7
|
const iconProto = L.extend({}, L.Icon.prototype);
|
|
5
8
|
|
|
6
9
|
L.Icon.include({
|
|
@@ -22,7 +25,7 @@ L.Icon.include({
|
|
|
22
25
|
if (anchor) {
|
|
23
26
|
img.style.marginLeft = (-anchor.x) + 'px';
|
|
24
27
|
img.style.marginTop = (-anchor.y) + 'px';
|
|
25
|
-
|
|
28
|
+
/** @TODO use iconProto._setIconStyles */
|
|
26
29
|
img.style[L.DomUtil.TRANSFORM + "Origin"] = anchor.x + "px " + anchor.y + "px 0px";
|
|
27
30
|
}
|
|
28
31
|
|
|
@@ -1,31 +1,49 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* L.
|
|
2
|
+
* @external L.Marker
|
|
3
|
+
* @external L.Handler.MarkerDrag
|
|
4
|
+
*
|
|
5
|
+
* @see https://github.com/Leaflet/Leaflet/tree/v1.9.3/src/layer/marker/Marker.js
|
|
3
6
|
*/
|
|
4
|
-
|
|
7
|
+
|
|
8
|
+
const markerProto = L.extend({}, L.Marker.prototype);
|
|
9
|
+
|
|
10
|
+
L.Marker.mergeOptions({
|
|
11
|
+
|
|
12
|
+
// @option rotation: Number = 0
|
|
13
|
+
// Rotation of this marker in rad
|
|
14
|
+
rotation: 0,
|
|
15
|
+
|
|
16
|
+
// @option rotateWithView: Boolean = false
|
|
17
|
+
// Rotate this marker when map rotates
|
|
18
|
+
rotateWithView: false,
|
|
19
|
+
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
var markerDragProto; // retrived at runtime (see below: L.Marker::_initInteraction())
|
|
5
23
|
|
|
6
24
|
var MarkerDrag = {
|
|
7
25
|
|
|
8
|
-
_onDragStart: function() {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
},
|
|
26
|
+
// _onDragStart: function() {
|
|
27
|
+
// if (!this._marker._map._rotate) {
|
|
28
|
+
// return markerDragProto._onDragStart.call(this)
|
|
29
|
+
// }
|
|
30
|
+
// this._draggable.updateMapBearing(this._marker._map._bearing);
|
|
31
|
+
// },
|
|
14
32
|
|
|
15
33
|
_onDrag: function(e) {
|
|
16
34
|
var marker = this._marker,
|
|
17
|
-
|
|
35
|
+
/** @TODO use markerDragProto._onDrag */
|
|
18
36
|
rotated_marker = marker.options.rotation || marker.options.rotateWithView,
|
|
19
37
|
shadow = marker._shadow,
|
|
20
38
|
iconPos = L.DomUtil.getPosition(marker._icon);
|
|
21
39
|
|
|
22
|
-
|
|
40
|
+
/** @TODO use markerDragProto._onDrag */
|
|
23
41
|
// update shadow position
|
|
24
42
|
if (!rotated_marker && shadow) {
|
|
25
43
|
L.DomUtil.setPosition(shadow, iconPos);
|
|
26
44
|
}
|
|
27
45
|
|
|
28
|
-
|
|
46
|
+
/** @TODO use markerDragProto._onDrag */
|
|
29
47
|
if (marker._map._rotate) {
|
|
30
48
|
// Reverse calculation from mapPane coordinates to rotatePane coordinates
|
|
31
49
|
iconPos = marker._map.mapPanePointToRotatedPoint(iconPos);
|
|
@@ -36,7 +54,7 @@ var MarkerDrag = {
|
|
|
36
54
|
e.latlng = latlng;
|
|
37
55
|
e.oldLatLng = this._oldLatLng;
|
|
38
56
|
|
|
39
|
-
|
|
57
|
+
/** @TODO use markerDragProto._onDrag */
|
|
40
58
|
if (rotated_marker) marker.setLatLng(latlng); // use `setLatLng` to presisit rotation. low efficiency
|
|
41
59
|
else marker.fire('move', e); // `setLatLng` will trig 'move' event. we imitate here.
|
|
42
60
|
|
|
@@ -55,23 +73,6 @@ var MarkerDrag = {
|
|
|
55
73
|
|
|
56
74
|
};
|
|
57
75
|
|
|
58
|
-
/**
|
|
59
|
-
* L.Marker
|
|
60
|
-
*/
|
|
61
|
-
const markerProto = L.extend({}, L.Marker.prototype);
|
|
62
|
-
|
|
63
|
-
L.Marker.mergeOptions({
|
|
64
|
-
|
|
65
|
-
// @option rotation: Number = 0
|
|
66
|
-
// Rotation of this marker in rad
|
|
67
|
-
rotation: 0,
|
|
68
|
-
|
|
69
|
-
// @option rotateWithView: Boolean = false
|
|
70
|
-
// Rotate this marker when map rotates
|
|
71
|
-
rotateWithView: false,
|
|
72
|
-
|
|
73
|
-
});
|
|
74
|
-
|
|
75
76
|
L.Marker.include({
|
|
76
77
|
|
|
77
78
|
getEvents: function() {
|
|
@@ -88,9 +89,11 @@ L.Marker.include({
|
|
|
88
89
|
if (this.dragging && this.dragging.enabled() && this._map && this._map._rotate) {
|
|
89
90
|
// L.Handler.MarkerDrag is used internally by L.Marker to make the markers draggable
|
|
90
91
|
markerDragProto = markerDragProto || Object.getPrototypeOf(this.dragging);
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
92
|
+
Object.assign(this.dragging, {
|
|
93
|
+
// _onDragStart: MarkerDrag._onDragStart.bind(this.dragging),
|
|
94
|
+
_onDrag: MarkerDrag._onDrag.bind(this.dragging),
|
|
95
|
+
_onDragEnd: MarkerDrag._onDragEnd.bind(this.dragging),
|
|
96
|
+
})
|
|
94
97
|
this.dragging.disable();
|
|
95
98
|
this.dragging.enable();
|
|
96
99
|
}
|
|
@@ -99,21 +102,23 @@ L.Marker.include({
|
|
|
99
102
|
|
|
100
103
|
_setPos: function(pos) {
|
|
101
104
|
|
|
102
|
-
|
|
105
|
+
/** @TODO use markerProto._setPos */
|
|
103
106
|
if (this._map._rotate) {
|
|
104
107
|
pos = this._map.rotatedPointToMapPanePoint(pos);
|
|
105
108
|
}
|
|
106
109
|
|
|
107
|
-
|
|
110
|
+
/** @TODO use markerProto._setPos */
|
|
108
111
|
var bearing = this.options.rotation || 0;
|
|
109
112
|
if (this.options.rotateWithView) {
|
|
110
113
|
bearing += this._map._bearing;
|
|
111
114
|
}
|
|
112
115
|
|
|
113
|
-
|
|
114
|
-
|
|
116
|
+
/** @TODO use markerProto._setPos */
|
|
117
|
+
if (this._icon) {
|
|
118
|
+
L.DomUtil.setPosition(this._icon, pos, bearing, pos);
|
|
119
|
+
}
|
|
115
120
|
|
|
116
|
-
|
|
121
|
+
/** @TODO use markerProto._setPos */
|
|
117
122
|
if (this._shadow) {
|
|
118
123
|
L.DomUtil.setPosition(this._shadow, pos, bearing, pos);
|
|
119
124
|
}
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* L.GridLayer
|
|
2
|
+
* @external L.GridLayer
|
|
3
|
+
*
|
|
4
|
+
* @see https://github.com/Leaflet/Leaflet/tree/v1.9.3/src/layer/tile/GridLayer.js
|
|
3
5
|
*/
|
|
6
|
+
|
|
4
7
|
const gridLayerProto = L.extend({}, L.GridLayer.prototype);
|
|
5
8
|
|
|
6
9
|
L.GridLayer.include({
|
|
@@ -21,19 +24,7 @@ L.GridLayer.include({
|
|
|
21
24
|
return gridLayerProto._getTiledPixelBounds.call(this, center);
|
|
22
25
|
}
|
|
23
26
|
|
|
24
|
-
|
|
25
|
-
mapZoom = map._animatingZoom ? Math.max(map._animateToZoom, map.getZoom()) : map.getZoom(),
|
|
26
|
-
scale = map.getZoomScale(mapZoom, this._tileZoom),
|
|
27
|
-
pixelCenter = map.project(center, this._tileZoom).floor(),
|
|
28
|
-
size = map.getSize(),
|
|
29
|
-
halfSize = new L.Bounds([
|
|
30
|
-
map.containerPointToLayerPoint([0, 0]).floor(),
|
|
31
|
-
map.containerPointToLayerPoint([size.x, 0]).floor(),
|
|
32
|
-
map.containerPointToLayerPoint([0, size.y]).floor(),
|
|
33
|
-
map.containerPointToLayerPoint([size.x, size.y]).floor()
|
|
34
|
-
]).getSize().divideBy(scale * 2);
|
|
35
|
-
|
|
36
|
-
return new L.Bounds(pixelCenter.subtract(halfSize), pixelCenter.add(halfSize));
|
|
27
|
+
return this._map._getNewPixelBounds(center, this._tileZoom);
|
|
37
28
|
},
|
|
38
29
|
|
|
39
30
|
});
|
|
@@ -1,25 +1,28 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* L.Canvas
|
|
2
|
+
* @external L.Canvas
|
|
3
|
+
*
|
|
4
|
+
* @see https://github.com/Leaflet/Leaflet/tree/v1.9.3/src/layer/vector/Canvas.js
|
|
3
5
|
*/
|
|
6
|
+
|
|
4
7
|
const canvasProto = L.extend({}, L.Canvas.prototype);
|
|
5
8
|
|
|
6
9
|
L.Canvas.include({
|
|
7
10
|
|
|
8
|
-
onAdd: function() {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
},
|
|
11
|
+
// onAdd: function() {
|
|
12
|
+
// canvasProto.onAdd.call(this);
|
|
13
|
+
// // When rotating the canvas itself, it is cleared by some weird reason, so redraw.
|
|
14
|
+
// this._map.on('rotate', this._redraw, this);
|
|
15
|
+
// },
|
|
13
16
|
|
|
14
|
-
onRemove: function() {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
},
|
|
17
|
+
// onRemove: function() {
|
|
18
|
+
// canvasProto.onRemove.call(this);
|
|
19
|
+
// this._map.off('rotate', this._redraw, this);
|
|
20
|
+
// },
|
|
18
21
|
|
|
19
|
-
_update: function() {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
},
|
|
22
|
+
// _update: function() {
|
|
23
|
+
// canvasProto._update.call(this);
|
|
24
|
+
// // Tell paths to redraw themselves
|
|
25
|
+
// this.fire('update')
|
|
26
|
+
// },
|
|
24
27
|
|
|
25
28
|
});
|
|
@@ -1,20 +1,28 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* L.Renderer
|
|
2
|
+
* @external L.Renderer
|
|
3
|
+
*
|
|
4
|
+
* @see https://github.com/Leaflet/Leaflet/tree/v1.9.3/src/layer/vector/Renderer.js
|
|
3
5
|
*/
|
|
6
|
+
|
|
4
7
|
const rendererProto = L.extend({}, L.Renderer.prototype);
|
|
5
8
|
|
|
6
9
|
L.Renderer.include({
|
|
7
10
|
|
|
8
|
-
onAdd: function() {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
},
|
|
12
|
-
|
|
13
|
-
onRemove: function() {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
},
|
|
17
|
-
|
|
11
|
+
// onAdd: function() {
|
|
12
|
+
// rendererProto.onAdd.call(this);
|
|
13
|
+
// // this._map.on('rotate', this._update, this);
|
|
14
|
+
// },
|
|
15
|
+
|
|
16
|
+
// onRemove: function() {
|
|
17
|
+
// rendererProto.onRemove.call(this);
|
|
18
|
+
// // this._map.off('rotate', this._update, this);
|
|
19
|
+
// },
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* @TODO rechek this changes from leaflet@v1.9.3
|
|
23
|
+
*
|
|
24
|
+
* @see https://github.com/Leaflet/Leaflet/compare/v1.7.0...v1.9.3
|
|
25
|
+
*/
|
|
18
26
|
_updateTransform: function(center, zoom) {
|
|
19
27
|
if (!this._map._rotate) {
|
|
20
28
|
return rendererProto._updateTransform.call(this, center, zoom);
|
|
@@ -34,25 +42,8 @@ L.Renderer.include({
|
|
|
34
42
|
}
|
|
35
43
|
// Update pixel bounds of renderer container (for positioning/sizing/clipping later)
|
|
36
44
|
// Subclasses are responsible of firing the 'update' event.
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
size = this._map.getSize(),
|
|
40
|
-
padMin = size.multiplyBy(-p),
|
|
41
|
-
padMax = size.multiplyBy(1 + p),
|
|
42
|
-
//// TODO: Somehow refactor this out into map.something() - the code is
|
|
43
|
-
//// pretty much the same as in GridLayer.
|
|
44
|
-
clip = new L.Bounds([
|
|
45
|
-
map.containerPointToLayerPoint([padMin.x, padMin.y]).floor(),
|
|
46
|
-
map.containerPointToLayerPoint([padMin.x, padMax.y]).floor(),
|
|
47
|
-
map.containerPointToLayerPoint([padMax.x, padMin.y]).floor(),
|
|
48
|
-
map.containerPointToLayerPoint([padMax.x, padMax.y]).floor()
|
|
49
|
-
]);
|
|
50
|
-
//min = this._map.containerPointToLayerPoint(size.multiplyBy(-p)).round();
|
|
51
|
-
|
|
52
|
-
this._bounds = clip;
|
|
53
|
-
// this._topLeft = clip.min;
|
|
54
|
-
this._topLeft = this._map.layerPointToLatLng(clip.min);
|
|
55
|
-
|
|
45
|
+
this._bounds = this._map._getPaddedPixelBounds(this.options.padding);
|
|
46
|
+
this._topLeft = this._map.layerPointToLatLng(this._bounds.min);
|
|
56
47
|
this._center = this._map.getCenter();
|
|
57
48
|
this._zoom = this._map.getZoom();
|
|
58
49
|
},
|
package/src/layer/vector/SVG.js
CHANGED
|
@@ -1,15 +1,18 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* L.SVG
|
|
2
|
+
* @external L.SVG
|
|
3
|
+
*
|
|
4
|
+
* @see https://github.com/Leaflet/Leaflet/tree/v1.9.3/src/layer/vector/SVG.js
|
|
3
5
|
*/
|
|
6
|
+
|
|
4
7
|
const svgProto = L.extend({}, L.SVG.prototype);
|
|
5
8
|
|
|
6
9
|
L.SVG.include({
|
|
7
10
|
|
|
8
|
-
_update: function() {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
},
|
|
11
|
+
// _update: function() {
|
|
12
|
+
// svgProto._update.call(this);
|
|
13
|
+
// if (this._map._rotate) {
|
|
14
|
+
// this.fire('update');
|
|
15
|
+
// }
|
|
16
|
+
// },
|
|
14
17
|
|
|
15
18
|
});
|