Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is it possible to re-initialize OpenLayers Map with a different projection ?


  1. OL Map with projection 4326 is created, along with click, measurement, drawing handlers.

  2. A button to switch to projection 3857 exists

  3. When the button is clicked, we 'ideally' want to re-initialize the map to 3857, without re-init all the handlers (click, measurement, drawing etc), because the tiles are are in 3857.

How do I do this?

share|improve this question

Create a map, with 2 layers. 1 shown (4326) and 1 hidden (3857). On your button click just take the 2nd layer (3857) and set it as the base map. That's it.

This is all assuming, of course, that all of your other functions and calculations are projection-aware. Meaning that at every step you're dealing with objects you are transforming them from the base layer projection to some base one (like 4326).

Now, if you have other non-baselayers drawn, you'll have to redraw them, and if you have vector data, you'll have to r-eproject it and re-draw. And if those layers don't support that project (e.g. the WMS service doesn't support 3857) then you just won't see anything.

share|improve this answer
Thanks Vadim. the projection is set dynamically, so it's not limited to 2, it comes from the server, so I can't use 2 layers with different projection. – portoalet May 11 '12 at 2:11
How do you mean dynamically? By user? By your code? You (in code) can always find out what the projection object is. And you can always transform on the fly from one to another (vector data here, not images). Either way, all of your displayed data is driven by the BASE LAYER projection. And all of your event handlers should transform results into 1 format (e.g. the mouse coordinates will come back in the base map projection, but if you always want to display Lat/Lon to user, you have to transform) – Vadim May 11 '12 at 16:55

I re-init the map every time the button is clicked, making it not complicated

map = new OpenLayers.Map()
share|improve this answer

Your Answer


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.