Version :- "@arcgis/core": "4.30.9"I am implementing a LayerList widget with actions. One of these actions is 'Description' which redirects the user to the map server directory. For this purpose, I need to get the URL of the selected layer. You can find the solutions tried below.
const layerList = new LayerList({
view: view,
listItemCreatedFunction: layerItemActions,
});
layerList.on('trigger-action', async (event) => {
// Capture the action id.
const id = event.action.id;
if (id == 'description') {
const layerUrl = (await event.item.layer.url) as string;
window.open(layerUrl);
}
});
Even though above solution works it gives the following error,
'Property 'url' does not exist on type 'Layer'.'
Second implementation:
const layerList = new LayerList({
view: view,
listItemCreatedFunction: layerItemActions,
});
layerList.on('trigger-action', async (event) => {
// Capture the action id.
const id = event.action.id;
if (id == 'description') {
const layerUrl = (await event.item.layer.get('url')) as string;
window.open(layerUrl);
}
});
The above solution also works, But with the following deprecated message,
[esri.layers.FeatureLayer] 🛑 DEPRECATED - Function: `Accessor.get` is deprecated in favor of using optional chaining()
As far as I understand, the first approach might be the correct one. But I need to find a way to avoid this error message. How do we fix this issue?