Skip to content

Switch of basemaps doesn't work properly when using multiple webmaps #7

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

Closed
mmoosbac94 opened this issue May 8, 2023 · 6 comments
Closed
Labels
question Further information is requested

Comments

@mmoosbac94
Copy link

mmoosbac94 commented May 8, 2023

With version 200.1 we currently have the issue that the switch of basemaps (also when using basemap-gallery) doesn't work when using multiple webmaps. So we have a viewmodel where we create Map using Map(item: ...). The basemaps are working correctly. When we then switch to another webmap also using Map(item: ...) and so override map in viewModel the switch of basemaps doesn't work properly anymore (so one basemap can be selected, the other cannot). Same issue with the Basemap-gallery (here even both basemaps cannot be selected).

e.g.
we first fetch default webmap with "item: PortalItem(portal: portal, id: PortalItem.ID("...")!) and after that we load portalItems/webmaps from portal manually with "findItems" and set selected map also in viewmodel.

It's working when we first load all portalItems/webmaps with "findItems" and then choose a portalItem with specific ID.

@yo1995 yo1995 added the question Further information is requested label May 8, 2023
@yo1995
Copy link
Contributor

yo1995 commented May 8, 2023

Thanks for reaching out. Since this is more of a UI/View model issue, would you mind moving this issue to toolkit repo or asking on Esri Community?

Also, please clarify

doesn't work properly anymore (so one basemap can be selected, the other cannot)

  • It seems you are using webmaps from ArcGIS Online given the Map(item:) initializer. Are you trying to switch between maps (i.e., Map instances), or basemaps (Basemap)?
  • Can you further explain "cannot be selected"? i.e., is it an UI issue or a data issue?
  • Do you see any error message logged in the console?
  • It would be great if you can provide a repro code snippet using the BasemapGallery that shows the problem.

Thank you

@mmoosbac94
Copy link
Author

mmoosbac94 commented May 8, 2023

Thank you for the quick response. We decided to ask here because we aren't sure if it is an sdk issue related to different/multiple map initializations. So everything is working fine when using one webmap, but if we initialize another one, it's not working properly anymore.

  • We are trying to switch basemaps on different webmaps. So switching webmaps is working fine, but the basemaps on the displayed webmap cannot be switched after choosing another webmap (so creating a new map instance with fetched portalItems from ArcGIS Online). The weird thing is, that when we first fetch all portalItems and then switch between basemaps everything is working fine. But as soon as we use portalItem with portal argument and specific ID for a default webmap, the switch between basemaps is not working correctly anymore.
  • "Cannot be selected" in this context means to display specific basemap on webmap. We know that the basemaps exist but it's not gonna be updated on webmap.
  • There are not error messages related to this issue.

@rolson
Copy link

rolson commented May 8, 2023

cc @mhdostal

@mhdostal
Copy link
Member

mhdostal commented May 8, 2023

@mmoosbac94 I was able to reproduce the behavior you're seeing. A Basemap object can only be set on one map, it can't be set on a map, then set on another map. That is why it's working great with the first map, but as soon as you switch maps it doesn't work. The solution is to recreate the array of basemaps you're using whenever you switch maps.

There's one other solution that @rolson mentioned: if you set the basemap of the existing map to nil prior to setting the same basemap on a second map, that will work also. Essentially, a basemap cannot be set on two maps at the same time. As long as you avoid that scenario, everything will work fine.

Let us know if you have any more issues!

@mmoosbac94
Copy link
Author

Oh yes! Very nice. It's working now if we set basemap to nil prior creating a new map with same basemap. But it only seems to work when we use a custom solution for displaying the selection of basemaps. So when we use the BasemapGallery from ArcGIS Toolkit for a second map it is not working. Maybe the BasemapGallery is only meant to cover one map with basemaps.

Thank you very much for your quick help and reply!

@mhdostal
Copy link
Member

mhdostal commented May 9, 2023

@mmoosbac94 I just merged a PR into the Toolkit's v.next branch which should fix your issue, without changes on your side (when using the BasemapGallery). This fix was to clone the basemap prior to setting it on the map. This would only apply when the BasemapGallery was initialized with an array of basemap items. When passing in a Portal, the basemap list is refreshed when the gallery is displayed, so there is not the "Object already owned" error in that case.

You could employ the same solution when using your custom method for selecting basemaps. Just call .clone() on your basemap, prior to setting it on the existing map.

Hope that helps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

4 participants