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
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