Skip to content

Commit f90d09f

Browse files
committed
【update】1) 解决webMap中wms1.1.1出图错乱问题
(reviewed by yuzy)
1 parent d29a711 commit f90d09f

File tree

1 file changed

+64
-1
lines changed

1 file changed

+64
-1
lines changed

src/openlayers/mapping/WebMap.js

Lines changed: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import * as olProj4 from 'ol/proj/proj4';
3434
import Units from 'ol/proj/Units';
3535
import * as olLayer from 'ol/layer';
3636
import WMTSCapabilities from 'ol/format/WMTSCapabilities';
37+
import WMSCapabilities from 'ol/format/WMSCapabilities';
3738
import TileGrid from 'ol/tilegrid/TileGrid';
3839
import WMTSTileGrid from 'ol/tilegrid/WMTS';
3940
import * as olGeometry from 'ol/geom';
@@ -638,6 +639,8 @@ export class WebMap extends Observable {
638639
await this.getWmtsInfo(baseLayer);
639640
} else if (layerType === 'TILE') {
640641
await this.getTileInfo(baseLayer);
642+
} else if(layerType === 'WMS') {
643+
await this.getWmsInfo(baseLayer);
641644
}
642645
baseLayer.projection = mapInfo.projection;
643646
if (!baseLayer.extent) {
@@ -1186,7 +1189,8 @@ export class WebMap extends Observable {
11861189
wrapX: false,
11871190
params: {
11881191
LAYERS: layerInfo.layers ? layerInfo.layers[0] : "0",
1189-
FORMAT: 'image/png'
1192+
FORMAT: 'image/png',
1193+
VERSION: layerInfo.version || "1.3.0"
11901194
},
11911195
projection: layerInfo.projection || that.baseProjection,
11921196
tileLoadFunction: function (imageTile, src) {
@@ -1432,6 +1436,59 @@ export class WebMap extends Observable {
14321436
that.errorCallback && that.errorCallback(error, 'getWmtsFaild', that.map)
14331437
});
14341438
}
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+
}
14351492
/**
14361493
* @private
14371494
* @function ol.supermap.WebMap.prototype.getTileUrl
@@ -1724,6 +1781,12 @@ export class WebMap extends Observable {
17241781
that.layerAdded++;
17251782
that.sendMapToUser(len);
17261783
})
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+
})
17271790
} else {
17281791
layer.projection = that.baseProjection;
17291792
that.map.addLayer(that.createBaseLayer(layer, layerIndex));

0 commit comments

Comments
 (0)