Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在openlayers中添加WFS和WMS?_Openlayers - Fatal编程技术网

如何在openlayers中添加WFS和WMS?

如何在openlayers中添加WFS和WMS?,openlayers,Openlayers,我有两个服务url,如WFS和WMS,如下所示: 我希望这两个服务需要添加为我的openlayers地图中的图层。有可能吗?怎么可能 使用示例数据更新代码: 此处的图层url: 下面是图层对象: Abstract: "Als Kulturgüter von nationaler Bedeutung im Inventar von 2009 gelten rund 3200 Objekte (Einzelbauten / Sammlungen in Museeen, Archiven und B

我有两个服务url,如WFS和WMS,如下所示:

我希望这两个服务需要添加为我的openlayers地图中的图层。有可能吗?怎么可能

使用示例数据更新代码:

此处的图层url:

下面是图层对象:

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);
输出如下:[工作正常]


查看WMS FOR WFS的示例如果发现任何问题,请尝试使用该示例向我们展示您所做的工作,我们将提供帮助you@Atanu在您给定的wms示例中,区段是硬代码,如何使用动态区段?请参见此示例Hi@Atanu,感谢您的快速回复。从这个服务url中,我得到了层的列表,现在我想显示列表中的一些层,而不是全部。假设有一个层,您能提供一些示例代码,我可以通过这些代码将特定层添加到openlayers映射中吗?嗨@Atanu,我也可以将您的代码用于wfs服务吗?我认为wms和wfs是一样的,对吧?@user10496245 wfs基本上是矢量层源,而不是wms标题,看到这个例子,他们使用了url,因为这个例子让我很困惑:+'version=1.1.0&request=GetFeature&typename=osm:water\u arears&'+'outputFormat=application/json&srsname=EPSG:3857&'+'bbox='+extent.join','+',EPSG:3857'我见过一些wfs示例url,比如:在最后一个示例url中,他们没有使用bbox或投影,所以在这种情况下,他们的代码将无法工作,我想,你能在这个问题上帮助我吗?
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);