LayerMenu类代码
using System;
using System.Drawing;
using System.Runtime.InteropServices;
using ESRI.ArcGIS.ADF.BaseClasses;
using ESRI.ArcGIS.ADF.CATIDs;
using ESRI.ArcGIS.Controls;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Geometry;
using ESRI.ArcGIS.Display;
using NBGIS.PluginEngine;
namespace NBGIS.MainGIS
{
/// <summary>
/// Summary description for LayerMenu.
/// </summary>
[Guid("58b4faf5-a657-443f-bfac-57b7e10d903c")]
[ClassInterface(ClassInterfaceType.None)]
[ProgId("NBGIS.MainGIS.LayerMenu")]
public sealed class LayerMenu : BaseCommand
{
#region COM Registration Function(s)
[ComRegisterFunction()]
[ComVisible(false)]
static void RegisterFunction(Type registerType)
{
// Required for ArcGIS Component Category Registrar support
ArcGISCategoryRegistration(registerType);
//
// TODO: Add any COM registration code here
//
}
[ComUnregisterFunction()]
[ComVisible(false)]
static void UnregisterFunction(Type registerType)
{
// Required for ArcGIS Component Category Registrar support
ArcGISCategoryUnregistration(registerType);
//
// TODO: Add any COM unregistration code here
//
}
#region ArcGIS Component Category Registrar generated code
/// <summary>
/// Required method for ArcGIS Component Category registration -
/// Do not modify the contents of this method with the code editor.
/// </summary>
private static void ArcGISCategoryRegistration(Type registerType)
{
string regKey = string.Format("HKEY_CLASSES_ROOT\\CLSID\\{{{0}}}", registerType.GUID);
ControlsCommands.Register(regKey);
}
/// <summary>
/// Required method for ArcGIS Component Category unregistration -
/// Do not modify the contents of this method with the code editor.
/// </summary>
private static void ArcGISCategoryUnregistration(Type registerType)
{
string regKey = string.Format("HKEY_CLASSES_ROOT\\CLSID\\{{{0}}}", registerType.GUID);
ControlsCommands.Unregister(regKey);
}
#endregion
#endregion
private IHookHelper m_hookHelper;
private ITOCControlDefault m_tocControl;
private NBGIS.PluginEngine.IApplication m_App;
public LayerMenu(ITOCControlDefault tocControl,NBGIS.PluginEngine.IApplication app)
{
m_tocControl = tocControl;
m_App = app;
//
// TODO: Define values for the public properties
//
base.m_category = "LayerMenu"; //localizable text
base.m_caption = "ChangeRendering"; //localizable text
base.m_message = "ChangeRendering"; //localizable text
base.m_toolTip = "ChangeRendering"; //localizable text
base.m_name = "LayerMenu_ChangeRendering"; //unique id, non-localizable (e.g. "MyCategory_MyCommand")
try
{
//
// TODO: change bitmap name if necessary
//
string bitmapResourceName = GetType().Name + ".bmp";
//base.m_bitmap = new Bitmap(GetType(), bitmapResourceName);
base.m_bitmap = new Bitmap(this.GetType().Assembly.GetManifestResourceStream(bitmapResourceName));
}
catch (Exception ex)
{
System.Diagnostics.Trace.WriteLine(ex.Message, "Invalid Bitmap");
}
}
#region Overriden Class Methods
/// <summary>
/// Occurs when this command is created
/// </summary>
/// <param name="hook">Instance of the application</param>
public override void OnCreate(object hook)
{
if (hook == null)
return;
if (m_hookHelper == null)
m_hookHelper = new HookHelperClass();
m_hookHelper.Hook = hook;
// TODO: Add other initialization code
}
/// <summary>
/// Occurs when this command is clicked
/// </summary>
public override void OnClick()
{
IMapControlDefault pMapControl = m_hookHelper.Hook as IMapControlDefault;
IGeoFeatureLayer pGeoFeatLyr = pMapControl.CustomProperty as IGeoFeatureLayer;
if (pGeoFeatLyr == null) return;
SymbolForm symbolForm = new SymbolForm();
IStyleGalleryItem styleGalleryItem = null;
switch (pGeoFeatLyr.FeatureClass.ShapeType)
{
case esriGeometryType.esriGeometryPoint:
styleGalleryItem = symbolForm.GetItem(esriSymbologyStyleClass.esriStyleClassMarkerSymbols);
break;
case esriGeometryType.esriGeometryPolyline:
styleGalleryItem = symbolForm.GetItem(esriSymbologyStyleClass.esriStyleClassLineSymbols);
break;
case esriGeometryType.esriGeometryPolygon:
styleGalleryItem = symbolForm.GetItem(esriSymbologyStyleClass.esriStyleClassFillSymbols);
break;
}
symbolForm.Dispose();
m_App.MainPlatform.Activate();
if (styleGalleryItem == null) return;
ISimpleRenderer simpleRenderer = new SimpleRendererClass();
simpleRenderer.Symbol = (ISymbol)styleGalleryItem.Item;
pGeoFeatLyr.Renderer = simpleRenderer as IFeatureRenderer ;
pMapControl.Refresh(esriViewDrawPhase.esriViewGeography, null, null);
this.m_tocControl.Update();
}
#endregion
}
}
Related Items
Comments
实际上我是反对在构造函数里面直接把要引用的东西传进来的(我试着解耦的时候觉的是个麻烦),
pMapControl.CustomProperty是个object对象,我觉的它的作用类似于tag,本身就是用来传递额外的数据对象,把要传递的
ITOCControlDefault tocControl,
NBGIS.PluginEngine.IApplication app
IGeoFeatureLayer
封装成一个对象直接交给pMapControl.CustomProperty是否能达到清爽的目的呢?
我本人也认为ArcMap其实是最好的插件式框架,可惜我们中国人开发系统的系统大部分都喜欢另起炉灶,要求看起来与众不同。
至于在构造函数中传入必要的参数合不合适,恐怕没有一个标准的答案,不过我的建议是,不要染上“面向对象洁癖症”,适合的就是最好的。
fanfeilong 于 2009-4-24 11:08:37 回复恩 同意。
蒋老师:在SymbolForm框关闭时,主程序界面并没有出现,请问是何问题?谢谢!
ym 于 2010-12-27 22:29:00 回复重新表达一下,用.show() 可以使主程序界面出现,但为何activate不行?
Leave a comment
Or, take a look at Archives and Categories
当初第一次开发的时候傻傻的把arcgis的符号渲染面板的
简单渲染、唯一值渲染、分类渲染都实现了下。现在想想,完全没必要重复开发arcgis的这个功能,这些完全可以直接使用arcmap做好地图就可以了,二次开发应该关注需求相关算法以及业务流程的整合上,我们有80%的精力在做重复性的东东。根本上我更希望直接在arcmap上面开发插件,能够直接关注该关注的东西。当然了,现实总有更多理由。。。