Box Selector

A control that enables users to select a bounds on a map by holding the shift key and dragging on a map. It’s useful for stuff like selecting areas to render in TileMill or areas to download for offline use.

Example

var url = 'https://api.tiles.mapbox.com/v3/mapbox.blue-marble-topo-bathy-jul.jsonp';
wax.tilejson(url, function(tilejson) {
    var m = new MM.Map('map-div',
      new wax.mm.connector(tilejson));
    wax.mm.boxselector(m, tilejson, {
      callback: function(coords) {
        $('#boxselector-text').text(
          coords.map(function(c) {
            return c.lat + ',' + c.lon;
          }).join(' - '));
      }
    });
    m.setCenterZoom({ lat: 39, lon: -98 }, 2);
});

API

var boxselector = wax.mm.boxselector(map, options or callback)
Create a new boxselector object. The second argument can be either an options object with a 'callback' member for a callback function, or just a callback function. Options is an object with options:
callback
A function that will be called with a single argument coords, containing the extent of a selection, as represented by an array with two elements of type com.modestmaps.Location.
var extent = boxselector.extent()
Get the current extent of the boxselector control, in the same form as would be passed to the callback.
boxselector.extent([com.modestmaps.Location, com.modestmaps.Location], [silent])
Set the extent of the boxselector with a two-element array of `com.modestmaps.Location`. The boxselector control will internally fix their order to be top-left, bottom-right, if they are unordered.
Since Wax 3.0.7, this control also accepts a `silent` option - which if true means that boxselector's callback will not be called upon this setting of the extent.
</dl>