Loading play-services-maps-core-mapbox/src/main/kotlin/org/microg/gms/maps/mapbox/model/Circle.kt +36 −36 Original line number Diff line number Diff line Loading @@ -34,15 +34,14 @@ import com.mapbox.turf.TurfTransformation import org.microg.gms.maps.mapbox.GoogleMapImpl import com.google.android.gms.maps.model.CircleOptions as GmsCircleOptions val NORTH_POLE = Point.fromLngLat(0.0, 90.0) val SOUTH_POLE = Point.fromLngLat(0.0, -90.0) val NORTH_POLE: Point = Point.fromLngLat(0.0, 90.0) val SOUTH_POLE: Point = Point.fromLngLat(0.0, -90.0) /** * Amount of points to be used in the polygon that approximates the circle. */ const val CIRCLE_POLYGON_STEPS = 256 class CircleImpl(private val map: GoogleMapImpl, private val id: String, options: GmsCircleOptions) : ICircleDelegate.Stub(), Markup<Fill, FillOptions> { private var center: LatLng = options.center private var radius: Double = options.radius // in meters Loading Loading @@ -94,10 +93,10 @@ class CircleImpl(private val map: GoogleMapImpl, private val id: String, options ) * 1000 < radius } private fun makeOutlineLatLngs() = TurfMeta.coordAll( private fun makeOutlineLatLngs(): MutableList<Point> { val pointList = TurfMeta.coordAll( makePolygon(), wrapsAroundPoles() ).let { ) // Circles around the poles are tricky to draw (https://github.com/mapbox/mapbox-gl-js/issues/11235). // We modify our lines such to match the way Mapbox / MapLibre draws them. // This results in a small gap somewhere in the line, but avoids an incorrect horizontal line. Loading @@ -106,33 +105,34 @@ class CircleImpl(private val map: GoogleMapImpl, private val id: String, options if (!centerPoint.equals(NORTH_POLE) && TurfMeasurement.distance(centerPoint, NORTH_POLE) * 1000 < radius) { // Wraps around North Pole for (i in 0 until it.size) { for (i in 0 until pointList.size) { // We want to have the north-most points at the start and end if (it[0].latitude() > it[1].latitude() && it[it.size-1].latitude() > it[it.size-2].latitude()) { return@let it if (pointList[0].latitude() > pointList[1].latitude() && pointList[pointList.size - 1].latitude() > pointList[pointList.size - 2].latitude()) { return pointList } else { // Cycle point list val zero = it.removeFirst() it.add(zero) val zero = pointList.removeFirst() pointList.add(zero) } } } if (!centerPoint.equals(SOUTH_POLE) && TurfMeasurement.distance(centerPoint, SOUTH_POLE) * 1000 < radius) { // Wraps around South Pole for (i in 0 until it.size) { for (i in 0 until pointList.size) { // We want to have the south-most points at the start and end if (it[0].latitude() < it[1].latitude() && it[it.size-1].latitude() < it[it.size-2].latitude()) { return@let it if (pointList[0].latitude() < pointList[1].latitude() && pointList[pointList.size - 1].latitude() < pointList[pointList.size - 2].latitude()) { return pointList } else { // Cycle point list val last = it.removeAt(it.size - 1) it.add(0, last) val last = pointList.removeAt(pointList.size - 1) pointList.add(0, last) } } } it // In this case no changes were made return pointList } private fun updateLatLngs() { Loading Loading
play-services-maps-core-mapbox/src/main/kotlin/org/microg/gms/maps/mapbox/model/Circle.kt +36 −36 Original line number Diff line number Diff line Loading @@ -34,15 +34,14 @@ import com.mapbox.turf.TurfTransformation import org.microg.gms.maps.mapbox.GoogleMapImpl import com.google.android.gms.maps.model.CircleOptions as GmsCircleOptions val NORTH_POLE = Point.fromLngLat(0.0, 90.0) val SOUTH_POLE = Point.fromLngLat(0.0, -90.0) val NORTH_POLE: Point = Point.fromLngLat(0.0, 90.0) val SOUTH_POLE: Point = Point.fromLngLat(0.0, -90.0) /** * Amount of points to be used in the polygon that approximates the circle. */ const val CIRCLE_POLYGON_STEPS = 256 class CircleImpl(private val map: GoogleMapImpl, private val id: String, options: GmsCircleOptions) : ICircleDelegate.Stub(), Markup<Fill, FillOptions> { private var center: LatLng = options.center private var radius: Double = options.radius // in meters Loading Loading @@ -94,10 +93,10 @@ class CircleImpl(private val map: GoogleMapImpl, private val id: String, options ) * 1000 < radius } private fun makeOutlineLatLngs() = TurfMeta.coordAll( private fun makeOutlineLatLngs(): MutableList<Point> { val pointList = TurfMeta.coordAll( makePolygon(), wrapsAroundPoles() ).let { ) // Circles around the poles are tricky to draw (https://github.com/mapbox/mapbox-gl-js/issues/11235). // We modify our lines such to match the way Mapbox / MapLibre draws them. // This results in a small gap somewhere in the line, but avoids an incorrect horizontal line. Loading @@ -106,33 +105,34 @@ class CircleImpl(private val map: GoogleMapImpl, private val id: String, options if (!centerPoint.equals(NORTH_POLE) && TurfMeasurement.distance(centerPoint, NORTH_POLE) * 1000 < radius) { // Wraps around North Pole for (i in 0 until it.size) { for (i in 0 until pointList.size) { // We want to have the north-most points at the start and end if (it[0].latitude() > it[1].latitude() && it[it.size-1].latitude() > it[it.size-2].latitude()) { return@let it if (pointList[0].latitude() > pointList[1].latitude() && pointList[pointList.size - 1].latitude() > pointList[pointList.size - 2].latitude()) { return pointList } else { // Cycle point list val zero = it.removeFirst() it.add(zero) val zero = pointList.removeFirst() pointList.add(zero) } } } if (!centerPoint.equals(SOUTH_POLE) && TurfMeasurement.distance(centerPoint, SOUTH_POLE) * 1000 < radius) { // Wraps around South Pole for (i in 0 until it.size) { for (i in 0 until pointList.size) { // We want to have the south-most points at the start and end if (it[0].latitude() < it[1].latitude() && it[it.size-1].latitude() < it[it.size-2].latitude()) { return@let it if (pointList[0].latitude() < pointList[1].latitude() && pointList[pointList.size - 1].latitude() < pointList[pointList.size - 2].latitude()) { return pointList } else { // Cycle point list val last = it.removeAt(it.size - 1) it.add(0, last) val last = pointList.removeAt(pointList.size - 1) pointList.add(0, last) } } } it // In this case no changes were made return pointList } private fun updateLatLngs() { Loading