无法过滤掉.bindPopup

时间:2018-02-25 19:18:30

标签: filter geojson

我在使用示例数据过滤geoJson图层时遇到了很多麻烦。这是一张传单图,显示了土壤经过铅测试的位置。

有些地点最多被抽样五次而其他地方只有一次。我想只显示一个值,如果存在的话。 GeoJson将这些样品分离为Lead_A至Lead_B。某些位置的Lead_#为空白值,其他位置只有Lead_A。例如:



{
   "type": "Feature",
   "geometry": {
      "type": "Point",
      "coordinates":  [ -75.214921,39.997753 ]
   },
   "properties": {
   "Date":"7/19/2016",
   "Location":"Educare Learning Center ",
   "Address":"",
   "Lead_A":43,
   "Lead_B":73,
   "Lead_C":"18",
   "Lead_D":"866",
   "Lead_E":"88"
   }

// or 

{
   "type": "FeatureCollection",
   "features": [
  {
    "type": "Feature",
    "geometry": {
       "type": "Point",
       "coordinates":  [ -76.311359,40.04514 ]
    },
    "properties": {
    "Date":"6/29/17",
    "Location":"Northwest Corridor Linear Park",
    "Address":"W Lemon St, Lancaster, PA 17603 ",
    "Lead_A":39
    }




这会导致popUp显示未定义的没有值的位置。我想理想地过滤掉undefined,null和0.但我首先尝试未定义。

PopUp with undefined tags

任何帮助表示赞赏!谢谢。这是代码:



function popUp(feature) {
  if(typeof feature.properties.Lead_B != undefined ||
    typeof feature.properties.Lead_C != undefined ||
    typeof feature.properties.Lead_D != undefined ||
    typeof feature.properties.Lead_E != undefined ||
  ) return true;

};

console.log(popUp);

L.geoJson(leadSample, {
  filter: popUp,
  pointToLayer: function(feature, latlng) {
               var pennLogo = new L.Icon({
                     iconUrl: 'images/pennLogo.png', //source, online search
                     iconSize: [25, 25],
                     iconAnchor: [12, 25],
                     popupAnchor: [0, -25]
               });
               return L.marker(latlng, {
                 icon: pennLogo,
                 tags: [undefined, null, 0]
               });
           }

}).bindPopup(function (layer) {

    return ( "Sample Date:" + " " + layer.feature.properties.Date +
     "<dd>" + "<em>" + "Parts Per Million" + "</em>" + "</dd>" +
    ("<dd>" + "Sample A:" + " " + layer.feature.properties.Lead_A + "</dd>") +
   ("<dd>" + "Sample B:" + " " + layer.feature.properties.Lead_B + "</dd>")+
  ("<dd>" + "Sample C:" + " " + layer.feature.properties.Lead_C + "</dd>")+
 ("<dd>" + "Sample D:" + " " + layer.feature.properties.Lead_D + "</dd>")+
("<dd>" + "Sample E:" + " " + layer.feature.properties.Lead_E + "</dd>")
   );
 }).addTo(map);
&#13;
&#13;
&#13;

0 个答案:

没有答案