m.sai
m.sai

Reputation: 1

Change Map view port and zoom according to different coordinates

i'm using OpenLayers API as a client for streamed maps located on a mapping server (geoServer), when i got a search results placed on the map,the view port and zooming level doesn't change, i want to make a zoom to the coordinates extent of the result set to make a suitable zooming level to fit all resulting coordinates.

I tried the following code but without any value..

var Newbounds= new OpenLayers.Bounds();  //global var
Newbounds.extend(lonLatMarker);     // inside the function of setting the marker data    
map.zoomToExtent(Newbounds);        // after showing results set of coordinates on the map

Upvotes: 0

Views: 2609

Answers (1)

igorti
igorti

Reputation: 3856

What kind of object is lonLatMarker? Should be OpenLayers.LonLat, not OpenLayers.Marker

Given that you have correct object type, this code should work:

var newBounds = new OpenLayers.Bounds(lonLatMarker.lon, lonLatMarker.lat, lonLatMarker.lon, lonLatMarker.lat); 
map.zoomToExtent(newBounds);

Upvotes: 2

Related Questions