gov.nasa.worldwind.View Java Examples

The following examples show how to use gov.nasa.worldwind.View. 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: NwwUtilities.java    From hortonmachine with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Get the lat/long world geometry from two screen corner coordinates.
 * 
 * @param wwd
 *            the {@link WorldWindow} instance.
 * @param x1
 *            the first point screen x.
 * @param y1
 *            the first point screen y.
 * @param x2
 *            the second point screen x.
 * @param y2
 *            the second point screen y.
 * @return the world geomnetry.
 */
public static Geometry getScreenPointsPolygon( WorldWindow wwd, int x1, int y1, int x2, int y2 ) {
    View view = wwd.getView();
    Position p1 = view.computePositionFromScreenPoint(x1, y1);
    Position p2 = view.computePositionFromScreenPoint(x1, y2);
    Position p3 = view.computePositionFromScreenPoint(x2, y2);
    Position p4 = view.computePositionFromScreenPoint(x2, y1);

    Coordinate[] coords = { //
            new Coordinate(p1.longitude.degrees, p1.latitude.degrees), //
            new Coordinate(p2.longitude.degrees, p2.latitude.degrees), //
            new Coordinate(p3.longitude.degrees, p3.latitude.degrees), //
            new Coordinate(p4.longitude.degrees, p4.latitude.degrees)//
    };
    Geometry convexHull = GeometryUtilities.gf().createMultiPoint(coords).convexHull();
    return convexHull;
}
 
Example #2
Source File: NwwPanel.java    From hortonmachine with GNU General Public License v3.0 6 votes vote down vote up
public ReferencedEnvelope getViewportBounds() {
    View view = wwd.getView();
    Position posUL = view.computePositionFromScreenPoint(0, 0);
    Position posLR = view.computePositionFromScreenPoint(getWidth(), getHeight());

    if (posLR != null && posUL != null) {
        double west = posUL.longitude.degrees;
        double north = posUL.latitude.degrees;
        double east = posLR.longitude.degrees;
        double south = posLR.latitude.degrees;

        ReferencedEnvelope env = new ReferencedEnvelope(west, east, south, north, DefaultGeographicCRS.WGS84);
        return env;
    } else {
        return null;// new ReferencedEnvelope(-180, 180, -90, 90,
                    // DefaultGeographicCRS.WGS84);
    }
}
 
Example #3
Source File: WWJPanel.java    From openvisualtraceroute with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
protected void focusPoint(final GeoPoint point, final boolean isRunning, final boolean animation) {
	final long elevation = 5000 * 1000;
	if (_controller == null || _controller.getWWd() == null) {
		return;
	}
	// center the map on the given point
	final LabeledPath label = point == null ? null : _pointToLabel.get(point);
	if (label != null) {
		highlightAnnotation(label, point);
		final View view = _controller.getWWd().getView();
		final OrbitViewInputHandler ovih = (OrbitViewInputHandler) view.getViewInputHandler();
		if (animation && Env.INSTANCE.getAnimationSpeed() > 0) {
			final Position pos = new Position(label.getLocations().iterator().next(), 10);
			ovih.addPanToAnimator(pos, view.getHeading(), view.getPitch(), elevation, Env.INSTANCE.getAnimationSpeed(), true);
			//				if (_mode == Mode.TRACE_ROUTE && isRunning) {
			//					// if tracing, move at the speed of the timeout
			//					final Position pos = new Position(label.getLocations().iterator().next(), 10);
			//					ovih.addPanToAnimator(pos, view.getHeading(), view.getPitch(), elevation,
			//							Env.INSTANCE.getAnimationSpeed(), true);
			//				} else if (_mode == Mode.TRACE_ROUTE || !isRunning) {
			//					_controller.getWWd().getView()
			//							.goTo(new Position(label.getLocations().iterator().next(), 10), elevation);
			//				}
		} else {
			final Position p = new Position(Angle.fromDegrees(point.getLat()), Angle.fromDegrees(point.getLon()), 2000);
			((OrbitView) view).setCenterPosition(p);
		}
	}
}
 
Example #4
Source File: NwwPanel.java    From hortonmachine with GNU General Public License v3.0 5 votes vote down vote up
public void setZoomLimits( double minZoom, double maxZoom ) {
    View view = getWwd().getView();
    if (view != null && view instanceof OrbitView) {
        OrbitView oView = (OrbitView) view;
        OrbitViewLimits orbitViewLimits = oView.getOrbitViewLimits();
        orbitViewLimits.setZoomLimits(minZoom, maxZoom);
    }
}
 
Example #5
Source File: NwwPanel.java    From hortonmachine with GNU General Public License v3.0 5 votes vote down vote up
public void setPitchLimits( Angle minAngle, Angle maxangle ) {
    View view = getWwd().getView();
    if (view != null && view instanceof OrbitView) {
        OrbitView oView = (OrbitView) view;
        OrbitViewLimits orbitViewLimits = oView.getOrbitViewLimits();
        orbitViewLimits.setPitchLimits(minAngle, maxangle);
    }
}
 
Example #6
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 #7
Source File: WWBaseToolView.java    From snap-desktop with GNU General Public License v3.0 5 votes vote down vote up
private void gotoProduct(final Product product) {
    if (product == null) return;

    final View theView = getWwd().getView();
    final Position origPos = theView.getEyePosition();
    final GeoCoding geoCoding = product.getSceneGeoCoding();
    if (geoCoding != null && origPos != null) {
        final GeoPos centre = product.getSceneGeoCoding().getGeoPos(new PixelPos(product.getSceneRasterWidth() / 2,
                                                                            product.getSceneRasterHeight() / 2), null);
        centre.normalize();
        theView.setEyePosition(Position.fromDegrees(centre.getLat(), centre.getLon(), origPos.getElevation()));
    }
}
 
Example #8
Source File: NwwUtilities.java    From hortonmachine with GNU General Public License v3.0 4 votes vote down vote up
public static Point getScreenPoint( WorldWindow wwd, int x1, int y1 ) {
    View view = wwd.getView();
    Position p = view.computePositionFromScreenPoint(x1, y1);
    Coordinate c = new Coordinate(p.longitude.degrees, p.latitude.degrees);
    return GeometryUtilities.gf().createPoint(c);
}
 
Example #9
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;
}