Esempio n. 1
0
        //创建饼状专题图
        public static void CreatePieTheme(System.Web.UI.Page page, int nLayerID, string[] fields)
        {
            if (page == null)
            {
                return;
            }
            // 得到地图服务下的ArcObjects map对象
            ESRI.ArcGIS.Server.IServerContext pServerContext = GetServerContext(page);

            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(nLayerID);//得到图层
            ESRI.ArcGIS.Carto.IGeoFeatureLayer pGeoLayer = pLayer as IGeoFeatureLayer;

            //设置专题图的属性列表
            ESRI.ArcGIS.Carto.IChartRenderer  pCharRenderer = pServerContext.CreateObject("esriCarto.ChartRenderer") as IChartRenderer;
            ESRI.ArcGIS.Carto.IRendererFields pRenderFields = pCharRenderer as IRendererFields;
            foreach (string var in fields)
            {
                pRenderFields.AddField(var, var);
            }

            //实例化图表对象并取得元素指定属性的最大值
            ESRI.ArcGIS.Display.IPieChartSymbol pPieSym  = pServerContext.CreateObject("esriDisplay.PieChartSymbol") as ESRI.ArcGIS.Display.IPieChartSymbol;
            ESRI.ArcGIS.Display.IChartSymbol    pCharSym = pPieSym as ESRI.ArcGIS.Display.IChartSymbol;
            pPieSym.Clockwise  = true;
            pPieSym.UseOutline = true;

            pCharSym.MaxValue = GetStaMaxMin(fields, pGeoLayer)[0];

            //设置饼图外围线
            ISimpleLineSymbol pOutLine = pServerContext.CreateObject("esriDisplay.SimpleLineSymbol") as ISimpleLineSymbol;

            pOutLine.Color = GetRGB(255, 0, 128, pServerContext);
            pOutLine.Style = ESRI.ArcGIS.Display.esriSimpleLineStyle.esriSLSSolid;
            pOutLine.Width = 1;

            pPieSym.Outline = pOutLine;
            IMarkerSymbol pMarkSym = pPieSym as IMarkerSymbol;

            pMarkSym.Size = 5;


            //设置饼状图填充效果
            ESRI.ArcGIS.Display.ISymbolArray pSymArr = pPieSym as ISymbolArray;
            ISimpleFillSymbol pSimFillSym            = pServerContext.CreateObject("esriDisplay.SimpleFillSymbol") as ESRI.ArcGIS.Display.SimpleFillSymbol;

            pSimFillSym.Color   = GetRGB(128, 128, 128, pServerContext);
            pSimFillSym.Outline = pOutLine;

            Random randColor = new Random();

            for (int i = 0; i < fields.Length; i++)
            {
                IFillSymbol pFillSym = pServerContext.CreateObject("esriDisplay.SimpleFillSymbol") as IFillSymbol;
                pFillSym.Color = GetRGB(randColor.Next(255), randColor.Next(255), randColor.Next(255), pServerContext);
                pSymArr.AddSymbol((ISymbol)pFillSym);
            }

            //设置地图图层背景
            pSimFillSym              = pServerContext.CreateObject("esriDisplay.SimpleFillSymbol") as ESRI.ArcGIS.Display.SimpleFillSymbol;
            pSimFillSym.Color        = GetRGB(255, 128, 255, pServerContext);
            pCharRenderer.BaseSymbol = pSimFillSym as ISymbol;


            //设置饼状图表属性
            IPieChartRenderer pPieChartRenderer = pCharRenderer as IPieChartRenderer;

            pPieChartRenderer.MinValue             = 0.1;
            pPieChartRenderer.MinSize              = 1;
            pPieChartRenderer.FlanneryCompensation = false;
            pPieChartRenderer.ProportionalBySum    = true;
            pPieChartRenderer.ProportionalField    = fields[0];
            pCharRenderer.ChartSymbol              = pPieSym as IChartSymbol;
            pCharRenderer.Label = "面积";

            //应用饼状专题到指定图层
            pCharRenderer.UseOverposter = false;
            pCharRenderer.CreateLegend();
            pGeoLayer.Renderer = pCharRenderer as IFeatureRenderer;

            //刷新地图显示图表及图例
            mapServerObjects.RefreshServerObjects();
            // Map1.RefreshResource("MapResourceItem0");
            pServerContext.ReleaseContext();
        }
Esempio n. 2
0
        //创建柱状专题图
        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();
        }