sarsegmentplane.java
来自「world wind java sdk 源码」· Java 代码 · 共 913 行 · 第 1/3 页
JAVA
913 行
public String getText(SegmentPlane segmentPlane, Position position, AVList values) { StringBuilder sb = new StringBuilder(); sb.append("Lat ").append(this.formatAngle(position.getLatitude())); sb.append("\n"); sb.append("Lon ").append(this.formatAngle(position.getLongitude())); sb.append("\n"); sb.append("Alt ").append(this.formatElevation(position.getElevation())); if (this.isShowHeightAboveSurface()) { if (values != null) { Double height = AVListImpl.getDoubleValue(values, AVKey.HEIGHT); if (height != null) { sb.append("\n"); sb.append("AGL ").append(this.formatElevation(height)); } } } if (this.isShowSegmentHeading()) { LatLon[] locations = segmentPlane.getPlaneLocations(); Angle heading = LatLon.rhumbAzimuth(locations[0], locations[1]); sb.append("\n"); sb.append("Heading ").append(SARSegmentPlane.formatAngle(null, heading)); } return sb.toString(); } } public static class AltitudeLabelAttributes extends SARLabelAttributes { public AltitudeLabelAttributes(Color color, Font font, String horizontalAlignment, String verticalAlignment, SARSegmentPlane context) { super(color, font, horizontalAlignment, verticalAlignment, context); } public AltitudeLabelAttributes() { } public SegmentPlaneAttributes.LabelAttributes copy() { return this.copyTo(new AltitudeLabelAttributes()); } public String getText(SegmentPlane segmentPlane, Position position, AVList values) { StringBuilder sb = new StringBuilder(); sb.append(this.formatElevation(position.getElevation())); return sb.toString(); } } public static class AxisLabelAttributes extends SARLabelAttributes { public AxisLabelAttributes(Color color, Font font, String horizontalAlignment, String verticalAlignment, SARSegmentPlane context) { super(color, font, horizontalAlignment, verticalAlignment, context); } public AxisLabelAttributes() { } public SegmentPlaneAttributes.LabelAttributes copy() { return this.copyTo(new AxisLabelAttributes()); } public String getText(SegmentPlane segmentPlane, Position position, AVList values) { StringBuilder sb = new StringBuilder(); if (values != null) { Double width = AVListImpl.getDoubleValue(values, AVKey.WIDTH); Double height = AVListImpl.getDoubleValue(values, AVKey.HEIGHT); boolean haveTuple = (width != null && height != null); if (haveTuple) sb.append("("); if (width != null) sb.append(this.formatElevation(width)); if (haveTuple) sb.append(", "); if (height != null) sb.append(this.formatElevation(height)); if (haveTuple) sb.append(")"); } if (sb.length() == 0) return null; return sb.toString(); } } public static class MessageLabelAttributes extends SegmentPlaneAttributes.LabelAttributes { private String message; public MessageLabelAttributes(Color color, Font font, String horizontalAlignment, String verticalAlignment, String message) { super(color, font, horizontalAlignment, verticalAlignment); this.message = message; } public MessageLabelAttributes() { } public String getMessage() { return this.message; } public void setMessage(String message) { this.message = message; } public SegmentPlaneAttributes.LabelAttributes copy() { return this.copyTo(new MessageLabelAttributes()); } protected SegmentPlaneAttributes.LabelAttributes copyTo(SegmentPlaneAttributes.LabelAttributes copy) { super.copyTo(copy); if (copy instanceof MessageLabelAttributes) { ((MessageLabelAttributes) copy).setMessage(this.getMessage()); } return copy; } public String getText(SegmentPlane segmentPlane, Position position, AVList values) { return this.getMessage(); } } protected static String formatAngle(String format, Angle angle) { if (Angle.ANGLE_FORMAT_DMS.equals(format)) { return angle.toDMSString(); } else { return angle.toDecimalDegreesString(4); } } protected static String formatElevation(String elevationFormat, double elevation) { if (SAR2.UNIT_IMPERIAL.equals(elevationFormat)) { return String.format("%.0f ft", WWMath.convertMetersToFeet(elevation)); } else // Default to metric units. { return String.format("%.0f m", elevation); } } //**************************************************************// //******************** Utility Methods ***********************// //**************************************************************// protected static double getSurfaceElevationAt(WorldWindow wwd, Angle latitude, Angle longitude) { if (wwd == null) { String message = Logging.getMessage("nullValue.WorldWindow"); Logging.logger().severe(message); throw new IllegalArgumentException(message); } Globe globe = wwd.getModel().getGlobe(); if (globe == null) { String message = Logging.getMessage("nullValue.GlobeIsNull"); Logging.logger().severe(message); throw new IllegalArgumentException(message); } SectorGeometryList sgl = wwd.getSceneController().getTerrain(); if (sgl != null) { Vec4 point = sgl.getSurfacePoint(latitude, longitude); if (point != null) { Position pos = globe.computePositionFromPoint(point); return pos.getElevation(); } } return globe.getElevation(latitude, longitude); } protected static double[] computeAltitudesToFitPositions(WorldWindow wwd, SegmentPlane segmentPlane, Iterable<? extends Position> positions, boolean recallUserDefinedVGap) { Globe globe = wwd.getModel().getGlobe(); double[] altitudes = segmentPlane.getPlaneAltitudes(); double[] gridSizes = segmentPlane.getGridCellDimensions(); Position[] segmentPositions = segmentPlane.getSegmentPositions(); double oldMaxSegmentAltitude = Math.max(segmentPositions[0].getElevation(), segmentPositions[1].getElevation()); double[] minAndMaxElevation = globe.getMinAndMaxElevations(Sector.boundingSector(positions)); double newMaxSegmentAltitude = -Double.MAX_VALUE; for (Position pos : positions) { if (newMaxSegmentAltitude < pos.getElevation()) newMaxSegmentAltitude = pos.getElevation(); } double segmentVGap = altitudes[1] - oldMaxSegmentAltitude; if (!recallUserDefinedVGap || segmentVGap < 0) { segmentVGap = computeInitialVerticalGap(wwd, segmentPlane, positions); } return new double[] { gridSizes[1] * Math.floor(minAndMaxElevation[0] / gridSizes[1]), newMaxSegmentAltitude + segmentVGap }; } protected static LatLon[] computeLocationsToFitPositions(WorldWindow wwd, SegmentPlane segmentPlane, Position position1, Position position2, boolean recallUserDefinedHGap) { LatLon[] locations = segmentPlane.getPlaneLocations(); Position[] segmentPositions = segmentPlane.getSegmentPositions(); Angle segmentHGap = LatLon.rhumbDistance(segmentPositions[1], locations[1]); if (!recallUserDefinedHGap || segmentHGap.compareTo(Angle.ZERO) < 0) { segmentHGap = computeInitialHorizontalGap(wwd, segmentPlane, position1, position2); } Angle newSegmentHeading = LatLon.rhumbAzimuth(position1, position2); Angle newSegmentLength = LatLon.rhumbDistance(position1, position2).add(segmentHGap); return new LatLon[] { new LatLon(position1), LatLon.rhumbEndPosition(position1, newSegmentHeading, newSegmentLength) }; } protected static double computeInitialVerticalGap(WorldWindow wwd, SegmentPlane segmentPlane, Iterable<? extends Position> positions) { double[] gridCellDimensions = segmentPlane.getGridCellDimensions(); double maxHeightAboveSurface = -Double.MAX_VALUE; for (Position pos : positions) { double heightAboveSurface = pos.getElevation() - getSurfaceElevationAt(wwd, pos.getLatitude(), pos.getLongitude()); if (heightAboveSurface > maxHeightAboveSurface) { maxHeightAboveSurface = heightAboveSurface; } } return Math.max(2 * gridCellDimensions[1], maxHeightAboveSurface / 2.0); } protected static Angle computeInitialHorizontalGap(WorldWindow wwd, SegmentPlane segmentPlane, Position position1, Position position2) { double[] gridCellDimensions = segmentPlane.getGridCellDimensions(); double gridWidthRadians = gridCellDimensions[0] / wwd.getModel().getGlobe().getRadius(); double segmentDistanceRadians = LatLon.rhumbDistance(position1, position2).radians; return Angle.fromRadians(Math.max(2 * gridWidthRadians, segmentDistanceRadians / 2.0)); }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?