【C# + Argis Engine】地图上绘制圆形并且实时的显示半径源码
来源:互联网 发布:linux mkdir命令 编辑:程序博客网 时间:2024/06/16 10:44
主要思路:
1.用到AxMapControl的三个事件
2.自写绘制方法,从中获得想要的数据
3.将数据跟随Move事件,标注的地图上
*文本标注的局部刷新,防止连带圆形一块刷新导致模糊的情况,可参考http://blog.csdn.net/fuyouche/article/details/8618788
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
using System;
using System.Collections.Generic;using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Display;
using ESRI.ArcGIS.Geometry;
using stdole;
namespace 地图绘圆
{
public partial class MapViwer : Form
{
//用到的全局变量
IActiveView pActiveView;IMap pMap;
IGraphicsContainer pGraphicscon;
INewCircleFeedback pCircleFeed;
ITextElement textElement;
IElement element;
IPoint StartPoint;
//构造函数
public MapViwer(){
InitializeComponent();
}
private void MapViwer_Load(object sender, EventArgs e)
{
InitializeGlobeVar();
}
//初始化全局变量
private void InitializeGlobeVar()
{
pMap = axMapControl1.Map;
pActiveView = pMap as IActiveView;
pGraphicscon = pActiveView as IGraphicsContainer;
ObtainedValues = new List<double>();
}
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
private void axMapControl1_OnMouseDown(object sender, ESRI.ArcGIS.Controls.IMapControlEvents2_OnMouseDownEvent e)
{
FixCircleCenter(e);
CreateTextNote();
}
private void FixCircleCenter(ESRI.ArcGIS.Controls.IMapControlEvents2_OnMouseDownEvent e)
{
StartPoint = new PointClass();
StartPoint.PutCoords(e.mapX, e.mapY);
if (pCircleFeed == null)
{
pCircleFeed = new NewCircleFeedbackClass();
pCircleFeed.Display = pActiveView.ScreenDisplay;
pCircleFeed.Start(StartPoint);
}
}
private void CreateTextNote()
{
IRgbColor pColor = new RgbColorClass()
{
Red = 255,
Blue = 0,
Green = 0
};
IFontDisp pFont = new StdFont()
{
Name = "宋体",
Size = 3
} as IFontDisp;
ITextSymbol pTextSymbol = new TextSymbolClass()
{
Color = pColor,
Font = pFont,
Size = 11
};
textElement = new TextElementClass()
{
Symbol = pTextSymbol,
ScaleText = true,
Text = "10公里"
};
element = textElement as IElement;
element.Geometry = StartPoint;
pGraphicscon.AddElement(element, 1);
}
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//鼠标移动
private void axMapControl1_OnMouseMove(object sender, ESRI.ArcGIS.Controls.IMapControlEvents2_OnMouseMoveEvent e)
{
RepaintCircleNote(e);
}
/// <summary>
/// 重新绘制圆和半径标注
/// </summary>
/// <param name="e"></param>
private void RepaintCircleNote(ESRI.ArcGIS.Controls.IMapControlEvents2_OnMouseMoveEvent e)
{
ObtainedValues.Clear();
IPoint MovePoint = new PointClass();
MovePoint.PutCoords(e.mapX, e.mapY);
if (pCircleFeed != null)
{
pCircleFeed.MoveTo(MovePoint);
if (element != null)
{
ILine line = new LineClass();
line.FromPoint = StartPoint;
line.ToPoint = MovePoint;
textElement.Text = Math.Round((Math.Abs(line.Length * 100)), 0).ToString() + "公里";
ObtainedValues.Add(Math.Round((Math.Abs(line.Length * 100)), 0));
ObtainedValues.Add(StartPoint.X);
ObtainedValues.Add(StartPoint.Y);
//此段代码是测试获得的值用的,可以不要
double x1 = StartPoint.X;
double y1 = StartPoint.Y;
double x2 = MovePoint.X;
double y2 = MovePoint.Y;
double l =Math.Round(Math.Sqrt((x2 - x1) * (x2 - x1) + (y2 - y1)*(y2 - y1)),2);
ObtainedValues.Add(l);
}
}
}
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//鼠标抬起
private void axMapControl1_OnMouseUp(object sender, ESRI.ArcGIS.Controls.IMapControlEvents2_OnMouseUpEvent e)
{
ReloadMap();
}
private void ReloadMap()
{
pGraphicscon.DeleteElement(element);
pCircleFeed = null;
element = null;
pActiveView.Refresh();
MessageBox.Show(ObtainedValues[0].ToString() +"\r\n" + ObtainedValues[3].ToString(),"",MessageBoxButtons.OK);
}
}
}
- 【C# + Argis Engine】地图上绘制圆形并且实时的显示半径源码
- 百度地图---绘制圆时实时显示圆半径
- ArcGIS Engine + C# 开发过程中,鼠标在地图上滑过时,显示地图相关信息
- 手机端GSP地图的定位 并且在网页上显示地图的轨迹
- Matlab—动态绘制半径渐变的圆形与绕圆心旋转的直线
- android百度地图:在地图上绘制点、线、多边形、圆形和文字
- android百度地图:在地图上绘制点、线、多边形、圆形和文字
- C#绘制实时曲线
- arcgismobile10 绘制圆并且在GPS定位点为中心,半径R 搜索圆内的管线信息
- 对Graphic的应用,实现类似九宫格的绘制字符串、制定圆心,半径绘制圆形、用火柴棍拼字[Java ME]
- 圆形头像的绘制
- Silverlight实现对图片的涂鸦、绘制矩形、圆形、直线、文本,并且能够移动
- 地图上绘制多边形
- 限制字数, 并且实时显示字数的EditText
- ArcGIS Engine 地图制作 C#
- 传入两个中文地点,解析成坐标点,并且在地图上显示出它们之间的路线图
- iOS 使用UIBezierPath绘制圆型, 并且根据半径, 角度, 长度在圆外任意一点绘制线段, 通常用于饼状图的文字说明
- 安卓开发:怎样实时在百度地图上绘制运动轨迹?
- Android的Task和Activity相关
- 展讯6820的代码
- C语言开源正则表达式库-----PCRE
- Android 4.2 Input 流程分析
- linux内核input子系统解析
- 【C# + Argis Engine】地图上绘制圆形并且实时的显示半径源码
- 线段树单点更新
- 单例模式之生产实践
- TCP和UDP网络通讯的区别及实现方式
- Android Binder 之奇幻國度
- socket和http间的区别
- Comet:基于 HTTP 长连接的“服务器推”技术
- 【Android数据存储】ContentProvider详细介绍(附实例源码)
- java调用oracle存储过程详细实例