From badca0446d79701fc5545fe84261456f76f85ca8 Mon Sep 17 00:00:00 2001 From: "yuqi.pyq" Date: Mon, 17 Jun 2019 16:55:18 +0800 Subject: [PATCH] =?UTF-8?q?fix(line-layer):=20=E4=BF=AE=E5=A4=8D=E7=9B=B8?= =?UTF-8?q?=E9=82=BB=E7=BA=BF=E6=AE=B5=E9=87=8D=E5=8F=A0=E6=83=85=E5=86=B5?= =?UTF-8?q?=E4=B8=8B=E7=9A=84=E6=8E=A5=E5=A4=B4=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/util/polyline-normals.js | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/util/polyline-normals.js b/src/util/polyline-normals.js index 4a104dcb06..dc6f2452ba 100644 --- a/src/util/polyline-normals.js +++ b/src/util/polyline-normals.js @@ -88,7 +88,28 @@ export default function(points, closed, indexOffset) { // get orientation let flip = (dot(tangent, _normal) < 0) ? -1 : 1; - const bevel = miterLen > miterLimit; + const bevel = Math.abs(miterLen) > miterLimit; + + // 处理前后两条线段重合的情况,这种情况不需要使用任何接头(miter/bevel)。 + // 理论上这种情况下 miterLen = Infinity,本应通过 isFinite(miterLen) 判断, + // 但是 AMap 投影变换后丢失精度,只能通过一个阈值(1000)判断。 + if (Math.abs(miterLen) > 1000) { + normal(_normal, lineA); + extrusions(attrPos, out, cur, _normal, 1); + attrDistance.push(d, d); + attrIndex.push( + _lastFlip === 1 ? [ index + 1, index + 3, index + 2 ] + : [ index, index + 2, index + 3 ] + ); + + // 避免在 Material 中使用 THREE.DoubleSide + attrIndex.push([ index + 2, index + 3, index + 4 ]); + + count += 2; + _lastFlip = -1; + continue; + } + if (bevel) { miterLen = miterLimit;