BUGFIX : zoom turned into a member variable to properly handle zoom changes
authorjaviplx <javiplx@gmail.com>
Fri, 4 Jun 2010 09:02:30 +0000 (09:02 +0000)
committerjaviplx <javiplx@gmail.com>
Fri, 4 Jun 2010 09:02:30 +0000 (09:02 +0000)
git-svn-id: file:///svnroot/wifihood/trunk/wifiscanner@8 c51dfc6a-5949-4919-9c8e-f207a149c383

wifiview

index 0b07de9..ce26e21 100755 (executable)
--- a/wifiview
+++ b/wifiview
@@ -20,26 +20,25 @@ class mapWidget(gtk.Image):
     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
@@ -50,7 +49,7 @@ class mapWidget(gtk.Image):
     # 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 )
@@ -60,8 +59,8 @@ class mapWidget(gtk.Image):
           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 :
@@ -93,7 +92,7 @@ class mapWidget(gtk.Image):
             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)
@@ -114,7 +113,7 @@ class mapWidget(gtk.Image):
         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 ) :
@@ -134,31 +133,31 @@ class mapWidget(gtk.Image):
     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: