WorldWind Android



WMTS Layer

This tutorial adds a hillshade WMTS layer to the basic globe example.

WmtsLayerFragment.java

The WmtsLayerFragment class extends the BasicGlobeFragment and overrides the createWorldWindow method. Here we use WorldWind’s LayerFactory to display the contents of a remote OGC Web Map Tile Service (WMTS). LayerFactory asynchronously negotiates with the WMTS endpoint to configure a WorldWind layer, then notifies the application when it’s done.

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

    /**
     * Creates a new WorldWindow (GLSurfaceView) object with a WMTS Layer
     *
     * @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 factory, WorldWind's general component for creating layers
        // from complex data sources.
        LayerFactory layerFactory = new LayerFactory();

        // Create an OGC Web Map Tile Service (WMTS) layer to display Global Hillshade based on GMTED2010
        layerFactory.createFromWmts(
            "https://tiles.geoservice.dlr.de/service/wmts", // WMTS server URL
            "hillshade",                                    // WMTS layer identifier
            new LayerFactory.Callback() {
                @Override
                public void creationSucceeded(LayerFactory factory, Layer layer) {
                    // Add the finished WMTS layer to the WorldWindow.
                    getWorldWindow().getLayers().addLayer(layer);
                    Log.i("gov.nasa.worldwind", "WMTS layer creation succeeded");
                }

                @Override
                public void creationFailed(LayerFactory factory, Layer layer, Throwable ex) {
                    // Something went wrong connecting to the WMTS server.
                    Log.e("gov.nasa.worldwind", "WMTS layer creation failed", ex);
                }
            }
        );

        return wwd;
    }
}