2

I have a layer which I have seeded in GeoServer using GWC in EPSG:3857. I have made sure that "Enable direct integration with GeoServer WMS" has been selected, however when I run the Openlayers code below, my CPU goes to close to 100% and the GeoServer logs says its tiling. I have the "tiled=true" option in the code, so I am trying to understand why the seeded tiles are not being used.

<!DOCTYPE html>
<html>
  <head>
    <title>Tiled WMS</title>
    <link rel="stylesheet" href="https://openlayers.org/en/v4.6.5/css/ol.css" type="text/css">
    <!-- The line below is only needed for old environments like Internet Explorer and Android 4.x -->
    <script src="https://cdn.polyfill.io/v2/polyfill.min.js?features=requestAnimationFrame,Element.prototype.classList,URL"></script>
    <script src="https://openlayers.org/en/v4.6.5/build/ol.js"></script>
  </head>
  <body>
    <div id="map" class="map"></div>
    <script>
      var layers = [
        new ol.layer.Tile({
          source: new ol.source.OSM()
        }),
        new ol.layer.Tile({
          source: new ol.source.TileWMS({
            url: 'http://localhost:8081/geoserver/cite/wms?',
            params: {'LAYERS': 'Flood 3', 'TILED': true},
            serverType: 'geoserver'
          })
        })
      ];
      var map = new ol.Map({
        layers: layers,
        target: 'map',
        view: new ol.View({
          center: [-177754,6960981],
          zoom: 4
        })
      });
    </script>
  </body>
</html>

I have also tried using the GeoWebCache endpoint URL option, http://localhost:8081/geoserver/gwc/service/wmts?, which works and the seed tiles are used, however there appears to be a loss in quality, see below.

enter image description here

At this point I am happy to use WMTS if the WMS option doesn't work but does anyone know why the quality of the tiles are lower for WMTS than WMS?

UPDATE:

For those having the same quality degradation issue I was having, it was because my resolutions were off. I used the "REQUEST=GetCapabilities" request to solve my problem. Here is the full code:

<!DOCTYPE html>
<html>
  <head>
    <title>WMTS Layer from Capabilities</title>
    <link rel="stylesheet" href="https://openlayers.org/en/v4.6.5/css/ol.css" type="text/css">
    <!-- The line below is only needed for old environments like Internet Explorer and Android 4.x -->
    <script src="https://cdn.polyfill.io/v2/polyfill.min.js?features=requestAnimationFrame,Element.prototype.classList,URL"></script>
    <script src="https://openlayers.org/en/v4.6.5/build/ol.js"></script>
  </head>
  <body>
    <div id="map" class="map"></div>
    <script>
      var parser = new ol.format.WMTSCapabilities();
      var map;

      fetch('http://localhost:8081/geoserver/cite/gwc/service/wmts?REQUEST=GetCapabilities').then(function(response) {
        return response.text();
      }).then(function(text) {
        var result = parser.read(text);
        var options = ol.source.WMTS.optionsFromCapabilities(result, {
          layer: 'Flood 3',
          matrixSet: 'EPSG:3857'
        });
        console.log(options)
        map = new ol.Map({
          layers: [
            new ol.layer.Tile({
              source: new ol.source.OSM(),
              opacity: 0.7
            }),
            new ol.layer.Tile({
              opacity: 1,
              source: new ol.source.WMTS(/** @type {!olx.source.WMTSOptions} */ (options))
            })
          ],
          target: 'map',
          view: new ol.View({
            projection: 'EPSG:3857',
            center: [0, 0],
            zoom: 2
          })
        });
      });
    </script>
  </body>
</html> 
2

As noted in the manual you must provide the tilesorigin option with the tiled option or GeoServer doesn't know where to start tiling from (remember each WMS request is stateless). You will also need to have WMS direct integration turned on in GeoWebCache and the following criteria must be met:

When this feature is enabled, GeoServer WMS will cache and retrieve tiles from GeoWebCache (via a GetMap request) only if all of the following criteria are followed:

WMS Direct integration is enabled (you can set this on the Caching defaults page)

tiled=true is included in the request

The request only references a single layer

Caching is enabled for that layer

The image requested is of the same height and width as the size saved in the layer configuration

The requested CRS matches one of the available tile layer gridsets

The image requested lines up with the existing grid bounds

A parameter is included for which there is a corresponding Parameter Filter

To be honest, I can't see a difference in your two images but the most likely problem is that you are requesting WMTS tiles at different resolutions than they are generated at and so OpenLayers is either compressing or expanding them slightly to match.

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.