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
5 changes: 5 additions & 0 deletions src/main/java/com/mapconductor/core/OverlayCollector.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ interface ComponentState {
* [StateMutationSignal.notifying]. Without that the collector never hears
* about an in-place change and the renderer keeps drawing the old value —
* silently, which is why this is required rather than defaulted.
*
* Only an assignment to a field is reported. Changing the object a field
* holds — adding to a list passed in as `points`, say — reaches no one, and
* assigning a value equal to the current one is ignored, so re-assigning a
* list after editing it in place does nothing either. Assign a new value.
*/
val mutations: StateMutationSignal
}
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/com/mapconductor/core/StateMutationSignal.kt
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ class StateMutationSignal {
*
* Declare `mutations` above the fields that use it: property initialisers
* run in declaration order, and the other way round it is still null here.
*
* The field reports assignments to itself and nothing else: an in-place
* change to the object it holds (a `MutableList`, a `mutableStateListOf`)
* is not seen, and an assignment equal to the current value is dropped.
* Callers change such a field by assigning a new value.
*/
fun <T> notifying(initial: T): MutableState<T> = NotifyingState(mutableStateOf(initial), this)
}
Expand Down
20 changes: 20 additions & 0 deletions src/main/java/com/mapconductor/core/polygon/Polygon.kt
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,27 @@ class PolygonState(
*/
var clickable by mutations.notifying(clickable)
var zIndex by mutations.notifying(zIndex)

/**
* 外周の頂点。
*
* state が見ているのはこのプロパティへの代入だけ。渡したリストをその場で書き換えても
* 描き直されない(`mutableStateListOf` を渡して `add` / `set` する使い方は効かない)。
* 形を変えるときは新しいリストを代入する:
*
* ```
* polygonState.points = polygonState.points.toMutableList().apply { this[i] = moved }
* ```
*
* 内容の等しいリストの代入は無視される。その場で書き換えた同じリストを代入し直しても、
* 前の値と同じものなので何も起きない。
*/
var points by mutations.notifying<List<GeoPointInterface>>(points)

/**
* 穴(内周)の頂点。[points] と同じく、変えるときは新しいリストを代入する。
* 内側のリストをその場で書き換えても描き直されない。
*/
var holes by mutations.notifying<List<List<GeoPointInterface>>>(holes)
var extra by mutations.notifying(extra)
var onClick by mutations.notifying(onClick)
Expand Down
15 changes: 15 additions & 0 deletions src/main/java/com/mapconductor/core/polyline/Polyline.kt
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,21 @@ class PolylineState(
*/
var clickable by mutations.notifying(clickable)
var zIndex by mutations.notifying(zIndex)

/**
* 線の頂点。
*
* state が見ているのはこのプロパティへの代入だけ。渡したリストをその場で書き換えても
* 描き直されない(`mutableStateListOf` を渡して `add` / `set` する使い方は効かない)。
* 形を変えるときは新しいリストを代入する:
*
* ```
* polylineState.points = polylineState.points + nextPoint
* ```
*
* 内容の等しいリストの代入は無視される。その場で書き換えた同じリストを代入し直しても、
* 前の値と同じものなので何も起きない。
*/
var points by mutations.notifying<List<GeoPointInterface>>(points)
var extra by mutations.notifying(extra)
var onClick by mutations.notifying(onClick)
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/com/mapconductor/core/raster/RasterLayer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ class RasterLayerState(
var zIndex by mutations.notifying(zIndex)
var userAgent by mutations.notifying(userAgent)
var debug by mutations.notifying(debug)

/**
* タイル要求に足すヘッダー。変えるときは新しい Map を代入する。渡した Map をその場で
* 書き換えても state には伝わらず、内容の等しい Map の代入は無視される。
*/
var extraHeaders by mutations.notifying(extraHeaders)

private fun rasterLayerId(hashCodes: List<Int>): Int =
Expand Down
Loading