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 use openlayers in my web app.I want to set map extent on specific country to show cities of that country but i don't know which option of map can show specific country in map!.
How can i show specific country on map and can show cities of that country?
To setting map on specific bound when i use below code i can set extent to desire extent!

var bounds = new OpenLayers.Bounds();
    bounds.extend(new OpenLayers.LonLat(8.91,55.18).transform(new OpenLayers.Projection("EPSG:4326"),
    new OpenLayers.Projection('EPSG:900913')));
    bounds.extend(new OpenLayers.LonLat(16.19,56.22).transform(new OpenLayers.Projection("EPSG:4326"),
    new OpenLayers.Projection('EPSG:900913')));
    map = new OpenLayers.Map('map_element', {
        projection: new OpenLayers.Projection('EPSG:900913'),
        zoomToExtent:bounds
  });
map.setCenter(new OpenLayers.LonLat(-1.788, 53.571).transform(
    new OpenLayers.Projection("EPSG:4326"),
    new OpenLayers.Projection('EPSG:900913')
), zoom);

But when i use zoomToExtent and zoomTo function map can't show my desire bound!

var bounds = new OpenLayers.Bounds();
    bounds.extend(new OpenLayers.LonLat(8.91,55.18).transform(new OpenLayers.Projection("EPSG:4326"),
    new OpenLayers.Projection('EPSG:900913')));
    bounds.extend(new OpenLayers.LonLat(16.19,56.22).transform(new OpenLayers.Projection("EPSG:4326"),
    new OpenLayers.Projection('EPSG:900913')));
    map = new OpenLayers.Map('map_element', {
        projection: new OpenLayers.Projection('EPSG:900913')
  });
map.zoomTo(10);
map.zoomToExtent(bounds);

why in the above code i can't zoom to desire bound?

share|improve this question
add comment

1 Answer 1

up vote 1 down vote accepted

Check out this question and i think 3rd comment is the answer which u are looking for...

I had similar problem when using cached layers with fixed zoomlevels. zoomToExtent didn't work. I used map.setCenter(lonlat,zoomlevel) instead. I guess it had something to do with the fact that open layers couldn't zoom to that exact extent because it didn't match any zoomlevel. – Voooza Sep 26 '11 at 17:01

share|improve this answer
add comment

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.