geoJson属性添加/更新

时间:2015-08-13 15:59:31

标签: javascript d3.js leaflet geojson

是否有可能通过d3 / leaflet动态地向功能添加属性。

我有这种GeoJson文件:

        {"type":"Feature","id":"01","properties":
{"name":"Alabama","density":94.65, "news":22},
"geometry":{"type":"Polygon","coordinates":
[[[-87.359296,35.00118],[-85.606675,34.984749],[-85.431413,34.124869]...

我想要更新新闻属性,例如用户单击该功能,或者如果新功能不在此功能中,则添加该功能。这可能吗?

1 个答案:

答案 0 :(得分:4)

当然可能:GeoJSON是JSON的超集,它在JavaScript中表示为普通对象。要更新此GeoJSON功能的属性(如果它存储为变量feature),您可以编写

feature.properties.news = 23;