[OpenLayers-Users] getLayerByName

Benoit PESTY tchule at hotmail.com
Thu Aug 9 10:41:03 EDT 2007


Hello,

I've been in need for a function to get a layer by name instead of by id, 
i've added the following method to map.js. Maybe this could be interesting 
to have it in the API.

    /**
     * @param {String} name
     *
     * @returns The Layer with the corresponding name from the map's
     *           layer collection, or null if not found.
     * @type OpenLayers.Layer
     */
    getLayerByName: function(name) {
        var foundLayer = null;
        for (var i = 0; i < this.layers.length; i++) {
            var layer = this.layers[i];
            if (layer.name == name) {
                foundLayer = layer;
            }
        }
        return foundLayer;
    },

Regards,

Tchule.

_________________________________________________________________
Now you can see trouble…before he arrives 
http://newlivehotmail.com/?ocid=TXT_TAGHM_migration_HM_viral_protection_0507




More information about the Users mailing list