[OpenLayers-Dev] SelectFeature and last/prevHighlighter

Slawomir Messner slawomir.messner at staff.uni-marburg.de
Mon May 9 08:52:10 EDT 2011


Hi,
I have a question. In the unhighlight function if another SelectFeature 
was the prevHighlighter it is set to the lastHighlighter but then the 
feature is simply redraw with it's own style/layer style or default 
renderIntent. Shouldn't this be only in the first to cases of the 
if-stmt? in the third like in outFeature that the highlight of the "new" 
lastHighlighter is used?
Here the code I'm talking about(Without the comments in it):

     unhighlight: function(feature) {
         var layer = feature.layer;
         if(feature._prevHighlighter == undefined) {
             delete feature._lastHighlighter;
         } else if(feature._prevHighlighter == this.id) {
             delete feature._prevHighlighter;
         } else {
             feature._lastHighlighter = feature._prevHighlighter;
             delete feature._prevHighlighter;
         }
          layer.drawFeature(feature, feature.style || feature.layer.style ||
                 "default");
         this.events.triggerEvent("featureunhighlighted", {feature : 
feature});
     },

Now how I think it should be:

unhighlight: function(feature) {
         var layer = feature.layer;
     var newHighlighter = null;
         if(feature._prevHighlighter == undefined) {
             delete feature._lastHighlighter;
         } else if(feature._prevHighlighter == this.id) {
             delete feature._prevHighlighter;
         } else {
             feature._lastHighlighter = feature._prevHighlighter;
             delete feature._prevHighlighter;
             newHighlighter = this.map.getControl(feature._lastHighlighter);
         }
         if(newHighlighter != null) {
             newHighlighter.highlight(feature);
         } else {
             layer.drawFeature(feature, feature.style || 
feature.layer.style ||
                 "default");
             this.events.triggerEvent("featureunhighlighted", {feature : 
feature});
         }
},
When I look at the code of highlight the "featureunhighlighted" should 
always thrown to a symmetric behavior of un-/highlight or the 
"featurehighlighted" event should only be triggered in the highlight 
when there was no _lastHighlighter.
Regards
Slawomir


More information about the Dev mailing list