1

I cached my map hoping to use it with openlayers. This is my code below.

    var layers = [
    new ol.layer.Image({
      source: new ol.source.ImageWMS({
        url: 'http://0.0.0.0:8080/geoserver/wms',
        params: {'LAYERS': 'silapha:basemap'},
        ratio: 1,
        serverType: 'geoserver'
      })
    })
  ];

  var map = new ol.Map({
    layers: layers,
    target: 'map',
    view: new ol.View({
      center: [0, 869099],
      zoom: 7
    })
  });

This still renders the old uncached layer. I enable direct wms integration as well but I can't just render the cached map.

This this is the url to the cached map and the preview works well. http://0.0.0.0:8080/geoserver/gwc/demo/silapha:basemap?gridSet=EPSG:900913&format=image/png

What have i done wrong, what should add to the code to get the cache tile rendering instead of the uncached one.

2

As described in this example you need to use a Tile Layer with a TileWMS source:

new ol.layer.Tile({
      extent: [-13884991, 2870341, -7455066, 6338219],
      source: new ol.source.TileWMS({
        url: 'https://ahocevar.com/geoserver/wms',
        params: {'LAYERS': 'topp:states', 'TILED': true},
        serverType: 'geoserver'
      })
    })
  ];

By using an ImageWMS Source you request one big image which will always defeat the cache.

1
  • It works so smoothly. So the problem is with ImageWMS instead of TileWMS
    – saviour123
    May 16 '17 at 17:31
0

I believe I read the question a little differently and that you want to retrieve your layers from geowebcache, rather than using tiled wms. This example will do that, and show how to set up the tilegrid.

var mylayer = new ol.layer.Tile({
    source: new ol.source.WMTS({
        url: 'http://0.0.0.0:8080/geoserver/gwc/service/wmts',
        layer: 'silapha:basemap',
        format: 'image/png',
        matrixSet: 'EPSG:900913',
        tileGrid: tileGrid,
    })
});

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.