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
7 changes: 5 additions & 2 deletions api/android-for-arcgis.api
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,15 @@ public final class com.mapconductor.arcgis.ArcGISGeoViewHolder$DefaultImpls {
public final class com.mapconductor.arcgis.ArcGISGraphicsZIndex {
public com.mapconductor.arcgis.ArcGISGraphicsZIndex();
public final synchronized void place(com.arcgismaps.mapping.view.Graphic, java.lang.Integer);
public final synchronized void placeAt(com.arcgismaps.mapping.view.Graphic, double);
public final synchronized void replaceAll(kotlin.jvm.functions.Function1<? super com.arcgismaps.mapping.view.Graphic, java.lang.Double>);
public final synchronized void forget(com.arcgismaps.mapping.view.Graphic);
public final synchronized int getSize();
}
final class com.mapconductor.arcgis.ArcGISGraphicsZIndex$Entry {
public final com.arcgismaps.mapping.view.Graphic getGraphic();
public final int getZIndex();
public final void setZIndex(int);
public final double getZIndex();
public final void setZIndex(double);
public final long getSeq();
public final int getRank();
public final void setRank(int);
Expand Down Expand Up @@ -520,6 +522,7 @@ public final class com.mapconductor.arcgis.marker.ArcGISMarkerRenderer extends c
public void setMarkerVisible(com.mapconductor.core.marker.MarkerEntityInterface<com.arcgismaps.mapping.view.Graphic>, boolean);
public void setMarkerPosition(com.mapconductor.core.marker.MarkerEntityInterface<com.arcgismaps.mapping.view.Graphic>, com.mapconductor.core.features.GeoPoint);
public java.lang.Object onAdd(java.util.List<? extends com.mapconductor.core.marker.MarkerOverlayRendererInterface$AddParamsInterface>, kotlin.coroutines.Continuation<? super java.util.List<com.arcgismaps.mapping.view.Graphic>>);
protected java.lang.Object applyDrawOrder(java.util.List<? extends com.mapconductor.core.marker.MarkerEntityInterface<com.arcgismaps.mapping.view.Graphic>>, kotlin.coroutines.Continuation<? super kotlin.Unit>);
public java.lang.Object onRemove(java.util.List<? extends com.mapconductor.core.marker.MarkerEntityInterface<com.arcgismaps.mapping.view.Graphic>>, kotlin.coroutines.Continuation<? super kotlin.Unit>);
public java.lang.Object onPostProcess(kotlin.coroutines.Continuation<? super kotlin.Unit>);
public java.lang.Object onChange(java.util.List<? extends com.mapconductor.core.marker.MarkerOverlayRendererInterface$ChangeParamsInterface<com.arcgismaps.mapping.view.Graphic>>, kotlin.coroutines.Continuation<? super java.util.List<com.arcgismaps.mapping.view.Graphic>>);
Expand Down
28 changes: 26 additions & 2 deletions src/main/java/com/mapconductor/arcgis/ArcGISGraphicsZIndex.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import java.util.IdentityHashMap
internal class ArcGISGraphicsZIndex {
private class Entry(
val graphic: Graphic,
var zIndex: Int,
var zIndex: Double,
val seq: Long,
var rank: Int,
)
Expand All @@ -43,8 +43,19 @@ internal class ArcGISGraphicsZIndex {
fun place(
graphic: Graphic,
zIndex: Int?,
) = placeAt(graphic, (zIndex ?: 0).toDouble())

/**
* [graphic] を描く順の値 [order](大きいほど上)の位置に置く。マーカーが使う
* (`MarkerDrawOrder` の値: zIndex が第 1 キー、同じなら南・西が上)。値が同じものの
* 間だけ、最初に渡された順になる。
*/
@Synchronized
fun placeAt(
graphic: Graphic,
order: Double,
) {
val z = zIndex ?: 0
val z = order
val existing = byGraphic[graphic]
val entry =
if (existing != null) {
Expand All @@ -60,6 +71,19 @@ internal class ArcGISGraphicsZIndex {
assignRanksFrom(at)
}

/**
* 置いている Graphic の値をまとめて付け直す(地図が回ったときのマーカー)。
*
* 1 つずつ [placeAt] するとずらしが重なるので、並べ替えて順位を振り直す。
* [orderOf] が null を返した Graphic は値を変えない。
*/
@Synchronized
fun replaceAll(orderOf: (Graphic) -> Double?) {
entries.forEach { entry -> orderOf(entry.graphic)?.let { entry.zIndex = it } }
entries.sortWith(::compare)
assignRanksFrom(0)
}

/** [graphic] を外す。順位は詰めない(残りの並びはそのまま正しい)。 */
@Synchronized
fun forget(graphic: Graphic) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ 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 java.util.IdentityHashMap
import kotlin.math.abs
import kotlin.math.cos
import kotlin.math.max
Expand Down Expand Up @@ -132,7 +133,7 @@ class ArcGISMarkerRenderer(
it.attributes[BASE_HEIGHT_KEY] = height
it.attributes[BASE_OFFSET_Y_KEY] = anchorY.toFloat()
}
stackOrder.place(marker, params.state.zIndex)
stackOrder.placeAt(marker, drawOrderOf(params.state))
return@map marker
}.also {
markerLayer.graphics.addAll(it)
Expand All @@ -141,6 +142,13 @@ class ArcGISMarkerRenderer(
}
}

// 地図が回ったら、今ある全マーカーの重なり順を付け直す。
override suspend fun applyDrawOrder(entities: List<MarkerEntityInterface<ArcGISActualMarker>>) {
val orders = IdentityHashMap<Graphic, Double>()
entities.forEach { entity -> entity.marker?.let { orders[it] = drawOrderOf(entity.state) } }
withContext(coroutine.coroutineContext) { stackOrder.replaceAll { orders[it] } }
}

override suspend fun onRemove(data: List<MarkerEntityInterface<ArcGISActualMarker>>) {
coroutine.launch {
val elements = data.map { params -> params.marker }
Expand Down Expand Up @@ -211,7 +219,10 @@ class ArcGISMarkerRenderer(
marker.geometry = GeoPoint.from(params.current.state.position).toViewPoint()
// Always set visibility explicitly like Google Maps (remove conditional check)
marker.isVisible = params.current.visible
stackOrder.place(marker, params.current.state.zIndex)
stackOrder.placeAt(
marker,
drawOrderOf(params.current.state),
)

// ArcGISはマーカーを再作成しなくてよいので、同じマーカーのインスタンスを返す
marker
Expand Down
Loading