Leaflet.js:是否有可能通过属性过滤geoJSON功能? [英] Leaflet.js: is it possible to filter geoJSON features by property?

查看:920
本文介绍了Leaflet.js:是否有可能通过属性过滤geoJSON功能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我环顾四周,看到很多关于如何显示/隐藏图层的信息。这很酷,但是因为我可以添加任意的属性geoJSON功能,我希望能够相应地过滤它们。

例如,如果我有功能1,2和; 3具有这些属性


  1. small |红色|很好

  2. large |绿色|酸

  3. small |红色| hot

如何按大小筛选它们?或按颜色或味道? 是的,你可以,只需添加一个过滤器功能,如:

  L.geoJson(someFeatures,{
filter:function(feature,layer){
return feature .properties.show_on_map;
}
})。addTo(map);

或者如果你想动态更新,在这个其他SO问题中有一个很好的答案:
传单:更新GeoJson过滤器?


I'm looking around and I see a lot of information about how to show/hide layers. That's cool, but since I can add arbitrary properties to geoJSON features I kind of expect to be able to filter them accordingly.

For instance if I have features 1, 2 & 3 with these properties

  1. small | red | sweet
  2. large | green | sour
  3. small | red | hot

How would I filter them by size? Or by color or flavor?

解决方案

http://leafletjs.com/examples/geojson.html

Yes you can, just add a filter function like:

L.geoJson(someFeatures, {
    filter: function(feature, layer) {
        return feature.properties.show_on_map;
    }
}).addTo(map);

Or if you want dynamic updating, there's a great answer in this other SO question: Leaflet: Update GeoJson filter?

这篇关于Leaflet.js:是否有可能通过属性过滤geoJSON功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