(mapInfo)
| 124 | } |
| 125 | |
| 126 | async _registerMapCRS(mapInfo) { |
| 127 | const { projection, extent = { leftBottom: {}, rightTop: {} }, baseLayer = {} } = mapInfo; |
| 128 | const epsgCode = toEpsgCode(projection); |
| 129 | let crs = { |
| 130 | name: epsgCode, |
| 131 | extent: [extent.leftBottom.x, extent.leftBottom.y, extent.rightTop.x, extent.rightTop.y], |
| 132 | wkt: this._getProjectionWKT(projection) |
| 133 | }; |
| 134 | if (!crsManager.getCRS(epsgCode)) { |
| 135 | switch (baseLayer.layerType) { |
| 136 | case 'MAPBOXSTYLE': { |
| 137 | let url = baseLayer.dataSource.url; |
| 138 | if (url.indexOf('/restjsr/') > -1 && !/\/style\.json$/.test(url)) { |
| 139 | url = Util.urlPathAppend(url, '/style.json'); |
| 140 | } |
| 141 | const res = await this.webMapService.getMapBoxStyle(url); |
| 142 | if (res && res.metadata && res.metadata.indexbounds) { |
| 143 | crs.extent = res.metadata.indexbounds; |
| 144 | } |
| 145 | break; |
| 146 | } |
| 147 | case 'TILE': { |
| 148 | // 获取地图的wkt |
| 149 | if (!crs.wkt) { |
| 150 | crs.wkt = await this.getEpsgCodeWKT(Util.urlPathAppend(baseLayer.url, '/prjCoordSys.wkt'), { |
| 151 | withoutFormatSuffix: true, |
| 152 | withCredentials: this.webMapService.handleWithCredentials('', baseLayer.url, false) |
| 153 | }); |
| 154 | } |
| 155 | const boundsRes = await this.getBounds(`${baseLayer.url}.json`, { |
| 156 | withoutFormatSuffix: true, |
| 157 | withCredentials: this.webMapService.handleWithCredentials('', baseLayer.url, false) |
| 158 | }); |
| 159 | if (boundsRes && boundsRes.bounds) { |
| 160 | crs.extent = [ |
| 161 | boundsRes.bounds.leftBottom.x, |
| 162 | boundsRes.bounds.leftBottom.y, |
| 163 | boundsRes.bounds.rightTop.x, |
| 164 | boundsRes.bounds.rightTop.y |
| 165 | ]; |
| 166 | } |
| 167 | break; |
| 168 | } |
| 169 | case 'ZXY_TILE': { |
| 170 | const extent = this._getZXYTileCrsExtent(baseLayer); |
| 171 | crs.extent = extent; |
| 172 | break; |
| 173 | } |
| 174 | default: |
| 175 | crs = null; |
| 176 | break; |
| 177 | } |
| 178 | } |
| 179 | if (!crs) { |
| 180 | throw new Error('Unsupported coordinate system!') |
| 181 | } |
| 182 | crsManager.registerCRS(crs); |
| 183 | return epsgCode; |
no test coverage detected