地图金字塔所在块的经纬度范围

地图金字塔所在块的经纬度范围 算法

地图金字塔从第0层开始

#define LON_SPAN 360.0
// 开始经度(最左端)
#define LAT_SPAN 180.0
#define GLOBAL_LEFT -180.0
// 开始纬度(最上端)
#define GLOBAL_TOP 90.0
#define GLOBAL_RIGHT 180.0
#define GLOBAL_BOTTOM -90.0
// 地球的纬度跨度(180-(-180)):360
#define LON_SPAN (GLOBAL_RIGHT - GLOBAL_LEFT)
// 地球的纬度跨度(90-(-90)):180
#define LAT_SPAN (GLOBAL_TOP - GLOBAL_BOTTOM)

	/// 
	/// 给出块所在的层行列,求该块的经纬范围
	/// 
	/// 块所在的列
	/// 块所在的行
	/// 层数(start from 0)
	void block_lat_and_lon_range(int storey, int block_x, int block_y, float& block_left, float& block_right, float& block_top, float& block_bottom)
	{
	    // 得到该块的经纬度坐标边界
    	int n = pow(2, storey);
    	// 经度
   	 	float tile_width = LON_SPAN / n; // 每块的纬度跨度
    	block_left = GLOBAL_LEFT + (block_y * tile_width);
    	block_right = GLOBAL_LEFT + ((block_y + 1) * tile_width);
    	// 纬度
    	float tile_height = LAT_SPAN / n; // 每块的经度跨度
    	block_top = GLOBAL_TOP - (block_x * tile_height);
    	block_bottom = GLOBAL_TOP - ((block_x + 1) * tile_height);
	}

你可能感兴趣的:(C++,地图金字塔)