【问题标题】:Leaflet filtering existing featuregroup传单过滤现有功能组
【发布时间】:2015-02-09 11:25:35
【问题描述】:

我有一个 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(map);

我还添加了一个组合框,我想通过组合框中选择的值过滤图层的特征。我想将组合框中的选定值与图层中每个特征的“级别”属性结合起来。

到目前为止我已经编码:

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

问候,

【问题讨论】:

    标签: filter filtering leaflet layer


    【解决方案1】:

    在您的change 事件中,您正在创建另一个包含适当过滤器选项的geoJSON 层...但您不会删除之前在第一个代码块中显示的exp_colJSON。在用map.removeLayer(exp_colJSON) 初始化新层之前去掉它。确保在您的 pointToLayer 函数中删除 addTo(map),Leaflet 会为您执行此操作。最好保存您的选项哈希,以便在每次初始化时继续重用。我只是想提一下,因为您没有在 change 事件期间将其包含在初始化中。

    【讨论】:

      猜你喜欢
      • 2020-07-10
      • 2019-09-05
      • 1970-01-01
      • 2018-12-15
      • 2012-03-26
      • 1970-01-01
      • 2016-03-07
      • 2020-10-03
      • 1970-01-01
      相关资源
      最近更新 更多