Class: Mapstatic::Map
- Inherits:
-
Object
- Object
- Mapstatic::Map
- Defined in:
- lib/mapstatic/map.rb
Constant Summary collapse
- TILE_SIZE =
256
Instance Attribute Summary collapse
-
#height ⇒ Object
readonly
Returns the value of attribute height.
-
#lat ⇒ Object
readonly
Returns the value of attribute lat.
-
#lng ⇒ Object
readonly
Returns the value of attribute lng.
-
#tile_source ⇒ Object
Returns the value of attribute tile_source.
-
#width ⇒ Object
readonly
Returns the value of attribute width.
-
#zoom ⇒ Object
readonly
Returns the value of attribute zoom.
Instance Method Summary collapse
-
#initialize(params = {}) ⇒ Map
constructor
A new instance of Map.
- #metadata ⇒ Object
- #render_map(filename) ⇒ Object
- #to_image ⇒ Object
Constructor Details
#initialize(params = {}) ⇒ Map
Returns a new instance of Map.
11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/mapstatic/map.rb', line 11 def initialize(params={}) if params[:bbox] @bounding_box = params[:bbox].split(',').map(&:to_f) else @lat = params.fetch(:lat).to_f @lng = params.fetch(:lng).to_f @width = params.fetch(:width).to_f @height = params.fetch(:height).to_f end @zoom = params.fetch(:zoom).to_i @tile_source = TileSource.new(params[:provider]) end |
Instance Attribute Details
#height ⇒ Object (readonly)
Returns the value of attribute height.
8 9 10 |
# File 'lib/mapstatic/map.rb', line 8 def height @height end |
#lat ⇒ Object (readonly)
Returns the value of attribute lat.
8 9 10 |
# File 'lib/mapstatic/map.rb', line 8 def lat @lat end |
#lng ⇒ Object (readonly)
Returns the value of attribute lng.
8 9 10 |
# File 'lib/mapstatic/map.rb', line 8 def lng @lng end |
#tile_source ⇒ Object
Returns the value of attribute tile_source.
9 10 11 |
# File 'lib/mapstatic/map.rb', line 9 def tile_source @tile_source end |
#width ⇒ Object (readonly)
Returns the value of attribute width.
8 9 10 |
# File 'lib/mapstatic/map.rb', line 8 def width @width end |
#zoom ⇒ Object (readonly)
Returns the value of attribute zoom.
8 9 10 |
# File 'lib/mapstatic/map.rb', line 8 def zoom @zoom end |
Instance Method Details
#metadata ⇒ Object
49 50 51 52 53 54 55 56 57 |
# File 'lib/mapstatic/map.rb', line 49 def { :bbox => bounding_box.join(','), :width => width.to_i, :height => height.to_i, :zoom => zoom, :number_of_tiles => required_tiles.length, } end |
#render_map(filename) ⇒ Object
45 46 47 |
# File 'lib/mapstatic/map.rb', line 45 def render_map(filename) to_image.write filename end |
#to_image ⇒ Object
38 39 40 41 42 43 |
# File 'lib/mapstatic/map.rb', line 38 def to_image base_image = create_uncropped_image base_image = fill_image_with_tiles(base_image) crop_to_size base_image base_image end |