I have this piece of code :
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
});
why is this working ? :
text.setText("otherString");
icon.setText(text);
feature.setStyle(icon)
// the name of someFeature is changed to someOtherString as supposed to
but this is not working :
feature.setStyle(icon.setText(text.setText("anotherString")));
//name is not changed.
This is probably something about Javascript that I don't understand. Please help! Thanks!
Probably because someText.setText()
return type is not what is expected to be input type of someIcon.setText()
.
If you try to do like: someIcon.setText(someText);
You are passing a object someText
and not the output of someText.setText("someOtherString")
.
That is the reason why someIcon.setText(someText);
is working but someIcon.setText(someText.setText("someOtherString"))
is not working.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.