use of org.cesiumjs.cs.promise.Fulfill in project gwt-cs by iSergio.
the class KML method buildPanel.
@Override
public void buildPanel() {
csVPanel = new ViewerPanel();
ListBox kmlLBox = new ListBox();
kmlLBox.addItem("KML - Global Science Facilities", GWT.getModuleBaseURL() + "SampleData/kml/facilities/facilities.kml");
kmlLBox.addItem("KMZ with embedded data - GDP per capita", GWT.getModuleBaseURL() + "SampleData/kml/gdpPerCapita2008.kmz");
kmlLBox.addItem("gx KML extensions - Bike Ride", GWT.getModuleBaseURL() + "SampleData/kml/bikeRide.kml");
kmlLBox.addChangeHandler(new ChangeHandler() {
@Override
public void onChange(ChangeEvent changeEvent) {
reset();
ListBox source = (ListBox) changeEvent.getSource();
final Viewer viewer = csVPanel.getViewer();
org.cesiumjs.cs.scene.Camera camera = viewer.camera;
CanvasElement canvas = viewer.canvas();
camera.flyHome(0);
// camera, canvas);
KmlDataSourceOptions kmlDataSourceOptions = new KmlDataSourceOptions();
kmlDataSourceOptions.canvas = canvas;
kmlDataSourceOptions.camera = camera;
if (!source.getSelectedValue().contains("bikeRide")) {
csVPanel.getViewer().dataSources().add(KmlDataSource.load(source.getSelectedValue(), kmlDataSourceOptions));
} else {
csVPanel.getViewer().dataSources().add(KmlDataSource.load(source.getSelectedValue(), kmlDataSourceOptions)).then(new Fulfill<KmlDataSource>() {
@Override
public void onFulfilled(KmlDataSource dataSource) {
viewer.clock().shouldAnimate = false;
final Entity rider = dataSource.entities.getById("tour");
viewer.flyTo(rider).then(new Fulfill<Boolean>() {
@Override
public void onFulfilled(Boolean value) {
viewer.trackedEntity = rider;
viewer.selectedEntity = viewer.trackedEntity;
viewer.clock().multiplier = 30;
viewer.clock().shouldAnimate = true;
}
});
}
});
}
}
});
AbsolutePanel aPanel = new AbsolutePanel();
aPanel.add(csVPanel);
aPanel.add(kmlLBox, 20, 20);
contentPanel.add(new HTML("<p>A simple KML example.</p>"));
contentPanel.add(aPanel);
initWidget(contentPanel);
}
use of org.cesiumjs.cs.promise.Fulfill in project gwt-cs by iSergio.
the class Terrain method buildPanel.
@Override
public void buildPanel() {
csVPanel = new ViewerPanel();
CesiumTerrainProviderOptions cesiumTerrainProviderOptions = new CesiumTerrainProviderOptions();
cesiumTerrainProviderOptions.url = "https://assets.agi.com/stk-terrain/world";
cesiumTerrainProviderOptions.requestWaterMask = true;
cesiumTerrainProviderOptions.requestVertexNormals = true;
cesiumTerrainProviderMeshes = new CesiumTerrainProvider(cesiumTerrainProviderOptions);
csVPanel.getViewer().terrainProvider = cesiumTerrainProviderMeshes;
Cartesian3 target = new Cartesian3(300770.50872389384, 5634912.131394585, 2978152.2865545116);
Cartesian3 offset = new Cartesian3(6344.974098678562, -793.3419798081741, 2499.9508860763162);
csVPanel.getViewer().camera.lookAt(target, offset);
csVPanel.getViewer().camera.lookAtTransform(Matrix4.IDENTITY());
ListBox terrainsLBox = new ListBox();
terrainsLBox.setWidth("130px");
terrainsLBox.addItem("CesiumTerrainProvider - STK World Terrain", "0");
terrainsLBox.addItem("CesiumTerrainProvider - STK World Terrain - no effects", "1");
terrainsLBox.addItem("CesiumTerrainProvider - STK World Terrain w/ Lighting", "2");
terrainsLBox.addItem("CesiumTerrainProvider - STK World Terrain w/ Water", "3");
terrainsLBox.addItem("EllipsoidTerrainProvider", "4");
terrainsLBox.addItem("VRTheWorldTerrainProvider", "5");
terrainsLBox.addItem("GeoserverTerrainProvider", "6");
terrainsLBox.addChangeHandler(new ChangeHandler() {
@Override
public void onChange(ChangeEvent changeEvent) {
ListBox source = (ListBox) changeEvent.getSource();
switch(source.getSelectedValue()) {
case "0":
{
csVPanel.getViewer().terrainProvider = cesiumTerrainProviderMeshes;
csVPanel.getViewer().scene().globe.enableLighting = true;
}
break;
case "1":
{
CesiumTerrainProviderOptions options = new CesiumTerrainProviderOptions();
options.url = "https://assets.agi.com/stk-terrain/world";
csVPanel.getViewer().terrainProvider = new CesiumTerrainProvider(options);
}
break;
case "2":
{
CesiumTerrainProviderOptions options = new CesiumTerrainProviderOptions();
options.url = "https://assets.agi.com/stk-terrain/world";
options.requestVertexNormals = true;
csVPanel.getViewer().terrainProvider = new CesiumTerrainProvider(options);
csVPanel.getViewer().scene().globe.enableLighting = true;
}
break;
case "3":
{
CesiumTerrainProviderOptions options = new CesiumTerrainProviderOptions();
options.url = "https://assets.agi.com/stk-terrain/world";
options.requestWaterMask = true;
csVPanel.getViewer().terrainProvider = new CesiumTerrainProvider(options);
csVPanel.getViewer().scene().globe.enableLighting = true;
}
break;
case "4":
{
csVPanel.getViewer().terrainProvider = new EllipsoidTerrainProvider();
}
break;
case "5":
{
VRTheWorldTerrainProviderOptions options = new VRTheWorldTerrainProviderOptions();
options.url = "http://www.vr-theworld.com/vr-theworld/tiles1.0.0/73/";
csVPanel.getViewer().terrainProvider = new VRTheWorldTerrainProvider(options);
}
break;
case "6":
{
GeoserverTerrainProviderOptions options = new GeoserverTerrainProviderOptions();
options.url = "http://sergeserver.noip.me/geobase-portal/ows";
options.layerName = "geoserver:geobase:SRTM90";
options.styleName = "geobase:grayToColor";
csVPanel.getViewer().terrainProvider = new GeoserverTerrainProvider(options);
}
break;
default:
break;
}
}
});
ListBox targetsLBox = new ListBox();
targetsLBox.addItem("Mount Everest", "0");
targetsLBox.addItem("Half Dome", "1");
targetsLBox.addItem("San Francisco Bay", "2");
targetsLBox.addChangeHandler(new ChangeHandler() {
@Override
public void onChange(ChangeEvent changeEvent) {
ListBox source = (ListBox) changeEvent.getSource();
switch(source.getSelectedValue()) {
case "0":
{
Cartesian3 target = new Cartesian3(300770.50872389384, 5634912.131394585, 2978152.2865545116);
Cartesian3 offset = new Cartesian3(6344.974098678562, -793.3419798081741, 2499.9508860763162);
csVPanel.getViewer().camera.lookAt(target, offset);
csVPanel.getViewer().camera.lookAtTransform(Matrix4.IDENTITY());
}
break;
case "1":
{
Cartesian3 target = new Cartesian3(-2489625.0836225147, -4393941.44443024, 3882535.9454173897);
Cartesian3 offset = new Cartesian3(-6857.40902037546, 412.3284835694358, 2147.5545426812023);
csVPanel.getViewer().camera.lookAt(target, offset);
csVPanel.getViewer().camera.lookAtTransform(Matrix4.IDENTITY());
}
break;
case "2":
{
Cartesian3 target = new Cartesian3(-2708814.85583248, -4254159.450845907, 3891403.9457429945);
Cartesian3 offset = new Cartesian3(70642.66030209465, -31661.517948317807, 35505.179997143336);
csVPanel.getViewer().camera.lookAt(target, offset);
csVPanel.getViewer().camera.lookAtTransform(Matrix4.IDENTITY());
}
default:
break;
}
}
});
ToggleButton lightingTBtn = new ToggleButton("Toggle Lighting");
lightingTBtn.setWidth("130px");
lightingTBtn.setValue(true);
lightingTBtn.addValueChangeHandler(new ValueChangeHandler<Boolean>() {
@Override
public void onValueChange(ValueChangeEvent<Boolean> valueChangeEvent) {
csVPanel.getViewer().scene().globe.enableLighting = !csVPanel.getViewer().scene().globe.enableLighting;
}
});
ToggleButton fogTBtn = new ToggleButton("Toggle Fog");
fogTBtn.setWidth("130px");
fogTBtn.setValue(true);
fogTBtn.addValueChangeHandler(new ValueChangeHandler<Boolean>() {
@Override
public void onValueChange(ValueChangeEvent<Boolean> valueChangeEvent) {
csVPanel.getViewer().scene().fog.enabled = !csVPanel.getViewer().scene().fog.enabled;
}
});
Button sampleBtn = new Button("Sample Everest Terrain");
sampleBtn.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent clickEvent) {
int gridWidth = 41;
int gridHeight = 41;
double everestLatitude = Math.toRadians(27.988257);
double everestLongitude = Math.toRadians(86.925145);
double rectangleHalfSize = 0.005;
Rectangle e = new Rectangle(everestLongitude - rectangleHalfSize, everestLatitude - rectangleHalfSize, everestLongitude + rectangleHalfSize, everestLatitude + rectangleHalfSize);
terrainSamplePositions = new ArrayList<>();
for (int y = 0; y < gridHeight; ++y) {
for (int x = 0; x < gridWidth; ++x) {
double lon = Math.lerp(e.west, e.east, (double) x / (gridWidth - 1.));
double lat = Math.lerp(e.south, e.north, (double) y / (gridHeight - 1.));
Cartographic position = new Cartographic(lon, lat);
terrainSamplePositions.add(position);
}
}
Promise<Cartographic[], Void> promise = Cesium.sampleTerrain(csVPanel.getViewer().terrainProvider, 9, terrainSamplePositions.toArray(new Cartographic[terrainSamplePositions.size()]));
promise.then(new Fulfill<Cartographic[]>() {
@Override
public void onFulfilled(Cartographic[] value) {
sampleTerrainSuccess();
}
});
}
});
VerticalPanel vPanel = new VerticalPanel();
vPanel.add(targetsLBox);
vPanel.add(terrainsLBox);
vPanel.add(lightingTBtn);
vPanel.add(fogTBtn);
vPanel.add(sampleBtn);
AbsolutePanel aPanel = new AbsolutePanel();
aPanel.add(csVPanel);
aPanel.add(vPanel, 20, 20);
contentPanel.add(new HTML("<p>Visualize worldwide, high-resolution terrain.</p>"));
contentPanel.add(aPanel);
initWidget(contentPanel);
}
use of org.cesiumjs.cs.promise.Fulfill in project gwt-cs by iSergio.
the class Billboards method offsetByDistance.
private void offsetByDistance() {
Resource.fetchImage(GWT.getModuleBaseURL() + "images/Cesium_Logo_overlay.png").then(new Fulfill<JsImage>() {
@Override
public void onFulfilled(JsImage logoImg) {
Resource.fetchImage(GWT.getModuleBaseURL() + "images/facility.gif").then(new Fulfill<JsImage>() {
@Override
public void onFulfilled(JsImage facilityImg) {
int facilityHeight = facilityImg.height;
BillboardGraphicsOptions billboardGraphicsOptions = new BillboardGraphicsOptions();
billboardGraphicsOptions.image = new ConstantProperty<>(facilityImg);
billboardGraphicsOptions.horizontalOrigin = new ConstantProperty<>(HorizontalOrigin.CENTER());
billboardGraphicsOptions.verticalOrigin = new ConstantProperty<>(VerticalOrigin.BOTTOM());
BillboardGraphics billboardGraphics = new BillboardGraphics(billboardGraphicsOptions);
EntityOptions entityOptions = new EntityOptions();
entityOptions.billboard = billboardGraphics;
entityOptions.position = new ConstantPositionProperty(Cartesian3.fromDegrees(-75.59777, 40.03883));
csVPanel.getViewer().entities().add(new Entity(entityOptions));
billboardGraphicsOptions = new BillboardGraphicsOptions();
billboardGraphicsOptions.image = new ConstantProperty<>(logoImg);
billboardGraphicsOptions.horizontalOrigin = new ConstantProperty<>(HorizontalOrigin.CENTER());
billboardGraphicsOptions.verticalOrigin = new ConstantProperty<>(VerticalOrigin.BOTTOM());
billboardGraphicsOptions.pixelOffset = new ConstantProperty<>(new Cartesian2(0.0, -facilityHeight));
billboardGraphicsOptions.pixelOffsetScaleByDistance = new ConstantProperty<>(new NearFarScalar(1.0e3, 1.0, 1.5e6, 0.0));
billboardGraphicsOptions.translucencyByDistance = new ConstantProperty<>(new NearFarScalar(1.0e3, 1.0, 1.5e6, 0.1));
billboardGraphics = new BillboardGraphics(billboardGraphicsOptions);
entityOptions = new EntityOptions();
entityOptions.billboard = billboardGraphics;
entityOptions.position = new ConstantPositionProperty(Cartesian3.fromDegrees(-75.59777, 40.03883));
csVPanel.getViewer().entities().add(new Entity(entityOptions));
}
}, new Reject<Void>() {
@Override
public void onRejected(Void value) {
LOGGER.info("facility imagery not loaded");
}
});
}
}, new Reject<Void>() {
@Override
public void onRejected(Void value) {
LOGGER.info("Cesium_Logo_overlay imagery not loaded");
}
});
}
use of org.cesiumjs.cs.promise.Fulfill 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.promise.Fulfill 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);
}
Aggregations