ArcGIS Server 专题图开发(柱状图实现实例)


       最近学习ArcGIS Server开发,学习到ArcGIS Server 专题图开发,对其实现的一般步骤还没有能完全掌握,现以柱状图实现实例代码为例,供研究学习之用。


      //创建柱状专题图

    public void CreateBarRenderer(int layerID, string[] fields)
    {
        // 得到地图服务下的ArcObjects map对象
        ESRI.ArcGIS.Server.IServerContext pServerContext = GetServerContext();
        ESRI.ArcGIS.Carto.IMapServer mapServer = (ESRI.ArcGIS.Carto.IMapServer)pServerContext.ServerObject;
        ESRI.ArcGIS.Carto.IMapServerObjects2 mapServerObjects = (ESRI.ArcGIS.Carto.IMapServerObjects2)mapServer;
        string mapName = mapServer.DefaultMapName;
        ESRI.ArcGIS.Carto.IMap aoMap = mapServerObjects.get_Map(mapName);
      
        ESRI.ArcGIS.Carto.ILayer pLayer = aoMap.get_Layer(layerID);//得到图层
        ESRI.ArcGIS.Carto.IGeoFeatureLayer pGeoLayer = pLayer as IGeoFeatureLayer;
        //设置专题图元素的属性名称列表           
        IChartRenderer pChartRender = pServerContext.CreateObject("esriCarto.ChartRenderer") as IChartRenderer;
        IRendererFields pRenderFields = pChartRender as IRendererFields;
        foreach (string var in fields)
        {
            pRenderFields.AddField(var, var);
        }


        //实例化图表对象并取得元素指定属性的最大值
        IBarChartSymbol pBarChartSymbol = pServerContext.CreateObject("esriDisplay.BarChartSymbol") as IBarChartSymbol;
        IChartSymbol pChartSymbol = pBarChartSymbol as IChartSymbol;
        pChartSymbol.MaxValue = GetStaMaxMin(fields,pGeoLayer)[0];        
        pBarChartSymbol.Width = 8;
        IMarkerSymbol pMarkerSymbol = pBarChartSymbol as IMarkerSymbol;
        pMarkerSymbol.Size = 50;


        //设置柱状图每列填充效果
        ISymbolArray pSymbolArray = pBarChartSymbol as ISymbolArray;
        Random ranColor = new Random();
        for (int i = 0; i < fields.Length; i++)
        {
            IFillSymbol pFillSymbol = pServerContext.CreateObject("esriDisplay.SimpleFillSymbol") as IFillSymbol;
            pFillSymbol.Color = GetRGB(ranColor.Next(255), ranColor.Next(255), ranColor.Next(255),pServerContext);
            pSymbolArray.AddSymbol((ISymbol)pFillSymbol);
        }


        //设置地图图层背景
        ESRI.ArcGIS.Display.ISimpleFillSymbol pFSymbol = pServerContext.CreateObject("esriDisplay.SimpleFillSymbol") as ESRI.ArcGIS.Display.SimpleFillSymbol;
        pFSymbol.Color = GetRGB(239, 228, 249,pServerContext);
        pChartRender.BaseSymbol = pFSymbol as ISymbol;


        //应用柱状专题到指定图层
        pChartRender.ChartSymbol = pBarChartSymbol as IChartSymbol;
        pChartRender.Label = "Test";
        pChartRender.UseOverposter = false;        
        pChartRender.CreateLegend();
        pGeoLayer.Renderer = pChartRender as IFeatureRenderer;


        //刷新地图显示图表及图例
        mapServerObjects.RefreshServerObjects();
        Map1.RefreshResource("MapResourceItem0");
        Toc1.BuddyControl = "Map1";
        Toc1.Refresh();
        Map1.Refresh();
        pServerContext.ReleaseContext();
        
    }

你可能感兴趣的:(ASP.NET,ArcGIS,Server,ArcGIS,Server,Web,ADF)