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

Download json file of saved positions #1237

Merged
merged 37 commits into from
Jan 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
87f5076
detect key from longer URL
vanithaak Oct 16, 2022
f6225c3
Merge branch 'main' of https://github.com/vanithaak/Leaflet.Distortab…
vanithaak Oct 17, 2022
4976617
Merge branch 'publiclab:main' into main
vanithaak Oct 19, 2022
c71fc06
Merge branch 'publiclab:main' into main
vanithaak Oct 19, 2022
8db3a8e
Merge branch 'publiclab:main' into main
vanithaak Oct 19, 2022
1dca9e3
Merge branch 'publiclab:main' into main
vanithaak Oct 20, 2022
7cbcb80
fixes
vanithaak Oct 20, 2022
24df784
Merge branch 'main' of https://github.com/vanithaak/Leaflet.Distortab…
vanithaak Oct 20, 2022
47f1aa2
Merge branch 'publiclab:main' into main
vanithaak Oct 21, 2022
07c7e94
Merge branch 'publiclab:main' into main
vanithaak Oct 21, 2022
773c2fe
Merge branch 'publiclab:main' into main
vanithaak Oct 22, 2022
13c6402
Merge branch 'publiclab:main' into main
vanithaak Oct 23, 2022
67b2862
updates
vanithaak Oct 23, 2022
8407d0f
save map coordinates in local storage
vanithaak Oct 22, 2022
4a1339a
error fixes
vanithaak Oct 22, 2022
a03c45c
made a new method to save map in localStorage
vanithaak Oct 23, 2022
e409e69
error fixes
vanithaak Oct 23, 2022
415f0da
error fixes X2
vanithaak Oct 23, 2022
44d3a4b
error fixes X3
vanithaak Oct 23, 2022
f9e8212
Merge branch 'main' into localStorage
vanithaak Oct 25, 2022
eb09b9e
Merge branch 'main' into localStorage
vanithaak Oct 25, 2022
57613e6
removed overwriting of coordinates
vanithaak Oct 25, 2022
5f3e111
removed overwriting of coordinates
vanithaak Oct 25, 2022
a798be5
error fixes
vanithaak Oct 25, 2022
8e680cb
allowing download of the positions as a JSON file: mapknitter.json
vanithaak Oct 25, 2022
e3b8b1f
error fixes
vanithaak Oct 25, 2022
385ea0d
Merge branch 'main' into downloadJSON
vanithaak Oct 31, 2022
b9147e1
Merge branch 'main' into downloadJSON
vanithaak Nov 3, 2022
c3946d8
Merge branch 'main' of https://github.com/publiclab/Leaflet.Distortab…
7malikk Jan 19, 2023
3d8a625
Merge branch 'main' of https://github.com/publiclab/Leaflet.Distortab…
7malikk Jan 20, 2023
55c57e1
downloadJSON
7malikk Jan 24, 2023
3c21e05
Merge branch 'main' into downloadJSON
7malikk Jan 24, 2023
b898437
hot fix
7malikk Jan 24, 2023
d1d3478
Merge branch 'downloadJSON' of https://github.com/vanithaak/Leaflet.D…
7malikk Jan 24, 2023
fd381b2
final fix
7malikk Jan 24, 2023
54f35af
refactor downloadJSON
7malikk Jan 25, 2023
3d6ea86
Merge branch 'main' into downloadJSON
jywarren Jan 26, 2023
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
18 changes: 16 additions & 2 deletions dist/leaflet.distortableimage.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 7 additions & 4 deletions examples/archive.html
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,11 @@ <h2 class="modal-title">Welcome to MapKnitter Lite</h2>

