leaflet-rotate 0.4.0 → 0.5.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.
@@ -1,30 +1,57 @@
1
1
  /**
2
+ * Recalculates vector renderer bounds and transforms for rotated and pitched maps.
3
+ *
2
4
  * @external L.Renderer
3
5
  *
4
6
  * @see https://github.com/Leaflet/Leaflet/tree/v1.9.3/src/layer/vector/Renderer.js
7
+ *
8
+ * @since leaflet-rotate (v0.1.0)
5
9
  */
6
10
 
7
11
  const rendererProto = Object.defineProperties({}, Object.getOwnPropertyDescriptors(L.Renderer.prototype));
8
12
  const rendererBase = Object.getPrototypeOf(L.Renderer.prototype);
9
13
  const rendererGetEvents = rendererProto.getEvents || rendererBase.getEvents;
14
+ const rendererOnMoveEnd = rendererProto._onMoveEnd || rendererBase._onMoveEnd;
10
15
 
11
16
  L.Renderer.include({
12
17
 
13
18
  /**
14
- * Redraw L.Canvas and L.SVG renderer bounds after the
15
- * map is moved by just calling `map.setBearing(theta)`
19
+ * Subscribe the renderer to map rotation so its visible bounds are recalculated.
16
20
  *
17
21
  * @listens L.Map~rotate
22
+ *
23
+ * @returns {Object} Leaflet event map for the renderer.
24
+ *
25
+ * @since leaflet-rotate (v0.1.0)
18
26
  */
19
27
  getEvents() {
20
28
  const events = rendererGetEvents.apply(this, arguments);
21
- return L.version.startsWith('2.') ? events : Object.assign(events, { rotate: this._update });
29
+ return Object.assign(events, { rotate: this._onRotate });
22
30
  },
23
31
 
24
32
  /**
25
- * Fix for `map.flyTo()` when `false === map.options.zoomAnimation`
33
+ * Reproject vector paths and refresh renderer bounds after bearing changes.
34
+ *
35
+ * @since leaflet-rotate (v0.1.0)
36
+ */
37
+ _onRotate() {
38
+ if (!this._map._rotate) { return; }
39
+ this._onZoomEnd();
40
+ if (L.version.startsWith('2.')) {
41
+ this._onMoveEnd();
42
+ } else {
43
+ this._update();
44
+ }
45
+ },
46
+
47
+ /**
48
+ * Add the zoom-animation class needed for correct renderer transforms in Leaflet 1.
49
+ *
50
+ * Fixes `map.flyTo()` when `map.options.zoomAnimation` is false.
26
51
  *
27
52
  * @see https://github.com/Leaflet/Leaflet/pull/8794
53
+ *
54
+ * @since leaflet-rotate (v0.2.0)
28
55
  */
29
56
  onAdd() {
30
57
  rendererProto.onAdd.apply(this, arguments);
@@ -35,6 +62,8 @@ L.Renderer.include({
35
62
  },
36
63
 
37
64
  /**
65
+ * Update the renderer transform during zoom animation, accounting for rotated coordinates.
66
+ *
38
67
  * @FIXME layer drifts on `map.setZoom()` (eg. zoom during animation)
39
68
  *
40
69
  * the main cause seems to be related to `this._updateTransform(path._center, path._zoom))`
@@ -49,9 +78,14 @@ L.Renderer.include({
49
78
  * @see https://github.com/Leaflet/Leaflet/pull/8103
50
79
  * @see https://github.com/Leaflet/Leaflet/issues/7466
51
80
  *
52
- * @TODO rechek this changes from leaflet@v1.9.3
81
+ * @TODO recheck these changes against leaflet@v1.9.3
53
82
  *
54
83
  * @see https://github.com/Leaflet/Leaflet/compare/v1.7.0...v1.9.3
84
+ *
85
+ * @param {L.LatLng} center Target map center.
86
+ * @param {number} zoom Target zoom level.
87
+ *
88
+ * @since leaflet-rotate (v0.1.0)
55
89
  */
56
90
  _updateTransform(center, zoom) {
57
91
  if (L.version.startsWith('2.')) {
@@ -82,9 +116,16 @@ L.Renderer.include({
82
116
 
83
117
  },
84
118
 
119
+ /**
120
+ * Recalculate bounds and finish renderer updates after movement on Leaflet 2.
121
+ *
122
+ * @param {Object} ev Map movement event.
123
+ *
124
+ * @since leaflet-rotate (v0.4.0)
125
+ */
85
126
  _onMoveEnd(ev) {
86
127
  if (!L.version.startsWith('2.') || !this._map._rotate) {
87
- return rendererBase._onMoveEnd.apply(this, arguments);
128
+ return rendererOnMoveEnd.apply(this, arguments);
88
129
  }
89
130
 
90
131
  this._bounds = this._map._getPaddedPixelBounds(this.options.padding);
@@ -97,6 +138,11 @@ L.Renderer.include({
97
138
  this._onSettled(ev);
98
139
  },
99
140
 
141
+ /**
142
+ * Resize the renderer container to cover the pitch-aware map bounds.
143
+ *
144
+ * @since leaflet-rotate (v0.4.0)
145
+ */
100
146
  _resizeContainer() {
101
147
  if (!L.version.startsWith('2.') || !this._map._rotate || !this._bounds) {
102
148
  return rendererBase._resizeContainer.apply(this, arguments);
@@ -150,6 +196,11 @@ L.Renderer.include({
150
196
  // }
151
197
  // },
152
198
 
199
+ /**
200
+ * Recalculate renderer bounds and cached view state.
201
+ *
202
+ * @since leaflet-rotate (v0.1.0)
203
+ */
153
204
  _update() {
154
205
  if (!this._map._rotate) {
155
206
  return rendererProto._update.apply(this, arguments);