Search in sources :

Example 11 with EntityOptions

use of org.cesiumjs.cs.datasources.options.EntityOptions in project gwt-cs by iSergio.

the class Cardboard method buildPanel.

@Override
public void buildPanel() {
    ViewerOptions viewerOptions = new ViewerOptions();
    viewerOptions.vrButton = true;
    ViewerPanel csVPanel = new ViewerPanel(viewerOptions);
    csVPanel.getViewer().scene().globe.enableLighting = true;
    CesiumTerrainProviderOptions cesiumTerrainProviderOptions = new CesiumTerrainProviderOptions();
    cesiumTerrainProviderOptions.url = "https://assets.agi.com/stk-terrain/world";
    cesiumTerrainProviderOptions.requestVertexNormals = true;
    csVPanel.getViewer().terrainProvider = new CesiumTerrainProvider(cesiumTerrainProviderOptions);
    csVPanel.getViewer().scene().globe.depthTestAgainstTerrain = true;
    // Follow the path of a plane. See the interpolation Sandcastle example.
    Math.setRandomNumberSeed(3);
    start = JulianDate.fromDate(new JsDate(2015, 2, 25, 16));
    stop = JulianDate.addSeconds(start, 360, new JulianDate());
    csVPanel.getViewer().clock().startTime = start.clone();
    csVPanel.getViewer().clock().stopTime = stop.clone();
    csVPanel.getViewer().clock().currentTime = start.clone();
    csVPanel.getViewer().clock().clockRange = ClockRange.LOOP_STOP();
    csVPanel.getViewer().clock().multiplier = 1.0;
    double lon = -112.110693;
    double lat = 36.0994841;
    double radius = 0.03;
    String modelURI = GWT.getModuleBaseURL() + "SampleData/models/CesiumBalloon/CesiumBalloon.glb";
    EntityOptions entityOptions = new EntityOptions();
    TimeIntervalOptions timeIntervalOptions = new TimeIntervalOptions();
    timeIntervalOptions.start = start;
    timeIntervalOptions.stop = stop;
    entityOptions.availability = new TimeIntervalCollection(new TimeInterval[] { new TimeInterval(timeIntervalOptions) });
    entityOptions.position = computeCirclularFlight(lon, lat, radius);
    ModelGraphicsOptions modelGraphicsOptions = new ModelGraphicsOptions();
    modelGraphicsOptions.uri = new ConstantProperty<>(modelURI);
    modelGraphicsOptions.minimumPixelSize = new ConstantProperty<>(64);
    entityOptions.model = new ModelGraphics(modelGraphicsOptions);
    entity = csVPanel.getViewer().entities().add(entityOptions);
    SampledPropertyInterpolationOptions sampledPropertyInterpolationOptions = new SampledPropertyInterpolationOptions();
    sampledPropertyInterpolationOptions.interpolationDegree = 2;
    sampledPropertyInterpolationOptions.interpolationAlgorithm = HermitePolynomialApproximation.instance();
    ((SampledPositionProperty) entity.position).setInterpolationOptions(sampledPropertyInterpolationOptions);
    // Set initial camera position and orientation to be when in the model's reference frame.
    final org.cesiumjs.cs.scene.Camera camera = csVPanel.getViewer().camera;
    camera.position = new Cartesian3(0.25, 0.0, 0.0);
    camera.direction = new Cartesian3(1.0, 0.0, 0.0);
    camera.up = new Cartesian3(0.0, 0.0, 1.0);
    camera.right = new Cartesian3(0.0, -1.0, 0.0);
    csVPanel.getViewer().scene().preRender().addEventListener(new Scene.Listener() {

        @Override
        public void function(Scene scene, JulianDate time) {
            Cartesian3 position = entity.position.getValue(time);
            if (position == null || !Cesium.defined(position)) {
                return;
            }
            Matrix4 transform;
            if (!Cesium.defined(entity.orientation)) {
                transform = Transforms.eastNorthUpToFixedFrame(position);
            } else {
                Quaternion orientation = (Quaternion) entity.orientation.getValue(time);
                if (!Cesium.defined(orientation)) {
                    return;
                }
                transform = Matrix4.fromRotationTranslation(Matrix3.fromQuaternion(orientation), position);
            }
            // Save camera state
            Cartesian3 offset = camera.position.clone();
            Cartesian3 direction = camera.direction.clone();
            Cartesian3 up = camera.up.clone();
            // Set camera to be in model's reference frame.
            camera.lookAtTransform(transform);
            // Reset the camera state to the saved state so it appears fixed in the model's frame.
            offset.clone(camera.position);
            direction.clone(camera.direction);
            up.clone(camera.up);
            Cartesian3.cross(direction, up, camera.right);
        }
    });
    // Add a few more balloons flying with the one the viewer is in.
    int numBalloons = 12;
    for (int i = 0; i < numBalloons; ++i) {
        double balloonRadius = (Math.nextRandomNumber() * 2.0 - 1.0) * 0.01 + radius;
        entityOptions = new EntityOptions();
        timeIntervalOptions = new TimeIntervalOptions();
        timeIntervalOptions.start = start;
        timeIntervalOptions.stop = stop;
        entityOptions.availability = new TimeIntervalCollection(new TimeInterval[] { new TimeInterval(timeIntervalOptions) });
        entityOptions.position = computeCirclularFlight(lon, lat, balloonRadius);
        modelGraphicsOptions = new ModelGraphicsOptions();
        modelGraphicsOptions.uri = new ConstantProperty<>(modelURI);
        modelGraphicsOptions.minimumPixelSize = new ConstantProperty<>(64);
        entityOptions.model = new ModelGraphics(modelGraphicsOptions);
        Entity balloon = csVPanel.getViewer().entities().add(entityOptions);
        sampledPropertyInterpolationOptions = new SampledPropertyInterpolationOptions();
        sampledPropertyInterpolationOptions.interpolationDegree = 2;
        sampledPropertyInterpolationOptions.interpolationAlgorithm = HermitePolynomialApproximation.instance();
        ((SampledPositionProperty) balloon.position).setInterpolationOptions(sampledPropertyInterpolationOptions);
    }
    contentPanel.add(new HTML("<p>Configure viewer to add a button enabling look at a mobile device with cardboard.</p>"));
    contentPanel.add(csVPanel);
    initWidget(contentPanel);
}
Also used : CesiumTerrainProviderOptions(org.cesiumjs.cs.core.providers.options.CesiumTerrainProviderOptions) Entity(org.cesiumjs.cs.datasources.Entity) SampledPropertyInterpolationOptions(org.cesiumjs.cs.datasources.properties.options.SampledPropertyInterpolationOptions) ViewerOptions(org.cesiumjs.cs.widgets.options.ViewerOptions) HTML(com.google.gwt.user.client.ui.HTML) JsDate(org.cesiumjs.cs.js.JsDate) ModelGraphics(org.cesiumjs.cs.datasources.graphics.ModelGraphics) EntityOptions(org.cesiumjs.cs.datasources.options.EntityOptions) CesiumTerrainProvider(org.cesiumjs.cs.core.providers.CesiumTerrainProvider) SampledPositionProperty(org.cesiumjs.cs.datasources.properties.SampledPositionProperty) ViewerPanel(org.cesiumjs.cs.widgets.ViewerPanel) TimeIntervalOptions(org.cesiumjs.cs.core.options.TimeIntervalOptions) TimeIntervalCollection(org.cesiumjs.cs.collections.TimeIntervalCollection) Scene(org.cesiumjs.cs.scene.Scene) ModelGraphicsOptions(org.cesiumjs.cs.datasources.graphics.options.ModelGraphicsOptions)

