basicorbitviewlimits.java
来自「world wind java sdk 源码」· Java 代码 · 共 380 行
JAVA
380 行
/* Copyright (C) 2001, 2009 United States Government as represented bythe Administrator of the National Aeronautics and Space Administration.All Rights Reserved.*/package gov.nasa.worldwind.view;import gov.nasa.worldwind.geom.*;import gov.nasa.worldwind.util.*;/** * @author dcollins * @version $Id: BasicOrbitViewLimits.java 10301 2009-04-17 20:21:46Z dcollins $ */public class BasicOrbitViewLimits implements OrbitViewLimits{ protected Sector centerLocationLimits; protected double minCenterElevation; protected double maxCenterElevation; protected Angle minHeading; protected Angle maxHeading; protected Angle minPitch; protected Angle maxPitch; protected double minZoom; protected double maxZoom; public BasicOrbitViewLimits() { this.centerLocationLimits = Sector.FULL_SPHERE; this.minCenterElevation = -Double.MAX_VALUE; this.maxCenterElevation = Double.MAX_VALUE; this.minHeading = Angle.NEG180; this.maxHeading = Angle.POS180; this.minPitch = Angle.ZERO; this.maxPitch = Angle.POS90; this.minZoom = 0; this.maxZoom = Double.MAX_VALUE; } public Sector getCenterLocationLimits() { return this.centerLocationLimits; } public void setCenterLocationLimits(Sector sector) { if (sector == null) { String message = Logging.getMessage("nullValue.SectorIsNull"); Logging.logger().severe(message); throw new IllegalArgumentException(message); } this.centerLocationLimits = sector; } public double[] getCenterElevationLimits() { return new double[] {this.minCenterElevation, this.maxCenterElevation}; } public void setCenterElevationLimits(double minValue, double maxValue) { this.minCenterElevation = minValue; this.maxCenterElevation = maxValue; } public Angle[] getHeadingLimits() { return new Angle[] {this.minHeading, this.maxHeading}; } public void setHeadingLimits(Angle minAngle, Angle maxAngle) { if (minAngle == null || maxAngle == null) { String message = Logging.getMessage("nullValue.MinOrMaxAngleIsNull"); Logging.logger().severe(message); throw new IllegalArgumentException(message); } this.minHeading = minAngle; this.maxHeading = maxAngle; } public Angle[] getPitchLimits() { return new Angle[] {this.minPitch, this.maxPitch}; } public void setPitchLimits(Angle minAngle, Angle maxAngle) { if (minAngle == null || maxAngle == null) { String message = Logging.getMessage("nullValue.MinOrMaxAngleIsNull"); Logging.logger().severe(message); throw new IllegalArgumentException(message); } this.minPitch = minAngle; this.maxPitch = maxAngle; } public double[] getZoomLimits() { return new double[] {this.minZoom, this.maxZoom}; } public void setZoomLimits(double minValue, double maxValue) { this.minZoom = minValue; this.maxZoom = maxValue; } public static void applyLimits(OrbitView view, OrbitViewLimits viewLimits) { if (view == null) { String message = Logging.getMessage("nullValue.ViewIsNull"); Logging.logger().severe(message); throw new IllegalArgumentException(message); } if (viewLimits == null) { String message = Logging.getMessage("nullValue.ViewLimitsIsNull"); Logging.logger().severe(message); throw new IllegalArgumentException(message); } view.setCenterPosition(limitCenterPosition(view.getCenterPosition(), viewLimits)); view.setHeading(limitHeading(view.getHeading(), viewLimits)); view.setPitch(limitPitch(view.getPitch(), viewLimits)); view.setZoom(limitZoom(view.getZoom(), viewLimits)); } public static Position limitCenterPosition(Position position, OrbitViewLimits viewLimits) { if (position == null) { String message = Logging.getMessage("nullValue.PositionIsNull"); Logging.logger().severe(message); throw new IllegalArgumentException(message); } if (viewLimits == null) { String message = Logging.getMessage("nullValue.ViewLimitsIsNull"); Logging.logger().severe(message); throw new IllegalArgumentException(message); } return new Position( limitCenterLocation(position.getLatitude(), position.getLongitude(), viewLimits), limitCenterElevation(position.getElevation(), viewLimits)); } public static LatLon limitCenterLocation(Angle latitude, Angle longitude, OrbitViewLimits viewLimits) { if (latitude == null || longitude == null) { String message = Logging.getMessage("nullValue.LatitudeOrLongitudeIsNull"); Logging.logger().severe(message); throw new IllegalArgumentException(message); } if (viewLimits == null) { String message = Logging.getMessage("nullValue.ViewLimitsIsNull"); Logging.logger().severe(message); throw new IllegalArgumentException(message); } Sector limits = viewLimits.getCenterLocationLimits(); Angle newLatitude = latitude; Angle newLongitude = longitude; if (latitude.compareTo(limits.getMinLatitude()) < 0) { newLatitude = limits.getMinLatitude(); } else if (latitude.compareTo(limits.getMaxLatitude()) > 0) { newLatitude = limits.getMaxLatitude(); } if (longitude.compareTo(limits.getMinLongitude()) < 0) { newLongitude = limits.getMinLongitude(); } else if (longitude.compareTo(limits.getMaxLongitude()) > 0) { newLongitude = limits.getMaxLongitude(); } return new LatLon(newLatitude, newLongitude); } public static double limitCenterElevation(double value, OrbitViewLimits viewLimits) { if (viewLimits == null) { String message = Logging.getMessage("nullValue.ViewLimitsIsNull"); Logging.logger().severe(message); throw new IllegalArgumentException(message); } double[] limits = viewLimits.getCenterElevationLimits(); double newValue = value; if (value < limits[0]) { newValue = limits[0]; } else if (value > limits[1]) { newValue = limits[1]; } return newValue; } public static Angle limitHeading(Angle angle, OrbitViewLimits viewLimits) { if (angle == null) { String message = Logging.getMessage("nullValue.AngleIsNull"); Logging.logger().severe(message); throw new IllegalArgumentException(message); } if (viewLimits == null) { String message = Logging.getMessage("nullValue.ViewLimitsIsNull"); Logging.logger().severe(message); throw new IllegalArgumentException(message); } Angle[] limits = viewLimits.getHeadingLimits(); Angle newAngle = angle; if (angle.compareTo(limits[0]) < 0) { newAngle = limits[0]; } else if (angle.compareTo(limits[1]) > 0) { newAngle = limits[1]; } return newAngle; } public static Angle limitPitch(Angle angle, OrbitViewLimits viewLimits) { if (angle == null) { String message = Logging.getMessage("nullValue.AngleIsNull"); Logging.logger().severe(message); throw new IllegalArgumentException(message); } if (viewLimits == null) { String message = Logging.getMessage("nullValue.ViewLimitsIsNull"); Logging.logger().severe(message); throw new IllegalArgumentException(message); } Angle[] limits = viewLimits.getPitchLimits(); Angle newAngle = angle; if (angle.compareTo(limits[0]) < 0) { newAngle = limits[0]; } else if (angle.compareTo(limits[1]) > 0) { newAngle = limits[1]; } return newAngle; } public static double limitZoom(double value, OrbitViewLimits viewLimits) { if (viewLimits == null) { String message = Logging.getMessage("nullValue.ViewLimitsIsNull"); Logging.logger().severe(message); throw new IllegalArgumentException(message); } double[] limits = viewLimits.getZoomLimits(); double newValue = value; if (value < limits[0]) { newValue = limits[0]; } else if (value > limits[1]) { newValue = limits[1]; } return newValue; } //**************************************************************// //******************** Restorable State ***********************// //**************************************************************// public void getRestorableState(RestorableSupport rs, RestorableSupport.StateObject context) { rs.addStateValueAsSector(context, "centerLocationLimits", this.centerLocationLimits); rs.addStateValueAsDouble(context, "minCenterElevation", this.minCenterElevation); rs.addStateValueAsDouble(context, "maxCenterElevation", this.maxCenterElevation); rs.addStateValueAsDouble(context, "minHeadingDegrees", this.minHeading.degrees); rs.addStateValueAsDouble(context, "maxHeadingDegrees", this.maxHeading.degrees); rs.addStateValueAsDouble(context, "minPitchDegrees", this.minPitch.degrees); rs.addStateValueAsDouble(context, "maxPitchDegrees", this.maxPitch.degrees); rs.addStateValueAsDouble(context, "minZoom", this.minZoom); rs.addStateValueAsDouble(context, "maxZoom", this.maxZoom); } public void restoreState(RestorableSupport rs, RestorableSupport.StateObject context) { Sector sector = rs.getStateValueAsSector(context, "centerLocationLimits"); if (sector != null) this.setCenterLocationLimits(sector); // Min and max center elevation. double[] minAndMaxValue = this.getCenterElevationLimits(); Double min = rs.getStateValueAsDouble(context, "minCenterElevation"); if (min != null) minAndMaxValue[0] = min; Double max = rs.getStateValueAsDouble(context, "maxCenterElevation"); if (max != null) minAndMaxValue[1] = max; if (min != null || max != null) this.setCenterElevationLimits(minAndMaxValue[0], minAndMaxValue[1]); // Min and max heading angle. Angle[] minAndMaxAngle = this.getHeadingLimits(); min = rs.getStateValueAsDouble(context, "minHeadingDegrees"); if (min != null) minAndMaxAngle[0] = Angle.fromDegrees(min); max = rs.getStateValueAsDouble(context, "maxHeadingDegrees"); if (max != null) minAndMaxAngle[1] = Angle.fromDegrees(max); if (min != null || max != null) this.setHeadingLimits(minAndMaxAngle[0], minAndMaxAngle[1]); // Min and max pitch angle. minAndMaxAngle = this.getPitchLimits(); min = rs.getStateValueAsDouble(context, "minPitchDegrees"); if (min != null) minAndMaxAngle[0] = Angle.fromDegrees(min); max = rs.getStateValueAsDouble(context, "maxPitchDegrees"); if (max != null) minAndMaxAngle[1] = Angle.fromDegrees(max); if (min != null || max != null) this.setPitchLimits(minAndMaxAngle[0], minAndMaxAngle[1]); // Min and max zoom value. minAndMaxValue = this.getZoomLimits(); min = rs.getStateValueAsDouble(context, "minZoom"); if (min != null) minAndMaxValue[0] = min; max = rs.getStateValueAsDouble(context, "maxZoom"); if (max != null) minAndMaxValue[1] = max; if (min != null || max != null) this.setZoomLimits(minAndMaxValue[0], minAndMaxValue[1]); }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?