|
|
|
|
using ESRI.ArcGIS.Carto;
|
|
|
|
|
using ESRI.ArcGIS.Controls;
|
|
|
|
|
using ESRI.ArcGIS.Display;
|
|
|
|
|
using ESRI.ArcGIS.Geometry;
|
|
|
|
|
using KGIS.Framework.Maps;
|
|
|
|
|
using KGIS.Framework.Utils.Helper;
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
namespace Kingo.Plugin.MapView
|
|
|
|
|
{
|
|
|
|
|
public partial class UcAerialView : UserControl
|
|
|
|
|
{
|
|
|
|
|
AxMapControl axMapControl1 = null;
|
|
|
|
|
private bool initialZT = false;
|
|
|
|
|
public UcAerialView()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
//MapsManager.Instance.MapService.getAxMapControl().OnMapReplaced += UcAerialView_OnMapReplaced;
|
|
|
|
|
MapsManager.Instance.MapService.getAxMapControl().OnExtentUpdated += UcAerialView_OnExtentUpdated;
|
|
|
|
|
MapsManager.Instance.MapService.ProjectOpened += MapService_ProjectOpened;
|
|
|
|
|
MapsManager.Instance.MapService.ProjectClosed += MapService_ProjectClosed;
|
|
|
|
|
}
|
|
|
|
|
public void InitView(ILayer layer)
|
|
|
|
|
{
|
|
|
|
|
axMapControl1 = MapsManager.Instance.MapService.getAxMapControl() as AxMapControl;
|
|
|
|
|
if (axMapControl1.LayerCount > 0)
|
|
|
|
|
{
|
|
|
|
|
axMapControl.Map = new MapClass();
|
|
|
|
|
//for (int i = 0; i <= axMapControl1.Map.LayerCount - 1; i++)
|
|
|
|
|
//{
|
|
|
|
|
// axMapControl.AddLayer(axMapControl1.get_Layer(i));
|
|
|
|
|
//}
|
|
|
|
|
if ((layer as IFeatureLayer).Visible == false)
|
|
|
|
|
{
|
|
|
|
|
(layer as IFeatureLayer).Visible = true;
|
|
|
|
|
initialZT = true;
|
|
|
|
|
}
|
|
|
|
|
if (layer != null)
|
|
|
|
|
axMapControl.AddLayer(layer);
|
|
|
|
|
axMapControl.SpatialReference = axMapControl1.SpatialReference;
|
|
|
|
|
axMapControl.Extent = layer.AreaOfInterest;
|
|
|
|
|
axMapControl.Refresh();
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void MapService_ProjectClosed(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (axMapControl != null)
|
|
|
|
|
axMapControl.ClearLayers();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void MapService_ProjectOpened(object sender, KGIS.Framework.Maps.Handlers.ProjectArgs args)
|
|
|
|
|
{
|
|
|
|
|
if (axMapControl == null) return;
|
|
|
|
|
AxMapControl axMapControl1 = MapsManager.Instance.MapService.getAxMapControl() as AxMapControl;
|
|
|
|
|
if (axMapControl1.LayerCount > 0)
|
|
|
|
|
{
|
|
|
|
|
axMapControl.Map = new MapClass();
|
|
|
|
|
//for (int i = 0; i <= axMapControl1.Map.LayerCount - 1; i++)
|
|
|
|
|
//{
|
|
|
|
|
ILayer layer = MapsManager.Instance.MapService.GetFeatureLayerByLayerName("行政区");
|
|
|
|
|
if (layer != null)
|
|
|
|
|
axMapControl.AddLayer(layer);
|
|
|
|
|
//}
|
|
|
|
|
axMapControl.SpatialReference = axMapControl1.SpatialReference;
|
|
|
|
|
|
|
|
|
|
axMapControl.Extent = layer.AreaOfInterest;
|
|
|
|
|
axMapControl.Refresh();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Close(ILayer layer)
|
|
|
|
|
{
|
|
|
|
|
MapsManager.Instance.MapService.ProjectOpened -= MapService_ProjectOpened;
|
|
|
|
|
//MapsManager.Instance.MapService.getAxMapControl().OnMapReplaced -= UcAerialView_OnMapReplaced;
|
|
|
|
|
MapsManager.Instance.MapService.getAxMapControl().OnExtentUpdated -= UcAerialView_OnExtentUpdated;
|
|
|
|
|
if (initialZT == true) (layer as IFeatureLayer).Visible = false;
|
|
|
|
|
axMapControl.ClearLayers();
|
|
|
|
|
axMapControl.Dispose();
|
|
|
|
|
axMapControl = null;
|
|
|
|
|
this.Dispose();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void UcAerialView_OnExtentUpdated(object sender, IMapControlEvents2_OnExtentUpdatedEvent e)
|
|
|
|
|
{
|
|
|
|
|
// 得到新范围
|
|
|
|
|
IEnvelope pEnvelope = (IEnvelope)e.newEnvelope;
|
|
|
|
|
|
|
|
|
|
IGraphicsContainer pGraphicsContainer = axMapControl.Map as IGraphicsContainer;
|
|
|
|
|
|
|
|
|
|
IActiveView pActiveView = pGraphicsContainer as IActiveView;
|
|
|
|
|
|
|
|
|
|
//在绘制前,清除axMapControl2中的任何图形元素
|
|
|
|
|
pGraphicsContainer.DeleteAllElements();
|
|
|
|
|
|
|
|
|
|
IRectangleElement pRectangleEle = new RectangleElementClass();
|
|
|
|
|
IElement pElement = pRectangleEle as IElement;
|
|
|
|
|
pElement.Geometry = pEnvelope;
|
|
|
|
|
|
|
|
|
|
//设置鹰眼图中的红线框
|
|
|
|
|
|
|
|
|
|
IRgbColor pColor = new RgbColorClass();
|
|
|
|
|
pColor.Red = 255;
|
|
|
|
|
pColor.Green = 0;
|
|
|
|
|
pColor.Blue = 0;
|
|
|
|
|
pColor.Transparency = 255;
|
|
|
|
|
|
|
|
|
|
//产生一个线符号对象
|
|
|
|
|
|
|
|
|
|
ILineSymbol pOutline = new SimpleLineSymbolClass();
|
|
|
|
|
pOutline.Width = 3;
|
|
|
|
|
pOutline.Color = pColor;
|
|
|
|
|
|
|
|
|
|
//设置颜色属性
|
|
|
|
|
|
|
|
|
|
pColor = new RgbColorClass();
|
|
|
|
|
pColor.Red = 255;
|
|
|
|
|
pColor.Green = 0;
|
|
|
|
|
pColor.Blue = 0;
|
|
|
|
|
pColor.Transparency = 0;
|
|
|
|
|
|
|
|
|
|
//设置填充符号的属性
|
|
|
|
|
|
|
|
|
|
IFillSymbol pFillSymbol = new SimpleFillSymbolClass();
|
|
|
|
|
pFillSymbol.Color = pColor;
|
|
|
|
|
pFillSymbol.Outline = pOutline;
|
|
|
|
|
IFillShapeElement pFillShapeEle = pElement as IFillShapeElement;
|
|
|
|
|
pFillShapeEle.Symbol = pFillSymbol;
|
|
|
|
|
pGraphicsContainer.AddElement((IElement)pFillShapeEle, 0);
|
|
|
|
|
|
|
|
|
|
pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//private void UcAerialView_OnMapReplaced(object sender, ESRI.ArcGIS.Controls.IMapControlEvents2_OnMapReplacedEvent e)
|
|
|
|
|
//{
|
|
|
|
|
// AxMapControl axMapControl1 = sender as AxMapControl;
|
|
|
|
|
// if (axMapControl1.LayerCount > 0)
|
|
|
|
|
// {
|
|
|
|
|
// axMapControl.Map = new MapClass();
|
|
|
|
|
// for (int i = 0; i <= axMapControl1.Map.LayerCount - 1; i++)
|
|
|
|
|
// {
|
|
|
|
|
// axMapControl.AddLayer(axMapControl1.get_Layer(i));
|
|
|
|
|
// }
|
|
|
|
|
// axMapControl.Extent = axMapControl1.Extent;
|
|
|
|
|
// axMapControl.Refresh();
|
|
|
|
|
// }
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
private void axMapControl_OnMouseMove(object sender, IMapControlEvents2_OnMouseMoveEvent e)
|
|
|
|
|
{
|
|
|
|
|
if (e.button == 1)
|
|
|
|
|
{
|
|
|
|
|
IPoint pPoint = new PointClass();
|
|
|
|
|
pPoint.PutCoords(e.mapX, e.mapY);
|
|
|
|
|
axMapControl1.CenterAt(pPoint);
|
|
|
|
|
axMapControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void axMapControl_OnMouseDown(object sender, IMapControlEvents2_OnMouseDownEvent e)
|
|
|
|
|
{
|
|
|
|
|
if (axMapControl.Map.LayerCount > 0)
|
|
|
|
|
{
|
|
|
|
|
if (e.button == 1)
|
|
|
|
|
{
|
|
|
|
|
IPoint pPoint = new PointClass();
|
|
|
|
|
pPoint.PutCoords(e.mapX, e.mapY);
|
|
|
|
|
axMapControl1.CenterAt(pPoint);
|
|
|
|
|
axMapControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null);
|
|
|
|
|
}
|
|
|
|
|
else if (e.button == 2)
|
|
|
|
|
{
|
|
|
|
|
IEnvelope pEnv = axMapControl.TrackRectangle();
|
|
|
|
|
axMapControl1.Extent = pEnv;
|
|
|
|
|
axMapControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|