Open Mobile Maps supports the WMTS (Web Map Tile Service) standard and can parse Capability XML files to automatically generate raster layer configurations.
Parsing WMTS Capabilities
Create a WMTS resource from a Capabilities XML document.
val resource = WmtsCapabilitiesResource.create(xml)
Creating Layers from WMTS
Once you have a WMTS capabilities resource, create layers using specific layer identifiers.
Android
iOS (SwiftUI)
iOS (UIKit)
val resource = WmtsCapabilitiesResource.create(xml)
val layer = resource.createLayer("identifier", dataLoader)
mapView.addLayer(layer.asLayerInterface())
With Custom Data Loader
val dataLoader = DataLoader(this, cacheDir, 50L * 1024L * 1024L, "example-referrer")
val resource = WmtsCapabilitiesResource.create(xml)
val layer = resource.createLayer("identifier", dataLoader)
mapView.addLayer(layer.asLayerInterface())
struct ContentView: View {
@State private var camera = MapView.Camera(
latitude: 46.962592372639634,
longitude: 8.378232525377973,
zoom: 1000000
)
@State private var layers: [any Layer] = []
var body: some View {
MapView(
camera: $camera,
layers: layers
)
.onAppear {
setupWMTSLayer()
}
}
private func setupWMTSLayer() {
guard let resource = MCWmtsCapabilitiesResource.create(xml),
let wmtsLayer = resource.createLayer("identifier", tileLoader: MCTextureLoader()) else {
return
}
layers = [wmtsLayer]
}
}
let resource = MCWmtsCapabilitiesResource.create(xml)!
let layer = resource.createLayer("identifier", tileLoader: MCTextureLoader())
mapView.add(layer: layer?.asLayerInterface())
Parameters
The WMTS GetCapabilities XML response as a string
The layer identifier from the WMTS capabilities document
Data loader for fetching tiles (Android)
Texture loader for fetching tiles (iOS)
WMTS Capabilities XML
A WMTS GetCapabilities response typically looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<Capabilities xmlns="http://www.opengis.net/wmts/1.0"
xmlns:ows="http://www.opengis.net/ows/1.1"
xmlns:xlink="http://www.w3.org/1999/xlink"
version="1.0.0">
<ows:ServiceIdentification>
<ows:Title>Example WMTS Service</ows:Title>
</ows:ServiceIdentification>
<Contents>
<Layer>
<ows:Title>Base Map</ows:Title>
<ows:Identifier>basemap</ows:Identifier>
<Style isDefault="true">
<ows:Identifier>default</ows:Identifier>
</Style>
<Format>image/png</Format>
<TileMatrixSetLink>
<TileMatrixSet>EPSG:3857</TileMatrixSet>
</TileMatrixSetLink>
</Layer>
<!-- Additional layers -->
</Contents>
</Capabilities>
Fetching WMTS Capabilities
You can fetch the capabilities XML from a WMTS service endpoint:
https://example.com/wmts?SERVICE=WMTS&REQUEST=GetCapabilities
Texture/Data Loaders
The Android implementation uses DataLoader which can be configured with caching:val dataLoader = DataLoader(
context = this,
cacheDir = cacheDir,
cacheSize = 50L * 1024L * 1024L, // 50 MB
referrer = "com.example.app"
)
The iOS implementation provides a default MCTextureLoader:let loader = MCTextureLoader()
You can also implement a custom texture loader by conforming to the TextureLoaderInterface.
Example: Complete WMTS Integration
// Fetch capabilities XML (pseudo-code)
val xml = fetchCapabilitiesXML("https://example.com/wmts?SERVICE=WMTS&REQUEST=GetCapabilities")
// Parse capabilities
val resource = WmtsCapabilitiesResource.create(xml)
// Create data loader
val dataLoader = DataLoader(this, cacheDir, 50L * 1024L * 1024L, "my-app")
// Create layer with specific identifier
val layer = resource.createLayer("basemap", dataLoader)
// Add to map
mapView.addLayer(layer.asLayerInterface())
This feature is still being improved to support a wider range of WMTS capabilities. Some WMTS services may not be fully supported.
Supported Features
- Parsing WMTS 1.0.0 GetCapabilities responses
- Layer creation from capability identifiers
- Automatic tile matrix configuration
- Multiple coordinate reference systems
- Custom data/texture loaders
Limitations
- Not all WMTS capability variations are currently supported
- Complex tile matrix sets may require additional configuration
- Some advanced WMTS features may need custom implementation