Select to view content in your preferred language

how do I access all attributes in a MapImageLayer SubLayer from PopupTemplate

4355
15
09-13-2018 11:20 AM
by Anonymous User
Not applicable

hello,

I have a MapImageLayer (hosted on our portal), with several sublayers. I wish to display some other data in the popup by using a function to return the content (the function is getting called, and I can return what I want). However, the attribute data I need to create/query the other data (non-arcgis data) is not being passed to the content function. The only attribute being sent back is the 'Name' field, and I cannot find a way to set the outFields property for the query that gets run.

Snippet

         this.map.layers.forEach((layer) => {
           if (layer.title === 'Some Title') {
             layer.outFields = ["*"]; //<-- does nothing
             layer.sublayers.forEach(subLayer => {
               subLayer.outFields = ["*"]; //<-- also does nothing
               if (subLayer.title === 'hidden layer') {
                 subLayer.visible = false;
               } else if (subLayer.title === 'other layer') {
                   this.otherLayer = subLayer;
               }
               subLayer.popupTemplate = {
                   title: subLayer.title,
                   content: this.getData.bind(this),
                   actions: [{
                     id: subLayer.title,
                     className: 'esri-icon-table',
                     title: 'Dashboard'
                   }]
               };
             }
             });
           }
         });

Snippet

getData(evt) {
     console.debug(evt); //<-- only attribute is 'Name'
     console.debug(this.view.popup.viewModel.selectedFeature); //<-- same

There are definitely more attributes on the layer, but only Name is being returned. Am I missing something somewhere in my code to set the outFields for a Portal hosted MapImageLayer? or is there something I need to have changed in the service to return all attributes? thanks!

Tags (1)
15 Replies
RobertScheitlin__GISP
MVP Emeritus

Troy,

   Do you define the sublayers for this MapImageLayer when you add it to the map? Sublayer will default to only include the ObjectId and Display Field for performance reasons (not documented that I know of). If you define other fields in the sublayers popup template when constructing the MapImageLayer then those fields will be included when accessing the sublayer.

0 Kudos
by Anonymous User
Not applicable

Thanks Robert,

No, the MapImageLayer (and sublayers) are created/added when I create the map from a portal item:

this.map = new WebMap({ portalItem: {id: "PortalItemID" } });

I did forget to mention that the Name field is indeed the Display Field for the layer(s), so that would explain why it is being returned

how do I define other fields on the PopupTemplate if I'm using a function call to create/return the required HTML? is it the fieldInfos array?

like such (sorry, at lunch and can't test at the moment):

subLayer.popupTemplate = {
 title: subLayer.title,
 content: this.getData.bind(this),
 fieldInfos: [{
    fieldName:'CS_ID' //<-- desired field
 }]
 actions: [{
 id: subLayer.title,
 className: 'esri-icon-table',
 title: 'Dashboard'
 }]
};

 

Thanks again!

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Troy,

   I have never had a workflow using a Portal item and then trying to define the sublayers popup. I would imagine that you need to define the popups fields in the webmap that the portal item references.

0 Kudos
by Anonymous User
Not applicable

ok. I double checked the WebMap that the portal item is referencing, the popups are fully configured there with all the desired attribute fields. I tried adding the fieldInfos array to the popupTemplate for the sublayer(s) and still no go. it looks like a limitation of the 4.x branch?

Thanks for the info. I'll keep digging to see if I can solve this!

0 Kudos
HeatherGonzago
Esri Contributor

This is a little late in a response. In case someone else comes across this, make sure that you set the PopupTemplate.outFields property. This property returns the fields needed to render the popup properly.

by Anonymous User
Not applicable

Thanks for the update Heather!

I actually solved this by using each layer as a FeatureLayer instead of the default SubLayer type from the webmap item, then settings started working as originally planned. If I get a chance, I will try to cycle back to this and see if the PopupTemplate.outFields option works for my use case.

0 Kudos
HeatherGonzago
Esri Contributor

Thanks Tory,

Setting the `outFields` should work with the MapImageLayer. If you come across this again or have any problems, just let us know.

Thanks,

Heather

hoogw
by
Regular Contributor

ESRI staff, 

          outFields: ["*"]   ------------ does nothing, it not work  

0 Kudos
hoogw
by
Regular Contributor

I get nothing on popupTemplate.

                           const _dynamic_image_layer = new MapImageLayer({
                      // url: "https://sampleserver6.arcgisonline.com/arcgis/rest/services/USA/MapServer",
                          url: ___url_string,


/*by default, sublayers not define, will show all layers.
* if sublayers defined as [....], only show what you put in [].
*/
sublayers: [{
id: 13,
title: "xxxxxxx",
outFields: ["*"],
popupTemplate : {
// autocasts as new PopupTemplate()
title: "jjjjjj",
content: getInfo,

},
outFields: ["*"]
},


{
id: 8,
title: "yyyyyyyy"
}]




});

0 Kudos