Hi,
When you instantiate a layer, you can add a name option.

Example:
var layer = new ol.layer.Tile({
    *name: 'myLayer',*
    source: new ol.source.OSM()
});

// To get layer by name, you can write this
var layers = map.getLayers().getArray();
for (var i=0; i<layers.length; ++i)    {
    // Simply use get
    if (layers[i].get('name') === 'myLayer)    {
        .........
    }
}

PS: You can do it better with jquery for example

Philippe


Le jeudi 30 juin 2016 17:56:28 UTC+2, Paolo Gallo a écrit :
>
> Hello,
>
> I need to assigne in to a variable the names of the current layers loaded 
> on my map,
> I use this code, but it doesn't work.
>
> for (var i=0;i<map.getLayers().getLength();i++) {
> var name=map.getLayers().getArray()[i];
> alert(name);
> };
>
> can help me please?
> thank you.
>
> Paolo
>

-- 
You received this message because you are subscribed to the Google Groups "OL3 
Dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/ol3-dev.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ol3-dev/d0a78d76-8dc0-474a-87f7-008122b53c25%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to