three.js 3D可视化地图

这篇具有很好参考价值的文章主要介绍了three.js 3D可视化地图。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

threejs地图文章来源地址https://www.toymoban.com/news/detail-828336.html

可视化地图——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','北京市' );

到了这里,关于three.js 3D可视化地图的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • Three.js3D可视化介绍,以及本地搭建three.js官网

    一、什么是Three.js three.js官网 :https://threejs.org/ Three.js 是一个基于 WebGL 的 JavaScript 3D 图形库,它可以轻松地在浏览器中 创建3D场景和动画 。同时,它支持外部模型和纹理的导入,让开发者可以更加便捷地创建出震撼的 3D场景 。 Three.js 的应用场景非常广泛,主要包括以下几个

    2024年02月09日
    浏览(32)
  • 【可视化大屏-3d机房监控】Vue与three.js搭建可视化机房监控

    演示网址:http://jstopo.top网站地址 3d机房地址:http://jstopo.top/threeTopo/#/monitor/index

    2024年03月10日
    浏览(41)
  • 使用Three.js创建令人惊叹的WebGL 3D可视化

    WebGL 可视化 3D 绘图是一项新兴技术,具有广阔的应用前景。它允许开发人员在 Web 浏览器中创建和渲染 3D 图形,而无需安装额外的插件或软件。 本博客将介绍 Three.js,Three.js 是一个功能强大的 WebGL 框架,提供了丰富的 API 用于创建和渲染 3D 图形,接下来让我们通

    2024年01月19日
    浏览(44)
  • Three.js学习项目--3D抗美援朝数据可视化

    部分场景 体验地址 https://kmyc.hongbin.xyz/ 操作说明 视频 操作说明 我做了哪些(功能) draco解析glb模型 同时处理部分纹理请求 减轻一次加载纹理压力 手动控制轨道控制器镜头动画 多音频拼接 控制 封装动画播放器 控制进度切换 动画进度控制器 同步音频 模拟视频体验 useCon

    2024年02月11日
    浏览(50)
  • DataGear 制作基于 three.js 的 3D 数据可视化看板

    DataGear 支持采用原生的HTML、JavaScript、CSS制作数据可视化看板,也支持导入由 npm 、 vite 等前端工具构建的前端程序包。得益于这一特性,可以很容易制作基于three.js的3D数据可视化看板。 首先,参考three.js的官方教程 https://threejs.org/docs/index.html#manual/en/introduction/Installation 编写

    2024年03月09日
    浏览(42)
  • THREEJS 地图可视化案例分享

    个人练习学习案例,代码放在git了,需要的可以下载 threejs_map: threejs 地图可视化案例 效果预览

    2024年02月12日
    浏览(52)
  • 除了three.js,还有许多其他前端开发语言和库可以用于创建3D可视化大屏

    hello老铁们...本人熟悉html5,vue对bootsrap,uniapp,layui,element,vite,antd,echarts,jq响应式尤其擅长,ui设计等技能,如果ui前端工作中有遇到烦恼可私信关注评论我们共同交流进步!谢谢       随着前端技术的飞速发展,3D可视化已经成为许多应用场景中不可或缺的一部分。在

    2024年03月15日
    浏览(48)
  • 3D可视化集装箱货柜模型开发 --threejs

    教程效果实现效果     集装箱模型 箱子模型   中文文档:three.js docs 1.安装并 引入threejs 创建 安装threejs依赖包 在需要用的的代码文件里面引入threejs 2.实现3D模型最基础的渲染骨架部分 以下例子是在vue的项目里面实现一个简单的场景渲染,目前场景除了坐标轴并无其他物体

    2024年02月15日
    浏览(37)
  • vue基于threejs实现的3D可视化编辑器

    随着5G网络的渐渐普及,物联网在人们的生活中渐渐广泛使用,社会向着越来越智能化的方向发展。当康科技经过不懈努力,研发属于自己的一款3D可视化编辑器,助力企业应用实现3D可视化服务。 编辑器界面如下: 操作视频演示: 3D可视化编辑器v1.0版本完成 主要功能点如下

    2024年02月13日
    浏览(28)
  • 前端前沿web 3d可视化技术 ThreeJS学习全记录

    完整案例与项目代码: gitee开源项目地址 https://gitee.com/jumping-world-line/01_threeJS_basic 随着浏览器性能和网络带宽的提升 使得3D技术不再是桌面的专利 打破传统平面展示模式 前端方向主要流向的3D图形库包括Three.js和WebGL WebGL灵活高性能,但代码量大,难度大,需要掌握很多底层

    2024年02月01日
    浏览(43)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包