Skip to content

Commit

Permalink
Fix widget to calculate difference between layers (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
kandersolar authored Nov 12, 2024
1 parent 7c5ba93 commit 46c64b0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
6 changes: 4 additions & 2 deletions website/source/_static/map-widget-template.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div id="sidebar-##ID##" class="leaflet-sidebar collapsed" style="bottom:100px">
<div id="sidebar-##ID##" class="leaflet-sidebar collapsed" style="bottom:300px">
<!-- Nav tabs -->
<div class="leaflet-sidebar-tabs">
<ul role="tablist"> <!-- top aligned tabs -->
Expand All @@ -14,10 +14,12 @@ <h1 class="leaflet-sidebar-header" style="color: #fff">
<div class="leaflet-sidebar-close"><i class="fa fa-caret-left"></i></div>
</h1>

<p>Calculate and show the difference between two layers:
<p>Calculate a new layer from the difference between two layers:</p>

<p>Layer 1: <select id="select-layer1-##ID##"></select></p>
<p>Layer 2: <select id="select-layer2-##ID##"></select></p>

<p>The calculated layer is available in the layer dropdown widget.</p>
</div>
</div>
</div>
Expand Down
18 changes: 12 additions & 6 deletions website/source/_static/map-widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ L.Control.Layers.include({
});


function rasterToLayer(georaster, metadata, options){
function rasterToLayer(georaster, options){
// console.log(chroma.brewer);

// default values, to be optionally overridden by configuration in RST
Expand Down Expand Up @@ -76,7 +76,7 @@ function addLayer(filename, map, layerControl, name, order, options){
});
});

var layer = rasterToLayer(georaster, metadata, options);
var layer = rasterToLayer(georaster, options);
layer.options.order = order;
layer.options.filename = filename;
layer.options.metadata = metadata;
Expand Down Expand Up @@ -249,17 +249,23 @@ function init(id, options){
}
}
}
var georaster1 = getGeoraster(document.getElementById("select-layer1-" + id).value);
var georaster2 = getGeoraster(document.getElementById("select-layer2-" + id).value);
var name1 = document.getElementById("select-layer1-" + id).value;
var name2 = document.getElementById("select-layer2-" + id).value;
var georaster1 = getGeoraster(name1);
var georaster2 = getGeoraster(name2);
var georasterDifference = await doArithmetic("a - b", georaster1, georaster2);

if(calculationLayer !== null){
layerControl.removeLayer(calculationLayer);
map.removeLayer(calculationLayer);
}
// TODO: metadata for calculated layer?
calculationLayer = rasterToLayer(georasterDifference, {});
calculationLayer.addTo(map);
calculationLayer = rasterToLayer(georasterDifference, options);
calculationLayer.options.metadata = {
DESCRIPTION: "Calculated from layers '" + name1 + "' and '" + name2 + "'.",
CREATION_DATE: "N/A",
};
// calculationLayer.addTo(map);
layerControl.addBaseLayer(calculationLayer, "Calculated");
}
document.getElementById("select-layer1-" + id).onchange = onSelectChange;
Expand Down

0 comments on commit 46c64b0

Please sign in to comment.