* @private * @function WebMap.prototype.addLayers * @description 添加叠加图层 * @param {Object} mapInfo - 地图信息
(mapInfo)
| 2006 | * @param {Object} mapInfo - 地图信息 |
| 2007 | */ |
| 2008 | async addLayers(mapInfo) { |
| 2009 | let layers = mapInfo.layers, |
| 2010 | that = this; |
| 2011 | let features = [], |
| 2012 | len = layers.length; |
| 2013 | if (len > 0) { |
| 2014 | //存储地图上所有的图层对象 |
| 2015 | this.layers = layers; |
| 2016 | for (let index = 0; index < layers.length; index++) { |
| 2017 | const layer = layers[index]; |
| 2018 | //加上底图的index |
| 2019 | let layerIndex = index + 1, |
| 2020 | dataSource = layer.dataSource, |
| 2021 | isSampleData = dataSource && dataSource.type === 'SAMPLE_DATA' && !!dataSource.name; //SAMPLE_DATA是本地示例数据 |
| 2022 | if (layer.layerType === 'MAPBOXSTYLE') { |
| 2023 | that |
| 2024 | .addMVTMapLayer(mapInfo, layer, layerIndex) |
| 2025 | .then(() => { |
| 2026 | that.layerAdded++; |
| 2027 | that.sendMapToUser(len); |
| 2028 | }) |
| 2029 | .catch(function (error) { |
| 2030 | that.layerAdded++; |
| 2031 | that.sendMapToUser(len); |
| 2032 | that.errorCallback && that.errorCallback(error, 'getLayerFaild', that.map); |
| 2033 | }); |
| 2034 | } else if ( |
| 2035 | (dataSource && dataSource.serverId) || |
| 2036 | layer.layerType === 'MARKER' || |
| 2037 | layer.layerType === 'HOSTED_TILE' || |
| 2038 | isSampleData |
| 2039 | ) { |
| 2040 | //数据存储到iportal上了 |
| 2041 | let dataSource = layer.dataSource, |
| 2042 | serverId = dataSource ? dataSource.serverId : layer.serverId; |
| 2043 | if (!serverId && !isSampleData) { |
| 2044 | await that.addLayer(layer, null, layerIndex); |
| 2045 | that.layerAdded++; |
| 2046 | that.sendMapToUser(len); |
| 2047 | continue; |
| 2048 | } |
| 2049 | if ( |
| 2050 | layer.layerType === 'MARKER' || |
| 2051 | (dataSource && (!dataSource.accessType || dataSource.accessType === 'DIRECT')) || |
| 2052 | isSampleData |
| 2053 | ) { |
| 2054 | //原来二进制文件 |
| 2055 | let url = isSampleData |
| 2056 | ? `${that.server}apps/dataviz/libs/sample-datas/${dataSource.name}.json` |
| 2057 | : `${that.server}web/datas/${serverId}/content.json?pageSize=9999999¤tPage=1`; |
| 2058 | url = that.getRequestUrl(url, layer.proxy); |
| 2059 | FetchRequest.get(url, null, { |
| 2060 | withCredentials: that.isCredentail(url, layer.proxy) |
| 2061 | }) |
| 2062 | .then(function (response) { |
| 2063 | return response.json(); |
| 2064 | }) |
| 2065 | .then(async function (data) { |
no test coverage detected