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 12 12 var map = new OpenLayers.Map(); 13 13 var layer = new OpenLayers.Layer("test", {isBaseLayer: true}); 14 14 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")); 15 18 return map; 16 19 } 17 20 … … 86 89 panel = new GeoExt.MapPanel({ 87 90 renderTo: "mappanel", 88 91 map: map, 92 height: 400, 93 width: 600, 89 94 extent: [1, 2, 3, 4] 90 95 }); 91 96 t.eq(log.extent.toArray(), [1, 2, 3, 4], "map extent set with array"); … … 101 106 panel = new GeoExt.MapPanel({ 102 107 renderTo: "mappanel", 103 108 map: map, 109 height: 400, 110 width: 600, 104 111 extent: "1, 2, 3, 4" 105 112 }); 106 113 t.eq(log.extent.toArray(), [1, 2, 3, 4], "map extent set with string"); … … 115 122 panel = new GeoExt.MapPanel({ 116 123 renderTo: "mappanel", 117 124 map: map, 125 height: 400, 126 width: 600, 118 127 extent: new OpenLayers.Bounds(1, 2, 3, 4) 119 128 }); 120 129 t.eq(log.extent.toArray(), [1, 2, 3, 4], "map extent set with Bounds"); … … 136 145 panel = new GeoExt.MapPanel({ 137 146 renderTo: "mappanel", 138 147 map: map, 148 height: 400, 149 width: 600, 139 150 center: [1, 2] 140 151 }); 141 152 t.eq(log.center.toString(), "lon=1,lat=2", "map center set with array"); … … 151 162 panel = new GeoExt.MapPanel({ 152 163 renderTo: "mappanel", 153 164 map: map, 165 height: 400, 166 width: 600, 154 167 center: "1, 2" 155 168 }); 156 169 t.eq(log.center.toString(), "lon=1,lat=2", "map center set with string"); … … 166 179 panel = new GeoExt.MapPanel({ 167 180 renderTo: "mappanel", 168 181 map: map, 182 height: 400, 183 width: 600, 169 184 center: new OpenLayers.LonLat(1, 2) 170 185 }); 171 186 t.eq(log.center.toString(), "lon=1,lat=2", "map center set with LonLat"); … … 176 191 177 192 } 178 193 194 function test_layout(t) { 195 t.plan(1); 179 196 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 180 231 </script> 181 232 <body> 182 233 <div id="mappanel"></div> -
lib/GeoExt/widgets/MapPanel.js
old new 125 125 }, 126 126 127 127 /** private: method[updateMapSize] 128 * Tell the map that it needs to reca culate its size and position.128 * Tell the map that it needs to recalculate its size and position. 129 129 */ 130 130 updateMapSize: function() { 131 131 if(this.map) { 132 132 this.map.updateSize(); 133 133 } 134 134 }, 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. 139 139 */ 140 onRender: function() { 141 GeoExt.MapPanel.superclass.onRender.apply(this, arguments); 140 renderMap: function() { 142 141 this.map.render(this.body.dom); 142 this.updateMapSize(); 143 143 if(this.map.layers.length > 0) { 144 144 if(this.center) { 145 145 // zoom does not have to be defined 146 146 this.map.setCenter(this.center, this.zoom); 147 } else if(this.extent) {147 } else if(this.extent) { 148 148 this.map.zoomToExtent(this.extent); 149 149 } else { 150 150 this.map.zoomToMaxExtent(); … … 157 157 */ 158 158 afterRender: function() { 159 159 GeoExt.MapPanel.superclass.afterRender.apply(this, arguments); 160 if(this.ownerCt) { 160 if(!this.ownerCt) { 161 this.renderMap(); 162 } else { 161 163 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 }); 162 171 } 163 }, 172 }, 164 173 165 174 /** private: method[onResize] 166 175 * Private method called after the panel has been resized.