private static List <List <PointF> > ConvertToPointF(Geometry geom)
        {
            List <List <PointF> > list = new List <List <PointF> >();

            if (geom is Polygon)
            {
                Polygon polygon = geom as Polygon;
                list.Add((from p in polygon.ExteriorRing.Vertices select new PointF((float)p.X, (float)p.Y)).ToList());
            }
            else if (geom is MultiPolygon)
            {
                MultiPolygon polygons = geom as MultiPolygon;
                foreach (Polygon polygon in polygons.Polygons)
                {
                    list.Add((from p in polygon.ExteriorRing.Vertices select new PointF((float)p.X, (float)p.Y)).ToList());
                }
            }
            else if (geom is EasyMap.Geometries.Point)
            {
                EasyMap.Geometries.Point p = (EasyMap.Geometries.Point)geom;
                PointF        p1           = new PointF(float.Parse(p.X.ToString()), (float)p.Y);
                List <PointF> lp           = new List <PointF>();
                lp.Add(p1);
                list.Add(lp);
            }
            return(list);
        }
        protected void RenderPoint(Map map, Point point, Graphics g)
        {
            if (point == null)
            {
                return;
            }


            PointF pp = Transform.WorldtoMap(point, map);

            pp = PointF.Add(pp, GetOffset());

            if (Rotation != 0f && !Single.IsNaN(Rotation))
            {
                Matrix startingTransform = g.Transform.Clone();

                Matrix transform      = g.Transform;
                PointF rotationCenter = pp;
                transform.RotateAt(Rotation, rotationCenter);

                g.Transform = transform;

                OnRenderInternal(pp, g);

                g.Transform = startingTransform;
            }
            else
            {
                OnRenderInternal(pp, g);
            }
        }
Exemple #3
0
 /// <summary>
 /// 按照地图将指定点变换为地图坐标
 /// </summary>
 /// <param name="p"></param>
 /// <param name="map"></param>
 /// <returns></returns>
 public static Point MapToWorld(PointF p, Map map)
 {
     if (map.Center.IsEmpty() || double.IsNaN(map.MapHeight))
     {
         return(new Point(0, 0));
     }
     else
     {
         Point ul = new Point(map.Center.X - map.Zoom * .5, map.Center.Y + map.MapHeight * .5);
         return(new Point(ul.X + p.X * map.PixelWidth,
                          ul.Y - p.Y * map.PixelHeight));
     }
 }
Exemple #4
0
        /// <summary>
        /// 将序列化的数据转化为元素,并添加到图层中
        /// </summary>
        /// <param name="type"></param>
        /// <param name="data"></param>
        /// <param name="layer"></param>
        public static void Restore(string type, byte[] data, VectorLayer layer)
        {
            object obj = DeserializeObject(data);

            if (obj == null)
            {
                return;
            }
            GeometryProvider provider = (GeometryProvider)layer.DataSource;

            if (type == "GeoPoint")
            {
                GeoPoint point = (GeoPoint)obj;
                provider.Geometries.Add(point);
            }
            else if (type == "Point3D")
            {
                Point3D point3D = (Point3D)obj;
                provider.Geometries.Add(point3D);
            }
            else if (type == "Polygon")
            {
                Polygon polygon = (Polygon)obj;
                provider.Geometries.Add(polygon);
            }
            else if (type == "LineString")
            {
                LineString lineString = (LineString)obj;
                provider.Geometries.Add(lineString);
            }
            else if (type == "MultiLineString")
            {
                MultiLineString multiLineString = (MultiLineString)obj;
                provider.Geometries.Add(multiLineString);
            }
            else if (type == "MultiPoint")
            {
                MultiPoint multiPoint = (MultiPoint)obj;
                provider.Geometries.Add(multiPoint);
            }
            else if (type == "MultiPolygon")
            {
                MultiPolygon multiPolygon = (MultiPolygon)obj;
                provider.Geometries.Add(multiPolygon);
            }
        }
Exemple #5
0
        /// <summary>
        /// 按照地图将指定点变换为显示坐标
        /// </summary>
        /// <param name="p"></param>
        /// <param name="map"></param>
        /// <returns></returns>
        public static PointF WorldtoMap(Point p, Map map)
        {
            //if (map.MapTransform != null && !map.MapTransform.IsIdentity)
            //	map.MapTransform.TransformPoints(new System.Drawing.PointF[] { p });
            PointF result = new System.Drawing.Point();
            double height = (map.Zoom * map.Size.Height) / map.Size.Width;
            double left   = map.Center.X - map.Zoom * 0.5;
            double top    = map.Center.Y + height * 0.5 * map.PixelAspectRatio;

            result.X = (float)((p.X - left) / map.PixelWidth);
            result.Y = (float)((top - p.Y) / map.PixelHeight);
            if (double.IsNaN(result.X) || double.IsNaN(result.Y))
            {
                result = PointF.Empty;
            }
            return(result);
        }
        public void InsertCoordinate(EasyMap.Geometries.Point point)
        {
            int row = 0;

            if (view.CurrentCell != null)
            {
                row = view.CurrentCell.RowIndex;
            }
            view.Rows[row].Cells[0].Value = point.X;
            view.Rows[row].Cells[1].Value = point.Y;
            if (row == view.RowCount - 1)
            {
                int newrow = view.Rows.Add();

                view.Rows[newrow].Cells[0].Value  = point.X;
                view.Rows[newrow].Cells[1].Value  = point.Y;
                view.Rows[row + 1].Cells[0].Value = "";
                view.Rows[row + 1].Cells[1].Value = "";
            }
            row++;
            view.CurrentCell = view.Rows[row].Cells[0];
        }
Exemple #7
0
 protected override void OnMouseMove(MouseEventArgs e)
 {
     base.OnMouseMove(e);
     if (_DrawEnd)
     {
         return;
     }
     //转化为地图坐标
     EasyMap.Geometries.Point WorldPos = MainMapImage.Map.ImageToWorld(new System.Drawing.Point(e.X, e.Y));
     //显示当前地图坐标
     if (oldimage != null)
     {
         if (SelectionType == SELECTION_TYPE.RECTANGLE ||
             SelectionType == SELECTION_TYPE.CIRCLE)
         {
             //修改最后一个点坐标
             int count = marea.ExteriorRing.Vertices.Count;
             if (count > 1)
             {
                 marea.ExteriorRing.Vertices[count - 1] = WorldPos;
             }
             Refresh();
         }
         else if (MainMapImage.ActiveTool == MapImage.Tools.MeasureLength)
         {
             //修改最后一个点坐标
             int count = mline.Vertices.Count;
             if (count > 1)
             {
                 mline.Vertices[count - 1] = WorldPos;
                 //设置测量窗口的信息
                 if (SetLength != null)
                 {
                     SetLength(mline.Length, mline.Length - oldlength);
                 }
             }
             Refresh();
         }
         else if (MainMapImage.ActiveTool == MapImage.Tools.MeasureArea ||
                  MainMapImage.ActiveTool == MapImage.Tools.DefineArea ||
                  MainMapImage.ActiveTool == MapImage.Tools.SelectPoint ||
                  MainMapImage.ActiveTool == MapImage.Tools.ZoomArea ||
                  SelectionType == SELECTION_TYPE.POLYGON)
         {
             int index = marea.ExteriorRing.Vertices.Count;
             if (index > 1)
             {
                 marea.ExteriorRing.Vertices[index - 1] = WorldPos;
             }
             if (MainMapImage.ActiveTool == MapImage.Tools.MeasureArea)
             {
                 //设置测量窗口的信息
                 if (SetArea != null)
                 {
                     SetArea(marea.Area);
                 }
             }
             Refresh();
         }
     }
 }
