MGMap.getMapLayer   Go to object model Go to parent topic Go to previous topic Go to next topic

Syntax

MGMapLayer getMapLayer(String layername)

Description

Gets the specified map layer.

Parameters

layername - Name of the map layer to return.

Returns

MGMapLayer - The specified map layer, or null if no layer exists with the given name.

Error Codes

-3 (illegal argument)

Example

The following example is designed to work with the Tutorial.mwf file that is included with Autodesk MapGuide Author. It takes a layer name as its argument. If the layer exists, its visibility is toggled. Otherwise, an alert displays:

function layerToggle(name)
{   
    var map = getMap();
    var layer = map.getMapLayer(name);
   
    if (layer == null)
        alert("layer not found.");    
    else
        layer.setVisibility(!layer.getVisibility());
        
    map.refresh();
} 

You might use the following HTML to call the function on a layer called "World Countries":

<FORM>
<INPUT TYPE="button" VALUE="Toggle" ONCLICK="layerToggle('World Countries');">
</FORM>

See Also

MapLayers, getMapLayersEx, getMapLayers