/ 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. keepalived安装配置实战心得(实现高可用保证网络服务不间断)

    keepalived安装配置实战心得(实现高可用保证网络服务不间断) 一.准备2台虚拟机     安装的系统是:centos-release-7-1.1503.el7.centos.2.8.x86_6 ...

  2. (转)CentOS7下yum安装mysql配置多实例

    原文:http://blog.csdn.net/poklau/article/details/54951798

  3. Linux驱动:SPI驱动编写要点

    题外话:面对成功和失败,一个人有没有“冠军之心”,直接影响他的表现. 几周前剖析了Linux SPI 驱动框架,算是明白个所以然,对于这么一个庞大的框架,并不是每一行代码都要自己去敲,因为前人已经把这 ...

  4. Angularjs集成第三方js插件之Uploadify

    有时候需要用一些第三方插件,比如datepicker,slider,或者tree等.以前的做法是直接通过jquery取得某个元素,然后调用某个方法即可.但在angularjs中,不能直接这么写,必须写 ...

  5. EF基础知识小记四(数据库=>模型设计器)

    EF基础知识小记三(设计器=>数据库)介绍了如何创建一个空设计器模型,并如何将模型同步到数据库的表中,本文则主要介绍如何将一个存在的数据库同步到模型设计器中.为了能快速的模拟这个过程,给出一下建 ...

  6. Java_try,catch,finally return之间的执行顺序

    以往认为函数只要执行到return语句便会返回结果并终止,然而这时错误的,因为这存在特例. 掌握下面几条原则就可以完全解决“当try.catch.finally遭遇return”的问题. 原则:1.f ...

  7. asp.net六种方法刷新页面

    第一: private void Button1_Click( object sender, System.EventArgs e )   {     Response.Redirect( Reque ...

  8. MySQL命令行导入导出数据

    参考:http://www.cnblogs.com/xcxc/archive/2013/01/30/2882840.html 这篇文章写得非常好,又简洁,而且深入浅出,排版也非常好看,不会像网上的只是 ...

  9. 面试题20:搜索二叉树可能有两个元素发生了交换,如何恢复BST?

    Two elements of a binary search tree (BST) are swapped by mistake. Recover the tree without changing ...

  10. spring中获取applicationContext

    常用的5种获取spring 中bean的方式总结: 方法一:在初始化时保存ApplicationContext对象代码:ApplicationContext ac = new FileSystemXm ...