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

refactor

parent 582f24aa
...@@ -22,33 +22,11 @@ var regionChooser = (function(){ ...@@ -22,33 +22,11 @@ var regionChooser = (function(){
source: new ol.source.OSM() source: new ol.source.OSM()
}); });
function read_kml(url){ var kml_source = utils.read_kml(fromJavaFX ? undefined : 'data/citygml_hulls.kml');
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_layer = new ol.layer.Vector({ var kml_layer = new ol.layer.Vector({
source : kml_source, source : kml_source,
style : polygon_style('#447744', 0.2) style : utils.polygon_style('#447744', 0.2)
}); });
var intersections = new ol.source.Vector(); var intersections = new ol.source.Vector();
...@@ -184,7 +162,7 @@ var regionChooser = (function(){ ...@@ -184,7 +162,7 @@ var regionChooser = (function(){
publicScope.highlightPolygon = function(i) { publicScope.highlightPolygon = function(i) {
var feature = kml_source.getFeatureById(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) { publicScope.resetHighlight = function(i) {
...@@ -199,7 +177,7 @@ var regionChooser = (function(){ ...@@ -199,7 +177,7 @@ var regionChooser = (function(){
var checkedBoxes = Array.from(document.querySelectorAll("input.select_citygml")).filter(c => c.checked); var checkedBoxes = Array.from(document.querySelectorAll("input.select_citygml")).filter(c => c.checked);
var checkbox_ids = checkedBoxes.map(c => c.id); var checkbox_ids = checkedBoxes.map(c => c.id);
var features = getCheckedPolygons(checkbox_ids); 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); document.getElementById("download_region_button").disabled = (checkedBoxes.length == 0);
} }
...@@ -401,7 +379,7 @@ var regionChooser = (function(){ ...@@ -401,7 +379,7 @@ var regionChooser = (function(){
var checkbox_ids = checkedBoxes.map(c => c.id); var checkbox_ids = checkedBoxes.map(c => c.id);
var features = getCheckedPolygons(checkbox_ids); 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)); publicScope.downloadRegionFromCityGMLs(checkedBoxes.map(c => c.id));
} }
......
...@@ -38,5 +38,27 @@ var utils = { ...@@ -38,5 +38,27 @@ var utils = {
document.body.removeChild(textarea); 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
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