2016-07-26 06:31:39 +00:00
|
|
|
var S2 = require('s2geometry-node');
|
2016-07-28 04:37:43 +00:00
|
|
|
|
|
|
|
// Provo, UT (Center St)
|
|
|
|
//var lat = 40.2574448;
|
|
|
|
//var lng = -111.7089464;
|
|
|
|
|
|
|
|
// Startup Building in Provo
|
2016-07-28 09:06:23 +00:00
|
|
|
//var lat = 40.2262363;
|
|
|
|
//var lng = -111.6630927;
|
|
|
|
|
|
|
|
// Kyderman's test location
|
|
|
|
var lat = 51.352085106718384;
|
|
|
|
var lng = -2.9877930879592896;
|
2016-07-26 06:31:39 +00:00
|
|
|
|
|
|
|
var s2latlng = new S2.S2LatLng(lat, lng);
|
|
|
|
var cellId = new S2.S2CellId(s2latlng).parent(15);
|
|
|
|
var cell;
|
|
|
|
|
|
|
|
var walk = [];
|
|
|
|
var next = cellId;
|
|
|
|
var prev = cellId;
|
|
|
|
var i;
|
|
|
|
|
2016-07-27 11:56:55 +00:00
|
|
|
// -10 - -1
|
2016-07-26 06:31:39 +00:00
|
|
|
for (i = 0; i < 10; i += 1) {
|
|
|
|
prev = prev.prev();
|
|
|
|
|
2016-07-26 06:36:42 +00:00
|
|
|
walk.unshift([ -(i + 1), prev ]);
|
|
|
|
}
|
|
|
|
|
2016-07-27 11:56:55 +00:00
|
|
|
// 0
|
2016-07-26 06:36:42 +00:00
|
|
|
walk.push([ 0, cellId ]);
|
|
|
|
|
2016-07-27 11:56:55 +00:00
|
|
|
// 1 - 10
|
2016-07-26 06:36:42 +00:00
|
|
|
for (i = 0; i < 10; i += 1) {
|
|
|
|
next = next.next();
|
|
|
|
|
|
|
|
walk.push([ i + 1, next ]);
|
2016-07-26 06:31:39 +00:00
|
|
|
}
|
|
|
|
|
2016-07-27 11:56:55 +00:00
|
|
|
// all results
|
2016-07-26 06:36:42 +00:00
|
|
|
walk.forEach(function (parts) {
|
|
|
|
var i = parts[0];
|
|
|
|
var cellId = parts[1];
|
|
|
|
|
|
|
|
cell = new S2.S2Cell(cellId);
|
|
|
|
console.log(i, cell.face(), cellId.id(), cellId.toString(), cellId.toLatLng().toString(), cellId.level());
|
|
|
|
});
|