5

I am using the Leaflet.TileLayer.WMTS plugin (https://github.com/mylen/leaflet.TileLayer.WMTS). However, I believe that this only works with WMTSes which add parameters to GetTile requests as querystring variables in key=val pairs (eg http://www.provider.net/path?var1=val1&var2=val2 etc). I need to add a WMTS which uses a URL path for its parameters (eg http://www.provider.net/path/val1/val2 etc). The WMTS in question is https://www.basemap.at/wmts/1.0.0/WMTSCapabilities.xml.

The way other clients handle this is by parsing the GetCapabilities URL, which provides the parameter mapping for GetTile requests. I see that OpenLayers has a method for parsing GetCapabilities to add the WMTS (https://openlayers.org/en/latest/examples/wmts-layer-from-capabilities.html).

I'm aware that at least one other question has this as the underlying issue (https://stackoverflow.com/questions/44300140/wmts-layer-syntax-for-leaflet), but it doesn't make it clear what the underlying problem is, so I thought it was worth asking a new question.

I know that I can either read the GetCapabilities XML myself (or look at network requests from a working client) and determine the structure to add a plain XYZ tileserver. However, I am trying to code this into qgis2web, which needs to accomplish this programmatically.

So, is there any way of adding a WMTS to a Leaflet webmap if you only have the URL for its GetCapabilities method?

5
  • 3
    each layer available in the service should be listed in the GetCapabilities XML with it's specific ressource URL as template. why don't you try to load and parse the XML and read out the specific nodes? that's pretty much what OL does, albeit more sophisticated for universal use...
    – geozelot
    Commented Jan 18, 2018 at 11:15
  • got it to work?
    – geozelot
    Commented Jan 19, 2018 at 14:05
  • 1
    Not yet, and not accepted your answer yet, purely in the hope that someone might have a solution which uses any established lib to parse the GetCapabilities, rather than the hard-coding you've done (which I don't doubt works). Investigated whether the OL function could be easily ported, but it depends on a bunch of other OL modules. I'm sure it could be done, but I don't think I could do it. It would be a hugely valuable addition to Leaflet.TileLayer.WMTS, though. Commented Jan 19, 2018 at 14:08
  • 1
    true that. well, the most unflexible (hardcoded) part is the one where the subdomains are listed to an array (maps, maps1, ...). the URL parameters (e.g. {TileMatrix}, {TileRow}, {TileCol} being the z, y, x tile index, as well as {TileMatrixSet}, {Layer} and {Style}) are part of the WMTS standard and are more or less universal (provided that the service host honors it). the server subdomain names however are not, being subject to the providers taste or whatever, thus the hardcoded part. it is consistent throughout the above service, though.
    – geozelot
    Commented Jan 19, 2018 at 14:51
  • 1
    I need to start implementing a more universal approach myself, starting next week I think. if you like we can further discuss this in chat, I opened a room for this?
    – geozelot
    Commented Jan 19, 2018 at 15:59

1 Answer 1

5

I made a jsfiddle to give you an example of how to create a L.tileLayer from your GetCapabilities document.

It's a quick mockup and could be improved a lot (absolutely no error handling, XML search is rather naive etc.), but gives you an idea about how to get going.

Note: you can use a layer name of your choice, but there is no further dynamics in creating the base URL for the L.tileLayer. All further value parsing is hardcoded (e.g. see the part where the subdomains are extracted and listed). More versatile parsing would require a lot more effort in string matching and so forth...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.