cesium之深圳区域行政图

效果如下
在这里插入图片描述

class District{
	constructor() {
		this.viewer = null
		this.init()
	}

	init() {
		//初始化地图
		this.initMap()
		
		//渲染行政区域图
		this.renderDistrict()	

		//去掉ntity的点击事件
		this.removeClick()	
	}

	initMap() {
		this.viewer = new Cesium.Viewer('cesiumContainer',{
			geocoder: false,
			baseLayerPicker: false,
			sceneModePicker: false,
			fullscreenButton: false,
			navigationHelpButton: false,
			sceneMode: Cesium.SceneMode.SCENE3D,
			shouldAnimate: true,
			animation: false,
			timeline: false,
			imageryProvider: new Cesium.WebMapTileServiceImageryProvider({
				url: "http://t0.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=1a7ec240fc2783062616cc53caac5514",
				layer: "tdtBasicLayer",
				style: "default",
				format: "image/jpeg",
				tileMatrixSetID: "GoogleMapsCompatible",
				maximumLevel: 18,
				show: false,
		   })
		});
						 
		this.viewer.camera.flyTo({
			destination : Cesium.Cartesian3.fromDegrees(114.14743519182551,22.575871697376243, 100000.0)
		});
	}

	removeClick() {
      	this.viewer.cesiumWidget.screenSpaceEventHandler.removeInputAction(Cesium.ScreenSpaceEventType.LEFT_DOUBLE_CLICK);
      	this.viewer.cesiumWidget.screenSpaceEventHandler.removeInputAction(Cesium.ScreenSpaceEventType.LEFT_CLICK);
	}

	renderDistrict() {
		   
		 Cesium.GeoJsonDataSource.load('./district.json',{
            stroke: Cesium.Color.WHITE,//设置多边形轮廓的默认颜色
            strokeWidth: 20,//轮廓的宽度
            clamToGround: true//让地图贴地
        }).then((dataSource)=>{

            this.viewer.dataSources.add(dataSource);

            let entities = dataSource.entities.values;

            for (let i = 0; i < entities.length; i++) {

                let entity = entities[i];
            
                //将随机产生的颜色赋予多边形
               	//对南山和宝安进行特殊处理,让多个区块颜色保持一致
               	if(entity._name == '宝安区'){

               		entity.polygon.material = Cesium.Color.ORANGE.withAlpha(0.5);
               	}else 
               		if(entity._name == '南山区'){
               			entity.polygon.material = Cesium.Color.RED.withAlpha(0.5);
               		}	
               		else{
               			entity.polygon.material = Cesium.Color.fromRandom({ alpha: 0.5 });
               		}
                 
                let polyCenter = Cesium.Cartesian3.fromDegrees(entity._properties.centroid._value[0],entity._properties.centroid._value[1], 100);
                
                this.viewer.entities.add({
                    position: polyCenter,
                    label: {
                        font: '24px sans-serif',
                        text: entity._name,
                        showBackground: true,
                        scale: 0.6,
                        horizontalOrigin: Cesium.HorizontalOrigin.CENTER,
                        verticalOrigin: Cesium.VerticalOrigin.BOTTOM
                    }
                })
            }
        });
	}

}

new District()

  • 1
    点赞
  • 17
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值