As part of evaluation of the MouseListener code, we realized that there is a level of abstraction that was not really well defined in the code. Essentially, there are a number of core events -- like drawing a box, moving the map, and drawing point/path/polygon features -- below the level of the "Controls". In order to make developing controls more modular and easier, we've migrated this functionality into a set of handlers which encapsulates these methods. As described in a Mailing List Post, this has made things like MouseDefaults a trivial control using these handlers.
Some of the examples demonstrate how to use this simply:
control = new OpenLayers.Control();
OpenLayers.Util.extend(control, {
draw: function () {
// this Handler.Box will intercept the shift-mousedown
// before Control.MouseDefault gets to see it
this.box = new OpenLayers.Handler.Box( control,
{"done": this.notice},
{keyMask: OpenLayers.Handler.MOD_SHIFT});
this.box.activate();
},
notice: function (bounds) {
alert(bounds);
}
});
the 'draw' function is called by control initialize, and the draw funciton in this case simply adds a Box handler that calls a callback 'done'. The callback (in this case) alerts the bounds that is returned by the handler.
The Point handler will draw a temporary vector feature following the mouse (until you let it up), and then return the OpenLayers.Geometry.Point that was created. That Geometry.Point can be added to a layer: the Control.DrawFeature demonstrates this functionality. Alternatively, the information can just be reported, or anything else can happen with it.
var control = new OpenLayers.Control();
OpenLayers.Util.extend(control, {
draw: function () {
this.point = new OpenLayers.Handler.Point( control,
{"done": this.notice},
{keyMask: OpenLayers.Handler.MOD_SHIFT})
this.point.activate();
},
notice: function (point) {
alert(point.CLASS_NAME + ": " + point.lon.toFixed(4) + "," + point.lat.toFixed(4) );
}
});
