Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple Image Select #158

Merged
merged 63 commits into from
Mar 30, 2019
Merged
Show file tree
Hide file tree
Changes from 57 commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
a207da0
dist file
sashadev-sky Mar 24, 2019
b2eb23d
Add ability to return array of all images on the map
sashadev-sky Feb 26, 2019
624484b
clean up code
sashadev-sky Feb 26, 2019
519ea8f
fix removeChild error
sashadev-sky Mar 9, 2019
2bde31d
add to container
sashadev-sky Mar 12, 2019
39c5625
Move multiple markers
sashadev-sky Mar 13, 2019
6a98899
Move multiple images
sashadev-sky Mar 15, 2019
6134d8e
Begin migrating code into a class
sashadev-sky Mar 16, 2019
9a47c71
continue code migration
sashadev-sky Mar 16, 2019
8b5a4f1
move multiple images through layer group
sashadev-sky Mar 18, 2019
cb98bd2
use available _updateCorner method
sashadev-sky Mar 18, 2019
3106757
remove test code
sashadev-sky Mar 18, 2019
e68ffb7
refactor out utility functions
sashadev-sky Mar 18, 2019
47ca719
Feature Group Implementation
sashadev-sky Mar 18, 2019
4e57a0f
Commit dist file
sashadev-sky Mar 18, 2019
5d3e3ce
remove migrated code
sashadev-sky Mar 18, 2019
c4505a1
Use getLayers instead of eachLayer
sashadev-sky Mar 18, 2019
1344070
Deselect all images on map click
sashadev-sky Mar 18, 2019
ab59ece
Remove hardcoding -- now works with any number of selected images
sashadev-sky Mar 19, 2019
9ed9558
Begin migrating code to custom featureGroup class
sashadev-sky Mar 19, 2019
45d4494
Hide multiple toolbars for multiple image drag
sashadev-sky Mar 19, 2019
6e2e416
Add DomUtil toggle method
sashadev-sky Mar 19, 2019
0280008
Prevent dragging if image is locked
sashadev-sky Mar 19, 2019
ff6111c
Remove all hardcoding
sashadev-sky Mar 19, 2019
ed97ed9
Work on fixing bug with rotation and scale
sashadev-sky Mar 19, 2019
892a109
Set edgeMinWidth and edgeMinHeight for scaling
sashadev-sky Mar 19, 2019
2b11ed5
Add removeHooks for new event listeners
sashadev-sky Mar 19, 2019
1b57443
Remove toolbar on image delete
sashadev-sky Mar 19, 2019
4b89e72
Attempt to encapsulate state in collection class
sashadev-sky Mar 20, 2019
5a4776f
Todos
sashadev-sky Mar 20, 2019
888c8ad
encapsulate all logic into DistortableCollection class
sashadev-sky Mar 22, 2019
4092391
refactoring
sashadev-sky Mar 22, 2019
dab47a8
refactor 2
sashadev-sky Mar 22, 2019
15cd875
Refactorings
sashadev-sky Mar 22, 2019
9516d81
Change box shadow to yellow
sashadev-sky Mar 22, 2019
d4e7110
Integrate boxzoom multi-selection
sashadev-sky Mar 23, 2019
069bb9d
Integrate esc key binding
sashadev-sky Mar 23, 2019
10065e0
undo last commit
sashadev-sky Mar 23, 2019
7e5c975
Begin updating README
sashadev-sky Mar 23, 2019
11b4111
Add sample code to readme
sashadev-sky Mar 23, 2019
6ea5ccd
Finish README
sashadev-sky Mar 23, 2019
cf843a0
Add tests for locking / selection as part of documentation
sashadev-sky Mar 24, 2019
72b9779
Finalize PR
sashadev-sky Mar 24, 2019
0638e79
Resolve conflict
sashadev-sky Mar 24, 2019
fedfc3c
Resolve conflicts
sashadev-sky Mar 24, 2019
6dbf87a
handlers.off()
sashadev-sky Mar 24, 2019
67e83b9
Temp disable box zoom
sashadev-sky Mar 24, 2019
ca3ba16
Fix typo
sashadev-sky Mar 24, 2019
fe817a3
Bump version 0.3.0 -> 0.4.0
sashadev-sky Mar 29, 2019
4782ecd
markers
sashadev-sky Mar 29, 2019
98a8a5d
Manage multiple multiple markers
sashadev-sky Mar 29, 2019
6cf0d92
Clean up code
sashadev-sky Mar 29, 2019
9bea9d4
Complete marker handling logic
sashadev-sky Mar 29, 2019
0326b62
Handle edge cases
sashadev-sky Mar 29, 2019
cfb7a31
Sync toolbar with markers
sashadev-sky Mar 29, 2019
0a65305
Refactor
sashadev-sky Mar 29, 2019
b61d3bd
Update test
sashadev-sky Mar 29, 2019
4a8284d
add showMarkers to DistortableImage.Edit
sashadev-sky Mar 29, 2019
b129060
add map click deselect for single image
sashadev-sky Mar 29, 2019
690c162
Add deselect with esc for single image
sashadev-sky Mar 30, 2019
9d54d8f
Remove yellow border highlight for single image
sashadev-sky Mar 30, 2019
83a1e1b
Fix typos
sashadev-sky Mar 30, 2019
effd49b
Refactoring
sashadev-sky Mar 30, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,10 @@ module.exports = function(grunt) {
'src/edit/RotateHandle.js',
'src/edit/ScaleHandle.js',
'src/DistortableImageOverlay.js',
'src/DistortableCollection.js',
'src/edit/DistortableImage.EditToolbar.js',
'src/edit/DistortableImage.Edit.js',
'src/edit/BoxSelectHandle.js'
],
dest: 'dist/leaflet.distortableimage.js',
}
Expand Down
62 changes: 39 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ A Leaflet extension to distort images -- "rubbersheeting" -- for the [MapKnitter

Advantages include:

* it can handle over 100 images smoothly, even on a smartphone.
* images can be right-clicked and downloaded individually in their original state
* It can handle over 100 images smoothly, even on a smartphone.
* Images can be right-clicked and downloaded individually in their original state
* CSS3 transforms are GPU-accelerated in most (all?) browsers, for a very smooth UI
* no need to server-side generate raster GeoTiffs, tilesets, etc in order to view distorted imagery layers
* images use DOM event handling for real-time distortion
* [full resolution download option](https://github.com/publiclab/Leaflet.DistortableImage/pull/100) for large images, using WebGL acceleration
* No need to server-side generate raster GeoTiffs, tilesets, etc. in order to view distorted imagery layers
* Images use DOM event handling for real-time distortion
* [Full resolution download option](https://github.com/publiclab/Leaflet.DistortableImage/pull/100) for large images, using WebGL acceleration

[Download as zip](https://github.com/publiclab/Leaflet.DistortableImage/releases) or clone to get a copy of the repo.
[Download as zip](https://github.com/publiclab/Leaflet.DistortableImage/releases) or clone the repo to get a local copy.

This plugin has basic functionality, and is in production as part of MapKnitter, but there are [plenty of outstanding issues to resolve](https://github.com/publiclab/Leaflet.DistortableImage/issues). Please consider helping out!

Expand All @@ -34,7 +34,9 @@ And watch this GIF demo:

To test the code, open `index.html` in your browser and click and drag the markers on the edges of the image. The image will show perspectival distortions.

## Usage
## Basic Usage

The most simple implementation to get started:

```js
// basic Leaflet map setup
Expand All @@ -56,11 +58,11 @@ img = new L.DistortableImageOverlay(
new L.latLng(51.50,-0.10),
new L.latLng(51.50,-0.14)
],
fullResolutionSrc: 'large.jpg' // optionally pass in a higher resolution image to use in full-res exporting
}
).addTo(map);

L.DomEvent.on(img._image, 'load', img.editing.enable, img.editing); // enable editing
// enable editing
L.DomEvent.on(img._image, 'load', img.editing.enable, img.editing);

```

Expand All @@ -74,19 +76,10 @@ We've added a GPU-accelerated means to generate a full resolution version of the
<script src="../node_modules/glfx/glfx.js"></script>
```

## Usage

```js
// basic Leaflet map setup
map = new L.map('map').setView([51.505, -0.09], 13);
L.tileLayer('https://{s}.tiles.mapbox.com/v3/anishshah101.ipm9j6em/{z}/{x}/{y}.png', {
maxZoom: 18,
attribution: 'Map data &copy; <a href="http://openstreetmap.org">OpenStreetMap</a> contributors, ' +
'<a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, ' +
'Imagery © <a href="http://mapbox.com">Mapbox</a>',
id: 'examples.map-i86knfo3'
}).addTo(map);
When instantiating a Distortable Image, pass in a `fullResolutionSrc` option set to the url of the higher resolution image. This image will be used in full-res exporting.

```js
// create an image
img = new L.DistortableImageOverlay(
'example.png', {
Expand All @@ -96,16 +89,39 @@ img = new L.DistortableImageOverlay(
new L.latLng(51.50,-0.10),
new L.latLng(51.50,-0.14)
],
fullResolutionSrc: 'large.jpg' // optionally pass in a higher resolution image to use in full-res exporting
fullResolutionSrc: 'large.jpg'
}
).addTo(map);

L.DomEvent.on(img._image, 'load', img.editing.enable, img.editing); // enable editing
L.DomEvent.on(img._image, 'load', img.editing.enable, img.editing);

```

## Multiple Images

To test the multi-image interface, open `select.html`. Currently it supports multiple image selection and translations; image distortions still use the single-image interface.

- Multiple images can be selected using <kbd>cmd</kbd> + `click` to toggle individual image selection.
- Click on the map or hit the <kbd>esc</kbd> key to quickly deselect all images.

Our `DistortableCollection` lass allows working with multiple images simultaneously. Say we instantiated 3 images, saved them to the variables `img`, `img2`, and `img3`, and enabled editing on all of them. To access the UI and functionalities available in the multiple image interface, pass them to the collection class:
sashadev-sky marked this conversation as resolved.
Show resolved Hide resolved

```js
// OPTION 1: Pass in images immediately
new L.DistortableCollection([img, img2, img3]).addTo(map);

// OPTION 2: Instantiate an empty collection and pass in images later
var imageFeatureGroup = new L.DistortableCollection().addTo(map);

imageFeatureGroup.addLayer(img);
imageFeatureGroup.addLayer(img2);
imageFeatureGroup.addLayer(img3);

```

## Image-ordering

For multiple images, we've added a `ToggleOrder` action, that switches overlapping images back and forth into view by employing the [`bringToFront()`](https://leafletjs.com/reference-1.4.0.html#popup-bringtofront) and [`bringToBack()`](https://leafletjs.com/reference-1.4.0.html#popup-bringtoback).
For multiple images, we've also added a `ToggleOrder` action, that switches overlapping images back and forth into view by employing [`bringToFront()`](https://leafletjs.com/reference-1.4.0.html#popup-bringtofront) and [`bringToBack()`](https://leafletjs.com/reference-1.4.0.html#popup-bringtoback) from the Leaflet API.

```js
ToggleOrder = EditOverlayAction.extend({
Expand Down
4 changes: 4 additions & 0 deletions dist/leaflet.distortableimage.css
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,7 @@
.leaflet-toolbar-tip {
box-sizing: border-box;
}

img.leaflet-image-layer.selected {
box-shadow: 0px 0px 0px 12px #ffea00;
}
Loading