[OpenLayers-Users] getDataExtent delay problem

Marcelo m_tchelo at yahoo.com
Fri Jul 22 18:28:03 EDT 2011


Hi List, 

I am having a problem that i just cannot find the solution. I want just to load a base WMS layer and a KML file on it. The problem is that I want to display the map just arround the bounding box of the KML file but the method getDataExtent only returns something usefull when the method has returned. Some ideias ?

Browser: Google Chrome, 
OpenLayers: From SVN on 23-07-2011
 Here is the code I am using:

function init() {

        document.namespaces;
wms = new OpenLayers.Layer.WMS(
"OpenLayers WMS",
"http://vmap0.tiles.osgeo.org/wms/vmap0",
{ layers: 'basic'},
{ 'maxExtent': new OpenLayers.Bounds(-180,-90,180,90), 'maxResolution': "auto" }
);

var http = new OpenLayers.Protocol.HTTP({
               url: "file.kml",
              format: new OpenLayers.Format.KML({ extractStyles: false })
         });

var sta = [new OpenLayers.Strategy.Fixed({ preload: true } )];
station = new OpenLayers.Layer.Vector("Stations", { strategies: sta, protocol: http })

map = new OpenLayers.Map('map');
map.addLayers([wms, station]);
map.addControl(new OpenLayers.Control.LayerSwitcher());
map.zoomToMaxExtent();
map.zoomToExtent(station.getDataExtent());
}

and the error i am getting on the console:

OpenLayers.js:526Uncaught TypeError: Cannot call method 'getCenterLonLat' of null

cheers, 

Marcelo
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/openlayers-users/attachments/20110722/329a32ed/attachment.html


More information about the Users mailing list