コード例 #1
0
ファイル: SelectElementEx.cs プロジェクト: AnuoF/MapFrame
        // 鼠标起来事件
        private void gmapControl_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
        {
            bIsLeftButtonDown = false;

            if (polygonElement == null)
            {
                return;
            }

            GMapPolygon   rectPolygon = polygonElement as GMapPolygon;
            List <GPoint> gpointList  = rectPolygon.LocalPoints;

            if (gpointList.Count == 0)
            {
                return;
            }

            GPoint p0 = gpointList[0];
            GPoint p1 = gpointList[1];
            GPoint p2 = gpointList[2];
            GPoint p3 = gpointList[3];

            Point leftUpPoint = new Point((int)p0.X, (int)p0.Y);
            int   width       = 0;
            int   height      = 0;

            width  = Math.Abs((int)p1.X - (int)p0.X);
            height = Math.Abs((int)p2.Y - (int)p1.Y);
            Rectangle rect = new Rectangle(leftUpPoint, new Size(width, height));

            // 框选需要清除上一次的图元
            foreach (IMFElement ele in elementList)
            {
                ele.HightLight(false);
            }
            elementList.Clear();

            foreach (IMFLayer maplayer in mapLogic.GetLayers())
            {
                foreach (IMFElement element in maplayer.GetElementList())
                {
                    if (element.IsHightLight)
                    {
                        continue;
                    }

                    GMapMarker marker = element as GMapMarker;
                    if (marker == null)
                    {
                        continue;
                    }

                    Point tmpPoint = marker.LocalPosition;
                    if (rect.Contains(tmpPoint))
                    {
                        element.HightLight(true);
                        elementList.Add(element);
                    }
                }
            }

            layer.RemoveElement("select_rect");
            RegistCommondExcuteEvent();
        }