OpenLayers OpenLayers

Ticket #549: clearMapDiv.patch

File clearMapDiv.patch, 5.1 kB (added by euzuro, 2 years ago)

this patch clears the div on map destroy, adds a test for that to the map test, and adds calls to map.destroy() in some test files to help them pass correctly in Opera. according to my tests, this fixes the markers and overviewmap tests in opera, though the wms test is still failing mysteriously.

  • tests/test_Map.html

    old new  
    318318 
    319319     
    320320    function test_99_Map_destroy (t) { 
    321         t.plan( 2 );     
     321        t.plan( 3 );     
    322322        map = new OpenLayers.Map('map'); 
    323323        map.destroy(); 
    324324        t.eq( map.layers, null, "map.layers is null after destroy" ); 
    325325        t.eq( map.controls, null, "map.controls is null after destroy" ); 
     326        t.eq( map.div.innerHTML, "", "map's div cleared out"); 
    326327    } 
    327328  // --> 
    328329  </script> 
  • tests/Control/test_OverviewMap.html

    old new  
    2121        t.eq( parseInt(control.div.style.zIndex), map.Z_INDEX_BASE['Control'] + 4, "Control div zIndexed properly" ); 
    2222        t.eq( parseInt(map.viewPortDiv.lastChild.style.zIndex), map.Z_INDEX_BASE['Control'] + 4, "Viewport div contains control div" ); 
    2323 
     24        map.destroy(); 
    2425    } 
    2526    function test_03_Control_PanZoom_control_events (t) { 
    2627        t.plan( 10 ); 
     
    6465        t.eq(overviewCenter.lat, 0, "Overviewmap center lat correct -- second zoom"); 
    6566        t.eq(overviewZoom, 0, "Overviewmap zoomcorrect -- second zoom"); 
    6667         
     68        map.destroy(); 
    6769 
    6870    } 
    6971  // --> 
  • tests/test_Marker.html

    old new  
    4242        mlayer.addMarker(marker2); 
    4343 
    4444        t.ok( !marker2.onScreen(), "marker knows it's offscreen" ); 
    45          
     45        map.destroy(); 
    4646    } 
    4747 
    4848    function test_03_Marker_setOpacity(t) { 
     
    7070        marker.setOpacity(0.5); 
    7171 
    7272        t.eq(parseFloat(marker.icon.imageDiv.style.opacity), 0.5, "marker.setOpacity() works"); 
     73        map.destroy(); 
    7374    } 
    7475    function test_04_Marker_moveTo(t) { 
    7576        t.plan( 6 ); 
     
    101102        marker.moveTo(new OpenLayers.Pixel(0,0)); 
    102103        t.eq(marker.lonlat.lon, map.getExtent().left, "on left edge of map");  
    103104        t.eq(marker.lonlat.lat, map.getExtent().top, "on top edge of map");  
     105        map.destroy(); 
    104106     
    105107    } 
    106108 
  • tests/Layer/test_WMS.html

    old new  
    6262             url + "?" + OpenLayers.Util.getParameterString(tParams), 
    6363             "div first child is correct image object" ); 
    6464        t.eq( tile.position.toString(), "x=5,y=6", "Position of tile is set correctly." ); 
     65        map.destroy(); 
    6566    } 
    6667     
    6768    function test_03_Layer_WMS_inittiles (t) { 
     
    7273        map.setCenter(new OpenLayers.LonLat(0,0),5); 
    7374        t.eq( layer.grid.length, 7, "Grid rows is correct." ); 
    7475        t.eq( layer.grid[0].length, 6, "Grid cols is correct." ); 
    75          
     76        map.destroy(); 
    7677    } 
    7778 
    7879 
     
    101102        t.eq( clone.alpha, layer.alpha, "alpha copied correctly"); 
    102103 
    103104        layer.grid = null; 
     105        map.destroy(); 
    104106    } 
    105107 
    106108    function test_05_Layer_WMS_isBaseLayer(t) { 
     
    142144        newParams.CHICKPEAS = 151; 
    143145 
    144146        t.eq( layer.params.CHICKPEAS, "image/png", "mergeNewParams() makes clean copy of hashtable"); 
     147        map.destroy(); 
    145148    } 
    146149 
    147150    function test_07_Layer_WMS_getFullRequestString (t) { 
     
    171174        t.eq(str, 
    172175             tUrl + "?" + OpenLayers.Util.getParameterString(tParams), 
    173176             "getFullRequestString() by default does *not* add SRS value if projection is 'none'"); 
     177        map.destroy(); 
    174178  
    175179    } 
    176180 
     
    196200        tile.draw(); 
    197201        t.eq(parseFloat(tile.imgDiv.style.opacity), 0.6, "Tile opacity is set correctly"); 
    198202 
     203        map.destroy(); 
    199204    }     
    200205     
    201206    function test_20_Layer_WMS_Reproject (t) {  
    202207        t.plan(5); 
     208 
    203209        var map = new OpenLayers.Map('map'); 
    204210        var layer = new OpenLayers.Layer.Google("Google"); 
    205211        map.addLayer(layer); 
     
    212218        t.eq( tile.bounds.right, -11.25, "top side matches" );  
    213219        t.eq( tile.bounds.bottom.toFixed(6), '11.178402', "bottom side matches" );  
    214220        t.eq( tile.bounds.top.toFixed(6), '21.943046', "top side matches" );  
     221        map.destroy(); 
    215222         
    216223        var map = new OpenLayers.Map('map'); 
    217224        layer = new OpenLayers.Layer.WMS(name, url, params); 
     
    219226        map.setCenter(new OpenLayers.LonLat(0,0), 5); 
    220227        var tile = layer.grid[0][0]; 
    221228        t.ok( tile.bounds.equals(new OpenLayers.Bounds(-33.75, 33.75, -22.5, 45)), "okay"); 
     229 
     230        map.destroy(); 
    222231    } 
    223232     
    224233    function test_99_Layer_WMS_destroy (t) { 
  • lib/OpenLayers/Map.js

    old new  
    225225            }  
    226226            this.controls = null; 
    227227        } 
     228        this.div.innerHTML = ""; 
    228229    }, 
    229230 
    230231    /**