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 e8584d0b45c1ecf75f9b16ccb8c9a377cd4ca82d..5f5af1a50dfef15c6366d7c293d54e9bb3ab7d82 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 @@ -22,33 +22,11 @@ var regionChooser = (function(){ source: new ol.source.OSM() }); - function read_kml(url){ - return new ol.source.KML({ - projection : ol.proj.get('EPSG:3857'), - url : url, - extractAttributes : false, - extractStyles : false - }); - } - - var kml_source = read_kml(fromJavaFX ? undefined : 'data/citygml_hulls.kml'); - - function polygon_style(color, alpha) { - return new ol.style.Style({ - fill : new ol.style.Fill({ - color : 'rgba(255, 255, 255,' + alpha + ')' - }), - stroke : new ol.style.Stroke({ - color : color, - width : 2, - lineDash : [ 5, 10 ] - }), - }); - } + var kml_source = utils.read_kml(fromJavaFX ? undefined : 'data/citygml_hulls.kml'); var kml_layer = new ol.layer.Vector({ source : kml_source, - style : polygon_style('#447744', 0.2) + style : utils.polygon_style('#447744', 0.2) }); var intersections = new ol.source.Vector(); @@ -184,7 +162,7 @@ var regionChooser = (function(){ publicScope.highlightPolygon = function(i) { var feature = kml_source.getFeatureById(i); - feature.setStyle(polygon_style("#ff44a2", 0.7)); + feature.setStyle(utils.polygon_style("#ff44a2", 0.7)); } publicScope.resetHighlight = function(i) { @@ -199,7 +177,7 @@ var regionChooser = (function(){ var checkedBoxes = Array.from(document.querySelectorAll("input.select_citygml")).filter(c => c.checked); var checkbox_ids = checkedBoxes.map(c => c.id); var features = getCheckedPolygons(checkbox_ids); - features.forEach(f => f.setStyle(polygon_style("#ffff00", 0.8))); + features.forEach(f => f.setStyle(utils.polygon_style("#ffff00", 0.8))); document.getElementById("download_region_button").disabled = (checkedBoxes.length == 0); } @@ -401,7 +379,7 @@ var regionChooser = (function(){ var checkbox_ids = checkedBoxes.map(c => c.id); var features = getCheckedPolygons(checkbox_ids); - features.forEach(f => f.setStyle(polygon_style("#ffff00", 0.8))); + features.forEach(f => f.setStyle(utils.polygon_style("#ffff00", 0.8))); publicScope.downloadRegionFromCityGMLs(checkedBoxes.map(c => c.id)); } diff --git a/src/main/resources/eu/simstadt/regionchooser/website/script/utils.js b/src/main/resources/eu/simstadt/regionchooser/website/script/utils.js index d3182a0456683e496259e9924b430d315e6de6eb..6d6702b0c5f5f41eb39511e87266791ae261c6a7 100644 --- a/src/main/resources/eu/simstadt/regionchooser/website/script/utils.js +++ b/src/main/resources/eu/simstadt/regionchooser/website/script/utils.js @@ -38,5 +38,27 @@ var utils = { document.body.removeChild(textarea); } } + }, + + read_kml: function(url){ + return new ol.source.KML({ + projection : ol.proj.get('EPSG:3857'), + url : url, + extractAttributes : false, + extractStyles : false + }); + }, + + polygon_style: function(color, alpha) { + return new ol.style.Style({ + fill : new ol.style.Fill({ + color : 'rgba(255, 255, 255,' + alpha + ')' + }), + stroke : new ol.style.Stroke({ + color : color, + width : 2, + lineDash : [ 5, 10 ] + }), + }); } }; \ No newline at end of file