[GIS] the difference between projection and displayprojection for a Map in OpenLayers

openlayers-2

I am familiarizing myself with Openlayers, and am having trouble with understanding the projection and displayprojection properties for a Map.

When the map is initialized with the following code:

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

What exactly is happening?

The documentation of the OpenLayers.Map says that

projection -Set in the map options to override the default projection string [in] this map – also set maxExtent, maxResolution, and units if appropriate. Default is “EPSG:4326”.

while displayProjection is the Projection used by several controls to display data to user. If this property is set, it will be set on any control which has a null displayProjection property at the time the control is added to the map.

This does not make it clear.

Could someone explain what exactly do these two option do?

Best Answer

From the OpenLayers Beginner's guide:

This 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).

The bold parts should give you an idea. I hope it helps.