leaflet-rotate 0.5.0 → 0.5.2

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.
@@ -30,13 +30,41 @@ L.Renderer.include({
30
30
  },
31
31
 
32
32
  /**
33
- * Reproject vector paths and refresh renderer bounds after bearing changes.
33
+ * Refresh renderer bounds after bearing or pitch changes.
34
+ *
35
+ * Paths are reprojected only when the pixel origin actually changed (eg. fractional centers
36
+ * after an off-center zoom), since reprojection is the main cost with long polylines.
34
37
  *
35
38
  * @since leaflet-rotate (v0.1.0)
36
39
  */
37
40
  _onRotate() {
38
41
  if (!this._map._rotate) { return; }
39
- this._onZoomEnd();
42
+ const origin = this._map.getPixelOrigin();
43
+ if (!this._rotateOrigin || !this._rotateOrigin.equals(origin)) {
44
+ this._rotateOrigin = origin;
45
+ clearTimeout(this._rotateTimer);
46
+ this._onZoomEnd();
47
+ this._updateAfterRotate();
48
+ return;
49
+ }
50
+ // paths are still aligned: only redraw when the view leaves the already drawn area
51
+ if (this._bounds && this._bounds.contains(this._map._getPaddedPixelBounds(0))) { return; }
52
+ clearTimeout(this._rotateTimer);
53
+ const wait = (this._lastRotateUpdate || 0) + 100 - performance.now();
54
+ if (wait > 0) {
55
+ this._rotateTimer = setTimeout(() => this._map && this._updateAfterRotate(), wait);
56
+ } else {
57
+ this._updateAfterRotate();
58
+ }
59
+ },
60
+
61
+ /**
62
+ * Recalculate renderer bounds and redraw after bearing or pitch changes.
63
+ *
64
+ * @since leaflet-rotate (0.5.1)
65
+ */
66
+ _updateAfterRotate() {
67
+ this._lastRotateUpdate = performance.now();
40
68
  if (L.version.startsWith('2.')) {
41
69
  this._onMoveEnd();
42
70
  } else {
@@ -63,57 +91,31 @@ L.Renderer.include({
63
91
 
64
92
  /**
65
93
  * Update the renderer transform during zoom animation, accounting for rotated coordinates.
66
- *
67
- * @FIXME layer drifts on `map.setZoom()` (eg. zoom during animation)
68
- *
69
- * the main cause seems to be related to `this._updateTransform(path._center, path._zoom))`
70
- * and `this._topLeft = this._map.layerPointToLatLng(this._bounds.min);`
71
- *
72
- * @example
73
- * map.setZoom(2);
74
- * path._renderer._update();
75
- * path._renderer._updateTransform(path._renderer._center, path._renderer._zoom);
76
94
  *
77
95
  * @see https://github.com/Leaflet/Leaflet/pull/8794
78
96
  * @see https://github.com/Leaflet/Leaflet/pull/8103
79
97
  * @see https://github.com/Leaflet/Leaflet/issues/7466
80
98
  *
81
- * @TODO recheck these changes against leaflet@v1.9.3
82
- *
83
- * @see https://github.com/Leaflet/Leaflet/compare/v1.7.0...v1.9.3
84
- *
85
99
  * @param {L.LatLng} center Target map center.
86
100
  * @param {number} zoom Target zoom level.
87
101
  *
88
102
  * @since leaflet-rotate (v0.1.0)
89
103
  */
90
104
  _updateTransform(center, zoom) {
91
- if (L.version.startsWith('2.')) {
92
- if (this._map._rotate) {
93
- const scale = this._map.getZoomScale(zoom, this._zoom),
94
- offset = this._topLeftPoint.multiplyBy(scale)
95
- .subtract(this._map._getNewPixelOrigin(center, zoom));
96
-
97
- L.DomUtil.setTransform(this._container, offset, scale);
98
- return;
99
- }
100
- return rendererBase._updateTransform.apply(this, arguments);
101
- }
105
+ const v2 = L.version.startsWith('2.');
102
106
  if (!this._map._rotate) {
103
- return rendererProto._updateTransform.apply(this, arguments);
107
+ return (v2 ? rendererBase : rendererProto)._updateTransform.apply(this, arguments);
104
108
  }
105
- if (zoom === this._zoom) {
109
+ if (!v2 && zoom === this._zoom) {
106
110
  // _reset() has already repositioned the renderer at the current zoom.
107
111
  return;
108
112
  }
109
- /**
110
- * @FIXME see path._renderer._reset();
111
- */
113
+ // Stay in pixel space: round-tripping `_topLeft` through lat/lng clamps at low zooms (layers jump).
112
114
  const scale = this._map.getZoomScale(zoom, this._zoom),
113
- offset = this._map._latLngToNewLayerPoint(this._topLeft, zoom, center);
115
+ offset = this._topLeftPoint.multiplyBy(scale)
116
+ .subtract(this._map._getNewPixelOrigin(center, zoom));
114
117
 
115
118
  L.DomUtil.setTransform(this._container, offset, scale);
116
-
117
119
  },
118
120
 
119
121
  /**
@@ -211,6 +213,7 @@ L.Renderer.include({
211
213
  this._topLeft = this._map.layerPointToLatLng(this._bounds.min);
212
214
  this._center = this._map.getCenter();
213
215
  this._zoom = this._map.getZoom();
216
+ this._topLeftPoint = this._map._getNewPixelOrigin(this._center, this._zoom).add(this._bounds.min);
214
217
  },
215
218
 
216
219
  });