墨卡托投影无法正常工作

mercator projection is not working fine?

本文关键字:常工作 工作 投影      更新时间:2023-09-26

我需要在我的 svg 应用程序中使用墨卡托投影按纬度和对数指向地点。我已经撒了很多,我得到了这些链接,


http://en.wikipedia.org/wiki/Mercator_projection墨卡托投影上像素 (x,y) 的隐蔽纬度/经度点

法典

            //this lat and long is for chicago
            var latitude = 41.850033; // (φ)
            var longitude = -87.65005229999997;   // (λ)
            var PI = 3.14;
            var mapWidth = 750;
            var mapHeight = 380;
            // get x value
            var x = (mapWidth * (180+longitude) / 360) % mapWidth + (mapWidth / 2);
            // convert from degrees to radians
            var latRad = latitude * PI / 180;
            // get y value
            var mercN = Math.log(Math.tan((PI / 4) + (latRad / 2)));
            var y = (mapHeight / 2) - (mapWidth * mercN / (2 * PI));

我已经在我的应用程序中使用了这段代码,但它对我不起作用。
请帮助从纬度和经度获取 x 和 y 位置。任何建议都应不胜感激。

您忘记了地图的左上角和右下角,以及乘以 x,y 坐标以给出正确地图投影的因子。您可以使用固定的地图坐标,即因子,也可以计算边界框:将纬度/纬度转换为像素坐标?然后计算适合地图宽度和高度的世界宽度和高度。