Enables unselecting selected features by clicking outside any feature. This is the default mode of the modify feature control. If you want to use the old mode where a click on a selected feature unselects that feature, set the toggle option to true. If you really want the old mode and not have selected features be unselected when clicking outside any feature, set the clickout option to false. The patch also adds the properties toggleKey and multipleKey to the modify feature control. With these one can temporarily enable the toggle and multiple mode, respectively. See the select-feature.html example to see all this in action. Thanks to pvalsecc and tschaub for the great colloration on this. (closes #1137)
git-svn-id: http://svn.openlayers.org/trunk/openlayers@5506 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
@@ -15,12 +15,40 @@
|
||||
*/
|
||||
OpenLayers.Control.SelectFeature = OpenLayers.Class(OpenLayers.Control, {
|
||||
|
||||
/**
|
||||
* Property: multipleKey
|
||||
* {String} An event modifier ('altKey' or 'shiftKey') that temporarily sets
|
||||
* the <multiple> property to true. Default is null.
|
||||
*/
|
||||
multipleKey: null,
|
||||
|
||||
/**
|
||||
* Property: toggleKey
|
||||
* {String} An event modifier ('altKey' or 'shiftKey') that temporarily sets
|
||||
* the <toggle> property to true. Default is null.
|
||||
*/
|
||||
toggleKey: null,
|
||||
|
||||
/**
|
||||
* APIProperty: multiple
|
||||
* {Boolean} Allow selection of multiple geometries
|
||||
* {Boolean} Allow selection of multiple geometries. Default is false.
|
||||
*/
|
||||
multiple: false,
|
||||
|
||||
/**
|
||||
* APIProperty: clickout
|
||||
* {Boolean} Unselect features when clicking outside any feature.
|
||||
* Default is true.
|
||||
*/
|
||||
clickout: true,
|
||||
|
||||
/**
|
||||
* APIProperty: toggle
|
||||
* {Boolean} Unselect a selected feature on click. Default is false. Only
|
||||
* has meaning if hover is false.
|
||||
*/
|
||||
toggle: false,
|
||||
|
||||
/**
|
||||
* APIProperty: hover
|
||||
* {Boolean} Select on mouse over and deselect on mouse out. If true, this
|
||||
@@ -85,18 +113,31 @@ OpenLayers.Control.SelectFeature = OpenLayers.Class(OpenLayers.Control, {
|
||||
this.layer = layer;
|
||||
this.callbacks = OpenLayers.Util.extend({
|
||||
click: this.clickFeature,
|
||||
clickout: this.clickoutFeature,
|
||||
over: this.overFeature,
|
||||
out: this.outFeature
|
||||
}, this.callbacks);
|
||||
var handlerOptions = {geometryTypes: this.geometryTypes};
|
||||
var handlerOptions = { geometryTypes: this.geometryTypes};
|
||||
this.handler = new OpenLayers.Handler.Feature(this, layer,
|
||||
this.callbacks,
|
||||
handlerOptions);
|
||||
},
|
||||
|
||||
/**
|
||||
* Method: unselectAll
|
||||
* Unselect all selected features.
|
||||
*/
|
||||
unselectAll: function() {
|
||||
// we'll want an option to supress notification here
|
||||
while (this.layer.selectedFeatures.length > 0) {
|
||||
this.unselect(this.layer.selectedFeatures[0]);
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Method: clickFeature
|
||||
* Called when the feature handler detects a click on a feature
|
||||
* Called on click in a feature
|
||||
* Only responds if this.hover is false.
|
||||
*
|
||||
* Parameters:
|
||||
* feature - {<OpenLayers.Vector.Feature>}
|
||||
@@ -105,56 +146,66 @@ OpenLayers.Control.SelectFeature = OpenLayers.Class(OpenLayers.Control, {
|
||||
if(this.hover) {
|
||||
return;
|
||||
}
|
||||
if (this.multiple) {
|
||||
if(OpenLayers.Util.indexOf(this.layer.selectedFeatures, feature) > -1) {
|
||||
var selected = (OpenLayers.Util.indexOf(this.layer.selectedFeatures,
|
||||
feature) > -1);
|
||||
if(!this.multiple && !this.handler.evt[this.multipleKey]) {
|
||||
// perhaps an "except" argument
|
||||
this.unselectAll();
|
||||
}
|
||||
if(selected) {
|
||||
if(this.toggle || this.handler.evt[this.toggleKey]) {
|
||||
// notify here
|
||||
this.unselect(feature);
|
||||
} else {
|
||||
// don't notify here - could be removed if unselectAll is modified
|
||||
this.select(feature);
|
||||
}
|
||||
} else {
|
||||
if(OpenLayers.Util.indexOf(this.layer.selectedFeatures, feature) > -1) {
|
||||
this.unselect(feature);
|
||||
} else {
|
||||
if (this.layer.selectedFeatures) {
|
||||
for (var i = 0; i < this.layer.selectedFeatures.length; i++) {
|
||||
this.unselect(this.layer.selectedFeatures[i]);
|
||||
}
|
||||
}
|
||||
this.select(feature);
|
||||
}
|
||||
this.select(feature);
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Method: clickoutFeature
|
||||
* Called on click outside a previously clicked (selected) feature.
|
||||
* Only responds if this.hover is false.
|
||||
*
|
||||
* Parameters:
|
||||
* feature - {<OpenLayers.Vector.Feature>}
|
||||
*/
|
||||
clickoutFeature: function(feature) {
|
||||
if(!this.hover && this.clickout) {
|
||||
this.unselectAll();
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Method: overFeature
|
||||
* Called when the feature handler detects a mouse-over on a feature.
|
||||
* Called on over a feature.
|
||||
* Only responds if this.hover is true.
|
||||
*
|
||||
* Parameters:
|
||||
* feature - {<OpenLayers.Feature.Vector>}
|
||||
*/
|
||||
overFeature: function(feature) {
|
||||
if(!this.hover) {
|
||||
return;
|
||||
}
|
||||
if(!(OpenLayers.Util.indexOf(this.layer.selectedFeatures, feature) > -1)) {
|
||||
if(this.hover &&
|
||||
(OpenLayers.Util.indexOf(this.layer.selectedFeatures, feature) == -1)) {
|
||||
this.select(feature);
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Method: outFeature
|
||||
* Called when the feature handler detects a mouse-out on a feature.
|
||||
* Called on out of a selected feature.
|
||||
* Only responds if this.hover is true.
|
||||
*
|
||||
* Parameters:
|
||||
* feature - {<OpenLayers.Feature.Vector>}
|
||||
*/
|
||||
outFeature: function(feature) {
|
||||
if(!this.hover) {
|
||||
return;
|
||||
if(this.hover) {
|
||||
this.unselect(feature);
|
||||
}
|
||||
this.unselect(feature);
|
||||
},
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user