Class: RailsGoogleMap::Configuration
- Inherits:
-
Object
- Object
- RailsGoogleMap::Configuration
- Defined in:
- lib/rails_google_map/configuration.rb,
sig/rails_google_map.rbs
Overview
Holds the gem-wide defaults. Configure it from an initializer:
RailsGoogleMap.configure do |config|
config.api_key = ENV["GOOGLE_MAPS_EMBED_KEY"]
config.zoom = 16
end
Every setting is optional. Without an api_key the helpers fall back to
Google's keyless embed endpoint, which needs no key and no billing account.
Instance Attribute Summary collapse
-
#api_key ⇒ String?
Maps Embed API key.
-
#height ⇒ String, ...
Default iframe width/height, as passed straight to the iframe attributes.
-
#language ⇒ String?
Language for map labels, e.g.
-
#map_class ⇒ String?
CSS class applied to the iframe itself.
-
#map_type ⇒ String?
Default map type: "roadmap" or "satellite" (Embed API only).
-
#partial ⇒ String
Partial that #render_google_map renders.
-
#width ⇒ String, ...
Default iframe width/height, as passed straight to the iframe attributes.
-
#wrapper_class ⇒ String?
CSS class for the div the partial wraps the map in.
-
#zoom ⇒ Integer?
Default zoom level for the generated map (Embed API only).
Instance Method Summary collapse
-
#api_key? ⇒ Boolean
True when an API key is present, i.e.
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
Constructor Details
#initialize ⇒ Configuration
Returns a new instance of Configuration.
36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/rails_google_map/configuration.rb', line 36 def initialize @api_key = ENV["GOOGLE_MAPS_EMBED_KEY"] || ENV["GOOGLE_MAPS_API_KEY"] @zoom = 15 @map_type = "roadmap" @width = "100%" @height = "450" @language = nil @wrapper_class = "google-map" @map_class = nil @partial = "rails_google_map/map" end |
Instance Attribute Details
#api_key ⇒ String?
Maps Embed API key. Falls back to GOOGLE_MAPS_EMBED_KEY / GOOGLE_MAPS_API_KEY.
18 19 20 |
# File 'lib/rails_google_map/configuration.rb', line 18 def api_key @api_key end |
#height ⇒ String, ...
Default iframe width/height, as passed straight to the iframe attributes.
24 25 26 |
# File 'lib/rails_google_map/configuration.rb', line 24 def height @height end |
#language ⇒ String?
Language for map labels, e.g. "en" or "ne" (Embed API only).
26 27 28 |
# File 'lib/rails_google_map/configuration.rb', line 26 def language @language end |
#map_class ⇒ String?
CSS class applied to the iframe itself. Nil leaves the attribute off.
30 31 32 |
# File 'lib/rails_google_map/configuration.rb', line 30 def map_class @map_class end |
#map_type ⇒ String?
Default map type: "roadmap" or "satellite" (Embed API only).
22 23 24 |
# File 'lib/rails_google_map/configuration.rb', line 22 def map_type @map_type end |
#partial ⇒ String
Partial that #render_google_map renders. Override it in your own app by creating a template at the same path -- app view paths win over the engine's -- or point this at a partial of your own.
34 35 36 |
# File 'lib/rails_google_map/configuration.rb', line 34 def partial @partial end |
#width ⇒ String, ...
Default iframe width/height, as passed straight to the iframe attributes.
24 25 26 |
# File 'lib/rails_google_map/configuration.rb', line 24 def width @width end |
#wrapper_class ⇒ String?
CSS class for the div the partial wraps the map in.
28 29 30 |
# File 'lib/rails_google_map/configuration.rb', line 28 def wrapper_class @wrapper_class end |
#zoom ⇒ Integer?
Default zoom level for the generated map (Embed API only).
20 21 22 |
# File 'lib/rails_google_map/configuration.rb', line 20 def zoom @zoom end |
Instance Method Details
#api_key? ⇒ Boolean
True when an API key is present, i.e. when the Maps Embed API can be used.
49 50 51 |
# File 'lib/rails_google_map/configuration.rb', line 49 def api_key? !api_key.nil? && !api_key.to_s.strip.empty? end |