|
|
|
@ -31,6 +31,7 @@ public class GeoJsonAreaSelectionDialog extends AreaSelectionDialog{
|
|
|
|
|
* Instantiates a new geo json area selection dialog.
|
|
|
|
|
*/
|
|
|
|
|
public GeoJsonAreaSelectionDialog() {
|
|
|
|
|
super();
|
|
|
|
|
|
|
|
|
|
//THE HANDLER
|
|
|
|
|
SelectAreaDialogEventHandler handler = new SelectAreaDialogEventHandler() {
|
|
|
|
@ -82,22 +83,22 @@ public class GeoJsonAreaSelectionDialog extends AreaSelectionDialog{
|
|
|
|
|
var ol = $wnd.ol;
|
|
|
|
|
var geojson_options = {};
|
|
|
|
|
var wkt_format = new ol.format.WKT();
|
|
|
|
|
var testFeature = wkt_format.readFeature(wktData);
|
|
|
|
|
var wktFeature = wkt_format.readFeature(wktData);
|
|
|
|
|
//console.log('WKT feature: '+wktFeature);
|
|
|
|
|
var wkt_options = {};
|
|
|
|
|
var geojson_format = new ol.format.GeoJSON(wkt_options);
|
|
|
|
|
var out = geojson_format.writeFeature(testFeature);
|
|
|
|
|
//window.getELementById("my-id").innerhtml(out);
|
|
|
|
|
//alert(out);
|
|
|
|
|
console.log(out)
|
|
|
|
|
return out;
|
|
|
|
|
console.log('geojson_format: '+geojson_format);
|
|
|
|
|
var geoJsonFeature = geojson_format.writeFeature(wktFeature);
|
|
|
|
|
//console.log('GeoJSON Feature: '+geoJsonFeature);
|
|
|
|
|
return geoJsonFeature;
|
|
|
|
|
}catch(err) {
|
|
|
|
|
console.log(err.message);
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}-*/;
|
|
|
|
|
|
|
|
|
|
public static native String print(String data) /*-{
|
|
|
|
|
console.log(out)
|
|
|
|
|
public static native String print(String txt) /*-{
|
|
|
|
|
console.log(txt)
|
|
|
|
|
}-*/;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -106,32 +107,39 @@ public class GeoJsonAreaSelectionDialog extends AreaSelectionDialog{
|
|
|
|
|
*
|
|
|
|
|
* @param wktTxt the wkt txt
|
|
|
|
|
* @return the string
|
|
|
|
|
* @throws Exception the exception
|
|
|
|
|
*/
|
|
|
|
|
public String wktToGeoJSON(String wktTxt){
|
|
|
|
|
String geoJSON = convertWKTToGeoJSON(wktTxt);
|
|
|
|
|
//Window.alert("geoJSON: "+geoJSON);
|
|
|
|
|
print("geoJSON: "+geoJSON);
|
|
|
|
|
|
|
|
|
|
if(geoJSON==null)
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
|
|
JavaScriptObject toJSON = JsonUtils.safeEval(geoJSON);
|
|
|
|
|
JSONObject objJson = new JSONObject(toJSON);
|
|
|
|
|
return objJson.get("geometry").toString();
|
|
|
|
|
public String wktToGeoJSON(String wktTxt) throws Exception{
|
|
|
|
|
try {
|
|
|
|
|
String geoJSON = convertWKTToGeoJSON(wktTxt);
|
|
|
|
|
//Window.alert("geoJSON: "+geoJSON);
|
|
|
|
|
print("geoJSON: "+geoJSON);
|
|
|
|
|
|
|
|
|
|
if(geoJSON==null)
|
|
|
|
|
throw new Exception();
|
|
|
|
|
|
|
|
|
|
JavaScriptObject toJSON = JsonUtils.safeEval(geoJSON);
|
|
|
|
|
JSONObject objJson = new JSONObject(toJSON);
|
|
|
|
|
return objJson.get("geometry").toString();
|
|
|
|
|
}catch(Exception e) {
|
|
|
|
|
//silent
|
|
|
|
|
throw new Exception("Sorry, an error occurred while getting GeoJSON format for the drawn Geometry");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Gets the WKT to geo json.
|
|
|
|
|
*
|
|
|
|
|
* @return the WKT to geo json
|
|
|
|
|
* @throws Exception the exception
|
|
|
|
|
*/
|
|
|
|
|
public String getWKTToGeoJSON(){
|
|
|
|
|
public String getWKTToGeoJSON() throws Exception{
|
|
|
|
|
|
|
|
|
|
if(wktArea==null){
|
|
|
|
|
print("wktArea is null");
|
|
|
|
|
return null;
|
|
|
|
|
throw new Exception("Sorry, an error occurred while reading the drawn Geometry");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//print("wktArea is: "+wktArea);
|
|
|
|
|
return wktToGeoJSON(wktArea);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|