On Friday, August 14, 2009, Raul David Orozco <[email protected]> wrote: > I'm here again with mi newbie questions. I've been dealing with this issue > for a long time and I can't fix it no matter how hard I try.I need to make OL > set an initial coordinates and zoom so when I open the browser the map stars > in some specific part of the world. > I've done it perfectly with an example doing this:var options = { > minResolution: "auto", > minExtent: new OpenLayers.Bounds(-1, -1, 1, 1), > maxResolution: "auto", > maxExtent: new OpenLayers.Bounds(-180, -90, 180, 90) > }; > > map = new OpenLayers.Map( 'map' , options); > > > layer = new OpenLayers.Layer.WMS( "OpenLayers WMS", > "http://labs.metacarta.com/wms/vmap0", {layers: 'basic'}); > map.addLayer(layer); > > map.setCenter(new OpenLayers.LonLat(-73, 3), 3);And it works just > the way I want, but when I do this with my map:var options = { > minResolution: "auto", > minExtent: new OpenLayers.Bounds(-1, -1, 1, 1), > maxResolution: "auto", > maxExtent: new OpenLayers.Bounds(-180, -90, 180, > 90) > }; > > var map = new OpenLayers.Map( 'map' , options); > > > var request = OpenLayers.Request.GET( > {url: > "dir/smms/wms.php?VERSION=1.1.1&REQUEST=GetCapabilities&SERVICE=WMS", > success: function(response){ > var XMLformat = new > OpenLayers.Format.XML(); > var xml = XMLformat.read(response.responseText); > var CAPformat = new > OpenLayers.Format.WMSCapabilities(); > var cap = CAPformat.read(xml); > > for (var i=0; > i<cap.capability.layers.length; i++) { > layer = > cap.capability.layers[i]; > > layers_array[i] = new OpenLayers.Layer.WMS( layer.name, > "dir/smms/wms.php", > {'layers': layer.name, format: > "image/png"} > ); > > > > > map.addLayer(layers_array[i]); > } > }, > failure: function(response){ > alert(response.status); > alert("GetCapabilities failed"); > } > }); > > map.setCenter(new OpenLayers.LonLat(-73, 3), 3); > IT DOESN'T WORK, I get the error : > maxExtent is null. What can I do??? I hope somebody can help me.
Hi you must call setCenter in the Ajax callback, else there's chance that there'sno layer in thw map at the time setCenter is called. > -- Eric Lemoine Camptocamp France SAS Savoie Technolac, BP 352 73377 Le Bourget du Lac, Cedex Tel : 00 33 4 79 44 44 96 Mail : [email protected] http://www.camptocamp.com _______________________________________________ Users mailing list [email protected] http://openlayers.org/mailman/listinfo/users
