[OpenLayers-Users] Best strategy to implement show/hide for large sets of features ?

Jérôme Petazzoni jerome.petazzoni at sipartech.com
Fri Feb 26 13:04:27 EST 2010


Jérôme Petazzoni wrote:
> I think that my current implementation is a bit naive, since each time I 
> check/uncheck a folder, I :
> - create a new StyleMap,
> - apply the KML styles,
> - apply a dynamic "foldervisibility" map (containing, for each folder, a 
> {display:'none'} if the folder should be hidden),
> - redraw the layer.
> This approach worked well enough at first (displaying 150 linestrings 
> with ~10 points per linestring), but when I added the "points" layer 
> with 250 point features, it started to be really slow.
>   
Actually, after using Firebug's excellent profiler module, I discovered 
that my browser was spending most of its time evaluating style rules.
Investigating a bit more, I discovered that my KML file had more than 
1000 styles, but only ~50 of them were used.
But my code was stupidly creating 1000 style rules anyway, and running 
thru all those style rules for *each* feature at *each* pan/zoom was 
painfully slow.
I added some code to discard the unused styles, and the application is 
now fast and smooth again.

So I guess I won't have to try other approaches (yet) ; and I will 
definitely (ab)use the profiler when I have performance problems instead 
of asking silly questions ! :-)

Regards,




More information about the Users mailing list