Search in sources :

Example 1 with Promise

use of org.cesiumjs.cs.promise.Promise in project gwt-cs by iSergio.

the class Terrain method buildPanel.

@Override
public void buildPanel() {
    csVPanel = new ViewerPanel();
    CesiumTerrainProviderOptions cesiumTerrainProviderOptions = new CesiumTerrainProviderOptions();
    cesiumTerrainProviderOptions.url = "https://assets.agi.com/stk-terrain/world";
    cesiumTerrainProviderOptions.requestWaterMask = true;
    cesiumTerrainProviderOptions.requestVertexNormals = true;
    cesiumTerrainProviderMeshes = new CesiumTerrainProvider(cesiumTerrainProviderOptions);
    csVPanel.getViewer().terrainProvider = cesiumTerrainProviderMeshes;
    Cartesian3 target = new Cartesian3(300770.50872389384, 5634912.131394585, 2978152.2865545116);
    Cartesian3 offset = new Cartesian3(6344.974098678562, -793.3419798081741, 2499.9508860763162);
    csVPanel.getViewer().camera.lookAt(target, offset);
    csVPanel.getViewer().camera.lookAtTransform(Matrix4.IDENTITY());
    ListBox terrainsLBox = new ListBox();
    terrainsLBox.setWidth("130px");
    terrainsLBox.addItem("CesiumTerrainProvider - STK World Terrain", "0");
    terrainsLBox.addItem("CesiumTerrainProvider - STK World Terrain - no effects", "1");
    terrainsLBox.addItem("CesiumTerrainProvider - STK World Terrain w/ Lighting", "2");
    terrainsLBox.addItem("CesiumTerrainProvider - STK World Terrain w/ Water", "3");
    terrainsLBox.addItem("EllipsoidTerrainProvider", "4");
    terrainsLBox.addItem("VRTheWorldTerrainProvider", "5");
    terrainsLBox.addItem("GeoserverTerrainProvider", "6");
    terrainsLBox.addChangeHandler(new ChangeHandler() {

        @Override
        public void onChange(ChangeEvent changeEvent) {
            ListBox source = (ListBox) changeEvent.getSource();
            switch(source.getSelectedValue()) {
                case "0":
                    {
                        csVPanel.getViewer().terrainProvider = cesiumTerrainProviderMeshes;
                        csVPanel.getViewer().scene().globe.enableLighting = true;
                    }
                    break;
                case "1":
                    {
                        CesiumTerrainProviderOptions options = new CesiumTerrainProviderOptions();
                        options.url = "https://assets.agi.com/stk-terrain/world";
                        csVPanel.getViewer().terrainProvider = new CesiumTerrainProvider(options);
                    }
                    break;
                case "2":
                    {
                        CesiumTerrainProviderOptions options = new CesiumTerrainProviderOptions();
                        options.url = "https://assets.agi.com/stk-terrain/world";
                        options.requestVertexNormals = true;
                        csVPanel.getViewer().terrainProvider = new CesiumTerrainProvider(options);
                        csVPanel.getViewer().scene().globe.enableLighting = true;
                    }
                    break;
                case "3":
                    {
                        CesiumTerrainProviderOptions options = new CesiumTerrainProviderOptions();
                        options.url = "https://assets.agi.com/stk-terrain/world";
                        options.requestWaterMask = true;
                        csVPanel.getViewer().terrainProvider = new CesiumTerrainProvider(options);
                        csVPanel.getViewer().scene().globe.enableLighting = true;
                    }
                    break;
                case "4":
                    {
                        csVPanel.getViewer().terrainProvider = new EllipsoidTerrainProvider();
                    }
                    break;
                case "5":
                    {
                        VRTheWorldTerrainProviderOptions options = new VRTheWorldTerrainProviderOptions();
                        options.url = "http://www.vr-theworld.com/vr-theworld/tiles1.0.0/73/";
                        csVPanel.getViewer().terrainProvider = new VRTheWorldTerrainProvider(options);
                    }
                    break;
                case "6":
                    {
                        GeoserverTerrainProviderOptions options = new GeoserverTerrainProviderOptions();
                        options.url = "http://sergeserver.noip.me/geobase-portal/ows";
                        options.layerName = "geoserver:geobase:SRTM90";
                        options.styleName = "geobase:grayToColor";
                        csVPanel.getViewer().terrainProvider = new GeoserverTerrainProvider(options);
                    }
                    break;
                default:
                    break;
            }
        }
    });
    ListBox targetsLBox = new ListBox();
    targetsLBox.addItem("Mount Everest", "0");
    targetsLBox.addItem("Half Dome", "1");
    targetsLBox.addItem("San Francisco Bay", "2");
    targetsLBox.addChangeHandler(new ChangeHandler() {

        @Override
        public void onChange(ChangeEvent changeEvent) {
            ListBox source = (ListBox) changeEvent.getSource();
            switch(source.getSelectedValue()) {
                case "0":
                    {
                        Cartesian3 target = new Cartesian3(300770.50872389384, 5634912.131394585, 2978152.2865545116);
                        Cartesian3 offset = new Cartesian3(6344.974098678562, -793.3419798081741, 2499.9508860763162);
                        csVPanel.getViewer().camera.lookAt(target, offset);
                        csVPanel.getViewer().camera.lookAtTransform(Matrix4.IDENTITY());
                    }
                    break;
                case "1":
                    {
                        Cartesian3 target = new Cartesian3(-2489625.0836225147, -4393941.44443024, 3882535.9454173897);
                        Cartesian3 offset = new Cartesian3(-6857.40902037546, 412.3284835694358, 2147.5545426812023);
                        csVPanel.getViewer().camera.lookAt(target, offset);
                        csVPanel.getViewer().camera.lookAtTransform(Matrix4.IDENTITY());
                    }
                    break;
                case "2":
                    {
                        Cartesian3 target = new Cartesian3(-2708814.85583248, -4254159.450845907, 3891403.9457429945);
                        Cartesian3 offset = new Cartesian3(70642.66030209465, -31661.517948317807, 35505.179997143336);
                        csVPanel.getViewer().camera.lookAt(target, offset);
                        csVPanel.getViewer().camera.lookAtTransform(Matrix4.IDENTITY());
                    }
                default:
                    break;
            }
        }
    });
    ToggleButton lightingTBtn = new ToggleButton("Toggle Lighting");
    lightingTBtn.setWidth("130px");
    lightingTBtn.setValue(true);
    lightingTBtn.addValueChangeHandler(new ValueChangeHandler<Boolean>() {

        @Override
        public void onValueChange(ValueChangeEvent<Boolean> valueChangeEvent) {
            csVPanel.getViewer().scene().globe.enableLighting = !csVPanel.getViewer().scene().globe.enableLighting;
        }
    });
    ToggleButton fogTBtn = new ToggleButton("Toggle Fog");
    fogTBtn.setWidth("130px");
    fogTBtn.setValue(true);
    fogTBtn.addValueChangeHandler(new ValueChangeHandler<Boolean>() {

        @Override
        public void onValueChange(ValueChangeEvent<Boolean> valueChangeEvent) {
            csVPanel.getViewer().scene().fog.enabled = !csVPanel.getViewer().scene().fog.enabled;
        }
    });
    Button sampleBtn = new Button("Sample Everest Terrain");
    sampleBtn.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent clickEvent) {
            int gridWidth = 41;
            int gridHeight = 41;
            double everestLatitude = Math.toRadians(27.988257);
            double everestLongitude = Math.toRadians(86.925145);
            double rectangleHalfSize = 0.005;
            Rectangle e = new Rectangle(everestLongitude - rectangleHalfSize, everestLatitude - rectangleHalfSize, everestLongitude + rectangleHalfSize, everestLatitude + rectangleHalfSize);
            terrainSamplePositions = new ArrayList<>();
            for (int y = 0; y < gridHeight; ++y) {
                for (int x = 0; x < gridWidth; ++x) {
                    double lon = Math.lerp(e.west, e.east, (double) x / (gridWidth - 1.));
                    double lat = Math.lerp(e.south, e.north, (double) y / (gridHeight - 1.));
                    Cartographic position = new Cartographic(lon, lat);
                    terrainSamplePositions.add(position);
                }
            }
            Promise<Cartographic[], Void> promise = Cesium.sampleTerrain(csVPanel.getViewer().terrainProvider, 9, terrainSamplePositions.toArray(new Cartographic[terrainSamplePositions.size()]));
            promise.then(new Fulfill<Cartographic[]>() {

                @Override
                public void onFulfilled(Cartographic[] value) {
                    sampleTerrainSuccess();
                }
            });
        }
    });
    VerticalPanel vPanel = new VerticalPanel();
    vPanel.add(targetsLBox);
    vPanel.add(terrainsLBox);
    vPanel.add(lightingTBtn);
    vPanel.add(fogTBtn);
    vPanel.add(sampleBtn);
    AbsolutePanel aPanel = new AbsolutePanel();
    aPanel.add(csVPanel);
    aPanel.add(vPanel, 20, 20);
    contentPanel.add(new HTML("<p>Visualize worldwide, high-resolution terrain.</p>"));
    contentPanel.add(aPanel);
    initWidget(contentPanel);
}
Also used : VRTheWorldTerrainProvider(org.cesiumjs.cs.core.providers.VRTheWorldTerrainProvider) CesiumTerrainProviderOptions(org.cesiumjs.cs.core.providers.options.CesiumTerrainProviderOptions) EllipsoidTerrainProvider(org.cesiumjs.cs.core.providers.EllipsoidTerrainProvider) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) ArrayList(java.util.ArrayList) GeoserverTerrainProviderOptions(org.cesiumjs.cs.core.providers.options.GeoserverTerrainProviderOptions) VRTheWorldTerrainProviderOptions(org.cesiumjs.cs.core.providers.options.VRTheWorldTerrainProviderOptions) ValueChangeHandler(com.google.gwt.event.logical.shared.ValueChangeHandler) ChangeHandler(com.google.gwt.event.dom.client.ChangeHandler) CesiumTerrainProvider(org.cesiumjs.cs.core.providers.CesiumTerrainProvider) Fulfill(org.cesiumjs.cs.promise.Fulfill) ViewerPanel(org.cesiumjs.cs.widgets.ViewerPanel) Promise(org.cesiumjs.cs.promise.Promise) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) ChangeEvent(com.google.gwt.event.dom.client.ChangeEvent) ValueChangeEvent(com.google.gwt.event.logical.shared.ValueChangeEvent) GeoserverTerrainProvider(org.cesiumjs.cs.core.providers.GeoserverTerrainProvider)

