s2-geometry.js/tests/simple.js

52 lines
805 B
JavaScript
Raw Normal View History

2016-08-03 23:43:35 +00:00
'use strict';
var S2 = require('../src/s2geometry.js').S2;
var lat = 40.2574448;
var lng = -111.7089464;
var level = 15;
2016-08-03 23:48:24 +00:00
//
// Convert from Lat / Lng
//
2016-08-03 23:43:35 +00:00
var key = S2.latLngToKey(lat, lng, level);
console.log(key);
2016-08-03 23:48:24 +00:00
// '4/032212303102210'
2016-08-03 23:43:35 +00:00
2016-08-03 23:48:24 +00:00
//
// Convert between Hilbert Curve Quadtree Key and S2 Cell Id
//
2016-08-03 23:43:35 +00:00
var id = S2.keyToId(key);
console.log(id);
2016-08-03 23:48:24 +00:00
// '9749618446378729472'
var key = S2.idToKey(id);
console.log(key);
// '9749618446378729472'
2016-08-03 23:43:35 +00:00
2016-08-03 23:48:24 +00:00
//
// Neighbors
//
2016-08-03 23:43:35 +00:00
var neighbors = S2.latLngToNeighborKeys(lat, lng, level);
console.log(neighbors);
2016-08-03 23:48:24 +00:00
// [ keyLeft, keyDown, keyRight, keyUp ]
2016-08-03 23:43:35 +00:00
2016-08-03 23:48:24 +00:00
//
// Previous, Next, and Step
//
2016-08-03 23:43:35 +00:00
var nextKey = S2.nextKey(key);
console.log(nextKey);
var prevKey = S2.prevKey(key);
console.log(prevKey);
2016-08-03 23:48:24 +00:00
var backTenKeys = S2.stepKey(key, -10);
console.log(backTenKeys);