Hi,
I am trying to show a popup template whenever users click on the map. It works fine when I use FeatureLayer but doesn't work if I use MapImageLayer (to show all sub features layer).
Any help is much appreciated.
Hi @anuragmittal ,
Here is the codepen sample for you.
https://codepen.io/thanhtetaung/pen/bGwzWEX?editors=1000
Basically you need to define popup template for each sublayer as in
sublayers: [
{
id: 3,
visible: true,
popupTemplate:{
title:"County: {name}",
content: "State name {state_name}"
}
}, {
id: 2,
visible: true,
popupTemplate:{
title:"State: {state_name}",
content: "Sub Region {sub_region}"
}
}...
Let me know how it is go.
Best regards,
Than
Thank you Than. But this won't work in my case as we have 100s of features layer. Defining sublayer with ID and template for all feature layers will be difficult to maintain in future.
Is there any way I can loop over each layer and create a popup template to show all feature content (*)?
Hi @anuragmittal ,
Wildcard is no supported from version 4.12
Refer to this reference -
https://developers.arcgis.com/javascript/latest/api-reference/esri-PopupTemplate.html
It mentioned you can use defaultTemplatePopupEnabled property of the view popup widget.
However, so far map image layer is not supported yet.
In my opinion, you have two options
Option 1. When you publish map image layer, enable all popup for all layers and use the portal item id.
e.g. https://codepen.io/thanhtetaung/pen/yLaZZQg
To enable all layer, below items might help you and save time.
Option 2: downgrade to 4.11 or use jsapi 3.xxx with wildcard
e.g. https://codepen.io/thanhtetaung/pen/OJRddyd
Hope these will help you.
Hi there,
You can enable popupTemplate on sublayers by calling FeatureLayer.createPopupTemplate and setting the view.popup.defaultPopupTemplatedEnabled property to true.
This simple test app shows you how to show the default popup for all sublayers in a MapImageLayer.
Hope this helps,
-Undral
Thank you Undral. This might work for me. But how can I highlight the selected feature layer? And how can I show the popup if a pin is dropped on the map? Currently I am suing hitTest whenever a pin is dropped and it works perfectly fine with direct feature layer but not with MapImageLayer.
I updated the app to showcase what are you asking. You will need to tweak it meet your needs. With this said, the application performance will be bad if you are dealing with hundreds of sublayers, lots of fields for each layer, and large geometries... as the application needs to make bunch of server side calls whenever user clicks on the map.