[英]javascript openlayers3 object methods
我有这段代码:
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);
正在工作,但是someIcon.setText(someText.setText("someOtherString"))
无法工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.