首页 > 解决方案 > 类型错误:mapLayers[i].getSource 不是函数

问题描述

现在我用 ol-layerswitcher (walkermatt) 构建了一个开放层地图。该地图在其他版本中使用 OL 6 和 Firefox。https://www.kweimar.de/TB_MapOS.html(侧边栏(onClick)中的链接仅适用于firefox。)在https://www.kweimar.de/TB_MapOS1.html中是错误Uncaught TypeError : mapLayers[i].getSource 不是函数 因为该函数在其他版本中工作,我认为还有另一个问题。关键是地图只能在我的帐户中使用。这是部分:

var select = new ol.interaction.Select();
map.addInteraction(select);
var selectedFeatures = select.getFeatures();
var infoBox = document.getElementById('sidebar-list');

map.on('moveend', function(e) {
infoBox.innerHTML = "";
var info = [];
var mapLayers = map.getLayers().getArray();
for(var i=1;i<7 ; i++) {
    if (mapLayers[i].getVisible()==true) {
        var Source = mapLayers[i].getSource();
        var extent = map.getView().calculateExtent(map.getSize());
        Source.forEachFeatureIntersectingExtent(extent, function(feature) {
            nam = feature.get('name')
            nummer = feature.get('nummer');
            listed = feature.get('listed');
//          searchString="Llan";
            if(nam !== null && nam.toUpperCase().match(searchString.toUpperCase())){
            info.push([nam,listed,nummer]);
            }
        });         
    }   // ende if
}   // ende for

谢谢

标签: javascript

解决方案


推荐阅读