2015-02-09 76 views
0

我有一个左侧贴图,我想过滤要显示的功能组。传单过滤现有功能组

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(map);

我还添加了一个组合框,我想通过在组合框中选择的值来过滤图层的功能。我想通过图层中每个要素的“level”属性来组合选定的值。

到目前为止,我还编码:

$(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

里面你change事件,要创建一个使用适当的过滤器选项另一个GeoJSON的层侧...但你是不是删除以前exp_colJSON显示在您的第一个代码块中。在使用map.removeLayer(exp_colJSON)初始化新图层之前删除它。确保在您的pointToLayer函数中删除addTo(map),Leaflet为您做到了这一点。同样最好保存你的选项哈希值,以便在每次初始化时继续重复使用。我想提及的是,因为在change事件期间你没有在初始化过程中包含它。