Exemple #8
0
        protected override void OnMouseDown(MouseEventArgs e)
        {
            base.OnMouseDown(e);
            if (e.Button == MouseButtons.Right)
            {
                if (!_DrawEnd)
                {
                    if (MainMapImage.ActiveTool == MapImage.Tools.MeasureArea ||
                        MainMapImage.ActiveTool == MapImage.Tools.DefineArea ||
                        MainMapImage.ActiveTool == MapImage.Tools.SelectPoint ||
                        MainMapImage.ActiveTool == MapImage.Tools.ZoomArea)
                    {
                        if (MainMapImage.ActiveTool == MapImage.Tools.ZoomArea)
                        {
                            this.Visible = false;
                            if (AfterDefineArea != null)
                            {
                                AfterDefineArea(SelectionType, null, _R);
                            }
                            return;
                        }
                        if (marea.ExteriorRing.Vertices.Count > 0)
                        {
                            marea.ExteriorRing.Vertices.RemoveAt(marea.ExteriorRing.Vertices.Count - 1);
                        }
                        else
                        {
                            this.Visible = false;
                            if (AfterDefineArea != null)
                            {
                                AfterDefineArea(SelectionType, null, _R);
                            }
                            return;
                        }
                        if (MainMapImage.ActiveTool == MapImage.Tools.MeasureArea)
                        {
                            if (SetArea != null)
                            {
                                SetArea(marea.Area);
                            }
                        }
                        else if (MainMapImage.ActiveTool == MapImage.Tools.DefineArea ||
                                 MainMapImage.ActiveTool == MapImage.Tools.SelectPoint)
                        {
                            Refresh();

                            Polygon newArea = null;
                            string  text    = null;
                            if (MainMapImage.ActiveTool == MapImage.Tools.DefineArea)
                            {
                                InputStringForm form = new InputStringForm("请输入区域名称:", "");

                                if (form.ShowDialog() == DialogResult.OK)
                                {
                                    //text = form.InputContext;
                                    marea.Text = form.InputContext;
                                }
                                else
                                {
                                    this.Visible = false;
                                    if (AfterDefineArea != null)
                                    {
                                        AfterDefineArea(SelectionType, null, _R);
                                    }
                                    return;
                                }
                                //取得当前图层
                                VectorLayer layer = (VectorLayer)MainMapImage.Map.CurrentLayer;
                                //取得图层数据源
                                GeometryProvider provider = (GeometryProvider)layer.DataSource;
                                //添加当前定义的多边形
                                newArea      = marea.Clone();
                                newArea.Text = marea.Text;
                                newArea.ID   = marea.ID;
                                provider.Geometries.Add(newArea);
                                //强制地图刷新
                                MainMapImage.Refresh();
                            }
                            if (AfterDefineArea != null)
                            {
                                AfterDefineArea(SelectionType, marea, _R);
                            }
                            if (newArea != null)
                            {
                                newArea.ID = marea.ID;
                            }
                            //重新初始化多边形
                            marea        = new Polygon();
                            this.Visible = false;
                        }
                    }

                    else if (MainMapImage.ActiveTool == MapImage.Tools.MeasureLength)
                    {
                        mline.Vertices.RemoveAt(mline.Vertices.Count - 1);
                        //设置测量窗口的信息
                        if (SetLength != null)
                        {
                            SetLength(mline.Length, mline.Length - oldlength);
                        }
                    }
                    Refresh();
                    _DrawEnd = true;
                }
            }
            if (e.Button == MouseButtons.Left)
            {
                if (_DrawEnd)
                {
                    Initial(SelectionType);
                }
                _DrawEnd = false;
                //将图像坐标转化为地图坐标
                EasyMap.Geometries.Point WorldPos = MainMapImage.Map.ImageToWorld(new System.Drawing.Point(e.X, e.Y));
                //保存上一次的长度,以便计算出最后一段直线的长度
                oldlength = mline.Length;
                if (SelectionType == SELECTION_TYPE.CIRCLETEMP)
                {
                    //添加救援点
                    //double radius = 10;
                    //double deltaDegrees = 2;
                    //double deltaRadians = (Math.PI / 180) * deltaDegrees;
                    EasyMap.Geometries.Point marea = new Geometries.Point();
                    marea = new EasyMap.Geometries.Point(WorldPos.X, WorldPos.Y);
                    EasyMap.Geometries.Point newArea = new Geometries.Point();
                    //string text = null;
                    if (MainMapImage.ActiveTool == MapImage.Tools.DefineArea)
                    {
                        InputStringForm form = new InputStringForm("请输入救援力量名称:", "");

                        if (form.ShowDialog() == DialogResult.OK)
                        {
                            //text = form.InputContext;
                            marea.Text = form.InputContext;
                        }
                        else
                        {
                            this.Visible = false;
                            if (AfterDefineArea1 != null)
                            {
                                AfterDefineArea1(SelectionType, null, _R);
                            }
                            return;
                        }
                        //取得当前图层
                        VectorLayer layer = (VectorLayer)MainMapImage.Map.CurrentLayer;
                        //取得图层数据源
                        GeometryProvider provider = (GeometryProvider)layer.DataSource;
                        //添加当前定义的多边形
                        marea.ID     = MapDBClass.GetObjectId(MainMapImage.Map.MapId, layer.ID);
                        newArea      = marea.Clone();
                        newArea.Text = marea.Text;
                        newArea.ID   = marea.ID;
                        provider.Geometries.Add(newArea);

                        //强制地图刷新
                        MainMapImage.Refresh();
                    }

                    if (AfterDefineArea1 != null)
                    {
                        AfterDefineArea1(SelectionType, marea, _R);
                    }
                    //强制地图刷新
                    MainMapImage.Refresh(); newArea.ID = marea.ID;
                    //重新初始化多边形
                    //marea = new Polygon();
                    marea        = new Geometries.Point();
                    this.Visible = false;
                    ////强制地图刷新
                    MainMapImage.Refresh();
                }
                else if (SelectionType == SELECTION_TYPE.PROBLEMPOINT)
                {
                    EasyMap.Geometries.Point marea = new Geometries.Point();
                    marea = new EasyMap.Geometries.Point(WorldPos.X, WorldPos.Y);
                    EasyMap.Geometries.Point newArea = new Geometries.Point();
                    if (MainMapImage.ActiveTool == MapImage.Tools.DefineArea)
                    {
                        InputStringForm form = new InputStringForm("请输入遇难点名称:", "");

                        if (form.ShowDialog() == DialogResult.OK)
                        {
                            //text = form.InputContext;
                            marea.Text = form.InputContext;
                        }
                        else
                        {
                            this.Visible = false;
                            if (AfterDefineArea1 != null)
                            {
                                AfterDefineArea1(SelectionType, null, _R);
                            }
                            return;
                        }
                        //取得当前图层
                        VectorLayer layer = (VectorLayer)MainMapImage.Map.CurrentLayer;
                        //取得图层数据源
                        GeometryProvider provider = (GeometryProvider)layer.DataSource;
                        marea.ID = MapDBClass.GetObjectId(MainMapImage.Map.MapId, layer.ID);
                        //添加当前定义的多边形
                        newArea      = marea.Clone();
                        newArea.Text = marea.Text;
                        newArea.ID   = marea.ID;
                        provider.Geometries.Add(newArea);

                        //强制地图刷新
                        MainMapImage.Refresh();
                    }

                    if (AfterDefineArea1 != null)
                    {
                        AfterDefineArea1(SelectionType, marea, _R);
                    }
                    //强制地图刷新
                    MainMapImage.Refresh();
                    newArea.ID   = marea.ID;
                    marea        = new Geometries.Point();
                    this.Visible = false;
                    ////强制地图刷新
                    MainMapImage.Refresh();
                }
                else if (SelectionType == SELECTION_TYPE.RECTANGLE ||
                         SelectionType == SELECTION_TYPE.CIRCLE)
                {
                    marea.ExteriorRing.Vertices.Add(WorldPos);
                    marea.ExteriorRing.Vertices.Add(new EasyMap.Geometries.Point(WorldPos.X, WorldPos.Y));
                    if (marea.ExteriorRing.Vertices.Count > 2)
                    {
                        _DrawEnd     = true;
                        this.Visible = false;
                        if (SelectionType == SELECTION_TYPE.RECTANGLE)
                        {
                            double x1 = marea.ExteriorRing.Vertices[0].X;
                            double y1 = marea.ExteriorRing.Vertices[0].Y;
                            double x3 = marea.ExteriorRing.Vertices[1].X;
                            double y3 = marea.ExteriorRing.Vertices[1].Y;
                            double x2 = x1;
                            double y2 = y3;
                            double x4 = x3;
                            double y4 = y1;
                            marea.ExteriorRing.Vertices.Clear();
                            marea.ExteriorRing.Vertices.Add(new EasyMap.Geometries.Point(x1, y1));
                            marea.ExteriorRing.Vertices.Add(new EasyMap.Geometries.Point(x2, y2));
                            marea.ExteriorRing.Vertices.Add(new EasyMap.Geometries.Point(x3, y3));
                            marea.ExteriorRing.Vertices.Add(new EasyMap.Geometries.Point(x4, y4));
                        }
                        if (AfterDefineArea != null)
                        {
                            AfterDefineArea(SelectionType, marea, _R);
                        }
                        //Polygon newArea = null;
                        //if (SelectionType == SELECTION_TYPE.CIRCLE)
                        //{
                        //    InputStringForm form = new InputStringForm("请输入区域名称:", "");

                        //    if (form.ShowDialog() == DialogResult.OK)
                        //    {
                        //        //text = form.InputContext;
                        //        marea.Text = form.InputContext;
                        //    }
                        //    else
                        //    {
                        //        this.Visible = false;
                        //        if (AfterDefineArea != null)
                        //        {
                        //            AfterDefineArea(SelectionType, null, _R);
                        //        }
                        //        return;
                        //    }
                        //    //取得当前图层
                        //    VectorLayer layer = (VectorLayer)MainMapImage.Map.CurrentLayer;
                        //    //取得图层数据源
                        //    GeometryProvider provider = (GeometryProvider)layer.DataSource;
                        //    //添加当前定义的多边形
                        //    newArea = marea.Clone();
                        //    newArea.Text = "";
                        //    newArea.ID = marea.ID;
                        //    provider.Geometries.Add(newArea);
                        //    //强制地图刷新
                        //    MainMapImage.Refresh();
                        //}
                        return;
                    }
                }
                else if (SelectionType == SELECTION_TYPE.CIRCLE_RADIO)
                {
                    marea.ExteriorRing.Vertices.Add(WorldPos);
                    XYInputForm form = new XYInputForm();
                    form.txtX.Enabled = false;
                    form.txtY.Enabled = false;
                    form.XX           = marea.ExteriorRing.Vertices[0].X;
                    form.YY           = marea.ExteriorRing.Vertices[0].Y;
                    if (form.ShowDialog() == DialogResult.OK)
                    {
                        marea.ExteriorRing.Vertices.Add(WorldPos);
                        marea.ExteriorRing.Vertices.Add(WorldPos);
                        _R = (float)form.R;
                        if (AfterDefineArea != null)
                        {
                            AfterDefineArea(SelectionType, marea, _R);
                        }
                    }
                    _DrawEnd     = true;
                    this.Visible = false;
                    return;
                }
                //如果是测量长度
                else if (MainMapImage.ActiveTool == MapImage.Tools.MeasureLength)
                {
                    //添加地图坐标
                    mline.Vertices.Add(WorldPos);
                    //如果是第一次添加,那么需要追加一个点,以便在鼠标移动的时候更改这个点
                    if (mline.Vertices.Count < 2)
                    {
                        mline.Vertices.Add(new EasyMap.Geometries.Point(WorldPos.X, WorldPos.Y));
                    }
                }
                //如果是测量面积
                else if (MainMapImage.ActiveTool == MapImage.Tools.MeasureArea ||
                         MainMapImage.ActiveTool == MapImage.Tools.DefineArea ||
                         MainMapImage.ActiveTool == MapImage.Tools.SelectPoint ||
                         MainMapImage.ActiveTool == MapImage.Tools.ZoomArea ||
                         SelectionType == SELECTION_TYPE.POLYGON)
                {
                    if (MainMapImage.ActiveTool == MapImage.Tools.ZoomArea &&
                        marea.ExteriorRing.Vertices.Count == 2)
                    {
                        this.Visible = false;
                        if (AfterDefineArea != null)
                        {
                            AfterDefineArea(SelectionType, marea, _R);
                        }
                        return;
                    }
                    //添加地图坐标
                    marea.ExteriorRing.Vertices.Add(WorldPos);
                    //如果是第一次添加,那么需要追加一个点,以便在鼠标移动的时候更改这个点
                    if (marea.ExteriorRing.Vertices.Count < 2)
                    {
                        marea.ExteriorRing.Vertices.Add(new EasyMap.Geometries.Point(WorldPos.X, WorldPos.Y));
                    }
                }
            }
        }
