Skip to content

Commit f547907

Browse files
authoredNov 28, 2024··
Fix the issue that the empty polyline cannot be updated (#3046)
1 parent 69660be commit f547907

File tree

3 files changed

+67
-56
lines changed

3 files changed

+67
-56
lines changed
 

‎platform/android/MapLibreAndroid/src/main/java/org/maplibre/android/maps/PolygonContainer.java

+4-6
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,10 @@ class PolygonContainer implements Polygons {
2727
@Override
2828
public Polygon addBy(@NonNull PolygonOptions polygonOptions, @NonNull MapLibreMap maplibreMap) {
2929
Polygon polygon = polygonOptions.getPolygon();
30-
if (!polygon.getPoints().isEmpty()) {
31-
long id = nativeMap != null ? nativeMap.addPolygon(polygon) : 0;
32-
polygon.setId(id);
33-
polygon.setMapLibreMap(maplibreMap);
34-
annotations.put(id, polygon);
35-
}
30+
long id = nativeMap != null ? nativeMap.addPolygon(polygon) : 0;
31+
polygon.setId(id);
32+
polygon.setMapLibreMap(maplibreMap);
33+
annotations.put(id, polygon);
3634
return polygon;
3735
}
3836

‎platform/android/MapLibreAndroid/src/main/java/org/maplibre/android/maps/PolylineContainer.java

+4-6
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,10 @@ class PolylineContainer implements Polylines {
2727
@Override
2828
public Polyline addBy(@NonNull PolylineOptions polylineOptions, @NonNull MapLibreMap maplibreMap) {
2929
Polyline polyline = polylineOptions.getPolyline();
30-
if (!polyline.getPoints().isEmpty()) {
31-
long id = nativeMap != null ? nativeMap.addPolyline(polyline) : 0;
32-
polyline.setMapLibreMap(maplibreMap);
33-
polyline.setId(id);
34-
annotations.put(id, polyline);
35-
}
30+
long id = nativeMap != null ? nativeMap.addPolyline(polyline) : 0;
31+
polyline.setMapLibreMap(maplibreMap);
32+
polyline.setId(id);
33+
annotations.put(id, polyline);
3634
return polyline;
3735
}
3836

‎platform/android/MapLibreAndroid/src/test/java/org/maplibre/android/maps/AnnotationManagerTest.kt

+59-44
Original file line numberDiff line numberDiff line change
@@ -8,35 +8,43 @@ import org.maplibre.android.annotations.MarkerOptions
88
import org.maplibre.android.geometry.LatLng
99
import org.junit.Assert
1010
import org.junit.Test
11+
import org.maplibre.android.annotations.PolygonOptions
12+
import org.maplibre.android.annotations.PolylineOptions
1113
import org.mockito.ArgumentMatchers
1214
import org.mockito.Mockito
1315

1416
class AnnotationManagerTest {
17+
18+
private val aNativeMapView: NativeMap = Mockito.mock(NativeMapView::class.java)
19+
private val aMapView = Mockito.mock(MapView::class.java)
20+
private val annotationsArray = LongSparseArray<Annotation>()
21+
private val aIconManager = Mockito.mock(
22+
IconManager::class.java
23+
)
24+
private val aMapLibreMap = Mockito.mock(MapLibreMap::class.java)
25+
26+
private val annotations: Annotations = AnnotationContainer(aNativeMapView, annotationsArray)
27+
private val markers: Markers = MarkerContainer(aNativeMapView, annotationsArray, aIconManager)
28+
private val polygons: Polygons = PolygonContainer(aNativeMapView, annotationsArray)
29+
private val polylines: Polylines = PolylineContainer(aNativeMapView, annotationsArray)
30+
private val shapeAnnotations: ShapeAnnotations =
31+
ShapeAnnotationContainer(aNativeMapView, annotationsArray)
32+
33+
34+
private val annotationManager = AnnotationManager(
35+
aMapView,
36+
annotationsArray,
37+
aIconManager,
38+
annotations,
39+
markers,
40+
polygons,
41+
polylines,
42+
shapeAnnotations
43+
)
44+
1545
@Test
1646
@Throws(Exception::class)
1747
fun checksAddAMarker() {
18-
val aNativeMapView: NativeMap = Mockito.mock(NativeMapView::class.java)
19-
val aMapView = Mockito.mock(MapView::class.java)
20-
val annotationsArray = LongSparseArray<Annotation>()
21-
val aIconManager = Mockito.mock(
22-
IconManager::class.java
23-
)
24-
val annotations: Annotations = AnnotationContainer(aNativeMapView, annotationsArray)
25-
val markers: Markers = MarkerContainer(aNativeMapView, annotationsArray, aIconManager)
26-
val polygons: Polygons = PolygonContainer(aNativeMapView, annotationsArray)
27-
val polylines: Polylines = PolylineContainer(aNativeMapView, annotationsArray)
28-
val shapeAnnotations: ShapeAnnotations =
29-
ShapeAnnotationContainer(aNativeMapView, annotationsArray)
30-
val annotationManager = AnnotationManager(
31-
aMapView,
32-
annotationsArray,
33-
aIconManager,
34-
annotations,
35-
markers,
36-
polygons,
37-
polylines,
38-
shapeAnnotations
39-
)
4048
val aMarker = Mockito.mock(
4149
Marker::class.java
4250
)
@@ -55,28 +63,6 @@ class AnnotationManagerTest {
5563
@Test
5664
@Throws(Exception::class)
5765
fun checksAddMarkers() {
58-
val aNativeMapView = Mockito.mock(NativeMapView::class.java)
59-
val aMapView = Mockito.mock(MapView::class.java)
60-
val annotationsArray = LongSparseArray<Annotation>()
61-
val aIconManager = Mockito.mock(
62-
IconManager::class.java
63-
)
64-
val annotations: Annotations = AnnotationContainer(aNativeMapView, annotationsArray)
65-
val markers: Markers = MarkerContainer(aNativeMapView, annotationsArray, aIconManager)
66-
val polygons: Polygons = PolygonContainer(aNativeMapView, annotationsArray)
67-
val polylines: Polylines = PolylineContainer(aNativeMapView, annotationsArray)
68-
val shapeAnnotations: ShapeAnnotations =
69-
ShapeAnnotationContainer(aNativeMapView, annotationsArray)
70-
val annotationManager = AnnotationManager(
71-
aMapView,
72-
annotationsArray,
73-
aIconManager,
74-
annotations,
75-
markers,
76-
polygons,
77-
polylines,
78-
shapeAnnotations
79-
)
8066
val firstId = 1L
8167
val secondId = 2L
8268
val markerList: MutableList<BaseMarkerOptions<*, *>> = ArrayList()
@@ -101,4 +87,33 @@ class AnnotationManagerTest {
10187
Assert.assertEquals("first", (annotationManager.getAnnotation(firstId) as Marker).title)
10288
Assert.assertEquals("second", (annotationManager.getAnnotation(secondId) as Marker).title)
10389
}
90+
91+
@Test
92+
@Throws(Exception::class)
93+
fun checksAddEmptyPolygon() {
94+
val pId = 5L
95+
val polygonOptions = PolygonOptions()
96+
val polygon = polygonOptions.polygon
97+
Mockito.`when`(aNativeMapView.addPolygon(polygon)).thenReturn(pId)
98+
val resultPolygon = annotationManager.addPolygon(polygonOptions, aMapLibreMap)
99+
Assert.assertEquals(polygon, resultPolygon)
100+
Assert.assertEquals(pId, resultPolygon.id)
101+
Assert.assertEquals(1, annotationManager.annotations.size)
102+
Assert.assertEquals(polygon, annotationManager.annotations[0])
103+
104+
}
105+
106+
@Test
107+
@Throws(Exception::class)
108+
fun checksAddEmptyPolyline() {
109+
val pId = 5L
110+
val polylineOptions = PolylineOptions()
111+
val polyline = polylineOptions.polyline
112+
Mockito.`when`(aNativeMapView.addPolyline(polyline)).thenReturn(pId)
113+
val resultPolyline = annotationManager.addPolyline(polylineOptions, aMapLibreMap)
114+
Assert.assertEquals(polyline, resultPolyline)
115+
Assert.assertEquals(pId, resultPolyline.id)
116+
Assert.assertEquals(1, annotationManager.annotations.size)
117+
Assert.assertEquals(polyline, annotationManager.annotations[0])
118+
}
104119
}

0 commit comments

Comments
 (0)
Please sign in to comment.