Search code examples
openlayers

on postcompose in ol6 - how to draw on canvas on every render


In ol6 the rendering context was removed from the postcompose event (according to the release notes).

How would I achieve to draw on a context on every render of one of the map layers? Currently (ol < 6) I simply was drawing on the context in postcompose. I already tried to add a separate vector layer and to draw in the postrender - but did not find an easy way to ensure a render on this layer if one of the lower layers is rendered (e.g. due to pan/zoom/...). Currently I guess I have to move outside of Openlayers and create an own canvas context on top of the map - so I can still draw in the postcompose (into my own context) . Not very elegant however...


Solution

  • A radius 0 circle will not be seen but with infinite render buffer there should always be a postrender event

    new ol.layer.Vector({
        source: new ol.source.Vector({
            features: [new ol.Feature(new ol.geom.Point([0,0]))]
        }),
        style: new ol.style.Style({
            image: new ol.style.Circle({
                radius: 0
            })
        }),
        renderBuffer: Infinity,
        zIndex: Infinity
    });