@@ -308,7 +308,7 @@ export class WebMap extends Observable {
308308 that . mapParams = {
309309 title : mapInfo . title ,
310310 description : mapInfo . description
311- } ;
311+ } ;
312312
313313 if ( handleResult . action === "BrowseMap" ) {
314314 that . createSpecLayer ( mapInfo ) ;
@@ -351,7 +351,7 @@ export class WebMap extends Observable {
351351 * @private
352352 * @param {string } crs 必传参数,值是webmap2中定义的坐标系,可能是 1、EGSG:xxx 2、WKT string
353353 * @param {string } baseLayerUrl 可选参数,地图的服务地址;用于EPSG:-1 的时候,用于请求iServer提供的wkt
354- * @return {Object }
354+ * @return {Object }
355355 */
356356 async handleCRS ( crs , baseLayerUrl ) {
357357 let that = this , handleResult = { } ;
@@ -1160,7 +1160,7 @@ export class WebMap extends Observable {
11601160 * @private
11611161 * @function ol.supermap.WebMap.prototype.createXYZSource
11621162 * @description 创建图层的XYZsource。
1163- * @param {Object } layerInfo - 图层信息。。
1163+ * @param {Object } layerInfo - 图层信息
11641164 * @returns {ol/source/XYZ } xyz的source
11651165 */
11661166 createXYZSource ( layerInfo ) {
@@ -1196,52 +1196,71 @@ export class WebMap extends Observable {
11961196
11971197 /**
11981198 * @private
1199- * @function ol.supermap.WebMap.prototype.getLayerExtent
1200- * @description 获取(Supermap Rest/WMS )的图层参数。
1199+ * @function ol.supermap.WebMap.prototype.getTileLayerExtent
1200+ * @description 获取(Supermap RestMap )的图层参数。
12011201 * @param {Object } layerInfo - 图层信息。
1202- * @param {function } callback - 获得wmts图层参数执行的回调函数
1202+ * @param {function } callback - 获得tile图层参数执行的回调函数
12031203 */
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 ) {
12051227 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 ) {
12091236 let projection = {
12101237 epsgCode : that . baseProjection . split ( ":" ) [ 1 ]
12111238 }
1212- if ( that . baseProjection !== "EPSG:-1" ) {
1239+ if ( that . baseProjection !== "EPSG:-1" ) {
12131240 // bug IE11 不会自动编码
12141241 url += '.json?prjCoordSys=' + encodeURI ( JSON . stringify ( projection ) ) ;
1215- }
1216- if ( layerInfo . credential ) {
1217- url = `${ url } &token=${ encodeURI ( layerInfo . credential . token ) } ` ;
12181242 }
1219- } else {
1220- url += ( url . indexOf ( '?' ) > - 1 ? '&SERVICE=WMS&REQUEST=GetCapabilities' : '?SERVICE=WMS&REQUEST=GetCapabilities' ) ;
12211243 }
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'
12431262 }
1244- } ) . catch ( ( error ) => {
1263+ } ) . catch ( ( error ) => {
12451264 throw error ;
12461265 } ) ;
12471266 }
@@ -1663,8 +1682,13 @@ export class WebMap extends Observable {
16631682 }
16641683 } else if ( dataSource && dataSource . type === "USER_DATA" ) {
16651684 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' ||
16681692 layer . layerType === "WMS" ||
16691693 layer . layerType === "WMTS" ) {
16701694 if ( layer . layerType === "WMTS" ) {
@@ -1674,11 +1698,10 @@ export class WebMap extends Observable {
16741698 that . sendMapToUser ( len ) ;
16751699 } )
16761700 } 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 ) ;
16821705 }
16831706 } else if ( dataSource && dataSource . type === "REST_DATA" ) {
16841707 //从restData获取数据
@@ -3749,7 +3772,7 @@ export class WebMap extends Observable {
37493772 *
37503773 * @param {String } wkt 字符串
37513774 * @param {string } crsCode epsg信息,如: "EPSG:4490"
3752- *
3775+ *
37533776 * @returns {Boolean } 坐标系是否添加成功
37543777 */
37553778 addProjctionFromWKT ( wkt , crsCode ) {
0 commit comments