{"name":"s2-geometry","version":"1.2.2","description":"A pure JavaScript/ES5.1 port of Google/Niantic's S2 Geometry library (used by Ingress, Pokemon GO)","main":"src/s2geometry.js","scripts":{"test":"node tests/latlng2cell.js"},"repository":{"type":"git","url":"git+https://github.com/coolaj86/s2-geometry-javascript.git"},"keywords":["s2","geometry","s2geometry","Niantic","Ingress","Pokemon","GO","PokemonGO","cellid","s2cell","s2cellid","latitude","longitude","lat","lng"],"author":{"name":"AJ ONeal","email":"coolaj86@gmail.com","url":"https://coolaj86.com/"},"license":"ISC","bugs":{"url":"https://github.com/coolaj86/s2-geometry-javascript/issues"},"homepage":"https://github.com/coolaj86/s2-geometry-javascript#readme","dependencies":{"long":"^3.2.0"},"contributors":[{"name":"Jon Atkins","email":"github@jonatkins.com","url":"http://www.jonatkins.com/"},{"name":"AJ ONeal","email":"coolaj86@gmail.com","url":"https://coolaj86.com"}],"gitHead":"c0c80ca0f8597d3056bddc2817b7d8c651ffcfd6","_id":"s2-geometry@1.2.2","_shasum":"20e32d33b81d6f655161342b2fda0f2b1ac09af9","_from":".","_npmVersion":"3.10.3","_nodeVersion":"6.3.0","_npmUser":{"name":"coolaj86","email":"coolaj86@gmail.com"},"maintainers":[{"name":"coolaj86","email":"coolaj86@gmail.com"}],"dist":{"shasum":"20e32d33b81d6f655161342b2fda0f2b1ac09af9","tarball":"http://registry-npm.ywwl.com/s2-geometry/download/s2-geometry-1.2.2.tgz","integrity":"sha512-8P+KWwb2qfb6qD+CDPe8sKzgtGeYl6zI/r2Iiep00VB/KNBywdDyuCpd77ZRqY02EbFxbSb3H0x04CYcjWzVsg==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCFn/Fk/NMIUV69l/RTxwjQ7qp/xUmGa/DOO4tVTUSdKgIgUZ9K0xUqZRwbjvZRtCM7pe5POf1eU1Ay24kAjlGiQ2I="}],"size":10061,"noattachment":false,"key":"/s2-geometry/-/s2-geometry-1.2.2.tgz"},"_npmOperationalInternal":{"host":"packages-12-west.internal.npmjs.com","tmp":"tmp/s2-geometry-1.2.2.tgz_1469854241157_0.5735540690366179"},"directories":{},"readme":"s2-geometry (JavaScript/ES5.1)\n======================\n\n| Sponsored by [ppl](https://ppl.family)\n\nA pure JavaScript/ES5.1 port of Google/Niantic's S2 Geometry library (as used by **Ingress**, **Pokemon GO**)\n\nCurrently contains basic support for S2Cell\n\n<table>\n<tr>\n<td></td>\n<td>\nFace 2\n<br>\nOrientation A\n\n<a href=\"http://i.imgur.com/SODO4bT.jpg\" target=\"_face2\"><img src=\"http://i.imgur.com/SODO4bTt.jpg\" title=\"Face 2\" alt=\"Face 2\"></a>\n\n<br>\nThe North Pole<br>(and Canada / Europe)\n</td>\n<td></td>\n</tr>\n<tr>\n<td>\nFace 0\n<br>\nOrientation A\n\n<a href=\"http://i.imgur.com/dLI5Zd1.jpg\" target=\"_face0\"><img src=\"http://i.imgur.com/dLI5Zd1t.jpg\" title=\"Face 0\" alt=\"Face 0\"></a>\n\n<br>\nAfrica\n</td>\n<td>\nFace 1\n<br>\nOrientation D\n\n<a href=\"http://i.imgur.com/duTLDTV.jpg\" target=\"_face1\"><img src=\"http://i.imgur.com/duTLDTVt.jpg\" title=\"Face 1\" alt=\"Face 1\"></a>\n\n<br>\nAsia\n</td>\n<td>\nFace 3\n<br>\nOrientation D\n\n<a href=\"http://i.imgur.com/6Ho35Tc.jpg\" target=\"_face3\"><img src=\"http://i.imgur.com/6Ho35Tct.jpg\" title=\"Face 3\" alt=\"Face 3\"></a>\n\n<br>\nNothing<br>(and Australia)\n</td>\n<td>\nFace 4\n<br>\nOrientation A\n\n<a href=\"http://i.imgur.com/3IBAfqj.jpg\" target=\"_face4\"><img src=\"http://i.imgur.com/3IBAfqjt.jpg\" title=\"Face 4\" alt=\"Face 4\"></a>\n\n<br>\nThe Americas<br>(and Provo, UT)\n</td>\n</tr>\n<tr>\n<td></td>\n<td></td>\n<td></td>\n<td>\nFace 5\n<br>\nOrientation D\n\n<a href=\"http://i.imgur.com/HZCBvgy.jpg\" target=\"_face5\"><img src=\"http://i.imgur.com/HZCBvgyt.jpg\" title=\"Face 5\" alt=\"Face 5\"></a>\n\n<br>\nAntarctica\n</td>\n</tr>\n</table>\n\nWhere is this being used?\n---------------------\n\n* [pokemap-webapp](https://github.com/Daplie/pokemap-webapp)\n* [node-pokemap](https://github.com/Daplie/node-pokemap)\n* [Pokemon-GO-node-api](https://github.com/Daplie/Pokemon-GO-node-api)\n\nSimple Examples\n---------------\n\n```javascript\n'use strict';\n\nvar S2 = require('s2-geometry').S2;\n\nvar lat = 40.2574448;\nvar lng = -111.7089464;\nvar level = 15;\n\n\n\n//\n// Convert from Lat / Lng\n//\nvar key = S2.latLngToKey(lat, lng, level);\n// '4/032212303102210'\n\n\n\n//\n// Convert between Hilbert Curve Quadtree Key and S2 Cell Id\n//\nvar id = S2.keyToId(key);\n// '9749618446378729472'\n\nvar key = S2.idToKey(id);\n// '9749618446378729472'\n\n\n//\n// Convert between Quadkey and Id\n//\nvar latlng = S2.keyToLatLng(key);\nvar latlng = S2.idToLatLng(id);\n\n\n\n//\n// Neighbors\n//\nvar neighbors = S2.latLngToNeighborKeys(lat, lng, level);\n// [ keyLeft, keyDown, keyRight, keyUp ]\n\n\n\n//\n// Previous, Next, and Step\n//\nvar nextKey = S2.nextKey(key);\nvar prevKey = S2.prevKey(key);\n\nvar backTenKeys = S2.stepKey(key, -10);\n```\n\nPrevious and Next\n-----------------\n\nYou can get the previous and next S2CellId from any given Key:\n\n1. Convert from Lat/Lng to Key (Face and Hilbert Curve Quadtree)\n2. Get the Previous or Next Key\n3. Convert the Key to an Id (uint64 string)\n\n```javascript\nvar key = S2.latLngToKey(40.2574448, -111.7089464, 15);   // '4/032212303102210'\nvar id = S2.keyToId(key);                                 // '9749618446378729472'\n\nvar nextKey = S2.nextKey(key);\nvar nextId = S2.keyToId(nextKey);\n\nvar prevKey = S2.prevKey(key);\nvar prevId = S2.keyToId(prevKey);\n\nvar backTenKeys = S2.stepKey(key, -10);\n\n// See it\nconsole.log(prevKey);                                 // '4/032212303102203'\nconsole.log(key);                                     // '4/032212303102210'\nconsole.log(nextKey);                                 // '4/032212303102211'\nconsole.log(nextId);\n```\n\nconvert Cell Id to Hilbert Curve Quad Tree\n------------------\n\nConvert from base 10 (decimal) `S2 Cell Id` to base 4 `quadkey` (aka hilbert curve quadtree id)\n\nExample '4/032212303102210' becomes '9749618446378729472'\n\n```javascript\n'use strict';\n\nvar quadkey = '4/032212303102210'\nvar parts = quadkey.split('/');\nvar face = parts[0];                  // 4\nvar position = parts[1];              // '032212303102210';\nvar level = '032212303102210'.length; // 15\n\nvar cellId = S2.facePosLevelToId(face, position, level);\n\nconsole.log(cellId);\n```\n\nConvert from hilbert quadtree id to s2 cell id:\n\nExample '9749618446378729472' becomes '4/032212303102210'\n\n```javascript\n'use strict';\n\nvar cellId = '9749618446378729472';\n\nvar hilbertQuadkey = S2.idToKey(cellId);\n\nconsole.log(hilbertQuadkey);\n```\n\nConvert Key and Id to LatLng\n---------------------\n\n```javascript\nvar latlng = S2.keyToLatLng('4/032212303102210');\n\nvar latlng = S2.idToLatLng('9749618446378729472');\n```\n","publish_time":1469854242760,"_cnpm_publish_time":1469854242760,"dist-tags":{"latest":"1.2.10"}}