阅读:2693回复:9
关于设计一个Identify组件的接口设计和实现问题
<P><B>
</B>这个问题似乎不难,但是并不定很多人都清楚。具体来讲就是,在VB中如何设计这个接口(方法、属性或事件),要引用哪些AO的接口和对象?小弟不胜感激。</P> <P>这个问题我在ArcGISWorld里面也问过了,但是问题依然没有解决。</P> |
|
1楼#
发布于:2004-09-03 08:44
<P>这是在esri上发现的,但是dephi版的,先看看,接着发出vb的</P><P>The Zip file I've attached to this post was built by me! It's really easy to use. You can add it to your Object Repository for use in your Delphi map projects. I built it in version 6, but I'm sure it would work in 5.
What's so special: This identify box lets you filter out which fields your users see from a particular shapefile. This identify box lets you print all the objects that are currently in it. Inserting into a project: It's best if there is only one global reference to the dialog box, but of course you can add several to your project if you want to. Currently, the box can only be used to identify one layer. Some spiffy programming could change this, though. After adding it to your project, all you have to do (this is so easy!) is scroll through the code looking for {*}. The {*} marks the lines you have to modify for your project. You don't need to modify the form at all! In the code of the form that contains the map control, you need to do a few things: 1. Before the dialog box is used, you must set its Map property to the Map Control on your form. You can do this in the FormCreate procedure. 2. Next, add the code below to the MouseDown event of your Map Control. Note about the code: Your type library importer may have imported the function names different than mine did. Like sometimes underscores (_) are added to procedure names, interface names, etc. This subtle difference may cause MyInfo to not compile. Just find the valid names with Code Insight or open the esriCore_TLB.pas file. Using: When you click on a feature on the map, the identify box will show up. If you shift-click another feature, the identify box will remain and will add that feature to the list. If you click on a feature in the list, the shape flashes on the map and its attributes are shown on the right of the Identify Box. You can remove all the features from the list with the click of a button, or one at a time. And if you have a default printer, you can print attributes for all of the features in the Identify box. I would like feedback if you please. This is a free thing. Is it cool? </P><P><a href="http://forums.esri.com/Attachments/2207.zip" target="_blank" >http://forums.esri.com/Attachments/2207.zip</A></P><PRE>procedure TMainForm.MapControl1MouseDown(Sender: TObject; button, shift, x, y: Integer; mapX, mapY: Double);var pClick: IPoint; pArray: IArray;begin pClick := CoPoint.Create as IPoint; pClick.PutCoords(MapX, MapY); //Assuming you want to identify the 4th layer (index 3) (MapControl1.Layer[3] as IIdentify).Identify( pClick, pArray ); if ( shift and 1 ) = 1 then FeatureIdentifier.AddFeatures( pArray ) else FeatureIdentifier.ClearAndAddFeatures( pArray ); FeatureIdentifier.Show;end;</PRE> |
|
|
2楼#
发布于:2004-09-03 08:46
<P>这是vb的例子</P><PRE><PRE>Option Explicit
Private m_pCommand As ICommand 'used for the Identify tool '************** Private Sub Form_Load() '********** ' Create the AfCommandsVB Identify tool Set m_pCommand = New AfCommandsVB.Identify ' Pass the Map control as the hook m_pCommand.OnCreate MapControl1.Object '********** End Sub Private Sub Toolbar1_ButtonClick(ByVal button As MSComctlLib.button) With MapControl1 ' Reset the CurrentTool Set .CurrentTool = Nothing Select Case button.Key Case "Identify" .MousePointer = esriPointerDefault Set .CurrentTool = m_pCommand End Select End With End Sub </PRE></PRE> [此贴子已经被作者于2004-9-3 8:54:58编辑过]
|
|
|
3楼#
发布于:2004-09-03 09:00
Dim pMap As Imap
Dim pIdentify As Iidentify Dim ppoint As IPoint Dim pIDArray As IArray Dim pFeatIdObj As IFeatureIdentifyObj Dim pIdObj As IIdentifyObj Dim pActiveView As IactiveView Set pActiveView = MapControl1.ActiveView Set pMap = MapControl1.ActiveView.FocusMap Set pIdentify = pMap.layer(3) 'this is Group_Shapefile layer Set ppoint = MapControl1.ToMapPoint(X, Y) Set pIDArray = pIdentify.Identify(ppoint) 'Get the FeatureIdentifyObject If Not pIDArray Is Nothing Then Set pFeatIdObj = pIDArray.Element(0) Set pIdObj = pFeatIdObj ‘here pIdObj contains the OID 'highlight the feature clicked on pIdObj.Flash pActiveView.ScreenDisplay Call Exe(pIdObj.Name) ‘execute the query with the OID In fact, finding how to access the Attribute table was the idea that brought me to the solution for the Identify of Group or Plantation. Because then I have looked for how to get the X and Y coordinates when you click on a feature on the map, that has been collected thanks to the parameters of the event function MapControl1_OnMouseDown. After that as I have found how to identify the OID of a feature that has those X and Y coordinate, with the help of the Iidentify interface, I have been able to identify the feature clicked on the map. This the way I have found the mechanism for a solution to identify a Group or a Plantation feature. Another chunk of my report that do the identifying of a shapefile wich type is Point, because I did not manage to use the same process of coding for this type of shapefile: This has been done by using an ESRI component called Identify. It acts exactely as the same as the tool identify in ArcMap that launch a dialogbox. I have look for other solution to make the identify because sometimes an automation error appear when you use it in VisualizeGIS (never mind you can try it again till it works, the application won’t end). Also it makes the identify on getting information only from the Attribute table and not more on the tree95 table. So it wasn’t only what I was expected to do. By the way I have kept this tool to identify the Individual tree because the mechanism that I have used for the Group and Plantation Identify wasn’t working on the Individual Shapefile. And I haven’t found why. (see in the Recommandation part something that I have noticed that may be the reason why it wasn’t working). Private Sub Toolbar1_ButtonClick(ByVal button As MSComctlLib.button) With MapControl1 ' Reset the CurrentTool Set .CurrentTool = Nothing Select Case button.Key … Case "identify" .MousePointer = esriPointerIdentify Set .CurrentTool = m_pCommand MSFlexGrid1.Visible = False Label4.Caption = "" lbl_cols.Caption = "" lbl_rows.Caption = "" lblLayer.Caption = "" lblFeature.Caption = "" … End Select End With End Sub |
|
|
4楼#
发布于:2004-09-03 09:46
<P>多谢GIS大热情支持。看了你的文章我明白了如何来使用Identify组件,但是还有一个关键问题是,如何把上述过程封装成一个DLL(VB),我感觉有两个难点:</P><P>1。如何传入外部地图对象,即</P><P>Set pMap = MapControl1.ActiveView.FocusMap‘我在组件中是不能引用Mapcontrol的,而是要用外部的MapControl</P><P>2。如何获得外部地图(mapcontrol)的鼠标单击事件</P>
|
|
5楼#
发布于:2004-09-03 11:03
<P>如果你是编写dll在arcmap中调用,你只需要更改下vba的程序就可以,如何获取地图对象你可以看看application</P><P>和mxd等的说明和接口</P><P>dll的命令调用你可以看看自带的例子里的mapcontrol的例子</P><P>你不需要在dll中应用mapcontrol,你只需要定义接口,然后调用就可以</P>
|
|
|
6楼#
发布于:2004-09-03 11:34
<P>对于第二个问题:</P><P>Implements ICommand ' Provides basic services to Hosting Framework
Implements ITool ' Provides services for interacting with the ActiveView</P><P>通过 ITool 的mouse 事件来处理 control 控件上的对应mouse 事件。 </P><P>对于第一个问题:</P><P>Private m_pHookHelper As IHookHelper ' Helper object to get hook to ArcGIS controls or Application</P><P>Private Sub ICommand_OnCreate(ByVal hook As Object) On Error GoTo ErrorHandler</P><P> ' OnCreate method called when framework creates command ' The IDispatch interface of the hosting framwork is passed ' through the hook variable. This should be QId for an appropriate ' interface for use in the other methods</P><P> ' The hook helper object enables commands to be written that ' work generically for both the ArcMap application and ArcGIS controls ' such as the MapControl, PageLayoutControl, ToolbarControl and ReaderControl. ' The IHookHelper interface has useful members to return objects such as ' the active view or focus map Set m_pHookHelper = New HookHelper Set m_pHookHelper.hook = hook</P><P>...</P><P>Dim pActiveView As IActiveView Set pActiveView = m_pHookHelper.ActiveView</P><P>pactiveview.FocusMap </P><P><b>借助 ESRI Command Wizard Addin for VB 来实现,会自动按你的需要做出一个基本的框架,要好处理得多。</b></P> |
|
|
7楼#
发布于:2004-09-04 10:40
<P>多谢二位的回复,我再试试。</P>
|
|
8楼#
发布于:2005-05-23 17:21
identify 脱离ARCMP 环境能用吗?我的在这句“set pidentifydialog=new identifydialog"提示429错误,不能创建对象!用自带的窗口是否不行?
|
|
9楼#
发布于:2005-06-02 14:37
最重要的是使用IIdentify及相关接口。esri网站上有相应例子。
|
|