1

I have a lot of features (thousands of) and some of them (~hundreds) change position/direction/state. So i tried to update layer/map with two ways as below:

  1. I update by setCoordinates: (data comes through socket.io)

    feature.getGeometry().setCoordinates(ol.proj.transform([data.longitude, data.latitude], 'EPSG:4326', 'EPSG:3857'));

  2. I created a global array that include all features and i set an interval (5 sec) and clear vector source and add features from global array again. By the way i update global array as below:

    // data: is an updated feature here. (position,direction and a custom state has been changed).

    var index = globalFeaturesArray.findIndex(feature => feature.getId() == data.getId()); globalFeaturesArray[index] = data; // new features' been set in global array

The problem is that if there are too many updated features, browser freezes while finding them in global array and replacing. Along the replacement, the new updates may come again and again (bottleneck). It happens same for first way too. It also re-calculate the cluster for every feature updates.

What's the best way to show features in openlayers map if they are getting updates constantly? I read topics about geoserver and WFS but i'm not sure if it is suitable for my situation? 100x feature may change position while 900x feature stand so wfs server will send me 1k feature again and again? This may happen huge and useless traffic between geoserver and clients?

Hope there is a better way to solve this problem in realtime!

  • 1
    I think you could improve a lot if you change your algorithm to update. Now you have a worst case of n*m (where n is globalFeaturesArray length and m is the number of features to update each time), you traverse the globalFeaturesArray for each update, this is not good.You could improve this in different ways. As an example, using a dictionary instead of an array. – cabesuon Jan 11 '20 at 20:03

0 Answers0