Class: MapKit::BoundingBox
- Inherits:
-
Object
- Object
- MapKit::BoundingBox
- 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
-
#bottom ⇒ Object
Returns the value of attribute bottom.
-
#left ⇒ Object
Returns the value of attribute left.
-
#right ⇒ Object
Returns the value of attribute right.
-
#top ⇒ Object
Returns the value of attribute top.
-
#zoom ⇒ Object
Returns the value of attribute zoom.
Instance Method Summary collapse
-
#center ⇒ Object
returns [lat, lnt] of bounding box.
-
#coords ⇒ Object
returns array of [top, left, bottom, right].
-
#grow(percent) ⇒ Object
grow bounding box by percentage and return new bounding box object.
-
#grow!(percent) ⇒ Object
grow bounding box by percentage.
-
#height ⇒ Object
returns the height of the bounding box in degrees.
-
#initialize(top, left, bottom, right, zoom = 0) ⇒ BoundingBox
constructor
initialize the bounding box using the positions of two points and a optional zoom level.
-
#sspn ⇒ Object
returns array of [width, height] of sspn.
-
#width ⇒ Object
returns the width of the bounding box in degrees.
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
#bottom ⇒ Object
Returns the value of attribute bottom.
56 57 58 |
# File 'lib/mapkit.rb', line 56 def bottom @bottom end |
#left ⇒ Object
Returns the value of attribute left.
56 57 58 |
# File 'lib/mapkit.rb', line 56 def left @left end |
#right ⇒ Object
Returns the value of attribute right.
56 57 58 |
# File 'lib/mapkit.rb', line 56 def right @right end |
#top ⇒ Object
Returns the value of attribute top.
56 57 58 |
# File 'lib/mapkit.rb', line 56 def top @top end |
#zoom ⇒ Object
Returns the value of attribute zoom.
56 57 58 |
# File 'lib/mapkit.rb', line 56 def zoom @zoom end |
Instance Method Details
#center ⇒ Object
returns [lat, lnt] of bounding box
93 94 95 |
# File 'lib/mapkit.rb', line 93 def center [@left + width / 2, @bottom + height / 2] end |
#coords ⇒ Object
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 |
#height ⇒ Object
returns the height of the bounding box in degrees
83 84 85 |
# File 'lib/mapkit.rb', line 83 def height @top - @bottom end |
#sspn ⇒ Object
returns array of [width, height] of sspn
88 89 90 |
# File 'lib/mapkit.rb', line 88 def sspn [width / 2, height / 2] end |
#width ⇒ Object
returns the width of the bounding box in degrees
78 79 80 |
# File 'lib/mapkit.rb', line 78 def width @right - @left end |