I used the Layer Swipe for an app with OL5, like this example and it work perfectly for compare the baselayer with a new layer on the right side. But how to set a layer for the left side to ? I could change baselayer, but it appear behind the layer on right side, and I don't want.
var anneeCouche = "2016_20cm";
var _rasterSource = new ol.source.TileWMS({
url: 'http://serveradress/geoserver/raster/wms?',
params: {LAYERS: 'raster:ortho'+anneeCouche}
});
function changeDateRight(annee) {
if (annee === '2013') {
var anneeCouche = "2013_20cm";
} else {
var anneeCouche = "2016_20cm";
};
_rasterSource.updateParams({LAYERS: 'raster:ortho'+anneeCouche});
};
var _rightLayer = new ol.layer.Tile({
title: 'Ortho',
source: _rasterSource
});
_rightLayer.on('precompose', function(event) {
var ctx = event.context;
var width = ctx.canvas.width * (swipe.value / 100);
ctx.save();
ctx.beginPath();
ctx.rect(width, 0, ctx.canvas.width - width, ctx.canvas.height);
ctx.clip();
});
_rightLayer.on('postcompose', function(event) {
var ctx = event.context;
ctx.restore();
});