Class: RailsGoogleMap::Configuration

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

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_keyString?

Maps Embed API key. Falls back to GOOGLE_MAPS_EMBED_KEY / GOOGLE_MAPS_API_KEY.

Returns:

  • (String, nil)


18
19
20
# File 'lib/rails_google_map/configuration.rb', line 18

def api_key
  @api_key
end

#heightString, ...

Default iframe width/height, as passed straight to the iframe attributes.

Returns:

  • (String, Integer, nil)


24
25
26
# File 'lib/rails_google_map/configuration.rb', line 24

def height
  @height
end

#languageString?

Language for map labels, e.g. "en" or "ne" (Embed API only).

Returns:

  • (String, nil)


26
27
28
# File 'lib/rails_google_map/configuration.rb', line 26

def language
  @language
end

#map_classString?

CSS class applied to the iframe itself. Nil leaves the attribute off.

Returns:

  • (String, nil)


30
31
32
# File 'lib/rails_google_map/configuration.rb', line 30

def map_class
  @map_class
end

#map_typeString?

Default map type: "roadmap" or "satellite" (Embed API only).

Returns:

  • (String, nil)


22
23
24
# File 'lib/rails_google_map/configuration.rb', line 22

def map_type
  @map_type
end

#partialString

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.

Returns:

  • (String)


34
35
36
# File 'lib/rails_google_map/configuration.rb', line 34

def partial
  @partial
end

#widthString, ...

Default iframe width/height, as passed straight to the iframe attributes.

Returns:

  • (String, Integer, nil)


24
25
26
# File 'lib/rails_google_map/configuration.rb', line 24

def width
  @width
end

#wrapper_classString?

CSS class for the div the partial wraps the map in.

Returns:

  • (String, nil)


28
29
30
# File 'lib/rails_google_map/configuration.rb', line 28

def wrapper_class
  @wrapper_class
end

#zoomInteger?

Default zoom level for the generated map (Embed API only).

Returns:

  • (Integer, nil)


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.

Returns:

  • (Boolean)


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