标题:新手求- C# 地图显示
只看楼主
lru52777
Rank: 1
来 自:江苏
等 级:新手上路
帖 子:26
专家分:0
注 册:2011-6-7
得分:0 
回复 20楼 qq1023569223
哦,是MapInfo,嘿嘿。。。MapX,想替换成MapXtreme,可是代码太多了,无从下手。。。
2011-06-11 10:17
dwwwing
Rank: 8Rank: 8
等 级:蝙蝠侠
威 望:1
帖 子:284
专家分:986
注 册:2008-10-11
得分:0 
回复 21楼 lru52777
要运行程序才能看的到的。
2011-06-12 19:23
lru52777
Rank: 1
来 自:江苏
等 级:新手上路
帖 子:26
专家分:0
注 册:2011-6-7
得分:0 
怎么结贴了?我还没解决问题呢。。。
2011-06-15 13:05
qq1023569223
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
来 自:湖南科技大学
等 级:贵宾
威 望:26
帖 子:2753
专家分:13404
注 册:2010-12-22
得分:0 
哎,这种东西本来就难学!

   唯实惟新 至诚致志
2011-06-16 11:34
qq1023569223
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
来 自:湖南科技大学
等 级:贵宾
威 望:26
帖 子:2753
专家分:13404
注 册:2010-12-22
得分:0 
程序代码:
using System;
using System.Collections.Generic;
using using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
//using 
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Controls;
using ESRI.ArcGIS.esriSystem;
using ESRI.ArcGIS.Geometry;
using ESRI.ArcGIS.Display;
using ESRI.ArcGIS.SystemUI;
//看这AE编程,看了一下午的接口,晕了
namespace AE1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        //窗体载入
        private void Form1_Load(object sender, EventArgs e)
        {
            this.axToolbarControl1.SetBuddyControl(this.axMapControl1);
            this.axTOCControl1.SetBuddyControl(this.axMapControl1);
            this.axTOCControl1.ContextMenuStrip = this.lymean;
            this.axMapControl1.ContextMenuStrip = this.mapmeau;
          
            this.axToolbarControl1.AddItem("esriControlTools.ControlsMapNavigationToolBar");
          
            string s=@"C:\Documents and Settings\Administrator\桌面\0810050225\控制网\地图文档\ctNet.mxd";

            if (this.axMapControl1.CheckMxFile(s))
            {
                this.axMapControl1.LoadMxFile(s);
                this.axMapControl1.Extent = this.axMapControl1.FullExtent;
              
                this.Text = (s);
            }
            else
            {
                MessageBox.Show("Wrong!");
            }
        }
        //右击显示菜单
        private void axTOCControl1_OnMouseDown(object sender, ESRI.ArcGIS.Controls.ITOCControlEvents_OnMouseDownEvent e)
        {
            if (e.button==2)
            {
                this.lymean.Show(MousePosition.X,MousePosition.Y);
            }
        }
        //添加图层
        private void t1_Click(object sender, EventArgs e)
        {
            OpenFileDialog of = new OpenFileDialog();
            of.Title = "添加图层";
            of.Filter = "图层文件(*.shp,*.lyr)|*.shp|*.lyr|";
            of.Multiselect = true;

            if( of.ShowDialog()==DialogResult.OK)
            {
               string[] file = of.FileNames;
               for (int i = 0; i < file.Length; i++)
               {
                  try
                  {
                      if ((file[i]).CompareTo(".shp")==0)
                      {
                          this.axMapControl1.AddShapeFile((file[i]),(file[i]));
                      }
                      else
                      {
                          this.axMapControl1.AddLayerFromFile(file[i]);
                      }
                  }
                  catch
                  {
                    MessageBox.Show("无法加载" + file[i]);
                  }
               }
            }
        }
        //删除第一个图层
        private void t2_Click(object sender, EventArgs e)
        {
            if (this.axMapControl1.LayerCount > 0)
            {
                if (MessageBox.Show("确定删除图层?", "确认操作", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    this.axMapControl1.DeleteLayer(0);
                }
            }
        }
        //保存mxd文档
        private void t4_Click(object sender, EventArgs e)
        {
            SaveFileDialog sd = new SaveFileDialog();
            sd.DefaultExt = ".mxd";
            sd.InitialDirectory = Application.StartupPath;
            sd.RestoreDirectory = true;
            sd.FileName = "new";

            if (sd.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    IMapDocument mapdocumet = new MapDocumentClass();
                    mapdocumet.Save(mapdocumet.UsesRelativePaths, true);
                }
                catch (Exception o)
                {
                    MessageBox.Show(o.Message);
                }
            }
        }
        //最后一个图层移到第一个
        private void t5_Click(object sender, EventArgs e)
        {
            if (this.axMapControl1.LayerCount > 0)
            {
                this.axMapControl1.MoveLayerTo(this.axMapControl1.LayerCount - 1, 0);
            }
        }

        private void axMapControl1_OnMouseDown(object sender, IMapControlEvents2_OnMouseDownEvent e)
        {
            if (e.button == 2)
            {
                this.mapmeau.Show(MousePosition.X, MousePosition.Y);
            }
        }

        private void drawLine_Click(object sender, EventArgs e)
        {
            IPoint p = new PointClass();
            p.X = MousePosition.X;
            p.Y = MousePosition.Y;
            IGeometry pgeo = p as IGeometry;
            IRgbColor pcolor = new RgbColorClass();
            pcolor.Red = 0;
            pcolor.Green = 0;
            pcolor.Blue = 0;
            object symbol = null;

            ITextSymbol ts = new TextSymbolClass();
            ts.Color = pcolor;
            symbol = ts;

            this.axMapControl1.MousePointer = esriControlsMousePointer.esriPointerCrosshair;
            this.axMapControl1.DrawText(pgeo, "写文字", ref symbol);
            //this.axMapControl1.Refresh(esriViewDrawPhase.esriViewGeography, null, null);
        }
    }
}

   唯实惟新 至诚致志
2011-06-21 11:30



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-342123-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.074850 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved