Skip to content

Commit c8785f4

Browse files
authored
Annotation improvements (#1064)
* allAnnotations + customData * add changelog entry
1 parent 2b7e02b commit c8785f4

32 files changed

+726
-46
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
### 2.17.0-rc.1
2+
3+
* Add the ability to get all annotations from an annotation manager.
4+
* Add `customData` field to annotations to be able to pass user data.
5+
16
### 2.17.0-beta.1
27

38
> [!NOTE]

android/src/main/kotlin/com/mapbox/maps/mapbox_maps/annotation/CircleAnnotationController.kt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// This file is generated.
22
package com.mapbox.maps.mapbox_maps.annotation
33

4+
import com.google.gson.Gson
45
import com.mapbox.maps.mapbox_maps.pigeons.*
56
import com.mapbox.maps.plugin.annotation.generated.CircleAnnotationManager
67
import toCircleElevationReference
@@ -16,6 +17,14 @@ class CircleAnnotationController(private val delegate: ControllerDelegate) : _Ci
1617
private val annotationMap = mutableMapOf<String, com.mapbox.maps.plugin.annotation.generated.CircleAnnotation>()
1718
private val managerCreateAnnotationMap = mutableMapOf<String, MutableList<String>>()
1819

20+
override fun getAnnotations(
21+
managerId: String,
22+
callback: (Result<List<CircleAnnotation>>) -> Unit
23+
) {
24+
val manager = delegate.getManager(managerId) as CircleAnnotationManager
25+
callback(Result.success(manager.annotations.map { it.toFLTCircleAnnotation() }))
26+
}
27+
1928
override fun create(
2029
managerId: String,
2130
annotationOption: CircleAnnotationOptions,
@@ -490,6 +499,7 @@ fun com.mapbox.maps.plugin.annotation.generated.CircleAnnotation.toFLTCircleAnno
490499
circleStrokeColor = circleStrokeColorInt?.toUInt()?.toLong(),
491500
circleStrokeOpacity = circleStrokeOpacity,
492501
circleStrokeWidth = circleStrokeWidth,
502+
customData = if (getData() != null) Gson().fromJson<Map<String, Any>>(getData()!!, Map::class.java) else null
493503
)
494504
}
495505

@@ -525,6 +535,9 @@ fun CircleAnnotationOptions.toCircleAnnotationOptions(): com.mapbox.maps.plugin.
525535
this.circleStrokeWidth?.let {
526536
options.withCircleStrokeWidth(it)
527537
}
538+
this.customData?.let {
539+
options.withData(Gson().toJsonTree(it))
540+
}
528541
return options
529542
}
530543
// End of generated file.

android/src/main/kotlin/com/mapbox/maps/mapbox_maps/annotation/PointAnnotationController.kt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package com.mapbox.maps.mapbox_maps.annotation
33

44
import android.graphics.Bitmap
55
import android.graphics.BitmapFactory
6+
import com.google.gson.Gson
67
import com.mapbox.maps.mapbox_maps.pigeons.*
78
import com.mapbox.maps.plugin.annotation.generated.PointAnnotationManager
89
import toFLTIconAnchor
@@ -39,6 +40,14 @@ class PointAnnotationController(private val delegate: ControllerDelegate) : _Poi
3940
private val annotationMap = mutableMapOf<String, com.mapbox.maps.plugin.annotation.generated.PointAnnotation>()
4041
private val managerCreateAnnotationMap = mutableMapOf<String, MutableList<String>>()
4142

43+
override fun getAnnotations(
44+
managerId: String,
45+
callback: (Result<List<PointAnnotation>>) -> Unit
46+
) {
47+
val manager = delegate.getManager(managerId) as PointAnnotationManager
48+
callback(Result.success(manager.annotations.map { it.toFLTPointAnnotation() }))
49+
}
50+
4251
override fun create(
4352
managerId: String,
4453
annotationOption: PointAnnotationOptions,
@@ -1781,6 +1790,7 @@ fun com.mapbox.maps.plugin.annotation.generated.PointAnnotation.toFLTPointAnnota
17811790
textHaloWidth = textHaloWidth,
17821791
textOcclusionOpacity = textOcclusionOpacity,
17831792
textOpacity = textOpacity,
1793+
customData = if (getData() != null) Gson().fromJson<Map<String, Any>>(getData()!!, Map::class.java) else null
17841794
)
17851795
}
17861796

