Search in sources :

Example 26 with Entity

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

the class Billboards method setBillboardProperties.

private void setBillboardProperties() {
    BillboardGraphicsOptions billboardGraphicsOptions = new BillboardGraphicsOptions();
    // default: undefined
    billboardGraphicsOptions.image = new ConstantProperty<>(GWT.getModuleBaseURL() + "images/Cesium_Logo_overlay.png");
    // default
    billboardGraphicsOptions.show = new ConstantProperty<>(true);
    // default: (0, 0)
    billboardGraphicsOptions.pixelOffset = new ConstantProperty<>(new Cartesian2(0, -50));
    // default
    billboardGraphicsOptions.eyeOffset = new ConstantProperty<>(new Cartesian3(0, 0, 0));
    // default
    billboardGraphicsOptions.horizontalOrigin = new ConstantProperty<>(HorizontalOrigin.CENTER());
    // default: CENTER
    billboardGraphicsOptions.verticalOrigin = new ConstantProperty<>(VerticalOrigin.BOTTOM());
    // default: 1.0
    billboardGraphicsOptions.scale = new ConstantProperty<>(2.0);
    // default: WHITE
    billboardGraphicsOptions.color = new ConstantProperty<>(Color.LIME());
    // default: 0.0
    billboardGraphicsOptions.rotation = new ConstantProperty<>(Math.PI_OVER_FOUR());
    // default
    billboardGraphicsOptions.alignedAxis = new ConstantProperty<>(Cartesian3.ZERO());
    // default: undefined
    billboardGraphicsOptions.width = new ConstantProperty<>(100);
    // default: undefined
    billboardGraphicsOptions.height = new ConstantProperty<>(25);
    EntityOptions entityOptions = new EntityOptions();
    entityOptions.position = new ConstantPositionProperty(Cartesian3.fromDegrees(-75.59777, 40.03883));
    entityOptions.billboard = new BillboardGraphics(billboardGraphicsOptions);
    csVPanel.getViewer().entities().add(new Entity(entityOptions));
}
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)

Example 27 with Entity

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

the class Picking method pickPosition.

private void pickPosition() {
    ModelGraphicsOptions modelGraphicsOptions = new ModelGraphicsOptions();
    modelGraphicsOptions.uri = new ConstantProperty<>(GWT.getModuleBaseURL() + "SampleData/models/CesiumMilkTruck/CesiumMilkTruck-kmc.gltf");
    EntityOptions entityOptions = new EntityOptions();
    entityOptions.position = new ConstantPositionProperty(Cartesian3.fromDegrees(-123.0744619, 44.0503706));
    entityOptions.name = "milktruck";
    entityOptions.model = new ModelGraphics(modelGraphicsOptions);
    final Entity modelEntity = viewerPanel.getViewer().entities().add(new Entity(entityOptions));
    viewerPanel.getViewer().zoomTo(modelEntity);
    LabelGraphicsOptions labelGraphicsOptions = new LabelGraphicsOptions();
    labelGraphicsOptions.show = new ConstantProperty<>(false);
    labelGraphicsOptions.horizontalOrigin = new ConstantProperty<>(HorizontalOrigin.LEFT());
    entityOptions = new EntityOptions();
    entityOptions.label = new LabelGraphics(labelGraphicsOptions);
    final Entity labelEntity = viewerPanel.getViewer().entities().add(new Entity(entityOptions));
    _handler = new ScreenSpaceEventHandler(viewerPanel.getViewer().scene().canvas());
    _handler.setInputAction(new ScreenSpaceEventHandler.Listener<MouseMoveEvent>() {

        @Override
        public void function(MouseMoveEvent event) {
            boolean foundPosition = false;
            Scene scene = viewerPanel.getViewer().scene();
            PickedObject pickedObject = scene.pick(event.endPosition);
            if (scene.pickPositionSupported() && pickedObject != null && pickedObject.id == modelEntity) {
                Cartesian3 cartesian = viewerPanel.getViewer().scene().pickPosition(event.endPosition);
                if (cartesian != null) {
                    Cartographic cartographic = Cartographic.fromCartesian(cartesian);
                    String lon = new BigDecimal(Math.toDegrees(cartographic.longitude)).setScale(2, RoundingMode.HALF_EVEN).toString();
                    String lat = new BigDecimal(Math.toDegrees(cartographic.latitude)).setScale(2, RoundingMode.HALF_EVEN).toString();
                    String height = new BigDecimal(cartographic.height).setScale(2, RoundingMode.HALF_EVEN).toString();
                    labelEntity.position = new ConstantPositionProperty(cartesian);
                    labelEntity.label.show = new ConstantProperty<>(true);
                    labelEntity.label.text = new ConstantProperty<>("(" + lon + ", " + lat + ", " + height + ")");
                    Camera camera = scene.camera();
                    labelEntity.label.eyeOffset = new ConstantProperty<>(new Cartesian3(0.0, 0.0, ((PerspectiveFrustum) camera.frustum).near * 1.5 - (double) Cartesian3.distance(cartesian, camera.position)));
                    foundPosition = true;
                }
            }
            if (!foundPosition) {
                labelEntity.label.show = new ConstantProperty<>(false);
            }
        }
    }, ScreenSpaceEventType.MOUSE_MOVE());
}
Also used : Entity(org.cesiumjs.cs.datasources.Entity) MouseMoveEvent(org.cesiumjs.cs.core.events.MouseMoveEvent) LabelGraphics(org.cesiumjs.cs.datasources.graphics.LabelGraphics) Scene(org.cesiumjs.cs.scene.Scene) ModelGraphics(org.cesiumjs.cs.datasources.graphics.ModelGraphics) EntityOptions(org.cesiumjs.cs.datasources.options.EntityOptions) BigDecimal(java.math.BigDecimal) ModelGraphicsOptions(org.cesiumjs.cs.datasources.graphics.options.ModelGraphicsOptions) Camera(org.cesiumjs.cs.scene.Camera) LabelGraphicsOptions(org.cesiumjs.cs.datasources.graphics.options.LabelGraphicsOptions)

Example 28 with Entity

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

the class Picking method drillDownPicking.

private void drillDownPicking() {
    _pickedEntities = new EntityCollection();
    _pickColor = Color.YELLOW().withAlpha(0.5f);
    PolygonGraphicsOptions polygonGraphicsOptions = new PolygonGraphicsOptions();
    polygonGraphicsOptions.hierarchy = new ConstantProperty<>(new PolygonHierarchy(Cartesian3.fromDegreesArray(new double[] { -70.0, 30.0, -60.0, 30.0, -60.0, 40.0, -70.0, 40.0 })));
    polygonGraphicsOptions.height = new ConstantProperty<>(0);
    EntityOptions entityOptions = new EntityOptions();
    entityOptions.polygon = new PolygonGraphics(polygonGraphicsOptions);
    Entity red = viewerPanel.getViewer().entities().add(new Entity(entityOptions));
    makeProperty(red, Color.RED().withAlpha(0.5f));
    polygonGraphicsOptions = new PolygonGraphicsOptions();
    polygonGraphicsOptions.hierarchy = new ConstantProperty<>(new PolygonHierarchy(Cartesian3.fromDegreesArray(new double[] { -75.0, 34.0, -63.0, 34.0, -63.0, 40.0, -75.0, 40.0 })));
    polygonGraphicsOptions.height = new ConstantProperty<>(0);
    entityOptions = new EntityOptions();
    entityOptions.polygon = new PolygonGraphics(polygonGraphicsOptions);
    Entity blue = viewerPanel.getViewer().entities().add(new Entity(entityOptions));
    makeProperty(blue, Color.BLUE().withAlpha(0.5f));
    polygonGraphicsOptions = new PolygonGraphicsOptions();
    polygonGraphicsOptions.hierarchy = new ConstantProperty<>(new PolygonHierarchy(Cartesian3.fromDegreesArray(new double[] { -67.0, 36.0, -55.0, 36.0, -55.0, 30.0, -67.0, 30.0 })));
    polygonGraphicsOptions.height = new ConstantProperty<>(0);
    entityOptions = new EntityOptions();
    entityOptions.polygon = new PolygonGraphics(polygonGraphicsOptions);
    Entity green = viewerPanel.getViewer().entities().add(new Entity(entityOptions));
    makeProperty(green, Color.GREEN().withAlpha(0.5f));
    // Move the primitive that the mouse is over to the top.
    _handler = new ScreenSpaceEventHandler(viewerPanel.getViewer().scene().canvas());
    _handler.setInputAction(new ScreenSpaceEventHandler.Listener<MouseMoveEvent>() {

        @Override
        public void function(MouseMoveEvent event) {
            PickedObject[] pickedObjects = viewerPanel.getViewer().scene().drillPick(event.endPosition);
            if (pickedObjects != null) {
                _pickedEntities.removeAll();
                for (PickedObject pickedObject : pickedObjects) {
                    Entity entity = (Entity) pickedObject.id;
                    _pickedEntities.add(entity);
                }
            }
        }
    }, ScreenSpaceEventType.MOUSE_MOVE());
}
Also used : Entity(org.cesiumjs.cs.datasources.Entity) MouseMoveEvent(org.cesiumjs.cs.core.events.MouseMoveEvent) EntityCollection(org.cesiumjs.cs.collections.EntityCollection) PolygonGraphicsOptions(org.cesiumjs.cs.datasources.graphics.options.PolygonGraphicsOptions) PolygonGraphics(org.cesiumjs.cs.datasources.graphics.PolygonGraphics) EntityOptions(org.cesiumjs.cs.datasources.options.EntityOptions)

Example 29 with Entity

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

the class Picking method showCartographicPositionOnMouseOver.

public void showCartographicPositionOnMouseOver() {
    LabelGraphicsOptions labelGraphicsOptions = new LabelGraphicsOptions();
    labelGraphicsOptions.show = new ConstantProperty<>(true);
    EntityOptions entityOptions = new EntityOptions();
    entityOptions.label = new LabelGraphics(labelGraphicsOptions);
    final Entity entity = viewerPanel.getViewer().entities().add(new Entity(entityOptions));
    _handler = new ScreenSpaceEventHandler(viewerPanel.getViewer().scene().canvas());
    _handler.setInputAction(new ScreenSpaceEventHandler.Listener<MouseMoveEvent>() {

        @Override
        public void function(MouseMoveEvent event) {
            Cartesian3 cartesian = viewerPanel.getViewer().camera.pickEllipsoid(event.endPosition, viewerPanel.getViewer().scene().globe.ellipsoid);
            if (cartesian != null) {
                Cartographic cartographic = Cartographic.fromCartesian(cartesian);
                String lon = new BigDecimal(Math.toDegrees(cartographic.longitude)).setScale(2, RoundingMode.HALF_EVEN).toString();
                String lat = new BigDecimal(Math.toDegrees(cartographic.latitude)).setScale(2, RoundingMode.HALF_EVEN).toString();
                entity.position = new ConstantPositionProperty(cartesian);
                entity.label.show = new ConstantProperty<>(true);
                entity.label.text = new ConstantProperty<>("(" + lon + ", " + lat + ")");
            } else {
                entity.label.show = new ConstantProperty<>(false);
            }
        }
    }, ScreenSpaceEventType.MOUSE_MOVE());
}
Also used : Entity(org.cesiumjs.cs.datasources.Entity) MouseMoveEvent(org.cesiumjs.cs.core.events.MouseMoveEvent) LabelGraphics(org.cesiumjs.cs.datasources.graphics.LabelGraphics) EntityOptions(org.cesiumjs.cs.datasources.options.EntityOptions) BigDecimal(java.math.BigDecimal) LabelGraphicsOptions(org.cesiumjs.cs.datasources.graphics.options.LabelGraphicsOptions)

Example 30 with Entity

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

the class Shadows method setLocation.

public void setLocation(Location location) {
    double lon = location.lon;
    double lat = location.lat;
    double height = location.height;
    for (int i = 0; i < csVPanel.getViewer().entities().values().length; ++i) {
        Entity entity = csVPanel.getViewer().entities().values()[i];
        entity.position = new ConstantPositionProperty(Cartesian3.fromRadians(lon, lat, height + JsObject.getNumber(entity, "height").doubleValue()));
    }
    csVPanel.getViewer().clock().currentTime = new JulianDate(location.date);
    csVPanel.getViewer().clock().multiplier = 1.0;
}
Also used : JulianDate(org.cesiumjs.cs.core.JulianDate) Entity(org.cesiumjs.cs.datasources.Entity) ConstantPositionProperty(org.cesiumjs.cs.datasources.properties.ConstantPositionProperty)

Aggregations

Entity (org.cesiumjs.cs.datasources.Entity)31 EntityOptions (org.cesiumjs.cs.datasources.options.EntityOptions)27 ConstantPositionProperty (org.cesiumjs.cs.datasources.properties.ConstantPositionProperty)16 ViewerPanel (org.cesiumjs.cs.widgets.ViewerPanel)13 BillboardGraphics (org.cesiumjs.cs.datasources.graphics.BillboardGraphics)12 BillboardGraphicsOptions (org.cesiumjs.cs.datasources.graphics.options.BillboardGraphicsOptions)12 HTML (com.google.gwt.user.client.ui.HTML)9 MouseMoveEvent (org.cesiumjs.cs.core.events.MouseMoveEvent)5 ModelGraphics (org.cesiumjs.cs.datasources.graphics.ModelGraphics)5 ModelGraphicsOptions (org.cesiumjs.cs.datasources.graphics.options.ModelGraphicsOptions)5 ColorMaterialProperty (org.cesiumjs.cs.datasources.properties.ColorMaterialProperty)5 ConstantProperty (org.cesiumjs.cs.datasources.properties.ConstantProperty)5 ViewerOptions (org.cesiumjs.cs.widgets.options.ViewerOptions)5 ChangeEvent (com.google.gwt.event.dom.client.ChangeEvent)4 ChangeHandler (com.google.gwt.event.dom.client.ChangeHandler)4 AbsolutePanel (com.google.gwt.user.client.ui.AbsolutePanel)4 CesiumTerrainProvider (org.cesiumjs.cs.core.providers.CesiumTerrainProvider)4 CesiumTerrainProviderOptions (org.cesiumjs.cs.core.providers.options.CesiumTerrainProviderOptions)4 LabelGraphics (org.cesiumjs.cs.datasources.graphics.LabelGraphics)4 Fulfill (org.cesiumjs.cs.promise.Fulfill)4