ArcServer调用AO接口导出地图服务的图例

mapservice发布的时候是没有图例、指南针等地图要素的。在Flex前端显示图例,常见的做法是制作一张图片来代表图例,后台mxd文档改变之后该图片也需要更新。 但是对于如等值面的图例,这种实现方式就不可取了。一般的等值面颜色是一种渐变色, 而且根据不同数据生成的渐变颜色范围也是不同的,所以图例也是有变化的 故而前一种方式很难实现。

这里提供另一种server调用AO的方式来实现动态生成图例, 每个mapservice后门都有个mxd文档,通过AO去解析这个文档的图例等信息就容易了。下面直接贴代码~~

public void initServer(){

         ESRI.ArcGIS.Server.GISServerConnectionClass gisconnection;
         gisconnection = new ESRI.ArcGIS.Server.GISServerConnectionClass();
         gisconnection.Connect("localhost");
         ESRI.ArcGIS.Server.IServerObjectManager SOM = gisconnection.ServerObjectManager;

         try
         {

   //获取guangyuangp这个mapservice

             IServerContext pServerContext = SOM.CreateServerContext("guangyuangp", "MapServer");
             IMapServer pMapServer = pServerContext.ServerObject as IMapServer;
             IMapServerObjects mapServerObjects;
             mapServerObjects = (IMapServerObjects)pMapServer;

            //获取该地图的layout对象

   IMapServerLayout layout = pMapServer as IMapServerLayout;

             IImageType it = pServerContext.CreateObject("esriCarto.ImageType") as IImageType;
             it.Format = esriImageFormat.esriImageJPG;
             it.ReturnType = esriImageReturnType.esriImageReturnURL;

           

              IImageDisplay idisp = pServerContext.CreateObject("esriCarto.ImageDisplay") as IImageDisplay;
             idisp.Height = 400;
             idisp.Width = 200;
             idisp.DeviceResolution = 150;

             

             IImageDescription pID = pServerContext.CreateObject("esriCarto.ImageDescription") as IImageDescription;
             pID.Display = idisp;
             pID.Type = it;

          

             ILegend legend = pServerContext.CreateObject("esriCarto.Legend") as ILegend;
             legend.Title = "图例";


             IMapServerInfo pMapServerInfo = pMapServer.GetServerInfo(pMapServer.DefaultMapName);
             IMapDescription pMD = pMapServerInfo.DefaultMapDescription;


             IImageResult img = layout.ExportLegend(legend, pMD, idisp, null, pID);

            //释放ServerContext
             pServerContext.ReleaseContext();


             System.Console.Write(img.URL);
             System.Console.ReadLine();

         }
         catch (Exception e)
         {

              som = null;
         }

最后img.URL给我返回的就是这个图例的图片地址:http://sps-010/arcgisoutput/_ags_map7c62545600764e188803bfa46d8f1055.jpg 我们在前端做相关处理 然后显示该图片就可以了。

image

posted @ 2010-04-09 16:33  千禧牛  阅读(1501)  评论(1)    收藏  举报