Feature Layer Name undefined?

2778
5
08-03-2012 04:37 AM
AdamWills
New Contributor II
This may be something silly that I'm doing wrong, but my feature layer name keeps coming back as undefined.

console.log(featureLayer) produces this:
a ->
...
id: "graphicsLayer4"
..
name: "Fire Station"
..


console.log(featureLayer.id) produces "graphicsLayer4"
console.log(featureLayer.name) produces "undefined"

Any ideas what I'm doing wrong?
0 Kudos
5 Replies
danbecker
Occasional Contributor III
from the api reference:
"The name of the layer as defined in the map service."

a ->
...
id: "graphicsLayer4"


console.log(featureLayer.name) - would return the name of the layer as defined in the service. Doesn't look like you can define name, only properties listed in the 'constructor detail' section of the api reference.
0 Kudos
AdamWills
New Contributor II
I'm not looking to define the name - just want to return the name in the service.  But it keeps returning undefined.
0 Kudos
RahulMetangale1
Occasional Contributor II
Since name is coming from map service you have to wait till layer is added to map then only you can access its properties like name. Here is the sample code to retrieve the name from feature layer:
 
dojo.connect(featureLayer,"onLoad",function(){
alert(featureLayer.name);           
        });


Here is the complete sample:
http://jsfiddle.net/rahulm/nGc9b/
0 Kudos
AdamWills
New Contributor II
Perhaps I'm just confused as to when I log the object, I get the name returned, but when I try to access that property, I can't.

Edit: And I can access other properties, such as the id and url....
0 Kudos
ChristianDebono
New Contributor II
Perhaps I'm just confused as to when I log the object, I get the name returned, but when I try to access that property, I can't.

Edit: And I can access other properties, such as the id and url....


I have the same problem. Have you came up with a solution for it?
0 Kudos