Commit b6d2a5d8 authored by Eric Duminil's avatar Eric Duminil
Browse files

Trying many stuff. Checklist instead of single link.

parent eb1c4870
var regionChooser = (function(){ var regionChooser = (function(){
var publicScope = {}; var publicScope = {};
var fromJavaFX = navigator.userAgent.indexOf('JavaFX') !== -1; var fromJavaFX = navigator.userAgent.indexOf('JavaFX') !== -1;
//NOTE: Could do without jQuery
var dataPanel = $('#dataPanel'); var dataPanel = $('#dataPanel');
var wgs84Sphere = new ol.Sphere(6378137); var wgs84Sphere = new ol.Sphere(6378137);
var gmlId = 0; var gmlId = 0;
...@@ -9,21 +10,21 @@ var regionChooser = (function(){ ...@@ -9,21 +10,21 @@ var regionChooser = (function(){
$("html").addClass("wait"); $("html").addClass("wait");
} }
// Hash function // Hash function. For testing purposes in browser (no Feature ID is available)
const cyrb53 = (str, seed = 0) => { const cyrb53 = (str, seed = 0) => {
let h1 = 0xdeadbeef ^ seed, let h1 = 0xdeadbeef ^ seed,
h2 = 0x41c6ce57 ^ seed; h2 = 0x41c6ce57 ^ seed;
for (let i = 0, ch; i < str.length; i++) { for (let i = 0, ch; i < str.length; i++) {
ch = str.charCodeAt(i); ch = str.charCodeAt(i);
h1 = Math.imul(h1 ^ ch, 2654435761); h1 = Math.imul(h1 ^ ch, 2654435761);
h2 = Math.imul(h2 ^ ch, 1597334677); h2 = Math.imul(h2 ^ ch, 1597334677);
} }
h1 = Math.imul(h1 ^ (h1 >>> 16), 2246822507) ^ Math.imul(h2 ^ (h2 >>> 13), 3266489909); h1 = Math.imul(h1 ^ (h1 >>> 16), 2246822507) ^ Math.imul(h2 ^ (h2 >>> 13), 3266489909);
h2 = Math.imul(h2 ^ (h2 >>> 16), 2246822507) ^ Math.imul(h1 ^ (h1 >>> 13), 3266489909); h2 = Math.imul(h2 ^ (h2 >>> 16), 2246822507) ^ Math.imul(h1 ^ (h1 >>> 13), 3266489909);
return 4294967296 * (2097151 & h2) + (h1 >>> 0); return 4294967296 * (2097151 & h2) + (h1 >>> 0);
}; };
var osm_layer = new ol.layer.Tile({ var osm_layer = new ol.layer.Tile({
source: new ol.source.OSM() source: new ol.source.OSM()
...@@ -173,12 +174,13 @@ const cyrb53 = (str, seed = 0) => { ...@@ -173,12 +174,13 @@ const cyrb53 = (str, seed = 0) => {
// TODO: Add checkbox + label + // TODO: Add checkbox + label +
// TODO: Add submit. // TODO: Add submit.
// TODO: If possible, highlight the corresponding polygon when hovering above a name. // TODO: If possible, highlight the corresponding polygon when hovering above a name.
console.log("Feature name : "+ feature["name"]);
console.log("Feature ID : "+ feature.getId());
if (fromJavaFX) { if (fromJavaFX) {
link += "<a href=\"#\" onclick=\"regionChooser.downloadRegionFrom" + feature["source"] + "(" + feature.getId() link += '<input type="checkbox" id="check_' + feature.getId() + '" class="select_citygml"><label for="check_' + feature.getId() + '">' + feature['name'] + '</label>';
+ ");return false;\">" + feature["name"] + "</a>";
} else { } else {
h = cyrb53(feature['name']); h = cyrb53(feature['name']);
link += '<input type="checkbox" id="check' + h+ '"><label for="check' + h + '">' + feature['name'] + '</label>'; link += '<input type="checkbox" id="check_' + h+ '" class="select_citygml"><label for="check_' + h + '">' + feature['name'] + '</label>';
} }
link += " (" + citygml_percentage + "%"; link += " (" + citygml_percentage + "%";
...@@ -201,9 +203,10 @@ const cyrb53 = (str, seed = 0) => { ...@@ -201,9 +203,10 @@ const cyrb53 = (str, seed = 0) => {
var polygonArea = sketch.getGeometry().getArea(); var polygonArea = sketch.getGeometry().getArea();
var intersection_found = false; var intersection_found = false;
intersections.clear(); intersections.clear();
//NOTE: getFeatures seems to not be sorted anymore. :-/
features_by_project = groupBy(kml_source.getFeatures(), "project"); features_by_project = groupBy(kml_source.getFeatures(), "project");
Object.keys(features_by_project).sort().forEach(function(project) { Object.keys(features_by_project).forEach(function(project) {
features = features_by_project[project]; features = features_by_project[project];
features_and_intersections = features.map(f=> [f, findIntersection(f,polygon)]).filter(l => l[1] !== undefined); features_and_intersections = features.map(f=> [f, findIntersection(f,polygon)]).filter(l => l[1] !== undefined);
if (features_and_intersections.length > 0){ if (features_and_intersections.length > 0){
...@@ -213,7 +216,11 @@ const cyrb53 = (str, seed = 0) => { ...@@ -213,7 +216,11 @@ const cyrb53 = (str, seed = 0) => {
} }
}); });
if (!intersection_found) { if (intersection_found) {
document.getElementById("download").style.visibility = 'visible';
}
else {
document.getElementById("download").style.visibility = 'hidden';
dataPanel.append("No intersection found with any CityGML file.<br/>\n"); dataPanel.append("No intersection found with any CityGML file.<br/>\n");
} }
} }
...@@ -272,6 +279,8 @@ const cyrb53 = (str, seed = 0) => { ...@@ -272,6 +279,8 @@ const cyrb53 = (str, seed = 0) => {
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");
dataPanel.append('<button type="button" onclick="regionChooser.clickety_click()" id="download" style="visibility:hidden">Download Region</button>');
dataPanel.append('<br/>\n');
findIntersections(); findIntersections();
} }
...@@ -352,6 +361,11 @@ const cyrb53 = (str, seed = 0) => { ...@@ -352,6 +361,11 @@ const cyrb53 = (str, seed = 0) => {
$("html").removeClass("wait"); $("html").removeClass("wait");
console.log("READY!"); console.log("READY!");
} }
publicScope.clickety_click = function() {
console.log("You clicked pretty well");
document.querySelectorAll("input.select_citygml").forEach(x => console.log(x));
}
focusOnMap(); focusOnMap();
//var regionChooser = publicScope; //NOTE: In order to open closure. For debugging //var regionChooser = publicScope; //NOTE: In order to open closure. For debugging
......
Markdown is supported
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