Search in sources :

Example 6 with LabelGraphicsOptions

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

the class Labels method offsetByDistance.

private void offsetByDistance() {
    final JsImage image = new JsImage();
    image.onload = new JsImage.Listener() {

        @Override
        public void function() {
            BillboardGraphicsOptions billboardGraphicsOptions = new BillboardGraphicsOptions();
            billboardGraphicsOptions.scaleByDistance = new ConstantProperty<>(new NearFarScalar(1.5e2, 5.0, 1.5e7, 0.5));
            billboardGraphicsOptions.image = new ConstantProperty<>(image);
            LabelGraphicsOptions labelGraphicsOptions = new LabelGraphicsOptions();
            labelGraphicsOptions.text = new ConstantProperty<>("Label on top of scaling billboard");
            labelGraphicsOptions.font = new ConstantProperty<>("20px sans-serif");
            labelGraphicsOptions.showBackground = new ConstantProperty<>(true);
            labelGraphicsOptions.horizontalOrigin = new ConstantProperty<>(HorizontalOrigin.CENTER());
            labelGraphicsOptions.pixelOffset = new ConstantProperty<>(new Cartesian2(0.0, -image.height));
            labelGraphicsOptions.pixelOffsetScaleByDistance = new ConstantProperty<>(new NearFarScalar(1.5e2, 3.0, 1.5e7, 0.5));
            EntityOptions entityOptions = new EntityOptions();
            entityOptions.position = new ConstantPositionProperty(Cartesian3.fromDegrees(-75.1641667, 39.9522222));
            entityOptions.billboard = new BillboardGraphics(billboardGraphicsOptions);
            entityOptions.label = new LabelGraphics(labelGraphicsOptions);
            csVPanel.getViewer().entities().add(entityOptions);
        }
    };
    image.src = GWT.getModuleBaseURL() + "images/facility.gif";
}
Also used : JsImage(org.cesiumjs.cs.js.JsImage) ConstantProperty(org.cesiumjs.cs.datasources.properties.ConstantProperty) Cartesian2(org.cesiumjs.cs.core.Cartesian2) BillboardGraphicsOptions(org.cesiumjs.cs.datasources.graphics.options.BillboardGraphicsOptions) BillboardGraphics(org.cesiumjs.cs.datasources.graphics.BillboardGraphics) LabelGraphics(org.cesiumjs.cs.datasources.graphics.LabelGraphics) NearFarScalar(org.cesiumjs.cs.core.NearFarScalar) ConstantPositionProperty(org.cesiumjs.cs.datasources.properties.ConstantPositionProperty) LabelGraphicsOptions(org.cesiumjs.cs.datasources.graphics.options.LabelGraphicsOptions) EntityOptions(org.cesiumjs.cs.datasources.options.EntityOptions)

Example 7 with LabelGraphicsOptions

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

the class Labels method setProperties.

private void setProperties() {
    LabelGraphicsOptions labelGraphicsOptions = new LabelGraphicsOptions();
    labelGraphicsOptions.text = new ConstantProperty<>("Philadelphia");
    EntityOptions entityOptions = new EntityOptions();
    entityOptions.position = new ConstantPositionProperty(Cartesian3.fromDegrees(-75.1641667, 39.9522222, 300000.0));
    entityOptions.label = new LabelGraphics(labelGraphicsOptions);
    Entity entity = csVPanel.getViewer().entities().add(entityOptions);
    entity.label.scale = new ConstantProperty<>(2.0);
    entity.label.showBackground = new ConstantProperty<>(true);
}
Also used : Entity(org.cesiumjs.cs.datasources.Entity) LabelGraphics(org.cesiumjs.cs.datasources.graphics.LabelGraphics) ConstantPositionProperty(org.cesiumjs.cs.datasources.properties.ConstantPositionProperty) LabelGraphicsOptions(org.cesiumjs.cs.datasources.graphics.options.LabelGraphicsOptions) EntityOptions(org.cesiumjs.cs.datasources.options.EntityOptions)

Example 8 with LabelGraphicsOptions

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

the class Labels method setFont.

private void setFont() {
    LabelGraphicsOptions labelGraphicsOptions = new LabelGraphicsOptions();
    labelGraphicsOptions.text = new ConstantProperty<>("Philadelphia");
    labelGraphicsOptions.font = new ConstantProperty<>("24px Helvetica");
    labelGraphicsOptions.fillColor = new ConstantProperty<>(Color.SKYBLUE());
    labelGraphicsOptions.outlineColor = new ConstantProperty<>(Color.BLACK());
    labelGraphicsOptions.outlineWidth = new ConstantProperty<>(2);
    labelGraphicsOptions.style = new ConstantProperty<>(LabelStyle.FILL_AND_OUTLINE());
    EntityOptions entityOptions = new EntityOptions();
    entityOptions.position = new ConstantPositionProperty(Cartesian3.fromDegrees(-75.1641667, 39.9522222));
    entityOptions.label = new LabelGraphics(labelGraphicsOptions);
    csVPanel.getViewer().entities().add(entityOptions);
}
Also used : LabelGraphics(org.cesiumjs.cs.datasources.graphics.LabelGraphics) ConstantPositionProperty(org.cesiumjs.cs.datasources.properties.ConstantPositionProperty) LabelGraphicsOptions(org.cesiumjs.cs.datasources.graphics.options.LabelGraphicsOptions) EntityOptions(org.cesiumjs.cs.datasources.options.EntityOptions)

Example 9 with LabelGraphicsOptions

use of org.cesiumjs.cs.datasources.graphics.options.LabelGraphicsOptions 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 10 with LabelGraphicsOptions

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

Aggregations

LabelGraphics (org.cesiumjs.cs.datasources.graphics.LabelGraphics)10 LabelGraphicsOptions (org.cesiumjs.cs.datasources.graphics.options.LabelGraphicsOptions)10 EntityOptions (org.cesiumjs.cs.datasources.options.EntityOptions)10 ConstantPositionProperty (org.cesiumjs.cs.datasources.properties.ConstantPositionProperty)8 Entity (org.cesiumjs.cs.datasources.Entity)4 BigDecimal (java.math.BigDecimal)3 NearFarScalar (org.cesiumjs.cs.core.NearFarScalar)3 MouseMoveEvent (org.cesiumjs.cs.core.events.MouseMoveEvent)2 BillboardGraphics (org.cesiumjs.cs.datasources.graphics.BillboardGraphics)2 BillboardGraphicsOptions (org.cesiumjs.cs.datasources.graphics.options.BillboardGraphicsOptions)2 Cartesian2 (org.cesiumjs.cs.core.Cartesian2)1 ModelGraphics (org.cesiumjs.cs.datasources.graphics.ModelGraphics)1 ModelGraphicsOptions (org.cesiumjs.cs.datasources.graphics.options.ModelGraphicsOptions)1 ConstantProperty (org.cesiumjs.cs.datasources.properties.ConstantProperty)1 JsImage (org.cesiumjs.cs.js.JsImage)1 Camera (org.cesiumjs.cs.scene.Camera)1 Scene (org.cesiumjs.cs.scene.Scene)1