Openlayers - WMS图层:如何从特定图层获取时间维度

问题描述 投票:0回答:1

我正在尝试加载WMS层。使用当前的ISO-8601时间层显示,但我也希望能够设置不同的日期/时间。

为了使用在特定范围内的日期/时间,我需要通过例如检索时间维度来检索时间维度。此特定图层的GetCapabilities并将检索到的值放入数组中。从那时起,我可以使用updateParams来设置/更新日期/时间。

我怎样才能做到这一点?

E.g:

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具有TAG“”......在这种情况下,对于层“dwd:RX-Produkt”。

在此TAG中,有许多可用的日期/时间显示。这些“日期/时间”我需要放入一个数组中。

我希望你能帮帮我!

编辑:低于更新的代码(thx到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});
    }
});

剩下的问题是:

openlayers wms openlayers-5
1个回答
2
投票

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的codepen:https://codepen.io/loicgasser/pen/BMdLYX

© www.soinside.com 2019 - 2024. All rights reserved.