138
|
Chapter 7
Applications
The Add/Update Polygon button calls a JavaScript function that lets the user
draw a polygon by digitizing points on the map. The function first checks to
see if there’s a value in the Polygon Name check box. If there is a value, the
function calls either the
digitizePolygon
or
digitizePolygonEx
method. Otherwise, the function displays an alert and exits:
function add_pgon()
{
// get map object
var map = getMap();
// exit function if 'Polygon Name' text box is empty
if (document.the_form.the_textbox.value == "")
{
alert("Please enter a polygon name.")
return;
}
// if browser is Netscape, use 'Ex' version and pass
// observer applet; if browser is Internet Explorer,
// use 'non-Ex' version with no argument
if (navigator.appName == "Netscape")
map.digitizePolygonEx(document.obs);
else
map.digitizePolygon();
}
The
digitizePolygon
and
digitizePolygonEx
methods both fire the
onDigitizedPolygon
event, passing it the map object, the number of
polygon vertices, and the coordinates of those vertices. The
onDigitizedPolygon
event looks for a JavaScript function of the same
name and, if that function exists, executes it. In fact, the
onDigitizedPolygon
function does exist, because we’ve created it. Here’s
the code for that function:
onDigitizedPolygon Function
function onDigitizedPolygon(map, numPoints, points)
{
// create variable and assign it user-specified value
// from 'Polygon Name' text box
var formText = document.the_form.the_textbox.value;
// create redline layer, or get it if it already exists
var layer = map.getMapLayer("My Redline Layer");
if (layer == null)
layer = map.createLayer("redline", "My Redline Layer");
// create redline object or get it if it exists (getMapObject
// takes an object key as its value, while createMapObject
// takesa key and a name -- the formText variable supplies
// both of those values)
Содержание 15606-011408-9300 - MAP R6.3 UPG
Страница 1: ...15306 010000 5060 October 2001 Autodesk MapGuide Release 6 Developer s Guide ...
Страница 6: ...vi ...
Страница 16: ...16 ...
Страница 30: ...30 ...
Страница 84: ...84 ...
Страница 134: ...134 ...
Страница 202: ...202 ...