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

3546
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
HeatherGonzago
Esri Contributor

We made some updates to how popups work when fetching all field data in the latest release (4.12). The original response of setting the `popupTemplate.outFields` to include everything still holds true but setting the popupTemplate's content to {"*"} is no longer supported. Instead, we suggest setting view.popup.defaultPopupTemplateEnabled = true. Unfortunately, this is not implemented on the MapImagelayer. As a workaround for now, you can add this bit of code to get this to work,

sublayer.createFeatureLayer()
.then((featureLayer) => featureLayer.load())
.then((featureLayer) => {
   sublayer.popupTemplate = featureLayer.createPopupTemplate();
 })
hoogw
by
New Contributor III

Exactly solved my problem!!!!!!!! This bug bother me 8 hours, you help me made it. Thanks!!!!!!! 

0 Kudos
HeatherGonzago
Esri Contributor

Glad you got it working. 🙂

0 Kudos
SimonSchütte_ct
Occasional Contributor III

@HeatherGonzago Is it possible by now to use defaultPopupTemplateEnabled for MapImageLayers? If so, could you provide a sample? All the samples I can find define their own PopupTemplate or use FeatureLayers.

0 Kudos
HeatherGonzago
Esri Contributor

Another thing, the code you pasted above 

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" 
  }]
});


You have the outFields set outside of the PopupTemplate. It is not supported on the subLayer.
Also, remove the comma after getInfo. What happens when you update with these changes?
As for my other response with the provided workaround, this still applies to instances where
you are using a MapImageLayer with multiple sublayers and want to populate all fields.

Jose_LuisParra_Ocampo
New Contributor

The outFields example in the PopupTemplate sets that property outside of the popupTemplate property of the sublayer for some reason. 

USALayer = new MapImageLayer({
  url: "https://sampleserver6.arcgisonline.com/arcgis/rest/services/USA/MapServer",
  id: "USA",
  sublayers: [{
    id: 2,
    visible: true,
    popupTemplate: {
      title: "{state_name} Population",
      content: getInfo
    },
    outFields: ["*"]
  }]
})‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

outFields does work though, but I was in the same boat as Leo since I just blindly followed the example. After reading your answer I realized there was no reason to put it outside of the popupTemplate. Thanks!

0 Kudos