sep. map, view and control classes

git-svn-id: http://www.neo1973-germany.de/svn@29 46df4e5c-bc4e-4628-a0fc-830ba316316d
This commit is contained in:
emdete 2008-03-12 08:11:29 +00:00
parent 5cf999b48c
commit 86c0f82b35

View file

@ -58,7 +58,26 @@ class Mark(evas.Image):
self.position = (x,y) self.position = (x,y)
self.move(x,y) self.move(x,y)
class Pylgrim(edje.Edje): class PylgrimMap(object):
def download(self, x,y,z):
filename = "%d/%d/%d.png"%(z,x,y)
print 'download', filename
try:
dirname = "%d/%d"%(z,x)
if not os.path.exists(dirname):
os.makedirs(dirname)
localFile = open(filename, 'w')
webFile = urllib.urlopen("http://a.tile.openstreetmap.org/%d/%d/%d.png"%(z,x,y))
localFile.write(webFile.read())
webFile.close()
localFile.close()
except Exception, e:
print 'download error', e
if os.path.exists(filename):
os.unlink(filename)
class PylgrimView(edje.Edje, PylgrimMap):
def __init__(self, evas_canvas, filename, initial_lat, initial_lon, initial_zoom=10, offline=False, use_overlay=True): def __init__(self, evas_canvas, filename, initial_lat, initial_lon, initial_zoom=10, offline=False, use_overlay=True):
self.evas_canvas = evas_canvas self.evas_canvas = evas_canvas
self.offline = offline self.offline = offline
@ -162,11 +181,13 @@ class Pylgrim(edje.Edje):
return True return True
def position(self, content): def position(self, content):
latitude = float(content.get('latitude', self.lat)) fix = int(content.get('fix', 0))
longitude = float(content.get('longitude', self.lon)) if fix:
print 'position', latitude, longitude latitude = float(content.get('latitude', self.lat))
if not self.animate: longitude = float(content.get('longitude', self.lon))
self.set_current_tile(latitude, longitude, self.z) print 'position', latitude, longitude
if not self.animate:
self.set_current_tile(latitude, longitude, self.z)
def on_key_down(self, obj, event): def on_key_down(self, obj, event):
if event.keyname in ("F6", "f"): if event.keyname in ("F6", "f"):
@ -209,23 +230,6 @@ class Pylgrim(edje.Edje):
self.init_redraw() self.init_redraw()
self.update_coordinates() self.update_coordinates()
def download(self, x,y,z):
filename = "%d/%d/%d.png"%(z,x,y)
print 'download', filename
try:
dirname = "%d/%d"%(z,x)
if not os.path.exists(dirname):
os.makedirs(dirname)
localFile = open(filename, 'w')
webFile = urllib.urlopen("http://a.tile.openstreetmap.org/%d/%d/%d.png"%(z,x,y))
localFile.write(webFile.read())
webFile.close()
localFile.close()
except Exception, e:
print 'download error', e
if os.path.exists(filename):
os.unlink(filename)
#jump to coordinates #jump to coordinates
def set_current_tile(self, lat, lon, z): def set_current_tile(self, lat, lon, z):
#update shown coordinates everytime they change #update shown coordinates everytime they change
@ -410,6 +414,10 @@ class Pylgrim(edje.Edje):
#self.marker.set_position(self.marker.pos[0]-delta_x,self.marker.pos[1]-delta_y) #self.marker.set_position(self.marker.pos[0]-delta_x,self.marker.pos[1]-delta_y)
class PylgrimControl(PylgrimView):
def __init__(self, evas_canvas, filename, initial_lat, initial_lon, initial_zoom=10, offline=False, use_overlay=True):
PylgrimView.__init__(self, evas_canvas, filename, initial_lat, initial_lon, initial_zoom=10, offline=False, use_overlay=True)
if __name__ == "__main__": if __name__ == "__main__":
WIDTH = 480 WIDTH = 480
HEIGHT = 640 HEIGHT = 640
@ -504,7 +512,7 @@ if __name__ == "__main__":
size=options.geometry size=options.geometry
) )
filename = os.path.splitext(sys.argv[0])[0] + ".edj" filename = os.path.splitext(sys.argv[0])[0] + ".edj"
Pylgrim(evas_canvas, filename, 49.009051, 8.402481, 13, options.offline, ) PylgrimControl(evas_canvas, filename, 49.009051, 8.402481, 13, options.offline, )
ecore.main_loop_begin() ecore.main_loop_begin()
''' '''