Skip to content

Commit

Permalink
Fix wrong calculation of maxHeight when keepAspectRatio is used
Browse files Browse the repository at this point in the history
Thanks to @mejackreed who provided the fix. Fixes #21
  • Loading branch information
heyman committed Nov 21, 2023
1 parent f4690fd commit 27d6687
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
8 changes: 7 additions & 1 deletion example/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,13 @@
attribution: '&copy; <a href="https://osm.org/copyright">OpenStreetMap</a> contributors'
}).addTo(map);

var areaSelect = L.areaSelect({width:200, height:250});
var areaSelect = L.areaSelect({
width:200,
height:250,
//keepAspectRatio:true,
//minHorizontalSpacing: 80,
//minVerticalSpacing: 80,
});
areaSelect.on("change", function() {
var bounds = this.getBounds();
$("#result .sw").val(bounds.getSouthWest().lat + ", " + bounds.getSouthWest().lng);
Expand Down
2 changes: 1 addition & 1 deletion src/leaflet-areaselect.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ L.AreaSelect = L.Class.extend({
}
function dragMove(pageX, pageY) {
if (self.options.keepAspectRatio) {
var maxHeight = (self._height >= self._width ? size.y : size.y * (1/ratio) ) - Math.max(self.options.minVerticalSpacing, self.options.minHorizontalSpacing);
var maxHeight = (self._height >= self._width ? size.y : (size.x / ratio) ) - Math.max(self.options.minVerticalSpacing, self.options.minHorizontalSpacing);
self._height += (curY - pageY) * 2 * yMod;
self._height = Math.max(self.options.minHeight, self.options.minWidth, self._height);
self._height = Math.min(maxHeight, self._height);
Expand Down

0 comments on commit 27d6687

Please sign in to comment.