Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenLayer Coordinate System

I'm struggling to understand the coordinate system used by OpenLayers.

Leicester, UK is at approx.

Latitude:  52.63973017532399
Longitude: -1.142578125

But to display the same location using OpenLayers I have to use:

Latitude:  6915601.9146245
Longitude: -125089.1967713

e.g:

var center  = new OpenLayers.LonLat(-125089.1967713, 6915601.9146245);
var map     = new OpenLayers.Map("demoMap");
map.addLayer(new OpenLayers.Layer.OSM());
map.setCenter(center, 12);

These are clearly not Latitude-Longitude coordinates, is there some conversion I need to take account of?

A working example is http://craig-russell.co.uk/demos/openlayers/so_map.html

like image 865
Craig552uk Avatar asked Jul 17 '12 11:07

Craig552uk


People also ask

What is Openlayer projection?

What projection is OpenLayers using? Every map that you'll create with OpenLayers will have a view, and every view will have a projection. As the earth is three-dimensional and round but the 2D view of a map isn't, we need a mathematical expression to represent it. Enter projections.

What is the most accurate coordinate system?

State Plane Coordinate System (SPCS) This coordinate system is highly accurate (four times as accurate as UTM).

What coordinate system does Google Maps use?

(Google uses the World Geodetic System WGS84 standard.) World coordinates, which reference a point on the map uniquely.


2 Answers

It looks like I do need to map between coordinate systems. This is done with the transform() function like so:

var coor_from = new OpenLayers.Projection("EPSG:4326");
var coor_to   = new OpenLayers.Projection("EPSG:900913");
var center    = new OpenLayers.LonLat(-1.142578125, 52.63973017532399);
var map       = new OpenLayers.Map("demoMap");
center.transform(coor_from, coor_to);
map.addLayer(new OpenLayers.Layer.OSM());
map.setCenter(center, 12);
like image 171
Craig552uk Avatar answered Sep 28 '22 04:09

Craig552uk


Now it is possible to do:

var map = new OpenLayers.Map("demoMap");
var p = map.getView().getProjection();
var cord = ol.proj.fromLonLat([longitude, latitude], p);
like image 31
boreq Avatar answered Sep 29 '22 04:09

boreq