cesium只展示某个区域市省地图

效果如下所示:

主要是调用_c_add_geojson_area方法

代码如下:geojson数据获取:DataV.GeoAtlas地理小工具系列

<template>
  <div class="mapBox">
    <div id="cesium" ref="cesium"></div>
  </div>
</template>

<script>
import mapMixin from "./js/mapMixin";
import geojson from "./js/data/town.json";
export default {
  data() {
    return {
      viewer:null,
      tilesets:null
    }
  },
  mounted() {
    this.mapInit();
  },
  methods: {
    mapInit() {
      Cesium.Camera.DEFAULT_VIEW_RECTANGLE = Cesium.Rectangle.fromDegrees( 90, -20, 110, 90); //西南东北,默认显示中国
      this.viewer = new Cesium.Viewer("cesium", {
        animation: false, //是否显示动画控件
        homeButton: false, //是否显示home键
        geocoder: false,// 查询
        baseLayerPicker: false, //是否显示图层选择控件
        timeline: false, //是否显示时间线控件
        fullscreenButton: false, //是否全屏显示
        scene3DOnly: true, //如果设置为true,则所有几何图形以3D模式绘制以节约GPU资源
        infoBox: false, //是否显示点击要素之后显示的信息
        sceneModePicker: false, //是否显示投影方式控件  三维/二维
        navigationHelpButton: false, //是否显示帮助信息控件
        imageryProvider: new Cesium.UrlTemplateImageryProvider({
          url: "http://map.geoq.cn/ArcGIS/rest/services/ChinaOnlineStreetPurplishBlue/MapServer/tile/{z}/{y}/{x}",
        }),
        terrainProvider: new Cesium.CesiumTerrainProvider({ 
          url: "http://data.marsgis.cn/terrain"
        }),
        skyAtmosphere:false,
        // orderIndependentTranslucency: false,
        contextOptions: {
          webgl: {
            alpha: true,
          },
        },
      });
      // 设置基本属性
      this.viewer.scene.sun.show = false; 
      this.viewer.scene.moon.show = false;
      this.viewer.scene.skyBox.show = false; //关闭天空盒,否则会显示天空颜色
      this.viewer.scene.undergroundMode = true; 
      this.viewer.scene.globe.show = true; 
      this.viewer.scene.backgroundColor = new Cesium.Color(0, 0, 0, 0);
      this.viewer.scene.screenSpaceCameraController.minimumZoomDistance = 1000;
      this.viewer.scene.screenSpaceCameraController.maximumZoomDistance = 5600000;
      if (Cesium.FeatureDetection.supportsImageRenderingPixelated()) {
        //判断是否支持图像渲染像素化处理
        this.viewer.resolutionScale = window.devicePixelRatio;
      }
      this.viewer.scene.fxaa = true;
      this.viewer.scene.postProcessStages.fxaa.enabled = true;
      // 隐藏版权
      this.viewer._cesiumWidget._creditContainer.style.display = "none";

      this.viewer.scene.camera.setView({
        destination: Cesium.Cartesian3.fromDegrees(
          120.952811,31.854272,
          6000
        ),
        orientation: {
          heading: Cesium.Math.toRadians(0),
          pitch: Cesium.Math.toRadians(-40),
          roll: Cesium.Math.toRadians(0), //heading、pitch和roll就是镜头相对于xyz轴的角度,比如pitch为-90°而另外两个为0时,就是90°向下俯视地球。
        },
      });
      mapMixin.viewer = this.viewer

      mapMixin._c_add_geojson_area(geojson)   // 只显示区域地图
    },
  },
  }
</script>
<style lang='scss'>
.mapBox{
  width: 100%;
  height: 100%;
  #cesium{
    width: 100%;
    height: 100%;
    padding:20px;
    box-sizing: border-box;
  }
  .cesium-selection-wrapper,.cesium-selection-wrapper-visible{
    display: none!important;
  }
}
</style>

 _c_add_geojson_area方法代码如下:

// 只展示geojson地图
    _c_add_geojson_area: function(geojson){
      console.log(geojson.features[0].geometry.coordinates[0]);
      let arr = []
      geojson.features[0].geometry.coordinates[0][0].forEach(item => {
        arr.push(item[0])
        arr.push(item[1])
      });
      console.log(arr);
      var polygonWithHole = new Cesium.PolygonGeometry({
          polygonHierarchy: new Cesium.PolygonHierarchy(
            Cesium.Cartesian3.fromDegreesArray([73.0, 53.0, 73.0, 0.0, 135.0, 0.0, 135.0, 53.0]), 
            [new Cesium.PolygonHierarchy(Cesium.Cartesian3.fromDegreesArray(arr))]
          )
      });
      var geometry = Cesium.PolygonGeometry.createGeometry(polygonWithHole);
      let instances = [];
      instances.push(new Cesium.GeometryInstance({
          geometry: geometry,
          attributes: {
              color: Cesium.ColorGeometryInstanceAttribute.fromColor(Cesium.Color.fromCssColorString("#081122"))
          }
      }));
      function addRect(instances, left, down, right, up) {
        instances.push(new Cesium.GeometryInstance({
          geometry: new Cesium.RectangleGeometry({
            rectangle: Cesium.Rectangle.fromDegrees(left, down, right, up)
          }),
          attributes: {
            color: Cesium.ColorGeometryInstanceAttribute.fromColor(Cesium.Color.fromCssColorString("#081122"))
          }
        }));
      }
      addRect(instances, -180.0, -90.0, 73.0, 90.0);
      addRect(instances, 135.0, -90.0, 180.0, 90.0);
      addRect(instances, 73.0, 53.0, 135.0, 90.0);
      addRect(instances, 73.0, -90.0, 135.0, 0.0);
      this.viewer.scene.primitives.add(new Cesium.Primitive({
        geometryInstances: instances,
        appearance: new Cesium.PerInstanceColorAppearance({
          flat: true,
          translucent: false
        })
      }));
    },

 

  • 3
    点赞
  • 18
    收藏
    觉得还不错? 一键收藏
  • 10
    评论
Cesium是一款基于WebGL的地球可视化引擎,可以用于展示地球和空间数据的三维可视化效果。在Cesium中,展示弹窗是一种常见的交互方式,用于在地球上显示地点或者要素的详细信息。 展示弹窗可以通过一系列的鼠标或者触摸操作触发,比如单击地球上的特定点、悬停在特定要素上、或者通过程序控制等。当展示弹窗被触发时,弹窗会在地球的特定位置显示,并呈现相关的信息。 在弹窗中,可以展示各种信息,比如地点的名称、经纬度、高度、描述、图片、链接等。这些信息可以根据具体的需求进行自定义,以展示不同类型的地理数据。 Cesium提供了一套API,开发者可以通过编写代码来创建和控制展示弹窗。首先,需要创建一个弹窗实例,并设置其显示的位置和样式。然后,可以将需要显示的内容添加到弹窗中,比如文字、图片等。最后,通过开启或关闭弹窗的可见状态来控制弹窗的显示和隐藏。 展示弹窗可以增强用户与地球数据的交互体验,使用户能够更加直观地了解和浏览地球上的特定信息。例如,在地理信息系统(GIS)应用中,展示弹窗可以用于展示不同位置的特征、属性和测量结果,有助于用户对地球数据进行分析和决策。 总而言之,Cesium展示弹窗是一种交互方式,可以在地球上显示地点或要素的详细信息,通过适当的操作和代码编写,可以实现各种需求,提供更加丰富的地球可视化体验。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值