3. Cesium使用并引用天地图图层

1. Cesium使用

<template>
  <div>
    <div id="cesiumContainer"></div>
  </div>
</template>

<script setup lang="ts" name="cesium">
import { onMounted, ref, onBeforeUnmount } from "vue";
import * as Cesium from 'cesium'

import { cesiumProps } from "./props";

const props = defineProps(cesiumProps)

const viewer = ref()
onMounted(()=>{
  // 服务负载子域
  const subdomains = ['0','1','2','3','4','5','6','7'];
  Cesium.Ion.defaultAccessToken = props.cesiumAsset;

  viewer.value = new Cesium.Viewer('cesiumContainer',{
    shouldAnimate: true,
    animation: false,       //动画
    homeButton:false,       //home键
    geocoder:false,         //地址编码
    baseLayerPicker:false, //图层选择控件
    timeline:false,        //时间轴
    fullscreenButton:false, //全屏显示
    infoBox:false,         //点击要素之后浮窗
    sceneModePicker:false,  //投影方式  三维/二维
    navigationInstructionsInitiallyVisible:false, //导航指令
    navigationHelpButton:false,     //帮助信息
    selectionIndicator:false, // 选择
    imageryProvider: new Cesium.WebMapTileServiceImageryProvider({
      //影像底图
      url: "http://t{s}.tianditu.com/img_w/wmts?service=wmts&request=GetTile&version=1.0.0&LAYER=img" +
          "&tileMatrixSet=w&TileMatrix={TileMatrix}&TileRow={TileRow}&TileCol={TileCol}&style=default&format=tiles&tk="+props.tiandituTk,
      subdomains: subdomains,
      layer: "tdtImgLayer",
      style: "default",
      format: "image/jpeg",
      tileMatrixSetID: "GoogleMapsCompatible",//使用谷歌的瓦片切片方式
      show: true
    })
  });
  viewer.value._cesiumWidget._creditContainer.style.display = "none";  // 隐藏cesium ion
  viewer.value.imageryLayers.addImageryProvider(new Cesium.WebMapTileServiceImageryProvider({
    //影像注记
    url: "http://t{s}.tianditu.com/cia_w/wmts?service=wmts&request=GetTile&version=1.0.0&LAYER=cia&tileMatrixSet=w" +
        "&TileMatrix={TileMatrix}&TileRow={TileRow}&TileCol={TileCol}&style=default.jpg&tk="+props.tiandituTk,
    subdomains: subdomains,
    layer: "tdtCiaLayer",
    style: "default",
    format: "image/jpeg",
    tileMatrixSetID: "GoogleMapsCompatible",
    show: true
  }));

  props.cesiumLoadCB(viewer.value)
})

onBeforeUnmount(()=> {
  viewer.value.destroy();
})

</script>

<style scoped>
#cesiumContainer{
  width: 100vw;
  height: 100vh;
  padding: 0;
  margin: 0;
  /*overflow: hidden;*/
}
</style>

2. 天地图图层

2.1 加载影像底图

 imageryProvider: new Cesium.WebMapTileServiceImageryProvider({
      //影像底图
      url: "http://t{s}.tianditu.com/img_w/wmts?service=wmts&request=GetTile&version=1.0.0&LAYER=img" +
          "&tileMatrixSet=w&TileMatrix={TileMatrix}&TileRow={TileRow}&TileCol={TileCol}&style=default&format=tiles&tk="+props.tiandituTk,
      subdomains: subdomains,
      layer: "tdtImgLayer",
      style: "default",
      format: "image/jpeg",
      tileMatrixSetID: "GoogleMapsCompatible",//使用谷歌的瓦片切片方式
      show: true
    })

2.2 加载影像底标注

  viewer.value.imageryLayers.addImageryProvider(new Cesium.WebMapTileServiceImageryProvider({
    //影像注记
    url: "http://t{s}.tianditu.com/cia_w/wmts?service=wmts&request=GetTile&version=1.0.0&LAYER=cia&tileMatrixSet=w" +
        "&TileMatrix={TileMatrix}&TileRow={TileRow}&TileCol={TileCol}&style=default.jpg&tk="+props.tiandituTk,
    subdomains: subdomains,
    layer: "tdtCiaLayer",
    style: "default",
    format: "image/jpeg",
    tileMatrixSetID: "GoogleMapsCompatible",
    show: true
  }));
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Cesium是一个开源的地球可视化引擎,高德地图是中国主要的地图服务提供商。在Cesium使用高德地图图层时,可能会出现一些偏移的问题。 这种偏移问题主要是由于不同地图服务提供商使用了自己的坐标系统或投影方式,导致不同地图之间存在一定的地理坐标偏移。在使用高德地图图层时,也会遇到类似的偏移情况。 为了解决这个问题,可以尝试以下两种方法来进行偏移修正。 第一种方法是手动修正。在Cesium中,我们可以通过手动调整图层的位置,使其与其他图层或实际地图上的特定位置对齐。调整的方法可以根据实际情况选择,在代码中设置图层的位置坐标。 第二种方法是使用坐标转换库。可以使用一些开源的坐标转换库,如Proj4js、Coordinate Transformations for Cesium等,将高德地图的坐标转换到与Cesium相同的坐标系或投影系统。通过使用这些坐标转换库,可以将高德地图的坐标进行转换,以解决偏移问题。 需要注意的是,每个地图服务提供商可能会采用不同的坐标系统、投影方式或坐标转换方法。因此,在使用高德地图图层时,需要根据实际情况选择适合的坐标转换方法,并进行相应的调整。 总之,在Cesium使用高德地图图层时存在一定的偏移问题,可以通过手动修正或使用坐标转换库来解决。根据实际情况选择适合的方法,进行相应的调整,以实现准确的地图显示。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值