Example 12 with EntityOptions

use of org.cesiumjs.cs.datasources.options.EntityOptions in project gwt-cs by iSergio.

the class CustomHomeButton method buildPanel.

@Override
public void buildPanel() {
    final PointGraphicsOptions pointOptions = new PointGraphicsOptions();
    pointOptions.pixelSize = new ConstantProperty<>(5);
    final EntityOptions entityOptions = new EntityOptions();
    entityOptions.position = new ConstantPositionProperty(Cartesian3.fromDegrees(-73.986555, 40.735396, 0));
    entityOptions.point = new PointGraphics(pointOptions);
    final Entity entity = new Entity(entityOptions);
    final ViewerOptions viewerOptions = new ViewerOptions();
    final ViewerPanel viewer = new ViewerPanel(viewerOptions);
    viewer.getViewer().homeButton().viewModel.tooltip = "Fly to New York";
    viewer.getViewer().entities().add(entity);
    viewer.getViewer().homeButton().viewModel.command.beforeExecute.addEventListener(new Event.Listener() {

        @Override
        public void function(Object... o) {
            viewer.getViewer().flyTo(entity);
        }
    });
    contentPanel.add(new HTML("<div>Click the home button to fly to New York.</div>"));
    contentPanel.add(viewer);
    initWidget(contentPanel);
}
Also used : ViewerPanel(org.cesiumjs.cs.widgets.ViewerPanel) Entity(org.cesiumjs.cs.datasources.Entity) PointGraphicsOptions(org.cesiumjs.cs.datasources.graphics.options.PointGraphicsOptions) ViewerOptions(org.cesiumjs.cs.widgets.options.ViewerOptions) PointGraphics(org.cesiumjs.cs.datasources.graphics.PointGraphics) HTML(com.google.gwt.user.client.ui.HTML) ConstantPositionProperty(org.cesiumjs.cs.datasources.properties.ConstantPositionProperty) EntityOptions(org.cesiumjs.cs.datasources.options.EntityOptions) Event(org.cesiumjs.cs.core.Event)

Example 13 with EntityOptions

use of org.cesiumjs.cs.datasources.options.EntityOptions in project gwt-cs by iSergio.

the class Camera method viewRectangle.

