Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions Sources/MapConductorForMapKit/MapKitMapView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ private struct MapKitMapViewRepresentable: UIViewRepresentable {
controller.registerOverlayController(polygonController)
controller.registerOverlayController(groundImageController)
controller.registerOverlayController(rasterLayerController)
controller.clearOverlaysHandler = { [weak self] in await self?.clearOverlays() }

let overlayScope = MapOverlayScope()
self.overlayScope = overlayScope
Expand Down Expand Up @@ -316,6 +317,17 @@ private struct MapKitMapViewRepresentable: UIViewRepresentable {
}
}

/// android-sdk の `clearOverlays()` と同じく、各オーバーレイのコントローラを空にする。
/// `controller.clearOverlaysHandler` から呼ばれる。
func clearOverlays() async {
await markerController?.clear()
await polylineController?.clear()
await polygonController?.clear()
await groundImageController?.clear()
await circleController?.clear()
await rasterLayerController?.clear()
}

func unbind() {
// 登録した capability を取り下げる。レジストリの持ち主は state で、ビューより長生きするため、
// ここで外さないと破棄済みのコントローラを掴んだまま残る。
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,12 @@ final class MapKitViewController: MapViewControllerProtocol {
cancelCameraAnimation()
}

/// ``clearOverlays()`` の中身。オーバーレイのコントローラはホストが持っているので、
/// ホストが生成時に設定する(android-sdk と同じく、各コントローラの `clear()` を呼ぶ)。
var clearOverlaysHandler: (@MainActor () async -> Void)?

func clearOverlays() async {
guard let mapView = mapView else { return }
mapView.removeAnnotations(mapView.annotations)
mapView.removeOverlays(mapView.overlays)
await clearOverlaysHandler?()
}

func setCameraMoveStartListener(listener: OnCameraMoveHandler?) {
Expand Down
Loading