繁体   English   中英

在打开的图层中获取具有特定功能的图层3

[英]Get the layer given a feature in open layers3

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

以前版本的开放层在每个要素上都具有 layer属性。 这样可以轻松地将特定于图层的样式应用于要素或按图层组织要素。

开放层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
    });

只是想回答我自己的问题,以防其他人遇到这个问题。 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;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM