OpenLayers OpenLayers

Changeset 5555

Show
Ignore:
Timestamp:
12/21/07 03:48:08 (1 year ago)
Author:
tschaub
Message:

Making feature handler call over and out callbacks just once per mouseover and mouseout (of a feature). r=elemoine (closes #1226)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/openlayers/lib/OpenLayers/Handler/Feature.js

    r5553 r5555  
    3434    /** 
    3535     * Property: feature 
     36     * {<OpenLayers.Feature.Vector>} The feature currently being handled. 
     37     */ 
     38    feature: null, 
     39 
     40    /** 
     41     * Property: lastFeature 
    3642     * {<OpenLayers.Feature.Vector>} The last feature that was handled. 
    3743     */ 
    38     feature: null, 
     44    lastFeature: null, 
    3945 
    4046    /** 
     
    134140    /** 
    135141     * Method: mousemove 
    136      * Handle mouse moves.  Call the "over" callback if move over a feature, 
    137      *     or the "out" callback if move outside any feature. 
     142     * Handle mouse moves.  Call the "over" callback if moving in to a feature, 
     143     *     or the "out" callback if moving out of a feature. 
    138144     *  
    139145     * Parameters: 
     
    191197        var type = evt.type; 
    192198        var stopEvtPropag = false; 
    193         var lastFeature = this.feature; 
    194         var feature = this.layer.getFeatureFromEvent(evt); 
    195         if(feature) { 
    196             if(this.geometryTypeMatches(feature)) { 
    197                 if(lastFeature && (lastFeature != feature)) { 
    198                     // out of last feature 
    199                     this.triggerCallback(type, 'out', [lastFeature]); 
     199        var previouslyIn = !!(this.feature); // previously in a feature 
     200        var click = (type == "click" || type == "dblclick"); 
     201        this.feature = this.layer.getFeatureFromEvent(evt); 
     202        if(this.feature) { 
     203            var inNew = (this.feature != this.lastFeature); 
     204            if(this.geometryTypeMatches(this.feature)) { 
     205                // in to a feature 
     206                if(previouslyIn && inNew) { 
     207                    // out of last feature and in to another 
     208                    this.triggerCallback(type, 'out', [this.lastFeature]); 
     209                    this.triggerCallback(type, 'in', [this.feature]); 
     210                } else if(!previouslyIn || click) { 
     211                    // in feature for the first time 
     212                    this.triggerCallback(type, 'in', [this.feature]); 
    200213                } 
    201                 this.triggerCallback(type, 'in', [feature]); 
    202                 lastFeature = feature; 
    203214                stopEvtPropag = true; 
    204215            } else { 
    205                 if(lastFeature && (lastFeature != feature)) { 
    206                     // out of last feature 
    207                     this.triggerCallback(type, 'out', [lastFeature]); 
    208                     lastFeature = feature
     216                // not in to a feature 
     217                if(previouslyIn && inNew || (click && this.lastFeature)) { 
     218                    // out of last feature for the first time 
     219                    this.triggerCallback(type, 'out', [this.lastFeature])
    209220                } 
    210221            } 
     222            this.lastFeature = this.feature; 
    211223        } else { 
    212             if(lastFeature) { 
    213                 this.triggerCallback(type, 'out', [lastFeature]); 
    214                 lastFeature = null; 
    215             } 
    216         } 
    217         if(lastFeature) { 
    218             this.feature = lastFeature; 
     224            if(previouslyIn || (click && this.lastFeature)) { 
     225                this.triggerCallback(type, 'out', [this.lastFeature]); 
     226            } 
    219227        } 
    220228        return stopEvtPropag; 
     
    278286            } 
    279287            this.feature = null; 
     288            this.lastFeature = null; 
    280289            this.down = null; 
    281290            this.up = null;