From: Robert Kaiser Date: Fri, 7 Nov 2014 02:52:50 +0000 (+0100) Subject: make segments be separate lines without connections, try to make track drawing code... X-Git-Tag: producution~21 X-Git-Url: https://git-public.kairo.at/?p=lantea.git;a=commitdiff_plain;h=852bc801f08c0f6dfcec29a7f92d517a5578aa2b make segments be separate lines without connections, try to make track drawing code a bit more consolidated and easier to understand --- diff --git a/js/map.js b/js/map.js index f6b9d86..2532a03 100644 --- a/js/map.js +++ b/js/map.js @@ -661,7 +661,7 @@ function drawTrack() { if (gTrack.length) { for (var i = 0; i < gTrack.length; i++) { drawTrackPoint(gTrack[i].coords.latitude, gTrack[i].coords.longitude, - (i + 1 >= gTrack.length)); + (i + 1 >= gTrack.length || gTrack[i+1].beginSegment)); } } } @@ -681,22 +681,23 @@ function drawTrackPoint(aLatitude, aLongitude, lastPoint) { gTrackContext.lineCap = "round"; gTrackContext.lineJoin = "round"; } + // This breaks optimiziation, so make sure to reset optimization. if (!gLastDrawnPoint || gLastDrawnPoint == trackpoint) { - // This breaks optimiziation, so make sure to close path and reset optimization. - if (gLastDrawnPoint && gLastDrawnPoint.optimized) + trackpoint.optimized = false; + // Close path if one was open. + if (gLastDrawnPoint && gLastDrawnPoint.optimized) { gTrackContext.stroke(); + } + } + if (!gLastDrawnPoint || (gLastDrawnPoint == trackpoint) || !gLastDrawnPoint.optimized) { + // Start drawing a segment. gTrackContext.beginPath(); - trackpoint.optimized = false; gTrackContext.arc(mappos.x, mappos.y, gTrackContext.lineWidth, 0, Math.PI * 2, false); gTrackContext.fill(); } else { - if (!gLastDrawnPoint || !gLastDrawnPoint.optimized) { - gTrackContext.beginPath(); - gTrackContext.moveTo(Math.round((gLastDrawnPoint.x - gMap.pos.x) / gMap.zoomFactor + gMap.width / 2), - Math.round((gLastDrawnPoint.y - gMap.pos.y) / gMap.zoomFactor + gMap.height / 2)); - } + // Continue drawing segment, close if needed. gTrackContext.lineTo(mappos.x, mappos.y); if (!trackpoint.optimized) gTrackContext.stroke();