The creation of a custom tooltip controller is demonstrated in the lightspeed.customization.controller sample. This controller shows an information panel when the mouse cursor hovers over an object.

custom controller tooltip
Figure 1. The lightspeed.customization.controller sample

The lightspeed.customization.controller sample applies the principle of controller chaining. For more information, see Controller chaining.

Program: Implementation of the custom tooltip controller shows how the tooltip controller is implemented in general, and the handleAWTEventImpl method in particular. On a mouse-moved or mouse-dragged event, the tooltip panel is either moved, unless the mouse cursor does not touch any object. In that case, the tooltip panel is removed. A mouse-exited event removes the tooltip as well. No events are consumed, because they may still be of use to other controllers. If a pan controller has been included in the chain, for example, it will still receive mouse-dragged events.

Program: Implementation of the custom tooltip controller (from samples/lightspeed/customization/controller/InformationPanelController)
@Override
public AWTEvent handleAWTEventImpl(AWTEvent aAWTEvent) {
  // Handle mouse events only
  if (aAWTEvent instanceof MouseEvent) {
    MouseEvent event = (MouseEvent) aAWTEvent;

    if (event.getID() == MouseEvent.MOUSE_MOVED || event.getID() == MouseEvent.MOUSE_DRAGGED) {
      // move the information panel to the mouse cursor
      movePanel(event.getX(), event.getY());
    } else if (event.getID() == MouseEvent.MOUSE_EXITED) {
      // remove the information panel if the mouse is outside the view
      removePanel();
    }
  }

  // Do not consume events, in order to make it possible for other controllers to use them.
  return aAWTEvent;
}

Note that coordinates obtained from an input event, a MouseEvent for example, are expressed in so-called toolkit coordinates. If DPI scaling is enabled in the host operating system, toolkit coordinates are different from Lightspeed view coordinates. When you are using the API to transform points between, for instance, cursor positions and geographic coordinates, it is important to be aware of this distinction. ALspViewXYZWorldTransformation provides the toolkitPoint2ViewSFCT, toolkitPoint2WorldSFCT, viewPoint2ToolkitSFCT and worldPoint2ToolkitSFCT methods facilitate this. Support high-resolution displays on a Lightspeed map provides further information about DPI scaling.