@@ -308,7 +308,7 @@ export class WebMap extends Observable {
308
308
that . mapParams = {
309
309
title : mapInfo . title ,
310
310
description : mapInfo . description
311
- } ;
311
+ } ;
312
312
313
313
if ( handleResult . action === "BrowseMap" ) {
314
314
that . createSpecLayer ( mapInfo ) ;
@@ -351,7 +351,7 @@ export class WebMap extends Observable {
351
351
* @private
352
352
* @param {string } crs 必传参数,值是webmap2中定义的坐标系,可能是 1、EGSG:xxx 2、WKT string
353
353
* @param {string } baseLayerUrl 可选参数,地图的服务地址;用于EPSG:-1 的时候,用于请求iServer提供的wkt
354
- * @return {Object }
354
+ * @return {Object }
355
355
*/
356
356
async handleCRS ( crs , baseLayerUrl ) {
357
357
let that = this , handleResult = { } ;
@@ -1160,7 +1160,7 @@ export class WebMap extends Observable {
1160
1160
* @private
1161
1161
* @function ol.supermap.WebMap.prototype.createXYZSource
1162
1162
* @description 创建图层的XYZsource。
1163
- * @param {Object } layerInfo - 图层信息。。
1163
+ * @param {Object } layerInfo - 图层信息
1164
1164
* @returns {ol/source/XYZ } xyz的source
1165
1165
*/
1166
1166
createXYZSource ( layerInfo ) {
@@ -1196,52 +1196,71 @@ export class WebMap extends Observable {
1196
1196
1197
1197
/**
1198
1198
* @private
1199
- * @function ol.supermap.WebMap.prototype.getLayerExtent
1200
- * @description 获取(Supermap Rest/WMS )的图层参数。
1199
+ * @function ol.supermap.WebMap.prototype.getTileLayerExtent
1200
+ * @description 获取(Supermap RestMap )的图层参数。
1201
1201
* @param {Object } layerInfo - 图层信息。
1202
- * @param {function } callback - 获得wmts图层参数执行的回调函数
1202
+ * @param {function } callback - 获得tile图层参数执行的回调函数
1203
1203
*/
1204
- getLayerExtent ( layerInfo , callback ) {
1204
+ async getTileLayerExtent ( layerInfo , callback ) {
1205
+ let that = this ;
1206
+ // 默认使用动态投影方式请求数据
1207
+ let dynamicLayerInfo = await that . getTileLayerExtentInfo ( layerInfo )
1208
+ if ( dynamicLayerInfo ) {
1209
+ Object . assign ( layerInfo , dynamicLayerInfo ) ;
1210
+ callback ( layerInfo ) ;
1211
+ } else {
1212
+ // 不支持动态投影,请求restmap原始信息
1213
+ let originLayerInfo = await that . getTileLayerExtentInfo ( layerInfo , false ) ;
1214
+ Object . assign ( layerInfo , originLayerInfo ) ;
1215
+ callback ( layerInfo ) ;
1216
+ }
1217
+ }
1218
+
1219
+ /**
1220
+ * @private
1221
+ * @function ol.supermap.WebMap.prototype.getTileLayerExtentInfo
1222
+ * @description 获取rest map的图层参数。
1223
+ * @param {String } url - 图层url。
1224
+ * @param {Boolean } isDynamic - 是否请求动态投影信息
1225
+ */
1226
+ getTileLayerExtentInfo ( layerInfo , isDynamic = true ) {
1205
1227
let that = this ,
1206
- url = layerInfo . url . trim ( ) ;
1207
- if ( layerInfo . layerType === "TILE" ) {
1208
- // 直接使用动态投影方式请求数据
1228
+ token ,
1229
+ url = layerInfo . url . trim ( ) ,
1230
+ credential = layerInfo . credential ,
1231
+ options = {
1232
+ withCredentials : this . withCredentials ,
1233
+ withoutFormatSuffix : true
1234
+ } ;
1235
+ if ( isDynamic ) {
1209
1236
let projection = {
1210
1237
epsgCode : that . baseProjection . split ( ":" ) [ 1 ]
1211
1238
}
1212
- if ( that . baseProjection !== "EPSG:-1" ) {
1239
+ if ( that . baseProjection !== "EPSG:-1" ) {
1213
1240
// bug IE11 不会自动编码
1214
1241
url += '.json?prjCoordSys=' + encodeURI ( JSON . stringify ( projection ) ) ;
1215
- }
1216
- if ( layerInfo . credential ) {
1217
- url = `${ url } &token=${ encodeURI ( layerInfo . credential . token ) } ` ;
1218
1242
}
1219
- } else {
1220
- url += ( url . indexOf ( '?' ) > - 1 ? '&SERVICE=WMS&REQUEST=GetCapabilities' : '?SERVICE=WMS&REQUEST=GetCapabilities' ) ;
1221
1243
}
1222
- let options = {
1223
- withCredentials : this . withCredentials ,
1224
- withoutFormatSuffix : true
1225
- } ;
1226
- FetchRequest . get ( that . getRequestUrl ( `${ url } .json` ) , null , options ) . then ( function ( response ) {
1227
- return layerInfo . layerType === "TILE" ? response . json ( ) : response . text ( ) ;
1228
- } ) . then ( async function ( result ) {
1229
- if ( layerInfo . layerType === "TILE" ) {
1230
- layerInfo . units = result . coordUnit && result . coordUnit . toLowerCase ( ) ;
1231
- layerInfo . coordUnit = result . coordUnit ;
1232
- layerInfo . visibleScales = result . visibleScales ;
1233
- layerInfo . extent = [ result . bounds . left , result . bounds . bottom , result . bounds . right , result . bounds . top ] ;
1234
- layerInfo . projection = `EPSG:${ result . prjCoordSys . epsgCode } ` ;
1235
- let token = layerInfo . credential ? layerInfo . credential . token : undefined ;
1236
- let isSupprtWebp = await that . isSupportWebp ( layerInfo . url , token ) ;
1237
- // eslint-disable-next-line require-atomic-updates
1238
- layerInfo . format = isSupprtWebp ? 'webp' : 'png' ;
1239
- callback ( layerInfo ) ;
1240
- } else {
1241
- layerInfo . projection = that . baseProjection ;
1242
- callback ( layerInfo ) ;
1244
+ if ( credential ) {
1245
+ url = `${ url } &token=${ encodeURI ( credential . token ) } ` ;
1246
+ token = credential . token ;
1247
+ }
1248
+ return FetchRequest . get ( that . getRequestUrl ( `${ url } .json` ) , null , options ) . then ( function ( response ) {
1249
+ return response . json ( ) ;
1250
+ } ) . then ( async ( result ) => {
1251
+ if ( result . succeed === false ) {
1252
+ return null
1253
+ } ;
1254
+ let isSupportWebp = await that . isSupportWebp ( layerInfo . url , token ) ;
1255
+ return {
1256
+ units : result . coordUnit && result . coordUnit . toLowerCase ( ) ,
1257
+ coordUnit : result . coordUnit ,
1258
+ visibleScales : result . visibleScales ,
1259
+ extent : [ result . bounds . left , result . bounds . bottom , result . bounds . right , result . bounds . top ] ,
1260
+ projection : `EPSG:${ result . prjCoordSys . epsgCode } ` ,
1261
+ format : isSupportWebp ? 'webp' : 'png'
1243
1262
}
1244
- } ) . catch ( ( error ) => {
1263
+ } ) . catch ( ( error ) => {
1245
1264
throw error ;
1246
1265
} ) ;
1247
1266
}
@@ -1663,8 +1682,13 @@ export class WebMap extends Observable {
1663
1682
}
1664
1683
} else if ( dataSource && dataSource . type === "USER_DATA" ) {
1665
1684
that . addGeojsonFromUrl ( layer , len , layerIndex , false ) ;
1666
- } else if ( layer . layerType === 'SUPERMAP_REST' ||
1667
- layer . layerType === "TILE" ||
1685
+ } else if ( layer . layerType === "TILE" ) {
1686
+ that . getTileLayerExtent ( layer , function ( layerInfo ) {
1687
+ that . map . addLayer ( that . createBaseLayer ( layerInfo , layerIndex ) ) ;
1688
+ that . layerAdded ++ ;
1689
+ that . sendMapToUser ( len ) ;
1690
+ } )
1691
+ } else if ( layer . layerType === 'SUPERMAP_REST' ||
1668
1692
layer . layerType === "WMS" ||
1669
1693
layer . layerType === "WMTS" ) {
1670
1694
if ( layer . layerType === "WMTS" ) {
@@ -1674,11 +1698,10 @@ export class WebMap extends Observable {
1674
1698
that . sendMapToUser ( len ) ;
1675
1699
} )
1676
1700
} else {
1677
- that . getLayerExtent ( layer , function ( layerInfo ) {
1678
- that . map . addLayer ( that . createBaseLayer ( layerInfo , layerIndex ) ) ;
1679
- that . layerAdded ++ ;
1680
- that . sendMapToUser ( len ) ;
1681
- } ) ;
1701
+ layer . projection = that . baseProjection ;
1702
+ that . map . addLayer ( that . createBaseLayer ( layer , layerIndex ) ) ;
1703
+ that . layerAdded ++ ;
1704
+ that . sendMapToUser ( len ) ;
1682
1705
}
1683
1706
} else if ( dataSource && dataSource . type === "REST_DATA" ) {
1684
1707
//从restData获取数据
@@ -3749,7 +3772,7 @@ export class WebMap extends Observable {
3749
3772
*
3750
3773
* @param {String } wkt 字符串
3751
3774
* @param {string } crsCode epsg信息,如: "EPSG:4490"
3752
- *
3775
+ *
3753
3776
* @returns {Boolean } 坐标系是否添加成功
3754
3777
*/
3755
3778
addProjctionFromWKT ( wkt , crsCode ) {
0 commit comments