OpenLayers OpenLayers

Changeset 4053

Show
Ignore:
Timestamp:
08/27/07 11:54:57 (1 year ago)
Author:
euzuro
Message:

add removeLayer() function to Layers... implement it for EventPane so that it removes the extra 'pane' div when the layer is removed. (Closes #887)

Files:

Legend:

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

    r4051 r4053  
    420420     
    421421    /** 
     422     * APIMethod: removeMap 
     423     * Just as setMap() allows each layer the possibility to take a  
     424     *     personalized action on being added to the map, removeMap() allows 
     425     *     each layer to take a personalized action on being removed from it.  
     426     *     For now, this will be mostly unused, except for the EventPane layer, 
     427     *     which needs this hook so that it can remove the special invisible 
     428     *     pane.  
     429     *  
     430     * Parameters: 
     431     * map - {<OpenLayers.Map>} 
     432     */ 
     433    removeMap: function(map) { 
     434        //to be overridden by subclasses 
     435    }, 
     436     
     437    /** 
    422438     * APIMethod: getImageSize 
    423439     *  
  • trunk/openlayers/lib/OpenLayers/Layer/EventPane.js

    r3984 r4053  
    105105        } 
    106106    }, 
     107 
     108    /** 
     109     * APIMethod: removeMap 
     110     * On being removed from the map, we'll like to remove the invisible 'pane' 
     111     *     div that we added to it on creation.  
     112     *  
     113     * Parameters: 
     114     * map - {<OpenLayers.Map>} 
     115     */ 
     116    removeMap: function(map) { 
     117        if (this.pane && this.pane.parentNode) { 
     118            this.pane.parentNode.removeChild(this.pane); 
     119            this.pane = null; 
     120        } 
     121        OpenLayers.Layer.prototype.removeMap.apply(this, arguments); 
     122    }, 
    107123   
    108124    /** 
  • trunk/openlayers/lib/OpenLayers/Map.js

    r3984 r4053  
    567567            this.layerContainerDiv.removeChild(layer.div); 
    568568        } 
     569        OpenLayers.Util.removeItem(this.layers, layer); 
     570        layer.removeMap(this); 
    569571        layer.map = null; 
    570         OpenLayers.Util.removeItem(this.layers, layer); 
    571572 
    572573        // if we removed the base layer, need to set a new one 
  • trunk/openlayers/tests/Layer/test_EventPane.html

    r3814 r4053  
    106106        t.eq(layer.visibility, true, "layer pane is now visible"); 
    107107    } 
     108 
     109     
     110    function test_Layer_EventPane_removeLayer(t) { 
     111        t.plan(1); 
     112        var map = new OpenLayers.Map('map'); 
     113         
     114        layer = new OpenLayers.Layer.EventPane('Test Layer'); 
     115        layer.loadMapObject = function() { }; 
     116        layer.getWarningHTML = function() { this.warning = true; return ""; }; 
     117        map.addLayer(layer); 
     118        map.removeLayer(layer); 
     119        t.eq(layer.pane, null, "Layer.pane is null after being removed."); 
     120   }       
     121 
    108122  // --> 
    109123  </script>