40 lines
730 B
JavaScript
40 lines
730 B
JavaScript
var S2 = require('s2geometry-node');
|
|
var lat = 40.2574448;
|
|
var lng = -111.7089464;
|
|
|
|
var s2latlng = new S2.S2LatLng(lat, lng);
|
|
var point;
|
|
var cellId = new S2.S2CellId(s2latlng).parent(15);
|
|
var cell;
|
|
|
|
var walk = [];
|
|
var next = cellId;
|
|
var prev = cellId;
|
|
var i;
|
|
|
|
// -10 - -1
|
|
for (i = 0; i < 10; i += 1) {
|
|
prev = prev.prev();
|
|
|
|
walk.unshift([ -(i + 1), prev ]);
|
|
}
|
|
|
|
// 0
|
|
walk.push([ 0, cellId ]);
|
|
|
|
// 1 - 10
|
|
for (i = 0; i < 10; i += 1) {
|
|
next = next.next();
|
|
|
|
walk.push([ i + 1, next ]);
|
|
}
|
|
|
|
// all results
|
|
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());
|
|
});
|