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

save map coordinates in localStorage #1220

Closed
wants to merge 25 commits into from
Closed
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
87f5076
detect key from longer URL
vanithaak Oct 16, 2022
049a0f4
Merge branch 'main' into vanithak
vanithaak Oct 16, 2022
9b89862
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
2ea3e66
Merge branch 'main' into vanithak
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
3abe3f4
fto
vanithaak Oct 20, 2022
05d7f31
Merge branch 'main' into vanithak1
vanithaak Oct 20, 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
5b53274
fixes
vanithaak Oct 20, 2022
9cbefd9
fixes
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
b553cca
Merge branch 'main' into setscale
vanithaak Oct 22, 2022
9c701b5
save map coordinates in local storage
vanithaak Oct 22, 2022
c0f9356
error fixes
vanithaak Oct 22, 2022
0ae3356
updating archive.html
vanithaak Oct 23, 2022
7d1732a
updating archive.html x2
vanithaak Oct 23, 2022
1acdd38
Merge branch 'main' into setscale
vanithaak Oct 23, 2022
dfb8e16
Merge branch 'main' into setscale
vanithaak Oct 25, 2022
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
15 changes: 9 additions & 6 deletions dist/leaflet.distortableimage.js

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

4 changes: 3 additions & 1 deletion examples/archive.html
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,9 @@ <h3 id="offcanvasRightLabel">Images</h3>
form.addEventListener('submit', (event) => {
event.preventDefault();
const url = input.value.replace('details', 'metadata');
let fetchedFrom
let splitUrl = url.split('/');
Copy link
Member

Choose a reason for hiding this comment

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

Hi, it looks like you may be mixing code from separate PRs here. This can happen if you work from your main branch and don't separate work into different branches. Could you reset it so these unrelated changes are not included in the PR?

You could try this -- https://stackoverflow.com/questions/7147270/hard-reset-of-a-single-file or just copy the version from the publiclab main branch (https://github.com/publiclab/Leaflet.DistortableImage) over your own and add it so there are no changes shown here. Let me know if you need help!

let detectKey = splitUrl[splitUrl.length - 2];
console.log(detectKey);
axios.get(url)
.then((response) => {
if (response.data.files && response.data.files.length != 0) {
Expand Down
14 changes: 7 additions & 7 deletions src/DistortableCollection.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ L.DistortableCollection = L.FeatureGroup.extend({
layer._dragStartPoints = {};
layer.deselect();
for (i = 0; i < 4; i++) {
let c = layer.getCorner(i);
const c = layer.getCorner(i);
layer._dragStartPoints[i] = map.latLngToLayerPoint(c);
}
});
Expand Down Expand Up @@ -174,7 +174,7 @@ L.DistortableCollection = L.FeatureGroup.extend({
let i;

layersToMove.forEach((layer) => {
let movedPoints = {};
const movedPoints = {};
for (i = 0; i < 4; i++) {
movedPoints[i] = p.transform(layer._dragStartPoints[i]);
}
Expand All @@ -195,10 +195,10 @@ L.DistortableCollection = L.FeatureGroup.extend({

this.eachLayer(function(layer) {
if (this.isCollected(layer)) {
let sections = layer._image.src.split('/');
let filename = sections[sections.length-1];
let zc = layer.getCorners();
let corners = [
const sections = layer._image.src.split('/');
const filename = sections[sections.length-1];
const zc = layer.getCorners();
const corners = [
{lat: zc[0].lat, lon: zc[0].lng},
{lat: zc[1].lat, lon: zc[1].lng},
{lat: zc[3].lat, lon: zc[3].lng},
Expand All @@ -218,7 +218,7 @@ L.DistortableCollection = L.FeatureGroup.extend({

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

json.images.map(each=> localStorage.setItem('locations', JSON.stringify(each.nodes)));
Copy link
Member

Choose a reason for hiding this comment

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

Here is your code, i see! Actually I wonder if this code should be outside the generateExportJson() method. Should there be a method like collection.saveToLocalStorage() instead? What do you think?

return json;
},
});
Expand Down
18 changes: 9 additions & 9 deletions src/DistortableImageOverlay.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ L.DistortableImageOverlay = L.ImageOverlay.extend({
this._initImageDimensions();

if (this.options.rotation) {
const units = this.options.rotation.deg ? 'deg' : 'rad';
const units = this.options.rotation.deg >= 0 ? 'deg' : 'rad';
this.setAngle(this.options.rotation[units], units);
} else {
this.rotation = {deg: 0, rad: 0};
Expand Down Expand Up @@ -234,7 +234,7 @@ L.DistortableImageOverlay = L.ImageOverlay.extend({
let i = 0;

// this is to fix https://github.com/publiclab/Leaflet.DistortableImage/issues/402
for (let k in latlngObj) {
for (const k in latlngObj) {
if (this._cornerExceedsMapLats(zoom, latlngObj[k], map)) {
// calling reset / update w/ the same corners bc it prevents a marker flicker for rotate
this.setBounds(L.latLngBounds(this.getCorners()));
Expand All @@ -243,7 +243,7 @@ L.DistortableImageOverlay = L.ImageOverlay.extend({
}
}

for (let k in latlngObj) {
for (const k in latlngObj) {
this._corners[i] = latlngObj[k];
i += 1;
}
Expand All @@ -266,7 +266,7 @@ L.DistortableImageOverlay = L.ImageOverlay.extend({
const edit = this.editing;
let i = 0;

for (let k in pointsObj) {
for (const k in pointsObj) {
const corner = map.layerPointToLatLng(pointsObj[k]);

if (this._cornerExceedsMapLats(zoom, corner, map)) {
Expand All @@ -277,7 +277,7 @@ L.DistortableImageOverlay = L.ImageOverlay.extend({
}
}

for (let k in pointsObj) {
for (const k in pointsObj) {
this._corners[i] = map.layerPointToLatLng(pointsObj[k]);
i += 1;
}
Expand All @@ -299,7 +299,7 @@ L.DistortableImageOverlay = L.ImageOverlay.extend({
const center = map.project(this.getCenter());
let i;
let p;
let scaledCorners = {};
const scaledCorners = {};

if (scale === 0) { return; }

Expand Down Expand Up @@ -356,7 +356,7 @@ L.DistortableImageOverlay = L.ImageOverlay.extend({
rotateBy(angle, unit = 'deg') {
const map = this._map;
const center = map.project(this.getCenter());
let corners = {};
const corners = {};
let i;
let p;
let q;
Expand All @@ -383,7 +383,7 @@ L.DistortableImageOverlay = L.ImageOverlay.extend({
const map = this._map;
let i;
let p;
let transCorners = {};
const transCorners = {};
const delta = map.project(formerPoint).subtract(map.project(newPoint));

for (i = 0; i < 4; i++) {
Expand Down Expand Up @@ -507,7 +507,7 @@ L.DistortableImageOverlay = L.ImageOverlay.extend({
const offset = latLngToCartesian(this.getCorner(0));
const w = this.getElement().offsetWidth || 500;
const h = this.getElement().offsetHeight || 375;
let c = [];
const c = [];
let j;
/* Convert corners to container points (i.e. cartesian coordinates). */
for (j = 0; j < 4; j++) {
Expand Down
Loading