fix polyline bug

This commit is contained in:
jiaming 2018-12-09 19:48:46 +08:00
parent 653ca26de6
commit 002e0de26d
1 changed files with 2 additions and 4 deletions

View File

@ -15,17 +15,15 @@ export function drawLine (ctx, lineBegin, lineEnd, lineWidth = 2, lineColor = '#
ctx.stroke() ctx.stroke()
} }
export function drawPolyline (ctx, points, lineWidth = 2, lineColor = '#000', close = false, dashArray = [10, 10]) { export function drawPolyline (ctx, points, lineWidth = 2, lineColor = '#000', close = false, dashArray = [10, 0]) {
if (!ctx || !points.length) return if (!ctx || !points.length) return
ctx.beginPath() ctx.beginPath()
points.forEach((point, i) => i === 0 ? ctx.moveTo(...point) : ctx.LineTo(...point)) points.forEach((point, i) => i === 0 ? ctx.moveTo(...point) : ctx.lineTo(...point))
close && ctx.lineTo(...points[0]) close && ctx.lineTo(...points[0])
ctx.closePath()
ctx.lineWidth = lineWidth ctx.lineWidth = lineWidth
ctx.strokeStyle = lineColor ctx.strokeStyle = lineColor
ctx.setLineDash(dashArray) ctx.setLineDash(dashArray)