From 71f056c75cb35056243a660f139441ab4ab78486 Mon Sep 17 00:00:00 2001 From: Simon Daron Date: Sat, 25 Apr 2020 06:53:58 +0200 Subject: [PATCH] Use prerender and postrender events on Vector Clipping Layer example for better readability --- examples/layer-clipping-vector.js | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/examples/layer-clipping-vector.js b/examples/layer-clipping-vector.js index 46d922acbc..82b318916d 100644 --- a/examples/layer-clipping-vector.js +++ b/examples/layer-clipping-vector.js @@ -13,25 +13,22 @@ const base = new TileLayer({ }); const clipLayer = new VectorLayer({ - style: null, + style: new Style({ + fill: new Fill({ + color: 'black', + }), + }), source: new VectorSource({ url: './data/geojson/switzerland.geojson', format: new GeoJSON(), }), }); -const style = new Style({ - fill: new Fill({ - color: 'black', - }), +clipLayer.on('prerender', function (e) { + e.context.globalCompositeOperation = 'destination-in'; }); -base.on('postrender', function (e) { - e.context.globalCompositeOperation = 'destination-in'; - const vectorContext = getVectorContext(e); - clipLayer.getSource().forEachFeature(function (feature) { - vectorContext.drawFeature(feature, style); - }); +clipLayer.on('postrender', function (e) { e.context.globalCompositeOperation = 'source-over'; });