Exemple #9
0
        public static BoundingBox GetCenterPhotoData(int currentlevel, int level)
        {
            EasyMap.Geometries.Point center = Map.Center;
            int       rootlevel             = level / 4 + 1;
            TreeNode  node  = _PhotoRoot;
            DataTable table = MapDBClass.GetCenterTifInformation(center.X, center.Y);
            bool      find  = false;
            PhotoData data  = new PhotoData();

            for (int i = 0; i < table.Rows.Count; i++)
            {
                string name = table.Rows[i]["Name"] as string;
                node = FindNode(_PhotoRoot, name);
                PhotoData tempdata = null;
                if (node != null)
                {
                    if (node.Parent != null)
                    {
                        tempdata = node.Parent.Tag as PhotoData;
                    }
                }
                if (node != null && (node.Level == rootlevel || (tempdata != null && (tempdata.FileName == "" || tempdata.FileName == null) && node.Level - 1 == rootlevel)))
                {
                    data.PhotoId    = (int)table.Rows[i]["PhotoId"];
                    data.Name       = (string)table.Rows[i]["Name"];
                    data.FileName   = (string)table.Rows[i]["FileName"];
                    data.MinX       = (double)table.Rows[i]["MinX"];
                    data.MinY       = (double)table.Rows[i]["MinY"];
                    data.MaxX       = (double)table.Rows[i]["MaxX"];
                    data.MaxY       = (double)table.Rows[i]["MaxY"];
                    data.Transform1 = (double)table.Rows[i]["Transform1"];
                    data.Transform2 = (double)table.Rows[i]["Transform2"];
                    data.Transform3 = (double)table.Rows[i]["Transform3"];
                    data.Transform4 = (double)table.Rows[i]["Transform4"];
                    data.Transform5 = (double)table.Rows[i]["Transform5"];
                    data.Transform6 = (double)table.Rows[i]["Transform6"];
                    data.Width      = (int)table.Rows[i]["Width"];
                    data.Height     = (int)table.Rows[i]["Height"];
                    find            = true;
                    break;
                }
            }
            if (!find)
            {
                return(Map.Envelope);
            }
            int step = -100;

            if (currentlevel < level)
            {
                step = -100;
            }
            int overviewlevel = 0;
            int overviewzoom  = 0;

            find = false;
            BoundingBox box = Map.Envelope;

            box = new BoundingBox(box.Min.X, box.Min.Y, box.Max.X, box.Max.Y);

            if (currentlevel < level)
            {
                while (overviewlevel != (4 - level % 4) && box.Min.X < box.Max.X && box.Min.Y < box.Max.Y)
                {
                    box.Min.X -= step;
                    box.Min.Y -= step;
                    box.Max.X += step;
                    box.Max.Y += step;

                    find = SetOverView(data, out overviewlevel, out overviewzoom);
                }
            }
            else
            {
                BoundingBox maxbox = Map.GetExtents();
                while (overviewlevel != (4 - level % 4) && box.Min.X > maxbox.Min.X && box.Min.Y > maxbox.Min.Y && box.Max.X < maxbox.Max.X && box.Max.Y < maxbox.Max.Y)
                {
                    box.Min.X -= step;
                    box.Min.Y -= step;
                    box.Max.X += step;
                    box.Max.Y += step;

                    find = SetOverView(data, out overviewlevel, out overviewzoom);
                }
            }
            return(box);
        }
