Commit 29c9d253 authored by iSergio's avatar iSergio
Browse files

Examples fixes

parent a2dd4fd7
Loading
Loading
Loading
Loading
+70 −40
Original line number Diff line number Diff line
@@ -17,13 +17,14 @@
package org.cleanlogic.cesiumjs4gwt.showcase.examples;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ChangeEvent;
import com.google.gwt.event.dom.client.ChangeHandler;
import com.google.gwt.user.client.ui.AbsolutePanel;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.ListBox;
import org.cesiumjs.cs.Cesium;
import org.cesiumjs.cs.core.HeadingPitchRoll;
import org.cesiumjs.cs.core.Math;
import org.cesiumjs.cs.core.*;
import org.cesiumjs.cs.core.providers.TerrainProvider;
import org.cesiumjs.cs.datasources.Entity;
import org.cesiumjs.cs.datasources.graphics.BillboardGraphics;
import org.cesiumjs.cs.datasources.graphics.options.BillboardGraphicsOptions;
@@ -31,8 +32,10 @@ import org.cesiumjs.cs.datasources.options.EntityOptions;
import org.cesiumjs.cs.datasources.properties.ConstantPositionProperty;
import org.cesiumjs.cs.datasources.properties.ConstantProperty;
import org.cesiumjs.cs.js.JsImage;
import org.cesiumjs.cs.scene.enums.HeightReference;
import org.cesiumjs.cs.scene.enums.HorizontalOrigin;
import org.cesiumjs.cs.scene.enums.VerticalOrigin;
import org.cesiumjs.cs.scene.options.ViewOptions;
import org.cesiumjs.cs.widgets.ViewerPanel;
import org.cleanlogic.cesiumjs4gwt.showcase.basic.AbstractExample;
import org.cleanlogic.cesiumjs4gwt.showcase.components.store.ShowcaseExampleStore;
@@ -43,7 +46,8 @@ import javax.inject.Inject;
 * @author Serge Silaev aka iSergio
 */
public class Billboards extends AbstractExample {
    ViewerPanel csVPanel;
    private ViewerPanel csVPanel = null;
    private TerrainProvider terrainProvider = null;

