@@ -71,10 +71,11 @@ const dpiConfig = {
7171 * @class ol.supermap.WebMap
7272 * @category iPortal/Online
7373 * @classdesc 对接 iPortal/Online 地图类
74- * @param {number } id - 地图的id
7574 * @param {Object } options - 参数
7675 * @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请求地址
7879 * @param {function } [options.successCallback] - 成功加载地图后调用的函数
7980 * @param {function } [options.errorCallback] - 加载地图失败调用的函数
8081 * @param {string } [options.credentialKey] - 凭证密钥。例如为"key"、"token",或者用户自定义的密钥。用户申请了密钥,此参数必填
@@ -94,9 +95,14 @@ export class WebMap extends Observable {
9495
9596 constructor ( id , options ) {
9697 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+ }
98104 options = options || { } ;
99- this . server = options . server || 'https://www.supermapol.com' ;
105+ this . server = options . server ;
100106 this . successCallback = options . successCallback ;
101107 this . errorCallback = options . errorCallback ;
102108 this . credentialKey = options . credentialKey ;
@@ -111,8 +117,17 @@ export class WebMap extends Observable {
111117 this . layerAdded = 0 ;
112118 this . layers = [ ] ;
113119 this . events = new Events ( this , null , [ "updateDataflowFeature" ] , true ) ;
120+ this . webMap = options . webMap ;
114121 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+ }
116131 }
117132
118133 /**
@@ -227,20 +242,25 @@ export class WebMap extends Observable {
227242 * @private
228243 * @function ol.supermap.WebMap.prototype.createWebmap
229244 * @description 创建webmap
245+ * @param {string } webMapUrl - 请求webMap的地址
230246 */
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+ }
244264 }
245265 }
246266 this . getMapInfo ( mapUrl ) ;
@@ -263,60 +283,75 @@ export class WebMap extends Observable {
263283 withCredentials : this . withCredentials
264284 } ) . then ( function ( response ) {
265285 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+ }
298292
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 ) ;
311341 if ( ! mapInfo . layers || mapInfo . layers . length === 0 ) {
312342 that . sendMapToUser ( 0 ) ;
313343 } else {
314344 that . addLayers ( mapInfo ) ;
315345 }
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 ) ;
316353 }
317- } ) . catch ( function ( error ) {
318- that . errorCallback && that . errorCallback ( error , 'getMapFaild' , that . map ) ;
319- } ) ;
354+ }
320355 }
321356 /**
322357 * @private
@@ -1675,7 +1710,7 @@ export class WebMap extends Observable {
16751710 let geojson = that . excelData2FeatureByDivision ( data . content , divisionType , divisionField ) ;
16761711 features = that . _parseGeoJsonData2Feature ( { allDatas : { features : geojson . features } , fileCode : layerInfo . projection } ) ;
16771712 } else {
1678- features = that . excelData2Feature ( data . content , layerInfo ) ;
1713+ features = await that . excelData2Feature ( data . content , layerInfo ) ;
16791714 }
16801715 } else {
16811716 var geoJson = data . content ? JSON . parse ( data . content ) : data ;
0 commit comments