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.

While going through the examples in OpenLayers, I notice several examples with the following code:

map = new OpenLayers.Map('map_element',{
 ...               
 units: 'm',
 projection: new OpenLayers.Projection('EPSG:900913'),
 displayProjection: new OpenLayers.Projection("EPSG:4326"),
});

My understanding is that the code:

projection: new OpenLayers.Projection('EPSG:900913')

displays a square-shaped map using a Spherical Mercator projection, and that the code:

displayProjection: new OpenLayers.Projection("EPSG:4326")

allows map controls such as the mouse to read from an ellipsoidal projection.

Notwithstanding the differences in units used (the former is in metres while the latter is in degrees), these two projections are totally incompatible since the points on these projections do not really match even if converted to the same unit.

So my question is: Why are these two projections being used together?

share|improve this question

marked as duplicate by Devdatta Tengshe, MappaGnosis, iant, Zachary, whuber Mar 8 '13 at 15:03

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

1 Answer 1

up vote 5 down vote accepted

From the OpenLayers Beginner's guide, displayProjection is

... a property that is used mainly by controls which show coordinate information. By setting this property on the map object, any control that has a displayProjection property will be set to this value. Controls, such as the MousePosition control, can display coordinates in the displayProjection. So, your map could be in a different projection than what you wish to display the coordinates in. However, to use a displayProjection other than EPSG:4326 or EPSG:900913, Proj4js must be included on your page. This property comes in very handy if, for instance, your map is in a spherical Mercator projection (i.e., EPSG:900913), but you might wish to display coordinates in another projection, like EPSG:4326 (to display lon/lat coordinates).

As for your concern that

Notwithstanding the differences in units used (the former is in metres while the latter is in degrees), these two projections are totally incompatible since the points on these projections do not really match even if converted to the same unit.

If they're totally incompatible then none of those mashups would work would they? They wouldn't overlay at all. Fortunately, we can do coordinate transformations and that's why it works. The two projections are not incompatible. You can transform coordinates from EPSG:4326 to EPSG:90093 and vice versa.

share|improve this answer
    
Can I take it that there is some kind of transformation going on from projection to display projection? –  Question Overflow Oct 12 '12 at 7:25
    
Yes. projection refers to the map's actual projection whereas the displayProjection refers to the projection of the coordinates that are displayed. In your example, the map has EPSG:900913 coordinates but OpenLayers converts them to EPSG:4326 for display. –  R.K. Oct 12 '12 at 7:34
    
Ah.. I see. Thanks for clearing this up for me :) –  Question Overflow Oct 12 '12 at 7:56
    
You're welcome :) –  R.K. Oct 12 '12 at 8:03

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