Openlayers Vector Rendering

المشرف العام

Administrator
طاقم الإدارة
I've just added a couple of more WFS backed vector layers to a map and the performance has dropped. Whilst debugging this I've noticed that openlayers is considering every feature in the visible layers when rendering.

If I'm zoomed right in so there are a only couple of features from a few layers and then say pan the map up a small amount. I'd expect openlayers to use a spatial index to identify which features need to be rendered and only render those.

However, I'm seeing my context based styles being asked for symbolizer info for every feature in every layer. E.g. my externalGraphic function is been called for features that are on the other side of the country!

externalGraphic: function(f) { return map.zoom < switchZoom ? icon : "/grails-app/feature/image/" + f.fid; }When zoomed out my layers are not visible but when zoomed in there are suddenly 1000s of feature being considered. Is there a way to get openlayers to use some filter when rendering? I had thought about adding map zoom/pan event handlers to map features in and out of layers using a spatial filter but I'm pretty sure I shouldn't have to do that.

I don't believe that the fact that my data originally comes from a WFS source is the issue here. My app also runs offline, the data, once retrieved is stored locally, the retrieval and resources needed to hold these in memory is fine.

There must be a way of getting OL to apply some intelligence when rendering vector features when zoomed in, it shouldn't be even considering rendering features that are hundreds of miles away from the current bounds, this is triggering retrieval of images from either the local file system or the server when I the zoom level switches from a generic icon to a more detailed device specific image.

In total I have about 5000 features, this should be a trivial amount. I've worked around this by handling move/zoom events and mapping my features in and out of the layers using a quad tree from the bespoke library I wrote years ago and want to move away from. This is an ugly hack that I find it hard to believe that that there is not a more elegant way to handle, I'd expect to provide the map with my vectors and let it manage them.



أكثر...
 
أعلى