根据geojson数据要素的属性名称过滤数据


var geonjson = [{
        "type": "Feature",
        "geometry": {
            "type": "LineString",
            "coordinates":[[-106.67999, 35.14097],
                [-106.68892, 35.12974],
                [-106.69064, 35.1098]]
        },
        "properties": {
            "name": "LineString",
            "title": "A line along the Rio Grande"
        }
    },{
        "type": "Feature",
        "geometry": {
            "type": "Polygon",
            "coordinates":[[[-106.78059, 35.14574],
                [-106.7799, 35.10559],
                [-106.71467, 35.13704],
                [-106.69716, 35.17942],
                [-106.78059, 35.14574]]]
        },
        "properties": {
            "name": "Polygon",
            "title": "Balloon Fiesta Park"
        }
    }];
   
    L.geoJson(geonjson,{
        filter:function(feature,latlng){
            switch (feature.properties.name) {
                case 'Polygon': return true; 
                case 'LineString': return false;
            }
        }
    }).addTo(map)
    //地图上只会加载polygon

你可能感兴趣的:(Leaflet.js,javascript)