arcgis AO Export Legend

来源:互联网 发布:护照相片制作软件 编辑:程序博客网 时间:2024/05/29 19:46
public string GetMapLegend(string mapservice, string visibleLayerNames) { ESRI.ArcGIS.ADF.Identity identity = new Identity("***", "***", "***"); ESRI.ArcGIS.ADF.Connection.AGS.AGSServerConnection gisconnection; gisconnection = new ESRI.ArcGIS.ADF.Connection.AGS.AGSServerConnection("***", identity); gisconnection.Connect(); ESRI.ArcGIS.Server.IServerObjectManager som = gisconnection.ServerObjectManager; IServerContext pServerContext = som.CreateServerContext(mapservice, "MapServer"); IMapServer pMapServer = pServerContext.ServerObject as IMapServer; IMapServerInfo pMapServerInfo = pMapServer.GetServerInfo(pMapServer.DefaultMapName); IMapDescription pMD = pMapServerInfo.DefaultMapDescription; IMapServerObjects mapServerObjects; mapServerObjects = (IMapServerObjects)pMapServer; // QI IMap map; map = mapServerObjects.get_Map(pMapServer.DefaultMapName); ESRI.ArcGIS.esriSystem.UID uid = (ESRI.ArcGIS.esriSystem.UID)pServerContext.CreateObject("esriSystem.UID"); uid.Value = "esriCarto.Legend"; ILegend theLegend; theLegend = (ILegend)map.CreateMapSurround(uid, null); theLegend.Format.ShowTitle = false; ILegendItem legendItem; ILayer layer; int itemCount = theLegend.ItemCount; for (int i = 0; i < itemCount; i++) { layer = theLegend.get_Item(itemCount - 1 - i).Layer; //take out anything that is a raster or not in the visible layers names list if ((layer is IRasterLayer) || (visibleLayerNames.IndexOf(layer.Name) == -1)) { theLegend.RemoveItem(itemCount - 1 - i); } else { layer.MaximumScale = 0; layer.MinimumScale = 0; theLegend.get_Item(itemCount - 1 - i).ShowLayerName = true; layer.Visible = true; } } // Step 1: Set image description (used for the legend image to be generated) // Image type IImageType imageType = pServerContext.CreateObject("esriCarto.ImageType") as ImageType; imageType.Format = esriImageFormat.esriImageJPG; imageType.ReturnType = esriImageReturnType.esriImageReturnURL; // Image Display IImageDisplay imageDisp = pServerContext.CreateObject("esriCarto.ImageDisplay") as IImageDisplay; //imageDisp.Height = vislayerCount; //int aNo = Convert.ToInt32(vislayerCount); imageDisp.Height = 0; imageDisp.Width = 0; imageDisp.DeviceResolution = 96; // Image Description IImageDescription imageDesc = (IImageDescription)pServerContext.CreateObject("esriCarto.ImageDescription"); imageDesc.Type = imageType; imageDesc.Display = imageDisp; // Step 2: Set map display (used to calculate scale dependet layer visibility in // the legend IImageDisplay mapDisplay = pServerContext.CreateObject("esriCarto.ImageDisplay") as ImageDisplay; mapDisplay.Height = 10; mapDisplay.Width = 10; mapDisplay.DeviceResolution = 96; // Export legend IMapServerLayout mapServerLayout; mapServerLayout = (IMapServerLayout)pMapServer; IImageResult imageResult; imageResult = mapServerLayout.ExportLegend(theLegend, pMD, mapDisplay, null, imageDesc); pServerContext.ReleaseContext(); //theLegend = null; //theLegend = null; return imageResult.URL; }
原创粉丝点击