⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 utilities.cs

📁 C#开发的ArcGIS Server9.2地图选择控件
💻 CS
📖 第 1 页 / 共 2 页
字号:
            PointCollection ptColl = new PointCollection();
            Point adfPt;

            foreach (System.Drawing.Point pt in vectors)
            {
                adfPt = ESRI.ArcGIS.ADF.Web.Geometry.Point.ToMapPoint(pt,
                    map.Extent, mapWidth, mapHeight);
                ptColl.Add(adfPt);
            }
            // TODO: see if closing polygon here necessary (as with circle)
            if (closePolygon)
            {
                adfPt = ESRI.ArcGIS.ADF.Web.Geometry.Point.ToMapPoint(vectors[0],
                     map.Extent, mapWidth, mapHeight);
                ptColl.Add(adfPt);
            }

            return ptColl;
        }
        #endregion

        #region CreateCirclePolygon

        public static Polygon CreateCirclePolygon(ESRI.ArcGIS.ADF.Web.Geometry.Point center,
            double radius, double degreeIncrement)
        {
            if (radius <= 0 || degreeIncrement <= 0)
                return null;

            // Convert degree increment to radians
            double incrRad = degreeIncrement * Math.PI / 180;
            // Number of points in "circle"
            int numPoints = (int)Math.Round(360 / degreeIncrement);
            
            // New polygon
            Polygon poly = new Polygon();
            Ring ring = new Ring();
            poly.Rings.Add(ring);
            Point pt;
            double angle = 0;

            // Calculate points around the circle
            for (int i = 0; i < numPoints; i++)
            {
                pt = new Point();
                pt.X = center.X + Math.Cos(angle) * radius;
                pt.Y = center.Y + Math.Sin(angle) * radius;
                ring.Points.Add(pt);
                angle += incrRad;
            }
            // Add closing point (cos(0)=1, sin(0)=0)
            pt = new Point();
            pt.X = center.X + radius;
            pt.Y = center.Y;
            ring.Points.Add(pt);

            return poly;
        }
        #endregion

        #region FindControlRecursive
        /// <summary>
        /// Finds a control by recursively searching containing controls
        /// </summary>
        /// <param name="root">Top-level control that contains controls</param>
        /// <param name="id">ID of the control to find</param>
        /// <returns>Control matching the ID</returns>
        public static Control FindControlRecursive(Control root, string id)
        {
            if (root.ID == id)
            {
                return root;
            }

            foreach (Control c in root.Controls)
            {
                Control t = FindControlRecursive(c, id);
                if (t != null)
                {
                    return t;
                }
            }

            return null;
        }
        #endregion

        #region FindControls method
        /// <summary>
        /// Finds the controls of the type input in the control collection
        /// </summary>
        /// <param name="type">Type to find</param>
        /// <param name="controls">Controls (e.g., Page.Controls)</param>
        /// <returns>List of controls, or empty List if none found</returns>
        public static List<Control> FindControls(Type type, ControlCollection controls)
        {
            List<Control> ctls = new List<Control>();

            foreach (Control ctl in controls)
            {
                if (type.IsInstanceOfType(ctl))
                    ctls.Add(ctl);

                // just in case control contains controls of its own type, always check child controls
                if (ctl.HasControls())
                {
                    List<Control> childCtls = FindControls(type, ctl.Controls);
                    foreach (Control c in childCtls)
                    {
                        ctls.Add(c);
                    }
                    //return childCtls;
                }
            }
            return ctls;
        }
        #endregion

        #region GetTaskResultsControls
        internal static List<TaskResults> GetTaskResultsControls(
            BuddyControlCollection taskResultsContainers,
            Page controlPage)
        {
            List<TaskResults> resultsItems = new List<TaskResults>(taskResultsContainers.Count);

            TaskResults tr;

            // TaskResultsContainers has name(s) of TaskResults control(s) - usually only 1 control
            foreach (BuddyControl bc in taskResultsContainers)
            {
                // Get the TaskResults control associated with each buddy control name
                tr = (TaskResults)FindControlRecursive(controlPage, bc.Name);

                if (tr != null)
                    resultsItems.Add(tr);
            }

            return resultsItems;
        }
        #endregion

        #region GetGISResources
        /// <summary>
        /// Gets the collection of resources (IGISResource) in 
        /// the MapControlManager associated with a Map
        /// </summary>
        /// <param name="mapControl">Map control associated with a MapControlManager</param>
        /// <param name="invalidServices">Array of service names that
        /// are not responding correctly; empty array if all responded properly.</param>
        /// <returns>Collection of IGISResource items.
        /// Will be an empty collection if no functionalities found
        /// in the MapResourceManager, or none are valid.</returns>
        public static GISResourceCollection GetGISResources(Map mapControl,
            out string[] invalidServices)
        {
            GISResourceCollection resourceCollection = new GISResourceCollection();
            List<string> invalidList = new List<string>();

            if (mapControl != null)
            {
                // ensure map initialized
                if (!mapControl.InitializedFunctionalities)
                    mapControl.InitializeFunctionalities();

                MapResourceManager mrm = mapControl.MapResourceManagerInstance;
                if (mrm != null)
                {
                    foreach (GISResourceItem resource in mrm.ResourceItems)
                    {
                        // Make sure the resource is initialized--otherwise can't get layer list
                        MapResourceItem mri = resource as MapResourceItem;
                        if (mri != null)
                            mri.InitializeResource();

                        if (resource.FailedToInitialize)
                            invalidList.Add(resource.Name);
                        else
                        {
                            IMapFunctionality mf = mapControl.GetFunctionality(resource.Name);
                            if (mf != null)
                                resourceCollection.Add(mf.Resource);
                            else
                                invalidList.Add(resource.Name);
                        }
                    }
                }

                // GetFunctionalities seems to skip resources when null -- need to know,
                //  so used above code instead
                //foreach (IGISFunctionality gisFunct in mapControl.GetFunctionalities())
                //    // gisFunct may be null if map service is down
                //    if (gisFunct != null)
                //        resourceCollection.Add(gisFunct.Resource);
                //    else
                //        invalidList.Add(gisFunct.Name);
            }

            // set list of invalid services, if any
            invalidServices = invalidList.ToArray();

            return resourceCollection;
        }
        #endregion

        #region GetMapResource
        /// <summary>
        /// Finds the map resource in the MapResourceManager associated with a Map control
        /// </summary>
        /// <param name="resourceName">Name of the map resource item</param>
        /// <param name="mapControl">Map control with associated MapResourceManager</param>
        /// <returns>IMapResource object. Cast to the appropriate specific type of map resource.</returns>
        public static ESRI.ArcGIS.ADF.Web.DataSources.IMapResource GetMapResource
            (string resourceName, Map mapControl)
        {
            ESRI.ArcGIS.ADF.Web.DataSources.IMapResource mapResource = null;
            
            // ensure map initialized
            if (!mapControl.InitializedFunctionalities)
                mapControl.InitializeFunctionalities();

            foreach (IGISFunctionality gisFunct in mapControl.GetFunctionalities())
            {
                // gisFunct will be null if map service is down
                if (gisFunct != null)
                {
                    if (gisFunct.Resource.Name == resourceName)
                    {
                        // The MapResource object implements both IGISResource and IMapResource
                        mapResource = (IMapResource)gisFunct.Resource;
                        break;
                    }
                }
            }

            return mapResource;
        }
        #endregion
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -