Skip to content

Commit

Permalink
fix scale/rotate/rotateScale distortions + tests (publiclab#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 authored and themacboy committed Sep 19, 2019
1 parent 037412e commit b024571
Show file tree
Hide file tree
Showing 15 changed files with 1,116 additions and 94 deletions.
35 changes: 35 additions & 0 deletions README.md
Expand Up @@ -510,10 +510,35 @@ We have made slight changes to a default Leaflet handler:
<ul><li>Returns the coordinates of the image corner at <i>index</i>.</li></ul>
</details>
<<<<<<< Upstream, based on Leaflet.DistortableImage/main
<details><summary><code><b>getCorners()</b>: 4 [LatLng, LatLng, LatLng, LatLng]</code></summary>
<ul><li>Returns the coordinates of the image corners in NW, NE, SW, SE order.</li></ul>
</details>
=======
- `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.
>>>>>>> 2d8a1db fix scale/rotate/rotateScale distortions + tests (#380)
<<<<<<< Upstream, based on Leaflet.DistortableImage/main
<details><summary><code><b>setCorner(<i>idx</i> &#60;number 0..3>, <i>LatLng</i>)</b>: this</code></summary>
<ul>
<li>Updates the coordinates of the image corner at <i>index</i> to <i>LatLng</i> and, where applicable, marker and toolbar positioning.</li>
Expand Down Expand Up @@ -622,6 +647,16 @@ A handler that holds the keybindings and toolbar API for an image instance. It i
</details>

---
=======
- `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>
>>>>>>> 2d8a1db fix scale/rotate/rotateScale distortions + tests (#380)

`L.DistortableCollection`

Expand Down

0 comments on commit b024571

Please sign in to comment.