Autodesk 15606-011408-9300 Developer Guide - Page 52
Working with Map Layers, Map Features, and Printing, able
UPC - 606121429548
View all Autodesk 15606-011408-9300 manuals
Add to My Manuals
Save this manual to your list of manuals |
Page 52 highlights
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); msg += layer.getName() + "\n"; // get next layer // 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 variable, 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 52 | Chapter 4 Working with Map Layers, Map Features, and Printing