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.
This commit is contained in:
7
gmap.py
7
gmap.py
@@ -15,6 +15,7 @@ helptext = """
|
|||||||
def main():
|
def main():
|
||||||
parser = OptionParser(usage=helptext)
|
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("-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()
|
options, args = parser.parse_args()
|
||||||
|
|
||||||
@@ -41,7 +42,7 @@ def main():
|
|||||||
if not os.path.exists(destdir):
|
if not os.path.exists(destdir):
|
||||||
os.mkdir(destdir)
|
os.mkdir(destdir)
|
||||||
zoom = world.get_quadtree_depth(mincol, maxcol, minrow, maxrow)
|
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."
|
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");
|
tiledir = os.path.join(destdir, "tiles");
|
||||||
@@ -51,11 +52,13 @@ def main():
|
|||||||
|
|
||||||
print "DONE"
|
print "DONE"
|
||||||
|
|
||||||
def write_html(path, zoomlevel):
|
def write_html(path, zoomlevel, cachelife):
|
||||||
templatepath = os.path.join(os.path.split(__file__)[0], "template.html")
|
templatepath = os.path.join(os.path.split(__file__)[0], "template.html")
|
||||||
html = open(templatepath, 'r').read()
|
html = open(templatepath, 'r').read()
|
||||||
html = html.replace(
|
html = html.replace(
|
||||||
"{maxzoom}", str(zoomlevel))
|
"{maxzoom}", str(zoomlevel))
|
||||||
|
html = html.replace(
|
||||||
|
"{cachelife}", str(cachelife))
|
||||||
|
|
||||||
with open(os.path.join(path, "index.html"), 'w') as output:
|
with open(os.path.join(path, "index.html"), 'w') as output:
|
||||||
output.write(html)
|
output.write(html)
|
||||||
|
|||||||
@@ -16,7 +16,8 @@
|
|||||||
fileExt: 'png',
|
fileExt: 'png',
|
||||||
tileSize: 384,
|
tileSize: 384,
|
||||||
defaultZoom: 1,
|
defaultZoom: 1,
|
||||||
maxZoom: {maxzoom}
|
maxZoom: {maxzoom},
|
||||||
|
cacheMinutes: {cachelife}
|
||||||
};
|
};
|
||||||
|
|
||||||
var MCMapOptions = {
|
var MCMapOptions = {
|
||||||
@@ -34,6 +35,8 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
url = url + '.' + config.fileExt;
|
url = url + '.' + config.fileExt;
|
||||||
|
var d = new Date();
|
||||||
|
url += '?c=' + Math.floor(d.getTime() / (1000 * 60 * config.cacheMinutes));
|
||||||
return(url);
|
return(url);
|
||||||
},
|
},
|
||||||
tileSize: new google.maps.Size(config.tileSize, config.tileSize),
|
tileSize: new google.maps.Size(config.tileSize, config.tileSize),
|
||||||
|
|||||||
Reference in New Issue
Block a user