[OpenLayers-Dev] Re: How do I fire a function after all features have been selected by a box in OpenLayers?

Xavier Mamano (jorix) xavier.mamano at gmail.com
Tue Jan 10 14:52:46 EST 2012

Hi brianwmunz,

I have prepared a code modification to allow to do what you mentioned. I
have thought to propose a "Pull Request" for this change. 

The change is:

An example of use:
// listeners
var onFeatureSelect = function(evt) {
    alert("Selected feature id =" + evt.feature.id + (evt.boxSelection?" by
var onFeatureUnselect =function(evt) {
    alert("Unselected feature id =" + evt.feature.id);
var onBoxSelection =function(evt) {
    alert("Box selected " + evt.features.length + " features");
// select control
var selectCtrl = new OpenLayers.Control.SelectFeature(layerVector, {
    clickout: true,
    box: true,
    eventListeners: {
        boxselection: onBoxSelection
    'featureselected': onFeatureSelect,
    'featureunselected': onFeatureUnselect

NOTE: Is not used "onSelect" and "onUnselect" of SelectFeature so they are
considered deprecated (even that is not documented and some examples still
use them)

Sorry, SelectFeature is a road full of obstacles for beginners, and
sometimes for those who are not ;-/

Xavier Mamano

> Thanks for your quick response.
> I'm somewhat new to OpenLayers, so your example is a little over my head
> right now :)
> Could you please explain a little more?  I'm doing some pretty basic
> things.  I have an OSM base layer and a vector layer which contains
> polygon features.
> I'd like to be able to have a function fire after the box has been dragged
> that gets a list of all selected features.
> I understand that we're attaching an event, but I'm not sure where to
> attach it and that kind of thing.
> Again, sorry if I sound pretty ignorant on this, but like I said I'm just
> getting my feet wet with OpenLayers.
> Thanks a lot for your help.

View this message in context: http://osgeo-org.1803224.n2.nabble.com/How-do-I-fire-a-function-after-all-features-have-been-selected-by-a-box-in-OpenLayers-tp7168754p7173471.html
Sent from the OpenLayers Dev mailing list archive at Nabble.com.

More information about the Dev mailing list