|
| 1 | +from TileCache.Service import Request, Capabilities |
| 2 | +from TileCache.Services.TMS import TMS |
| 3 | +import TileCache.Layer as Layer |
| 4 | + |
| 5 | +class KML(TMS): |
| 6 | + def parse (self, fields, path, host): |
| 7 | + tile = TMS.parse(self,fields, path, host) |
| 8 | + tiles = [ |
| 9 | + Layer.Tile(tile.layer, tile.x << 1, tile.y << 1, tile.z + 1), |
| 10 | + Layer.Tile(tile.layer, (tile.x << 1) + 1, tile.y << 1, tile.z + 1), |
| 11 | + Layer.Tile(tile.layer, (tile.x << 1) + 1, (tile.y << 1) + 1, tile.z + 1), |
| 12 | + Layer.Tile(tile.layer, tile.x << 1 , (tile.y << 1) + 1, tile.z + 1) |
| 13 | + ] |
| 14 | + |
| 15 | + network_links = [] |
| 16 | + |
| 17 | + for single_tile in tiles: |
| 18 | + b = single_tile.bounds() |
| 19 | + network_links.append("""<NetworkLink> |
| 20 | + <name>tile</name> |
| 21 | + <Region> |
| 22 | + <Lod> |
| 23 | + <minLodPixels>128</minLodPixels><maxLodPixels>-1</maxLodPixels> |
| 24 | + </Lod> |
| 25 | + <LatLonAltBox> |
| 26 | + <north>%s</north><south>%s</south> |
| 27 | + <east>%s</east><west>%s</west> |
| 28 | + </LatLonAltBox> |
| 29 | + </Region> |
| 30 | + <Link> |
| 31 | + <href>%s/1.0.0/%s/%s/%s/%s.kml</href> |
| 32 | + <viewRefreshMode>onRegion</viewRefreshMode> |
| 33 | + </Link> |
| 34 | + </NetworkLink>""" % (b[3], b[1], b[2], b[0], host, single_tile.layer.name, single_tile.z, single_tile.x, single_tile.y)) |
| 35 | + |
| 36 | + b = tile.bounds() |
| 37 | + |
| 38 | + kml = """<?xml version="1.0" encoding="UTF-8"?> |
| 39 | +<kml xmlns="http://earth.google.com/kml/2.1"> |
| 40 | + <Document> |
| 41 | + <Region> |
| 42 | + <Lod> |
| 43 | + <minLodPixels>128</minLodPixels><maxLodPixels>-1</maxLodPixels> |
| 44 | + </Lod> |
| 45 | + <LatLonAltBox> |
| 46 | + <north>%s</north><south>%s</south> |
| 47 | + <east>%s</east><west>%s</west> |
| 48 | + </LatLonAltBox> |
| 49 | + </Region> |
| 50 | + <GroundOverlay> |
| 51 | + <drawOrder>5</drawOrder> |
| 52 | + <Icon> |
| 53 | + <href>%s/1.0.0/%s/%s/%s/%s</href> |
| 54 | + </Icon> |
| 55 | + <LatLonBox> |
| 56 | + <north>%s</north><south>%s</south> |
| 57 | + <east>%s</east><west>%s</west> |
| 58 | + </LatLonBox> |
| 59 | + </GroundOverlay> |
| 60 | + %s |
| 61 | + </Document> |
| 62 | +</kml>""" % (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)) |
| 63 | + |
| 64 | + return ("text/plain", kml) |
0 commit comments