是否有可能通过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]...
我想要更新新闻属性,例如用户单击该功能,或者如果新功能不在此功能中,则添加该功能。这可能吗?
答案 0 :(得分:4)
当然可能:GeoJSON是JSON的超集,它在JavaScript中表示为普通对象。要更新此GeoJSON功能的属性(如果它存储为变量feature
),您可以编写
feature.properties.news = 23;