Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/409.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 为每个特征调用两次样式函数_Javascript_Openlayers 3 - Fatal编程技术网

Javascript 为每个特征调用两次样式函数

Javascript 为每个特征调用两次样式函数,javascript,openlayers-3,Javascript,Openlayers 3,我想知道为什么对于添加到图层中的每个特征,我的样式函数会被调用两次。这是我的代码: var features = new ol.Collection(), layer = new ol.layer.Vector({ source: new ol.source.Vector({features: features}), style: function(feature, resolution){ console.log("called it"); // <--

我想知道为什么对于添加到图层中的每个特征,我的样式函数会被调用两次。这是我的代码:

var features = new ol.Collection(),
layer = new ol.layer.Vector({
    source: new ol.source.Vector({features: features}),
    style: function(feature, resolution){
        console.log("called it"); // <-- called twice for each feature
        return getStyle(feature);  
    }
});
map.addLayer(layer);
var draw = new ol.interaction.Draw({
    features: features,
    type: (geomType)
});         
map.addInteraction(draw);
var features=new ol.Collection(),
图层=新的ol.layer.Vector({
source:newol.source.Vector({features:features}),
样式:功能(特征、分辨率){

控制台。日志(“调用它”);//因为您自己解决了这个问题,而且还没有答案。请考虑锁定或删除这个问题。我提供了一个答案。问题是设置一个功能上的任何属性触发样式函数。然后将您的答案作为一个实际答案,并接受您自己的答案。