Module: Decidim::MapHelper

Defined in:
app/helpers/decidim/map_helper.rb

Overview

This helper include some methods for rendering resources static and dynamic maps.

Instance Method Summary collapse

Instance Method Details

#dynamic_map_for(markers_data) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'app/helpers/decidim/map_helper.rb', line 26

def dynamic_map_for(markers_data)
  return if Decidim.geocoder.blank?

  map_html_options = {
    class: "google-map",
    id: "map",
    "data-markers-data" => markers_data.to_json,
    "data-here-app-id" => Decidim.geocoder[:here_app_id],
    "data-here-app-code" => Decidim.geocoder[:here_app_code]
  }
  content = capture { yield }.html_safe
   :div, class: "row column" do
    (:div, "", map_html_options) + content
  end
end

Renders a link to openstreetmaps with the resource latitude and longitude. The link’s content is a static map image.

resource - A geolocalizable resource options - An optional hash of options (default: { zoom: 17 })

* zoom: A number to represent the zoom value of the map


12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'app/helpers/decidim/map_helper.rb', line 12

def static_map_link(resource, options = {})
  return unless resource.geocoded?

  zoom = options[:zoom] || 17
  latitude = resource.latitude
  longitude = resource.longitude

  map_url = "https://www.openstreetmap.org/?mlat=#{latitude}&mlon=#{longitude}#map=#{zoom}/#{latitude}/#{longitude}"

  link_to map_url, target: "_blank", rel: "noopener" do
    image_tag decidim.static_map_path(sgid: resource.to_sgid.to_s)
  end
end