cloudmade 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,54 @@
1
+ #
2
+ # Copyright 2009 CloudMade.
3
+ #
4
+ # Licensed under the GNU Lesser General Public License, Version 3.0;
5
+ # You may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.gnu.org/licenses/lgpl-3.0.txt
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+ module CloudMade
18
+
19
+ # General class for all CloudMade's services
20
+ class Service
21
+ require 'net/http'
22
+ require 'cgi'
23
+ attr_accessor :subdomain
24
+ attr_accessor :connection
25
+
26
+ def url_template
27
+ return "http://#{@subdomain}.#{@connection.url}/#{@connection.api_key}"
28
+ end
29
+
30
+ # Template for service's domain
31
+ # By default it is <service_name>.cloudmade.com
32
+ # E.g. tile.cloudmade.com, geocoding.cloudmade.com
33
+ def url
34
+ "#{@subdomain}.#{@connection.base_url}"
35
+ end
36
+
37
+ class << self
38
+ def to_url_params(params)
39
+ params.map {|k,v| "#{CGI.escape(k.to_s)}=#{CGI.escape(v.to_s)}" }.join('&')
40
+ end
41
+ end
42
+
43
+ protected
44
+ def initialize(connection, subdomain)
45
+ @connection = connection
46
+ @subdomain = subdomain
47
+ end
48
+
49
+ def connect(request)
50
+ puts "Requesting: #{url} -- #{url_template}#{request}"
51
+ return @connection.connect(url, "#{url_template}#{request}")
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,105 @@
1
+ #
2
+ # Copyright 2009 CloudMade.
3
+ #
4
+ # Licensed under the GNU Lesser General Public License, Version 3.0;
5
+ # You may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.gnu.org/licenses/lgpl-3.0.txt
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+ include CloudMade
18
+
19
+ module CloudMade
20
+
21
+ # Class that is responsible for tile services of Cloudmade
22
+ class TilesService < Service
23
+ attr_accessor :default_tile_size
24
+ attr_accessor :default_style_id
25
+
26
+ def initialize(client, subdomain, options = {})
27
+ super(client, subdomain)
28
+ @default_tile_size = (options.has_key? 'tile_size') ? options['tile_size'] : 256
29
+ @default_style_id = (options.has_key? 'style_id') ? options['style_id'] : 1
30
+ end
31
+
32
+ # Convert latitude, longitude pair to tile coordinates. Returns tile coordinates as a CloudMade::Point object
33
+ # * +lat+ Latitude
34
+ # * +lon+ Longitude
35
+ # * +zoom+ Zoom level
36
+ def latlon2tilenums(lat, lon, zoom)
37
+ factor = 2**(zoom - 1)
38
+ lat = radians(lat)
39
+ lon = radians(lon)
40
+ xtile = 1 + lon / Math::PI
41
+ ytile = 1 - Math.log(Math.tan(lat) + (1 / Math.cos(lat))) / Math::PI
42
+ return Point.new((xtile * factor).to_i, (ytile * factor).to_i)
43
+ end
44
+
45
+ # Convert tile coordinates pair to latitude, longitude. Returns latitude, longitude as a CloudMade::Point object
46
+ # * +xtile+ X coordinate of the tile
47
+ # * +ytile+ Y coordinate of the tile
48
+ # * +zoom+ Zoom level
49
+ def tilenums2latlon(xtile, ytile, zoom)
50
+ factor = 2.0 ** zoom
51
+ lon = (xtile * 360 / factor) - 180.0
52
+ lat = Math.atan(Math.sinh(Math::PI * (1 - 2 * ytile / factor)))
53
+ return Point.new(degrees(lat), lon)
54
+ end
55
+
56
+ # :nodoc:
57
+ def radians(degrees)
58
+ Math::PI * degrees / 180
59
+ end
60
+
61
+ def degrees(radians)
62
+ radians * 180 / Math::PI
63
+ end
64
+
65
+ def xtile(lon, zoom)
66
+ factor = 2**(zoom - 1)
67
+ xtile = 1 + lon / 180.0
68
+ return (xtile * factor).to_i
69
+ end
70
+
71
+ def ytile(lat, zoom)
72
+ factor = 2**(zoom - 1)
73
+ lat = radians(lat)
74
+ ytile = 1 - Math.log(Math.tan(lat) + (1 / Math.cos(lat))) / Math::PI
75
+ return (ytile * factor).to_i
76
+ end
77
+
78
+ # Get tile with given latitude, longitude and zoom.
79
+ # Returns Raw PNG data which could be saved to file
80
+ #
81
+ # * +lat+ Latitude of requested tile
82
+ # * +lon+ Longitude of requested tile
83
+ # * +zoom+ Zoom level, on which tile is being requested
84
+ # * +style_id+ CloudMade's style id, if not given, default style is used (usually 1)
85
+ # * +tile_size+ size of tile, if not given the default 256 is used
86
+ def get_tile(lat, lon, zoom, style_id = nil, tile_size = nil)
87
+ get_xy_tile(xtile(lon, zoom), ytile(lat, zoom), zoom, style_id, tile_size)
88
+ end
89
+
90
+ # Get tile with given x, y numbers and zoom
91
+ # Returns Raw PNG data which could be saved to file
92
+ #
93
+ # * +xtile+
94
+ # * +ytile+
95
+ # * +zoom+ Zoom level, on which tile is being requested
96
+ # * +style_id+ CloudMade's style id, if not given, default style is used (usually 1)
97
+ # * +tile_size+ size of tile, if not given the default 256 is used
98
+ def get_xy_tile(xtile, ytile, zoom, style_id = nil, tile_size = nil)
99
+ style_id = self.default_style_id if style_id == nil
100
+ tile_size = self.default_tile_size if tile_size == nil
101
+ connect "/#{style_id}/#{tile_size}/#{zoom}/#{xtile}/#{ytile}.png"
102
+ end
103
+ end
104
+
105
+ end
@@ -0,0 +1,3 @@
1
+ module Cloudmade
2
+ VERSION = "0.1.2"
3
+ end
@@ -0,0 +1,15 @@
1
+ require 'cloudmade'
2
+
3
+ include CloudMade
4
+
5
+ class MockConnection < Connection
6
+ attr_accessor :return_data
7
+ attr_accessor :request
8
+ attr_accessor :server_url
9
+
10
+ def connect(server_url, request)
11
+ self.request = request
12
+ self.server_url = server_url
13
+ return return_data
14
+ end
15
+ end
@@ -0,0 +1,71 @@
1
+ $:.push File.expand_path("../../lib", __FILE__)
2
+ $:.push File.expand_path("../..", __FILE__)
3
+
4
+ require 'cloudmade'
5
+ require 'test/unit'
6
+ require 'test/mock_connection'
7
+
8
+ include CloudMade
9
+
10
+ class GeocodingServiceTest < Test::Unit::TestCase #:nodoc: all
11
+
12
+ RETURN_DATA_FIND = <<-eos
13
+ {"found": 2, "type": "FeatureCollection",
14
+ "features": [{"properties": {"name": "New Oxford Street"}, "centroid":
15
+ {"type": "POINT", "coordinates": [51.51695, -0.12652]}, "location":
16
+ {"city": "London", "postcode": "WC2"}, "geometry": {"type": "MULTILINESTRING",
17
+ "coordinates": [[[51.5166, -0.12894], [51.51679, -0.12751], [51.51691, -0.12687],
18
+ [51.51704, -0.12587], [51.51717, -0.1251]], [[51.51721, -0.12261], [51.51722, -0.12312]],
19
+ [[51.51639, -0.13042], [51.51653, -0.12954], [51.51654, -0.12948], [51.5166, -0.12894]],
20
+ [[51.51722, -0.12312], [51.51717, -0.12498], [51.51717, -0.1251]], [[51.51717, -0.12498],
21
+ [51.51722, -0.12503]]]}, "id": 490249, "bounds": [[51.51639, -0.13042], [51.51722, -0.12261]]},
22
+ {"properties": {"name": "Oxford Street"}, "centroid": {"type": "POINT", "coordinates":
23
+ [51.51499, -0.14448]}, "location": {"city": "London", "postcode": "SE1"},
24
+ "geometry": {"type": "MULTILINESTRING", "coordinates": [[[51.51341, -0.15853],
25
+ [51.51342, -0.15821], [51.51371, -0.15593], [51.5139, -0.15381], [51.51404, -0.15257], [51.51411, -0.15195],
26
+ [51.51418, -0.15132], [51.51424, -0.15072], [51.51424, -0.15068], [51.51427, -0.15029], [51.51434, -0.14986],
27
+ [51.51442, -0.14919], [51.51445, -0.149], [51.5145, -0.14851], [51.51457, -0.14798], [51.51459, -0.1478],
28
+ [51.51469, -0.14691], [51.51476, -0.14639], [51.51477, -0.14631], [51.51485, -0.1457], [51.51501, -0.1443],
29
+ [51.51521, -0.14269], [51.51528, -0.14213], [51.5153, -0.142]], [[51.5153, -0.142], [51.51537, -0.14137],
30
+ [51.51545, -0.14073]], [[51.51545, -0.14073], [51.5155, -0.14036], [51.51556, -0.13991], [51.5156, -0.13935],
31
+ [51.51568, -0.13863], [51.51577, -0.13771], [51.51581, -0.13732], [51.51585, -0.13678], [51.51594, -0.13586],
32
+ [51.51598, -0.13537], [51.51603, -0.13468], [51.51609, -0.13405], [51.51624, -0.13289], [51.51626, -0.13267],
33
+ [51.51634, -0.13166], [51.51639, -0.13042]]]}, "id": 500456, "bounds": [[51.51341, -0.15853], [51.51639, -0.13042]]}],
34
+ "bounds": [[51.51341, -0.15853], [51.51722, -0.12261]],
35
+ "crs": {"type": "EPSG", "properties": {"code": 4326, "coordinate_order": [0, 1]}}}
36
+ eos
37
+
38
+ RETURN_DATA_CLOSEST =<<-eos
39
+ {"found": 1, "type": "FeatureCollection", "features": [{"properties": {"power": "tower"},
40
+ "location": {"city": "Kingston upon Hull", "postcode": "DN37"}, "centroid": {"type": "POINT",
41
+ "coordinates": [53.52435, -0.143]}, "id": 75035, "bounds": [[53.52435, -0.143], [53.52435, -0.143]]}],
42
+ "bounds": [[53.52435, -0.143], [53.52435, -0.143]],
43
+ "crs": {"type": "EPSG", "properties": {"code": 4326, "coordinate_order": [0, 1]}}}
44
+ eos
45
+
46
+ def test_find
47
+ connection = MockConnection.new('FAKE-API-KEY', 'fake-cloudmade.com')
48
+ connection.return_data = RETURN_DATA_FIND
49
+ geocoding = GeocodingService.new(connection, 'geocoding')
50
+ geo_results = geocoding.find('/geocoding/find/Oxford%20street%2CLondon.js?bbox_only=True&skip=0&return_location=True&results=2&return_geometry=True')
51
+ assert geo_results.found == 2
52
+ assert_equal geo_results.bounds, BBox.from_coordinates([[51.51341,-0.15853],[51.51722,-0.12261]])
53
+ assert geo_results.results[0].properties["name"] == "New Oxford Street"
54
+ assert geo_results.results[1].properties["name"] == "Oxford Street"
55
+ assert_equal geo_results.results[1].geometry.class.to_s, 'CloudMade::MultiLine'
56
+ assert_equal geo_results.results[1].location.city, "London"
57
+ end
58
+
59
+ def test_closest
60
+ connection = MockConnection.new('FAKE-API-KEY', 'fake-cloudmade.com')
61
+ connection.return_data = RETURN_DATA_CLOSEST
62
+ geocoding = GeocodingService.new(connection, 'geocoding')
63
+ geo_result = geocoding.find_closest("poi", 53.51722, -0.12312,
64
+ :options => { :return_location => true, :return_geometry => false})
65
+ assert_equal geo_result.class.to_s, 'CloudMade::GeoResult'
66
+ #assert_equal connection.uri, """/geocoding/closest/poi/53.51722,-0.12312.js?return_location=True&return_geometry=False"""
67
+ assert_nil geo_result.geometry
68
+ assert_equal geo_result.location.city, 'Kingston upon Hull'
69
+ assert_equal geo_result.centroid, Point.new(53.52435, -0.143)
70
+ end
71
+ end
@@ -0,0 +1,100 @@
1
+ $LOAD_PATH.unshift File.join('..', 'lib')
2
+ require 'cloudmade'
3
+ require 'test/unit'
4
+
5
+ include CloudMade
6
+
7
+ class PointTest < Test::Unit::TestCase #:nodoc: all
8
+
9
+ def test_initialization
10
+ point = Point.new(1, 2)
11
+ assert_equal point.lat, 1
12
+ assert_equal point.lon, 2
13
+
14
+ point = Point.new([1, 3])
15
+ assert_equal point.lat, 1
16
+ assert_equal point.lon, 3
17
+ end
18
+
19
+ def test_equality
20
+ point1 = Point.new(1, 0)
21
+ point2 = Point.new(2/2, 1-1)
22
+ assert point1 == point2
23
+
24
+ point3 = Point.new(1.0, 0.1)
25
+ assert point1 != point3
26
+ end
27
+
28
+ def test_to_latlon
29
+ point = Point.new(1, 2)
30
+ assert_equal point.to_latlon, '1,2'
31
+ end
32
+ end
33
+
34
+ class LineTest < Test::Unit::TestCase #:nodoc: all
35
+
36
+ def test_initialization
37
+ line = Line.new([[1.1, 2.0], [0.1, 2.1]])
38
+ assert_equal line.points.length, 2
39
+ assert_equal line.points[0].lat, 1.1
40
+ assert_equal line.points[0].lon, 2.0
41
+ assert_equal line.points[1].lat, 0.1
42
+ assert_equal line.points[1].lon, 2.1
43
+
44
+ line = Line.new([[1.1, 2.0], [0.1, 2.1], [0.5, 3.1], [3.1, 4.1]])
45
+ assert_equal line.points.length, 4
46
+ end
47
+ end
48
+
49
+ class MultiLineTest < Test::Unit::TestCase #:nodoc: all
50
+ def test_initialization
51
+ coords = [[[0.2, 35.2], [4.3, 45.1], [5.7, 11.2]], [[1.1, 33.2], [5.3, 22.2]]]
52
+ ml = MultiLine.new(coords)
53
+ assert_equal ml.lines.size, 2
54
+ assert_equal ml.lines[0].points.length, 3
55
+ assert_equal ml.lines[1].points.length, 2
56
+ assert_equal ml.lines[1].points[0].lon, 33.2
57
+ end
58
+ end
59
+
60
+ class PolygonTest < Test::Unit::TestCase #:nodoc: all
61
+ def test_initialization
62
+ coords = [[[0.2, 35.2], [4.3, 45.1], [5.7, 11.2]], [[1.1, 33.2], [5.3, 22.2]]]
63
+ polygon = Polygon.new(coords)
64
+ assert polygon.border_line != nil
65
+ assert_equal polygon.border_line.points.size, 3
66
+ assert polygon.holes != nil
67
+ assert_equal polygon.holes.size, 1
68
+ end
69
+ end
70
+
71
+ class MultiPolygonTest < Test::Unit::TestCase #:nodoc: all
72
+ def test_initialization
73
+ coords = [[[[0.2, 35.2], [4.3, 45.1]]], [[[1.1, 33.2], [5.3, 22.2]]]]
74
+ mp = MultiPolygon.new(coords)
75
+ assert_equal mp.polygons.size, 2
76
+ assert_equal mp.polygons[0].holes.size, 0
77
+ assert_equal mp.polygons[1].holes.size, 0
78
+ end
79
+ end
80
+
81
+ class BBoxTest < Test::Unit::TestCase #:nodoc: all
82
+ def test_initialization
83
+ coordinates = [[0.2, 35.2], [4.3, 45.1]]
84
+ point1 = Point.new(coordinates[0])
85
+ point2 = Point.new(coordinates[1])
86
+ bbox = BBox.from_points([point1, point2])
87
+ assert_equal bbox.points.length, 2
88
+ assert_equal bbox.points[0], point1
89
+ assert_equal bbox.points[1], point2
90
+
91
+ bbox = BBox.from_coordinates(coordinates)
92
+ assert_equal bbox.points.length, 2
93
+ assert_equal bbox.points[0], point1
94
+ assert_equal bbox.points[1], point2
95
+ end
96
+ end
97
+
98
+ # TODO: add code to parse that
99
+ #class GeometryTest < Test::Unit::TestCase #:nodoc: all
100
+ #end
@@ -0,0 +1,78 @@
1
+ $LOAD_PATH.unshift File.join('..', 'lib')
2
+ require 'cloudmade'
3
+ require 'test/unit'
4
+ require 'test/mock_connection'
5
+
6
+ include CloudMade
7
+
8
+ class RoutingServiceTest < Test::Unit::TestCase #:nodoc: all
9
+
10
+ RETURN_DATA_EMPTY = '{}'
11
+
12
+ RETURN_DATA_ROUTING = <<-eos
13
+ {"status":0,"route_instructions":[["Head south on Generaal Belliardstraat",16,0,2,"16 m","S",176.2],
14
+ ["Turn right at Falconrui",149,1,18,"0.1 km","W",262.8,"TR",86.6],["Turn right at Falconplein",347,3,42,"0.3 km","N",345.9,"TR",83.0],
15
+ ["Turn right at Huikstraat",212,9,25,"0.2 km","SW",243.8,"TR",79.2],["Turn left at Sint-Paulusstraat",12,14,1,"12 m","SE",145.4,"TL",306.7],
16
+ ["Continue on Minderbroedersrui",303,15,18,"0.3 km","SE",152.4,"C",7.0],["Turn left at Kipdorp",337,22,40,"0.3 km","E",103.9,"TL",304.7],
17
+ ["Turn right at Sint-Jacobstraat",339,28,41,"0.3 km","S",196.2,"TR",94.1],["Turn right at Lange Nieuwstraat",297,33,71,"0.3 km","W",266.3,"TR",70.2],
18
+ ["Turn left at Sint-Katelijnevest",173,40,10,"0.2 km","S",182.4,"TL",259.4],["Slight left",21,46,1,"21 m","SE",156.0,"TSLL",331.3],
19
+ ["Continue on Meir",22,49,1,"22 m","SE",142.9,"C",351.3],["Slight right at Huidevettersstraat",266,51,16,"0.3 km","S",180.0,"TSLR",37.1],
20
+ ["Continue on Lange Gasthuisstraat",349,66,21,"0.3 km","S",167.6,"C",350.1],["Slight left at Sint-Jorispoort",192,71,12,"0.2 km","E",109.7,"TSLL",314.9],
21
+ ["Slight right at Mechelsesteenweg",96,74,6,"96 m","S",171.9,"TSLR",37.1],["Continue",59,76,3,"59 m","S",179.2,"C",6.8],
22
+ ["Continue on N1\/Mechelsesteenweg",754,79,39,"0.8 km","S",172.5,"C",353.8],
23
+ ["Turn right at Van Schoonbekestraat",367,91,44,"0.4 km","SW",247.0,"TR",88.6],["Turn left at Schulstraat",234,95,28,"0.2 km","SE",124.9,"TL",269.3],
24
+ ["Turn left at Harmoniestraat",3418,97,410,"3.4 km","NE",38.8,"TL",242.5],["Continue on Ellermanstraat",47,101,3,"47 m","W",267.9,"C",0.0]],
25
+ "route_summary":{"total_time":852,"transit_points":[["Sint-Jacobstraat",51.22006,4.40965],["Harmoniestraat",51.20047,4.40913]],
26
+ "total_distance":8010,"end_point":"Ellermanstraat","start_point":"Generaal Belliardstraat"},
27
+ "route_geometry":[[51.22545,4.40728],[51.2253,4.4073],[51.22515,4.40533],[51.22514,4.40518],[51.22565,4.40498],
28
+ [51.22651,4.40514],[51.22665,4.40511],[51.22652,4.40506],[51.2256,4.40479],[51.22511,4.40501],[51.22505,4.40481],
29
+ [51.22503,4.40477],[51.22456,4.40388],[51.22406,4.40325],[51.22371,4.40307],[51.22362,4.40317],[51.22356,4.40321],
30
+ [51.2226,4.40425],[51.22182,4.40501],[51.22179,4.40502],[51.22145,4.40507],[51.22141,4.40509],[51.22125,4.40519],
31
+ [51.221,4.40681],[51.22096,4.40709],[51.22088,4.40769],[51.22087,4.40779],[51.22073,4.40921],[51.22064,4.40992],
32
+ [51.21966,4.40947],[51.21966,4.40947],[51.22064,4.40992],[51.22006,4.40965],[51.21966,4.40947],[51.21965,4.40928],
33
+ [51.21974,4.40814],[51.21981,4.40735],[51.21982,4.40726],[51.21989,4.40628],[51.21997,4.40571],[51.22003,4.40526],
34
+ [51.21997,4.40526],[51.21923,4.40516],[51.21912,4.40509],[51.21893,4.40505],[51.2186,4.40503],[51.21849,4.40499],
35
+ [51.21847,4.40501],[51.21838,4.40509],[51.21833,4.40514],[51.21826,4.40525],[51.21817,4.40533],[51.21809,4.40534],
36
+ [51.2178,4.40533],[51.21752,4.40533],[51.21723,4.40537],[51.2169,4.40543],[51.2167,4.40543],[51.21655,4.4054],
37
+ [51.21644,4.40534],[51.21638,4.40529],[51.2163,4.40516],[51.21625,4.40497],[51.21617,4.40483],[51.21616,4.40481],
38
+ [51.2161,4.40478],[51.21596,4.40482],[51.21514,4.40511],[51.21402,4.40501],[51.21381,4.405],[51.21304,4.40499],
39
+ [51.21286,4.40512],[51.21244,4.40699],[51.21227,4.40744],[51.21213,4.4075],[51.21142,4.40766],[51.21127,4.40768],
40
+ [51.21112,4.40768],[51.21097,4.4077],[51.21074,4.40771],[51.20968,4.40793],[51.20914,4.40825],[51.20869,4.40857],
41
+ [51.2084,4.40887],[51.20829,4.40894],[51.20695,4.40973],[51.20672,4.4098],[51.20644,4.40989],[51.20618,4.40991],
42
+ [51.2059,4.40989],[51.20565,4.40998],[51.20432,4.41081],[51.2039,4.40924],[51.20382,4.40898],[51.20376,4.40884],
43
+ [51.20218,4.40704],[51.20162,4.40833],[51.20097,4.40976],[51.20053,4.40921],[51.20097,4.40976],[51.22982,4.42068],
44
+ [51.22981,4.42001],[51.22981,4.42001]],"version":"0.3"}
45
+ eos
46
+
47
+ def test_empty_routing
48
+ transit_points = [Point.new([51.22, 4.41]), Point.new([51.2, 4.41])]
49
+ connection = MockConnection.new('FAKE-API-KEY', 'fake-cloudmade.com')
50
+ connection.return_data = RETURN_DATA_EMPTY
51
+ routing = RoutingService.new(connection, 'routing')
52
+ begin
53
+ route = routing.route(Point.new([51.22545, 4.40730]), Point.new([51.23, 4.42]),
54
+ transit_points, 'car', 'shortest')
55
+ assert false
56
+ rescue RouteNotFound
57
+ assert true
58
+ end
59
+ end
60
+
61
+ def test_routing
62
+ transit_points = [Point.new([51.22, 4.41]), Point.new([51.2, 4.41])]
63
+ connection = MockConnection.new('FAKE-API-KEY', 'fake-cloudmade.com')
64
+ connection.return_data = RETURN_DATA_ROUTING
65
+ routing = RoutingService.new(connection, 'routing')
66
+ begin
67
+ route = routing.route(Point.new([51.22545, 4.40730]), Point.new([51.23, 4.42]),
68
+ transit_points, 'car', 'shortest')
69
+ assert_equal route.version, '0.3'
70
+ assert_equal route.summary.total_time, 852
71
+ assert_equal route.summary.total_distance, 8010
72
+ assert_equal route.summary.end_point, 'Ellermanstraat'
73
+ assert_equal route.summary.start_point, 'Generaal Belliardstraat'
74
+ rescue RouteNotFound
75
+ assert false
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,33 @@
1
+ $LOAD_PATH.unshift File.join('..', 'lib')
2
+ require 'cloudmade'
3
+ require 'test/unit'
4
+ require 'test/mock_connection'
5
+
6
+ include CloudMade
7
+
8
+ class TilesServiceTest < Test::Unit::TestCase #:nodoc: all
9
+
10
+ def setup
11
+ @connection = MockConnection.new('FAKE-API-KEY', 'fake-cloudmade.com')
12
+ @tiles = TilesService.new(@connection, 'tile')
13
+ end
14
+
15
+ def test_latlon2tilenums
16
+ p = @tiles.latlon2tilenums(11.1, 34.5, 15)
17
+ assert p.lat == 19524
18
+ assert p.lon == 15367
19
+ end
20
+
21
+ def test_tilenums2latlon
22
+ p = @tiles.tilenums2latlon(19524, 15367, 15)
23
+ assert p.lat.to_i == 11
24
+ assert p.lon.to_i == 34
25
+ end
26
+
27
+ def test_get_tile
28
+ @connection.return_data = "PNG file content"
29
+ png = @tiles.get_tile(11.1, 34.5, 15)
30
+ assert_equal @connection.request, 'http://tile.fake-cloudmade.com/FAKE-API-KEY/1/256/15/19524/15367.png'
31
+ assert png == @connection.return_data
32
+ end
33
+ end