Sha256: 8f08b448e30ae61cfc003d75e8d063b19a12933a5b335c22f5aa9cb1c2aa38ec

Contents?: true

Size: 1.39 KB

Versions: 30

Compression:

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

Version data entries

30 entries across 30 versions & 1 rubygems

Version Path
decidim-core-0.14.4 app/helpers/decidim/map_helper.rb
decidim-core-0.14.3 app/helpers/decidim/map_helper.rb
decidim-core-0.14.2 app/helpers/decidim/map_helper.rb
decidim-core-0.14.1 app/helpers/decidim/map_helper.rb
decidim-core-0.13.1 app/helpers/decidim/map_helper.rb
decidim-core-0.12.2 app/helpers/decidim/map_helper.rb
decidim-core-0.13.0 app/helpers/decidim/map_helper.rb
decidim-core-0.12.1 app/helpers/decidim/map_helper.rb
decidim-core-0.13.0.pre1 app/helpers/decidim/map_helper.rb
decidim-core-0.12.0 app/helpers/decidim/map_helper.rb
decidim-core-0.11.2 app/helpers/decidim/map_helper.rb
decidim-core-0.12.0.pre app/helpers/decidim/map_helper.rb
decidim-core-0.11.1 app/helpers/decidim/map_helper.rb
decidim-core-0.11.0.pre1 app/helpers/decidim/map_helper.rb
decidim-core-0.10.1 app/helpers/decidim/map_helper.rb
decidim-core-0.10.0 app/helpers/decidim/map_helper.rb
decidim-core-0.9.3 app/helpers/decidim/map_helper.rb
decidim-core-0.9.2 app/helpers/decidim/map_helper.rb
decidim-core-0.9.1 app/helpers/decidim/map_helper.rb
decidim-core-0.9.0 app/helpers/decidim/map_helper.rb