|
| 1 | +import { tiandituTileLayer } from '../../../src/leaflet/mapping/TiandituTileLayer'; |
| 2 | +import { mockCreateTile } from '../../tool/mock_leaflet'; |
| 3 | +import { TianDiTu_WGS84CRS, TianDiTu_MercatorCRS } from '../../../src/leaflet/core/ExtendsCRS'; |
| 4 | + |
| 5 | +describe('leaflet_TiandituTileLayer', () => { |
| 6 | + var originalTimeout, map, layer,testDiv; |
| 7 | + beforeAll(() => { |
| 8 | + testDiv = document.createElement('div'); |
| 9 | + testDiv.setAttribute('id', 'map'); |
| 10 | + testDiv.style.styleFloat = 'left'; |
| 11 | + testDiv.style.marginLeft = '8px'; |
| 12 | + testDiv.style.marginTop = '50px'; |
| 13 | + testDiv.style.width = '500px'; |
| 14 | + testDiv.style.height = '500px'; |
| 15 | + mockCreateTile(); |
| 16 | + document.body.appendChild(testDiv); |
| 17 | + map = L.map('map', { |
| 18 | + center: [0, 0], |
| 19 | + maxZoom: 17, |
| 20 | + zoom: 1, |
| 21 | + crs: TianDiTu_MercatorCRS |
| 22 | + }); |
| 23 | + }); |
| 24 | + beforeEach(() => { |
| 25 | + originalTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL; |
| 26 | + jasmine.DEFAULT_TIMEOUT_INTERVAL = 50000; |
| 27 | + }); |
| 28 | + afterEach(() => { |
| 29 | + jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeout; |
| 30 | + if (layer) { |
| 31 | + layer.remove(); |
| 32 | + layer = null; |
| 33 | + } |
| 34 | + }); |
| 35 | + afterAll(() => { |
| 36 | + document.body.removeChild(testDiv); |
| 37 | + map.remove(); |
| 38 | + }); |
| 39 | + |
| 40 | + it('initialize', () => { |
| 41 | + layer = tiandituTileLayer({ |
| 42 | + key: '123456' |
| 43 | + }).addTo(map); |
| 44 | + expect(layer).not.toBeNull(); |
| 45 | + expect(layer.options.layer).toBe('vec'); |
| 46 | + expect(layer.options.isLabel).toBeFalse; |
| 47 | + expect(layer.options.tilematrixSet).toBe('w'); |
| 48 | + expect(layer.options.maxZoom).toBe(17); |
| 49 | + expect(layer.options.requestEncoding).toBe('KVP'); |
| 50 | + expect(layer.options.key).toBe('123456'); |
| 51 | + expect(layer._url).toBe('https://t{s}.tianditu.gov.cn/vec_w/wmts?tk=123456'); |
| 52 | + }); |
| 53 | + |
| 54 | + it('initialize_img', () => { |
| 55 | + layer = tiandituTileLayer({ |
| 56 | + layerType: 'img', |
| 57 | + isLabel: true, |
| 58 | + key: '123456' |
| 59 | + }).addTo(map); |
| 60 | + expect(layer).not.toBeNull(); |
| 61 | + expect(layer.options.layer).toBe('cia'); |
| 62 | + expect(layer.options.isLabel).toBeTrue; |
| 63 | + expect(layer.options.tilematrixSet).toBe('w'); |
| 64 | + expect(layer.options.maxZoom).toBe(17); |
| 65 | + expect(layer.options.requestEncoding).toBe('KVP'); |
| 66 | + expect(layer.options.key).toBe('123456'); |
| 67 | + expect(layer._url).toBe('https://t{s}.tianditu.gov.cn/cia_w/wmts?tk=123456'); |
| 68 | + }); |
| 69 | + |
| 70 | + it('initialize_ter', () => { |
| 71 | + layer = tiandituTileLayer({ |
| 72 | + layerType: 'ter', |
| 73 | + key: '123456' |
| 74 | + }).addTo(map); |
| 75 | + expect(layer).not.toBeNull(); |
| 76 | + expect(layer.options.layer).toBe('ter'); |
| 77 | + expect(layer.options.isLabel).toBeFalse; |
| 78 | + expect(layer.options.tilematrixSet).toBe('w'); |
| 79 | + expect(layer.options.maxZoom).toBe(13); |
| 80 | + expect(layer.options.requestEncoding).toBe('KVP'); |
| 81 | + expect(layer.options.key).toBe('123456'); |
| 82 | + expect(layer._url).toBe('https://t{s}.tianditu.gov.cn/ter_w/wmts?tk=123456'); |
| 83 | + }); |
| 84 | + |
| 85 | + it('initialize_4326', () => { |
| 86 | + map.options.crs = TianDiTu_WGS84CRS; |
| 87 | + layer = tiandituTileLayer({ |
| 88 | + layerType: 'ter', |
| 89 | + key: '123456' |
| 90 | + }).addTo(map); |
| 91 | + expect(layer).not.toBeNull(); |
| 92 | + expect(layer.options.layer).toBe('ter'); |
| 93 | + expect(layer.options.isLabel).toBeFalse; |
| 94 | + expect(layer.options.tilematrixSet).toBe('c'); |
| 95 | + expect(layer.options.maxZoom).toBe(13); |
| 96 | + expect(layer.options.requestEncoding).toBe('KVP'); |
| 97 | + expect(layer.options.key).toBe('123456'); |
| 98 | + expect(layer._url).toBe('https://t{s}.tianditu.gov.cn/ter_c/wmts?tk=123456'); |
| 99 | + map.options.crs = TianDiTu_MercatorCRS; |
| 100 | + }); |
| 101 | + |
| 102 | + it('initialize_url', () => { |
| 103 | + layer = tiandituTileLayer({ |
| 104 | + url: 'https://my.tianditu/{layer}_{proj}/wmts?', |
| 105 | + key: '123456' |
| 106 | + }).addTo(map); |
| 107 | + expect(layer).not.toBeNull(); |
| 108 | + expect(layer.options.layer).toBe('vec'); |
| 109 | + expect(layer.options.isLabel).toBeFalse; |
| 110 | + expect(layer.options.tilematrixSet).toBe('w'); |
| 111 | + expect(layer._url).toBe('https://my.tianditu/vec_w/wmts?tk=123456'); |
| 112 | + }); |
| 113 | + |
| 114 | + it('getTileUrl', () => { |
| 115 | + var coords = { x: 0, y: 0, z: 0 }; |
| 116 | + layer = tiandituTileLayer({ |
| 117 | + layerType: 'img', |
| 118 | + isLabel: true, |
| 119 | + key: '123456' |
| 120 | + }).addTo(map); |
| 121 | + expect(layer).not.toBeNull(); |
| 122 | + expect(layer.options.layer).toBe('cia'); |
| 123 | + expect(layer.options.isLabel).toBeTrue; |
| 124 | + expect(layer.options.tilematrixSet).toBe('w'); |
| 125 | + expect(layer.options.maxZoom).toBe(17); |
| 126 | + expect(layer.options.requestEncoding).toBe('KVP'); |
| 127 | + expect(layer.options.key).toBe('123456'); |
| 128 | + expect(layer._url).toBe('https://t{s}.tianditu.gov.cn/cia_w/wmts?tk=123456'); |
| 129 | + expect(layer.getTileUrl(coords)).toBe( |
| 130 | + 'https://t0.tianditu.gov.cn/cia_w/wmts?tk=123456&service=WMTS&request=GetTile&version=1.0.0&style=default&tilematrixSet=w&format=tiles&width=256&height=256&layer=cia&tilematrix=2&tilerow=0&tilecol=0' |
| 131 | + ); |
| 132 | + }); |
| 133 | + |
| 134 | + it('getTileUrl_remove', () => { |
| 135 | + var coords = { x: 0, y: 0, z: 0 }; |
| 136 | + layer = tiandituTileLayer({ |
| 137 | + layerType: 'img', |
| 138 | + isLabel: true, |
| 139 | + key: '123456' |
| 140 | + }).addTo(map); |
| 141 | + expect(layer.getTileUrl(coords)).toBe( |
| 142 | + 'https://t0.tianditu.gov.cn/cia_w/wmts?tk=123456&service=WMTS&request=GetTile&version=1.0.0&style=default&tilematrixSet=w&format=tiles&width=256&height=256&layer=cia&tilematrix=2&tilerow=0&tilecol=0' |
| 143 | + ); |
| 144 | + layer.remove(); |
| 145 | + layer.addTo(map); |
| 146 | + expect(layer.getTileUrl(coords)).toBe( |
| 147 | + 'https://t0.tianditu.gov.cn/cia_w/wmts?tk=123456&service=WMTS&request=GetTile&version=1.0.0&style=default&tilematrixSet=w&format=tiles&width=256&height=256&layer=cia&tilematrix=2&tilerow=0&tilecol=0' |
| 148 | + ); |
| 149 | + }); |
| 150 | +}); |
0 commit comments