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.
Solved! Go to Solution.
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;
});
});
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;
});
});
@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!
@MattStayner On your code I'm assuming this is when you were adding a layer through code? I'm trying to get all the popups in the Map Image to turn on without having to format each popup.
@JohnLucotch2 I actually put the code above inside a `.when` so it runs once the layer is added (see below). I hope that helps!
layerToAdd.when(() => {
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 so much @MattStayner!