Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I'm using this to center my points in the map screen:

var centerPoint = new OpenLayers.LonLat(feature.geometry.x, feature.geometry.y);
map.setCenter(centerPoint);

what should I use to center polylines and polygons?

thanks in advance,

share|improve this question

2 Answers 2

You can use the following:

map.setCenter(map.layers[1].getDataExtent().getCenterLonLat(),12);

This will center your map to the center of your vector layer 1, at a zoom level 12.

share|improve this answer
    
thanks for the the idea, how about if I want to set the zoom according to the size of each feature? I mean I have a big polygon and a point with the same name, both features are selected but they are not zoomed proportionally to their sizes, is it possible? –  Gery Feb 20 '13 at 14:49
    
found the solution, it was just to use ft.geometry.id and if/else with a like operator –  Gery Feb 20 '13 at 18:36
up vote 1 down vote accepted

solution:

var ft = vectorLayer.features[0];
var bounds = ft.geometry.bounds;
if(zoom)
    map.zoomToExtent(bounds);
else
    map.setCenter(bounds.getCenterLonLat());
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.