From a8a25c44168c21e25ba0658a9db5ab9264357134 Mon Sep 17 00:00:00 2001
From: Eric Duminil <eric.duminil@gmail.com>
Date: Fri, 14 Oct 2022 10:30:30 +0200
Subject: [PATCH] refactor

---
 .../website/script/simstadt_openlayers.js     | 32 +++----------------
 .../regionchooser/website/script/utils.js     | 22 +++++++++++++
 2 files changed, 27 insertions(+), 27 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 e8584d0..5f5af1a 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 d3182a0..6d6702b 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
-- 
GitLab