具有空值和未知属性的 Leaflet Popup

Leaflet Popup with null values and unknown properties

当用户将 CSV 点文件拖放到 Leaflet 地图中时,无法预先查看存在什么样的属性。所以我需要找到一个解决方案,当用户单击地图上的一个点时,只应显示具有值的属性。

我一直在使用下面的示例,它工作正常,但只有当属性如图所示时才有效。如何更改此设置以显示任何具有值的属性但不显示具有空值或空值的属性?

    onEachFeature: function(feature, layer) {
    
    var popupText = '';
    
    popupText += (feature.properties.typeId) ? 'Concept:\u00A0<b>' + feature.properties.typeId: ''
    
    popupText += (feature.properties.branchId) ? '</b><br>BranchID:\u00A0<b>' + feature.properties.blomId: '';
    
    popupText += (feature.properties.name) ? '</b><br>Name:\u00A0<b>' + feature.properties.name: '';

    popupText += (feature.properties.streetName) ? '<br></b>StreetName:\u00A0<b>' + feature.properties.streetName.toUpperCase(): '';
    
    popupText += (feature.properties.streetNumber) ? '\u00A0</b><b>' + feature.properties.streetNumber: '';
    
    popupText += (feature.properties.streetLetter) ? '\u00A0</b><b>' + feature.properties.streetLetter: '';
    
    popupText += (feature.properties.postalCode) ? '</b><br>PostalCode, City:\u00A0<b>' + feature.properties.postalCode: '';
    
    popupText += (feature.properties.city) ? '</b>,\u00A0<b>' + feature.properties.city: '';
            

  layer.bindPopup(popupText, {
    closeButton: true,
    offset: L.point(0, -20)
  });
  layer.on('click', function() {
    layer.openPopup();
  });
},

遍历所有属性:

for(var prop in feature.properties){
   if(feature.properties[prop]){
      popupText += prop + ": "+feature.properties[prop]+"<br>";
   }
}