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 28 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
29 changes: 29 additions & 0 deletions dist/leaflet.distortableimage.js

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

26 changes: 25 additions & 1 deletion src/DistortableCollection.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,11 +218,35 @@ L.DistortableCollection = L.FeatureGroup.extend({

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

var jsonImages = json.images;
savetoLocalStorage(jsonImages);
return json;
},
});

L.distortableCollection = function(id, options) {
return new L.DistortableCollection(id, options);
};

function savetoLocalStorage(jsonImages) {
var result = jsonImages.map(img => ({value: img.nodes}));
var getImages = localStorage.setItem('locations', JSON.stringify(result));
downloadFromLocalStorage(getImages);
}

function downloadFromLocalStorage(getImages) {
var obj = localStorage.getItem('locations');
Copy link
Member

@jywarren jywarren Jan 3, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Per our conversation, after generateExportJson() is changed, we can just do this!

Suggested change
var obj = localStorage.getItem('locations');
var obj = generateExportJson(true);

var data = 'text/json;charset=utf-8,' + encodeURIComponent(JSON.stringify(obj, prettyJson));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From here down is what you want. Let's just connect it to a button! And we can probably skip the prettyJson below - could do it later with a library!

var a = document.createElement('a');
a.href = 'data:' + data;
a.download = 'mapknitter.json';
// a.innerHTML = 'download JSON';
// console.log(a);
a.click();
}

function prettyJson(key, value) {
// return value.replace(/[^\w\s]/gi, '\n');
// (/\n/g, "\r\n")
return value.replace(/\n/g, '\\\\n').replace(/\r/g, '\\\\r').replace(/\t/g, '\\\\t');
}