fix: incorrect polyline decoding (#993)

* fix: incorrect polyline decoding
Don't split static image encoded path on pipe or comma

Signed-off-by: boldtrn <boldtrn@gmail.com>

* fix: still allow other parameters other than enc:
That way we can still style individual paths

Signed-off-by: boldtrn <boldtrn@gmail.com>

* chore: lint

Signed-off-by: Andrew Calcutt <acalcutt@techidiots.net>

* chore: lint + comment

Signed-off-by: Andrew Calcutt <acalcutt@techidiots.net>

* docs: try to clarify path information

Signed-off-by: Andrew Calcutt <acalcutt@techidiots.net>

* fix: stroke color not working unless path is specified

i found this issue testing encoded paths. If width is not specifed, stroke color does not work

Signed-off-by: Andrew Calcutt <acalcutt@techidiots.net>

* docs: show different options

Signed-off-by: Andrew Calcutt <acalcutt@techidiots.net>

---------

Signed-off-by: boldtrn <boldtrn@gmail.com>
Signed-off-by: Andrew Calcutt <acalcutt@techidiots.net>
Co-authored-by: Andrew Calcutt <acalcutt@techidiots.net>
This commit is contained in:
Robin
2023-09-27 05:53:16 +02:00
committed by GitHub
parent c13e5e6821
commit d759dd2952
3 changed files with 28 additions and 24 deletions

View File

@@ -162,21 +162,12 @@ const extractPathsFromQuery = (query, transformer) => {
providedPath.includes('enc:') &&
PATH_PATTERN.test(decodeURIComponent(providedPath))
) {
const encodedPaths = providedPath.split(',');
for (const path of encodedPaths) {
const line = path
.split('|')
.filter(
(x) =>
!x.startsWith('fill') &&
!x.startsWith('stroke') &&
!x.startsWith('width'),
)
.join('')
.replace('enc:', '');
const coords = polyline.decode(line).map(([lat, lng]) => [lng, lat]);
paths.push(coords);
}
// +4 because 'enc:' is 4 characters, everything after 'enc:' is considered to be part of the polyline
const encIndex = providedPath.indexOf('enc:') + 4;
const coords = polyline
.decode(providedPath.substring(encIndex))
.map(([lat, lng]) => [lng, lat]);
paths.push(coords);
} else {
// Iterate through paths, parse and validate them
const currentPath = [];
@@ -520,8 +511,8 @@ const drawPath = (ctx, path, query, pathQuery, z) => {
if ('stroke' in query) {
ctx.strokeStyle = query.stroke;
}
// Path Width gets higher priority
if (pathHasWidth) {
// Path Stroke gets higher priority
if (pathHasStroke) {
ctx.strokeStyle = splitPaths
.find((x) => x.startsWith('stroke:'))
.replace('stroke:', '');