aboutsummaryrefslogtreecommitdiff
path: root/app/helpers
diff options
context:
space:
mode:
Diffstat (limited to 'app/helpers')
-rw-r--r--app/helpers/leaflet_helper.rb19
-rw-r--r--app/helpers/sections_helper.rb15
2 files changed, 17 insertions, 17 deletions
diff --git a/app/helpers/leaflet_helper.rb b/app/helpers/leaflet_helper.rb
index 6ca03f3..67820d3 100644
--- a/app/helpers/leaflet_helper.rb
+++ b/app/helpers/leaflet_helper.rb
@@ -1,11 +1,22 @@
module LeafletHelper
- def marker_for(resource, options = {})
- coords = [resource.latitude, resource.longitude]
+ def json_marker_for(resource, section)
+ # Style according to requested section
+ marker = resource.to_geojson
+ marker['style'] = {
+ classes: "cat#{section.category_id} sec#{section.id}",
+ color: section.category.color
+ }
+ marker['icon'] = {
+ name: 'fa-neuter' || section.icon_name || 'fa-circle',
+ shape: 'penta' # TODO: change shape according to marker state
+ }
+ # Render HTML popup
+ marker['popup'] = popup_for(resource)
- "L.marker(#{coords}, #{options}).bindPopup(%s)" % popup_for(resource)
+ marker.to_json
end
def popup_for(resource)
- render partial: 'resource/popup', locals: { resource: resource }
+ render partial: 'resources/popup', locals: { resource: resource }, formats: [:html]
end
end
diff --git a/app/helpers/sections_helper.rb b/app/helpers/sections_helper.rb
index 8180fee..20f602b 100644
--- a/app/helpers/sections_helper.rb
+++ b/app/helpers/sections_helper.rb
@@ -1,19 +1,8 @@
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 }
+ features = section.resources.map { |res| json_marker_for(res, section) }.join(',')
- 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(',')} ] }")
+ raw("{ \"type\": \"FeatureCollection\", \"features\": [ #{features} ] }")
end
end