Cesium 解析3DTile的包圍盒中心點(diǎn)坐標(biāo)

從3DTile數(shù)據(jù)的tileset.json文件中姨裸,解析出包圍盒中心點(diǎn)坐標(biāo)悲敷。包圍盒包含:box覆履、region蹋盆、sphere费薄。
用經(jīng)緯度記錄數(shù)據(jù)的WGS84坐標(biāo)系,WKID是4326栖雾,用地心為坐標(biāo)原點(diǎn)的空間直角坐標(biāo)來記錄數(shù)據(jù)的坐標(biāo)系义锥,WKID是4979。3dTiles用的就是4979坐標(biāo)系岩灭。

效果

1665740109(1).png

代碼

<template>
    <div>
        <div id="cesiumContainer"></div>
        <div class="form">
            <div>3DTile包圍盒中心點(diǎn)解析結(jié)果:</div>
            <div>經(jīng)度:{{ lon }}</div>
            <div>緯度:{{ lat }}</div>
            <div>高度:{{ height }}</div>
        </div>
    </div>
</template>

<script>
export default {
    name: "Calc3DTileCenter",
    data() {
        return {
            lon: 0,
            lat: 0,
            height: 0,
        };
    },
    mounted() {
        this.initViewer();
        this.load3DTile();
    },
    methods: {
        initViewer() {
            let defaultRect = Cesium.Rectangle.fromDegrees(90, 20, 130, 50);
            Cesium.Camera.DEFAULT_VIEW_RECTANGLE = defaultRect;
            window.viewer = new Cesium.Viewer("cesiumContainer", {
                animation: false,
                shouldAnimate: true,
                baseLayerPicker: false,
                fullscreenButton: false,
                geocoder: false,
                homeButton: false,
                sceneModePicker: false,
                selectionIndicator: false,
                timeline: false,
                navigationHelpButton: false,
                infoBox: false,
                navigationInstructionsInitiallyVisible: false,
                imageryProvider: new Cesium.UrlTemplateImageryProvider({
                    url: "https://webst01.is.autonavi.com/appmaptile?style=6&x={x}&y={y}&z={z}",
                }),
            });
            window.viewer.scene.debugShowFramesPerSecond = true;
        },
        // 加載3DTile
        load3DTile() {
            // box
            let url = "data/BatchTableHierarchy/tileset.json";
            // region
            // let url = "data/Tileset/tileset.json";
            // sphere
            // let url = "data/ceke/tileset.json";
            this.calc3DTileCenter(url);
            let tileset = new Cesium.Cesium3DTileset({
                url: url,
            });
            viewer.scene.primitives.add(tileset);
            viewer.zoomTo(tileset);
        },
        // 解析包圍盒中心點(diǎn)坐標(biāo)
        calc3DTileCenter(url) {
            axios.get(url).then((response) => {
                let data = response.data;
                let root = data.root;
                let boundingVolume = root.boundingVolume;
                let modelCenter;
                if (boundingVolume.hasOwnProperty("box")) {
                    let x = boundingVolume.box[0];
                    let y = boundingVolume.box[1];
                    let z = boundingVolume.box[2];
                    let w = 1;
                    modelCenter = new Cesium.Cartesian4(x, y, z, w);
                } else if (boundingVolume.hasOwnProperty("region")) {
                    let x = (boundingVolume.region[0] + boundingVolume.region[2]) / 2;
                    let y = (boundingVolume.region[1] + boundingVolume.region[3]) / 2;
                    let z = (boundingVolume.region[4] + boundingVolume.region[5]) / 2;
                    let cartographic = new Cesium.Cartographic(x, y, z);
                    let wgs84Cartesian3 = Cesium.Cartographic.toCartesian(cartographic);
                    modelCenter = new Cesium.Cartesian4(wgs84Cartesian3.x, wgs84Cartesian3.y, wgs84Cartesian3.z, 1);
                } else if (boundingVolume.hasOwnProperty("sphere")) {
                    let x = boundingVolume.sphere[0];
                    let y = boundingVolume.sphere[1];
                    let z = boundingVolume.sphere[2];
                    let w = 1;
                    modelCenter = new Cesium.Cartesian4(x, y, z, w);
                }
                // 是否有轉(zhuǎn)換矩陣
                if (root.hasOwnProperty("transform")) {
                    let transform = root.transform;
                    let matrix4 = Cesium.Matrix4.fromColumnMajorArray(transform);
                    let wgs84Cartesian4 = Cesium.Matrix4.multiplyByVector(matrix4, modelCenter, new Cesium.Cartesian4());
                    let wgs84Cartesian3 = Cesium.Cartesian3.fromCartesian4(wgs84Cartesian4);
                    let wgs84Cartographic = Cesium.Cartographic.fromCartesian(wgs84Cartesian3);
                    let lon = Cesium.Math.toDegrees(wgs84Cartographic.longitude);
                    let lat = Cesium.Math.toDegrees(wgs84Cartographic.latitude);
                    let height = wgs84Cartographic.height;
                    this.lon = lon;
                    this.lat = lat;
                    this.height = height;
                } else {
                    let wgs84Cartographic = Cesium.Cartographic.fromCartesian(modelCenter);
                    let lon = Cesium.Math.toDegrees(wgs84Cartographic.longitude);
                    let lat = Cesium.Math.toDegrees(wgs84Cartographic.latitude);
                    let height = wgs84Cartographic.height;
                    this.lon = lon;
                    this.lat = lat;
                    this.height = height;
                }
            });
        },
    },
};
</script>

