[mapguide-users] Re: change layer filter after map has been loaded
tmblackflag
steve.calpoly at gmail.com
Wed Oct 26 19:21:30 EDT 2011
that worked, for anyone trying to do something similar here is the code:
InitializeWebTier();
MgUserInformation userInfo = new MgUserInformation(sessionId);
MgSiteConnection siteConnection = new MgSiteConnection();
siteConnection.Open(userInfo);
string myLayerName = "Committed - Deal Type";
MgResourceService resourceService =
siteConnection.CreateService(MgServiceType.ResourceService) as
MgResourceService;
MgMap map = new MgMap();
map.Open(resourceService, floor1);
MgLayerCollection layers = map.GetLayers();
MgLayer layer = GetLayerByName(map, myLayerName);
MgResourceIdentifier resId = new
MgResourceIdentifier(layer.GetFeatureSourceId());
MgResourceIdentifier layerDefResId = layer.GetLayerDefinition();
MgByteReader byteReader =
resourceService.GetResourceContent(layerDefResId);
MgByteReader rd = resourceService.GetResourceContent(new
MgResourceIdentifier("Library://LAYERS/Reports/Committed - Deal
Type.LayerDefinition"));
XmlDocument doc = new XmlDocument();
doc.PreserveWhitespace = true;
doc.LoadXml(rd.ToString());
doc.GetElementsByTagName("Filter").Item(0).InnerText = "change
layer filter here";
MgResourceIdentifier tempLayer = new
MgResourceIdentifier("Session:" + sessionId + "//Committed - Deal Type
New.LayerDefinition");
resourceService.SetResource(tempLayer, new
MgByteReader(doc.OuterXml, "text/xml"), null);
MgLayer newLayer = new MgLayer(tempLayer, resourceService);
newLayer.SetName("Committed - Deal Type New");
newLayer.SetLegendLabel(layer.GetLegendLabel());
newLayer.SetDisplayInLegend(layer.GetDisplayInLegend());
newLayer.SetVisible(true);
newLayer.SetSelectable(layer.GetSelectable());
layers.Insert(layers.IndexOf(layer), newLayer);
layers.Remove(layer);
newLayer.ForceRefresh();
map.Save(resourceService);
--
View this message in context: http://osgeo-org.1803224.n2.nabble.com/change-layer-filter-after-map-has-been-loaded-tp6911078p6934634.html
Sent from the MapGuide Users mailing list archive at Nabble.com.
More information about the mapguide-users
mailing list