Add map surrounds using the SymbologyControl

/ Copyright 2010 ESRI// // All rights reserved under the copyright laws of the United States// and applicable international laws, treaties, and conventions.// // You may freely redistribute and use this sample code, with or// without modification, provided you include the original copyright// notice and use restrictions.// // See the use restrictions at <your ArcGIS install location>/DeveloperKit10.0/userestrictions.txt.// using System;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Controls;
using ESRI.ArcGIS.Display;
using ESRI.ArcGIS.Geometry;
using ESRI.ArcGIS.ADF.BaseClasses;
using ESRI.ArcGIS.ADF.CATIDs;
using System.Runtime.InteropServices;

namespace AddMapSurrounds
{
  [ClassInterface(ClassInterfaceType.None)]
  [Guid("5175B831-F18E-4cff-A016-146A7923681D")]

  publicsealedclass CreateNorthArrow : BaseTool
  {
    private IHookHelper m_HookHelper;
    private INewEnvelopeFeedback m_Feedback;
    private IPoint m_Point;
    privatebool m_InUse;

    //Windows API functions to capture mouse and keyboard//input to a window when the mouse is outside the window
    [DllImport("User32", CharSet=CharSet.Auto)]
    privatestaticexternint SetCapture(int hWnd);
    [DllImport("User32", CharSet=CharSet.Auto)]
    privatestaticexternint GetCapture();
    [DllImport("User32", CharSet=CharSet.Auto)]
    privatestaticexternint ReleaseCapture();

    #region Component Category Registration
    [ComRegisterFunction()]
    [ComVisible(false)]
    staticvoid RegisterFunction(String sKey)
    {
      ControlsCommands.Register(sKey);
    }
    [ComUnregisterFunction()]
    [ComVisible(false)]
    staticvoid UnregisterFunction(String sKey)
    {
       ControlsCommands.Unregister(sKey);
    }
    #endregionpublic CreateNorthArrow()
    {
      //Create an IHookHelper object
      m_HookHelper = new HookHelperClass();

      //Set the tool propertiesbase.m_bitmap = new System.Drawing.Bitmap(GetType().Assembly.GetManifestResourceStream(GetType(), "NorthArrow.bmp"));
      base.m_caption = "NorthArrow";
      base.m_category = "myCustomCommands(C#)";
      base.m_message = "Add a north arrow map surround";
      base.m_name = "myCustomCommands(C#)_NorthArrow";
      base.m_toolTip = "Add a north arrow";
      base.m_deactivate = true;
    }

    publicoverridevoid OnCreate(object hook)
    {
      m_HookHelper.Hook = hook;
    }

    publicoverridevoid OnMouseDown(int Button, int Shift, int X, int Y)
    {
      //Create a point in map coordinates
      m_Point = m_HookHelper.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(X, Y);

      //Start capturing mouse events
      SetCapture(m_HookHelper.ActiveView.ScreenDisplay.hWnd);

      m_InUse = true;
    }

    publicoverridevoid OnMouseMove(int Button, int Shift, int X, int Y)
    {
      if (m_InUse == false) return;

      //Start an envelope feedbackif (m_Feedback == null )
      {
        m_Feedback = new NewEnvelopeFeedbackClass();
        m_Feedback.Display = m_HookHelper.ActiveView.ScreenDisplay;
        m_Feedback.Start(m_Point);
      }

      //Move the envelope feedback
      m_Feedback.MoveTo(m_HookHelper.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(X, Y));
    }

    publicoverridevoid OnMouseUp(int Button, int Shift, int X, int Y)
    {
      if (m_InUse == false) return;

      //Stop capturing mouse eventsif (GetCapture() == m_HookHelper.ActiveView.ScreenDisplay.hWnd)
        ReleaseCapture();

      //If an envelope has not been tracked or its height/width is 0if (m_Feedback == null)
      {
        m_Feedback = null;
        m_InUse = false;
        return;
      }
      IEnvelope envelope = m_Feedback.Stop();
      if ((envelope.IsEmpty) || (envelope.Width == 0) || (envelope.Height == 0))
      {
        m_Feedback = null;
        m_InUse = false;
        return;
      }

      //Create the form with the SymbologyControl
      SymbolForm symbolForm = new SymbolForm();
      //Get the IStyleGalleryItem
      IStyleGalleryItem styleGalleryItem = symbolForm.GetItem(esriSymbologyStyleClass.esriStyleClassNorthArrows);
      //Release the form
      symbolForm.Dispose();
      if (styleGalleryItem == null) return;

      //Get the map frame of the focus map
      IMapFrame mapFrame = (IMapFrame) m_HookHelper.ActiveView.GraphicsContainer.FindFrame(m_HookHelper.ActiveView.FocusMap);

      //Create a map surround frame
      IMapSurroundFrame mapSurroundFrame = new MapSurroundFrameClass();
      //Set its map frame and map surround
      mapSurroundFrame.MapFrame = mapFrame;
      mapSurroundFrame.MapSurround = (IMapSurround) styleGalleryItem.Item;

      //QI to IElement and set its geometry
      IElement element = (IElement) mapSurroundFrame;
      element.Geometry = envelope;

      //Add the element to the graphics container
      m_HookHelper.ActiveView.GraphicsContainer.AddElement((IElement)mapSurroundFrame, 0);
      //Refresh
      m_HookHelper.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, mapSurroundFrame, null);

      m_Feedback = null;
      m_InUse = false;
    }
  }
}
时间: 2024-08-30 07:12:40

