当前位置: 首页 > news >正文

three.js 3D可视化地图

threejs地图

可视化地图——three.js实现
this.provinceInfo = document.getElementById('provinceInfo');
// 渲染器
this.renderer = new THREE.WebGLRenderer({antialias: true
});
this.renderer.setSize(window.innerWidth, window.innerHeight);
this.container.appendChild(this.renderer.domElement);this.labelRenderer = new THREE.CSS3DRenderer(); //新建CSS3DRenderer
this.labelRenderer.setSize(window.innerWidth, window.innerHeight);
this.labelRenderer.domElement.style.position = 'absolute';
this.labelRenderer.domElement.style.top = 0;
document.body.appendChild(this.labelRenderer.domElement);// 场景
this.scene = new THREE.Scene();
// 假设 scene 是一个 Scene 对象
const textureLoader = new THREE.TextureLoader();
this.scene.background = textureLoader.load("img/bg.png");// 相机 透视相机
this.camera = new THREE.PerspectiveCamera(45, window.innerWidth / window.innerHeight, 0.1, 1000);
this.camera.position.set(this.orbitParams.pos.x, this.orbitParams.pos.y, this.orbitParams.pos.z);
this.camera.lookAt(this.orbitParams.target.x, this.orbitParams.target.y, this.orbitParams.target.z);

地图数据的加载渲染

this.map = new THREE.Object3D();
this.map.add(cityPointGroup);
this.map.add(cityGroup);
this.map.add(flyGroup);let _this = this;
_this.maptext = [];
const projection = d3.geoMercator().center([104.0, 37.5]).scale(80).translate([0, 0]);
let pintArr = [];
const textureLoader = new THREE.TextureLoader();
const material = new THREE.MeshPhongMaterial({color: '#03121b',transparent: true,normalScale: new THREE.Vector2( 0.150, 0.150 ),normalMap: textureLoader.load( 'img/OIP-C.jpg' ),opacity: 0.9
});const material1 = new THREE.MeshBasicMaterial({color: '#15d0b1',transparent: true,// normalMap: textureLoader.load( 'img/earth_normal_2048.jpg' ),opacity: 0.7
});chinaJson.features.forEach(elem => {// 定一个省份3D对象const province = new THREE.Object3D();// 每个的 坐标 数组const coordinates = elem.geometry.coordinates;// 循环坐标数组coordinates.forEach(multiPolygon => {multiPolygon.forEach(polygon => {const shape = new THREE.Shape();const lineMaterial = new THREE.LineBasicMaterial({color: '#15d0b1',});const lineGeometry = new THREE.Geometry();let boundingBox = {max: { x:undefined,y:undefined },min: { x:undefined,y:undefined }};for (let i = 0; i < polygon.length; i++) {const [x, y] = projection(polygon[i]);if (i === 0) {shape.moveTo(x, -y);}shape.lineTo(x, -y);lineGeometry.vertices.push(new THREE.Vector3(x, -y, 4.01));if(undefined==boundingBox.max.x) boundingBox.max.x = x;if(undefined==boundingBox.max.y) boundingBox.max.y = -y;if(undefined==boundingBox.min.x) boundingBox.min.x = x;if(undefined==boundingBox.min.y) boundingBox.min.y = -y;if(x > boundingBox.max.x) boundingBox.max.x = x;if(-y > boundingBox.max.y) boundingBox.max.y = -y;if(x < boundingBox.min.x) boundingBox.min.x = x;if(-y < boundingBox.min.y) boundingBox.min.y = -y;}let width = Math.abs( boundingBox.max.x - boundingBox.min.x );let height = Math.abs( boundingBox.max.y - boundingBox.min.y );const extrudeSettings = {depth: 4,bevelEnabled: false,UVGenerator : {generateTopUV: function ( geometry, vertices, indexA, indexB, indexC ) {  },generateSideWallUV: function ( geometry, vertices, indexA, indexB, indexC, indexD ) {}}};const geometry = new THREE.ExtrudeGeometry(shape, extrudeSettings);const mesh = new THREE.Mesh(geometry, [material, material1]);const line = new THREE.Line(lineGeometry, lineMaterial);mesh.userData.oldMaterial = true;province.add(mesh);province.add(line)})})province.properties = elem.properties;if (elem.properties.contorid) {const [x, y] = projection(elem.properties.contorid);province.properties._centroid = [x, y];}_this.map.add(province);if (elem.properties.center) {const [x, y] = projection(elem.properties.center);const center = new THREE.Vector3(x, -y, 4.01);_this.maptext.push( {pos:center,text:elem.properties.name} );}if (elem.properties.name == "北京市") {const [x, y] = projection(elem.properties.center);const center = new THREE.Vector3(x, -y, 4.01);pintArr.push(center.clone())}
})this.scene.add(this.map);
this.loadFont(_this.maptext);
_this.ctrlBarDatas( true,'bar','北京市' );

http://www.lryc.cn/news/302443.html

相关文章:

  • Unity所有关于旋转的方法详解
  • Vue3
  • 浅谈业务场景中缓存的使用
  • Itext生成pdf文件,html转pdf时中文一直显示不出来
  • 题目 1138: C语言训练-求矩阵的两对角线上的元素之和
  • 第6讲自定义icon实现
  • 花费200元,我用全志H616和雪糕棒手搓了一台可UI交互的视觉循迹小车
  • AUTOSAR OS TASK
  • 陇剑杯 2021刷题记录
  • 前端常见的设计模式
  • OpenAI视频生成模型Sora的全面解析:从ViViT、扩散Transformer到NaViT、VideoPoet
  • 3个密码学相关的问题
  • 5G网络eMBB、uRLLC、mMTC
  • matplotlib图例使用案例1.1:在不同行或列的图例上添加title
  • nginx 日志改为json格式
  • 【DDD】学习笔记-应用服务
  • 【医学大模型】MEDDM LLM-Executable CGT 结构化医学知识: 将临床指导树结构化,便于LLM理解和应用
  • YOLOV8改进系列指南
  • FlinkSql一个简单的测试程序
  • 二、ActiveMQ安装
  • 通俗易懂的L0范数和L1范数及其Python实现
  • 如何在30天内使用python制作一个卡牌游戏
  • VsCode指定插件安装目录
  • 解决npm淘宝镜像到期问题
  • 【JAVA】java泛型 详解
  • 基于RBAC的权限管理的理论实现和权限管理的实现
  • Atcoder ABC340 C - Divide and Divide
  • 趣学贝叶斯统计:概率密度分布(probability density function)
  • 伦敦金行情分析需要学习吗?
  • Java实现停车场收费系统 JAVA+Vue+SpringBoot+MySQL