Class: MapKit::BoundingBox

Inherits:
Object
  • Object
show all
Defined in:
lib/mapkit.rb

Overview

The class represents a bounding box specified by a top/left point and a bottom/right point (the coordinates can be pixels or degrees)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(top, left, bottom, right, zoom = 0) ⇒ BoundingBox

initialize the bounding box using the positions of two points and a optional zoom level

     top
left o------+
     |      |
     |      |
     +------o right
            bottom


68
69
70
# File 'lib/mapkit.rb', line 68

def initialize(top, left, bottom, right, zoom = 0)
  @top, @left, @bottom, @right, @zoom = top, left, bottom, right, zoom
end

Instance Attribute Details

#bottomObject

Returns the value of attribute bottom.



56
57
58
# File 'lib/mapkit.rb', line 56

def bottom
  @bottom
end

#leftObject

Returns the value of attribute left.



56
57
58
# File 'lib/mapkit.rb', line 56

def left
  @left
end

#rightObject

Returns the value of attribute right.



56
57
58
# File 'lib/mapkit.rb', line 56

def right
  @right
end

#topObject

Returns the value of attribute top.



56
57
58
# File 'lib/mapkit.rb', line 56

def top
  @top
end

#zoomObject

Returns the value of attribute zoom.



56
57
58
# File 'lib/mapkit.rb', line 56

def zoom
  @zoom
end

Instance Method Details

#centerObject

returns [lat, lnt] of bounding box



93
94
95
# File 'lib/mapkit.rb', line 93

def center
  [@left + width / 2, @bottom + height / 2]
end

#coordsObject

returns array of [top, left, bottom, right]



73
74
75
# File 'lib/mapkit.rb', line 73

def coords
  [@top, @left, @bottom, @right]
end

#grow(percent) ⇒ Object

grow bounding box by percentage and return new bounding box object



108
109
110
111
112
# File 'lib/mapkit.rb', line 108

def grow(percent)
  copy = self.clone
  copy.grow!(percent)
  copy
end

#grow!(percent) ⇒ Object

grow bounding box by percentage



98
99
100
101
102
103
104
105
# File 'lib/mapkit.rb', line 98

def grow!(percent)
  lng = ((100.0 + percent) * (width / 2.0 / 100.0)) / 2.0
  lat = ((100.0 + percent) * (height / 2.0 / 100.0)) / 2.0
  @top += lat
  @left -= lng
  @bottom -= lat
  @right += lng
end

#heightObject

returns the height of the bounding box in degrees



83
84
85
# File 'lib/mapkit.rb', line 83

def height
  @top - @bottom
end

#sspnObject

returns array of [width, height] of sspn



88
89
90
# File 'lib/mapkit.rb', line 88

def sspn
  [width / 2, height / 2]
end

#widthObject

returns the width of the bounding box in degrees



78
79
80
# File 'lib/mapkit.rb', line 78

def width
  @right - @left
end