Ticket #60: 60-also-fixes-39.patch

File 60-also-fixes-39.patch, 5.8 kB (added by ahocevar, 1 year ago)
  • tests/lib/GeoExt/widgets/MapPanel.html

    old new  
    1212            var map = new OpenLayers.Map(); 
    1313            var layer = new OpenLayers.Layer("test", {isBaseLayer: true}); 
    1414            map.addLayer(layer); 
     15            // add a vector layer, which would fail onmapresize if we render 
     16            // the map before the panel has a layout. 
     17            map.addLayer(new OpenLayers.Layer.Vector("vector layer")); 
    1518            return map; 
    1619        } 
    1720 
     
    8689            panel = new GeoExt.MapPanel({ 
    8790                renderTo: "mappanel", 
    8891                map: map, 
     92                height: 400, 
     93                width: 600, 
    8994                extent: [1, 2, 3, 4] 
    9095            });             
    9196            t.eq(log.extent.toArray(), [1, 2, 3, 4], "map extent set with array"); 
     
    101106            panel = new GeoExt.MapPanel({ 
    102107                renderTo: "mappanel", 
    103108                map: map, 
     109                height: 400, 
     110                width: 600, 
    104111                extent: "1, 2, 3, 4" 
    105112            }); 
    106113            t.eq(log.extent.toArray(), [1, 2, 3, 4], "map extent set with string"); 
     
    115122            panel = new GeoExt.MapPanel({ 
    116123                renderTo: "mappanel", 
    117124                map: map, 
     125                height: 400, 
     126                width: 600, 
    118127                extent: new OpenLayers.Bounds(1, 2, 3, 4) 
    119128            }); 
    120129            t.eq(log.extent.toArray(), [1, 2, 3, 4], "map extent set with Bounds"); 
     
    136145            panel = new GeoExt.MapPanel({ 
    137146                renderTo: "mappanel", 
    138147                map: map, 
     148                height: 400, 
     149                width: 600, 
    139150                center: [1, 2] 
    140151            });             
    141152            t.eq(log.center.toString(), "lon=1,lat=2", "map center set with array"); 
     
    151162            panel = new GeoExt.MapPanel({ 
    152163                renderTo: "mappanel", 
    153164                map: map, 
     165                height: 400, 
     166                width: 600, 
    154167                center: "1, 2" 
    155168            });             
    156169            t.eq(log.center.toString(), "lon=1,lat=2", "map center set with string"); 
     
    166179            panel = new GeoExt.MapPanel({ 
    167180                renderTo: "mappanel", 
    168181                map: map, 
     182                height: 400, 
     183                width: 600, 
    169184                center: new OpenLayers.LonLat(1, 2) 
    170185            });             
    171186            t.eq(log.center.toString(), "lon=1,lat=2", "map center set with LonLat"); 
     
    176191 
    177192        } 
    178193 
     194        function test_layout(t) { 
     195            t.plan(1); 
    179196 
     197            var map, panel, layout = 0; 
     198 
     199            map = new OpenLayers.Map({ 
     200                render: function() { 
     201                    OpenLayers.Map.prototype.render.apply(this, arguments); 
     202                    t.ok(layout, 1, 
     203                         "the OpenLayers map is rendered once the container " + 
     204                         "has its final dimensions"); 
     205                }, 
     206                allOverlays: true 
     207            }); 
     208             
     209            panel = new Ext.Panel({ 
     210                layout: "border", 
     211                renderTo: "mappanel", 
     212                listeners: { 
     213                    afterlayout: function() { 
     214                        layout++; 
     215                    } 
     216                }, 
     217                items: [{ 
     218                    region: "center", 
     219                    xtype: "gx_mappanel", 
     220                    map: map, 
     221                    layers: [ 
     222                        new OpenLayers.Layer("") 
     223                    ] 
     224                }] 
     225            }); 
     226 
     227            panel.destroy(); 
     228        } 
     229 
     230 
    180231    </script> 
    181232  <body> 
    182233    <div id="mappanel"></div> 
  • lib/GeoExt/widgets/MapPanel.js

    old new  
    125125    }, 
    126126     
    127127    /** private: method[updateMapSize] 
    128      *  Tell the map that it needs to recaculate its size and position. 
     128     *  Tell the map that it needs to recalculate its size and position. 
    129129     */ 
    130130    updateMapSize: function() { 
    131131        if(this.map) { 
    132132            this.map.updateSize(); 
    133133        } 
    134134    }, 
    135      
    136     /** private: method[onRender
    137      *  Private method called after the panel has been 
    138      *  rendered
     135 
     136    /** private: method[renderMap
     137     *  Private method called after the panel has been rendered or after it 
     138     *  has been laid out by its parent's layout
    139139     */ 
    140     onRender: function() { 
    141         GeoExt.MapPanel.superclass.onRender.apply(this, arguments); 
     140    renderMap: function() { 
    142141        this.map.render(this.body.dom); 
     142        this.updateMapSize(); 
    143143        if(this.map.layers.length > 0) { 
    144144            if(this.center) { 
    145145                // zoom does not have to be defined 
    146146                this.map.setCenter(this.center, this.zoom); 
    147             } else if(this.extent) { 
     147            } else if(this.extent) { 
    148148                this.map.zoomToExtent(this.extent); 
    149149            } else { 
    150150                this.map.zoomToMaxExtent(); 
     
    157157     */ 
    158158    afterRender: function() { 
    159159        GeoExt.MapPanel.superclass.afterRender.apply(this, arguments); 
    160         if(this.ownerCt) { 
     160        if(!this.ownerCt) { 
     161            this.renderMap(); 
     162        } else { 
    161163            this.ownerCt.on("move", this.updateMapSize, this); 
     164            this.ownerCt.on({ 
     165                "afterlayout": { 
     166                    fn: this.renderMap, 
     167                    scope: this, 
     168                    single: true 
     169                } 
     170            }); 
    162171        } 
    163     },     
     172    }, 
    164173 
    165174    /** private: method[onResize] 
    166175     *  Private method called after the panel has been resized.