How do I add a popup to every layer in a map service in 4.x?

213
2
Jump to solution
06-11-2021 04:24 PM
MattStayner
Occasional Contributor

How can I add a map service so that my users can click on features in the map service? In 3.x I used ArcGISDynamicMapServiceLayer. In 4.x I'm now using MapImageLayer to load the map service. Is that correct? To enable the popup on my FeatureLayer I just added popupTemplate: {}. You can't use that on MapImageLayer. What can I do to enable a popup?

FYI, I'm using a custom panel to show the information, so I don't actually need a popup, I just need await view.popup.fetchFeatures(event) to trigger.

Tags (2)
0 Kudos
1 Solution

Accepted Solutions
EthanBodin1
New Contributor II

It looks like we have to configure popups for each sublayer. In my case I don't know all the sublayers beforehand; this code enables popups for every sublayer when the layer initially loads:

layer.when(() => {
    layer.allSublayers.forEach((sublayer) => {
        sublayer.popupEnabled = true;
    });
});

View solution in original post

2 Replies
EthanBodin1
New Contributor II

It looks like we have to configure popups for each sublayer. In my case I don't know all the sublayers beforehand; this code enables popups for every sublayer when the layer initially loads:

layer.when(() => {
    layer.allSublayers.forEach((sublayer) => {
        sublayer.popupEnabled = true;
    });
});

View solution in original post

MattStayner
Occasional Contributor

@EthanBodin1 thanks for the help!

That wasn't exactly what I needed, but allSublayers got me on the right path. It turns out, in may case any way, popupEnabled was already true, it was just missing the popupTemplate. Here's what I ended up with:

layerToAdd.allSublayers.forEach((sublayer) => {
  sublayer.popupEnabled = true // required to trigger info panel
  sublayer.popupTemplate = { // required to trigger info panel
    outFields: ['*'] // required to view all attributes in popup
  }
})

Thanks again for the help!

0 Kudos