From b6d2a5d82f33a7b8e8f13d54c6c843bfd99e2cd4 Mon Sep 17 00:00:00 2001 From: Eric Duminil <eric.duminil@gmail.com> Date: Tue, 4 Oct 2022 16:33:24 +0200 Subject: [PATCH] Trying many stuff. Checklist instead of single link. --- .../website/script/simstadt_openlayers.js | 54 ++++++++++++------- 1 file changed, 34 insertions(+), 20 deletions(-) diff --git a/src/main/resources/eu/simstadt/regionchooser/website/script/simstadt_openlayers.js b/src/main/resources/eu/simstadt/regionchooser/website/script/simstadt_openlayers.js index 3fdc709..cf4aad5 100644 --- a/src/main/resources/eu/simstadt/regionchooser/website/script/simstadt_openlayers.js +++ b/src/main/resources/eu/simstadt/regionchooser/website/script/simstadt_openlayers.js @@ -1,6 +1,7 @@ var regionChooser = (function(){ var publicScope = {}; var fromJavaFX = navigator.userAgent.indexOf('JavaFX') !== -1; + //NOTE: Could do without jQuery var dataPanel = $('#dataPanel'); var wgs84Sphere = new ol.Sphere(6378137); var gmlId = 0; @@ -9,21 +10,21 @@ var regionChooser = (function(){ $("html").addClass("wait"); } - // Hash function -const cyrb53 = (str, seed = 0) => { - let h1 = 0xdeadbeef ^ seed, - h2 = 0x41c6ce57 ^ seed; - for (let i = 0, ch; i < str.length; i++) { - ch = str.charCodeAt(i); - h1 = Math.imul(h1 ^ ch, 2654435761); - h2 = Math.imul(h2 ^ ch, 1597334677); - } - - 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); - - return 4294967296 * (2097151 & h2) + (h1 >>> 0); -}; + // Hash function. For testing purposes in browser (no Feature ID is available) + const cyrb53 = (str, seed = 0) => { + let h1 = 0xdeadbeef ^ seed, + h2 = 0x41c6ce57 ^ seed; + for (let i = 0, ch; i < str.length; i++) { + ch = str.charCodeAt(i); + h1 = Math.imul(h1 ^ ch, 2654435761); + h2 = Math.imul(h2 ^ ch, 1597334677); + } + + 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); + + return 4294967296 * (2097151 & h2) + (h1 >>> 0); + }; var osm_layer = new ol.layer.Tile({ source: new ol.source.OSM() @@ -173,12 +174,13 @@ const cyrb53 = (str, seed = 0) => { // TODO: Add checkbox + label + // TODO: Add submit. // 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) { - link += "<a href=\"#\" onclick=\"regionChooser.downloadRegionFrom" + feature["source"] + "(" + feature.getId() - + ");return false;\">" + feature["name"] + "</a>"; + link += '<input type="checkbox" id="check_' + feature.getId() + '" class="select_citygml"><label for="check_' + feature.getId() + '">' + feature['name'] + '</label>'; } else { 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 + "%"; @@ -201,9 +203,10 @@ const cyrb53 = (str, seed = 0) => { var polygonArea = sketch.getGeometry().getArea(); var intersection_found = false; intersections.clear(); + //NOTE: getFeatures seems to not be sorted anymore. :-/ 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_and_intersections = features.map(f=> [f, findIntersection(f,polygon)]).filter(l => l[1] !== undefined); if (features_and_intersections.length > 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"); } } @@ -272,6 +279,8 @@ const cyrb53 = (str, seed = 0) => { dataPanel.append(wgs84_coords + "<br/>\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(); } @@ -352,6 +361,11 @@ const cyrb53 = (str, seed = 0) => { $("html").removeClass("wait"); console.log("READY!"); } + + publicScope.clickety_click = function() { + console.log("You clicked pretty well"); + document.querySelectorAll("input.select_citygml").forEach(x => console.log(x)); + } focusOnMap(); //var regionChooser = publicScope; //NOTE: In order to open closure. For debugging -- GitLab