mapkit 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/mapkit.rb +21 -8
- metadata +1 -1
data/lib/mapkit.rb
CHANGED
@@ -25,7 +25,7 @@ module MapKit
|
|
25
25
|
RESOLUTION = 2 * Math::PI * EARTH_RADIUS / TILE_SIZE
|
26
26
|
|
27
27
|
# version of MapKit
|
28
|
-
VERSION = "0.0.
|
28
|
+
VERSION = "0.0.3"
|
29
29
|
|
30
30
|
# The class represents an lat/lng point
|
31
31
|
class Point
|
@@ -45,9 +45,12 @@ module MapKit
|
|
45
45
|
# returns relative x and y for point in bounding_box
|
46
46
|
def pixel(bounding_box)
|
47
47
|
top, left, bottom, right = bounding_box.coords
|
48
|
-
ws =
|
49
|
-
hs =
|
50
|
-
|
48
|
+
ws = bounding_box.width / TILE_SIZE
|
49
|
+
hs = bounding_box.height / TILE_SIZE
|
50
|
+
shift_lng = (@lng > 0) ? (@lng - left) : (left - @lng)
|
51
|
+
shift_lat = (@lat > 0) ? (top - @lat) : (@lat - top)
|
52
|
+
|
53
|
+
[(shift_lng.abs / ws).to_i, (shift_lat.abs / hs).to_i]
|
51
54
|
end
|
52
55
|
end
|
53
56
|
|
@@ -74,21 +77,31 @@ module MapKit
|
|
74
77
|
def coords
|
75
78
|
[@top, @left, @bottom, @right]
|
76
79
|
end
|
80
|
+
|
81
|
+
# returns the width of the bounding box in degrees
|
82
|
+
def width
|
83
|
+
@right - @left
|
84
|
+
end
|
85
|
+
|
86
|
+
# returns the height of the bounding box in degrees
|
87
|
+
def height
|
88
|
+
@top - @bottom
|
89
|
+
end
|
77
90
|
|
78
91
|
# returns array of [width, height] of sspn
|
79
92
|
def sspn
|
80
|
-
[
|
93
|
+
[width / 2, height / 2]
|
81
94
|
end
|
82
95
|
|
83
96
|
# returns [lat, lnt] of bounding box
|
84
97
|
def center
|
85
|
-
[@left +
|
98
|
+
[@left + width / 2, @bottom + height / 2]
|
86
99
|
end
|
87
100
|
|
88
101
|
# grow bounding box by percentage
|
89
102
|
def grow!(percent)
|
90
|
-
lng = percent * (
|
91
|
-
lat = percent * (
|
103
|
+
lng = ((100.0 + percent) * (width / 2.0 / 100.0)) / 2.0
|
104
|
+
lat = ((100.0 + percent) * (height / 2.0 / 100.0)) / 2.0
|
92
105
|
@top += lat
|
93
106
|
@left -= lng
|
94
107
|
@bottom -= lat
|