AMapUtils.kt
1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package cn.qiuxiang.react.amap3d
import android.content.res.Resources
import com.amap.api.maps.model.LatLng
import com.amap.api.maps.model.LatLngBounds
import com.facebook.react.bridge.Arguments
import com.facebook.react.bridge.ReadableArray
import com.facebook.react.bridge.ReadableMap
import com.facebook.react.bridge.WritableMap
fun Float.toPx(): Int {
return (this * Resources.getSystem().displayMetrics.density).toInt()
}
fun ReadableMap.toLatLng(): LatLng {
return LatLng(this.getDouble("latitude"), this.getDouble("longitude"))
}
fun ReadableArray.toLatLngList(): ArrayList<LatLng> {
return ArrayList((0..(this.size() - 1)).map { this.getMap(it)!!.toLatLng() })
}
fun LatLng.toWritableMap(): WritableMap {
val map = Arguments.createMap()
map.putDouble("latitude", this.latitude)
map.putDouble("longitude", this.longitude)
return map
}
fun ReadableMap.toLatLngBounds(): LatLngBounds {
val latitude = this.getDouble("latitude")
val longitude = this.getDouble("longitude")
val latitudeDelta = this.getDouble("latitudeDelta")
val longitudeDelta = this.getDouble("longitudeDelta")
return LatLngBounds(
LatLng(latitude - latitudeDelta / 2, longitude - longitudeDelta / 2),
LatLng(latitude + latitudeDelta / 2, longitude + longitudeDelta / 2)
)
}