@@ -71,10 +71,11 @@ const dpiConfig = {
71
71
* @class ol.supermap.WebMap
72
72
* @category iPortal/Online
73
73
* @classdesc 对接 iPortal/Online 地图类
74
- * @param {number } id - 地图的id
75
74
* @param {Object } options - 参数
76
75
* @param {string } [options.target='map'] - 地图容器id
77
- * @param {string } [options.server="https://www.supermapol.com"] - 地图的地址
76
+ * @param {Object | string } [options.webMap] - webMap对象,或者是获取webMap的url地址。存在webMap,优先使用webMap, id的选项则会被忽略
77
+ * @param {number } [options.id] - 地图的id
78
+ * @param {string } [options.server="https://www.supermapol.com"] - 地图的地址,如果使用传入id,server则会和id拼接成webMap请求地址
78
79
* @param {function } [options.successCallback] - 成功加载地图后调用的函数
79
80
* @param {function } [options.errorCallback] - 加载地图失败调用的函数
80
81
* @param {string } [options.credentialKey] - 凭证密钥。例如为"key"、"token",或者用户自定义的密钥。用户申请了密钥,此参数必填
@@ -94,9 +95,14 @@ export class WebMap extends Observable {
94
95
95
96
constructor ( id , options ) {
96
97
super ( ) ;
97
- this . mapId = id ;
98
+ if ( Util . isObject ( id ) ) {
99
+ options = id ;
100
+ this . mapId = options . id ;
101
+ } else {
102
+ this . mapId = id ;
103
+ }
98
104
options = options || { } ;
99
- this . server = options . server || 'https://www.supermapol.com' ;
105
+ this . server = options . server ;
100
106
this . successCallback = options . successCallback ;
101
107
this . errorCallback = options . errorCallback ;
102
108
this . credentialKey = options . credentialKey ;
@@ -111,8 +117,17 @@ export class WebMap extends Observable {
111
117
this . layerAdded = 0 ;
112
118
this . layers = [ ] ;
113
119
this . events = new Events ( this , null , [ "updateDataflowFeature" ] , true ) ;
120
+ this . webMap = options . webMap ;
114
121
this . createMap ( options . mapSetting ) ;
115
- this . createWebmap ( ) ;
122
+ if ( this . webMap ) {
123
+ // webmap有可能是url地址,有可能是webmap对象
124
+ Util . isString ( this . webMap ) ? this . createWebmap ( this . webMap ) : this . getMapInfoSuccess ( options . webMap ) ;
125
+ } else {
126
+ if ( ! this . server ) {
127
+ this . server = 'https://www.supermapol.com' ;
128
+ }
129
+ this . createWebmap ( ) ;
130
+ }
116
131
}
117
132
118
133
/**
@@ -227,20 +242,25 @@ export class WebMap extends Observable {
227
242
* @private
228
243
* @function ol.supermap.WebMap.prototype.createWebmap
229
244
* @description 创建webmap
245
+ * @param {string } webMapUrl - 请求webMap的地址
230
246
*/
231
- createWebmap ( ) {
232
- let urlArr = this . server . split ( '' ) ;
233
- if ( urlArr [ urlArr . length - 1 ] !== '/' ) {
234
- this . server += '/' ;
235
- }
236
-
237
- let mapUrl = this . server + 'web/maps/' + this . mapId + '/map' ;
238
- let filter = 'getUrlResource.json?url=' ;
239
- if ( this . excludePortalProxyUrl && this . server . indexOf ( filter ) > - 1 ) {
240
- //大屏需求,或者有加上代理的
241
- let urlArray = this . server . split ( filter ) ;
242
- if ( urlArray . length > 1 ) {
243
- mapUrl = urlArray [ 0 ] + filter + this . server + 'web/maps/' + this . mapId + '/map.json' ;
247
+ createWebmap ( webMapUrl ) {
248
+ let mapUrl ;
249
+ if ( webMapUrl ) {
250
+ mapUrl = webMapUrl ;
251
+ } else {
252
+ let urlArr = this . server . split ( '' ) ;
253
+ if ( urlArr [ urlArr . length - 1 ] !== '/' ) {
254
+ this . server += '/' ;
255
+ }
256
+ mapUrl = this . server + 'web/maps/' + this . mapId + '/map' ;
257
+ let filter = 'getUrlResource.json?url=' ;
258
+ if ( this . excludePortalProxyUrl && this . server . indexOf ( filter ) > - 1 ) {
259
+ //大屏需求,或者有加上代理的
260
+ let urlArray = this . server . split ( filter ) ;
261
+ if ( urlArray . length > 1 ) {
262
+ mapUrl = urlArray [ 0 ] + filter + this . server + 'web/maps/' + this . mapId + '/map.json' ;
263
+ }
244
264
}
245
265
}
246
266
this . getMapInfo ( mapUrl ) ;
@@ -263,60 +283,75 @@ export class WebMap extends Observable {
263
283
withCredentials : this . withCredentials
264
284
} ) . then ( function ( response ) {
265
285
return response . json ( ) ;
266
- } ) . then ( async function ( mapInfo ) {
267
- if ( mapInfo . succeed === false ) {
268
- that . errorCallback && that . errorCallback ( mapInfo . error , 'getMapFaild' , that . map ) ;
269
- return ;
270
- }
271
- if ( mapInfo . projection === 'EPSG:910111' || mapInfo . projection === 'EPSG:910112' ) {
272
- // 早期数据存在的自定义坐标系 "EPSG:910111": "GCJ02MERCATOR", "EPSG:910112": "BDMERCATOR"
273
- mapInfo . projection = "EPSG:3857" ;
274
- } else if ( mapInfo . projection === 'EPSG:910101' || mapInfo . projection === 'EPSG:910102' ) {
275
- // 早期数据存在的自定义坐标系 "EPSG:910101": "GCJ02", "EPSG:910102": "BD",
276
- mapInfo . projection = "EPSG:4326" ;
277
- }
278
- that . baseProjection = mapInfo . projection ;
279
- that . webMapVersion = mapInfo . version ;
280
- that . baseLayer = mapInfo . baseLayer ;
281
- that . mapParams = {
282
- title : mapInfo . title ,
283
- description : mapInfo . description
284
- } ; //存储地图的名称以及描述等信息,返回给用户
285
-
286
- // 目前iServer服务中可能出现的EPSG 0,-1,-1000
287
- if ( mapInfo . projection . indexOf ( "EPSG" ) === 0 && mapInfo . projection . split ( ":" ) [ 1 ] <= 0 ) {
288
- //对于这两种地图,只能view,不能叠加其他图层
289
- that . createSpecLayer ( mapInfo ) ;
290
- return ;
291
- } else if ( that . addProjctionFromWKT ( mapInfo . projection ) ) {
292
- mapInfo . projection = that . baseProjection = that . getEpsgInfoFromWKT ( mapInfo . projection ) ;
293
- } else {
294
- // 不支持的坐标系
295
- that . errorCallback && that . errorCallback ( { type : "Not support CS" , errorMsg : `Not support CS: ${ mapInfo . projection } ` } , 'getMapFaild' , that . map ) ;
296
- return ;
297
- }
286
+ } ) . then ( function ( mapInfo ) {
287
+ that . getMapInfoSuccess ( mapInfo ) ;
288
+ } ) . catch ( function ( error ) {
289
+ that . errorCallback && that . errorCallback ( error , 'getMapFaild' , that . map ) ;
290
+ } ) ;
291
+ }
298
292
299
- if ( mapInfo . baseLayer && mapInfo . baseLayer . layerType === 'MAPBOXSTYLE' ) {
300
- // 添加矢量瓦片服务作为底图
301
- that . addMVTMapLayer ( mapInfo , mapInfo . baseLayer , 0 ) . then ( ( ) => {
302
- that . createView ( mapInfo ) ;
303
- if ( ! mapInfo . layers || mapInfo . layers . length === 0 ) {
304
- that . sendMapToUser ( 0 ) ;
305
- } else {
306
- that . addLayers ( mapInfo ) ;
307
- }
308
- } ) ;
309
- } else {
310
- await that . addBaseMap ( mapInfo ) ;
293
+ /**
294
+ * @private
295
+ * @function ol.supermap.WebMap.prototype.getMapInfoSuccess
296
+ * @description 获取地图的json信息
297
+ * @param {Object } mapInfo - webMap对象
298
+ */
299
+ async getMapInfoSuccess ( mapInfo ) {
300
+ let that = this ;
301
+ if ( mapInfo . succeed === false ) {
302
+ that . errorCallback && that . errorCallback ( mapInfo . error , 'getMapFaild' , that . map ) ;
303
+ return ;
304
+ }
305
+ if ( mapInfo . projection === 'EPSG:910111' || mapInfo . projection === 'EPSG:910112' ) {
306
+ // 早期数据存在的自定义坐标系 "EPSG:910111": "GCJ02MERCATOR", "EPSG:910112": "BDMERCATOR"
307
+ mapInfo . projection = "EPSG:3857" ;
308
+ } else if ( mapInfo . projection === 'EPSG:910101' || mapInfo . projection === 'EPSG:910102' ) {
309
+ // 早期数据存在的自定义坐标系 "EPSG:910101": "GCJ02", "EPSG:910102": "BD",
310
+ mapInfo . projection = "EPSG:4326" ;
311
+ }
312
+ // 传入webMap的就使用rootUrl.没有传入就用默认值
313
+ if ( that . webMap ) {
314
+ that . server = mapInfo . rootUrl ;
315
+ }
316
+ that . baseProjection = mapInfo . projection ;
317
+ that . webMapVersion = mapInfo . version ;
318
+ that . baseLayer = mapInfo . baseLayer ;
319
+ that . mapParams = {
320
+ title : mapInfo . title ,
321
+ description : mapInfo . description
322
+ } ; //存储地图的名称以及描述等信息,返回给用户
323
+
324
+ // 目前iServer服务中可能出现的EPSG 0,-1,-1000
325
+ if ( mapInfo . projection . indexOf ( "EPSG" ) === 0 && mapInfo . projection . split ( ":" ) [ 1 ] <= 0 ) {
326
+ //对于这两种地图,只能view,不能叠加其他图层
327
+ that . createSpecLayer ( mapInfo ) ;
328
+ return ;
329
+ } else if ( that . addProjctionFromWKT ( mapInfo . projection ) ) {
330
+ mapInfo . projection = that . baseProjection = that . getEpsgInfoFromWKT ( mapInfo . projection ) ;
331
+ } else {
332
+ // 不支持的坐标系
333
+ that . errorCallback && that . errorCallback ( { type : "Not support CS" , errorMsg : `Not support CS: ${ mapInfo . projection } ` } , 'getMapFaild' , that . map ) ;
334
+ return ;
335
+ }
336
+
337
+ if ( mapInfo . baseLayer && mapInfo . baseLayer . layerType === 'MAPBOXSTYLE' ) {
338
+ // 添加矢量瓦片服务作为底图
339
+ that . addMVTMapLayer ( mapInfo , mapInfo . baseLayer , 0 ) . then ( ( ) => {
340
+ that . createView ( mapInfo ) ;
311
341
if ( ! mapInfo . layers || mapInfo . layers . length === 0 ) {
312
342
that . sendMapToUser ( 0 ) ;
313
343
} else {
314
344
that . addLayers ( mapInfo ) ;
315
345
}
346
+ } ) ;
347
+ } else {
348
+ await that . addBaseMap ( mapInfo ) ;
349
+ if ( ! mapInfo . layers || mapInfo . layers . length === 0 ) {
350
+ that . sendMapToUser ( 0 ) ;
351
+ } else {
352
+ that . addLayers ( mapInfo ) ;
316
353
}
317
- } ) . catch ( function ( error ) {
318
- that . errorCallback && that . errorCallback ( error , 'getMapFaild' , that . map ) ;
319
- } ) ;
354
+ }
320
355
}
321
356
/**
322
357
* @private
@@ -1675,7 +1710,7 @@ export class WebMap extends Observable {
1675
1710
let geojson = that . excelData2FeatureByDivision ( data . content , divisionType , divisionField ) ;
1676
1711
features = that . _parseGeoJsonData2Feature ( { allDatas : { features : geojson . features } , fileCode : layerInfo . projection } ) ;
1677
1712
} else {
1678
- features = that . excelData2Feature ( data . content , layerInfo ) ;
1713
+ features = await that . excelData2Feature ( data . content , layerInfo ) ;
1679
1714
}
1680
1715
} else {
1681
1716
var geoJson = data . content ? JSON . parse ( data . content ) : data ;
0 commit comments