Jens Müller wrote:
Am 14.02.2010 13:25, schrieb Andreas Titz:
I display the tiles with pymap (which in in the svn [1]), but I extended
that script a little bit, so that it can handle the t...@h-tilesets (zip-files)
directly.
[1]http://trac.openstreetmap.org/browser/applications/viewer/pymap
Can you send your extension?
Here it is (as attachment).
To use ist, you have to install the attached file parallel to the
original pymap-file. Create a directory tiles/osma.zip additionally to
the existing tiles/osma. Then you can put your created tilesets into the
osma.zip dir.
If you have a connection to the internet, then you can populate the
other dirs in tiles with the original pymap (for instance for
mapnik-tiles or the lowzoom t...@h-tiles).
My pymap-zip won't connect to the internet at all. It serves only the
pre-fetched tiles or tiles from a tileset-file.
You can put your own slippymap application into the dir planer. To
display it, you have to enter the URI http://localhost:8008/index.html
(or http://localhost:8008/planer/index.html if you installed an own
slippy map) into your browser.
HTH, Andreas
#!/usr/bin/python
# licensed under a BSD license of your choice
import urllib,re,os,sys,stat,errno,socket,time,socket,zipfile
from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer
class MyHttpHandler(BaseHTTPRequestHandler):
query_string=''
def fetch_tile(self):
"""Retrieve a tile from a remote server and store it locally"""
m= re.compile('/tiles/(\w+)/(\d+)/(\d+)/(\d+).png').match(self.path)
if not m: return None
(layer,z,x,y)=(m.group(1),m.group(2),m.group(3),m.group(4))
localpath = installpath + '/tiles/' + layer + '/' + z + '/' + x + '/' + y +
'.png'
if int(z) < 12: return False
zipX = int(x) >> ( int(z) - 12 )
zipY = int(y) >> ( int(z) - 12 )
zippath = installpath + '/tiles/' + layer + '.zip/tile_12_' + str(zipX) +
'_' + str(zipY) + '_17592.zip'
zip = zipfile.ZipFile(zippath, 'r')
file = zip.read('tile_' + z + '_' + x + '_' + y + '.png')
zip.close()
outfile = open(installpath + '/tile_tmp.png', 'w')
outfile.write(file)
outfile.close()
return True
def return_file(self,path):
if path.endswith(".png"):contenttype='image/png'
elif path.endswith('.js'):contenttype='text/javascript'
elif path.endswith('.css'):contenttype='text/css'
elif path.endswith('.gpx'):contenttype='application/x-gpx+xml'
else: contenttype='text/html'
try:
f = open(installpath + path, 'rb')
self.send_response(200)
self.send_header('Content-type',contenttype)
self.end_headers()
self.wfile.write(f.read())
f.close()
return
except IOError:
self.send_error(404,'File Not Found: %s' % self.path)
except socket.error:
#client most likely aborted connection (zooming etc)
return None
def do_GET(self):
if self.path.find('?') != -1:
(self.path, self.query_string) = self.path.split('?', 1)
if self.path=='/': self.return_file('/index.html')
elif self.path.startswith('/JaSE'):self.return_file(self.path)
elif self.path.startswith('/planer'):self.return_file(self.path)
elif self.path.startswith('/static'):self.return_file(self.path)
elif self.path.startswith('/tiles'):
try:
os.stat(installpath+self.path)
self.return_file(self.path)
except os.error, e:
if e.errno == errno.ENOENT:
print "FETCHING missing tile from zip:"+self.path
if self.fetch_tile():
self.return_file('/tile_tmp.png')
else:
self.send_error(404,'File Not Found: %s' % self.path)
else:
raise
else: self.send_error(404,'File Not Found: %s' % self.path)
return
#main():
installpath=sys.path[0]
server = HTTPServer(('127.0.0.1', 8008), MyHttpHandler)
server.serve_forever()
_______________________________________________
Tilesathome mailing list
[email protected]
http://lists.openstreetmap.org/listinfo/tilesathome