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

Change downloaded JSON to have "collection" key instead of "images" #1349

Open
jywarren opened this issue Feb 7, 2023 · 6 comments
Open

Comments

@jywarren
Copy link
Member

jywarren commented Feb 7, 2023

const jsonImages = map.imgGroup.generateExportJson(true).images;

// download JSON
saveMap.addEventListener('click', () => {
  const jsonImages = {
    collection: map.imgGroup.generateExportJson(true).images
  }
@jywarren
Copy link
Member Author

jywarren commented Feb 7, 2023

This will be compatible with changes in #1345, for a full download/upload lifecycle!

@jywarren
Copy link
Member Author

jywarren commented Feb 7, 2023

The changes would also occur in this function:

generateExportJson: function generateExportJson() {
var allImages = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
var json = {};
json.images = [];
this.eachLayer(function (layer) {
if (allImages || this.isCollected(layer)) {
var sections = layer._image.src.split('/');
var filename = sections[sections.length - 1];
var zc = layer.getCorners();
var 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
}, {
lat: zc[2].lat,
lon: zc[2].lng
}];
json.images.push({
id: layer._leaflet_id,
src: layer._image.src,
width: layer._image.width,
height: layer._image.height,
image_file_name: filename,
nodes: corners,
cm_per_pixel: L.ImageUtil.getCmPerPixel(layer)
});
}
}, this);
json.images = json.images.reverse();
json.avg_cm_per_pixel = this._getAvgCmPerPixel(json.images);
return json;
}
});

@segun-codes
Copy link
Collaborator

segun-codes commented Feb 8, 2023

const jsonImages = map.imgGroup.generateExportJson(true).images;

// download JSON
saveMap.addEventListener('click', () => {
  const jsonImages = {
    collection: map.imgGroup.generateExportJson(true).images
  }

The changes suggested here have been implemented through PR #1345. Key changed from "images" to "collection."

@segun-codes
Copy link
Collaborator

segun-codes commented Feb 8, 2023

The changes would also occur in this function:

generateExportJson: function generateExportJson() {
var allImages = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
var json = {};
json.images = [];
this.eachLayer(function (layer) {
if (allImages || this.isCollected(layer)) {
var sections = layer._image.src.split('/');
var filename = sections[sections.length - 1];
var zc = layer.getCorners();
var 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
}, {
lat: zc[2].lat,
lon: zc[2].lng
}];
json.images.push({
id: layer._leaflet_id,
src: layer._image.src,
width: layer._image.width,
height: layer._image.height,
image_file_name: filename,
nodes: corners,
cm_per_pixel: L.ImageUtil.getCmPerPixel(layer)
});
}
}, this);
json.images = json.images.reverse();
json.avg_cm_per_pixel = this._getAvgCmPerPixel(json.images);
return json;
}
});

Hi @jywarren, my understanding is that we agreed not to alter this code but repackage the return json into a format where key images is changed to "collection" within /example/archive.js. For this purpose, I had created such adapter in archive.js (see #1345) without altering the generateExportJson() in this light. Or is there a change of plan now?

@jywarren
Copy link
Member Author

jywarren commented Feb 8, 2023

No, that's fine, that's what we decided for that PR! This issue is for if we decide later to completely rework things. I just think that if we do, it should be done separately from the purpose of the PR, and we shouldn't try to do them both together.

@jywarren
Copy link
Member Author

This is also completed then, i think! isn't that right @segun-codes?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants