单张过滤现有要素组

时间:2015-02-09 11:25:35

标签: filter filtering leaflet layer

我有一个leftleat地图,我想过滤我正在显示的功能组。

exp_colJSON = new L.geoJson(exp_col,{
onEachFeature: pop_col,
pointToLayer: function (feature, latlng) {  
    return L.circleMarker(latlng, {
        radius: feature.properties.radius_qgis2leaf,
        fillColor: feature.properties.color_qgis2leaf,
        color: feature.properties.borderColor_qgis2leaf,
        weight: 1,
        opacity: feature.properties.transp_qgis2leaf,
        fillOpacity: feature.properties.transp_qgis2leaf    }).addTo(map).bindLabel(Autolinker.link(String(feature.properties['name'])), { noHide: true });
    }
});

feature_group.addLayer(exp_colJSON);
exp_colJSON.addTo(地图);

我还添加了一个组合框,我想通过组合框中选择的值来过滤图层的特征。我想在组合框中选择具有图层中每个要素的“级别”属性的值。

到目前为止我已编码:

$(document).ready(function(){ // ran when the document is fully loaded
  // retrieve the jQuery wrapped dom object identified by the selector 
  var exp_getxocolcolegiosJSON = {};
  var sel = $('#niveles');
  // assign a change listener to it
  sel.change(function(){ //inside the listener
    // retrieve the value of the object firing the event (referenced by this)
    var value = $(this).val();

    //do whatever needed here to filter the layer

    L.geoJson(exp_col, {
    filter: function(feature, layer) {
         return(feature.properties.nivelmodelo.match(/.*value.*\/)) 
     }
    }).addTo(map);

    // I know this has no sense but i don't know how to code it

  }); // close the change listener
}); // close the ready listener 

此致

1 个答案:

答案 0 :(得分:1)

change事件中,您正在创建另一个包含正确过滤器选项的geoJSON图层...但您没有删除第一个代码块中显示的先前exp_colJSON。在使用map.removeLayer(exp_colJSON)初始化新图层之前删除它。请务必删除addTo(map)功能中的pointToLayer,Leaflet会为您执行此操作。最好保存你的选项哈希,以便在每次初始化时继续重用。我想我会提到,因为在change事件期间你没有将它包含在你的初始化中。

相关问题