Openlayers - WMS层:如何从特定层获取时间维度
Openlayers - WMS layer: how to get the time dimension from a specific layer
我正在尝试加载 WMS 层。使用当前的 ISO-8601 图层显示时间,但我也希望能够设置不同的 Date/Times.
为了使用一定范围内的Date/Times,我需要通过例如检索时间维度这个特定层的 GetCapabilities 并将检索到的值放在一个数组中。从那时起,我可以使用 updateParams 来 set/update Date/Time.
我该怎么做?
例如:
var WMS_DWD = new ol.layer.Image({
name: 'Radar D',
title: "Radar D",
source: new ol.source.ImageWMS({
ratio: 1,
url: 'https://maps.dwd.de/geoserver/ows?service=wms&version=1.3.0&request=GetCapabilities',
params: {
'FORMAT': "image/png",
'VERSION': '1.1.1',
'LAYERS': 'dwd:RX-Produkt',
time : '2019-02-03T15:35:00.000Z',
"exceptions": 'application/vnd.ogc.se_inimage'
}
})
});
当我在浏览器中查看 url 时,生成的 XML 有一个标签“”.....在本例中为图层 "dwd:RX-Produkt"。
在此 TAG 中,显示了一些可用的 Date/Times。这些"Date/Times"我需要放到一个数组中
希望你能帮帮我!
编辑:在更新代码下方(感谢 oicgasser)
WMSlyr = new ol.layer.Tile({
name: 'myLYR',
title: "myLYR",
preload: Infinity,
source: new ol.source.TileWMS({
url: 'https://ogcie.iblsoft.com/observations',
params: {
'FORMAT': "image/png",
'VERSION': '1.3.0'
}
}),
urlCapabilities: 'https://ogcie.iblsoft.com/observations?REQUEST=GetCapabilities&SERVICE=WMS&VERSION=1.3.0'
});
LYR = 'metar';
url = 'https://ogcie.iblsoft.com/observations?REQUEST=GetCapabilities&SERVICE=WMS&VERSION=1.3.0';
window['timeArray'] = [];
var parser = new ol.format.WMSCapabilities();
Time = '2019-02-15T17:00:00.000Z';
fetch(url).then(function (response) {
return response.text();
}).then(function (text) {
var capabilities = parser.read(text);
var currentProj = map.getView().getProjection().getCode();
var crs;
// the parser can only read the list of projections from the WMS 1.3.0 responses.
// For previous version the current projection wil be used as the default one.
// If the WMS (< 1.3.0) does not support the default projection the layer will not load.
if (capabilities.version === '1.3.0'){
crs = capabilities.Capability.Layer.CRS; // supported EPSG-numbers
}
else {
crs = [currentProj];
}
console.log('Projection WMS: ' + crs);
var layers = capabilities.Capability.Layer.Layer;
var AllLayerNames = [];
if (layers.length > 0 && crs.indexOf(currentProj) > -1){
for (var i = 0; i < layers.length; i += 1){
if ( _.isArray(layers[i]['Dimension']) && layers[i]['Dimension'].length > 0 ){
console.log(layers[i].Name);
AllLayerNames.push(layers[i].Name);
console.log(layers[i]['Dimension'][0]['values']);
}
}
}
var LYRnr = (_.invert(AllLayerNames))[LYR];
window['timeArray'] = layers[LYRnr]['Dimension'][0]['values'].split(',');
var formats = capabilities.Capability.Request.GetMap.Format;
var allformats = [];
for (var i = 0; i < formats.length; i += 1){
allformats.push(formats[i]);
}
console.log(allformats); // array with all the supported output-formats
if (window['timeArray'].indexOf(Time.substr(0,16))) { // use part of string because some WMS dimensions use milliseconds and some do not
WMSlyr.getSource().updateParams({'LAYERS': LYR, 'TIME': Time});
}
});
剩下的问题是:
- 某些 WMS 功能-XML(例如“https://maps.dwd.de/geoserver/wms?version=1.3.0&request=GetCapabilities”)显示比 'normal' 更深的图层。代码显示错误,因为未找到层 LYR 的维度............当我有该层的名称或更好时如何搜索这些层......我如何概括上面的代码可以实现吗?
Openlayers 中有一个 WMS GetCapabilities 解析器。
以下是有关如何使用 ol 4.6.5 实现该功能的代码示例:
var parser = new ol.format.WMSCapabilities();
fetch("https://maps.dwd.de/geoserver/ows?service=wms&version=1.3.0&request=GetCapabilities")
.then(function(response) {
return response.text();
})
.then(function(text) {
var result = parser.read(text);
var layers = result.Capability.Layer.Layer;
console.log(layers);
})
});
然后需要在数组中寻找你感兴趣的图层,分析Dimension
字段。确保递归查看所有子层,因为它们大部分是嵌套的。
这是您的 WMS GetCapabilities 的代码笔:
https://codepen.io/loicgasser/pen/BMdLYX
我正在尝试加载 WMS 层。使用当前的 ISO-8601 图层显示时间,但我也希望能够设置不同的 Date/Times.
为了使用一定范围内的Date/Times,我需要通过例如检索时间维度这个特定层的 GetCapabilities 并将检索到的值放在一个数组中。从那时起,我可以使用 updateParams 来 set/update Date/Time.
我该怎么做?
例如:
var WMS_DWD = new ol.layer.Image({
name: 'Radar D',
title: "Radar D",
source: new ol.source.ImageWMS({
ratio: 1,
url: 'https://maps.dwd.de/geoserver/ows?service=wms&version=1.3.0&request=GetCapabilities',
params: {
'FORMAT': "image/png",
'VERSION': '1.1.1',
'LAYERS': 'dwd:RX-Produkt',
time : '2019-02-03T15:35:00.000Z',
"exceptions": 'application/vnd.ogc.se_inimage'
}
})
});
当我在浏览器中查看 url 时,生成的 XML 有一个标签“”.....在本例中为图层 "dwd:RX-Produkt"。
在此 TAG 中,显示了一些可用的 Date/Times。这些"Date/Times"我需要放到一个数组中
希望你能帮帮我!
编辑:在更新代码下方(感谢 oicgasser)
WMSlyr = new ol.layer.Tile({
name: 'myLYR',
title: "myLYR",
preload: Infinity,
source: new ol.source.TileWMS({
url: 'https://ogcie.iblsoft.com/observations',
params: {
'FORMAT': "image/png",
'VERSION': '1.3.0'
}
}),
urlCapabilities: 'https://ogcie.iblsoft.com/observations?REQUEST=GetCapabilities&SERVICE=WMS&VERSION=1.3.0'
});
LYR = 'metar';
url = 'https://ogcie.iblsoft.com/observations?REQUEST=GetCapabilities&SERVICE=WMS&VERSION=1.3.0';
window['timeArray'] = [];
var parser = new ol.format.WMSCapabilities();
Time = '2019-02-15T17:00:00.000Z';
fetch(url).then(function (response) {
return response.text();
}).then(function (text) {
var capabilities = parser.read(text);
var currentProj = map.getView().getProjection().getCode();
var crs;
// the parser can only read the list of projections from the WMS 1.3.0 responses.
// For previous version the current projection wil be used as the default one.
// If the WMS (< 1.3.0) does not support the default projection the layer will not load.
if (capabilities.version === '1.3.0'){
crs = capabilities.Capability.Layer.CRS; // supported EPSG-numbers
}
else {
crs = [currentProj];
}
console.log('Projection WMS: ' + crs);
var layers = capabilities.Capability.Layer.Layer;
var AllLayerNames = [];
if (layers.length > 0 && crs.indexOf(currentProj) > -1){
for (var i = 0; i < layers.length; i += 1){
if ( _.isArray(layers[i]['Dimension']) && layers[i]['Dimension'].length > 0 ){
console.log(layers[i].Name);
AllLayerNames.push(layers[i].Name);
console.log(layers[i]['Dimension'][0]['values']);
}
}
}
var LYRnr = (_.invert(AllLayerNames))[LYR];
window['timeArray'] = layers[LYRnr]['Dimension'][0]['values'].split(',');
var formats = capabilities.Capability.Request.GetMap.Format;
var allformats = [];
for (var i = 0; i < formats.length; i += 1){
allformats.push(formats[i]);
}
console.log(allformats); // array with all the supported output-formats
if (window['timeArray'].indexOf(Time.substr(0,16))) { // use part of string because some WMS dimensions use milliseconds and some do not
WMSlyr.getSource().updateParams({'LAYERS': LYR, 'TIME': Time});
}
});
剩下的问题是:
- 某些 WMS 功能-XML(例如“https://maps.dwd.de/geoserver/wms?version=1.3.0&request=GetCapabilities”)显示比 'normal' 更深的图层。代码显示错误,因为未找到层 LYR 的维度............当我有该层的名称或更好时如何搜索这些层......我如何概括上面的代码可以实现吗?
Openlayers 中有一个 WMS GetCapabilities 解析器。
以下是有关如何使用 ol 4.6.5 实现该功能的代码示例:
var parser = new ol.format.WMSCapabilities();
fetch("https://maps.dwd.de/geoserver/ows?service=wms&version=1.3.0&request=GetCapabilities")
.then(function(response) {
return response.text();
})
.then(function(text) {
var result = parser.read(text);
var layers = result.Capability.Layer.Layer;
console.log(layers);
})
});
然后需要在数组中寻找你感兴趣的图层,分析Dimension
字段。确保递归查看所有子层,因为它们大部分是嵌套的。
这是您的 WMS GetCapabilities 的代码笔: https://codepen.io/loicgasser/pen/BMdLYX