加载地图,加载shp文件和鹰眼图功能

//加载.mxd地图文件
private void button1_Click(object sender, EventArgs e)
{
   OpenFileDialog openMXD = new OpenFileDialog();
   openMXD.Title = "open map";
   openMXD.InitialDirectory = "F:";
   openMXD.Filter = "map document(*.mxd)|*.mxd";
   if (openMXD.ShowDialog() == DialogResult.OK)
   {
       string MxdPath = openMXD.FileName;
       axMapControl1.LoadMxFile(MxdPath);
   }
}

//加载shp文件
private void button2_Click(object sender, EventArgs e)
{

  OpenFileDialog openShpFile = new OpenFileDialog();
  openShpFile.Title = "open shape file";
  openShpFile.Filter = "shape file(*.shp)|*.shp";
  if (openShpFile.ShowDialog() == DialogResult.OK)
  {
      FileInfo fileInfo = new FileInfo(openShpFile.FileName);
      string path = fileInfo.Directory.ToString();
      string fileName = fileInfo.Name.Substring(0, fileInfo.Name.IndexOf("."));
      axMapControl1.AddShapeFile(path, fileName);

  }
}

//实现鹰眼图功能
private void axMapControl1_OnExtentUpdated(object sender,IMapControlEvents2_OnExtentUpdatedEvent e)
{

    IEnvelope pEnvelope = (IEnvelope)e.newEnvelope;
    IGraphicsContainer pGraphicsContainer = axMapControl2.Map as IGraphicsContainer;
    IActiveView pActiveView = pGraphicsContainer as IActiveView;

    pGraphicsContainer.DeleteAllElements();
    IRectangleElement pRectangleEle = new RectangleElementClass();
    IElement pElement = pRectangleEle as IElement;
    pElement.Geometry = pEnvelope;

    IRgbColor pColor = new RgbColorClass();
    pColor.RGB = 255;
    pColor.Transparency = 255;

    ILineSymbol pOutline = new SimpleLineSymbolClass();
    pOutline.Width = 3;
    pOutline.Color = pColor;

    pColor = new RgbColorClass();
    pColor.RGB = 255;
    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 axMapControl1_OnMapReplaced(object sender, IMapControlEvents2_OnMapReplacedEvent e)
{
    IMap pMap = axMapControl1.Map;
    for (int i = 0; i < pMap.LayerCount; i++)
    {
        axMapControl2.Map.AddLayer(pMap.get_Layer(i));
    }
}

private void axMapControl2_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 axMapControl2_OnMouseDown(object sender, IMapControlEvents2_OnMouseDownEvent e)
{
    if (axMapControl2.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 = axMapControl2.TrackRectangle();
            axMapControl1.Extent = pEnv;
            axMapControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null);
        }
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值