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

Syntax

ActiveX Control: void addMapLayer(String URL)

Plug-In/Java Edition: void addMapLayer(String URL, MGAddMapLayerObserver observer)

Description

Downloads and adds the specified Map Layer File (.mlf) to the map.

It then fires the event onAddMapLayer either when the file is added, when the stop button is clicked, or when a download error occurs.

For Autodesk MapGuide Viewer Plug-In, the observer parameter specifies the object that either handles the event or forwards it back to JavaScript.

This method always refreshes the map when the autoRefresh flag is set to True or when called from the onViewChanging or onMapLoaded events.

Note that this method does not work during a busy state. For additional information about the busy state, refer to "Handling Busy State and Map Refresh" chapter in the Autodesk MapGuide Developer's Guide.

Parameters

URL - The URL of the Map Layer File.

observer - A Java object that implements MGAddMapLayerObserver (Plug-In and Java Edition only).

Error Codes

-1 (busy)

Example

The following example is designed to work with the Tutorial.mwf file that is included with Autodesk MapGuide Author. It adds a new layer, named "USStCap.mlf", to a map:

function addOneLayer()
{
    var map = getMap();
    var mapUrl = "http://yourserver/maps/USStCap.mlf";

    // check Viewer version (type)...
    if (map.getViewerType() == "ActiveX Control")
        // ...if IE, addMapLayer() takes URL as only argument 
        map.addMapLayer(mapUrl);
    else
        // ...if Netscape or Java, second argument also needed 
        map.addMapLayer(mapUrl, document.obs);
}

For Autodesk MapGuide Viewer Plug-In and the Autodesk MapGuide Viewer, Java Edition, addMapLayer() requires the observer applet as its second argument. If you are not writing code to handle the onAddMapLayer event, the second argument can be "null", instead of "document.obs":

     map.addMapLayer(mapUrl, null);

See Also

addMapLayers, removeMapLayer, viewBuffer, onAddMapLayer