OpenLayers OpenLayers

Ticket #742: controlGetRemove.2.patch

File controlGetRemove.2.patch, 1.8 kB (added by euzuro, 1 year ago)

take two. removeControl() now takes a control instead of an id

  • tests/test_Map.html

    old new  
    431431        t.ok(foundDiv, "new control's div correctly added to viewPort"); 
    432432 
    433433    //remove control         
    434         map1.removeControl(control.id
     434        map1.removeControl(control
    435435        newNumControls = map1.controls.length; 
    436436        t.ok( newNumControls == oldNumControls, "removing the control decreases control count") 
    437437 
     
    448448        t.ok(!foundDiv, "control no longer child of viewPort"); 
    449449 
    450450    //remove bogus 
    451         map1.removeControl("bogus id"); 
     451        control = { id: "bogus id" }; 
     452        map1.removeControl(control); 
    452453        newNumControls = map1.controls.length; 
    453454        t.ok( newNumControls == oldNumControls, "removing bad controlid doesnt crash or decrease control count") 
    454455    } 
  • lib/OpenLayers/Map.js

    old new  
    621621     *   object's internal array of controls, as well as from the map's  
    622622     *   viewPort (assuming the control was not added outsideViewport) 
    623623     *  
    624      * @param {String} id ID of the control to remove 
     624     * @param {OpenLayers.Control} control control to remove 
    625625     */     
    626     removeControl: function (id) { 
    627         var control = this.getControl(id); 
    628         if (control) { 
     626    removeControl: function (control) { 
     627        //make sure control is non-null and actually part of our map 
     628        if ( (control) && (control == this.getControl(control.id)) ) { 
    629629            if (!control.outsideViewport) { 
    630630                this.viewPortDiv.removeChild(control.div) 
    631631            }