* @function VideoLayer.prototype.onAdd * @description 添加该图层。 * @param {mapboxgl.Map} map - 地图实例。
(map)
| 112 | * @param {mapboxgl.Map} map - 地图实例。 |
| 113 | */ |
| 114 | onAdd(map) { |
| 115 | this.map = map; |
| 116 | this.renderer = new VideoLayerRenderer({ url: this.url, id: this.layerId }); |
| 117 | this.video = this.renderer.createVideo(); |
| 118 | this.videoDomId = this.renderer.getVideoDomId(); |
| 119 | |
| 120 | this.video.one('firstplay', () => { |
| 121 | this.video.play(); |
| 122 | }); |
| 123 | this.video.one('canplay', () => { |
| 124 | this.videoWidth = this.video.videoWidth(); |
| 125 | this.videoHeight = this.video.videoHeight(); |
| 126 | if (!Array.isArray(this.videoParameters)) { |
| 127 | this.videoParameters = [this.videoParameters]; |
| 128 | } |
| 129 | this._initParameters(this.videoParameters[0]).then((coordTransfer) => { |
| 130 | this.coordTransfer = coordTransfer; |
| 131 | this.timeParams = {}; |
| 132 | this.videoParameters.forEach((dataItem) => { |
| 133 | const { pitch, roll, yaw, x, y, z, fovX, fovY, centerX, centerY } = dataItem; |
| 134 | const time = dataItem.time || 0; |
| 135 | this.timeParams[time] = {} |
| 136 | let fx = fovXToFx(fovX, this.videoWidth); |
| 137 | let fy = fovYToFy(fovY, this.videoHeight); |
| 138 | this.coordTransfer.setCameraLocation({ |
| 139 | pitch, roll, yaw, x, y, z, fx, fy, centerX, centerY |
| 140 | }); |
| 141 | const extent = dataItem.extent || this.extent; |
| 142 | const formatExtent = extent.map((item) => { |
| 143 | if (Array.isArray(item)) { |
| 144 | return item; |
| 145 | } |
| 146 | return [item.x, item.y]; |
| 147 | }); |
| 148 | const poly = polygon([ |
| 149 | [...formatExtent, formatExtent[0]] |
| 150 | ]); |
| 151 | const result = bbox(poly); |
| 152 | this.timeParams[time].result = result; |
| 153 | let latlng = []; |
| 154 | this.timeParams[time].allContained = true; |
| 155 | let that = this; |
| 156 | let temp = [[0, 0], [that.videoWidth, 0], [that.videoWidth, that.videoHeight], [0, that.videoHeight]]; |
| 157 | let realHeight = this.videoHeight; |
| 158 | if (this.clipRegion.length) { |
| 159 | temp = this.clipRegion; |
| 160 | realHeight = this.clipRegion[2][1] - this.clipRegion[0][1]; |
| 161 | } |
| 162 | this.timeParams[time].realHeight = realHeight; |
| 163 | temp.forEach((point) => { |
| 164 | let coord = this.coordTransfer.toSpatialCoordinate(point); |
| 165 | let tcoord = [coord[0], coord[1]]; |
| 166 | const pcoord = proj4('EPSG:3857', 'EPSG:4326', tcoord); |
| 167 | if (!this._contain(pcoord, result)) { |
| 168 | this.timeParams[time].allContained = false; |
| 169 | } |
| 170 | latlng.push(pcoord); |
| 171 | }); |
nothing calls this directly
no test coverage detected