52
|
Chapter 4
Working with Map Layers, Map Features, and Printing
Next, the
listLayers
function uses a
for
loop to cycle through the layer
collection, placing all the layer names in the single
msg
variable:
var msg;
// empty variable to hold layer names
var i;
// counter variable; used by loop
for (i = 0; i < cnt; i++)
// iterate layer count times
{
var layer = layers.item(i);
// get next layer
msg += layer.getName() + "\n";
// add layer name to msg
}
The
cnt
variable tells the
for
loop to iterate once for each map layer. At each
iteration, the loop counter variable (
i
) is incremented and the following
statements are processed:
var layer = layers.item(i);
// get next layer
msg += layer.getName() + "\n";
// add layer name to msg
The first statement uses the
item
method to select a layer from the collection
and assign it to a variable called
layer
.
The second statement operates on the
layer
variable, first using the
getName
method to obtain the name of the layer represented by that vari-
able, and then assigning that name to the
msg
variable. In addition to the
layer name,
msg
is also assigned its previous contents and the JavaScript
newline character,
\n
. This has the effect of adding each layer name to
msg
as a separate text line.
Finally,
listLayers
uses the JavaScript
alert
function to display the
contents of the variable
msg
in an
alert
box:
alert(msg);
alert
box displaying layer names
Содержание 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 ...