leaflet-rotate 0.2.3 → 0.2.4

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/src/map/Map.js CHANGED
@@ -95,6 +95,15 @@ L.Map.include({
95
95
  .rotate(-this._bearing);
96
96
  },
97
97
 
98
+ // latLngToLayerPoint: function (latlng) {
99
+ // var projectedPoint = this.project(L.latLng(latlng))._round();
100
+ // return projectedPoint._subtract(this.getPixelOrigin());
101
+ // },
102
+
103
+ // latLngToContainerPoint: function (latlng) {
104
+ // return this.layerPointToContainerPoint(this.latLngToLayerPoint(toLatLng(latlng)));
105
+ // },
106
+
98
107
  /**
99
108
  * Given latlng bounds, returns the bounds in projected pixel
100
109
  * relative to the map container.
@@ -110,10 +119,12 @@ L.Map.include({
110
119
  if (!this._rotate && mapProto.mapBoundsToContainerBounds) {
111
120
  return mapProto.mapBoundsToContainerBounds.apply(this, arguments);
112
121
  }
113
- const nw = this.latLngToContainerPoint(bounds.getNorthWest()),
114
- ne = this.latLngToContainerPoint(bounds.getNorthEast()),
115
- sw = this.latLngToContainerPoint(bounds.getSouthWest()),
116
- se = this.latLngToContainerPoint(bounds.getSouthEast());
122
+ // same as `this.latLngToContainerPoint(latlng)` but with floating point precision
123
+ const origin = this.getPixelOrigin().add(this._getMapPanePos());
124
+ const nw = this.project(bounds.getNorthWest())._subtract(origin),
125
+ ne = this.project(bounds.getNorthEast())._subtract(origin),
126
+ sw = this.project(bounds.getSouthWest())._subtract(origin),
127
+ se = this.project(bounds.getSouthEast())._subtract(origin);
117
128
  return L.bounds([
118
129
  L.point(Math.min(nw.x, ne.x, se.x, sw.x), Math.min(nw.y, ne.y, se.y, sw.y)), // [ minX, minY ]
119
130
  L.point(Math.max(nw.x, ne.x, se.x, sw.x), Math.max(nw.y, ne.y, se.y, sw.y)) // [ maxX, maxY ]
package/test/index.html CHANGED
@@ -55,6 +55,10 @@
55
55
  <button onclick="map.flyTo(places['Washington'], 10);">Washington</button>
56
56
  <button onclick="map.flyTo(places['Trondheim'], 10);">Trondheim</button>
57
57
  </p>
58
+ <p>
59
+ <strong>Fit bounds (z = 0): </strong>
60
+ <button onclick="map.setZoom(0, {animate: false}) && setTimeout(() => map.fitBounds(rectangle.getBounds(), { animate: false }), 1000);" title="DEBUG: map.setZoom(0) && map.getBoundsZoom(rectangle.getBounds())">RECTANGLE</button>
61
+ </p>
58
62
  </div>
59
63
 
60
64
  <script>
@@ -143,8 +147,16 @@
143
147
  [52, 4]
144
148
  ]).addTo(map);
145
149
 
150
+ const rectangle = L.rectangle([
151
+ [60.81123, 25.71632],
152
+ [60.81028, 25.73166],
153
+ [60.7997, 25.72892],
154
+ [60.80061, 25.71362]
155
+ ]).addTo(map);
156
+
146
157
  // Display some debug info
147
158
  L.Rotate.debug(map);
159
+
148
160
  </script>
149
161
 
150
162
  <a href="https://github.com/Raruto/leaflet-rotate" class="view-on-github" style="position: fixed;bottom: 10px;left: calc(50% - 60px);z-index: 9999;"> <img alt="View on Github" src="https://raruto.github.io/img/view-on-github.png" title="View on Github"