function calculate(z, x, y) => {
// 层级
const level = Number(z);
// 瓦片坐标
const tileX = Number(x);
const tileY = Number(y);
// 像素坐标
const pixelX = {
pixel_left_X: 0,
pixel_left_Y: 255 // 左下角坐标,像素坐标系为东向,南向
};
const pixelY = {
pixel_right_X: 255,
pixel_right_Y: 0
};
// 左下经纬度
const left_lng_lat = pixelToLnglat(pixelX.pixel_left_X, pixelX.pixel_left_Y, tileX, tileY, level);
// 右上经纬度
const right_lng_lat = pixelToLnglat(pixelY.pixel_right_X, pixelY.pixel_right_Y, tileX, tileY, level);
return [left_lng_lat.lng, left_lng_lat.lat, right_lng_lat.lng, right_lng_lat.lat];
};
// 参考资料:http://wiki.openstreetmap.org/wiki/Slippy_map_tilenames
// 适用地图:高德,Google Map,OSM
function _Math_sinh(x) {
return (Math.exp(x) - Math.exp(-x)) / 2;
}
// 某一瓦片等级下瓦片地图X轴(Y轴)上的瓦片数目
function _getMapSize(level) {
return Math.pow(2, level);
}
function _pixelXTolng(pixelX, tileX, level) {
const pixelXToTileAddition = pixelX / 256.0;
const lngitude = (tileX + pixelXToTileAddition) / _getMapSize(level) * 360 - 180;
return lngitude;
}
function _pixelYToLat(pixelY, tileY, level) {
const pixelYToTileAddition = pixelY / 256.0;
const latitude = Math.atan(_Math_sinh(Math.PI * (1 - 2 * (tileY + pixelYToTileAddition) / _getMapSize(level)))) * 180.0 / Math.PI;
// let latitude = Math.atan(_Math_sinh(Math.PI * (-1 + 2 * (tileY + 1 - pixelYToTileAddition) / _getMapSize(level)))) * 180.0 / Math.PI; osm坐标系
return latitude;
}
// 从某一瓦片的某一像素点到经纬度
function pixelToLnglat(pixelX, pixelY, tileX, tileY, level) {
const lng = _pixelXTolng(pixelX, tileX, level);
const lat = _pixelYToLat(pixelY, tileY, level);
return {
lng,
lat
};
}
计算瓦片对应的经纬度
最新推荐文章于 2023-02-26 23:40:01 发布