|
1 | 1 | export type TileType = 'roadmap' | 'satellite'; |
2 | 2 | export const tileTypes: TileType[] = ['roadmap', 'satellite']; |
3 | 3 |
|
| 4 | +/** |
| 5 | + * Takes one bang operator and decodes it. |
| 6 | + * |
| 7 | + * Possible types are: |
| 8 | + * - `s`: string |
| 9 | + * - `v`: timestamp => keep as string |
| 10 | + * - `b`: boolean? / byte? => keep as string |
| 11 | + * - `f`: float |
| 12 | + * - `d`: double |
| 13 | + * - `i`: int |
| 14 | + * - `m`: matrix => length as int |
| 15 | + * - `e`: enum |
| 16 | + * - `z`: base64 encoded coordinates => Degrees Minutes Seconds Direction |
| 17 | + * |
| 18 | + * Unknown types are kept as string. |
| 19 | + * |
| 20 | + * @param item One bang operator with the structure: position, one character (data type), encoded data |
| 21 | + * @returns Array of two items. First is the decoded result. Second describes if the result is a new matrix. |
| 22 | + */ |
4 | 23 | function convertType(item: string): [string | TileType | number, boolean] { |
5 | 24 | item = item.replace(/^\d+/, ''); |
6 | 25 | const type: string = item.charAt(0); |
@@ -29,6 +48,28 @@ function convertType(item: string): [string | TileType | number, boolean] { |
29 | 48 | return [val, type === 'm']; |
30 | 49 | } |
31 | 50 |
|
| 51 | +/** |
| 52 | + * Half iterative half recursive function that converts an array of split hashbangs and converts it into a fitting representation. |
| 53 | + * Multiple nested arrays possible. |
| 54 | + * |
| 55 | + * Example input: |
| 56 | + * ```ts |
| 57 | + * TODO: ['', '', ''] |
| 58 | + * ``` |
| 59 | + * |
| 60 | + * Example result: |
| 61 | + * ```ts |
| 62 | + * TODO: |
| 63 | + * ``` |
| 64 | + * |
| 65 | + * References: |
| 66 | + * - https://andrewwhitby.com/2014/09/09/google-maps-new-embed-format/ |
| 67 | + * - https://blog.themillhousegroup.com/2016/08/deep-diving-into-google-pb-embedded-map.html |
| 68 | + * - https://stackoverflow.com/a/47042514 |
| 69 | + * @param items Bang operators (e.g. `!1m13`) split into pieces at `!` |
| 70 | + * @param out Array for top and recursion levels to save results and return |
| 71 | + * @returns Filled `out` array with bang operators converted into readable format |
| 72 | + */ |
32 | 73 | export function parsePB(items: string[], out: any[] = []): any[] { |
33 | 74 | let i = 0; |
34 | 75 | while (i < items.length) { |
|
0 commit comments