2

I am working on a project that uses OpenLayers to show shapefiles from the GeoServer and then show them on Google Maps. The only problem is when the page loads, I want to go to the spatial coordinate and zoom to the shapefile that is loaded on map. Is there any way to do this? I want to go to the coordinates around 32 and 50 in zone 39N. Can you help me about this problem?

I tried this code:

var dataExtent = states.getDataExtent();
map.zoomToExtent(dataExtent);

But it does not work, where is my mistake?

This is the result:

h++p://173.244.165.194/

It loads many maps of world. I have to zoom to go to my location :( Here is exact place that I want to zoom when page loads:

http://173.244.165.194/?zoom=12&lat=31.62211&lon=51.48708&layers=B00T
2
  • first, your map must be in the same projection than your layer Sep 17, 2014 at 18:12
  • I set maps projection and it places on right location.I just want to load a cordinate on start
    – Majid
    Sep 17, 2014 at 18:38

1 Answer 1

1

its difficult to know what is going wrong without all your code.

If you dont define a map size, you can try to do it before calling map.zoomToExtent()

map.size = new OpenLayers.Size(1125,745);
3
  • Thanks..What does map.size do?its parameters are cordinates?
    – Majid
    Sep 18, 2014 at 16:16
  • no the parameters are just the widh and heigh of the map in pixel (int). I had problem with zoomToExtent() in some projects when the size was not defined. Sep 18, 2014 at 16:38
  • I set the size to full screen.I used the sample template in openlayers website and changed it into what I needed ,Anyway I'll try your suggestion and let you know the results,Thank you very much
    – Majid
    Sep 18, 2014 at 17:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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