0
点赞
收藏
分享

微信扫一扫

arcgis engine二次开发学习01

Soy丶sauce 2022-03-26 阅读 56

arcgis engine二次开发学习01

学习内容:

  1. MAPCONTROL加载shap
  2. mapcontrol加载mxd
  3. mapcontrol的layercount属性
  4. mapcontrol 的getlayer的方法
  5. 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);
            }
        }
举报

相关推荐

0 条评论