use of org.cesiumjs.cs.datasources.properties.ConstantProperty in project gwt-cs by iSergio.
the class Tiles3DClippingPlanes method loadTileset.
private void loadTileset(Promise<IonResource, Void> resource) {
final ClippingPlane[] clippingPlanes = new ClippingPlane[] { new ClippingPlane(new Cartesian3(0.0, 0.0, -1.0), -100.0) };
ClippingPlaneCollectionOptions clippingPlaneCollectionOptions = new ClippingPlaneCollectionOptions();
clippingPlaneCollectionOptions.planes = clippingPlanes;
clippingPlaneCollectionOptions.edgeWidth = edgeStylingCBox.getValue() ? 1.0 : 0.0;
Cesium3DTilesetOptions tilesetOptions = Cesium3DTilesetOptions.create(resource);
tilesetOptions.clippingPlanes = new ClippingPlaneCollection(clippingPlaneCollectionOptions);
tileset = (Cesium3DTileset) csVPanel.getViewer().scene().primitives().add(new Cesium3DTileset(tilesetOptions));
tileset.debugShowBoundingVolume = boundingVolumeCBox.getValue();
tileset.readyPromise().then(new Fulfill<Cesium3DTileset>() {
@Override
public void onFulfilled(Cesium3DTileset value) {
BoundingSphere boundingSphere = tileset.boundingSphere();
double radius = boundingSphere.radius;
csVPanel.getViewer().zoomTo(tileset, new HeadingPitchRange(0.5, -0.2, radius * 4.0));
for (final ClippingPlane plane : clippingPlanes) {
PlaneGraphicsOptions planeGraphicsOptions = new PlaneGraphicsOptions();
planeGraphicsOptions.dimensions = new ConstantProperty<>(new Cartesian2(radius * 2.5, radius * 2.5));
planeGraphicsOptions.material = new ColorMaterialProperty(Color.WHITE().withAlpha(0.1f));
planeGraphicsOptions.plane = new CallbackProperty(new CallbackProperty.Callback() {
@Override
public Object function(JulianDate time, Object result) {
plane.distance = targetY;
return ClippingPlane.transform(plane, tileset.modelMatrix, scratchPlane);
}
}, false);
planeGraphicsOptions.outline = new ConstantProperty<>(true);
planeGraphicsOptions.outlineColor = new ConstantProperty<>(Color.WHITE());
EntityOptions entityOptions = new EntityOptions();
entityOptions.position = new ConstantPositionProperty(boundingSphere.center);
entityOptions.plane = new PlaneGraphics(planeGraphicsOptions);
planeEntities.add(csVPanel.getViewer().entities().add(entityOptions));
}
}
});
}
use of org.cesiumjs.cs.datasources.properties.ConstantProperty 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.datasources.properties.ConstantProperty in project gwt-cs by iSergio.
the class GeoJSONAndTopoJSON method buildPanel.
@Override
public void buildPanel() {
csVPanel = new ViewerPanel();
csVPanel.getViewer().dataSources().removeAll();
csVPanel.getViewer().camera.lookAt(Cartesian3.fromDegrees(-98.0, 40.0), new Cartesian3(0.0, -4790000.0, 3930000.0));
csVPanel.getViewer().camera.lookAtTransform(Matrix4.IDENTITY());
Button defaultStylingBtn = new Button("Default styling");
defaultStylingBtn.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent clickEvent) {
reset();
csVPanel.getViewer().dataSources().add(GeoJsonDataSource.load(GWT.getModuleBaseURL() + "SampleData/ne_10m_us_states.topojson"));
}
});
Button basicStylingBtn = new Button("Basic styling");
basicStylingBtn.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent clickEvent) {
reset();
GeoJsonDataSourceOptions options = new GeoJsonDataSourceOptions();
options.stroke = Color.HOTPINK();
options.fill = Color.DEEPPINK().withAlpha(0.5f);
options.strokeWidth = 3;
csVPanel.getViewer().dataSources().add(GeoJsonDataSource.load(GWT.getModuleBaseURL() + "SampleData/ne_10m_us_states.topojson", options));
}
});
Button customStylingBtn = new Button("Custom styling");
customStylingBtn.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent clickEvent) {
Math.setRandomNumberSeed(0);
Promise<GeoJsonDataSource, String> promise = GeoJsonDataSource.load(GWT.getModuleBaseURL() + "SampleData/ne_10m_us_states.topojson");
promise.then(new Fulfill<GeoJsonDataSource>() {
@Override
public void onFulfilled(GeoJsonDataSource dataSource) {
reset();
csVPanel.getViewer().dataSources().add(dataSource);
Entity[] entities = dataSource.entities.values();
HashMap<String, Color> colorHash = new HashMap<>();
for (int i = 0; i < entities.length; i++) {
Entity entity = entities[i];
String name = entity.name;
Color color = colorHash.get(name);
if (color == null) {
ColorRandomOptions options = new ColorRandomOptions();
options.alpha = 1.0f;
color = Color.fromRandom(options);
colorHash.put(name, color);
}
entity.polygon.material = new ColorMaterialProperty(new ConstantProperty<>(color));
entity.polygon.outline = new ConstantProperty<>(false);
entity.polygon.extrudedHeight = new ConstantProperty<>(JsObject.getObject(entity, "properties").getNumber("Population").doubleValue() / 50.);
}
}
}, new Reject<String>() {
@Override
public void onRejected(String value) {
Window.alert(value);
}
});
}
});
HorizontalPanel hPanel = new HorizontalPanel();
hPanel.setSpacing(5);
hPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
hPanel.add(defaultStylingBtn);
hPanel.add(basicStylingBtn);
hPanel.add(customStylingBtn);
AbsolutePanel aPanel = new AbsolutePanel();
aPanel.add(csVPanel);
aPanel.add(hPanel, 20, 20);
contentPanel.add(new HTML("<p>Load GeoJSON or TopoJSON data and apply custom styling.</p>"));
contentPanel.add(aPanel);
initWidget(contentPanel);
}
use of org.cesiumjs.cs.datasources.properties.ConstantProperty in project gwt-cs by iSergio.
the class Tiles3DFeaturePicking method buildPanel.
@Override
public void buildPanel() {
final ViewerPanel csVPanel = new ViewerPanel();
nameOverlay = RootPanel.get().getElement().getOwnerDocument().createDivElement();
csVPanel.getViewer().container().appendChild(nameOverlay);
nameOverlay.setClassName("backdrop");
nameOverlay.getStyle().setDisplay(Style.Display.NONE);
nameOverlay.getStyle().setPosition(Style.Position.ABSOLUTE);
nameOverlay.getStyle().setBottom(0, Style.Unit.PX);
nameOverlay.getStyle().setLeft(0, Style.Unit.PX);
// nameOverlay.style['pointer-events'] = 'none';
nameOverlay.getStyle().setPadding(4, Style.Unit.PX);
nameOverlay.getStyle().setBackgroundColor("black");
Cartesian3 initialPosition = Cartesian3.fromDegrees(-74.01881302800248, 40.69114333714821, 753);
org.cesiumjs.cs.core.HeadingPitchRoll initialOrientation = org.cesiumjs.cs.core.HeadingPitchRoll.fromDegrees(21.27879878293835, -21.34390550872461, 0.0716951918898415);
ViewOptions viewOptions = new ViewOptions();
viewOptions.destinationPos = initialPosition;
viewOptions.orientation = initialOrientation;
viewOptions.endTransform = Matrix4.IDENTITY();
csVPanel.getViewer().scene().camera().setView(viewOptions);
// Load the NYC buildings tileset
Cesium3DTileset tileset = (Cesium3DTileset) csVPanel.getViewer().scene().primitives().add(Cesium3DTileset.create("https://beta.cesium.com/api/assets/1461?access_token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiJkYWJmM2MzNS02OWM5LTQ3OWItYjEyYS0xZmNlODM5ZDNkMTYiLCJpZCI6NDQsImFzc2V0cyI6WzE0NjFdLCJpYXQiOjE0OTkyNjQ3NDN9.vuR75SqPDKcggvUrG_vpx0Av02jdiAxnnB1fNf-9f7s"));
csVPanel.getViewer().screenSpaceEventHandler().setInputAction(new ScreenSpaceEventHandler.Listener() {
@Override
public void function(Object event) {
MouseMoveEvent movement = (MouseMoveEvent) event;
// If a feature was previously highlighted, undo the highlight
if (Cesium.defined(highlighted.feature)) {
highlighted.feature.color = highlighted.originalColor;
highlighted.feature = (Cesium3DTileFeature) JsObject.undefined();
}
// Pick a new feature
Cesium3DTileFeature pickedFeature = (Cesium3DTileFeature) csVPanel.getViewer().scene().pick(movement.endPosition);
if (!Cesium.defined(pickedFeature)) {
nameOverlay.getStyle().setDisplay(Style.Display.NONE);
return;
}
// A feature was picked, so show it's overlay content
nameOverlay.getStyle().setDisplay(Style.Display.BLOCK);
nameOverlay.getStyle().setBottom(csVPanel.getViewer().canvas().getClientHeight() - movement.endPosition.y + 26, Style.Unit.PX);
nameOverlay.getStyle().setLeft(movement.endPosition.x + 26, Style.Unit.PX);
String name = pickedFeature.getProperty("name").toString();
if (!Cesium.defined(name)) {
name = pickedFeature.getProperty("id").toString();
}
nameOverlay.setInnerHTML("<font color=\"white\">" + name + "</font>");
// Highlight the feature if it's not already selected.
if (!pickedFeature.equals(selected.feature)) {
highlighted.feature = pickedFeature;
Color.clone(pickedFeature.color, highlighted.originalColor);
pickedFeature.color = Color.YELLOW();
}
}
}, ScreenSpaceEventType.MOUSE_MOVE());
final Function clickHandler = csVPanel.getViewer().screenSpaceEventHandler().getInputAction(ScreenSpaceEventType.LEFT_CLICK());
csVPanel.getViewer().screenSpaceEventHandler().setInputAction(new ScreenSpaceEventHandler.Listener() {
@Override
public void function(Object event) {
MouseClickEvent movement = (MouseClickEvent) event;
// If a feature was previously selected, undo the highlight
if (Cesium.defined(selected.feature)) {
selected.feature.color = selected.originalColor;
selected.feature = (Cesium3DTileFeature) JsObject.undefined();
}
// Pick a new feature
Cesium3DTileFeature pickedFeature = (Cesium3DTileFeature) csVPanel.getViewer().scene().pick(movement.position);
if (!Cesium.defined(pickedFeature)) {
GWT.log("undefined");
clickHandler.exec();
return;
}
// Select the feature if it's not already selected
if (selected.feature == pickedFeature) {
return;
}
selected.feature = pickedFeature;
// Save the selected feature's original color
if (pickedFeature == highlighted.feature) {
Color.clone(highlighted.originalColor, selected.originalColor);
highlighted.feature = (Cesium3DTileFeature) JsObject.undefined();
} else {
Color.clone(pickedFeature.color, selected.originalColor);
}
// Highlight newly selected feature
pickedFeature.color = Color.LIME();
// Set feature infobox description
String featureName = pickedFeature.getProperty("name").toString();
selectedEntity.name = featureName;
selectedEntity.description = new ConstantProperty<>("Loading <div class=\"cesium-infoBox-loading\"></div>");
csVPanel.getViewer().selectedEntity = selectedEntity;
selectedEntity.description = new ConstantProperty<>("<table class=\"cesium-infoBox-defaultTable\"><tbody>" + "<tr><th>BIN</th><td>" + pickedFeature.getProperty("BIN").toString() + "</td></tr>" + "<tr><th>DOITT ID</th><td>" + pickedFeature.getProperty("DOITT_ID").toString() + "</td></tr>" + "<tr><th>SOURCE ID</th><td>" + pickedFeature.getProperty("SOURCE_ID").toString() + "</td></tr>" + "</tbody></table>");
}
}, ScreenSpaceEventType.LEFT_CLICK());
contentPanel.add(new HTML("<p>Pick features in a 3D Tiles tileset.</p>"));
contentPanel.add(csVPanel);
initWidget(contentPanel);
}
Aggregations