I do that, but then my map zooms at 0,0.<br>It looks like it can't get the proper coordinates from getDataExtent().<br>My data comes from postgis in 4326, but in firebug myvector.getExtent() gives coordinates in 900913. Map is in 900913.<br>
I tried all sorts of transformations but it's always the same.<br><br>Vlado <br><br><br><div class="gmail_quote">On Mon, Dec 19, 2011 at 6:12 PM, Arnd Wippermann <span dir="ltr"><<a href="mailto:arnd.wippermann@web.de">arnd.wippermann@web.de</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi,<br>
<br>
for vector layers you can use<br>
<br>
map.zoomToExtent(yourVectorLayer.getDataExtent());<br>
<br>
after all features are loaded.<br>
<br>
Arnd<br>
<br>
<br>
-----Ursprüngliche Nachricht-----<br>
Von: <a href="mailto:openlayers-users-bounces@lists.osgeo.org">openlayers-users-bounces@lists.osgeo.org</a><br>
[mailto:<a href="mailto:openlayers-users-bounces@lists.osgeo.org">openlayers-users-bounces@lists.osgeo.org</a>] Im Auftrag von arbormagna<br>
Gesendet: Montag, 19. Dezember 2011 00:45<br>
An: <a href="mailto:users@openlayers.org">users@openlayers.org</a><br>
Betreff: [OpenLayers-Users] zoom to feature(s) extent<br>
<div class="HOEnZb"><div class="h5"><br>
Hi to all,<br>
<br>
I am developing my app and every day I keep bumping in walls.<br>
<br>
Today I spend 12 hours trying to figure how to zoom to the extent of the<br>
queried features, but couldn't sort it out.<br>
I use *zoomToExtent(vector_layer.getExtent())*,<br>
<br>
but it zooms somewhere in the middle atlantic :).<br>
<br>
In the firebug, when I call<br>
<br>
*getExtent()*<br>
<br>
it returns it. If I say<br>
<br>
*new OpenLayers.Bounds(vector_layer.getExtent())*<br>
<br>
it returns just left boundary?!<br>
<br>
If I try *vector_layer.calculateBounds* or *getBounds* it returns<br>
"undefined".<br>
<br>
The strangest thing is when I call *vector_layer.geometryType* it returns<br>
Null, although map displays all polygons perfectly.<br>
<br>
Can anybody help, I would be very grateful - this just makes me out of<br>
myself :).<br>
<br>
Here is the code:<br>
<br>
var map, osm, kml;<br>
<br>
upit="/kml/";<br>
{%if search_details%}<br>
<br>
upit="/kml/?q={{x}}&r={{y}}";<br>
<br>
{%endif%}<br>
<br>
function init(){<br>
<br>
<br>
var options = {maxExtent: new OpenLayers.Bounds(<br>
1813816.431496, 5245458.4167548, 2178341.4193136,<br>
5664389.3081316),<br>
units: 'm',<br>
projection: new OpenLayers.Projection('EPSG:900913'),<br>
displayProjection: new OpenLayers.Projection('EPSG:3908')<br>
<br>
}<br>
map = new OpenLayers.Map('map', options);<br>
<br>
map.addControl(new OpenLayers.Control.LayerSwitcher());<br>
map.addControl(new OpenLayers.Control.MousePosition());<br>
<br>
osm = new OpenLayers.Layer.OSM(<br>
"OSM");<br>
<br>
kml = new OpenLayers.Layer.Vector("KML",<br>
{<br>
projection: new OpenLayers.Projection('EPSG:4326'),<br>
protocol: new OpenLayers.Protocol.HTTP({<br>
url: upit,<br>
format: new OpenLayers.Format.KML({<br>
extractAttributes: true,<br>
extractstyles: true<br>
})<br>
}),<br>
strategies: [new OpenLayers.Strategy.Fixed()]});<br>
<br>
map.addLayers([osm, kml]);<br>
<br>
var google_satellite = new OpenLayers.Layer.Google('Google', {<br>
type: google.maps.MapTypeId.SATELLITE<br>
});<br>
map.addLayer(google_satellite);<br>
<br>
/*map.zoomToExtent(<br>
new OpenLayers.Bounds(<br>
1813816.431496, 5245458.4167548, 2178341.4193136,<br>
5664389.3081316))*/<br>
<br>
map.zoomToExtent(new OpenLayers.Bounds(kml.getExtent()))<br>
<br>
<br>
<br>
<br>
--<br>
View this message in context:<br>
<a href="http://osgeo-org.1803224.n2.nabble.com/zoom-to-feature-s-extent-tp7106787p71%0A06787.html" target="_blank">http://osgeo-org.1803224.n2.nabble.com/zoom-to-feature-s-extent-tp7106787p71<br>
06787.html</a><br>
Sent from the OpenLayers Users mailing list archive at Nabble.com.<br>
_______________________________________________<br>
Users mailing list<br>
<a href="mailto:Users@lists.osgeo.org">Users@lists.osgeo.org</a><br>
<a href="http://lists.osgeo.org/mailman/listinfo/openlayers-users" target="_blank">http://lists.osgeo.org/mailman/listinfo/openlayers-users</a><br>
<br>
</div></div></blockquote></div><br><br clear="all"><br>-- <br>Vladimir Stupar<br>Katedra za Ekologiju šuma<br>Šumarski fakultet, Univerzitet u Banjaluci<br>S. Stepanovića 75a, 78000 Banjaluka<br>Bosna i Hercegovina<br>tel.:+38765692006<br>
fax.:+38751460550<br>e-mail: <a href="mailto:stuparvladimir@gmail.com">stuparvladimir@gmail.com</a><br>skype: vmstupar<br><br>Vladimir Stupar<br>Department for Forest ecology<br>Forestry faculty, University in Banjaluka<br>
S. Stepanovica 75a, 78000 Banjaluka<br>Bosnia & Hercegovina<br>tel.:+38765692006<br>fax.:+38751460550<br>e-mail: <a href="mailto:stuparvladimir@gmail.com">stuparvladimir@gmail.com</a><br>skype: vmstupar<br><br><br>