Skip to content

Commit

Permalink
fix scale/rotate/rotateScale distortions + tests (#380)
Browse files Browse the repository at this point in the history
* test scale

* no more distortions

* improve revert

* refactor

* update docs

* move comment out of code into README

* clean tests

* clean

* clean

* refactor
  • Loading branch information
sashadev-sky committed Aug 13, 2019
1 parent 2aeeb45 commit e6acff0
Show file tree
Hide file tree
Showing 15 changed files with 403 additions and 324 deletions.
27 changes: 27 additions & 0 deletions README.md
Expand Up @@ -374,8 +374,35 @@ Defaults:

- [`getCorners()`](#corners) and [`getCorner(idx)`](#corners)

- `setCorner(idx, latLng)` - update an individual image corner and, where applicable, marker and toolbar positioning. We use this internally for `distort` mode.

- `setCorners(corners)` - same as`setCorner`, but takes in a "corners" object to update all 4 corners with only one UI update at the end. We use this internally for image translation, rotation, and scaling.
- Ex.
```JS
/** keys: 0-4, values: L.latLng objects for desired corner positions */
scaledCorners = {0: '', 1: '', 2: '', 3: ''};

for (i = 0; i < 4; i++) {
p = map
.project(this.getCorner(i))
.subtract(center)
.multiplyBy(scale)
.add(center);
scaledCorners[i] = map.unproject(p);
}

this.setCorners(scaledCorners);
```

- `getCenter()` - Calculates the centroid of the image.

- `scaleBy(num)` - scales the image by the given ratio and calls `setCorners`.
- ex. `overlay.scaleBy(0.5)`
- a scale of 0 or 1 will leave the image unchanged - but 0 causes the function to automatically return
- a negative scale will invert the image and, depending on the scale value, change its size

- `rotateBy(rad)` - rotates the image by the given radian angle and calls `setCorners`.

<hr>

`L.DistortableCollection`
Expand Down

0 comments on commit e6acff0

Please sign in to comment.