如何在openlayers中添加WFS和WMS?
How to add WFS and WMS in openlayers?
我有两个服务 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());
}
层 url 在这里:
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
抱歉回复晚了,但我在我的项目中使用了这段代码和自定义设置,这为我提供了一个有效的输出。
代码如下[请用你的变量更改静态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);
输出如下:[工作正常]
我有两个服务 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());
}
层 url 在这里: 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
抱歉回复晚了,但我在我的项目中使用了这段代码和自定义设置,这为我提供了一个有效的输出。 代码如下[请用你的变量更改静态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);
输出如下:[工作正常]