Is it somehow possible to dynamically add properties to features through d3 / leaflet.
I have this kind of GeoJson file:
{"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]...
And I would like to either update the news property when e.g. the user clicks on the feature or if news is not in this feature then add it. Is that possible?
Is it somehow possible to dynamically add properties to features through d3 / leaflet.
I have this kind of GeoJson file:
{"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]...
And I would like to either update the news property when e.g. the user clicks on the feature or if news is not in this feature then add it. Is that possible?
Share Improve this question asked Aug 13, 2015 at 15:59 EychEych 3231 gold badge5 silver badges14 bronze badges 1- Hi, I am more familiar with OpenLayers than Leaflet, but i gess your geojson is interpreted as features objects with attributes. Those object attributes can be edited, but you won't edit the geojsonfile itself. – jcs Commented Aug 13, 2015 at 16:04
1 Answer
Reset to default 7It's certainly possible: GeoJSON is a superset of JSON, which is represented in JavaScript as a normal object. To update a property of this GeoJSON feature if it was stored as the variable feature
, you would write
feature.properties.news = 23;