Skip to content

Commit

Permalink
issue/hitide-ui-44: cleaned up footprint/preview display code
Browse files Browse the repository at this point in the history
  • Loading branch information
jbyrne committed Mar 7, 2024
1 parent 63ebb3f commit bc42074
Showing 1 changed file with 23 additions and 42 deletions.
65 changes: 23 additions & 42 deletions src/jpl/dijit/GranulesController.js
Original file line number Diff line number Diff line change
Expand Up @@ -746,16 +746,6 @@ define([
postGranulesFetch: function(response) {
this.availableGranules = response.hits;
var _context = this;
var currentlyVisibleFootprints = {}
var currentlyVisiblePreviews = {}

for (var i=0; i<this.stateStore.data.length; i++) {
var currentVisibleGranule = this.stateStore.data[i]
if (currentVisibleGranule.footprint) currentlyVisibleFootprints[currentVisibleGranule["Granule-Name"]] = currentVisibleGranule
if (currentVisibleGranule.preview) currentlyVisiblePreviews[currentVisibleGranule["Granule-Name"]] = currentVisibleGranule
}
var footprintKeys = Object.keys(currentlyVisibleFootprints)
var previewKeys = Object.keys(currentlyVisiblePreviews)

response.items.map(function(x) {
GranuleMetadata.convertFootprintAndImageFromCMR(x);
Expand All @@ -773,39 +763,22 @@ define([
x["Granule-StopTime"] = moment.utc(x["umm"]["TemporalExtent"]["RangeDateTime"]["EndingDateTime"]);

x["source"] = "cmr";

// TODO
// // if Granule not in list of currently visible footprints and preview, remove that footprint/preview from display on the map
// var granuleName = x["Granule-Name"]
// if (granuleName) {
// if (footprintKeys.length > 0) {
// if (footprintKeys.includes(granuleName)) {
// x.footprint = true
// // remove object from list
// delete currentlyVisibleFootprints[x["Granule-Name"]]
// } else {
// x.footprint = false
// }
// }
// if (previewKeys.length > 0) {
// if (previewKeys.includes(granuleName)) {
// x.preview = true
// delete currentlyVisiblePreviews[x["Granule-Name"]]
// } else {
// x.preview = false
// }
// }
// }

_context.gridStore.add(x)
});

// remove footprints and previews on the map that are not being shown in the granule table
var objectsToRemove = Object.values(currentlyVisibleFootprints).concat(Object.values(currentlyVisiblePreviews))
if (objectsToRemove.length > 0) {
_context.toggleFootprints(objectsToRemove, false)
_context.togglePreviews(objectsToRemove, false)
// remove footprints and preview from displaying on the map if they are not in the current page of the granule table
var currentlyVisibleFootprints = {}
var currentlyVisiblePreviews = {}

for (var i=0; i<this.stateStore.data.length; i++) {
var currentVisibleGranule = this.stateStore.data[i]
if (currentVisibleGranule.footprint) currentlyVisibleFootprints[currentVisibleGranule["Granule-Name"]] = currentVisibleGranule
if (currentVisibleGranule.preview) currentlyVisiblePreviews[currentVisibleGranule["Granule-Name"]] = currentVisibleGranule
}

_context.toggleFootprints(Object.values(currentlyVisibleFootprints), false, true)
_context.togglePreviews(Object.values(currentlyVisiblePreviews), false, true)

this.granulesInGrid = this.gridStore.query().length;

Expand Down Expand Up @@ -946,15 +919,19 @@ define([
}
},

toggleFootprints: function(granuleObjs, active) {
toggleFootprints: function(granuleObjs, active, inStoreAlready) {
// if obj already in grid store, update and don't put
inStoreAlready = inStoreAlready || false
for (var i = 0; i < granuleObjs.length; i++) {
// Update store
var obj = granuleObjs[i];

if (obj.footprint != active) {
if(obj["Granule-Footprint"]){
obj.footprint = active;
this.gridStore.put(obj);
if (!inStoreAlready) {
this.gridStore.put(obj);
}
this.updateStateStoreObj(obj);

// Update fp
Expand All @@ -965,14 +942,18 @@ define([
}
},

togglePreviews: function(granuleObjs, active) {
togglePreviews: function(granuleObjs, active, inStoreAlready) {
// if obj already in grid store, update and don't put
inStoreAlready = inStoreAlready || false
for (var i = 0; i < granuleObjs.length; i++) {
// Update store
var obj = granuleObjs[i];
if (obj.preview != active) {
if(obj.has_image){
obj.preview = active;
this.gridStore.put(obj);
if (!inStoreAlready) {
this.gridStore.put(obj);
}
this.updateStateStoreObj(obj);

// Update preview
Expand Down

0 comments on commit bc42074

Please sign in to comment.