added a single config option to allow several features as a result of a click (or 'zero extent' box), r=elemoine, (Closes #2643)

git-svn-id: http://svn.openlayers.org/trunk/openlayers@10361 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
pgiraud
2010-05-28 08:54:39 +00:00
parent 925b6fa206
commit 8b0712bb24
2 changed files with 31 additions and 8 deletions

View File

@@ -65,6 +65,16 @@ OpenLayers.Control.GetFeature = OpenLayers.Class(OpenLayers.Control, {
* selected. Default is true.
*/
click: true,
/**
* APIProperty: single
* {Boolean} Tells whether select by click should select a single
* feature. If set to false, all matching features are selected.
* If set to true, only the best matching feature is selected.
* This option has an effect only of the <click> option is set
* to true. Default is true.
*/
single: true,
/**
* APIProperty: clickout
@@ -98,7 +108,11 @@ OpenLayers.Control.GetFeature = OpenLayers.Class(OpenLayers.Control, {
/**
* APIProperty: box
* {Boolean} Allow feature selection by drawing a box.
* {Boolean} Allow feature selection by drawing a box. If set to
* true set <click> to false to disable the click handler and
* rely on the box handler only, even for "zero extent" boxes.
* See the description of the <click> option for additional
* information. Default is false.
*/
box: false,
@@ -211,7 +225,7 @@ OpenLayers.Control.GetFeature = OpenLayers.Class(OpenLayers.Control, {
if(this.click) {
this.handlers.click = new OpenLayers.Handler.Click(this,
{click: this.selectSingle}, this.handlerOptions.click || {});
{click: this.selectClick}, this.handlerOptions.click || {});
}
if(this.box) {
@@ -270,20 +284,20 @@ OpenLayers.Control.GetFeature = OpenLayers.Class(OpenLayers.Control, {
},
/**
* Method: selectSingle
* Method: selectClick
* Called on click
*
* Parameters:
* evt - {<OpenLayers.Event>}
*/
selectSingle: function(evt) {
selectClick: function(evt) {
// Set the cursor to "wait" to tell the user we're working on their click.
OpenLayers.Element.addClass(this.map.viewPortDiv, "olCursorWait");
var bounds = this.pixelToBounds(evt.xy);
this.setModifiers(evt);
this.request(bounds, {single: true});
this.request(bounds, {single: this.single});
},
/**

View File

@@ -22,7 +22,7 @@
}
function test_Control_GetFeature_select(t) {
t.plan(5);
t.plan(6);
var map = new OpenLayers.Map("map");
var layer = new OpenLayers.Layer.WMS("foo", "wms", {
layers: "foo"
@@ -49,9 +49,9 @@
t.eq(evt.feature.id, feature1.id, "featureselected callback called with closest feature");
}
control.events.register("featureselected", this, singleTest);
control.selectSingle({xy: new OpenLayers.Pixel(200, 125)});
control.selectClick({xy: new OpenLayers.Pixel(200, 125)});
control.events.unregister("featureselected", this, singleTest);
var count = 0;
var beforeFeatureSelected = function(evt) {
count++;
@@ -78,6 +78,15 @@
control.events.unregister("featuresselected", this, featuresSelected);
t.eq(features.length, 2, "2 features inside box selected");
t.eq(features[1].id, feature2.id, "featureselected callback called with multiple features");
// allow several features even for single click
control.single = false;
var multiplePointTest = function(evt) {
t.eq(evt.features.length, 3, "3 features passed to the featuresselected handler");
}
control.events.register("featuresselected", this, multiplePointTest);
control.selectClick({xy: new OpenLayers.Pixel(200, 125)});
control.events.unregister("featuresselected", this, multiplePointTest);
}
function test_Control_GetFeature_hover(t) {