def __init__(self, layer, osmFile, watermark, cacheDir): import TileCache.Service from TileCache.Caches.Disk import Disk from TileCache.Layers.Mapnik import Mapnik self.layer = Mapnik(layer, mapfile=osmFile, watermarkimage=watermark, watermarkopacity=1.0) self.tileService = TileCache.Service(Disk(cacheDir), {"layer": self.layer})
def get_eb_layer(name): # svc = Service.load(settings.TILECACHE_CONFIG) mapfile = r"/data/oceancolor/terra/L3m/2017/001/T2017001_L3m_DAY_NSST_sst_4km.map" svc = Service( Disk('/tmp/somecache'), # See "Cache Invalidation", below { "raster": MS.MapServer("basic", mapfile, layers="raster", srs='EPSG:4326', debug=False), }) ''' svc = Service( Disk('/tmp/somecache'), # See "Cache Invalidation", below { "raster": WMS.WMS("basic", r"http://localhost/cgi-bin/mapserv.cgi?map=/data/oceancolor/aqua/L3m/2017/001/A2017001.L3m_DAY_SST_sst_4km.map&mode=map&layer=raster", srs='EPSG:4326', width='256', height='256'), } ) ''' return svc.layers[name]
# hackish way to grab style obj and avoid parsing XML each request... m = mapnik.Map(1, 1) mapnik.load_map(m, settings.MAPNIK_STYLESHEET) style = m.find_style('style') del m srv = None if settings.CACHE_SEARCH_METHOD == 'mem': srv = Service( Memcached(), {}, # layers are dynamic ) else: srv = Service( Disk(settings.CACHE_SEARCH_DISK_PATH), {}, # layers are dynamic ) query_hash = {} class TileResponse(object): def __init__(self, tile_bytes): self.tile_bytes = tile_bytes def __call__(self, extension='png'): if self.tile_bytes: # mod_python handler in django borkes unless mimetype is string return HttpResponse(self.tile_bytes, mimetype=str('image/%s' % extension))
def set(self, tile, data): data = optimize_png(data) Disk.set(self, tile, data)
def __init__ (self, **kwargs): Disk.__init__(self, **kwargs) warnings.warn("GoogleDisk type is deprecated. use a Disk cache and set the structure to google", DeprecationWarning)