Exemple #10
0
        public static bool SetOverView(PhotoData data, out int overviewlevel, out int overviewzoom)
        {
            Size _imagesize = new Size(data.Width, data.Height);

            double[] trans = new double[6];
            trans[0] = data.Transform1;
            trans[1] = data.Transform2;
            trans[2] = data.Transform3;
            trans[3] = data.Transform4;
            trans[4] = data.Transform5;
            trans[5] = data.Transform6;
            GeoTransform _geoTransform = new GeoTransform(trans);
            double       right = 0, left = 0, top = 0, bottom = 0;
            double       dblW, dblH;

            dblW = _imagesize.Width;
            dblH = _imagesize.Height;

            left   = _geoTransform.EnvelopeLeft(dblW, dblH);
            right  = _geoTransform.EnvelopeRight(dblW, dblH);
            top    = _geoTransform.EnvelopeTop(dblW, dblH);
            bottom = _geoTransform.EnvelopeBottom(dblW, dblH);
            BoundingBox _envelope = new BoundingBox(left, bottom, right, top);

            overviewlevel = -1;
            overviewzoom  = 1;
            int viewcount = 4;

            int[] scale      = new int[viewcount + 1];
            int[] scalelevel = new int[viewcount + 1];
            scale[0]      = 1;
            scalelevel[0] = -1;
            for (int i = 1; i <= viewcount; i++)
            {
                scale[i]      = Convert.ToInt32(Math.Pow(2.0, i + 1));
                scalelevel[i] = i - 1;
            }
            BoundingBox displayBbox = Map.Envelope;

            // bounds of section of image to be displayed
            left   = Math.Max(displayBbox.Left, _envelope.Left);
            top    = Math.Min(displayBbox.Top, _envelope.Top);
            right  = Math.Min(displayBbox.Right, _envelope.Right);
            bottom = Math.Max(displayBbox.Bottom, _envelope.Bottom);


            if ((displayBbox.Left > _envelope.Right) || (displayBbox.Right < _envelope.Left) ||
                (displayBbox.Top < _envelope.Bottom) || (displayBbox.Bottom > _envelope.Top))
            {
                overviewlevel = scalelevel[1];
                overviewzoom  = scale[1];
                return(false);
            }

            for (int i = scale.Length - 1; i >= 0; i--)
            {
                BoundingBox trueImageBbox = new BoundingBox(left, bottom, left + (right - left) / scale[i], top);
                BoundingBox shownImageBbox;
                EasyMap.Geometries.Point imageTL = new EasyMap.Geometries.Point(), imageBR = new EasyMap.Geometries.Point();
                // put display bounds into current projection
//                if (_transform != null)
//                {
//#if !DotSpatialProjections
//                    _transform.MathTransform.Invert();
//                    shownImageBbox = GeometryTransform.TransformBox(trueImageBbox, _transform.MathTransform);
//                    _transform.MathTransform.Invert();
//#else
//                    shownImageBbox = GeometryTransform.TransformBox(trueImageBbox, _transform.Source, _transform.Target);
//#endif
//                }
//                else
                shownImageBbox = trueImageBbox;

                // find min/max x and y pixels needed from image
                imageBR.X =
                    (int)
                    (Math.Max(_geoTransform.GroundToImage(shownImageBbox.TopLeft).X,
                              Math.Max(_geoTransform.GroundToImage(shownImageBbox.TopRight).X,
                                       Math.Max(_geoTransform.GroundToImage(shownImageBbox.BottomLeft).X,
                                                _geoTransform.GroundToImage(shownImageBbox.BottomRight).X))) + 1);
                imageBR.Y =
                    (int)
                    (Math.Max(_geoTransform.GroundToImage(shownImageBbox.TopLeft).Y,
                              Math.Max(_geoTransform.GroundToImage(shownImageBbox.TopRight).Y,
                                       Math.Max(_geoTransform.GroundToImage(shownImageBbox.BottomLeft).Y,
                                                _geoTransform.GroundToImage(shownImageBbox.BottomRight).Y))) + 1);
                imageTL.X =
                    (int)
                    Math.Min(_geoTransform.GroundToImage(shownImageBbox.TopLeft).X,
                             Math.Min(_geoTransform.GroundToImage(shownImageBbox.TopRight).X,
                                      Math.Min(_geoTransform.GroundToImage(shownImageBbox.BottomLeft).X,
                                               _geoTransform.GroundToImage(shownImageBbox.BottomRight).X)));
                imageTL.Y =
                    (int)
                    Math.Min(_geoTransform.GroundToImage(shownImageBbox.TopLeft).Y,
                             Math.Min(_geoTransform.GroundToImage(shownImageBbox.TopRight).Y,
                                      Math.Min(_geoTransform.GroundToImage(shownImageBbox.BottomLeft).Y,
                                               _geoTransform.GroundToImage(shownImageBbox.BottomRight).Y)));

                // stay within image
                if (imageBR.X > _imagesize.Width)
                {
                    imageBR.X = _imagesize.Width;
                }
                if (imageBR.Y > _imagesize.Height)
                {
                    imageBR.Y = _imagesize.Height;
                }
                if (imageTL.Y < 0)
                {
                    imageTL.Y = 0;
                }
                if (imageTL.X < 0)
                {
                    imageTL.X = 0;
                }
                double cx2 = imageBR.X;
                double cx1 = imageTL.X;

                int displayImageLength = (int)(imageBR.X - imageTL.X);
                int displayImageHeight = (int)(imageBR.Y - imageTL.Y);

                // convert ground coordinates to map coordinates to figure out where to place the bitmap
                System.Drawing.Point bitmapBR = new System.Drawing.Point((int)Map.WorldToImage(trueImageBbox.BottomRight).X + 1,
                                                                         (int)Map.WorldToImage(trueImageBbox.BottomRight).Y + 1);
                System.Drawing.Point bitmapTL = new System.Drawing.Point((int)Map.WorldToImage(trueImageBbox.TopLeft).X,
                                                                         (int)Map.WorldToImage(trueImageBbox.TopLeft).Y);

                int bitmapLength = bitmapBR.X - bitmapTL.X;
                int bitmapHeight = bitmapBR.Y - bitmapTL.Y;

                // check to see if image is on its side
                if (bitmapLength > bitmapHeight && displayImageLength < displayImageHeight)
                {
                    displayImageLength = bitmapHeight;
                    displayImageHeight = bitmapLength;
                }
                else
                {
                    displayImageLength = bitmapLength;
                    displayImageHeight = bitmapHeight;
                }
                double temp = (cx2 - cx1) / (displayImageLength - 1);
                if (i == 0 && temp < 1)
                {
                    return(false);
                }
                else if (temp >= scale[i])
                {
                    overviewzoom  = scale[i];
                    overviewlevel = scalelevel[i];
                    return(true);
                }
            }
            overviewzoom  = scale[0];
            overviewlevel = scalelevel[0];
            return(true);
        }
