Leaflet.js:是否有可能通过属性过滤geoJSON功能? [英] Leaflet.js: is it possible to filter geoJSON features by property?
本文介绍了Leaflet.js:是否有可能通过属性过滤geoJSON功能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
例如,如果我有功能1,2和; 3具有这些属性
- small |红色|很好
- large |绿色|酸
- 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
- small | red | sweet
- large | green | sour
- 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屋!
查看全文