JavaScript 4.11 - Looking to Assign PopupTemplate to Map Service Layer by ID Number

217
4
Jump to solution
04-03-2019 02:23 PM
IanPeebles
Regular Contributor

Hello.  Starting to look at using the 4.x JavaScript API.  I am looking to assign a popupTemplate to each layer within a map service.  Can I do this without having to add each individual feature layer to the map?  I have done this in the 3.x API.  Here is my sample below and this works well:

electricGPS = new            ArcGISDynamicMapServiceLayer("https://arcgis03/arcgis/rest/services/Electric/ElectricGPS/MapServer", {
id: "Electric GPS",
visible: true,
outFields: ["*"]
});


// Set Info Template for Electric GPS
electricGPS.setInfoTemplates({
0: {infoTemplate: genericPointsInfoTemplate},
1: {infoTemplate: poleAttachmentsInfoTemplate},
2: {infoTemplate: poleInfoTemplate},
3: {infoTemplate: pedestalInfoTemplate},
4: {infoTemplate: propertyInfoTemplate},
5: {infoTemplate: streetlightInfoTemplate},
6: {infoTemplate: switchingFacilityInfoTemplate},
7: {infoTemplate: transformerFacilityInfoTemplate},
8: {infoTemplate: servicePointsInfoTemplate},
9: {infoTemplate: anchorGuyInfoTemplate},
10: {infoTemplate: PrimaryMeterInfoTemplate},
11: {infoTemplate: genericLineInfoTemplate},
12: {infoTemplate: UGPrimaryInfoTemplate},
13: {infoTemplate: UGSecondaryInfoTemplate},
14: {infoTemplate: AreaGenericInfoTemplate}
});

How would this work using the 4.x API?  Trying to find clues in the API reference.  Thank you for any information you can provide.

Tags (1)
0 Kudos
1 Solution

Accepted Solutions
IanPeebles
Regular Contributor

Robert,

That is exactly what I was looking for.  Thank you much!  I did learn more about the sublayers too .  Here is my final coding structure:

Popup Definitions

View solution in original post

0 Kudos
4 Replies
RobertScheitlin__GISP
MVP Esteemed Contributor

Ian,

  The below sample shows how to set the renderer for individual sublayers. But to set the popup you would just add the popupTemplate property to the sublayers property too.

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

https://developers.arcgis.com/javascript/latest/sample-code/sandbox/index.html?sample=layers-mapimag...

IanPeebles
Regular Contributor

Robert,

Thank you much for the resources.  I tried this out and got it to work.  However, when using the sublayers, it seems to eliminate all the other layers, if you are only specifying one layer.  I guess it is all or nothing?

In the 3.x environment, I was able to specify the ID of the layer and assign a popup for it, while allowing all layers to display.  I guess I need to research this further...trying to learn the differences between the 3x and 4x API.

0 Kudos
RobertScheitlin__GISP
MVP Esteemed Contributor

Ian,

   In 4.x Specifying sublayers is telling the API that you only want those specific sublayers to show in the view. If you want all the sublayers but what to only specify the popupTemplate for one then wait for the view to load and then use code like this:

view.when(function(){
layer.findSublayerById(2).popupTemaplate = blah;
});
IanPeebles
Regular Contributor

Robert,

That is exactly what I was looking for.  Thank you much!  I did learn more about the sublayers too .  Here is my final coding structure:

Popup Definitions

View solution in original post

0 Kudos