|
| 1 | +import { GoogleTms, QuadKey } from '@basemaps/geo'; |
| 2 | +import o from 'ospec'; |
| 3 | +import { addChildren, addSurrounding } from '../covering.js'; |
| 4 | + |
| 5 | +o.spec('getChildren', () => { |
| 6 | + o('should get children', () => { |
| 7 | + o(addChildren({ z: 0, x: 0, y: 0 })).deepEquals([ |
| 8 | + { z: 1, x: 0, y: 0 }, |
| 9 | + { z: 1, x: 1, y: 0 }, |
| 10 | + { z: 1, x: 0, y: 1 }, |
| 11 | + { z: 1, x: 1, y: 1 }, |
| 12 | + ]); |
| 13 | + }); |
| 14 | + |
| 15 | + ['', '3', '310', '013', '3100123', '3103123231312301'].map((qk) => { |
| 16 | + o('should match QuadKey: ' + qk, () => { |
| 17 | + const tileChildren = addChildren(QuadKey.toTile(qk)); |
| 18 | + const qkChildren = QuadKey.children(qk).map(QuadKey.toTile); |
| 19 | + o(tileChildren).deepEquals(qkChildren); |
| 20 | + }); |
| 21 | + }); |
| 22 | +}); |
| 23 | + |
| 24 | +o.spec('SurroundingTiles', () => { |
| 25 | + o('should not have surrounding tiles at z0', () => { |
| 26 | + const todo = addSurrounding({ z: 0, x: 0, y: 0 }, GoogleTms); |
| 27 | + o(todo).deepEquals([]); |
| 28 | + }); |
| 29 | + |
| 30 | + o('should add all surrounding tiles', () => { |
| 31 | + o(addSurrounding({ z: 2, x: 1, y: 1 }, GoogleTms)).deepEquals([ |
| 32 | + { z: 2, x: 1, y: 0 }, |
| 33 | + { z: 2, x: 2, y: 1 }, |
| 34 | + { z: 2, x: 1, y: 2 }, |
| 35 | + { z: 2, x: 0, y: 1 }, |
| 36 | + ]); |
| 37 | + }); |
| 38 | + |
| 39 | + o('should wrap at matrix extent', () => { |
| 40 | + // Top left tile |
| 41 | + o(addSurrounding({ z: 2, x: 0, y: 0 }, GoogleTms)).deepEquals([ |
| 42 | + { z: 2, x: 0, y: 3 }, // North - Wrapping North to South |
| 43 | + { z: 2, x: 1, y: 0 }, // East |
| 44 | + { z: 2, x: 0, y: 1 }, // South |
| 45 | + { z: 2, x: 3, y: 0 }, // West - Wrapping West to East |
| 46 | + ]); |
| 47 | + |
| 48 | + // Bottom right tile |
| 49 | + o(addSurrounding({ z: 2, x: 3, y: 3 }, GoogleTms)).deepEquals([ |
| 50 | + { z: 2, x: 3, y: 2 }, // North |
| 51 | + { z: 2, x: 0, y: 3 }, // East -- Wrapping East to West |
| 52 | + { z: 2, x: 3, y: 0 }, // South -- Wrapping South to NOrth |
| 53 | + { z: 2, x: 2, y: 3 }, // West |
| 54 | + ]); |
| 55 | + }); |
| 56 | +}); |
0 commit comments