2

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?

1 Answer 1

6

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

4
  • 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. Oct 13, 2012 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, 2012 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? Oct 14, 2012 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, 2012 at 19:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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