arcengine二次开发——景点信息介绍

arcengine二次开发,今天写一个功能吧~学完大家去试试~

实现的结果先附上:

先简单介绍一下窗体:

代码如下:

using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Controls;
using ESRI.ArcGIS.Geodatabase;
using ESRI.ArcGIS.Geometry;
using ESRI.ArcGIS.SystemUI;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace XXXX //改成你自己的项目名
{
    public partial class SpotInformation : Form
    {
        private AxMapControl _axMapControl;
        public SpotInformation(AxMapControl axMapControl1)
        {
            _axMapControl = axMapControl1;
            InitializeComponent();
        }

        private void SpotInformation_Load(object sender, EventArgs e)
        {
            My_Conbobox();
        }

        private void My_Conbobox()
        {
            //throw new NotImplementedException();
        }

        public static void ZoomToGeometry(ESRI.ArcGIS.Geometry.IGeometry geometry, IActiveView activeView)
        {
            IEnvelope env = geometry.Envelope;
            IGeometry5 geo = geometry as IGeometry5;

            if (env.Width == 0 || env.Height == 0)
            {
                IPoint centerPoint = new PointClass();
                centerPoint.X = geo.CentroidEx.X;
                centerPoint.Y = geo.CentroidEx.Y;

                //IDisplayTransformation displayTrans = activeView.ScreenDisplay.DisplayTransformation;
                //displayTrans.SpatialReference = activeView.FocusMap.SpatialReference;

                env.XMin = centerPoint.X - 50;
                env.XMax = centerPoint.X + 50;
                env.YMin = centerPoint.Y - 50;
                env.YMax = centerPoint.Y + 50;

                env.CenterAt(centerPoint);
            }
            env.Expand(3, 3, true);
            activeView.Extent = env;
            activeView.Refresh();
            activeView.ScreenDisplay.UpdateWindow();
        }

        //private IFeatureLayer mFeatureLayer;
        private void button1_Click(object sender, EventArgs e)
        {//“确认”按钮实现的功能【查询地点位置并缩放到该地点】
            string text = listBox1.Text.Trim();
            IFeatureLayer pFeatureLayer = _axMapControl.get_Layer(15) as IFeatureLayer;//“15”通常也要改,看你自己的图层属于第几层,改上去就行
            
            IQueryFilter queryFilter = new QueryFilterClass();
       
            queryFilter.WhereClause = "Name='" + text + "'";//这一句通常也要改,文章后面会讲解
          
            try
            {
                IFeatureCursor featureCursor = pFeatureLayer.Search(queryFilter, false);
                IFeature pFeature;
                while ((pFeature = featureCursor.NextFeature()) != null)
                {
                    ZoomToGeometry(pFeature.Shape, _axMapControl.ActiveView);
                    _axMapControl.FlashShape(pFeature.Shape);
                }
            }
            catch (Exception pException)
            {
                MessageBox.Show(pException.Message);
            }
            switch (text)
            {
                case "龙水峡地缝":
                    richTextBox1.Text = "龙水峡地缝是全长4公里的泉水流瀑挂壁险峻幽深,怪石峥嵘,在 武隆区 仙女山镇境内。 龙水峡地缝设有80米瀑布水帘,奇哉妙哉。";
                    this.pictureBox1.ImageLocation = "https://youimg1.c-ctrip.com/target/100c12000000rvdpx30D5.jpg";
                    break;
                    
                case "仙女山国家森林公园":
                    richTextBox1.Text = "仙女山国家森林公园是国家AAAAA级景区,位于 重庆市 武隆区 境,总面积8910公顷,平均海拔1900米,最高峰2033米,以其江南独具魅力的高山草原、南国罕见的林海雪原、青幽秀美的丛林碧野景观而誉为“东方瑞士”。";
                    this.pictureBox1.ImageLocation = "http://qnimg.zowoyoo.com/img/965122/1582530416519.jpg";
                    //string url = "http://qnimg.zowoyoo.com/img/965122/1582530416519.jpg";
                    //this.pictureBox1.Image = Image.FromStream(System.Net.WebRequest.Create(url).GetResponse().GetResponseStream());
                    break;
                case "XXX"://这些XXX的地方改成自己的数据,上面两个是示范
                    richTextBox1.Text = "XXX";
                    this.pictureBox1.ImageLocation = "XXX";
                    break;
            };
        }

        private void button2_Click(object sender, EventArgs e)
        {//“刷新”按钮实现的功能
            this.listBox1.Items.Clear();   
            listBox1.Items.Clear();   
            listBox1.Items.Add("仙女山国家森林公园");
            listBox1.Items.Add("XXX");//填自己的数据
            listBox1.Refresh();
        }

        private void button4_Click(object sender, EventArgs e)
        {//“关闭”按钮实现的功能【关闭信息窗口】
            this.Close();
        }
    }
}

讲解一下这句代码吧,毕竟我当时也是移植的别人的代码,改了很久才发现问题所在:

最开始没有修改的时候会报一个这样的错误:

那个“Name”指的是你该图层的一个字段名,如图所示:

写该功能时,图层名也最好改成中文吧。

  • 3
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

每天都是被迫学习

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值