-
Notifications
You must be signed in to change notification settings - Fork 131
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix api signature for framing viewannotation
- Loading branch information
Showing
7 changed files
with
216 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
sdk/src/main/java/com/mapbox/maps/viewannotation/ViewAnnotationOptionsExt.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
@file:JvmName("ViewAnnotationOptionsExt") | ||
package com.mapbox.maps.viewannotation | ||
|
||
import android.graphics.Rect | ||
import androidx.annotation.VisibleForTesting | ||
import com.mapbox.maps.ViewAnnotationAnchor | ||
import com.mapbox.maps.ViewAnnotationOptions | ||
|
||
/** | ||
* Get [Rect] from [ViewAnnotationOptions]'s geometry, width and height. | ||
* This function takes [ViewAnnotationOptions.geometry] as the center of rectangle and | ||
* use width, height and offset values to calculate [Rect] associated. | ||
* | ||
* @return [Rect] associated with [ViewAnnotationOptions] | ||
*/ | ||
@VisibleForTesting(otherwise = VisibleForTesting.PRIVATE) | ||
internal fun ViewAnnotationOptions.frame(): Rect? { | ||
if (width != null && height != null) { | ||
val offsetWidth = (width!! * 0.5).toInt() | ||
val offsetHeight = (height!! * 0.5).toInt() | ||
// create a dummy rect with center assume at 0,0 with offsetWidth and offsetHeight. | ||
val rect = Rect( | ||
-offsetWidth, | ||
-offsetHeight, | ||
offsetWidth, | ||
offsetHeight | ||
) | ||
|
||
// offset rect with respect to anchor defined in viewannotation options. | ||
when (anchor ?: ViewAnnotationAnchor.CENTER) { | ||
ViewAnnotationAnchor.TOP -> rect.offset(0, offsetHeight) | ||
ViewAnnotationAnchor.TOP_LEFT -> rect.offset(offsetWidth, offsetHeight) | ||
ViewAnnotationAnchor.TOP_RIGHT -> rect.offset(-offsetWidth, offsetHeight) | ||
ViewAnnotationAnchor.BOTTOM -> rect.offset(0, -offsetHeight) | ||
ViewAnnotationAnchor.BOTTOM_LEFT -> rect.offset(offsetWidth, -offsetHeight) | ||
ViewAnnotationAnchor.BOTTOM_RIGHT -> rect.offset(-offsetWidth, -offsetHeight) | ||
ViewAnnotationAnchor.LEFT -> rect.offset(offsetWidth, 0) | ||
ViewAnnotationAnchor.RIGHT -> rect.offset(-offsetWidth, 0) | ||
else -> rect.offset(0, 0) | ||
} | ||
// add view annotation option's offsetX and offsetY field to offset the rect. | ||
rect.offset(offsetX ?: 0, offsetY ?: 0) | ||
return rect | ||
} | ||
return null | ||
} |
Oops, something went wrong.