Exemplo n.º 1
0
        private void DrawTerminalSegments(System.Drawing.Point prevPoint, System.Drawing.Point curPoint)
        {
            if (m_Points.Count == 2)
            {
                var graph = MapImage.CreateGraphics();
                graph.DrawLine(new Pen(Color.Black), m_Points[0], m_Points[1]);
            }

            if (curPoint != System.Drawing.Point.Empty)
            {
                ControlPaint.DrawReversibleLine(MapImage.PointToScreen(curPoint), MapImage.PointToScreen(m_Points[0]),
                                                Color.Black);
                if (m_Points.Count > 1)
                {
                    ControlPaint.DrawReversibleLine(MapImage.PointToScreen(curPoint),
                                                    MapImage.PointToScreen(m_Points[m_Points.Count - 1]), Color.Black);
                }
            }

            if (prevPoint != System.Drawing.Point.Empty)
            {
                ControlPaint.DrawReversibleLine(MapImage.PointToScreen(prevPoint), MapImage.PointToScreen(m_Points[0]),
                                                Color.Black);
                if (m_Points.Count > 1)
                {
                    ControlPaint.DrawReversibleLine(MapImage.PointToScreen(prevPoint),
                                                    MapImage.PointToScreen(m_Points[m_Points.Count - 1]), Color.Black);
                }
            }
        }
Exemplo n.º 2
0
 void MapImage_MouseMove(Point worldPos, MouseEventArgs e)
 {
     if (m_ToolPhase == ToolPhase.WaitFirst)
     {
         return;
     }
     System.Drawing.Point p = e.Location;
     DrawTerminalSegments(m_LastMousePosition, p);
     m_LastMousePosition = p;
 }
Exemplo n.º 3
0
 /// <summary>
 /// Transforms from world coordinate system (WCS) to image coordinates
 /// NOTE: This method DOES NOT take the MapTransform property into account (use SharpMap.Map.MapToWorld instead)
 /// </summary>
 /// <param name="p">Point in WCS</param>
 /// <param name="map">Map reference</param>
 /// <returns>Point in image coordinates</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);
     return result;
 }
Exemplo n.º 4
0
        /// <summary>
        /// Transforms from world coordinate system (WCS) to image coordinates
        /// NOTE: This method DOES NOT take the MapTransform property into account (use SharpMap.Map.MapToWorld instead)
        /// </summary>
        /// <param name="p">Point in WCS</param>
        /// <param name="map">Map reference</param>
        /// <returns>Point in image coordinates</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);
            return(result);
        }
Exemplo n.º 5
0
 private void MapImage_MouseDown(object sender, MouseEventArgs e)
 {
     _panOrQueryIsPan = false;
     if (_map != null)
     {
         if (e.Button == MouseButtons.Left || e.Button == MouseButtons.Middle) //dragging
         {
             _mousedrag = e.Location;
         }
         if (MouseDown != null)
         {
             MouseDown(_map.ImageToWorld(new System.Drawing.Point(e.X, e.Y), true), e);
         }
     }
 }
Exemplo n.º 6
0
        void MapImage_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            if (m_ToolPhase == ToolPhase.WaitFirst)
            {
                return;
            }
            //if (DataProvider == null) NoDataProvider();

            //compleate polygon
            if (m_Vertices.Count < 3)
            {
                return;
            }

            m_Vertices.Add(m_Vertices[0]);

            var      linearRing = new LinearRing(m_Vertices);
            Geometry polygon    = new Polygon(linearRing);

            //polygon = GeometryTransform.TransformGeometry(polygon, CoordinateSystems.SphericalMercatorCS,
            //                                                      CoordinateSystems.WGS84);
            m_ToolPhase = ToolPhase.WaitFirst;

            var connectionString = ConnectionManager.DefaultInstance.ConnectionString;
            var connection       = new SqlConnection(connectionString);

            var valid = SqlExecHelper.SqlGeometryValidation(connection, polygon);

            if (!valid)
            {
                MessageForm.Show(Resources.gis_MtIndependentPolygonBufferZone_CheckValidityMsg);
            }
            else
            {
                //show form
                var frm = new PolygonBufZone();
                //frm.ZoneLayer = string.Empty;

                if (frm.ShowDialog() == DialogResult.OK)
                {
                    if (m_TargetLayerGuid == Guid.Empty)
                    {
                        return;
                    }

                    var eidssUserBufZoneLayer =
                        (EidssUserBufZoneLayer)UserDbLayersManager.GetUserLayer(m_TargetLayerGuid);

                    if (eidssUserBufZoneLayer == null)
                    {
                        return;
                    }


                    var userBufZone = new EidssUserBufZoneLayer.UserBufZone
                    {
                        Geometry    = polygon,
                        Description = frm.Description,
                        Name        = frm.ZoneName,
                        //Center = new Point(0, 0)
                    };

                    eidssUserBufZoneLayer.AddNewZone(userBufZone);
                }
            }
            MapImage.Refresh();

            m_Vertices.Clear();
            m_Points.Clear();
            m_LastMousePosition = System.Drawing.Point.Empty;
        }
