Sha256: b8da1ffe0dcd2db9a065c105fb5c262c525be680aeb45911c88cd874e58d565e

Contents?: true

Size: 1.4 KB

Versions: 31

Compression:

Stored size: 1.4 KB

Contents

# frozen_string_literal: true

module Decidim
  # This helper include some methods for rendering resources static and dynamic maps.
  module MapHelper
    # 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
    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" do
        image_tag decidim.static_map_path(sgid: resource.to_sgid.to_s)
      end
    end

    def dynamic_map_for(markers_data)
      return unless Decidim.geocoder.present?

      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 }
      content_tag :div, class: "row column" do
        content_tag(:div, "", map_html_options) + content
      end
    end
  end
end

Version data entries

31 entries across 31 versions & 2 rubygems

Version Path
decidim-core-0.6.8 app/helpers/decidim/map_helper.rb
decidim-0.6.8 decidim-core/app/helpers/decidim/map_helper.rb
decidim-core-0.6.7 app/helpers/decidim/map_helper.rb
decidim-0.6.7 decidim-core/app/helpers/decidim/map_helper.rb
decidim-core-0.6.6 app/helpers/decidim/map_helper.rb
decidim-0.6.6 decidim-core/app/helpers/decidim/map_helper.rb
decidim-core-0.6.5 app/helpers/decidim/map_helper.rb
decidim-0.6.5 decidim-core/app/helpers/decidim/map_helper.rb
decidim-core-0.6.4 app/helpers/decidim/map_helper.rb
decidim-0.6.4 decidim-core/app/helpers/decidim/map_helper.rb
decidim-core-0.6.3 app/helpers/decidim/map_helper.rb
decidim-0.6.3 decidim-core/app/helpers/decidim/map_helper.rb
decidim-core-0.6.2 app/helpers/decidim/map_helper.rb
decidim-0.6.2 decidim-core/app/helpers/decidim/map_helper.rb
decidim-core-0.6.1 app/helpers/decidim/map_helper.rb
decidim-0.6.1 decidim-core/app/helpers/decidim/map_helper.rb
decidim-core-0.6.0 app/helpers/decidim/map_helper.rb
decidim-0.6.0 decidim-core/app/helpers/decidim/map_helper.rb
decidim-core-0.5.1 app/helpers/decidim/map_helper.rb
decidim-0.5.1 decidim-core/app/helpers/decidim/map_helper.rb