繁体   English   中英

javascript没有将值传递给函数,但函数仍然具有它

[英]javascript not passing value to function, but function still have it

我不明白styleFunction是如何工作的(我从此Openlayers 4 示例中获得了它):

var styleFunction = function(feature) {
    return styles[feature.getGeometry().getType()];
};

var vectorSource = new ol.source.Vector({
    features: reader.readFeatures(listaMappe[i].geoJSON,projector)
});

var vectorLayer = new ol.layer.Vector({
    source: vectorSource,
    style: styleFunction
});

没有参数传递给它(来自vectorLayer),但是值feature具有值(我认为应该为空)。

这个问题来自我需要向styleFunction添加另一个参数,以便可以从listaMappe[i].color传递值。 (我试图将代码仅更改为function(feature, color) ,但我不知道为什么,但是值color不为空,它是一个实数...)

函数传递参数被调用时。

vectorLayer没有调用任何东西。

vactorLayer是一个变量,其中ol.layer.Vector的返回值。

styleFunction传递给ol.layer.Vector (这是您未包含在问题中的代码,并且大概是其他人编写的)。 在该函数内部的某处,其中styleFunction并传递了参数。

暂无
暂无

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

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