根据投影坐标(x,y)计算bbox
根据墨卡托投影坐标(x,y)计算该瓦片的对角线坐标bbox
import * as olProj from 'ol/proj';
import { getTopLeft, getWidth } from 'ol/extent';
const tileWidth = 256; // wms 瓦片size
const projExtent = (olProj as any).get('EPSG:3857').getExtent();
const startResolution = getWidth(projExtent) / tileWidth;
let resolutions = new Array(22);
for (let i = 0, ii = resolutions.length; i < ii; ++i) {
resolutions[i] = startResolution / Math.pow(2, i);
}
/**
* 根据投影坐标(x,y)计算bbox
* @param z zoom
* @param x tileCoord.x
* @param y tileCoord.y
* @param origin 当前地图可视视图的起始坐标(左上角)
* @returns bbox string
*/
const zxyToBbox = (z: number, x: number, y: number, origin: any) => {
let minX, minY, maxX, maxY;
let size = tileWidth * resolutions[z];
minX = origin[0] + x * size;
maxX = origin[0] + x * size + size;
minY = origin[1] - y * size - size;
maxY = origin[1] - y * size;
return [minX, minY, maxX, maxY].join(',');
}
const origin = getTopLeft(projExtent); //地图左上角坐标
zxyToBbox(zoom, x, y, origin);
我的个人博客地址:http://www.cnblogs.com/xsilence/
本文来自博客园,作者:silencetea,转载请注明原文链接:https://www.cnblogs.com/xsilence/p/17247384.html