Skip to content

Commit 72578fc

Browse files
committed
【fix】webmap使用代理请求逻辑处理
1 parent d4f4165 commit 72578fc

File tree

1 file changed

+4
-26
lines changed

1 file changed

+4
-26
lines changed

src/openlayers/mapping/WebMap.js

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -563,7 +563,7 @@ export class WebMap extends Observable {
563563
url,
564564
tileGrid: TileSuperMapRest.optionsFromMapJSON(url, result).tileGrid
565565
}
566-
if (url && !me.isSameDomain(url)) {
566+
if (url && !CommonUtil.isInTheSameDomain(url) && !this.isIportalProxyServiceUrl(url)) {
567567
options.tileProxy = me.server + 'apps/viewer/getUrlResource.png?url=';
568568
}
569569
source = new TileSuperMapRest(options);
@@ -1167,7 +1167,7 @@ export class WebMap extends Observable {
11671167
options.tileGrid = tileGrid;
11681168
}
11691169
//主机名相同时不添加代理,iportal geturlResource不支持webp代理
1170-
if (layerInfo.url && !this.isSameDomain(layerInfo.url) && layerInfo.format !== 'webp') {
1170+
if (layerInfo.url && !CommonUtil.isInTheSameDomain(layerInfo.url) && !this.isIportalProxyServiceUrl(layerInfo.url) && layerInfo.format !== 'webp') {
11711171
options.tileProxy = this.server + 'apps/viewer/getUrlResource.png?url=';
11721172
}
11731173
let source = new TileSuperMapRest(options);
@@ -2631,7 +2631,7 @@ export class WebMap extends Observable {
26312631
} else {
26322632
let requestUrl = that.formatUrlWithCredential(url), serviceOptions = {};
26332633
serviceOptions.withCredentials = this.withCredentials;
2634-
if (!this.excludePortalProxyUrl && !CommonUtil.isInTheSameDomain(requestUrl)) {
2634+
if (!this.excludePortalProxyUrl && !CommonUtil.isInTheSameDomain(requestUrl) && !this.isIportalProxyServiceUrl(requestUrl)) {
26352635
serviceOptions.proxy = this.getProxy();
26362636
}
26372637
//因为itest上使用的https,iserver是http,所以要加上代理
@@ -3973,7 +3973,7 @@ export class WebMap extends Observable {
39733973
if (this.excludePortalProxyUrl) {
39743974
return;
39753975
}
3976-
return CommonUtil.isInTheSameDomain(url) ? url : `${this.getProxy()}${encodeURIComponent(url)}`;
3976+
return CommonUtil.isInTheSameDomain(url) || this.isIportalProxyServiceUrl(url) ? url : `${this.getProxy()}${encodeURIComponent(url)}`;
39773977
}
39783978

39793979
/**
@@ -4817,28 +4817,6 @@ export class WebMap extends Observable {
48174817
})
48184818
}
48194819

4820-
/**
4821-
* @private
4822-
* @function WebMap.prototype.isSameDomain
4823-
* @description 判断是否同域名(如果是域名,只判断后门两级域名是否相同,第一级忽略),如果是ip地址则需要完全相同。
4824-
* @param {*} url
4825-
*/
4826-
isSameDomain(url) {
4827-
let documentUrlArray = url.split("://"), substring = documentUrlArray[1];
4828-
let domainIndex = substring.indexOf("/"), domain = substring.substring(0, domainIndex);
4829-
4830-
let documentUrl = document.location.toString();
4831-
let docUrlArray = documentUrl.split("://"), documentSubstring = docUrlArray[1];
4832-
let docuDomainIndex = documentSubstring.indexOf("/"), docDomain = documentSubstring.substring(0, docuDomainIndex);
4833-
4834-
if (domain.indexOf(':') > -1 || window.location.port !== "") {
4835-
//说明用的是ip地址,判断完整域名判断
4836-
return domain === docDomain;
4837-
} else {
4838-
let domainArray = domain.split('.'), docDomainArray = docDomain.split('.');
4839-
return domainArray[1] === docDomainArray[1] && domainArray[2] === docDomainArray[2];
4840-
}
4841-
}
48424820
/**
48434821
* @private
48444822
* @function WebMap.prototype.isSupportWebp

0 commit comments

Comments
 (0)