1

I'm new to Web WorldWind and forgive me if this is a simple question, but I haven't found a solution in the documentation or elsewhere. I have the following:

<div style="position: absolute; top: 5px; left: 5px;">
    <!-- Create a canvas for Web WorldWind. -->
    <canvas id="canvasOne" width="1040" height="630">
    Your browser does not support HTML5 Canvas.
</canvas>
</div>

<script>
var wwd;
window.addEventListener("load", eventWindowLoaded, false);

// Define the event listener to initialize Web WorldWind.
function eventWindowLoaded() {
    // Create a WorldWindow for the canvas.
    wwd = new WorldWind.WorldWindow("canvasOne");
    // Add some image layers to the WorldWindow's globe
    //wwd.addLayer(new WorldWind.BingAerialWithLabelsLayer());.
    wwd.addLayer(new WorldWind.BingRoadsLayer());

    // Add a compass, a coordinates display and some view controls to the WorldWindow.
    wwd.addLayer(new WorldWind.CompassLayer());
    wwd.addLayer(new WorldWind.CoordinatesDisplayLayer(wwd));
    wwd.addLayer(new WorldWind.ViewControlsLayer(wwd));
}
</script>

When the map is displaying, I'd like to add a toggle to switch between the roads layer and the high resolution aerial window. Any help is appreciated.

ZaredH
  • 491
  • 1
  • 7
  • 23

1 Answers1

1

Set the boolean enabled property to show/hide an individual layer.

// Create the roads and aerial imagery layers and set the initial visability
var aerialLayer = new WorldWind.BingAerialWithLabelsLayer(),
    roadsLayer = new WorldWind.BingRoadsLayer();
aerialLayer.enabled = true;
roadsLayer.enabled = false;

// Add the layers to the WorldWindow (globe)
wwd.addLayer(aerialLayer);
wwd.addLayer(roadsLayer);

// Toggles the display of the roads and aerial imagery layers
function toggleLayers() {
    aerialLayer.enabled = !aerialLayer.enabled;
    roadsLayer.enabled = !roadsLayer.enabled;
}

FYI: The WorldWindow (wwd) object has a layers array property where you can access the layers.

See: WorldWind.Layer

See also: layers in WorldWind.WorldWindow

Emxsys
  • 11
  • 1