@@ -8,14 +8,16 @@ import {
8
8
SecurityManager ,
9
9
ColorsPickerUtil ,
10
10
ArrayStatistic ,
11
- Events
11
+ Events ,
12
+ CommonUtil
12
13
} from '@supermap/iclient-common' ;
13
14
import {
14
15
Util
15
16
} from '../core/Util' ;
16
17
import {
17
18
StyleUtils
18
19
} from '../core/StyleUtils' ;
20
+
19
21
import provincialCenterData from './webmap/config/ProvinceCenter' ;
20
22
import municipalCenterData from './webmap/config/MunicipalCenter' ;
21
23
import jsonsql from 'jsonsql' ;
@@ -128,10 +130,6 @@ export class WebMap extends ol.Observable {
128
130
mapUrl = urlArray [ 0 ] + filter + this . server + 'web/maps/' + this . mapId + '/map.json' ;
129
131
}
130
132
}
131
- //todo 请求用户以及更新时间和地图标签等参数,暂时不需要
132
- // let appUrl = this.server;
133
- // appUrl += ('.json?' + this.credentialKey + '=' + this.credentialValue);
134
- // this.getAppInfo(appUrl);
135
133
this . getMapInfo ( mapUrl ) ;
136
134
}
137
135
@@ -148,7 +146,7 @@ export class WebMap extends ol.Observable {
148
146
//传递过来的url,没有包括.json,在这里加上。
149
147
mapUrl = `${ url } .json`
150
148
}
151
- FetchRequest . get ( mapUrl , null , {
149
+ FetchRequest . get ( that . getRequestUrl ( mapUrl ) , null , {
152
150
withCredentials : this . withCredentials
153
151
} ) . then ( function ( response ) {
154
152
return response . json ( ) ;
@@ -239,7 +237,7 @@ export class WebMap extends ol.Observable {
239
237
240
238
let source ;
241
239
if ( baseLayerType === "TILE" ) {
242
- FetchRequest . get ( ` ${ me . getProxy ( ) } ${ url } .json`, null , {
240
+ FetchRequest . get ( me . getRequestUrl ( ` ${ url } .json`) , null , {
243
241
withCredentials : this . withCredentials
244
242
} ) . then ( function ( response ) {
245
243
return response . json ( ) ;
@@ -257,7 +255,7 @@ export class WebMap extends ol.Observable {
257
255
source = me . createWMSSource ( baseLayerInfo ) ;
258
256
me . addSpecToMap ( source ) ;
259
257
} else if ( baseLayerType === "WMTS" ) {
260
- FetchRequest . get ( ` ${ me . getProxy ( ) } ${ url } ` , null , {
258
+ FetchRequest . get ( me . getRequestUrl ( url ) , null , {
261
259
withCredentials : this . withCredentials
262
260
} ) . then ( function ( response ) {
263
261
return response . text ( ) ;
@@ -815,7 +813,6 @@ export class WebMap extends ol.Observable {
815
813
let projection = {
816
814
epsgCode : that . baseProjection . split ( ":" ) [ 1 ]
817
815
}
818
- //url += `.json?prjCoordSys=${JSON.stringify(projection)}`;
819
816
// bug IE11 不会自动编码
820
817
url += '.json?prjCoordSys=' + encodeURI ( JSON . stringify ( projection ) ) ;
821
818
@@ -826,13 +823,12 @@ export class WebMap extends ol.Observable {
826
823
withCredentials : this . withCredentials ,
827
824
withoutFormatSuffix : true
828
825
} ;
829
- FetchRequest . get ( url , null , options ) . then ( function ( response ) {
826
+ FetchRequest . get ( that . getRequestUrl ( url ) , null , options ) . then ( function ( response ) {
830
827
return layerInfo . layerType === "TILE" ? response . json ( ) : response . text ( ) ;
831
828
} ) . then ( function ( result ) {
832
829
if ( layerInfo . layerType === "TILE" ) {
833
830
layerInfo . extent = [ result . bounds . left , result . bounds . bottom , result . bounds . right , result . bounds . top ] ;
834
831
layerInfo . projection = `EPSG:${ result . prjCoordSys . epsgCode } ` ;
835
-
836
832
callback ( layerInfo ) ;
837
833
} else {
838
834
layerInfo . projection = that . baseProjection ;
@@ -850,12 +846,11 @@ export class WebMap extends ol.Observable {
850
846
*/
851
847
getTileInfo ( layerInfo , callback , mapInfo ) {
852
848
let that = this ;
853
- let url = layerInfo . url ;
854
849
let options = {
855
850
withCredentials : this . withCredentials ,
856
851
withoutFormatSuffix : true
857
852
} ;
858
- FetchRequest . get ( url + " .json" , null , options ) . then ( function ( response ) {
853
+ FetchRequest . get ( that . getRequestUrl ( ` ${ layerInfo . url } .json` ) , null , options ) . then ( function ( response ) {
859
854
return response . json ( ) ;
860
855
} ) . then ( function ( result ) {
861
856
layerInfo . projection = mapInfo . projection ;
@@ -886,12 +881,11 @@ export class WebMap extends ol.Observable {
886
881
*/
887
882
getWmtsInfo ( layerInfo , callback , mapInfo ) {
888
883
let that = this ;
889
- let url = layerInfo . url ;
890
884
let options = {
891
885
withCredentials : false ,
892
886
withoutFormatSuffix : true
893
887
} ;
894
- FetchRequest . get ( url , null , options ) . then ( function ( response ) {
888
+ FetchRequest . get ( that . getRequestUrl ( layerInfo . url ) , null , options ) . then ( function ( response ) {
895
889
return response . text ( ) ;
896
890
} ) . then ( function ( capabilitiesText ) {
897
891
const format = new ol . format . WMTSCapabilities ( ) ;
@@ -1102,9 +1096,7 @@ export class WebMap extends ol.Observable {
1102
1096
if ( ( layer . layerType === "MARKER" ) || ( dataSource && ( ! dataSource . accessType || dataSource . accessType === 'DIRECT' ) ) ) {
1103
1097
//原来二进制文件
1104
1098
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 ) ;
1108
1100
FetchRequest . get ( url , null , {
1109
1101
withCredentials : this . withCredentials
1110
1102
} ) . then ( function ( response ) {
@@ -1320,7 +1312,7 @@ export class WebMap extends ol.Observable {
1320
1312
getDataflowInfo ( layerInfo , success , faild ) {
1321
1313
let that = this ;
1322
1314
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` )
1324
1316
if ( layerInfo . credential && layerInfo . credential . token ) {
1325
1317
token = layerInfo . credential . token ;
1326
1318
requestUrl += `?token=${ token } ` ;
@@ -1369,7 +1361,7 @@ export class WebMap extends ol.Observable {
1369
1361
let that = this , dataSource = layer . dataSource ,
1370
1362
url = layer . dataSource . url ,
1371
1363
dataSourceName = dataSource . dataSourceName || layer . name ;
1372
- let requestUrl = that . server + 'apps/viewer/getUrlResource.json?url=' + encodeURIComponent ( url ) ;
1364
+ let requestUrl = that . getRequestUrl ( url ) ;
1373
1365
//因为itest上使用的https,iserver是http,所以要加上代理
1374
1366
Util . getFeatureBySQL ( requestUrl , [ dataSourceName ] , function ( result ) {
1375
1367
let features = that . parseGeoJsonData2Feature ( {
@@ -2814,7 +2806,8 @@ export class WebMap extends ol.Observable {
2814
2806
* @returns {Promise<T | never> } 关系型文件一些参数
2815
2807
*/
2816
2808
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 , {
2818
2811
withCredentials : this . withCredentials
2819
2812
} ) . then ( function ( response ) {
2820
2813
return response . json ( )
@@ -2830,7 +2823,10 @@ export class WebMap extends ol.Observable {
2830
2823
* @returns {Promise<T | never> } 数据源名称
2831
2824
*/
2832
2825
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 ) {
2834
2830
return response . json ( )
2835
2831
} ) . then ( function ( datasource ) {
2836
2832
let datasourceNames = datasource . datasourceNames ;
@@ -2847,7 +2843,8 @@ export class WebMap extends ol.Observable {
2847
2843
* @returns {Promise<T | never> } 数据的信息
2848
2844
*/
2849
2845
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 , {
2851
2848
withCredentials : this . withCredentials
2852
2849
} ) . then ( function ( response ) {
2853
2850
return response . json ( )
@@ -2857,11 +2854,30 @@ export class WebMap extends ol.Observable {
2857
2854
return result ;
2858
2855
} ) ;
2859
2856
}
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
+
2860
2876
/**
2861
2877
* @private
2862
2878
* @function ol.supermap.WebMap.prototype.getProxy
2863
2879
* @description 获取代理地址
2864
- * @returns {Promise<T | never> } 代理地址
2880
+ * @returns {Promise<T | never> } 代理地址
2865
2881
*/
2866
2882
getProxy ( ) {
2867
2883
return this . server + 'apps/viewer/getUrlResource.json?url=' ;
@@ -2875,19 +2891,18 @@ export class WebMap extends ol.Observable {
2875
2891
* @returns {Promise<T | never> } 地图服务信息
2876
2892
*/
2877
2893
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 , {
2883
2897
withCredentials : this . withCredentials
2884
2898
} ) . then ( function ( response ) {
2885
2899
return response . json ( )
2886
2900
} ) . then ( function ( mapInfo ) {
2887
2901
let promises = [ ] ;
2888
2902
if ( mapInfo ) {
2889
2903
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 , {
2891
2906
withCredentials : that . withCredentials
2892
2907
} ) . then ( function ( response ) {
2893
2908
return response . json ( )
@@ -3261,7 +3276,9 @@ export class WebMap extends ol.Observable {
3261
3276
return this . getDatasetsInfo ( serviceUrl , datasetName ) . then ( ( info ) => {
3262
3277
//判断是否和底图坐标系一直
3263
3278
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 ) {
3265
3282
return response . json ( )
3266
3283
} ) . then ( function ( result ) {
3267
3284
info . isMvt = result . error && result . error . code === 400 ;
@@ -3285,15 +3302,17 @@ export class WebMap extends ol.Observable {
3285
3302
getDatasetsInfo ( serviceUrl , datasetName ) {
3286
3303
let that = this ;
3287
3304
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 ) {
3291
3310
return response . json ( )
3292
3311
} ) . then ( function ( datasetsInfo ) {
3293
3312
return {
3294
3313
epsgCode : datasetsInfo . datasetInfo . prjCoordSys . epsgCode ,
3295
3314
bounds : datasetsInfo . datasetInfo . bounds ,
3296
- url
3315
+ url //返回的是原始url,没有代理。因为用于请求mvt
3297
3316
} ;
3298
3317
} ) ;
3299
3318
} )
@@ -3309,7 +3328,7 @@ export class WebMap extends ol.Observable {
3309
3328
let baseLayer = mapInfo . baseLayer ,
3310
3329
url = baseLayer . dataSource . url ,
3311
3330
layerInfo = { } ;
3312
- return FetchRequest . get ( url ) . then ( result => {
3331
+ return FetchRequest . get ( this . getRequestUrl ( url ) ) . then ( result => {
3313
3332
return result . json ( ) ;
3314
3333
} ) . then ( styles => {
3315
3334
let extent = styles . metadata . mapbounds ;
0 commit comments