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 |
# File 'lib/mapkit.rb', line 46 def pixel(bounding_box) x, y = MapKit.latlng2pixel(@lat, @lng, bounding_box.zoom) tile_x, tile_y = MapKit.latlng2pixel(bounding_box.top, bounding_box.left, bounding_box.zoom) [x-tile_x, y-tile_y] end |