0

如何在开放层 3 中获得要素层?

过去版本的开放图层在每个要素上都有一个图层属性。这使得将特定于图层的样式应用于功能或按图层组织功能变得容易。

开放层 3 缺少此属性。我正在使用ol.map.forEachFeatureAtPixel来获取悬停功能。

    // Loop through all features a given pixel
    var feature = map.forEachFeatureAtPixel(pixel, function(feature, layer) {
        console.log(layer);
        return feature;      // just return the first feature
    });
4

1 回答 1

4

只是想回答我自己的问题,以防其他人遇到这个问题。 OL3论坛对此进行了讨论。

此处的解决方案遵循 OL3 悬停示例并将图层传递给ol.map.forEachFeatureAtPixel函数。此参数不在文档中,因此很难找到,但它会为您提供图层。我不确定这如何与多个图层上的功能交互。

   // Loop through all features at this pixel but just return the top level feature
    var fl = map.forEachFeatureAtPixel(pixel, function(feature, layer) {
        return {'feature':feature, 'layer':layer};
    });

    var feature = fl.feature,   feature
        layer = fl.layer;
于 2014-07-08T17:53:53.050 回答