Java Code Examples for gov.nasa.worldwind.View#goTo()

The following examples show how to use gov.nasa.worldwind.View#goTo() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: NwwPanel.java    From hortonmachine with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Move to see a given sector.
 * 
 * @param sector
 *            the sector to go to.
 * @param animate
 *            if <code>true</code>, it animates to the position.
 */
public void goTo( Sector sector, boolean animate ) {
    View view = getWwd().getView();
    view.stopAnimations();
    view.stopMovement();
    if (sector == null) {
        return;
    }
    // Create a bounding box for the specified sector in order to estimate
    // its size in model coordinates.
    Box extent = Sector.computeBoundingBox(getWwd().getModel().getGlobe(),
            getWwd().getSceneController().getVerticalExaggeration(), sector);

    // Estimate the distance between the center position and the eye
    // position that is necessary to cause the sector to
    // fill a viewport with the specified field of view. Note that we change
    // the distance between the center and eye
    // position here, and leave the field of view constant.
    Angle fov = view.getFieldOfView();
    double zoom = extent.getRadius() / fov.cosHalfAngle() / fov.tanHalfAngle();

    // Configure OrbitView to look at the center of the sector from our
    // estimated distance. This causes OrbitView to
    // animate to the specified position over several seconds. To affect
    // this change immediately use the following:

    if (animate) {
        view.goTo(new Position(sector.getCentroid(), 0d), zoom);
    } else {
        ((OrbitView) wwd.getView()).setCenterPosition(new Position(sector.getCentroid(), 0d));
        ((OrbitView) wwd.getView()).setZoom(zoom);
    }
}
 
Example 2
Source File: NwwPanel.java    From hortonmachine with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Move to a given location.
 * 
 * @param lon
 *            the longitude.
 * @param lat
 *            the latitude.
 * @param elev
 *            the eye elevation.
 * @param azimuth
 *            if supplied, the map is rotated to follow that angle.
 * @param animate
 *            if <code>true</code>, it animates to the position.
 */
public synchronized Position goTo( Double lon, Double lat, Double elev, Double azimuth, boolean animate ) {
    View view = getWwd().getView();
    view.stopAnimations();
    view.stopMovement();

    Position eyePosition;
    if (lon == null || lat == null) {
        Position currentEyePosition = wwd.getView().getCurrentEyePosition();
        if (currentEyePosition != null) {
            lat = currentEyePosition.latitude.degrees;
            lon = currentEyePosition.longitude.degrees;
        } else {
            return null;
        }
    }

    if (elev == null) {
        // use the current
        elev = wwd.getView().getCurrentEyePosition().getAltitude();
    }
    if (Double.isNaN(elev)) {
        if (!Double.isNaN(lastElevation)) {
            elev = lastElevation;
        } else {
            elev = NwwUtilities.DEFAULT_ELEV;
        }
    }
    eyePosition = NwwUtilities.toPosition(lat, lon, elev);
    if (animate) {
        view.goTo(eyePosition, elev);
    } else {
        view.setEyePosition(eyePosition);
    }
    if (azimuth != null) {
        Angle heading = Angle.fromDegrees(azimuth);
        view.setHeading(heading);
    }
    lastElevation = elev;
    return eyePosition;
}