1

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();
});

1 Answer 1

0

You would need to change the clipping rectangle to the left side of the swipe

ctx.rect(0, 0, width, ctx.canvas.height);

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.