Popups using MapImageLayer

4476
5
Jump to solution
08-02-2017 12:54 PM
SarojThapa1
Occasional Contributor III

I have a map service published through ArcGIS Server. The map service has 3 layers and the layers have sublayers. I am trying to transition from Esri's JSAPI 3.x to 4.x. In 3.x, I used to call a ArcGISDynamicMapServiceLayer and use layer.setInfotemplates to add popups to the map. I have a few layers, so I do not want to use feature layer to create popups for the sake of performance. 

Can I call popups using MapImageLayer in JS API 4.x?

The codes I used in 3.x is as follow:

 

var popupTemplate = new PopupTemplate({
  "title": "Row Flags",
  fieldInfos: [
    {fieldName: "GPS_Date", visible: true, label: "Date Collected", format: {dateFormat: "shortDate"}},
    {fieldName: "GNSS_Heigh", visible: true, label: "Z-value"},
    {fieldName: "Feature_Description", visible: true, label: "Description"}
  ]
});
var dynamicLayer = new ArcGISDynamicMapServiceLayer("https://RESTURLEndpoints", {
  "imageParameters": imageParameters,
  opacity: 1
});
dynamicLayer.setInfoTemplates({
  1: {infoTemplate: popupTemplate},
  2: {infoTemplate: popupTemplate2},
  4: {infoTemplate: popupTemplate3},
  5: {infoTemplate: popupTemplate4},
  7: {infoTemplate: popupTemplate5},
  8: {infoTemplate: popupTemplate6},
  9: {infoTemplate: popupTemplate7},
  10: {infoTemplate: popupTemplate8}
});

Thanks,

1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus

Saroj,

  Sure just set the template on the sublayer:

https://developers.arcgis.com/javascript/latest/api-reference/esri-layers-support-Sublayer.html#popu... 

var layer = new MapImageLayer({
  url: "https://sampleserver6.arcgisonline.com/arcgis/rest/services/USA/MapServer",
  sublayers: [{
    id: 0,
    popupTemplate: {
      title: "{COUNTY}",
      content: "{POP2007} people lived in this county in 2007"
    }
  }]
});

View solution in original post

5 Replies
RobertScheitlin__GISP
MVP Emeritus

Saroj,

  Sure just set the template on the sublayer:

https://developers.arcgis.com/javascript/latest/api-reference/esri-layers-support-Sublayer.html#popu... 

var layer = new MapImageLayer({
  url: "https://sampleserver6.arcgisonline.com/arcgis/rest/services/USA/MapServer",
  sublayers: [{
    id: 0,
    popupTemplate: {
      title: "{COUNTY}",
      content: "{POP2007} people lived in this county in 2007"
    }
  }]
});
SarojThapa1
Occasional Contributor III

Thank you Robert.

0 Kudos
chakreshsahu
New Contributor III
chakreshsahu
New Contributor III