<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<pre wrap="">Hi,
You need to call
map.zoomToExtent(new OpenLayers.Bounds(kml.getExtent()))
from the event handler. Something like this
deeds.events.on({
'loadend': function (evt) {
var deeds_extent = deeds.getDataExtent();
map.zoomToExtent(deeds_extent);
}
});
Jim
Hi to all,
I am developing my app and every day I keep bumping in walls.
Today I spend 12 hours trying to figure how to zoom to the extent of the
queried features, but couldn't sort it out.
I use *zoomToExtent(vector_layer.getExtent())*,
but it zooms somewhere in the middle atlantic <span class="moz-smiley-s1" title=":)"></span>.
In the firebug, when I call
*getExtent()*
it returns it. If I say
*new OpenLayers.Bounds(vector_layer.getExtent())*
it returns just left boundary?!
If I try <b class="moz-txt-star"><span class="moz-txt-tag">*</span>vector_layer.calculateBounds<span class="moz-txt-tag">*</span></b> or <b class="moz-txt-star"><span class="moz-txt-tag">*</span>getBounds<span class="moz-txt-tag">*</span></b> it returns
"undefined".
The strangest thing is when I call <b class="moz-txt-star"><span class="moz-txt-tag">*</span>vector_layer.geometryType<span class="moz-txt-tag">*</span></b> it returns
Null, although map displays all polygons perfectly.
Can anybody help, I would be very grateful - this just makes me out of
myself <span class="moz-smiley-s1" title=":)"></span>.
Here is the code:
var map, osm, kml;
upit="<i class="moz-txt-slash"><span class="moz-txt-tag">/</span>kml<span class="moz-txt-tag">/</span></i>";
{%if search_details%}
upit="<i class="moz-txt-slash"><span class="moz-txt-tag">/</span>kml<span class="moz-txt-tag">/</span></i>?q={{x}}&r={{y}}";
{%endif%}
function init(){
var options = {maxExtent: new OpenLayers.Bounds(
1813816.431496, 5245458.4167548, 2178341.4193136,
5664389.3081316),
units: 'm',
projection: new OpenLayers.Projection('EPSG:900913'),
displayProjection: new OpenLayers.Projection('EPSG:3908')
}
map = new OpenLayers.Map('map', options);
map.addControl(new OpenLayers.Control.LayerSwitcher());
map.addControl(new OpenLayers.Control.MousePosition());
osm = new OpenLayers.Layer.OSM(
"OSM");
kml = new OpenLayers.Layer.Vector("KML",
{
projection: new OpenLayers.Projection('EPSG:4326'),
protocol: new OpenLayers.Protocol.HTTP({
url: upit,
format: new OpenLayers.Format.KML({
extractAttributes: true,
extractstyles: true
})
}),
strategies: [new OpenLayers.Strategy.Fixed()]});
map.addLayers([osm, kml]);
var google_satellite = new OpenLayers.Layer.Google('Google', {
type: google.maps.MapTypeId.SATELLITE
});
map.addLayer(google_satellite);
/*map.zoomToExtent(
new OpenLayers.Bounds(
1813816.431496, 5245458.4167548, 2178341.4193136,
5664389.3081316))*/
map.zoomToExtent(new OpenLayers.Bounds(kml.getExtent()))
</pre>
</body>
</html>