| MGCollection.item |
|
object item(int index)
Gets the object at the specified index in the collection.
index - The zero-based index of the desired object.
object - The object at the specified index.
-7 (no such element)
This example is designed to work with the Tutorial.mwf file that is included with Autodesk MapGuide Author. It displays a dialog box listing all the layers in the map. First, MGMap.getMapLayersEx is used to obtain the map layer collection and to assign it to a variable named layers. Then, size and item are used in a for loop to operate on each item in the collection:
function listLayers()
{
var map = getMap();
var msg = "";
// Assign collection to layers variable
var layers = map.getMapLayersEx();
// Use size() to step through collection
for (var i = 0; i < layers.size(); i++)
{
// Get each item in collection...
var layer = layers.item(i);
// ...then get item name and add it to msg
msg = msg + layer.getName() + "\n";
}
// Display the layer names
alert(msg);
}