State management, Creating a custom tool, Creating a – Pitney Bowes MapXtreme User Manual

Page 88: Custom tool

Advertising
background image

Chapter 5: Web Applications, Controls, and Tools

Creating a Custom Tool

MapXtreme v7.1

88

Developer Guide

The Global.asax files provided with our sample applications demonstrate an example of handling
application errors. If the application encounters an error while processing a request for a map image,
the Application_Error method creates an image containing an error message, and returns that to the
client.

For more information on Error Management, refer to the

MSDN site

on error handling with ASP.NET.

State Management

The MapInfo.WebControls.StateManager is an abstract class that includes methods SaveState and
RestoreState. MapXtreme’s map tools call RestoreState and SaveState before and after the
processing, respectively. Since state management is application specific, it is your responsibility to
implement these methods in a concrete class in the application. This allows you to control what gets
restored and saved and how things are restored and saved.

For more information on state management, see

Chapter 6: Understanding State Management

.

Creating a Custom Tool

To create a custom tool, you can modify or add behavior to a built-in tool or write your own custom
commands and tools.

For example, you may wish to modify a Zoom-In tool to zoom-in and select a feature with one click.
This tool requires a server command class that contains code to zoom-in and perform the selection.
Since we provide the source code for all the server command classes, you can simply modify the
ZoomIn command class to add the selection code.

If our source code does not provide a starting point for your customization, you must write your own
commands and tool classes. The source code is located in your MapXtreme installation under
\Samples\MapXtremeWebControlsSourceCode.

As you plan your customization, keep the following MapXtreme tool architecture in mind. A
MapXtreme map tool consists of:

A client-side tool class that inherits from MapInfo.WebControls.WebTool.

Properties on the tool class that control the behavior of the tool, including:

JavaScript that describes the interaction of the tool with the MapControl (click, draw
rectangle, etc.)

JavaScript that creates the url request for the tool.

A server-side command class that is derived from MapInfo.WebControls.MapBaseCommand
that carries out the desired tool behavior.

Properties for the tool are defined either in the class or on the web page. The custom tool is
referenced on the web page by the tool class name.

The code used in the following procedure can be found under the Samples folder under
\Web\Features\CustomTools\CustomToolsCS.

To create a custom tool:

Advertising