簡體   English   中英

當它是 null 時,如何從 Mapbox GL JS 工具提示中隱藏文本?

[英]How to hide text from Mapbox GL JS tooltips when it is null?

我在 mapbox GL JS 中創建了一個 map,但是當值為 null 時無法隱藏工具提示內容。 例子。 這是完整的代碼: https://github.com/Ninlin/irystory/blob/main/index.html

我嘗試了以下方法,但 if 語句不起作用並完全刪除了工具提示。 我應該修改什么?

popup
    .setLngLat(e.lngLat)
    .setHTML("<h3>" + name + "</h3>" +
    "<h4 id ='fn'>" + full_name + '</h4>')
    .addTo(map);

if (full_name != null) {
document.getElementById('fn').style.display = 'block';
} else {
document.getElementById('fn').style.display = 'none';
};

有趣的是, full_name實際上是一個字符串,所以這似乎有效:

if (full_name != "null") {
    popup
      .setLngLat(e.lngLat)
      .setHTML("<h3>" + name + "</h3>" +
        '<hr>' +
        "<h4>" + full_name + '</h4>' +
        '<h4>' + birth + '-' + death + '</h4>' +
        '<p>'+occupation+'</p>')
      .addTo(map);
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM