Home.vue 2.08 KB
<template>
    <div class="home">
         <div id="cesiumContainer" style="width:100%;height:100%;"></div>
    </div>
</template>
<script>

    export default {
        components: {},
        data() {
            return {
                viewer: undefined, 
                entity: undefined,
            }
        },
        mounted() {
            Cesium.Ion.defaultAccessToken = this.config.mapToken;
            this.viewer = new Cesium.Viewer('cesiumContainer', {
                geocoder:true,
                timeline:false
            });

            this.viewer.imageryLayers.addImageryProvider(
                new Cesium.UrlTemplateImageryProvider({
                url: "https://mt1.google.cn/vt/lyrs=s&hl=zh-CN&x={x}&y={y}&z={z}&s=Gali"
            }));


            let tileset = new Cesium.Cesium3DTileset({
                url : 'http://localhost:9000/model/e44fe150d09b11eaabec1d24e8548b3a/tileset.json',
                skipLevelOfDetail : true,
                baseScreenSpaceError : 1024,
                skipScreenSpaceErrorFactor : 16,
                skipLevels : 1,
                immediatelyLoadDesiredLevelOfDetail : false,
                loadSiblings : false,
                cullWithChildrenBounds : true
            }), height = -2440;
            this.viewer.scene.primitives.add(tileset);
            
            tileset.readyPromise.then(argument => {
                var cartographic = Cesium.Cartographic.fromCartesian(tileset.boundingSphere.center);
                var surface = Cesium.Cartesian3.fromRadians(cartographic.longitude, cartographic.latitude, cartographic.height);
                var offset = Cesium.Cartesian3.fromRadians(cartographic.longitude, cartographic.latitude, cartographic.height + height);
                var translation = Cesium.Cartesian3.subtract(offset, surface, new Cesium.Cartesian3());
                tileset.modelMatrix = Cesium.Matrix4.fromTranslation(translation);
                this.viewer.zoomTo(tileset);
            });



            

        },
        methods: {
            
        }
    }
</script>

<style scoped lang="scss">

    
</style>