Add map surrounds using the SymbologyControl的相关文章

今天愣了半天硬是没想到用map,在此还原以下代码

/** * 左边为项目类型,树结构的,需要将项目的树结构目录加上项目名拼接在一起,不同的项目做成下拉列表 */ @Transactional(readOnly = false) public List<Map<String,Object>> findFullName(){ //获取所有的父id和项目名称 List<ProjectInfo> list=projectInfoDao.findParentIdsAndProjectName(); //定义一个list,泛型为m

java中如何实现数组、List、Set、Map之间互相转换。

1.数组转List: String[] countries = {"Array", "List", "Set", "Map"}; List list = Arrays.asList(countries); 2.Array转:Set String [] countries = {"Array", "List", "Set"}; Set<String> set

Struts2标签遍历List&lt;Map&lt;String, String&gt;&gt;

import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import com.opensymphony.xwork2.ActionSupport; public class LoginAction extends ActionSupport { private List<Map<String, String>> list; @Override

list中含有map的排序问题

Map的种类 在Java中,Map的主要作用是存储键值对.由于是根据键得到值,所以不允许键重复.它主要有如下几个类别: HashMap: 最常用的Map,它根据键的HashCode值存储数据,根据键可以直接获取它的值,具有很快的访问速度,遍历时,取得数据的顺序是完全随机的.HashMap最多只允许一条记录的键为Null;允许多条记录的值为Null;HashMap不支持线程的同步,即任一时刻可以有多个线程同时写HashMap;可能会导致数据的不一致.如果需要同步,可以用Collections的sy

list+map

通常读取数据库表中的一条记录后,可以存储于Hashmap变量中:若要读取多条记录,则依次读取每个记录时,先用Hashmap变量存取,然后将Hashmap加到ArrayList变量中. 注意: 每次读取一条记录的时候,应该new一个Hashmap变量,不能用同一个Hashmap变量存取不同的记录,否则ArrayList变量中的每个对象指向的地址均为同一个地址,即最后ArrayList变量中所有的值均指向最后一条记录. 代码示例如下: List list=new ArrayList(); Hashm

对List&lt;Map&lt;String,Object&gt;&gt; 进行排序

1 package lltse.base.collectiondemo; 2 3 import java.util.ArrayList; 4 import java.util.Collections; 5 import java.util.Comparator; 6 import java.util.HashMap; 7 import java.util.List; 8 import java.util.Map; 9 import java.util.Random; 10 11 12 publi

List map的使用

初始化map Map<String, String> map=new HashMap<String, String>(); String sql="from Tab0 t0 where t0.keytypeid='"+keytypeid+"' and "+ "t0.tabKeys.adddate<'"+(years1+1)+ "-01-01 00:00:00' and t0.tabKeys.adddate&

spring,cxf,restful发布webservice传递List,Map,List&lt;Map&gt;

上一篇文章中概述了怎么在Javaweb中发布webservice,这篇文章讲解怎么传递复杂的对象 所用的jar包如下 当服务器返回的是List或者是Map时,一定要将其封装在一个类中, 首先创建封装类,封装了List,Map对象,以及自定义的User类 User.java public class User { private String name; private int age; public User() { } public User(String name, int age) { t

java转换xml、list、map和json

java转换xml.list.map和json [java] view plaincopy package com.shine.framework.core.util; import java.io.ByteArrayOutputStream; import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; i