Skip to content

Commit 12fc838

Browse files
修复视频地图视频图层渲染时机问题 review by luox
1 parent f7979ca commit 12fc838

File tree

7 files changed

+13
-26
lines changed

7 files changed

+13
-26
lines changed

examples/mapboxgl/videoMap.html

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,6 @@
207207
y: cameraLocation.cameraY,
208208
z: cameraLocation.cameraZ
209209
},
210-
autoplay: false,
211210
styleOptions: {
212211
sprite: 'https://iclient.supermap.io/web/styles/street/sprite',
213212
glyphs:

src/mapboxgl/mapping/layers/VideoMapLayer.js

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -40,19 +40,10 @@ export default class VideoMapLayer extends mapboxgl.Evented {
4040
this.play();
4141
}
4242
});
43-
this.video.one('ready', () => {
44-
setTimeout(() => {
45-
this.videoWidth = this.video.videoWidth();
46-
this.videoHeight = this.video.videoHeight();
47-
this._addVideoLayer(this.map);
48-
}, 1000);
49-
});
5043
this.video.one('canplay', () => {
51-
setTimeout(() => {
52-
if (this.autoplay) {
53-
this.map.getSource(this.id).play();
54-
}
55-
}, 1500);
44+
this.videoWidth = this.video.videoWidth();
45+
this.videoHeight = this.video.videoHeight();
46+
this._addVideoLayer(this.map);
5647
});
5748
}
5849

@@ -99,6 +90,9 @@ export default class VideoMapLayer extends mapboxgl.Evented {
9990
}
10091

10192
_afterAddVideoLayer() {
93+
if (this.autoplay) {
94+
this.map.getSource(this.id).play();
95+
}
10296
this.fire('loaded', {
10397
originCoordsRightBottom: this.originCoordsRightBottom,
10498
originCoordsLeftTop: this.originCoordsLeftTop,

src/mapboxgl/overlay/VideoLayer.js

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -88,17 +88,10 @@
8888
this.video.one('firstplay', () => {
8989
this.video.play();
9090
});
91-
this.video.one('ready', () => {
92-
setTimeout(() => {
93-
this.videoWidth = this.video.videoWidth();
94-
this.videoHeight = this.video.videoHeight();
95-
this._addVideoLayer(this.map);
96-
}, 1000);
97-
});
9891
this.video.one('canplay', () => {
99-
setTimeout(() => {
100-
map.getSource(this.layerId).play();
101-
}, 1500);
92+
this.videoWidth = this.video.videoWidth();
93+
this.videoHeight = this.video.videoHeight();
94+
this._addVideoLayer(this.map);
10295
});
10396
}
10497

@@ -264,6 +257,7 @@
264257
source: this.layerId
265258
}
266259
);
260+
map.getSource(this.layerId).play();
267261
});
268262
}
269263

test/karma.conf.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ module.exports = function (config) {
7070
{ pattern: '../src/classic/libs/Lang/*.js', included: true },
7171
{ pattern: '../src/classic/theme/default/*.css', included: true },
7272
{ pattern: './resources/data/**.fgb', included: false },
73-
{ pattern: './resources/data/**.m3u8', included: false },
73+
{ pattern: './resources/data/**.mp4', included: false },
7474
{ pattern: './resources/img/**.svg', included: false },
7575
{ pattern: './resources/img/baiduTileTest.png', included: false },
7676
/**测试文件**/

test/mapboxgl/mapping/VideoMapSpec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { VideoMap } from '../../../src/mapboxgl/mapping/VideoMap';
22
import mapboxgl from 'mapbox-gl';
33
import mbglmap from '../../tool/mock_mapboxgl_map';
4-
var videoUrl = 'base/resources/data/index.m3u8';
4+
var videoUrl = 'base/resources/data/test.mp4';
55
describe('mapboxgl_videoMap', () => {
66
var originalTimeout;
77
var testDiv;

test/mapboxgl/overlay/VideoLayerSpec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { VideoLayer } from '../../../src/mapboxgl/overlay/VideoLayer';
22
import mapboxgl from 'mapbox-gl';
33
import mbglmap from '../../tool/mock_mapboxgl_map';
44
var url = GlobeParameter.ChinaURL + '/zxyTileImage.png?z={z}&x={x}&y={y}';
5-
var videoUrl = 'base/resources/data/index.m3u8';
5+
var videoUrl = 'base/resources/data/test.mp4';
66
describe('mapboxgl_VideoLayer', () => {
77
var originalTimeout;
88
var testDiv, map;

test/resources/data/test.mp4

306 KB
Binary file not shown.

0 commit comments

Comments
 (0)