Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SubLayers of L.Esri.DynamicMapLayer get recreated and assigned new leaflet id on add/remove #1046

Closed
ahalota opened this issue Feb 9, 2018 · 8 comments
Labels
Comments Needed stale Closed due to inactivity. Wontfix

Comments

@ahalota
Copy link

ahalota commented Feb 9, 2018

  • Version of Leaflet (L.version):
    1.3.1
  • Version of esri Leaflet (L.esri.VERSION):
    2.1.2

Steps to reproduce the error:

  1. Add L.Esri.DynamicMapLayer to map, with 1 subLayer.
    myLayer = L.esri.dynamicMapLayer({ url: layerUrl, layers: [0]}).addTo(map)
  2. Check layer ids on your map
    map._layers >> {32: NewClass, 33: NewClass, 70: NewClass, 85: NewClass, 163: NewClass}
    In my case, 70 is the esriLayer, and 163 is the layer for [0]
  3. Remove superLayer
    map.removeLayer(myLayer)
    map._layers >> {32: NewClass, 33: NewClass, 85: NewClass}
  4. Add the layer again
    map.addLayer(myLayer)
    map._layers >> {32: NewClass, 33: NewClass, 70: NewClass, 85: NewClass, 172: NewClass}

You can see that the subLayer [0] has a new id, 172, instead of the previous 163.
This creates a big issue if attempting to attach any handlers to the subLayer, since it is recreated.

@Biboba
Copy link
Contributor

Biboba commented Feb 9, 2018

Hello,

Not sure this is an issue but rather an expected behavior as layer id gets incremented when adding new layers.
Why would you remove layer to add them again ? Could not you set layers as not visible if you want to hide them ?

@ahalota
Copy link
Author

ahalota commented Feb 9, 2018

I've always used map.add/removeLayer() to change visibility in leaflet. Is there a different way?

What do you mean by set to not visible? Does this avoid requesting the info from the server (I don't want to request a bunch of rasters and then 'hide' them with an opacity of 0)

@Biboba
Copy link
Contributor

Biboba commented Feb 9, 2018

For a dynamicMapLayer, you can use setLayers with an empty array:
myLayer.setLayers([])
And it avoids requesting the layer info one more time, contrary to removeLayer and addLayer.

@ahalota
Copy link
Author

ahalota commented Feb 9, 2018

While that does work, it doesn't change the unexpected change of layerId. Even if I use setLayers to add/remove sublayers, they are assigned a new layerId. With setLayers, I can understand that a new layerId would be created (since it's hard to predict when switching from [0] to [1,2,] to [0] for example that you are going back to a previously made layer). Underneath everything it probably is just adding/removing/recreating the layers as usual.

Based on the way other leaflet layers work, when adding/removing a specific layer it should be added back in the same state it was removed, so the expected behavior for removing then adding a parent layer is that its child layers retain their original ids as well.

@jwasilgeo
Copy link
Contributor

@ahalota do you still find that this statement is still true in the most recent version of esri-leaflet?

This creates a big issue if attempting to attach any handlers to the subLayer, since it is recreated.

If so, can you please create and share a public demo that we can use to investigate and discuss further?

@ahalota
Copy link
Author

ahalota commented Nov 17, 2020 via email

@jwasilgeo
Copy link
Contributor

Thanks for your interest and patience! I'd like to dust it off and give it a fresh pair of eyes.

@stale
Copy link

stale bot commented Sep 14, 2021

This issue has been automatically marked as stale because we're waiting on more information or details, but have not received any response. It will be closed if no further activity occurs. Thank you!

@stale stale bot added the Wontfix label Sep 14, 2021
@gavinr gavinr added the stale Closed due to inactivity. label Sep 14, 2021
@stale stale bot closed this as completed Sep 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Comments Needed stale Closed due to inactivity. Wontfix
Projects
None yet
Development

No branches or pull requests

4 participants