diff --git a/src/s2geometry.js b/src/s2geometry.js index 4a2961e..c28087e 100644 --- a/src/s2geometry.js +++ b/src/s2geometry.js @@ -333,6 +333,9 @@ S2.fromFacePosLevel = function (faceN, posS, levelN) { posB = '0' + posB; } var bin = Long.fromString(faceN.toString(10), true, 10).toString(2); + while (bin.length < 3) { + bin = '0' + bin; + } bin += posB; bin += '1'; while (bin.length < (S2.FACE_BITS + S2.POS_BITS)) { diff --git a/tests/prev-next.js b/tests/prev-next.js index f8835a1..30e9691 100644 --- a/tests/prev-next.js +++ b/tests/prev-next.js @@ -29,6 +29,7 @@ function getNeighbors(lat, lng, step) { } +/* // Startup Building in Provo var lat = 40.2262363; var lng = -111.6630927; @@ -48,3 +49,24 @@ walk.forEach(function (cellId, i) { // ! because converting CellId / HilbertQuadkey to LatLng is not implemented... yet console.log(-((walk.length - 1) / 2) + i, face, cellId, S2.fromId(cellId), '!', level); }); +*/ + + +// Kyderman's test location +var lat = 51.352085106718384; +var lng = -2.9877930879592896; +var walk = getNeighbors(lat, lng, 5); + +walk.forEach(function (cellId, i) { + var key = S2.fromId(cellId); + var face = parseInt(key.substr(0, 1), 10); + var pos = key.substr(2); + var level = pos.length; + + // TODO + // S2.keyToLatLng(key); + // S2.idToLatLng(id); + + // ! because converting CellId / HilbertQuadkey to LatLng is not implemented... yet + console.log(-((walk.length - 1) / 2) + i, face, cellId, S2.fromId(cellId), '!', level); +}); diff --git a/tests/s2-node-hilbert.js b/tests/s2-node-hilbert.js index 7f1d0a8..2fb903e 100644 --- a/tests/s2-node-hilbert.js +++ b/tests/s2-node-hilbert.js @@ -5,8 +5,12 @@ var S2 = require('s2geometry-node'); //var lng = -111.7089464; // Startup Building in Provo -var lat = 40.2262363; -var lng = -111.6630927; +//var lat = 40.2262363; +//var lng = -111.6630927; + +// Kyderman's test location +var lat = 51.352085106718384; +var lng = -2.9877930879592896; var s2latlng = new S2.S2LatLng(lat, lng); var cellId = new S2.S2CellId(s2latlng).parent(15);