SelectFeature now takes a hilightOnly config options, that way user can hover features without actually selecting
them, combining two differents controls will allow to separate hover and click events, patches from ahocevar, elemoine and pgiraud, reviewers are ahocevar, elemoine and pgiraud git-svn-id: http://svn.openlayers.org/trunk/openlayers@9176 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
@@ -19,6 +19,16 @@
|
||||
* - <OpenLayers.Control>
|
||||
*/
|
||||
OpenLayers.Control.SelectFeature = OpenLayers.Class(OpenLayers.Control, {
|
||||
|
||||
/**
|
||||
* Constant: EVENT_TYPES
|
||||
*
|
||||
* Supported event types:
|
||||
* - *beforefeaturehighlighted* Triggered before a feature is highlighted
|
||||
* - *featurehighlighted* Triggered when a feature is highlighted
|
||||
* - *featureunhighlighted* Triggered when a feature is unhighlighted
|
||||
*/
|
||||
EVENT_TYPES: ["beforefeaturehighlighted", "featurehighlighted", "featureunhighlighted"],
|
||||
|
||||
/**
|
||||
* Property: multipleKey
|
||||
@@ -60,6 +70,14 @@ OpenLayers.Control.SelectFeature = OpenLayers.Class(OpenLayers.Control, {
|
||||
* ignores clicks and only listens to mouse moves.
|
||||
*/
|
||||
hover: false,
|
||||
|
||||
/**
|
||||
* APIProperty: highlightOnly
|
||||
* {Boolean} If true do not actually select features (i.e. place them in the
|
||||
* layer's selected features array), just highlight them. This property has
|
||||
* no effect if hover is false. Defaults to false.
|
||||
*/
|
||||
highlightOnly: false,
|
||||
|
||||
/**
|
||||
* APIProperty: box
|
||||
@@ -150,6 +168,11 @@ OpenLayers.Control.SelectFeature = OpenLayers.Class(OpenLayers.Control, {
|
||||
* options - {Object}
|
||||
*/
|
||||
initialize: function(layers, options) {
|
||||
// concatenate events specific to this control with those from the base
|
||||
this.EVENT_TYPES =
|
||||
OpenLayers.Control.SelectFeature.prototype.EVENT_TYPES.concat(
|
||||
OpenLayers.Control.prototype.EVENT_TYPES
|
||||
);
|
||||
OpenLayers.Control.prototype.initialize.apply(this, [options]);
|
||||
if(!(layers instanceof Array)) {
|
||||
layers = [layers];
|
||||
@@ -331,9 +354,14 @@ OpenLayers.Control.SelectFeature = OpenLayers.Class(OpenLayers.Control, {
|
||||
* feature - {<OpenLayers.Feature.Vector>}
|
||||
*/
|
||||
overFeature: function(feature) {
|
||||
if(this.hover &&
|
||||
(OpenLayers.Util.indexOf(feature.layer.selectedFeatures, feature) == -1)) {
|
||||
this.select(feature);
|
||||
var layer = feature.layer;
|
||||
if(this.hover) {
|
||||
if(this.highlightOnly) {
|
||||
this.highlight(feature);
|
||||
} else if(OpenLayers.Util.indexOf(
|
||||
layer.selectedFeatures, feature) == -1) {
|
||||
this.select(feature);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
@@ -347,9 +375,68 @@ OpenLayers.Control.SelectFeature = OpenLayers.Class(OpenLayers.Control, {
|
||||
*/
|
||||
outFeature: function(feature) {
|
||||
if(this.hover) {
|
||||
this.unselect(feature);
|
||||
if(this.highlightOnly) {
|
||||
// we do nothing if we're not the last highlighter of the
|
||||
// feature
|
||||
if(feature._lastHighlighter == this.id) {
|
||||
// if another select control had highlighted the feature before
|
||||
// we did it ourself then we use that control to highlight the
|
||||
// feature as it was before we highlighted it, else we just
|
||||
// unhighlight it
|
||||
if(feature._prevHighlighter &&
|
||||
feature._prevHighlighter != this.id) {
|
||||
delete feature._lastHighlighter;
|
||||
var control = this.map.getControl(
|
||||
feature._prevHighlighter);
|
||||
if(control) {
|
||||
control.highlight(feature);
|
||||
}
|
||||
} else {
|
||||
this.unhighlight(feature);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
this.unselect(feature);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Method: highlight
|
||||
* Redraw feature with the select style.
|
||||
*
|
||||
* Parameters:
|
||||
* feature - {<OpenLayers.Feature.Vector>}
|
||||
*/
|
||||
highlight: function(feature) {
|
||||
var layer = feature.layer;
|
||||
var cont = this.events.triggerEvent("beforefeaturehighlighted", {
|
||||
feature : feature
|
||||
});
|
||||
if(cont !== false) {
|
||||
feature._prevHighlighter = feature._lastHighlighter;
|
||||
feature._lastHighlighter = this.id;
|
||||
var style = this.selectStyle || this.renderIntent;
|
||||
layer.drawFeature(feature, style);
|
||||
this.events.triggerEvent("featurehighlighted", {feature : feature});
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Method: unhighlight
|
||||
* Redraw feature with the "default" style
|
||||
*
|
||||
* Parameters:
|
||||
* feature - {<OpenLayers.Feature.Vector>}
|
||||
*/
|
||||
unhighlight: function(feature) {
|
||||
var layer = feature.layer;
|
||||
feature._lastHighlighter = feature._prevHighlighter;
|
||||
delete feature._prevHighlighter;
|
||||
layer.drawFeature(feature, feature.style || feature.layer.style ||
|
||||
"default");
|
||||
this.events.triggerEvent("featureunhighlighted", {feature : feature});
|
||||
},
|
||||
|
||||
/**
|
||||
* Method: select
|
||||
@@ -369,10 +456,7 @@ OpenLayers.Control.SelectFeature = OpenLayers.Class(OpenLayers.Control, {
|
||||
if(cont !== false) {
|
||||
layer.selectedFeatures.push(feature);
|
||||
this.layerData = {};
|
||||
|
||||
var selectStyle = this.selectStyle || this.renderIntent;
|
||||
|
||||
layer.drawFeature(feature, selectStyle);
|
||||
this.highlight(feature);
|
||||
layer.events.triggerEvent("featureselected", {feature: feature});
|
||||
this.onSelect.call(this.scope, feature);
|
||||
}
|
||||
@@ -390,7 +474,7 @@ OpenLayers.Control.SelectFeature = OpenLayers.Class(OpenLayers.Control, {
|
||||
unselect: function(feature) {
|
||||
var layer = feature.layer;
|
||||
// Store feature style for restoration later
|
||||
layer.drawFeature(feature, "default");
|
||||
this.unhighlight(feature);
|
||||
OpenLayers.Util.removeItem(layer.selectedFeatures, feature);
|
||||
layer.events.triggerEvent("featureunselected", {feature: feature});
|
||||
this.onUnselect.call(this.scope, feature);
|
||||
|
||||
Reference in New Issue
Block a user