diff --git a/example/index.html b/example/index.html index 339741b..e546ca4 100644 --- a/example/index.html +++ b/example/index.html @@ -39,7 +39,13 @@ attribution: '© OpenStreetMap 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); diff --git a/src/leaflet-areaselect.js b/src/leaflet-areaselect.js index efb5388..28b5377 100644 --- a/src/leaflet-areaselect.js +++ b/src/leaflet-areaselect.js @@ -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);