use of org.cesiumjs.cs.core.events.MouseMoveEvent in project gwt-cs by iSergio.
the class Picking method pickEntity.
private void pickEntity() {
BillboardGraphicsOptions billboardGraphicsOptions = new BillboardGraphicsOptions();
billboardGraphicsOptions.image = new ConstantProperty<>(GWT.getModuleBaseURL() + "images/Cesium_Logo_overlay.png");
EntityOptions entityOptions = new EntityOptions();
entityOptions.position = new ConstantPositionProperty(Cartesian3.fromDegrees(-75.59777, 40.03883));
entityOptions.billboard = new BillboardGraphics(billboardGraphicsOptions);
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) {
PickedObject pickedObject = viewerPanel.getViewer().scene().pick(event.endPosition);
if (pickedObject != null && pickedObject.id == entity) {
entity.billboard.scale = new ConstantProperty<>(2.0);
entity.billboard.color = new ConstantProperty<>(Color.YELLOW());
} else {
entity.billboard.scale = new ConstantProperty<>(1.0);
entity.billboard.color = new ConstantProperty<>(Color.WHITE());
}
}
}, ScreenSpaceEventType.MOUSE_MOVE());
}
use of org.cesiumjs.cs.core.events.MouseMoveEvent in project gwt-cs by iSergio.
the class Tiles3DClippingPlanes method buildPanel.
@Override
public void buildPanel() {
ViewerOptions viewerOptions = new ViewerOptions();
viewerOptions.skyAtmosphere = null;
viewerOptions.infoBox = false;
viewerOptions.selectionIndicator = false;
csVPanel = new ViewerPanel(viewerOptions);
ScreenSpaceEventHandler downHandler = new ScreenSpaceEventHandler(csVPanel.getViewer().canvas());
downHandler.setInputAction(new ScreenSpaceEventHandler.Listener() {
@Override
public void function(Object event) {
MouseDownEvent mouseDownEvent = (MouseDownEvent) event;
PickedObject pickedObject = csVPanel.getViewer().scene().pick(mouseDownEvent.position);
if (!Cesium.defined(pickedObject)) {
return;
}
if (!(pickedObject.id instanceof Entity)) {
return;
}
if (Cesium.defined(pickedObject) && Cesium.defined(pickedObject.id) && Cesium.defined(((Entity) pickedObject.id).plane)) {
selectedPlane = ((Entity) pickedObject.id).plane;
selectedPlane.material = new ColorMaterialProperty(Color.WHITE().withAlpha(0.05f));
selectedPlane.outlineColor = new ConstantProperty<>(Color.WHITE());
csVPanel.getViewer().scene().screenSpaceCameraController().enableInputs = false;
}
}
}, ScreenSpaceEventType.LEFT_DOWN());
ScreenSpaceEventHandler upHandler = new ScreenSpaceEventHandler(csVPanel.getViewer().canvas());
upHandler.setInputAction(new ScreenSpaceEventHandler.Listener() {
@Override
public void function(Object event) {
if (Cesium.defined(selectedPlane)) {
selectedPlane.material = new ColorMaterialProperty(Color.WHITE().withAlpha(0.1f));
selectedPlane.outlineColor = new ConstantProperty<>(Color.WHITE());
selectedPlane = (PlaneGraphics) JsObject.undefined();
}
csVPanel.getViewer().scene().screenSpaceCameraController().enableInputs = true;
}
}, ScreenSpaceEventType.LEFT_UP());
ScreenSpaceEventHandler moveHandler = new ScreenSpaceEventHandler(csVPanel.getViewer().scene().canvas());
moveHandler.setInputAction(new ScreenSpaceEventHandler.Listener() {
@Override
public void function(Object event) {
if (Cesium.defined(selectedPlane)) {
MouseMoveEvent mouseMoveEvent = (MouseMoveEvent) event;
double deltaY = mouseMoveEvent.startPosition.y - mouseMoveEvent.endPosition.y;
targetY += deltaY;
}
}
}, ScreenSpaceEventType.MOUSE_MOVE());
ListBox clipObjectLBox = new ListBox();
clipObjectLBox.addItem("BIM");
clipObjectLBox.addItem("Point Cloud");
clipObjectLBox.addItem("Instanced");
clipObjectLBox.addItem("Model");
clipObjectLBox.addChangeHandler(new ChangeHandler() {
@Override
public void onChange(ChangeEvent event) {
reset();
ListBox source = (ListBox) event.getSource();
switch(source.getSelectedIndex()) {
case 0:
loadTileset(bimUrl);
break;
case 1:
loadTileset(pointCloudUrl);
tileset.readyPromise().then(new Fulfill<Cesium3DTileset>() {
@Override
public void onFulfilled(Cesium3DTileset value) {
tileset.clippingPlanes.modelMatrix = Transforms.eastNorthUpToFixedFrame(tileset.boundingSphere().center);
}
});
break;
case 2:
loadTileset(instancedUrl);
tileset.readyPromise().then(new Fulfill<Cesium3DTileset>() {
@Override
public void onFulfilled(Cesium3DTileset value) {
tileset.clippingPlanes.modelMatrix = Transforms.eastNorthUpToFixedFrame(tileset.boundingSphere().center);
}
});
break;
case 3:
loadModel(modelUrl);
break;
default:
break;
}
}
});
boundingVolumeCBox = new CheckBox("Show bounding volume");
boundingVolumeCBox.setValue(false);
boundingVolumeCBox.getElement().getStyle().setColor("white");
boundingVolumeCBox.addValueChangeHandler(new ValueChangeHandler<Boolean>() {
@Override
public void onValueChange(ValueChangeEvent<Boolean> event) {
if (Cesium.defined(tileset)) {
tileset.debugShowBoundingVolume = event.getValue();
}
}
});
edgeStylingCBox = new CheckBox("Enable edge styling");
edgeStylingCBox.setValue(true);
edgeStylingCBox.getElement().getStyle().setColor("white");
edgeStylingCBox.addValueChangeHandler(new ValueChangeHandler<Boolean>() {
@Override
public void onValueChange(ValueChangeEvent<Boolean> event) {
double edgeWidth = event.getValue() ? 1.0 : 0.0;
if (Cesium.defined(tileset)) {
tileset.clippingPlanes.edgeWidth = edgeWidth;
}
if (Cesium.defined(modelEntityClippingPlanes)) {
modelEntityClippingPlanes.edgeWidth = edgeWidth;
}
}
});
AbsolutePanel aPanel = new AbsolutePanel();
aPanel.add(csVPanel);
aPanel.add(clipObjectLBox, 20, 20);
aPanel.add(boundingVolumeCBox, 20, 50);
aPanel.add(edgeStylingCBox, 20, 70);
contentPanel.add(new HTML("<p>User-defined clipping planes applied to a batched 3D Tileset, point cloud, and model.</p>"));
contentPanel.add(aPanel);
initWidget(contentPanel);
loadTileset(bimUrl);
}
use of org.cesiumjs.cs.core.events.MouseMoveEvent in project gwt-cs by iSergio.
the class DrawInteraction method modifyDrawing.
private void modifyDrawing(Object event) {
if (!active) {
return;
}
MouseMoveEvent mouseMoveEvent = (MouseMoveEvent) event;
Cartesian2 position = mouseMoveEvent.endPosition;
if (position == null) {
return;
}
Cartesian3 cartesian;
if (scene.mode.equals(SceneMode.SCENE3D())) {
Ray ray = scene.camera().getPickRay(mouseMoveEvent.endPosition);
cartesian = scene.globe.pick(ray, scene);
} else {
cartesian = scene.camera().pickEllipsoid(mouseMoveEvent.endPosition, scene.globe.ellipsoid);
}
if (cartesian == null) {
return;
}
if (pointPrimitive != null) {
pointPrimitive.position = cartesian;
} else if (pointBillboard != null) {
pointBillboard.position = cartesian;
}
if (type == PrimitiveType.RECTANGLE) {
if (rectangle != null) {
Cartographic secondPoint = scene.globe.ellipsoid.cartesianToCartographic(cartesian);
Rectangle value = getExtent(firstPoint, secondPoint);
updateExtent(value);
}
} else if (type == PrimitiveType.POLYGON || type == PrimitiveType.CORRIDOR) {
if (positions.size() == 0) {
return;
}
positions.remove(positions.size() - 1);
cartesian.y += (1 + Math.random());
positions.add(cartesian);
if (positions.size() >= options.minPoints) {
if (type == PrimitiveType.POLYGON) {
polygon.setPositions(positions.toArray(new Cartesian3[positions.size()]));
polygon.createPrimitive = true;
} else {
corridor.setPositions(positions.toArray(new Cartesian3[positions.size()]));
corridor.createPrimitive = true;
}
}
if (isShiftKeyDown && isLeftDown) {
// Free hand mode
positions.add(cartesian);
// Not need display all markers ?
// markers.add(cartesian);
} else {
if (options.markerType == MarkerType.POINT_PRIMITIVE) {
markers.getPoint(markers.count() - 1).position = cartesian;
} else if (options.markerType == MarkerType.BILLBOARD_GRAPHIC) {
markers.getBillboard(markers.count() - 1).position = cartesian;
}
}
} else if (type == PrimitiveType.CIRCLE) {
if (circle == null) {
return;
}
circle.setRadius(Cartesian3.distance(circle.getCenter(), cartesian));
// Update radius
positions.remove(positions.size() - 1);
cartesian.y += (1 + Math.random());
positions.add(cartesian);
if (positions.size() >= options.minPoints) {
radius.setPositions(positions.toArray(new Cartesian3[positions.size()]));
radius.createPrimitive = true;
}
markers.update(new Cartesian3[] { cartesian });
}
}
use of org.cesiumjs.cs.core.events.MouseMoveEvent 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());
}
use of org.cesiumjs.cs.core.events.MouseMoveEvent 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());
}
Aggregations