Rossko wrote:
Can you explain why it makes a difference to iterate in this way?

map.layers isn't an array - treat it more like a stack.   When removeLaver
is used on the first layer, the stack collapses, what was layer[1] becomes
the new layer[0]


Could you kindly point me to the documentation that describes the above? The reason I ask -- my understanding was not so. I always assumed that since I add an array of layers to my map, it would be treated as an array. In fact, for what its worth, my code is just like Tom's code in that I do iterate over the array of layers to remove them, and then add new ones, and it works fine for me. Am I just lucky?

var l = layers.length;
if (l > 0) {
    for (var i = 0; i < l; i++) {

        /*
        Since the layer being removed is not a baselayer,
        the second argument to the following method is false
        */
        map.removeLayer(layers[i], false);
    }

    /*
    Now, reset the layers variable so we can add new layers
    to it
    */
    layers = [];
}


--
Puneet Kishor
_______________________________________________
Users mailing list
[email protected]
http://lists.osgeo.org/mailman/listinfo/openlayers-users

Reply via email to