@@ -8,14 +8,16 @@ import {
88 SecurityManager ,
99 ColorsPickerUtil ,
1010 ArrayStatistic ,
11- Events
11+ Events ,
12+ CommonUtil
1213} from '@supermap/iclient-common' ;
1314import {
1415 Util
1516} from '../core/Util' ;
1617import {
1718 StyleUtils
1819} from '../core/StyleUtils' ;
20+
1921import provincialCenterData from './webmap/config/ProvinceCenter' ;
2022import municipalCenterData from './webmap/config/MunicipalCenter' ;
2123import jsonsql from 'jsonsql' ;
@@ -128,10 +130,6 @@ export class WebMap extends ol.Observable {
128130 mapUrl = urlArray [ 0 ] + filter + this . server + 'web/maps/' + this . mapId + '/map.json' ;
129131 }
130132 }
131- //todo 请求用户以及更新时间和地图标签等参数,暂时不需要
132- // let appUrl = this.server;
133- // appUrl += ('.json?' + this.credentialKey + '=' + this.credentialValue);
134- // this.getAppInfo(appUrl);
135133 this . getMapInfo ( mapUrl ) ;
136134 }
137135
@@ -148,7 +146,7 @@ export class WebMap extends ol.Observable {
148146 //传递过来的url,没有包括.json,在这里加上。
149147 mapUrl = `${ url } .json`
150148 }
151- FetchRequest . get ( mapUrl , null , {
149+ FetchRequest . get ( that . getRequestUrl ( mapUrl ) , null , {
152150 withCredentials : this . withCredentials
153151 } ) . then ( function ( response ) {
154152 return response . json ( ) ;
@@ -239,7 +237,7 @@ export class WebMap extends ol.Observable {
239237
240238 let source ;
241239 if ( baseLayerType === "TILE" ) {
242- FetchRequest . get ( ` ${ me . getProxy ( ) } ${ url } .json`, null , {
240+ FetchRequest . get ( me . getRequestUrl ( ` ${ url } .json`) , null , {
243241 withCredentials : this . withCredentials
244242 } ) . then ( function ( response ) {
245243 return response . json ( ) ;
@@ -257,7 +255,7 @@ export class WebMap extends ol.Observable {
257255 source = me . createWMSSource ( baseLayerInfo ) ;
258256 me . addSpecToMap ( source ) ;
259257 } else if ( baseLayerType === "WMTS" ) {
260- FetchRequest . get ( ` ${ me . getProxy ( ) } ${ url } ` , null , {
258+ FetchRequest . get ( me . getRequestUrl ( url ) , null , {
261259 withCredentials : this . withCredentials
262260 } ) . then ( function ( response ) {
263261 return response . text ( ) ;
@@ -815,7 +813,6 @@ export class WebMap extends ol.Observable {
815813 let projection = {
816814 epsgCode : that . baseProjection . split ( ":" ) [ 1 ]
817815 }
818- //url += `.json?prjCoordSys=${JSON.stringify(projection)}`;
819816 // bug IE11 不会自动编码
820817 url += '.json?prjCoordSys=' + encodeURI ( JSON . stringify ( projection ) ) ;
821818
@@ -826,13 +823,12 @@ export class WebMap extends ol.Observable {
826823 withCredentials : this . withCredentials ,
827824 withoutFormatSuffix : true
828825 } ;
829- FetchRequest . get ( url , null , options ) . then ( function ( response ) {
826+ FetchRequest . get ( that . getRequestUrl ( url ) , null , options ) . then ( function ( response ) {
830827 return layerInfo . layerType === "TILE" ? response . json ( ) : response . text ( ) ;
831828 } ) . then ( function ( result ) {
832829 if ( layerInfo . layerType === "TILE" ) {
833830 layerInfo . extent = [ result . bounds . left , result . bounds . bottom , result . bounds . right , result . bounds . top ] ;
834831 layerInfo . projection = `EPSG:${ result . prjCoordSys . epsgCode } ` ;
835-
836832 callback ( layerInfo ) ;
837833 } else {
838834 layerInfo . projection = that . baseProjection ;
@@ -850,12 +846,11 @@ export class WebMap extends ol.Observable {
850846 */
851847 getTileInfo ( layerInfo , callback , mapInfo ) {
852848 let that = this ;
853- let url = layerInfo . url ;
854849 let options = {
855850 withCredentials : this . withCredentials ,
856851 withoutFormatSuffix : true
857852 } ;
858- FetchRequest . get ( url + " .json" , null , options ) . then ( function ( response ) {
853+ FetchRequest . get ( that . getRequestUrl ( ` ${ layerInfo . url } .json` ) , null , options ) . then ( function ( response ) {
859854 return response . json ( ) ;
860855 } ) . then ( function ( result ) {
861856 layerInfo . projection = mapInfo . projection ;
@@ -886,12 +881,11 @@ export class WebMap extends ol.Observable {
886881 */
887882 getWmtsInfo ( layerInfo , callback , mapInfo ) {
888883 let that = this ;
889- let url = layerInfo . url ;
890884 let options = {
891885 withCredentials : false ,
892886 withoutFormatSuffix : true
893887 } ;
894- FetchRequest . get ( url , null , options ) . then ( function ( response ) {
888+ FetchRequest . get ( that . getRequestUrl ( layerInfo . url ) , null , options ) . then ( function ( response ) {
895889 return response . text ( ) ;
896890 } ) . then ( function ( capabilitiesText ) {
897891 const format = new ol . format . WMTSCapabilities ( ) ;
@@ -1102,9 +1096,7 @@ export class WebMap extends ol.Observable {
11021096 if ( ( layer . layerType === "MARKER" ) || ( dataSource && ( ! dataSource . accessType || dataSource . accessType === 'DIRECT' ) ) ) {
11031097 //原来二进制文件
11041098 let url = `${ that . server } web/datas/${ serverId } /content.json?pageSize=9999999¤tPage=1` ;
1105- if ( that . credentialValue ) {
1106- url = `${ url } &${ that . credentialKey } =${ that . credentialValue } ` ;
1107- }
1099+ url = that . getRequestUrl ( url ) ;
11081100 FetchRequest . get ( url , null , {
11091101 withCredentials : this . withCredentials
11101102 } ) . then ( function ( response ) {
@@ -1320,7 +1312,7 @@ export class WebMap extends ol.Observable {
13201312 getDataflowInfo ( layerInfo , success , faild ) {
13211313 let that = this ;
13221314 let url = layerInfo . url , token ;
1323- let requestUrl = that . server + 'apps/viewer/getUrlResource.json?url=' + encodeURIComponent ( url ) + ' .json' ;
1315+ let requestUrl = that . getRequestUrl ( ` ${ url } .json` )
13241316 if ( layerInfo . credential && layerInfo . credential . token ) {
13251317 token = layerInfo . credential . token ;
13261318 requestUrl += `?token=${ token } ` ;
@@ -1369,7 +1361,7 @@ export class WebMap extends ol.Observable {
13691361 let that = this , dataSource = layer . dataSource ,
13701362 url = layer . dataSource . url ,
13711363 dataSourceName = dataSource . dataSourceName || layer . name ;
1372- let requestUrl = that . server + 'apps/viewer/getUrlResource.json?url=' + encodeURIComponent ( url ) ;
1364+ let requestUrl = that . getRequestUrl ( url ) ;
13731365 //因为itest上使用的https,iserver是http,所以要加上代理
13741366 Util . getFeatureBySQL ( requestUrl , [ dataSourceName ] , function ( result ) {
13751367 let features = that . parseGeoJsonData2Feature ( {
@@ -2814,7 +2806,8 @@ export class WebMap extends ol.Observable {
28142806 * @returns {Promise<T | never> } 关系型文件一些参数
28152807 */
28162808 checkUploadToRelationship ( fileId ) {
2817- return FetchRequest . get ( `${ this . server } web/datas/${ fileId } /datasets.json` , null , {
2809+ let url = this . getRequestUrl ( `${ this . server } web/datas/${ fileId } /datasets.json` ) ;
2810+ return FetchRequest . get ( url , null , {
28182811 withCredentials : this . withCredentials
28192812 } ) . then ( function ( response ) {
28202813 return response . json ( )
@@ -2830,7 +2823,10 @@ export class WebMap extends ol.Observable {
28302823 * @returns {Promise<T | never> } 数据源名称
28312824 */
28322825 getDatasources ( url ) {
2833- return FetchRequest . get ( `${ this . getProxy ( ) } ${ url } /data/datasources.json` ) . then ( function ( response ) {
2826+ let requestUrl = this . getRequestUrl ( `${ url } /data/datasources.json` ) ;
2827+ return FetchRequest . get ( requestUrl , null , {
2828+ withCredentials : this . withCredentials
2829+ } ) . then ( function ( response ) {
28342830 return response . json ( )
28352831 } ) . then ( function ( datasource ) {
28362832 let datasourceNames = datasource . datasourceNames ;
@@ -2847,7 +2843,8 @@ export class WebMap extends ol.Observable {
28472843 * @returns {Promise<T | never> } 数据的信息
28482844 */
28492845 getDataService ( fileId , datasetName ) {
2850- return FetchRequest . get ( `${ this . server } web/datas/${ fileId } .json` , null , {
2846+ let url = this . getRequestUrl ( `${ this . server } web/datas/${ fileId } .json` ) ;
2847+ return FetchRequest . get ( url , null , {
28512848 withCredentials : this . withCredentials
28522849 } ) . then ( function ( response ) {
28532850 return response . json ( )
@@ -2857,11 +2854,30 @@ export class WebMap extends ol.Observable {
28572854 return result ;
28582855 } ) ;
28592856 }
2857+
2858+ /**
2859+ * @private
2860+ * @function ol.supermap.WebMap.prototype.getRootUrl
2861+ * @description 获取请求地址
2862+ * @returns {Promise<T | never> } 请求地址
2863+ */
2864+ getRequestUrl ( url ) {
2865+ if ( this . credentialValue ) {
2866+ //有token之类的配置项
2867+ url = `${ url } &${ this . credentialKey } =${ this . credentialValue } ` ;
2868+ }
2869+ //如果传入进来的url带了代理则不需要处理
2870+ if ( this . excludePortalProxyUrl ) {
2871+ return ;
2872+ }
2873+ return CommonUtil . isInTheSameDomain ( url ) ? url : `${ this . getProxy ( ) } ${ encodeURIComponent ( url ) } ` ;
2874+ }
2875+
28602876 /**
28612877 * @private
28622878 * @function ol.supermap.WebMap.prototype.getProxy
28632879 * @description 获取代理地址
2864- * @returns {Promise<T | never> } 代理地址
2880+ * @returns {Promise<T | never> } 代理地址
28652881 */
28662882 getProxy ( ) {
28672883 return this . server + 'apps/viewer/getUrlResource.json?url=' ;
@@ -2875,19 +2891,18 @@ export class WebMap extends ol.Observable {
28752891 * @returns {Promise<T | never> } 地图服务信息
28762892 */
28772893 getTileLayerInfo ( url ) {
2878- let that = this ;
2879- let proxyUrl = this . server + 'apps/viewer/getUrlResource.json?url=' ;
2880- let requestUrl = proxyUrl + encodeURIComponent ( url ) ;
2881- let epsgCode = that . baseProjection . split ( 'EPSG:' ) [ 1 ] ;
2882- return FetchRequest . get ( `${ requestUrl } /maps.json` , null , {
2894+ let that = this , epsgCode = that . baseProjection . split ( 'EPSG:' ) [ 1 ] ;
2895+ let requestUrl = that . getRequestUrl ( `${ url } /maps.json` ) ;
2896+ return FetchRequest . get ( requestUrl , null , {
28832897 withCredentials : this . withCredentials
28842898 } ) . then ( function ( response ) {
28852899 return response . json ( )
28862900 } ) . then ( function ( mapInfo ) {
28872901 let promises = [ ] ;
28882902 if ( mapInfo ) {
28892903 mapInfo . forEach ( function ( info ) {
2890- let promise = FetchRequest . get ( `${ proxyUrl } ${ info . path } .json?prjCoordSys=${ JSON . stringify ( { epsgCode : epsgCode } ) } ` , null , {
2904+ let mapUrl = that . getRequestUrl ( `${ info . path } .json?prjCoordSys=${ encodeURI ( JSON . stringify ( { epsgCode : epsgCode } ) ) } ` )
2905+ let promise = FetchRequest . get ( mapUrl , null , {
28912906 withCredentials : that . withCredentials
28922907 } ) . then ( function ( response ) {
28932908 return response . json ( )
@@ -3261,7 +3276,9 @@ export class WebMap extends ol.Observable {
32613276 return this . getDatasetsInfo ( serviceUrl , datasetName ) . then ( ( info ) => {
32623277 //判断是否和底图坐标系一直
32633278 if ( info . epsgCode == that . baseProjection . split ( 'EPSG:' ) [ 1 ] ) {
3264- return FetchRequest . get ( `${ that . getProxy ( ) } ${ info . url } /tilefeature.mvt` ) . then ( function ( response ) {
3279+ return FetchRequest . get ( that . getRequestUrl ( `${ info . url } /tilefeature.mvt` ) , null , {
3280+ withCredentials : that . withCredentials
3281+ } ) . then ( function ( response ) {
32653282 return response . json ( )
32663283 } ) . then ( function ( result ) {
32673284 info . isMvt = result . error && result . error . code === 400 ;
@@ -3285,15 +3302,17 @@ export class WebMap extends ol.Observable {
32853302 getDatasetsInfo ( serviceUrl , datasetName ) {
32863303 let that = this ;
32873304 return that . getDatasources ( serviceUrl ) . then ( function ( datasourceName ) {
3288- //判断mvt服务是否可用
3289- let url = `${ serviceUrl } /data/datasources/${ datasourceName } /datasets/${ datasetName } ` ;
3290- return FetchRequest . get ( `${ that . getProxy ( ) } ${ url } .json` ) . then ( function ( response ) {
3305+ //判断mvt服务是否可用
3306+ let url = `${ serviceUrl } /data/datasources/${ datasourceName } /datasets/${ datasetName } .json` ;
3307+ return FetchRequest . get ( that . getRequestUrl ( url ) , null , {
3308+ withCredentials : that . withCredentials
3309+ } ) . then ( function ( response ) {
32913310 return response . json ( )
32923311 } ) . then ( function ( datasetsInfo ) {
32933312 return {
32943313 epsgCode : datasetsInfo . datasetInfo . prjCoordSys . epsgCode ,
32953314 bounds : datasetsInfo . datasetInfo . bounds ,
3296- url
3315+ url //返回的是原始url,没有代理。因为用于请求mvt
32973316 } ;
32983317 } ) ;
32993318 } )
@@ -3309,7 +3328,7 @@ export class WebMap extends ol.Observable {
33093328 let baseLayer = mapInfo . baseLayer ,
33103329 url = baseLayer . dataSource . url ,
33113330 layerInfo = { } ;
3312- return FetchRequest . get ( url ) . then ( result => {
3331+ return FetchRequest . get ( this . getRequestUrl ( url ) ) . then ( result => {
33133332 return result . json ( ) ;
33143333 } ) . then ( styles => {
33153334 let extent = styles . metadata . mapbounds ;
0 commit comments