3

I have gps coords features on a map and I want to add a line that shows the route of the feature , so I created an icon with long arrow (40px X 600px) I've noticed that the moment I pan the map and the feature is outside of the visible area , it disappears (although the icon should still be visible)

How can I keep the features from disappear outside the visible map ?

2
  • I'm not sure but isn't it a question of loading strategy ? We usually use a bbox strategy to load only the features that are within bbox extent, but it's possible to change that to load all features. Check the doc here : openlayers.org/en/latest/apidoc/ol.loadingstrategy.html Commented Nov 20, 2016 at 9:35
  • Maybe my solution is wrong , I want to draw a line to show the prediction of object advancement even when its outside of the visible area
    – Alophind
    Commented Nov 20, 2016 at 10:04

2 Answers 2

8
+50

ol.layer.Vector has a property called renderBuffer. This property will prevent the icons from disappearing if you set this to the pixel value of the longest side of your icon images, 600px in your example:

var vectorLayer = new ol.layer.Vector({
  source: vectorSource,
  renderBuffer: 600 // value in pixels
});

Demo code: https://plnkr.co/edit/R4qs5cmgEdYQCSu9c3gn -- Try changing the renderBuffer value in script.js, line 44 to see the result.

2
  • I will try this only later the week , but it looks like its suppose to work. thank you.
    – Alophind
    Commented Nov 24, 2016 at 14:58
  • Will this affect the performance in anyway? Commented Feb 22, 2019 at 13:32
0

This is perhaps not a correct solution, but setting useSpatialIndex to false on a VectorSource seems to allow a custom Style.renderer function to avoid disappearing when the feature geometry is out of view.

Disabling useSpatialIndex has ramifications (see the VectorSource docs), so it's best to use in a limited way.

Perhaps another method is to do something similar to the Graticule implementation, with a custom loader function.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.