Camptocamp – News

2018 OpenLayers 6 code sprint

26 November 2018

Last week took place a 1-week OpenLayers code sprint in Saas-Fee, Switzerland, with 6 participants from Camptocamp, Boundless Geo and Planet Labs.

Mainly funded by Swisstopo, this code sprint was aimed at generally improving the rendering performances of OpenLayers, and more specifically for vector tiles rendering.

Vector tiles support has been in OpenLayers for around 3 years, including Mapbox tile and style formats, and has been receiving regular improvements since then. Still, for all the benefits they bring, vector tiles are often large chunks of data which take a long time to process and render in an interactive map.

The perspective of releasing version 6 of OpenLayers and making backwards-incompatible changes to the library allowed for a lot of freedom in reworking the code base in depth. This is exactly what happened during the week, as several major changes were merged into the master branch.

Replacement of the previous Canvas2D map renderer with a composition system using DOM elements

The use of DOM elements for composition was already there in previous versions of OL; now that most browsers offer very good performance when compositing images, this solution was reintroduced as the default one, bringing much more flexibility to layer types.

One example of this is using the Mapbox GL JS library for a layer on an OpenLayers map.

Preparation work to anticipate the use of Web Workers in vector tiles rendering

Web Workers is a widely supported standard that allows multi-thread processing in a web browser. This is commonly used for intensive tasks, which are common in vector tiles rendering.

Most of the Replay Group system (objects used for drawing shapes on screen) has been refactored to be usable partly in Web Workers. This has been a significant task which is still ongoing.

Many optimizations regarding vector tile rendering

A benchmarking system was also put into place alongside, which helped monitor the improvements made on the rendering side and general user experience. The benchmarks produce two output values for each scenario: average frame time and max frame time (computed over many iterations). At the end of the codesprint, the improvement on the average frame time was around 20% with many optimizations still left to carry out.

The legacy WebGL renderers which have been part of OpenLayers since version 3 have been removed (this includes raster tiles, image layers, vector layers)

This decision was the logical follow-up of a few simple observations:

  • The WebGL renderers have not received enough attention and maintenance over the years to be fully production-ready, at least not all of them
  • Keeping them up-to-date with the recent overhaul of the rendering system would have a considerable cost
  • Most of the time their performances are on par with the Canvas2D renderers, if not worse

However, this was not just about removing things. WebGL rendering can be relevant for some edge cases, such as rendering millions of points, displaying special effects, post-processing, etc.

As such, some of the existing WebGL code was reworked to offer a lower level toolkit for using WebGL on custom layer types. This was used to rewrite the already existing Heatmap layer, offering better performances and user experience overall.

The work initiated during the code sprint will continue in the months to come: expect more blog posts from Camptocamp on this topic!

Many thanks to everyone involved in organizing and funding this event, and to those who keep making OpenLayers a great web mapping library, years after years. The future is promising and we cannot wait to be there already!