I do that, but then my map zooms at 0,0. It looks like it can't get the proper coordinates from getDataExtent(). My data comes from postgis in 4326, but in firebug myvector.getExtent() gives coordinates in 900913. Map is in 900913. I tried all sorts of transformations but it's always the same.
Vlado On Mon, Dec 19, 2011 at 6:12 PM, Arnd Wippermann <[email protected]>wrote: > Hi, > > for vector layers you can use > > map.zoomToExtent(yourVectorLayer.getDataExtent()); > > after all features are loaded. > > Arnd > > > -----Ursprüngliche Nachricht----- > Von: [email protected] > [mailto:[email protected]] Im Auftrag von > arbormagna > Gesendet: Montag, 19. Dezember 2011 00:45 > An: [email protected] > Betreff: [OpenLayers-Users] zoom to feature(s) extent > > 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 :). > > 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 *vector_layer.calculateBounds* or *getBounds* it returns > "undefined". > > The strangest thing is when I call *vector_layer.geometryType* it returns > Null, although map displays all polygons perfectly. > > Can anybody help, I would be very grateful - this just makes me out of > myself :). > > Here is the code: > > var map, osm, kml; > > upit="/kml/"; > {%if search_details%} > > upit="/kml/?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())) > > > > > -- > View this message in context: > > http://osgeo-org.1803224.n2.nabble.com/zoom-to-feature-s-extent-tp7106787p71 > 06787.html > Sent from the OpenLayers Users mailing list archive at Nabble.com. > _______________________________________________ > Users mailing list > [email protected] > http://lists.osgeo.org/mailman/listinfo/openlayers-users > > -- Vladimir Stupar Katedra za Ekologiju šuma Šumarski fakultet, Univerzitet u Banjaluci S. Stepanovića 75a, 78000 Banjaluka Bosna i Hercegovina tel.:+38765692006 fax.:+38751460550 e-mail: [email protected] skype: vmstupar Vladimir Stupar Department for Forest ecology Forestry faculty, University in Banjaluka S. Stepanovica 75a, 78000 Banjaluka Bosnia & Hercegovina tel.:+38765692006 fax.:+38751460550 e-mail: [email protected] skype: vmstupar
_______________________________________________ Users mailing list [email protected] http://lists.osgeo.org/mailman/listinfo/openlayers-users