Example 2 with Promise

use of org.cesiumjs.cs.promise.Promise in project gwt-cs by iSergio.

the class GeoJSONAndTopoJSON method buildPanel.

@Override
public void buildPanel() {
    csVPanel = new ViewerPanel();
    csVPanel.getViewer().dataSources().removeAll();
    csVPanel.getViewer().camera.lookAt(Cartesian3.fromDegrees(-98.0, 40.0), new Cartesian3(0.0, -4790000.0, 3930000.0));
    csVPanel.getViewer().camera.lookAtTransform(Matrix4.IDENTITY());
    Button defaultStylingBtn = new Button("Default styling");
    defaultStylingBtn.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent clickEvent) {
            reset();
            csVPanel.getViewer().dataSources().add(GeoJsonDataSource.load(GWT.getModuleBaseURL() + "SampleData/ne_10m_us_states.topojson"));
        }
    });
    Button basicStylingBtn = new Button("Basic styling");
    basicStylingBtn.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent clickEvent) {
            reset();
            GeoJsonDataSourceOptions options = new GeoJsonDataSourceOptions();
            options.stroke = Color.HOTPINK();
            options.fill = Color.DEEPPINK().withAlpha(0.5f);
            options.strokeWidth = 3;
            csVPanel.getViewer().dataSources().add(GeoJsonDataSource.load(GWT.getModuleBaseURL() + "SampleData/ne_10m_us_states.topojson", options));
        }
    });
    Button customStylingBtn = new Button("Custom styling");
    customStylingBtn.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent clickEvent) {
            Math.setRandomNumberSeed(0);
            Promise<GeoJsonDataSource, String> promise = GeoJsonDataSource.load(GWT.getModuleBaseURL() + "SampleData/ne_10m_us_states.topojson");
            promise.then(new Fulfill<GeoJsonDataSource>() {

                @Override
                public void onFulfilled(GeoJsonDataSource dataSource) {
                    reset();
                    csVPanel.getViewer().dataSources().add(dataSource);
                    Entity[] entities = dataSource.entities.values();
                    HashMap<String, Color> colorHash = new HashMap<>();
                    for (int i = 0; i < entities.length; i++) {
                        Entity entity = entities[i];
                        String name = entity.name;
                        Color color = colorHash.get(name);
                        if (color == null) {
                            ColorRandomOptions options = new ColorRandomOptions();
                            options.alpha = 1.0f;
                            color = Color.fromRandom(options);
                            colorHash.put(name, color);
                        }
                        entity.polygon.material = new ColorMaterialProperty(new ConstantProperty<>(color));
                        entity.polygon.outline = new ConstantProperty<>(false);
                        entity.polygon.extrudedHeight = new ConstantProperty<>(JsObject.getObject(entity, "properties").getNumber("Population").doubleValue() / 50.);
                    }
                }
            }, new Reject<String>() {

                @Override
                public void onRejected(String value) {
                    Window.alert(value);
                }
            });
        }
    });
    HorizontalPanel hPanel = new HorizontalPanel();
    hPanel.setSpacing(5);
    hPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
    hPanel.add(defaultStylingBtn);
    hPanel.add(basicStylingBtn);
    hPanel.add(customStylingBtn);
    AbsolutePanel aPanel = new AbsolutePanel();
    aPanel.add(csVPanel);
    aPanel.add(hPanel, 20, 20);
    contentPanel.add(new HTML("<p>Load GeoJSON or TopoJSON data and apply custom styling.</p>"));
    contentPanel.add(aPanel);
    initWidget(contentPanel);
}
Also used : Entity(org.cesiumjs.cs.datasources.Entity) GeoJsonDataSource(org.cesiumjs.cs.datasources.GeoJsonDataSource) HashMap(java.util.HashMap) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) ColorMaterialProperty(org.cesiumjs.cs.datasources.properties.ColorMaterialProperty) Reject(org.cesiumjs.cs.promise.Reject) Cartesian3(org.cesiumjs.cs.core.Cartesian3) ColorRandomOptions(org.cesiumjs.cs.core.options.ColorRandomOptions) GeoJsonDataSourceOptions(org.cesiumjs.cs.datasources.options.GeoJsonDataSourceOptions) Fulfill(org.cesiumjs.cs.promise.Fulfill) ViewerPanel(org.cesiumjs.cs.widgets.ViewerPanel) ConstantProperty(org.cesiumjs.cs.datasources.properties.ConstantProperty) Color(org.cesiumjs.cs.core.Color) Promise(org.cesiumjs.cs.promise.Promise) ClickHandler(com.google.gwt.event.dom.client.ClickHandler)

