From 31557b06beeadd6f85e3075400074b4376dcfa8f Mon Sep 17 00:00:00 2001 From: Javier Goizueta Date: Wed, 31 May 2017 11:48:06 +0200 Subject: [PATCH] Add test to detect and fix incorrect bbox filter splitting When bbox crosses date line and is split in two, the eastern box wasn't correct --- lib/cartodb/models/filter/bbox.js | 3 ++- .../cartodb/model/filter/bbox-filters.test.js | 17 +++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/lib/cartodb/models/filter/bbox.js b/lib/cartodb/models/filter/bbox.js index 8afdf905..dcf19e55 100644 --- a/lib/cartodb/models/filter/bbox.js +++ b/lib/cartodb/models/filter/bbox.js @@ -66,7 +66,8 @@ function getBoundingBoxes(west, south, east, north) { bboxes.push([west, south, east, north]); } else { bboxes.push([west, south, 180, north]); - bboxes.push([-180, south, east % 180, north]); + // here we assume west,east have been adjusted => west >= -180 => east > 180 + bboxes.push([-180, south, east - 360, north]); } return bboxes; diff --git a/test/unit/cartodb/model/filter/bbox-filters.test.js b/test/unit/cartodb/model/filter/bbox-filters.test.js index df894892..68327a7a 100644 --- a/test/unit/cartodb/model/filter/bbox-filters.test.js +++ b/test/unit/cartodb/model/filter/bbox-filters.test.js @@ -111,6 +111,23 @@ describe('Bounding box filter', function() { createRef([-180, -45, 0, 45]) ); }); + + it('generating multiple bbox', function() { + var bbox = [90, -45, 190, 45]; + var bboxFilter = createFilter(bbox); + + assert.equal(bboxFilter.bboxes.length, 2); + + assert.deepEqual( + bboxFilter.bboxes[0], + createRef([90, -45, 180, 45]) + ); + assert.deepEqual( + bboxFilter.bboxes[1], + createRef([-180, -45, -170, 45]) + ); + }); + }); describe('out of bounds', function() {