我正在尝试从 WMS 层返回一组时间值,我必须在 Openlayers 中填充下拉菜单。我已经能够在函数内部的层中获取时间值列表(并将此输出打印到函数中的控制台),但无法从函数中获取此数组。当前代码如下:
var url = **working_WMS_url**
var GetCaps = new ol.format.WMSCapabilities();
fetch(url).then(function(response) {
return response.text();
}).then(function(text) {
var result = GetCaps.read(text);
var times = result.Capability.LayerLayer[0].Dimension;
return times;
});
console.log(times);
// Section below links and populates dropdown menu
var time_list = document.getELementById("time_list");
for(var i = 0; i < times.length; i++) {
var opt = times[i];
var el = document.createElement("option");
el.textContent = opt;
el.value = opt;
time_list.appendChild(el);
}
为了确认,下拉菜单工作正常,我用手动定义的一组时间进行了测试。我只是无法弄清楚为什么没有从函数返回列表“时间”。
为清楚起见,我对 javascript 相对较新,但一般不会编码,因此如果有一个非常简单的解决方案,我深表歉意。我花了最后一个小时查看 StackOverflow 问题,但找不到能准确回答这个问题的问题。