Adding Popups to an ArcGISDynamicMapLayer

851
3
08-30-2017 08:12 AM
GregSalvador
New Contributor III

Hi all,

I am trying to add a popup to an ArcGISDynamicMapLayer, and I am a little stuck. I can't get the popups to appear, but I'm not getting any errors in the console. I think the error might be when I try to add the intoTemplate to the layer, but I'm not sure. Here is my code: (I've edited it out extra widgets so it is shorter, but I left the requires and declarations)

require([
"esri/map",
"esri/arcgis/utils",
"esri/layers/ArcGISDynamicMapServiceLayer",
"esri/dijit/LayerList",
"esri/dijit/BasemapGallery",
"esri/dijit/Popup",
"esri/dijit/PopupTemplate",
"dojo/parser",
"dojo/dom-construct",
"dojo/on",
"esri/InfoTemplate",
"dijit/layout/BorderContainer",
"dijit/layout/ContentPane",
"dojox/layout/ExpandoPane",
"dojo/domReady!"
], function (Map, arcgisUtils,
ArcGISDynamicMapServiceLayer,
LayerList, BasemapGallery,
Popup, PopupTemplate,
parser, domConstruct, on, InfoTemplate) {
var popup = new Popup({}, domConstruct.create("div"));
var map = new Map("map", {
basemap: "topo",
center: [-98.40, 29.67], //centers on san antonio
zoom: 11, //zooms to all of bexar county, must be integer
infoWindow: popup
});
BCADParcelPopup = new InfoTemplate("2016 BCAD Parcels", "");
var infoTemplates = {
infoTemplate: BCADParcelPopup,
layerUrl: url + "/40" //sudocode, i actually have the url as a string here.
};
var landLayer = new ArcGISDynamicMapServiceLayer(
url,
{
"id": "Land"
});
landLayer.setImageFormat("png32");
landLayer.setInfoTemplates({ infoTemplates });
map.addLayer(landLayer);
});

Tags (1)
0 Kudos
3 Replies
RobertScheitlin__GISP
MVP Emeritus

Greg,

   You are not setting the infotemplates correctly. Here is what the .setInforTemplates should look like:

      demographicsLayer.setInfoTemplates({
        1: { infoTemplate: _blockGroupInfoTemplate },
        2: { infoTemplate: _countyCensusInfoTemplate }
      });

See this sample:

Add two dynamic maps | ArcGIS API for JavaScript 3.21 

0 Kudos
GregSalvador
New Contributor III

Hi Robert,

I changed "landLayer.setInfoTemplates({ infoTemplates });" to "landLayer.setInfoTemplates({ 1: { infoTemplate: infoTemplates } });", but nothing is appearing. 

sideNote: why is the syntax for this line include 1: ?? I've never seen anything like that. 

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Greg,

   You are saying that number 1 (meaning the first layer in the map service) receives this particular info window template. It is pretty well spelled out in the doc:

https://developers.arcgis.com/javascript/3/jsapi/arcgisdynamicmapservicelayer-amd.html#infotemplates 

0 Kudos