gpt4 book ai didi

javascript openlayers3 对象方法

转载 作者:行者123 更新时间:2023-12-03 03:11:00 25 4
gpt4 key购买 nike

我有这段代码:

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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com