Exemple #11
0
        protected void RenderGeometry(Graphics g, Map map, Geometry feature, VectorStyle layerstyle, RenderType renderType)
        {
            VectorStyle style = layerstyle;

            if (feature.StyleType == 1)
            {
                style = new VectorStyle();
                style.EnableOutline = feature.EnableOutline;
                style.Fill          = new SolidBrush(Color.FromArgb(feature.Fill));
                style.Line          = new Pen(Color.Black);
                if (feature.DashStyle >= 0 && feature.DashStyle <= 4)
                {
                    style.Line.DashStyle = (DashStyle)(feature.DashStyle);
                }
                else
                {
                    style.Line.DashStyle = DashStyle.Solid;
                }
                style.Outline           = new Pen(Color.FromArgb(feature.Outline), feature.OutlineWidth);
                style.Outline.DashStyle = style.Line.DashStyle;
                style.HatchStyle        = feature.HatchStyle;
                style.Penstyle          = feature.Penstyle;
            }
            if (feature.PointSymbol != null)
            {
                style.PointSymbol = feature.PointSymbol;
            }
            if (feature.PointSelectSymbol != null)
            {
                style.PointSelectSymbol = feature.PointSelectSymbol;
            }
            if (style.Penstyle == 6)
            {
                style.Outline.CompoundArray = new float[] { 0, 2f / style.Outline.Width, 1 - 2f / style.Outline.Width, 1 };
            }
            GeometryType2 geometryType = feature.GeometryType;
            string        key          = this.ID.ToString() + "_" + feature.ID.ToString();

            switch (geometryType)
            {
            case GeometryType2.Polygon:
                Brush brush = style.Fill;
                if (PriceTable.ContainsKey(key))
                {
                    brush = PriceTable[key] as SolidBrush;
                }
                else if (GeometryColor.ContainsKey(feature))
                {
                    brush = new SolidBrush((Color)GeometryColor[feature]);
                }
                else if (style.HatchStyle >= 0)
                {
                    brush = new HatchBrush((HatchStyle)style.HatchStyle, style.Outline.Color, style.Fill.Color);
                }
                if (style.EnableOutline)
                {
                    VectorRenderer.DrawPolygon(g, (Polygon)feature, brush, style.Outline, _clippingEnabled,
                                               map, style, renderType, Type.ToString());
                }
                else
                {
                    VectorRenderer.DrawPolygon(g, (Polygon)feature, brush, null, _clippingEnabled, map, style, renderType, Type.ToString());
                }
                break;

            case GeometryType2.MultiPolygon:
                Brush brush1 = style.Fill;
                if (PriceTable.ContainsKey(key))
                {
                    brush1 = PriceTable[key] as SolidBrush;
                }
                else if (GeometryColor.ContainsKey(feature))
                {
                    brush1 = new SolidBrush((Color)GeometryColor[feature]);
                }
                else if (style.HatchStyle >= 0)
                {
                    brush1 = new HatchBrush((HatchStyle)style.HatchStyle, style.Outline.Color, style.Fill.Color);
                }

                if (style.EnableOutline)
                {
                    VectorRenderer.DrawMultiPolygon(g, (MultiPolygon)feature, brush1, style.Outline,
                                                    _clippingEnabled, map, style, renderType, Type.ToString());
                }
                else
                {
                    VectorRenderer.DrawMultiPolygon(g, (MultiPolygon)feature, brush1, null, _clippingEnabled,
                                                    map, style, renderType, Type.ToString());
                }
                break;

            case GeometryType2.LineString:
                if (style.LineSymbolizer != null)
                {
                    style.LineSymbolizer.Render(map, (LineString)feature, g);
                    return;
                }
                //VectorRenderer.zoom = zoom;
                VectorRenderer.DrawLineString(g, (LineString)feature, style.Outline, map, style.LineOffset, style, renderType);
                return;

            case GeometryType2.MultiLineString:
                if (style.LineSymbolizer != null)
                {
                    style.LineSymbolizer.Render(map, (MultiLineString)feature, g);
                    return;
                }
                VectorRenderer.DrawMultiLineString(g, (MultiLineString)feature, style.Outline, map, style.LineOffset, style, renderType);
                break;

            case GeometryType2.Point:
                if (style.PointSymbolizer != null)
                {
                    VectorRenderer.DrawPoint(style.PointSymbolizer, g, (Point)feature, map, style, renderType);
                    return;
                }

                if (style.Symbol != null || style.PointColor == null)
                {
                    Image image = style.Symbol;
                    Point point = (Point)feature;
                    if (style.PointSymbol != null)
                    {
                        image = style.PointSymbol;
                        if (point.Select && style.PointSelectSymbol != null)
                        {
                            image = style.PointSelectSymbol;
                        }
                    }
                    if (point.IsAreaPriceMonitor)
                    {
                        if (style.PointPriceSymbol != null)
                        {
                            image = style.PointPriceSymbol;
                        }
                        if (point.Select && style.PointPriceSelectSymbol != null)
                        {
                            image = style.PointPriceSelectSymbol;
                        }
                    }
                    VectorRenderer.DrawPoint(g, (Point)feature, image, style.SymbolScale, style.SymbolOffset,
                                             style.SymbolRotation, map, style, renderType);
                    return;
                }
                VectorRenderer.DrawPoint(g, (Point)feature, style.PointColor, style.PointSize, style.SymbolOffset, map, style, renderType);

                break;

            case GeometryType2.MultiPoint:
                if (style.PointSymbolizer != null)
                {
                    VectorRenderer.DrawMultiPoint(style.PointSymbolizer, g, (MultiPoint)feature, map, style, renderType);
                }
                if (style.Symbol != null || style.PointColor == null)
                {
                    VectorRenderer.DrawMultiPoint(g, (MultiPoint)feature, style.Symbol, style.SymbolScale,
                                                  style.SymbolOffset, style.SymbolRotation, map, style, renderType);
                }
                else
                {
                    VectorRenderer.DrawMultiPoint(g, (MultiPoint)feature, style.PointColor, style.PointSize, style.SymbolOffset, map, style, renderType);
                }
                break;

            case GeometryType2.GeometryCollection:
                foreach (Geometry geom in (GeometryCollection)feature)
                {
                    RenderGeometry(g, map, geom, style, renderType);
                }
                break;

            default:
                break;
            }
        }
        //新加
        private static EasyMap.Geometries.Point[] ConvertToPointF1(Geometry geom)
        {
            List <EasyMap.Geometries.Point[]> listAll = new List <EasyMap.Geometries.Point[]>();

            EasyMap.Geometries.Point[] list = null;

            if (geom is Polygon)
            {
                Polygon polygon = geom as Polygon;
                list = new EasyMap.Geometries.Point[polygon.ExteriorRing.Vertices.Count];
                for (int i = 0; i < polygon.ExteriorRing.Vertices.Count; i++)
                {
                    EasyMap.Geometries.Point point = new EasyMap.Geometries.Point(polygon.ExteriorRing.Vertices[i].X, polygon.ExteriorRing.Vertices[i].Y);
                    list[i] = point;
                    //if (obj is GeoPoint)
                    //{
                    //    GeoPoint point = obj as GeoPoint;
                    //    if (point.IsAreaPriceMonitor)
                    //    {
                    //        if (area.InPoly(point))
                    //        {
                    //            list.Add(point);
                    //        }
                    //    }
                    //}
                }
                listAll.Add(list);
                //list[1] = new EasyMap.Geometries.Point(polygon, 1);
            }
            else if (geom is MultiPolygon)
            {
                MultiPolygon polygons = geom as MultiPolygon;
                //foreach (Polygon polygon in polygons.Polygons)
                //{
                int n = 0;
                for (int i = 0; i < polygons.Polygons.Count; i++)
                {
                    Polygon polygon = polygons.Polygons[i] as Polygon;
                    for (int j = 0; j < polygon.ExteriorRing.Vertices.Count; j++)
                    {
                        EasyMap.Geometries.Point point = new EasyMap.Geometries.Point(polygon.ExteriorRing.Vertices[i].X, polygon.ExteriorRing.Vertices[i].Y);
                        //list.Add((from p in polygon.ExteriorRing.Vertices select new PointF((float)p.X, (float)p.Y)).ToList());
                        if (point != null)
                        {
                            n++;
                        }
                    }
                }
                list = new EasyMap.Geometries.Point[n];
                n    = 0;
                for (int i = 0; i < polygons.Polygons.Count; i++)
                {
                    Polygon polygon = polygons.Polygons[i] as Polygon;
                    for (int j = 0; j < polygon.ExteriorRing.Vertices.Count; j++)
                    {
                        EasyMap.Geometries.Point point = new EasyMap.Geometries.Point(polygon.ExteriorRing.Vertices[j].X, polygon.ExteriorRing.Vertices[j].Y);
                        //list.Add((from p in polygon.ExteriorRing.Vertices select new PointF((float)p.X, (float)p.Y)).ToList());
                        if (point != null)
                        {
                            list[n] = point;
                            n++;
                        }
                    }
                    listAll.Add(list);
                }
            }
            else if (geom is EasyMap.Geometries.Point)
            {
                list = new EasyMap.Geometries.Point[1];
                EasyMap.Geometries.Point point = (EasyMap.Geometries.Point)geom;
                list[0] = point;
                listAll.Add(list);
                //list[1] = new EasyMap.Geometries.Point(polygon, 1);
            }
            return(list);
        }
        private void btnImport_Click(object sender, EventArgs e)
        {
            if (openFileDialog1.ShowDialog() != DialogResult.OK)
            {
                return;
            }
            if (!File.Exists(openFileDialog1.FileName))
            {
                MessageBox.Show("没有找到指定文件。");
                return;
            }
            StreamReader sr = new StreamReader(openFileDialog1.FileName);

            string[] lines = sr.ReadToEnd().Split('\n');
            sr.Close();
            List <EasyMap.Geometries.Point> points = new List <Geometries.Point>();
            string    first      = "";
            string    last       = "";
            DataTable transtable = new DataTable();

            transtable.Columns.Add("X");
            transtable.Columns.Add("Y");
            transtable.Columns.Add("Z");
            foreach (string line in lines)
            {
                string data = line.Trim();
                if (!data.StartsWith("J"))
                {
                    continue;
                }
                string[] list = data.Split(',');
                if (list.Length < 3)
                {
                    continue;
                }
                double x = 0, y = 0;
                if (!double.TryParse(list[list.Length - 2], out x) ||
                    !double.TryParse(list[list.Length - 1], out y))
                {
                    continue;
                }
                if (first == "")
                {
                    first = list[0];
                }
                else
                {
                    last = list[0];
                }
                DataRow row = transtable.Rows.Add();
                row[0] = x;
                row[1] = y;
                row[2] = 0;
            }
            PConvert convertform = new PConvert();

            convertform.table = transtable;
            if (convertform.ShowDialog() != DialogResult.OK)
            {
                return;
            }
            bool convertSuccess = true;

            for (int i = 0; i < convertform.table.Rows.Count; i++)
            {
                double x, y;
                if (!double.TryParse(convertform.table.Rows[i][0].ToString(), out x))
                {
                    convertSuccess = false;
                    continue;
                }
                if (!double.TryParse(convertform.table.Rows[i][1].ToString(), out y))
                {
                    convertSuccess = false;
                    continue;
                }
                EasyMap.Geometries.Point point = new Geometries.Point(x, y);
                points.Add(point);
            }
            view.Rows.Clear();
            if (first == last && first != "")
            {
                chkPolygon.Checked = true;
            }
            else if (first != "")
            {
                chkCurve.Checked = true;
            }
            for (int i = 0; i < points.Count; i++)
            {
                if (first == last && first != "" && i == points.Count - 1)
                {
                    continue;
                }
                EasyMap.Geometries.Point point = points[i];
                int row = view.Rows.Add();
                view.Rows[row].Cells[0].Value = point.X;
                view.Rows[row].Cells[1].Value = point.Y;
            }
            if (!convertSuccess)
            {
                MessageBox.Show("导入完毕,但是坐标转换过程中有错误发生,已经被忽略。");
            }
        }
        public void Initial(Geometry geomtry)
        {
            _triggerevent      = false;
            _Geomtry           = geomtry;
            chkCurve.Enabled   = false;
            chkPoint.Enabled   = false;
            chkPolygon.Enabled = false;
            if (geomtry is EasyMap.Geometries.Point)
            {
                EasyMap.Geometries.Point point = geomtry as EasyMap.Geometries.Point;
                chkPoint.Checked        = true;
                view.AllowUserToAddRows = false;
                view.RowCount           = 1;

                view.Rows[0].Cells[0].Value = String.Format("{0:N5}", point.X);
                view.Rows[0].Cells[1].Value = String.Format("{0:N5}", point.Y);
            }
            else if (geomtry is LinearRing || geomtry is LineString)
            {
                chkCurve.Checked = true;
                IList <EasyMap.Geometries.Point> vertices = null;
                if (geomtry is LinearRing)
                {
                    LinearRing line = geomtry as LinearRing;
                    vertices = line.Vertices;
                }
                else
                {
                    LineString line = geomtry as LineString;
                    vertices = line.Vertices;
                }
                view.RowCount = vertices.Count;
                int index = 0;
                foreach (EasyMap.Geometries.Point point in vertices)
                {
                    view.Rows[index].Cells[0].Value = String.Format("{0:N5}", point.X);
                    view.Rows[index].Cells[1].Value = String.Format("{0:N5}", point.Y);
                    index++;
                }
            }
            else if (geomtry is Polygon)
            {
                chkPolygon.Checked = true;
                Polygon polygon = geomtry as Polygon;
                IList <EasyMap.Geometries.Point> vertices = polygon.ExteriorRing.Vertices;
                view.RowCount = vertices.Count;
                int index = 0;
                foreach (EasyMap.Geometries.Point point in vertices)
                {
                    view.Rows[index].Cells[0].Value = String.Format("{0:N5}", point.X);
                    view.Rows[index].Cells[1].Value = String.Format("{0:N5}", point.Y);
                    index++;
                }
            }
            else if (geomtry is MultiPolygon)
            {
                chkPolygon.Checked = true;
                MultiPolygon polygons = geomtry as MultiPolygon;
                int          index    = 0;

                for (int i = 0; i < polygons.Polygons.Count; i++)
                {
                    Polygon polygon = polygons.Polygons[i];
                    IList <EasyMap.Geometries.Point> vertices = polygon.ExteriorRing.Vertices;

                    foreach (EasyMap.Geometries.Point point in vertices)
                    {
                        index++;
                    }
                }
                view.RowCount = index;
                index         = 0;
                for (int i = 0; i < polygons.Polygons.Count; i++)
                {
                    Polygon polygon = polygons.Polygons[i];
                    IList <EasyMap.Geometries.Point> vertices = polygon.ExteriorRing.Vertices;

                    foreach (EasyMap.Geometries.Point point in vertices)
                    {
                        view.Rows[index].Cells[0].Value = String.Format("{0:N5}", point.X);
                        view.Rows[index].Cells[1].Value = String.Format("{0:N5}", point.Y);
                        view.Rows[index].Cells[2].Value = i;
                        index++;
                    }
                }
            }
            _triggerevent = true;
        }
        private void btnOk_Click(object sender, EventArgs e)
        {
            double x     = 0;
            double y     = 0;
            int    count = 0;

            if (!addNew)
            {
                if (chkPoint.Checked)
                {
                    for (int i = 0; i < view.RowCount; i++)
                    {
                        if (!double.TryParse(GetValue(i, 0), out x))
                        {
                            continue;
                        }
                        if (!double.TryParse(GetValue(i, 1), out y))
                        {
                            continue;
                        }
                        EasyMap.Geometries.Point point = new EasyMap.Geometries.Point(x, y);
                        if (_Geomtry != null)
                        {
                            point   = _Geomtry as EasyMap.Geometries.Point;
                            point.X = x;
                            point.Y = y;
                        }

                        if (Preview != null)
                        {
                            Preview(null, _PreviewGeomtry);
                        }
                        if (AfterInput != null)
                        {
                            if (_Geomtry != null)
                            {
                                AfterInput(null);
                            }
                            else
                            {
                                AfterInput(point);
                            }
                        }
                    }
                }
                else if (chkCurve.Checked)
                {
                    if (_Geomtry != null)
                    {
                        count = 0;
                        for (int i = 0; i < view.RowCount; i++)
                        {
                            if (!double.TryParse(GetValue(i, 0), out x))
                            {
                                continue;
                            }
                            if (!double.TryParse(GetValue(i, 1), out y))
                            {
                                continue;
                            }
                            count++;
                        }
                        if (count < 2)
                        {
                            return;
                        }
                    }
                    LineString lines = new LineString();

                    IList <EasyMap.Geometries.Point> vertices = lines.Vertices;
                    if (_Geomtry != null)
                    {
                        if (_Geomtry is LinearRing)
                        {
                            LinearRing line = _Geomtry as LinearRing;
                            vertices = line.Vertices;
                        }
                        else if (_Geomtry is LineString)
                        {
                            LineString line = _Geomtry as LineString;
                            vertices = line.Vertices;
                        }
                    }
                    vertices.Clear();
                    for (int i = 0; i < view.RowCount; i++)
                    {
                        if (!double.TryParse(GetValue(i, 0), out x))
                        {
                            continue;
                        }
                        if (!double.TryParse(GetValue(i, 1), out y))
                        {
                            continue;
                        }
                        count++;
                        EasyMap.Geometries.Point point = new EasyMap.Geometries.Point(x, y);
                        vertices.Add(point);
                    }

                    if (Preview != null)
                    {
                        Preview(null, _PreviewGeomtry);
                        _PreviewGeomtry = null;
                    }
                    if (AfterInput != null && count > 1)
                    {
                        if (_Geomtry == null)
                        {
                            AfterInput(lines);
                        }
                        else
                        {
                            AfterInput(null);
                        }
                    }
                    if (_Geomtry == null)
                    {
                        Initial(lines);
                    }
                }
                else if (chkPolygon.Checked)
                {
                    for (int i = 0; i < view.RowCount; i++)
                    {
                        if (!double.TryParse(GetValue(i, 0), out x))
                        {
                            continue;
                        }
                        if (!double.TryParse(GetValue(i, 1), out y))
                        {
                            continue;
                        }
                        count++;
                    }
                    if (count < 2)
                    {
                        return;
                    }
                    Polygon polygon = new Polygon();
                    IList <EasyMap.Geometries.Point> vertices = polygon.ExteriorRing.Vertices;
                    if (_Geomtry == null)
                    {
                        vertices = polygon.ExteriorRing.Vertices;
                        vertices.Clear();
                        for (int i = 0; i < view.RowCount; i++)
                        {
                            if (!double.TryParse(GetValue(i, 0), out x))
                            {
                                continue;
                            }
                            if (!double.TryParse(GetValue(i, 1), out y))
                            {
                                continue;
                            }
                            count++;
                            EasyMap.Geometries.Point point = new EasyMap.Geometries.Point(x, y);
                            vertices.Add(point);
                        }
                    }
                    else
                    {
                        if (_Geomtry is Polygon)
                        {
                            polygon  = _Geomtry as Polygon;
                            vertices = polygon.ExteriorRing.Vertices;
                            vertices.Clear();
                            for (int i = 0; i < view.RowCount; i++)
                            {
                                if (!double.TryParse(GetValue(i, 0), out x))
                                {
                                    continue;
                                }
                                if (!double.TryParse(GetValue(i, 1), out y))
                                {
                                    continue;
                                }
                                count++;
                                EasyMap.Geometries.Point point = new EasyMap.Geometries.Point(x, y);
                                vertices.Add(point);
                            }
                        }
                        else if (_Geomtry is MultiPolygon)
                        {
                            MultiPolygon polygons = _Geomtry as MultiPolygon;
                            for (int i = 0; i < polygons.Polygons.Count; i++)
                            {
                                polygon  = polygons.Polygons[i];
                                vertices = polygon.ExteriorRing.Vertices;
                                vertices.Clear();
                            }
                            for (int i = 0; i < view.RowCount; i++)
                            {
                                int index = Int32.Parse(GetValue(i, 2));
                                polygon  = polygons.Polygons[index];
                                vertices = polygon.ExteriorRing.Vertices;
                                if (!double.TryParse(GetValue(i, 0), out x))
                                {
                                    continue;
                                }
                                if (!double.TryParse(GetValue(i, 1), out y))
                                {
                                    continue;
                                }
                                count++;
                                EasyMap.Geometries.Point point = new EasyMap.Geometries.Point(x, y);
                                vertices.Add(point);
                            }
                        }
                    }
                    if (Preview != null)
                    {
                        Preview(_PreviewGeomtry, null);
                        _PreviewGeomtry = null;
                    }
                    if (AfterInput != null && count > 2)
                    {
                        if (_Geomtry == null)
                        {
                            AfterInput(polygon);
                        }
                        else
                        {
                            AfterInput(null);
                        }
                    }
                    if (_Geomtry == null)
                    {
                        Initial(polygon);
                    }
                }
            }
            else
            {
                // double x = 0;
                //double y = 0;
                //int count = 0;
                if (chkPoint.Checked)
                {
                    for (int i = 0; i < view.RowCount; i++)
                    {
                        if (!double.TryParse(GetValue(i, 0), out x))
                        {
                            continue;
                        }
                        if (!double.TryParse(GetValue(i, 1), out y))
                        {
                            continue;
                        }
                        EasyMap.Geometries.Point point = new EasyMap.Geometries.Point(x, y);
                        if (_Geomtry != null)
                        {
                            point   = _Geomtry as EasyMap.Geometries.Point;
                            point.X = x;
                            point.Y = y;
                        }

                        if (Preview != null)
                        {
                            Preview(null, _PreviewGeomtry);
                        }
                        if (AfterInput != null)
                        {
                            if (_Geomtry != null)
                            {
                                AfterInput(null);
                            }
                            else
                            {
                                AfterInput(point);
                            }
                        }
                    }
                }
                else if (chkCurve.Checked)
                {
                    if (_Geomtry != null)
                    {
                        count = 0;
                        for (int i = 0; i < view.RowCount; i++)
                        {
                            if (!double.TryParse(GetValue(i, 0), out x))
                            {
                                continue;
                            }
                            if (!double.TryParse(GetValue(i, 1), out y))
                            {
                                continue;
                            }
                            count++;
                        }
                        if (count < 2)
                        {
                            return;
                        }
                    }
                    LineString lines = new LineString();

                    IList <EasyMap.Geometries.Point> vertices = lines.Vertices;
                    if (_Geomtry != null)
                    {
                        if (_Geomtry is LinearRing)
                        {
                            LinearRing line = _Geomtry as LinearRing;
                            vertices = line.Vertices;
                        }
                        else if (_Geomtry is LineString)
                        {
                            LineString line = _Geomtry as LineString;
                            vertices = line.Vertices;
                        }
                    }
                    vertices.Clear();
                    for (int i = 0; i < view.RowCount; i++)
                    {
                        if (!double.TryParse(GetValue(i, 0), out x))
                        {
                            continue;
                        }
                        if (!double.TryParse(GetValue(i, 1), out y))
                        {
                            continue;
                        }
                        count++;
                        EasyMap.Geometries.Point point = new EasyMap.Geometries.Point(x, y);
                        vertices.Add(point);
                    }

                    if (Preview != null)
                    {
                        Preview(null, _PreviewGeomtry);
                        _PreviewGeomtry = null;
                    }
                    if (AfterInput != null && count > 1)
                    {
                        if (_Geomtry == null)
                        {
                            AfterInput(lines);
                        }
                        else
                        {
                            AfterInput(null);
                        }
                    }
                    if (_Geomtry == null)
                    {
                        Initial(lines);
                    }
                }
                else if (chkPolygon.Checked)
                {
                    for (int i = 0; i < view.RowCount; i++)
                    {
                        if (!double.TryParse(GetValue(i, 0), out x))
                        {
                            continue;
                        }
                        if (!double.TryParse(GetValue(i, 1), out y))
                        {
                            continue;
                        }
                        count++;
                    }
                    if (count < 2)
                    {
                        return;
                    }
                    Polygon polygon = new Polygon();
                    IList <EasyMap.Geometries.Point> vertices = polygon.ExteriorRing.Vertices;
                    if (_Geomtry == null)
                    {
                        vertices = polygon.ExteriorRing.Vertices;
                        vertices.Clear();
                        for (int i = 0; i < view.RowCount; i++)
                        {
                            if (!double.TryParse(GetValue(i, 0), out x))
                            {
                                continue;
                            }
                            if (!double.TryParse(GetValue(i, 1), out y))
                            {
                                continue;
                            }
                            count++;
                            EasyMap.Geometries.Point point = new EasyMap.Geometries.Point(x, y);
                            vertices.Add(point);
                        }
                    }
                    else
                    {
                        if (_Geomtry is Polygon)
                        {
                            //polygon = _Geomtry as Polygon;
                            polygon  = new Geometries.Polygon();
                            vertices = polygon.ExteriorRing.Vertices;
                            vertices.Clear();
                            for (int i = 0; i < view.RowCount; i++)
                            {
                                if (!double.TryParse(GetValue(i, 0), out x))
                                {
                                    continue;
                                }
                                if (!double.TryParse(GetValue(i, 1), out y))
                                {
                                    continue;
                                }
                                count++;
                                EasyMap.Geometries.Point point = new EasyMap.Geometries.Point(x, y);
                                vertices.Add(point);
                            }
                        }
                        else if (_Geomtry is MultiPolygon)
                        {
                            //MultiPolygon polygons = _Geomtry as MultiPolygon;
                            MultiPolygon polygons = new MultiPolygon();
                            for (int i = 0; i < polygons.Polygons.Count; i++)
                            {
                                polygon  = polygons.Polygons[i];
                                vertices = polygon.ExteriorRing.Vertices;
                                vertices.Clear();
                            }
                            for (int i = 0; i < view.RowCount; i++)
                            {
                                int index = Int32.Parse(GetValue(i, 2));
                                polygon  = polygons.Polygons[index];
                                vertices = polygon.ExteriorRing.Vertices;
                                if (!double.TryParse(GetValue(i, 0), out x))
                                {
                                    continue;
                                }
                                if (!double.TryParse(GetValue(i, 1), out y))
                                {
                                    continue;
                                }
                                count++;
                                EasyMap.Geometries.Point point = new EasyMap.Geometries.Point(x, y);
                                vertices.Add(point);
                            }
                        }
                    }
                    if (Preview != null)
                    {
                        Preview(_PreviewGeomtry, null);
                        _PreviewGeomtry = null;
                    }
                    if (AfterInput != null && count > 2)
                    {
                        if (_Geomtry == null)
                        {
                            AfterInput(polygon);
                        }
                        else
                        {
                            AfterInput(null);
                        }
                    }
                    if (_Geomtry == null)
                    {
                        Initial(polygon);
                    }
                }
            }
        }
