Example #1
0
 public override bool Cover(WEPoint poi)
 {
     return(WEMapTools.IsPointOnPoint(poi, this));
 }
Example #2
0
        //鼠标移动
        private void WEMapControl_MouseMove(object sender, MouseEventArgs e)
        {
            if (WEMouseMove != null)
            {
                WEMouseMove(this, e.Location);
            }
            switch (MapOpStyle)
            {
            case 0:
                break;

            case 1:                 //放大
                if (e.Button == MouseButtons.Left)
                {
                    Refresh();
                    Graphics g       = Graphics.FromHwnd(this.Handle);
                    Pen      sBoxPen = new Pen(mcSelectingBoxColor, mcSelectingBoxWidth);
                    float    sMinX   = Math.Min(mStartPoint.X, e.Location.X);
                    float    sMinY   = Math.Min(mStartPoint.Y, e.Location.Y);
                    float    sMaxX   = Math.Max(mStartPoint.X, e.Location.X);
                    float    sMaxY   = Math.Max(mStartPoint.Y, e.Location.Y);
                    g.DrawRectangle(sBoxPen, sMinX, sMinY, sMaxX - sMinX, sMaxY - sMinY);
                    g.Dispose();
                }
                break;

            case 2:                 //缩小
                if (e.Button == MouseButtons.Left)
                {
                    Refresh();
                    Graphics g       = Graphics.FromHwnd(this.Handle);
                    Pen      sBoxPen = new Pen(mcSelectingBoxColor, mcSelectingBoxWidth);
                    float    sMinX   = Math.Min(mStartPoint.X, e.Location.X);
                    float    sMinY   = Math.Min(mStartPoint.Y, e.Location.Y);
                    float    sMaxX   = Math.Max(mStartPoint.X, e.Location.X);
                    float    sMaxY   = Math.Max(mStartPoint.Y, e.Location.Y);
                    g.DrawRectangle(sBoxPen, sMinX, sMinY, sMaxX - sMinX, sMaxY - sMinY);
                    g.Dispose();
                }
                break;

            case 3:                 //漫游
                if (e.Button == MouseButtons.Left)
                {
                    //PointF sPreMouseLocation = new PointF(mStartPoint.X, mStartPoint.Y);
                    //WEPoint sPrePoint = WEMapTools.ToMapPoint(sPreMouseLocation);
                    WEPoint sPrePoint = WEMapTools.ToMapPoint(mStartPoint);
                    //PointF sCurMouseLocation = new PointF(e.Location.X, e.Location.Y);
                    //WEPoint sCurPoint = WEMapTools.ToMapPoint(sCurMouseLocation);
                    WEPoint sCurPoint = WEMapTools.ToMapPoint(e.Location);
                    WEPoint offset    = WEMapTools.ToMapPoint(new PointF(e.Location.X - mStartPoint.X, e.Location.Y - mStartPoint.Y));
                    //修改offset
                    double      mOffsetX = sPrePoint.X - sCurPoint.X;
                    double      mOffsetY = sPrePoint.Y - sCurPoint.Y;
                    WERectangle newRect  = new WERectangle(WEMapTools.DisplayMBR.MinX + mOffsetX, WEMapTools.DisplayMBR.MaxX + mOffsetX,
                                                           WEMapTools.DisplayMBR.MinY + mOffsetY, WEMapTools.DisplayMBR.MaxY + mOffsetY);
                    WEMapTools.DisplayMBR = newRect;
                    ZoomByMBR(WEMapTools.DisplayMBR);
                    mStartPoint = e.Location;

                    /*
                     * //修改offset
                     * mOffsetX = (mStartPoint.X - e.Location.X) * WEMapTools.DisplayMBR.Width / WEMapTools.DisplayWidth;
                     * mOffsetY = (e.Location.Y - mStartPoint.Y) * WEMapTools.DisplayMBR.Height / WEMapTools.DisplayHeight;
                     * newRect = new WERectangle(WEMapTools.DisplayMBR.MinX + mOffsetX, WEMapTools.DisplayMBR.MaxX + mOffsetX,
                     *  WEMapTools.DisplayMBR.MinY + mOffsetY, WEMapTools.DisplayMBR.MaxY + mOffsetY);
                     * WEMapTools.DisplayMBR = newRect;
                     * ZoomByMBR(WEMapTools.DisplayMBR);
                     * mStartPoint.X = e.Location.X;
                     * mStartPoint.Y = e.Location.Y;
                     */
                }
                break;

            case 4:
                mStartPoint = e.Location;
                List <WEPoint> tem = new List <WEPoint>();
                if (CurrentEdit < 0 || CurrentEdit > AllLayer.Count())
                {
                    break;
                }
                if (NodeEdit == 0)
                {
                    switch (AllLayer[CurrentEdit].FeatureType)
                    {
                    case FeatureType.WEMultiPoint:
                    case FeatureType.WEEntityPoint:
                        if (NewPoints.Count() != 0)
                        {
                            NewPoints[0]           = e.Location;
                            EditFeature.Geometries = new WEMultiPoint(new WEPoint[1] {
                                WEMapTools.ToMapPoint(NewPoints[0])
                            });
                        }
                        else
                        {
                            NewPoints.Add(e.Location);
                        }
                        //NewPoints.Clear();
                        //EditFeature = AllLayer[CurrentEdit].Features.Last();
                        //AllLayer[CurrentEdit].Features[AllLayer[CurrentEdit].Features.Count() - 1].Geometries = new WEMultiPoint(new WEGeometry[1] {  });
                        break;

                    case FeatureType.WEEntityPolyline:
                    case FeatureType.WEMultiPolyline:
                        NewPoints.Add(e.Location);

                        WEMultiPolyline temm  = (WEMultiPolyline)(EditFeature.Geometries);
                        WEPolyline      temmm = (WEPolyline)temm.Polylines[temm.Polylines.Count() - 1];
                        //tem.AddRange(temmm.Points);
                        foreach (var i in NewPoints)
                        {
                            tem.Add(WEMapTools.ToMapPoint(i));
                        }
                        temmm.Points = (WEPoint[])tem.ToArray();
                        temm.DeletePolyline(temm.Polylines.Count() - 1);
                        temm.Add(temmm);
                        EditFeature.Geometries = temm;

                        NewPoints.RemoveAt(NewPoints.Count - 1);

                        break;

                    case FeatureType.WEEntityPolygon:
                    case FeatureType.WEMultiPolygon:
                        NewPoints.Add(e.Location);

                        WEMultiPolygon temm3  = (WEMultiPolygon)(EditFeature.Geometries);
                        WEPolygon      temmm3 = (WEPolygon)temm3.Polygons[temm3.Polygons.Count() - 1];
                        //tem.AddRange(temmm3.Points);
                        foreach (var i in NewPoints)
                        {
                            tem.Add(WEMapTools.ToMapPoint(i));
                        }
                        temmm3.Points = (WEPoint[])tem.ToArray();
                        temm3.DeletePolygon(temm3.Polygons.Count() - 1);
                        temm3.Add(temmm3);
                        EditFeature.Geometries = temm3;

                        NewPoints.RemoveAt(NewPoints.Count - 1);

                        break;
                    }
                    Refresh();
                }
                else if (EditFeature.Geometries.PointCount != 0)
                {
                    CursorMap = WEMapTools.ToMapPoint(e.Location);
                    switch (EditFeature.FeatureType)
                    {
                    case FeatureType.WEMultiPoint:
                    case FeatureType.WEEntityPoint:
                        isGravitationCaptured = -1;
                        for (int i = 0; i < EditFeature.Geometries.PointCount; i++)
                        {
                            WEPoint poi = (WEPoint)((WEMultiPoint)EditFeature.Geometries).Points[i];
                            if (WEMapTools.IsPointOnPoint(CursorMap, poi))
                            {
                                isGravitationCaptured = i;
                                break;
                            }
                        }
                        break;

                    case FeatureType.WEEntityPolyline:
                    case FeatureType.WEMultiPolyline:
                        isGravitationCaptured = -1;
                        for (int i = 0; i < EditFeature.Geometries.PointCount; i++)
                        {
                            WEPolyline polyline = (WEPolyline)((WEMultiPolyline)EditFeature.Geometries).Polylines[i];
                            for (int j = 0; j < polyline.PointCount; j++)
                            {
                                if (WEMapTools.IsPointOnPoint(CursorMap, polyline.Points[j]))
                                {
                                    isGravitationCaptured = j;
                                    break;
                                }
                            }
                            if (isGravitationCaptured != -1)
                            {
                                helpGravitationCaptured = i;
                                break;
                            }
                            if (polyline.PointCount == 1)
                            {
                                continue;
                            }
                            for (int j = 1; j < polyline.PointCount; j++)
                            {
                                if (WEMapTools.IsPointOnPolyline(CursorMap, new WEPolyline(new WEPoint[2] {
                                    polyline.Points[j], polyline.Points[j - 1]
                                })))
                                {
                                    ;
                                }
                                {
                                    isGravitationCaptured = j;
                                    break;
                                }
                            }
                            if (isGravitationCaptured != -1)
                            {
                                helpGravitationCaptured = -i;
                                break;
                            }
                        }
                        break;

                    case FeatureType.WEEntityPolygon:
                    case FeatureType.WEMultiPolygon:
                        isGravitationCaptured = -1;
                        for (int i = 0; i < EditFeature.Geometries.PointCount; i++)
                        {
                            WEPolygon polygon = (WEPolygon)((WEMultiPolyline)EditFeature.Geometries).Polylines[i];
                            for (int j = 0; j < polygon.PointCount; j++)
                            {
                                if (WEMapTools.IsPointOnPoint(CursorMap, polygon.Points[j]))
                                {
                                    isGravitationCaptured = j;
                                    break;
                                }
                            }
                            if (isGravitationCaptured != -1)
                            {
                                helpGravitationCaptured = i;
                                break;
                            }
                            if (polygon.PointCount == 1)
                            {
                                continue;
                            }
                            for (int j = 1; j < polygon.PointCount; j++)
                            {
                                if (WEMapTools.IsPointOnPolyline(CursorMap, new WEPolyline(new WEPoint[2] {
                                    polygon.Points[j], polygon.Points[j - 1]
                                })))
                                {
                                    ;
                                }
                                {
                                    isGravitationCaptured = j;
                                    break;
                                }
                            }
                            if (WEMapTools.IsPointOnPolyline(CursorMap, new WEPolyline(new WEPoint[2] {
                                polygon.Points.Last(), polygon.Points.First()
                            })))
                            {
                                ;
                            }
                            isGravitationCaptured = polygon.PointCount;
                            if (isGravitationCaptured != -1)
                            {
                                helpGravitationCaptured = -i;
                                break;
                            }
                        }
                        break;

                    default:
                        isGravitationCaptured = -1;
                        break;
                    }
                    if (isGravitationCaptured != -1)
                    {
                        Cursor = Cursors.SizeAll;
                        using (Graphics g = Graphics.FromHwnd(this.Handle))
                        {
                            g.FillRectangle(new SolidBrush(Color.Black), 0, 0, 100, 100);
                        }
                    }
                    else
                    {
                        Cursor = Cursors.Cross;
                    }
                }
                if (isGravitationCaptured != -1)
                {
                }

                break;

            case 5:                 //选择要素
                if (e.Button == MouseButtons.Left)
                {
                    Refresh();
                    Graphics g       = Graphics.FromHwnd(this.Handle);
                    Pen      sBoxPen = new Pen(mcSelectingBoxColor, mcSelectingBoxWidth);
                    float    sMinX   = Math.Min(mStartPoint.X, e.Location.X);
                    float    sMinY   = Math.Min(mStartPoint.Y, e.Location.Y);
                    float    sMaxX   = Math.Max(mStartPoint.X, e.Location.X);
                    float    sMaxY   = Math.Max(mStartPoint.Y, e.Location.Y);
                    g.DrawRectangle(sBoxPen, sMinX, sMinY, sMaxX - sMinX, sMaxY - sMinY);
                    g.Dispose();
                }
                break;

            default:
                mStartPoint = e.Location;
                break;
            }
        }