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
80 changes: 80 additions & 0 deletions api/android-sdk-core.api
Original file line number Diff line number Diff line change
Expand Up @@ -2068,6 +2068,38 @@ public final class com.mapconductor.core.marker.MarkerState implements com.mapco
public int hashCode();
public final com.mapconductor.core.marker.MarkerFingerPrint fingerPrint();
}
final class com.mapconductor.core.marker.MarkerState$Values {
public final com.mapconductor.core.features.GeoPointInterface getPosition();
public final com.mapconductor.core.marker.MarkerIconInterface getIcon();
public final com.mapconductor.core.marker.MarkerAnimation getAnimation();
public final java.lang.Integer getZIndex();
public final boolean getClickable();
public final boolean getDraggable();
public final kotlin.jvm.functions.Function1<com.mapconductor.core.marker.MarkerState, kotlin.Unit> getOnClick();
public final kotlin.jvm.functions.Function1<com.mapconductor.core.marker.MarkerState, kotlin.Unit> getOnDragStart();
public final kotlin.jvm.functions.Function1<com.mapconductor.core.marker.MarkerState, kotlin.Unit> getOnDrag();
public final kotlin.jvm.functions.Function1<com.mapconductor.core.marker.MarkerState, kotlin.Unit> getOnDragEnd();
public final kotlin.jvm.functions.Function1<com.mapconductor.core.marker.MarkerState, kotlin.Unit> getOnAnimateStart();
public final kotlin.jvm.functions.Function1<com.mapconductor.core.marker.MarkerState, kotlin.Unit> getOnAnimateEnd();
public final int getIconRevision();
public final com.mapconductor.core.features.GeoPointInterface component1();
public final com.mapconductor.core.marker.MarkerIconInterface component2();
public final com.mapconductor.core.marker.MarkerAnimation component3();
public final java.lang.Integer component4();
public final boolean component5();
public final boolean component6();
public final kotlin.jvm.functions.Function1<com.mapconductor.core.marker.MarkerState, kotlin.Unit> component7();
public final kotlin.jvm.functions.Function1<com.mapconductor.core.marker.MarkerState, kotlin.Unit> component8();
public final kotlin.jvm.functions.Function1<com.mapconductor.core.marker.MarkerState, kotlin.Unit> component9();
public final kotlin.jvm.functions.Function1<com.mapconductor.core.marker.MarkerState, kotlin.Unit> component10();
public final kotlin.jvm.functions.Function1<com.mapconductor.core.marker.MarkerState, kotlin.Unit> component11();
public final kotlin.jvm.functions.Function1<com.mapconductor.core.marker.MarkerState, kotlin.Unit> component12();
public final int component13();
public final com.mapconductor.core.marker.MarkerState$Values copy(com.mapconductor.core.features.GeoPointInterface, com.mapconductor.core.marker.MarkerIconInterface, com.mapconductor.core.marker.MarkerAnimation, java.lang.Integer, boolean, boolean, kotlin.jvm.functions.Function1<? super com.mapconductor.core.marker.MarkerState, kotlin.Unit>, kotlin.jvm.functions.Function1<? super com.mapconductor.core.marker.MarkerState, kotlin.Unit>, kotlin.jvm.functions.Function1<? super com.mapconductor.core.marker.MarkerState, kotlin.Unit>, kotlin.jvm.functions.Function1<? super com.mapconductor.core.marker.MarkerState, kotlin.Unit>, kotlin.jvm.functions.Function1<? super com.mapconductor.core.marker.MarkerState, kotlin.Unit>, kotlin.jvm.functions.Function1<? super com.mapconductor.core.marker.MarkerState, kotlin.Unit>, int);
public java.lang.String toString();
public int hashCode();
public boolean equals(java.lang.Object);
}
public interface com.mapconductor.core.marker.MarkerTileRasterLayerCallback {
public abstract java.lang.Object onRasterLayerUpdate(com.mapconductor.core.raster.RasterLayerState, kotlin.coroutines.Continuation<? super kotlin.Unit>);
}
Expand Down Expand Up @@ -2498,6 +2530,32 @@ public final class com.mapconductor.core.polygon.PolygonState implements com.map
public com.mapconductor.core.polygon.PolygonState(java.util.List, java.util.List, java.lang.String, long, float, long, boolean, boolean, int, java.io.Serializable, kotlin.jvm.functions.Function1, kotlin.jvm.functions.Function1, kotlin.jvm.internal.DefaultConstructorMarker);
public com.mapconductor.core.polygon.PolygonState(java.util.List, java.util.List, java.lang.String, long, float, long, boolean, boolean, int, java.io.Serializable, kotlin.jvm.functions.Function1, kotlin.jvm.internal.DefaultConstructorMarker);
}
final class com.mapconductor.core.polygon.PolygonState$Values {
public final java.util.List<com.mapconductor.core.features.GeoPointInterface> getPoints();
public final java.util.List<java.util.List<com.mapconductor.core.features.GeoPointInterface>> getHoles();
public final long getStrokeColor-0d7_KjU();
public final float getStrokeWidth-D9Ej5fM();
public final long getFillColor-0d7_KjU();
public final boolean getGeodesic();
public final boolean getClickable();
public final int getZIndex();
public final java.io.Serializable getExtra();
public final kotlin.jvm.functions.Function1<com.mapconductor.core.polygon.PolygonEvent, kotlin.Unit> getOnClick();
public final java.util.List<com.mapconductor.core.features.GeoPointInterface> component1();
public final java.util.List<java.util.List<com.mapconductor.core.features.GeoPointInterface>> component2();
public final long component3-0d7_KjU();
public final float component4-D9Ej5fM();
public final long component5-0d7_KjU();
public final boolean component6();
public final boolean component7();
public final int component8();
public final java.io.Serializable component9();
public final kotlin.jvm.functions.Function1<com.mapconductor.core.polygon.PolygonEvent, kotlin.Unit> component10();
public final com.mapconductor.core.polygon.PolygonState$Values copy-cWpAVu8(java.util.List<? extends com.mapconductor.core.features.GeoPointInterface>, java.util.List<? extends java.util.List<? extends com.mapconductor.core.features.GeoPointInterface>>, long, float, long, boolean, boolean, int, java.io.Serializable, kotlin.jvm.functions.Function1<? super com.mapconductor.core.polygon.PolygonEvent, kotlin.Unit>);
public java.lang.String toString();
public int hashCode();
public boolean equals(java.lang.Object);
}
public final class com.mapconductor.core.polygon.PolygonTileGeometryKt {
public static final double POLYGON_CELL;
public static final int POLYGON_MAX_CELLS;
Expand Down Expand Up @@ -2831,6 +2889,28 @@ public final class com.mapconductor.core.polyline.PolylineState implements com.m
public com.mapconductor.core.polyline.PolylineState(java.util.List, java.lang.String, long, float, boolean, boolean, int, java.io.Serializable, kotlin.jvm.functions.Function1, kotlin.jvm.functions.Function1, kotlin.jvm.internal.DefaultConstructorMarker);
public com.mapconductor.core.polyline.PolylineState(java.util.List, java.lang.String, long, float, boolean, boolean, int, java.io.Serializable, kotlin.jvm.functions.Function1, kotlin.jvm.internal.DefaultConstructorMarker);
}
final class com.mapconductor.core.polyline.PolylineState$Values {
public final java.util.List<com.mapconductor.core.features.GeoPointInterface> getPoints();
public final long getStrokeColor-0d7_KjU();
public final float getStrokeWidth-D9Ej5fM();
public final boolean getGeodesic();
public final boolean getClickable();
public final int getZIndex();
public final java.io.Serializable getExtra();
public final kotlin.jvm.functions.Function1<com.mapconductor.core.polyline.PolylineEvent, kotlin.Unit> getOnClick();
public final java.util.List<com.mapconductor.core.features.GeoPointInterface> component1();
public final long component2-0d7_KjU();
public final float component3-D9Ej5fM();
public final boolean component4();
public final boolean component5();
public final int component6();
public final java.io.Serializable component7();
public final kotlin.jvm.functions.Function1<com.mapconductor.core.polyline.PolylineEvent, kotlin.Unit> component8();
public final com.mapconductor.core.polyline.PolylineState$Values copy-3MZ6nm0(java.util.List<? extends com.mapconductor.core.features.GeoPointInterface>, long, float, boolean, boolean, int, java.io.Serializable, kotlin.jvm.functions.Function1<? super com.mapconductor.core.polyline.PolylineEvent, kotlin.Unit>);
public java.lang.String toString();
public int hashCode();
public boolean equals(java.lang.Object);
}
public final class com.mapconductor.core.polyline.PolylineTileSet {
public static final com.mapconductor.core.polyline.PolylineTileSet$Companion Companion;
public com.mapconductor.core.polyline.PolylineTileSet(com.mapconductor.core.tileserver.LocalTileServer, kotlinx.coroutines.CoroutineScope);
Expand Down
114 changes: 77 additions & 37 deletions src/main/java/com/mapconductor/core/marker/Marker.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.mapconductor.core.marker

import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableIntStateOf
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.setValue
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.geometry.Size
Expand Down Expand Up @@ -55,26 +55,73 @@ class MarkerState(
*/
override val mutations = StateMutationSignal()

private val currentIcon = mutations.notifying<MarkerIconInterface?>(icon)
// One Compose snapshot record per marker rather than one per attribute, as
// in CircleState: a mutableStateOf is three objects, and there were thirteen.
private data class Values(
val position: GeoPointInterface,
val icon: MarkerIconInterface?,
val animation: MarkerAnimation?,
val zIndex: Int?,
val clickable: Boolean,
val draggable: Boolean,
val onClick: OnMarkerEventHandler?,
val onDragStart: OnMarkerEventHandler?,
val onDrag: OnMarkerEventHandler?,
val onDragEnd: OnMarkerEventHandler?,
val onAnimateStart: OnMarkerEventHandler?,
val onAnimateEnd: OnMarkerEventHandler?,
/** [iconRevision] の中身。URL の画像が届くたびに増える。 */
val iconRevision: Int = 0,
)

private var values by mutableStateOf(
Values(
position, icon, animation, zIndex, clickable, draggable,
onClick, onDragStart, onDrag, onDragEnd, onAnimateStart, onAnimateEnd,
),
)

// A write compares only the field written, as the per-attribute states did,
// and is serialized so writes to two fields from two threads both land (an
// animation moving the marker while the app swaps its icon, say).
private inline fun write(next: (Values) -> Values?) {
synchronized(this) { values = next(values) ?: return }
mutations.notifyMutated()
}

/** [iconRevision] の中身。URL の画像が届くたびに増える。 */
internal val iconRevisionState = mutableIntStateOf(0)
internal val iconRevisionValue: Int get() = values.iconRevision

var icon: MarkerIconInterface?
get() = currentIcon.value
get() = values.icon
set(value) {
val changed = currentIcon.value != value
currentIcon.value = value
val changed = values.icon != value
write { if (it.icon == value) null else it.copy(icon = value) }
if (changed) redrawWhenImageLoaded(value)
}
var clickable by mutations.notifying(clickable)
var draggable by mutations.notifying(draggable)
var onClick by mutations.notifying(onClick)
var onDragStart by mutations.notifying(onDragStart)
var onDrag by mutations.notifying(onDrag)
var onDragEnd by mutations.notifying(onDragEnd)
var onAnimateStart by mutations.notifying(onAnimateStart)
var onAnimateEnd by mutations.notifying(onAnimateEnd)
var clickable: Boolean
get() = values.clickable
set(value) = write { if (it.clickable == value) null else it.copy(clickable = value) }
var draggable: Boolean
get() = values.draggable
set(value) = write { if (it.draggable == value) null else it.copy(draggable = value) }
var onClick: OnMarkerEventHandler?
get() = values.onClick
set(value) = write { if (it.onClick == value) null else it.copy(onClick = value) }
var onDragStart: OnMarkerEventHandler?
get() = values.onDragStart
set(value) = write { if (it.onDragStart == value) null else it.copy(onDragStart = value) }
var onDrag: OnMarkerEventHandler?
get() = values.onDrag
set(value) = write { if (it.onDrag == value) null else it.copy(onDrag = value) }
var onDragEnd: OnMarkerEventHandler?
get() = values.onDragEnd
set(value) = write { if (it.onDragEnd == value) null else it.copy(onDragEnd = value) }
var onAnimateStart: OnMarkerEventHandler?
get() = values.onAnimateStart
set(value) = write { if (it.onAnimateStart == value) null else it.copy(onAnimateStart = value) }
var onAnimateEnd: OnMarkerEventHandler?
get() = values.onAnimateEnd
set(value) = write { if (it.onAnimateEnd == value) null else it.copy(onAnimateEnd = value) }

/**
* Called once each time this marker goes from not being on the map to being on it:
Expand All @@ -92,9 +139,9 @@ class MarkerState(
* it redraws nothing. If the same state is shown on two maps, each map calls it.
*/
var onAdded: OnMarkerEventHandler? = onAdded
var zIndex by mutations.notifying<Int?>(zIndex)

private var internalAnimation by mutations.notifying<MarkerAnimation?>(animation)
var zIndex: Int?
get() = values.zIndex
set(value) = write { if (it.zIndex == value) null else it.copy(zIndex = value) }

init {
redrawWhenImageLoaded(icon)
Expand All @@ -110,10 +157,7 @@ class MarkerState(
private fun redrawWhenImageLoaded(icon: MarkerIconInterface?) {
val image = icon as? ImageIcon ?: return
image.whenImageLoaded {
if (currentIcon.value === image) {
iconRevisionState.intValue++
mutations.notifyMutated()
}
write { if (it.icon !== image) null else it.copy(iconRevision = it.iconRevision + 1) }
}
}

Expand Down Expand Up @@ -152,19 +196,14 @@ class MarkerState(
)

fun animate(animation: MarkerAnimation?) {
internalAnimation = animation
write { if (it.animation == animation) null else it.copy(animation = animation) }
}

fun getAnimation(): MarkerAnimation? = internalAnimation
fun getAnimation(): MarkerAnimation? = values.animation

private val currentPosition = mutations.notifying(position)
var position: GeoPointInterface
get() {
return currentPosition.value
}
set(value) {
currentPosition.value = value
}
get() = values.position
set(value) = write { if (it.position == value) null else it.copy(position = value) }

/**
* Copies this state, carrying every property over unless overridden.
Expand Down Expand Up @@ -254,9 +293,10 @@ class MarkerState(
var result = extra?.hashCode() ?: 0
result = 31 * result + clickable.hashCode()
result = 31 * result + draggable.hashCode()
result = 31 * result + currentPosition.value.latitude.hashCode()
result = 31 * result + currentPosition.value.longitude.hashCode()
result = 31 * result + currentPosition.value.altitude.hashCode()
val position = values.position
result = 31 * result + position.latitude.hashCode()
result = 31 * result + position.longitude.hashCode()
result = 31 * result + position.altitude.hashCode()
result = 31 * result + (icon?.hashCode() ?: 0)
result = 31 * result + zIndex.hashCode()
return result
Expand All @@ -268,9 +308,9 @@ class MarkerState(
icon.hashCode(),
clickable.hashCode(),
draggable.hashCode(),
currentPosition.value.latitude.hashCode(),
currentPosition.value.longitude.hashCode(),
internalAnimation?.hashCode() ?: 1,
values.position.latitude.hashCode(),
values.position.longitude.hashCode(),
values.animation?.hashCode() ?: 1,
zIndex.hashCode(),
)
}
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/com/mapconductor/core/marker/MarkerIconRevision.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import com.mapconductor.core.InternalMapConductorApi
* [MarkerState.icon] の URL の画像が届くたびに増える数。Compose から読むと、そのとき描き直される。
*
* URL の画像が届いても、アイコンは同じインスタンスのまま `hashCode` だけが変わるので、
* `marker.icon` を読んでいるだけのコンポジションは走り直さない。マーカーをコンポーズの
* オーバーレイとして描くプロバイダは、これも読んで `remember` のキーにする。
* `remember(marker.icon)` は作り直されない。マーカーをコンポーズのオーバーレイとして描く
* プロバイダは、これも `remember` のキーにする。
*
* [MarkerState.icon] の読み出し自体は Compose の状態を増やさない。タイルの描画スレッドや
* コントローラが 14 万回読むので、そこへ余計な読み取りを足さないため。
* マーカーの値は 1 つの Compose 状態にまとめてあるので、これを読んでも状態の読み取りは
* 増えない(タイルの描画スレッドやコントローラが 14 万回読むので、そこは増やさない)。
*/
@InternalMapConductorApi
val MarkerState.iconRevision: Int
get() = iconRevisionState.intValue
get() = iconRevisionValue
Loading
Loading