/ 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. Hive导出表数据

    法一: hive (stuchoosecourse) > insert overwrite local directory '/home/landen/文档/exportDir'         ...

  2. Java之集合(八)HashMap

    转载请注明源出处:http://www.cnblogs.com/lighten/p/7338372.html 1.前言 本章介绍Java中最常用的一个集合类HashMap,此类在不同的JDK版本有不同 ...

  3. 【Git】学习记录

    配置git git config --global user.name "用户名或者用户ID" git config --global user.email "邮箱&qu ...

  4. spring boot整合RabbitMQ(Fanout模式)

    1.Fanout Exchange介绍Fanout Exchange 消息广播的模式,不管路由键或者是路由模式,会把消息发给绑定给它的全部队列,如果配置了routing_key会被忽略. 如上图所示, ...

  5. PHP中 LFI Local File Include,本地文件包 漏洞

    在allow_url_include=On就是远程文件包含了,假设这里为off,那就只能本地包含了. 1.       包含上传文件 只要目标服务器支持上传,不管是jpg,txt,gif等都可以,在其 ...

  6. shell中的(),{}几种语法用法

    转自:https://www.cnblogs.com/HKUI/p/6423918.html 查看脚本语法是否有错误:bash -n modify_suffix.sh跟踪执行sh -x modify_ ...

  7. protocol buffers生成go代码原理

    本文描述了protocol buffers使用.proto文件生成pb.go文件的过程 编译器 编译器需要插件来编译环境,使用如下方式安装插件:go get github.com/golang/pro ...

  8. Go语言学习笔记九: 指针

    Go语言学习笔记九: 指针 指针的概念是当时学C语言时了解的.Go语言的指针感觉与C语言的没啥不同. 指针定义与使用 指针变量是保存内存地址的变量.其他变量保存的是数值,而指针变量保存的是内存地址.这 ...

  9. 数据库报错com.mysql.jdbc.MysqlDataTruncation: Data truncation: Data too long for column 'ua' at row 1

    记一次报错记录,成长路上的点滴 明明使用浏览器或者微信开发工具调试接口没有问题,但是在真机测试时候就出问题了.(((¬_¬)) 500服务器内部错误,要死的节奏啊 登陆tomcat服务器 使用命令ta ...

  10. android学习-LocationManager(一)-定位方式原理解析

    参考资源:android 4种定位原理及实现——1 android使用不同的方法为应用提供位置信息. 定位的方式有三种:GPS地位(A-GPSAssistedGPS:辅助全球卫星定位系统,或者是同步G ...