* @private * @function WebMap.prototype.getMapboxStyle * @description 获取mapboxstyle --- ipt中自定义底图请求mapboxstyle目前有两种url格式 * rest-map服务的Mapbox Style资源地址是这样的: .../iserver/services/map-Population/rest/maps/PopulationDistribution/tileFeature/vectorstyles.json?type=MapBox_GL&styleonly=true * r
(mapInfo, layerInfo)
| 5023 | * @returns {Object} 图层信息 |
| 5024 | */ |
| 5025 | getMapboxStyle(mapInfo, layerInfo) { |
| 5026 | let _this = this; |
| 5027 | let url = layerInfo.url || layerInfo.dataSource.url; |
| 5028 | let styleUrl = url; |
| 5029 | if (styleUrl.indexOf('/restjsr/') > -1 && !/\/style\.json$/.test(url)) { |
| 5030 | styleUrl = `${styleUrl}/style.json`; |
| 5031 | } |
| 5032 | styleUrl = this.getRequestUrl(styleUrl); |
| 5033 | let credential = layerInfo.credential; |
| 5034 | //携带令牌(restmap用的首字母大写,但是这里要用小写) |
| 5035 | let credentialValue, keyfix; |
| 5036 | if (credential) { |
| 5037 | keyfix = Object.keys(credential)[0]; |
| 5038 | credentialValue = credential[keyfix]; |
| 5039 | styleUrl = `${styleUrl}?${keyfix}=${credentialValue}`; |
| 5040 | } |
| 5041 | |
| 5042 | return FetchRequest.get(styleUrl, null, { |
| 5043 | withCredentials: this.isCredentail(styleUrl), |
| 5044 | withoutFormatSuffix: true, |
| 5045 | headers: { |
| 5046 | 'Content-Type': 'application/json;chartset=uft-8' |
| 5047 | } |
| 5048 | }) |
| 5049 | .then(function (response) { |
| 5050 | return response.json(); |
| 5051 | }) |
| 5052 | .then((styles) => { |
| 5053 | _this._matchStyleObject(styles); |
| 5054 | let bounds = layerInfo.bounds; |
| 5055 | // 处理携带令牌的情况 |
| 5056 | if (credentialValue) { |
| 5057 | styles.sprite = `${styles.sprite}?${keyfix}=${credentialValue}`; |
| 5058 | let sources = styles.sources; |
| 5059 | let sourcesNames = Object.keys(sources); |
| 5060 | sourcesNames.forEach(function (sourceName) { |
| 5061 | styles.sources[sourceName].tiles.forEach(function (tiles, i) { |
| 5062 | const splicing = tiles.includes('?') ? '&' : '?'; |
| 5063 | styles.sources[sourceName].tiles[i] = `${tiles}${splicing}${keyfix}=${credentialValue}`; |
| 5064 | }); |
| 5065 | }); |
| 5066 | } |
| 5067 | |
| 5068 | let newLayerInfo = { |
| 5069 | url: url, |
| 5070 | sourceType: 'VECTOR_TILE', |
| 5071 | layerType: 'VECTOR_TILE', |
| 5072 | styles: styles, |
| 5073 | extent: bounds && [bounds.left, bounds.bottom, bounds.right, bounds.top], |
| 5074 | bounds: layerInfo.bounds, |
| 5075 | projection: 'EPSG:' + layerInfo.epsgCode, |
| 5076 | epsgCode: layerInfo.epsgCode, |
| 5077 | name: layerInfo.name |
| 5078 | }; |
| 5079 | Object.assign(layerInfo, newLayerInfo); |
| 5080 | if (layerInfo.zIndex > 0) { |
| 5081 | // 过滤styles 非底图mapboxstyle图层才需此处理 |
| 5082 | _this.modifyMapboxstyleLayer(mapInfo, layerInfo); |
no test coverage detected