Map中实现 矩形框跟随鼠标移动
来源:互联网 发布:美菱冰箱 知乎 编辑:程序博客网 时间:2024/05/21 08:53
Map中实现 矩形框跟随鼠标移动
1按钮实现选择是自定义画矩形框还是指定大小的矩形框:
//在矩形中分两种:1 地图上画矩形 2 指定宽高
switch (DrawingInfo.Draw_rectWay)
{
case RectWay.RectDraw:
{
_mapControl.Action = SuperAction.CreateRectangle;
}
break;
case RectWay.RectCustm:
{
//画自定义矩形
double w = DrawingInfo.Draw_rectWidth;
double h = DrawingInfo.Draw_rectHeight;
pnt_before = m_map.MapToPixel(m_map.Center);
Rectangle2D rect = new Rectangle2D(m_map.Center, new Size2D(w, h));
_mapControl.Action = SuperAction.Null;
_mapControl.Cursor = Cursors.Cross;
DrawCustomerRect(rect);
isMoveRect = true;
}
break;
default:
break;
}
2 画指定大小的矩形框:
private void DrawCustomerRect(Rectangle2D rect)
{
rect_move = rect;
_mapControl.Cursor = Cursors.Cross;
double x = rect.Left;
double y = rect.Top;
double dblWidth = rect.Width;
double dblHeight = rect.Height;
Point2Ds points = new Point2Ds();
Point2D pntLeftTop = new Point2D(x, y);
Point2D pntLeftBottom = new Point2D(x, y - dblHeight);
Point2D pntRightBottom = new Point2D(x + dblWidth, y - dblHeight);
Point2D pntRightTop = new Point2D(x + dblWidth, y);
points.Add(pntLeftTop);
points.Add(pntLeftBottom);
points.Add(pntRightBottom);
points.Add(pntRightTop);
points.Add(pntLeftTop);
GeoLine rectLine = new GeoLine();
rectLine.AddPart(points);
GeoStyle rectangleStyle = new GeoStyle();
rectangleStyle.LineColor = Color.FromArgb(255, 0, 0);
rectangleStyle.LineWidth = 0.5;
rectLine.Style = rectangleStyle;
int moveRectIndex = m_map.TrackingLayer.IndexOf("CustRect");
if (moveRectIndex >= 0)
{
m_map.TrackingLayer.Remove(moveRectIndex);
}
m_map.TrackingLayer.Add(rectLine, "CustRect");
m_map.RefreshTrackingLayer();
}
/// <summary>
/// point2D的偏移点
/// </summary>
/// <param name="point"></param>
/// <param name="dx"></param>
/// <param name="dy"></param>
/// <returns></returns>
private Point2D OffsetPoint(Point2D point, double dx, double dy)
{
point.Offset(dx, dy);
return point;
}
3,鼠标移动事件:
private void _mapControl_MouseMove(object sender, MouseEventArgs e)
{
if (isMoveRect)
{
Point2D pnt2DBeforeMove = m_map.PixelToMap(pnt_before);
Point2D pnt2DAfterMove = m_map.PixelToMap(e.Location);
double dx = pnt2DAfterMove.X - pnt2DBeforeMove.X;
double dy = pnt2DAfterMove.Y - pnt2DBeforeMove.Y;
rect_move = new Rectangle2D(OffsetPoint(new Point2D(rect_move.Left, rect_move.Top), dx, dy),
OffsetPoint(new Point2D(rect_move.Right, rect_move.Bottom), dx, dy));
DrawCustomerRect(rect_move);
pnt_before = e.Location;//这句很重要
}
}
4, mapcontrol动作光标改变事件:
this._mapControl.ActionCursorChanging += _mapControl_ActionCursorChanging;
void _mapControl_ActionCursorChanging(object sender, ActionCursorChangingEventArgs e)
{
if (isMoveRect)
{
e.FollowingCursor = Cursors.Cross;
}
}
5 变量的声明。这一步其实该放第一位,忘了。所以补上:
private bool isMoveRect = false;
private Point pnt_before;
private Rectangle2D rect_move;
mapcontrol属性:
this._mapControl.IsWaitCursorEnabled = false;
this._mapControl.TrackMode = TrackMode.Track;
- Map中实现 矩形框跟随鼠标移动
- threejs中坐标系转换和实现物体跟随鼠标移动
- js实现跟随鼠标移动的提示框
- 实现界面跟随鼠标移动的实例
- JS实现图片跟随鼠标移动
- 游戏人物跟随鼠标移动的实现
- JS实现控件跟随鼠标移动
- Unity 代码实现物体跟随鼠标移动
- vc中圆形跟随者鼠标移动
- qt中文字图片跟随鼠标移动
- opencv中实现鼠标选定矩形框
- C# 图片框跟随鼠标移动
- 层跟随鼠标移动
- 人物跟随鼠标移动
- 跟随鼠标移动div
- 图片跟随鼠标移动
- 跟随鼠标移动
- JavaScript实现跟随鼠标移动而移动的文字
- onbeforeunload与onunload事件
- 探索Java语言与JVM中的Lambda表达式
- iOS多线程编程之Grand Central Dispatch(GCD)介绍和使用
- 使用jquery moblie进行移动智能开发(1)
- 单线程不固定大小对象的内存池实现
- Map中实现 矩形框跟随鼠标移动
- 信号量
- OpenCV HOG PeopleDetector:从训练到检测 1
- day 1
- Oracle创建表空间
- 042 - dbms_rls.add_policy
- Designer与Eclipse同步开发
- 转载 Windows8 游戏开发教程-开篇 主要是知识点和工具的列举和对比
- coffeescript语法入门