<template>
  <div class="plant-gs-warp">
    <div ref="viewwarp" class="plant-gs-content" :style="{ 'background-image': 'url(' + getAssetsFile('images/plant/bg1.png') + ')' }">
      <vc-config-provider :cesium-path="vcConfig.cesiumPath" :access-token="vcConfig.accessToken">
        <vc-viewer ref="viewerRef" @ready="onViewerReady">
          <vc-layer-imagery :minimum-level="12" :maximum-level="18" :contrast="1.8" :saturation="1" :alpha="1">
            <vc-imagery-provider-amap :key="'c843a50db7157faf295c6fa37c48719f'"></vc-imagery-provider-amap>
          </vc-layer-imagery>

          <vc-overlay-html ref="html" :position="pos" :show="show">
            <div class="vc-name">耿马镇</div>
          </vc-overlay-html>

          <vc-entity description="Hello VueCesium">
            <vc-graphics-rectangle
              ref="rectangle2"
              :coordinates="hierarchy4"
              :material="[59, 199, 231, 80]"
              :rotation="0.9"
              :extruded-height="1000"
              :height="0"
              :outline="true"
              :outline-width="0.1"
              :clamp-to-ground="false"
              :outline-color="[59, 199, 231, 150]"
            ></vc-graphics-rectangle>
          </vc-entity>
        </vc-viewer>
      </vc-config-provider>
    </div>
  </div>
</template>
<script setup>
import { isEmpty, getAssetsFile } from '@/utils';
import { ref, reactive, onMounted, computed, nextTick, getCurrentInstance } from 'vue';
import {
  VcViewer,
  VcConfigProvider,
  VcImageryProviderAmap,
  VcLayerImagery,
  VcGraphicsPlane,
  VcEntity,
  VcGraphicsPolygon,
  VcGraphicsRectangle,
  VcOverlayHtml,
} from 'vue-cesium';
import 'vue-cesium/dist/index.css';

const vcConfig = reactive({
  cesiumPath: 'https://cdn.bootcdn.net/ajax/libs/cesium/1.80.0/Cesium.js',
  accessToken:
    'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiJiNjJjZTUxYi1lOTQ3LTQ3YjctOGI3ZS02ZGUzY2E4YWFkNDkiLCJpZCI6Mjg4MjAxLCJpYXQiOjE3NDMwNTY0MzN9.rjHQiqf7Y8bccaqsapqveULVAUH6M1QkeFp-AKG-frA',
});
const viewerRef = ref(null);
const viewwarp = ref(null);
const rectangle2 = ref(null);

onMounted(() => {
  Promise.all([rectangle2.value.creatingPromise]).then((instances) => {
    // console.info('aa', instances[0].viewer.entities);
    instances[0].viewer.zoomTo(instances[0].viewer.entities);
  });
});
const hierarchy4 = reactive([99.302267, 23.438899, 99.312267, 23.448889]);
const pos = reactive([99.302267, 23.438899]);

const onViewerReady = (readyObj) => {
  console.info('readyObj', readyObj.Cesium); // Cesium namespace object
  console.log(readyObj.viewer); // instanceof Cesium.Viewer

  const { Cesium, viewer } = readyObj;

  // 设置相机视角
  viewer.camera.setView({
    destination: Cesium.Cartesian3.fromDegrees(99.516667, 23.640556, 4000), // 目标中心点
    orientation: {
      ading: Cesium.Math.toRadians(6), //
      pitch: Cesium.Math.toRadians(-25), //
      roll: Cesium.Math.toRadians(6), //
    },
  });
};
</script>
<style lang="scss" scoped>
.plant-gs-warp {
  height: 100%;
  padding: 10px 0;
  width: 100%;
  box-sizing: border-box;
  .plant-gs-content {
    background-size: 100% 100%;
    background-repeat: no-repeat;
    width: 100%;
    height: 100%;
    overflow: hidden;
    .vc-name {
      color: #fff;
      font-size: 16px;
      font-weight: bold;
    }
    ::v-deep() {
      .vc-viewer {
        height: calc(100% - 30px) !important;
        width: calc(100% - 20px) !important;
        margin: 20px 10px 10px 10px !important;
      }
      canvas {
        border-radius: 10px !important;
      }
      .cesium-viewer-bottom {
        display: none !important;
      }
    }
  }
}
</style>
