World Wind Java球体增加一些内容,使它在展示数据时方式更丰富,应用更灵活。
图标图元
World Wind Java中图标图元(Icon)是指尺寸为16*16、32*32、64*64的png/jpg等格式的文件,在World Wind球体上绘制为图标,绘制的大小不会随地图的视野范围改变,无论视野范围改变,无论比例尺放大缩小,它们在画布上的绘制尺寸都是指定的。
World Wind Java使用IconLayer图层类表现图标图元数据,通过IconLayer上增加UserFacingIcon类的实例显示图标图元文件,一个IconLayer图层可以容纳多个UserFacingIcon类。UserFacingIcon类创建时要指定图像文件、经纬度、海拔高度、显示尺寸等属性。
代码如下:
import java.awt.Dimension;
import gov.nasa.worldwind.geom.Angle;
import gov.nasa.worldwind.geom.Position;
import gov.nasa.worldwind.layers.IconLayer;
import gov.nasa.worldwind.layers.RenderableLayer;
import gov.nasa.worldwind.render.UserFacingIcon;
public class wwjIcon extends wwjBasics{
private static final long serialVersionUID = 1L;
protected IconLayer iconLayer;
protected RenderableLayer renderableLayer;
public boolean AddIconLayer(String layerName){
boolean rtnResult = false;
try{
iconLayer = new IconLayer();
iconLayer.setName(layerName);
this.worldWindowGLCanvas.getModel().getLayers().add(iconLayer);
rtnResult = true;
}
catch(Exception ex){
System.out.println(ex.getMessage());
}
return rtnResult;
}
public boolean AddIcon(String filePath,double lon ,double lat, Integer elevation, String IconTip){
boolean rtnResult = false;
try{
UserFacingIcon userFacingIcon = new UserFacingIcon();
userFacingIcon.setImageSource(filePath);
Position iconPosition = new Position(Angle.fromDegrees(lat),Angle.fromDegrees(lon),elevation);
userFacingIcon.setPosition(iconPosition);
userFacingIcon.setSize(new Dimension(32,32));
userFacingIcon.setShowToolTip(true);
userFacingIcon.setToolTipText(IconTip);
iconLayer.addIcon(userFacingIcon);
}catch(Exception ex){
System.out.println(ex.getMessage());
}
return rtnResult;
}
public wwjIcon(){
AddIconLayer("图标显示");
AddIcon("src/images/32x32-icon-nasa.png",120.0,38.0,0,"测试");
this.layerPanel.update(this.worldWindowGLCanvas);
}
public static void main(String[] args) {
String strTitle = "图标测试";
wwjIcon wwjRun = new wwjIcon();
wwjRun.setTitle(strTitle);
}
}
结果如下: