实例介绍
【实例简介】
【实例截图】
【核心代码】
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Geometry;
using ESRI.ArcGIS.Display;
using ESRI.ArcGIS.Controls;
using celiang222222;
using ESRI.ArcGIS.esriSystem;
using gisprojectselect;
using ESRI.ArcGIS.SystemUI;
using System.Runtime.InteropServices;
using ESRI.ArcGIS.Geodatabase;
using ESRI.ArcGIS.DataSourcesRaster;
using gisprojectSceneselect;
namespace _12
{
public partial class frm : Form
{
#region 主窗体按钮定义
private System.Windows.Forms.Panel panel1;
private System.Windows.Forms.ToolStrip toolStrip1;
private System.Windows.Forms.ToolStripButton openfile;
private System.Windows.Forms.ToolStripButton zmin;
private System.Windows.Forms.ToolStripButton zmout;
private System.Windows.Forms.ToolStripButton manyou;
private System.Windows.Forms.ToolStripButton quantu;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button MeasureLength;
private System.Windows.Forms.StatusStrip statusStrip1;
private System.Windows.Forms.ToolStripStatusLabel toolStripStatusLabel1;
private System.Windows.Forms.ToolStripStatusLabel toolStripStatusLabel2;
private System.Windows.Forms.ToolStripStatusLabel toolstripX;
private System.Windows.Forms.ToolStripStatusLabel toolstripY;
private System.Windows.Forms.ToolStripStatusLabel toolstripUnits;
private System.Windows.Forms.TabControl tabControl1;
private System.Windows.Forms.TabPage tabPage1;
private System.Windows.Forms.TabPage tabPage2;
#endregion
#region 变量定义
//显示地图量测结果
private FormMeasureResult frmMeasureResult = null;//量算结果窗体
private ESRI.ArcGIS.Display.INewLineFeedback pNewLineFeedback; //追踪线对象
private ESRI.ArcGIS.Geometry.IPoint pPointPt = null; //鼠标点击点位置
private ESRI.ArcGIS.Geometry.IPoint pMovePoint = null; //鼠标移动点位置
private double dToltalLength = 0.0; //量测总长度
private double dSegmentLength = 0.0; //片段距离
private string sMapUnits = "UnKnow";
private object missing = Type.Missing;
//鹰眼同步
private bool bCanDrag; //鹰眼地图上的矩形框可移动的标志
private IPoint pMoveRectPoint; //记录在移动鹰眼地图上的矩形框时鼠标的位置
private IEnvelope pEnv; //记录数据视图的Extent
#endregion
public frm()
{
InitializeComponent();
EyeaxMapControl2.Extent = axMapControl1.FullExtent;
pEnv = EyeaxMapControl2.Extent;
DrawRectangle(pEnv);
}
string pMouseOperate = null;
private string GetMapUnit(esriUnits _esriMapUnit)
{
string sMapUnits = string.Empty;
switch (_esriMapUnit)
{
case esriUnits.esriCentimeters:
sMapUnits = "厘米";
break;
case esriUnits.esriDecimalDegrees:
sMapUnits = "十进制";
break;
case esriUnits.esriDecimeters:
sMapUnits = "分米";
break;
case esriUnits.esriFeet:
sMapUnits = "尺";
break;
case esriUnits.esriInches:
sMapUnits = "英寸";
break;
case esriUnits.esriKilometers:
sMapUnits = "千米";
break;
case esriUnits.esriMeters:
sMapUnits = "米";
break;
sMapUnits = "英里";
break;
case esriUnits.esriMillimeters:
sMapUnits = "毫米";
break;
case esriUnits.esriNauticalMiles:
sMapUnits = "海里";
break;
case esriUnits.esriPoints:
sMapUnits = "点";
break;
case esriUnits.esriUnitsLast:
sMapUnits = "UnitsLast";
break;
case esriUnits.esriUnknownUnits:
sMapUnits = "未知单位";
break;
case esriUnits.esriYards:
sMapUnits = "码";
break;
default:
break;
}
return sMapUnits;
}//获得地图单位
private void axMapControl1_OnMouseMove(object sender, ESRI.ArcGIS.Controls.IMapControlEvents2_OnMouseMoveEvent e)
{
sMapUnits = GetMapUnit(axMapControl1.Map.MapUnits);
#region 长度量算
pMovePoint = (axMapControl1.Map as IActiveView).ScreenDisplay.DisplayTransformation.ToMapPoint(e.x, e.y);
//长度量算
if (pMouseOperate == "MeasureLength")
{
if (pNewLineFeedback != null)
{
pNewLineFeedback.MoveTo(pMovePoint);
}
double deltaX = 0; //两点之间X差值
double deltaY = 0; //两点之间Y差值
if ((pPointPt != null) && (pNewLineFeedback != null))
{
deltaX = pMovePoint.X - pPointPt.X;
deltaY = pMovePoint.Y - pPointPt.Y;
dSegmentLength = Math.Round(Math.Sqrt((deltaX * deltaX) (deltaY * deltaY)), 3);
dToltalLength = dToltalLength dSegmentLength;
if (frmMeasureResult != null)
{
frmMeasureResult.lblMeasureResult.Text = String.Format(
"当前线段长度:{0:.###}{1};\r\n\n总长度为: {2:.###}{1}",
dSegmentLength, sMapUnits, dToltalLength);
dToltalLength = dToltalLength - dSegmentLength; //鼠标移动到新点重新开始计算
}
frmMeasureResult.frmClosed = new FormMeasureResult.FormClosedEventHandler(frmMeasureResult_frmColsed);
}
}
#endregion
#region 屏幕坐标显示
toolstripX.Text = e.mapX.ToString("0.000000");
toolstripY.Text = e.mapY.ToString("0.000000");
toolstripUnits.Text = getUnits();
#endregion
}
private void axMapControl1_OnMouseDown(object sender, ESRI.ArcGIS.Controls.IMapControlEvents2_OnMouseDownEvent e)
{
#region 放大缩小漫游
IActiveView pActiveView = axMapControl1.ActiveView;
ESRI.ArcGIS.Geometry.IEnvelope ipEnv;
if (pMouseOperate == "zmin")
{
//放大
ipEnv = axMapControl1.TrackRectangle();
axMapControl1.Extent = ipEnv;
}
if (pMouseOperate == "zmout")
{
//缩小
ipEnv = axMapControl1.TrackRectangle();
//如果拉框范围为空则退出
if (ipEnv == null || ipEnv.IsEmpty || ipEnv.Height == 0 || ipEnv.Width == 0)
{
return;
}
//如果有拉框范围,则以拉框范围为中心,缩小倍数为:当前视图范围/拉框范围
else
{
double dWidth = pActiveView.Extent.Width * pActiveView.Extent.Width / ipEnv.Width;
double dHeight = pActiveView.Extent.Height * pActiveView.Extent.Height / ipEnv.Height;
double dXmin = pActiveView.Extent.XMin -
((ipEnv.XMin - pActiveView.Extent.XMin) * pActiveView.Extent.Width /
ipEnv.Width);
double dYmin = pActiveView.Extent.YMin -
((ipEnv.YMin - pActiveView.Extent.YMin) * pActiveView.Extent.Height /
ipEnv.Height);
double dXmax = dXmin dWidth;
double dYmax = dYmin dHeight;
ipEnv.PutCoords(dXmin, dYmin, dXmax, dYmax);
}
pActiveView.Extent = ipEnv;
pActiveView.Refresh();
}
if (pMouseOperate == "manyou")
{
ipEnv = axMapControl1.Extent;
axMapControl1.Pan();
}
#endregion
#region 地图测量
pPointPt = (axMapControl1.Map as IActiveView).ScreenDisplay.DisplayTransformation.ToMapPoint(e.x, e.y);
//IEnvelope pEnvelope = new Envelope() as IEnvelope;
if (pMouseOperate == "MeasureLength")
{
//判断追踪线对象是否为空,若是则实例化并设置当前鼠标点为起始点
if (pNewLineFeedback == null)
{
//实例化追踪线对象
pNewLineFeedback = new NewLineFeedback();
pNewLineFeedback.Display = (axMapControl1.Map as IActiveView).ScreenDisplay;
//设置起点,开始动态线绘制
pNewLineFeedback.Start(pPointPt);
dToltalLength = 0;
}
else //如果追踪线对象不为空,则添加当前鼠标点
{
pNewLineFeedback.AddPoint(pPointPt);
}
//pGeometry = m_PointPt;
if (dSegmentLength != 0)
{
dToltalLength = dToltalLength dSegmentLength;
}
}
#endregion
#region 地图上点击查询
// this.axMapControl1.CurrentTool = null;
// axMapControl1.Map.ClearSelection();
// //它有一Identify方法,返回一个IArray数组对象。
// IIdentify pIdentify = null;
// IPoint pPoint = null;
// IArray pIDArray = null;
// IFeatureIdentifyObj pFeatIdObj = null;//定义一个要素对象
// IRowIdentifyObject pRowIdObj = null; //定义一个Row对象
// IIdentifyObj pIdObj = null;
// FeatureLayer plyr = null;
// IFeature pfeature = null; //定义一个featrue
// IMap pMap = axMapControl1.Map;//将当前地图赋给地图对象pMap
// for (int i = 0; i < axMapControl1.Map.LayerCount; i )
// {
// if (axMapControl1.Map.Layer[i].Name.ToString().Substring(0, axMapControl1.Map.Layer[i].Name.ToString().Length - 2).Equals(main_ui.frmlinem.lstLineAll.SelectedItem.ToString().Substring(0, main_ui.frmlinem.lstLineAll.SelectedItem.ToString().Length - 2)))
// {
// if (axMapControl1.Map.Layer[i].Name.ToString().Substring(axMapControl1.Map.Layer[i].Name.ToString().Length - 2, 2).Equals("_点"))
// {
// pIdentify = pMap.get_Layer(i) as IIdentify;//将图层赋给图层对象pIdentify
// plyr = pMap.get_Layer(i) as FeatureLayer;
// break;
// }
// }
// }
// pPoint = new ESRI.ArcGIS.Geometry.Point();//定义了一个实现IPoint接口的点对象
// pPoint.PutCoords(e.mapX, e.mapY);//pPoint.PutCoords用来设置点的X,Y值从而创建一个点对象。
// pPoint.SpatialReference = pMap.SpatialReference;
// IEnvelope pEnvelope = new Envelope() as IEnvelope;
// IGeometry bufGeo;
// ITopologicalOperator bufferPoint = pPoint as ITopologicalOperator;
// bufGeo = bufferPoint.Buffer(axMapControl1.ActiveView.Extent.Width / 300);
// pEnvelope = bufGeo.Envelope;
// pIDArray = pIdentify.Identify(pEnvelope);//Identify方法返回一个Array数组对象
// IGeometry pGG = null;
// pGG = pPoint;
// if (pIDArray != null)
// {
// pFeatIdObj = pIDArray.get_Element(0) as IFeatureIdentifyObj;//获得要素集数组中的第一个元素
// pIdObj = pFeatIdObj as IIdentifyObj;
// //让鼠标点击的点闪烁一次,当然可以根据自己需要调整
// axMapControl1.FlashShape(pPoint, 1, 500, null);
// //axMapMain.Map.ClearSelection();
// axMapControl1.Map.SelectByShape(pGG, null, false);
// //axMapMain.Refresh();
// //显示要素所在图层的名字,要素的的名字
// if (frmpic == null || frmpic.IsDisposed)
// {
// IFeatureClass featureClass = plyr.FeatureClass;
// IQueryFilter queryFilter = new QueryFilter(); //创建一个查询筛选
// pRowIdObj = pFeatIdObj as IRowIdentifyObject;
// pfeature = pRowIdObj.Row as IFeature;
// queryFilter.WhereClause = "FID = " pRowIdObj.Row.OID; //查询条件,即选中获取的ID
// queryFilter.SubFields = "杆塔编号";
// int fieldPosition = featureClass.FindField("杆塔编号"); //获取字段(这里是SHAPE_Area),其他字段同理
// IFeatureCursor featureCursor = featureClass.Search(queryFilter, true);
// IFeature feature = null;
// while ((feature = featureCursor.NextFeature()) != null)
// {
// //MessageBox.Show(feature.get_Value(fieldPosition).ToString()); //获取字段的值。
// frmpic = new picBox(pIdObj.Layer.Name, feature.get_Value(fieldPosition).ToString(), pfeature);
// frmpic.ShowInTaskbar = false;
// frmpic.Owner = this;
// frmpic.Location = new System.Drawing.Point(0, 0);
// frmpic.Show();
// }
// }
// else
// {
// frmpic.Close();
// IFeatureClass featureClass = plyr.FeatureClass;
// IQueryFilter queryFilter = new QueryFilter(); //创建一个查询筛选
// pRowIdObj = pFeatIdObj as IRowIdentifyObject;
// pfeature = pRowIdObj.Row as IFeature;
// queryFilter.WhereClause = "FID = " pRowIdObj.Row.OID; //查询条件,即选中获取的ID
// queryFilter.SubFields = "杆塔编号";
// int fieldPosition = featureClass.FindField("杆塔编号"); //获取字段(这里是SHAPE_Area),其他字段同理
// IFeatureCursor featureCursor = featureClass.Search(queryFilter, true);
// IFeature feature = null;
// while ((feature = featureCursor.NextFeature()) != null)
// {
// //MessageBox.Show(feature.get_Value(fieldPosition).ToString()); //获取字段的值。
// frmpic = new picBox(pIdObj.Layer.Name, feature.get_Value(fieldPosition).ToString(), pfeature);
// frmpic.ShowInTaskbar = false;
// frmpic.Owner = this;
// frmpic.Location = new System.Drawing.Point(0, 0);
// frmpic.Show();
// }
// }
// //MessageBox.Show("Layer Name:" pIdObj.Layer.Name "\n" "Feature Name:" pIdObj.Name);
// //点击messagebox确定按钮后,清除选择
// axMapControl1.Map.ClearSelection();
// }
#endregion
}
private string getUnits()
{
string xUnits = axMapControl1.MapUnits.ToString();
string unit = "";
if (xUnits.Equals("esriDecimalDegrees"))
{
unit = "°";
}
else
{
unit = "无单位";
}
return unit;
}//屏幕坐标单位
private void toolStripButton1_Click(object sender, EventArgs e)
{
#region 打开地图文档
OpenFileDialog OpenMXD = new OpenFileDialog();
OpenMXD.Title = "打开地图";
OpenMXD.Filter = "Map Document(*.mxd)|*.mxd";
if (OpenMXD.ShowDialog() == DialogResult.OK)
{
string MxdPath = OpenMXD.FileName;
axMapControl1.LoadMxFile(MxdPath);
//<span style="white-space:pre"> </span>
}
#endregion
}
private void toolStripButton2_Click(object sender, EventArgs e)//放大
{
axMapControl1.MousePointer = esriControlsMousePointer.esriPointerPageZoomIn;
pMouseOperate = "zmin";
}
private void toolStripButton3_Click(object sender, EventArgs e)//缩小
{
axMapControl1.MousePointer = esriControlsMousePointer.esriPointerPageZoomOut;
pMouseOperate = "zmout";
}
//private ICommand pCommand = null;
private void toolStripButton4_Click(object sender, EventArgs e)//漫游
{
//pCommand = new ControlsMapPanTool();
//pCommand.OnCreate(axMapControl1.Object);
//axMapControl1.CurrentTool = pCommand as ITool;
//pCommand.OnClick();
axMapControl1.MousePointer = esriControlsMousePointer.esriPointerPagePan;
pMouseOperate = "manyou";
}
private void toolStripButton5_Click(object sender, EventArgs e)//全图
{
axMapControl1.Extent = axMapControl1.FullExtent;
}
private void button1_Click(object sender, EventArgs e)
{
MapSelectByAttributes frms = new MapSelectByAttributes();
frms.showForm(axMapControl1);
}
private void MeasureLength_Click(object sender, EventArgs e)
{
axMapControl1.CurrentTool = null;
pMouseOperate = "MeasureLength";
axMapControl1.MousePointer = esriControlsMousePointer.esriPointerCrosshair;
if (frmMeasureResult == null || frmMeasureResult.IsDisposed)
{
frmMeasureResult = new FormMeasureResult();
frmMeasureResult.frmClosed = new FormMeasureResult.FormClosedEventHandler(frmMeasureResult_frmColsed);
frmMeasureResult.lblMeasureResult.Text = "";
frmMeasureResult.Text = "距离量测";
frmMeasureResult.Show();
}
else
{
frmMeasureResult.Activate();
}
}
private void frmMeasureResult_frmColsed()
{
//清空线对象
if (pNewLineFeedback != null)
{
pNewLineFeedback.Stop();
pNewLineFeedback = null;
}
//清空量算画的线、面对象
axMapControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewForeground, null, null);
//结束量算功能
pMouseOperate = string.Empty;
axMapControl1.MousePointer = esriControlsMousePointer.esriPointerDefault;
}
private void axMapControl1_OnDoubleClick(object sender, IMapControlEvents2_OnDoubleClickEvent e)
{
#region 长度量算
if (pMouseOperate == "MeasureLength")
{
if (frmMeasureResult != null)
{
frmMeasureResult.lblMeasureResult.Text = "线段总长度为:" dToltalLength sMapUnits;
}
if (pNewLineFeedback != null)
{
pNewLineFeedback.Stop();
pNewLineFeedback = null;
//清空所画的线对象
(axMapControl1.Map as IActiveView).PartialRefresh(esriViewDrawPhase.esriViewForeground, null, null);
}
dToltalLength = 0;
dSegmentLength = 0;
}
#endregion
}
private void minimum_Click(object sender, EventArgs e)
{
panel2.Visible = false;
maxmum.Visible = true;
}
private void maxmum_Click(object sender, EventArgs e)
{
panel2.Visible = true;
maxmum.Visible = false;
}
#region 鹰眼的实现和同步
private void AddAllDataset(IWorkspace pWorkspace, AxMapControl mapControl)
{
IEnumDataset pEnumDataset = pWorkspace.get_Datasets(ESRI.ArcGIS.Geodatabase.esriDatasetType.esriDTAny);
pEnumDataset.Reset();
//将Enum数据集中的数据一个个读到DataSet中
IDataset pDataset = pEnumDataset.Next();
//判断数据集是否有数据
while (pDataset != null)
{
if (pDataset is IFeatureDataset) //要素数据集
{
IFeatureWorkspace pFeatureWorkspace = (IFeatureWorkspace)pWorkspace;
IFeatureDataset pFeatureDataset = pFeatureWorkspace.OpenFeatureDataset(pDataset.Name);
IEnumDataset pEnumDataset1 = pFeatureDataset.Subsets;
pEnumDataset1.Reset();
IGroupLayer pGroupLayer = new GroupLayer();
pGroupLayer.Name = pFeatureDataset.Name;
IDataset pDataset1 = pEnumDataset1.Next();
while (pDataset1 != null)
{
if (pDataset1 is IFeatureClass) //要素类
{
IFeatureLayer pFeatureLayer = new FeatureLayer();
pFeatureLayer.FeatureClass = pFeatureWorkspace.OpenFeatureClass(pDataset1.Name);
if (pFeatureLayer.FeatureClass != null)
{
pFeatureLayer.Name = pFeatureLayer.FeatureClass.AliasName;
pGroupLayer.Add(pFeatureLayer);
mapControl.Map.AddLayer(pFeatureLayer);
}
}
pDataset1 = pEnumDataset1.Next();
}
}
else if (pDataset is IFeatureClass) //要素类
{
IFeatureWorkspace pFeatureWorkspace = (IFeatureWorkspace)pWorkspace;
IFeatureLayer pFeatureLayer = new FeatureLayer();
pFeatureLayer.FeatureClass = pFeatureWorkspace.OpenFeatureClass(pDataset.Name);
pFeatureLayer.Name = pFeatureLayer.FeatureClass.AliasName;
mapControl.Map.AddLayer(pFeatureLayer);
}
else if (pDataset is IRasterDataset) //栅格数据集
{
IRasterWorkspaceEx pRasterWorkspace = (IRasterWorkspaceEx)pWorkspace;
IRasterDataset pRasterDataset = pRasterWorkspace.OpenRasterDataset(pDataset.Name);
//影像金字塔判断与创建
IRasterPyramid3 pRasPyrmid;
pRasPyrmid = pRasterDataset as IRasterPyramid3;
if (pRasPyrmid != null)
{
if (!(pRasPyrmid.Present))
{
pRasPyrmid.Create(); //创建金字塔
}
}
IRasterLayer pRasterLayer = new RasterLayer();
pRasterLayer.CreateFromDataset(pRasterDataset);
ILayer pLayer = pRasterLayer as ILayer;
mapControl.AddLayer(pLayer, 0);
}
pDataset = pEnumDataset.Next();
}
mapControl.ActiveView.Refresh();
//同步鹰眼
SynchronizeEagleEye();
}
private void ClearAllData()
{
if (axMapControl1.Map != null && axMapControl1.Map.LayerCount > 0)
{
//新建mainMapControl中Map
IMap dataMap = new Map();
dataMap.Name = "Map";
axMapControl1.DocumentFilename = string.Empty;
axMapControl1.Map = dataMap;
//新建EagleEyeMapControl中Map
IMap eagleEyeMap = new Map();
eagleEyeMap.Name = "eagleEyeMap";
EyeaxMapControl2.DocumentFilename = string.Empty;
EyeaxMapControl2.Map = eagleEyeMap;
}
}
//获取RGB值
private IRgbColor GetRgbColor(int intR, int intG, int intB)
{
IRgbColor pRgbColor = null;
if (intR < 0 || intR > 255 || intG < 0 || intG > 255 || intB < 0 || intB > 255)
{
return pRgbColor;
}
pRgbColor = new RgbColor();
pRgbColor.Red = intR;
pRgbColor.Green = intG;
pRgbColor.Blue = intB;
return pRgbColor;
}
//在鹰眼地图上面画矩形框
private void DrawRectangle(IEnvelope pEnvelope)
{
//在绘制前,清除鹰眼中之前绘制的矩形框
IGraphicsContainer pGraphicsContainer = EyeaxMapControl2.Map as IGraphicsContainer;
IActiveView pActiveView = pGraphicsContainer as IActiveView;
pGraphicsContainer.DeleteAllElements();
//得到当前视图范围
IRectangleElement pRectangleElement = new RectangleElement() as IRectangleElement;
IElement pElement = pRectangleElement as IElement;
pElement.Geometry = pEnvelope;
//设置矩形框(实质为中间透明度面)
IRgbColor pColor = new RgbColor();
pColor = GetRgbColor(255, 0, 0);
pColor.Transparency = 255;
ILineSymbol pOutLine = new SimpleLineSymbol();
pOutLine.Width = 1;
pOutLine.Color = pColor;
IFillSymbol pFillSymbol = new SimpleFillSymbol();
pColor = new RgbColor();
pColor.Transparency = 0;
pFillSymbol.Color = pColor;
pFillSymbol.Outline = pOutLine;
//向鹰眼中添加矩形框
IFillShapeElement pFillShapeElement = pElement as IFillShapeElement;
pFillShapeElement.Symbol = pFillSymbol;
pGraphicsContainer.AddElement((IElement)pFillShapeElement, 0);
//刷新
pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
}
//绘制矩形框
private void axMapControl1_OnExtentUpdated(object sender, IMapControlEvents2_OnExtentUpdatedEvent e)
{
//得到当前视图范围,绘制矩形框
pEnv = (IEnvelope)e.newEnvelope;
DrawRectangle(pEnv);
}
private void axMapControl1_OnMapReplaced(object sender, IMapControlEvents2_OnMapReplacedEvent e)
{
SynchronizeEagleEye();
}
private void SynchronizeEagleEye()
{
if (EyeaxMapControl2.LayerCount > 0)
{
EyeaxMapControl2.ClearLayers();
}
//设置鹰眼和主地图的坐标系统一致
EyeaxMapControl2.SpatialReference = axMapControl1.SpatialReference;
for (int i = axMapControl1.LayerCount - 1; i >= 0; i--)
{
//使鹰眼视图与数据视图的图层上下顺序保持一致
ILayer pLayer = axMapControl1.get_Layer(i);
if (pLayer is IGroupLayer || pLayer is ICompositeLayer)
{
ICompositeLayer pCompositeLayer = (ICompositeLayer)pLayer;
for (int j = pCompositeLayer.Count - 1; j >= 0; j--)
{
ILayer pSubLayer = pCompositeLayer.get_Layer(j);
IFeatureLayer pFeatureLayer = pSubLayer as IFeatureLayer;
if (pFeatureLayer != null)
{
//由于鹰眼地图较小,所以过滤点图层不添加
if (pFeatureLayer.FeatureClass.ShapeType != esriGeometryType.esriGeometryPoint
&& pFeatureLayer.FeatureClass.ShapeType != esriGeometryType.esriGeometryMultipoint)
{
EyeaxMapControl2.AddLayer(pLayer);
}
}
}
}
else
{
IFeatureLayer pFeatureLayer = pLayer as IFeatureLayer;
if (pFeatureLayer != null)
{
if (pFeatureLayer.FeatureClass.ShapeType != esriGeometryType.esriGeometryPoint
&& pFeatureLayer.FeatureClass.ShapeType != esriGeometryType.esriGeometryMultipoint)
{
EyeaxMapControl2.AddLayer(pLayer);
}
}
}
//设置鹰眼地图全图显示
EyeaxMapControl2.Extent = axMapControl1.FullExtent;
pEnv = axMapControl1.Extent as IEnvelope;
DrawRectangle(pEnv);
EyeaxMapControl2.ActiveView.Refresh();
}
}
private void EyeaxMapControl2_OnMouseDown(object sender, IMapControlEvents2_OnMouseDownEvent e)
{
if (EyeaxMapControl2.Map.LayerCount > 0)
{
//按下鼠标左键移动矩形框
if (e.button == 1)
{
//如果指针落在鹰眼的矩形框中,标记可移动
if (e.mapX > pEnv.XMin && e.mapY > pEnv.YMin && e.mapX < pEnv.XMax && e.mapY < pEnv.YMax)
{
bCanDrag = true;
}
pMoveRectPoint = new ESRI.ArcGIS.Geometry.Point();
pMoveRectPoint.PutCoords(e.mapX, e.mapY); //记录点击的第一个点的坐标
}
//按下鼠标右键绘制矩形框
else if (e.button == 2)
{
IEnvelope pEnvelope = EyeaxMapControl2.TrackRectangle();
IPoint pTempPoint = new ESRI.ArcGIS.Geometry.Point();
pTempPoint.PutCoords(pEnvelope.XMin pEnvelope.Width / 2, pEnvelope.YMin pEnvelope.Height / 2);
axMapControl1.Extent = pEnvelope;
//矩形框的高宽和数据试图的高宽不一定成正比,这里做一个中心调整
axMapControl1.CenterAt(pTempPoint);
}
}
}
//移动矩形框
private void EyeaxMapControl2_OnMouseMove(object sender, IMapControlEvents2_OnMouseMoveEvent e)
{
if (e.mapX > pEnv.XMin && e.mapY > pEnv.YMin && e.mapX < pEnv.XMax && e.mapY < pEnv.YMax)
{
//如果鼠标移动到矩形框中,鼠标换成小手,表示可以拖动
EyeaxMapControl2.MousePointer = esriControlsMousePointer.esriPointerHand;
if (e.button == 2) //如果在内部按下鼠标右键,将鼠标演示设置为默认样式
{
EyeaxMapControl2.MousePointer = esriControlsMousePointer.esriPointerDefault;
}
}
else
{
//在其他位置将鼠标设为默认的样式
EyeaxMapControl2.MousePointer = esriControlsMousePointer.esriPointerDefault;
}
if (bCanDrag)
{
double Dx, Dy; //记录鼠标移动的距离
Dx = e.mapX - pMoveRectPoint.X;
Dy = e.mapY - pMoveRectPoint.Y;
pEnv.Offset(Dx, Dy); //根据偏移量更改 pEnv 位置
pMoveRectPoint.PutCoords(e.mapX, e.mapY);
DrawRectangle(pEnv);
axMapControl1.Extent = pEnv;
}
}
private void EyeaxMapControl2_OnMouseUp(object sender, IMapControlEvents2_OnMouseUpEvent e)
{
if (e.button == 1 && pMoveRectPoint != null)
{
if (e.mapX == pMoveRectPoint.X && e.mapY == pMoveRectPoint.Y)
{
axMapControl1.CenterAt(pMoveRectPoint);
}
bCanDrag = false;
}
}
#endregion
private void button2_Click(object sender, EventArgs e)
{
SceneSelectByAttributes frms = new SceneSelectByAttributes();
frms.showForm(axSceneControl1);
}
}
}
好例子网口号:伸出你的我的手 — 分享!
小贴士
感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。
- 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
- 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
- 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
- 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。
关于好例子网
本站旨在为广大IT学习爱好者提供一个非营利性互相学习交流分享平台。本站所有资源都可以被免费获取学习研究。本站资源来自网友分享,对搜索内容的合法性不具有预见性、识别性、控制性,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,平台无法对用户传输的作品、信息、内容的权属或合法性、安全性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论平台是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二与二十三条之规定,若资源存在侵权或相关问题请联系本站客服人员,点此联系我们。关于更多版权及免责申明参见 版权及免责申明


网友评论
我要评论