* @private * @function WebMap.prototype.getTileInfo * @description 获取rest map的图层参数。 * @param {Object} layerInfo - 图层信息。 * @param {function} callback - 获得wmts图层参数执行的回调函数
(layerInfo, callback, mapInfo)
| 1577 | * @param {function} callback - 获得wmts图层参数执行的回调函数 |
| 1578 | */ |
| 1579 | getTileInfo(layerInfo, callback, mapInfo) { |
| 1580 | let that = this; |
| 1581 | let options = { |
| 1582 | withCredentials: that.isCredentail(layerInfo.url, layerInfo.proxy), |
| 1583 | withoutFormatSuffix: true |
| 1584 | }; |
| 1585 | let tempUrl = layerInfo.url; |
| 1586 | if (layerInfo.url.indexOf('?token=') > -1) { |
| 1587 | layerInfo.credential = { token: layerInfo.url.split('?token=')[1] }; |
| 1588 | layerInfo.url = layerInfo.url.split('?token=')[0]; |
| 1589 | } |
| 1590 | let url = this.handleJSONSuffix(tempUrl); |
| 1591 | return FetchRequest.get(that.getRequestUrl(url, layerInfo.proxy), null, options) |
| 1592 | .then(function (response) { |
| 1593 | return response.json(); |
| 1594 | }) |
| 1595 | .then(async function (result) { |
| 1596 | // layerInfo.projection = mapInfo.projection; |
| 1597 | // layerInfo.extent = [mapInfo.extent.leftBottom.x, mapInfo.extent.leftBottom.y, mapInfo.extent.rightTop.x, mapInfo.extent.rightTop.y]; |
| 1598 | // 比例尺 单位 |
| 1599 | if (result && result.code && result.code !== 200) { |
| 1600 | throw result; |
| 1601 | } |
| 1602 | if (result.visibleScales) { |
| 1603 | layerInfo.visibleScales = result.visibleScales; |
| 1604 | layerInfo.coordUnit = result.coordUnit; |
| 1605 | } |
| 1606 | layerInfo.maxZoom = result.maxZoom; |
| 1607 | layerInfo.maxZoom = result.minZoom; |
| 1608 | let token = layerInfo.credential ? layerInfo.credential.token : undefined; |
| 1609 | layerInfo.format = 'png'; |
| 1610 | // china_dark为默认底图,还是用png出图 |
| 1611 | if ( |
| 1612 | that.tileFormat === 'webp' && |
| 1613 | layerInfo.url !== 'https://maptiles.supermapol.com/iserver/services/map_China/rest/maps/China_Dark' |
| 1614 | ) { |
| 1615 | const isSupprtWebp = await that.isSupportWebp(layerInfo.url, token, layerInfo.proxy); |
| 1616 | layerInfo.format = isSupprtWebp ? 'webp' : 'png'; |
| 1617 | } |
| 1618 | // 请求结果完成 继续添加图层 |
| 1619 | if (mapInfo) { |
| 1620 | //todo 这个貌似没有用到,下次优化 |
| 1621 | callback && callback(mapInfo, null, true, that); |
| 1622 | } else { |
| 1623 | callback && callback(layerInfo); |
| 1624 | } |
| 1625 | }) |
| 1626 | .catch(function (error) { |
| 1627 | that.errorCallback && that.errorCallback(error, 'getTileInfo', that.map); |
| 1628 | }); |
| 1629 | } |
| 1630 | /** |
| 1631 | * @private |
| 1632 | * @function WebMap.prototype.getWMTSUrl |
no test coverage detected