@@ -27,7 +27,7 @@ import SampleDataInfo from './webmap/config/SampleDataInfo.json';// eslint-disab
27
27
import GeoJSON from 'ol/format/GeoJSON' ;
28
28
import MVT from 'ol/format/MVT' ;
29
29
import Observable from 'ol/Observable' ;
30
- import olMap from 'ol/Map' ;
30
+ import Map from 'ol/Map' ;
31
31
import View from 'ol/View' ;
32
32
import * as olProj from 'ol/proj' ;
33
33
import * as olProj4 from 'ol/proj/proj4' ;
@@ -216,7 +216,7 @@ export class WebMap extends Observable {
216
216
overlays = mapSetting . overlays ;
217
217
controls = mapSetting . controls ;
218
218
}
219
- this . map = new olMap ( {
219
+ this . map = new Map ( {
220
220
interactions : interactions ,
221
221
overlays : overlays ,
222
222
controls : controls ,
@@ -302,57 +302,100 @@ export class WebMap extends Observable {
302
302
that . errorCallback && that . errorCallback ( mapInfo . error , 'getMapFaild' , that . map ) ;
303
303
return ;
304
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 ;
305
+ let handleResult = await that . handleCRS ( mapInfo . projection , mapInfo . baseLayer . url ) ;
306
+
307
+ //存储地图的名称以及描述等信息,返回给用户
319
308
that . mapParams = {
320
309
title : mapInfo . title ,
321
310
description : mapInfo . description
322
- } ; //存储地图的名称以及描述等信息,返回给用户
311
+ } ;
323
312
324
- // 目前iServer服务中可能出现的EPSG 0,-1,-1000
325
- if ( mapInfo . projection . indexOf ( "EPSG" ) === 0 && mapInfo . projection . split ( ":" ) [ 1 ] <= 0 ) {
326
- //对于这两种地图,只能view,不能叠加其他图层
313
+ if ( handleResult . action === "BrowseMap" ) {
327
314
that . createSpecLayer ( mapInfo ) ;
328
- return ;
329
- } else if ( that . addProjctionFromWKT ( mapInfo . projection ) ) {
330
- mapInfo . projection = that . baseProjection = that . getEpsgInfoFromWKT ( mapInfo . projection ) ;
315
+ } else if ( handleResult . action === "OpenMap" ) {
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
+ if ( mapInfo . baseLayer && mapInfo . baseLayer . layerType === 'MAPBOXSTYLE' ) {
325
+ // 添加矢量瓦片服务作为底图
326
+ that . addMVTMapLayer ( mapInfo , mapInfo . baseLayer , 0 ) . then ( ( ) => {
327
+ that . createView ( mapInfo ) ;
328
+ if ( ! mapInfo . layers || mapInfo . layers . length === 0 ) {
329
+ that . sendMapToUser ( 0 ) ;
330
+ } else {
331
+ that . addLayers ( mapInfo ) ;
332
+ }
333
+ } ) ;
334
+ } else {
335
+ await that . addBaseMap ( mapInfo ) ;
336
+ if ( ! mapInfo . layers || mapInfo . layers . length === 0 ) {
337
+ that . sendMapToUser ( 0 ) ;
338
+ } else {
339
+ that . addLayers ( mapInfo ) ;
340
+ }
341
+ }
331
342
} else {
332
343
// 不支持的坐标系
333
344
that . errorCallback && that . errorCallback ( { type : "Not support CS" , errorMsg : `Not support CS: ${ mapInfo . projection } ` } , 'getMapFaild' , that . map ) ;
334
345
return ;
335
346
}
347
+ }
336
348
337
- if ( mapInfo . baseLayer && mapInfo . baseLayer . layerType === 'MAPBOXSTYLE' ) {
338
- // 添加矢量瓦片服务作为底图
339
- that . addMVTMapLayer ( mapInfo , mapInfo . baseLayer , 0 ) . then ( ( ) => {
340
- that . createView ( mapInfo ) ;
341
- if ( ! mapInfo . layers || mapInfo . layers . length === 0 ) {
342
- that . sendMapToUser ( 0 ) ;
349
+ /**
350
+ * 处理坐标系
351
+ * @private
352
+ * @param {string } crs 必传参数,值是webmap2中定义的坐标系,可能是 1、EGSG:xxx 2、WKT string
353
+ * @param {string } baseLayerUrl 可选参数,地图的服务地址;用于EPSG:-1 的时候,用于请求iServer提供的wkt
354
+ * @return {Object }
355
+ */
356
+ async handleCRS ( crs , baseLayerUrl ) {
357
+ let that = this , handleResult = { } ;
358
+ let newCrs = crs , action = "OpenMap" ;
359
+
360
+ if ( crs === "EPSG:-1" ) {
361
+ // 去iServer请求wkt 否则只能预览出图
362
+ await FetchRequest . get ( that . getRequestUrl ( `${ baseLayerUrl } /prjCoordSys.wkt` ) , null , {
363
+ withCredentials : that . withCredentials ,
364
+ withoutFormatSuffix : true
365
+ } ) . then ( function ( response ) {
366
+ return response . text ( ) ;
367
+ } ) . then ( async function ( result ) {
368
+ if ( result . indexOf ( "<!doctype html>" ) === - 1 ) {
369
+ that . addProjctionFromWKT ( result , "EPSG:-1" ) ;
370
+ handleResult = { action, newCrs} ;
343
371
} else {
344
- that . addLayers ( mapInfo ) ;
372
+ throw 'ERROR' ;
345
373
}
374
+ } ) . catch ( function ( ) {
375
+ action = "BrowseMap" ;
376
+ handleResult = { action, newCrs}
346
377
} ) ;
347
378
} else {
348
- await that . addBaseMap ( mapInfo ) ;
349
- if ( ! mapInfo . layers || mapInfo . layers . length === 0 ) {
350
- that . sendMapToUser ( 0 ) ;
351
- } else {
352
- that . addLayers ( mapInfo ) ;
379
+ if ( crs . indexOf ( "EPSG" ) === 0 && crs . split ( ":" ) [ 1 ] <= 0 ) {
380
+ // 自定义坐标系 rest map EPSG:-1(自定义坐标系) 支持编辑
381
+ // 未知坐标系情况特殊处理,只支持预览 1、rest map EPSG:-1000(没定义坐标系) 2、wms/wmts EPSG:0 (自定义坐标系)
382
+ action = "BrowseMap" ;
383
+ } else if ( crs === 'EPSG:910111' || crs === 'EPSG:910112' ) {
384
+ // 早期数据存在的自定义坐标系 "EPSG:910111": "GCJ02MERCATOR", "EPSG:910112": "BDMERCATOR"
385
+ newCrs = "EPSG:3857" ;
386
+ } else if ( crs === 'EPSG:910101' || crs === 'EPSG:910102' ) {
387
+ // 早期数据存在的自定义坐标系 "EPSG:910101": "GCJ02", "EPSG:910102": "BD",
388
+ newCrs = "EPSG:4326" ;
389
+ } else if ( crs . indexOf ( "EPSG" ) !== 0 ) {
390
+ // wkt
391
+ that . addProjctionFromWKT ( newCrs ) ;
392
+ newCrs = that . getEpsgInfoFromWKT ( crs ) ;
353
393
}
394
+ handleResult = { action, newCrs} ;
354
395
}
396
+ return handleResult ;
355
397
}
398
+
356
399
/**
357
400
* @private
358
401
* @function ol.supermap.WebMap.prototype.getScales
@@ -475,7 +518,7 @@ export class WebMap extends Observable {
475
518
me . mapParams . extent = extent ;
476
519
me . mapParams . projection = mapInfo . projection ;
477
520
}
478
- if ( url . indexOf ( "?token=" ) > - 1 ) {
521
+ if ( url && url . indexOf ( "?token=" ) > - 1 ) {
479
522
//兼容iserver地址有token的情况
480
523
me . credentialKey = 'token' ;
481
524
me . credentialValue = mapInfo . baseLayer . credential = url . split ( "?token=" ) [ 1 ] ;
@@ -532,6 +575,7 @@ export class WebMap extends Observable {
532
575
} else {
533
576
me . errorCallback && me . errorCallback ( { type : "Not support CS" , errorMsg : `Not support CS: ${ baseLayerType } ` } , 'getMapFaild' , me . map ) ;
534
577
}
578
+ view && view . fit ( extent ) ;
535
579
}
536
580
537
581
/**
@@ -595,7 +639,7 @@ export class WebMap extends Observable {
595
639
baseLayer . extent = [ mapInfo . extent . leftBottom . x , mapInfo . extent . leftBottom . y , mapInfo . extent . rightTop . x , mapInfo . extent . rightTop . y ] ;
596
640
}
597
641
this . createView ( mapInfo ) ;
598
- let layer = this . createBaseLayer ( baseLayer , 0 ) ;
642
+ let layer = this . createBaseLayer ( baseLayer , 0 , null , null , true ) ;
599
643
//底图增加图层类型,DV分享需要用它来识别版权信息
600
644
layer . setProperties ( {
601
645
layerType : layerType
@@ -734,8 +778,8 @@ export class WebMap extends Observable {
734
778
* @param {boolean } isCallBack - 是否调用回调函数
735
779
* @param {scope } {object } this对象
736
780
*/
737
- createBaseLayer ( layerInfo , index , isCallBack , scope ) {
738
- let source , isBaseLayer , that = this ;
781
+ createBaseLayer ( layerInfo , index , isCallBack , scope , isBaseLayer ) {
782
+ let source , that = this ;
739
783
740
784
if ( scope ) {
741
785
// 解决异步回调
@@ -996,9 +1040,12 @@ export class WebMap extends Observable {
996
1040
serverType : serverType ,
997
1041
// crossOrigin: 'anonymous', //在IE11.0.9600版本,会影响通过注册服务打开的iserver地图,不出图。因为没有携带cookie会报跨域问题
998
1042
// extent: this.baseLayerExtent,
999
- prjCoordSys : { epsgCode : isBaseLayer ? layerInfo . projection . split ( ':' ) [ 1 ] : this . baseProjection . split ( ':' ) [ 1 ] } ,
1043
+ // prjCoordSys: {epsgCode: isBaseLayer ? layerInfo.projection.split(':')[1] : this.baseProjection.split(':')[1]},
1000
1044
format : layerInfo . format
1001
1045
} ;
1046
+ if ( ! isBaseLayer && this . baseProjection !== "EPSG:-1" ) {
1047
+ options . prjCoordSys = { epsgCode : this . baseProjection . split ( ':' ) [ 1 ] } ;
1048
+ }
1002
1049
if ( layerInfo . visibleScales && layerInfo . visibleScales . length > 0 ) {
1003
1050
let visibleResolutions = [ ] ;
1004
1051
for ( let i in layerInfo . visibleScales ) {
@@ -1162,23 +1209,27 @@ export class WebMap extends Observable {
1162
1209
let projection = {
1163
1210
epsgCode : that . baseProjection . split ( ":" ) [ 1 ]
1164
1211
}
1165
- // bug IE11 不会自动编码
1166
- url += '.json?prjCoordSys=' + encodeURI ( JSON . stringify ( projection ) ) ;
1212
+ if ( that . baseProjection !== "EPSG:-1" ) {
1213
+ // bug IE11 不会自动编码
1214
+ url += '.json?prjCoordSys=' + encodeURI ( JSON . stringify ( projection ) ) ;
1215
+ }
1167
1216
if ( layerInfo . credential ) {
1168
1217
url = `${ url } &token=${ encodeURI ( layerInfo . credential . token ) } ` ;
1169
1218
}
1170
-
1171
1219
} else {
1172
1220
url += ( url . indexOf ( '?' ) > - 1 ? '&SERVICE=WMS&REQUEST=GetCapabilities' : '?SERVICE=WMS&REQUEST=GetCapabilities' ) ;
1173
1221
}
1174
1222
let options = {
1175
1223
withCredentials : this . withCredentials ,
1176
1224
withoutFormatSuffix : true
1177
1225
} ;
1178
- FetchRequest . get ( that . getRequestUrl ( url ) , null , options ) . then ( function ( response ) {
1226
+ FetchRequest . get ( that . getRequestUrl ( ` ${ url } .json` ) , null , options ) . then ( function ( response ) {
1179
1227
return layerInfo . layerType === "TILE" ? response . json ( ) : response . text ( ) ;
1180
1228
} ) . then ( async function ( result ) {
1181
1229
if ( layerInfo . layerType === "TILE" ) {
1230
+ layerInfo . units = result . coordUnit && result . coordUnit . toLowerCase ( ) ;
1231
+ layerInfo . coordUnit = result . coordUnit ;
1232
+ layerInfo . visibleScales = result . visibleScales ;
1182
1233
layerInfo . extent = [ result . bounds . left , result . bounds . bottom , result . bounds . right , result . bounds . top ] ;
1183
1234
layerInfo . projection = `EPSG:${ result . prjCoordSys . epsgCode } ` ;
1184
1235
let token = layerInfo . credential ? layerInfo . credential . token : undefined ;
@@ -1190,6 +1241,8 @@ export class WebMap extends Observable {
1190
1241
layerInfo . projection = that . baseProjection ;
1191
1242
callback ( layerInfo ) ;
1192
1243
}
1244
+ } ) . catch ( ( error ) => {
1245
+ throw error ;
1193
1246
} ) ;
1194
1247
}
1195
1248
@@ -1282,8 +1335,7 @@ export class WebMap extends Observable {
1282
1335
let content = capabilities . Contents ,
1283
1336
tileMatrixSet = content . TileMatrixSet ,
1284
1337
layers = content . Layer ,
1285
- layer , relSet = [ ] ,
1286
- idx , layerFormat , style = 'default' ;
1338
+ layer , idx , layerFormat , style = 'default' ;
1287
1339
1288
1340
for ( let n = 0 ; n < layers . length ; n ++ ) {
1289
1341
if ( layers [ n ] . Identifier === layerInfo . layer ) {
@@ -1314,8 +1366,7 @@ export class WebMap extends Observable {
1314
1366
break ;
1315
1367
}
1316
1368
}
1317
- let name = layerInfo . name ,
1318
- matrixSet = relSet [ idx ] , extent ;
1369
+ let name = layerInfo . name , extent ;
1319
1370
if ( layerBounds ) {
1320
1371
extent = olProj . transformExtent ( layerBounds , 'EPSG:4326' , that . baseProjection ) ;
1321
1372
} else {
@@ -1324,7 +1375,6 @@ export class WebMap extends Observable {
1324
1375
layerInfo . tileUrl = that . getTileUrl ( capabilities . OperationsMetadata . GetTile . DCP . HTTP . Get , layer , layerFormat , isKvp ) ;
1325
1376
//将需要的参数补上
1326
1377
layerInfo . extent = extent ;
1327
- layerInfo . matrixSet = matrixSet ;
1328
1378
layerInfo . name = name ;
1329
1379
layerInfo . orginEpsgCode = layerInfo . projection ;
1330
1380
layerInfo . overLayer = true ;
@@ -3698,17 +3748,19 @@ export class WebMap extends Observable {
3698
3748
* 通过wkt参数扩展支持多坐标系
3699
3749
*
3700
3750
* @param {String } wkt 字符串
3751
+ * @param {string } crsCode epsg信息,如: "EPSG:4490"
3752
+ *
3701
3753
* @returns {Boolean } 坐标系是否添加成功
3702
3754
*/
3703
- addProjctionFromWKT ( wkt ) {
3755
+ addProjctionFromWKT ( wkt , crsCode ) {
3704
3756
if ( typeof ( wkt ) !== 'string' ) {
3705
3757
//参数类型错误
3706
3758
return false ;
3707
3759
} else {
3708
3760
if ( wkt === "EPSG:4326" || wkt === "EPSG:3857" ) {
3709
3761
return true ;
3710
3762
} else {
3711
- let epsgCode = this . getEpsgInfoFromWKT ( wkt ) ;
3763
+ let epsgCode = crsCode || this . getEpsgInfoFromWKT ( wkt ) ;
3712
3764
if ( epsgCode ) {
3713
3765
proj4 . defs ( epsgCode , wkt ) ;
3714
3766
// 重新注册proj4到ol.proj,不然不会生效
0 commit comments