ArcGIS API for Javascript featureLayer.title not returning full title

325
0
08-26-2020 08:16 AM
carolineglazer1
New Contributor

I'm trying to access a WFL with 14 layers on it. I successfully pull all the layers off the service and display them on a map and in a layerList widget, but I would like to edit the featureLayer.title attribute to remove the prefix that ArcGIS Online adds to all layers within a WFL. (The WFL is named "Stewardship Data Aggregated by Stewardship Activity" and the individual layers have names like "Agriculture", "Wilderness", "Grazing", etc. - I want to just display the end portion of the full name.) When I console.log(featureLayer.title), I am only shown the prefix part ("Stewardship Data Aggregated by Stewardship Activity"); however, when I actually inspect the featureLayer object, I can see that the title is really something like "Stewardship Data Aggregated by Stewardship Activity - Agriculture"

Is this a bug in featureLayer.title? When I later try to substring(54) the title, it returns an empty string. What am I doing wrong?!?! (code below)

// Get feature layers for Survey Responses
            surveysArray = new Collection;
            for (var i = 0i < 14i++) {
                var featureLayer = new FeatureLayer({
                    url: 'https://services.arcgis.com/7CRlmWNEbeCqEJ6a/arcgis/rest/services/Stewardship_Data_Aggregated_by_Stewardship_Activity/FeatureServer/'+i.toString(10),
                    outFields: ["*"],
                    popupTemplate: template
                })
                console.log(featureLayer.title)
                console.log(featureLayer)
                featureLayer.title = featureLayer.title.substring(54);
                console.log(featureLayer.title)
                console.log(featureLayer)
                surveysArray.add(featureLayer);
            }

            // Initialize the layer list widget
            var layerList = new LayerList({
                view: view,
                listItemCreatedFunction: function(event) {
                    var item = event.item;
                    if (item.layer.type != "group") {
                        //don't show legend twice
                        item.panel = {
                            content: "legend",
                            open: false
                        };
                    };
                    // Fix the titles for Stewardship Survey Aggregated Data
                    // if (item.layer.title.startsWith("Stewardship Data Aggregated") && item.layer.title.length > 54) {
                    //     item.layer.title = item.layer.title.substring(54);
                    //     console.log(item.layer.title)
                    // };   
                }
            });

0 Kudos
0 Replies