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

deduikertjes DeDuikertjes at xs4all.nl
Wed Oct 21 02:57:32 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 
-- 
View this message in context: http://n2.nabble.com/How-to-check-of-a-layer-is-correctly-loaded-created-tp3863492p3863492.html
Sent from the OpenLayers Users mailing list archive at Nabble.com.



More information about the Users mailing list