Hi,
I have different types of layers added to my map, How can I find which layer has invoked the popup, I am using watchUtils to find when when the popup is visible, but I am unable to find which layers has invoked the popup
watchUtils.when(view.popup, "visible", function(evt){
//Code
});
I am using Arcgis Javascript 4.24 version. kindly guide me how can I find the layer info
Solved! Go to Solution.
You can probably do this a couple of ways, but one would be using the reactive utils.
https://developers.arcgis.com/javascript/latest/api-reference/esri-core-reactiveUtils.html
You can watch visible prop of the popup, then the selectedFeature, and check the layer the feature comes from.
watch(
() => view.popup.visible,
() => {
watch(
() => view.popup.selectedFeature,
(selectedFeature) => console.log("Source layer", selectedFeature.layer),
{ once: true }
);
}
);
Here's a sample showing how you can use it.
https://codepen.io/odoe/pen/GRGVBgr?editors=1000
You don't even need to watch the Popup visible, and just watch the selectedFeature, but if you paginate, it wouldn't always be the one that opened the popup.
You can probably do this a couple of ways, but one would be using the reactive utils.
https://developers.arcgis.com/javascript/latest/api-reference/esri-core-reactiveUtils.html
You can watch visible prop of the popup, then the selectedFeature, and check the layer the feature comes from.
watch(
() => view.popup.visible,
() => {
watch(
() => view.popup.selectedFeature,
(selectedFeature) => console.log("Source layer", selectedFeature.layer),
{ once: true }
);
}
);
Here's a sample showing how you can use it.
https://codepen.io/odoe/pen/GRGVBgr?editors=1000
You don't even need to watch the Popup visible, and just watch the selectedFeature, but if you paginate, it wouldn't always be the one that opened the popup.