diff --git a/pre-2.0/TileCache/Service.py b/pre-2.0/TileCache/Service.py index 8e3810b..78ac0cc 100755 --- a/pre-2.0/TileCache/Service.py +++ b/pre-2.0/TileCache/Service.py @@ -137,12 +137,18 @@ def expireTile (self, tile): self.cache.delete(coverage) def dispatchRequest (self, params, path_info="/", req_method="GET", host="http://example.com/"): + if path_info.split(".")[-1] == "kml": + from TileCache.Services.KML import KML + return KML(self).parse(params, path_info, host) + raise TileCacheException("What, you think we do KML?") + if params.has_key("service") or params.has_key("SERVICE") or \ params.has_key("REQUEST") and params['REQUEST'] == "GetMap" or \ params.has_key("request") and params['request'] == "GetMap": from TileCache.Services.WMS import WMS tile = WMS(self).parse(params, path_info, host) - elif params.has_key("L") or params.has_key("l"): + elif params.has_key("L") or params.has_key("l") or \ + params.has_key("request") and params['request'] == "metadata": from TileCache.Services.WorldWind import WorldWind tile = WorldWind(self).parse(params, path_info, host) elif params.has_key("interface"): diff --git a/pre-2.0/TileCache/Services/KML.py b/pre-2.0/TileCache/Services/KML.py new file mode 100644 index 0000000..fd63b84 --- /dev/null +++ b/pre-2.0/TileCache/Services/KML.py @@ -0,0 +1,64 @@ +from TileCache.Service import Request, Capabilities +from TileCache.Services.TMS import TMS +import TileCache.Layer as Layer + +class KML(TMS): + def parse (self, fields, path, host): + tile = TMS.parse(self,fields, path, host) + tiles = [ + Layer.Tile(tile.layer, tile.x << 1, tile.y << 1, tile.z + 1), + Layer.Tile(tile.layer, (tile.x << 1) + 1, tile.y << 1, tile.z + 1), + Layer.Tile(tile.layer, (tile.x << 1) + 1, (tile.y << 1) + 1, tile.z + 1), + Layer.Tile(tile.layer, tile.x << 1 , (tile.y << 1) + 1, tile.z + 1) + ] + + network_links = [] + + for single_tile in tiles: + b = single_tile.bounds() + network_links.append(""" + tile + + + 128-1 + + + %s%s + %s%s + + + + %s/1.0.0/%s/%s/%s/%s.kml + onRegion + + """ % (b[3], b[1], b[2], b[0], host, single_tile.layer.name, single_tile.z, single_tile.x, single_tile.y)) + + b = tile.bounds() + + kml = """ + + + + + 128-1 + + + %s%s + %s%s + + + + 5 + + %s/1.0.0/%s/%s/%s/%s + + + %s%s + %s%s + + + %s + +""" % (b[3], b[1], b[2], b[0], host, tile.layer, tile.z, tile.x, tile.y, b[3], b[1], b[2], b[0], "\n".join(network_links)) + + return ("text/plain", kml)