



private void AddLayerLoad_Click(object sender, EventArgs e)
{
//此处的路径改为自己电脑上Continents.lyr的位置
String lyrPath = @"D:\Program Files (x86)\ArcGIS\DeveloperKit10.2\Samples\data\World\Continents.lyr";
MapDocument mapDoc = new MapDocument();
mapDoc.Open(lyrPath);
//获取第一个地图的第一个图层
ILayer pLyr = mapDoc.get_Layer(0, 0);
axMapControl1.AddLayer(pLyr);
}
调试运行,出现下列画面:
双击‘通过AddLayerFromFile加载’,增加代码:
private void AddLayerFromFileLoad_Click(object sender, EventArgs e)
{
string lyrPath = @"D:\Program Files (x86)\ArcGIS\DeveloperKit10.2\Samples\data\World\Continents.lyr";
axMapControl1.AddLayerFromFile(lyrPath);
}
调试运行后,点击‘通过AddLayerFromFile加载’,画面如下,和上一个做法效果一样:
双击‘通过AddShapeFile加载’,增加代码:
private void AddShapeFileLoad_Click(object sender, EventArgs e)
{
string shpPath = @"D:\Program Files (x86)\ArcGIS\DeveloperKit10.2\Samples\data\World";
axMapControl1.AddShapeFile(shpPath, "World30.shp");
}
调试运行后,点击‘通过AddShapeFile加载’,结果如下:
private void DialogAddLayer_Click(object sender, EventArgs e)
{
OpenFileDialog opFDialog = new OpenFileDialog();
opFDialog.Title = "请选择图层";
opFDialog.Filter = "layers(*.lyr)|*.lyr";
if (opFDialog.ShowDialog() == DialogResult.OK)
{
string lyrPath = opFDialog.FileName;
axMapControl1.AddLayerFromFile(lyrPath);
}
}
双击‘加载ShapeFile’,增加代码:
private void DialogAddShapeFile_Click(object sender, EventArgs e)
{
OpenFileDialog opFDialog = new OpenFileDialog();
opFDialog.Title = "请选择Shapefile";
opFDialog.Filter = "Shapefile(*.shp)|*.shp";
if (opFDialog.ShowDialog() == DialogResult.OK)
{
string shpPath = opFDialog.FileName;
string filePath = System.IO.Path.GetDirectoryName(shpPath);
string fileName = System.IO.Path.GetFileNameWithoutExtension(shpPath);
axMapControl1.AddShapeFile(filePath, fileName);
}
双击‘加载地图文档’,增加代码:
private void DialogAddmxd_Click(object sender, EventArgs e)
{
OpenFileDialog opFDialog = new OpenFileDialog();
opFDialog.Title = "请选择地图文档";
//'|'前的文字是选择对话框的提示文字,后面是格式(后缀)过滤,每个格式用';'分开
opFDialog.Filter = "Map Document(*.mxd;*.pmf;*.mxt)|*.mxd;*.pmf;*.mxt";
if (opFDialog.ShowDialog() == DialogResult.OK)
{
string mxPath = opFDialog.FileName;
axMapControl1.LoadMxFile(mxPath);
}
}
运行调试,依次点击‘加载layer图层’、‘加载ShapeFile’、‘加载地图文档’,结果依次为:
上一节:一、AE+C#之可视化组件
网友评论