@@ -34,6 +34,7 @@ import * as olProj4 from 'ol/proj/proj4';
34
34
import Units from 'ol/proj/Units' ;
35
35
import * as olLayer from 'ol/layer' ;
36
36
import WMTSCapabilities from 'ol/format/WMTSCapabilities' ;
37
+ import WMSCapabilities from 'ol/format/WMSCapabilities' ;
37
38
import TileGrid from 'ol/tilegrid/TileGrid' ;
38
39
import WMTSTileGrid from 'ol/tilegrid/WMTS' ;
39
40
import * as olGeometry from 'ol/geom' ;
@@ -638,6 +639,8 @@ export class WebMap extends Observable {
638
639
await this . getWmtsInfo ( baseLayer ) ;
639
640
} else if ( layerType === 'TILE' ) {
640
641
await this . getTileInfo ( baseLayer ) ;
642
+ } else if ( layerType === 'WMS' ) {
643
+ await this . getWmsInfo ( baseLayer ) ;
641
644
}
642
645
baseLayer . projection = mapInfo . projection ;
643
646
if ( ! baseLayer . extent ) {
@@ -1186,7 +1189,8 @@ export class WebMap extends Observable {
1186
1189
wrapX : false ,
1187
1190
params : {
1188
1191
LAYERS : layerInfo . layers ? layerInfo . layers [ 0 ] : "0" ,
1189
- FORMAT : 'image/png'
1192
+ FORMAT : 'image/png' ,
1193
+ VERSION : layerInfo . version || "1.3.0"
1190
1194
} ,
1191
1195
projection : layerInfo . projection || that . baseProjection ,
1192
1196
tileLoadFunction : function ( imageTile , src ) {
@@ -1432,6 +1436,59 @@ export class WebMap extends Observable {
1432
1436
that . errorCallback && that . errorCallback ( error , 'getWmtsFaild' , that . map )
1433
1437
} ) ;
1434
1438
}
1439
+ /**
1440
+ * @private
1441
+ * @function ol.supermap.WebMap.prototype.getWmsInfo
1442
+ * @description 获取wms的图层参数。
1443
+ * @param {Object } layerInfo - 图层信息。
1444
+ */
1445
+ getWmsInfo ( layerInfo ) {
1446
+ let that = this ;
1447
+ let url = layerInfo . url . trim ( ) ;
1448
+ url += ( url . indexOf ( '?' ) > - 1 ? '&SERVICE=WMS&REQUEST=GetCapabilities' : '?SERVICE=WMS&REQUEST=GetCapabilities' ) ;
1449
+ let options = {
1450
+ withCredentials : that . withCredentials ,
1451
+ withoutFormatSuffix : true
1452
+ } ;
1453
+
1454
+ let promise = new Promise ( function ( resolve ) {
1455
+ return FetchRequest . get ( that . getRequestUrl ( url , true ) , null , options ) . then ( function ( response ) {
1456
+ return response . text ( ) ;
1457
+ } ) . then ( async function ( capabilitiesText ) {
1458
+ const format = new WMSCapabilities ( ) ;
1459
+ let capabilities = format . read ( capabilitiesText ) ;
1460
+ if ( capabilities ) {
1461
+ let layers = capabilities . Capability . Layer . Layer , proj = layerInfo . projection ;
1462
+ layerInfo . subLayers = layerInfo . layers [ 0 ] ;
1463
+ layerInfo . version = capabilities . version ;
1464
+ for ( let i = 0 ; i < layers . length ; i ++ ) {
1465
+ // 图层名比对
1466
+ if ( layerInfo . layers [ 0 ] === layers [ i ] . name ) {
1467
+ let layer = layers [ i ] ;
1468
+ if ( layer . bbox [ proj ] ) {
1469
+ let bbox = layer . bbox [ proj ] . bbox ;
1470
+ // wmts 130 坐标轴是否反向,目前还无法判断
1471
+ // 后续还需继续完善WKT 增加坐标轴方向值
1472
+ // 目前wkt信息 来自https://epsg.io/
1473
+ // 提供坐标方向值的网站 如:https://www.epsg-registry.org/export.htm?wkt=urn:ogc:def:crs:EPSG::4490
1474
+ if ( ( layerInfo . version === "1.3.0" && layerInfo . projection === "EPSG:4326" ) || ( layerInfo . version === "1.3.0" && layerInfo . projection === "EPSG:4490" ) ) {
1475
+ layerInfo . extent = [ bbox [ 1 ] , bbox [ 0 ] , bbox [ 3 ] , bbox [ 2 ] ] ;
1476
+ } else {
1477
+ layerInfo . extent = bbox ;
1478
+ }
1479
+ break ;
1480
+ }
1481
+ }
1482
+ }
1483
+ }
1484
+ resolve ( ) ;
1485
+ } ) . catch ( function ( error ) {
1486
+ that . errorCallback && that . errorCallback ( error , 'getWMSFaild' , that . map )
1487
+ resolve ( ) ;
1488
+ } )
1489
+ } ) ;
1490
+ return promise ;
1491
+ }
1435
1492
/**
1436
1493
* @private
1437
1494
* @function ol.supermap.WebMap.prototype.getTileUrl
@@ -1724,6 +1781,12 @@ export class WebMap extends Observable {
1724
1781
that . layerAdded ++ ;
1725
1782
that . sendMapToUser ( len ) ;
1726
1783
} )
1784
+ } else if ( layer . layerType === "WMS" ) {
1785
+ that . getWmsInfo ( layer ) . then ( ( ) => {
1786
+ that . map . addLayer ( that . createBaseLayer ( layer , layerIndex ) ) ;
1787
+ that . layerAdded ++ ;
1788
+ that . sendMapToUser ( len ) ;
1789
+ } )
1727
1790
} else {
1728
1791
layer . projection = that . baseProjection ;
1729
1792
that . map . addLayer ( that . createBaseLayer ( layer , layerIndex ) ) ;
0 commit comments