Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SelectFeature should toggle features with box select #1444

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/OpenLayers/Control/SelectFeature.js
Original file line number Diff line number Diff line change
Expand Up @@ -592,6 +592,9 @@ OpenLayers.Control.SelectFeature = OpenLayers.Class(OpenLayers.Control, {
if (OpenLayers.Util.indexOf(layer.selectedFeatures, feature) == -1) {
this.select(feature);
}
else if (this.toggleSelect()) {
this.unselect(feature);
}
}
}
}
Expand Down
23 changes: 23 additions & 0 deletions tests/Control/SelectFeature.html
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,29 @@
t.ok(firesBoxselectionend,"selectBox fires boxselectionend event");
t.eq(afterSelectingNumberOfFeatures,1,"boxselectionend fires after feature selected");
}
function test_selectBox_toggle(t) {
t.plan(2);
var map = new OpenLayers.Map("map");
var layer1 = new OpenLayers.Layer.Vector();
map.addLayer(layer1);
map.setBaseLayer(layer1);
var layer2 = new OpenLayers.Layer.Vector();
map.addLayer(layer2);
map.setCenter(new OpenLayers.LonLat(1,1));
var feature = new OpenLayers.Feature.Vector(new OpenLayers.Geometry.Point(1,1));
layer1.addFeatures([feature]);
var control = new OpenLayers.Control.SelectFeature(layer1, {toggle: true, multiple: true});
control.setMap(map);
map.getLonLatFromPixel = function(arg) {
return new OpenLayers.LonLat(arg.x, arg.y);
};
control.activate();
var bounds = new OpenLayers.Bounds(-1,-1,2,2);
control.selectBox(bounds);
t.eq(layer1.selectedFeatures.length, 1, "selectBox toggles the selected item.");
control.selectBox(bounds);
t.eq(layer1.selectedFeatures.length, 0, "selectBox toggles the selected item.");
}
function test_Control_SelectFeature_activate(t) {
t.plan(4);
var map = new OpenLayers.Map("map");
Expand Down