laptop and a wrench

Erro

The RemoveLayer function of the WebMap object removes every other layer when included in a for-loop.

Última Publicação: November 21, 2019 Portal for ArcGIS
Número de ID do Erro BUG-000126749
EnviadoNovember 14, 2019
Última ModificaçãoJune 5, 2024
Aplica-se àPortal for ArcGIS
Versão encontradaN/A
StatusWill Not Be Addressed

Informações Adicionais

This is not a bug. This behavior is how Python (and languages like JS) handles lists in memory. The user can use the workaround or simply call the clear() method as shown below: >>> wm = WebMap(wm_item) >>> wm.layers.clear() # removes all layers by calling the built-in clear() method off List obj Long explanation This pattern of looping through elements of a List and removing it not the best practice. Consider the case below: >>> my_list = list(range(0,10)) >>> print(my_list) # [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] # remove by looping >>> for element in my_list: print(element) my_list.remove(element) # prints 0,2,4,6,8 >>> print(my_list) # [1, 3, 5, 7, 9] The issue is reproducible even with simple List objects. The best way to clear a list is to imply initialize it to an empty list [ ] or call clear() method.

Solução Provisória

Include the for-loop in a while-loop which runs until the length of the list of layers is equal to zero.

Etapas para Reproduzir

ID do Erro: BUG-000126749

Software:

  • Portal for ArcGIS

Seja notificado quando o status de um erro mudar

Baixe o Aplicativo de Suporte da Esri

Descubra mais sobre este tema

Obtenha ajuda de especialistas do ArcGIS

Entre em contato com Suporte Técnico

Baixe o Aplicativo de Suporte da Esri

Ir para as opções de download