MGCollection.item   Go to object model Go to parent topic Go to previous topic Go to next topic

Syntax

object item(int index)

Description

Gets the object at the specified index in the collection.

Parameters

index - The zero-based index of the desired object.

Returns

object - The object at the specified index.

Error Codes

-7 (no such element)

Example

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);
}