| MGMap.digitizePolylineEx |
|
boolean digitizePolylineEx(MGDigitizePolylineObserverEx observer)
Enables a user to use the mouse to define a polyline on the map, then fires the event onDigitizedPolyline upon completion.
digitizePolylineEx does not perform any functions other than sending the polyline coordinates to onDigitizedPolyline. 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.
Plug-In and Java Edition only. This method is an updated version of digitizePolyline. The older method still works in Release 6.
observer - A Java object that implements MGDigitizePolylineObserverEx.
boolean - Returns True if successful; otherwise, returns False.
-1 (busy)
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 user-specified polyline.
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 getPolyline invokes the appropriate digitize method:
function getPolyline()
{
// If browser is Netscape...
if (navigator.appName == "Netscape")
// ...use newer Ex version, and pass observer applet.
getMap().digitizePolylineEx(document.obs);
// If browser is IE...
else
// ...use older non-Ex version, with no argument.
getMap().digitizePolyline();
}
Then, if you've set up your event handler properly, digitizePolyline() or digitizePolylineEx() fires the onDigitizedPolyline event, passing it the map object, the number of polyline 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 onDigitizedPolyline event looks for a JavaScript function of the same name and, if that function exists, executes it:
function onDigitizedPolyline(map, numPoints, points)
{
alert("You just digitized a polyline 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.
digitizeCircle, digitizePoint, digitizePolygonEx