Autodesk 15606-011408-9300 Developer Guide - Page 51
Listing Map Layers, Working with Map Layers
UPC - 606121429548
View all Autodesk 15606-011408-9300 manuals
Add to My Manuals
Save this manual to your list of manuals |
Page 51 highlights
Next, the countLayers function calls the getMapLayersEx method, an Autodesk MapGuide Viewer API method that returns an MGCollection object containing all the layers defined in the map. The layer collection is assigned to the layers variable: var layers = map.getMapLayersEx(); Then it calls the MGCollection:size method, which returns a count of the layers in the collection; that number is assigned to the cnt variable: var cnt = layers.size(); Finally, countLayers displays the count, using the JavaScript alert function: alert("This map has " + cnt + " layer(s)."); Displaying the layer count Listing Map Layers The listLayers function counts the layers in a map and displays their names: function listLayers() { var map = getMap(); var layers = map.getMapLayersEx(); var cnt = layers.size(); var msg; var i; for (i = 0; i < cnt; i++) { var layer = layers.item(i); msg = msg + layer.getName() + "\n"; } alert(msg); } The function starts by getting an instance of the map, a layer collection, and a layer count, using the same code as the previous example: var map = getMap(); // get an MGMap object var layers = map.getMapLayersEx(); // create layer collection var cnt = layers.size(); // get layer count Working with Map Layers | 51