Ticket #60: 60-also-fixes-39.1.patch
| File 60-also-fixes-39.1.patch, 8.2 kB (added by elemoine, 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 18 21 function test_mappanel(t) { 19 t.plan( 3)22 t.plan(4) 20 23 24 var moveToCnt; 25 21 26 var map = createMap(); 22 27 map.moveTo = function() { 28 moveToCnt++; 29 OpenLayers.Map.prototype.moveTo.apply(this, arguments); 30 }; 31 32 moveToCnt = 0; 23 33 var mapPanel = new GeoExt.MapPanel({ 24 34 // panel options 25 35 id: "map-panel", … … 32 42 center: new OpenLayers.LonLat(5, 45), 33 43 zoom: 4 34 44 }); 45 t.eq(moveToCnt, 1, "map.moveTo called exactly once"); 35 46 t.eq(mapPanel.map.getCenter().toString(), "lon=5,lat=45", "Map center set correctly"); 36 47 t.eq(mapPanel.map.getZoom(), 4, "Zoom set correctly"); 37 48 t.eq(GeoExt.MapPanel.guess().id, mapPanel.id, "MapPanel guessed correctly"); … … 82 93 map = createMap(); 83 94 map.zoomToExtent = function(extent) { 84 95 log.extent = extent; 85 } 96 }; 86 97 panel = new GeoExt.MapPanel({ 87 98 renderTo: "mappanel", 88 99 map: map, 100 height: 400, 101 width: 600, 89 102 extent: [1, 2, 3, 4] 90 103 }); 91 104 t.eq(log.extent.toArray(), [1, 2, 3, 4], "map extent set with array"); … … 97 110 map = createMap(); 98 111 map.zoomToExtent = function(extent) { 99 112 log.extent = extent; 100 } 113 }; 101 114 panel = new GeoExt.MapPanel({ 102 115 renderTo: "mappanel", 103 116 map: map, 117 height: 400, 118 width: 600, 104 119 extent: "1, 2, 3, 4" 105 120 }); 106 121 t.eq(log.extent.toArray(), [1, 2, 3, 4], "map extent set with string"); … … 111 126 map = createMap(); 112 127 map.zoomToExtent = function(extent) { 113 128 log.extent = extent; 114 } 129 }; 115 130 panel = new GeoExt.MapPanel({ 116 131 renderTo: "mappanel", 117 132 map: map, 133 height: 400, 134 width: 600, 118 135 extent: new OpenLayers.Bounds(1, 2, 3, 4) 119 136 }); 120 137 t.eq(log.extent.toArray(), [1, 2, 3, 4], "map extent set with Bounds"); … … 132 149 map = createMap(); 133 150 map.setCenter = function(center) { 134 151 log.center = center; 135 } 152 }; 136 153 panel = new GeoExt.MapPanel({ 137 154 renderTo: "mappanel", 138 155 map: map, 156 height: 400, 157 width: 600, 139 158 center: [1, 2] 140 159 }); 141 160 t.eq(log.center.toString(), "lon=1,lat=2", "map center set with array"); … … 147 166 map = createMap(); 148 167 map.setCenter = function(center) { 149 168 log.center = center; 150 } 169 }; 151 170 panel = new GeoExt.MapPanel({ 152 171 renderTo: "mappanel", 153 172 map: map, 173 height: 400, 174 width: 600, 154 175 center: "1, 2" 155 176 }); 156 177 t.eq(log.center.toString(), "lon=1,lat=2", "map center set with string"); … … 162 183 map = createMap(); 163 184 map.setCenter = function(center) { 164 185 log.center = center; 165 } 186 }; 166 187 panel = new GeoExt.MapPanel({ 167 188 renderTo: "mappanel", 168 189 map: map, 190 height: 400, 191 width: 600, 169 192 center: new OpenLayers.LonLat(1, 2) 170 193 }); 171 194 t.eq(log.center.toString(), "lon=1,lat=2", "map center set with LonLat"); … … 213 236 214 237 } 215 238 239 function test_layout(t) { 240 t.plan(1); 216 241 242 var map, panel, layout = 0; 243 244 map = new OpenLayers.Map({ 245 render: function() { 246 OpenLayers.Map.prototype.render.apply(this, arguments); 247 t.ok(layout, 1, 248 "the OpenLayers map is rendered once the container " + 249 "has its final dimensions"); 250 }, 251 allOverlays: true 252 }); 253 254 panel = new Ext.Panel({ 255 layout: "border", 256 renderTo: "mappanel", 257 listeners: { 258 afterlayout: function() { 259 layout++; 260 } 261 }, 262 items: [{ 263 region: "center", 264 xtype: "gx_mappanel", 265 map: map, 266 layers: [ 267 new OpenLayers.Layer("") 268 ] 269 }] 270 }); 271 272 panel.destroy(); 273 } 274 275 217 276 </script> 218 277 <body> 219 278 <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); 142 this.map.render(this.body.dom); 143 if(this.map.layers.length > 0) { 140 renderMap: function() { 141 var map = this.map; 142 143 // hack: set map.size to null to prevent map.updateSize (called from 144 // within map.render) from zooming to the map extent. This hack is a 145 // workaround for <http://trac.openlayers.org/ticket/2105> and must be 146 // removed once this ticket is closed. 147 map.size = null; 148 149 map.render(this.body.dom); 150 151 if(map.layers.length > 0) { 144 152 if(this.center) { 145 153 // zoom does not have to be defined 146 this.map.setCenter(this.center, this.zoom);147 } else if(this.extent) {148 this.map.zoomToExtent(this.extent);154 map.setCenter(this.center, this.zoom); 155 } else if(this.extent) { 156 map.zoomToExtent(this.extent); 149 157 } else { 150 this.map.zoomToMaxExtent();158 map.zoomToMaxExtent(); 151 159 } 152 160 } 153 161 }, … … 157 165 */ 158 166 afterRender: function() { 159 167 GeoExt.MapPanel.superclass.afterRender.apply(this, arguments); 160 if(this.ownerCt) { 168 if(!this.ownerCt) { 169 this.renderMap(); 170 } else { 161 171 this.ownerCt.on("move", this.updateMapSize, this); 172 this.ownerCt.on({ 173 "afterlayout": { 174 fn: this.renderMap, 175 scope: this, 176 single: true 177 } 178 }); 162 179 } 163 }, 180 }, 164 181 165 182 /** private: method[onResize] 166 183 * Private method called after the panel has been resized.