arcgis-maps-sdk-swift-samples icon indicating copy to clipboard operation
arcgis-maps-sdk-swift-samples copied to clipboard

Refactor `IdentifyKMLFeaturesView` to not pass proxy across boundary

Open yo1995 opened this issue 1 year ago • 0 comments

Remove the kmlPlacemark(for:using:) method, and avoid passing the proxy across "main actor isolated context". Therefore, the @MainActor attribute can be removed from the root view.

.onSingleTapGesture { screenPoint, _ in
    Task {
        guard let forecastLayer else { return }
        do {
            // Identify the screen point on the KML layer using the map view proxy.
            let identifyResult = try await mapViewProxy.identify(on: forecastLayer, screenPoint: screenPoint, tolerance: 2)
            
            // Get the first KML placemark from the result's geo elements.
            if let placemark = identifyResult.geoElements.first(where: { $0 is KMLPlacemark }) as? KMLPlacemark {
                // Update the callout's text and placement.
                try updateCalloutText(using: placemark)
                if let location = mapViewProxy.location(fromScreenPoint: screenPoint) {
                    calloutPlacement = .location(location)
                }
            } else {
                // Dismiss the callout if a placemark was not found.
                calloutPlacement = nil
            }
        } catch {
            self.error = error
        }
    }
}

yo1995 avatar Jul 17 '24 19:07 yo1995