[英]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.