Commit 395f34dd authored by duminil's avatar duminil
Browse files

RegionChooser js refactoring.

new Java methods.
parent 7b5a7cea
......@@ -25,7 +25,6 @@ public void start(Stage stage) {
stage.setTitle("RegionChooserJavaFX");
scene = new Scene(new Browser(), 1024, 768, Color.web("#666970"));
stage.setScene(scene);
scene.getStylesheets().add("webviewsample/BrowserToolbar.css");
stage.show();
}
......@@ -42,6 +41,15 @@ class Browser extends Region
public void downloadRegion(String wktPolygon) {
System.out.println("FROM JAVA : DO SOMETHING with " + wktPolygon);
}
public void downloadRegionFromCityGML(String wktPolygon, String citygmlDescription) {
System.out.println("FROM JAVA : DO SOMETHING with " + wktPolygon + " from \n" + citygmlDescription);
}
public boolean checkIfCityGMLSAreAvailable(String citygmlDescription) {
//TODO: IMPLEMENT ME
return true;
}
}
final WebView browser = new WebView();
......
......@@ -36,10 +36,6 @@ var kml_layer = new ol.layer.Vector({
})
});
kml_layer.addEventListener("change", function(event) {
map.getView().fitExtent(kml_source.getExtent(), (map.getSize()));
});
var intersections = new ol.source.Vector();
var intersections_layer = new ol.layer.Vector({
......@@ -59,6 +55,21 @@ var map = new ol.Map({
})
});
var geoJSONformat = new ol.format.GeoJSON();
kml_layer.addEventListener("change", function(event) {
var fromJavaFX = (typeof fxapp !== 'undefined');
map.getView().fitExtent(kml_source.getExtent(), (map.getSize()));
kml_source.forEachFeature(function(feature) {
feature["geoJSON"] = geoJSONformat.writeFeatureObject(feature);
feature["area"] = feature.getGeometry().getArea();
var citygmlHere;
if (fromJavaFX) {
citygmlHere = fxapp.checkIfCityGMLSAreAvailable(feature.get("description"));
}
feature["available"] = citygmlHere;
});
});
// The features are not added to a regular vector layer/source,
// but to a feature overlay which holds a collection of features.
// This collection is passed to the modify and also the draw
......@@ -113,19 +124,16 @@ draw.on('drawstart', function(evt) {
reset_btn.disabled = false;
});
var sourceProj = map.getView().getProjection();
var geoJSONformat = new ol.format.GeoJSON();
function findIntersections() {
var features = kml_source.getFeatures();
var sketch_area = sketch.getGeometry().getArea();
var poly1 = geoJSONformat.writeFeatureObject(sketch);
var intersection_found = false;
intersections.clear();
for (var i = 0; i < features.length; i++) {
var feature = features[i];
var poly2 = geoJSONformat.writeFeatureObject(feature);
var i = 0;
kml_source.forEachFeature(function(feature) {
try {
var jsonIntersection = turf.intersect(poly1, poly2);
var jsonIntersection = turf.intersect(poly1, feature["geoJSON"]);
if (undefined != jsonIntersection) {
if (!intersection_found) {
$('#dataPanel').append("Intersection found with :<br/>\n");
......@@ -133,12 +141,19 @@ function findIntersections() {
}
var intersection = geoJSONformat.readFeature(jsonIntersection);
var intersectionArea = intersection.getGeometry().getArea();
var citygmlArea = feature.getGeometry().getArea();
var citygml_percentage = Math.round(intersectionArea / citygmlArea * 100);
var citygml_percentage = Math.round(intersectionArea / feature["area"] * 100);
var sketch_percentage = Math.round(intersectionArea / sketch_area * 100);
intersections.addFeature(intersection);
$('#dataPanel').append(feature.get('description') + " (" + citygml_percentage + "%");
var description;
if (feature["available"]) {
description = "<a href=\"#\" onclick=\"downloadRegionFromCityGML(" + i
+ ");return false;\">"+feature.get('description')+"</a>";
} else {
description = feature.get('description');
}
$('#dataPanel').append(description + " (" + citygml_percentage + "%");
if (sketch_percentage == 100) {
$('#dataPanel').append(", all inside");
}
......@@ -148,11 +163,18 @@ function findIntersections() {
} catch (err) {
console.log(feature.get('description') + " - " + err);
}
}
i++;
})
if (!intersection_found) {
$('#dataPanel').append("No intersection found with any CityGML<br/>\n");
}
}
function downloadRegionFromCityGML(i) {
$('#dataPanel').append("COMING FROM " + i);
fxapp.downloadRegionFromCityGML(sketchAsWKT(), kml_source.getFeatures()[i].get("description"));
}
function displayInfo() {
var start = new Date().getTime();
$('#dataPanel').empty();
......@@ -201,17 +223,21 @@ $('#reset').click(function() {
});
$('#send').click(function() {
focusOnMap();
fxapp.downloadRegion(sketchAsWKT());
});
function sketchAsWKT() {
var wktFormat = new ol.format.WKT();
fxapp.downloadRegion(wktFormat.writeFeature(sketch, {
return wktFormat.writeFeature(sketch, {
dataProjection : ol.proj.get('EPSG:4326'),
featureProjection : ol.proj.get('EPSG:3857')
}));
focusOnMap();
});
})
}
function focusOnMap() {
$('#map').focus();
$('#map').scrollIntoView();
// $('#map').scrollIntoView();
}
focusOnMap();
focusOnMap();
\ No newline at end of file
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