|
| 1 | +import { S2 } from "s2-geometry"; |
| 2 | + |
| 3 | +// $ExpectType LatLng |
| 4 | +const ll = S2.L.LatLng(37.819737, -122.478562); |
| 5 | +// { lat: 37.819737, lng: -122.478562 } |
| 6 | + |
| 7 | +// $ExpectType [number, number, number] |
| 8 | +const xyz = S2.LatLngToXYZ(ll); |
| 9 | +// [ -0.42418720312180813, -0.6663906343183068, 0.6131792064319718 ] |
| 10 | + |
| 11 | +// $ExpectType LatLng |
| 12 | +S2.XYZToLatLng(xyz); |
| 13 | +// { lat: 37.819737, lng: -122.478562 } |
| 14 | + |
| 15 | +// $ExpectType [number, [number, number]] |
| 16 | +const [face, uv] = S2.XYZToFaceUV(xyz); |
| 17 | +// [ 4, [ -0.9201497963116357, -0.6365443649365452 ] ] |
| 18 | + |
| 19 | +// $ExpectType [number, number, number] |
| 20 | +S2.FaceUVToXYZ(face, uv); |
| 21 | +// [ -0.6365443649365452, -1, 0.9201497963116357 ] |
| 22 | + |
| 23 | +// $ExpectType [number, number] |
| 24 | +const st = S2.UVToST(uv); |
| 25 | +// [ 0.030406091585901684, 0.14711766714135244 ] |
| 26 | + |
| 27 | +// $ExpectType [number, number] |
| 28 | +S2.STToUV(st); |
| 29 | +// [ -0.9201497963116357, -0.6365443649365452 ] |
| 30 | + |
| 31 | +// $ExpectType [number, number] |
| 32 | +const ij = S2.STToIJ(st, 10); |
| 33 | +// [ 31, 150 ] |
| 34 | + |
| 35 | +// $ExpectType [number, number] |
| 36 | +S2.IJToST(ij, 10, [0, 0]); |
| 37 | +// [ 0.0302734375, 0.146484375 ] |
| 38 | + |
| 39 | +// $ExpectType S2Cell |
| 40 | +S2.S2Cell.FromHilbertQuadKey('4/0010023002'); |
| 41 | +// { face: 4, ij: [ 30, 150 ], level: 10 } |
| 42 | + |
| 43 | +// $ExpectType S2Cell |
| 44 | +const cell = S2.S2Cell.FromLatLng(ll, 10); |
| 45 | +// { face: 4, ij: [ 31, 150 ], level: 10 } |
| 46 | + |
| 47 | +// $ExpectType S2Cell |
| 48 | +S2.S2Cell.FromFaceIJ(face, ij, 10); |
| 49 | +// { face: 4, ij: [ 31, 150 ], level: 10 } |
| 50 | + |
| 51 | +// $ExpectType string |
| 52 | +const quadkey = cell.toHilbertQuadkey(); |
| 53 | +// '4/0010023003' |
| 54 | + |
| 55 | +// $ExpectType [string, string, string, string] |
| 56 | +S2.latLngToNeighborKeys(ll.lat, ll.lng, 10); |
| 57 | +// $ExpectType [string, string, string, string] |
| 58 | +S2.S2Cell.latLngToNeighborKeys(ll.lat, ll.lng, 10); |
| 59 | +// [ '4/0010023002', '4/0010023010', '4/0010132332', '4/0010023000' ] |
| 60 | + |
| 61 | +// $ExpectType string |
| 62 | +S2.facePosLevelToId(4, '0010023003', 10); |
| 63 | +// $ExpectType string |
| 64 | +S2.fromFacePosLevel(4, '0010023003', 10); |
| 65 | +// $ExpectType string |
| 66 | +S2.S2Cell.facePosLevelToId(4, '0010023003', 10); |
| 67 | +// '9260956642827042816' |
| 68 | + |
| 69 | +// $ExpectType string |
| 70 | +const id = S2.keyToId(quadkey); |
| 71 | +// $ExpectType string |
| 72 | +S2.toId(quadkey); |
| 73 | +// $ExpectType string |
| 74 | +S2.toCellId(quadkey); |
| 75 | +// $ExpectType string |
| 76 | +S2.fromKey(quadkey); |
| 77 | +// $ExpectType string |
| 78 | +S2.S2Cell.keyToId(quadkey); |
| 79 | +// '9260956642827042816' |
| 80 | + |
| 81 | +// $ExpectType string |
| 82 | +S2.idToKey(id); |
| 83 | +// $ExpectType string |
| 84 | +S2.toKey(id); |
| 85 | +// $ExpectType string |
| 86 | +S2.fromCellId(id); |
| 87 | +// $ExpectType string |
| 88 | +S2.fromId(id); |
| 89 | +// $ExpectType string |
| 90 | +S2.toHilbertQuadkey(id); |
| 91 | +// $ExpectType string |
| 92 | +S2.S2Cell.idToKey(id); |
| 93 | +// $ExpectType string |
| 94 | +S2.S2Cell.toKey(id); |
| 95 | +// $ExpectType string |
| 96 | +S2.S2Cell.toHilbertQuadkey(id); |
| 97 | +// '4/0010023003' |
| 98 | + |
| 99 | +// $ExpectType LatLng |
| 100 | +S2.keyToLatLng(quadkey); |
| 101 | +// $ExpectType LatLng |
| 102 | +S2.S2Cell.keyToLatLng(quadkey); |
| 103 | +// { lat: 37.7878524048216, lng: -122.49200878539423 } |
| 104 | + |
| 105 | +// $ExpectType LatLng |
| 106 | +S2.idToLatLng(id); |
| 107 | +// $ExpectType LatLng |
| 108 | +S2.S2Cell.idToLatLng(id); |
| 109 | +// { lat: 37.7878524048216, lng: -122.49200878539423 } |
| 110 | + |
| 111 | +// $ExpectType string |
| 112 | +S2.latLngToKey(ll.lat, ll.lng, 10); |
| 113 | +// $ExpectType string |
| 114 | +S2.latLngToQuadkey(ll.lat, ll.lng, 10); |
| 115 | +// $ExpectType string |
| 116 | +S2.S2Cell.latLngToKey(ll.lat, ll.lng, 10); |
| 117 | +// '4/0010023003' |
| 118 | + |
| 119 | +// $ExpectType string |
| 120 | +S2.prevKey(quadkey); |
| 121 | +// $ExpectType string |
| 122 | +S2.S2Cell.prevKey(quadkey); |
| 123 | +// '4/0010023002' |
| 124 | + |
| 125 | +// $ExpectType string |
| 126 | +S2.nextKey(quadkey); |
| 127 | +// $ExpectType string |
| 128 | +S2.S2Cell.nextKey(quadkey); |
| 129 | +// '4/0010023010' |
| 130 | + |
| 131 | +// $ExpectType string |
| 132 | +S2.stepKey(quadkey, 10); |
| 133 | +// '4/0010023031' |
0 commit comments