Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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

The Beginner's Guide to OpenLayers 2.10 says the following:

sphericalMercator {Boolean}

This property determines if the map should behave as a Mercator-projected map. Setting this to true will allow us to use other layers, such as Vector layer, with the actual map projection.

Given that there is already a method where the projection is specified, i.e. in map.projection, why is there a need to specify the same thing over again in the Layer property? Is there a situation where a different projection is required in Layer as compared to the map?

Or do they serve totally different purpose?

share|improve this question
up vote 6 down vote accepted

It's a shorthand for EPSG:900913 and a number of zoom levels: here's the relevant code in OpenLayers.

share|improve this answer
Thanks for the link. I have tested the code without specifying map.projection. By setting sphericalMercator:true, it does indeed return EPSG:900913 using the getProjection method. This is useful, but doesn't fully answer my question why it is necessary to specify separately since I could have done that in map.projection. – Question Overflow Oct 13 '12 at 7:10
Okay, to be more clear: it isn't necessary - you can do one and/or the other. As far as specifying projection/settings in the map object or layer object, OL will check the layer object for a projection and then go to the projection on the map object. It's recommended to set all projection & zoom-level type settings on layers, so that you don't have configuration inheritance. – tmcw Oct 14 '12 at 8:18
Wouldn't it be ideal if layer projection is inherited from map projection so that there is no need to set this in each layer? Is there a scenario where a different projection is required? – Question Overflow Oct 14 '12 at 12:04
You can do either, but often layers will have more or fewer zoom levels. As soon as there's a "every layer has X but this layer has Y" relationship, it gets harder to track. I'd rather be explicit about configuration, but it's essentially a judgment call. – tmcw Oct 14 '12 at 19:35

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.