Module: Avo::MapStyles

Defined in:
lib/avo/map_styles.rb

Overview

The light/dark style pair every Avo map defaults to.

Mapbox stays the default for anyone who has a token. Without one its mapbox:// URLs render a blank map, which is why a fresh Avo install used to need a Mapbox signup before it could show a map at all — so fall back to OpenFreeMap: no key, no registration, no request cap, commercial use allowed. Attribution rides along in the TileJSON, so the map's own attribution control credits OpenFreeMap/OpenMapTiles/OpenStreetMap with nothing extra to wire up. https://openfreemap.org

Force one either way with config.map_view = {styles: :mapbox} (or :open_free_map), or give it your own {light:, dark:} pair.

Override a single map with mapkick_options: {style: "..."}. That is one style rather than a pair, so Avo leaves that map alone in dark mode.

Class Method Summary collapse

Class Method Details

.defaultObject



37
38
39
# File 'lib/avo/map_styles.rb', line 37

def default
  resolve(Avo.configuration.map_view[:styles]) || (mapbox_token? ? mapbox : open_free_map)
end

.lightObject



41
# File 'lib/avo/map_styles.rb', line 41

def light = default[:light]

.mapboxObject



23
24
25
26
27
28
# File 'lib/avo/map_styles.rb', line 23

def mapbox
  {
    light: "mapbox://styles/mapbox/light-v11",
    dark: "mapbox://styles/mapbox/dark-v11"
  }.freeze
end

.open_free_mapObject



30
31
32
33
34
35
# File 'lib/avo/map_styles.rb', line 30

def open_free_map
  {
    light: "https://tiles.openfreemap.org/styles/positron",
    dark: "https://tiles.openfreemap.org/styles/dark"
  }.freeze
end

.wrapper_data(custom_style: nil) ⇒ Object

Data attributes for the map wrapper. map-dark-mode swaps between the two styles on theme change; without the pair it leaves the map alone, which is what we want when the resource picked its own style.



46
47
48
49
50
# File 'lib/avo/map_styles.rb', line 46

def wrapper_data(custom_style: nil)
  data = {controller: "map-dark-mode"}
  data[:map_dark_mode_styles_value] = default if custom_style.blank?
  data
end