So far, we've been talking about the abstract idea of a projection. Let's dive into OpenLayer's ol.proj namespace functions and the associated class ol.proj.Projection class, which is what we use to actually handle projections. The ol.proj.Projection class relies on internal code, managing the most used projection in the web mapping world: the EPSG:4326 projection (also named WGS 84) and the EPSG:3857 projection, also known as EPSG:900913 (using leetspeak, it means Google, the first company relying on this exact projection), and also, alternatively named WGS 84 Spherical Mercator. For reference, you can have the full history of the second projection at http://wiki.openstreetmap.org/wiki/EPSG:3857
For other use case such as custom projections, OpenLayers, for convenience, supports an external library called Proj4js, which can be found at http://proj4js.org. First, we'll talk about what we can do without the Proj4js library, and then talk about what we can do with it.
In truth, whenever you load your web mapping application, you have already instantiated the default projections, EPSG:4326 and EPSG:3857.
You only need to access ol.proj.Projection by typing the following line of code:
ol.proj.get('EPSG:3857')In ol.proj.get, you can use a projectionCode, a string for identifying the WKID (Well Known Identifier) for the projection, such as an EPSG code in the form of EPSG:4326.
When creating a map and loading a particular projection, you will only require to declare Proj4js-specific definition and use OpenLayers built-in functions to use them. This string, such as EPSG:4326, is also known as an SRS (Spatial Reference System) code. When passing in a code, like we've done with all our examples so far, ol.proj.get() will automatically create a projection object, as long as the projection definition is known to Proj4js.
The projection class (the list is available at http://openlayers.org/en/v3.0.0/apidoc/ol.proj.Projection.html) has a number of methods, including the following: