diff --git a/Sources/MapConductorForHERE/HereMapHost.swift b/Sources/MapConductorForHERE/HereMapHost.swift index a790edd..1a8ee15 100644 --- a/Sources/MapConductorForHERE/HereMapHost.swift +++ b/Sources/MapConductorForHERE/HereMapHost.swift @@ -321,6 +321,17 @@ public final class HereMapHost: MapViewCoordinatorBase, Marker applyStrategyRendering(nil) } + /// `clearOverlays()` から呼ばれる。strategy は接続したまま、描いたマーカーだけを消す。 + /// 同じインスタンスの一覧が送られている間は描かず、顔ぶれが変わるか作り直された state が + /// 来たら描き直す(StrategyMarkerManager.clearMarkers・オーバーレイのコレクタと同じ)。 + public func clearMarkers() async { + strategyClearedUntilListChanges = true + await strategyMarkerController?.clear() + } + + /// ``clearMarkers()`` の後、一覧が変わるまで描かない印。 + private var strategyClearedUntilListChanges = false + public func beginContentPass() { strategyConnectedThisPass = false } @@ -340,6 +351,7 @@ public final class HereMapHost: MapViewCoordinatorBase, Marker let renderer = HereMarkerRenderer(mapView: mapView) strategyMarkerRenderer = renderer strategyMarkerController = StrategyMarkerController(strategy: strategy, renderer: renderer) + strategyClearedUntilListChanges = false // find() の android 同等 screen 空間判定用に geo→screen 投影を注入する。 strategyMarkerController?.markerProjector = { [weak self] geo in guard let mapView = self?.mapView, @@ -380,6 +392,10 @@ public final class HereMapHost: MapViewCoordinatorBase, Marker newStatesById[state.id] = state } strategyMarkerStatesById = newStatesById + if strategyClearedUntilListChanges { + guard shouldSyncList else { return } + strategyClearedUntilListChanges = false + } for id in oldIds.subtracting(newIds) { strategyMarkerSubscriptions[id]?.cancel() @@ -457,6 +473,8 @@ public final class HereMapHost: MapViewCoordinatorBase, Marker await groundImageController?.clear() await circleController?.clear() await rasterLayerController?.clear() + // strategy(クラスタリングなど)が描いたマーカーも消す。 + await state.serviceRegistry.clearMarkerRendering() } public func unbind() {