src.gov.nasa.worldwindx.examples.LayerTreeUsage 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.avlist.AVKey;
import gov.nasa.worldwindx.examples.util.HotSpotController;
import gov.nasa.worldwind.util.layertree.LayerTree;
import gov.nasa.worldwind.layers.RenderableLayer;
import gov.nasa.worldwind.util.WWUtil;
import java.awt.*;
/**
* Example of using {@link gov.nasa.worldwind.util.tree.BasicTree} to display a list of layers.
*
* @author pabercrombie
* @version $Id: LayerTreeUsage.java 1171 2013-02-11 21:45:02Z dcollins $
*/
public class LayerTreeUsage extends ApplicationTemplate
{
public static class AppFrame extends ApplicationTemplate.AppFrame
{
protected LayerTree layerTree;
protected RenderableLayer hiddenLayer;
protected HotSpotController controller;
public AppFrame()
{
super(true, false, false); // Don't include the layer panel; we're using the on-screen layer tree.
this.layerTree = new LayerTree();
// Set up a layer to display the on-screen layer tree in the WorldWindow.
this.hiddenLayer = new RenderableLayer();
this.hiddenLayer.addRenderable(this.layerTree);
this.getWwd().getModel().getLayers().add(this.hiddenLayer);
// Mark the layer as hidden to prevent it being included in the layer tree's model. Including the layer in
// the tree would enable the user to hide the layer tree display with no way of bringing it back.
this.hiddenLayer.setValue(AVKey.HIDDEN, true);
// Refresh the tree model with the WorldWindow's current layer list.
this.layerTree.getModel().refresh(this.getWwd().getModel().getLayers());
// Add a controller to handle input events on the layer tree.
this.controller = new HotSpotController(this.getWwd());
// Size the World Window to take up the space typically used by the layer panel. This illustrates the
// screen space gained by using the on-screen layer tree.
Dimension size = new Dimension(1000, 600);
this.setPreferredSize(size);
this.pack();
WWUtil.alignComponent(null, this, AVKey.CENTER);
}
}
public static void main(String[] args)
{
ApplicationTemplate.start("World Wind Layer Tree", AppFrame.class);
}
}