src.gov.nasa.worldwindx.examples.SimpleShapeDragging Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of worldwind Show documentation
Show all versions of worldwind Show documentation
World Wind is a collection of components that interactively display 3D geographic information within Java applications or applets.
/*
* Copyright (C) 2012 United States Government as represented by the Administrator of the
* National Aeronautics and Space Administration.
* All Rights Reserved.
*/
package gov.nasa.worldwindx.examples;
import gov.nasa.worldwind.*;
import gov.nasa.worldwind.awt.WorldWindowGLCanvas;
import gov.nasa.worldwind.event.*;
import gov.nasa.worldwind.geom.Sector;
import gov.nasa.worldwind.layers.*;
import gov.nasa.worldwind.layers.placename.PlaceNameLayer;
import gov.nasa.worldwind.render.SurfaceImage;
import gov.nasa.worldwind.util.BasicDragger;
import javax.swing.*;
/**
* This example demonstrates the use of the {@link gov.nasa.worldwind.util.BasicDragger} class for dragging a shape
* across the globe.
*
* @version $Id: SimpleShapeDragging.java 1171 2013-02-11 21:45:02Z dcollins $
*/
public class SimpleShapeDragging extends JFrame
{
public SimpleShapeDragging()
{
final WorldWindowGLCanvas wwd = new WorldWindowGLCanvas();
wwd.setPreferredSize(new java.awt.Dimension(1000, 800));
this.getContentPane().add(wwd, java.awt.BorderLayout.CENTER);
wwd.setModel(new BasicModel());
// Add a layer containing an image
SurfaceImage si = new SurfaceImage("images/400x230-splash-nww.png", Sector.fromDegrees(35, 45, -115, -95));
RenderableLayer layer = new RenderableLayer();
layer.addRenderable(si);
insertBeforePlacenames(wwd, layer);
// Set up to drag
wwd.addSelectListener(new SelectListener()
{
private BasicDragger dragger = new BasicDragger(wwd);
public void selected(SelectEvent event)
{
// Delegate dragging computations to a dragger.
this.dragger.selected(event);
}
});
}
public static void main(String[] args)
{
java.awt.EventQueue.invokeLater(new Runnable()
{
public void run()
{
JFrame frame = new SimpleShapeDragging();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.setVisible(true);
}
});
}
public static void insertBeforePlacenames(WorldWindow wwd, Layer layer)
{
// Insert the layer into the layer list just before the placenames.
int compassPosition = 0;
LayerList layers = wwd.getModel().getLayers();
for (Layer l : layers)
{
if (l instanceof PlaceNameLayer)
compassPosition = layers.indexOf(l);
}
layers.add(compassPosition, layer);
}
}