World Wind Java球体增加一些内容,使它在展示数据时方式更丰富,应用更灵活。
立体图元
World Wind Java中使用AirspaceLayer图层类表示立体图元数据,通过在AirspaceLayer上增加具有AbstractAirspace接口的各种立体图元类显示,一个AirspaceLayer图层可容纳多个立体图元,立体图元包括:圆柱、圆弧、层叠饼、轨道、帘幕、多边形、路径和球等多种形式,通过AirspaceAttribute属性指定显示的颜色和材质,在通过指定诸如高度、宽度、半径等属性来设置它的尺寸,最后通过指定中心空间坐标设置空间图元的显示位置。
- 圆柱(CappedCylinder)
2.0的代码如下:
import java.awt.Color;
import gov.nasa.worldwind.geom.Angle;
import gov.nasa.worldwind.geom.LatLon;
import gov.nasa.worldwind.geom.Sector;
import gov.nasa.worldwind.layers.AirspaceLayer;
import gov.nasa.worldwind.layers.SurfaceImageLayer;
import gov.nasa.worldwind.render.Material;
import gov.nasa.worldwind.render.airspaces.Airspace;
import gov.nasa.worldwind.render.airspaces.CappedCylinder;
public class wwjOldAirspace extends wwjBasics {
protected AirspaceLayer airspaceLayer;
public void addAirspaceLayer(String layerName){
airspaceLayer = new AirspaceLayer();
airspaceLayer.setName(layerName);
this.worldWindowGLCanvas.getModel().getLayers().add(airspaceLayer);
this.layerPanel.update(this.worldWindowGLCanvas);
}
public Color makeBrighter(Color color){
float[] hsbComponents = new float[3];
Color.RGBtoHSB(color.getRed(), color.getGreen(), color.getBlue(), hsbComponents);
float hue = hsbComponents[0];
float saturation = hsbComponents[1];
float brightness = hsbComponents[2];
saturation /= 3f;
brightness *= 3f;
if (saturation <0f) saturation = 0f;
if (brightness >1f) brightness = 1f;
int rgbInt = Color.HSBtoRGB(hue, saturation, brightness);
return new Color(rgbInt);
}
public void setupDefautMaterial(Airspace airspace, Color color){
Color outlineColor = makeBrighter(color);
airspace.getAttributes().setDrawOutline(true);
airspace.getAttributes().setOutlineMaterial(new Material(color));
airspace.getAttributes().setOpacity(0.8);
airspace.getAttributes().setOutlineOpacity(0.9);
airspace.getAttributes().setOutlineWidth(3.0);
}
public boolean addCappedCylinder(double lat,double lon,double radius ,double minAltitude,double maxAltitude,Color color ){
boolean rtnResult = false;
try{
CappedCylinder cappedCylinder = new CappedCylinder();
cappedCylinder.setCenter(LatLon.fromDegrees(lat, lon));
cappedCylinder.setRadius(radius);
cappedCylinder.setAltitudes(minAltitude,maxAltitude);
cappedCylinder.setTerrainConforming(true,true);
this.setupDefautMaterial(cappedCylinder, color);
this.airspaceLayer.addAirspace(cappedCylinder);
rtnResult = true;
}
catch(Exception ex){
System.out.println(ex.getMessage());
}
return rtnResult;
}
public wwjOldAirspace(){
addAirspaceLayer("立体图元");
addCappedCylinder(34.0,122.0,30000.0,5000.0,10000.0,Color.blue);
}
public static void main(String[] args) {
String strTitle = "显示Airspace";
wwjOldAirspace wwjRun = new wwjOldAirspace();
wwjRun.setTitle(strTitle);
}
}
2.1的代码如下:
封装空间基础类,以后的要用到。
import java.awt.Color;
import gov.nasa.worldwind.layers.RenderableLayer;
import gov.nasa.worldwind.render.Material;
import gov.nasa.worldwind.render.airspaces.Airspace;
public class wwjAirPlace extends wwjBasics{
private static final long serialVersionUID = 1L;
public RenderableLayer renderableLayer;
public void addAirspaceLayer(String layerName){
renderableLayer = new RenderableLayer();
renderableLayer.setName(layerName);
this.worldWindowGLCanvas.getModel().getLayers().add(renderableLayer);
this.layerPanel.update(this.worldWindowGLCanvas);
}
public Color makeBrighter(Color color){
float[] hsbComponents = new float[3];
Color.RGBtoHSB(color.getRed(), color.getGreen(), color.getBlue(), hsbComponents);
float hue = hsbComponents[0];
float saturation = hsbComponents[1];
float brightness = hsbComponents[2];
saturation /= 3f;
brightness *= 3f;
if (saturation <0f) saturation = 0f;
if (brightness >1f) brightness = 1f;
int rgbInt = Color.HSBtoRGB(hue, saturation, brightness);
return new Color(rgbInt);
}
public void setupDefautMaterial(Airspace airspace, Color color){
Color outlineColor = makeBrighter(color);
airspace.getAttributes().setDrawOutline(true);
airspace.getAttributes().setOutlineMaterial(new Material(outlineColor));
airspace.getAttributes().setOutlineOpacity(0.9);
airspace.getAttributes().setOutlineWidth(3.0);
}
}
添加圆柱的代码如下
import java.awt.Color;
import gov.nasa.worldwind.avlist.AVKey;
import gov.nasa.worldwind.geom.LatLon;
import gov.nasa.worldwind.render.airspaces.CappedCylinder;
public class wwjCappedCylinder extends wwjAirPlace{
private static final long serialVersionUID = 1L;
public boolean addCappedCylinder(double lat,double lon,double radius ,double minAltitude,double maxAltitude,Color color ){
boolean rtnResult = false;
try{
CappedCylinder cappedCylinder = new CappedCylinder();
cappedCylinder.setCenter(LatLon.fromDegrees(lat, lon));
cappedCylinder.setRadius(radius);
cappedCylinder.setAltitudes(minAltitude,maxAltitude);
cappedCylinder.setTerrainConforming(true,true);
cappedCylinder.setValue(AVKey.DISPLAY_NAME, "30km radius Cylinder with top and bottom terrain conformance");
this.setupDefautMaterial(cappedCylinder, color);
this.renderableLayer.addRenderable(cappedCylinder);
}
catch(Exception ex){
System.out.println(ex.getMessage());
}
return rtnResult;
}
public wwjCappedCylinder(){
addAirspaceLayer("圆柱");
addCappedCylinder(34.0,122.0,30000.0,5000.0,50000.0,Color.blue);
}
public static void main(String[] args) {
String strTitle = "显示Airspace";
wwjCappedCylinder wwjRun = new wwjCappedCylinder();
wwjRun.setTitle(strTitle);
}
}
结果如下: