Skip to content

Commit 9b714e5

Browse files
authored
[Port] Fix multiple annotation clusters not supported issue. (#2631) (#2642)
1 parent 42512c1 commit 9b714e5

File tree

7 files changed

+32
-88
lines changed

7 files changed

+32
-88
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
Mapbox welcomes participation and contributions from everyone.
44

5+
# 10.18.3
6+
## Bug fixes 🐞
7+
* Fix multiple annotation clusters not supported issue.
58

69
# 10.18.2 June 24, 2024
710
## Features ✨ and improvements 🏁

plugin-annotation/api/PublicRelease/metalava.txt

Lines changed: 7 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,13 @@ package com.mapbox.maps.plugin.annotation {
4747
property protected abstract String layerId;
4848
property public java.util.List<V> longClickListeners;
4949
property protected abstract String sourceId;
50+
field public static final com.mapbox.maps.plugin.annotation.AnnotationManagerImpl.Companion Companion;
51+
}
52+
53+
public static final class AnnotationManagerImpl.Companion {
54+
method public java.util.concurrent.atomic.AtomicLong getID_GENERATOR();
55+
method public void setID_GENERATOR(java.util.concurrent.atomic.AtomicLong ID_GENERATOR);
56+
property public final java.util.concurrent.atomic.AtomicLong ID_GENERATOR;
5057
}
5158

5259
public final class AnnotationManagerImpl.MapClick implements com.mapbox.maps.plugin.gestures.OnMapClickListener {
@@ -176,13 +183,6 @@ package com.mapbox.maps.plugin.annotation.generated {
176183
property public com.mapbox.maps.extension.style.expressions.generated.Expression? layerFilter;
177184
property protected String layerId;
178185
property protected String sourceId;
179-
field public static final com.mapbox.maps.plugin.annotation.generated.CircleAnnotationManager.Companion Companion;
180-
}
181-
182-
public static final class CircleAnnotationManager.Companion {
183-
method public java.util.concurrent.atomic.AtomicLong getID_GENERATOR();
184-
method public void setID_GENERATOR(java.util.concurrent.atomic.AtomicLong ID_GENERATOR);
185-
property public final java.util.concurrent.atomic.AtomicLong ID_GENERATOR;
186186
}
187187

188188
public final class CircleAnnotationManagerKt {
@@ -518,13 +518,6 @@ package com.mapbox.maps.plugin.annotation.generated {
518518
property public final com.mapbox.maps.extension.style.layers.properties.generated.TextTranslateAnchor? textTranslateAnchor;
519519
property public final java.util.List<java.lang.String>? textVariableAnchor;
520520
property public final java.util.List<java.lang.String>? textWritingMode;
521-
field public static final com.mapbox.maps.plugin.annotation.generated.PointAnnotationManager.Companion Companion;
522-
}
523-
524-
public static final class PointAnnotationManager.Companion {
525-
method public java.util.concurrent.atomic.AtomicLong getID_GENERATOR();
526-
method public void setID_GENERATOR(java.util.concurrent.atomic.AtomicLong ID_GENERATOR);
527-
property public final java.util.concurrent.atomic.AtomicLong ID_GENERATOR;
528521
}
529522

530523
public final class PointAnnotationManagerKt {
@@ -756,13 +749,6 @@ package com.mapbox.maps.plugin.annotation.generated {
756749
property public com.mapbox.maps.extension.style.expressions.generated.Expression? layerFilter;
757750
property protected String layerId;
758751
property protected String sourceId;
759-
field public static final com.mapbox.maps.plugin.annotation.generated.PolygonAnnotationManager.Companion Companion;
760-
}
761-
762-
public static final class PolygonAnnotationManager.Companion {
763-
method public java.util.concurrent.atomic.AtomicLong getID_GENERATOR();
764-
method public void setID_GENERATOR(java.util.concurrent.atomic.AtomicLong ID_GENERATOR);
765-
property public final java.util.concurrent.atomic.AtomicLong ID_GENERATOR;
766752
}
767753

768754
public final class PolygonAnnotationManagerKt {
@@ -902,13 +888,6 @@ package com.mapbox.maps.plugin.annotation.generated {
902888
property public final com.mapbox.maps.extension.style.layers.properties.generated.LineTranslateAnchor? lineTranslateAnchor;
903889
property public final java.util.List<java.lang.Double>? lineTrimOffset;
904890
property protected String sourceId;
905-
field public static final com.mapbox.maps.plugin.annotation.generated.PolylineAnnotationManager.Companion Companion;
906-
}
907-
908-
public static final class PolylineAnnotationManager.Companion {
909-
method public java.util.concurrent.atomic.AtomicLong getID_GENERATOR();
910-
method public void setID_GENERATOR(java.util.concurrent.atomic.AtomicLong ID_GENERATOR);
911-
property public final java.util.concurrent.atomic.AtomicLong ID_GENERATOR;
912891
}
913892

914893
public final class PolylineAnnotationManagerKt {

plugin-annotation/src/main/java/com/mapbox/maps/plugin/annotation/AnnotationManagerImpl.kt

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ import java.util.*
4040
import java.util.concurrent.ConcurrentHashMap
4141
import java.util.concurrent.CountDownLatch
4242
import java.util.concurrent.TimeUnit
43+
import java.util.concurrent.atomic.AtomicLong
4344

4445
/**
4546
* Base class for annotation managers
@@ -49,6 +50,7 @@ abstract class AnnotationManagerImpl<G : Geometry, T : Annotation<G>, S : Annota
4950
final override val delegateProvider: MapDelegateProvider,
5051
private val annotationConfig: AnnotationConfig?
5152
) : AnnotationManager<G, T, S, D, U, V, I> {
53+
internal val id: Long = ID_GENERATOR.incrementAndGet()
5254
private var mapCameraManagerDelegate: MapCameraManagerDelegate =
5355
delegateProvider.mapCameraManagerDelegate
5456
private var mapFeatureQueryDelegate: MapFeatureQueryDelegate =
@@ -70,6 +72,9 @@ abstract class AnnotationManagerImpl<G : Geometry, T : Annotation<G>, S : Annota
7072
protected abstract val dragLayerId: String
7173
protected abstract val dragSourceId: String
7274

75+
private val associatedLayers = mutableListOf<String>()
76+
private val associatedSources = mutableListOf<String>()
77+
7378
@Suppress("UNCHECKED_CAST")
7479
private var gesturesPlugin: GesturesPlugin = delegateProvider.mapPluginProviderDelegate.getPlugin(
7580
MAPBOX_GESTURES_PLUGIN_ID
@@ -207,6 +212,7 @@ abstract class AnnotationManagerImpl<G : Geometry, T : Annotation<G>, S : Annota
207212
source?.let {
208213
if (!style.styleSourceExists(it.sourceId)) {
209214
style.addSource(it)
215+
associatedSources.add(it.sourceId)
210216
}
211217
}
212218

@@ -228,19 +234,22 @@ abstract class AnnotationManagerImpl<G : Geometry, T : Annotation<G>, S : Annota
228234
if (!layerAdded) {
229235
style.addPersistentLayer(it)
230236
}
237+
associatedLayers.add(it.layerId)
231238
}
232239
}
233240

234241
dragSource?.let {
235242
if (!style.styleSourceExists(it.sourceId)) {
236243
style.addSource(it)
244+
associatedSources.add(it.sourceId)
237245
}
238246
}
239247
dragLayer?.let {
240248
if (!style.styleLayerExists(it.layerId)) {
241249
layer?.layerId?.let { aboveLayerId ->
242250
// Add drag layer above the annotation layer
243251
style.addPersistentLayer(it, LayerPosition(aboveLayerId, null, null))
252+
associatedLayers.add(it.layerId)
244253
}
245254
}
246255
}
@@ -257,17 +266,19 @@ abstract class AnnotationManagerImpl<G : Geometry, T : Annotation<G>, S : Annota
257266
val clusterLevelLayer = createClusterLevelLayer(level, it.colorLevels)
258267
if (!style.styleLayerExists(clusterLevelLayer.layerId)) {
259268
style.addPersistentLayer(clusterLevelLayer)
269+
associatedLayers.add(clusterLevelLayer.layerId)
260270
}
261271
}
262272
val clusterTextLayer = createClusterTextLayer()
263273
if (!style.styleLayerExists(clusterTextLayer.layerId)) {
264274
style.addPersistentLayer(clusterTextLayer)
275+
associatedLayers.add(clusterTextLayer.layerId)
265276
}
266277
}
267278
}
268279

269280
private fun createClusterLevelLayer(level: Int, colorLevels: List<Pair<Int, Int>>) =
270-
circleLayer("mapbox-android-cluster-circle-layer-$level", sourceId) {
281+
circleLayer("mapbox-android-cluster-circle-layer-$id-level-$level", sourceId) {
271282
circleColor(colorLevels[level].second)
272283
annotationConfig?.annotationSourceOptions?.clusterOptions?.let {
273284
if (it.circleRadiusExpression == null) {
@@ -289,7 +300,7 @@ abstract class AnnotationManagerImpl<G : Geometry, T : Annotation<G>, S : Annota
289300
)
290301
}
291302

292-
private fun createClusterTextLayer() = symbolLayer(CLUSTER_TEXT_LAYER_ID, sourceId) {
303+
private fun createClusterTextLayer() = symbolLayer("mapbox-android-cluster-text-layer-$id", sourceId) {
293304
annotationConfig?.annotationSourceOptions?.clusterOptions?.let {
294305
textField(if (it.textField == null) DEFAULT_TEXT_FIELD else it.textField as Expression)
295306
if (it.textSizeExpression == null) {
@@ -516,24 +527,14 @@ abstract class AnnotationManagerImpl<G : Geometry, T : Annotation<G>, S : Annota
516527
*/
517528
override fun onDestroy() {
518529
delegateProvider.getStyle { style ->
519-
layer?.let {
520-
if (style.styleLayerExists(it.layerId)) {
521-
style.removeStyleLayer(it.layerId)
522-
}
523-
}
524-
source?.let {
525-
if (style.styleSourceExists(it.sourceId)) {
526-
style.removeStyleSource(it.sourceId)
527-
}
528-
}
529-
dragLayer?.let {
530-
if (style.styleLayerExists(it.layerId)) {
531-
style.removeStyleLayer(it.layerId)
530+
associatedLayers.forEach {
531+
if (style.styleLayerExists(it)) {
532+
style.removeStyleLayer(it)
532533
}
533534
}
534-
dragSource?.let {
535-
if (style.styleSourceExists(it.sourceId)) {
536-
style.removeStyleSource(it.sourceId)
535+
associatedSources.forEach {
536+
if (style.styleSourceExists(it)) {
537+
style.removeStyleSource(it)
537538
}
538539
}
539540
}
@@ -874,7 +875,7 @@ abstract class AnnotationManagerImpl<G : Geometry, T : Annotation<G>, S : Annota
874875
/**
875876
* Static variables and methods.
876877
*/
877-
private companion object {
878+
companion object {
878879
/**
879880
* Tag for log
880881
*/
@@ -883,7 +884,8 @@ abstract class AnnotationManagerImpl<G : Geometry, T : Annotation<G>, S : Annota
883884

884885
/** At most wait 2 seconds to prevent ANR */
885886
private const val QUERY_WAIT_TIME = 2L
886-
private const val CLUSTER_TEXT_LAYER_ID = "mapbox-android-cluster-text-layer"
887887
private val DEFAULT_TEXT_FIELD = get("point_count")
888+
/** The generator for id */
889+
var ID_GENERATOR = AtomicLong(0)
888890
}
889891
}

plugin-annotation/src/public/java/com/mapbox/maps/plugin/annotation/generated/CircleAnnotationManager.kt

Lines changed: 0 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

plugin-annotation/src/public/java/com/mapbox/maps/plugin/annotation/generated/PointAnnotationManager.kt

Lines changed: 0 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

plugin-annotation/src/public/java/com/mapbox/maps/plugin/annotation/generated/PolygonAnnotationManager.kt

Lines changed: 0 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

plugin-annotation/src/public/java/com/mapbox/maps/plugin/annotation/generated/PolylineAnnotationManager.kt

Lines changed: 0 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)