|
| 1 | +import { VideoLayer } from '../../../src/mapboxgl/overlay/VideoLayer'; |
| 2 | +import mapboxgl from 'mapbox-gl'; |
| 3 | +import mbglmap from '../../tool/mock_mapboxgl_map'; |
| 4 | +var url = GlobeParameter.ChinaURL + '/zxyTileImage.png?z={z}&x={x}&y={y}'; |
| 5 | +describe('mapboxgl_VideoLayer', () => { |
| 6 | + var originalTimeout; |
| 7 | + var testDiv, map; |
| 8 | + beforeAll((done) => { |
| 9 | + testDiv = window.document.createElement('div'); |
| 10 | + testDiv.setAttribute('id', 'map'); |
| 11 | + testDiv.style.styleFloat = 'left'; |
| 12 | + testDiv.style.marginLeft = '8px'; |
| 13 | + testDiv.style.marginTop = '50px'; |
| 14 | + testDiv.style.width = '500px'; |
| 15 | + testDiv.style.height = '500px'; |
| 16 | + window.document.body.appendChild(testDiv); |
| 17 | + spyOn(mapboxgl, 'Map').and.callFake(mbglmap); |
| 18 | + map = new mapboxgl.Map({ |
| 19 | + container: 'map', |
| 20 | + style: { |
| 21 | + version: 8, |
| 22 | + sources: { |
| 23 | + 'raster-tiles': { |
| 24 | + type: 'raster', |
| 25 | + tiles: [url], |
| 26 | + tileSize: 256 |
| 27 | + } |
| 28 | + }, |
| 29 | + layers: [ |
| 30 | + { |
| 31 | + id: 'simple-tiles', |
| 32 | + type: 'raster', |
| 33 | + source: 'raster-tiles', |
| 34 | + minzoom: 0, |
| 35 | + maxzoom: 22 |
| 36 | + } |
| 37 | + ] |
| 38 | + }, |
| 39 | + center: [0, 0], |
| 40 | + zoom: 3 |
| 41 | + }); |
| 42 | + map.on('load', function () { |
| 43 | + done(); |
| 44 | + }); |
| 45 | + }); |
| 46 | + beforeEach(() => { |
| 47 | + originalTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL; |
| 48 | + jasmine.DEFAULT_TIMEOUT_INTERVAL = 50000; |
| 49 | + }); |
| 50 | + |
| 51 | + afterEach(() => { |
| 52 | + jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeout; |
| 53 | + }); |
| 54 | + |
| 55 | + afterAll(() => { |
| 56 | + document.body.removeChild(testDiv); |
| 57 | + map = null; |
| 58 | + }); |
| 59 | + |
| 60 | + it('init videoLayer', (done) => { |
| 61 | + var url = 'http://172.16.15.84:8000/live/test.flv'; |
| 62 | + var cv = { |
| 63 | + CV_32FC2: 'CV_32FC2', |
| 64 | + matFromImageData: function () { |
| 65 | + return { |
| 66 | + delete: function () { |
| 67 | + |
| 68 | + } |
| 69 | + } |
| 70 | + }, |
| 71 | + Size: function () { |
| 72 | + return { |
| 73 | + width: 770, |
| 74 | + height: 690 |
| 75 | + } |
| 76 | + }, |
| 77 | + matFromArray: function () { |
| 78 | + |
| 79 | + }, |
| 80 | + Mat: function () { |
| 81 | + return { |
| 82 | + delete: function () { }, |
| 83 | + cols: 2, |
| 84 | + rows: 2, |
| 85 | + data: [1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4] |
| 86 | + } |
| 87 | + }, |
| 88 | + findHomography: function () { |
| 89 | + |
| 90 | + }, |
| 91 | + warpPerspective: function () { |
| 92 | + |
| 93 | + } |
| 94 | + } |
| 95 | + spyOn(cv, 'Size'); |
| 96 | + spyOn(cv, 'findHomography'); |
| 97 | + spyOn(cv, 'warpPerspective'); |
| 98 | + var videoLayer = new VideoLayer({ |
| 99 | + url: url, |
| 100 | + opencv: cv, |
| 101 | + extent: [ |
| 102 | + [116.14394400766855, 28.249134537249257], |
| 103 | + [116.143464581289, 28.252977295834056], |
| 104 | + [116.14734767029731, 28.251762901914655], |
| 105 | + [116.14737169684759, 28.25095489453961] |
| 106 | + ] |
| 107 | + }); |
| 108 | + videoLayer.onAdd(map); |
| 109 | + setTimeout(() => { |
| 110 | + expect(cv.Size).toHaveBeenCalled(); |
| 111 | + expect(cv.findHomography).toHaveBeenCalled(); |
| 112 | + expect(cv.warpPerspective).toHaveBeenCalled(); |
| 113 | + expect(videoLayer.url).toBe(url); |
| 114 | + expect(videoLayer.videoDomId).not.toBeNull(); |
| 115 | + expect(videoLayer.video).not.toBeNull(); |
| 116 | + expect(videoLayer.pixelBBox).not.toBeNull(); |
| 117 | + done(); |
| 118 | + }, 3000); |
| 119 | + }); |
| 120 | +}); |
0 commit comments