[OpenLayers-Dev] SelectFeature and last/prevHighlighter

Eric Lemoine eric.lemoine at camptocamp.com
Mon May 9 12:03:29 EDT 2011


On Monday, May 9, 2011, Slawomir Messner
<slawomir.messner at staff.uni-marburg.de> wrote:
> 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.


Hi

I'd like to know your exact use-case (control1 does this, control2
does that, etc.). With that we should be able to write a test-case
demonstrating that the current code doesn't behave as expected.

Thanks for your effort on that. It's not trivial code.

-- 
Eric Lemoine

Camptocamp France SAS
Savoie Technolac, BP 352
73377 Le Bourget du Lac, Cedex

Tel : 00 33 4 79 44 44 96
Mail : eric.lemoine at camptocamp.com
http://www.camptocamp.com


More information about the Dev mailing list