p = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, True, 8, self.win_x, self.win_y)
self.set_from_pixbuf(p)
- zoom = 11
- #lat = 40.4400226381
- #lon = -3.6880185362
+ zoom = 17
lat = 40.40491
lon = -3.6774
self.reftile_x , self.reftile_y = self.lon2tilex( lon , zoom ) , self.lat2tiley( lat , zoom )
+ self.zoom = zoom
# Half the size of a tile
self.refpix_x , self.refpix_y = 128 , 128
self.refpix_x , self.refpix_y = 0 , 0
- self.composeMap()
+ self.composeMap( zoom )
- def lon2tilex ( self , lon , zoom=11 ) :
+ def lon2tilex ( self , lon , zoom ) :
return int( ( lon + 180 ) / 360 * 2 ** zoom )
- def lat2tiley ( self , lat , zoom=11 ) :
+ def lat2tiley ( self , lat , zoom ) :
lat = lat * math.pi / 180
return int( ( 1 - math.log( math.tan( lat ) + 1 / math.cos( lat ) ) / math.pi ) / 2 * 2 ** zoom )
- def composeMap( self ) :
+ def composeMap( self , zoom ) :
center_x , center_y = self.win_x / 2 , self.win_y / 2
# To get the central pixel in the window center, we must shift to the tile origin
# Maybe they should be decided based on self.win_x, self.win_y
for i in range(-3,4) :
for j in range(-3,4) :
- file = self.tilename( i , j )
+ file = self.tilename( i , j , zoom )
if file is None :
pixbuf = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, False, 8, 256, 256 )
pixbuf.fill( 0x00000000 )
except gobject.GError , ex :
print "Corrupted file %s" % ( file )
os.unlink( file )
- #file = self.tilename( self.reftile_x + i , self.reftile_y + j )
- file = self.tilename( i , j )
+ #file = self.tilename( self.reftile_x + i , self.reftile_y + j , zoom )
+ file = self.tilename( i , j , zoom )
try :
pixbuf = gtk.gdk.pixbuf_new_from_file( file )
except :
pixbuf.copy_area( init_x, init_y, size_x, size_y, self.get_pixbuf(), dest_x , dest_y )
del(pixbuf)
- def tilename ( self , x , y , zoom=11 ) :
+ def tilename ( self , x , y , zoom ) :
file = self.tile2file( self.reftile_x + x , self.reftile_y + y , zoom )
try :
os.stat(file)
return None
return file
- def tile2file( self , tilex , tiley , zoom=11 ) :
+ def tile2file( self , tilex , tiley , zoom ) :
basedir = "/home/user/MyDocs/.maps/OpenStreetMap I"
rootdir = "%s/%s" % ( basedir , zoom )
if not os.path.isdir( rootdir ) :
self.refpix_x -= dx + 256 * tile_x
self.refpix_y -= dy + 256 * tile_y
- self.composeMap()
+ self.composeMap( self.zoom )
self.show()
def Up( self ) :
self.hide()
self.reftile_y -= 1
- self.composeMap()
+ self.composeMap( self.zoom )
self.show()
def Down( self ) :
self.hide()
self.reftile_y += 1
- self.composeMap()
+ self.composeMap( self.zoom )
self.show()
def Right( self ) :
self.hide()
self.reftile_x += 1
- self.composeMap()
+ self.composeMap( self.zoom )
self.show()
def Left( self ) :
self.hide()
self.reftile_x -= 1
- self.composeMap()
+ self.composeMap( self.zoom )
self.show()
class MapWindow: