use of org.cesiumjs.cs.core.GeocoderResult in project gwt-cs by iSergio.
the class CustomGeocoder method buildPanel.
@Override
public void buildPanel() {
OpenStreetMapNominatimGeocoder openStreetMapNominatimGeocoder = new OpenStreetMapNominatimGeocoder();
openStreetMapNominatimGeocoder.geocode = new OpenStreetMapNominatimGeocoder.Geocode() {
@Override
public Promise<JsObject, Void> function(String input) {
String endpoint = "http://nominatim.openstreetmap.org/search?";
String query = "format=json&q=" + input;
String requestString = endpoint + query;
Promise<JsObject, Void> promise = Resource.fetchJson(requestString);
promise.then(new Fulfill<JsObject>() {
@Override
public void onFulfilled(JsObject value) {
JSONArray jsonArray = new JSONArray(value);
for (int i = 0; i < jsonArray.size(); i++) {
JSONObject jsonObject = jsonArray.get(i).isObject();
JSONArray bboxDegrees = jsonObject.get("boundingbox").isArray();
Rectangle destination = Rectangle.fromDegrees(Double.parseDouble(bboxDegrees.get(2).isString().toString().replace("\"", "")), Double.parseDouble(bboxDegrees.get(0).isString().toString().replace("\"", "")), Double.parseDouble(bboxDegrees.get(3).isString().toString().replace("\"", "")), Double.parseDouble(bboxDegrees.get(1).isString().toString().replace("\"", "")));
GeocoderResult geocoderResult = new GeocoderResult();
geocoderResult.displayName = jsonObject.get("display_name").isString().toString();
geocoderResult.destinationRectangle = destination;
jsonArray.set(i, new JSONObject((JsObject) (Object) geocoderResult));
}
}
});
return promise;
}
};
ViewerOptions viewerOptions = new ViewerOptions();
viewerOptions.geocoder = openStreetMapNominatimGeocoder;
csVPanel = new ViewerPanel(viewerOptions);
contentPanel.add(new HTML("<p>Example of a custom geocoder.</p>"));
contentPanel.add(csVPanel);
initWidget(contentPanel);
}
Aggregations