Problem solved,
if (this.map.getLayer (layerID)) this.map.removeLayer (this.map.getLayer (layerID));
where layerID is the given layer.id when the layer is created, e.g., could be the same as lyr.name in your case.
Membros conectados podem postar, seguir atualizações e mais. Novo aqui? Registre uma conta gratuita.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.