Exemplo n.º 7
0
        private void MapImage_MouseUp(object sender, MouseEventArgs e)
        {
            if (_map != null)
            {
                if (MouseUp != null)
                    MouseUp(_map.ImageToWorld(new System.Drawing.Point(e.X, e.Y), true), e);

                if (e.Button == MouseButtons.Left || e.Button == MouseButtons.Middle)
                {
                    if (ActiveTool == Tools.ZoomOut)
                    {
                        double scale = 0.5;
                        if (!_mousedragging)
                        {
                            _map.Center = _map.ImageToWorld(new System.Drawing.Point(e.X, e.Y), true);
                            if (MapCenterChanged != null)
                                MapCenterChanged(_map.Center);
                        }
                        else
                        {
                            if (e.Y - _mousedrag.Y < 0) //Zoom out
                                scale = (float)Math.Pow(1 / (float)(_mousedrag.Y - e.Y), 0.5);
                            else //Zoom in
                                scale = 1 + (e.Y - _mousedrag.Y) * 0.1;
                        }
                        _map.Zoom *= 1 / scale;
                        if (MapZoomChanged != null)
                            MapZoomChanged(_map.Zoom);
                        Refresh();
                    }
                    else if (ActiveTool == Tools.ZoomIn)
                    {
                        double scale = 2;
                        if (!_mousedragging)
                        {
                            _map.Center = _map.ImageToWorld(new System.Drawing.Point(e.X, e.Y), true);
                            if (MapCenterChanged != null)
                                MapCenterChanged(_map.Center);
                        }
                        else
                        {
                            if (e.Y - _mousedrag.Y < 0) //Zoom out
                                scale = (float)Math.Pow(1 / (float)(_mousedrag.Y - e.Y), 0.5);
                            else //Zoom in
                                scale = 1 + (e.Y - _mousedrag.Y) * 0.1;
                        }
                        _map.Zoom *= 1 / scale;
                        if (MapZoomChanged != null)
                            MapZoomChanged(_map.Zoom);
                        Refresh();
                    }
                    else if (ActiveTool == Tools.Pan || (ActiveTool == Tools.PanOrQuery && _panOrQueryIsPan))
                    {
                        if (_mousedragging)
                        {
                            System.Drawing.Point pnt = new System.Drawing.Point(Width / 2 + (_mousedrag.X - e.Location.X),
                                                                                Height / 2 + (_mousedrag.Y - e.Location.Y));
                            _map.Center = _map.ImageToWorld(pnt, true);
                            if (MapCenterChanged != null)
                                MapCenterChanged(_map.Center);
                        }
                        else if(_panOnClick && !_zoomOnDblClick)
                        {
                            _map.Center = _map.ImageToWorld(new System.Drawing.Point(e.X, e.Y), true);
                            if (MapCenterChanged != null)
                                MapCenterChanged(_map.Center);
                        }
                        Refresh();
                    }
                    else if (ActiveTool == Tools.Query || (ActiveTool == Tools.PanOrQuery && !_panOrQueryIsPan))
                    {
                        if (_queryLayerIndex < 0)
                            MessageBox.Show("No active layer to query");
                        else if (_queryLayerIndex < _map.Layers.Count)
                            QueryLayer(_map.Layers[_queryLayerIndex], new PointF(e.X, e.Y));
                        else if(_queryLayerIndex - Map.Layers.Count < _map.VariableLayers.Count)
                            QueryLayer(_map.VariableLayers[_queryLayerIndex - Map.Layers.Count], new PointF(e.X, e.Y));
                        else
                            MessageBox.Show("No active layer to query");
                    }
                }
                if (_mousedragImg != null)
                {
                    _mousedragImg.Dispose();
                    _mousedragImg = null;
                }
                _mousedragging = false;
            }
        }
