cesium 獲取 zoom、level 的幾種方法


  

/**
 * 獲取 zoom、level 的幾種方法
 */
// https://zhuanlan.zhihu.com/p/401514896
function getZoomLevel() {
    let h = viewer.camera.positionCartographic.height
    if (h <= 100) {return 19 }
     else if (h <= 300) {return 18 }
     else if (h <= 660) {return 17 }
     else if (h <= 1300) {return 16 }
     else if (h <= 2600) {return 15 }
     else if (h <= 6400) {return 14 }
     else if (h <= 13200) {return 13 }
     else if (h <= 26000) {return 12 }
     else if (h <= 67985) {return 11 }
     else if (h <= 139780) {return 10 }
     else if (h <= 250600) {return 9 }
     else if (h <= 380000) {return 8 }
     else if (h <= 640000) {return 7 }
     else if (h <= 1280000) {return 6 }
     else if (h <= 2600000) {return 5 }
     else if (h <= 6100000) {return 4 }
     else if (h <= 11900000) {return 3 }
     else {return 2 }
}

// https://blog.csdn.net/Tmraz/article/details/113501692
const getzoom = () => {
    var tilesToRender = viewer.scene.globe._surface._tilesToRender
    var level
    if (tilesToRender.length != 0) {
        level = tilesToRender[0].level
    }
    return level
}

// https://blog.csdn.net/qq_48203828/article/details/116999619
function heightToZoom() {
    const height = Math.ceil(viewer.camera.positionCartographic.height)
    const A = 40487.57
    const B = 0.00007096758
    const C = 91610.74
    const D = -40467.74
    return Math.round(D + (A - D) / (1 + Math.pow(height / C, B)))
}

viewer.camera.moveEnd.addEventListener(() => {
    console.log('getZoomLevel', getZoomLevel())
    console.log('heightToZoom', heightToZoom())
    console.log('getZoomLevel', getZoomLevel())
})

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM