Search in sources :

Example 1 with Reject

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

the class Billboards method offsetByDistance.

private void offsetByDistance() {
    Resource.fetchImage(GWT.getModuleBaseURL() + "images/Cesium_Logo_overlay.png").then(new Fulfill<JsImage>() {

        @Override
        public void onFulfilled(JsImage logoImg) {
            Resource.fetchImage(GWT.getModuleBaseURL() + "images/facility.gif").then(new Fulfill<JsImage>() {

                @Override
                public void onFulfilled(JsImage facilityImg) {
                    int facilityHeight = facilityImg.height;
                    BillboardGraphicsOptions billboardGraphicsOptions = new BillboardGraphicsOptions();
                    billboardGraphicsOptions.image = new ConstantProperty<>(facilityImg);
                    billboardGraphicsOptions.horizontalOrigin = new ConstantProperty<>(HorizontalOrigin.CENTER());
                    billboardGraphicsOptions.verticalOrigin = new ConstantProperty<>(VerticalOrigin.BOTTOM());
                    BillboardGraphics billboardGraphics = new BillboardGraphics(billboardGraphicsOptions);
                    EntityOptions entityOptions = new EntityOptions();
                    entityOptions.billboard = billboardGraphics;
                    entityOptions.position = new ConstantPositionProperty(Cartesian3.fromDegrees(-75.59777, 40.03883));
                    csVPanel.getViewer().entities().add(new Entity(entityOptions));
                    billboardGraphicsOptions = new BillboardGraphicsOptions();
                    billboardGraphicsOptions.image = new ConstantProperty<>(logoImg);
                    billboardGraphicsOptions.horizontalOrigin = new ConstantProperty<>(HorizontalOrigin.CENTER());
                    billboardGraphicsOptions.verticalOrigin = new ConstantProperty<>(VerticalOrigin.BOTTOM());
                    billboardGraphicsOptions.pixelOffset = new ConstantProperty<>(new Cartesian2(0.0, -facilityHeight));
                    billboardGraphicsOptions.pixelOffsetScaleByDistance = new ConstantProperty<>(new NearFarScalar(1.0e3, 1.0, 1.5e6, 0.0));
                    billboardGraphicsOptions.translucencyByDistance = new ConstantProperty<>(new NearFarScalar(1.0e3, 1.0, 1.5e6, 0.1));
                    billboardGraphics = new BillboardGraphics(billboardGraphicsOptions);
                    entityOptions = new EntityOptions();
                    entityOptions.billboard = billboardGraphics;
                    entityOptions.position = new ConstantPositionProperty(Cartesian3.fromDegrees(-75.59777, 40.03883));
                    csVPanel.getViewer().entities().add(new Entity(entityOptions));
                }
            }, new Reject<Void>() {

                @Override
                public void onRejected(Void value) {
                    LOGGER.info("facility imagery not loaded");
                }
            });
        }
    }, new Reject<Void>() {

        @Override
        public void onRejected(Void value) {
            LOGGER.info("Cesium_Logo_overlay imagery not loaded");
        }
    });
}
Also used : Entity(org.cesiumjs.cs.datasources.Entity) BillboardGraphics(org.cesiumjs.cs.datasources.graphics.BillboardGraphics) ConstantPositionProperty(org.cesiumjs.cs.datasources.properties.ConstantPositionProperty) EntityOptions(org.cesiumjs.cs.datasources.options.EntityOptions) JsImage(org.cesiumjs.cs.js.JsImage) Reject(org.cesiumjs.cs.promise.Reject) BillboardGraphicsOptions(org.cesiumjs.cs.datasources.graphics.options.BillboardGraphicsOptions) Fulfill(org.cesiumjs.cs.promise.Fulfill)

Example 2 with Reject

use of org.cesiumjs.cs.promise.Reject 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)

Aggregations

Entity (org.cesiumjs.cs.datasources.Entity)2 Fulfill (org.cesiumjs.cs.promise.Fulfill)2 Reject (org.cesiumjs.cs.promise.Reject)2 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)1 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)1 HashMap (java.util.HashMap)1 Cartesian3 (org.cesiumjs.cs.core.Cartesian3)1 Color (org.cesiumjs.cs.core.Color)1 ColorRandomOptions (org.cesiumjs.cs.core.options.ColorRandomOptions)1 GeoJsonDataSource (org.cesiumjs.cs.datasources.GeoJsonDataSource)1 BillboardGraphics (org.cesiumjs.cs.datasources.graphics.BillboardGraphics)1 BillboardGraphicsOptions (org.cesiumjs.cs.datasources.graphics.options.BillboardGraphicsOptions)1 EntityOptions (org.cesiumjs.cs.datasources.options.EntityOptions)1 GeoJsonDataSourceOptions (org.cesiumjs.cs.datasources.options.GeoJsonDataSourceOptions)1 ColorMaterialProperty (org.cesiumjs.cs.datasources.properties.ColorMaterialProperty)1 ConstantPositionProperty (org.cesiumjs.cs.datasources.properties.ConstantPositionProperty)1 ConstantProperty (org.cesiumjs.cs.datasources.properties.ConstantProperty)1 JsImage (org.cesiumjs.cs.js.JsImage)1 Promise (org.cesiumjs.cs.promise.Promise)1 ViewerPanel (org.cesiumjs.cs.widgets.ViewerPanel)1