diff --git a/.gitignore b/.gitignore index 39fb081..800ee20 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ *.iml +/.idea .gradle /local.properties /.idea/workspace.xml diff --git a/googlemaps/src/main/java/nz/co/trademe/mapme/googlemaps/GoogleMapMarkerAnnotation.kt b/googlemaps/src/main/java/nz/co/trademe/mapme/googlemaps/GoogleMapMarkerAnnotation.kt index 779231e..dd212e8 100644 --- a/googlemaps/src/main/java/nz/co/trademe/mapme/googlemaps/GoogleMapMarkerAnnotation.kt +++ b/googlemaps/src/main/java/nz/co/trademe/mapme/googlemaps/GoogleMapMarkerAnnotation.kt @@ -32,6 +32,10 @@ class GoogleMapMarkerAnnotation(latLng: LatLng, nativeMarker?.alpha = alpha } + override fun onUpdateAnchor(anchorUV: Pair) { + nativeMarker?.setAnchor(anchorUV.first, anchorUV.second) + } + private var nativeMarker: Marker? = null override fun annotatesObject(objec: Any): Boolean { diff --git a/mapbox/src/main/java/nz/co/trademe/mapme/mapbox/MapboxMarkerAnnotation.kt b/mapbox/src/main/java/nz/co/trademe/mapme/mapbox/MapboxMarkerAnnotation.kt index b7d59f0..912e23c 100644 --- a/mapbox/src/main/java/nz/co/trademe/mapme/mapbox/MapboxMarkerAnnotation.kt +++ b/mapbox/src/main/java/nz/co/trademe/mapme/mapbox/MapboxMarkerAnnotation.kt @@ -14,7 +14,6 @@ class MapboxMarkerAnnotation(latLng: LatLng, title: String?, icon: Bitmap? = null) : MarkerAnnotation(latLng, title, icon) { - override fun onUpdateIcon(icon: Bitmap?) { nativeMarker?.let { if (icon != null) { @@ -41,6 +40,10 @@ class MapboxMarkerAnnotation(latLng: LatLng, Log.w(MapboxMarkerAnnotation::class.simpleName, "alpha not supported on MapboxMarkerAnnotations") } + override fun onUpdateAnchor(anchorUV: Pair) { + Log.w(MapboxMarkerAnnotation::class.simpleName, "anchor not supported on MapboxMarkerAnnotations") + } + private var nativeMarker: Marker? = null override fun annotatesObject(objec: Any): Boolean { diff --git a/mapme/src/main/java/nz/co/trademe/mapme/annotations/MarkerAnnotation.kt b/mapme/src/main/java/nz/co/trademe/mapme/annotations/MarkerAnnotation.kt index 021832a..3e935c2 100644 --- a/mapme/src/main/java/nz/co/trademe/mapme/annotations/MarkerAnnotation.kt +++ b/mapme/src/main/java/nz/co/trademe/mapme/annotations/MarkerAnnotation.kt @@ -4,10 +4,11 @@ import android.graphics.Bitmap import nz.co.trademe.mapme.LatLng abstract class MarkerAnnotation(latLng: LatLng, - title: String? = null, - icon: Bitmap? = null, - zIndex: Float = 0f, - alpha: Float = 1f) : MapAnnotation() { + title: String? = null, + icon: Bitmap? = null, + zIndex: Float = 0f, + alpha: Float = 1f, + anchorUV: Pair = Pair(0.5f, 1.0f)) : MapAnnotation() { var latLng: LatLng = latLng set(value) { @@ -39,6 +40,12 @@ abstract class MarkerAnnotation(latLng: LatLng, onUpdateAlpha(value) } + var anchor: Pair = anchorUV + set(value) { + field = value + onUpdateAnchor(value) + } + /** * Called when an icon has been set on the annotation. * @@ -74,8 +81,16 @@ abstract class MarkerAnnotation(latLng: LatLng, */ abstract protected fun onUpdateAlpha(alpha: Float) + /** + * Called when an anchor has been set on the annotation. + * + * Update the native marker with the [anchor] + */ + abstract protected fun onUpdateAnchor(anchorUV: Pair) + + override fun toString(): String { - return "MarkerAnnotation(latLng=$latLng, title=$title, icon=$icon, zIndex=$zIndex, alpha=$alpha)" + return "MarkerAnnotation(latLng=$latLng, title=$title, icon=$icon, zIndex=$zIndex, alpha=$alpha, anchor(U,V)=${anchor.first},${anchor.second})" } } \ No newline at end of file diff --git a/mapme/src/test/java/nz/co/trademe/mapme/util/TestAnnotation.kt b/mapme/src/test/java/nz/co/trademe/mapme/util/TestAnnotation.kt index 4c5d2fb..eb3ef70 100644 --- a/mapme/src/test/java/nz/co/trademe/mapme/util/TestAnnotation.kt +++ b/mapme/src/test/java/nz/co/trademe/mapme/util/TestAnnotation.kt @@ -1,7 +1,6 @@ package nz.co.trademe.mapme.util -class TestAnnotation : nz.co.trademe.mapme.annotations.MarkerAnnotation(nz.co.trademe.mapme.LatLng(0.0, 0.0), "", null, 0f, 1f) { - +class TestAnnotation : nz.co.trademe.mapme.annotations.MarkerAnnotation(nz.co.trademe.mapme.LatLng(0.0, 0.0), "", null, 0f, 1f, Pair(0.5f, 1f)) { override fun annotatesObject(nativeObject: Any): Boolean { return false } @@ -27,10 +26,10 @@ class TestAnnotation : nz.co.trademe.mapme.annotations.MarkerAnnotation(nz.co.tr override fun onUpdateAlpha(alpha: Float) { } + override fun onUpdateAnchor(anchorUV: Pair) { + } + override fun toString(): String { return "TestAnnotation( position = $position)" - } - - }