【发布时间】:2016-06-01 08:02:37
【问题描述】:
我的传单地图显示来自 GeoJSON 文件的多边形。该文件有几个属性(attribute_1、attribute_2 等)。但是,有些是用文字填充的,有些是空的。
如何在弹出窗口中只显示用文本填充的属性而不显示空属性?
在每个属性下使用我的代码都会显示,如果它是空的,弹出窗口中会显示“null”:
// Integrate GeoJSON and style polygons
$.getJSON("klimagutachten_2001.geojson",function(klimagutachten){
L.geoJson( klimagutachten, {
style: function(feature){
return {
color: "#e60000",
weight: 4,
fillColor: "#e60000",
fillOpacity: .3
};
},
// Call popup
onEachFeature: function( feature, layer ){
layer.bindPopup("<strong> Attribute 1: \"" + feature.properties.attribute_1 + " and the second attribute is: " + feature.properties.attribute_2)
}
}).addTo(map);
});
【问题讨论】:
-
已经发布了一个类似的问题 (stackoverflow.com/questions/34055382/…),但它没有回答我的问题。
-
你的意思是你试过了还是不行?
-
它应该可以工作,但我不希望属性不按要求显示。我想要弹出窗口中每个不为空的属性。所以这是一个稍微不同的问题。
标签: null popup leaflet geojson