Fork me on GitHub

Labels

This tutorial uses Labels shapes to identify landmarks around Washington, D.C. Label shapes have a variety of configurable properties, including:

  • Text Color
  • Text Size (in screen pixels)
  • Typeface
  • Text Outline
  • Rotation
  • Outline Color
  • Outline Size

LabelsFragment.java

The LabelsFragment class extends BasicGlobeFragment and overrides the createWorldWindow method. Here we configure six Label shapes to identify landmarks around Washington, D.C.

package gov.nasa.worldwindx;
...
public class LabelsFragment extends BasicGlobeFragment {

    /**
     * Creates a new WorldWindow (GLSurfaceView) object with a set of label shapes
     *
     * @return The WorldWindow object containing the globe.
     */
    @Override
    public WorldWindow createWorldWindow() {
        // Let the super class (BasicGlobeFragment) do the creation
        WorldWindow wwd = super.createWorldWindow();

        // Create a layer to display the tutorial labels.
        RenderableLayer layer = new RenderableLayer();
        wwd.getLayers().addLayer(layer);

        // Create a basic label with the default attributes, including the default text color (white), the default text
        // size (24 pixels), the system default typeface, and the default alignment (bottom center).
        Label label = new Label(new Position(38.8977, -77.0365, 0), "The White House");
        layer.addRenderable(label);

        // Create a label with a black text color, the default text size, the system default typeface, the default
        // alignment, and a thick white text outline.
        TextAttributes attrs = new TextAttributes();
        attrs.setTextColor(new Color(0, 0, 0, 1)); // black text via r,g,b,a
        attrs.setOutlineColor(new Color(1, 1, 1, 1)); // white outline via r,g,b,a
        attrs.setOutlineWidth(5); // thicken the white outline
        label = new Label(new Position(38.881389, -77.036944, 0), "Thomas Jefferson Memorial", attrs);
        layer.addRenderable(label);

        // Create a right-aligned label using a bottom-right offset.
        attrs = new TextAttributes();
        attrs.setTextOffset(Offset.bottomRight());
        label = new Label(new Position(38.8893, -77.050111, 0), "Lincoln Memorial", attrs);
        layer.addRenderable(label);

        // Create a left-aligned label using a bottom-left offset.
        attrs = new TextAttributes();
        attrs.setTextOffset(Offset.bottomLeft());
        label = new Label(new Position(38.889803, -77.009114, 0), "United States Capitol", attrs);
        layer.addRenderable(label);

        // Create a label with a 48 pixel text size and a bold typeface.
        attrs = new TextAttributes();
        attrs.setTypeface(Typeface.DEFAULT_BOLD); // system default bold typeface
        attrs.setTextSize(48); // 48 screen pixels
        label = new Label(new Position(38.907192, -77.036871, 0), "Washington", attrs);
        layer.addRenderable(label);

        // Create a label with its orientation fixed relative to the globe.
        label = new Label(new Position(38.89, -77.023611, 0), "National Mall");
        label.setRotationMode(WorldWind.RELATIVE_TO_GLOBE);
        layer.addRenderable(label);

        // Place the viewer directly over the tutorial labels.
        wwd.getNavigator().setLatitude(38.89);
        wwd.getNavigator().setLongitude(-77.023611);
        wwd.getNavigator().setAltitude(10e3);

        return wwd;
    }
}


Server maintenance notice

Dear WorldWind Community,

The geospatial data services that feed WorldWind clients by default with data are undergoing maintenance. Outages between 2 to 4 hours per server may occur during the month of April 2023.

As always, if you have any inquiries or concerns, please contact us at:

arc-worldwind@mail.nasa.gov