@@ -1900,6 +1910,9 @@ fun PointAnnotationOptions.toPointAnnotationOptions(): com.mapbox.maps.plugin.an
19001910
this.textOpacity?.let {
19011911
options.withTextOpacity(it)
19021912
}
1913+
this.customData?.let {
1914+
options.withData(Gson().toJsonTree(it))
1915+
}
19031916
return options
19041917
}
19051918
// End of generated file.

android/src/main/kotlin/com/mapbox/maps/mapbox_maps/annotation/PolygonAnnotationController.kt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// This file is generated.
22
package com.mapbox.maps.mapbox_maps.annotation
33

4+
import com.google.gson.Gson
45
import com.mapbox.maps.mapbox_maps.pigeons.*
56
import com.mapbox.maps.plugin.annotation.generated.PolygonAnnotationManager
67
import toFLTFillElevationReference
@@ -12,6 +13,14 @@ class PolygonAnnotationController(private val delegate: ControllerDelegate) : _P
1213
private val annotationMap = mutableMapOf<String, com.mapbox.maps.plugin.annotation.generated.PolygonAnnotation>()
1314
private val managerCreateAnnotationMap = mutableMapOf<String, MutableList<String>>()
1415

16+
override fun getAnnotations(
17+
managerId: String,
18+
callback: (Result<List<PolygonAnnotation>>) -> Unit
19+
) {
20+
val manager = delegate.getManager(managerId) as PolygonAnnotationManager
21+
callback(Result.success(manager.annotations.map { it.toFLTPolygonAnnotation() }))
22+
}
23+
1524
override fun create(
1625
managerId: String,
1726
annotationOption: PolygonAnnotationOptions,
@@ -492,6 +501,7 @@ fun com.mapbox.maps.plugin.annotation.generated.PolygonAnnotation.toFLTPolygonAn
492501
// colorInt is 32 bit and may be bigger than MAX_INT, so transfer to UInt firstly and then to Long.
493502
fillTunnelStructureColor = fillTunnelStructureColorInt?.toUInt()?.toLong(),
494503
fillZOffset = fillZOffset,
504+
customData = if (getData() != null) Gson().fromJson<Map<String, Any>>(getData()!!, Map::class.java) else null
495505
)
496506
}
497507

@@ -530,6 +540,9 @@ fun PolygonAnnotationOptions.toPolygonAnnotationOptions(): com.mapbox.maps.plugi
530540
this.fillZOffset?.let {
531541
options.withFillZOffset(it)
532542
}
543+
this.customData?.let {
544+
options.withData(Gson().toJsonTree(it))
545+
}
533546
return options
534547
}
535548
// End of generated file.

android/src/main/kotlin/com/mapbox/maps/mapbox_maps/annotation/PolylineAnnotationController.kt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// This file is generated.
22
package com.mapbox.maps.mapbox_maps.annotation
33

4+
import com.google.gson.Gson
45
import com.mapbox.maps.extension.style.utils.ColorUtils
56
import com.mapbox.maps.mapbox_maps.pigeons.*
67
import com.mapbox.maps.plugin.annotation.generated.PolylineAnnotationManager
@@ -19,6 +20,14 @@ class PolylineAnnotationController(private val delegate: ControllerDelegate) : _
1920
private val annotationMap = mutableMapOf<String, com.mapbox.maps.plugin.annotation.generated.PolylineAnnotation>()
2021
private val managerCreateAnnotationMap = mutableMapOf<String, MutableList<String>>()
2122

23+
override fun getAnnotations(
24+
managerId: String,
25+
callback: (Result<List<PolylineAnnotation>>) -> Unit
26+
) {
27+
val manager = delegate.getManager(managerId) as PolylineAnnotationManager
28+
callback(Result.success(manager.annotations.map { it.toFLTPolylineAnnotation() }))
29+
}
30+
2231
override fun create(
2332
managerId: String,
2433
annotationOption: PolylineAnnotationOptions,
@@ -877,6 +886,7 @@ fun com.mapbox.maps.plugin.annotation.generated.PolylineAnnotation.toFLTPolyline
877886
lineOpacity = lineOpacity,
878887
linePattern = linePattern,
879888
lineWidth = lineWidth,
889+
customData = if (getData() != null) Gson().fromJson<Map<String, Any>>(getData()!!, Map::class.java) else null
880890
)
881891
}
882892

