diff --git a/dist/leaflet.distortableimage.js b/dist/leaflet.distortableimage.js index 9ec77360f..bf712bc2f 100644 --- a/dist/leaflet.distortableimage.js +++ b/dist/leaflet.distortableimage.js @@ -180,7 +180,7 @@ L.DistortableImageOverlay = L.ImageOverlay.extend({ height: 200, crossOrigin: true, // todo: find ideal number to prevent distortions during RotateScale, and make it dynamic (remove hardcoding) - edgeMinWidth: 520 + edgeMinWidth: 50 }, initialize: function(url, options) { @@ -1197,10 +1197,13 @@ L.RotateScaleHandle = L.EditHandle.extend({ this enables preventing scaling to zero, but we might also add an overall scale limit */ if (overlay.hasOwnProperty('edgeMinWidth')){ - var edgeMinWidth = overlay.edgeMinWidth, - w = L.latLng(overlay.getCorner(0)).distanceTo(overlay.getCorner(1)), - h = L.latLng(overlay.getCorner(1)).distanceTo(overlay.getCorner(2)); - if ((w > edgeMinWidth && h > edgeMinWidth) || scale > 1) { + var edgeMinWidth = overlay.edgeMinWidth; + var corner1 = overlay._map.latLngToContainerPoint(overlay.getCorner(0)), + corner2 = overlay._map.latLngToContainerPoint(overlay.getCorner(1)); + var w = Math.abs(corner1.x - corner2.x); + var h = Math.abs(corner1.y - corner2.y); + var distance = Math.sqrt(w * w + h * h); + if ((distance > edgeMinWidth) || scale > 1) { edit._scaleBy(scale); } } diff --git a/package.json b/package.json index 2f06bf8a9..863a0746b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "leaflet-distortableimage", - "version": "0.6.1", + "version": "0.6.2", "description": "Leaflet plugin enabling image overlays to be distorted, stretched, and warped (built for Public Lab's MapKnitter: http://publiclab.org).", "scripts": { "test": "echo \"Error: no test specified\" && exit 1" diff --git a/src/DistortableImageOverlay.js b/src/DistortableImageOverlay.js index 9551e6c03..16f6c6f03 100644 --- a/src/DistortableImageOverlay.js +++ b/src/DistortableImageOverlay.js @@ -5,7 +5,7 @@ L.DistortableImageOverlay = L.ImageOverlay.extend({ height: 200, crossOrigin: true, // todo: find ideal number to prevent distortions during RotateScale, and make it dynamic (remove hardcoding) - edgeMinWidth: 520 + edgeMinWidth: 50 }, initialize: function(url, options) { diff --git a/src/edit/RotateScaleHandle.js b/src/edit/RotateScaleHandle.js index 142006098..a571d3151 100644 --- a/src/edit/RotateScaleHandle.js +++ b/src/edit/RotateScaleHandle.js @@ -24,10 +24,13 @@ L.RotateScaleHandle = L.EditHandle.extend({ this enables preventing scaling to zero, but we might also add an overall scale limit */ if (overlay.hasOwnProperty('edgeMinWidth')){ - var edgeMinWidth = overlay.edgeMinWidth, - w = L.latLng(overlay.getCorner(0)).distanceTo(overlay.getCorner(1)), - h = L.latLng(overlay.getCorner(1)).distanceTo(overlay.getCorner(2)); - if ((w > edgeMinWidth && h > edgeMinWidth) || scale > 1) { + var edgeMinWidth = overlay.edgeMinWidth; + var corner1 = overlay._map.latLngToContainerPoint(overlay.getCorner(0)), + corner2 = overlay._map.latLngToContainerPoint(overlay.getCorner(1)); + var w = Math.abs(corner1.x - corner2.x); + var h = Math.abs(corner1.y - corner2.y); + var distance = Math.sqrt(w * w + h * h); + if ((distance > edgeMinWidth) || scale > 1) { edit._scaleBy(scale); } }