• 4.AE中的缩放,书签


    1.书签

    private void textBox1_TextChanged(object sender, EventArgs e)
    {
    if (txtBookmark.Text == "")
    {
    button1.Enabled = false;
    }
    else
    {
    button1.Enabled = true;
    }
    }

    //确定
    private void button1_Click(object sender, EventArgs e)
    {
    m_bookmark = txtBookmark.Text;
    txtBookmark.Text = "";
    m_check = 1;
    this.Close();
    }

    //取消
    private void button2_Click(object sender, EventArgs e)
    {
    txtBookmark.Text = "";
    m_check = 0;
    this.Close();
    }

    具体源码

    namespace WindowsFormsApplication1
    {
    public partial class FrmBookmark : Form
    {
    private string m_bookmark; //书签名
    private int m_check; //是否创建书签
    public FrmBookmark()
    {
    InitializeComponent();
    }

    private void textBox1_TextChanged(object sender, EventArgs e)
    {
    if (txtBookmark.Text == "")
    {
    button1.Enabled = false;
    }
    else
    {
    button1.Enabled = true;
    }
    }
    //设置书签名为只读
    public string Bookmark
    {
    get { return m_bookmark; }
    }

    //是否创建书签变量为只读
    public int Check
    {
    get { return m_check; }
    }
    //确定
    private void button1_Click(object sender, EventArgs e)
    {
    m_bookmark = txtBookmark.Text;
    txtBookmark.Text = "";
    m_check = 1;
    this.Close();
    }
    //取消
    private void button2_Click(object sender, EventArgs e)
    {
    txtBookmark.Text = "";
    m_check = 0;
    this.Close();
    }

    }

    #region 添加书签
    private void barButtonItem12_ItemClick(object sender, ItemClickEventArgs e)
    {
    //ICommand pCmmd;
    //ITool pTool;
    FrmBookmark frmBookMark = new FrmBookmark();
    frmBookMark.ShowDialog();
    string pName = string.Empty;
    int check = frmBookMark.Check;

    if (check == 1)
    {
    pName = frmBookMark.Bookmark;
    }
    if (string.IsNullOrEmpty(pName)) return;

    //书签进行重名判断
    IMapBookmarks mapBookmarks = axMapControl1.Map as IMapBookmarks;
    IEnumSpatialBookmark enumSpatialBookmarks = mapBookmarks.Bookmarks;
    enumSpatialBookmarks.Reset();
    ISpatialBookmark pSpatialBookmark;

    while ((pSpatialBookmark = enumSpatialBookmarks.Next()) != null)
    {
    if (pName == pSpatialBookmark.Name)
    {
    DialogResult dr = MessageBox.Show("此书签名已存在!是否替换?", "提示", MessageBoxButtons.YesNoCancel);
    if (dr == DialogResult.Yes)
    {
    mapBookmarks.RemoveBookmark(pSpatialBookmark);
    }
    else if (dr == DialogResult.No)
    {
    frmBookMark.ShowDialog();
    }
    else
    {
    return;
    }
    }
    }

    //获取当前地图的对象
    IActiveView pActiveView = axMapControl1.Map as IActiveView;
    //创建一个新的书签并设置其位置范围为当前视图的范围
    IAOIBookmark pBookmark = new AOIBookmarkClass();
    pBookmark.Location = pActiveView.Extent;
    //获得书签名
    pBookmark.Name = pName;
    //通过IMapBookmarks接口访问当前地图书签集,添加书签到地图的书签集中
    IMapBookmarks pMapBookmarks = axMapControl1.Map as IMapBookmarks;
    pMapBookmarks.AddBookmark(pBookmark);

    }
    #endregion

    2.管理书签

    具体源码

    namespace WindowsFormsApplication1
    {
    public partial class FrmManageBookmark : Form
    {
    private IMap _currentMap = null;
    Dictionary<string, ISpatialBookmark> pDictionary = new Dictionary<string, ISpatialBookmark>();
    IMapBookmarks mapBookmarks = null;
    public FrmManageBookmark(IMap pMap)
    {
    InitializeComponent();
    _currentMap = pMap; //获取当前地图
    InitControl();
    }

    //获取空间书签,对tlstBookMark进行初始化
    private void InitControl()
    {
    mapBookmarks = _currentMap as IMapBookmarks;
    IEnumSpatialBookmark enumSpatialBookmarks = mapBookmarks.Bookmarks;
    enumSpatialBookmarks.Reset();
    ISpatialBookmark pSpatialBookmark = enumSpatialBookmarks.Next();

    string sBookMarkName = string.Empty;
    while (pSpatialBookmark != null)
    {
    sBookMarkName = pSpatialBookmark.Name;
    //增加树节点
    treeView1.Nodes.Add(sBookMarkName);
    //添加到数据字典
    pDictionary.Add(sBookMarkName, pSpatialBookmark);
    pSpatialBookmark = enumSpatialBookmarks.Next();
    }
    }
    public FrmManageBookmark()
    {
    InitializeComponent();
    }
    //定位
    private void button1_Click(object sender, EventArgs e)
    {
    TreeNode pSelectedNode = treeView1.SelectedNode;
    //获得选中的书签对象
    ISpatialBookmark pSpatialBM = pDictionary[pSelectedNode.Text];
    //缩放到选中书签的视图范围
    pSpatialBM.ZoomTo(_currentMap);
    IActiveView pActiveView = _currentMap as IActiveView;
    pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null);
    }
    //删除书签
    private void button2_Click(object sender, EventArgs e)
    {
    TreeNode pSelectedNode = treeView1.SelectedNode;
    ISpatialBookmark pSpatialBookmark = pDictionary[pSelectedNode.Text];
    //删除选中的书签对象
    mapBookmarks.RemoveBookmark(pSpatialBookmark);
    //删除字典中数据
    pDictionary.Remove(pSelectedNode.Text);
    //删除树节点
    treeView1.Nodes.Remove(pSelectedNode);
    treeView1.Refresh();
    }

    private void button3_Click(object sender, EventArgs e)
    {
    Close();
    }
    private void tlstBookMark_MouseDoubleClick(object sender, MouseEventArgs e)
    {
    //调用定位执行命令
    button1.PerformClick();
    }

    private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
    {

    }
    }

    #region 管理书签
    private void barButtonItem13_ItemClick(object sender, ItemClickEventArgs e)
    {
    try
    {
    FrmManageBookmark frmManageBookMark = new FrmManageBookmark(axMapControl1.Map);
    frmManageBookMark.ShowDialog();
    }
    catch (Exception ex)
    {
    MessageBox.Show(ex.Message);
    }
    }
    #endregion

    end:地图缩放

    #region 地图浏览放大
    private void barButtonItem8_ItemClick(object sender, ItemClickEventArgs e)
    {
    IEnvelope pEnvelope;
    pEnvelope = axMapControl1.Extent;
    pEnvelope.Expand(0.5, 0.5, true);//放大2倍
    axMapControl1.Extent = pEnvelope;
    axMapControl1.ActiveView.Refresh();
    }
    #endregion
    #region 缩小
    private void barButtonItem9_ItemClick(object sender, ItemClickEventArgs e)
    {
    IActiveView pActiveView = axMapControl1.ActiveView;
    IPoint centerPoint = new PointClass();
    centerPoint.PutCoords((pActiveView.Extent.XMin + pActiveView.Extent.XMax) / 2, (pActiveView.Extent.YMin + pActiveView.Extent.YMax) / 2);
    IEnvelope envelope = pActiveView.Extent;
    envelope.Expand(1.5, 1.5, true);//和放大区别在于Expand函数参数不同
    pActiveView.Extent.CenterAt(centerPoint);
    pActiveView.Extent = envelope;
    pActiveView.Refresh();

    }
    #endregion

  • 相关阅读:
    菜鸟成长记(十二)----- 生活的意义是什么?
    菜鸟成长记(十一)----- 操蛋的2016与未知的2017
    菜鸟成长记(十)----- 好笑的格局
    菜鸟成长记(九)----- 当我作死的时候,我在想些什么。
    菜鸟成长记(八)----- 一个萝卜一个坑
    菜鸟成长记(七)----- 如何叫醒一个装睡的人?
    菜鸟成长记(六)----- 懒惰与惶恐的挣扎
    C++类的数组元素查找最大值问题
    成为IT精英,我奋斗了7年
    DS1337 时钟芯片在 C8051F 上的实现
  • 原文地址:https://www.cnblogs.com/bby2014210552/p/6226618.html
Copyright © 2020-2023  润新知