[OpenLayers-Trac] [OpenLayers] #3041: event after selection with box
OpenLayers
trac-20090302 at openlayers.org
Fri Feb 4 07:42:06 EST 2011
#3041: event after selection with box
---------------------+------------------------------------------------------
Reporter: travin | Owner:
Type: feature | Status: new
Priority: minor | Milestone: 2.11 Release
Component: general | Version: 2.10
Keywords: | State:
---------------------+------------------------------------------------------
I'm using following feature:
{{{
new OpenLayers.Control.SelectFeature(wfsLayer, {
box: true
});
}}}
When I select features with a box, I can wait for the 'featureselected'
event, but in my case I need an event triggered when all feateres in the
box have been selected. So I added the following event to
OpenLayers.Layer.Vector:
'allfeaturesselectedwithbox'. I pass the following object to the event:
{{{
{
features: //all selected features of the layer
}
}}}
I needed two code changes for this:
1: I added the event to EVENT_TYPES
2: in changed the method selectBox
{{{
selectBox: function(position) {
if (position instanceof OpenLayers.Bounds) {
var minXY = this.map.getLonLatFromPixel(
new OpenLayers.Pixel(position.left, position.bottom)
);
var maxXY = this.map.getLonLatFromPixel(
new OpenLayers.Pixel(position.right, position.top)
);
var bounds = new OpenLayers.Bounds(
minXY.lon, minXY.lat, maxXY.lon, maxXY.lat
);
// if multiple is false, first deselect currently selected
features
if (!this.multipleSelect()) {
this.unselectAll();
}
// because we're using a box, we consider we want multiple
selection
var prevMultiple = this.multiple;
this.multiple = true;
var layers = this.layers || [this.layer];
var layer;
for(var l=0; l<layers.length; ++l) {
layer = layers[l];
for(var i=0, len = layer.features.length; i<len; ++i) {
var feature = layer.features[i];
// check if the feature is displayed
if (!feature.getVisibility()) {
continue;
}
if (this.geometryTypes == null ||
OpenLayers.Util.indexOf(
this.geometryTypes,
feature.geometry.CLASS_NAME) > -1) {
if
(bounds.toGeometry().intersects(feature.geometry)) {
if
(OpenLayers.Util.indexOf(layer.selectedFeatures, feature) == -1) {
this.select(feature);
}
}
}
}
// MY FIX
layer.events.triggerEvent("allfeaturesselectedwithbox", {
features: layer.selectedFeatures
});
// END MY FIX
}
this.multiple = prevMultiple;
}
}
}}}
It's an easy feature, but I thought it could be useful for other
developers.
--
Ticket URL: <http://trac.openlayers.org/ticket/3041>
OpenLayers <http://openlayers.org/>
A free AJAX map viewer
More information about the Trac
mailing list