Example #1
0
        /// <summary>
        /// 向当前编辑的图层中添加一个几何对象
        /// </summary>
        public void AddGeometry(WEGeometry newGeo)
        {
            if (CurrentEdit == -1)
            {
                Console.WriteLine("非编辑状态");
                throw new Exception("非编辑状态");
            }
            WEFeature     newFea = new WEFeature();
            WEVectorLayer _lay   = (WEVectorLayer)(AllLayer[CurrentEdit]);
            int           id     = _lay.Features.Count();

            switch (AllLayer[CurrentEdit].FeatureType)
            {
            case FeatureType.WEEntityPoint:
                newFea = new WEEntityPoint(id, newGeo, _lay.Field);
                break;

            case FeatureType.WEEntityPolyline:
                newFea = new WEEntityPolyline(id, (WEMultiPolyline)newGeo, _lay.Field);
                break;

            case FeatureType.WEEntityPolygon:
                newFea = new WEEntityPolygon(id, (WEMultiPolygon)newGeo, _lay.Field);
                break;
            }
            _lay.AddFeature(newFea);
            AllLayer[CurrentEdit] = _lay;
        }
 /// <summary>
 /// 添加要素
 /// </summary>
 /// <param name="geometry"></param>
 public void AddFeature(WEFeature geometry)
 {
     _Features.Add(geometry);
     _MBR += geometry.MBR;
 }
Example #3
0
        //鼠标松开
        private void WEMapControl_MouseUp(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                Refresh();
                PointF  poimin, poimax;
                WEPoint p1, p2;
                switch (MapOpStyle)
                {
                case 0:
                    break;

                case 1:
                    if (DisplayScale < 0.0005 && DisplayScale > 0)
                    {
                        return;
                    }
                    if (mStartPoint == e.Location)
                    {
                        ZoomByCenter(e.Location, 1.1);
                    }
                    else
                    {
                        poimin = new PointF(Math.Min(mStartPoint.X, e.Location.X), Math.Min(mStartPoint.Y, e.Location.Y));    // 0,0
                        poimax = new PointF(Math.Max(mStartPoint.X, e.Location.X), Math.Max(mStartPoint.Y, e.Location.Y));
                        p1     = WEMapTools.ToMapPoint(poimin);
                        p2     = WEMapTools.ToMapPoint(poimax);
                        ZoomByMBR(new WERectangle(p1.X, p2.X, p2.Y, p1.Y));
                    }
                    break;

                case 2:
                    if (mStartPoint == e.Location)
                    {
                        ZoomByCenter(e.Location, 1 / 1.1);
                    }
                    else
                    {
                        PointF center = new PointF((mStartPoint.X + e.Location.X) / (float)2.0, (mStartPoint.Y + e.Location.Y) / (float)2.0);
                        poimin = new PointF(Math.Min(mStartPoint.X, e.Location.X), Math.Min(mStartPoint.Y, e.Location.Y));    // 0,0
                        poimax = new PointF(Math.Max(mStartPoint.X, e.Location.X), Math.Max(mStartPoint.Y, e.Location.Y));
                        ZoomByCenter(center, Math.Min((poimax.X - poimin.X) / WEMapTools.DisplayWidth, (poimax.Y - poimin.Y) / WEMapTools.DisplayHeight));
                    }
                    break;

                case 3:
                    break;

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

                case 5:    //选择要素
                    int flag = -1;
                    if (mStartPoint == e.Location)
                    {
                        p1 = WEMapTools.ToMapPoint(e.Location);
                        for (int i = 0; i < AllLayer.Count; i++)
                        {
                            var layer = AllLayer[i];
                            if (!layer.Visible)
                            {
                                continue;
                            }
                            if (flag != -1)
                            {
                                break;
                            }
                            foreach (WEFeature fea in layer.Features)
                            {
                                if (fea.Geometries.Cover(p1))
                                {
                                    _SelectedGeometries.Add(fea);
                                    flag = i;
                                    break;
                                }
                            }
                        }
                        Refresh();
                    }
                    else
                    {
                        poimin = new PointF(Math.Min(mStartPoint.X, e.Location.X), Math.Min(mStartPoint.Y, e.Location.Y));    // 0,0
                        poimax = new PointF(Math.Max(mStartPoint.X, e.Location.X), Math.Max(mStartPoint.Y, e.Location.Y));
                        p1     = WEMapTools.ToMapPoint(poimin);
                        p2     = WEMapTools.ToMapPoint(poimax);
                        for (int i = 0; i < AllLayer.Count; i++)
                        {
                            var layer = AllLayer[i];
                            if (!layer.Visible)
                            {
                                continue;
                            }
                            _SelectedGeometries.AddRange(layer.SelectByBox(new WERectangle(p1.X, p2.X, p2.Y, p1.Y)).ToArray());
                        }

                        Refresh();

                        //if (SelectingFinished != null)
                        //SelectingFinished(this);
                    }
                    List <int> ids = new List <int> {
                    };
                    foreach (var i in _SelectedGeometries)
                    {
                        ids.Add(i.ID);
                    }
                    if (SelectingFinished != null)
                    {
                        if (_SelectedGeometries.Count != 0)
                        {
                            EditFeature = _SelectedGeometries[0];
                            SelectingFinished(this, ids.ToArray(), flag, _SelectedGeometries[0]);
                        }
                        else
                        {
                            SelectingFinished(this, ids.ToArray(), flag, null);
                        }
                    }
                    break;

                default:
                    break;
                }
            }
        }