Class: MapKit::Point

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

Overview

The class represents an lat/lng point

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#latObject

Returns the value of attribute lat.



32
33
34
# File 'lib/mapkit.rb', line 32

def lat
  @lat
end

#lngObject

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

Returns:

  • (Boolean)


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
# File 'lib/mapkit.rb', line 46

def pixel(bounding_box)
  top, left, bottom, right = bounding_box.coords
  ws = (right - left) / TILE_SIZE
  hs = (bottom - top) / TILE_SIZE
  [((@lng - left) / ws).to_i, ((@lat - top) / hs).to_i]
end