Exemple #16
0
        private static BaseLabel CreateLabel(FeatureDataRow fdr, Geometry feature, string text, float rotation, int priority, LabelStyle style, Map map, Graphics g, GetLocationMethod _getLocationMethod)
        {
            BaseLabel lbl = null;

            SizeF size = VectorRenderer.SizeOfString(g, text, style.Font);

            if (feature is ILineal)
            {
                var line = feature as LineString;
                if (line != null)
                {
                    if (size.Width < 0.95 * line.Length / map.PixelWidth || !style.IgnoreLength)
                    {
                        var positiveLineString = PositiveLineString(line, false);
                        var lineStringPath     = LineStringToPath(positiveLineString, map /*, false*/);
                        var rect = lineStringPath.GetBounds();

                        if (style.CollisionDetection && !style.CollisionBuffer.IsEmpty)
                        {
                            var cbx = style.CollisionBuffer.Width;
                            var cby = style.CollisionBuffer.Height;
                            rect.Inflate(2 * cbx, 2 * cby);
                            rect.Offset(-cbx, -cby);
                        }
                        var labelBox = new LabelBox(rect);

                        lbl = new PathLabel(text, lineStringPath, 0, priority, labelBox, style);
                    }
                }
                return(lbl);
            }

            PointF position = Transform.WorldtoMap(feature.GetBoundingBox().GetCentroid(), map);

            if (_getLocationMethod != null)
            {
                Point p = _getLocationMethod(fdr);
                if (p != null)
                {
                    position = Transform.WorldtoMap(p, map);
                }
            }
            position.X = position.X - size.Width * (short)style.HorizontalAlignment * 0.5f;
            position.Y = position.Y - size.Height * (short)(2 - (int)style.VerticalAlignment) * 0.5f;
            if (position.X - size.Width > map.Size.Width || position.X + size.Width < 0 ||
                position.Y - size.Height > map.Size.Height || position.Y + size.Height < 0)
            {
                return(null);
            }

            if (!style.CollisionDetection)
            {
                lbl = new Label(text, position, rotation, priority, null, style);
            }
            else
            {
                //Collision detection is enabled so we need to measure the size of the string
                lbl = new Label(text, position, rotation, priority,
                                new LabelBox(position.X - size.Width * 0.5f - style.CollisionBuffer.Width,
                                             position.Y + size.Height * 0.5f + style.CollisionBuffer.Height,
                                             size.Width + 2f * style.CollisionBuffer.Width,
                                             size.Height + style.CollisionBuffer.Height * 2f), style);
            }

            /*
             * if (feature is LineString)
             * {
             *  var line = feature as LineString;
             *
             *  //Only label feature if it is long enough, or it is definately wanted
             *  if (line.Length / map.PixelSize > size.Width || style.IgnoreLength)
             *  {
             *      CalculateLabelOnLinestring(line, ref lbl, map);
             *  }
             *  else
             *      return null;
             * }
             */
            return(lbl);
        }