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

Syntax

object createObject(String type)

Description

Creates and returns an object of the specified type.

Parameters

type - The type of object you wish to create, either MGCollection, MGExtentEx, or MGPoint. Note that this parameter is not case-sensitive.

Returns

object - The newly created MGCollection, MGExtentEx, or MGPoint object.

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 shows the use of createObject() with an MGCollection:

function selectSomeStates() 
{
    // Get map object; then get "States" layer
    map = getMap();	
    var mapLayer = map.getMapLayer("States");

    // Create an MGCollection object called mapFeatures
    var mapFeatures = map.createObject("MGCollection");

    // Get features by key, then add to mapFeatures collection
    mapFeatures.add(mapLayer.getMapObject("AZ")); // key is "AZ"
    mapFeatures.add(mapLayer.getMapObject("CA")); // key is "CA"
    mapFeatures.add(mapLayer.getMapObject("NV")); // key is "NV"

    // Select and display contents of mapFeatures
    map.getSelection().addObjectsEx(mapFeatures, true);
}

To see an interesting use of this method, refer to the Selection Techniques example.