What is a controller

A controller allows the user of the application to interact with the map: navigating around, selecting or editing objects, creating new objects, and so on.

It is the task of the controller to capture the input provided by the user, such as the java.awt.MouseEvent, and translate this into concrete actions, panning the map to a new location for example.

A controller in the LuciadLightspeed API is represented by the ILcdGXYController interface. The API comes with a number of pre-defined controllers, for example:

  • A controller to navigate on the map

  • A controller to edit data

  • A controller to create new data

  • A controller to measure distances

The following section describes how to use and customize the main implementations of ILcdGXYController.

Chaining controllers

The default controllers in the API typically perform only one task. For example the TLcdGXYZoomController allows the user to zoom in and out on the map, but does not support panning the map.

Most of the time, you want a controller that combines the behavior of several controllers. You can create such a combination by chaining the controllers: events come in at the top of the chain, and each controller decides whether or not it handles the event. If the controller does not handle the event, or only handles it partially, the event is passed to the next controller in the chain.

lls controllers chainable

The chainable behavior is provided by the ILcdGXYChainableController interface, which the majority of the controllers implement.

Controllers decide whether or not to handle an event by checking their event filters. You can configure each controller in the LuciadLightspeed API with a filter for AWT Events. Events that do not pass the filter are delegated directly to the next controller in the chain. The controller implementation handles Events that pass the filter, but may still delegate them if the controller has no use for them, based on the current state for instance. You can use the class TLcdAWTEventFilterBuilder to create complex filters.

The following snippet illustrates how you can add navigation support to another chainable controller:

if (aController instanceof ILcdGXYChainableController) {
  ((ILcdGXYChainableController) aController).appendGXYController(new TLcdGXYNavigateController());