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

RegionChooser: Try to import dynamic kml.

parent ba84ea11
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.Paths; import java.nio.file.Paths;
...@@ -59,15 +60,19 @@ public JavaScriptFXBridge() { ...@@ -59,15 +60,19 @@ public JavaScriptFXBridge() {
public String refreshHulls() throws IOException { public String refreshHulls() throws IOException {
System.out.println("Look for hulls in " + repo); System.out.println("Look for hulls in " + repo);
Path url = Paths.get("just_a_test.kml"); Path url = Paths.get("just_a_test.kml");
String header = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<kml>\n" + " <Document>\n";
String footer = " </Document>\n" + "</kml>";
try (BufferedWriter bw = Files.newBufferedWriter(url)) { try (BufferedWriter bw = Files.newBufferedWriter(url)) {
bw.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<kml>\n" + " <Document>\n"); bw.write(header);
Files.walk(repo) Files.walk(repo)
.filter(Files::isRegularFile) .filter(Files::isRegularFile)
.filter(p -> p.toString().contains(".cache") && p.toString().endsWith(".xyz")) .filter(p -> p.toString().contains(".cache") && p.toString().endsWith(".xyz"))
.forEach(p -> { .forEach(p -> {
System.out.println("Parsing " + p); System.out.println("Parsing " + p);
jsApp.call("addCityGmlHull", p.toString());
try { try {
String hullKML = new String(Files.readAllBytes(p), StandardCharsets.UTF_8);
System.out.println(hullKML);
jsApp.call("addCityGmlHull", header + hullKML + footer);
List<String> lines = Files.readAllLines(p); List<String> lines = Files.readAllLines(p);
for (String line : lines) { for (String line : lines) {
bw.write(line + "\n"); bw.write(line + "\n");
...@@ -76,7 +81,7 @@ public String refreshHulls() throws IOException { ...@@ -76,7 +81,7 @@ public String refreshHulls() throws IOException {
ex.printStackTrace(); ex.printStackTrace();
} }
}); });
bw.write(" </Document>\n" + "</kml>"); bw.write(footer);
} catch (Exception ex) { } catch (Exception ex) {
ex.printStackTrace(); ex.printStackTrace();
} }
......
...@@ -19,6 +19,7 @@ proj4.defs("EPSG:28992", "+proj=sterea +lat_0=52.15616055555555 +lon_0=5.3876388 ...@@ -19,6 +19,7 @@ proj4.defs("EPSG:28992", "+proj=sterea +lat_0=52.15616055555555 +lon_0=5.3876388
source: new ol.source.OSM() source: new ol.source.OSM()
}); });
//NOTE: Use GeoJSON instead?
function read_kml(url){ function read_kml(url){
return new ol.source.KML({ return new ol.source.KML({
projection : ol.proj.get('EPSG:3857'), projection : ol.proj.get('EPSG:3857'),
...@@ -63,8 +64,13 @@ proj4.defs("EPSG:28992", "+proj=sterea +lat_0=52.15616055555555 +lon_0=5.3876388 ...@@ -63,8 +64,13 @@ proj4.defs("EPSG:28992", "+proj=sterea +lat_0=52.15616055555555 +lon_0=5.3876388
features : [] features : []
}); });
publicScope.addCityGmlHull = function(p) { publicScope.addCityGmlHull = function(kmlString) {
dataPanel.append(p + "<br/>\n") kml_source.addFeature(kmlFormat.readFeature(kmlString,
{
featureProjection: ol.proj.get('EPSG:3857')
}
));
updateGMLPolygons();
}; };
publicScope.addNovaFactoryProduct = function(xmin, ymin, xmax, ymax, name, epsgId) { publicScope.addNovaFactoryProduct = function(xmin, ymin, xmax, ymax, name, epsgId) {
...@@ -75,11 +81,12 @@ proj4.defs("EPSG:28992", "+proj=sterea +lat_0=52.15616055555555 +lon_0=5.3876388 ...@@ -75,11 +81,12 @@ proj4.defs("EPSG:28992", "+proj=sterea +lat_0=52.15616055555555 +lon_0=5.3876388
geometry : box, geometry : box,
name : name, name : name,
}); });
feature["geoJSON"] = geoJSONformat.writeFeatureObject(feature); feature["geoJSON"] = geoJsonFormat.writeFeatureObject(feature);
feature["area"] = feature.getGeometry().getArea(); feature["area"] = feature.getGeometry().getArea();
feature["description"] = "novaFACTORY>" + name; feature["description"] = "novaFACTORY>" + name;
feature["available"] = true; feature["available"] = true;
feature["source"] = "NovaFACTORY"; feature["source"] = "NovaFACTORY";
novafactory_vectors.addFeature(feature); novafactory_vectors.addFeature(feature);
}; };
...@@ -96,7 +103,8 @@ proj4.defs("EPSG:28992", "+proj=sterea +lat_0=52.15616055555555 +lon_0=5.3876388 ...@@ -96,7 +103,8 @@ proj4.defs("EPSG:28992", "+proj=sterea +lat_0=52.15616055555555 +lon_0=5.3876388
}) })
}); });
var geoJSONformat = new ol.format.GeoJSON(); var geoJsonFormat = new ol.format.GeoJSON();
var kmlFormat = new ol.format.KML();
kml_layer.addEventListener("change", function() { kml_layer.addEventListener("change", function() {
map.getView().fitExtent(kml_source.getExtent(), (map.getSize())); map.getView().fitExtent(kml_source.getExtent(), (map.getSize()));
...@@ -104,7 +112,7 @@ proj4.defs("EPSG:28992", "+proj=sterea +lat_0=52.15616055555555 +lon_0=5.3876388 ...@@ -104,7 +112,7 @@ proj4.defs("EPSG:28992", "+proj=sterea +lat_0=52.15616055555555 +lon_0=5.3876388
function updateGMLPolygons() { function updateGMLPolygons() {
kml_source.forEachFeature(function(feature) { kml_source.forEachFeature(function(feature) {
feature["geoJSON"] = geoJSONformat.writeFeatureObject(feature); feature["geoJSON"] = geoJsonFormat.writeFeatureObject(feature);
feature["area"] = feature.getGeometry().getArea(); feature["area"] = feature.getGeometry().getArea();
var project = feature.get("project"); var project = feature.get("project");
var name = feature.get("name"); var name = feature.get("name");
...@@ -178,7 +186,7 @@ proj4.defs("EPSG:28992", "+proj=sterea +lat_0=52.15616055555555 +lon_0=5.3876388 ...@@ -178,7 +186,7 @@ proj4.defs("EPSG:28992", "+proj=sterea +lat_0=52.15616055555555 +lon_0=5.3876388
function findIntersections() { function findIntersections() {
var sketch_area = sketch.getGeometry().getArea(); var sketch_area = sketch.getGeometry().getArea();
var poly1 = geoJSONformat.writeFeatureObject(sketch); var poly1 = geoJsonFormat.writeFeatureObject(sketch);
var intersection_found = false; var intersection_found = false;
intersections.clear(); intersections.clear();
function findIntersection(feature) { function findIntersection(feature) {
...@@ -189,7 +197,7 @@ proj4.defs("EPSG:28992", "+proj=sterea +lat_0=52.15616055555555 +lon_0=5.3876388 ...@@ -189,7 +197,7 @@ proj4.defs("EPSG:28992", "+proj=sterea +lat_0=52.15616055555555 +lon_0=5.3876388
dataPanel.append("Intersection found with :<br/>\n"); dataPanel.append("Intersection found with :<br/>\n");
intersection_found = true; intersection_found = true;
} }
var intersection = geoJSONformat.readFeature(jsonIntersection); var intersection = geoJsonFormat.readFeature(jsonIntersection);
var intersectionArea = intersection.getGeometry().getArea(); var intersectionArea = intersection.getGeometry().getArea();
var citygml_percentage = Math.round(intersectionArea / feature["area"] * 100); var citygml_percentage = Math.round(intersectionArea / feature["area"] * 100);
var sketch_percentage = Math.round(intersectionArea / sketch_area * 100); var sketch_percentage = Math.round(intersectionArea / sketch_area * 100);
...@@ -301,10 +309,11 @@ proj4.defs("EPSG:28992", "+proj=sterea +lat_0=52.15616055555555 +lon_0=5.3876388 ...@@ -301,10 +309,11 @@ proj4.defs("EPSG:28992", "+proj=sterea +lat_0=52.15616055555555 +lon_0=5.3876388
}); });
$('#refresh_hulls').click(function() { $('#refresh_hulls').click(function() {
kml_source.clear();
url = fxapp.refreshHulls(); url = fxapp.refreshHulls();
console.log('Loading ' + url); console.log('Loading ' + url);
kml_source = read_kml(url); //kml_source = read_kml(url);
kml_layer.setSource(kml_source); //kml_layer.setSource(kml_source);
}); });
novafactory_layer.downloadFinished = function() { novafactory_layer.downloadFinished = function() {
......
Supports Markdown
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