<style scoped>
#cesiumContainer {
    position: absolute;
    width: 100%;
    height: 100%;
}
.form {
    position: absolute;
    background-color: #ffffff;
    padding: 5px;
    top: 5px;
    left: 5px;
}
</style>
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個(gè)濱河市赂鲤,隨后出現(xiàn)的幾起案子噪径,更是在濱河造成了極大的恐慌,老刑警劉巖数初,帶你破解...
    沈念sama閱讀 217,277評(píng)論 6 503
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件找爱,死亡現(xiàn)場(chǎng)離奇詭異,居然都是意外死亡泡孩,警方通過查閱死者的電腦和手機(jī)车摄,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,689評(píng)論 3 393
  • 文/潘曉璐 我一進(jìn)店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來仑鸥,“玉大人吮播,你說我怎么就攤上這事⊙劭。” “怎么了意狠?”我有些...
    開封第一講書人閱讀 163,624評(píng)論 0 353
  • 文/不壞的土叔 我叫張陵,是天一觀的道長(zhǎng)疮胖。 經(jīng)常有香客問我环戈,道長(zhǎng),這世上最難降的妖魔是什么澎灸? 我笑而不...
    開封第一講書人閱讀 58,356評(píng)論 1 293
  • 正文 為了忘掉前任院塞,我火速辦了婚禮,結(jié)果婚禮上性昭,老公的妹妹穿的比我還像新娘拦止。我一直安慰自己,他們只是感情好巩梢,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,402評(píng)論 6 392
  • 文/花漫 我一把揭開白布创泄。 她就那樣靜靜地躺著,像睡著了一般括蝠。 火紅的嫁衣襯著肌膚如雪鞠抑。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 51,292評(píng)論 1 301
  • 那天忌警,我揣著相機(jī)與錄音搁拙,去河邊找鬼秒梳。 笑死,一個(gè)胖子當(dāng)著我的面吹牛箕速,可吹牛的內(nèi)容都是我干的酪碘。 我是一名探鬼主播,決...
    沈念sama閱讀 40,135評(píng)論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼盐茎,長(zhǎng)吁一口氣:“原來是場(chǎng)噩夢(mèng)啊……” “哼兴垦!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起字柠,我...
    開封第一講書人閱讀 38,992評(píng)論 0 275
  • 序言:老撾萬榮一對(duì)情侶失蹤探越,失蹤者是張志新(化名)和其女友劉穎,沒想到半個(gè)月后窑业,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體钦幔,經(jīng)...
    沈念sama閱讀 45,429評(píng)論 1 314
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,636評(píng)論 3 334
  • 正文 我和宋清朗相戀三年常柄,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了鲤氢。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點(diǎn)故事閱讀 39,785評(píng)論 1 348
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡西潘,死狀恐怖卷玉,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情喷市,我是刑警寧澤揍庄,帶...
    沈念sama閱讀 35,492評(píng)論 5 345
  • 正文 年R本政府宣布,位于F島的核電站东抹,受9級(jí)特大地震影響蚂子,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜缭黔,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,092評(píng)論 3 328
  • 文/蒙蒙 一食茎、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧馏谨,春花似錦别渔、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,723評(píng)論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至喊儡,卻和暖如春拨与,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背艾猜。 一陣腳步聲響...
    開封第一講書人閱讀 32,858評(píng)論 1 269
  • 我被黑心中介騙來泰國打工买喧, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留捻悯,地道東北人。 一個(gè)月前我還...
    沈念sama閱讀 47,891評(píng)論 2 370
  • 正文 我出身青樓淤毛,卻偏偏與公主長(zhǎng)得像今缚,于是被迫代替她去往敵國和親。 傳聞我的和親對(duì)象是個(gè)殘疾皇子低淡,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 44,713評(píng)論 2 354

推薦閱讀更多精彩內(nèi)容