首页 > 其他分享 >根据投影坐标(x,y)计算bbox

根据投影坐标(x,y)计算bbox

时间:2023-03-23 14:44:06浏览次数:31  
标签:origin const 坐标 投影 bbox resolutions size

根据墨卡托投影坐标(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); 

标签:origin,const,坐标,投影,bbox,resolutions,size
From: https://www.cnblogs.com/xsilence/p/17247384.html

相关文章