leaflet-rotate 0.2.2 → 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 +170 -59
- package/dist/leaflet-rotate-src.js.map +1 -1
- package/dist/leaflet-rotate.js +170 -59
- package/dist/leaflet-rotate.js.map +1 -1
- package/package.json +1 -1
- package/src/control/Rotate.js +42 -41
- package/src/layer/vector/Renderer.js +75 -5
- package/src/map/Map.js +6 -1
- package/src/map/handler/CompassBearing.js +47 -8
- package/src/map/handler/TouchZoom.js +0 -4
- package/test/index.html +2 -1
|
@@ -566,6 +566,33 @@
|
|
|
566
566
|
},
|
|
567
567
|
|
|
568
568
|
/**
|
|
569
|
+
* Fix for `map.flyTo()` when `false === map.options.zoomAnimation`
|
|
570
|
+
*
|
|
571
|
+
* @see https://github.com/Leaflet/Leaflet/pull/8794
|
|
572
|
+
*/
|
|
573
|
+
onAdd: function() {
|
|
574
|
+
rendererProto.onAdd.apply(this, arguments);
|
|
575
|
+
if (L.version <= "1.9.3") {
|
|
576
|
+
// always keep transform-origin as 0 0
|
|
577
|
+
this._container.classList.add('leaflet-zoom-animated');
|
|
578
|
+
}
|
|
579
|
+
},
|
|
580
|
+
|
|
581
|
+
/**
|
|
582
|
+
* @FIXME layer drifts on `map.setZoom()` (eg. zoom during animation)
|
|
583
|
+
*
|
|
584
|
+
* the main cause seems to be related to `this._updateTransform(path._center, path._zoom))`
|
|
585
|
+
* and `this._topLeft = this._map.layerPointToLatLng(this._bounds.min);`
|
|
586
|
+
*
|
|
587
|
+
* @example
|
|
588
|
+
* map.setZoom(2);
|
|
589
|
+
* path._renderer._update();
|
|
590
|
+
* path._renderer._updateTransform(path._renderer._center, path._renderer._zoom);
|
|
591
|
+
*
|
|
592
|
+
* @see https://github.com/Leaflet/Leaflet/pull/8794
|
|
593
|
+
* @see https://github.com/Leaflet/Leaflet/pull/8103
|
|
594
|
+
* @see https://github.com/Leaflet/Leaflet/issues/7466
|
|
595
|
+
*
|
|
569
596
|
* @TODO rechek this changes from leaflet@v1.9.3
|
|
570
597
|
*
|
|
571
598
|
* @see https://github.com/Leaflet/Leaflet/compare/v1.7.0...v1.9.3
|
|
@@ -574,15 +601,58 @@
|
|
|
574
601
|
if (!this._map._rotate) {
|
|
575
602
|
return rendererProto._updateTransform.apply(this, arguments);
|
|
576
603
|
}
|
|
604
|
+
/**
|
|
605
|
+
* @FIXME see path._renderer._reset();
|
|
606
|
+
*/
|
|
577
607
|
var scale = this._map.getZoomScale(zoom, this._zoom),
|
|
578
608
|
offset = this._map._latLngToNewLayerPoint(this._topLeft, zoom, center);
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
L.DomUtil.setPosition(this._container, offset);
|
|
583
|
-
}
|
|
609
|
+
|
|
610
|
+
L.DomUtil.setTransform(this._container, offset, scale);
|
|
611
|
+
|
|
584
612
|
},
|
|
585
613
|
|
|
614
|
+
// getEvents() {
|
|
615
|
+
// const events = {
|
|
616
|
+
// viewreset: this._reset,
|
|
617
|
+
// zoom: this._onZoom,
|
|
618
|
+
// moveend: this._update,
|
|
619
|
+
// zoomend: this._onZoomEnd
|
|
620
|
+
// };
|
|
621
|
+
// if (this._zoomAnimated) {
|
|
622
|
+
// events.zoomanim = this._onAnimZoom;
|
|
623
|
+
// }
|
|
624
|
+
// return events;
|
|
625
|
+
// },
|
|
626
|
+
|
|
627
|
+
// _onAnimZoom(ev) {
|
|
628
|
+
// this._updateTransform(ev.center, ev.zoom);
|
|
629
|
+
// },
|
|
630
|
+
|
|
631
|
+
// _onZoom() {
|
|
632
|
+
// this._updateTransform(this._map.getCenter(), this._map.getZoom());
|
|
633
|
+
// },
|
|
634
|
+
|
|
635
|
+
// _onZoomEnd() {
|
|
636
|
+
// for (const id in this._layers) {
|
|
637
|
+
// this._layers[id]._project();
|
|
638
|
+
// }
|
|
639
|
+
// },
|
|
640
|
+
|
|
641
|
+
// _reset() {
|
|
642
|
+
// this._update();
|
|
643
|
+
// this._updateTransform(this._center, this._zoom);
|
|
644
|
+
|
|
645
|
+
// for (const id in this._layers) {
|
|
646
|
+
// this._layers[id]._reset();
|
|
647
|
+
// }
|
|
648
|
+
// },
|
|
649
|
+
|
|
650
|
+
// _updatePaths() {
|
|
651
|
+
// for (const id in this._layers) {
|
|
652
|
+
// this._layers[id]._update();
|
|
653
|
+
// }
|
|
654
|
+
// },
|
|
655
|
+
|
|
586
656
|
_update: function() {
|
|
587
657
|
if (!this._map._rotate) {
|
|
588
658
|
return rendererProto._update.apply(this, arguments);
|
|
@@ -1072,11 +1142,16 @@
|
|
|
1072
1142
|
// return L.DomUtil.getPosition(this._rotatePane) || new L.Point(0, 0);
|
|
1073
1143
|
},
|
|
1074
1144
|
|
|
1145
|
+
// _latLngToNewLayerPoint(latlng, zoom, center) {
|
|
1146
|
+
// const topLeft = this._getNewPixelOrigin(center, zoom);
|
|
1147
|
+
// return this.project(latlng, zoom)._subtract(topLeft);
|
|
1148
|
+
//},
|
|
1149
|
+
|
|
1075
1150
|
_getNewPixelOrigin: function(center, zoom) {
|
|
1076
|
-
var viewHalf = this.getSize()._divideBy(2);
|
|
1077
1151
|
if (!this._rotate) {
|
|
1078
1152
|
return mapProto._getNewPixelOrigin.apply(this, arguments);
|
|
1079
1153
|
}
|
|
1154
|
+
var viewHalf = this.getSize()._divideBy(2);
|
|
1080
1155
|
return this.project(center, zoom)
|
|
1081
1156
|
.rotate(this._bearing)
|
|
1082
1157
|
._subtract(viewHalf)
|
|
@@ -1209,25 +1284,64 @@
|
|
|
1209
1284
|
|
|
1210
1285
|
initialize: function(map) {
|
|
1211
1286
|
this._map = map;
|
|
1212
|
-
|
|
1287
|
+
/** @see https://caniuse.com/?search=DeviceOrientation */
|
|
1288
|
+
if ('ondeviceorientationabsolute' in window) {
|
|
1289
|
+
this.__deviceOrientationEvent = 'deviceorientationabsolute';
|
|
1290
|
+
} else if('ondeviceorientation' in window) {
|
|
1291
|
+
this.__deviceOrientationEvent = 'deviceorientation';
|
|
1292
|
+
}
|
|
1293
|
+
this._throttled = L.Util.throttle(this._onDeviceOrientation, 100, this);
|
|
1213
1294
|
},
|
|
1214
1295
|
|
|
1215
1296
|
addHooks: function() {
|
|
1216
|
-
if (this._map._rotate &&
|
|
1217
|
-
L.DomEvent.on(window,
|
|
1297
|
+
if (this._map._rotate && this.__deviceOrientationEvent) {
|
|
1298
|
+
L.DomEvent.on(window, this.__deviceOrientationEvent, this._throttled, this);
|
|
1299
|
+
} else {
|
|
1300
|
+
// L.Map.CompassBearing handler will be automatically
|
|
1301
|
+
// disabled if device orientation is not supported.
|
|
1302
|
+
this.disable();
|
|
1218
1303
|
}
|
|
1219
1304
|
},
|
|
1220
1305
|
|
|
1221
1306
|
removeHooks: function() {
|
|
1222
|
-
if (this._map._rotate &&
|
|
1223
|
-
L.DomEvent.off(window,
|
|
1307
|
+
if (this._map._rotate && this.__deviceOrientationEvent) {
|
|
1308
|
+
L.DomEvent.off(window, this.__deviceOrientationEvent, this._throttled, this);
|
|
1224
1309
|
}
|
|
1225
1310
|
},
|
|
1226
1311
|
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1312
|
+
/**
|
|
1313
|
+
* `DeviceOrientationEvent.absolute` - Indicates whether the device is providing absolute
|
|
1314
|
+
* orientation values (relatives to Magnetic North) or
|
|
1315
|
+
* using some arbitrary frame determined by the device.
|
|
1316
|
+
*
|
|
1317
|
+
* `DeviceOrientationEvent.alpha` - Returns the rotation of the device around the Z axis;
|
|
1318
|
+
* that is, the number of degrees by which the device is
|
|
1319
|
+
* being twisted around the center of the screen.
|
|
1320
|
+
*
|
|
1321
|
+
* `window.orientation` - Returns the screen orientation in degrees (in 90-degree increments)
|
|
1322
|
+
* of the viewport relative to the device's natural orientation.
|
|
1323
|
+
* Its only possible values are -90, 0, 90, and 180. Positive
|
|
1324
|
+
* values are counterclockwise; negative values are clockwise.
|
|
1325
|
+
*
|
|
1326
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/DeviceOrientationEvent/absolute
|
|
1327
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/DeviceOrientationEvent/alpha
|
|
1328
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/Window/orientation
|
|
1329
|
+
*/
|
|
1330
|
+
_onDeviceOrientation: function(e) {
|
|
1331
|
+
var angle = e.webkitCompassHeading || e.alpha;
|
|
1332
|
+
var deviceOrientation = 0;
|
|
1333
|
+
|
|
1334
|
+
// Safari iOS
|
|
1335
|
+
if (!e.absolute && e.webkitCompassHeading) {
|
|
1336
|
+
angle = 360 - angle;
|
|
1337
|
+
}
|
|
1338
|
+
|
|
1339
|
+
// Older browsers
|
|
1340
|
+
if (!e.absolute && 'undefined' !== typeof window.orientation) {
|
|
1341
|
+
deviceOrientation = window.orientation;
|
|
1230
1342
|
}
|
|
1343
|
+
|
|
1344
|
+
this._map.setBearing(angle - deviceOrientation);
|
|
1231
1345
|
},
|
|
1232
1346
|
|
|
1233
1347
|
});
|
|
@@ -1588,10 +1702,6 @@
|
|
|
1588
1702
|
*/
|
|
1589
1703
|
touchZoom: L.Browser.touch,
|
|
1590
1704
|
|
|
1591
|
-
/**
|
|
1592
|
-
*
|
|
1593
|
-
*/
|
|
1594
|
-
|
|
1595
1705
|
/**
|
|
1596
1706
|
* @TODO check if this is a duplicate of `L.Map.TouchGestures::bounceAtZoomLimits`
|
|
1597
1707
|
*
|
|
@@ -1645,8 +1755,6 @@
|
|
|
1645
1755
|
},
|
|
1646
1756
|
|
|
1647
1757
|
onAdd: function(map) {
|
|
1648
|
-
this._onDeviceOrientation = L.Util.throttle(this._unthrottledOnDeviceOrientation, 100, this);
|
|
1649
|
-
|
|
1650
1758
|
var container = this._container = L.DomUtil.create('div', 'leaflet-control-rotate leaflet-bar');
|
|
1651
1759
|
|
|
1652
1760
|
// this.button = L.Control.Zoom.prototype._createButton.call(this, 'R', 'leaflet-control-rotate', 'leaflet-control-rotate', container, this._toggleLock);
|
|
@@ -1666,7 +1774,6 @@
|
|
|
1666
1774
|
link.appendChild(arrow);
|
|
1667
1775
|
link.href = '#';
|
|
1668
1776
|
link.title = 'Rotate map';
|
|
1669
|
-
// link.draggable = false;
|
|
1670
1777
|
|
|
1671
1778
|
L.DomEvent
|
|
1672
1779
|
.on(link, 'dblclick', L.DomEvent.stopPropagation)
|
|
@@ -1681,7 +1788,7 @@
|
|
|
1681
1788
|
|
|
1682
1789
|
this._restyle();
|
|
1683
1790
|
|
|
1684
|
-
map.on('rotate', this._restyle
|
|
1791
|
+
map.on('rotate', this._restyle, this);
|
|
1685
1792
|
|
|
1686
1793
|
// State flag
|
|
1687
1794
|
this._follow = false;
|
|
@@ -1693,9 +1800,13 @@
|
|
|
1693
1800
|
|
|
1694
1801
|
return container;
|
|
1695
1802
|
},
|
|
1803
|
+
|
|
1804
|
+
onRemove: function(map) {
|
|
1805
|
+
map.off('rotate', this._restyle, this);
|
|
1806
|
+
},
|
|
1696
1807
|
|
|
1697
1808
|
_handleMouseDown: function(e) {
|
|
1698
|
-
L.DomEvent.stop(e);
|
|
1809
|
+
L.DomEvent.stop(e);
|
|
1699
1810
|
this.dragging = true;
|
|
1700
1811
|
this.dragstartX = e.pageX;
|
|
1701
1812
|
this.dragstartY = e.pageY;
|
|
@@ -1705,7 +1816,7 @@
|
|
|
1705
1816
|
},
|
|
1706
1817
|
|
|
1707
1818
|
_handleMouseUp: function(e) {
|
|
1708
|
-
L.DomEvent.stop(e);
|
|
1819
|
+
L.DomEvent.stop(e);
|
|
1709
1820
|
this.dragging = false;
|
|
1710
1821
|
|
|
1711
1822
|
L.DomEvent
|
|
@@ -1720,64 +1831,64 @@
|
|
|
1720
1831
|
},
|
|
1721
1832
|
|
|
1722
1833
|
_cycleState: function(ev) {
|
|
1723
|
-
|
|
1834
|
+
if (!this._map) {
|
|
1835
|
+
return;
|
|
1836
|
+
}
|
|
1724
1837
|
|
|
1725
|
-
|
|
1838
|
+
var map = this._map;
|
|
1726
1839
|
|
|
1840
|
+
// Touch mode
|
|
1727
1841
|
if (!map.touchRotate.enabled() && !map.compassBearing.enabled()) {
|
|
1728
|
-
// Go from disabled to touch
|
|
1729
1842
|
map.touchRotate.enable();
|
|
1843
|
+
}
|
|
1844
|
+
|
|
1845
|
+
// Compass mode
|
|
1846
|
+
else if (!map.compassBearing.enabled()) {
|
|
1847
|
+
map.touchRotate.disable();
|
|
1848
|
+
map.compassBearing.enable();
|
|
1849
|
+
}
|
|
1730
1850
|
|
|
1731
|
-
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
map.touchRotate.
|
|
1737
|
-
map.compassBearing.enable();
|
|
1738
|
-
|
|
1739
|
-
// console.log('state is now: compass');
|
|
1740
|
-
|
|
1741
|
-
// It is possible that compass is not supported. If so,
|
|
1742
|
-
// the hangler will automatically go from compass to disabled.
|
|
1743
|
-
} else {
|
|
1744
|
-
// Go from compass to disabled
|
|
1745
|
-
map.compassBearing.disable();
|
|
1746
|
-
|
|
1747
|
-
// console.log('state is now: locked');
|
|
1748
|
-
|
|
1749
|
-
map.setBearing(0);
|
|
1750
|
-
if (this.options.closeOnZeroBearing) {
|
|
1751
|
-
map.touchRotate.enable();
|
|
1752
|
-
}
|
|
1851
|
+
// Locked mode
|
|
1852
|
+
else {
|
|
1853
|
+
map.compassBearing.disable();
|
|
1854
|
+
map.setBearing(0);
|
|
1855
|
+
if (this.options.closeOnZeroBearing) {
|
|
1856
|
+
map.touchRotate.enable();
|
|
1753
1857
|
}
|
|
1754
1858
|
}
|
|
1755
1859
|
this._restyle();
|
|
1756
1860
|
},
|
|
1757
1861
|
|
|
1758
1862
|
_restyle: function() {
|
|
1759
|
-
if (this._map.options.rotate) {
|
|
1863
|
+
if (!this._map.options.rotate) {
|
|
1864
|
+
L.DomUtil.addClass(this._link, 'leaflet-disabled');
|
|
1865
|
+
} else {
|
|
1760
1866
|
var map = this._map;
|
|
1761
1867
|
var bearing = map.getBearing();
|
|
1762
|
-
|
|
1868
|
+
|
|
1869
|
+
this._arrow.style.transform = 'rotate(' + bearing + 'deg)';
|
|
1870
|
+
|
|
1871
|
+
if (bearing && this.options.closeOnZeroBearing) {
|
|
1763
1872
|
this._container.style.display = 'block';
|
|
1764
1873
|
}
|
|
1765
1874
|
|
|
1766
|
-
|
|
1767
|
-
this._arrow.style.transform = cssTransform;
|
|
1768
|
-
|
|
1875
|
+
// Compass mode
|
|
1769
1876
|
if (map.compassBearing.enabled()) {
|
|
1770
1877
|
this._link.style.backgroundColor = 'orange';
|
|
1771
|
-
}
|
|
1878
|
+
}
|
|
1879
|
+
|
|
1880
|
+
// Touch mode
|
|
1881
|
+
else if (map.touchRotate.enabled()) {
|
|
1772
1882
|
this._link.style.backgroundColor = null;
|
|
1773
|
-
}
|
|
1883
|
+
}
|
|
1884
|
+
|
|
1885
|
+
// Locked mode
|
|
1886
|
+
else {
|
|
1774
1887
|
this._link.style.backgroundColor = 'grey';
|
|
1775
|
-
if (this.options.closeOnZeroBearing
|
|
1888
|
+
if (0 === bearing && this.options.closeOnZeroBearing) {
|
|
1776
1889
|
this._container.style.display = 'none';
|
|
1777
1890
|
}
|
|
1778
1891
|
}
|
|
1779
|
-
} else {
|
|
1780
|
-
L.DomUtil.addClass(this._link, 'leaflet-disabled');
|
|
1781
1892
|
}
|
|
1782
1893
|
},
|
|
1783
1894
|
|