📄 abstractairspace.java
字号:
count++;
}
}
// If there's no mean center point, then we cannot compute an enclosing extent, so just return null.
if (center == null)
{
return null;
}
// Divide by the number of contributing extents to compute the mean center point.
center = center.divide3(count);
// Compute the maximum distance from the mean center point to the outermost point on an airspace extent. This
// will be the radius of the enclosing extent.
for (Airspace airspace : airspaces)
{
Extent extent = airspace.getExtent(dc);
if (extent != null)
{
double distance = extent.getCenter().distanceTo3(center) + extent.getRadius();
if (radius < distance)
radius = distance;
}
}
return new Sphere(center, radius);
}
protected MemoryCache getGeometryCache()
{
return WorldWind.getMemoryCache(GEOMETRY_CACHE_KEY);
}
protected boolean isExpired(DrawContext dc, Geometry geom)
{
if (dc == null)
{
String message = Logging.getMessage("nullValue.DrawContextIsNull");
Logging.logger().severe(message);
throw new IllegalArgumentException(message);
}
if (dc.getGlobe() == null)
{
String message = Logging.getMessage("nullValue.DrawingContextGlobeIsNull");
Logging.logger().severe(message);
throw new IllegalArgumentException(message);
}
if (geom == null)
{
String message = "nullValue.AirspaceGeometryIsNull";
Logging.logger().severe(message);
throw new IllegalArgumentException(message);
}
Object o = geom.getValue(EXPIRY_TIME);
if (o != null && o instanceof Long)
if (dc.getFrameTimeStamp() > (Long) o)
return true;
o = geom.getValue(GLOBE_KEY);
if (o != null)
if (!dc.getGlobe().getStateKey(dc).equals(o))
return true;
return false;
}
protected void updateExpiryCriteria(DrawContext dc, Geometry geom)
{
if (dc == null)
{
String message = Logging.getMessage("nullValue.DrawContextIsNull");
Logging.logger().severe(message);
throw new IllegalArgumentException(message);
}
if (dc.getGlobe() == null)
{
String message = Logging.getMessage("nullValue.DrawingContextGlobeIsNull");
Logging.logger().severe(message);
throw new IllegalArgumentException(message);
}
long expiryTime = this.getExpiryTime();
geom.setValue(EXPIRY_TIME, (expiryTime >= 0L) ? expiryTime : null);
geom.setValue(GLOBE_KEY, dc.getGlobe().getStateKey(dc));
}
protected long getExpiryTime()
{
return this.expiryTime;
}
protected void setExpiryTime(long timeMillis)
{
this.expiryTime = timeMillis;
}
protected long[] getExpiryRange()
{
long[] array = new long[2];
array[0] = this.minExpiryTime;
array[1] = this.maxExpiryTime;
return array;
}
protected void setExpiryRange(long minTimeMillis, long maxTimeMillis)
{
this.minExpiryTime = minTimeMillis;
this.maxExpiryTime = maxTimeMillis;
}
protected long nextExpiryTime(DrawContext dc, boolean[] terrainConformance)
{
if (dc == null)
{
String message = Logging.getMessage("nullValue.DrawContextIsNull");
Logging.logger().severe(message);
throw new IllegalArgumentException(message);
}
long expiryTime;
if (terrainConformance[0] || terrainConformance[1])
{
long time = nextLong(this.minExpiryTime, this.maxExpiryTime);
expiryTime = dc.getFrameTimeStamp() + time;
}
else
{
expiryTime = -1L;
}
return expiryTime;
}
private static long nextLong(long lo, long hi)
{
long n = hi - lo + 1;
long i = rand.nextLong() % n;
return lo + ((i < 0 )? -i : i);
}
protected void clearElevationMap()
{
this.elevationMap.clear();
}
public Vec4 computePointFromPosition(DrawContext dc, Angle latitude, Angle longitude, double elevation,
boolean terrainConformant)
{
if (dc == null)
{
String message = Logging.getMessage("nullValue.DrawContextIsNull");
Logging.logger().severe(message);
throw new IllegalArgumentException(message);
}
if (dc.getGlobe() == null)
{
String message = Logging.getMessage("nullValue.DrawingContextGlobeIsNull");
Logging.logger().severe(message);
throw new IllegalStateException(message);
}
if (latitude == null || longitude == null)
{
String message = Logging.getMessage("nullValue.LatitudeOrLongitudeIsNull");
Logging.logger().severe(message);
throw new IllegalArgumentException(message);
}
double newElevation = elevation;
if (terrainConformant)
{
newElevation += this.computeElevationAt(dc, latitude, longitude);
}
return dc.getGlobe().computePointFromPosition(latitude, longitude, newElevation);
}
protected double computeElevationAt(DrawContext dc, Angle latitude, Angle longitude)
{
if (dc == null)
{
String message = Logging.getMessage("nullValue.DrawContextIsNull");
Logging.logger().severe(message);
throw new IllegalArgumentException(message);
}
if (dc.getGlobe() == null)
{
String message = Logging.getMessage("nullValue.DrawingContextGlobeIsNull");
Logging.logger().severe(message);
throw new IllegalStateException(message);
}
if (latitude == null || longitude == null)
{
String message = Logging.getMessage("nullValue.LatitudeOrLongitudeIsNull");
Logging.logger().severe(message);
throw new IllegalArgumentException(message);
}
Globe globe;
LatLon latlon;
Vec4 surfacePoint;
Position surfacePos;
Double elevation;
latlon = new LatLon(latitude, longitude);
elevation = this.elevationMap.get(latlon);
if (elevation == null)
{
globe = dc.getGlobe();
elevation = 0.0;
surfacePoint = dc.getPointOnGlobe(latitude, longitude);
if (surfacePoint != null)
{
surfacePos = globe.computePositionFromPoint(surfacePoint);
elevation += surfacePos.getElevation();
}
else
{
elevation += dc.getVerticalExaggeration() * globe.getElevation(latitude, longitude);
}
this.elevationMap.put(latlon, elevation);
}
return elevation;
}
//**************************************************************//
//******************** END Geometry Rendering *****************//
//**************************************************************//
public String getRestorableState()
{
RestorableSupport rs = RestorableSupport.newRestorableSupport();
this.doGetRestorableState(rs, null);
return rs.getStateAsXml();
}
protected void doGetRestorableState(RestorableSupport rs, RestorableSupport.StateObject context)
{
// Method is invoked by subclasses to have superclass add its state and only its state
this.doMyGetRestorableState(rs, context);
}
private void doMyGetRestorableState(RestorableSupport rs, RestorableSupport.StateObject context)
{
rs.addStateValueAsBoolean(context, "visible", this.isVisible());
rs.addStateValueAsDouble(context, "lowerAltitude", this.getAltitudes()[0]);
rs.addStateValueAsDouble(context, "upperAltitude", this.getAltitudes()[1]);
rs.addStateValueAsBoolean(context, "lowerTerrainConforming", this.isTerrainConforming()[0]);
rs.addStateValueAsBoolean(context, "upperTerrainConforming", this.isTerrainConforming()[1]);
this.attributes.getRestorableState(rs, rs.addStateObject(context, "attributes"));
}
public void restoreState(String stateInXml)
{
if (stateInXml == null)
{
String message = Logging.getMessage("nullValue.StringIsNull");
Logging.logger().severe(message);
throw new IllegalArgumentException(message);
}
RestorableSupport rs;
try
{
rs = RestorableSupport.parse(stateInXml);
}
catch (Exception e)
{
// Parsing the document specified by stateInXml failed.
String message = Logging.getMessage("generic.ExceptionAttemptingToParseStateXml", stateInXml);
Logging.logger().severe(message);
throw new IllegalArgumentException(message, e);
}
this.doRestoreState(rs, null);
}
protected void doRestoreState(RestorableSupport rs, RestorableSupport.StateObject context)
{
// Method is invoked by subclasses to have superclass add its state and only its state
this.doMyRestoreState(rs, context);
}
private void doMyRestoreState(RestorableSupport rs, RestorableSupport.StateObject context)
{
Boolean booleanState = rs.getStateValueAsBoolean(context, "visible");
if (booleanState != null)
this.setVisible(booleanState);
Double lo = rs.getStateValueAsDouble(context, "lowerAltitude");
if (lo == null)
lo = this.getAltitudes()[0];
Double hi = rs.getStateValueAsDouble(context, "upperAltitude");
if (hi == null)
hi = this.getAltitudes()[1];
this.setAltitudes(lo, hi);
Boolean loConform = rs.getStateValueAsBoolean(context, "lowerTerrainConforming");
if (loConform == null)
loConform = this.isTerrainConforming()[0];
Boolean hiConform = rs.getStateValueAsBoolean(context, "upperTerrainConforming");
if (hiConform == null)
hiConform = this.isTerrainConforming()[1];
this.setTerrainConforming(loConform, hiConform);
RestorableSupport.StateObject so = rs.getStateObject(context, "attributes");
if (so != null)
this.getAttributes().restoreState(rs, so);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -