Beispiel #1
0
        //在OnAfterScreenDraw事件下使用
        public static void Use_OnAfterScreenDraw(AxMapControl mapControl, AxPageLayoutControl axPageLayoutControl)
        {
            IActiveView            pActiveView           = axPageLayoutControl.ActiveView.FocusMap as IActiveView;
            IDisplayTransformation displayTransformation = pActiveView.ScreenDisplay.DisplayTransformation;

            displayTransformation.VisibleBounds = mapControl.Extent;
            axPageLayoutControl.ActiveView.Refresh();
            OperateFile.CopyAndOverwriteMap(mapControl, axPageLayoutControl);
        }
Beispiel #2
0
        //打开文件函数
        public static void OpenFile(AxMapControl mapControl, AxPageLayoutControl pageLayoutControl)
        {
            OpenFileDialog OpenFdlg = new OpenFileDialog();

            OpenFdlg.Title            = "选择需要加载的地理数据文件";
            OpenFdlg.Filter           = "mxd文件|*.mxd|Shape文件|*.shp|所有文件|*.*";
            OpenFdlg.RestoreDirectory = true;

            if (OpenFdlg.ShowDialog() == DialogResult.OK)
            {
                string strFileName = OpenFdlg.FileName;//完全名
                if (strFileName == string.Empty)
                {
                    return;
                }
                string pathName    = System.IO.Path.GetDirectoryName(strFileName);            //位置
                string strFExtendN = System.IO.Path.GetExtension(strFileName);                //后缀名
                string fileName    = System.IO.Path.GetFileNameWithoutExtension(strFileName); //单独的文件名
                string fileNameE   = System.IO.Path.GetFileName(strFileName);                 //文件名和扩展名
                switch (strFExtendN)
                {
                case ".shp":
                    mapControl.AddShapeFile(pathName, fileName);
                    OperateFile.CopyAndOverwriteMap(mapControl, pageLayoutControl);
                    break;

                case ".mxd":
                    if (mapControl.CheckMxFile(strFileName))
                    {
                        mapControl.MousePointer = esriControlsMousePointer.esriPointerHourglass;
                        mapControl.LoadMxFile(strFileName, 0, Type.Missing);
                        mapControl.MousePointer = esriControlsMousePointer.esriPointerDefault;
                        OperateFile.CopyAndOverwriteMap(mapControl, pageLayoutControl);
                    }
                    else
                    {
                        MessageBox.Show("所选文件不是地图文档文件!", "信息提示");
                        return;
                    }
                    break;

                case ".bmp":
                case ".BMP":
                case ".tif":
                case ".TIF":
                case ".jpg":
                case ".JPG":
                case ".img":
                case ".IMG":
                case ".png":
                case ".PNG":
                    IWorkspaceFactory pWSF;
                    pWSF = new RasterWorkspaceFactory();
                    IWorkspace pWS;
                    pWS = pWSF.OpenFromFile(pathName, 0);
                    IRasterWorkspace pRWS;
                    pRWS = pWS as IRasterWorkspace;
                    IRasterDataset pRasterDataset;
                    pRasterDataset = pRWS.OpenRasterDataset(fileNameE);
                    //影像金字塔判断与创建
                    IRasterPyramid pRasPyrmid;
                    pRasPyrmid = pRasterDataset as IRasterDataset as IRasterPyramid;
                    if (pRasPyrmid != null)
                    {
                        if (!(pRasPyrmid.Present))
                        {
                            pRasPyrmid.Create();    //在进度条中说明正在创建金字塔
                        }
                    }
                    IRaster pRaster;
                    pRaster = pRasterDataset.CreateDefaultRaster();
                    IRasterLayer pRasterLayer;
                    pRasterLayer = new RasterLayerClass();
                    pRasterLayer.CreateFromRaster(pRaster);
                    ILayer pLayer = pRasterLayer as ILayer;
                    mapControl.AddLayer(pLayer, 0);
                    OperateFile.CopyAndOverwriteMap(mapControl, pageLayoutControl);
                    //OperateFile.ArchieveEagleEyeWhenAddRaster(mapControl, strFileName);
                    break;
                }
            }
        }
Beispiel #3
0
 //在OnviewRfeshed事件下使用(联动)
 public static void Use_OnViewRefreshed(AxTOCControl toccControl, AxMapControl mapControl, AxPageLayoutControl axPageLayoutControl)
 {
     toccControl.Update();
     OperateFile.CopyAndOverwriteMap(mapControl, axPageLayoutControl);
 }