aboutsummaryrefslogtreecommitdiff
path: root/app/helpers/leaflet_helper.rb
diff options
context:
space:
mode:
authorhellekin <hellekin@cepheide.org>2021-01-22 10:35:07 +0100
committerhellekin <hellekin@cepheide.org>2021-01-22 10:35:07 +0100
commit97bfc3f6012027077077ea4a6b5f2f709c76158e (patch)
tree51df0783d3c8ce8b2e928c73d28a77fffb417dbb /app/helpers/leaflet_helper.rb
parentbf087e092cc60defb307f4625333c97327283cc3 (diff)
downloadincommon-map-97bfc3f6012027077077ea4a6b5f2f709c76158e.tar.gz
Add markers and popups
- Replace MakiMarkers with ExtraMarkers and ForkAwesome - Add HTML popup binding
Diffstat (limited to 'app/helpers/leaflet_helper.rb')
-rw-r--r--app/helpers/leaflet_helper.rb19
1 files changed, 15 insertions, 4 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