Skip to content

Commit

Permalink
Fix the issue that the empty polyline cannot be updated (#3046)
Browse files Browse the repository at this point in the history
  • Loading branch information
grab-liyanjin authored Nov 28, 2024
1 parent 69660be commit f547907
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,10 @@ class PolygonContainer implements Polygons {
@Override
public Polygon addBy(@NonNull PolygonOptions polygonOptions, @NonNull MapLibreMap maplibreMap) {
Polygon polygon = polygonOptions.getPolygon();
if (!polygon.getPoints().isEmpty()) {
long id = nativeMap != null ? nativeMap.addPolygon(polygon) : 0;
polygon.setId(id);
polygon.setMapLibreMap(maplibreMap);
annotations.put(id, polygon);
}
long id = nativeMap != null ? nativeMap.addPolygon(polygon) : 0;
polygon.setId(id);
polygon.setMapLibreMap(maplibreMap);
annotations.put(id, polygon);
return polygon;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,10 @@ class PolylineContainer implements Polylines {
@Override
public Polyline addBy(@NonNull PolylineOptions polylineOptions, @NonNull MapLibreMap maplibreMap) {
Polyline polyline = polylineOptions.getPolyline();
if (!polyline.getPoints().isEmpty()) {
long id = nativeMap != null ? nativeMap.addPolyline(polyline) : 0;
polyline.setMapLibreMap(maplibreMap);
polyline.setId(id);
annotations.put(id, polyline);
}
long id = nativeMap != null ? nativeMap.addPolyline(polyline) : 0;
polyline.setMapLibreMap(maplibreMap);
polyline.setId(id);
annotations.put(id, polyline);
return polyline;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,35 +8,43 @@ import org.maplibre.android.annotations.MarkerOptions
import org.maplibre.android.geometry.LatLng
import org.junit.Assert
import org.junit.Test
import org.maplibre.android.annotations.PolygonOptions
import org.maplibre.android.annotations.PolylineOptions
import org.mockito.ArgumentMatchers
import org.mockito.Mockito

class AnnotationManagerTest {

private val aNativeMapView: NativeMap = Mockito.mock(NativeMapView::class.java)
private val aMapView = Mockito.mock(MapView::class.java)
private val annotationsArray = LongSparseArray<Annotation>()
private val aIconManager = Mockito.mock(
IconManager::class.java
)
private val aMapLibreMap = Mockito.mock(MapLibreMap::class.java)

private val annotations: Annotations = AnnotationContainer(aNativeMapView, annotationsArray)
private val markers: Markers = MarkerContainer(aNativeMapView, annotationsArray, aIconManager)
private val polygons: Polygons = PolygonContainer(aNativeMapView, annotationsArray)
private val polylines: Polylines = PolylineContainer(aNativeMapView, annotationsArray)
private val shapeAnnotations: ShapeAnnotations =
ShapeAnnotationContainer(aNativeMapView, annotationsArray)


private val annotationManager = AnnotationManager(
aMapView,
annotationsArray,
aIconManager,
annotations,
markers,
polygons,
polylines,
shapeAnnotations
)

@Test
@Throws(Exception::class)
fun checksAddAMarker() {
val aNativeMapView: NativeMap = Mockito.mock(NativeMapView::class.java)
val aMapView = Mockito.mock(MapView::class.java)
val annotationsArray = LongSparseArray<Annotation>()
val aIconManager = Mockito.mock(
IconManager::class.java
)
val annotations: Annotations = AnnotationContainer(aNativeMapView, annotationsArray)
val markers: Markers = MarkerContainer(aNativeMapView, annotationsArray, aIconManager)
val polygons: Polygons = PolygonContainer(aNativeMapView, annotationsArray)
val polylines: Polylines = PolylineContainer(aNativeMapView, annotationsArray)
val shapeAnnotations: ShapeAnnotations =
ShapeAnnotationContainer(aNativeMapView, annotationsArray)
val annotationManager = AnnotationManager(
aMapView,
annotationsArray,
aIconManager,
annotations,
markers,
polygons,
polylines,
shapeAnnotations
)
val aMarker = Mockito.mock(
Marker::class.java
)
Expand All @@ -55,28 +63,6 @@ class AnnotationManagerTest {
@Test
@Throws(Exception::class)
fun checksAddMarkers() {
val aNativeMapView = Mockito.mock(NativeMapView::class.java)
val aMapView = Mockito.mock(MapView::class.java)
val annotationsArray = LongSparseArray<Annotation>()
val aIconManager = Mockito.mock(
IconManager::class.java
)
val annotations: Annotations = AnnotationContainer(aNativeMapView, annotationsArray)
val markers: Markers = MarkerContainer(aNativeMapView, annotationsArray, aIconManager)
val polygons: Polygons = PolygonContainer(aNativeMapView, annotationsArray)
val polylines: Polylines = PolylineContainer(aNativeMapView, annotationsArray)
val shapeAnnotations: ShapeAnnotations =
ShapeAnnotationContainer(aNativeMapView, annotationsArray)
val annotationManager = AnnotationManager(
aMapView,
annotationsArray,
aIconManager,
annotations,
markers,
polygons,
polylines,
shapeAnnotations
)
val firstId = 1L
val secondId = 2L
val markerList: MutableList<BaseMarkerOptions<*, *>> = ArrayList()
Expand All @@ -101,4 +87,33 @@ class AnnotationManagerTest {
Assert.assertEquals("first", (annotationManager.getAnnotation(firstId) as Marker).title)
Assert.assertEquals("second", (annotationManager.getAnnotation(secondId) as Marker).title)
}

@Test
@Throws(Exception::class)
fun checksAddEmptyPolygon() {
val pId = 5L
val polygonOptions = PolygonOptions()
val polygon = polygonOptions.polygon
Mockito.`when`(aNativeMapView.addPolygon(polygon)).thenReturn(pId)
val resultPolygon = annotationManager.addPolygon(polygonOptions, aMapLibreMap)
Assert.assertEquals(polygon, resultPolygon)
Assert.assertEquals(pId, resultPolygon.id)
Assert.assertEquals(1, annotationManager.annotations.size)
Assert.assertEquals(polygon, annotationManager.annotations[0])

}

@Test
@Throws(Exception::class)
fun checksAddEmptyPolyline() {
val pId = 5L
val polylineOptions = PolylineOptions()
val polyline = polylineOptions.polyline
Mockito.`when`(aNativeMapView.addPolyline(polyline)).thenReturn(pId)
val resultPolyline = annotationManager.addPolyline(polylineOptions, aMapLibreMap)
Assert.assertEquals(polyline, resultPolyline)
Assert.assertEquals(pId, resultPolyline.id)
Assert.assertEquals(1, annotationManager.annotations.size)
Assert.assertEquals(polyline, annotationManager.annotations[0])
}
}

0 comments on commit f547907

Please sign in to comment.