From ddbc9df11339a218728d419229d0f2bd88a1fdac Mon Sep 17 00:00:00 2001 From: Kushan Joshi <0o3ko0@gmail.com> Date: Mon, 25 Sep 2017 18:20:30 +0530 Subject: [PATCH] =?UTF-8?q?Sort=20mapillary=E2=80=99s=20rbush=20result?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/services/mapillary.js | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/modules/services/mapillary.js b/modules/services/mapillary.js index 514e9d771..b5282c487 100644 --- a/modules/services/mapillary.js +++ b/modules/services/mapillary.js @@ -236,11 +236,32 @@ function searchLimited(psize, limit, projection, rtree) { limit = limit || 3; var partitions = partitionViewport(psize, projection); - return _.flatten(_.compact(_.map(partitions, function(extent) { + console.time('previous'); + + var x = _.flatten(_.map(partitions, function(extent) { return rtree.search(extent.bbox()) .slice(0, limit) .map(function(d) { return d.data; }); - }))); + })); + console.timeEnd('previous'); + + console.time('new'); + var a = partitions.reduce(function(prev, curr) { + var searchResult = rtree.search(curr.bbox()); + // searchResult will always be an array + if (searchResult.length === 0) return prev; + + return prev.concat(searchResult + .slice(0, limit) + .map(function(d) { + return d.data; + }) + .sort(function(a, b) { + return a.key.localeCompare(b.key); + })); + }, []); + console.timeEnd('new'); + return a; }