I am new to web mapping and web in general.

I'm adding the default WMTS Italy mosaic that can be found in GeoServer (nurc:mosaic) to my map by following these examples: http://openlayers.org/en/latest/examples/wmts-capabilities.html https://openlayers.org/en/latest/examples/wmts-layer-from-capabilities.html

I downloaded wmts-getcapabilities xml file from my GeoServer's web admin page, simply by clicking on WMTS's 1.0.0. Then saved it within the same directory with my Italy_mosaic_OpenLayers.html file.

how the directory looks like

And here is how my Italy_mosaic_OpenLayers.html looks like :

var parser = new ol.format.WMTSCapabilities();

var map;

fetch('wmts-getcapabilities.xml').then(function(response) {
    return response.text();
}).then(function(text) {
    var result = parser.read(text);

    var options = ol.source.WMTS.optionsFromCapabilities(result, {
        layer: 'nurc:mosaic',
        matrixSet: 'EPSG:4326',
        format: 'image/png'

    map = new ol.Map({
        layers: [
            new ol.layer.Tile({
                source: new ol.source.OSM(),
                opacity: 1
            new ol.layer.Tile({
                opacity: 0.6,
                source: new ol.source.WMTS(/** @type {!olx.source.WMTSOptions} */ (options))
        target: 'map',
        view: new ol.View({
            center: ol.proj.fromLonLat([22, 42]),
            zoom: 5,

This code works only when my "wmts-getcapabilities.xml" file is in the same directory with my "Italy_mosaic_OpenLayers.html" file. However if I were to renew my Italy_ mosaic raster file I would have to download "wmts-getcapabilities.xml" file again and place it to the same directory(by the "Italy_mosaic_OpenLayers.html" file) again.

To avoid replacement of the xml file again and again, I tried to put 'http://localhost:8081/geoserver/gwc/service/wmts?REQUEST=GetCapabilities' instead of 'wmts-getcapabilities-xml' in my code, however I had a blank page. I also tried different matrixSet-projection combinations; no matter what matrixSet-projection combination I tried (I tried 9 possibilities, 3 for each (4326,3857 and 900913)), with fetch('http://localhost:8081/geoserver/gwc/service/wmts?REQUEST=GetCapabilities') I always had a blank page (not gray).

Here is my fiddle https://jsfiddle.net/qjcadvzq/15/

What am I missing ?


In the OL example that you have linked, the WMTSCapabilities.xml is read not read locally but directly from the server. You don't want any manual intervention between the server and the webapp, so it is better to always read the file from the server.

 fetch('https://openlayers.org/en/v4.6.4/examples/data/WMTSCapabilities.xml').then(function(response) { ...

which can turn into

fetch('http://localhost:8081/geoserver/gwc/service/wmts?request=getcapabilities').then(function(response) { ...

You said

I downloaded wmts-getcapabilities xml file from my GeoServer's web admin page, simply by clicking on WMTS's 1.0.0

You can copy the link from there instead of the file, and use this link as the URL in the above code.

  • When I copy the link location for WMTS 1.0.0 and paste it inside fetch like the following: fetch('http://localhost:8081/geoserver/gwc/service/wmts?REQUEST=GetCapabilities') I get a blank page. I also tried http://localhost:8081/geoserver/gwc/service/wmts? and http://localhost:8081/geoserver/gwc/service/wmts?REQUEST=getcapabilities&VERSION=1.0.0 and http://localhost:8081/geoserver/gwc/service/wmts?request=getcapabilities they don't work either. – Kaner Levent Feb 19 '18 at 14:56
  • Does this http://localhost:8081/geoserver/gwc/service/wmts?REQUEST=GetCapabilities url give you the capabilities file when you open it in a browser? If it doesn't, check if the service is disabled? – pavankguduru Feb 23 '18 at 8:12
  • @pavankguduru Pasting [link] (localhost:8081/geoserver/gwc/service/…) to the browser opens up a window and asks open with or save the xml file. To check whether the service disabled, I followed this [link]docs.geoserver.org/stable/en/user/geowebcache/webadmin/… In my GeoServer Provided Services Enable direct integration with GeoServer WMS Enable WMS-C Service Enable TMS Service Enable Data Security there is no checkbox for Enable WMTS Service like shown in the followed link. – Kaner Levent Feb 23 '18 at 8:59
  • @pavankguduru However under GeoServer Caching Defaults - Go to the embedded GeoWebCache home page I have GetCapabilities: WMTS 1.0.0 GetCapabilities document WMS 1.1.1 GetCapabilities document TMS 1.0.0 document Note that the latter will only work with clients that are WMS-C capable. Omitting tiled=true from the URL will omit the TileSet elements. – Kaner Levent Feb 23 '18 at 9:00
  • If it's giving you the xml file the problem is not with the url. Can you add the code where you replaced the url? – pavankguduru Feb 23 '18 at 9:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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