only one attribute returned for a selected feature graphic

1194
15
Jump to solution
06-15-2018 01:07 PM
JayHill
Occasional Contributor II

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
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus

Jay,

   Sorry to steer you wrong. In the 4.x API there is no outfields property on the Sublayer. Which means that the only fields that get returned for a function like you have is the display field. So if you specify fields in your content string only then do they get added to the query when clicking on the map. So here is what worked for me using your code:

//Create popup content
      contentPro = function (value, key, data) {
        var contentPro = "";
        if (key === "IMAGE_YR") {
          contentPro += "<span class='bold' title='Image Year'><b>Image Year: </b></span>" + data.IMAGE_YR + "<br/>";
        }
        if (key === "IMAGE_DATE") {
          contentPro += "<span class='bold' title='Image Year'><b>Image Date: </b></span>" + data.IMAGE_DATE + "<br/>";
        }
        if (key === "Decade") {
          contentPro += "<span class='bold' title='Image Year'><b>Decade: </b></span>" + data.Decade + "<br/>";
        }
        if (key === "IMAGE_SCALE") {
          contentPro += "<span class='bold' title='Image Year'><b>Image Scale: </b></span>" + data.IMAGE_SCALE + "<br/>";
        }
        if (key === "DATA_CAT") {
          contentPro += "<span class='bold' title='Image Year'><b>Data Category: </b></span>" + data.DATA_CAT + "<br/>";
        }
        if (key === "SUPPMAPINFO") {
          if(data.SUPPMAPINFO){
            contentPro += "<span class='bold'><b>Supplemental Map Info: </b></span>" + "<a href='" + data.SUPPMAPINFO + "' target='_blank'>Opens in new tab</a>";
          }else if (data.SUPPMAPINFO == null) {
            contentPro += "<span class='bold'><b>Supplemental Map Info: </b></span>Supplemental Map Info not currently available.";
          }
        }
        return contentPro;
      }

      contentClick = function (value, key, data) {
        var content = "";
        if (key === "ATTRIBUTE") {
          content += "<span class='bold' title='NWI Code'><b>Attribute: </b></span>" + data.ATTRIBUTE + "<br/>";
        }
        if (key === "WETLAND_TYPE") {
          content += "<span class='bold' title='Utah Type'><b>Wetland Type: </b></span>" + data.WETLAND_TYPE + "<br/>";
        }
        if (key === "ACRES") {
          content += "<span class='bold' title='Acres'><b>Acres: </b></span>" + data.ACRES.toFixed(2) + "<br/>";
        }
        if (key === "UtahUse") {
          content += "<span class='bold' title='Utah Use'><b>Utah Use: </b></span>" + data.UtahUse + "<br/>";
        }
        return content;
      }
...

// Add data
      var wetlandLayer = new MapImageLayer({
        url: "xxxxxxxxx/MapServer",
        sublayers: [{
            id: 4,
            title: "Wetlands Outline",
            visible: false
          },
          {
            id: 3,
            title: "Riverine",
            visible: false,
            popupTemplate: {
              title: "Riverine",
              content: "{ATTRIBUTE:contentClick}{WETLAND_TYPE:contentClick}{ACRES:contentClick}"
            },
            popupEnabled: true
          },
          {
            id: 2,
            title: "Wetlands (non-riverine)",
            visible: true,
            popupTemplate: {
              title: "Wetlands (non-riverine)",
              content: "{ATTRIBUTE:contentClick}{WETLAND_TYPE:contentClick}{ACRES:contentClick}"
            },
            popupEnabled: true
          },
          {
            id: 1,
            title: "Metadata",
            visible: false,
            popupTemplate: {
              title: "Metadata",
              content: "{IMAGE_YR:contentPro}{IMAGE_DATE:contentPro}{IMAGE_YR:contentPro}{Decade:contentPro}{IMAGE_SCALE:contentPro}{DATA_CAT}{SUPPMAPINFO:contentPro}"
            },
            popupEnabled: true
          }
        ]
      });

Notice in the content I specify the fields I want returned and a function that will format the data for each.

View solution in original post

0 Kudos
15 Replies
RobertScheitlin__GISP
MVP Emeritus

Jay,

   There is a strange bug/feature where you have to list sublayers in descending order or they do not function properly. So just move your id 2 to the proper location in the array (second to last).

0 Kudos
JayHill
Occasional Contributor II

Robert

