Пример #1
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();
        }
Пример #2
0
        /// <summary>
        /// 绘制点缓冲
        /// </summary>
        private void DrawBufferByPoint(ESRI.ArcGIS.ADF.Web.Geometry.Point adfPt)
        {
            //1.连接服务器
            AGSServerConnection connection = new AGSServerConnection();

            connection.Host = "localhost";
            connection.Connect();

            //2.获得服务器
            IServerObjectManager pSom      = connection.ServerObjectManager;
            IServerContext       pSc       = pSom.CreateServerContext("china", "MapServer");//服务名和类型
            IMapServer           mapServer = pSc.ServerObject as IMapServer;

            //3.使用服务器对象 几何对象转换
            IMapServerObjects pMso = mapServer as IMapServerObjects;
            //ESRI.ArcGIS.Geometry.IGeometry comPt = ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.Converter.ValueObjectToComObject(adfPt, pSc)
            //    as ESRI.ArcGIS.Geometry.IGeometry;////ValueObjectToComObject(pnt, pSC);
            IPoint pt = new ESRI.ArcGIS.Geometry.PointClass();

            pt.X = adfPt.X;
            pt.Y = adfPt.Y;
            ESRI.ArcGIS.Geometry.IGeometry comPt = pt;

            ESRI.ArcGIS.Geometry.SpatialReferenceEnvironment sre = new SpatialReferenceEnvironment();
            ISpatialReference pSR = sre.CreateGeographicCoordinateSystem(4326);

            comPt.SpatialReference = pSR;

            //绘制buffer
            ITopologicalOperator pTOPO = comPt as ITopologicalOperator;

            pTOPO.Simplify();//??
            double   bufDis  = Map1.Extent.Width / 2;
            IPolygon bufPoly = pTOPO.Buffer(10) as IPolygon;

            bufPoly.Densify(0, 0);
            ESRI.ArcGIS.ADF.ArcGISServer.PolygonN valuePolyN = ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.Converter.ComObjectToValueObject(bufPoly, pSc, typeof(ESRI.ArcGIS.ADF.ArcGISServer.PolygonN)) as ESRI.ArcGIS.ADF.ArcGISServer.PolygonN;
            ESRI.ArcGIS.ADF.Web.Geometry.Polygon  adfPoly    = ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.Converter.ToAdfPolygon(valuePolyN) as ESRI.ArcGIS.ADF.Web.Geometry.Polygon;


            #region Densify
            ////***Densify
            // ESRI.ArcGIS.Geometry.IPointCollection com_pointcollection = (ESRI.ArcGIS.Geometry.IPointCollection)bufPoly;
            // ESRI.ArcGIS.ADF.Web.Geometry.PointCollection new_adf_pointcollection = ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.Converter.ComObjectToValueObject(com_pointcollection, pSc, typeof(ESRI.ArcGIS.ADF.ArcGISServer.poly));
            //ESRI.ArcGIS.ADF.Web.Geometry.PointCollection new_adf_pointcollection = new ESRI.ArcGIS.ADF.Web.Geometry.PointCollection();
            //for (int i = 0; i < com_pointcollection.PointCount - 1; i++)
            //{
            //    ESRI.ArcGIS.ADF.Web.Geometry.Point new_adf_pt = new ESRI.ArcGIS.ADF.Web.Geometry.Point();
            //    new_adf_pt.X = com_pointcollection.get_Point(i).X;
            //    new_adf_pt.Y = com_pointcollection.get_Point(i).Y;
            //    new_adf_pointcollection.Add(new_adf_pt);
            //}
            //ESRI.ArcGIS.ADF.Web.Geometry.Ring new_adf_ring = new ESRI.ArcGIS.ADF.Web.Geometry.Ring();
            //new_adf_ring.Points = new_adf_pointcollection;
            //ESRI.ArcGIS.ADF.Web.Geometry.RingCollection new_adf_ringcollection = new ESRI.ArcGIS.ADF.Web.Geometry.RingCollection();
            //new_adf_ringcollection.Add(new_adf_ring);
            //ESRI.ArcGIS.ADF.Web.Geometry.Polygon new_adf_polygon = new ESRI.ArcGIS.ADF.Web.Geometry.Polygon();
            //new_adf_polygon.Rings = new_adf_ringcollection;
            //ESRI.ArcGIS.ADF.Web.Geometry.Geometry geom = new_adf_polygon as ESRI.ArcGIS.ADF.Web.Geometry.Geometry;
            ////*******Densify
            #endregion

            ESRI.ArcGIS.ADF.Web.Geometry.Geometry geom = adfPoly as ESRI.ArcGIS.ADF.Web.Geometry.Geometry;
            GraphicElement geoEle = new GraphicElement(geom, System.Drawing.Color.Red);
            try
            {
                Map1.Zoom(adfPoly);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }

            geoEle.Symbol.Transparency = 50;

            IEnumerable gfc = Map1.GetFunctionalities();

            MapResource gMap = null;
            foreach (IGISFunctionality gfunc in gfc)
            {
                if (gfunc.Resource.Name == "graph")
                {
                    gMap = (MapResource)gfunc.Resource;
                    break;
                }
            }
            if (gMap == null)
            {
                return;
            }
            ElementGraphicsLayer glayer = null;
            foreach (DataTable dt in gMap.Graphics.Tables)
            {
                if (dt is ElementGraphicsLayer)
                {
                    glayer = dt as ElementGraphicsLayer;
                    break;
                }
            }
            if (glayer == null)
            {
                glayer = new ElementGraphicsLayer();
                gMap.Graphics.Tables.Add(glayer);
            }

            glayer.Clear();//清除数据
            glayer.Add(geoEle);

            //4.释放服务器对象
            pSc.ReleaseContext();

            if (Map1.ImageBlendingMode == ImageBlendingMode.WebTier)
            {
                Map1.Refresh();
            }
            else if (Map1.ImageBlendingMode == ImageBlendingMode.Browser)
            {
                Map1.RefreshResource(gMap.Name);
            }
            return;
        }