class Decidim::Map::DynamicMap
A base class for dynamic mapping functionality, common to all dynamic map services.
Public Instance Methods
builder_class()
click to toggle source
Returns the builder class for the map. Allows fetching the class name dynamically also in the utility classes that extend this class.
@return [Class] The class for the builder object.
# File lib/decidim/map/dynamic_map.rb, line 23 def builder_class self.class.const_get(:Builder) end
builder_options()
click to toggle source
Returns the options for the default builder object.
@return [Hash] The default options for the map builder.
# File lib/decidim/map/dynamic_map.rb, line 30 def builder_options { marker_color: organization.colors.fetch("primary", "#ef604d"), tile_layer: tile_layer_configuration } end
create_builder(template, options = {})
click to toggle source
Creates a builder class for the front-end that is used to build the map HTML markup.
@param (see Decidim::Map::DynamicMap::Builder#initialize)
@return [Decidim::Map::DynamicMap::Builder] The builder object that can
be used to build the map's markup.
# File lib/decidim/map/dynamic_map.rb, line 15 def create_builder(template, options = {}) builder_class.new(template, builder_options.merge(options)) end
Protected Instance Methods
tile_layer_configuration()
click to toggle source
Prepares the tile layer configuration hash to be passed for the builder.
@return The tile layer configuration hash.
# File lib/decidim/map/dynamic_map.rb, line 43 def tile_layer_configuration tile_layer = configuration.fetch(:tile_layer, {}) tile_layer_options = tile_layer.except(:url).tap do |config| config.fetch(:api_key, nil) == true && config[:api_key] = configuration.fetch(:api_key, nil) end { url: tile_layer.fetch(:url, nil), options: tile_layer_options } end