@@ -81,8 +81,9 @@ const dpiConfig = {
8181 * @param {string } [options.credentialValue] - 凭证密钥对应的值,credentialKey和credentialValue必须一起使用
8282 * @param {boolean } [options.withCredentials=false] - 请求是否携带 cookie
8383 * @param {boolean } [options.excludePortalProxyUrl] - server传递过来的url是否带有代理
84- * @param {Object } [options.serviceProxy] - iportal服务代理信息
84+ * @param {Object } [options.serviceProxy] - iportal内置代理信息, 仅矢量瓦片图层上图才会使用
8585 * @param {string } [options.tiandituKey] - 天地图的key
86+ * @param {string } [options.proxy] - 代理地址,当域名不一致,请求会加上代理。避免跨域
8687 * @param {function } [options.mapSetting.mapClickCallback] - 地图被点击的回调函数
8788 * @param {function } [options.mapSetting.overlays] - 地图的overlayer
8889 * @param {function } [options.mapSetting.controls] - 地图的控件
@@ -105,6 +106,7 @@ export class WebMap extends Observable {
105106 this . excludePortalProxyUrl = options . excludePortalProxyUrl || false ;
106107 this . serviceProxy = options . serviceProxy || null ;
107108 this . tiandituKey = options . tiandituKey ;
109+ this . proxy = options . proxy ;
108110 //计数叠加图层,处理过的数量(成功和失败都会计数)
109111 this . layerAdded = 0 ;
110112 this . events = new Events ( this , null , [ "updateDataflowFeature" ] , true ) ;
@@ -423,7 +425,7 @@ export class WebMap extends Observable {
423425 source = me . createWMSSource ( baseLayerInfo ) ;
424426 me . addSpecToMap ( source ) ;
425427 } else if ( baseLayerType === "WMTS" ) {
426- FetchRequest . get ( me . getRequestUrl ( url ) , null , {
428+ FetchRequest . get ( me . getRequestUrl ( url , true ) , null , {
427429 withCredentials : this . withCredentials
428430 } ) . then ( function ( response ) {
429431 return response . text ( ) ;
@@ -1162,7 +1164,7 @@ export class WebMap extends Observable {
11621164 } else {
11631165 url += splitStr + '/1.0.0/WMTSCapabilities.xml' ;
11641166 }
1165- return this . getRequestUrl ( url ) ;
1167+ return this . getRequestUrl ( url , true ) ;
11661168 }
11671169
11681170 /**
@@ -1172,10 +1174,10 @@ export class WebMap extends Observable {
11721174 * @param {Object } layerInfo - 图层信息。
11731175 * @param {function } callback - 获得wmts图层参数执行的回调函数
11741176 */
1175- getWmtsInfo ( layerInfo , callback , mapInfo ) {
1177+ getWmtsInfo ( layerInfo , callback ) {
11761178 let that = this ;
11771179 let options = {
1178- withCredentials : true ,
1180+ withCredentials : that . withCredentials ,
11791181 withoutFormatSuffix : true
11801182 } ;
11811183 const isKvp = ! layerInfo . requestEncoding || layerInfo . requestEncoding === 'KVP' ;
@@ -1240,11 +1242,7 @@ export class WebMap extends Observable {
12401242 layerInfo . unit = "m" ;
12411243 layerInfo . layerFormat = layerFormat ;
12421244 layerInfo . matrixIds = matrixIds ;
1243- if ( mapInfo ) {
1244- callback && callback ( mapInfo , null , true , that ) ;
1245- } else {
1246- callback && callback ( layerInfo ) ;
1247- }
1245+ callback && callback ( layerInfo ) ;
12481246 }
12491247 } ) . catch ( function ( error ) {
12501248 that . errorCallback && that . errorCallback ( error , 'getWmtsFaild' , that . map )
@@ -1730,7 +1728,7 @@ export class WebMap extends Observable {
17301728 getDataflowInfo ( layerInfo , success , faild ) {
17311729 let that = this ;
17321730 let url = layerInfo . url , token ;
1733- let requestUrl = that . getRequestUrl ( `${ url } .json` )
1731+ let requestUrl = that . getRequestUrl ( `${ url } .json` , false ) ;
17341732 if ( layerInfo . credential && layerInfo . credential . token ) {
17351733 token = layerInfo . credential . token ;
17361734 requestUrl += `?token=${ token } ` ;
@@ -3519,10 +3517,12 @@ export class WebMap extends Observable {
35193517 * @private
35203518 * @function ol.supermap.WebMap.prototype.getRootUrl
35213519 * @description 获取请求地址
3520+ * @param {string } url 请求的地址
3521+ * @param {boolean } 请求是否带上Credential.
35223522 * @returns {Promise<T | never> } 请求地址
35233523 */
3524- getRequestUrl ( url ) {
3525- this . formatUrlWithCredential ( url ) ;
3524+ getRequestUrl ( url , excludeCreditial ) {
3525+ url = excludeCreditial ? url : this . formatUrlWithCredential ( url ) ;
35263526 //如果传入进来的url带了代理则不需要处理
35273527 if ( this . excludePortalProxyUrl ) {
35283528 return ;
@@ -3549,8 +3549,11 @@ export class WebMap extends Observable {
35493549 * @description 获取代理地址
35503550 * @returns {Promise<T | never> } 代理地址
35513551 */
3552- getProxy ( ) {
3553- return this . server + 'apps/viewer/getUrlResource.json?url=' ;
3552+ getProxy ( type ) {
3553+ if ( ! type ) {
3554+ type = 'json' ;
3555+ }
3556+ return this . proxy || this . server + `apps/viewer/getUrlResource.${ type } ?url=` ;
35543557 }
35553558
35563559 /**
@@ -4236,9 +4239,17 @@ export class WebMap extends Observable {
42364239 return false ;
42374240 }
42384241 url = token ? `${ url } /tileImage.webp?token=${ token } ` : `${ url } /tileImage.webp` ;
4239- url = this . getRequestUrl ( url ) ;
4242+ let isSameDomain = CommonUtil . isInTheSameDomain ( url ) , excledeCreditial ;
4243+ if ( isSameDomain && ! token ) {
4244+ // online上服务域名一直,要用token值
4245+ excledeCreditial = false ;
4246+ } else {
4247+ excledeCreditial = true ;
4248+ }
4249+ url = this . getRequestUrl ( url , excledeCreditial ) ;
42404250 return FetchRequest . get ( url , null , {
4241- withCredentials : this . withCredentials
4251+ withCredentials : this . withCredentials ,
4252+ withoutFormatSuffix : true
42424253 } ) . then ( function ( response ) {
42434254 if ( response . status !== 200 ) {
42444255 throw response . status ;
0 commit comments