Javascript 在开放层中获取给定特征的层3
如何在开放图层3中获取要素图层 开放图层的每个要素上都有一个图层特性。这使得将特定于图层的样式应用于要素或按图层组织要素变得容易 打开的图层3缺少此属性。我正在使用鼠标悬停获取功能Javascript 在开放层中获取给定特征的层3,javascript,openlayers,openlayers-3,Javascript,Openlayers,Openlayers 3,如何在开放图层3中获取要素图层 开放图层的每个要素上都有一个图层特性。这使得将特定于图层的样式应用于要素或按图层组织要素变得容易 打开的图层3缺少此属性。我正在使用鼠标悬停获取功能 // Loop through all features a given pixel var feature = map.forEachFeatureAtPixel(pixel, function(feature, layer) { console.log(layer);
// 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悬停并将层传递给函数。该参数不在文档中,因此很难找到,但它将为您提供图层。我不确定这是如何与多个图层上的功能交互的
// 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;
我只是想回答我自己的问题,以防其他人有这个问题。 在这个问题上 这里的解决方案是遵循OL3悬停并将层传递给函数。该参数不在文档中,因此很难找到,但它将为您提供图层。我不确定这是如何与多个图层上的功能交互的
// 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;
有帮助。您可以使用options array参数来确定要与哪个功能交互。完整的函数调用是:forEachFeatureAtPixel(pixel,callback,opt_this,opt_layerFilter,opt_this2)非常有用。您可以使用options array参数来确定要与哪个功能交互。完整的函数调用是:forEachFeatureAtPixel(pixel,callback,opt_this,opt_layerFilter,opt_this2)