(mapInfo)
| 265 | } |
| 266 | |
| 267 | async _getScales(mapInfo) { |
| 268 | const baseLayerInfo = mapInfo.baseLayer; |
| 269 | const scales = []; |
| 270 | let coordUnit = baseLayerInfo.coordUnit || baseLayerInfo.units || mapRepo.CRS.get(this.baseProjection).unit; |
| 271 | if (!coordUnit) { |
| 272 | coordUnit = this.baseProjection == 'EPSG:3857' ? 'm' : 'degree'; |
| 273 | } |
| 274 | let visibleScales = null; |
| 275 | if (baseLayerInfo.layerType === 'TILE') { |
| 276 | try { |
| 277 | const reqOptions = { |
| 278 | withoutFormatSuffix: true, |
| 279 | withCredentials: this.webMapService.handleWithCredentials('', baseLayerInfo.url, false) |
| 280 | }; |
| 281 | const res = await this.getBounds(`${baseLayerInfo.url}.json`, reqOptions) |
| 282 | if (res && res.visibleScales) { |
| 283 | visibleScales = res.visibleScales; |
| 284 | } |
| 285 | } catch (error) { |
| 286 | console.error(error); |
| 287 | } |
| 288 | } |
| 289 | if (visibleScales && visibleScales.length > 0) { |
| 290 | //底部设置过固定比例尺,则使用设置的 |
| 291 | visibleScales.forEach((scale) => { |
| 292 | const value = 1 / scale; |
| 293 | scales.push(`1:${value}`); |
| 294 | }); |
| 295 | } else if (baseLayerInfo.layerType === 'WMTS') { |
| 296 | try { |
| 297 | const result = await this.webMapService.getWmtsInfo(baseLayerInfo, this.baseProjection); |
| 298 | result.scales.forEach((scale) => { |
| 299 | scales.push(`1:${scale}`); |
| 300 | }); |
| 301 | } catch (error) { |
| 302 | console.error(error); |
| 303 | } |
| 304 | } else if (baseLayerInfo.layerType === 'ZXY_TILE') { |
| 305 | const { resolutions: visibleResolution } = baseLayerInfo; |
| 306 | visibleResolution.forEach((result) => { |
| 307 | const currentScale = '1:' + Util.getScaleFromResolution(result, coordUnit); |
| 308 | scales.push(currentScale); |
| 309 | }); |
| 310 | } else { |
| 311 | const extent = baseLayerInfo.layerType === 'MAPBOXSTYLE' ? mapRepo.CRS.get(this.baseProjection).extent : mapInfo.extent; |
| 312 | const resolutions = this._getResolutionsByExtent({ |
| 313 | extent: this._transExtentToBounds(extent), |
| 314 | tileSize: 512 |
| 315 | }); |
| 316 | for (const res of resolutions) { |
| 317 | const scale = '1:' + Util.getScaleFromResolution(res, coordUnit); |
| 318 | if (scales.indexOf(scale) === -1) { |
| 319 | scales.push(scale); |
| 320 | } |
| 321 | } |
| 322 | } |
| 323 | return scales; |
| 324 | } |
no test coverage detected