For my Java FX app, I need to display a lot of MapMarkers on my map.
In order to accelerate the map loading, I downloaded the Tiles for the Area I'm interested in, and I use LocalTileSourceFactory.
This works perfectly.
I need to display 10 000 markers on the map.
For each marker that I creates, I call
to add the marker on the ObservableList<Renderable> mapLayers attribute of the MapPane.
This also works, but each time the above methode is called, the RenderChangeListener is called to re-render the map.
This is time consuming (even for a single marker), so it is very very time consuming for my 10 000 markers.
Since this is done on the Java FX Application Thread, it blocks the UI for several seconds.
I tried to implement a custom javafx.concurrent.Task subclass, to perform all the expensive computation in a background thread.
But this fails because at some point, the RenderChangeListener is called (for each marker) and it needs to do its work on the UI Thread, so I get an exception (that actually kills my background thread)
So I have several questions :
1°) Why is it necessary to render everything when adding a MapMarker ?
RenderChangeListener calls renderControl(), which renders the map + the layers + the attributions
2°) Can I prevent the map from being rendered when iterating on my 10 000 map markers, and only perform one full render at the end ? This will probably save time
3°) How can I add 10 000 markers on a background thread, while the expansive computation (i.e. the marker rendering) needs to be done on the UI thread ?
Thanks for your insights !