Created
October 19, 2017 03:14
地图-瓦片计算
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 由18/19级的左上角/右下角瓦片,推导出20/21级的瓦片编码规则。 | |
* 依赖于[tile-lnglat-transform](https://github.com/CntChen/tile-lnglat-transform) | |
*/ | |
var TileLnglatTransform = require('../builds/index'); | |
var TileLnglatTransformBaidu = TileLnglatTransform.TileLnglatTransformBaidu; | |
// 可以通过百度web地图获取18级的瓦片 | |
let level = 18; | |
let data = { | |
[level]: { | |
// 左上角瓦片坐标 | |
leftTopTile: { | |
tileX: 48566, | |
tileY: 19307, | |
}, | |
// 右下角瓦片坐标 | |
rightBottomTile: { | |
tileX: 48570, | |
tileY: 19303, | |
}, | |
} | |
}; | |
// 获取瓦片左上角点的经纬度 | |
function getLeftTopPixelLatLng(level) | |
{ | |
let leftTopTile = data[level].leftTopTile; | |
return TileLnglatTransformBaidu.pixelToLnglat(5, 251, leftTopTile.tileX, leftTopTile.tileY, level); | |
} | |
// 获取瓦片右下角点的经纬度 | |
function getRightBottomPixelLatLng(_level) | |
{ | |
let rightBottomTile = data[_level].rightBottomTile; | |
return TileLnglatTransformBaidu.pixelToLnglat(251, 5, rightBottomTile.tileX, rightBottomTile.tileY, _level); | |
} | |
for(let _level = level + 1; _level <= 21; _level++) | |
{ | |
let leftTopLatLng = getLeftTopPixelLatLng(_level - 1); | |
let rightBottomLatLng = getRightBottomPixelLatLng(_level - 1); | |
let leftTopTile = TileLnglatTransformBaidu.lnglatToTile(leftTopLatLng.lng, leftTopLatLng.lat, _level); | |
let rightBottomTile = TileLnglatTransformBaidu.lnglatToTile(rightBottomLatLng.lng, rightBottomLatLng.lat, _level); | |
data[_level] = { | |
leftTopTile: leftTopTile, | |
rightBottomTile: rightBottomTile, | |
}; | |
} | |
console.log(JSON.stringify(data, null, 2)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
地图瓦片制作
输出结果: