1、openlayer经纬度转xyz
function lon2tile(lon, zoom) {
return (Math.floor((lon + 180) / 360 * Math.pow(2, zoom)));
}
function lat2tile(lat, zoom) {
return (Math.floor((1 - Math.log(Math.tan(lat * Math.PI / 180) + 1 / Math.cos(lat * Math.PI / 180)) / Math.PI) / 2 * Math.pow(2, zoom)));
}
const loadMapByBounds = (minLon, minLat, maxLon, maxLat, zoom) => {
const minTileX = lon2tile(minLon, zoom);
const minTileY = lat2tile(maxLat, zoom); // Y轴是反的,自上而下
const maxTileX = lon2tile(maxLon, zoom);
const maxTileY = lat2tile(minLat, zoom);
for (let x = minTileX; x <= maxTileX; x++) {
for (let y = minTileY; y <= maxTileY; y++) {
loadTile(x, y, zoom); // 加载瓦片
}
}
}
Openlayers中的比例尺(scale)和分辨率(resolution)_openlayers 比例尺-CSDN博客
参照 :GIS中XYZ瓦片的加载流程解析与实现 - 当时明月在曾照彩云归 - 博客园
2、cesium 比例尺方法获取
// 计算当前视图的比例尺分母及分辨率
function calculateScaleDenominator(viewer) {
let scale = null;
let centerX = viewer._lastWidth / 2;
let centerY = viewer._lastHeight / 2;
let cartesian2 = new Cesium.Cartesian2(centerX, centerY);
let ray = viewer.camera.getPickRay(cartesian2);
let cartesian = viewer.scene.globe.pick(ray, viewer.scene);
if (cartesian) {
let boundingSphere = new Cesium.BoundingSphere();
boundingSphere.center = cartesian;
boundingSphere.radius = 0.1;
let resolution = viewer.scene.camera.getPixelSize(
boundingSphere,
viewer.scene.context.drawingBufferWidth,
viewer.scene.context.drawingBufferHeight
);
scale = (96 * resolution) / 0.0254;
}
return { scale: scale, resolution: resolution };
}