Class: MapKit::Point
- Inherits:
-
Object
- Object
- MapKit::Point
- Defined in:
- lib/mapkit.rb
Overview
The class represents an lat/lng point
Instance Attribute Summary collapse
-
#lat ⇒ Object
Returns the value of attribute lat.
-
#lng ⇒ Object
Returns the value of attribute lng.
Instance Method Summary collapse
-
#in?(bounding_box) ⇒ Boolean
returns true if point is in bounding_box, false otherwise.
-
#initialize(lat, lng) ⇒ Point
constructor
initializes a point object using latitude and longitude.
-
#pixel(bounding_box) ⇒ Object
returns relative x and y for point in bounding_box.
Constructor Details
#initialize(lat, lng) ⇒ Point
initializes a point object using latitude and longitude
35 36 37 |
# File 'lib/mapkit.rb', line 35 def initialize(lat, lng) @lat, @lng = lat, lng end |
Instance Attribute Details
#lat ⇒ Object
Returns the value of attribute lat.
32 33 34 |
# File 'lib/mapkit.rb', line 32 def lat @lat end |
#lng ⇒ Object
Returns the value of attribute lng.
32 33 34 |
# File 'lib/mapkit.rb', line 32 def lng @lng end |
Instance Method Details
#in?(bounding_box) ⇒ Boolean
returns true if point is in bounding_box, false otherwise
40 41 42 43 |
# File 'lib/mapkit.rb', line 40 def in?(bounding_box) top, left, bottom, right = bounding_box.coords (left..right) === @lng && (top..bottom) === @lat end |
#pixel(bounding_box) ⇒ Object
returns relative x and y for point in bounding_box
46 47 48 49 50 51 52 53 54 |
# File 'lib/mapkit.rb', line 46 def pixel(bounding_box) top, left, bottom, right = bounding_box.coords ws = bounding_box.width / TILE_SIZE hs = bounding_box.height / TILE_SIZE shift_lng = (@lng > 0) ? (@lng - left) : (left - @lng) shift_lat = (@lat > 0) ? (top - @lat) : (@lat - top) [(shift_lng.abs / ws).to_i, (shift_lat.abs / hs).to_i] end |