arcgis engine二次开发学习01
学习内容:
- MAPCONTROL加载shap
- mapcontrol加载mxd
- mapcontrol的layercount属性
- mapcontrol 的getlayer的方法
- deletlayer方法
代码留存
MAPCONTROL加载shape
private void openShapefileToolStripMenuItem_Click(object sender, EventArgs e)
{
OpenFileDialog openfiledialog = new OpenFileDialog();
openfiledialog.Title = "加载shapefiles数据";
openfiledialog.Filter = "(*.shp)|*.shp";
if (openfiledialog.ShowDialog() == DialogResult.OK)
{
string fullpath = openfiledialog.FileName;
string path = fullpath.Substring(0, fullpath.LastIndexOf("\\"));
string name = fullpath.Substring(fullpath.LastIndexOf("\\") + 1);
MAINMapControl.AddShapeFile(path, name);
MAINMapControl.Refresh();
MessageBox.Show("文件加载成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
mapcontrol加载mxd
private void openMxdToolStripMenuItem_Click(object sender, EventArgs e)
{
OpenFileDialog openfiledialog = new OpenFileDialog();
openfiledialog.Title = "加载mxd数据";
openfiledialog.Filter = "(*.mxd)|*.mxd";
if (openfiledialog.ShowDialog() == DialogResult.OK)
{
string fullpath = openfiledialog.FileName;
//string path = fullpath.Substring(0, fullpath.LastIndexOf("\\"));
// string name = fullpath.Substring(fullpath.LastIndexOf("\\") + 1);
MAINMapControl.LoadMxFile(fullpath);
MAINMapControl.Refresh();
MessageBox.Show("文件加载成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
mapcontrol的layercount属性
private void 获取图层数量ToolStripMenuItem_Click(object sender, EventArgs e)
{
textBoxlayer.Text = MAINMapControl.LayerCount.ToString();
}
mapcontrol 的get_layer的方法
private void 获取图层名称ToolStripMenuItem_Click(object sender, EventArgs e)
{
int index = Convert.ToInt32(textBoxlayer.Text);
ILayer layer = MAINMapControl.get_Layer(index);
textBoxlayer.Text = layer.Name;
}
private void 获取图层序号ToolStripMenuItem_Click(object sender, EventArgs e)
{
for (int i = 0; i < MAINMapControl.LayerCount; i++)
{
if (MAINMapControl.get_Layer(i).Name == textBoxlayer.Text)
{
textBoxlayer.Text = i.ToString();
break;
}
}
}
deletlayer方法
private void 删除图层ToolStripMenuItem_Click(object sender, EventArgs e)
{
int index = Convert.ToInt32(textBoxlayer.Text);
MAINMapControl.DeleteLayer(index);
}
private void 清除数据ToolStripMenuItem_Click(object sender, EventArgs e)
{
int layerCount = MAINMapControl.LayerCount;
for (int i = 0; i < layerCount; i++)
{
MAINMapControl.DeleteLayer(0);
}
}