/usr/share/pyshared/TileCache/Layers/MapServer.py is in tilecache 2.11-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | # BSD Licensed, Copyright (c) 2006-2010 TileCache Contributors
from TileCache.Layer import MetaLayer
class MapServer(MetaLayer):
config_properties = [
{'name':'name', 'description': 'Name of Layer'},
{'name':'mapfile', 'description': 'Location of MapServer map file.'},
] + MetaLayer.config_properties
def __init__ (self, name, mapfile = None, styles = "", **kwargs):
MetaLayer.__init__(self, name, **kwargs)
self.mapfile = mapfile
self.styles = styles
def get_map(self, tile):
# tile is unused here but might be used in a subclass
# where the mapfile config depends on the tile extents or layer
import mapscript
wms = mapscript.mapObj(self.mapfile)
if self.metaBuffer:
try:
# if the metadata is already set, don't override.
wms.getMetaData("labelcache_map_edge_buffer")
except mapscript._mapscript.MapServerError:
# We stick an extra buffer of 5px in there because in the case
# of shields, we want to account for when the shield could get
# cut even though the label that the shield is on isn't.
buffer = -max(self.metaBuffer[0], self.metaBuffer[1]) - 5
wms.setMetaData("labelcache_map_edge_buffer", str(buffer))
return wms
def get_request(self, tile):
import mapscript
req = mapscript.OWSRequest()
req.setParameter("bbox", tile.bbox())
req.setParameter("width", str(tile.size()[0]))
req.setParameter("height", str(tile.size()[1]))
req.setParameter("srs", self.srs)
req.setParameter("format", self.mime_type)
req.setParameter("layers", self.layers)
req.setParameter("styles", self.styles)
req.setParameter("request", "GetMap")
return req
def renderTile(self, tile):
wms = self.get_map(tile)
req = self.get_request(tile)
wms.loadOWSParameters(req)
mapImage = wms.draw()
tile.data = mapImage.getBytes()
return tile.data
|