Search in sources :

Example 6 with Fulfill

use of org.cesiumjs.cs.promise.Fulfill 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);
}
Also used : ViewerPanel(org.cesiumjs.cs.widgets.ViewerPanel) JsObject(org.cesiumjs.cs.js.JsObject) JSONArray(com.google.gwt.json.client.JSONArray) Rectangle(org.cesiumjs.cs.core.Rectangle) ViewerOptions(org.cesiumjs.cs.widgets.options.ViewerOptions) HTML(com.google.gwt.user.client.ui.HTML) Promise(org.cesiumjs.cs.promise.Promise) JSONObject(com.google.gwt.json.client.JSONObject) Fulfill(org.cesiumjs.cs.promise.Fulfill) GeocoderResult(org.cesiumjs.cs.core.GeocoderResult)

Aggregations

Fulfill (org.cesiumjs.cs.promise.Fulfill)6 ViewerPanel (org.cesiumjs.cs.widgets.ViewerPanel)5 Entity (org.cesiumjs.cs.datasources.Entity)4 ChangeEvent (com.google.gwt.event.dom.client.ChangeEvent)3 ChangeHandler (com.google.gwt.event.dom.client.ChangeHandler)3 HTML (com.google.gwt.user.client.ui.HTML)3 Promise (org.cesiumjs.cs.promise.Promise)3 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)2 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)2 ValueChangeEvent (com.google.gwt.event.logical.shared.ValueChangeEvent)2 ValueChangeHandler (com.google.gwt.event.logical.shared.ValueChangeHandler)2 AbsolutePanel (com.google.gwt.user.client.ui.AbsolutePanel)2 ListBox (com.google.gwt.user.client.ui.ListBox)2 ColorMaterialProperty (org.cesiumjs.cs.datasources.properties.ColorMaterialProperty)2 ConstantProperty (org.cesiumjs.cs.datasources.properties.ConstantProperty)2 JsObject (org.cesiumjs.cs.js.JsObject)2 Reject (org.cesiumjs.cs.promise.Reject)2 ViewerOptions (org.cesiumjs.cs.widgets.options.ViewerOptions)2 CanvasElement (com.google.gwt.dom.client.CanvasElement)1 JSONArray (com.google.gwt.json.client.JSONArray)1