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
1 change: 1 addition & 0 deletions api/android-for-googlemaps.api
Original file line number Diff line number Diff line change
Expand Up @@ -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<com.mapconductor.googlemaps.GoogleMapViewHolder, com.google.android.gms.maps.model.Marker> {
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<? extends com.mapconductor.core.marker.MarkerEntityInterface<com.google.android.gms.maps.model.Marker>>, kotlin.coroutines.Continuation<? super kotlin.Unit>);
public boolean getSupportsAnimationOverlay();
public void setMarkerVisible(com.mapconductor.core.marker.MarkerEntityInterface<com.google.android.gms.maps.model.Marker>, boolean);
public void setMarkerPosition(com.mapconductor.core.marker.MarkerEntityInterface<com.google.android.gms.maps.model.Marker>, com.mapconductor.core.features.GeoPoint);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<MarkerEntityInterface<GoogleMapActualMarker>>) {
withContext(coroutine.coroutineContext) {
entities.forEach { entity -> entity.marker?.zIndex = resolveZIndex(entity.state) }
}
}

override val supportsAnimationOverlay: Boolean = true

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Loading