[OpenLayers-Users] How to check of a layer is correctly loaded (created)

DeDuikertjes DeDuikertjes at xs4all.nl
Tue Oct 20 10:32:26 EDT 2009


Dear List,

I'm trying to load a layer and on failure create an empty layer to draw
features on.
I cannot find a test to see if the layer loaded ok.

I've tried things like:
commentaarLayer = new OpenLayers.Layer.GML("Commentaar", commentaarURL,{
                      format: OpenLayers.Format.GeoJSON,
                      units :'m',
                      projection: new OpenLayers.Projection("EPSG:28992"),
                      displayInLayerSwitcher: true
                      });

	    map.addLayers([commentaarLayer]);
              if (typeof(commentaarLayer.features.count) == 'undefined') {
                  commentaarLayer.destroy();

                  commentaarLayer = new
OpenLayers.Layer.Vector("Commentaar",{
                      displayInLayerSwitcher: true,
                      units :'m',
                      projection: new OpenLayers.Projection("EPSG:28992")
                      });
              }

Unfortunately that's not working.
If a layer loads succesfully the test
(typeof(commentaarLayer.features.count) == 'undefined') also returns true.

So I've tried
if (commentaarLayer.features.length == 0) but this one returns 0 when
there are no feautures, but also when there are eg 3 features.


Can anyone suggest a bullit proof test?

MArco





More information about the Users mailing list