Loading play-services-maps/core/mapbox/src/main/kotlin/org/microg/gms/maps/mapbox/model/GroundOverlay.kt +34 −0 Original line number Diff line number Diff line Loading @@ -16,8 +16,11 @@ import com.google.android.gms.maps.model.LatLngBounds import com.google.android.gms.maps.model.internal.IGroundOverlayDelegate import org.microg.gms.maps.mapbox.GoogleMapImpl import org.microg.gms.utils.warnOnTransactionIssues import kotlin.math.cos import kotlin.math.min class GroundOverlayImpl(private val map: GoogleMapImpl, private val id: String, options: GroundOverlayOptions) : IGroundOverlayDelegate.Stub() { private val image: BitmapDescriptorImpl? = options.image?.remoteObject?.unwrap() private var location: LatLng? = options.location private var width: Float = options.width private var height: Float = options.height Loading @@ -26,9 +29,39 @@ class GroundOverlayImpl(private val map: GoogleMapImpl, private val id: String, private var zIndex: Float = options.zIndex private var visible: Boolean = options.isVisible private var transparency: Float = options.transparency private var anchorU: Float = options.anchorU private var anchorV: Float = options.anchorV private var clickable: Boolean = options.isClickable private var tag: Any? = null init { // Compute missing values if (height < 0 || height.isNaN()) { val imageHeight = image?.size?.getOrNull(0) ?: -1f val imageWidth = image?.size?.getOrNull(1) ?: -1f if (imageHeight >= 0 && imageWidth > 0) { height = (imageHeight / imageWidth) * width } } if (bounds == null && width >= 0 && height >= 0 && location != null) { val latitudeSpan = Math.toDegrees(height.toDouble() / EARTH_RADIUS) val longitudeSpan = min(Math.toDegrees(width.toDouble() / (cos(Math.toRadians(location!!.latitude)) * EARTH_RADIUS)), 359.999999) val north = location!!.latitude + (latitudeSpan * anchorV) val south = location!!.latitude - (latitudeSpan * (1.0 - anchorV)) val west = location!!.longitude - (longitudeSpan * anchorU) val east = location!!.longitude + (longitudeSpan * (1.0 - anchorU)) bounds = LatLngBounds(LatLng(south, west), LatLng(north, east)) } if (location == null && bounds != null) { val north = bounds!!.northeast.latitude val south = bounds!!.southwest.latitude var east = bounds!!.northeast.longitude val west = bounds!!.southwest.longitude while (east < west) east += 360.0 location = LatLng((1.0 - anchorV) * north + anchorV * south, (1.0 - anchorU) * west + anchorU * east) } } override fun getId(): String { return id } Loading Loading @@ -136,5 +169,6 @@ class GroundOverlayImpl(private val map: GoogleMapImpl, private val id: String, companion object { private const val TAG = "GroundOverlay" private const val EARTH_RADIUS = 6371009.0 } } play-services-maps/src/main/java/com/google/android/gms/maps/model/GroundOverlayOptions.java +1 −1 Original line number Diff line number Diff line Loading @@ -35,7 +35,7 @@ public class GroundOverlayOptions extends AutoSafeParcelable { @Field(4) private float width; @Field(5) private float height; private float height = NO_DIMENSION; @Field(6) private LatLngBounds bounds; @Field(7) Loading Loading
play-services-maps/core/mapbox/src/main/kotlin/org/microg/gms/maps/mapbox/model/GroundOverlay.kt +34 −0 Original line number Diff line number Diff line Loading @@ -16,8 +16,11 @@ import com.google.android.gms.maps.model.LatLngBounds import com.google.android.gms.maps.model.internal.IGroundOverlayDelegate import org.microg.gms.maps.mapbox.GoogleMapImpl import org.microg.gms.utils.warnOnTransactionIssues import kotlin.math.cos import kotlin.math.min class GroundOverlayImpl(private val map: GoogleMapImpl, private val id: String, options: GroundOverlayOptions) : IGroundOverlayDelegate.Stub() { private val image: BitmapDescriptorImpl? = options.image?.remoteObject?.unwrap() private var location: LatLng? = options.location private var width: Float = options.width private var height: Float = options.height Loading @@ -26,9 +29,39 @@ class GroundOverlayImpl(private val map: GoogleMapImpl, private val id: String, private var zIndex: Float = options.zIndex private var visible: Boolean = options.isVisible private var transparency: Float = options.transparency private var anchorU: Float = options.anchorU private var anchorV: Float = options.anchorV private var clickable: Boolean = options.isClickable private var tag: Any? = null init { // Compute missing values if (height < 0 || height.isNaN()) { val imageHeight = image?.size?.getOrNull(0) ?: -1f val imageWidth = image?.size?.getOrNull(1) ?: -1f if (imageHeight >= 0 && imageWidth > 0) { height = (imageHeight / imageWidth) * width } } if (bounds == null && width >= 0 && height >= 0 && location != null) { val latitudeSpan = Math.toDegrees(height.toDouble() / EARTH_RADIUS) val longitudeSpan = min(Math.toDegrees(width.toDouble() / (cos(Math.toRadians(location!!.latitude)) * EARTH_RADIUS)), 359.999999) val north = location!!.latitude + (latitudeSpan * anchorV) val south = location!!.latitude - (latitudeSpan * (1.0 - anchorV)) val west = location!!.longitude - (longitudeSpan * anchorU) val east = location!!.longitude + (longitudeSpan * (1.0 - anchorU)) bounds = LatLngBounds(LatLng(south, west), LatLng(north, east)) } if (location == null && bounds != null) { val north = bounds!!.northeast.latitude val south = bounds!!.southwest.latitude var east = bounds!!.northeast.longitude val west = bounds!!.southwest.longitude while (east < west) east += 360.0 location = LatLng((1.0 - anchorV) * north + anchorV * south, (1.0 - anchorU) * west + anchorU * east) } } override fun getId(): String { return id } Loading Loading @@ -136,5 +169,6 @@ class GroundOverlayImpl(private val map: GoogleMapImpl, private val id: String, companion object { private const val TAG = "GroundOverlay" private const val EARTH_RADIUS = 6371009.0 } }
play-services-maps/src/main/java/com/google/android/gms/maps/model/GroundOverlayOptions.java +1 −1 Original line number Diff line number Diff line Loading @@ -35,7 +35,7 @@ public class GroundOverlayOptions extends AutoSafeParcelable { @Field(4) private float width; @Field(5) private float height; private float height = NO_DIMENSION; @Field(6) private LatLngBounds bounds; @Field(7) Loading