use of org.cesiumjs.cs.datasources.graphics.options.ModelGraphicsOptions 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());
}
Aggregations