The Mercator projection is a cylindrical map projection presented by geographer and cartographer Geradus Mercator in 1569. The Spherical Mercator refers to those providers who use a Mercator projection and treat the earth as a sphere, rather than treat the earth as an ellipsoid. It's necessary to use this projection as it works well with many existing commercial APIs.
Each projection has its own EPSG code, which is short for European Petroleum Survey Group. The spherical projection has an unofficial but widely used code: “EPSG: 900913”, which describes coordinates in meters in x/y. Another common identifier is “EPSG:4326”, which describes coordinates using lat/lon system (Latitude is -90 to 90 and Longitude is -180 to 180).
Points, Bounds Transformation
ALKMaps provides data transformation from one projection to another. The code snippet below shows how to transform coordinates from Longitude/Latitude to Spherical Mercator projection.
var source = new ALKMaps.Projection("EPSG:4326"); var dest = map.getProjectionObject(); // point with Longitude and Latitude value. var point = new ALKMaps.LonLat(-96.78002,32.76093); point.transform(source, dest); . . . // now point has spherical mercator projection, you can use it in setCenter method. map.setCenter(point);
It's similar to transform the Bounds object. You can also directly call transform function:
var point = new ALKMaps.Bounds(-96.78002, 32.76093, -95.314232, 33.01234); point.transform(new ALKMaps.Projection("EPSG:4326"), map.getProjectionObject());
Geometry objects in ALKMaps also have the transform method as LonLat and Bounds objects. When you create a Geometry object, it must be transformed by calling transform method before adding to the layer. Note transform function is in place. After you have added a geometry to a layer, you should not call transform on it directly. Rather, you should make a clone of this geometry:
// get the third feature from myLayer var feature = myLayer.features; var geometry = feature.geometry.clone(); geometry.transform(layerProj, targetProj);