auto reload map

This commit is contained in:
Dominik Heidler 2015-10-19 14:09:34 +02:00
parent 75d7722797
commit b69df7b1a1
4 changed files with 37 additions and 13 deletions

18
ffmap/mapnik/dynmapnik.py Normal file
View File

@ -0,0 +1,18 @@
#!/usr/bin/python2
import os
import logging
import TileStache
class DynMapnik(TileStache.Providers.Mapnik):
def __init__(self, *args, **kwargs):
self.mapfile_mtime = 0
TileStache.Providers.Mapnik.__init__(self, *args, **kwargs)
def renderArea(self, *args, **kwargs):
cur_mapfile_mtime = os.path.getmtime(self.mapfile)
if cur_mapfile_mtime > self.mapfile_mtime:
self.mapfile_mtime = cur_mapfile_mtime
if self.mapnik is not None:
self.mapnik = None
logging.info('TileStache.DynMapnik.ImageProvider.renderArea() detected mapfile change')
return TileStache.Providers.Mapnik.renderArea(self, *args, **kwargs)

7
ffmap/mapnik/setup.py Normal file
View File

@ -0,0 +1,7 @@
#!/usr/bin/python2
from distutils.core import setup
setup(name='dynmapnik',
version='1.0',
py_modules=['dynmapnik'],
)

View File

@ -6,27 +6,24 @@
"layers": {
"tiles/links_and_routers": {
"provider": {
"name": "mapnik",
"mapfile": "/usr/share/ffmap/links_and_routers.xml",
"layers": [
[0, null],
[1, null]
]
"class": "dynmapnik:DynMapnik",
"kwargs": {
"mapfile": "/usr/share/ffmap/links_and_routers.xml"
}
},
"metatile": {"buffer": 128},
"cache lifespan": 300
},
"tiles/hoods": {
"provider": {
"name": "mapnik",
"mapfile": "/usr/share/ffmap/hoods.xml",
"layers": [
[0, null],
[1, null]
]
"class": "dynmapnik:DynMapnik",
"kwargs": {
"mapfile": "/usr/share/ffmap/hoods.xml"
}
},
"metatile": {"buffer": 128},
"cache lifespan": 300
}
}
},
"logging": "info"
}

View File

@ -20,3 +20,5 @@ cp -v ffmap/systemd/*.service /etc/systemd/system/
systemctl daemon-reload
python3 setup.py install --force
(cd ffmap/mapnik; python2 setup.py install)