root/trunk/py/ModestMaps/Google.py

Revision 701, 3.1 kB (checked in by migurski, 2 months ago)

Updated Google version numbers

Line 
1 """
2 >>> p = RoadProvider()
3 >>> p.getTileUrls(Coordinate(25322, 10507, 16)) #doctest: +ELLIPSIS
4 ('http://mt....google.com/mt?n=404&v=...&x=10507&y=25322&zoom=1',)
5 >>> p.getTileUrls(Coordinate(25333, 10482, 16)) #doctest: +ELLIPSIS
6 ('http://mt....google.com/mt?n=404&v=...&x=10482&y=25333&zoom=1',)
7
8 >>> p = AerialProvider()
9 >>> p.getTileUrls(Coordinate(25322, 10507, 16)) #doctest: +ELLIPSIS
10 ('http://kh....google.com/kh?n=404&v=...&t=tqtsqrqtrtttqsqsr',)
11 >>> p.getTileUrls(Coordinate(25333, 10482, 16)) #doctest: +ELLIPSIS
12 ('http://kh....google.com/kh?n=404&v=...&t=tqtsqrqtqssssqtrt',)
13
14 >>> p = HybridProvider()
15 >>> p.getTileUrls(Coordinate(25322, 10507, 16)) #doctest: +ELLIPSIS
16 ('http://kh....google.com/kh?n=404&v=...&t=tqtsqrqtrtttqsqsr', 'http://mt....google.com/mt?n=404&v=...&x=10507&y=25322&zoom=1')
17 >>> p.getTileUrls(Coordinate(25333, 10482, 16)) #doctest: +ELLIPSIS
18 ('http://kh....google.com/kh?n=404&v=...&t=tqtsqrqtqssssqtrt', 'http://mt....google.com/mt?n=404&v=...&x=10482&y=25333&zoom=1')
19 """
20
21 from Core import Coordinate
22 from Geo import MercatorProjection, Transformation
23 from Providers import IMapProvider
24
25 import random, Tiles
26
27 ROAD_VERSION = 'w2.83'
28 AERIAL_VERSION = '32'
29 HYBRID_VERSION = 'w2t.83'
30 TERRAIN_VERSION = 'app.81'
31
32 class AbstractProvider(IMapProvider):
33     def __init__(self):
34         t = Transformation(1.068070779e7, 0, 3.355443185e7,
35                                    0, -1.068070890e7, 3.355443057e7)
36
37         self.projection = MercatorProjection(26, t)
38
39     def getZoomString(self, coordinate):
40         return 'x=%d&y=%d&zoom=%d' % Tiles.toGoogleRoad(int(coordinate.column), int(coordinate.row), int(coordinate.zoom))
41
42     def tileWidth(self):
43         return 256
44
45     def tileHeight(self):
46         return 256
47
48 class RoadProvider(AbstractProvider):
49     def getTileUrls(self, coordinate):
50         # http://mt1.google.com/mt?v=w2.83&hl=en&x=10513&s=&y=25304&z=16&s=Gal
51         return ('http://mt%d.google.com/mt?v=%s&hl=en&%s' % (random.randint(0, 3), ROAD_VERSION, self.getZoomString(self.sourceCoordinate(coordinate))),)
52
53 class AerialProvider(AbstractProvider):
54     def getTileUrls(self, coordinate):
55         # http://khm1.google.com/kh?v=32&hl=en&x=10513&s=&y=25304&z=16&s=Gal
56         return ('http://khm%d.google.com/kh?v=%s&hl=en&%s' % (random.randint(0, 3), AERIAL_VERSION, self.getZoomString(self.sourceCoordinate(coordinate))),)
57
58 class HybridProvider(AbstractProvider):
59     def getTileUrls(self, coordinate):
60         # http://mt0.google.com/mt?v=w2t.83&hl=en&x=10510&s=&y=25303&z=16&s=G
61         under = AerialProvider().getTileUrls(coordinate)[0]
62         over = 'http://mt%d.google.com/mt?v=%s&hl=en&%s' % (random.randint(0, 3), HYBRID_VERSION, self.getZoomString(self.sourceCoordinate(coordinate)))
63         return (under, over)
64
65 class TerrainProvider(RoadProvider):
66     def getTileUrls(self, coordinate):
67         # http://mt1.google.com/mt?v=app.81&hl=en&x=5255&s=&y=12651&z=15&s=
68         return ('http://mt%d.google.com/mt?v=%s&hl=en&%s' % (random.randint(0, 3), TERRAIN_VERSION, self.getZoomString(self.sourceCoordinate(coordinate))),)
69
70 if __name__ == '__main__':
71     import doctest
72     doctest.testmod()
Note: See TracBrowser for help on using the browser.