Commit 9c10c90a authored by Eric Duminil's avatar Eric Duminil
Browse files

Disable or enable button.

No related merge requests found
Showing with 17 additions and 5 deletions
+17 -5
var regionChooser = (function(){ var regionChooser = (function(){
//TODO: Somehow split in classes. This file is getting too big and mixed
var publicScope = {}; var publicScope = {};
var fromJavaFX = navigator.userAgent.indexOf('JavaFX') !== -1; var fromJavaFX = navigator.userAgent.indexOf('JavaFX') !== -1;
var dataPanel = $('#dataPanel'); var dataPanel = $('#dataPanel');
...@@ -162,7 +163,7 @@ var regionChooser = (function(){ ...@@ -162,7 +163,7 @@ var regionChooser = (function(){
intersections.addFeature(intersection); intersections.addFeature(intersection);
var link = '<li>' var link = '<li>'
// TODO: If possible, highlight the corresponding polygon when hovering above a name. // TODO: If possible, highlight the corresponding polygon when hovering above a name.
link += '<input type="checkbox" id="citygml_' + feature.getId() + '" class="select_citygml"><label for="citygml_' + feature.getId() + '">' + feature['name'] + '</label>'; link += '<input type="checkbox" id="citygml_' + feature.getId() + '" class="select_citygml" onclick="regionChooser.canDownload();"><label for="citygml_' + feature.getId() + '">' + feature['name'] + '</label>';
link += " (" + citygml_percentage + "%"; link += " (" + citygml_percentage + "%";
if (sketch_percentage == 100) { if (sketch_percentage == 100) {
...@@ -171,6 +172,17 @@ var regionChooser = (function(){ ...@@ -171,6 +172,17 @@ var regionChooser = (function(){
dataPanel.append(link + ")\n"); dataPanel.append(link + ")\n");
} }
publicScope.canDownload = function(){
var count = 0;
console.log("...");
document.querySelectorAll("input.select_citygml").forEach(c => {
if (c.checked){
count += 1;
}
});
document.getElementById("download").disabled = (count == 0);
}
function findIntersection(feature, polygon) { function findIntersection(feature, polygon) {
try { try {
return turf.intersect(polygon, feature["geoJSON"]); return turf.intersect(polygon, feature["geoJSON"]);
...@@ -211,8 +223,6 @@ var regionChooser = (function(){ ...@@ -211,8 +223,6 @@ var regionChooser = (function(){
} }
publicScope.downloadRegionFromCityGMLs = function(checkbox_ids) { publicScope.downloadRegionFromCityGMLs = function(checkbox_ids) {
// TODO: Disable all links
// TODO: DRY
var features = checkbox_ids.map(checkbox_id => { var features = checkbox_ids.map(checkbox_id => {
var i = Number(checkbox_id.replace("citygml_", "")); var i = Number(checkbox_id.replace("citygml_", ""));
return kml_source.getFeatureById(i); return kml_source.getFeatureById(i);
...@@ -238,6 +248,7 @@ var regionChooser = (function(){ ...@@ -238,6 +248,7 @@ var regionChooser = (function(){
var time = end - start; var time = end - start;
console.log('Download Execution time: ' + (time / 1000).toFixed(3) + 's'); console.log('Download Execution time: ' + (time / 1000).toFixed(3) + 's');
setTimeout(function() { setTimeout(function() {
document.getElementById("download").disabled = false;
document.documentElement.className = ''; // Stop waiting document.documentElement.className = ''; // Stop waiting
}, 100); }, 100);
} else { } else {
...@@ -267,8 +278,7 @@ var regionChooser = (function(){ ...@@ -267,8 +278,7 @@ var regionChooser = (function(){
dataPanel.append(wgs84_coords + "<br/>\n"); dataPanel.append(wgs84_coords + "<br/>\n");
} }
dataPanel.append("<h3 class='clean'>Area : " + (area / 10000).toFixed(1) + " ha\n"); dataPanel.append("<h3 class='clean'>Area : " + (area / 10000).toFixed(1) + " ha\n");
//TODO: Hide button if empty dataPanel.append('<button type="button" onclick="regionChooser.downloadFromSelectedCityGMLs()" id="download" style="visibility:hidden" disabled>Download Region</button><br/>\n');
dataPanel.append('<button type="button" onclick="regionChooser.downloadFromSelectedCityGMLs()" id="download" style="visibility:hidden">Download Region</button><br/>\n');
dataPanel.append('<a href="#" onclick="regionChooser.checkCityGMLS(true);">(Select All)</a>'); dataPanel.append('<a href="#" onclick="regionChooser.checkCityGMLS(true);">(Select All)</a>');
dataPanel.append('<a href="#" onclick="regionChooser.checkCityGMLS(false);">(Select None)</a>'); dataPanel.append('<a href="#" onclick="regionChooser.checkCityGMLS(false);">(Select None)</a>');
dataPanel.append('<br/>\n'); dataPanel.append('<br/>\n');
...@@ -363,12 +373,14 @@ var regionChooser = (function(){ ...@@ -363,12 +373,14 @@ var regionChooser = (function(){
if (checkedBoxes.length === 0){ if (checkedBoxes.length === 0){
console.log("You should select at least one citygml, though."); console.log("You should select at least one citygml, though.");
} else{ } else{
document.getElementById("download").disabled = true;
publicScope.downloadRegionFromCityGMLs(checkedBoxes.map(c => c.id)); publicScope.downloadRegionFromCityGMLs(checkedBoxes.map(c => c.id));
} }
} }
publicScope.checkCityGMLS = function(allOrNone) { publicScope.checkCityGMLS = function(allOrNone) {
document.querySelectorAll("input.select_citygml").forEach(c => c.checked = allOrNone); document.querySelectorAll("input.select_citygml").forEach(c => c.checked = allOrNone);
publicScope.canDownload();
} }
publicScope.selectRepository = function() { publicScope.selectRepository = function() {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment