0

I have two VectorLayers setup, one for my actual features and another one for highlights (I'm rendering ~10000 features so I have a separate layer for highlight as recommended by ahocevar).

However, whenever I add/remove features to the highlight layer, it seems that the original layer is forced to be redrawn again, even though there was no interaction with that particular layer (besides hit detection).

Am I doing something wrong or does OL always rerenders all the layers when one of them changes?

  • OpenLayers currently uses a single canvas for the map and all layers are rendered to that. In the next release github.com/openlayers/openlayers/blob/master/changelog/… each layer will have its own canvas. You might want to test your code with the version 6 beta (for a quick test of the full build use openlayers.org/en/master/build/ol.js and openlayers.org/en/master/css/ol.css ) to see if there is any performance improvement. – Mike Feb 22 at 10:10
  • Also, if you are having performance issue with slow rendering of vectors make sure your style function is efficient and is using pre-generated styles wherever possible instead of creating new ones for each feature. – Mike Feb 22 at 10:11
  • I've now checked the OpenLayers example openlayers.org/en/v4.6.5/examples/vector-layer.html with version 4 and version 6 beta and pre/post compose/render events fire on both layers. So what you are seeing seems unavoidable at present. – Mike Feb 22 at 12:02
  • Thank you for your replies. All the styles are created beforehand and returned on the style function. I wonder if there is anyway to access the vectorContext outside of the render events? I could simply draw the highlighted feature directly to the canvas. – Thiatt Feb 22 at 16:29
  • With a single map canvas vectorContext = ol.render.toContext(map.getViewport().getElementsByTagName('canvas')[0].getContext('2d')); I'm not sure how to identify individual layer canvases in future versions. – Mike Feb 22 at 20:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.