Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
D
DSMS
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
詹银鑫
DSMS
Commits
e675859a
提交
e675859a
authored
5月 26, 2025
作者:
詹银鑫
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
线流动修改
上级
1c8f8427
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
98 行增加
和
28 行删除
+98
-28
map.js
src/views/gdMap/map.js
+98
-28
没有找到文件。
src/views/gdMap/map.js
浏览文件 @
e675859a
...
...
@@ -158,8 +158,6 @@ export class World extends Mini3d {
this
.
createInfoPoint
()
// 创建轮廓
this
.
createStorke
()
// 创建标签线
// this.createTagLine()
// 创建圆滑曲线
this
.
createSmoothLine
([
[
110.9801
,
39.8002
],
...
...
@@ -1453,41 +1451,111 @@ export class World extends Mini3d {
// // })
// // this.scene.add(tagLineTweenGroup)
// }
// createSmoothLine(lngLatArr) {
// const z = this.depth + 0.5;
// const points = lngLatArr.map(([lng, lat]) => {
// const [x, y] = this.geoProjection([lng, lat]);
// return new THREE.Vector3(x, z, y);
// });
// const curve = new THREE.CatmullRomCurve3(points, false, 'catmullrom', 0.5);
// const curvePoints = curve.getPoints(100);
// // 计算每个点的累积距离
// let distances = [0];
// for (let i = 1; i < curvePoints.length; i++) {
// distances[i] = distances[i - 1] + curvePoints[i].distanceTo(curvePoints[i - 1]);
// }
// const totalLength = distances[distances.length - 1];
// // 添加距离属性
// const geometry = new THREE.BufferGeometry().setFromPoints(curvePoints);
// const distanceAttr = new Float32Array(distances);
// geometry.setAttribute('aDistance', new THREE.BufferAttribute(distanceAttr, 1));
// // ShaderMaterial
// const material = new THREE.ShaderMaterial({
// uniforms: {
// color: { value: new THREE.Color(0xff0000) },
// dashSize: { value: 0.2 },
// gapSize: { value: 0.1 },
// totalLength: { value: totalLength },
// dashOffset: { value: 0 },
// },
// vertexShader: `
// attribute float aDistance;
// varying float vDistance;
// void main() {
// vDistance = aDistance;
// gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
// }
// `,
// fragmentShader: `
// uniform vec3 color;
// uniform float dashSize;
// uniform float gapSize;
// uniform float totalLength;
// uniform float dashOffset;
// varying float vDistance;
// void main() {
// float unitLen = dashSize + gapSize;
// float dist = mod(vDistance + dashOffset * totalLength, unitLen);
// if(dist > dashSize) discard;
// gl_FragColor = vec4(color, 1.0);
// }
// `,
// transparent: true
// });
// const line = new THREE.Line(geometry, material);
// this.scene.add(line);
// // 动画
// this.time.on("tick", () => {
// material.uniforms.dashOffset.value += 0.001; // 控制流动速度
// if(material.uniforms.dashOffset.value > 1.0) material.uniforms.dashOffset.value -= 1.0;
// });
// return line;
// }
createSmoothLine
(
lngLatArr
)
{
const
z
=
this
.
depth
+
0.5
;
// 生成原始曲线
const
points
=
lngLatArr
.
map
(([
lng
,
lat
])
=>
{
const
[
x
,
y
]
=
this
.
geoProjection
([
lng
,
lat
]);
return
new
THREE
.
Vector3
(
x
,
z
,
y
);
});
const
curve
=
new
THREE
.
CatmullRomCurve3
(
points
,
false
,
'catmullrom'
,
0.5
);
// 创建管道几何体(控制宽度)
const
radius
=
0.05
;
// 控制线条宽度
const
radialSegments
=
8
;
// 控制管道圆滑度
const
tubeGeometry
=
new
THREE
.
TubeGeometry
(
curve
,
100
,
// 分段数
radius
,
// 管道半径(即线宽)
radialSegments
// 径向分段数
);
// 计算总长度
const
curvePoints
=
curve
.
getPoints
(
100
);
// 计算每个点的累积距离
let
distances
=
[
0
];
let
totalLength
=
0
;
for
(
let
i
=
1
;
i
<
curvePoints
.
length
;
i
++
)
{
distances
[
i
]
=
distances
[
i
-
1
]
+
curvePoints
[
i
].
distanceTo
(
curvePoints
[
i
-
1
]);
totalLength
+=
curvePoints
[
i
].
distanceTo
(
curvePoints
[
i
-
1
]);
}
const
totalLength
=
distances
[
distances
.
length
-
1
];
// 添加距离属性
const
geometry
=
new
THREE
.
BufferGeometry
().
setFromPoints
(
curvePoints
);
const
distanceAttr
=
new
Float32Array
(
distances
);
geometry
.
setAttribute
(
'aDistance'
,
new
THREE
.
BufferAttribute
(
distanceAttr
,
1
));
// ShaderMaterial
// 修改后的ShaderMaterial
const
material
=
new
THREE
.
ShaderMaterial
({
uniforms
:
{
color
:
{
value
:
new
THREE
.
Color
(
0xff0000
)
},
dashSize
:
{
value
:
0.2
},
gapSize
:
{
value
:
0.1
},
totalLength
:
{
value
:
totalLength
},
dashOffset
:
{
value
:
0
}
dashOffset
:
{
value
:
0
}
,
},
vertexShader
:
`
attribute float aDistance;
uniform float totalLength;
varying vec2 vUv;
varying float vDistance;
void main() {
vDistance = aDistance;
vUv = uv;
vDistance = uv.x * totalLength; // 使用UV的x分量表示沿管道的距离
gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
}
`
,
...
...
@@ -1498,29 +1566,31 @@ createSmoothLine(lngLatArr) {
uniform float totalLength;
uniform float dashOffset;
varying float vDistance;
void main() {
float unitLen = dashSize + gapSize;
float dist = mod(vDistance + dashOffset * totalLength, unitLen);
if(dist > dashSize) discard;
if(dist > dashSize) discard; // 丢弃间隙部分
gl_FragColor = vec4(color, 1.0);
}
`
,
transparent
:
true
});
const
line
=
new
THREE
.
Line
(
g
eometry
,
material
);
this
.
scene
.
add
(
line
);
//
动画
// 创建网格对象
const
mesh
=
new
THREE
.
Mesh
(
tubeG
eometry
,
material
);
console
.
log
(
"mesh"
,
mesh
);
this
.
scene
.
add
(
mesh
);
//
保持原有动画逻辑
this
.
time
.
on
(
"tick"
,
()
=>
{
material
.
uniforms
.
dashOffset
.
value
+=
0.001
;
// 控制流动速度
if
(
material
.
uniforms
.
dashOffset
.
value
>
1.0
)
material
.
uniforms
.
dashOffset
.
value
-=
1.0
;
material
.
uniforms
.
dashOffset
.
value
+=
0.001
;
if
(
material
.
uniforms
.
dashOffset
.
value
>
1.0
)
{
material
.
uniforms
.
dashOffset
.
value
-=
1.0
;
}
});
return
line
;
return
mesh
;
}
// 跳转到指定group
zoomToFocusMapGroup
(
group
)
{
// 创建一个 Box3 来计算 focusMapGroup 的边界盒
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论