diff --git a/api/android-for-googlemaps.api b/api/android-for-googlemaps.api index 1d47c50..fee5f56 100644 --- a/api/android-for-googlemaps.api +++ b/api/android-for-googlemaps.api @@ -252,6 +252,7 @@ public final class com.mapconductor.googlemaps.marker.GoogleMapMarkerControllerI public final class com.mapconductor.googlemaps.marker.GoogleMapMarkerRenderer extends com.mapconductor.core.marker.AbstractMarkerOverlayRenderer { public com.mapconductor.googlemaps.marker.GoogleMapMarkerRenderer(com.mapconductor.googlemaps.GoogleMapViewHolder, kotlinx.coroutines.CoroutineScope); public com.mapconductor.googlemaps.marker.GoogleMapMarkerRenderer(com.mapconductor.googlemaps.GoogleMapViewHolder, kotlinx.coroutines.CoroutineScope, int, kotlin.jvm.internal.DefaultConstructorMarker); + protected java.lang.Object applyDrawOrder(java.util.List>, kotlin.coroutines.Continuation); public boolean getSupportsAnimationOverlay(); public void setMarkerVisible(com.mapconductor.core.marker.MarkerEntityInterface, boolean); public void setMarkerPosition(com.mapconductor.core.marker.MarkerEntityInterface, com.mapconductor.core.features.GeoPoint); diff --git a/src/main/java/com/mapconductor/googlemaps/marker/GoogleMapMarkerRenderer.kt b/src/main/java/com/mapconductor/googlemaps/marker/GoogleMapMarkerRenderer.kt index aa7e098..7ecbd7a 100644 --- a/src/main/java/com/mapconductor/googlemaps/marker/GoogleMapMarkerRenderer.kt +++ b/src/main/java/com/mapconductor/googlemaps/marker/GoogleMapMarkerRenderer.kt @@ -2,11 +2,11 @@ package com.mapconductor.googlemaps.marker import com.google.android.gms.maps.model.Marker import com.google.android.gms.maps.model.MarkerOptions -import com.mapconductor.core.calculateZIndex import com.mapconductor.core.features.GeoPoint import com.mapconductor.core.marker.AbstractMarkerOverlayRenderer import com.mapconductor.core.marker.MarkerEntityInterface import com.mapconductor.core.marker.MarkerOverlayRendererInterface +import com.mapconductor.core.marker.MarkerState import com.mapconductor.googlemaps.GoogleMapActualMarker import com.mapconductor.googlemaps.GoogleMapViewHolder import com.mapconductor.googlemaps.toLatLng @@ -22,8 +22,16 @@ class GoogleMapMarkerRenderer( holder = holder, coroutine = coroutine, ) { - private fun resolveZIndex(params: MarkerOverlayRendererInterface.AddParamsInterface): Float = - (params.state.zIndex ?: calculateZIndex(params.state.position)).toFloat() + // zIndex が第 1 キー、同じなら画面で下(北が上なら南、さらに西)が手前。値を小さく保つのは、 + // Google が大きな値(以前の -緯度 × 10^6)を明示の小さな zIndex と正しく比べないため。 + private fun resolveZIndex(state: MarkerState): Float = drawOrderOf(state).toFloat() + + // 地図が回ったら、今ある全マーカーの zIndex を付け直す。 + override suspend fun applyDrawOrder(entities: List>) { + withContext(coroutine.coroutineContext) { + entities.forEach { entity -> entity.marker?.zIndex = resolveZIndex(entity.state) } + } + } override val supportsAnimationOverlay: Boolean = true @@ -59,7 +67,7 @@ class GoogleMapMarkerRenderer( params.bitmapIcon.anchor.y, ).icon(bitmapDescriptor) .draggable(params.state.draggable) - .zIndex(resolveZIndex(params)) + .zIndex(resolveZIndex(params.state)) val marker = holder.map.addMarker(options)?.also { it.tag = params.state.id @@ -118,8 +126,7 @@ class GoogleMapMarkerRenderer( marker.position = GeoPoint.from(params.current.state.position).toLatLng() marker.isVisible = params.current.visible - marker.zIndex = - (params.current.state.zIndex ?: calculateZIndex(params.current.state.position)).toFloat() + marker.zIndex = resolveZIndex(params.current.state) // Google Mapsはマーカーを再作成しなくてよいので、同じマーカーのインスタンスを返す marker