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.
@@ -1,37 +1,29 @@
1
1
  /**
2
- * L.DivOverlay
2
+ * @external L.DivOverlay
3
+ *
4
+ * @see https://github.com/Leaflet/Leaflet/tree/v1.9.3/src/layer/DivOverlay.js
3
5
  */
6
+
4
7
  const divOverlayProto = L.extend({}, L.DivOverlay.prototype);
5
8
 
6
9
  L.DivOverlay.include({
7
10
 
8
11
  getEvents: function() {
9
- return L.extend(divOverlayProto.getEvents.call(this), { rotate: this._updatePosition });
12
+ return L.extend(divOverlayProto.getEvents.apply(this, arguments), { rotate: this._updatePosition });
10
13
  },
11
14
 
12
15
  _updatePosition: function() {
13
- if (!this._map) { return; }
14
-
15
- var pos = this._map.latLngToLayerPoint(this._latlng),
16
- offset = L.point(this.options.offset),
17
- anchor = this._getAnchor();
18
-
19
- if (this._zoomAnimated) {
20
- // TODO: use divOverlayProto._updatePosition
21
- if (this._map._rotate) {
22
- pos = this._map.rotatedPointToMapPanePoint(pos);
23
- }
24
- L.DomUtil.setPosition(this._container, pos.add(anchor));
25
- } else {
26
- offset = offset.add(pos).add(anchor);
16
+ // 0. update anchor (leaflet v1.9.3)
17
+ divOverlayProto._updatePosition.apply(this, arguments);
18
+ // 1. subtract anchor
19
+ // 2. rotate element
20
+ // 3. restore anchor
21
+ if (this._map && this._map._rotate && this._zoomAnimated) {
22
+ var anchor = this._getAnchor();
23
+ var pos = L.DomUtil.getPosition(this._container).subtract(anchor);
24
+ L.DomUtil.setPosition(this._container, this._map.rotatedPointToMapPanePoint(pos).add(anchor));
27
25
  }
28
26
 
29
- var bottom = this._containerBottom = -offset.y,
30
- left = this._containerLeft = -Math.round(this._containerWidth / 2) + offset.x;
31
-
32
- // bottom position the popup in case the height of the popup changes (images loading etc)
33
- this._container.style.bottom = bottom + 'px';
34
- this._container.style.left = left + 'px';
35
27
  },
36
28
 
37
29
  });
@@ -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
- if (!this._map._rotate) {
10
- popupProto._animateZoom.call(this, e);
12
+ // 0. update anchor (leaflet v1.9.3)
13
+ popupProto._animateZoom.apply(this, arguments);
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
- // TODO: use popupProto._adjustPan
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]);
@@ -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
- _updatePosition: function() {
11
+ _animateZoom: function(e) {
9
12
  if (!this._map._rotate) {
10
- return tooltipProto._updatePosition.call(this);
13
+ return tooltipProto._animateZoom.apply(this, arguments);
11
14
  }
12
- var pos = this._map.latLngToLayerPoint(this._latlng);
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
- _animateZoom: function(e) {
21
+ _updatePosition: function() {
19
22
  if (!this._map._rotate) {
20
- return tooltipProto._animateZoom.call(this, e);
23
+ return tooltipProto._updatePosition.apply(this, arguments);
21
24
  }
22
- var pos = this._map._latLngToNewLayerPoint(this._latlng, e.zoom, e.center);
25
+ var pos = this._map.latLngToLayerPoint(this._latlng);
23
26
 
24
27
  pos = this._map.rotatedPointToMapPanePoint(pos);
25
28
  this._setPosition(pos);
@@ -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
- // TODO: use iconProto._setIconStyles
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,53 @@
1
1
  /**
2
- * L.Handler.MarkerDrag
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
- var markerDragProto;
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
+ // @option scale: Number = undefined
21
+ // Scale of the marker icon
22
+ scale: undefined,
23
+
24
+ });
25
+
26
+ var markerDragProto; // retrived at runtime (see below: L.Marker::_initInteraction())
5
27
 
6
28
  var MarkerDrag = {
7
29
 
8
- _onDragStart: function() {
9
- if (!this._marker._map._rotate) {
10
- return markerDragProto._onDragStart.call(this)
11
- }
12
- this._draggable.updateMapBearing(this._marker._map._bearing);
13
- },
30
+ // _onDragStart: function() {
31
+ // if (!this._marker._map._rotate) {
32
+ // return markerDragProto._onDragStart.apply(this, arguments);
33
+ // }
34
+ // this._draggable.updateMapBearing(this._marker._map._bearing);
35
+ // },
14
36
 
15
37
  _onDrag: function(e) {
16
38
  var marker = this._marker,
17
- // TODO: use markerDragProto._onDrag
39
+ /** @TODO use markerDragProto._onDrag */
18
40
  rotated_marker = marker.options.rotation || marker.options.rotateWithView,
19
41
  shadow = marker._shadow,
20
42
  iconPos = L.DomUtil.getPosition(marker._icon);
21
43
 
22
- // TODO: use markerDragProto._onDrag
44
+ /** @TODO use markerDragProto._onDrag */
23
45
  // update shadow position
24
46
  if (!rotated_marker && shadow) {
25
47
  L.DomUtil.setPosition(shadow, iconPos);
26
48
  }
27
49
 
28
- // TODO: use markerDragProto._onDrag
50
+ /** @TODO use markerDragProto._onDrag */
29
51
  if (marker._map._rotate) {
30
52
  // Reverse calculation from mapPane coordinates to rotatePane coordinates
31
53
  iconPos = marker._map.mapPanePointToRotatedPoint(iconPos);
@@ -36,7 +58,7 @@ var MarkerDrag = {
36
58
  e.latlng = latlng;
37
59
  e.oldLatLng = this._oldLatLng;
38
60
 
39
- // TODO: use markerDragProto._onDrag
61
+ /** @TODO use markerDragProto._onDrag */
40
62
  if (rotated_marker) marker.setLatLng(latlng); // use `setLatLng` to presisit rotation. low efficiency
41
63
  else marker.fire('move', e); // `setLatLng` will trig 'move' event. we imitate here.
42
64
 
@@ -50,47 +72,32 @@ var MarkerDrag = {
50
72
  if (this._marker._map._rotate) {
51
73
  this._marker.update();
52
74
  }
53
- markerDragProto._onDragEnd.call(this, e);
75
+ markerDragProto._onDragEnd.apply(this, arguments);
54
76
  },
55
77
 
56
78
  };
57
79
 
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
80
  L.Marker.include({
76
81
 
77
82
  getEvents: function() {
78
- return L.extend(markerProto.getEvents.call(this), { rotate: this.update });
83
+ return L.extend(markerProto.getEvents.apply(this, arguments), { rotate: this.update });
79
84
  },
80
85
 
81
86
  onAdd: function(map) {
82
- markerProto.onAdd.call(this, map);
87
+ markerProto.onAdd.apply(this, arguments);
83
88
  map.on('rotate', this.update, this);
84
89
  },
85
90
 
86
91
  _initInteraction: function() {
87
- var ret = markerProto._initInteraction.call(this);
92
+ var ret = markerProto._initInteraction.apply(this, arguments);
88
93
  if (this.dragging && this.dragging.enabled() && this._map && this._map._rotate) {
89
94
  // L.Handler.MarkerDrag is used internally by L.Marker to make the markers draggable
90
95
  markerDragProto = markerDragProto || Object.getPrototypeOf(this.dragging);
91
- this.dragging._onDragStart = MarkerDrag._onDragStart.bind(this.dragging);
92
- this.dragging._onDrag = MarkerDrag._onDrag.bind(this.dragging);
93
- this.dragging._onDragEnd = MarkerDrag._onDragEnd.bind(this.dragging);
96
+ Object.assign(this.dragging, {
97
+ // _onDragStart: MarkerDrag._onDragStart.bind(this.dragging),
98
+ _onDrag: MarkerDrag._onDrag.bind(this.dragging),
99
+ _onDragEnd: MarkerDrag._onDragEnd.bind(this.dragging),
100
+ })
94
101
  this.dragging.disable();
95
102
  this.dragging.enable();
96
103
  }
@@ -99,23 +106,25 @@ L.Marker.include({
99
106
 
100
107
  _setPos: function(pos) {
101
108
 
102
- // TODO: use markerProto._setPos
109
+ /** @TODO use markerProto._setPos */
103
110
  if (this._map._rotate) {
104
111
  pos = this._map.rotatedPointToMapPanePoint(pos);
105
112
  }
106
113
 
107
- // TODO: use markerProto._setPos
114
+ /** @TODO use markerProto._setPos */
108
115
  var bearing = this.options.rotation || 0;
109
116
  if (this.options.rotateWithView) {
110
117
  bearing += this._map._bearing;
111
118
  }
112
119
 
113
- // TODO: use markerProto._setPos
114
- L.DomUtil.setPosition(this._icon, pos, bearing, pos);
120
+ /** @TODO use markerProto._setPos */
121
+ if (this._icon) {
122
+ L.DomUtil.setPosition(this._icon, pos, bearing, pos, this.options.scale);
123
+ }
115
124
 
116
- // TODO: use markerProto._setPos
125
+ /** @TODO use markerProto._setPos */
117
126
  if (this._shadow) {
118
- L.DomUtil.setPosition(this._shadow, pos, bearing, pos);
127
+ L.DomUtil.setPosition(this._shadow, pos, bearing, pos, this.options.scale);
119
128
  }
120
129
 
121
130
  this._zIndex = pos.y + this.options.zIndexOffset;
@@ -125,7 +134,7 @@ L.Marker.include({
125
134
 
126
135
  _updateZIndex: function(offset) {
127
136
  if (!this._map._rotate) {
128
- return markerProto._updateZIndex.call(this, offset)
137
+ return markerProto._updateZIndex.apply(this, arguments);
129
138
  }
130
139
  this._icon.style.zIndex = Math.round(this._zIndex + offset);
131
140
  },
@@ -1,12 +1,15 @@
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({
7
10
 
8
11
  getEvents: function() {
9
- var events = gridLayerProto.getEvents.call(this);
12
+ var events = gridLayerProto.getEvents.apply(this, arguments);
10
13
  if (this._map._rotate && !this.options.updateWhenIdle) {
11
14
  if (!this._onRotate) {
12
15
  this._onRotate = L.Util.throttle(this._onMoveEnd, this.options.updateInterval, this);
@@ -18,22 +21,10 @@ L.GridLayer.include({
18
21
 
19
22
  _getTiledPixelBounds: function(center) {
20
23
  if (!this._map._rotate) {
21
- return gridLayerProto._getTiledPixelBounds.call(this, center);
24
+ return gridLayerProto._getTiledPixelBounds.apply(this, arguments);
22
25
  }
23
26
 
24
- var map = this._map,
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
- canvasProto.onAdd.call(this);
10
- // When rotating the canvas itself, it is cleared by some weird reason, so redraw.
11
- this._map.on('rotate', this._redraw, this);
12
- },
11
+ // onAdd: function() {
12
+ // canvasProto.onAdd.apply(this, arguments);
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
- canvasProto.onRemove.call(this);
16
- this._map.off('rotate', this._redraw, this);
17
- },
17
+ // onRemove: function() {
18
+ // canvasProto.onRemove.apply(this, arguments);
19
+ // this._map.off('rotate', this._redraw, this);
20
+ // },
18
21
 
19
- _update: function() {
20
- canvasProto._update.call(this);
21
- // Tell paths to redraw themselves
22
- this.fire('update')
23
- },
22
+ // _update: function() {
23
+ // canvasProto._update.apply(this, arguments);
24
+ // // Tell paths to redraw themselves
25
+ // this.fire('update')
26
+ // },
24
27
 
25
28
  });
@@ -1,23 +1,31 @@
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
- rendererProto.onAdd.call(this);
10
- // this._map.on('rotate', this._update, this);
11
- },
12
-
13
- onRemove: function() {
14
- rendererProto.onRemove.call(this);
15
- // this._map.off('rotate', this._update, this);
16
- },
17
-
11
+ // onAdd: function() {
12
+ // rendererProto.onAdd.apply(this, arguments);
13
+ // // this._map.on('rotate', this._update, this);
14
+ // },
15
+
16
+ // onRemove: function() {
17
+ // rendererProto.onRemove.apply(this, arguments);
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
- return rendererProto._updateTransform.call(this, center, zoom);
28
+ return rendererProto._updateTransform.apply(this, arguments);
21
29
  }
22
30
  var scale = this._map.getZoomScale(zoom, this._zoom),
23
31
  offset = this._map._latLngToNewLayerPoint(this._topLeft, zoom, center);
@@ -30,29 +38,12 @@ L.Renderer.include({
30
38
 
31
39
  _update: function() {
32
40
  if (!this._map._rotate) {
33
- return rendererProto._update.call(this);
41
+ return rendererProto._update.apply(this, arguments);
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
- var p = this.options.padding,
38
- map = this._map,
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
  },
@@ -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
- svgProto._update.call(this);
10
- if (this._map._rotate) {
11
- this.fire('update');
12
- }
13
- },
11
+ // _update: function() {
12
+ // svgProto._update.apply(this, arguments);
13
+ // if (this._map._rotate) {
14
+ // this.fire('update');
15
+ // }
16
+ // },
14
17
 
15
18
  });