[OpenLayers-Users] Best strategy to implement show/hide for large
sets of features ?
Jérôme Petazzoni
jerome.petazzoni at sipartech.com
Thu Feb 25 10:38:49 EST 2010
Hi all,
I have coded a GeoDJango app to import a KML file into a PostGIS
database, preserving folders and styles.
I can successfully display the features (or "placemarks" in KML
terminology) on my OpenLayers map, serving them with FeatureServer.
Each feature has a folder_id and a style_id attribute.
I also have two custom webservices, generating JSON documents :
- one with the styles to be used for each feature (and loaded using
StyleMap.addUniqueValueRules),
- another with the hierarchy of folders.
The hierarchy of folders is then displayed (using ExtJS Ext.tree),
allowing to show/hide folders (and features contained into folders) - in
a manner similar to Google Earth.
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.
I have four layers right now : a WMS background map, and three Vector
layers (for points, linestrings and polygons).
I am considering two other methods :
1. Use one distinct layer for each KML folder, and toggle layer
visibility when the user checks/unchecks a folder.
Since I have ~50 folders (and probably hundreds when the app will be in
production), I am wondering if OpenLayers is supposed to behave nicely
with large number of layers ?
2. Maintain (client-side or server-side) a mapping to associate a folder
with the list of features contained into the folder.
In that case, should I toggle each feature visibility and redraw them
one by one, or is there a more efficient way (like, toggling visibility
and redrawing the whole layer, or submitting the list of modified
features...?)
Any comment about those methods will be more than welcome ! :-)
By the way, if anyone thinks that the KML->GeoDjango importer can be
useful, it will be made public (but it's still at preliminary stages,
therefore not very well documented nor written, to be honnest!)
Best regards,
More information about the Users
mailing list