Skip to content

Commit

Permalink
ADD: setAngle() method (#502)
Browse files Browse the repository at this point in the history
The method accepts an angle in degrees and sets element's rotation to be
that angle.

Resolves #102
  • Loading branch information
VladimirMikulic authored and jywarren committed Jan 2, 2020
1 parent 354e3c6 commit ab3eccc
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
10 changes: 10 additions & 0 deletions dist/leaflet.distortableimage.js
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,16 @@ L.DistortableImageOverlay = L.ImageOverlay.extend({
return this;
},

setAngle: function(angleInDeg) {
var currentAngleInDeg = this.getAngle();
var angleToRotateByInDeg = angleInDeg - currentAngleInDeg;

var angleInRad = L.TrigUtil.degreesToRadians(angleToRotateByInDeg);
this.rotateBy(angleInRad);

return this;
},

rotateBy: function(angle) {
var map = this._map;
var center = map.project(this.getCenter());
Expand Down
10 changes: 10 additions & 0 deletions src/DistortableImageOverlay.js
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,16 @@ L.DistortableImageOverlay = L.ImageOverlay.extend({
return this;
},

setAngle: function(angleInDeg) {
var currentAngleInDeg = this.getAngle();
var angleToRotateByInDeg = angleInDeg - currentAngleInDeg;

var angleInRad = L.TrigUtil.degreesToRadians(angleToRotateByInDeg);
this.rotateBy(angleInRad);

return this;
},

rotateBy: function(angle) {
var map = this._map;
var center = map.project(this.getCenter());
Expand Down

0 comments on commit ab3eccc

Please sign in to comment.