diff options
author | hellekin <hellekin@cepheide.org> | 2021-01-22 05:32:15 +0100 |
---|---|---|
committer | hellekin <hellekin@cepheide.org> | 2021-01-22 05:32:15 +0100 |
commit | b54a8458d5029b3494165b7430e21b3ae34ecc0c (patch) | |
tree | 32ea6fc6b8774f672325fec52f0ffc97229a9568 /app/helpers/sections_helper.rb | |
parent | 1c1aead78192982e221179de6688b944e5b01bf6 (diff) | |
download | incommon-map-b54a8458d5029b3494165b7430e21b3ae34ecc0c.tar.gz |
Upgrade Rails and add StimulusJS support
Diffstat (limited to 'app/helpers/sections_helper.rb')
-rw-r--r-- | app/helpers/sections_helper.rb | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/app/helpers/sections_helper.rb b/app/helpers/sections_helper.rb new file mode 100644 index 0000000..8180fee --- /dev/null +++ b/app/helpers/sections_helper.rb @@ -0,0 +1,19 @@ +module SectionsHelper + # Render a section as a GeoJSON FeatureCollection + def geojson_feature_collection(section) + out = [] + class_name = { baseVal: "cat#{section.category_id} sec#{section.id}" } + style = { fill: section.category.color } + + section.resources.each do |marker| + # Add styling + marker = marker.to_geojson + marker['className'] = class_name + marker['style'] = style + + out << marker.to_json + end + + raw("{ \"type\": \"FeatureCollection\", \"features\": [ #{out.join(',')} ] }") + end +end |