Class: Foliage::Leaf
- Inherits:
-
Object
- Object
- Foliage::Leaf
- Defined in:
- lib/foliage/leaf.rb
Instance Method Summary collapse
- #background(layer, options = {}) ⇒ Object
- #band(name, serie, options = {}) ⇒ Object
- #bubbles(name, serie, options = {}) ⇒ Object
- #categories(name, serie, options = {}) ⇒ Object
- #choropleth(name, serie, options = {}) ⇒ Object
-
#control(name, options = true) ⇒ Object
Add a control.
- #heatmap(name, serie, options = {}) ⇒ Object
-
#initialize(config = {}) ⇒ Leaf
constructor
A new instance of Leaf.
- #layer(name, serie, options = {}) ⇒ Object
- #map_backgrounds ⇒ Object
- #overlay(name, provider_name) ⇒ Object
- #path(name, serie, options = {}) ⇒ Object
- #paths(name, serie, options = {}) ⇒ Object
- #point_group(name, serie, options = {}) ⇒ Object
- #points(name, serie, options = {}) ⇒ Object
-
#serie(name, data) ⇒ Object
Add a serie of geo data.
- #simple(name, serie, options = {}) ⇒ Object
- #to_json ⇒ Object
Constructor Details
#initialize(config = {}) ⇒ Leaf
Returns a new instance of Leaf.
3 4 5 6 7 |
# File 'lib/foliage/leaf.rb', line 3 def initialize(config = {}) @config = config @categories_colors = @config.delete(:categories_colors) @config[:backgrounds] = map_backgrounds end |
Instance Method Details
#background(layer, options = {}) ⇒ Object
51 52 53 54 55 56 57 58 |
# File 'lib/foliage/leaf.rb', line 51 def background(layer, = {}) # allow to add custom background [:name] = layer.name if layer.name? [:url] = layer.url if layer.url? [:by_default] = layer.by_default if layer.by_default? @config[:backgrounds] ||= [] @config[:backgrounds] << end |
#band(name, serie, options = {}) ⇒ Object
93 94 95 |
# File 'lib/foliage/leaf.rb', line 93 def band(name, serie, = {}) layer(name, serie, .merge(type: :band)) end |
#bubbles(name, serie, options = {}) ⇒ Object
85 86 87 |
# File 'lib/foliage/leaf.rb', line 85 def bubbles(name, serie, = {}) layer(name, serie, .merge(type: :bubbles)) end |
#categories(name, serie, options = {}) ⇒ Object
97 98 99 |
# File 'lib/foliage/leaf.rb', line 97 def categories(name, serie, = {}) layer(name, serie, { colors: @categories_colors }.merge(.merge(type: :categories))) end |
#choropleth(name, serie, options = {}) ⇒ Object
81 82 83 |
# File 'lib/foliage/leaf.rb', line 81 def choropleth(name, serie, = {}) layer(name, serie, .merge(type: :choropleth)) end |
#control(name, options = true) ⇒ Object
Add a control
134 135 136 137 |
# File 'lib/foliage/leaf.rb', line 134 def control(name, = true) @config[:controls] ||= {}.with_indifferent_access @config[:controls][name.to_s.camelize(:lower)] = end |
#heatmap(name, serie, options = {}) ⇒ Object
89 90 91 |
# File 'lib/foliage/leaf.rb', line 89 def heatmap(name, serie, = {}) layer(name, serie, .merge(type: :heatmap)) end |
#layer(name, serie, options = {}) ⇒ Object
def layer(name, list = {})
@config[:layers] ||= []
@config[:layers] << {name: name, list: list}
end
70 71 72 73 74 75 |
# File 'lib/foliage/leaf.rb', line 70 def layer(name, serie, = {}) [:label] = name.to_s.humanize unless [:label] name = name.to_s.parameterize.tr('-', '_') unless name.is_a?(Symbol) @config[:layers] ||= [] @config[:layers] << { reference: name.to_s.camelcase(:lower) }.merge(.merge(name: name, serie: serie.to_s.camelcase(:lower))) end |
#map_backgrounds ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/foliage/leaf.rb', line 9 def map_backgrounds [ { name: 'OpenStreetMap Hot', url: 'http://{s}.tile.openstreetmap.fr/hot/{z}/{x}/{y}.png', referenceName: 'open_street_map.hot', attribution: '© <a href=\'http://openstreetmap.org\'>OpenStreetMap</a> contributors, <a href=\'http://creativecommons.org/licenses/by-sa/2.0/\'>CC-BY-SA</a>, Tiles courtesy of <a href=\'http://hot.openstreetmap.org/\' target=\'_blank\'>Humanitarian OpenStreetMap Team</a>', tms: false, byDefault: true }, { name: 'Thunderforest Landscape', url: 'https://{s}.tile.thunderforest.com/landscape/{z}/{x}/{y}.png', referenceName: 'thunderforest.landscape', attribution: 'Maps © <a href=\'http://www.thunderforest.com\'>Thunderforest</a>, Data © <a href=\'http://www.openstreetmap.org/copyright\'>OpenStreetMap contributors</a>', subdomains: 'abc', tms: false, byDefault: false }, { name: 'Stamen Watercolor', url: 'http://{s}.tile.stamen.com/watercolor/{z}/{x}/{y}.jpg', referenceName: 'stamen.watercolor', attribution: 'Map tiles by <a href=\'http://stamen.com\'>Stamen Design</a>, <a href=\'http://creativecommons.org/licenses/by/3.0\'>CC BY 3.0</a> — Map data © <a href=\'http://openstreetmap.org\'>OpenStreetMap</a> contributors, <a href=\'http://creativecommons.org/licenses/by-sa/2.0/\'>CC-BY-SA</a>', subdomains: 'abcd', minZoom: 3, maxZoom: 15, tms: false, byDefault: false }, { name: 'Esri World imagery', url: 'http://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}', referenceName: 'esri.world_imagery', attribution: 'Tiles © Esri — Source: Esri, i-cubed, USDA, USGS, AEX, GeoEye, Getmapping, Aerogrid, IGN, IGP, UPR-EGP, and the GIS User Community', tms: false, byDefault: false } ] end |
#overlay(name, provider_name) ⇒ Object
60 61 62 63 |
# File 'lib/foliage/leaf.rb', line 60 def (name, provider_name) @config[:overlays] ||= [] @config[:overlays] << { name: name, provider_name: provider_name } end |
#path(name, serie, options = {}) ⇒ Object
105 106 107 |
# File 'lib/foliage/leaf.rb', line 105 def path(name, serie, = {}) layer(name, serie, { colors: @categories_colors }.merge(.merge(type: :path))) end |
#paths(name, serie, options = {}) ⇒ Object
101 102 103 |
# File 'lib/foliage/leaf.rb', line 101 def paths(name, serie, = {}) layer(name, serie, { colors: @categories_colors }.merge(.merge(type: :paths))) end |
#point_group(name, serie, options = {}) ⇒ Object
113 114 115 |
# File 'lib/foliage/leaf.rb', line 113 def point_group(name, serie, = {}) layer(name, serie, .merge(type: :point_group)) end |
#points(name, serie, options = {}) ⇒ Object
109 110 111 |
# File 'lib/foliage/leaf.rb', line 109 def points(name, serie, = {}) layer(name, serie, { colors: @categories_colors }.merge(.merge(type: :points))) end |
#serie(name, data) ⇒ Object
Add a serie of geo data
122 123 124 125 126 127 128 129 130 131 |
# File 'lib/foliage/leaf.rb', line 122 def serie(name, data) raise StandardError, 'data must be an array. Got: ' + data.class.name unless data.is_a? Array @config[:series] ||= {}.with_indifferent_access @config[:series][name] = data.compact.collect do |item| next unless item[:shape] item .merge(shape: item[:shape]) .merge(item[:popup] ? { popup: compile_leaf_popup(item[:popup], item) } : {}) end.compact end |
#simple(name, serie, options = {}) ⇒ Object
77 78 79 |
# File 'lib/foliage/leaf.rb', line 77 def simple(name, serie, = {}) layer(name, serie, .merge(type: :simple)) end |
#to_json ⇒ Object
139 140 141 142 143 |
# File 'lib/foliage/leaf.rb', line 139 def to_json @config.deep_transform_keys do |key| key.to_s.camelize(:lower) end.to_json end |