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.
-
#initialize(top, left, bottom, right, zoom = nil) ⇒ 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.
Constructor Details
#initialize(top, left, bottom, right, zoom = nil) ⇒ BoundingBox
initialize the bounding box using the positions of two points and a optional zoom level
top
left o------+
| |
| |
+------o right
bottom
69 70 71 |
# File 'lib/mapkit.rb', line 69 def initialize(top, left, bottom, right, zoom = nil) @top, @left, @bottom, @right, @zoom = top, left, bottom, right, zoom end |
Instance Attribute Details
#bottom ⇒ Object
Returns the value of attribute bottom.
57 58 59 |
# File 'lib/mapkit.rb', line 57 def bottom @bottom end |
#left ⇒ Object
Returns the value of attribute left.
57 58 59 |
# File 'lib/mapkit.rb', line 57 def left @left end |
#right ⇒ Object
Returns the value of attribute right.
57 58 59 |
# File 'lib/mapkit.rb', line 57 def right @right end |
#top ⇒ Object
Returns the value of attribute top.
57 58 59 |
# File 'lib/mapkit.rb', line 57 def top @top end |
#zoom ⇒ Object
Returns the value of attribute zoom.
57 58 59 |
# File 'lib/mapkit.rb', line 57 def zoom @zoom end |
Instance Method Details
#center ⇒ Object
returns [lat, lnt] of bounding box
84 85 86 |
# File 'lib/mapkit.rb', line 84 def center [@left + (@right - @left) / 2, @top + (@bottom - @top) / 2] end |
#coords ⇒ Object
returns array of [top, left, bottom, right]
74 75 76 |
# File 'lib/mapkit.rb', line 74 def coords [@top, @left, @bottom, @right] end |
#grow(percent) ⇒ Object
grow bounding box by percentage and return new bounding box object
99 100 101 102 103 |
# File 'lib/mapkit.rb', line 99 def grow(percent) copy = self.clone copy.grow!(percent) copy end |
#grow!(percent) ⇒ Object
grow bounding box by percentage
89 90 91 92 93 94 95 96 |
# File 'lib/mapkit.rb', line 89 def grow!(percent) lng = percent * ((@right - @left) / 100) lat = percent * ((@top - @bottom) / 100) @top += lat @left -= lng @bottom -= lat @right += lng end |
#sspn ⇒ Object
returns array of [width, height] of sspn
79 80 81 |
# File 'lib/mapkit.rb', line 79 def sspn [(@right - @left) / 2, (@bottom - @top) / 2] end |