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

Restore original proportions tool and bug fixes #274

Merged
merged 44 commits into from
Jun 27, 2019
Merged
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
f68eae1
sdf
sashadev-sky Jun 15, 2019
aedac37
implement restore function
sashadev-sky May 29, 2019
5fd2484
Fix coordinates bug
sashadev-sky May 29, 2019
5bae884
Update README demos
sashadev-sky May 29, 2019
db52b50
create ImageUtil file
sashadev-sky May 29, 2019
77ba084
sfd
sashadev-sky May 30, 2019
6357093
cleanup
sashadev-sky May 30, 2019
450fd40
Cleanup 2
sashadev-sky May 30, 2019
a3799ae
Cleanup 3
sashadev-sky May 30, 2019
d9d02b8
test cleanup
sashadev-sky May 30, 2019
c7755dd
sdgh
sashadev-sky Jun 15, 2019
16241dd
Implement svg
sashadev-sky Jun 18, 2019
5cfd9b7
Accessibility
sashadev-sky Jun 18, 2019
fc7cae1
add opacity full
sashadev-sky Jun 18, 2019
0d1df94
Optimize svgs
sashadev-sky Jun 18, 2019
b045084
refactor
sashadev-sky Jun 18, 2019
ecca5ce
Stop creating new toolbar instances
sashadev-sky Jun 18, 2019
065bfd1
refactor
sashadev-sky Jun 18, 2019
4537d90
Refactor pt.2
sashadev-sky Jun 18, 2019
f2224fe
Refactoring 3
sashadev-sky Jun 18, 2019
a976d45
Refactor 3
sashadev-sky Jun 18, 2019
c166775
commit
sashadev-sky Jun 18, 2019
ac0418f
readme
sashadev-sky Jun 18, 2019
9a4882c
Add xlink for safari 7 support
sashadev-sky Jun 19, 2019
de6b768
correct polyfill usage confirmed
sashadev-sky Jun 19, 2019
7fa779e
update restore icon to filled icon
sashadev-sky Jun 19, 2019
b1f3f2c
Icon normalization
sashadev-sky Jun 19, 2019
745665d
Readme
sashadev-sky Jun 19, 2019
6f68083
remove useless css
sashadev-sky Jun 19, 2019
0a6fbfa
Toolbar documentation updates
sashadev-sky Jun 19, 2019
69cf37c
doc updates
sashadev-sky Jun 19, 2019
981ff83
docs
sashadev-sky Jun 19, 2019
aa74c0f
refactor
sashadev-sky Jun 20, 2019
f27aa9e
README icon ref
sashadev-sky Jun 21, 2019
3214fe8
version bump
sashadev-sky Jun 21, 2019
cefad7d
README format
sashadev-sky Jun 25, 2019
f09f701
update polyfill comment
sashadev-sky Jun 25, 2019
c4199f5
Update Gruntfile compile command
sashadev-sky Jun 25, 2019
b491fe4
add svgo minifier
sashadev-sky Jun 25, 2019
d947493
update wikis
sashadev-sky Jun 26, 2019
763ad36
remove commented lines
sashadev-sky Jun 26, 2019
be4254c
Remove trailing commas
sashadev-sky Jun 26, 2019
faab4db
undo version bump
sashadev-sky Jun 27, 2019
0e8fb6a
Fix capitalization
sashadev-sky Jun 27, 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
190 changes: 107 additions & 83 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,112 +3,136 @@ module.exports = function(grunt) {
require('matchdep').filterDev('grunt-*').forEach(grunt.loadNpmTasks);

grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
pkg: grunt.file.readJSON("package.json"),

jshint: {
options: {
node: true,
browser: true,
esnext: true,
bitwise: true,
curly: true,
eqeqeq: true,
immed: true,
indent: 4,
latedef: true,
newcap: true,
noarg: true,
regexp: true,
undef: true,
unused: 'strict',
trailing: true,
smarttabs: true,
globals: {
L: false,
$: false,
LeafletToolbar: false,
warpWebGl: false,
EXIF: false,
alert: false,
jshint: {
options: {
node: true,
browser: true,
esnext: true,
bitwise: true,
curly: true,
eqeqeq: true,
immed: true,
indent: 4,
latedef: true,
newcap: true,
noarg: true,
regexp: true,
undef: true,
unused: "strict",
trailing: true,
smarttabs: true,
globals: {
L: false,
$: false,
LeafletToolbar: false,
warpWebGl: false,
EXIF: false,
alert: false,

// Mocha
// Mocha

describe: false,
it: false,
before: false,
after: false,
beforeEach: false,
afterEach: false,
chai: false,
expect: false,
sinon: false
}
},
source: {
src: [ 'src/**/*.js', 'package.json' ]
},
grunt: {
src: [ 'Gruntfile.js' ]
}
describe: false,
it: false,
before: false,
after: false,
beforeEach: false,
afterEach: false,
chai: false,
expect: false,
sinon: false
}
},
source: {
src: ["src/**/*.js", "package.json"]
},
grunt: {
src: ["Gruntfile.js"]
}
},

karma: {
development: {
configFile: 'test/karma.conf.js',
},
test: {
configFile: 'test/karma.conf.js',
}
karma: {
development: {
configFile: "test/karma.conf.js"
},
test: {
configFile: "test/karma.conf.js"
}
},

watch: {
options : {
livereload: true
svg_sprite: {
options: {
// Task-specific options go here.
},
dist: {
expand: true,
cwd: "assets/",
src: ["icons/*.svg"],
dest: "assets/icons/",
options: {
log: "info",
shape: {
dimension: {
maxWidth: 18,
maxHeight: 18
}
},
source: {
files: [
'src/**/*.js',
'test/**/*.js',
'Gruntfile.js'
],
tasks: [ 'build:js' ]
mode: {
symbol: {
sprite: "sprite.symbol.svg",
example: true
}
}
}
}
},

watch: {
options: {
livereload: true
},
source: {
files: ["src/**/*.js", "test/**/*.js", "Gruntfile.js"],
tasks: ["build:js"]
}
},

concat: {
dist: {
src: [
'src/util/*.js',
'src/DistortableImageOverlay.js',
'src/DistortableCollection.js',
'src/edit/getEXIFdata.js',
'src/edit/EditHandle.js',
'src/edit/LockHandle.js',
'src/edit/DistortHandle.js',
'src/edit/RotateScaleHandle.js',
'src/edit/RotateHandle.js',
'src/edit/ScaleHandle.js',
'src/edit/DistortableImage.EditToolbar.js',
'src/edit/DistortableImage.Edit.js',
'src/edit/tools/DistortableImage.Keymapper.js',
'src/edit/BoxSelectHandle.js'
],
dest: 'dist/leaflet.distortableimage.js',
}
concat: {
dist: {
src: [
"src/util/*.js",
"src/DistortableImageOverlay.js",
"src/DistortableCollection.js",
"src/edit/getEXIFdata.js",
"src/edit/EditHandle.js",
"src/edit/LockHandle.js",
"src/edit/DistortHandle.js",
"src/edit/RotateScaleHandle.js",
"src/edit/RotateHandle.js",
"src/edit/ScaleHandle.js",
"src/edit/DistortableImage.EditToolbar.js",
"src/edit/DistortableImage.Edit.js",
"src/edit/tools/DistortableImage.Keymapper.js",
"src/edit/BoxSelectHandle.js"
],
dest: "dist/leaflet.distortableimage.js"
}
}
});

/* Run tests once. */
grunt.registerTask('test', [ 'jshint', 'karma:test' ]);

/* Default (development): Watch files and lint, test, and build on change. */
grunt.registerTask('default', ['karma:development:start', 'watch']);
grunt.registerTask('default', ['svg_sprite', 'karma:development:start', 'watch',]);

grunt.registerTask('build', [
'jshint',
'karma:development:start',
'svg_sprite',
'coverage',
'concat:dist'
'concat:dist',
]);

grunt.registerTask('coverage', 'Custom commmand-line reporter for karma-coverage', function() {
Expand Down
68 changes: 33 additions & 35 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,17 +64,16 @@ img = L.distortableImageOverlay(
L.latLng(51.50,-0.14),
L.latLng(51.50,-0.10)
],
}
).addTo(map);
}).addTo(map);

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

Options available to pass during `L.DistortableImageOverlay` initialization:
- corners
- [corners](#corners)

- [selected](#selection)
- [selected](#selected)

- [mode](#mode)

Expand All @@ -84,6 +83,33 @@ Options available to pass during `L.DistortableImageOverlay` initialization:

- [suppressToolbar](#Suppress-Toolbar)

## Corners

The corners are stored as `L.latLng` objects
on the image, and can be accessed using our `getCorners()` method after the image is instantiated and added to the map.

Useful usage example:

```js
// instantiate, add to map and enable
img = L.distortableImageOverlay(...);
img.addTo(map);
L.DomEvent.on(img._image, 'load', img.editing.enable, img.editing);

// grab the initial corner positions
JSON.stringify(img.getCorners())
=> "[{"lat":51.52,"lng":-0.14},{"lat":51.52,"lng":-0.1},{"lat":51.5,"lng":-0.14},{"lat":51.5,"lng":-0.1}]"

// ...move the image around...

// check the new corner positions.
JSON.stringify(img.getCorners())
=> "[{"lat":51.50685099607552,"lng":-0.06058305501937867},{"lat":51.50685099607552,"lng":-0.02058595418930054},{"lat":51.486652692081925,"lng":-0.06058305501937867},{"lat":51.486652692081925,"lng":-0.02058595418930054}]"

// note there is an added level of precision after dragging the image for debugging purposes

```
We further added a `getCorner(idx)` method used the same way as its plural counterpart but with an index passed to it.

## Selected

Expand Down Expand Up @@ -158,8 +184,7 @@ img = L.distortableImageOverlay(
L.latLng(51.50,-0.10)
],
fullResolutionSrc: 'large.jpg'
}
).addTo(map);
}).addTo(map);

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

Expand Down Expand Up @@ -212,6 +237,8 @@ imageFeatureGroup.addLayer(img3);

- "EnableEXIF"

- "Restore"

- "Export"

- "Delete"
Expand All @@ -226,41 +253,12 @@ imageFeatureGroup.addLayer(img3);

For multiple images, the `ToggleOrder` action 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.


## Quick API Reference

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

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

## Corners

The corners are stored as `L.latLng` objects
on the image, and can be accessed using our `getCorners()` method after the image is instantiated and added to the map.

Useful usage example:

```js
// instantiate, add to map and enable
img = L.distortableImageOverlay(...);
img.addTo(map);
L.DomEvent.on(img._image, 'load', img.editing.enable, img.editing);

// grab the initial corner positions
JSON.stringify(img.getCorners())
=> "[{"lat":51.52,"lng":-0.14},{"lat":51.52,"lng":-0.1},{"lat":51.5,"lng":-0.14},{"lat":51.5,"lng":-0.1}]"

// ...move the image around...

// check the new corner positions.
JSON.stringify(img.getCorners())
=> "[{"lat":51.50685099607552,"lng":-0.06058305501937867},{"lat":51.50685099607552,"lng":-0.02058595418930054},{"lat":51.486652692081925,"lng":-0.06058305501937867},{"lat":51.486652692081925,"lng":-0.02058595418930054}]"

// note there is an added level of precision after dragging the image for debugging purposes

```
We further added a `getCorner(idx)` method used the same way as its plural counterpart but with an index passed to it.

## Contributing

1. This project uses `grunt` to do a lot of things, including concatenate source files from /src/ to /DistortableImageOverlay.js. But you may need to install grunt-cli: `npm install -g grunt-cli` first.
Expand Down
3 changes: 3 additions & 0 deletions assets/icons/border_clear.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions assets/icons/border_outer.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions assets/icons/crop_rotate.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions assets/icons/delete_forever.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions assets/icons/explore.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions assets/icons/flip_to_back.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions assets/icons/flip_to_front.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions assets/icons/get_app.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions assets/icons/lock.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions assets/icons/opacity-full.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions assets/icons/opacity.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions assets/icons/restore.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading