Search in sources :

Example 11 with ModelGraphics

use of org.cesiumjs.cs.datasources.graphics.ModelGraphics 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)

Aggregations

ModelGraphics (org.cesiumjs.cs.datasources.graphics.ModelGraphics)11 ModelGraphicsOptions (org.cesiumjs.cs.datasources.graphics.options.ModelGraphicsOptions)11 EntityOptions (org.cesiumjs.cs.datasources.options.EntityOptions)11 ViewerPanel (org.cesiumjs.cs.widgets.ViewerPanel)7 ConstantPositionProperty (org.cesiumjs.cs.datasources.properties.ConstantPositionProperty)6 ChangeEvent (com.google.gwt.event.dom.client.ChangeEvent)5 Entity (org.cesiumjs.cs.datasources.Entity)5 ChangeHandler (com.google.gwt.event.dom.client.ChangeHandler)4 CesiumTerrainProvider (org.cesiumjs.cs.core.providers.CesiumTerrainProvider)4 CesiumTerrainProviderOptions (org.cesiumjs.cs.core.providers.options.CesiumTerrainProviderOptions)4 ViewerOptions (org.cesiumjs.cs.widgets.options.ViewerOptions)4 ValueChangeEvent (com.google.gwt.event.logical.shared.ValueChangeEvent)3 HTML (com.google.gwt.user.client.ui.HTML)3 TimeIntervalCollection (org.cesiumjs.cs.collections.TimeIntervalCollection)3 Cartesian3 (org.cesiumjs.cs.core.Cartesian3)3 TimeIntervalOptions (org.cesiumjs.cs.core.options.TimeIntervalOptions)3 ColorMaterialProperty (org.cesiumjs.cs.datasources.properties.ColorMaterialProperty)3 ValueChangeHandler (com.google.gwt.event.logical.shared.ValueChangeHandler)2 AbsolutePanel (com.google.gwt.user.client.ui.AbsolutePanel)2 ClippingPlaneCollection (org.cesiumjs.cs.collections.ClippingPlaneCollection)2