I have an application that adds/removes dynamic map layers based on the user selection from a combobox.I am using Flex API 1.9. The map services are running on ArcServer 9.3 on a Windows 2003 server. One of the map services has 37 layers (including a couple of group layers). Should I break it up?I'm also using labeling on a lot of the layers.Lately we've been having issues with our server having memory problems. I suspect it is either one of my map services, or the waymy application adds/removes dynamic layers that is causing the trouble. Here is my code for adding/removing layers. I am adding them over my base map and aerial caches.This code is called when the user selects a new "view" from the drop-down.Is there potential memory problems here? Something with the soc/som?The list in the switch block is actually much longer. I just put in a few to save spaceprivate function addLayers():void
{
myGraphicsLayer.clear();
// Some layers will not have anything visible at full extent
// Add busy cursor so user knows something is happening
// Then remove it when layer has been loaded
CursorManager.setBusyCursor();
// Remove layers that have already been loaded
for (var n:Number = MainMap.layers.length -1; n >= 0; n--) //loop thru all map layers
{
var layer:Layer = MainMap.getLayer(MainMap.layerIds);
if (layer.id == "viewLayer" || layer.id == "viewLayer2")
{
MainMap.removeLayer(layer);
}
}
// Create 2 new Dynamic Map layers
var lyr:ArcGISDynamicMapServiceLayer = new ArcGISDynamicMapServiceLayer;
var lyr2:ArcGISDynamicMapServiceLayer = new ArcGISDynamicMapServiceLayer;
// Create an array collection so only certain layers can be displayed
// If nothing is added to this ArrayCollection all visible layers in mxd are displayed
var visibleLayers:ArrayCollection = new ArrayCollection;
var visibleLayers2:ArrayCollection = new ArrayCollection;
// Set up map layer based on the currently selected view
switch (cbViews.text)
{
case "Annexations (City Limits)":
lyr.url = SERVER_NAME + "intranet/CityViewWeb/MapServer";
visibleLayers.addItem([12]);
lyr.alpha = 0.5;
break;
case "Building Inspection Areas":
lyr.url = SERVER_NAME + "intranet/CityViewWeb/MapServer";
visibleLayers.addItem([2, 3]); // Only draw the inspection areas layer
lyr.alpha = 0.5;
break;
case "Business Licenses":
lyr.url = SERVER_NAME + "public/buslicense/MapServer";
break;
case "Cell Sites":
lyr.url = SERVER_NAME + "intranet/CityViewWeb/MapServer";
lyr.alpha = 0.7;
visibleLayers.addItem([36, 37]);
break;
default: // For any view not in list above
CursorManager.removeBusyCursor();
break;
}
lyr.id = "viewLayer";
lyr.addEventListener(LayerEvent.LOAD, lyrLoad);
// Only draw layers added to ArrayCollection,
// if nothing has been added all visible layers in mxd are shown
if (visibleLayers.length > 0){lyr.visibleLayers = visibleLayers};
// Add layer to stack, just before parcel layer (so parcels appear on top)
MainMap.addLayer(lyr, 1);
// Add 2nd layer if it is needed
if (lyr2.url != null)
{
lyr2.id = "viewLayer2";
if (visibleLayers2.length > 0){lyr2.visibleLayers = visibleLayers2;}
MainMap.addLayer(lyr2, 2);
}
// Move map tips layer back to top so map tips work
MainMap.reorderLayer("MapTipsGraphicsLayer", MainMap.layers.length);
}
// Removes busy cursor after layer has been loaded
private function lyrLoad(event:Event):void
{
CursorManager.removeBusyCursor();
}