I am pulling data from a MapServer, now I'd like to be able to interact with features on each of the layers to enable pop up of feature.
my very simple code has this so far:
const mapLayer = new MapImageLayer({
url: e.url,
opacity: 0.5,
});
view?.map.add(mapLayer);
Any way to enable pop up template for each of the layers that come through? or have them automatically converted to featurelayer by default?
Solved! Go to Solution.
Hi there,
You need to set the popupTemplate on the sublayers as shown here: https://developers.arcgis.com/javascript/latest/api-reference/esri-layers-support-Sublayer.html#popu...
That will work when you have the layer, however in my case I don't and it can be many or 1.
Eventually I solved it this way.
mapServerLayers.loadAll().then(() => mapServerLayers.allSublayers.forEach((e) => e.popupTemplate = e.createPopupTemplate({visibleFieldNames: viewFields})));
Hi there,
You need to set the popupTemplate on the sublayers as shown here: https://developers.arcgis.com/javascript/latest/api-reference/esri-layers-support-Sublayer.html#popu...
I saw that previously, however in that scenario you have to provide id of the sublayer to apply it to.
In my case number of sublayers is anywhere between 1...N. They all have common data, so i want to apply it to all of the layers.
How would you go about this challenge?
You can loop through the sublayers once MapImageLayer is loaded into the MapView as shown below:
const popupTemplate = {
title: "Common title",
content: "Common content"
};
view.whenLayerView(layer).then(() => {
layer.sublayers.forEach(
(sublayer) => (sublayer.popupTemplate = popupTemplate)
);
});
That will work when you have the layer, however in my case I don't and it can be many or 1.
Eventually I solved it this way.
mapServerLayers.loadAll().then(() => mapServerLayers.allSublayers.forEach((e) => e.popupTemplate = e.createPopupTemplate({visibleFieldNames: viewFields})));