use of org.cesiumjs.cs.datasources.Entity 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.datasources.Entity in project gwt-cs by iSergio.
the class LoadImages method buildPanel.
@Override
public void buildPanel() {
csVPanel = new ViewerPanel();
AbsolutePanel aPanel = new AbsolutePanel();
aPanel.add(csVPanel);
org.cesiumjs.cs.core.PinBuilder pinBuilder = new org.cesiumjs.cs.core.PinBuilder();
pinBuilder.fromUrlPromise(GWT.getModuleBaseURL() + "images/Cesium_Logo_Color_Overlay.png", Color.WHITE().withAlpha(0.0f), 256).then(new Fulfill<CanvasElement>() {
@Override
public void onFulfilled(CanvasElement value) {
BillboardGraphicsOptions billboardOptions = new BillboardGraphicsOptions();
billboardOptions.image = new ConstantProperty<>(value.toDataUrl());
EntityOptions entityOptions = new EntityOptions();
entityOptions.name = "Pin billboard through fromUrl";
entityOptions.billboard = new BillboardGraphics(billboardOptions);
entityOptions.position = new ConstantPositionProperty(Cartesian3.fromDegrees(35, 35));
csVPanel.getViewer().entities().add(new Entity(entityOptions));
}
});
Resource.fetchImage((ResourceImageOptions) ResourceImageOptions.create(GWT.getModuleBaseURL() + "images/Cesium_Logo_Color_Overlay.png")).then(new Fulfill<JsImage>() {
@Override
public void onFulfilled(JsImage value) {
Canvas canvas = Canvas.createIfSupported();
canvas.setWidth(value.width + "px");
canvas.setHeight(value.height + "px");
Context2d context = canvas.getContext2d();
context.scale(0.1, 0.1);
context.drawImage((ImageElement) (Object) value, 0, 0);
BillboardGraphicsOptions billboardOptions = new BillboardGraphicsOptions();
billboardOptions.image = new ConstantProperty<>(canvas.toDataUrl());
EntityOptions entityOptions = new EntityOptions();
entityOptions.name = "Pin billboard through canvas";
entityOptions.billboard = new BillboardGraphics(billboardOptions);
entityOptions.position = new ConstantPositionProperty(Cartesian3.fromDegrees(45, 45));
csVPanel.getViewer().entities().add(new Entity(entityOptions));
}
});
// CORS not loaded
Resource.fetchImage((ResourceImageOptions) ResourceImageOptions.create("https://www.linux.org.ru/tango/img/games-logo.png")).then(new Fulfill<JsImage>() {
@Override
public void onFulfilled(JsImage value) {
Canvas canvas = Canvas.createIfSupported();
canvas.setWidth(value.width + "px");
canvas.setHeight(value.height + "px");
Context2d context = canvas.getContext2d();
context.scale(0.1, 0.1);
context.drawImage((ImageElement) (Object) value, 0, 0);
BillboardGraphicsOptions billboardOptions = new BillboardGraphicsOptions();
billboardOptions.image = new ConstantProperty<>(canvas.toDataUrl());
EntityOptions entityOptions = new EntityOptions();
entityOptions.name = "Pin billboard CORS";
entityOptions.billboard = new BillboardGraphics(billboardOptions);
entityOptions.position = new ConstantPositionProperty(Cartesian3.fromDegrees(55, 55));
csVPanel.getViewer().entities().add(new Entity(entityOptions));
}
});
// Cors not loaded!
final JsImage imageAmz = new JsImage();
imageAmz.crossOrigin = "*";
imageAmz.onload = new JsImage.Listener() {
@Override
public void function() {
Cesium.log(imageAmz);
/*Canvas canvas = Canvas.createIfSupported();
canvas.setWidth(imageAmz.width + "px");
canvas.setHeight(imageAmz.height + "px");
Context2d context = canvas.getContext2d();
context.scale(0.1, 0.1);
context.drawImage((ImageElement) (Object) imageAmz, 0, 0);*/
BillboardGraphicsOptions billboardOptions = new BillboardGraphicsOptions();
billboardOptions.image = new ConstantProperty<>(imageAmz);
// billboardOptions.image = new ConstantProperty<>(canvas.toDataUrl("image/png"));
EntityOptions entityOptions = new EntityOptions();
entityOptions.name = "Pin billboard CORS";
entityOptions.billboard = new BillboardGraphics(billboardOptions);
entityOptions.position = new ConstantPositionProperty(Cartesian3.fromDegrees(65, 65));
csVPanel.getViewer().entities().add(new Entity(entityOptions));
}
};
imageAmz.src = "https://d1.awsstatic.com/products/cloudfront/cloudfront-100_PoP_600x400.4a1edd6022833c54c41370ad9f615ae818350a23.png";
// Worked, have Access-Control-Allow-Origin: *
final JsImage imageWiki = new JsImage();
imageWiki.crossOrigin = "*";
imageWiki.onload = new JsImage.Listener() {
@Override
public void function() {
Cesium.log(imageWiki);
Canvas canvas = Canvas.createIfSupported();
canvas.setWidth(imageWiki.width + "px");
canvas.setHeight(imageWiki.height + "px");
Context2d context = canvas.getContext2d();
context.drawImage((ImageElement) (Object) imageWiki, 0, 0);
BillboardGraphicsOptions billboardOptions = new BillboardGraphicsOptions();
billboardOptions.image = new ConstantProperty<>(canvas.toDataUrl("image/png"));
EntityOptions entityOptions = new EntityOptions();
entityOptions.name = "Pin billboard CORS";
entityOptions.billboard = new BillboardGraphics(billboardOptions);
entityOptions.position = new ConstantPositionProperty(Cartesian3.fromDegrees(75, 75));
csVPanel.getViewer().entities().add(new Entity(entityOptions));
}
};
imageWiki.src = "https://ru.wikipedia.org/static/images/project-logos/ruwiki-2x.png";
contentPanel.add(new HTML("<p>Cluster labels, billboards and points.</p>"));
contentPanel.add(aPanel);
initWidget(contentPanel);
}
use of org.cesiumjs.cs.datasources.Entity 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.datasources.Entity in project gwt-cs by iSergio.
the class Shadows method buildPanel.
@Override
public void buildPanel() {
ViewerOptions viewerOptions = new ViewerOptions();
viewerOptions.infoBox = false;
viewerOptions.selectionIndicator = false;
viewerOptions.shadows = true;
viewerOptions.terrainShadows = ShadowMode.ENABLED();
csVPanel = new ViewerPanel(viewerOptions);
CesiumTerrainProviderOptions cesiumTerrainProviderOptions = new CesiumTerrainProviderOptions();
cesiumTerrainProviderOptions.url = "https://assets.agi.com/stk-terrain/world";
cesiumTerrainProviderOptions.requestVertexNormals = true;
cesiumTerrainProviderOptions.requestWaterMask = true;
csVPanel.getViewer().terrainProvider = new CesiumTerrainProvider(cesiumTerrainProviderOptions);
shadowMap = csVPanel.getViewer().shadowMap();
shadowMap.maximumDistance = 10000.0;
ModelGraphicsOptions modelGraphicsOptions = new ModelGraphicsOptions();
modelGraphicsOptions.uri = new ConstantProperty<>(GWT.getModuleBaseURL() + "SampleData/models/CesiumAir/Cesium_Air.glb");
EntityOptions entityOptions = new EntityOptions();
entityOptions.name = "Cesium Air";
entityOptions.model = new ModelGraphics(modelGraphicsOptions);
JsObject.$(entityOptions, "height", 20.0);
cesiumAir = csVPanel.getViewer().entities().add(entityOptions);
modelGraphicsOptions = new ModelGraphicsOptions();
modelGraphicsOptions.uri = new ConstantProperty<>(GWT.getModuleBaseURL() + "SampleData/models/CesiumGround/Cesium_Ground.glb");
entityOptions = new EntityOptions();
entityOptions.name = "Ground Vehicle";
JsObject.$(entityOptions, "height", 0.0);
entityOptions.model = new ModelGraphics(modelGraphicsOptions);
groundVehicle = csVPanel.getViewer().entities().add(entityOptions);
modelGraphicsOptions = new ModelGraphicsOptions();
modelGraphicsOptions.uri = new ConstantProperty<>(GWT.getModuleBaseURL() + "SampleData/models/CesiumMan/Cesium_Man.glb");
entityOptions = new EntityOptions();
entityOptions.name = "Cesium Man";
JsObject.$(entityOptions, "height", 0.0);
entityOptions.model = new ModelGraphics(modelGraphicsOptions);
cesiumMan = csVPanel.getViewer().entities().add(entityOptions);
modelGraphicsOptions = new ModelGraphicsOptions();
modelGraphicsOptions.uri = new ConstantProperty<>(GWT.getModuleBaseURL() + "SampleData/models/WoodTower/Wood_Tower.gltf");
entityOptions = new EntityOptions();
entityOptions.name = "Wood Tower";
JsObject.$(entityOptions, "height", 0.0);
entityOptions.model = new ModelGraphics(modelGraphicsOptions);
woodTower = csVPanel.getViewer().entities().add(entityOptions);
modelGraphicsOptions = new ModelGraphicsOptions();
modelGraphicsOptions.uri = new ConstantProperty<>(GWT.getModuleBaseURL() + "SampleData/models/ShadowTester/Shadow_Tester_4.gltf");
entityOptions = new EntityOptions();
entityOptions.name = "Simple City";
JsObject.$(entityOptions, "height", 0.0);
entityOptions.model = new ModelGraphics(modelGraphicsOptions);
simpleCity = csVPanel.getViewer().entities().add(entityOptions);
BoxGraphicsOptions boxGraphicsOptions = new BoxGraphicsOptions();
boxGraphicsOptions.dimensions = new ConstantProperty<>(new Cartesian3(10.0, 10.0, 10.0));
boxGraphicsOptions.material = new ColorMaterialProperty(Color.RED());
boxGraphicsOptions.shadows = new ConstantProperty<>(ShadowMode.ENABLED());
entityOptions = new EntityOptions();
entityOptions.name = "Box";
JsObject.$(entityOptions, "height", 10.0);
entityOptions.box = new BoxGraphics(boxGraphicsOptions);
boxEntity = csVPanel.getViewer().entities().add(entityOptions);
CheckerboardMaterialPropertyOptions checkerboardMaterialPropertyOptions = new CheckerboardMaterialPropertyOptions();
checkerboardMaterialPropertyOptions.evenColor = new ConstantProperty<>(Color.RED().withAlpha(0.5f));
checkerboardMaterialPropertyOptions.oddColor = new ConstantProperty<>(Color.RED().withAlpha(0.0f));
checkerboardMaterialPropertyOptions.repeat = new ConstantProperty<>(new Cartesian2(5.0, 10.0));
CheckerboardMaterialProperty checkerMaterial = new CheckerboardMaterialProperty(checkerboardMaterialPropertyOptions);
boxGraphicsOptions = new BoxGraphicsOptions();
boxGraphicsOptions.dimensions = new ConstantProperty<>(new Cartesian3(10.0, 10.0, 10.0));
boxGraphicsOptions.material = checkerMaterial;
boxGraphicsOptions.outline = new ConstantProperty<>(true);
boxGraphicsOptions.outlineColor = new ConstantProperty<>(Color.RED());
boxGraphicsOptions.shadows = new ConstantProperty<>(ShadowMode.ENABLED());
entityOptions = new EntityOptions();
entityOptions.name = "Checkered Box";
JsObject.$(entityOptions, "height", 10.0);
entityOptions.box = new BoxGraphics(boxGraphicsOptions);
checkerEntity = csVPanel.getViewer().entities().add(entityOptions);
EllipsoidGraphicsOptions ellipsoidGraphicsOptions = new EllipsoidGraphicsOptions();
ellipsoidGraphicsOptions.radii = new ConstantProperty<>(new Cartesian3(15.0, 15.0, 15.0));
ellipsoidGraphicsOptions.material = new ColorMaterialProperty(Color.BLUE().withAlpha(0.5f));
ellipsoidGraphicsOptions.slicePartitions = new ConstantProperty<>(24);
ellipsoidGraphicsOptions.stackPartitions = new ConstantProperty<>(36);
ellipsoidGraphicsOptions.shadows = new ConstantProperty<>(ShadowMode.ENABLED());
entityOptions = new EntityOptions();
entityOptions.name = "Sphere";
JsObject.$(entityOptions, "height", 10.0);
entityOptions.ellipsoid = new EllipsoidGraphics(ellipsoidGraphicsOptions);
sphereEntity = csVPanel.getViewer().entities().add(entityOptions);
setLocation(locations.get(0));
setEntity(cesiumAir);
ListBox locationLBox = new ListBox();
for (int i = 0; i < locations.size(); i++) {
Location location = locations.get(i);
locationLBox.addItem(location.name, i + "");
}
locationLBox.addChangeHandler(new ChangeHandler() {
@Override
public void onChange(ChangeEvent changeEvent) {
ListBox source = (ListBox) changeEvent.getSource();
setLocation(locations.get(Integer.parseInt(source.getSelectedValue())));
}
});
ListBox entitiList = new ListBox();
entitiList.addItem("Cesium Air");
entitiList.addItem("Ground Vehicle");
entitiList.addItem("Cesium Man");
entitiList.addItem("Wood Tower");
entitiList.addItem("Simple City");
entitiList.addItem("Box");
entitiList.addItem("Checkered Box");
entitiList.addItem("Sphere");
entitiList.addChangeHandler(new ChangeHandler() {
@Override
public void onChange(ChangeEvent changeEvent) {
ListBox source = (ListBox) changeEvent.getSource();
switch(source.getSelectedIndex()) {
case 0:
setEntity(cesiumAir);
break;
case 1:
setEntity(groundVehicle);
break;
case 2:
setEntity(cesiumMan);
break;
case 3:
setEntity(woodTower);
break;
case 4:
setEntity(simpleCity);
break;
case 5:
setEntity(boxEntity);
break;
case 6:
setEntity(checkerEntity);
break;
case 7:
setEntity(sphereEntity);
break;
default:
break;
}
}
});
CheckBox shadowsCBox = new CheckBox("Shadows");
shadowsCBox.getElement().getStyle().setColor("white");
shadowsCBox.setValue(true);
shadowsCBox.addValueChangeHandler(new ValueChangeHandler<Boolean>() {
@Override
public void onValueChange(ValueChangeEvent<Boolean> valueChangeEvent) {
csVPanel.getViewer().shadows = !csVPanel.getViewer().shadows;
}
});
CheckBox entitiShadowsCBox = new CheckBox("Entity Shadows");
entitiShadowsCBox.getElement().getStyle().setColor("white");
entitiShadowsCBox.setValue(true);
entitiShadowsCBox.addValueChangeHandler(new ValueChangeHandler<Boolean>() {
@Override
public void onValueChange(ValueChangeEvent<Boolean> valueChangeEvent) {
Number entityShadows = valueChangeEvent.getValue() ? ShadowMode.ENABLED() : ShadowMode.DISABLED();
for (int i = 0; i < csVPanel.getViewer().entities().values().length; i++) {
Entity entity = csVPanel.getViewer().entities().values()[i];
if (entity.model != null) {
entity.model.shadows = new ConstantProperty<>(entityShadows);
} else if (entity.box != null) {
entity.box.shadows = new ConstantProperty<>(entityShadows);
} else if (entity.ellipsoid != null) {
entity.ellipsoid.shadows = new ConstantProperty<>(entityShadows);
}
}
}
});
CheckBox terrainShadowsCBox = new CheckBox("Terrain Shadows");
terrainShadowsCBox.getElement().getStyle().setColor("white");
terrainShadowsCBox.setValue(true);
terrainShadowsCBox.addValueChangeHandler(new ValueChangeHandler<Boolean>() {
@Override
public void onValueChange(ValueChangeEvent<Boolean> valueChangeEvent) {
csVPanel.getViewer().terrainShadows = valueChangeEvent.getValue() ? ShadowMode.ENABLED() : ShadowMode.DISABLED();
}
});
CheckBox softShadowsCBox = new CheckBox("Soft Shadows");
softShadowsCBox.getElement().getStyle().setColor("white");
softShadowsCBox.addValueChangeHandler(new ValueChangeHandler<Boolean>() {
@Override
public void onValueChange(ValueChangeEvent<Boolean> valueChangeEvent) {
shadowMap.softShadows = valueChangeEvent.getValue();
}
});
ListBox sizeLBox = new ListBox();
sizeLBox.addItem("Size: 2048", "2048");
sizeLBox.addItem("Size: 1024", "1024");
sizeLBox.addItem("Size: 512", "512");
sizeLBox.addItem("Size: 256", "256");
sizeLBox.addChangeHandler(new ChangeHandler() {
@Override
public void onChange(ChangeEvent changeEvent) {
ListBox source = (ListBox) changeEvent.getSource();
shadowMap.size = Integer.parseInt(source.getSelectedValue());
}
});
VerticalPanel vPanel = new VerticalPanel();
vPanel.add(locationLBox);
vPanel.add(entitiList);
vPanel.add(shadowsCBox);
vPanel.add(entitiShadowsCBox);
vPanel.add(terrainShadowsCBox);
vPanel.add(softShadowsCBox);
vPanel.add(sizeLBox);
FlowPanel fPanel = new FlowPanel();
AbsolutePanel aPanel = new AbsolutePanel();
aPanel.add(csVPanel);
aPanel.add(vPanel, 20, 20);
fPanel.add(aPanel);
contentPanel.add(new HTML("<p>Shadow maps.</p>"));
contentPanel.add(fPanel);
initWidget(contentPanel);
}
use of org.cesiumjs.cs.datasources.Entity in project gwt-cs by iSergio.
the class Terrain method sampleTerrainSuccess.
private void sampleTerrainSuccess() {
Ellipsoid ellipsoid = Ellipsoid.WGS84();
csVPanel.getViewer().scene().globe.depthTestAgainstTerrain = true;
csVPanel.getViewer().entities().suspendEvents();
csVPanel.getViewer().entities().removeAll();
for (Cartographic position : terrainSamplePositions) {
BigDecimal bd = new BigDecimal(position.height).setScale(1, RoundingMode.HALF_EVEN);
BillboardGraphicsOptions billboardGraphicsOptions = new BillboardGraphicsOptions();
billboardGraphicsOptions.verticalOrigin = new ConstantProperty<>(VerticalOrigin.BOTTOM());
billboardGraphicsOptions.scale = new ConstantProperty<>(0.7);
billboardGraphicsOptions.image = new ConstantProperty<>(GWT.getModuleBaseURL() + "images/facility.gif");
LabelGraphicsOptions labelGraphicsOptions = new LabelGraphicsOptions();
labelGraphicsOptions.text = new ConstantProperty<>(bd.toString());
// HorizontalOrigin.CENTER());
labelGraphicsOptions.horizontalOrigin = new ConstantProperty<>(HorizontalOrigin.CENTER());
labelGraphicsOptions.scale = new ConstantProperty<>(0.3);
labelGraphicsOptions.pixelOffset = new ConstantProperty<>(new Cartesian2(0, -14));
labelGraphicsOptions.fillColor = new ConstantProperty<>(Color.RED());
labelGraphicsOptions.outlineColor = new ConstantProperty<>(Color.WHITE());
EntityOptions entityOptions = new EntityOptions();
entityOptions.name = bd.toString();
entityOptions.position = new ConstantPositionProperty(ellipsoid.cartographicToCartesian(position));
entityOptions.billboard = new BillboardGraphics(billboardGraphicsOptions);
entityOptions.label = new LabelGraphics(labelGraphicsOptions);
csVPanel.getViewer().entities().add(new Entity(entityOptions));
}
csVPanel.getViewer().entities().resumeEvents();
}
Aggregations