/ 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;
}
}
}

Add map surrounds using the SymbologyControl的更多相关文章

  1. java 使用map返回多个对象组装

    Object json=JSONObject.fromObject("{}"); List<Object> list = new ArrayList<Object ...

  2. a=av###b=bv###c=cv map键值对 (a,av) (b,bv) (c,cv)

    import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.File; impo ...

  3. xml/map转换器,递归设计思路

    xml/map转换器 图片:http://pan.baidu.com/s/1nuKJD13 应用场景,为什么要把xml转map?我直接用jdom,dom4j操作不行吗? 如果你了解模板引擎(像velo ...

  4. List<Map<String,Object>>使用Java代码遍历

    List<Map<String,Object>>的结果集怎么使用Java代码遍历以获取String,Object的值: package excel; import java.u ...

  5. java中对List<Map<String,Object>>中的中文汉字排序

    import java.text.Collator;import java.util.ArrayList;import java.util.Collections;import java.util.C ...

  6. java解析json与map,list相互之间的转换

    运行这个类需要加载jar包:ezmorph-1.0.6.jar.json-lib-2.4-jdk15.jar.jsoup-1.6.1.jar.commons-beanutils-1.8.0.jar.c ...

  7. JAVA基础学习day16--集合三-Map、HashMap,TreeMap与常用API

    一.Map简述 1.1.简述 public interface Map<K,V> 类型参数: K - 此映射所维护的键的类型 key V - 映射值的类型 value 该集合提供键--值的 ...

  8. 迭代输出Map和List<Map<String,Object>>的方法

    一.Map<String,Object> String:key的类型 Object:value的类型,value可能是String,或者int类型,什么类型都可以 对于Map接口来说,本身 ...

  9. 修改Map中确定key对应的value问题

    今天在码代码的时候出现一个没有预料的问题: 先看下面的代码: public static void main(String[] args) { String[] files=new String[]{ ...

随机推荐

  1. mapreduce程序的按照key值从大到小降序排列

    在近期的Hadoop的学习中,在学习mapreduce时遇到问题:让求所给数据的top10,们我们指导mapreduce中是有默认的排列机制的,是按照key的升序从大到小排列的 然而top10问题的求 ...

  2. js delete删除对象属性,delete删除不了变量及原型链中的变量

    js delete删除对象属性,delete删除不了变量及原型链中的变量 一.delete删除对象属性 function fun(){ this.name = 'gg'; } var obj = ne ...

  3. Tomcat发生java.lang.OutOfMemoryError: PermGen space的解决方案

    产生该问题的主要原因是JVM永久带空间不足导致的,可以在环境变量CATALINA_OPTS中提高MaxPermSize参数值   set CATALINA_OPTS = -XX:PermSize=12 ...

  4. SQLServer2005重建索引

    今天发现一个页面运行很慢,用SQL Server Profiler抓出了一条运行时间为12s的sql ) and wfinstance is not null and wftbrq>='2016 ...

  5. 在windows里安装系统7、8、10或Offcie或Visio等推荐的激活工具

    不多说,直接上干货! (1)激活Windows或者Office前,你务必先进去KMSAuto Net的System界面,安装KMS-host Service; (2)然后回到Main主界面,选择Act ...

  6. 解释mysql 语句 ——解释CREATE DATABASE `test` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci

    在我们创建mysql数据库的时候我们经常会用到这句SQL:CREATE DATABASE `test` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ ...

  7. Java 国际化

    国际化英文单词为:Internationalization,又称I18N,I为因为单词的第一个字母,18为这个单词的长度,而N代表这个单词的最后一个字母.国际化又称本地化(Localization,L ...

  8. java面试⑥框架部分

    2.5.1 什么是框架: 2.5.2 MVC模式 2.5.3 MVC框架 2.5.4 简单讲一下struts2的执行流程 2.5.5 Struts2中的拦截器,你都用它干什么? 2.5.6 简单讲一下 ...

  9. Hadoop/Spark生态圈里的新气象

    令人惊讶的是,Hadoop在短短一年的时间里被重新定义.让我们看看这个火爆生态圈的所有主要部分,以及它们各自具有的意义. 对于Hadoop你需要了解的最重要的事情就是 ,它不再是原来的Hadoop. ...

  10. 【转】30+有用的CSS代码片段

    来自:WEB资源网 链接:http://webres.wang/31-css-code-snippets-to-make-you-a-better-coder/ 原文:http://www.desig ...