简体   繁体   English

将图块的xyz坐标转换为经度/纬度

[英]Convert xyz coordinate of a tile to longitude/latitude

I wanted to make a map using openlayers but center it a unique way. 我想用openlayers制作一张地图,但却以独特的方式居中。 For example I have az/x/y coordinate of 12/2045/-1362, how do I convert it to longitude/latitude? 例如,我的z / x / y坐标为12/2045 / -1362,如何将其转换为经度/纬度? It's quite the polar opposite of this: How to get XYZ coordinates of tile by click on Leaflet map 这与此极为相反: 如何通过单击Leaflet map获取tile的XYZ坐标

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. 希望我的问题得到更多的理解。

Edit: Added code 编辑:添加代码

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)
    ];
}

You can test/verify at http://jsfiddle.net/eurx57s7/ 您可以在http://jsfiddle.net/eurx57s7/进行测试/验证

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) 注意(从ol3示例中窃取,但它适用于此处): 图块坐标是ol3标准化图块坐标(原点左下角),而不是OSM图块坐标(原点左上角)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM