diff --git a/src/main/java/com/mapconductor/maptiler/MapTilerMapView.kt b/src/main/java/com/mapconductor/maptiler/MapTilerMapView.kt index 7c54322..556e8fa 100644 --- a/src/main/java/com/mapconductor/maptiler/MapTilerMapView.kt +++ b/src/main/java/com/mapconductor/maptiler/MapTilerMapView.kt @@ -239,6 +239,20 @@ fun MapTilerMapSurface( onDispose { state.serviceRegistry.remove(MarkerRenderingSupportKey) } } + // MTMapView destroys its WebView itself; the controller (tile-server + // routes, overlay managers, its coroutine scope) is ours to free. Keyed + // like the WebView, so a design change frees the one it replaces. + DisposableEffect(controller) { + onDispose { + controller.destroy() + // No MapViewBase here to do it: the state (which the app keeps) must + // not hold on to the destroyed controller and its overlays. Only if + // it is still the attached one -- after a design change the new + // controller is attached before this runs. + state.detachController(controller) + } + } + // 設定を渡すだけ。**タイル経路に倒すかはコントローラが件数を見て決める** // (`shouldUseMarkerLayer`)。ここで `useMarkerLayer = markerTiling != null` と // 書くと、しきい値未満の件数でもタイル経路に落ちてマーカーが 1 つも描かれない。 diff --git a/src/main/java/com/mapconductor/maptiler/MapTilerViewStateImpl.kt b/src/main/java/com/mapconductor/maptiler/MapTilerViewStateImpl.kt index 3d3b926..07f00a2 100644 --- a/src/main/java/com/mapconductor/maptiler/MapTilerViewStateImpl.kt +++ b/src/main/java/com/mapconductor/maptiler/MapTilerViewStateImpl.kt @@ -38,7 +38,10 @@ class MapTilerViewState( MapTilerViewStateInterface { private var _mapDesignType by mutableStateOf(mapDesignType) - private var controller: MapTilerMapViewController? = null + // Read through the base so that letting go of the controller there (MapViewBase + // does it when the map is torn down) leaves nothing behind here. + private val controller: MapTilerMapViewController? + get() = attachedMapController as? MapTilerMapViewController override var mapDesignType: MapTilerMapDesignTypeInterface get() = _mapDesignType @@ -49,7 +52,6 @@ class MapTilerViewState( /** MapView 生成時にコントローラを紐付ける。 */ fun setController(controller: MapTilerMapViewController) { - this.controller = controller // 初期カメラは MTMapOptions で地図生成時に渡しているので、接続時には移動しない。 attachController(controller, moveToInitialCamera = false) }