vue+cesium初探(二)之绘制形状

1、在views新建Box.vue

<template>
  <div id="container" class="box">
    <div id="cesiumContainer"></div>
  </div>
</template>

<script>
export default {
  name: 'Home',
  mounted(){
    this.init()
  },
  methods: {
    init() {
      let Cesium = this.cesium
      let viewer = new Cesium.Viewer('cesiumContainer');
      var redBox = viewer.entities.add({
        name : '杭州上方三千米的蓝色半透明的盒子',
        position: Cesium.Cartesian3.fromDegrees(120.15, 30.28, 3000.0),
        box : {
          dimensions : new Cesium.Cartesian3(4000.0, 3000.0, 5000.0),
          material : Cesium.Color.BLUE.withAlpha(0.5),
          outline : true,
          outlineColor : Cesium.Color.BLACK
        }
      });

      viewer.zoomTo(viewer.entities);

      viewer._cesiumWidget._creditContainer.style.display = "none";// 隐藏版权
    }
  }
};
</script>

<style lang='scss' scoped>
html,
body,
#cesiumContainer {
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
  overflow: hidden;
}
</style>

2、配置路由

import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/Home.vue'

Vue.use(VueRouter)

  const routes = [
  {
    path: '/',
    name: 'Home',
    component: Home
  },
  {
    path: '/box',
    name: 'Box',
    component: () => import('../views/Box.vue')
  }
]

const router = new VueRouter({
  routes
})

export default router

3、修改App.vue

<template>
  <div id="app">
    <div class="menu">
      <div v-for="(item,index) in menuList" :key="index" class="item" @click="toPage(item.path)">
        {{item.title}}
      </div>
    </div>
    <router-view/>
  </div>
</template>

<script>
export default {
  data(){
    return{
      menuList : [
        {
          title : '首页',
          path : '/'
        },
        {
          title : '形状',
          path : '/box'
        }
      ]
    }
  },
  methods:{
    toPage(path){
      this.$router.push(path)
    }
  }
}
</script>
<style lang="scss">
html,
body,
#app {
  height: 100%;
  width: 100%;
  padding: 0;
  margin: 0;
  color: #000;
  overflow: hidden;
}

.box {
  height: calc(100vh - 50px);
} 

.menu{
  background-color: #000000;
  color: #ffffff;
  height: 50px;
  line-height: 50px;
  display: flex;
}

.item{
  margin: 0 10px;
  cursor: pointer;
}
</style>

4、效果图

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值