@@ -924,6 +934,9 @@ fun PolylineAnnotationOptions.toPolylineAnnotationOptions(): com.mapbox.maps.plu
924934
this.lineWidth?.let {
925935
options.withLineWidth(it)
926936
}
937+
this.customData?.let {
938+
options.withData(Gson().toJsonTree(it))
939+
}
927940
return options
928941
}
929942
// End of generated file.

android/src/main/kotlin/com/mapbox/maps/mapbox_maps/pigeons/CircleAnnotationMessenger.kt

Lines changed: 62 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,31 @@ private fun wrapError(exception: Throwable): List<Any?> {
3333
)
3434
}
3535
}
36+
private fun deepEqualsCircleAnnotationMessenger(a: Any?, b: Any?): Boolean {
37+
if (a is ByteArray && b is ByteArray) {
38+
return a.contentEquals(b)
39+
}
40+
if (a is IntArray && b is IntArray) {
41+
return a.contentEquals(b)
42+
}
43+
if (a is LongArray && b is LongArray) {
44+
return a.contentEquals(b)
45+
}
46+
if (a is DoubleArray && b is DoubleArray) {
47+
return a.contentEquals(b)
48+
}
49+
if (a is Array<*> && b is Array<*>) {
50+
return a.size == b.size &&
51+
a.indices.all { deepEqualsCircleAnnotationMessenger(a[it], b[it]) }
52+
}
53+
if (a is Map<*, *> && b is Map<*, *>) {
54+
return a.size == b.size && a.keys.all {
55+
(b as Map<Any?, Any?>).containsKey(it) &&
56+
deepEqualsCircleAnnotationMessenger(a[it], b[it])
57+
}
58+
}
59+
return a == b
60+
}
3661

3762
/**
3863
* Selects the base of circle-elevation. Some modes might require precomputed elevation data in the tileset.
@@ -146,7 +171,9 @@ data class CircleAnnotation(
146171
*/
147172
val circleStrokeWidth: Double? = null,
148173
/** Property to determine whether annotation can be manually moved around map. */
149-
val isDraggable: Boolean? = null
174+
val isDraggable: Boolean? = null,
175+
/** JSON convertible properties associated with the annotation, used to enrich Feature GeoJSON `properties["custom_data"]` field. */
176+
val customData: Map<String, Any>? = null
150177
) {
151178
companion object {
152179
fun fromList(pigeonVar_list: List<Any?>): CircleAnnotation {
@@ -161,7 +188,8 @@ data class CircleAnnotation(
161188
val circleStrokeOpacity = pigeonVar_list[8] as Double?
162189
val circleStrokeWidth = pigeonVar_list[9] as Double?
163190
val isDraggable = pigeonVar_list[10] as Boolean?
164-
return CircleAnnotation(id, geometry, circleSortKey, circleBlur, circleColor, circleOpacity, circleRadius, circleStrokeColor, circleStrokeOpacity, circleStrokeWidth, isDraggable)
191+
val customData = pigeonVar_list[11] as Map<String, Any>?
192+
return CircleAnnotation(id, geometry, circleSortKey, circleBlur, circleColor, circleOpacity, circleRadius, circleStrokeColor, circleStrokeOpacity, circleStrokeWidth, isDraggable, customData)
165193
}
166194
}
167195
fun toList(): List<Any?> {
@@ -177,6 +205,7 @@ data class CircleAnnotation(
177205
circleStrokeOpacity,
178206
circleStrokeWidth,
179207
isDraggable,
208+
customData,
180209
)
181210
}
182211
override fun equals(other: Any?): Boolean {
@@ -196,7 +225,8 @@ data class CircleAnnotation(
196225
circleStrokeColor == other.circleStrokeColor &&
197226
circleStrokeOpacity == other.circleStrokeOpacity &&
198227
circleStrokeWidth == other.circleStrokeWidth &&
199-
isDraggable == other.isDraggable
228+
isDraggable == other.isDraggable &&
229+
deepEqualsCircleAnnotationMessenger(customData, other.customData)
200230
}
201231

202232
override fun hashCode(): Int = toList().hashCode()
@@ -244,7 +274,9 @@ data class CircleAnnotationOptions(
244274
*/
245275
val circleStrokeWidth: Double? = null,
246276
/** Property to determine whether annotation can be manually moved around map. */
247-
val isDraggable: Boolean? = null
277+
val isDraggable: Boolean? = null,
278+
/** JSON convertible properties associated with the annotation, used to enrich Feature GeoJSON `properties["custom_data"]` field. */
279+
val customData: Map<String, Any>? = null
248280
) {
249281
companion object {
250282
fun fromList(pigeonVar_list: List<Any?>): CircleAnnotationOptions {
@@ -258,7 +290,8 @@ data class CircleAnnotationOptions(
258290
val circleStrokeOpacity = pigeonVar_list[7] as Double?
259291
val circleStrokeWidth = pigeonVar_list[8] as Double?
260292
val isDraggable = pigeonVar_list[9] as Boolean?
261-
return CircleAnnotationOptions(geometry, circleSortKey, circleBlur, circleColor, circleOpacity, circleRadius, circleStrokeColor, circleStrokeOpacity, circleStrokeWidth, isDraggable)
293+
val customData = pigeonVar_list[10] as Map<String, Any>?
294+
return CircleAnnotationOptions(geometry, circleSortKey, circleBlur, circleColor, circleOpacity, circleRadius, circleStrokeColor, circleStrokeOpacity, circleStrokeWidth, isDraggable, customData)
262295
}
263296
}
264297
fun toList(): List<Any?> {
@@ -273,6 +306,7 @@ data class CircleAnnotationOptions(
273306
circleStrokeOpacity,
274307
circleStrokeWidth,
275308
isDraggable,
309+
customData,
276310
)
277311
}
278312
override fun equals(other: Any?): Boolean {
@@ -291,7 +325,8 @@ data class CircleAnnotationOptions(
291325
circleStrokeColor == other.circleStrokeColor &&
292326
circleStrokeOpacity == other.circleStrokeOpacity &&
293327
circleStrokeWidth == other.circleStrokeWidth &&
294-
isDraggable == other.isDraggable
328+
isDraggable == other.isDraggable &&
329+
deepEqualsCircleAnnotationMessenger(customData, other.customData)
295330
}
296331

297332
override fun hashCode(): Int = toList().hashCode()
@@ -374,6 +409,7 @@ private open class CircleAnnotationMessengerPigeonCodec : StandardMessageCodec()
374409

375410
/** Generated interface from Pigeon that represents a handler of messages from Flutter. */
376411
interface _CircleAnnotationMessenger {
412+
fun getAnnotations(managerId: String, callback: (Result<List<CircleAnnotation>>) -> Unit)
377413
fun create(managerId: String, annotationOption: CircleAnnotationOptions, callback: (Result<CircleAnnotation>) -> Unit)
378414
fun createMulti(managerId: String, annotationOptions: List<CircleAnnotationOptions>, callback: (Result<List<CircleAnnotation>>) -> Unit)
379415
fun update(managerId: String, annotation: CircleAnnotation, callback: (Result<Unit>) -> Unit)
@@ -417,6 +453,26 @@ interface _CircleAnnotationMessenger {
417453
@JvmOverloads
418454
fun setUp(binaryMessenger: BinaryMessenger, api: _CircleAnnotationMessenger?, messageChannelSuffix: String = "") {
419455
val separatedMessageChannelSuffix = if (messageChannelSuffix.isNotEmpty()) ".$messageChannelSuffix" else ""
456+
run {
457+
val channel = BasicMessageChannel<Any?>(binaryMessenger, "dev.flutter.pigeon.mapbox_maps_flutter._CircleAnnotationMessenger.getAnnotations$separatedMessageChannelSuffix", codec)
458+
if (api != null) {
459+
channel.setMessageHandler { message, reply ->
460+
val args = message as List<Any?>
461+
val managerIdArg = args[0] as String
462+
api.getAnnotations(managerIdArg) { result: Result<List<CircleAnnotation>> ->
463+
val error = result.exceptionOrNull()
464+
if (error != null) {
465+
reply.reply(wrapError(error))
466+
} else {
467+
val data = result.getOrNull()
468+
reply.reply(wrapResult(data))
469+
}
470+
}
471+
}
472+
} else {
473+
channel.setMessageHandler(null)
474+
}
475+
}
420476
run {
421477
val channel = BasicMessageChannel<Any?>(binaryMessenger, "dev.flutter.pigeon.mapbox_maps_flutter._CircleAnnotationMessenger.create$separatedMessageChannelSuffix", codec)
422478
if (api != null) {

0 commit comments

Comments
 (0)