@Override public void run() { this.wwd.getNavigator().setAsCamera(this.wwd.getGlobe(), this.camera); this.wwd.requestRedraw(); pool.release(this.reset()); } }
/** * Updates the time of all timed renderables of a world window. */ @Override public Boolean call(LocalDateTime localDateTime) { if (null != localDateTime) { List<Layer> renderableLayers = this.picker.worldWindow.getModel().getLayers().getLayersByClass(RenderableLayer.class); for (Layer layer : renderableLayers) { for (Renderable renderable : ((RenderableLayer) layer).getRenderables()) { if (renderable instanceof TimedRenderable) { ((TimedRenderable) renderable).setTime(ZonedDateTime.of(localDateTime, ZoneId.of("UTC"))); } } } this.picker.worldWindow.redrawNow(); } return true; }
@Override protected void gestureDidBegin() { if (this.activeGestures++ == 0) { this.wwd.getNavigator().getAsCamera(this.wwd.getGlobe(), this.beginCamera); this.camera.set(this.beginCamera); } }
protected void handleTilt(GestureRecognizer recognizer) { int state = recognizer.getState(); float dx = recognizer.getTranslationX(); float dy = recognizer.getTranslationY(); if (state == WorldWind.BEGAN) { this.gestureDidBegin(); this.lastRotation = 0; } else if (state == WorldWind.CHANGED) { // Apply the change in tilt to the navigator, relative to when the gesture began. double headingDegrees = 180 * dx / this.wwd.getWidth(); double tiltDegrees = -180 * dy / this.wwd.getHeight(); this.lookAt.heading = WWMath.normalizeAngle360(this.beginLookAt.heading + headingDegrees); this.lookAt.tilt = this.beginLookAt.tilt + tiltDegrees; this.applyLimits(this.lookAt); this.wwd.getNavigator().setAsLookAt(this.wwd.getGlobe(), this.lookAt); this.wwd.requestRedraw(); } else if (state == WorldWind.ENDED || state == WorldWind.CANCELLED) { this.gestureDidEnd(); } }
/** * Creates a new WorldWindow (GLSurfaceView) object with a WMS Layer * * @return The WorldWindow object containing the globe. */ @Override public WorldWindow createWorldWindow() { // Let the super class (BasicGlobeFragment) do the creation WorldWindow wwd = super.createWorldWindow(); // Override the WorldWindow's built-in navigation behavior by adding picking support. wwd.setWorldWindowController(new PickNavigateController()); // Add a layer for placemarks to the WorldWindow RenderableLayer layer = new RenderableLayer("Placemarks"); wwd.getLayers().addLayer(layer); // Create a few placemarks with highlight attributes and add them to the layer layer.addRenderable(createAirportPlacemark(Position.fromDegrees(34.2000, -119.2070, 0), "Oxnard Airport")); layer.addRenderable(createAirportPlacemark(Position.fromDegrees(34.2138, -119.0944, 0), "Camarillo Airport")); layer.addRenderable(createAirportPlacemark(Position.fromDegrees(34.1193, -119.1196, 0), "Pt Mugu Naval Air Station")); layer.addRenderable(createAircraftPlacemark(Position.fromDegrees(34.15, -119.15, 2000))); // Position the viewer to look near the airports LookAt lookAt = new LookAt().set(34.15, -119.15, 0, WorldWind.ABSOLUTE, 2e4 /*range*/, 0 /*heading*/, 45 /*tilt*/, 0 /*roll*/); wwd.getNavigator().setAsLookAt(wwd.getGlobe(), lookAt); return wwd; }
double metersPerPixel = this.wwd.pixelSizeAtDistance(alt); double forwardMeters = (dy - this.lastY) * metersPerPixel; double sideMeters = -(dx - this.lastX) * metersPerPixel; this.lastY = dy; double globeRadius = this.wwd.getGlobe().getRadiusAt(lat, lon); double forwardDegrees = Math.toDegrees(forwardMeters / globeRadius); double sideDegrees = Math.toDegrees(sideMeters / globeRadius); this.wwd.getNavigator().setAsCamera(this.wwd.getGlobe(), this.camera); this.wwd.requestRedraw(); } else if (state == WorldWind.ENDED || state == WorldWind.CANCELLED) { this.gestureDidEnd();
@Override public void creationSucceeded(LayerFactory factory, Layer layer) { // Add the finished GeoPackage layer to the WorldWindow. getWorldWindow().getLayers().addLayer(layer); // Place the viewer directly over the GeoPackage image. getWorldWindow().getNavigator().setLatitude(36.8139677556754); getWorldWindow().getNavigator().setLongitude(-76.03260320181615); getWorldWindow().getNavigator().setAltitude(20e3); Log.i("gov.nasa.worldwind", "GeoPackage layer creation succeeded"); }
@Override public void doFrame(long frameTimeNanos) { if (this.lastFrameTimeNanos != 0) { // Compute the frame duration in seconds. double frameDurationSeconds = (frameTimeNanos - this.lastFrameTimeNanos) * 1.0e-9; double cameraDegrees = (frameDurationSeconds * this.cameraDegreesPerSecond); // Move the navigator to continuously bring new tiles into view. Navigator navigator = getWorldWindow().getNavigator(); navigator.setLongitude(navigator.getLongitude() + cameraDegrees); // Redraw the WorldWindow to display the above changes. this.getWorldWindow().requestRedraw(); } Choreographer.getInstance().postFrameCallback(this); this.lastFrameTimeNanos = frameTimeNanos; }
public void actionPerformed(ActionEvent actionEvent) { // Simply enable or disable the layer based on its toggle button. if (((JCheckBox) actionEvent.getSource()).isSelected()) this.layer.setEnabled(true); else this.layer.setEnabled(false); wwd.redraw(); } }
@Override public void onMessage(String name, Object sender, Map<Object, Object> userProperties) { if (name.equals(WorldWind.REQUEST_REDRAW)) { this.requestRedraw(); // may be called on any thread } }
/** * Prepares this WorldWindow for drawing and event handling. * * @param configChooser optional argument for choosing an EGL configuration; may be null */ protected void init(EGLConfigChooser configChooser) { // Initialize the WorldWindow's navigator. Location initLocation = Location.fromTimeZone(TimeZone.getDefault()); double initAltitude = this.distanceToViewGlobeExtents() * 1.1; // add 10% to the minimum distance to allow for space around the screen edges this.navigator.setLatitude(initLocation.latitude); this.navigator.setLongitude(initLocation.longitude); this.navigator.setAltitude(initAltitude); // Initialize the WorldWindow's controller. this.worldWindowController.setWorldWindow(this); // Initialize the WorldWindow's render resource cache. int cacheCapacity = RenderResourceCache.recommendedCapacity(this.getContext()); this.renderResourceCache = new RenderResourceCache(cacheCapacity); // Set up to render on demand to an OpenGL ES 2.x context // TODO Investigate and use the EGL chooser submitted by jgiovino this.setEGLConfigChooser(configChooser); this.setEGLContextClientVersion(2); // must be called before setRenderer this.setRenderer(this); this.setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY); // must be called after setRenderer // Log a message with some basic information about the WorldWindow's configuration. Logger.log(Logger.INFO, "WorldWindow initialized"); }
/** * Creates a new WorldWindow (GLSurfaceView) object. */ public WorldWindow createWorldWindow() { // Create the WorldWindow (a GLSurfaceView) which displays the globe. this.wwd = new WorldWindow(getContext()); // Setup the WorldWindow's layers. this.wwd.getLayers().addLayer(new BackgroundLayer()); this.wwd.getLayers().addLayer(new BlueMarbleLandsatLayer()); // Setup the WorldWindow's elevation coverages. this.wwd.getGlobe().getElevationModel().addCoverage(new BasicElevationCoverage()); return this.wwd; }
/** * Creates a new WorldWindow object with a custom WorldWindowController. */ @Override public WorldWindow createWorldWindow() { // Let the super class (BasicGlobeFragment) do the creation WorldWindow wwd = super.createWorldWindow(); // Override the default "look at" gesture behavior with a camera centric gesture controller wwd.setWorldWindowController(new CameraController()); // Create a camera position above KOXR airport, Oxnard, CA Camera camera = new Camera(); camera.set(34.2, -119.2, 10000, WorldWind.ABSOLUTE, 90, // Looking east 70, // Lookup up from nadir 0); // No roll // Apply the new camera position Globe globe = wwd.getGlobe(); wwd.getNavigator().setAsCamera(globe, camera); return wwd; }
wwd.getLayers().addLayer(placemarksLayer); Bitmap bitmap = BitmapFactory.decodeResource(getWorldWindow().getResources(), R.drawable.ehipcc); Placemark wildfire = new Placemark( Position.fromDegrees(34.300, -119.25, 0), LookAt lookAt = new LookAt().set(pos.latitude, pos.longitude, pos.altitude, WorldWind.ABSOLUTE, 1e5 /*range*/, 0 /*heading*/, 80 /*tilt*/, 0 /*roll*/); wwd.getNavigator().setAsLookAt(wwd.getGlobe(), lookAt);
/** * Updates the WorldWindow layer list on the UI Thread. */ @Override protected void onPostExecute(Void notUsed) { super.onPostExecute(notUsed); getWorldWindow().getLayers().addLayer(this.placeLayer); statusText.setText(String.format(Locale.US, "%,d US places created", this.numPlacesCreated)); getWorldWindow().requestRedraw(); }
private void fill(WorldWindow wwd) { // Fill the layers panel with the titles of all layers in the world window's current model. for (Layer layer : wwd.getModel().getLayers()) { if (layer.getName().equalsIgnoreCase("Atmosphere") || layer.getName().equalsIgnoreCase("World Map") || layer.getName().equalsIgnoreCase("Scale bar") || layer.getName().equalsIgnoreCase("Compass")) continue; final LayerAction action = new LayerAction(layer, wwd, layer.isEnabled()); final JCheckBox jcb = new JCheckBox(action); jcb.setSelected(action.selected); this.layersPanel.add(jcb); if (defaultFont == null) { this.defaultFont = jcb.getFont(); } } }
/** * Converts a screen point to the geographic coordinates on the globe. * * @param screenX X coordinate * @param screenY Y coordinate * @param result Pre-allocated Position receives the geographic coordinates * * @return true if the screen point could be converted; false if the screen point is not on the globe */ public boolean screenPointToGroundPosition(float screenX, float screenY, Position result) { if (this.wwd.rayThroughScreenPoint(screenX, screenY, ray)) { Globe globe = wwd.getGlobe(); if (globe.intersect(ray, this.pickPoint)) { globe.cartesianToGeographic(pickPoint.x, this.pickPoint.y, this.pickPoint.z, result); return true; } } return false; }
@Override public boolean handleMessage(Message msg) { if (this.animationAmount < 1) { // Increment the animation amount. this.animationAmount += this.animationIncrement; for (int idx = 0, len = this.flightPathLayer.count(); idx < len; idx++) { // Identify the departure airport and destination airport associated with each flight path. Path path = (Path) this.flightPathLayer.getRenderable(idx); Airport dept = (Airport) path.getUserProperty("dept"); Airport dest = (Airport) path.getUserProperty("dest"); // Compute the location on the great circle path between the departure and the destination that // corresponds to the animation amount. Position nextPos = dept.pos.interpolateAlongPath(dest.pos, WorldWind.GREAT_CIRCLE, this.animationAmount, new Position()); // Compute the altitude on the flight path that corresponds to the animation amount. We mock altitude // using an inverse parabolic function scaled to reach a max altitude of 10% of the flight distance. double dist = dept.pos.greatCircleDistance(dest.pos) * this.getWorldWindow().getGlobe().getEquatorialRadius(); double altCurve = (1 - this.animationAmount) * this.animationAmount * 4; nextPos.altitude = altCurve * dist * 0.1; // Append the location and altitude to the flight path's list of positions. List<Position> positions = path.getPositions(); positions.add(nextPos); path.setPositions(positions); } // Redraw the WorldWindow to display the changes. this.getWorldWindow().requestRedraw(); // Continue the animation after a delay. this.handler.sendEmptyMessageDelayed(0 /*what*/, 1000); } return false; }