From 562daa61242457c4296f959057b6f68b12edd12a Mon Sep 17 00:00:00 2001 From: Alex Smith Date: Sun, 20 Jun 2021 15:05:04 -0400 Subject: [PATCH] add null check on polygon in getTileIdsForPolygon --- src/tiles.ts | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/tiles.ts b/src/tiles.ts index 1a951bd..d75dd02 100644 --- a/src/tiles.ts +++ b/src/tiles.ts @@ -39,14 +39,18 @@ export async function getTilesForId(id:string) { export function getTileIdsForPolygon(polygon:turfHelpers.Feature, buffer:number=0):string[] { - var polyBound = bbox(polygon) + if (polygon === null) { + return []; + } else { - var nwPoint = destination([polyBound[0],polyBound[1]], buffer, 315, {'units':'meters'}); - var sePoint = destination([polyBound[2],polyBound[3]], buffer, 135, {'units':'meters'}); - let bounds = [nwPoint.geometry.coordinates[0], nwPoint.geometry.coordinates[1], sePoint.geometry.coordinates[0], sePoint.geometry.coordinates[1]]; - - return getTileIdsForBounds(bounds, false); - + var polyBound = bbox(polygon) + + var nwPoint = destination([polyBound[0],polyBound[1]], buffer, 315, {'units':'meters'}); + var sePoint = destination([polyBound[2],polyBound[3]], buffer, 135, {'units':'meters'}); + let bounds = [nwPoint.geometry.coordinates[0], nwPoint.geometry.coordinates[1], sePoint.geometry.coordinates[0], sePoint.geometry.coordinates[1]]; + + return getTileIdsForBounds(bounds, false); + } } export function getTileIdsForPoint(point:turfHelpers.Feature, buffer:number):string[] {