zoukankan      html  css  js  c++  java
  • 官方示例之地球模块十一:创建GeoPolygon

    /**
     * 创建 GeoBuilding 对象
     */
    var app = new THING.App();
    app.background = [0, 0, 0];
    
    THING.Utils.dynamicLoad('https://www.thingjs.com/uearth/uearth.min.js', function () {
    	var map = app.create({
    		type: 'Map',
    		attribution: 'Google'
    	});
    
    	// 创建一个瓦片图层
    	var tileLayer1 = app.create({
    		type: 'TileLayer',
    		name: 'tileLayer1',
    		url: 'https://mt{0,1,2,3}.google.cn/vt/lyrs=s&hl=zh-CN&gl=cn&x={x}&y={y}&z={z}',
    		style: {
    			template: CMAP.TileLayerStyle.DARKGREEN // 设置瓦片图层的样式为DARKGREEN
    		}
    	});
    	// 将瓦片图添加到地图中
    	map.addLayer(tileLayer1);
    	// 创建一个建筑物图层
    	var buildingLayer = app.create({
    		type: 'ThingLayer',
    		name: 'buildingLayer'
    	});
    	// 将 buildingLayer 添加到 map 中
    	map.addLayer(buildingLayer);
    
    	// 飞到地理位置和高度
    	app.camera.earthFlyTo({
    		lonlat: [116.4488, 39.9187],
    		height: 3000,
    		time: 2000,
    		complete: function () {
    			createBuilding()
    		}
    	});
    	var createBuilding = function () {
    		$.ajax({
    			type: 'GET',
    			url: 'https://www.thingjs.com/uearth/uGeo/chaoyang_building.geojson',
    			dataType: 'json',
    			success: function (data) {
    				createBuildings(data);
    			}
    		});
    	};
    
    	function createBuildings(data) {
    		var cnt = data.features.length;
    		console.log('共 ' + cnt + '个建筑');
    
    		for (var i = 0; i < cnt; i += 1) {
    			var feature = data.features[i];
    
    			var building = app.create({
    				type: 'GeoBuilding',
    				name: 'build' + i,
    				coordinates: feature.geometry.coordinates,
    				userData: feature.properties,
    				height: feature.properties.height,
    				renderer: {
    					type: 'image',
    					imageUrl: ['https://www.thingjs.com/uearth/uGeo/building_top.png', 'https://www.thingjs.com/uearth/uGeo/building.png'], // 楼宇顶部贴图和侧边贴图
    					blending: true // 贴图叠加混合
    				}
    			});
    			buildingLayer.add(building);
    		}
    	}
    
    	app.on('click', '.GeoBuilding', function (ev) {
    		var obj = ev.object;
    		var height = obj.userData.height;
    		var district = obj.userData.district;
    
    		console.log('建筑高度 ' + height + 'm 所属街道 ' + district);
    	})
    });
    
  • 相关阅读:
    亚信防毒墙网络版卸载
    Ubuntu之apt
    Python(00):内存中读写数据StringIO和BytesIO
    Windows使用cmd命令行中查看、修改、删除与添加环境变量
    微信小程序教程
    微信小程序之云开发
    微信小程序-简易计算器
    第一个微信小程序——实现获取用户信息替换用户名和头像到首页
    Python(00):RSA加解密
    Python(00):使用selenium模块
  • 原文地址:https://www.cnblogs.com/thingjs/p/13840353.html
Copyright © 2011-2022 走看看