/// <summary>
        /// 指示一个多边形是否完全位于多边形类
        /// </summary>
        /// <param name="poly"></param>
        /// <param name="box"></param>
        /// <returns></returns>
        internal static bool IsPolygonWithinBox(Polygon poly, RectangeD box)
        {
            int poiCount = poly.PointCount;

            for (int i = 0; i < poiCount; i++)
            {
                //if (! IsPointWiBox(poly.GetPoint(i), box) ) {
                if (IsPointWiBox(poly.GetPoint(i), box) == false)
                {
                    return(false);
                }
            }
            return(true);
        }
Exemple #2
0
        /// <summary>
        /// 返回选中的多边形集合
        /// </summary>
        /// <param name="box"></param>
        /// <returns></returns>
        public Polygon[] SelectByBox(RectangeD box)
        {
            List <Polygon> sSels     = new List <Polygon>();
            int            polyCount = _Polygons.Count;

            for (int i = 0; i < polyCount; i++)
            {
                if (MapTools.IsPolygonWithinBox(_Polygons[i], box) == true)
                {
                    sSels.Add(_Polygons[i]);
                }
            }
            return(sSels.ToArray());//返回选中的多边形集合
        }
 internal static class MapTools {//静态类,不能够实例化,类型下的所有函数都要声明static
     //internal 本程序集可以访问,介于public和private之间
     /// <summary>
     /// 判断指定点是否在指定矩形内
     /// </summary>
     /// <param name="poi"></param>
     /// <param name="rect"></param>
     /// <returns></returns>
     internal static bool IsPointWiBox(PointD poi, RectangeD box)
     {
         if (poi.X < box.MinX || poi.X > box.MaxX)
         {
             return(false);
         }
         else if (poi.Y < box.MinY || poi.Y > box.MaxY)
         {
             return(false);
         }
         else  //在边界上也是位于矩形内
         {
             return(true);
         }
     }
Exemple #4
0
        private void MapControl_MouseUp(object sender, MouseEventArgs e)
        {
            switch (mMapOpstyle)
            {
            case 0:
                break;

            case 1:      //放大
                break;

            case 2:       //缩小
                break;

            case 3:       //漫游
                break;

            case 4:        //输入多边形
                break;

            case 5:       //选择
                if (e.Button == MouseButtons.Left)
                {
                    double sMinX        = Math.Min(mStartPoint.X, e.Location.X);
                    double sMaxX        = Math.Max(mStartPoint.X, e.Location.X);
                    double sMinY        = Math.Min(mStartPoint.Y, e.Location.Y);
                    double sMaxY        = Math.Max(mStartPoint.Y, e.Location.Y);
                    PointD sTopLeft     = new PointD(sMinX, sMinY);
                    PointD sButtonRight = new PointD(sMaxX, sMaxY);
                    //变成地图坐标
                    PointD sTopLeftm     = ToMapPoint(sTopLeft);
                    PointD sButtonRightm = ToMapPoint(sButtonRight);

                    RectangeD sSelBox = new RectangeD(sTopLeftm.X, sButtonRightm.X, sTopLeftm.Y, sButtonRightm.Y);

                    Refresh();

                    SelectingFinished?.Invoke(this, sSelBox);
                }
                break;
            }
        }