Search in sources :

Example 1 with Viewer

use of org.cesiumjs.cs.widgets.Viewer in project gwt-cs by iSergio.

the class KML method buildPanel.

@Override
public void buildPanel() {
    csVPanel = new ViewerPanel();
    ListBox kmlLBox = new ListBox();
    kmlLBox.addItem("KML - Global Science Facilities", GWT.getModuleBaseURL() + "SampleData/kml/facilities/facilities.kml");
    kmlLBox.addItem("KMZ with embedded data - GDP per capita", GWT.getModuleBaseURL() + "SampleData/kml/gdpPerCapita2008.kmz");
    kmlLBox.addItem("gx KML extensions - Bike Ride", GWT.getModuleBaseURL() + "SampleData/kml/bikeRide.kml");
    kmlLBox.addChangeHandler(new ChangeHandler() {

        @Override
        public void onChange(ChangeEvent changeEvent) {
            reset();
            ListBox source = (ListBox) changeEvent.getSource();
            final Viewer viewer = csVPanel.getViewer();
            org.cesiumjs.cs.scene.Camera camera = viewer.camera;
            CanvasElement canvas = viewer.canvas();
            camera.flyHome(0);
            // camera, canvas);
            KmlDataSourceOptions kmlDataSourceOptions = new KmlDataSourceOptions();
            kmlDataSourceOptions.canvas = canvas;
            kmlDataSourceOptions.camera = camera;
            if (!source.getSelectedValue().contains("bikeRide")) {
                csVPanel.getViewer().dataSources().add(KmlDataSource.load(source.getSelectedValue(), kmlDataSourceOptions));
            } else {
                csVPanel.getViewer().dataSources().add(KmlDataSource.load(source.getSelectedValue(), kmlDataSourceOptions)).then(new Fulfill<KmlDataSource>() {

                    @Override
                    public void onFulfilled(KmlDataSource dataSource) {
                        viewer.clock().shouldAnimate = false;
                        final Entity rider = dataSource.entities.getById("tour");
                        viewer.flyTo(rider).then(new Fulfill<Boolean>() {

                            @Override
                            public void onFulfilled(Boolean value) {
                                viewer.trackedEntity = rider;
                                viewer.selectedEntity = viewer.trackedEntity;
                                viewer.clock().multiplier = 30;
                                viewer.clock().shouldAnimate = true;
                            }
                        });
                    }
                });
            }
        }
    });
    AbsolutePanel aPanel = new AbsolutePanel();
    aPanel.add(csVPanel);
    aPanel.add(kmlLBox, 20, 20);
    contentPanel.add(new HTML("<p>A simple KML example.</p>"));
    contentPanel.add(aPanel);
    initWidget(contentPanel);
}
Also used : ViewerPanel(org.cesiumjs.cs.widgets.ViewerPanel) Entity(org.cesiumjs.cs.datasources.Entity) KmlDataSource(org.cesiumjs.cs.datasources.KmlDataSource) AbsolutePanel(com.google.gwt.user.client.ui.AbsolutePanel) Viewer(org.cesiumjs.cs.widgets.Viewer) HTML(com.google.gwt.user.client.ui.HTML) KmlDataSourceOptions(org.cesiumjs.cs.datasources.options.KmlDataSourceOptions) CanvasElement(com.google.gwt.dom.client.CanvasElement) ChangeEvent(com.google.gwt.event.dom.client.ChangeEvent) ChangeHandler(com.google.gwt.event.dom.client.ChangeHandler) ListBox(com.google.gwt.user.client.ui.ListBox) Fulfill(org.cesiumjs.cs.promise.Fulfill)

Example 2 with Viewer

use of org.cesiumjs.cs.widgets.Viewer in project gwt-cs by iSergio.

the class Interpolation method buildPanel.

@Override
public void buildPanel() {
    csVPanel = new ViewerPanel();
    csVPanel.getViewer().scene().globe.enableLighting = false;
    CesiumTerrainProviderOptions cesiumTerrainProviderOptions = new CesiumTerrainProviderOptions();
    cesiumTerrainProviderOptions.url = "https://assets.agi.com/stk-terrain/world";
    cesiumTerrainProviderOptions.requestWaterMask = true;
    cesiumTerrainProviderOptions.requestVertexNormals = true;
    csVPanel.getViewer().terrainProvider = new CesiumTerrainProvider(cesiumTerrainProviderOptions);
    csVPanel.getViewer().scene().globe.depthTestAgainstTerrain = true;
    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 = 10;
    csVPanel.getViewer().timeline().zoomTo(_start, _stop);
    PositionProperty position = computeCirclularFlight(-112.110693, 36.0994841, 0.03);
    TimeIntervalOptions timeIntervalOptions = new TimeIntervalOptions();
    timeIntervalOptions.start = _start;
    timeIntervalOptions.stop = _stop;
    ModelGraphicsOptions modelGraphicsOptions = new ModelGraphicsOptions();
    modelGraphicsOptions.uri = new ConstantProperty<>(GWT.getModuleBaseURL() + "SampleData/models/CesiumAir/Cesium_Air.gltf");
    modelGraphicsOptions.minimumPixelSize = new ConstantProperty<>(64);
    PolylineGlowMaterialPropertyOptions polylineGlowMaterialPropertyOptions = new PolylineGlowMaterialPropertyOptions();
    polylineGlowMaterialPropertyOptions.glowPower = new ConstantProperty<>(0.1);
    polylineGlowMaterialPropertyOptions.color = new ConstantProperty<>(Color.YELLOW());
    PathGraphicsOptions pathGraphicsOptions = new PathGraphicsOptions();
    pathGraphicsOptions.resolution = new ConstantProperty<>(1);
    pathGraphicsOptions.material = new PolylineGlowMaterialProperty(polylineGlowMaterialPropertyOptions);
    pathGraphicsOptions.width = new ConstantProperty<>(10);
    EntityOptions entityOptions = new EntityOptions();
    entityOptions.availability = new TimeIntervalCollection(new TimeInterval[] { new TimeInterval(timeIntervalOptions) });
    entityOptions.position = position;
    entityOptions.orientation = new VelocityOrientationProperty(position);
    entityOptions.model = new ModelGraphics(modelGraphicsOptions);
    entityOptions.path = new PathGraphics(pathGraphicsOptions);
    _entity = csVPanel.getViewer().entities().add(entityOptions);
    ListBox interpolationsLBox = new ListBox();
    interpolationsLBox.addItem("Interpolation: Linear Approximation", "0");
    interpolationsLBox.addItem("Interpolation: Lagrange Polynomial Approximation", "1");
    interpolationsLBox.addItem("Interpolation: Hermite Polynomial Approximation", "2");
    interpolationsLBox.addChangeHandler(new ChangeHandler() {

        @Override
        public void onChange(ChangeEvent changeEvent) {
            ListBox source = (ListBox) changeEvent.getSource();
            SampledPropertyInterpolationOptions sampledPropertyInterpolationOptions = new SampledPropertyInterpolationOptions();
            switch(source.getSelectedValue()) {
                case "0":
                    sampledPropertyInterpolationOptions.interpolationDegree = 1;
                    sampledPropertyInterpolationOptions.interpolationAlgorithm = LinearApproximation.instance();
                    ((SampledPositionProperty) _entity.position).setInterpolationOptions(sampledPropertyInterpolationOptions);
                    break;
                case "1":
                    sampledPropertyInterpolationOptions.interpolationDegree = 5;
                    sampledPropertyInterpolationOptions.interpolationAlgorithm = LagrangePolynomialApproximation.instance();
                    ((SampledPositionProperty) _entity.position).setInterpolationOptions(sampledPropertyInterpolationOptions);
                    break;
                case "2":
                    sampledPropertyInterpolationOptions.interpolationDegree = 2;
                    sampledPropertyInterpolationOptions.interpolationAlgorithm = HermitePolynomialApproximation.instance();
                    ((SampledPositionProperty) _entity.position).setInterpolationOptions(sampledPropertyInterpolationOptions);
                    break;
                default:
                    break;
            }
        }
    });
    Button viewTopDownBtn = new Button("View Top Down");
    viewTopDownBtn.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent clickEvent) {
            Viewer viewer = csVPanel.getViewer();
            viewer.trackedEntity = (Entity) JsObject.undefined();
            viewer.zoomTo(viewer.entities(), new HeadingPitchRange(0, Math.toRadians(-90), 0));
        }
    });
    Button viewSideBtn = new Button("View Side");
    viewSideBtn.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent clickEvent) {
            Viewer viewer = csVPanel.getViewer();
            viewer.trackedEntity = (Entity) JsObject.undefined();
            viewer.zoomTo(viewer.entities(), new HeadingPitchRange(Math.toRadians(-90), Math.toRadians(-15), 7500.0));
        }
    });
    Button viewAircraftBtn = new Button("View Aircraft");
    viewAircraftBtn.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent clickEvent) {
            Viewer viewer = csVPanel.getViewer();
            viewer.trackedEntity = _entity;
        }
    });
    HorizontalPanel btnHPanel = new HorizontalPanel();
    btnHPanel.setSpacing(5);
    btnHPanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);
    btnHPanel.add(interpolationsLBox);
    btnHPanel.add(viewTopDownBtn);
    btnHPanel.add(viewSideBtn);
    btnHPanel.add(viewAircraftBtn);
    AbsolutePanel aPanel = new AbsolutePanel();
    aPanel.add(csVPanel);
    aPanel.add(btnHPanel, 20, 20);
    contentPanel.add(new HTML("<p>This example shows simple Cesium application</p>"));
    contentPanel.add(aPanel);
    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) PolylineGlowMaterialPropertyOptions(org.cesiumjs.cs.datasources.properties.options.PolylineGlowMaterialPropertyOptions) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) Viewer(org.cesiumjs.cs.widgets.Viewer) JsDate(org.cesiumjs.cs.js.JsDate) ModelGraphics(org.cesiumjs.cs.datasources.graphics.ModelGraphics) EntityOptions(org.cesiumjs.cs.datasources.options.EntityOptions) ChangeHandler(com.google.gwt.event.dom.client.ChangeHandler) CesiumTerrainProvider(org.cesiumjs.cs.core.providers.CesiumTerrainProvider) ViewerPanel(org.cesiumjs.cs.widgets.ViewerPanel) TimeIntervalOptions(org.cesiumjs.cs.core.options.TimeIntervalOptions) TimeIntervalCollection(org.cesiumjs.cs.collections.TimeIntervalCollection) PathGraphics(org.cesiumjs.cs.datasources.graphics.PathGraphics) PathGraphicsOptions(org.cesiumjs.cs.datasources.graphics.options.PathGraphicsOptions) ModelGraphicsOptions(org.cesiumjs.cs.datasources.graphics.options.ModelGraphicsOptions) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) ChangeEvent(com.google.gwt.event.dom.client.ChangeEvent)

Aggregations

ChangeEvent (com.google.gwt.event.dom.client.ChangeEvent)2 ChangeHandler (com.google.gwt.event.dom.client.ChangeHandler)2 Entity (org.cesiumjs.cs.datasources.Entity)2 Viewer (org.cesiumjs.cs.widgets.Viewer)2 ViewerPanel (org.cesiumjs.cs.widgets.ViewerPanel)2 CanvasElement (com.google.gwt.dom.client.CanvasElement)1 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)1 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)1 AbsolutePanel (com.google.gwt.user.client.ui.AbsolutePanel)1 HTML (com.google.gwt.user.client.ui.HTML)1 ListBox (com.google.gwt.user.client.ui.ListBox)1 TimeIntervalCollection (org.cesiumjs.cs.collections.TimeIntervalCollection)1 TimeIntervalOptions (org.cesiumjs.cs.core.options.TimeIntervalOptions)1 CesiumTerrainProvider (org.cesiumjs.cs.core.providers.CesiumTerrainProvider)1 CesiumTerrainProviderOptions (org.cesiumjs.cs.core.providers.options.CesiumTerrainProviderOptions)1 KmlDataSource (org.cesiumjs.cs.datasources.KmlDataSource)1 ModelGraphics (org.cesiumjs.cs.datasources.graphics.ModelGraphics)1 PathGraphics (org.cesiumjs.cs.datasources.graphics.PathGraphics)1 ModelGraphicsOptions (org.cesiumjs.cs.datasources.graphics.options.ModelGraphicsOptions)1 PathGraphicsOptions (org.cesiumjs.cs.datasources.graphics.options.PathGraphicsOptions)1