From 32c2626b39ff2c5346f63a1e9bd41fb38b8a4129 Mon Sep 17 00:00:00 2001 From: Gregory Short Date: Tue, 7 Sep 2010 19:56:44 -0500 Subject: [PATCH] Added configurable option for controlling how long a tile will live in the browser's cache before being refetched. Good for configurations where the map will be automatically updated ona regular basis and the web browser's cache would get out of sync. Default is 24 hours. --- gmap.py | 7 +++++-- template.html | 5 ++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/gmap.py b/gmap.py index 7ff6de0..1a2a23c 100755 --- a/gmap.py +++ b/gmap.py @@ -15,6 +15,7 @@ helptext = """ def main(): parser = OptionParser(usage=helptext) parser.add_option("-p", "--processes", dest="procs", help="How many chunks to render in parallel. A good number for this is 1 more than the number of cores in your computer. Default 2", default=2, action="store", type="int") + parser.add_option("-c", "--cachelife", dest="cachelife", help="How many minutes a tile will be considered valid by the web browser before it fetches a new copy. Used if you have a crontab or similar running this every once in a while. Default is 24 hours.", default=1440, action="store", type="int") options, args = parser.parse_args() @@ -41,7 +42,7 @@ def main(): if not os.path.exists(destdir): os.mkdir(destdir) zoom = world.get_quadtree_depth(mincol, maxcol, minrow, maxrow) - write_html(destdir, zoom+1) + write_html(destdir, zoom+1, options.cachelife) print "Generating quad tree. This may take a while and has no progress bar right now, so sit tight." tiledir = os.path.join(destdir, "tiles"); @@ -51,11 +52,13 @@ def main(): print "DONE" -def write_html(path, zoomlevel): +def write_html(path, zoomlevel, cachelife): templatepath = os.path.join(os.path.split(__file__)[0], "template.html") html = open(templatepath, 'r').read() html = html.replace( "{maxzoom}", str(zoomlevel)) + html = html.replace( + "{cachelife}", str(cachelife)) with open(os.path.join(path, "index.html"), 'w') as output: output.write(html) diff --git a/template.html b/template.html index 079a19a..b314738 100644 --- a/template.html +++ b/template.html @@ -16,7 +16,8 @@ fileExt: 'png', tileSize: 384, defaultZoom: 1, - maxZoom: {maxzoom} + maxZoom: {maxzoom}, + cacheMinutes: {cachelife} }; var MCMapOptions = { @@ -34,6 +35,8 @@ } } url = url + '.' + config.fileExt; + var d = new Date(); + url += '?c=' + Math.floor(d.getTime() / (1000 * 60 * config.cacheMinutes)); return(url); }, tileSize: new google.maps.Size(config.tileSize, config.tileSize),