打开地图文件
方法一:地图控件加载文件路径
在界面上已经添加地图控件的情况下,将地府文件路径加载至地图控件上
public static bool OpenMapFile(AxMapControl mapcontrol)
{
OpenFileDialog fileDialog = new OpenFileDialog();
fileDialog.Filter = "地图文档(*.mxd)|*.mxd";
if (fileDialog.ShowDialog()==DialogResult.OK)
{
string filePath = fileDialog.FileName;
if (mapcontrol.CheckMxFile(filePath))
{
mapcontrol.ClearLayers();
mapcontrol.LoadMxFile(filePath);
}
}
return false;
}
方法二:通过MapDocument打开且关联至地图控件
public static bool OpenMapFile(AxMapControl mapcontrol)
{
OpenFileDialog fileDialog = new OpenFileDialog();
fileDialog.Filter = "地图文档(*.mxd)|*.mxd";
if (fileDialog.ShowDialog() == DialogResult.OK)
{
string filePath = fileDialog.FileName;
if (mapcontrol.CheckMxFile(filePath))
{
IMapDocument mapDoc = new MapDocumentClass();
mapDoc.Open(filePath,"");
mapcontrol.Map = mapDoc.ActiveView.FocusMap;
mapcontrol.ActiveView.Refresh();
}
}
方法三:ArcGis 已经封装好的ControlsOpenDocCommandClass
public static void OpenMapFile(AxMapControl mapcontrol)
{
ICommand command = new ControlsOpenDocCommandClass();
command.OnCreate(mapcontrol.Object);
command.OnClick();
}