In general, to render a map, tell me how to bring the coordinates of Lon and Lat to such a view as to display them on a plane (without third-party libraries). Otherwise, the map looks deformable. Thank.

  • 3
    There are dozens of methods for transforming geographic coordinates into Cartesian for projecting the earth's surface onto a plane (creating maps). The choice of method may depend on the size of the section of the earth's surface, its location, the destination of the map. An additional complication is the choice of a geographic datum, that is, the shape / size of the ellipsoid and its position relative to WGS84. One of the commonly used types of transformations is the Mercator projection. - Igor

1 answer 1

In general, I use the following formulas now:

latToCart : function(lat, zoom) { return (Math.floor((1-Math.log(Math.tan(lat*Math.PI/180) + 1/Math.cos(lat*Math.PI/180))/Math.PI)/2 *Math.pow(2,zoom))); }, lonToCart : function(lon, zoom) { return Math.floor((lon + 180) / 360 * Math.pow(2, zoom)); }, cartToLat : function(x, y, zoom) { var n=Math.PI-2*Math.PI*y/Math.pow(2,z); return (180/Math.PI*Math.atan(0.5*(Math.exp(n)-Math.exp(-n)))); }, cartToLon : function(x, y, zoom) { return (x/Math.pow(2,z)*360-180); }