root/trunk/py/ModestMaps/Yahoo.py

Revision 305, 2.6 kB (checked in by migurski, 1 year ago)

Moved much of compose.py into a new ModestMaps?.Map class that knows how to draw itself

Line 
1 """
2 >>> p = RoadProvider()
3 >>> p.getTileUrls(Coordinate(25322, 10507, 16)) #doctest: +ELLIPSIS
4 ('http://us.maps2.yimg.com/us.png.maps.yimg.com/png?v=...&t=m&x=10507&y=7445&z=2',)
5 >>> p.getTileUrls(Coordinate(25333, 10482, 16)) #doctest: +ELLIPSIS
6 ('http://us.maps2.yimg.com/us.png.maps.yimg.com/png?v=...&t=m&x=10482&y=7434&z=2',)
7
8 >>> p = AerialProvider()
9 >>> p.getTileUrls(Coordinate(25322, 10507, 16)) #doctest: +ELLIPSIS
10 ('http://us.maps3.yimg.com/aerial.maps.yimg.com/tile?v=...&t=a&x=10507&y=7445&z=2',)
11 >>> p.getTileUrls(Coordinate(25333, 10482, 16)) #doctest: +ELLIPSIS
12 ('http://us.maps3.yimg.com/aerial.maps.yimg.com/tile?v=...&t=a&x=10482&y=7434&z=2',)
13
14 >>> p = HybridProvider()
15 >>> p.getTileUrls(Coordinate(25322, 10507, 16)) #doctest: +ELLIPSIS
16 ('http://us.maps3.yimg.com/aerial.maps.yimg.com/tile?v=...&t=a&x=10507&y=7445&z=2', 'http://us.maps3.yimg.com/aerial.maps.yimg.com/png?v=...&t=h&x=10507&y=7445&z=2')
17 >>> p.getTileUrls(Coordinate(25333, 10482, 16)) #doctest: +ELLIPSIS
18 ('http://us.maps3.yimg.com/aerial.maps.yimg.com/tile?v=...&t=a&x=10482&y=7434&z=2', 'http://us.maps3.yimg.com/aerial.maps.yimg.com/png?v=...&t=h&x=10482&y=7434&z=2')
19 """
20
21 from Core import Coordinate
22 from Geo import MercatorProjection, Transformation
23 from Providers import IMapProvider
24
25 import Tiles
26
27 ROAD_VERSION = '3.52'
28 AERIAL_VERSION = '1.7'
29 HYBRID_VERSION = '2.2'
30
31 class AbstractProvider(IMapProvider):
32     def __init__(self):
33         t = Transformation(1.068070779e7, 0, 3.355443185e7,
34                                    0, -1.068070890e7, 3.355443057e7)
35
36         self.projection = MercatorProjection(26, t)
37
38     def getZoomString(self, coordinate):
39         return 'x=%d&y=%d&z=%d' % Tiles.toYahoo(int(coordinate.column), int(coordinate.row), int(coordinate.zoom))
40
41     def tileWidth(self):
42         return 256
43
44     def tileHeight(self):
45         return 256
46
47 class RoadProvider(AbstractProvider):
48     def getTileUrls(self, coordinate):
49         return ('http://us.maps2.yimg.com/us.png.maps.yimg.com/png?v=%s&t=m&%s' % (ROAD_VERSION, self.getZoomString(self.sourceCoordinate(coordinate))),)
50
51 class AerialProvider(AbstractProvider):
52     def getTileUrls(self, coordinate):
53         return ('http://us.maps3.yimg.com/aerial.maps.yimg.com/tile?v=%s&t=a&%s' % (AERIAL_VERSION, self.getZoomString(self.sourceCoordinate(coordinate))),)
54
55 class HybridProvider(AbstractProvider):
56     def getTileUrls(self, coordinate):
57         under = AerialProvider().getTileUrls(coordinate)[0]
58         over = 'http://us.maps3.yimg.com/aerial.maps.yimg.com/png?v=%s&t=h&%s' % (HYBRID_VERSION, self.getZoomString(self.sourceCoordinate(coordinate)))
59         return (under, over)
60
61 if __name__ == '__main__':
62     import doctest
63     doctest.testmod()
Note: See TracBrowser for help on using the browser.