MapXtreme的自帶幫助的查找功能不好,不支援中文,網上的例子也比較少。把自己解決的幾個問題拿出來與大家共享,希望有幫助!
開發環境:VB.NET 2008 + MapXtreme2008
1、添加自定義工具
沒有使用mapxteme 提供的ToolBar控件,自己定制可互動的工具添加到自己的寫的架構上,例子為管線剖面圖工具,需要先在地圖上繪制一條線,然後通過計算和這條線相交的所有管線的剖面資訊,将剖面圖繪制到彈出的對話框上。
1) 聲明工具
Private m_SectionTool As MapInfo.Tools.MapTool
2) 添加工具
Dim insertionLayerFilter As IMapLayerFilter = MapLayerFilterFactory.FilterByLayerType(LayerType.Normal)
' Set the default style for the new objects (red fill with blue border).
Dim style As MapInfo.Styles.CompositeStyle = New MapInfo.Styles.CompositeStyle()
Dim addMapToolProperties As MapInfo.Tools.AddMapToolProperties = New MapInfo.Tools.AddMapToolProperties( _
MapLayerFilterFactory.FilterForTools(MapControl1.Map, insertionLayerFilter, _
MapLayerFilterFactory.FilterVisibleLayers(True), _
"CustomPolygonAddMapToolProperties", Nothing), style)
' Create an Add polygon tool with non-default properties.
m_SectionTool = New MapInfo.Tools.CustomLineMapTool(True, True, True, _
MapControl1.Viewer, MapControl1.Handle.ToInt32(), MapControl1.Tools, _
MapControl1.Tools.MouseToolProperties, MapControl1.Tools.MapToolProperties)
' Add it to the MapTools collection.
MapControl1.Tools.Add("SectionTool", m_SectionTool)
3) 注冊工具事件
Public Sub New()
AddHandler MapControl1.Tools.Used, AddressOf ToolUsed '工具事件
End Sub
4)響應工具消息
Public Sub ToolUsed(ByVal sender As Object, ByVal e As MapInfo.Tools.ToolUsedEventArgs)
Select Case e.ToolName
Case "SectionTool" '斷面工具
End Select
End Sub
5)發現一個例外:自定義工具使用 AddPointMapTool 不能觸發used事件。
解決方法:可以使用CustomPointMapTool 代替,AddPolylineMapTool也同理。