大家好,又见面了,我是你们的朋友全栈君。
ArcGIS二次开发基础教程(02):地图导航和鹰眼
地图导航(主要是调用命令和工具)
- 地图的放缩和漫游
if(axMapControl1.CurrentTool == null)
{
ICommand icc;
//地图放大
ITool tool = new ControlsMapZoomInToolClass();
//地图缩小
//ITool tool = new ControlsMapZoomOutToolClass();
//地图漫游
//ITool tool = new ControlsMapPanToolClass();
icc = tool as ICommand;
icc.OnCreate(axMapControl1.Object);//钩子函数
icc.OnClick();
}
-
全局地图
ICommand icc = new ControlsFullExtentCommandClass(); icc.OnCreate(axMapControl1.Object); icc.OnClick();
鹰眼
//注意:只有从mxd文件中加载图层鹰眼才会出现 axMapControl1是主地图 axMapControl2为鹰眼图
private void axMapControl1_OnMapReplaced(object sender, IMapControlEvents2_OnMapReplacedEvent e)
{
axMapControl2.Map.ClearLayer();
if(axMapControl1.LayerCount>0)
{
//从下往上获取图层添加到鹰眼图中防止覆盖
for(int i= axMapControl1.LayerCount-1;i>=0;i--)
{
ILayer layer = axMapControl1.get_Layer(i);
IObjectCopy copy = new ObjectCopyClass();
ILayer myLayer = copy.Copy(layer) as ILayer;
axMapControl2.AddLayer(layer);
}
//设置相同的空间参考
axMapControl2.SpatialReferencr = axMapControl1.SpatialReference;
//鹰眼图的全局为主地图的当前视图
axMapControl2.FullExtent = axMapControl1.Extent;
//每次主地图图层增减都刷新
axMapControl2.Refresh();
}
}
//当主地图变化时,鹰眼图框变化
private void axMapControl2_OnExtentUpdated(object sender, IMapControlEvents2_OnExtentUpdatedEvent e)
{
//创建一个矩形元素并转换为元素
IElement ele = new RectangleElementClass() as IElement;
//获取主地图的视图
IEenvlop env = axMapControl1.Extent;
ele.Geometry = env as IGeometry;
//外轮廓线
ISimpleLineSymbol lineSymbol = new SimpleLineSymbolClass();
IRGBColor color1 = new RGBColorClass();
color1.Red = 255;
color1.Green = 0;
color1.Blue = 0;
//透明度为255即不透明
color1.Tranparency = 255;
lineSymbol.Color= color1;
lineSymbol.Width = 2;
ISimpleFillSymbol fillSymbol = new SimpleFillSymbolClass();
IRGBColor color2 = new RGBColorClass();
color2.Red = 255;
color2.Green = 0;
color2.Blue = 0;
//透明度为0即完全透明
color2.Tranparency = 0;
fillSymbol.Color = color2;
fillSymbol.Outline = lineSymbol;
//实现线框的生成
IFillShapeElement fillShapeElement = ele as IFillShapeElement;
fillShapeElement.Symbol = fillSymbol;
//图形容器
IGraphicsContainer graphicsContainer = axMapControl2.Map as IGraphicsContainer;
//删掉以前的元素
graphicsContainer.DeleteAllElements();
//添加新元素
graphicsContainer.AddElement(fillShapeElement as IElement);
axMapControl2.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
}
//鹰眼图的鼠标点击事件
private void axMapControl2_OnMouseDown(object sender, IMapControlEvents2_OnMouseDownEvent e)
{
if(e.Button == 1)
{
//将主地图视图中心移到点击处
IPoint point = new PointClass();
point.PutCoords(e.mapX,e.mapY);
axMapControl1.CenterAt(point);
axMapControl1.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
}
else
{
//将主地图视图变为从鹰眼图获取的轨迹矩形
IEnvelop env = axMapControl2.TrackRectangle;
axMapCOntrol1.Extent = env;
axMapControl1.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
}
}
//鹰眼图的鼠标移动事件
private void axMapControl2_OnMouseMove(object sender, IMapControlEvents2_OnMouseMoveEvent e)
{
if(e.Button == 1)
{
IPoint point = new PointClass();
point.PutCoords(e.mapX,e.mapY);
axMapControl1.CenterAt(point);
axMapControl1.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
}
}
鹰眼效果:
发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/163452.html原文链接:https://javaforall.cn
【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛
【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...