我有这段代码:
let text = new ol.style.Text({
font: '14px Arial',
text: 'string'
});
let icon = new ol.style.Style({
image: new ol.style.Icon(/** @type {olx.style.IconOptions} */ ({
anchor: [0.5, 46],
anchorXUnits: 'fraction',
anchorYUnits: 'pixels',
src: './img/icon.png'
})),
text: text
});
为什么这有效? :
text.setText("otherString");
icon.setText(text);
feature.setStyle(icon)
// the name of someFeature is changed to someOtherString as supposed to
但这不起作用:
feature.setStyle(icon.setText(text.setText("anotherString")));
//name is not changed.
这可能是我不明白的有关 Javascript 的内容。请帮忙! 谢谢!
最佳答案
可能是因为 someText.setText()
返回类型不是 someIcon.setText()
预期的输入类型。
如果您尝试这样做:someIcon.setText(someText);
您传递的是对象 someText
,而不是 someText.setText("someOtherString")
的输出。
这就是为什么 someIcon.setText(someText);
有效但 someIcon.setText(someText.setText("someOtherString"))
无效的原因。
关于javascript openlayers3 对象方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46953181/