aboutsummaryrefslogtreecommitdiff
path: root/app/helpers/sections_helper.rb
blob: 8180fee5ceee8d9189ea2ec7570c4a30ae9ffef8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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