简体   繁体   English

javascript openlayers3对象方法

[英]javascript openlayers3 object methods

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. 这可能是我不了解的Javascript。 Please help! 请帮忙! Thanks! 谢谢!

Probably because someText.setText() return type is not what is expected to be input type of someIcon.setText() . 大概是因为someText.setText()的返回类型是不是预计的输入型someIcon.setText()

If you try to do like: someIcon.setText(someText); 如果您尝试这样做: someIcon.setText(someText);

You are passing a object someText and not the output of someText.setText("someOtherString") . 您正在传递对象someText而不是someText.setText("someOtherString")的输出。

That is the reason why someIcon.setText(someText); 这就是someIcon.setText(someText);的原因someIcon.setText(someText); is working but someIcon.setText(someText.setText("someOtherString")) is not working. 正在工作,但是someIcon.setText(someText.setText("someOtherString"))无法工作。

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

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