OpenLayers OpenLayers

Changeset 7682

Show
Ignore:
Timestamp:
08/02/08 22:06:31 (4 months ago)
Author:
crschmidt
Message:

Fix for Feature handler uses getFeatureFromEvent on mousemove even without
hover callbacks; r=ahocevar (Closes #1655)

This means that On the SelectFeature control hover can no longer be set on the
SelectFeature control after the control has been initialized: must be passed at
initialize time. Example has been updated.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/openlayers/examples/select-feature.html

    r7589 r7682  
    2424            map.addLayers([wmsLayer, vectors]); 
    2525            map.addControl(new OpenLayers.Control.LayerSwitcher()); 
    26             map.addControl(new OpenLayers.Control.MousePosition()); 
    2726             
    2827            drawControls = { 
     
    4443                        multipleKey: "shiftKey", // shift key adds to selection 
    4544                        box: true 
     45                    } 
     46                ), 
     47                selecthover: new OpenLayers.Control.SelectFeature( 
     48                    vectors, 
     49                    { 
     50                        multiple: false, hover: true, 
     51                        toggleKey: "ctrlKey", // ctrl key removes from selection 
     52                        multipleKey: "shiftKey" // shift key adds to selection 
    4653                    } 
    4754                ) 
     
    108115        </li> 
    109116        <li> 
     117            <input type="radio" name="type" value="selecthover" id="selecthoverToggle" 
     118                   onclick="toggleControl(this);" /> 
     119            <label for="selecthoverToggle">Select features on hover</label> 
     120        </li> 
     121        <li> 
    110122            <input type="radio" name="type" value="select" id="selectToggle" 
    111123                   onclick="toggleControl(this);" /> 
     
    122134                    <label for="clickout">click out to unselect features</label> 
    123135                </li> 
    124                 <li> 
    125                     <input id="hover" type="checkbox" 
    126                            name="hover" onchange="update()" /> 
    127                     <label for="hover">hover to select features</label> 
    128                 </li> 
    129136            </ul> 
    130137        </li> 
  • trunk/openlayers/lib/OpenLayers/Control/SelectFeature.js

    r7616 r7682  
    129129        OpenLayers.Control.prototype.initialize.apply(this, [options]); 
    130130        this.layer = layer; 
    131         this.callbacks = OpenLayers.Util.extend({ 
    132                                                   click: this.clickFeature, 
    133                                                   clickout: this.clickoutFeature, 
    134                                                   over: this.overFeature, 
    135                                                   out: this.outFeature 
    136                                                 }, this.callbacks); 
     131        var callbacks = { 
     132            click: this.clickFeature, 
     133            clickout: this.clickoutFeature 
     134        }; 
     135        if (this.hover) { 
     136            callbacks.over = this.overFeature; 
     137            callbacks.out = this.outFeature; 
     138        } 
     139              
     140        this.callbacks = OpenLayers.Util.extend(callbacks, this.callbacks); 
    137141        this.handlers = { 
    138142            feature: new OpenLayers.Handler.Feature( 
  • trunk/openlayers/lib/OpenLayers/Handler/Feature.js

    r6564 r7682  
    177177     */ 
    178178    mousemove: function(evt) { 
     179        if (!this.callbacks['over'] && !this.callbacks['out']) { 
     180            return false; 
     181        }      
    179182        this.handle(evt); 
    180183        return true; 
  • trunk/openlayers/tests/Handler/Feature.html

    r6719 r7682  
    178178        map.events.triggerEvent('click', evtPx); 
    179179 
     180        layer.getFeatureFromEvent = function(evt) { t.fail("mousemove called getFeatureFromEvent without any mousemove callbacks"); }; 
     181        evtPx.type = "mousemove"; 
     182        map.events.triggerEvent('mousemove', evtPx); 
     183        layer.getFeatureFromEvent = function(evt) { return newFeature; }; 
     184         
    180185        // test over a new feature 
    181186        // only 'over' callback should be called