From aa4c1aa7b940838576151fdbf140d46827b2e1f9 Mon Sep 17 00:00:00 2001 From: John Klancer Date: Thu, 10 Sep 2020 10:34:49 -0400 Subject: [PATCH] - fixes winding of GeoJSON to follow right-hand rule (#38) --- index.js | 6 +++--- test.js | 7 +++++++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 25d0e93..352fb0a 100644 --- a/index.js +++ b/index.js @@ -36,11 +36,11 @@ function tileToGeoJSON(tile) { var poly = { type: 'Polygon', coordinates: [[ - [bbox[0], bbox[1]], [bbox[0], bbox[3]], - [bbox[2], bbox[3]], + [bbox[0], bbox[1]], [bbox[2], bbox[1]], - [bbox[0], bbox[1]] + [bbox[2], bbox[3]], + [bbox[0], bbox[3]] ]] }; return poly; diff --git a/test.js b/test.js index 5367f04..b5b81b2 100644 --- a/test.js +++ b/test.js @@ -9,6 +9,13 @@ test('tile to geojson', function (t) { var geojson = tilebelt.tileToGeoJSON(tile1); t.ok(geojson, 'get geojson representation of tile'); t.equal(geojson.type, 'Polygon'); + t.deepEqual(geojson.coordinates, [[ + [-178.2421875, 84.73838712095339], + [-178.2421875, 84.7060489350415], + [-177.890625, 84.7060489350415], + [-177.890625, 84.73838712095339], + [-178.2421875, 84.73838712095339] + ]], 'Coordinates'); t.end(); });