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:
@@ -66,6 +66,16 @@ OpenLayers.Control.GetFeature = OpenLayers.Class(OpenLayers.Control, {
|
|||||||
*/
|
*/
|
||||||
click: 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
|
* APIProperty: clickout
|
||||||
* {Boolean} Unselect features when clicking outside any feature.
|
* {Boolean} Unselect features when clicking outside any feature.
|
||||||
@@ -98,7 +108,11 @@ OpenLayers.Control.GetFeature = OpenLayers.Class(OpenLayers.Control, {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* APIProperty: box
|
* 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,
|
box: false,
|
||||||
|
|
||||||
@@ -211,7 +225,7 @@ OpenLayers.Control.GetFeature = OpenLayers.Class(OpenLayers.Control, {
|
|||||||
|
|
||||||
if(this.click) {
|
if(this.click) {
|
||||||
this.handlers.click = new OpenLayers.Handler.Click(this,
|
this.handlers.click = new OpenLayers.Handler.Click(this,
|
||||||
{click: this.selectSingle}, this.handlerOptions.click || {});
|
{click: this.selectClick}, this.handlerOptions.click || {});
|
||||||
}
|
}
|
||||||
|
|
||||||
if(this.box) {
|
if(this.box) {
|
||||||
@@ -270,20 +284,20 @@ OpenLayers.Control.GetFeature = OpenLayers.Class(OpenLayers.Control, {
|
|||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method: selectSingle
|
* Method: selectClick
|
||||||
* Called on click
|
* Called on click
|
||||||
*
|
*
|
||||||
* Parameters:
|
* Parameters:
|
||||||
* evt - {<OpenLayers.Event>}
|
* evt - {<OpenLayers.Event>}
|
||||||
*/
|
*/
|
||||||
selectSingle: function(evt) {
|
selectClick: function(evt) {
|
||||||
// Set the cursor to "wait" to tell the user we're working on their click.
|
// Set the cursor to "wait" to tell the user we're working on their click.
|
||||||
OpenLayers.Element.addClass(this.map.viewPortDiv, "olCursorWait");
|
OpenLayers.Element.addClass(this.map.viewPortDiv, "olCursorWait");
|
||||||
|
|
||||||
var bounds = this.pixelToBounds(evt.xy);
|
var bounds = this.pixelToBounds(evt.xy);
|
||||||
|
|
||||||
this.setModifiers(evt);
|
this.setModifiers(evt);
|
||||||
this.request(bounds, {single: true});
|
this.request(bounds, {single: this.single});
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -22,7 +22,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
function test_Control_GetFeature_select(t) {
|
function test_Control_GetFeature_select(t) {
|
||||||
t.plan(5);
|
t.plan(6);
|
||||||
var map = new OpenLayers.Map("map");
|
var map = new OpenLayers.Map("map");
|
||||||
var layer = new OpenLayers.Layer.WMS("foo", "wms", {
|
var layer = new OpenLayers.Layer.WMS("foo", "wms", {
|
||||||
layers: "foo"
|
layers: "foo"
|
||||||
@@ -49,7 +49,7 @@
|
|||||||
t.eq(evt.feature.id, feature1.id, "featureselected callback called with closest feature");
|
t.eq(evt.feature.id, feature1.id, "featureselected callback called with closest feature");
|
||||||
}
|
}
|
||||||
control.events.register("featureselected", this, singleTest);
|
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);
|
control.events.unregister("featureselected", this, singleTest);
|
||||||
|
|
||||||
var count = 0;
|
var count = 0;
|
||||||
@@ -78,6 +78,15 @@
|
|||||||
control.events.unregister("featuresselected", this, featuresSelected);
|
control.events.unregister("featuresselected", this, featuresSelected);
|
||||||
t.eq(features.length, 2, "2 features inside box selected");
|
t.eq(features.length, 2, "2 features inside box selected");
|
||||||
t.eq(features[1].id, feature2.id, "featureselected callback called with multiple features");
|
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) {
|
function test_Control_GetFeature_hover(t) {
|
||||||
|
|||||||
Reference in New Issue
Block a user