基于threejs实现中国地图轮廓动画,简单聊聊2024年前端开发的现状和思考

本文介绍了一种使用threejs和SVG加载器来创建中国地图轮廓动画的方法,探讨了处理地理坐标到平面坐标的转换问题,并分享了前端开发的现状和思考。通过SVGLoader加载SVG路径,然后将其转化为threejs的几何形状,实现地图的渲染和动画效果。此外,还提到了前端开发者的学习和成长路径。
摘要由CSDN通过智能技术生成
  • @param polygon 多边形 点数组

  • @param color 材质颜色

  • */

function lineDraw(polygon:any, color:ColorRepresentation) {

const lineGeometry = new BufferGeometry();

const pointsArray = new Array();

polygon.forEach((row:any) => {

const projectionRow = projection(row);

if (!projectionRow) {

return

}

let x = projectionRow[0]

let y = projectionRow[1]

// 创建三维点

pointsArray.push(new Vector3(x, -y, 0));

linePinots.push([x, -y, 0]);

});

// 放入多个点

lineGeometry.setFromPoints(pointsArray);

const lineMaterial = new LineBasicMaterial({

color: color,

});

return new Line(lineGeometry, lineMaterial);

}

export { countryLine };

全部代码: demo

遇到问题



geojson 版本我们需要将提供的经纬度坐标点转场成平面,各平台算法不同,投影失真情况不同,所以一些情况地图会失真无法重合。

我们刚才使用卡墨托投影转换,也会失真并且和echarts 地图轮廓对不上,所以想起其他方案。

我们利用svg路径来取点,UI提供的svg地图轮廓肯定是一致的。

SVG版本



设计思路:

  1. 加载svg 取所有的点

  2. 根绝点来创建threejs 亮光点

  3. 移动动画

核心代码:

import * as THREE from ‘three’;

import { initRender } from ‘./render’;

import { initScene } from ‘./scene’;

import { initCamera } from ‘./camera’;

// import { countryLine } from “./countryPolygon”;

import { SVGLoader } from ‘three/examples/jsm/loaders/SVGLoader.js’;

export interface OutLineConfig {

outline: boolean;

outlineColor?: THREE.ColorRepresentation;

tintColor: THREE.ColorRepresentation;

speed: number;

tintLength?: number;

  • 28
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值