diff --git a/src/Path.Transform.js b/src/Path.Transform.js index 14f6cee..f45bc70 100644 --- a/src/Path.Transform.js +++ b/src/Path.Transform.js @@ -48,6 +48,7 @@ L.PathTransform.RotateHandle = L.PathTransform.Handle.extend({ L.Handler.PathTransform = L.Handler.extend({ options: { rotation: true, + rotationAnchor: null, scaling: true, uniformScaling: true, maxZoom: 22, @@ -360,12 +361,29 @@ L.Handler.PathTransform = L.Handler.extend({ this._path._transform(null); this._rect._transform(null); - this._transformPoints(this._path); - this._transformPoints(this._rect); - if (this.options.rotation) { this._handleLine._transform(null); - this._transformPoints(this._handleLine, this._angle, null, this._origin); + this._transformPoints( + this._path, + this._angle, + null, + this.options.rotationAnchor + ); + this._transformPoints( + this._rect, + this._angle, + null, + this.options.rotationAnchor + ); + this._transformPoints( + this._handleLine, + this._angle, + null, + this.options.rotationAnchor + ); + } else { + this._transformPoints(this._path); + this._transformPoints(this._rect); } }, @@ -506,7 +524,9 @@ L.Handler.PathTransform = L.Handler.extend({ // move handlers to the top of all other layers; prevents handlers from // being blocked by other layers - this._handlersGroup.getLayers().forEach(function(layer) { layer.bringToFront(); }); + this._handlersGroup.getLayers().forEach(function (layer) { + layer.bringToFront(); + }); }, /** @@ -558,6 +578,14 @@ L.Handler.PathTransform = L.Handler.extend({ * @return {L.LatLng} */ _getRotationOrigin: function () { + if (this.options.rotationAnchor) { + var anchor = this.options.rotationAnchor; + if (Array.isArray(anchor) && anchor.length >= 2) { + return new L.LatLng(anchor[0], anchor[1]); + } else if (anchor instanceof L.LatLng) { + return anchor; + } + } var latlngs = this._rect._latlngs[0]; var lb = latlngs[0]; var rt = latlngs[2];