    @Inject
    public Billboards(ShowcaseExampleStore store) {
@@ -66,9 +70,8 @@ public class Billboards extends AbstractExample {
        billboardsLBox.addItem("Fade by viewer distance", "6");
        billboardsLBox.addItem("Offset by viewer distance", "7");
        billboardsLBox.addItem("Add marker billboards", "8");
        billboardsLBox.addChangeHandler(new ChangeHandler() {
            @Override
            public void onChange(ChangeEvent changeEvent) {
        billboardsLBox.addItem("Disable the depth test when clamped to ground", "9");
        billboardsLBox.addChangeHandler(changeEvent -> {
            ListBox source = (ListBox) changeEvent.getSource();
            reset();
            switch (source.getSelectedValue()) {
@@ -98,10 +101,13 @@ public class Billboards extends AbstractExample {
                    break;
                case "8":
                    addMarkerBillboards();
                    break;
                case "9":
                    disableDepthTest();
                    break;
                default:
                    break;
            }
            }
        });

        AbsolutePanel aPanel = new AbsolutePanel();
@@ -144,8 +150,8 @@ public class Billboards extends AbstractExample {
        billboardGraphicsOptions.color = new ConstantProperty<>(Color.LIME()); // default: WHITE
        billboardGraphicsOptions.rotation = new ConstantProperty<>(Math.PI_OVER_FOUR()); // default: 0.0
        billboardGraphicsOptions.alignedAxis = new ConstantProperty<>(Cartesian3.ZERO()); // default
        billboardGraphicsOptions.width = new ConstantProperty<>(100); // default: undefined
        billboardGraphicsOptions.height = new ConstantProperty<>(25); // default: undefined
        billboardGraphicsOptions.width = new ConstantProperty<>(100.); // default: undefined
        billboardGraphicsOptions.height = new ConstantProperty<>(25.); // default: undefined
        EntityOptions entityOptions = new EntityOptions();
        entityOptions.position = new ConstantPositionProperty(Cartesian3.fromDegrees(-75.59777, 40.03883));
        entityOptions.billboard = new BillboardGraphics(billboardGraphicsOptions);
@@ -291,6 +297,11 @@ public class Billboards extends AbstractExample {
    private void reset() {
        csVPanel.getViewer().camera.flyHome(0);
        csVPanel.getViewer().entities().removeAll();
        if (terrainProvider != null) {
            csVPanel.getViewer().scene().globe.terrainProvider = terrainProvider;
            terrainProvider = null;
            csVPanel.getViewer().scene().globe.depthTestAgainstTerrain = false;
        }
    }

    private void createFacility(JsImage logoImg, JsImage facilityImg) {
@@ -321,4 +332,23 @@ public class Billboards extends AbstractExample {
        entityOptions.position = new ConstantPositionProperty(Cartesian3.fromDegrees(-75.59777, 40.03883));
        csVPanel.getViewer().entities().add(new Entity(entityOptions));
    }

    private void disableDepthTest() {
        terrainProvider = csVPanel.getViewer().terrainProvider;
        csVPanel.getViewer().terrainProvider = Cesium.createWorldTerrain();
        csVPanel.getViewer().scene().globe.depthTestAgainstTerrain = true;

        EntityOptions entityOptions = new EntityOptions();
        entityOptions.position = new ConstantPositionProperty(Cartesian3.fromDegrees(-122.1958, 46.1915));
        BillboardGraphicsOptions graphicsOptions = new BillboardGraphicsOptions();
        graphicsOptions.image = new ConstantProperty<>(GWT.getModuleBaseURL() + "images/facility.gif");
        graphicsOptions.heightReference = new ConstantProperty<>(HeightReference.CLAMP_TO_GROUND());
        graphicsOptions.disableDepthTestDistance = new ConstantProperty<>(Double.POSITIVE_INFINITY);
        entityOptions.billboard = new BillboardGraphics(graphicsOptions);
        csVPanel.getViewer().entities().add(entityOptions);

        csVPanel.getViewer().scene().camera().setView(new ViewOptions()
                .setDestination(new Cartesian3(-2357576.243142461, -3744417.5604860787, 4581807.855903771))
                .setOrientation(new HeadingPitchRoll(5.9920811504170475, -0.6032820429886212, 6.28201303164098)));
    }
}
+1 −1
Original line number Diff line number Diff line
@@ -78,7 +78,7 @@ public class CZMLModelArticulations extends AbstractExample {
        articulationsCZML.setProperty("Fairing Drop", fairingDropCZML);

        JsObject modelCZML = JsObject.create();
        modelCZML.setProperty("gltf", "https://assets.agi.com/models/launchvehicle.glb");
        modelCZML.setProperty("gltf", "https://cesium.com/public/SandcastleSampleData/launchvehicle.glb");
        modelCZML.setProperty("scale", 2.0);
        modelCZML.setProperty("minimumPixelSize", 128);
        modelCZML.setProperty("runAnimations", false);
+110 −89
Original line number Diff line number Diff line
@@ -17,12 +17,13 @@
package org.cleanlogic.cesiumjs4gwt.showcase.examples;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ChangeEvent;
import com.google.gwt.event.dom.client.ChangeHandler;
import com.google.gwt.user.client.ui.AbsolutePanel;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.ListBox;
import org.cesiumjs.cs.core.HeadingPitchRoll;
import org.cesiumjs.cs.core.Math;
import org.cesiumjs.cs.core.*;
import org.cesiumjs.cs.datasources.Entity;
@@ -89,9 +90,9 @@ public class Camera extends AbstractExample {
        listBox.addItem("View in ICRF", "9");
        listBox.addItem("Move events", "10");
        listBox.addItem("Camera changed event", "11");
        listBox.addChangeHandler(new ChangeHandler() {
            @Override
            public void onChange(ChangeEvent changeEvent) {
        listBox.addItem("Fly from Los Angeles to Tokyo via Europe", "12");
        listBox.addItem("Look down during exaggerated flight", "13");
        listBox.addChangeHandler(changeEvent -> {
            reset();
            ListBox source = (ListBox) changeEvent.getSource();
            switch (source.getSelectedValue()) {
@@ -125,15 +126,31 @@ public class Camera extends AbstractExample {
                case "11":
                    cameraChanges();
                    break;
                case "12":
                    flyOverLongitude(false);
                    break;
                case "13":
                    flyOverLongitude(true);
                    break;
                default:
                    break;
            }
            }
        });

        Button completeFlightBtn = new Button("Complete flight");
        completeFlightBtn.addClickHandler(event -> csVPanel.getViewer().camera.completeFlight());

        Button cancelFlightBtn = new Button("Cancel flight");
        cancelFlightBtn.addClickHandler(event -> csVPanel.getViewer().camera.cancelFlight());

        HorizontalPanel hPanel = new HorizontalPanel();
        hPanel.add(listBox);
        hPanel.add(completeFlightBtn);
        hPanel.add(cancelFlightBtn);

        AbsolutePanel absPanel = new AbsolutePanel();
        absPanel.add(csVPanel);
        absPanel.add(listBox, 20, 20);
        absPanel.add(hPanel, 20, 20);

        contentPanel.add(
                new HTML("<p>Fly to a specified location or view a geographic rectangle.</p>"));
@@ -155,20 +172,15 @@ public class Camera extends AbstractExample {
        final CameraFlyToOptions cameraFlyToOptions = new CameraFlyToOptions();
        cameraFlyToOptions.destinationPos = Cartesian3.fromDegrees(-73.98580932617188,
                40.74843406689482, 363.34038727246224);
        cameraFlyToOptions.complete = new org.cesiumjs.cs.scene.Camera.FlightCompleteCallback() {
            @Override
            public void on() {
                Utils.setTimeout(() -> {
                    CameraFlyToOptions cameraFlyToOptions = new CameraFlyToOptions();
                    cameraFlyToOptions.destinationPos = Cartesian3.fromDegrees(-73.98585975679403,
        cameraFlyToOptions.complete = () -> Utils.setTimeout(() -> {
            CameraFlyToOptions flyToOptions = new CameraFlyToOptions();
            flyToOptions.destinationPos = Cartesian3.fromDegrees(-73.98585975679403,
                    40.75759944127251, 186.50838555841779);
                    cameraFlyToOptions.orientation = new org.cesiumjs.cs.core.HeadingPitchRoll(
            flyToOptions.orientation = new org.cesiumjs.cs.core.HeadingPitchRoll(
                    Math.toRadians(200.0), Math.toRadians(-50.0));
                    cameraFlyToOptions.easingFunction = EasingFunction.LINEAR_NONE();
                    csVPanel.getViewer().camera.flyTo(cameraFlyToOptions);
            flyToOptions.easingFunction = EasingFunction.LINEAR_NONE();
            csVPanel.getViewer().camera.flyTo(flyToOptions);
        }, 1000);
            }
        };
        csVPanel.getViewer().camera.flyTo(cameraFlyToOptions);
    }

@@ -186,16 +198,16 @@ public class Camera extends AbstractExample {
        csVPanel.getViewer().camera.flyTo(cameraFlyToOptions);
    }

    private void viewRectangle() {
    private void flyToRectangle() {
        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);
        CameraFlyToOptions cameraFlyToOptions = new CameraFlyToOptions();
        cameraFlyToOptions.destinationRec = rectangle;
        csVPanel.getViewer().camera.flyTo(cameraFlyToOptions);

        RectangleGraphicsOptions rectangleGraphicsOptions = new RectangleGraphicsOptions();
        rectangleGraphicsOptions.coordinates = new ConstantProperty<>(rectangle);
@@ -207,16 +219,16 @@ public class Camera extends AbstractExample {
        csVPanel.getViewer().entities().add(new Entity(entityOptions));
    }

    private void flyToRectangle() {
        double west = -90.0;
    private void viewRectangle() {
        double west = -77.0;
        double south = 38.0;
        double east = -87.0;
        double north = 40.0;
        double east = -72.0;
        double north = 42.0;
        Rectangle rectangle = Rectangle.fromDegrees(west, south, east, north);

        CameraFlyToOptions cameraFlyToOptions = new CameraFlyToOptions();
        cameraFlyToOptions.destinationRec = rectangle;
        csVPanel.getViewer().camera.flyTo(cameraFlyToOptions);
        ViewOptions viewOptions = new ViewOptions();
        viewOptions.destinationRec = rectangle;
        csVPanel.getViewer().camera.setView(viewOptions);

        RectangleGraphicsOptions rectangleGraphicsOptions = new RectangleGraphicsOptions();
        rectangleGraphicsOptions.coordinates = new ConstantProperty<>(rectangle);
@@ -272,38 +284,47 @@ public class Camera extends AbstractExample {

    public void cameraEvents() {
        _removeStart = csVPanel.getViewer().camera.moveStart()
                .addEventListener(new org.cesiumjs.cs.scene.Camera.MoveListener() {
                    @Override
                    public void function() {
                        _eventsLbl.setVisible(true);
                    }
                });
                .addEventListener((org.cesiumjs.cs.scene.Camera.MoveListener) () -> _eventsLbl.setVisible(true));
        _removeEnd = csVPanel.getViewer().camera.moveEnd()
                .addEventListener(new org.cesiumjs.cs.scene.Camera.MoveListener() {
                    @Override
                    public void function() {
                        _eventsLbl.setVisible(false);
                    }
                });
                .addEventListener((org.cesiumjs.cs.scene.Camera.MoveListener) () -> _eventsLbl.setVisible(false));
    }

    private void cameraChanges() {
        _removeChanged = csVPanel.getViewer().camera.changed()
                .addEventListener(new org.cesiumjs.cs.scene.Camera.ChangedListener() {
                    @Override
                    public void function(double percentage) {
                .addEventListener((org.cesiumjs.cs.scene.Camera.ChangedListener) percentage -> {
                    ++_i;
                    _changesLbl.setText("Camera Changed: " + _i + ", "
                            + new BigDecimal(percentage).setScale(6, RoundingMode.HALF_EVEN).toString());
                    _changesLbl.setVisible(true);
                    }
                });
    }

    private void flyOverLongitude(boolean adjustPitch) {
        org.cesiumjs.cs.scene.Camera camera = csVPanel.getViewer().scene().camera();

        CameraFlyToOptions tokyoOptions = new CameraFlyToOptions()
                .setDestination(Cartesian3.fromDegrees(139.8148, 35.7142, 20000.0))
                .setOrientation(new HeadingPitchRoll(Math.toRadians(15.0), Math.toRadians(-60), 0.0))
                .setDuration(20.).setFlyOverLongitude(Math.toRadians(60.0));

        CameraFlyToOptions laOptions = new CameraFlyToOptions()
                .setDestination(Cartesian3.fromDegrees(-117.729, 34.457, 10000.0))
                .setOrientation(new HeadingPitchRoll(Math.toRadians(-15.0), -Math.PI_OVER_FOUR(), 0.0))
                .setDuration(5);
        laOptions.complete = () -> Utils.setTimeout(() -> camera.flyTo(tokyoOptions), 1000);

        if (adjustPitch) {
            tokyoOptions.pitchAdjustHeight = 1000;
            laOptions.pitchAdjustHeight = 1000;
        }

        camera.flyTo(laOptions);
    }

    private void reset() {
        csVPanel.getViewer().scene().completeMorph();
        csVPanel.getViewer().entities().removeAll();
        csVPanel.getViewer().scene().primitives().removeAll();
//        csVPanel.getViewer().scene().primitives().remove(referenceFramePrimitive);
//         csVPanel.getViewer().scene().tweens().removeAll();

        if (_removeStart != null) {
+27 −36
Original line number Diff line number Diff line
@@ -25,8 +25,6 @@ import org.cesiumjs.cs.core.*;
import org.cesiumjs.cs.core.enums.ClockRange;
import org.cesiumjs.cs.core.interpolation.HermitePolynomialApproximation;
import org.cesiumjs.cs.core.options.TimeIntervalOptions;
import org.cesiumjs.cs.core.providers.CesiumTerrainProvider;
import org.cesiumjs.cs.core.providers.options.CesiumTerrainProviderOptions;
import org.cesiumjs.cs.datasources.Entity;
import org.cesiumjs.cs.datasources.graphics.ModelGraphics;
import org.cesiumjs.cs.datasources.graphics.options.ModelGraphicsOptions;
@@ -61,16 +59,12 @@ public class Cardboard extends AbstractExample {
    public void buildPanel() {
        ViewerOptions viewerOptions = new ViewerOptions();
        viewerOptions.vrButton = true;
        viewerOptions.terrainProvider = Cesium.createWorldTerrain();

        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.
@@ -116,9 +110,7 @@ public class Cardboard extends AbstractExample {
        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) {
        csVPanel.getViewer().scene().preRender().addEventListener((Scene.Listener) (scene, time) -> {
            Cartesian3 position = entity.position.getValue(time);
            if (position == null || !Cesium.defined(position)) {
                return;
@@ -150,7 +142,6 @@ public class Cardboard extends AbstractExample {
            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.
+2 −8
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package org.cleanlogic.cesiumjs4gwt.showcase.examples;

import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.ui.HTML;
import org.cesiumjs.cs.Cesium;
import org.cesiumjs.cs.collections.BillboardCollection;
import org.cesiumjs.cs.core.*;
import org.cesiumjs.cs.core.geometry.BoxGeometry;
@@ -26,8 +27,6 @@ import org.cesiumjs.cs.core.geometry.RectangleGeometry;
import org.cesiumjs.cs.core.geometry.options.BoxGeometryOptions;
import org.cesiumjs.cs.core.geometry.options.RectangleGeometryOptions;
import org.cesiumjs.cs.core.options.GeometryInstanceOptions;
import org.cesiumjs.cs.core.providers.CesiumTerrainProvider;
import org.cesiumjs.cs.core.providers.options.CesiumTerrainProviderOptions;
import org.cesiumjs.cs.js.JsObject;
import org.cesiumjs.cs.scene.Globe;
import org.cesiumjs.cs.scene.Primitive;
@@ -59,12 +58,7 @@ public class CesiumInspector extends AbstractExample {
        Scene scene = csVPanel.getViewer().scene();
        Globe globe = csVPanel.getViewer().scene().globe;
        globe.depthTestAgainstTerrain = true;

        CesiumTerrainProviderOptions cesiumTerrainProviderOptions = new CesiumTerrainProviderOptions();
        cesiumTerrainProviderOptions.url = "https://assets.agi.com/stk-terrain/world";
        cesiumTerrainProviderOptions.requestVertexNormals = true;
        cesiumTerrainProviderOptions.requestWaterMask = true;
        csVPanel.getViewer().terrainProvider = new CesiumTerrainProvider(cesiumTerrainProviderOptions);
        globe.terrainProvider = Cesium.createWorldTerrain();

        // Add Cesium Inspector
        csVPanel.getViewer().extend(viewerCesiumInspectorMixin.instance());
Loading