Select to view content in your preferred language

How to take screenshot of map in SwiftUI

173
2
09-25-2024 10:36 PM
AnuDharmarajan
New Contributor

How to take screenshot of the ArcGIS map in SwiftUI sdk.

0 Kudos
2 Replies
ZacharyKline
Esri Contributor

Hello!

Thanks for the question and good news, we have a way of doing that. You can use the MapViewReader  to access the proxy which has operations for the MapView. And on that proxy we have a method to export an image of the current map. Like this:

 

var body: some View {
    MapViewReader { proxy in
        MapView(map: map)
            .task {
                // This will export the image when the view appears
                // but I recommend putting this code where you want
                // to take the screenshot.
                let screenshot = try? await proxy.exportImage()
            }
    }
}

 

RongweiJi
New Contributor

Thank you for your reply, I am working on a exporting function from the mapview or tilelayer image , which is the, I also research the api document from esri , find there is no other better way to perform this function . 

0 Kudos