<div class="offcanvas offcanvas-end" data-bs-backdrop="false" data-bs-keyboard="false" tabindex="1" id="offcanvasRight" aria-labelledby="offcanvasRightLabel">
<div class="offcanvas-header">
<h3 id="offcanvasRightLabel">Images</h3>
<button type="button" id="restoreWelcomeModalBtn" class="btn btn-primary btn-sm" data-bs-dismiss="offcanvas" aria-label="Close">Get Image</button>
<button type="button" class="btn btn-primary btn-sm" data-bs-dismiss="offcanvas" aria-label="Close">View Map</button>
<button type="button" id="restoreWelcomeModalBtn" class="btn btn-primary btn-md" data-bs-dismiss="offcanvas" aria-label="Close" title="Import images from collection URL">Import</button>
<button id="saveMap" type="button" class="btn btn-sm" aria-label="Save map" title="Save map in JSON format" >
<i class="fa fa-save fa-" style="font-size:24px" ></i>
</button>
<button type="button" class="btn-close" data-bs-dismiss="offcanvas" aria-label="Close" title="Close Sidebar" ></button>
</div>
<hr>
<div class="offcanvas-body">
Expand All @@ -76,10 +78,11 @@ <h3 id="offcanvasRightLabel">Images</h3>
</div>
<hr>
<div class="offcanvas-footer d-flex justify-content-evenly align-items-center">
<h3 id="offcanvasRightLabel">Images</h3>
<button title="Previous" id="prevBtn" style="all: unset; cursor: pointer;">
<i class=" fa fa-regular fa-chevron-left"></i>
</button>
<p style="margin: 5px;" id="range">1-50 of 200</p>
<p style="margin: 5px;" id="range">0-0 of 0</p>
<button title="Next" id="nextBtn" style="all: unset; cursor: pointer;">
<i class=" fa fa-regular fa-chevron-right"></i>
</button>
Expand Down
18 changes: 16 additions & 2 deletions examples/js/archive.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,8 @@ tileMap.addEventListener('click', (event) => {
});

function getImageName(imageURL) {
startIndex = imageURL.lastIndexOf('/') + 1;
endIndex = imageURL.lastIndexOf('.');
const startIndex = imageURL.lastIndexOf('/') + 1;
const endIndex = imageURL.lastIndexOf('.');
const imageName = imageURL.substring(startIndex, endIndex);

return imageName;
Expand All @@ -190,3 +190,17 @@ document.addEventListener('click', (event) => {
map.imgGroup.addLayer(image);
}
});

// download JSON
saveMap.addEventListener('click', () => {
const jsonImages = map.imgGroup.generateExportJson(true).images;
// a check to prevent download of empty file
if (jsonImages.length) {
const encodedFile = 'text/json;charset=utf-8,' + encodeURIComponent(JSON.stringify(jsonImages));
const a = document.createElement('a');
a.href = 'data:' + encodedFile;
const fileName = prompt('Use this file to recover your map’s saved state. Enter filename:');
a.download = fileName ? fileName + '.json' : 'MapknitterLite.json';
a.click();
}
})
5 changes: 2 additions & 3 deletions src/DistortableCollection.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,12 +212,12 @@ L.DistortableCollection = L.FeatureGroup.extend({
return false;
},

generateExportJson() {
generateExportJson(allImages = false) {
const json = {};
json.images = [];

this.eachLayer(function(layer) {
if (this.isCollected(layer)) {
if (allImages || this.isCollected(layer)) {
const sections = layer._image.src.split('/');
const filename = sections[sections.length-1];
const zc = layer.getCorners();
Expand All @@ -241,7 +241,6 @@ L.DistortableCollection = L.FeatureGroup.extend({

json.images = json.images.reverse();
json.avg_cm_per_pixel = this._getAvgCmPerPixel(json.images);

return json;
},
});
Expand Down
1 change: 0 additions & 1 deletion src/edit/DistortableCollection.Edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,6 @@ L.DistortableCollection.Edit = L.Handler.extend({
const map = group._map;

if (group.options.suppressToolbar || this.toolbar) { return; }

this.toolbar = L.distortableImage.controlBar({
actions: this.editActions,
position: 'topleft',
Expand Down