private void viewRectangle() {
    double west = -90.0;
    double south = 38.0;
    double east = -87.0;
    double north = 40.0;
    Rectangle rectangle = Rectangle.fromDegrees(west, south, east, north);
    ViewOptions viewOptions = new ViewOptions();
    viewOptions.destinationRec = rectangle;
    csVPanel.getViewer().camera.setView(viewOptions);
    RectangleGraphicsOptions rectangleGraphicsOptions = new RectangleGraphicsOptions();
    rectangleGraphicsOptions.coordinates = new ConstantProperty<>(rectangle);
    rectangleGraphicsOptions.fill = new ConstantProperty<>(false);
    rectangleGraphicsOptions.outline = new ConstantProperty<>(true);
    rectangleGraphicsOptions.outlineColor = new ConstantProperty<>(Color.WHITE());
    EntityOptions entityOptions = new EntityOptions();
    entityOptions.rectangle = new RectangleGraphics(rectangleGraphicsOptions);
    csVPanel.getViewer().entities().add(new Entity(entityOptions));
}
Also used : Entity(org.cesiumjs.cs.datasources.Entity) ViewOptions(org.cesiumjs.cs.scene.options.ViewOptions) RectangleGraphicsOptions(org.cesiumjs.cs.datasources.graphics.options.RectangleGraphicsOptions) EntityOptions(org.cesiumjs.cs.datasources.options.EntityOptions) RectangleGraphics(org.cesiumjs.cs.datasources.graphics.RectangleGraphics)

Example 14 with EntityOptions

use of org.cesiumjs.cs.datasources.options.EntityOptions 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 15 with EntityOptions

use of org.cesiumjs.cs.datasources.options.EntityOptions in project gwt-cs by iSergio.

the class Billboards method changeBillboardProperties.

private void changeBillboardProperties() {
    BillboardGraphicsOptions billboardGraphicsOptions = new BillboardGraphicsOptions();
    billboardGraphicsOptions.image = new ConstantProperty<>(GWT.getModuleBaseURL() + "images/Cesium_Logo_overlay.png");
    BillboardGraphics billboardGraphics = new BillboardGraphics(billboardGraphicsOptions);
    EntityOptions entityOptions = new EntityOptions();
    entityOptions.position = new ConstantPositionProperty(Cartesian3.fromDegrees(-75.59777, 40.03883, 300000.0));
    entityOptions.billboard = billboardGraphics;
    Entity entity = csVPanel.getViewer().entities().add(new Entity(entityOptions));
    entity.billboard.scale = new ConstantProperty<>(3.0);
    entity.billboard.color = new ConstantProperty<>(Color.WHITE().withAlpha(0.25f));
}
Also used : Entity(org.cesiumjs.cs.datasources.Entity) BillboardGraphicsOptions(org.cesiumjs.cs.datasources.graphics.options.BillboardGraphicsOptions) BillboardGraphics(org.cesiumjs.cs.datasources.graphics.BillboardGraphics) ConstantPositionProperty(org.cesiumjs.cs.datasources.properties.ConstantPositionProperty) EntityOptions(org.cesiumjs.cs.datasources.options.EntityOptions)

Aggregations

EntityOptions (org.cesiumjs.cs.datasources.options.EntityOptions)41 Entity (org.cesiumjs.cs.datasources.Entity)27 ConstantPositionProperty (org.cesiumjs.cs.datasources.properties.ConstantPositionProperty)27 BillboardGraphics (org.cesiumjs.cs.datasources.graphics.BillboardGraphics)13 BillboardGraphicsOptions (org.cesiumjs.cs.datasources.graphics.options.BillboardGraphicsOptions)13 ViewerPanel (org.cesiumjs.cs.widgets.ViewerPanel)13 ModelGraphics (org.cesiumjs.cs.datasources.graphics.ModelGraphics)11 ModelGraphicsOptions (org.cesiumjs.cs.datasources.graphics.options.ModelGraphicsOptions)11 LabelGraphics (org.cesiumjs.cs.datasources.graphics.LabelGraphics)10 LabelGraphicsOptions (org.cesiumjs.cs.datasources.graphics.options.LabelGraphicsOptions)10 HTML (com.google.gwt.user.client.ui.HTML)8 ConstantProperty (org.cesiumjs.cs.datasources.properties.ConstantProperty)6 ChangeEvent (com.google.gwt.event.dom.client.ChangeEvent)5 ColorMaterialProperty (org.cesiumjs.cs.datasources.properties.ColorMaterialProperty)5 ViewerOptions (org.cesiumjs.cs.widgets.options.ViewerOptions)5 ChangeHandler (com.google.gwt.event.dom.client.ChangeHandler)4 MouseMoveEvent (org.cesiumjs.cs.core.events.MouseMoveEvent)4 CesiumTerrainProvider (org.cesiumjs.cs.core.providers.CesiumTerrainProvider)4 CesiumTerrainProviderOptions (org.cesiumjs.cs.core.providers.options.CesiumTerrainProviderOptions)4 Scene (org.cesiumjs.cs.scene.Scene)4