//****************************************************************************** // Turn an existing layer in the MWF on or off. Longer method with checking. //****************************************************************************** layername = "Streets - All - With Names"; layer = map.getMapLayer(layername); if (layer == null) alert("Error - "+layername+" layer not found."); else layer.setVisibility(true); // Or all on one line for better readability when several layers are set. layername = "Streets - All - With Names"; layer = map.getMapLayer(layername); if (layer == null) alert("Error - "+layername+" layer not found."); else layer.setVisibility(false); map.refresh(); // Refresh after changing all layer and group visibility. //****************************************************************************** // Turn an existing layer in the MWF on or off. Short method with no error checking. //****************************************************************************** layer = map.getMapLayer("Verified Property"); layer.setVisibility(true); // 'true' to turn on or 'false' to turn off the layer. map.refresh(); // Refresh after changing all layer and group visibility. //****************************************************************************** // Turn an existing group in the MWF on or off. //****************************************************************************** group = map.getMapLayerGroup("City Limits"); if (group == null) alert("Error - City Limits group not found."); else group.setVisibility(true); // 'true' to turn on or 'false' to turn off the group. map.refresh(); // Refresh after changing all layer and group visibility. //****************************************************************************** // Add just one map layer from an MLF file. // (If you add more than one this way, each causes map busy.) //****************************************************************************** map.setAutoRefresh(false); // Turn layers on and off etc. here... // Add the hatched Major Corps Ortho from MLF for the Orthophotos. (This seems to force a map refresh, so we put it last.) map.addMapLayer("api/ortho/MajorCorpsOrthoAPI.mlf"); map.setAutoRefresh(true); map.refresh(); //****************************************************************************** // Add multiple layers from MLF files. This causes map busy. //****************************************************************************** var mapCollection = map.createObject("MGCollection"); mapCollection.add("/eim/ThemedMGNew/MLFs/OtherRightsofway.mlf"); mapCollection.add("/eim/ThemedMGNew/MLFs/RelinquishmentsHB.mlf"); mapCollection.add("/eim/ThemedMGNew/MLFs/SubdivisionRightsofway.mlf"); map.setAutoRefresh(false); map.addMapLayers(mapCollection); map.setAutoRefresh(true); map.refresh(); //****************************************************************************** // Create a legend group and move layers into the group. // This causes map busy if group layers are visible. //****************************************************************************** AMAGroup = map.createMapLayerGroup("ADWR Active Management Areas"); AMAGroup.setLegendLabel("ADWR Active Management Areas"); AMAGroup.addMapLayer(map.getMapLayer("Santa Cruz Active Management Area (SCAMA)")); AMAGroup.addMapLayer(map.getMapLayer("Tucson Active Management Area (TAMA)")); // It may not be necessary to set the group's visibility. AMAGroup.setVisibility(true); //****************************************************************************** // Add layers to an existing legend group already in the MWF. //****************************************************************************** // One method adds the layers to the group object. PimaLinesGroup = map.getMapLayerGroup("Pima County Detail - Lines"); PimaLinesGroup.addMapLayer(map.getMapLayer("Major Power Lines")); PimaLinesGroup.addMapLayer(map.getMapLayer("Sanitary Sewer Pipes")); PimaLinesGroup.addMapLayer(map.getMapLayer("Underground Pipelines")); // Another method assigns the group to the layer object. PimaLinesGroup = map.getMapLayerGroup("Pima County Detail - Lines"); map.getMapLayer("Major Power Lines").setMapLayerGroup(PimaLinesGroup); map.getMapLayer("Sanitary Sewer Pipes").setMapLayerGroup(PimaLinesGroup); map.getMapLayer("Underground Pipelines").setMapLayerGroup(PimaLinesGroup); //****************************************************************************** // Change the initial view location and width. //****************************************************************************** map.setAutoRefresh(false); map.zoomWidth(32.059319, -111.875904, 185, 'MI'); map.setAutoRefresh(true); map.refresh(); //****************************************************************************** // Change the viewing scale for a layer. //****************************************************************************** map.setAutoRefresh(false); // Turn layers on and off etc. here... // Change the min/max view scale for Streets - Major - With Names stLayer = map.getMapLayer("Streets - Major - With Names"); collectionObj = stLayer.getMapLayerStyles(); collectionObj.item(0).setDisplayRange(50000,150000); // Note Min/Max are reversed in the MG API documentation for this function map.setAutoRefresh(true); map.refresh(); //****************************************************************************** // Simple wait for map-not-busy. //****************************************************************************** function waitForNotBusy() { map = getMap(); if (map.isBusy()) setTimeout("waitForNotBusy()", 100); else // Continue processing here... } //****************************************************************************** // Cascading processing and waiting for map not busy. //****************************************************************************** // If possible it's best to cluster things that cause map busy and then // wait once for the map to be not-busy. Unfortunately, the busy state locks // out many map operations. //------------------------------------------------------------------------------ function setUpMap () { map = getMap(); // Do something that causes map busy... wait1(); } //------------------------------------------------------------------------------ function wait1() { map = getMap(); if (map.isBusy()) setTimeout("wait1()", 100); else { // Do more that causes map busy... wait2(); } } //------------------------------------------------------------------------------ function wait2() { map = getMap(); if (map.isBusy()) setTimeout("wait2()",100); else // Do final processing. }