检查所有(可见)图层的crossorigin-parameter并根据它返回一个变量

时间:2015-06-20 01:14:42

标签: openlayers-3

我在crossOrigin-Property(如果给定)上检查了地图图层后,我试图收到一个变量。

实际上我想设置我的变量printposs = true / false。

只要一个可见图层没有正确的CrossOrigin-Value,变量就应该变为可能= true并且函数/ foreach-loop可以退出,返回值“outside”

这就是我用我糟糕的JS知识得到的东西。但似乎变量始终保持最后处理层的值。

JSff here:http://jsfiddle.net/wa5g90xb/3/(我添加了浏览器控制台日志记录)

map.getLayers().forEach(function (layer, idx, a) {
if (layer instanceof ol.layer.Group) {
    layer.getLayers().forEach(function (sublayer, jdx, b) {
        var origin = sublayer.getSource()['crossOrigin'];
        var visible = sublayer.getVisible();
        var title = sublayer.get('title');

        if (visible === true && origin == 'anonymous') {
        printposs=true;

        } else if (visible == false) {
            printposs = true;

        } else {
            printposs = false;

            //return printposs; can abort here as soon as one visible layer doesnt have Crossorigin
        }

        return printposs;
    });
    console.log('outer return:' + printposs + ' - It seems always the value of the last "processed" layer is returned')
}

});

0 个答案:

没有答案