From 602ceef16dc704a75f4d2db03526a86bb5b1596f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matt=C3=A9o=20Delabre?= Date: Mon, 13 Jan 2020 13:00:09 +0100 Subject: [PATCH] Use darker color around brighter lines --- front/index.js | 24 ++++++++++++++++++++---- package.json | 1 + 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/front/index.js b/front/index.js index f4df909..6780687 100644 --- a/front/index.js +++ b/front/index.js @@ -23,12 +23,28 @@ licenses/by-sa/2.0/">CC-BY-SA`, // // TAM +const makeBorderColor = mainColor => +{ + const hsl = color(mainColor).hsl(); -const SERVER = 'http://localhost:3000'; + if (hsl.color[2] < 40) + { + hsl.color[2] += 30; + } + else + { + hsl.color[2] -= 20; + } -fetch(SERVER + '/line/6').then(res => res.json()).then(line => + return hsl.hex(); +}; + +const SERVER = window.origin; + +fetch(SERVER + '/line/1').then(res => res.json()).then(line => { const color = line.color; + const borderColor = makeBorderColor(color); line.routes.forEach(route => { @@ -36,7 +52,7 @@ fetch(SERVER + '/line/6').then(res => res.json()).then(line => { const wayPoints = way.map(({lat, lon}) => [lat, lon]); - L.polyline(wayPoints, {weight: 8, color: '#888'}).addTo(map); + L.polyline(wayPoints, {weight: 8, color: borderColor}).addTo(map); L.polyline(wayPoints, {weight: 6, color}).addTo(map); }); }); @@ -51,7 +67,7 @@ fetch(SERVER + '/line/6').then(res => res.json()).then(line => fillColor: color, radius: 6, fillOpacity: 1, - color: '#888', + color: borderColor, weight: 2 } ).addTo(map); diff --git a/package.json b/package.json index 61dd48f..7e6acbb 100644 --- a/package.json +++ b/package.json @@ -11,6 +11,7 @@ "author": "", "license": "ISC", "dependencies": { + "color": "^3.1.2", "csv-parse": "^4.8.3", "express": "^4.17.1", "leaflet": "^1.6.0",