Skip to content

BasemapGallery - Clone basemap prior to setting to avoid "object already owned" error. #328

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
mhdostal opened this issue May 9, 2023 · 2 comments
Assignees
Labels
Effort - small A low level of effort to complete enhancement New feature or request Priority - medium A medium-priority item

Comments

@mhdostal
Copy link
Member

mhdostal commented May 9, 2023

When the client passes in a list of base maps, and if multiple web maps are used with the BasemapGallery, you can get the "object already owned error". The solution is to clone the basemap prior to setting the new basemap.

Cloning is NOT necessary when the user passes in a portal, as the portal basemaps are reloaded every time the basemap gallery is displayed.

@mhdostal mhdostal self-assigned this May 9, 2023
@mhdostal mhdostal added enhancement New feature or request Effort - small A low level of effort to complete Priority - medium A medium-priority item labels May 9, 2023
@mhdostal mhdostal closed this as completed May 9, 2023
@dfeinzimer
Copy link
Collaborator

@mhdostal I'm trying to repro this to adjust the fix for #1126 but I'm not understanding the description:

and if multiple web maps are used with the BasemapGallery

Do you recall what the steps to reproduce were?

@mhdostal
Copy link
Member Author

mhdostal commented Apr 3, 2025

In BasemapGalleryExampleView, create a second map property:

    @State private var map2: Map = {
        let map = Map(basemapStyle: .arcGISImagery)
        map.initialViewpoint = Viewpoint(
            center: Point(x: -93.258133, y: 44.986656, spatialReference: .wgs84),
            scale: 1_000_000
        )
        return map
    }()

Then, create a .task on the MapView in the body of the example:

            .task {
                map2.basemap = basemaps.first?.basemap
                try? await map2.load()
            }

Then run the example and set the basemap of the original map to the first basemap in the list. If there is no .clone() call, you get the Object already owned error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Effort - small A low level of effort to complete enhancement New feature or request Priority - medium A medium-priority item
Projects
None yet
Development

No branches or pull requests

2 participants