How to get feature layer name, once graphic (feature) is clicked

2850
4
Jump to solution
06-04-2013 11:25 AM
tonylife
New Contributor III
When click a feature on map, the popup shows the attributes of the feature.
I want to show feature layer name in content of popup using infoTemplate.
I am able to get the graphic information at the time.
Is there a way I can get the feature layer name also?

Thanks,
Tony
0 Kudos
1 Solution

Accepted Solutions
KellyHutchins
Esri Frequent Contributor
One option is to define a function that will generate your popup content using setContent. Then you can use the graphic.getLayer method to retrieve the graphics layer name. Here's an example that shows how this works:


http://jsfiddle.net/AddHT/

View solution in original post

0 Kudos
4 Replies
JohnGravois
Frequent Contributor
it wouldn't be impossible to accomplish this, but the graphic returned by the GraphicsLayer onClick event does not expose the corresponding featureLayer name.

perhaps this?
var template = new esri.InfoTemplate();

var featureLayer = new esri.layers.FeatureLayer("http://servicesbeta.esri.com/ArcGIS/rest/services/SanFrancisco/SFStreetTreesRendered/MapServer/0",{
          id: "My Feature Layer Name",
    mode: esri.layers.FeatureLayer.MODE_SELECTION,
          outFields: ["*"],
          infoTemplate:template
});
//first pass infoTemplate, then instantiate feature layer, then set title using id
template.setTitle(featureLayer.id);
0 Kudos
KenBuja
MVP Esteemed Contributor
Here's the way I got the layer name into my infoWindow. This shows all the visible attributes for the layer

        connect.connect(map, "onClick", executeIdentifyTask);
        identifyTask = new esri.tasks.IdentifyTask(parameters.url);
        identifyParams = new esri.tasks.IdentifyParameters();
        identifyParams.tolerance = 3;
        identifyParams.returnGeometry = true;
        //identifyParams.layerIds = [0, 117];
        identifyParams.layerIds = myLayer.visibleLayers;
        identifyParams.layerOption = esri.tasks.IdentifyParameters.LAYER_OPTION_ALL;
        identifyParams.width = map.width;
        identifyParams.height = map.height;

        map.infoWindow.resize(415, 200);
        map.infoWindow.setTitle("Results");

    function executeIdentifyTask(evt) {
        identifyParams.geometry = evt.mapPoint;
        identifyParams.mapExtent = map.extent;
        identifyParams.layerIds = myLayer.visibleLayers; //in case the visible layers have changed for the layer

        var deferred = identifyTask.execute(identifyParams);
        deferred.addCallback(function (response) {
            return dojo.map(response, function (result) {
                var feature = result.feature;
                var infoTemplate = new esri.InfoTemplate("test", "${*}");
                var contentString = "";
                var sp = new Array();
                var sp = feature.attributes;

                contentString += "<b>" + result.layerName + "</b><hr width = '90%'>";

                for (x in sp) {
                    contentString += x + ": " + feature.attributes + "<br/>";
                }
                var infoTemplate = new esri.InfoTemplate();
                var titleText = "<div>" + "Title" + "</div>"
                infoTemplate.setTitle(titleText);
                infoTemplate.setContent(contentString);
                feature.setInfoTemplate(infoTemplate);

                return feature;
            });
        });
        map.infoWindow.setFeatures([deferred]);
        map.infoWindow.show(evt.mapPoint);
    }
0 Kudos
KellyHutchins
Esri Frequent Contributor
One option is to define a function that will generate your popup content using setContent. Then you can use the graphic.getLayer method to retrieve the graphics layer name. Here's an example that shows how this works:


http://jsfiddle.net/AddHT/
0 Kudos
tonylife
New Contributor III
One option is to define a function that will generate your popup content using setContent. Then you can use the graphic.getLayer method to retrieve the graphics layer name. Here's an example that shows how this works:


http://jsfiddle.net/AddHT/


Thank you!
This is the solution I am using. I do use a customized function with graphic parameter in setContent.
Actually what I need is graphic.getLayer().name.
0 Kudos