I have the following code that defines my feature layers, but I would like to evaluate the layer name to ensure that the numbered layer is the correct feature that I am referencing on the chance layers are added. How would I do this?
var initialExtent = new Extent({ "xmin": 777229.03, "ymin": 1133467.92, "xmax": 848340.14, "ymax": 1185634.58, "spatialReference": { "wkid": 3435 } }); // app configuration var config = { mapOptions: { showAttribution: false, sliderStyle: "small", extent: initialExtent, logo: false, sliderPosition: "bottom-right" }, signLayerUrl: "http://maps.decaturil.gov/arcgis/rest/services/test/StreetSignTest/FeatureServer/0", supportLayerUrl: "http://maps.decaturil.gov/arcgis/rest/services/test/StreetSignTest/FeatureServer/1" };
I tried doing the following:
var featureService = new FeatureLayer("http://maps.decaturil.gov/arcgis/rest/services/test/StreetSignTest/FeatureServer");
alert(featureService.LayerInfo[0].name);
And receive the following error:
"in domReady callback"
"TypeError: Cannot read property '0' of undefined
I thought that this would provide me with the name of the first layer, but I am receiving an error instead. How should I write this?
And I referenced this, but there are no examples: LayerInfo | API Reference | ArcGIS API for JavaScript
Solved! Go to Solution.
Chris,
Do you mean work with the raw layer json?
var requestHandle = esriRequest({ url: "http://maps.decaturil.gov/arcgis/rest/services/test/StreetSignTest/FeatureServer/0", content: { f: 'json' }, handleAs: "json" }); requestHandle.then(function(lyrJSON, io){ console.info(lyrJSON.name); }
Chris,
You need to wait for the FeatureLayer load event before you can check properties.
This syntax will give you the name of your featureLayer
featureLayer.on("load", function() { console.log(featureLayer.name); });
Ken and Robert Scheitlin, GISP I have the JSON information here: http://maps.decaturil.gov/arcgis/rest/services/test/StreetSignTest/FeatureServer/0?f=pjson
and I want the name of this layer. Do you know how to get the value from the name of name, which would be the name of the layer.
Chris,
Do you mean work with the raw layer json?
var requestHandle = esriRequest({ url: "http://maps.decaturil.gov/arcgis/rest/services/test/StreetSignTest/FeatureServer/0", content: { f: 'json' }, handleAs: "json" }); requestHandle.then(function(lyrJSON, io){ console.info(lyrJSON.name); }
Yes, this gets me a layer name. I would basically want to say something like:
If lryJSON.name = "sign" then app.signLayer = "http://maps.decaturil.gov/arcgis/rest/services/test/StreetSignTest/FeatureServer/0"
That way I can assign layers based on verified names in the event that they are moved. Do you know what I would need to add?
If you're getting the layer information on the entire feature service, then why not use the layers to give you the id number? Your service (http://maps.decaturil.gov/arcgis/rest/services/test/StreetSignTest/FeatureServer) returns the following JSON
{
"currentVersion": 10.2,
"serviceDescription": "Test service for Street Signs.",
"hasVersionedData": true,
"supportsDisconnectedEditing": true,
"syncEnabled": false,
"supportedQueryFormats": "JSON, AMF",
"maxRecordCount": 1000,
"capabilities": "Create,Query,Update,Uploads,Editing",
"description": "",
"copyrightText": "",
"spatialReference": {
"wkid": 102671,
"latestWkid": 3435
},
"initialExtent": {
"xmin": 774645.2192425077,
"ymin": 1152044.6375970563,
"xmax": 852104.4261770676,
"ymax": 1185177.4775575039,
"spatialReference": {
"wkid": 102671,
"latestWkid": 3435
}
},
"fullExtent": {
"xmin": 788974.3070424125,
"ymin": 1140570.7070784047,
"xmax": 837775.3383771628,
"ymax": 1186701.6062862352,
"spatialReference": {
"wkid": 102671,
"latestWkid": 3435
}
},
"allowGeometryUpdates": true,
"units": "esriFeet",
"documentInfo": {
"Title": "",
"Author": "",
"Comments": "Test service for Street Signs.",
"Subject": "Test service for Street Signs.",
"Category": "",
"Keywords": "Street Signs"
},
"layers": [
{
"id": 0,
"name": "Sign"
},
{
"id": 1,
"name": "Support"
}
],
"tables": [],
"enableZDefaults": false
}
Check the "layers" array and if name==="Sign", then you have the correct id to use. You don't have to worry about layers being inserted and changing the ids.