Just tried this and it still isn't working right. I thought it could have been the group layer it is in so I added that (layer 0) to the sublayers array but still nothing.

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Jay,

   In layer 1 and 4 you do not specify outfields. When you do not then the only field that will be added is the ObjectId field (and maybe the displayfield I can't remember).

0 Kudos
JayHill
Occasional Contributor II

Yeah I thought that too bud added that back in all of them. Still same result. When I add the service to a AGOL map all the attributes show up.

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Jay,

   Can I see all your code?

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Jay,

   Sorry to steer you wrong. In the 4.x API there is no outfields property on the Sublayer. Which means that the only fields that get returned for a function like you have is the display field. So if you specify fields in your content string only then do they get added to the query when clicking on the map. So here is what worked for me using your code:

//Create popup content
      contentPro = function (value, key, data) {
        var contentPro = "";
        if (key === "IMAGE_YR") {
          contentPro += "<span class='bold' title='Image Year'><b>Image Year: </b></span>" + data.IMAGE_YR + "<br/>";
        }
        if (key === "IMAGE_DATE") {
          contentPro += "<span class='bold' title='Image Year'><b>Image Date: </b></span>" + data.IMAGE_DATE + "<br/>";
        }
        if (key === "Decade") {
          contentPro += "<span class='bold' title='Image Year'><b>Decade: </b></span>" + data.Decade + "<br/>";
        }
        if (key === "IMAGE_SCALE") {
          contentPro += "<span class='bold' title='Image Year'><b>Image Scale: </b></span>" + data.IMAGE_SCALE + "<br/>";
        }
        if (key === "DATA_CAT") {
          contentPro += "<span class='bold' title='Image Year'><b>Data Category: </b></span>" + data.DATA_CAT + "<br/>";
        }
        if (key === "SUPPMAPINFO") {
          if(data.SUPPMAPINFO){
            contentPro += "<span class='bold'><b>Supplemental Map Info: </b></span>" + "<a href='" + data.SUPPMAPINFO + "' target='_blank'>Opens in new tab</a>";
          }else if (data.SUPPMAPINFO == null) {
            contentPro += "<span class='bold'><b>Supplemental Map Info: </b></span>Supplemental Map Info not currently available.";
          }
        }
        return contentPro;
      }

      contentClick = function (value, key, data) {
        var content = "";
        if (key === "ATTRIBUTE") {
          content += "<span class='bold' title='NWI Code'><b>Attribute: </b></span>" + data.ATTRIBUTE + "<br/>";
        }
        if (key === "WETLAND_TYPE") {
          content += "<span class='bold' title='Utah Type'><b>Wetland Type: </b></span>" + data.WETLAND_TYPE + "<br/>";
        }
        if (key === "ACRES") {
          content += "<span class='bold' title='Acres'><b>Acres: </b></span>" + data.ACRES.toFixed(2) + "<br/>";
        }
        if (key === "UtahUse") {
          content += "<span class='bold' title='Utah Use'><b>Utah Use: </b></span>" + data.UtahUse + "<br/>";
        }
        return content;
      }
...

// Add data
      var wetlandLayer = new MapImageLayer({
        url: "xxxxxxxxx/MapServer",
        sublayers: [{
            id: 4,
            title: "Wetlands Outline",
            visible: false
          },
          {
            id: 3,
            title: "Riverine",
            visible: false,
            popupTemplate: {
              title: "Riverine",
              content: "{ATTRIBUTE:contentClick}{WETLAND_TYPE:contentClick}{ACRES:contentClick}"
            },
            popupEnabled: true
          },
          {
            id: 2,
            title: "Wetlands (non-riverine)",
            visible: true,
            popupTemplate: {
              title: "Wetlands (non-riverine)",
              content: "{ATTRIBUTE:contentClick}{WETLAND_TYPE:contentClick}{ACRES:contentClick}"
            },
            popupEnabled: true
          },
          {
            id: 1,
            title: "Metadata",
            visible: false,
            popupTemplate: {
              title: "Metadata",
              content: "{IMAGE_YR:contentPro}{IMAGE_DATE:contentPro}{IMAGE_YR:contentPro}{Decade:contentPro}{IMAGE_SCALE:contentPro}{DATA_CAT}{SUPPMAPINFO:contentPro}"
            },
            popupEnabled: true
          }
        ]
      });

Notice in the content I specify the fields I want returned and a function that will format the data for each.

0 Kudos
JayHill
Occasional Contributor II

Thanks Robert! I had to add :contentPro the DATA_CAT field in order for it to work just right but thanks again!

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Ah, I missed that one.

0 Kudos
JayHill
Occasional Contributor II

If I want to add related table attributes to the popupTemplate function, do I have to set the fields the same way?

0 Kudos