Skip to content

Commit baef276

Browse files
committed
Add a primitive SuperOverlay generator. Will only work with factor
of 2 resolution changes, and doesn't really seem to work as completely as I would like, but it's an interesting step forward.
1 parent 9b7d4a2 commit baef276

2 files changed

Lines changed: 71 additions & 1 deletion

File tree

pre-2.0/TileCache/Service.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,12 +137,18 @@ def expireTile (self, tile):
137137
self.cache.delete(coverage)
138138

139139
def dispatchRequest (self, params, path_info="/", req_method="GET", host="http://example.com/"):
140+
if path_info.split(".")[-1] == "kml":
141+
from TileCache.Services.KML import KML
142+
return KML(self).parse(params, path_info, host)
143+
raise TileCacheException("What, you think we do KML?")
144+
140145
if params.has_key("service") or params.has_key("SERVICE") or \
141146
params.has_key("REQUEST") and params['REQUEST'] == "GetMap" or \
142147
params.has_key("request") and params['request'] == "GetMap":
143148
from TileCache.Services.WMS import WMS
144149
tile = WMS(self).parse(params, path_info, host)
145-
elif params.has_key("L") or params.has_key("l"):
150+
elif params.has_key("L") or params.has_key("l") or \
151+
params.has_key("request") and params['request'] == "metadata":
146152
from TileCache.Services.WorldWind import WorldWind
147153
tile = WorldWind(self).parse(params, path_info, host)
148154
elif params.has_key("interface"):

pre-2.0/TileCache/Services/KML.py

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
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

Comments
 (0)