我下面有两个服务URL,例如WFS和WMS:
我希望这两个服务需要在我的openlayers地图中添加为图层。有可能吗?
使用示例数据更新代码:
myFunction(layerUrl:string, layer: any) {
var bbox = layer.BoundingBox[0].extent;
var crs = layer.BoundingBox[0].crs;
var wmsSource = new ol.source.TileWMS({
url: `${layerUrl}`,
params: {'LAYERS': `${layer.Name}`, 'TILED': true},
serverType: 'geoserver',
projection: `${crs}`,
// Countries have transparency, so do not fade tiles:
transition: 0
});
var wmsLayer = new ol.layer.Tile({
extent: bbox,
source: wmsSource
});
map.addLayer(wmsLayer);
map.getView().fit(wmsLayer.getExtent());
}
此处的层网址: https://wms.geo.admin.ch/
这是图层对象:
Abstract: "Als Kulturgüter von nationaler Bedeutung im Inventar von 2009 gelten rund 3200 Objekte (Einzelbauten / Sammlungen in Museeen, Archiven und Bibliotheken sowie Archäologie)."
Attribution: {Title: "Das Geoportal des Bundes", OnlineResource: "http://www.geo.admin.ch/", LogoURL: {…}}
BoundingBox: [{…}]
CRS: (14) ["epsg:2056", "epsg:21781", "epsg:4326", "epsg:3857", "epsg:3034", "epsg:3035", "epsg:4258", "epsg:31287", "epsg:25832", "epsg:25833", "epsg:31467", "epsg:32632", "epsg:32633", "epsg:900913"]
Dimension: undefined
EX_GeographicBoundingBox: (4) [0.659965, 45.4183, 10.8344, 48.7495]
Layer: (2) [{…}, {…}]
MaxScaleDenominator: undefined
MinScaleDenominator: undefined
Name: "ch.babs.kulturgueter"
Style: [{…}]
Title: "KGS Inventar"
cascaded: undefined
fixedHeight: undefined
fixedWidth: undefined
noSubsets: false
opaque: false
queryable: false
__proto__: Object
答案 0 :(得分:1)
很抱歉,您的回复很晚,但是我在具有自定义设置的项目中使用了此代码,这为我提供了有效的输出。 代码如下[请使用您的变量更改静态ip]
var wmsSource = new ol.source.TileWMS({
url: 'https://wms.geo.admin.ch/',
params: {'LAYERS': 'ch.babs.kulturgueter','TILED': true},
serverType: 'geoserver',
projection: 'EPSG:4326',
transition: 0
});
var wmsLayer = new ol.layer.Tile({
source: wmsSource
});
map.addLayer(wmsLayer);
输出如下:[工作正常]