Class: Decidim::StaticMapGenerator

Inherits:
Object
  • Object
show all
Defined in:
app/services/decidim/static_map_generator.rb

Overview

This class generates a url to create a static map image for a geocoded resource

Instance Method Summary collapse

Constructor Details

#initialize(resource, options = {}) ⇒ StaticMapGenerator

Returns a new instance of StaticMapGenerator.



6
7
8
9
10
11
12
13
# File 'app/services/decidim/static_map_generator.rb', line 6

def initialize(resource, options = {})
  @resource = resource
  @options = options

  @options[:zoom] ||= 15
  @options[:width] ||= 120
  @options[:height] ||= 120
end

Instance Method Details

#dataObject



15
16
17
18
19
20
21
22
23
24
25
# File 'app/services/decidim/static_map_generator.rb', line 15

def data
  return if @resource.blank? || map_utility.nil?

  Rails.cache.fetch(@resource.cache_key) do
    map_utility.image_data(
      latitude: @resource.latitude,
      longitude: @resource.longitude,
      options: @options
    )
  end
end