three.js 使用geojson ,实现中国地图区域,边缘流动效果

server/2024/10/22 5:21:17/

three.js 使用geojson ,实现中国地图区域,边缘流动效果

在线链接:https://threehub.cn/#/codeMirror?navigation=ThreeJS&classify=expand&id=geoBorder

国内站点预览:http://threehub.cn

github地址: https://github.com/z2586300277/three-cesium-examples

import * as THREE from 'three'
import { OrbitControls } from 'three/examples/jsm/controls/OrbitControls.js'const box = document.getElementById('box')const scene = new THREE.Scene()const camera = new THREE.PerspectiveCamera(75, box.clientWidth / box.clientHeight, 0.1, 1000)camera.position.set(0, 0, 500)const renderer = new THREE.WebGLRenderer({ antialias: true, alpha: true, logarithmicDepthBuffer: true })renderer.setSize(box.clientWidth, box.clientHeight)box.appendChild(renderer.domElement)const controls = new OrbitControls(camera, renderer.domElement)controls.enableDamping = truescene.add(new THREE.AmbientLight(0xffffff, 1))const directionalLight = new THREE.DirectionalLight(0xffffff, 2)directionalLight.position.set(300, 300, 300)scene.add(directionalLight)const map = new THREE.TextureLoader().load(`https://file.threehub.cn/` + 'images/channels/lmap.png')map.wrapS = THREE.RepeatWrappingmap.wrapT = THREE.RepeatWrappingmap.needsUpdate = trueanimate()function animate() {requestAnimationFrame(animate)map.offset.x += 0.001controls.update()renderer.render(scene, camera)}window.onresize = () => {renderer.setSize(box.clientWidth, box.clientHeight)camera.aspect = box.clientWidth / box.clientHeightcamera.updateProjectionMatrix()}/* 边界 */
const group = new THREE.Group()fetch(`https://file.threehub.cn/` + 'files/json/chinaBound.json').then(r => r.json()).then(res => {const { features } = resfeatures.forEach((i) => {if (i.geometry.type === 'MultiPolygon') i.geometry.coordinates.forEach((j) => j.forEach((z) => createShapeWithCoord(group, z)))else if (i.geometry.type === 'Polygon') i.geometry.coordinates.forEach((j) => createShapeWithCoord(group, j))else if (i.geometry.type === 'LineString') i.geometry.coordinates.length > 1 && createShapeWithCoord(group, i.geometry.coordinates)})translationOriginForGroup(group)scene.add(group)})function createShapeWithCoord(group, coordinates) {if (coordinates.length < 1000) return // 设置点数限制 如果点太少则不绘制const curvePoints = coordinates.map((k) => coordToVector3(k))const curve = new THREE.CatmullRomCurve3(curvePoints)const geometry = new THREE.TubeGeometry(curve, curvePoints.length - 1, 1, 40, false)const material = new THREE.MeshPhongMaterial({ color: 0xffffff , map , transparent: true })const mesh = new THREE.Mesh(geometry, material)translationOriginForMesh(mesh)group.attach(mesh)}function coordToVector3(coord, slace = 10000) {const [lng, lat] = coordconst x = lng * 20037508.34 / 180const y = Math.log(Math.tan((90 + lat) * Math.PI / 360)) / (Math.PI / 180) * 20037508.34 / 180return new THREE.Vector3(x / slace, y / slace, 0)}function translationOriginForMesh(mesh) {const boundingBox = new THREE.Box3().setFromObject(mesh)boundingBox.getCenter(mesh.position)mesh.geometry.center()}// 设置组中心点
function translationOriginForGroup(group) {const boundingBox = new THREE.Box3().setFromObject(group)boundingBox.getCenter(group.position)group.traverse((c) => {c.isMesh && c.position.sub(group.position)})group.position.set(0, 0, 0)}/*** 名称: 地理边界* 作者: 优雅永不过时 https://github.com/z2586300277
*/

http://www.ppmy.cn/server/133803.html

相关文章

200例经济模型已更新完毕

200例经济模型已更新完毕 项目地址 关于经济模型的Python代码示例项目&#xff0c;由于“200例”这一数量较为庞大&#xff0c;且具体项目可能涉及多个领域和复杂的实现细节&#xff0c;因此在这里无法一一列举。不过&#xff0c;我可以提供一些经济模型Python代码示例的概述和…

chat_gpt回答:python使用gdal写tiff文件,如何使用内存映射的方法

使用 GDAL 写入 TIFF 文件并使用内存映射的方法&#xff0c;可以极大地提高处理大规模数据时的效率。内存映射使得数据可以直接从磁盘或内存访问&#xff0c;而不需要在内存和文件系统之间进行大量的 I/O 操作。 在 GDAL 中&#xff0c;你可以通过创建内存中的数据集&#xff…

数据结构(8.3_2)——快速排序

算法思想&#xff1a; 设置两个指针&#xff0c;一个i指针初值为low和一个j指针初值为high&#xff0c;j指针从左往右移&#xff0c;当j指向的元素小于枢轴元素&#xff0c;将该元素放到枢轴元素左边&#xff0c;i指针从右往左移&#xff0c;当i指向的元素大于枢轴元素&#xf…

麒麟操作系统服务器kylin-kms-activation反复启动失败问题排查

问题现象: messages日志中,kylin-kms-activation.service服务异常结束,返回码为255。并且一直在循环启动服务,循环打印错误日志。 Sep 13 17:06:59 server-sp3 systemd[1]: kylin-kms-activation.service: Main process exited, code=exited, status=255/EXCEPTION Sep 13 …

软件测试快速入门:测试对象、过程模型、生命周期与测试用例

✨✨ 欢迎大家来访Srlua的博文&#xff08;づ&#xffe3;3&#xffe3;&#xff09;づ╭❤&#xff5e;✨✨ &#x1f31f;&#x1f31f; 欢迎各位亲爱的读者&#xff0c;感谢你们抽出宝贵的时间来阅读我的文章。 我是Srlua小谢&#xff0c;在这里我会分享我的知识和经验。&am…

特斯拉自动驾驶出租车计划变成泡影?联想与Meta合作,推出面向PC的个人AI智能体AI Now|AI日报

文章推荐 Swarms Corporation创始人Kye Gomez实锤OpenAI多智能体Swarm抄袭其成果&#xff01;&#xff5c;AI日报 今日热点 中国海油“海能”人工智能模型正式发布 近日&#xff0c;由中国海油与中国电信、科大讯飞等企业合作打造“海能”人工智能模型正式推出。 中国海油“…

【付费】Ambari集成Dolphin实战-002-bigtop下编译dolphin——下

3.2 编译过程记录 3.2.1 do-component-build 执行 17:28:50.944 [ERROR] [system.err] + STATUS=0 17:28:50.944 [ERROR] [system

基于深度学习的基于视觉的机器人导航

基于深度学习的视觉机器人导航是一种通过深度学习算法结合视觉感知系统&#xff08;如摄像头、LiDAR等&#xff09;实现机器人在复杂环境中的自主导航的技术。这种方法使机器人能够像人类一样使用视觉信息感知环境、规划路径&#xff0c;并避开障碍物。与传统的导航方法相比&am…