Example 3 with Promise

use of org.cesiumjs.cs.promise.Promise 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)3 Promise (org.cesiumjs.cs.promise.Promise)3 ViewerPanel (org.cesiumjs.cs.widgets.ViewerPanel)3 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)2 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)2 ChangeEvent (com.google.gwt.event.dom.client.ChangeEvent)1 ChangeHandler (com.google.gwt.event.dom.client.ChangeHandler)1 ValueChangeEvent (com.google.gwt.event.logical.shared.ValueChangeEvent)1 ValueChangeHandler (com.google.gwt.event.logical.shared.ValueChangeHandler)1 JSONArray (com.google.gwt.json.client.JSONArray)1 JSONObject (com.google.gwt.json.client.JSONObject)1 HTML (com.google.gwt.user.client.ui.HTML)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Cartesian3 (org.cesiumjs.cs.core.Cartesian3)1 Color (org.cesiumjs.cs.core.Color)1 GeocoderResult (org.cesiumjs.cs.core.GeocoderResult)1 Rectangle (org.cesiumjs.cs.core.Rectangle)1 ColorRandomOptions (org.cesiumjs.cs.core.options.ColorRandomOptions)1 CesiumTerrainProvider (org.cesiumjs.cs.core.providers.CesiumTerrainProvider)1