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

Syntax

boolean digitizePolygonEx(MGDigitizePolygonObserverEx observer)

Description

Enables the user to use the mouse to define a polygon on the map, then fires the event onDigitizedPolygon on completion.

digitizePolygonEx does not perform any function other than sending the polygon coordinates to onDigitizedPolygon. The observer parameter specifies the object that either handles the event or forwards it back to JavaScript.

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.

Applies To

Plug-In and Java Edition only. This method is an updated version of digitizePolygon. digitizePolygon still works in Release 6.

Parameters

observer - A Java object that implements MGDigitizePolygonObserverEx.

Returns

boolean - Returns True if successful; otherwise, returns False.

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 shows how to display the coordinates of a a user-specified polygon.

Note: The example works with the Autodesk MapGuide Viewer Plug-In and Java Edition under Netscape, and with the ActiveX Control under Internet Explorer. It does not work with the Autodesk MapGuide Viewer, Java Edition under Internet Explorer. (All methods using the observer applet have this problem, because Internet Explorer doesn't allow for the passing of non-primitives between JavaScript and Java.) You can get around this limitation by calling the methods from a wrapper applet, as shown in Java Edition: Example 6.

First, a function called getPolygon invokes the appropriate digitize method:

function getPolygon()
{
    // If browser is Netscape...
    if (navigator.appName == "Netscape")
        // ...use newer Ex version, and pass observer applet.
        getMap().digitizePolygonEx(document.obs);
    // If browser is IE...
    else
        // ...use older non-Ex version, with no argument.
        getMap().digitizePolygon();
}

Then, if you've set up your event handler properly, digitizePolygon() or digitizePolygonEx() fires the onDigitizedPolygon event, passing it the map object, the number of polygon vertices, and the coordinates of those vertices. If the browser is Netscape, the observer applet is passed as well. See "Handling Busy State and Map Refresh" in the Autodesk MapGuide Developer's Guide for information about working with events and observers, including setting up event handlers.

Finally, the onDigitizedPolygon event looks for a JavaScript function of the same name and, if that function exists, executes it:

function onDigitizedPolygon(map, numPoints, points)
{
    alert("You just digitized a polygon with: " + numPoints + " Points");
    for (i = 0;  i <  numPoints; i++)
        alert("Point[" + i + "] = " + points.item(i).getY() + ", " + points.item(i).getX());
}

To see how these functions work in an application, refer to the Event Handling example.

See Also

digitizeCircle, digitizePoint, digitizePolylineEx, selectPolygonEx