Reputation: 217
I have two service url like WFS and WMS below:
I want those two services need to add as layer in my openlayers map. Is it possible and how?
Updated code with sample data:
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());
}
Layer url here: https://wms.geo.admin.ch/
Here is layer object:
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
Upvotes: 0
Views: 2523
Reputation: 337
Sorry for late reply, but i use this code in my project with custom settings and this provide me a valid output. Code is as follows [ please change static ip with your variable ]
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);
And the output is as follows: [ working just fine ]
Upvotes: 1