@@ -16,8 +16,11 @@ import com.google.android.gms.maps.model.LatLngBounds
1616import com.google.android.gms.maps.model.internal.IGroundOverlayDelegate
1717import org.microg.gms.maps.mapbox.GoogleMapImpl
1818import org.microg.gms.utils.warnOnTransactionIssues
19+ import kotlin.math.cos
20+ import kotlin.math.min
1921
2022class GroundOverlayImpl (private val map : GoogleMapImpl , private val id : String , options : GroundOverlayOptions ) : IGroundOverlayDelegate.Stub() {
23+ private val image: BitmapDescriptorImpl ? = options.image?.remoteObject?.unwrap()
2124 private var location: LatLng ? = options.location
2225 private var width: Float = options.width
2326 private var height: Float = options.height
@@ -26,9 +29,39 @@ class GroundOverlayImpl(private val map: GoogleMapImpl, private val id: String,
2629 private var zIndex: Float = options.zIndex
2730 private var visible: Boolean = options.isVisible
2831 private var transparency: Float = options.transparency
32+ private var anchorU: Float = options.anchorU
33+ private var anchorV: Float = options.anchorV
2934 private var clickable: Boolean = options.isClickable
3035 private var tag: Any? = null
3136
37+ init {
38+ // Compute missing values
39+ if (height < 0 || height.isNaN()) {
40+ val imageHeight = image?.size?.getOrNull(0 ) ? : - 1f
41+ val imageWidth = image?.size?.getOrNull(1 ) ? : - 1f
42+ if (imageHeight >= 0 && imageWidth > 0 ) {
43+ height = (imageHeight / imageWidth) * width
44+ }
45+ }
46+ if (bounds == null && width >= 0 && height >= 0 && location != null ) {
47+ val latitudeSpan = Math .toDegrees(height.toDouble() / EARTH_RADIUS )
48+ val longitudeSpan = min(Math .toDegrees(width.toDouble() / (cos(Math .toRadians(location!! .latitude)) * EARTH_RADIUS )), 359.999999 )
49+ val north = location!! .latitude + (latitudeSpan * anchorV)
50+ val south = location!! .latitude - (latitudeSpan * (1.0 - anchorV))
51+ val west = location!! .longitude - (longitudeSpan * anchorU)
52+ val east = location!! .longitude + (longitudeSpan * (1.0 - anchorU))
53+ bounds = LatLngBounds (LatLng (south, west), LatLng (north, east))
54+ }
55+ if (location == null && bounds != null ) {
56+ val north = bounds!! .northeast.latitude
57+ val south = bounds!! .southwest.latitude
58+ var east = bounds!! .northeast.longitude
59+ val west = bounds!! .southwest.longitude
60+ while (east < west) east + = 360.0
61+ location = LatLng ((1.0 - anchorV) * north + anchorV * south, (1.0 - anchorU) * west + anchorU * east)
62+ }
63+ }
64+
3265 override fun getId (): String {
3366 return id
3467 }
@@ -136,5 +169,6 @@ class GroundOverlayImpl(private val map: GoogleMapImpl, private val id: String,
136169
137170 companion object {
138171 private const val TAG = " GroundOverlay"
172+ private const val EARTH_RADIUS = 6371009.0
139173 }
140174}
0 commit comments