Events

Contents

Introduction

GermaniumWeb raises events whenever the user or your application initiates an action (e.g. a mouse click, activating a Placemark), or when an action started by the user or your application completes (e.g. BBL loading completed, glide ended). For additional control and interactivity options, you may listen out for a particular event and execute some actions when that event occurs.

To do so, you:

  1. Write your event handler, which is the function to be executed each time the event occurs.
  2. Add your event handler to an event using AddEventHandler().
  3. Optionally, when you no longer need to handle the event, you can remove your event handler from the event using RemoveEventHandler().

Writing an event handler

Your event handler should expect an Event object. The Event object contains properties relevant to an event.

Please refer to the full list of events, and their associated event properties in the API documentation.

For example, following event handler function will display some of the properties of a mouse event.

function AnnounceMouseEvent(eventArgs)
{
    // List which mouse button was clicked, and its screen position
    var strOut = "Event name = " + eventArgs.name + "\n";
    var strMouseButton = "";
    switch (eventArgs.mouseButton) {
        case Germanium.MouseButtons.Left:
            strMouseButton = "left button";
            break;
        case Germanium.MouseButtons.Middle:
            strMouseButton = "middle button";
            break;
        case Germanium.MouseButtons.Right:
            strMouseButton = "right button";
            break;
        default:
            break;
    }
    strOut += "mouseButton = " + strMouseButton + "\n";
    strOut += "windowX = " + eventArgs.windowX + "\n";
    strOut += "windowY = " + eventArgs.windowY + "\n";
    alert("Event properties:\n" + strOut);
}


Adding an event handler

Event handlers are added to an event using WebControl.AddEventHandler. You may attach multiple event handlers to the same event.

In the example below, we add the event handler to the OnDblMouseClick event.

germ.AddEventHandler(Germanium.Event.OnMouseDblClick, AnnounceMouseEvent);

After the event handler is added, whenever the user double clicks the mouse over the plugin area, the function AnnounceMouseEvent() will be called.

Removing an event handler

If you no longer want the event triggering your event handler, you can remove the event handler as follows using the WebControl.RemoveEventHandler

germ.RemoveEventHandler(Germanium.Event.OnMouseDblClick, AnnounceMouseEvent);
Note: You may only remove event handlers that are named functions using WebControl.RemoveEventHandler. However, using WebControl.RemoveAllEventHandlers will remove all event handlers, including anonymous handlers.

Reference

Retrieved from "http://www.germanium3d.com/code/EventConcepts"

This page has been accessed 18,984 times. This page was last modified on 24 May 2011, at 01:47.


Developers


Main

API Key Registration

Developer Guide
- Introduction
- Buildings
- Point Placemarks
- Line & Polygon      PlacemarksUpdated
- Model Placemarks New
- HTMLBoxes New
- Eye Control
- Clip Planes
- Events
- Coordinate System
- Navigation Modes
- Options

API Documentation

Examples
- Applications Gallery
- Hello Germanium
- Interactive samples

More Resources
- API Release Notes
- Developer FAQ
- "A Beginner's Guide" slides
- Training Materials
- Icon Gallery
- Sample Buildings
- BBL Tree

Report Bugs