fix: enable multiple paths while extracting them from query
Signed-off-by: Vinayak Kulkarni <19776877+vinayakkulkarni@users.noreply.github.com>
This commit is contained in:
parent
3417bd2df6
commit
b07b47e24c
1 changed files with 27 additions and 25 deletions
|
|
@ -150,37 +150,39 @@ const parseCoordinates = (coordinatePair, query, transformer) => {
|
||||||
* @param {Function} transformer Optional transform function.
|
* @param {Function} transformer Optional transform function.
|
||||||
*/
|
*/
|
||||||
const extractPathsFromQuery = (query, transformer) => {
|
const extractPathsFromQuery = (query, transformer) => {
|
||||||
const reqPath = decodeURIComponent(query.path);
|
// Initiate paths array
|
||||||
const paths = [];
|
const paths = [];
|
||||||
// Return an empty list if no paths have been provided
|
// Return an empty list if no paths have been provided
|
||||||
if ('path' in query && !query.path) {
|
if ('path' in query && !query.path) {
|
||||||
return paths;
|
return paths;
|
||||||
}
|
}
|
||||||
// Parse paths provided via path query argument
|
// Parse paths provided via path query argument
|
||||||
if ('path' in query && PATH_PATTERN.test(reqPath)) {
|
if ('path' in query) {
|
||||||
if (reqPath.includes('enc:')) {
|
const providedPaths = Array.isArray(query.path) ? query.path : [query.path];
|
||||||
const splitPaths = query.path.split('|');
|
// Iterate through paths, parse and validate them
|
||||||
const line = splitPaths
|
for (const providedPath of providedPaths) {
|
||||||
.filter(
|
// Logic for pushing coords to path when path includes google polyline
|
||||||
(x) =>
|
if (
|
||||||
!x.startsWith('fill') &&
|
providedPath.includes('enc:') &&
|
||||||
!x.startsWith('stroke') &&
|
PATH_PATTERN.test(decodeURIComponent(providedPath))
|
||||||
!x.startsWith('width'),
|
) {
|
||||||
)
|
const encodedPaths = providedPath.split(',');
|
||||||
.join('')
|
for (const path of encodedPaths) {
|
||||||
.replace('enc:', '');
|
const line = path
|
||||||
|
.split('|')
|
||||||
const coords = polyline.decode(line).map(([lat, lng]) => [lng, lat]);
|
.filter(
|
||||||
paths.push(coords);
|
(x) =>
|
||||||
} else {
|
!x.startsWith('fill') &&
|
||||||
// Check if multiple paths have been provided and mimic a list if it's a
|
!x.startsWith('stroke') &&
|
||||||
// single path.
|
!x.startsWith('width'),
|
||||||
const providedPaths = Array.isArray(query.path)
|
)
|
||||||
? query.path
|
.join('')
|
||||||
: [query.path];
|
.replace('enc:', '');
|
||||||
|
const coords = polyline.decode(line).map(([lat, lng]) => [lng, lat]);
|
||||||
// Iterate through paths, parse and validate them
|
paths.push(coords);
|
||||||
for (const providedPath of providedPaths) {
|
}
|
||||||
|
} else {
|
||||||
|
// Iterate through paths, parse and validate them
|
||||||
const currentPath = [];
|
const currentPath = [];
|
||||||
|
|
||||||
// Extract coordinate-list from path
|
// Extract coordinate-list from path
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue