From 8b0712bb24b68c550f6a5c8504c905e151659462 Mon Sep 17 00:00:00 2001 From: pgiraud Date: Fri, 28 May 2010 08:54:39 +0000 Subject: [PATCH] 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 --- lib/OpenLayers/Control/GetFeature.js | 24 +++++++++++++++++++----- tests/Control/GetFeature.html | 15 ++++++++++++--- 2 files changed, 31 insertions(+), 8 deletions(-) diff --git a/lib/OpenLayers/Control/GetFeature.js b/lib/OpenLayers/Control/GetFeature.js index 91c7a71abf..1b4482a6e8 100644 --- a/lib/OpenLayers/Control/GetFeature.js +++ b/lib/OpenLayers/Control/GetFeature.js @@ -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 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 to false to disable the click handler and + * rely on the box handler only, even for "zero extent" boxes. + * See the description of the 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 - {} */ - 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}); }, /** diff --git a/tests/Control/GetFeature.html b/tests/Control/GetFeature.html index 70249cea77..c613f42fa9 100644 --- a/tests/Control/GetFeature.html +++ b/tests/Control/GetFeature.html @@ -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) {