zoukankan      html  css  js  c++  java
  • Arcengine编辑代码

    1. using System;
    2. using System.Drawing;
    3. using System.Collections;
    4. using System.ComponentModel;
    5. using System.Windows.Forms;
    6. using System.Data;
    7. using System.IO;
    8. using System.Runtime.InteropServices;
    9. using ESRI.ArcGIS.esriSystem;
    10. using ESRI.ArcGIS.Carto;
    11. using ESRI.ArcGIS.Controls;
    12. using ESRI.ArcGIS.ADF;
    13. using ESRI.ArcGIS.SystemUI;
    14. namespace Demo2
    15. {
    16.     public sealed partial class MainForm : Form
    17.     {
    18.         #region private members
    19.         private IMapControl3 m_mapControl = null;
    20.         private string m_mapDocumentName = string.Empty;
    21.        
    22.         private IToolbarMenu m_toolbarMenu;
    23.         #endregion
    24.         #region class constructor
    25.         public MainForm()
    26.         {
    27.             InitializeComponent();
    28.         }
    29.         #endregion
    30.         private void MainForm_Load(object sender, EventArgs e)
    31.         {
    32.            
    33.             m_mapControl = (IMapControl3) axMapControl1.Object;
    34.             //Load the Data into the MapControl1
    35.             string sFilePath = @"C:ConferenceDataDemo Editing.mxd";
    36.             
    37.             if (m_mapControl.CheckMxFile(sFilePath))
    38.             {
    39.                 m_mapControl.LoadMxFile(sFilePath, null, null);
    40.             }
    41.             else
    42.                 MessageBox.Show(sFilePath + " is not a valid ArcMap document");
    43.             #region setup toolbar visibility
    44.             menuSaveDoc.Enabled = false;
    45.             editingToolStripMenuItem.Checked = true;
    46.             inkToolStripMenuItem.Checked = false;
    47.             GenericToolStripMenuItem.Checked = false;
    48.             navigationToolStripMenuItem.Checked = true;
    49.             axEditorToolbar.Visible = true;
    50.             axNavigationToolbar.Visible = true;
    51.             axExtraEditorToolbar.Visible = false;
    52.             axInkToolbar.Visible = false;
    53.             #endregion
    54.             //EditorToolbar          
    55.             axEditorToolbar.AddItem("esriControls.ControlsEditingEditorMenu", 0, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly);
    56.             axEditorToolbar.AddItem("esriControls.ControlsEditingEditTool", 0, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly);
    57.             axEditorToolbar.AddItem("esriControls.ControlsEditingSketchTool", 0, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly);
    58.             axEditorToolbar.AddItem("esriControls.ControlsEditingTargetToolControl", 0, -1, true, 0, esriCommandStyles.esriCommandStyleIconOnly);
    59.             axEditorToolbar.AddItem("esriControls.ControlsEditingTaskToolControl", 0, -1, true, 0, esriCommandStyles.esriCommandStyleIconOnly);
    60.             axEditorToolbar.AddItem("esriControls.ControlsEditingAttributeCommand", 0, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly);
    61.             axEditorToolbar.AddItem("esriControls.ControlsEditingSketchPropertiesCommand", 0, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly);
    62.             axEditorToolbar.AddItem("esriControls.ControlsUndoCommand", 0, -1, true, 0, esriCommandStyles.esriCommandStyleIconOnly);
    63.             axEditorToolbar.AddItem("esriControls.ControlsRedoCommand", 0, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly);
    64.             //ExtraEditorToolbar
    65.             axExtraEditorToolbar.AddItem(new EditPropertiesCmd(), 0, -1, false, 0, esriCommandStyles.esriCommandStyleTextOnly);
    66.             axExtraEditorToolbar.AddItem("esriControls.ControlsUndoCommand", 0, -1, true, 0, esriCommandStyles.esriCommandStyleIconOnly);
    67.             axExtraEditorToolbar.AddItem("esriControls.ControlsRedoCommand", 0, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly);
    68.             axExtraEditorToolbar.AddItem("esriControls.ControlsEditingCutCommand", 0, -1, true, 0, esriCommandStyles.esriCommandStyleIconOnly);
    69.             axExtraEditorToolbar.AddItem("esriControls.ControlsEditingPasteCommand", 0, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly);
    70.             axExtraEditorToolbar.AddItem("esriControls.ControlsEditingCopyCommand", 0, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly);
    71.             axExtraEditorToolbar.AddItem("esriControls.ControlsEditingClearCommand", 0, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly);
    72.             
    73.             //Create a popup menu
    74.             m_toolbarMenu = new ToolbarMenuClass();
    75.             m_toolbarMenu.AddItem("esriControls.ControlsEditingSketchContextMenu", 0, 0, false, esriCommandStyles.esriCommandStyleTextOnly);
    76.             //Share the Command Pool
    77.             m_toolbarMenu.CommandPool = axEditorToolbar.CommandPool;
    78.         }
    79.         #region Main Menu event handlers
    80.         private void menuNewDoc_Click(object sender, EventArgs e)
    81.         {
    82.             //execute New Document command
    83.             ICommand command = new CreateNewDocument();
    84.             command.OnCreate(m_mapControl.Object);
    85.             command.OnClick();
    86.         }
    87.         private void menuOpenDoc_Click(object sender, EventArgs e)
    88.         {
    89.             //execute Open Document command
    90.             ICommand command = new ControlsOpenDocCommandClass();
    91.             command.OnCreate(m_mapControl.Object);
    92.             command.OnClick();
    93.         }
    94.         private void menuSaveDoc_Click(object sender, EventArgs e)
    95.         {
    96.             //execute Save Document command
    97.             if (m_mapControl.CheckMxFile(m_mapDocumentName))
    98.             {
    99.                 //create a new instance of a MapDocument
    100.                 IMapDocument mapDoc = new MapDocumentClass();
    101.                 mapDoc.Open(m_mapDocumentName, string.Empty);
    102.                 //Make sure that the MapDocument is not readonly
    103.                 if (mapDoc.get_IsReadOnly(m_mapDocumentName))
    104.                 {
    105.                     MessageBox.Show("Map document is read only!");
    106.                     mapDoc.Close();
    107.                     return;
    108.                 }
    109.                 //Replace its contents with the current map
    110.                 mapDoc.ReplaceContents((IMxdContents)m_mapControl.Map);
    111.                 //save the MapDocument in order to persist it
    112.                 mapDoc.Save(mapDoc.UsesRelativePaths, false);
    113.                 //close the MapDocument
    114.                 mapDoc.Close();
    115.             }
    116.         }
    117.         private void menuSaveAs_Click(object sender, EventArgs e)
    118.         {
    119.             //execute SaveAs Document command
    120.             ICommand command = new ControlsSaveAsDocCommandClass();
    121.             command.OnCreate(m_mapControl.Object);
    122.             command.OnClick();
    123.         }
    124.         private void menuExitApp_Click(object sender, EventArgs e)
    125.         {
    126.             //exit the application
    127.             Application.Exit();
    128.         }
    129.         #endregion
    130.         //listen to MapReplaced evant in order to update the statusbar and the Save menu
    131.         private void axMapControl1_OnMapReplaced(object sender, IMapControlEvents2_OnMapReplacedEvent e)
    132.         {
    133.             //get the current document name from the MapControl
    134.             m_mapDocumentName = m_mapControl.DocumentFilename;
    135.             //if there is no MapDocument, diable the Save menu and clear the statusbar
    136.             if (m_mapDocumentName == string.Empty)
    137.             {
    138.                 menuSaveDoc.Enabled = false;
    139.                 statusBarXY.Text = string.Empty;
    140.             }
    141.             else
    142.             {
    143.                 //enable the Save manu and write the doc name to the statusbar
    144.                 menuSaveDoc.Enabled = true;
    145.                 statusBarXY.Text = Path.GetFileName(m_mapDocumentName);
    146.             }
    147.         }
    148.         private void axMapControl1_OnMouseMove(object sender, IMapControlEvents2_OnMouseMoveEvent e)
    149.         {
    150.             statusBarXY.Text = string.Format("{0}, {1}  {2}", e.mapX.ToString("#######.##"), e.mapY.ToString("#######.##"), axMapControl1.MapUnits.ToString().Substring(4));
    151.         }
    152.         private void editingToolStripMenuItem_Click(object sender, EventArgs e)
    153.         {
    154.             if (axEditorToolbar.Visible == false)
    155.             {
    156.                 axEditorToolbar.Visible = true;
    157.                 editingToolStripMenuItem.Checked = true;
    158.             }
    159.             else
    160.             {
    161.                 axEditorToolbar.Visible = false;
    162.                 editingToolStripMenuItem.Checked = false;
    163.             }
    164.         }
    165.         private void inkToolStripMenuItem_Click(object sender, EventArgs e)
    166.         {
    167.             if (axInkToolbar.Visible == false)
    168.                 axInkToolbar.Visible = true;
    169.             else
    170.                 axInkToolbar.Visible = false;
    171.         }
    172.         private void navigationToolStripMenuItem_Click(object sender, EventArgs e)
    173.         {
    174.             if (axNavigationToolbar.Visible == false)
    175.                 axNavigationToolbar.Visible = true;
    176.             else
    177.                 axNavigationToolbar.Visible = false;
    178.         }
    179.         private void bookmarksToolStripMenuItem_Click(object sender, EventArgs e)
    180.         {
    181.             if (axExtraEditorToolbar.Visible == false)
    182.                 axExtraEditorToolbar.Visible = true;
    183.             else
    184.                 axExtraEditorToolbar.Visible = false;
    185.         }
    186.         private void axMapControl1_OnMouseDown(object sender, IMapControlEvents2_OnMouseDownEvent e)
    187.         {
    188.             if (e.button == 2) m_toolbarMenu.PopupMenu(e.x, e.y, axMapControl1.hWnd);
    189.         }
    190.     }
    191. }
  • 相关阅读:
    jq原创幻灯片插件slideV1.0
    jq原创弹出层折叠效果
    jq实现鼠标经过图片翻滚效果
    开源代码的来源
    名词解析
    Joomla软件的简单介绍
    Java集合类的使用
    笔记
    MySQL基础篇一
    MySQL基础篇一
  • 原文地址:https://www.cnblogs.com/gisoracle/p/4676941.html
Copyright © 2011-2022 走看看