Select to view content in your preferred language

Enable feature selection on mapimagelayer

566
4
Jump to solution
12-20-2022 03:20 AM
Aeseir
by
Frequent Contributor

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?

0 Kudos
2 Solutions

Accepted Solutions
UndralBatsukh
Esri Regular Contributor
0 Kudos
Aeseir
by
Frequent Contributor

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

View solution in original post

0 Kudos
4 Replies
UndralBatsukh
Esri Regular Contributor

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...

 

0 Kudos
Aeseir
by
Frequent Contributor

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?

0 Kudos
UndralBatsukh
Esri Regular Contributor

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)
  );
});
0 Kudos
Aeseir
by
Frequent Contributor

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})));
0 Kudos