* @private * @function WebMap.prototype.createMVTLayer * @description 创建矢量瓦片图层 * @param {Object} layerInfo - 图层信息
(layerInfo)
| 5258 | * @param {Object} layerInfo - 图层信息 |
| 5259 | */ |
| 5260 | createMVTLayer(layerInfo) { |
| 5261 | let styles = layerInfo.styles; |
| 5262 | const indexbounds = styles && styles.metadata && styles.metadata.indexbounds; |
| 5263 | const visibleResolution = this.createVisibleResolution( |
| 5264 | layerInfo.visibleScales, |
| 5265 | indexbounds, |
| 5266 | layerInfo.bounds, |
| 5267 | layerInfo.coordUnit |
| 5268 | ); |
| 5269 | const envelope = this.getEnvelope(indexbounds, layerInfo.bounds); |
| 5270 | const styleResolutions = this.getStyleResolutions(envelope); |
| 5271 | const origin = [envelope.left, envelope.top]; |
| 5272 | let baseUrl = layerInfo.url; |
| 5273 | let paramUrl = baseUrl.split('?')[1]; |
| 5274 | if (layerInfo.dataSource.type === 'ARCGIS_VECTORTILE') { |
| 5275 | Object.keys(styles.sources).forEach(function (key) { |
| 5276 | Object.keys(styles.sources[key]).forEach(function(fieldName) { |
| 5277 | if (fieldName === 'url') { |
| 5278 | if (typeof styles.sources[key][fieldName] === 'string' && !CommonUtil.isAbsoluteURL(styles.sources[key][fieldName])) { |
| 5279 | styles.sources[key][fieldName] = CommonUtil.relative2absolute(styles.sources[key][fieldName], baseUrl); |
| 5280 | } |
| 5281 | styles.sources[key][fieldName] = styles.sources[key][fieldName] + (paramUrl ? '?' + paramUrl + '&f=json' : '?f=json'); |
| 5282 | } |
| 5283 | }); |
| 5284 | }); |
| 5285 | } |
| 5286 | let sourceName = Object.keys(styles.sources)[0]; |
| 5287 | let checkUrl = styles.sources[sourceName].url || styles.sources[sourceName].tiles[0]; |
| 5288 | if (checkUrl && !CommonUtil.isAbsoluteURL(checkUrl)) { |
| 5289 | checkUrl = CommonUtil.relative2absolute(checkUrl, baseUrl); |
| 5290 | } |
| 5291 | const withCredentials = CommonUtil.isInTheSameDomain(checkUrl) || this.isIportalProxyServiceUrl(checkUrl); |
| 5292 | const requestParameters = this.tileRequestParameters && this.tileRequestParameters(checkUrl); |
| 5293 | // 创建MapBoxStyle样式 |
| 5294 | let mapboxStyles = new MapboxStyles({ |
| 5295 | baseUrl, |
| 5296 | style: styles, |
| 5297 | source: styles.name, |
| 5298 | resolutions: styleResolutions, |
| 5299 | map: this.map, |
| 5300 | withCredentials, |
| 5301 | ...requestParameters |
| 5302 | }); |
| 5303 | return new Promise((resolve) => { |
| 5304 | mapboxStyles.on('styleloaded', function () { |
| 5305 | let minResolution = visibleResolution[visibleResolution.length - 1]; |
| 5306 | let maxResolution = visibleResolution[0]; |
| 5307 | let layer = new olLayer.VectorTile({ |
| 5308 | //设置避让参数 |
| 5309 | declutter: true, |
| 5310 | source: new VectorTileSuperMapRest({ |
| 5311 | baseUrl, |
| 5312 | style: styles, |
| 5313 | withCredentials, |
| 5314 | projection: layerInfo.projection, |
| 5315 | tileGrid: new TileGrid({ |
| 5316 | resolutions: styleResolutions, |
| 5317 | origin, |
no test coverage detected