Exemplo n.º 8
0
 private void MapImage_MouseDown(object sender, MouseEventArgs e)
 {
     _panOrQueryIsPan = false;
     if (_map != null)
     {
         if (e.Button == MouseButtons.Left || e.Button == MouseButtons.Middle) //dragging
             _mousedrag = e.Location;
         if (MouseDown != null)
             MouseDown(_map.ImageToWorld(new System.Drawing.Point(e.X, e.Y), true), e);
     }
 }
Exemplo n.º 9
0
        private void MapImage_MouseUp(object sender, MouseEventArgs e)
        {
            if (_map != null)
            {
                if (MouseUp != null)
                {
                    MouseUp(_map.ImageToWorld(new System.Drawing.Point(e.X, e.Y), true), e);
                }

                if (e.Button == MouseButtons.Left || e.Button == MouseButtons.Middle)
                {
                    if (ActiveTool == Tools.ZoomOut)
                    {
                        double scale = 0.5;
                        if (!_mousedragging)
                        {
                            _map.Center = _map.ImageToWorld(new System.Drawing.Point(e.X, e.Y), true);
                            if (MapCenterChanged != null)
                            {
                                MapCenterChanged(_map.Center);
                            }
                        }
                        else
                        {
                            if (e.Y - _mousedrag.Y < 0) //Zoom out
                            {
                                scale = (float)Math.Pow(1 / (float)(_mousedrag.Y - e.Y), 0.5);
                            }
                            else //Zoom in
                            {
                                scale = 1 + (e.Y - _mousedrag.Y) * 0.1;
                            }
                        }
                        _map.Zoom *= 1 / scale;
                        if (MapZoomChanged != null)
                        {
                            MapZoomChanged(_map.Zoom);
                        }
                        Refresh();
                    }
                    else if (ActiveTool == Tools.ZoomIn)
                    {
                        double scale = 2;
                        if (!_mousedragging)
                        {
                            _map.Center = _map.ImageToWorld(new System.Drawing.Point(e.X, e.Y), true);
                            if (MapCenterChanged != null)
                            {
                                MapCenterChanged(_map.Center);
                            }
                        }
                        else
                        {
                            if (e.Y - _mousedrag.Y < 0) //Zoom out
                            {
                                scale = (float)Math.Pow(1 / (float)(_mousedrag.Y - e.Y), 0.5);
                            }
                            else //Zoom in
                            {
                                scale = 1 + (e.Y - _mousedrag.Y) * 0.1;
                            }
                        }
                        _map.Zoom *= 1 / scale;
                        if (MapZoomChanged != null)
                        {
                            MapZoomChanged(_map.Zoom);
                        }
                        Refresh();
                    }
                    else if (ActiveTool == Tools.Pan || (ActiveTool == Tools.PanOrQuery && _panOrQueryIsPan))
                    {
                        if (_mousedragging)
                        {
                            System.Drawing.Point pnt = new System.Drawing.Point(Width / 2 + (_mousedrag.X - e.Location.X),
                                                                                Height / 2 + (_mousedrag.Y - e.Location.Y));
                            _map.Center = _map.ImageToWorld(pnt, true);
                            if (MapCenterChanged != null)
                            {
                                MapCenterChanged(_map.Center);
                            }
                        }
                        else if (_panOnClick && !_zoomOnDblClick)
                        {
                            _map.Center = _map.ImageToWorld(new System.Drawing.Point(e.X, e.Y), true);
                            if (MapCenterChanged != null)
                            {
                                MapCenterChanged(_map.Center);
                            }
                        }
                        Refresh();
                    }
                    else if (ActiveTool == Tools.Query || (ActiveTool == Tools.PanOrQuery && !_panOrQueryIsPan))
                    {
                        if (_queryLayerIndex < 0)
                        {
                            MessageBox.Show("No active layer to query");
                        }
                        else if (_queryLayerIndex < _map.Layers.Count)
                        {
                            QueryLayer(_map.Layers[_queryLayerIndex], new PointF(e.X, e.Y));
                        }
                        else if (_queryLayerIndex - Map.Layers.Count < _map.VariableLayers.Count)
                        {
                            QueryLayer(_map.VariableLayers[_queryLayerIndex - Map.Layers.Count], new PointF(e.X, e.Y));
                        }
                        else
                        {
                            MessageBox.Show("No active layer to query");
                        }
                    }
                }
                if (_mousedragImg != null)
                {
                    _mousedragImg.Dispose();
                    _mousedragImg = null;
                }
                _mousedragging = false;
            }
        }