|
| 1 | +/* Copyright© 2000 - 2023 SuperMap Software Co.Ltd. All rights reserved. |
| 2 | + * This program are made available under the terms of the Apache License, Version 2.0 |
| 3 | + * which accompanies this distribution and is available at http://www.apache.org/licenses/LICENSE-2.0.html.*/ |
| 4 | +import mapboxgl from 'mapbox-gl'; |
| 5 | +import { Util as CommonUtil } from '@supermap/iclient-common/commontypes/Util'; |
| 6 | +import { VideoLayerRenderer } from '@supermap/iclient-common/overlay/video/VideoLayerRenderer'; |
| 7 | + |
| 8 | +/** |
| 9 | + * @class VideoLayer |
| 10 | + * @category Visualization Video |
| 11 | + * @modulecategory Overlay |
| 12 | + * @param {string} name - 图层名称。 |
| 13 | + * @param {Object} options - 构造参数。 |
| 14 | + * @param {string} [options.id] - 专题图层 ID。默认使用 CommonUtil.createUniqueID("VideoLayer_") 创建专题图层 ID。 |
| 15 | + * @param {string} [options.url] - 视频 或 流链接。支持 flv, m3u8 流格式。 |
| 16 | + * @param {string} [options.extent] - 视频范围。 |
| 17 | + * @extends {mapboxgl.Evented} |
| 18 | + * @usage |
| 19 | + */ |
| 20 | +export class VideoLayer extends mapboxgl.Evented { |
| 21 | + |
| 22 | + constructor(name, options) { |
| 23 | + super(); |
| 24 | + var _options = options ? options : {}; |
| 25 | + this.options = _options; |
| 26 | + this.name = name; |
| 27 | + this.url = this.options.url; |
| 28 | + this.extent = this.options.extent; |
| 29 | + this.id = _options.id ? _options.id : CommonUtil.createUniqueID("VideoLayer_"); |
| 30 | + this.layerId = this.id + 'outer'; |
| 31 | + this.type = 'custom'; |
| 32 | + this.renderingMode = '3d'; |
| 33 | + this.overlay = true; |
| 34 | + } |
| 35 | + |
| 36 | + /** |
| 37 | + * @function VideoLayer.prototype.onAdd |
| 38 | + * @description 添加该图层。 |
| 39 | + */ |
| 40 | + onAdd(map) { |
| 41 | + this.map = map; |
| 42 | + this.renderer = new VideoLayerRenderer({ url: this.url, id: this.layerId }); |
| 43 | + this.video = this.renderer.createVideo(); |
| 44 | + this.videoDomId = this.renderer.getVideoDom(); |
| 45 | + this.video.one('firstplay', () => { |
| 46 | + this.video.play(); |
| 47 | + }); |
| 48 | + this.video.one('ready', () => { |
| 49 | + this._addVideoLayer(this.map); |
| 50 | + }); |
| 51 | + this.video.one('canplay', () => { |
| 52 | + setTimeout(() => { |
| 53 | + map.getSource(this.layerId).play(); |
| 54 | + }, 1000); |
| 55 | + }); |
| 56 | + } |
| 57 | + |
| 58 | + render() { } |
| 59 | + |
| 60 | + _addVideoLayer(map) { |
| 61 | + let url = this.videoDomId || this.url; |
| 62 | + map.addSource(this.layerId, { |
| 63 | + type: 'video', |
| 64 | + urls: [url], |
| 65 | + coordinates: this.extent |
| 66 | + }); |
| 67 | + |
| 68 | + map.addLayer( |
| 69 | + { |
| 70 | + id: this.layerId, |
| 71 | + type: 'raster', |
| 72 | + source: this.layerId |
| 73 | + } |
| 74 | + ); |
| 75 | + } |
| 76 | + |
| 77 | + /** |
| 78 | + * @function VideoLayer.prototype.moveLayer |
| 79 | + * @description 移动图层。 |
| 80 | + */ |
| 81 | + moveLayer(beforeId) { |
| 82 | + this.map.moveLayer(this.layerId, beforeId); |
| 83 | + } |
| 84 | + |
| 85 | + /** |
| 86 | + * @function VideoLayer.prototype.setVisibility |
| 87 | + * @description 设置图层可见性。 |
| 88 | + * @param {boolean} [visibility] - 是否显示图层。 |
| 89 | + */ |
| 90 | + setVisibility(visibility) { |
| 91 | + const visible = visibility ? 'visible' : 'none'; |
| 92 | + this.map.setLayoutProperty(this.layerId, 'visibility', visible); |
| 93 | + } |
| 94 | +} |
0 commit comments