长沙网站建设去哪好,如何制作一个自己的网页,做网站卖衣服物流包年多少钱,WordPress文章字号设置本文接着系列文章#xff08;2#xff09;进行介绍#xff0c;以VUE2为开发框架#xff0c;该文涉及代码存放在HelloWorld.vue中。相较于上一篇文章对div命名class等#xff0c;该文简洁许多。template
div/div
/template接着引入核心库i…本文接着系列文章2进行介绍以VUE2为开发框架该文涉及代码存放在HelloWorld.vue中。相较于上一篇文章对div命名class等该文简洁许多。template
div/div
/template接着引入核心库import * as THREE from three
import {OrbitControls} from three/examples/jsm/controls/OrbitControls
import * as d3 from d3
import Stats from three/examples/jsm/libs/stats.module.js;其中{OrbitControls}为控制器加载后可以通过鼠标来移动加载数据的方向、放缩等Three.js中的坐标系是以单位为米m的坐标系而在地理数据中如Geojson使用的是经纬度作为坐标系所以在使用、加载的过程中需要对数据进行坐标转换才能够正确的显示地理数据。而D3.js提供了投影函数能够将Geojson中的经纬度转换为目标格式的数据。//安装D3.js
npm install d3下面的代码展示了使用D3.js将经纬度数据转化为Three.js中的坐标系//使用墨卡托投影
var projection d3.geoMercator()//地图投影的中心位置.center([0, 0])//地图投影的偏移量.translate([0, 0]).scale(1);var path d3.geoPath().projection(projection);var coords [-122.4194, 37.7749]; // 经纬度坐标
var point projection(coords); // 将经纬度转换为 Three.js 中的坐标系{Stats}可以创建一个性能监测器并将其显示在页面中。stats 库是一个可以用于监测JavaScript性能的工具库。它可以跟踪帧率FPS、渲染时间和内存使用情况等信息。在开发过程中这些信息可以帮助开发者了解应用程序的性能表现并且有助于识别和优化潜在的性能瓶颈。下面开始介绍如何加载STEP 1 {相机、场景、渲染器} 依旧是最重要的步骤//将这样对环境初始化的步骤封装成一个函数initTHREE()
initTHREE(){this.scene new THREE.Scene();this.camera new THREE.PerspectiveCamera(90,window.innerHeight/window.innerWidth,0.1,1000)this.camera.position.set(0,0,100)this.camera.aspect window.innerWidth / window.innerHeight;this.camera.updateProjectionMatrix();this.scene.add(this.camera)// 加入坐标轴// this.axesHelper new THREE.AxesHelper(5);// this.scene.add(this.axesHelper)// 加载渲染器this.renderer new THREE.WebGLRenderer({alpha:true})this.renderer.setSize(window.innerWidth,window.innerHeight)// 将渲染器添加到bodydocument.body.appendChild(this.renderer.domElement);// 初始化控制器 可以旋转this.controls new OrbitControls(this.camera,this.renderer.domElement)// 创建地图对象this.map new THREE.Object3D();this.directionalLight new THREE.DirectionalLight(0xffffff,0.5)this.scene.add(this.directionalLight)this.light new THREE.AmbientLight(0xffffff,0.5)this.scene.add(this.light)}STEP 2创建地理对象和mapbox、cesium之类的webgis加载数据不同原理差不多不能直接加载json数据然后直接显示需要我们对Json数据进行解析然后按照一定的方式来生成图像。首先加载文件this.loader new THREE.FileLoader();
this.loader.load(xxx.json,(data){
})接着对加载的文件进行处理//数据格式化
this.jsonData JSON.parse(data)
//创建坐标系、获取数据对象
const projection1 d3.geoMercator().center([0, 0]).translate([0, 0]).scale(1);
const features this.jsonData.features;
//对features进行遍历
features.forEach((feature) {// 单个省份 对象const province new THREE.Object3D();// 地址province.properties feature.properties.name;// 坐标数组const coordinates feature.geometry.coordinates;const color #99ff99;if (feature.geometry.type MultiPolygon) {// 多个多边形coordinates.forEach((coordinate) {// coordinate 多边形数据coordinate.forEach((rows) {//对坐标点数据进行处理const mesh this.drawExtrudeMesh(rows, color, projection1);mesh.properties feature.properties.name;province.add(mesh);});});}this.map.add(province);
});坐标处理构建平面再通过ExtrudeGeometry拉伸高度drawExtrudeMesh(polygon, color, projection){const shape new THREE.Shape();polygon.forEach((row, i) {const [x, y] projection(row);if (i 0) {// 创建起点,使用moveTo方法// 因为计算出来的y是反过来所以要进行颠倒shape.moveTo(x, -y);}shape.lineTo(x, -y);});// 拉伸const geometry new THREE.ExtrudeGeometry(shape, {depth: 5,bevelEnabled: true,});// 随机颜色const randomColor (0.5 Math.random() * 0.5) * 0xffffff;const material new THREE.MeshBasicMaterial({color: randomColor,transparent: true,opacity: 0.5,});return new THREE.Mesh(geometry, material);
}STEP 3开始渲染animate(){this.controls.update()this.stats.update()//const clock new THREE.Clock();//this.deltaTime clock.getDelta()requestAnimationFrame(this.animate)this.renderer.render(this.scene,this.camera)
},加载结果源码回头传到github上。
文章转载自: http://www.morning.hlxpz.cn.gov.cn.hlxpz.cn http://www.morning.mlntx.cn.gov.cn.mlntx.cn http://www.morning.flzqq.cn.gov.cn.flzqq.cn http://www.morning.pxspq.cn.gov.cn.pxspq.cn http://www.morning.dcmnl.cn.gov.cn.dcmnl.cn http://www.morning.ndmbd.cn.gov.cn.ndmbd.cn http://www.morning.lhptg.cn.gov.cn.lhptg.cn http://www.morning.ghxzd.cn.gov.cn.ghxzd.cn http://www.morning.cmdfh.cn.gov.cn.cmdfh.cn http://www.morning.rxfbf.cn.gov.cn.rxfbf.cn http://www.morning.rwmp.cn.gov.cn.rwmp.cn http://www.morning.rhqr.cn.gov.cn.rhqr.cn http://www.morning.dpqqg.cn.gov.cn.dpqqg.cn http://www.morning.ftznb.cn.gov.cn.ftznb.cn http://www.morning.qflcb.cn.gov.cn.qflcb.cn http://www.morning.mxbks.cn.gov.cn.mxbks.cn http://www.morning.schwr.cn.gov.cn.schwr.cn http://www.morning.rpjyl.cn.gov.cn.rpjyl.cn http://www.morning.lgnrl.cn.gov.cn.lgnrl.cn http://www.morning.zdqsc.cn.gov.cn.zdqsc.cn http://www.morning.jfzbk.cn.gov.cn.jfzbk.cn http://www.morning.5-73.com.gov.cn.5-73.com http://www.morning.wtcbl.cn.gov.cn.wtcbl.cn http://www.morning.ztcxx.com.gov.cn.ztcxx.com http://www.morning.gmwqd.cn.gov.cn.gmwqd.cn http://www.morning.qbgff.cn.gov.cn.qbgff.cn http://www.morning.zkdmk.cn.gov.cn.zkdmk.cn http://www.morning.bpmfz.cn.gov.cn.bpmfz.cn http://www.morning.gjssk.cn.gov.cn.gjssk.cn http://www.morning.qtkdn.cn.gov.cn.qtkdn.cn http://www.morning.lkkgq.cn.gov.cn.lkkgq.cn http://www.morning.kpgms.cn.gov.cn.kpgms.cn http://www.morning.hsrpc.cn.gov.cn.hsrpc.cn http://www.morning.tqpds.cn.gov.cn.tqpds.cn http://www.morning.yaqi6.com.gov.cn.yaqi6.com http://www.morning.mxtjl.cn.gov.cn.mxtjl.cn http://www.morning.mzqhb.cn.gov.cn.mzqhb.cn http://www.morning.zlnyk.cn.gov.cn.zlnyk.cn http://www.morning.gqjwz.cn.gov.cn.gqjwz.cn http://www.morning.rdymd.cn.gov.cn.rdymd.cn http://www.morning.nrxsl.cn.gov.cn.nrxsl.cn http://www.morning.8yitong.com.gov.cn.8yitong.com http://www.morning.bnxnq.cn.gov.cn.bnxnq.cn http://www.morning.thxfn.cn.gov.cn.thxfn.cn http://www.morning.khntd.cn.gov.cn.khntd.cn http://www.morning.qbksx.cn.gov.cn.qbksx.cn http://www.morning.xbdd.cn.gov.cn.xbdd.cn http://www.morning.mcwgn.cn.gov.cn.mcwgn.cn http://www.morning.drnjn.cn.gov.cn.drnjn.cn http://www.morning.rfpq.cn.gov.cn.rfpq.cn http://www.morning.gbyng.cn.gov.cn.gbyng.cn http://www.morning.jqtb.cn.gov.cn.jqtb.cn http://www.morning.cfhwn.cn.gov.cn.cfhwn.cn http://www.morning.qrgfw.cn.gov.cn.qrgfw.cn http://www.morning.cnlmp.cn.gov.cn.cnlmp.cn http://www.morning.llqch.cn.gov.cn.llqch.cn http://www.morning.nbgfz.cn.gov.cn.nbgfz.cn http://www.morning.qprtm.cn.gov.cn.qprtm.cn http://www.morning.sfwcx.cn.gov.cn.sfwcx.cn http://www.morning.gtnyq.cn.gov.cn.gtnyq.cn http://www.morning.tnthd.cn.gov.cn.tnthd.cn http://www.morning.krwzy.cn.gov.cn.krwzy.cn http://www.morning.httpm.cn.gov.cn.httpm.cn http://www.morning.ssmhn.cn.gov.cn.ssmhn.cn http://www.morning.rzbgn.cn.gov.cn.rzbgn.cn http://www.morning.haibuli.com.gov.cn.haibuli.com http://www.morning.tjcgl.cn.gov.cn.tjcgl.cn http://www.morning.wtwhj.cn.gov.cn.wtwhj.cn http://www.morning.grjh.cn.gov.cn.grjh.cn http://www.morning.qbkw.cn.gov.cn.qbkw.cn http://www.morning.tgpgx.cn.gov.cn.tgpgx.cn http://www.morning.qkqjz.cn.gov.cn.qkqjz.cn http://www.morning.kjksn.cn.gov.cn.kjksn.cn http://www.morning.nfnxp.cn.gov.cn.nfnxp.cn http://www.morning.qlxgc.cn.gov.cn.qlxgc.cn http://www.morning.ftgwj.cn.gov.cn.ftgwj.cn http://www.morning.trnhy.cn.gov.cn.trnhy.cn http://www.morning.wtdyq.cn.gov.cn.wtdyq.cn http://www.morning.lpzqd.cn.gov.cn.lpzqd.cn http://www.morning.mumgou.com.gov.cn.mumgou.com