fix: drawPath method

Signed-off-by: Vinayak Kulkarni <19776877+vinayakkulkarni@users.noreply.github.com>
This commit is contained in:
Vinayak Kulkarni 2023-01-11 16:26:05 +05:30
parent 33cb7e82b4
commit 52958a2317
No known key found for this signature in database
GPG key ID: B8C8194CED989C08

View file

@ -443,9 +443,7 @@ const drawMarkers = async (ctx, markers, z) => {
* @param {number} z Map zoom level. * @param {number} z Map zoom level.
*/ */
const drawPath = (ctx, path, query, z) => { const drawPath = (ctx, path, query, z) => {
// Check if path in query is valid const renderPath = (splitPaths) => {
const splitPaths = query.path.split('|');
if (!path || path.length < 2) { if (!path || path.length < 2) {
return null; return null;
} }
@ -467,7 +465,8 @@ const drawPath = (ctx, path, query, z) => {
} }
// Optionally fill drawn shape with a rgba color from query // Optionally fill drawn shape with a rgba color from query
const pathHasFill = splitPaths.filter((x) => x.startsWith('fill')).length > 0; const pathHasFill =
splitPaths.filter((x) => x.startsWith('fill')).length > 0;
if (query.fill !== undefined || pathHasFill) { if (query.fill !== undefined || pathHasFill) {
if ('fill' in query) { if ('fill' in query) {
ctx.fillStyle = query.fill || 'rgba(255,255,255,0.4)'; ctx.fillStyle = query.fill || 'rgba(255,255,255,0.4)';
@ -538,6 +537,16 @@ const drawPath = (ctx, path, query, z) => {
ctx.strokeStyle = 'rgba(0,64,255,0.7)'; ctx.strokeStyle = 'rgba(0,64,255,0.7)';
} }
ctx.stroke(); ctx.stroke();
};
// Check if path in query is valid
if (Array.isArray(query.path)) {
for (let i = 0; i < query.path.length; i += 1) {
renderPath(query.path.at(i).split('|'));
}
} else {
renderPath(query.path.split('|'));
}
}; };
const renderOverlay = async ( const renderOverlay = async (