@@ -18,6 +18,8 @@ namespace TileMapService.Controllers
18
18
[ Route ( "tms" ) ]
19
19
public class TmsController : ControllerBase
20
20
{
21
+ private const string Version = "1.0.0" ;
22
+
21
23
private readonly ITileSourceFabric tileSourceFabric ;
22
24
23
25
public TmsController ( ITileSourceFabric tileSourceFabric )
@@ -35,7 +37,7 @@ public IActionResult GetRootResource()
35
37
return File ( EC . XmlDocumentToUTF8ByteArray ( xmlDoc ) , MediaTypeNames . Text . Xml ) ;
36
38
}
37
39
38
- [ HttpGet ( "1.0.0" ) ]
40
+ [ HttpGet ( Version ) ]
39
41
public IActionResult GetTileMapService ( )
40
42
{
41
43
// TODO: services/tilemapservice.xml
@@ -45,20 +47,21 @@ public IActionResult GetTileMapService()
45
47
return File ( EC . XmlDocumentToUTF8ByteArray ( xmlDoc ) , MediaTypeNames . Text . Xml ) ;
46
48
}
47
49
48
- [ HttpGet ( "1.0.0 /{tileset}") ]
50
+ [ HttpGet ( Version + " /{tileset}") ]
49
51
public IActionResult GetTileMap ( string tileset )
50
52
{
51
53
// TODO: services/basemap.xml
52
54
var capabilities = this . GetCapabilities ( ) ;
53
- var layer = capabilities . Layers ? . SingleOrDefault ( l => l . Identifier == tileset ) ;
55
+ var layer = capabilities . Layers . SingleOrDefault ( l => l . Identifier == tileset ) ;
54
56
if ( layer == null )
55
57
{
56
58
return NotFound ( ) ; // TODO: errors in XML format
57
59
}
58
-
59
- var xmlDoc = new Tms . CapabilitiesUtility ( capabilities ) . GetTileMap ( layer ) ;
60
-
61
- return File ( EC . XmlDocumentToUTF8ByteArray ( xmlDoc ) , MediaTypeNames . Text . Xml ) ;
60
+ else
61
+ {
62
+ var xmlDoc = new Tms . CapabilitiesUtility ( capabilities ) . GetTileMap ( layer ) ;
63
+ return File ( EC . XmlDocumentToUTF8ByteArray ( xmlDoc ) , MediaTypeNames . Text . Xml ) ;
64
+ }
62
65
}
63
66
64
67
/// <summary>
@@ -70,7 +73,7 @@ public IActionResult GetTileMap(string tileset)
70
73
/// <param name="z">Tile Z coordinate (zoom level).</param>
71
74
/// <param name="extension">File extension.</param>
72
75
/// <returns>Response with tile contents.</returns>
73
- [ HttpGet ( "1.0.0 /{tileset}/{z}/{x}/{y}.{extension}") ]
76
+ [ HttpGet ( Version + " /{tileset}/{z}/{x}/{y}.{extension}") ]
74
77
public async Task < IActionResult > GetTileAsync ( string tileset , int x , int y , int z , string extension , CancellationToken cancellationToken )
75
78
{
76
79
// TODO: z can be a string, not integer number
@@ -108,19 +111,18 @@ public async Task<IActionResult> GetTileAsync(string tileset, int x, int y, int
108
111
109
112
private Tms . Capabilities GetCapabilities ( )
110
113
{
111
- var layers = EC . SourcesToLayers ( this . tileSourceFabric . Sources ) ;
112
114
return new Tms . Capabilities
113
115
{
116
+ BaseUrl = this . BaseUrl ,
117
+ Layers = EC . SourcesToLayers ( this . tileSourceFabric . Sources ) ,
114
118
ServiceTitle = this . tileSourceFabric . ServiceProperties . Title ,
115
119
ServiceAbstract = this . tileSourceFabric . ServiceProperties . Abstract ,
116
- BaseUrl = this . BaseUrl ,
117
- Layers = layers . ToArray ( ) ,
118
120
} ;
119
121
}
120
122
121
123
private string BaseUrl => $ "{ this . Request . Scheme } ://{ this . Request . Host } { this . Request . PathBase } ";
122
124
123
- private IActionResult ResponseWithNotFoundError ( string message )
125
+ private FileContentResult ResponseWithNotFoundError ( string message )
124
126
{
125
127
var xmlDoc = new Tms . TileMapServerError ( message ) . ToXml ( ) ;
126
128
Response . ContentType = MediaTypeNames . Text . XmlUtf8 ;
0 commit comments