0

In my OpenLayers 3 (v3.15.1) application, I use to load a larger amount of GeoJSON features on my map via an ol.Vector source and a custom loading fuction. This function receives the GeoJSON data from a webserver via Ajax and consequently adds it to the vector layer's source via my_layer.getSource().addFeatures(ol.format.GeoJSON().readFeatures()).

However, for about 30000 features and some custom styling rules applied, this makes the browser freeze for quite a while. While I do not mind that loading the data takes some time, the freeze makes the user feel as if the browser just crashed which is a bad feeling as we all know. Once the data is loaded, however, speed is not a concern since I wrap the vector features in an ImageVector layer which is pretty fast.

I think that the freeze comes from some OpenLayers 3 internals which add the features to the layer synchronously in the main thread.

Is there any possibility how the freeze can be avoided? I saw some other threads on similar topics where people talked about web workers. However, none of them had a solution yet, so maybe there are different ways as well.

  • 2
    Not a solution but rethinking the approach: Do you need to load and display all features at the same time? Would it be possible to cluster features in lower zoom levels and load only the features currently in the viewport in higher zoom levels? This way you would have a lower number of features to be drawn and maybe would avoid the freeze. Additionally: have you tested with different browsers on different computers? – bennos Apr 13 '16 at 8:20
  • True, when the desired asynchronous feature loading will not be possible, this will be the way to go. There is usually no need to display so many features at lower zoom levels where you can't see the majority of them anyway because they are covered by others. By the way, I accidentally tried this with around 100k features instead of 30000 - for the latter, the freeze is not that long of course. – Dirk Apr 15 '16 at 8:44

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.