Select to view content in your preferred language

only one attribute returned for a selected feature graphic

2174
15
Jump to solution
06-15-2018 01:07 PM
JayHill
Frequent Contributor

My console log for a selected feature popup.watch is only showing one attribute when there should be all of them returned. Is it something simple I am overlooking? 

var stuffLayer = new MapImageLayer({
          url: "https://",
          sublayers: [{
                id: 2,
                title: "Stuff",
                visible: true,
                outFields: ["*"],
                popupTemplate: {
                  title: "Stuff",
                  content: createClickContentType
                }
                //minScale: 100000
            },
            {
                id: 4,
                title: "Stuff 2",
                visible: false,
                //minScale: 100000,
                //legendEnabled: false
            },
            {
              id: 3,
              title: "Stuff 3",
              visible: false,
              outFields: ["*"],
              popupTemplate: {
                title: "Stuff 3",
                content: createClickContentType
              },
              //maxScale: 100000
          },
          {
              id: 1,
              title: "Metadata",
              visible: false,
              popupTemplate: {
                title: "Metadata",
                content: createClickContentPro
              },
          }    

          ]
      });

mapView.map.add(stuffLayer);

          mapView.popup.watch(["selectedFeature"], function(g){

             console.log(g);

          });
Tags (1)
0 Kudos
15 Replies
RobertScheitlin__GISP
MVP Emeritus

Yes

0 Kudos
JayHill
Frequent Contributor

Is there special notation for the related table fields? Similar to the 3.x api ?

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Jay,

   From what I understand you use something like this for the field name

relationships/0/Point_Count_COMMON

0 Kudos
JayHill
Frequent Contributor

Ok, I can get the values I need returned to the console but nothing in the popup. Is it a timing issue to return them back to the popupTemplate function?

            contentSpecies = function(value, key, data) {
                var contentSpecies = "";
                objectID = data.OBJECTID;
                var queryTask = new QueryTask({
                    url: "https://blah.com/MapServer/1"
                });
                var relationQuery = new RelationshipQuery({
                    objectIds: [objectID],
                    outFields: ["Species", "Notes", "Status"],
                    returnGeometry: true,
                    relationshipId: 0
                });
                queryTask.executeRelationshipQuery(relationQuery)
                .then(function(rslts) {
                    var features = rslts[objectID].features;
                    features.forEach(function(ftr) {
                        var t = ftr.attributes;
                        var species = t.Species;
                        contentSpecies += "<span class='bold' title='Species'><b>Species: </b></span>" + species + "<br/>";
                        var notes = t.Notes;
                        contentSpecies += "<span class='bold' title='Notese'><b>Notes: </b></span>" + notes + "<br/>";
                        var status = t.Status;
                        contentSpecies += "<span class='bold' title='Status'><b>Status: </b></span>" + status + "<br/>";
                    });
                    console.log(contentSpecies);
                    //return contentSpecies;
                })
                return contentSpecies;
            };‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍
0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Jay,

   You are returning contentSpecies before the relationship query is done.

0 Kudos
JayHill
Frequent Contributor

I tried with the async await feature but it is not even firing the function now when called.

contentSpecies = async function(value, key, data) {
  console.log("functioning");
    try {
        var contentSpecies = "";

        objectID = data.OBJECTID;

        var queryTask = new QueryTask({
            url: "https://webmaps.com/MapServer/1"
        });

        var relationQuery = new RelationshipQuery({
            objectIds: [objectID],
            outFields: ["Species", "Notes", "Status"],
            returnGeometry: true,
            relationshipId: 0
        });
        let rslts = await queryTask.executeRelationshipQuery(relationQuery);
        var features = rslts[objectID].features;
        console.log(features);
        features.forEach(function(ftr) {
            var t = ftr.attributes;
            var species = t.Species;
            contentSpecies += "<span class='bold' title='Species'><b>Species: </b></span>" + species + "<br/>";
            var notes = t.Notes;
            contentSpecies += "<span class='bold' title='Notese'><b>Notes: </b></span>" + notes + "<br/>";
            var status = t.Status;
            contentSpecies += "<span class='bold' title='Status'><b>Status: </b></span>" + status + "<br/>";

        });
    } catch (e) {
        console.error(e);
    } finally {
      console.log(contentSpecies);
        return contentSpecies;
    }
}
0 Kudos