From c65239853a87345b88e85798100382f739d9acd9 Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Thu, 28 Jul 2016 02:25:17 -0400 Subject: [PATCH] update docs and comments --- README.md | 28 ++++++++++++++++++++++++++++ src/s2geometry.js | 3 +++ 2 files changed, 31 insertions(+) diff --git a/README.md b/README.md index f06031a..4578289 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,34 @@ var cell = S2.S2Cell.FromLatLng(latlng, level); cell.getNeighbors(); // [ cellLeft, cellDown, cellRight, cellUp ] cell.getLatLng(); // { lat: 40.2574448, lng: -111.7089464 } + +var key = cell.toHilbertQuadkey(); +``` + +Previous and Next +----------------- + +You can get the previous and next S2CellId from any given Key: + +1. Convert from Lat/Lng to Key (Face and Hilbert Curve Quadtree) +2. Get the Previous or Next Key +3. Convert the Key to an Id (uint64 string) + +``` +var key = S2.latLngToKey(40.2574448, -111.7089464); +var id = S2.toId(key); + +var nextKey = S2.nextKey(key); +var nextId = S2.toId(nextKey); + +var prevKey = S2.prevKey(key); +var prevId = S2.toId(prevKey); + +// See it +console.log(prevKey); +console.log(key); +console.log(nextKey); +console.log(nextId); ``` convert Cell Id to Quadkey diff --git a/src/s2geometry.js b/src/s2geometry.js index ebc0556..4a2961e 100644 --- a/src/s2geometry.js +++ b/src/s2geometry.js @@ -375,6 +375,8 @@ S2.latLngToKey = S2.latLngToQuadkey = function (lat, lng, level) { // // S2.idToLatLng(id) // S2.keyToLatLng(key) + // S2.nextFace(key) // prevent wrapping on nextKey + // S2.prevFace(key) // prevent wrapping on prevKey // // .toKeyArray(id) // face,quadtree // .toKey(id) // hilbert @@ -382,6 +384,7 @@ S2.latLngToKey = S2.latLngToQuadkey = function (lat, lng, level) { // .toId(key) // uint64 (as string) // .toLong(key) // long.js // .toLatLng(id) // object? or array?, or string (with comma)? + // // maybe S2.HQ.x, S2.GPS.x, S2.CI.x? return S2.S2Cell.FromLatLng({ lat: lat, lng: lng }, level).toHilbertQuadkey(); };