AE+C#实现缩放坐标比例尺长度面积量测输出图片等功能
2013-03-22 18:56
609 查看
代码如下:
#region "工具条按钮"
//拉框放大
private void toolStripButton_Zoomin_Click(object sender, EventArgs e)
{
currentoperation = "拉框放大";
axMapControl1.MousePointer = esriControlsMousePointer.esriPointerZoomIn;
}
//拉框缩小
private void toolStripButton_Zoomout_Click(object sender, EventArgs e)
{
currentoperation = "拉框缩小";
axMapControl1.MousePointer = esriControlsMousePointer.esriPointerZoomOut;
}
//平移
private void toolStripButton_Pan_Click(object sender, EventArgs e)
{
currentoperation = "平移漫游";
axMapControl1.MousePointer = esriControlsMousePointer.esriPointerPan;
}
//全图
private void toolStripButton_FullExtent_Click(object sender, EventArgs e)
{
currentoperation = "全图显示";
axMapControl1.Extent = axMapControl1.FullExtent;
axMapControl1.MousePointer = esriControlsMousePointer.esriPointerDefault;
}
//上一视图
private void toolStripButton_LastExtent_Click(object sender, EventArgs e)
{
currentoperation = "上一视图";
IExtentStack pExtentStack = null;
pExtentStack = axMapControl1.ActiveView.ExtentStack;
if (pExtentStack.CanUndo())
pExtentStack.Undo();
axMapControl1.Refresh();
axMapControl1.MousePointer = esriControlsMousePointer.esriPointerDefault;
}
//下一视图
private void toolStripButton_NextExtent_Click(object sender, EventArgs e)
{
currentoperation = "下一视图";
IExtentStack pExtentStack = null;
pExtentStack = axMapControl1.ActiveView.ExtentStack;
if (pExtentStack.CanRedo())
pExtentStack.Redo();
axMapControl1.Refresh();
axMapControl1.MousePointer = esriControlsMousePointer.esriPointerDefault;
}
//中心放大
private void toolStripButton_Zoomin1_Click(object sender, EventArgs e)
{
currentoperation = "中心放大";
IEnvelope objEnvelope = null;
objEnvelope = axMapControl1.Extent;
objEnvelope.Expand(0.5, 0.5, true);
axMapControl1.Extent = objEnvelope;
axMapControl1.MousePointer = esriControlsMousePointer.esriPointerDefault;
}
//中心缩小
private void toolStripButton_Zoomout1_Click(object sender, EventArgs e)
{
currentoperation = "中心缩小";
IEnvelope objEnvelope = null;
objEnvelope = axMapControl1.Extent;
objEnvelope.Expand(2, 2, true);
axMapControl1.Extent = objEnvelope;
axMapControl1.MousePointer = esriControlsMousePointer.esriPointerDefault;
}
//刷新
private void toolStripButton_Refresh_Click(object sender, EventArgs e)
{
currentoperation = "刷新";
axMapControl1.Refresh();
axMapControl1.MousePointer = esriControlsMousePointer.esriPointerDefault;
}
//长度量测
private void toolStripButton_LengthMeasure_Click(object sender, EventArgs e)
{
currentoperation = "长度量测";
axMapControl1.MousePointer = esriControlsMousePointer.esriPointerDefault;
}
//面积量测
private void toolStripButton_AreaMeasure_Click(object sender, EventArgs e)
{
currentoperation = "面积量测";
axMapControl1.MousePointer = esriControlsMousePointer.esriPointerDefault;
}
//地图输出
private void toolStripButton_OutputMap_Click(object sender, EventArgs e)
{
currentoperation = "地图输出";
OutputMap();
}
#endregion
//=========================================================================================================
#region"axMapControl事件"
//鼠标按下事件
private void axMapControl1_OnMouseDown(object sender, AxESRI.ArcGIS.Controls.IMapControlEvents2_OnMouseDownEvent e)
{
IEnvelope objEnvelope = null;
IPoint pPoint = null;
double x;
x = (6371110 * 2 * Math.PI) / 360;
IActiveView pActiveView = axMapControl1.ActiveView.FocusMap as IActiveView;
pPoint = pActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(e.x, e.y);
switch (currentoperation)
{
case "拉框放大":
objEnvelope = axMapControl1.TrackRectangle();
if (!objEnvelope.IsEmpty)
{
axMapControl1.Extent = objEnvelope;
}
else
{
//点击放大
pPoint.X = e.mapX;
pPoint.Y = e.mapY;
pPoint.Z = 0;
objEnvelope = axMapControl1.Extent;
objEnvelope.CenterAt(pPoint);
objEnvelope.Expand(0.5, 0.5, true);
axMapControl1.Extent = objEnvelope;
}
break;
case "拉框缩小":
objEnvelope = axMapControl1.TrackRectangle();
IEnvelope currentExtent = this.axMapControl1.Extent;
double dXmin = 0, dYmin = 0, dXmax = 0, dYmax = 0, dHeight = 0, dWidth = 0;
if (!objEnvelope.IsEmpty)
{
dWidth = currentExtent.Width * (currentExtent.Width / objEnvelope.Width);
dHeight = currentExtent.Height * (currentExtent.Height / objEnvelope.Height);
dXmin = currentExtent.XMin - ((objEnvelope.XMin - currentExtent.XMin) * (currentExtent.Width / objEnvelope.Width));
dYmin = currentExtent.YMin - ((objEnvelope.YMin - currentExtent.YMin) * (currentExtent.Height / objEnvelope.Height));
dXmax = dXmin + dWidth;
dYmax = dYmin + dHeight;
objEnvelope.PutCoords(dXmin, dYmin, dXmax, dYmax);
this.axMapControl1.Extent = objEnvelope;
}
else
{
//点击缩小
pPoint.X = e.mapX;
pPoint.Y = e.mapY;
pPoint.Z = 0;
objEnvelope = axMapControl1.Extent;
objEnvelope.CenterAt(pPoint);
objEnvelope.Expand(2, 2, true);
axMapControl1.Extent = objEnvelope;
}
break;
case "平移漫游":
axMapControl1.Pan();
break;
case "长度量测":
IPolyline pPolyline = null;
pPolyline = (IPolyline)axMapControl1.TrackLine();
double l ;
l =Math.Abs( Math.Round(pPolyline.Length * x,2));
MessageBox.Show("您量测的距离为" + l.ToString() + "米。", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
break;
case "面积量测":
IPolygon pPolygon = null;
pPolygon =(IPolygon)axMapControl1.TrackPolygon();
IArea pArea =(IArea)pPolygon;
double s;
s = Math.Abs(Math.Round(pArea.Area * x * x, 2));
MessageBox.Show("您量测的距离为" + s.ToString() + "平方米。", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
break;
}
}
//鼠标移动事件,获取坐标值
private void axMapControl1_OnMouseMove(object sender, AxESRI.ArcGIS.Controls.IMapControlEvents2_OnMouseMoveEvent e)
{
//double X = 0;
//double Y = 0;
//X = Math.Round(e.mapX, 6); //保留6位小数
//Y = Math.Round(e.mapY, 6);
toolStripStatusLabel_X.Text = "X=" + e.mapX.ToString() + " ";
toolStripStatusLabel_Y.Text = "Y=" + e.mapY.ToString();
}
//获取当前比例尺
private void axMapControl1_OnViewRefreshed(object sender, AxESRI.ArcGIS.Controls.IMapControlEvents2_OnViewRefreshedEvent e)
{
double S= Math.Round(axMapControl1.MapScale, 0); //保留0位小数
toolStripStatusLabel_Scale.Text = "比列尺: 1:" + S.ToString() + " ";
}
#endregion
#region"私有函数"
private void OutputMap()
{
try
{
SaveFileDialog sfd = new SaveFileDialog();
sfd.Filter = "(*jpg)|*jpg|(*.tif)|*tif|(*.pdf)|*.pdf|(*.bmp)|*.bmp";
sfd.Title = "图片另存为";
if (sfd.ShowDialog() == DialogResult.OK)
{
IExport pExport = null;
if (1 == sfd.FilterIndex)
{
pExport = new ExportJPEGClass();
pExport.ExportFileName = sfd.FileName + ".jpeg";
}
else if (2 == sfd.FilterIndex)
{
pExport = new ExportTIFFClass();
pExport.ExportFileName = sfd.FileName + ".tif";
}
else if (3 == sfd.FilterIndex)
{
pExport = new ExportPDFClass();
pExport.ExportFileName = sfd.FileName + ".pdf";
}
else if (4 == sfd.FilterIndex)
{
pExport = new ExportBMPClass();
pExport.ExportFileName = sfd.FileName + ".bmp";
}
//pExport.ExportFileName = sfd.FileName;
int res = 96;
pExport.Resolution = res;
tagRECT exportRECT = axMapControl1.ActiveView.ExportFrame;
IEnvelope pENV = new EnvelopeClass();
pENV.PutCoords(exportRECT.left, exportRECT.top, exportRECT.right, exportRECT.bottom);
pExport.PixelBounds = pENV;
int Hdc = pExport.StartExporting();
IEnvelope pVisibleBounds = null;
ESRI.ArcGIS.esriSystem.ITrackCancel pTrack = null;
axMapControl1.ActiveView.Output(Hdc, (int)pExport.Resolution, ref exportRECT, pVisibleBounds, pTrack);
Application.DoEvents();
pExport.FinishExporting();
pExport.Cleanup();
}
MessageBox.Show("地图输出成功!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch
{
}
}
相关文章推荐
- AE+C#实现缩放坐标比例尺长度面积量测输出图片等功能
- AE+C#实现缩放坐标比例尺长度面积量测输出图片等功能
- ArcGIS API For Javascript之地图基本加载与显示,地图切换、缩放、定位、比例尺、鹰眼图、坐标显示、查询搜索功能实现
- C#实现的图片缩放与剪切功能
- C#之PixturBox控件实现缩放和拖动图片
- 如何在C#中实现图片缩放
- AE SceneControl 滚轮实现缩放功能
- 使用Martix来实现缩放图片的功能
- 如何在C#中实现图片缩放
- 如何在C#中实现图片缩放
- AE+C#实现鹰眼功能——(二)(带鼠标拖动)
- C# 图片盖章功能实现,支持拖拽-旋转-放缩-保存
- PHP实现将几张照片拼接到一起的合成图片功能【便于整体打印输出】
- c# WPF 中图片缩放功能,鼠标拖动位置
- C# 中实现ftp 图片上传功能(多快好省)
- JS实现图片缩放功能
- C#+AE实现类似Identify功能
- 在图片上面添加一个图片,实现12306验证码的选择并获取相关坐标的功能
- 怎样实现C# 的流程日志输出功能[textBox]
- iOS-UI篇—UIScrollView控件实现图片缩放功能