adjusted pathes

git-svn-id: http://www.neo1973-germany.de/svn@71 46df4e5c-bc4e-4628-a0fc-830ba316316d
This commit is contained in:
emdete 2008-04-04 06:28:07 +00:00
parent f4b55d18c7
commit b599c882ce

View file

@ -33,19 +33,24 @@ from dbus import SystemBus, Interface
import time import time
import math import math
from urllib2 import build_opener from urllib2 import build_opener
from freesmartphone import DBUS_NAME, DIN_LOCATION
from base import dedbusmap
def err(*data):
print 'err', data
class PylgrimMap(object): class PylgrimMap(object):
def __init__(self): def __init__(self):
self.opener = build_opener() self.opener = build_opener()
def download(self, x,y,z): def download(self, x, y, zoom):
filename = "%d/%d/%d.png"%(z,x,y) filename = "%d/%d/%d.png"%(zoom, x, y)
print 'download', filename print 'download', filename
try: try:
dirname = "%d/%d"%(z,x) dirname = "%d/%d"%(zoom, x)
if not os.path.exists(dirname): if not os.path.exists(dirname):
os.makedirs(dirname) os.makedirs(dirname)
localFile = open(filename, 'w') localFile = open(filename, 'w')
webFile = self.opener.open("http://a.tile.openstreetmap.org/%d/%d/%d.png"%(z,x,y)) webFile = self.opener.open("http://a.tile.openstreetmap.org/%d/%d/%d.png"%(zoom, x, y))
localFile.write(webFile.read()) localFile.write(webFile.read())
webFile.close() webFile.close()
localFile.close() localFile.close()
@ -79,7 +84,7 @@ class PylgrimView(edje.Edje, PylgrimMap):
self.position = (x, y) self.position = (x, y)
self.move(x, y) self.move(x, y)
def __init__(self, evas_canvas, filename, initial_lat, initial_lon, initial_zoom=10, offline=False, use_overlay=True): def __init__(self, evas_canvas, filename, latitude, longitude, zoom=10, offline=False, use_overlay=True):
PylgrimMap.__init__(self) PylgrimMap.__init__(self)
self.evas_canvas = evas_canvas self.evas_canvas = evas_canvas
self.offline = offline self.offline = offline
@ -104,12 +109,12 @@ class PylgrimView(edje.Edje, PylgrimMap):
self.tiles_to_download_total = 0 self.tiles_to_download_total = 0
self.tiles_to_preload = [] self.tiles_to_preload = []
#initial lat,lon,zoom #initial latitude, longitude, zoom
self.lat = initial_lat self.latitude = latitude
self.lon = initial_lon self.longitude = longitude
self.x = 0 self.x = 0
self.y = 0 self.y = 0
self.z = initial_zoom self.zoom = zoom
self.offset_x = 0 self.offset_x = 0
self.offset_y = 0 self.offset_y = 0
@ -150,46 +155,50 @@ class PylgrimView(edje.Edje, PylgrimMap):
self.animate = False self.animate = False
self.set_current_tile(initial_lat, initial_lon, initial_zoom) self.set_current_tile(self.latitude, self.longitude, zoom)
''' '''
self.marker = PylgrimView.Mark(self.evas_canvas.evas_obj.evas) self.marker = PylgrimView.Mark(self.evas_canvas.evas_obj.evas)
self.marker.file_set("blue-dot.png") self.marker.file_set("blue-dot.png")
self.marker.lat = 49.073866 self.marker.latitude = 49.073866
self.marker.lon = 8.184814 self.marker.longitude = 8.184814
self.marker.size_set(32, 32) self.marker.size_set(32, 32)
self.marker.fill_set(0, 0, 32, 32) self.marker.fill_set(0, 0, 32, 32)
self.marker.x = (self.marker.lon+180)/360 * 2**self.z self.marker.x = (self.marker.longitude+180)/360 * 2**self.zoom
self.marker.y = (1-math.log(math.tan(self.marker.lat*math.pi/180) + 1/math.cos(self.marker.lat*math.pi/180))/math.pi)/2 * 2**self.z self.marker.y = (1-math.log(math.tan(self.marker.latitude*math.pi/180) + 1/math.cos(self.marker.latitude*math.pi/180))/math.pi)/2 * 2**self.zoom
self.marker.offset_x, self.marker.offset_y = int((self.marker.x-int(self.marker.x))*256), int((self.marker.y-int(self.marker.y))*256) self.marker.offset_x, self.marker.offset_y = int((self.marker.x-int(self.marker.x))*256), int((self.marker.y-int(self.marker.y))*256)
self.marker.set_position(self.size[0]/2-16+256*(int(self.marker.x)-int(self.x))+self.marker.offset_x-self.offset_x, self.size[1]/2-32+256*(int(self.marker.y)-int(self.y))+self.marker.offset_y-self.offset_y) self.marker.set_position(self.size[0]/2-16+256*(int(self.marker.x)-int(self.x))+self.marker.offset_x-self.offset_x, self.size[1]/2-32+256*(int(self.marker.y)-int(self.y))+self.marker.offset_y-self.offset_y)
self.marker.layer = 1 self.marker.layer = 1
self.marker.show() self.marker.show()
''' '''
#ecore.timer_add(3, self.init_dbus) ecore.timer_add(3, self.init_dbus)
def init_dbus(self): def init_dbus(self):
print 'LocationFeed init_dbus' print 'PylgrimView init_dbus'
try: try:
gps_obj = SystemBus(mainloop=DBusEcoreMainLoop()).get_object('org.mobile.gps', '/org/mobile/gps/RemoteObject') gps_obj = SystemBus(mainloop=DBusEcoreMainLoop()).get_object(DBUS_NAME,
gps_name = 'org.mobile.gps.RemoteInterface' #'/org/mobile/GoogleLocation',
gps_obj.connect_to_signal("position", self.position, dbus_interface=gps_name) '/org/mobile/GpsLocation',
self.gps_interface = Interface(gps_obj, gps_name) )
#self.gps_interface.get_position() gps_obj.connect_to_signal("position", self.position, dbus_interface=DIN_LOCATION)
self.gps_interface = Interface(gps_obj, DIN_LOCATION)
self.gps_interface.GetPosition(reply_handler=self.position, error_handler=err, )
return False return False
except Exception, e: except Exception, e:
print 'LocationFeed', e print 'PylgrimView', e
return True return True
def position(self, content): def position(self, content):
content = dedbusmap(content)
print 'position', content
fix = int(content.get('fix', 0)) fix = int(content.get('fix', 0))
if fix: if fix:
latitude = float(content.get('latitude', self.lat)) latitude = float(content.get('latitude', self.latitude))
longitude = float(content.get('longitude', self.lon)) longitude = float(content.get('longitude', self.longitude))
print 'position', latitude, longitude print 'position', latitude, longitude
if not self.animate: if not self.animate:
self.set_current_tile(latitude, longitude, self.z) self.set_current_tile(latitude, longitude, self.zoom)
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"):
@ -233,20 +242,20 @@ class PylgrimView(edje.Edje, PylgrimMap):
self.update_coordinates() self.update_coordinates()
#jump to coordinates #jump to coordinates
def set_current_tile(self, lat, lon, z): def set_current_tile(self, latitude, longitude, zoom):
#update shown coordinates everytime they change #update shown coordinates everytime they change
self.overlay.part_text_set("label", "lat:%f lon:%f zoom:%d"%(lat,lon,z)) self.overlay.part_text_set("label", "latitude:%f longitude:%f zoom:%d"%(latitude, longitude, zoom))
x = (lon+180)/360 * 2**z x = (longitude+180)/360 * 2**zoom
y = (1-math.log(math.tan(lat*math.pi/180) + 1/math.cos(lat*math.pi/180))/math.pi)/2 * 2**z y = (1-math.log(math.tan(latitude*math.pi/180) + 1/math.cos(latitude*math.pi/180))/math.pi)/2 * 2**zoom
offset_x, offset_y = int((x-int(x))*256), int((y-int(y))*256) offset_x, offset_y = int((x-int(x))*256), int((y-int(y))*256)
#only redraw if x, y, z, offset_x or offset_y differ from before #only redraw if x, y, zoom, offset_x or offset_y differ from before
if int(x) != int(self.x) \ if int(x) != int(self.x) \
or int(y) != int(self.y) \ or int(y) != int(self.y) \
or z != self.z \ or zoom != self.zoom \
or offset_x != self.offset_x \ or offset_x != self.offset_x \
or offset_y != self.offset_y: or offset_y != self.offset_y:
self.z = z self.zoom = zoom
self.x = x self.x = x
self.y = y self.y = y
self.offset_x, self.offset_y = offset_x, offset_y self.offset_x, self.offset_y = offset_x, offset_y
@ -269,9 +278,9 @@ class PylgrimView(edje.Edje, PylgrimMap):
#add all tiles that are not yet downloaded to a list #add all tiles that are not yet downloaded to a list
for i in xrange(2*self.border_x+1): for i in xrange(2*self.border_x+1):
for j in xrange(2*self.border_y+1): for j in xrange(2*self.border_y+1):
if not os.path.exists("%d/%d/%d.png"%(self.z,self.x+i-self.border_x,self.y+j-self.border_y))\ if not os.path.exists("%d/%d/%d.png"%(self.zoom, self.x+i-self.border_x, self.y+j-self.border_y))\
and not (self.z,self.x+i-self.border_x,self.y+j-self.border_y) in self.tiles_to_download: and not (self.zoom, self.x+i-self.border_x, self.y+j-self.border_y) in self.tiles_to_download:
self.tiles_to_download.append((self.z,self.x+i-self.border_x,self.y+j-self.border_y)) self.tiles_to_download.append((self.zoom, self.x+i-self.border_x, self.y+j-self.border_y))
self.tiles_to_download_total = len(self.tiles_to_download) self.tiles_to_download_total = len(self.tiles_to_download)
''' '''
#add additional tiles around the raster to a preload list #add additional tiles around the raster to a preload list
@ -279,8 +288,8 @@ class PylgrimView(edje.Edje, PylgrimMap):
if i == 0 or i == 2*self.border_x+2: if i == 0 or i == 2*self.border_x+2:
#if first or last row, download full row #if first or last row, download full row
for j in xrange(2*self.border_y+3): for j in xrange(2*self.border_y+3):
if not os.path.exists("%d/%d/%d.png"%(self.z,self.x+i-self.border_x-1,self.y+j-self.border_y-1)): if not os.path.exists("%d/%d/%d.png"%(self.zoom, self.x+i-self.border_x-1, self.y+j-self.border_y-1)):
self.tiles_to_preload.append((self.z,self.x+i-self.border_x-1,self.y+j-self.border_y-1)) self.tiles_to_preload.append((self.zoom, self.x+i-self.border_x-1, self.y+j-self.border_y-1))
#lots TODO here #lots TODO here
#let preload more than one tile - maybe a preload_border_x/y variable #let preload more than one tile - maybe a preload_border_x/y variable
#manage simultaneos proeloads #manage simultaneos proeloads
@ -297,18 +306,18 @@ class PylgrimView(edje.Edje, PylgrimMap):
def download_and_paint_current_tiles(self): def download_and_paint_current_tiles(self):
if len(self.tiles_to_download) > 0: if len(self.tiles_to_download) > 0:
z,x,y = self.tiles_to_download.pop() zoom, x, y = self.tiles_to_download.pop()
if self.use_overlay: if self.use_overlay:
self.progress.geometry = 40, self.size[1]/2, (self.size[0]-80)*(self.tiles_to_download_total-len(self.tiles_to_download))/self.tiles_to_download_total, 20 self.progress.geometry = 40, self.size[1]/2, (self.size[0]-80)*(self.tiles_to_download_total-len(self.tiles_to_download))/self.tiles_to_download_total, 20
self.overlay.part_text_set("progress", "downloaded %d of %d tiles"%(self.tiles_to_download_total-len(self.tiles_to_download), self.tiles_to_download_total)) self.overlay.part_text_set("progress", "downloaded %d of %d tiles"%(self.tiles_to_download_total-len(self.tiles_to_download), self.tiles_to_download_total))
self.download(x,y,z) self.download(x, y, zoom)
return True return True
#we get here if all tiles are downloaded #we get here if all tiles are downloaded
for i in xrange(2*self.border_x+1): for i in xrange(2*self.border_x+1):
for j in xrange(2*self.border_y+1): for j in xrange(2*self.border_y+1):
#if some errors occur replace with placeholder #if some errors occur replace with placeholder
filename = "%d/%d/%d.png"%(self.z,self.x+i-self.border_x,self.y+j-self.border_y) filename = "%d/%d/%d.png"%(self.zoom, self.x+i-self.border_x, self.y+j-self.border_y)
try: try:
self.icons[(2*self.border_y+1)*i+j].file_set(filename) self.icons[(2*self.border_y+1)*i+j].file_set(filename)
except Exception, e: except Exception, e:
@ -330,27 +339,27 @@ class PylgrimView(edje.Edje, PylgrimMap):
def update_coordinates(self): def update_coordinates(self):
x = int(self.x) + (self.offset_x-self.current_pos[0])/256.0 x = int(self.x) + (self.offset_x-self.current_pos[0])/256.0
y = int(self.y) + (self.offset_y-self.current_pos[1])/256.0 y = int(self.y) + (self.offset_y-self.current_pos[1])/256.0
self.lon = (x*360)/2**self.z-180 self.longitude = (x*360)/2**self.zoom-180
n = math.pi*(1-2*y/2**self.z) n = math.pi*(1-2*y/2**self.zoom)
self.lat = 180/math.pi*math.atan(0.5*(math.exp(n)-math.exp(-n))) self.latitude = 180/math.pi*math.atan(0.5*(math.exp(n)-math.exp(-n)))
self.overlay.part_text_set("label", "lat:%f lon:%f zoom:%d"%(self.lat,self.lon,self.z)) self.overlay.part_text_set("label", "latitude:%f longitude:%f zoom:%d"%(self.latitude, self.longitude, self.zoom))
def zoom_in(self, z): def zoom_in(self, zoom):
for icon in self.icons: for icon in self.icons:
x = (1+z)*(icon.position[0]-self.size[0]/2)+self.size[0]/2 x = (1+zoom)*(icon.position[0]-self.size[0]/2)+self.size[0]/2
y = (1+z)*(icon.position[1]-self.size[1]/2)+self.size[1]/2 y = (1+zoom)*(icon.position[1]-self.size[1]/2)+self.size[1]/2
icon.geometry = int(x),int(y),256+int(256*z),256+int(256*z) icon.geometry = int(x), int(y), 256+int(256*zoom), 256+int(256*zoom)
icon.fill = 0, 0, 256+int(256*z),256+int(256*z) icon.fill = 0, 0, 256+int(256*zoom), 256+int(256*zoom)
def zoom_out(self, z): def zoom_out(self, zoom):
for icon in self.icons: for icon in self.icons:
x = (1-z*0.5)*(icon.position[0]-self.size[0]/2)+self.size[0]/2 x = (1-zoom*0.5)*(icon.position[0]-self.size[0]/2)+self.size[0]/2
y = (1-z*0.5)*(icon.position[1]-self.size[1]/2)+self.size[1]/2 y = (1-zoom*0.5)*(icon.position[1]-self.size[1]/2)+self.size[1]/2
icon.geometry = int(x),int(y),256-int(256*z*0.5),256-int(256*z*0.5) icon.geometry = int(x), int(y), 256-int(256*zoom*0.5), 256-int(256*zoom*0.5)
icon.fill = 0, 0, 256-int(256*z*0.5),256-int(256*z*0.5) icon.fill = 0, 0, 256-int(256*zoom*0.5), 256-int(256*zoom*0.5)
def animate_zoom_in(self): def animate_zoom_in(self):
if self.z < 18: if self.zoom < 18:
self.animate = True self.animate = True
if self.zoom_step < 1.0: if self.zoom_step < 1.0:
self.zoom_in(self.zoom_step) self.zoom_in(self.zoom_step)
@ -358,13 +367,13 @@ class PylgrimView(edje.Edje, PylgrimMap):
return True return True
self.zoom_step = 0.0 self.zoom_step = 0.0
self.set_current_tile(self.lat, self.lon, self.z+1) self.set_current_tile(self.latitude, self.longitude, self.zoom+1)
else: else:
self.animate = False self.animate = False
return False return False
def animate_zoom_out(self): def animate_zoom_out(self):
if self.z > 5: if self.zoom > 5:
self.animate = True self.animate = True
if self.zoom_step < 1.0: if self.zoom_step < 1.0:
self.zoom_out(self.zoom_step) self.zoom_out(self.zoom_step)
@ -372,7 +381,7 @@ class PylgrimView(edje.Edje, PylgrimMap):
return True return True
self.zoom_step = 0.0 self.zoom_step = 0.0
self.set_current_tile(self.lat, self.lon, self.z-1) self.set_current_tile(self.latitude, self.longitude, self.zoom-1)
else: else:
self.animate = False self.animate = False
return False return False
@ -417,8 +426,8 @@ class PylgrimView(edje.Edje, PylgrimMap):
#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): class PylgrimControl(PylgrimView):
def __init__(self, evas_canvas, filename, initial_lat, initial_lon, initial_zoom=10, offline=False, use_overlay=True): def __init__(self, evas_canvas, filename, latitude, longitude, 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) PylgrimView.__init__(self, evas_canvas, filename, latitude, longitude, zoom=10, offline=False, use_overlay=True)
if __name__ == "__main__": if __name__ == "__main__":
WIDTH = 480 WIDTH = 480
@ -506,6 +515,7 @@ if __name__ == "__main__":
def on_delete_request(self, evas_obj): def on_delete_request(self, evas_obj):
ecore.main_loop_quit() ecore.main_loop_quit()
print 'start', __name__
options, args = myOptionParser(usage="usage: %prog [options]").parse_args() options, args = myOptionParser(usage="usage: %prog [options]").parse_args()
edje.frametime_set(1.0 / options.fps) edje.frametime_set(1.0 / options.fps)
evas_canvas = EvasCanvas( evas_canvas = EvasCanvas(
@ -516,11 +526,4 @@ if __name__ == "__main__":
filename = os.path.splitext(sys.argv[0])[0] + ".edj" filename = os.path.splitext(sys.argv[0])[0] + ".edj"
PylgrimControl(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()
# vim:tw=0:nowrap
'''
export CPPFLAGS="$CPPFLAGS -I/opt/e17/include"
export LDFLAGS="$LDFLAGS -L/opt/e17/lib"
export PKG_CONFIG_PATH="/opt/e17/lib/pkgconfig:$PKG_CONFIG_PATH"
export PATH="$PATH:/opt/e17/bin"
export PYTHONPATH="/home/josch/usr/lib/python2.5/site-packages"
'''