Commit 05b9a735 authored by 7c00's avatar 7c00

添加 android Marker#lockToScreen 接口

resolve #112
parent e1e9a924
package cn.qiuxiang.react.amap3d
import android.content.res.Resources
import com.amap.api.maps.AMapUtils
import com.amap.api.maps.model.LatLng
import com.facebook.react.bridge.Promise
......@@ -18,3 +19,6 @@ class AMapUtilsModule(reactContext: ReactApplicationContext) : ReactContextBaseJ
promise.resolve(AMapUtils.calculateLineDistance(LatLng(lat1, lng1), LatLng(lat2, lng2)))
}
}
val Int.toPx: Int
get() = (this * Resources.getSystem().displayMetrics.density).toInt()
......@@ -4,8 +4,10 @@ import android.content.Context
import android.graphics.Bitmap
import android.graphics.Canvas
import android.view.View
import cn.qiuxiang.react.amap3d.toPx
import com.amap.api.maps.AMap
import com.amap.api.maps.model.*
import com.facebook.react.bridge.ReadableArray
import com.facebook.react.views.view.ReactViewGroup
class AMapMarker(context: Context) : ReactViewGroup(context), AMapOverlay {
......@@ -157,4 +159,12 @@ class AMapMarker(context: Context) : ReactViewGroup(context), AMapOverlay {
anchorV = y.toFloat()
marker?.setAnchor(anchorU, anchorV)
}
fun lockToScreen(args: ReadableArray?) {
if (args != null) {
val x = args.getInt(0).toPx
val y = args.getInt(1).toPx
marker?.setPositionByPixels(x, y)
}
}
}
......@@ -39,12 +39,14 @@ internal class AMapMarkerManager : ViewGroupManager<AMapMarker>() {
companion object {
val UPDATE = 1
val ACTIVE = 2
val LOCK_TO_SCREEN = 3
}
override fun getCommandsMap(): Map<String, Int> {
return mapOf(
"update" to UPDATE,
"active" to ACTIVE
"active" to ACTIVE,
"lockToScreen" to LOCK_TO_SCREEN
)
}
......@@ -52,6 +54,7 @@ internal class AMapMarkerManager : ViewGroupManager<AMapMarker>() {
when (commandId) {
UPDATE -> marker.updateIcon()
ACTIVE -> marker.active = true
LOCK_TO_SCREEN -> marker.lockToScreen(args)
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment