Customizing tools – Pitney Bowes MapXtreme User Manual

Page 146

Advertising
background image

Chapter 7: Desktop Applications, Controls, Dialogs, and Tools

Customizing Tools

MapXtreme v7.1

146

Developer Guide

Customizing Tools

Tools for desktop applications can be customized in two ways: by creating a subclass of an existing
tool, or by using one of the tools in the Custom Tools group. Any of the Tool classes provided in
MapXtreme can be customized by creating a subclass derived from the desired particular Tool class.
An example of this is deriving a new tool class from the AddLineTool class. The tool could be
changed to a particular behavior (e.g., always beep when line is drawn), a particular appearance
(e.g., always draw the line in red), or to a particular functionality (e.g., always constrain line drawing
to 90 degree increments).

Another example would be to create two different tools based upon the same tool. The AddPointTool
could be used to subclass two other tools that each use different symbols for indicating two kinds of
points on a map. Assign one tool to the left mouse button and assign the other to the right mouse
button.

The following code example illustrates a customization of the AddPolygonTool.

VB example:

Dim insertionlayerfilter As IMapLayerFilter
Dim style As MapInfo.Styles.CompositeStyle
Dim addmaptoolproperties As MapInfo.Tools.AddMapToolProperties
Dim maptool As MapInfo.Tools.MapTool

insertionlayerfilter = _

MapLayerFilterFactory.FilterByLayerType(LayerType.Normal)

style = New MapInfo.Styles.CompositeStyle

addmaptoolproperties = New _

MapInfo.Tools.AddMapToolProperties(MapLayerFilterFactory.Filter_

ForTools(MapControl1.Map, insertionlayerfilter, _
MapLayerFilterFactory.FilterVisibleLayers(True), _
"CustomPolygonAddMapToolProperties", Nothing), style)

maptool = New MapInfo.Tools.AddMapTool(MapControl1.Viewer, _

MapControl1.Handle.ToInt32(), MapControl1.Tools, New _

MapInfo.Tools.MouseToolProperties(Cursors.Default, _
Cursors.Default Cursors.Default),_
MapControl1.Tools.MapToolProperties, addmaptoolproperties)

Additionally, MapXtreme ships with a desktop tools sample application that you can analyze the
implementation and customize it for your needs. See
..\MapInfo\MapXtreme\7.x.x\Samples\Desktop\Features\DesktopTools\cs under your installation of
MapXtreme.

Advertising