From f41078b7698aaa15eaecf9f811987aca7fcbe6c7 Mon Sep 17 00:00:00 2001 From: Fedor Katurov Date: Fri, 24 Jan 2020 18:08:34 +0700 Subject: [PATCH] printing gpx tracks --- src/map/GpxPolyline/index.tsx | 3 ++- src/redux/editor/sagas.ts | 15 +++++++++++++++ src/utils/dom.ts | 2 +- src/utils/renderer.ts | 28 ++++++++++++++++++++++------ 4 files changed, 40 insertions(+), 8 deletions(-) diff --git a/src/map/GpxPolyline/index.tsx b/src/map/GpxPolyline/index.tsx index c870d49..72bd459 100644 --- a/src/map/GpxPolyline/index.tsx +++ b/src/map/GpxPolyline/index.tsx @@ -14,8 +14,9 @@ const GpxPolyline: FC = ({ latlngs, color }) => { const item = new Polyline([], { color, stroke: true, - opacity: 0.4, + opacity: 1, weight: 9, + dashArray: [12,12], }).addTo(MainMap); setLayer(item); diff --git a/src/redux/editor/sagas.ts b/src/redux/editor/sagas.ts index 8e324eb..8c8ad71 100644 --- a/src/redux/editor/sagas.ts +++ b/src/redux/editor/sagas.ts @@ -118,6 +118,7 @@ function* getRenderData() { yield put(editorSetRenderer({ info: 'Загрузка тайлов', progress: 0.1 })); const { route, stickers, provider }: ReturnType = yield select(selectMap); + const gpx: ReturnType = yield select(selectEditorGpx); const { distance }: ReturnType = yield select(selectEditor); const canvas = document.getElementById('renderer'); @@ -137,6 +138,20 @@ function* getRenderData() { yield composeImages({ geometry, images, ctx }); yield composePoly({ points, ctx }); + + gpx.list.forEach(item => { + if (!gpx.enabled || !item.enabled || !item.latlngs.length) return; + + composePoly({ + points: getPolyPlacement(item.latlngs), + ctx, + color: item.color, + opacity: 0.5, + weight: 9, + dash: [12, 12], + }); + }); + yield composeArrows({ points, ctx }); yield composeDistMark({ ctx, points, distance }); yield composeStickers({ stickers: sticker_points, ctx }); diff --git a/src/utils/dom.ts b/src/utils/dom.ts index ebcb930..16ff712 100644 --- a/src/utils/dom.ts +++ b/src/utils/dom.ts @@ -10,5 +10,5 @@ export const getStyle = (oElm: any, strCssRule: string): string => { export const getRandomColor = () => { - return `hsl(${(Math.floor(Math.random() * 360))}, 100%, 50%)` + return `hsla(${(Math.floor(Math.random() * 360))}, 100%, 50%, 0.4)` } \ No newline at end of file diff --git a/src/utils/renderer.ts b/src/utils/renderer.ts index 0c75f86..9235ed2 100644 --- a/src/utils/renderer.ts +++ b/src/utils/renderer.ts @@ -170,9 +170,16 @@ export const composeImages = ({ export const composePoly = ({ points, ctx, + color = 'gradient', + weight = CLIENT.STROKE_WIDTH, + dash = null, }: { points: Point[]; ctx: CanvasRenderingContext2D; + color?: string; + opacity?: number; + weight?: number; + dash?: number[]; }): void => { if (points.length === 0) return; @@ -181,10 +188,9 @@ export const composePoly = ({ let minY = points[0].y; let maxY = points[0].y; - ctx.strokeStyle = 'red'; ctx.lineCap = 'round'; ctx.lineJoin = 'round'; - ctx.lineWidth = CLIENT.STROKE_WIDTH + 0.5; + ctx.lineWidth = weight + 0.5; ctx.beginPath(); ctx.moveTo(points[0].x, points[0].y); @@ -199,11 +205,21 @@ export const composePoly = ({ if (points[i].y > maxY) maxY = points[i].y; } - const gradient = ctx.createLinearGradient(minX, minY, minX, maxY); - gradient.addColorStop(0, COLORS.PATH_COLOR[0]); - gradient.addColorStop(1, COLORS.PATH_COLOR[1]); + if (color === 'gradient') { - ctx.strokeStyle = gradient; + const gradient = ctx.createLinearGradient(minX, minY, minX, maxY); + gradient.addColorStop(0, COLORS.PATH_COLOR[0]); + gradient.addColorStop(1, COLORS.PATH_COLOR[1]); + + ctx.strokeStyle = gradient; + } else { + ctx.strokeStyle = color; + } + + if (dash) { + ctx.setLineDash([12,12]); + } + ctx.stroke(); ctx.closePath(); };