将图块的xyz坐标转换为经度/纬度 [英] Convert xyz coordinate of a tile to longitude/latitude

查看:298
本文介绍了将图块的xyz坐标转换为经度/纬度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用openlayers制作地图,但以一种独特的方式居中.例如,我的z/x/y坐标为12/2045/-1362,如何将其转换为经度/纬度?这是完全相反的:如何通过单击传单地图获取瓷砖的XYZ坐标

I wanted to make a map using openlayers but center it a unique way. For example I have a z/x/y coordinate of 12/2045/-1362, how do I convert it to longitude/latitude? It's quite the polar opposite of this: How to get X Y Z coordinates of tile by click on Leaflet map

我很难获得上述链接的逻辑并将其反转.我希望这里的人对此有经验或现成的公式.谢谢

It's quite hard for me to get the logic of the above link and invert it. I hope someone here has an experience or a ready-made formula for this. Thanks

稍后,我将这样渲染地图中心:

Later I'll this in rendering the center of my map like this:

var z = 12;
var x = 2045;
var y = -1362;

function convertXYZtoCoor(z, x, y) {
    // code here
    return [lng, lat];
}

var coor = convertXYZtoCoor(z, x, y);
var view = new ol.View({
                    center: ol.proj.transform(
                        [coor[0], coor[1]], 'EPSG:4326', 'EPSG:3857'),
                    zoom: z
            });

var map = new ol.Map({
                layers: [
                    new ol.layer.Tile({
                        source: new ol.source.OSM()
                    })
                ],
                target: 'map',
                view: view
          });

希望我的问题得到更多的理解.

Hope my question is understood more thanks.

添加了代码

推荐答案

var tileExtent = function(tileCoord){
    var z = tileCoord[0];
    var x = tileCoord[1];
    var y = tileCoord[2];
    var tileGridOrigin = tileGrid.getOrigin(z);
    var tileSizeAtResolution = tileGrid.getTileSize(z) * tileGrid.getResolution(z);
    return [
        tileGridOrigin[0] + tileSizeAtResolution * x,
        tileGridOrigin[1] + tileSizeAtResolution * y,
        tileGridOrigin[0] + tileSizeAtResolution * (x + 1),
        tileGridOrigin[1] + tileSizeAtResolution * (y + 1)
    ];
}

您可以在 http://jsfiddle.net/eurx57s7/

注意(从ol3示例中窃取,但适用于此):图块坐标是ol3归一化图块坐标(左下角原点),而不是OSM图块坐标(左上角原点)

Note (stolen from the ol3 example, but it applies here to): The tile coordinates are ol3 normalized tile coordinates (origin bottom left), not OSM tile coordinates (origin top left)

这篇关于将图块的xyz坐标转换为经度/纬度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