最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - geoJson properties addupdate - Stack Overflow

programmeradmin0浏览0评论

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
Add a ment  | 

1 Answer 1

Reset to default 7

It'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;
发布评论

评论列表(0)

  1. 暂无评论