Changeset 484
- Timestamp:
- 02/13/08 23:36:28 (7 months ago)
- Files:
-
- trunk/processing/modest_maps/Google.pde (modified) (1 diff)
- trunk/processing/modest_maps/init.pde (modified) (1 diff)
- trunk/processing/modest_maps/modest_maps.pde (modified) (3 diffs)
- trunk/processing/modest_maps/Tiles.pde (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/processing/modest_maps/Google.pde
r483 r484 1 1 2 /* 2 void doGoogleTest() { 3 3 4 ROAD_VERSION = 'w2.66' 5 AERIAL_VERSION = '24' 6 HYBRID_VERSION = 'w2t.66' 7 TERRAIN_VERSION = 'w2p.64' 4 println(); 5 println("google test"); 6 println(); 8 7 9 class AbstractProvider(IMapProvider): 10 def __init__(self):11 t = Transformation(1.068070779e7, 0, 3.355443185e7,12 0, -1.068070890e7, 3.355443057e7)8 AbstractMapProvider p = new GoogleRoadProvider(); 9 String[] urls = p.getTileUrls(new Coordinate(25322, 10507, 16)); 10 println(urls); 11 println( urls[0].startsWith("http://mt") && urls[0].endsWith("&x=10507&y=25322&zoom=1") ); //('....google.com/mt?n=404&v=...',) 13 12 14 self.projection = MercatorProjection(26, t) 13 urls = p.getTileUrls(new Coordinate(25333, 10482, 16)); 14 println( urls[0].startsWith("http://mt") && urls[0].endsWith("&x=10482&y=25333&zoom=1") ); //('....google.com/mt?n=404&v=...',) 15 15 16 def getZoomString(self, coordinate): 17 raise NotImplementedError() 16 p = new GoogleAerialProvider(); 17 urls = p.getTileUrls(new Coordinate(25322, 10507, 16)); 18 println( urls[0].startsWith("http://kh") && urls[0].endsWith("&t=tqtsqrqtrtttqsqsr") ); //google.com/kh?n=404&v= 18 19 19 def tileWidth(self):20 return 25620 urls = p.getTileUrls(new Coordinate(25333, 10482, 16)); 21 println( urls[0].startsWith("http://kh") && urls[0].endsWith("&t=tqtsqrqtqssssqtrt") ); //google.com/kh?n=404&v= 21 22 22 def tileHeight(self): 23 return 256 23 p = new GoogleHybridProvider(); 24 urls = p.getTileUrls(new Coordinate(25322, 10507, 16)); 25 println(urls); 26 println( urls[0].startsWith("http://kh") && urls[0].endsWith("&t=tqtsqrqtrtttqsqsr") ); //google.com/kh?n=404&v= 27 println( urls[1].startsWith("http://mt") && urls[1].endsWith("&x=10507&y=25322&zoom=1") ); //google.com/mt?n=404&v= 24 28 25 class RoadProvider(AbstractProvider): 26 def getTileUrls(self, coordinate): 27 return ('http://mt%d.google.com/mt?n=404&v=%s&%s' % (random.randint(0, 3), ROAD_VERSION, self.getZoomString(self.sourceCoordinate(coordinate))),) 28 29 def getZoomString(self, coordinate): 30 return 'x=%d&y=%d&zoom=%d' % Tiles.toGoogleRoad(int(coordinate.column), int(coordinate.row), int(coordinate.zoom)) 29 urls = p.getTileUrls(new Coordinate(25333, 10482, 16)); 30 println(urls); 31 println( urls[0].startsWith("http://kh") && urls[0].endsWith("&t=tqtsqrqtqssssqtrt") ); //google.com/kh?n=404&v= 32 println( urls[1].startsWith("http://mt") && urls[1].endsWith("&x=10482&y=25333&zoom=1") ); //google.com/mt?n=404&v= 33 } 31 34 32 class AerialProvider(AbstractProvider): 33 def getTileUrls(self, coordinate): 34 return ('http://kh%d.google.com/kh?n=404&v=%s&t=%s' % (random.randint(0, 3), AERIAL_VERSION, self.getZoomString(self.sourceCoordinate(coordinate))),) 35 abstract class GoogleProvider extends AbstractMapProvider{ 35 36 36 def getZoomString(self, coordinate): 37 return Tiles.toGoogleAerial(int(coordinate.column), int(coordinate.row), int(coordinate.zoom)) 37 String ROAD_VERSION = "w2.66"; 38 String AERIAL_VERSION = "24"; 39 String HYBRID_VERSION = "w2t.66"; 40 String TERRAIN_VERSION = "w2p.64"; 38 41 39 class HybridProvider(AbstractProvider): 40 def getTileUrls(self, coordinate): 41 under = AerialProvider().getTileUrls(coordinate)[0] 42 over = 'http://mt%d.google.com/mt?n=404&v=%s&%s' % (random.randint(0, 3), HYBRID_VERSION, RoadProvider().getZoomString(self.sourceCoordinate(coordinate))) 43 return (under, over) 42 GoogleProvider() { 43 super( new MercatorProjection(26, new Transformation(1.068070779e7, 0, 3.355443185e7, 0, -1.068070890e7, 3.355443057e7) ) ); 44 } 44 45 45 class TerrainProvider(RoadProvider): 46 def getTileUrls(self, coordinate): 47 return ('http://mt%d.google.com/mt?n=404&v=%s&%s' % (random.randint(0, 3), TERRAIN_VERSION, self.getZoomString(self.sourceCoordinate(coordinate))),) 46 abstract String getZoomString(Coordinate coordinate); 48 47 49 */ 48 int tileWidth() { 49 return 256; 50 } 51 52 int tileHeight() { 53 return 256; 54 } 55 56 } 57 58 class GoogleRoadProvider extends GoogleProvider { 59 String[] getTileUrls(Coordinate coordinate) { 60 String url = "http://mt" + (int)random(0, 4) + ".google.com/mt?n=404&v=" + ROAD_VERSION + "&" + getZoomString(sourceCoordinate(coordinate)); 61 return new String[] { 62 url }; 63 } 64 String getZoomString(Coordinate coordinate) { 65 Coordinate coord = toGoogleRoad(coordinate.container()); 66 return "x=" + (int)coord.column + "&y=" + (int)coord.row + "&zoom=" + (int)coord.zoom; 67 } 68 } 69 70 class GoogleAerialProvider extends GoogleProvider { 71 String[] getTileUrls(Coordinate coordinate) { 72 String url = "http://kh" + (int)random(0, 4) + ".google.com/kh?n=404&v=" + AERIAL_VERSION + "&t=" + getZoomString(sourceCoordinate(coordinate)); 73 return new String[] { 74 url }; 75 } 76 String getZoomString(Coordinate coordinate) { 77 return toGoogleAerial(coordinate.container()); 78 } 79 } 80 81 class GoogleHybridProvider extends GoogleProvider { 82 String[] getTileUrls(Coordinate coordinate) { 83 String under = new GoogleAerialProvider().getTileUrls(coordinate)[0]; 84 String over = "http://mt" + (int)random(0, 4) + ".google.com/mt?n=404&v=" + HYBRID_VERSION + "&" + getZoomString(sourceCoordinate(coordinate)); 85 return new String[] { 86 under, over }; 87 } 88 String getZoomString(Coordinate coordinate) { 89 Coordinate coord = toGoogleRoad(coordinate.container()); 90 return "x=" + (int)coord.column + "&y=" + (int)coord.row + "&zoom=" + (int)coord.zoom; 91 } 92 } 93 94 class GoogleTerrainProvider extends GoogleRoadProvider { 95 String[] getTileUrls(Coordinate coordinate) { 96 String url = "http://mt" + (int)random(0, 4) + ".google.com/mt?n=404&v=" + TERRAIN_VERSION + "&" + getZoomString(sourceCoordinate(coordinate)); 97 return new String[] { 98 url }; 99 } 100 } trunk/processing/modest_maps/init.pde
r483 r484 152 152 try { 153 153 for (int i = 0; i < urls.length; i++) { 154 imgs[i] = loadImage(urls[i]); 154 String type = urls[i].startsWith("http://mt") ? "png" : urls[i].startsWith("http://kh") ? "jpg" : null; 155 if (type != null) { 156 imgs[i] = loadImage(urls[i], type); 157 } 158 else { 159 imgs[i] = loadImage(urls[i]); 160 } 155 161 } 156 162 } trunk/processing/modest_maps/modest_maps.pde
r483 r484 8 8 void draw() { 9 9 10 Map m = new Map(new RoadProvider(), new Point(600, 600), new Location(51.5, -0.137), 14); 10 // Map m = new Map(new GoogleRoadProvider(), new Point(600, 600), new Coordinate(3165, 1313, 13), new Point(-144, -94)); 11 Map m = new Map(new GoogleTerrainProvider(), new Point(600, 600), new Location(51.5, -0.137), 12); 11 12 PImage img = m.draw(true); 12 13 … … 15 16 println(img); 16 17 17 image(img,0,0); 18 image(img,0,0); 18 19 } 19 20 … … 21 22 doTilesTest(); 22 23 doMicrosoftTest(); 24 doGoogleTest(); 23 25 doGeoTest(); 24 26 doCoreTest(); trunk/processing/modest_maps/Tiles.pde
r483 r484 4 4 println("tiles test"); 5 5 println(); 6 6 7 7 println( "1".equals(binary(1)) ); 8 8 println( "10".equals(binary(2)) ); … … 17 17 /* 18 18 >>> fromGoogleRoad(0, 0, 16) 19 (0, 0, 1) 20 >>> fromGoogleRoad(10507, 25322, 1) 21 (10507, 25322, 16) 22 >>> fromGoogleRoad(10482, 25333, 1) 23 (10482, 25333, 16) 24 25 >>> toGoogleRoad(0, 0, 1) 26 (0, 0, 16) 27 >>> toGoogleRoad(10507, 25322, 16) 28 (10507, 25322, 1) 29 >>> toGoogleRoad(10482, 25333, 16) 30 (10482, 25333, 1) 31 32 >>> fromGoogleAerial('tq') 33 (0, 0, 1) 34 >>> fromGoogleAerial('tqtsqrqtrtttqsqsr') 35 (10507, 25322, 16) 36 >>> fromGoogleAerial('tqtsqrqtqssssqtrt') 37 (10482, 25333, 16) 38 39 >>> toGoogleAerial(0, 0, 1) 40 'tq' 41 >>> toGoogleAerial(10507, 25322, 16) 42 'tqtsqrqtrtttqsqsr' 43 >>> toGoogleAerial(10482, 25333, 16) 44 'tqtsqrqtqssssqtrt' 45 46 >>> fromYahooRoad(0, 0, 17) 47 (0, 0, 1) 48 >>> fromYahooRoad(10507, 7445, 2) 49 (10507, 25322, 16) 50 >>> fromYahooRoad(10482, 7434, 2) 51 (10482, 25333, 16) 52 53 >>> toYahooRoad(0, 0, 1) 54 (0, 0, 17) 55 >>> toYahooRoad(10507, 25322, 16) 56 (10507, 7445, 2) 57 >>> toYahooRoad(10482, 25333, 16) 58 (10482, 7434, 2) 59 60 >>> fromYahooAerial(0, 0, 17) 61 (0, 0, 1) 62 >>> fromYahooAerial(10507, 7445, 2) 63 (10507, 25322, 16) 64 >>> fromYahooAerial(10482, 7434, 2) 65 (10482, 25333, 16) 66 67 >>> toYahooAerial(0, 0, 1) 68 (0, 0, 17) 69 >>> toYahooAerial(10507, 25322, 16) 70 (10507, 7445, 2) 71 >>> toYahooAerial(10482, 25333, 16) 72 (10482, 7434, 2) 73 19 (0, 0, 1) 20 >>> fromGoogleRoad(10507, 25322, 1) 21 (10507, 25322, 16) 22 >>> fromGoogleRoad(10482, 25333, 1) 23 (10482, 25333, 16) 24 25 >>> toGoogleRoad(0, 0, 1) 26 (0, 0, 16) 27 >>> toGoogleRoad(10507, 25322, 16) 28 (10507, 25322, 1) 29 >>> toGoogleRoad(10482, 25333, 16) 30 (10482, 25333, 1) 31 32 >>> fromGoogleAerial('tq') 33 (0, 0, 1) 34 >>> fromGoogleAerial('tqtsqrqtrtttqsqsr') 35 (10507, 25322, 16) 36 >>> fromGoogleAerial('tqtsqrqtqssssqtrt') 37 (10482, 25333, 16) 38 39 >>> toGoogleAerial(0, 0, 1) 40 'tq' 41 >>> toGoogleAerial(10507, 25322, 16) 42 'tqtsqrqtrtttqsqsr' 43 >>> toGoogleAerial(10482, 25333, 16) 44 'tqtsqrqtqssssqtrt' 74 45 */ 46 /* 47 >>> fromYahooRoad(0, 0, 17) 48 (0, 0, 1) 49 >>> fromYahooRoad(10507, 7445, 2) 50 (10507, 25322, 16) 51 >>> fromYahooRoad(10482, 7434, 2) 52 (10482, 25333, 16) 53 54 >>> toYahooRoad(0, 0, 1) 55 (0, 0, 17) 56 >>> toYahooRoad(10507, 25322, 16) 57 (10507, 7445, 2) 58 >>> toYahooRoad(10482, 25333, 16) 59 (10482, 7434, 2) 60 61 >>> fromYahooAerial(0, 0, 17) 62 (0, 0, 1) 63 >>> fromYahooAerial(10507, 7445, 2) 64 (10507, 25322, 16) 65 >>> fromYahooAerial(10482, 7434, 2) 66 (10482, 25333, 16) 67 68 >>> toYahooAerial(0, 0, 1) 69 (0, 0, 17) 70 >>> toYahooAerial(10507, 25322, 16) 71 (10507, 7445, 2) 72 >>> toYahooAerial(10482, 25333, 16) 73 (10482, 7434, 2) 74 75 */ 75 76 76 77 Coordinate c = fromMicrosoftRoad("0"); … … 91 92 e = fromMicrosoftAerial("0230102033330212"); 92 93 println(e.column == 25333.0 && e.row == 10482.0 && e.zoom == 16.0); 93 94 94 95 println( "0".equals( toMicrosoftAerial(0, 0, 1) ) ); 95 96 println( "0230102122203031".equals(toMicrosoftAerial(10507, 25322, 16) ) ); … … 98 99 } 99 100 100 101 102 /* 103 String[] octalStrings = { "000", "001", "010", "011", "100", "101", "110", "111" }; 104 105 def fromGoogleRoad(x, y, z) { 106 """ Return column, row, zoom for Google Road tile x, y, z. 107 """ 108 col = x 109 row = y 110 zoom = 17 - z 111 return col, row, zoom 112 113 def toGoogleRoad(col, row, zoom) { 114 """ Return x, y, z for Google Road tile column, row, zoom. 115 """ 116 x = col 117 y = row 118 z = 17 - zoom 119 return col, row, z 120 121 googleFromCorners = {'t' { '00', 's' { '01', 'q' { '10', 'r' { '11'} 122 googleToCorners = {'00' { 't', '01' { 's', '10' { 'q', '11' { 'r'} 123 124 def fromGoogleAerial(s) { 125 """ Return column, row, zoom for Google Aerial tile string. 126 """ 127 row, col = map(fromBinaryString, zip(*[list(googleFromCorners[c]) for c in s])) 128 zoom = len(s) - 1 129 row = int(math.pow(2, zoom) - row - 1) 130 return col, row, zoom 131 132 def toGoogleAerial(col, row, zoom) { 133 """ Return string for Google Road tile column, row, zoom. 134 """ 135 x = col 136 y = int(math.pow(2, zoom) - row - 1) 137 z = zoom + 1 138 y, x = toBinaryString(y).rjust(z, '0'), toBinaryString(x).rjust(z, '0') 139 string = ''.join([googleToCorners[y[c]+x[c]] for c in range(z)]) 140 return string 141 */ 101 Coordinate fromGoogleRoad(Coordinate coord) { 102 // Return column, row, zoom for Google Road tile x, y, z. 103 return new Coordinate(coord.row, coord.column, 17 - coord.zoom); 104 } 105 106 Coordinate toGoogleRoad(Coordinate coord) { 107 // Return x, y, z for Google Road tile column, row, zoom. 108 return new Coordinate(coord.row, coord.column, 17 - coord.zoom); 109 } 110 111 112 //googleFromCorners = {'t' { '00', 's' { '01', 'q' { '10', 'r' { '11'} 113 //googleToCorners = {'00' { 't', '01' { 's', '10' { 'q', '11' { 'r'} 114 115 Coordinate fromGoogleAerial(String s) { 116 // Return column, row, zoom for Google Aerial tile string. 117 String rowS = ""; 118 String colS = ""; 119 for (int i = 0; i < s.length(); i++) { 120 switch (s.charAt(i)) { 121 case 't': 122 rowS += '0'; 123 colS += '0'; 124 break; 125 case 's': 126 rowS += '0'; 127 colS += '1'; 128 break; 129 case 'q': 130 rowS += '1'; 131 colS += '0'; 132 break; 133 case 'r': 134 rowS += '1'; 135 colS += '1'; 136 break; 137 } 138 } 139 int row = unbinary(rowS); 140 int col = unbinary(colS); 141 int zoom = s.length() - 1; 142 row = (int)pow(2, zoom) - row - 1; 143 return new Coordinate( row, col, zoom ); 144 } 145 146 String toGoogleAerial(Coordinate coord) { 147 // Return string for Google Road tile column, row, zoom. 148 int x = (int)coord.column; 149 int y = (int)pow(2, coord.zoom) - (int)coord.row - 1; 150 int z = (int)coord.zoom + 1; 151 String yb = binary(y,z); 152 String xb = binary(x,z); 153 String string = ""; 154 String googleToCorners = "tsqr"; 155 for (int c = 0; c < z; c++) { 156 string += googleToCorners.charAt(unbinary("" + yb.charAt(c) + xb.charAt(c))); 157 } 158 return string; 159 } 142 160 143 161 /* 144 162 def fromYahoo(x, y, z) { 145 """ Return column, row, zoom for Yahoo x, y, z.146 """147 zoom = 18 - z148 row = int(math.pow(2, zoom - 1) - y - 1)149 col = x150 return col, row, zoom151 152 def toYahoo(col, row, zoom) {153 """ Return x, y, z for Yahoo tile column, row, zoom.154 """155 x = col156 y = int(math.pow(2, zoom - 1) - row - 1)157 z = 18 - zoom158 return x, y, z159 160 def fromYahooRoad(x, y, z) {161 """ Return column, row, zoom for Yahoo Road tile x, y, z.162 """163 return fromYahoo(x, y, z)164 165 def toYahooRoad(col, row, zoom) {166 """ Return x, y, z for Yahoo Road tile column, row, zoom.167 """168 return toYahoo(col, row, zoom)169 170 def fromYahooAerial(x, y, z) {171 """ Return column, row, zoom for Yahoo Aerial tile x, y, z.172 """173 return fromYahoo(x, y, z)174 175 def toYahooAerial(col, row, zoom) {176 """ Return x, y, z for Yahoo Aerial tile column, row, zoom.177 """178 return toYahoo(col, row, zoom)179 180 */163 """ Return column, row, zoom for Yahoo x, y, z. 164 """ 165 zoom = 18 - z 166 row = int(math.pow(2, zoom - 1) - y - 1) 167 col = x 168 return col, row, zoom 169 170 def toYahoo(col, row, zoom) { 171 """ Return x, y, z for Yahoo tile column, row, zoom. 172 """ 173 x = col 174 y = int(math.pow(2, zoom - 1) - row - 1) 175 z = 18 - zoom 176 return x, y, z 177 178 def fromYahooRoad(x, y, z) { 179 """ Return column, row, zoom for Yahoo Road tile x, y, z. 180 """ 181 return fromYahoo(x, y, z) 182 183 def toYahooRoad(col, row, zoom) { 184 """ Return x, y, z for Yahoo Road tile column, row, zoom. 185 """ 186 return toYahoo(col, row, zoom) 187 188 def fromYahooAerial(x, y, z) { 189 """ Return column, row, zoom for Yahoo Aerial tile x, y, z. 190 """ 191 return fromYahoo(x, y, z) 192 193 def toYahooAerial(col, row, zoom) { 194 """ Return x, y, z for Yahoo Aerial tile column, row, zoom. 195 """ 196 return toYahoo(col, row, zoom) 197 198 */ 181 199 182 200
