[base_3.4.0-map-sdk]

This commit is contained in:
zhongchao
2023-08-18 18:42:12 +08:00
parent 10b5933c03
commit fc25630dc4
43 changed files with 644 additions and 790 deletions

View File

@@ -1,5 +1,6 @@
package com.zhidaoauto.map.sdk.open.data
import android.annotation.SuppressLint
import android.app.ActivityManager
import android.content.Context
import android.text.TextUtils
@@ -20,14 +21,13 @@ import com.zhidaoauto.map.data.road.*
import com.zhidaoauto.map.sdk.open.abs.OnHdDataDownByCityListener
import java.util.concurrent.ConcurrentHashMap
@SuppressLint("StaticFieldLeak")
object MapDataApi {
private val TAG = javaClass.simpleName
private var mContext:Context? = null
fun getContext():Context?{
return mContext
}
@@ -52,31 +52,6 @@ object MapDataApi {
mContext = null
}
/**
* 判断服务是否开启
*
* @return
*/
fun isServiceRunning(context: Context, ServiceName: String): Boolean {
if (true) {
return false
}
if (TextUtils.isEmpty(ServiceName)) {
return false
}
val myManager = context
.getSystemService(Context.ACTIVITY_SERVICE) as ActivityManager
val runningServices = myManager
.getRunningServices(50) as ArrayList<ActivityManager.RunningServiceInfo>
for (info in runningServices) {
if (info.service.className.equals(ServiceName)) {
return true
}
}
return false
}
fun getRouteInfo(
centerLon: Float,
centerLat: Float, coor: Int, type: Int

View File

@@ -4,16 +4,15 @@ import android.graphics.Point
import android.util.Log
import com.autonavi.nge.map.LonLat
import com.zhidaoauto.map.data.point.LonLatPoint
import com.zhidaoauto.map.sdk.inner.CompileConfig
import com.zhidaoauto.map.sdk.inner.CompileConfig.DEBUG
import com.zhidaoauto.map.sdk.inner.abs.IMapController
import com.zhidaoauto.map.sdk.inner.proxy.CommonProxy
import com.zhidaoauto.map.sdk.inner.utils.MathUtils
import kotlin.math.absoluteValue
import kotlin.math.*
object MapTools {
val TAG = javaClass.simpleName
val TAG: String = javaClass.simpleName
var viewHeight = 1040
var viewWidth = 1920
@@ -21,13 +20,13 @@ object MapTools {
* 屏幕坐标转经纬度
*/
fun fromScreenLocation(paramPoint: Point,mMapController: IMapController?): LonLatPoint {
if (CompileConfig.DEBUG) {
if (DEBUG) {
Log.i(TAG, "lonlatop--fromScreenLocation--${paramPoint.toString()}")
}
var lonLat = mMapController?.pixelsToLonlat(paramPoint.x.toFloat(), paramPoint.y.toFloat())
val lonLat = mMapController?.pixelsToLonlat(paramPoint.x.toFloat(), paramPoint.y.toFloat())
lonLat?.let {
val lonLatPoint = CommonProxy.getInstance().getLonLatProxy().switchLonLat(it)
if (CompileConfig.DEBUG) {
if (DEBUG) {
Log.i(
TAG,
"lonlatop-toScreenLocation-toOuter-before:${lonLat},after:${lonLatPoint}"
@@ -42,16 +41,16 @@ object MapTools {
* 经纬度转屏幕坐标
*/
fun toScreenLocation(lonLatPoint: LonLatPoint,mMapController: IMapController?): Point {
var lonLat: LonLat = CommonProxy.getInstance().getLonLatProxy().switchLonLat(lonLatPoint)
if (CompileConfig.DEBUG) {
val lonLat: LonLat = CommonProxy.getInstance().getLonLatProxy().switchLonLat(lonLatPoint)
if (DEBUG) {
Log.i(TAG, "lonlatop-toScreenLocation-toInner-before:${lonLatPoint},after:${lonLat}")
}
var point = mMapController?.lonlatToPixels(
val point = mMapController?.lonlatToPixels(
lonLat.lon,
lonLat.lat
)
point?.let {
if (CompileConfig.DEBUG) {
if (DEBUG) {
Log.i(TAG, "lonlatop-toScreenLocation-result-${point}")
}
return Point(point.x.toInt(), point.y.toInt())
@@ -79,9 +78,9 @@ object MapTools {
* 批量经纬度转屏幕坐标
*/
fun toScreenLocations(data: List<LonLatPoint>,mMapController: IMapController?): List<Point> {
var arrayList: ArrayList<Point> = ArrayList()
val arrayList: ArrayList<Point> = ArrayList()
for (pp in data) {
var point = toScreenLocation(pp,mMapController)
val point = toScreenLocation(pp,mMapController)
arrayList.add(point)
}
return arrayList
@@ -91,9 +90,9 @@ object MapTools {
* 批量屏幕坐标转经纬度
*/
fun fromScreenLocations(data: List<Point>,mMapController: IMapController?): List<LonLatPoint> {
var arrayList: ArrayList<LonLatPoint> = ArrayList()
val arrayList: ArrayList<LonLatPoint> = ArrayList()
for (pp in data) {
var lonLat = fromScreenLocation(pp,mMapController)
val lonLat = fromScreenLocation(pp,mMapController)
arrayList.add(lonLat)
}
return arrayList
@@ -131,10 +130,10 @@ object MapTools {
}
fun getLonLats(start: LonLatPoint, end: LonLatPoint): List<LonLatPoint> {
var lonLatPoints: ArrayList<LonLatPoint> = ArrayList<LonLatPoint>()
val lonLatPoints: ArrayList<LonLatPoint> = ArrayList()
val x = end.latitude - start.latitude
val y = end.longitude - start.longitude
val dis = Math.sqrt(x * x + y * y).absoluteValue
val dis = sqrt(x * x + y * y).absoluteValue
val num = (dis / 0.000001).toInt()
val numX = x / num.toDouble()
val numY = y / num.toDouble()
@@ -143,7 +142,7 @@ object MapTools {
val lat = start.latitude + numX * i
val lonlatPoint = LonLatPoint(lon, lat)
if (DEBUG) {
Log.d(TAG, "lonlatPoint: ${lonlatPoint}")
Log.d(TAG, "lonlatPoint: $lonlatPoint")
}
lonLatPoints.add(lonlatPoint)
@@ -156,7 +155,7 @@ object MapTools {
}
fun HaverSin(theta: Double): Double {
val v = Math.sin(theta / 2)
val v = sin(theta / 2)
return v * v
}
@@ -186,12 +185,12 @@ object MapTools {
lon2 = ConvertDegreesToRadians(lon2)
//差值
val vLon = Math.abs(lon1 - lon2)
val vLat = Math.abs(lat1 - lat2)
val vLon = abs(lon1 - lon2)
val vLat = abs(lat1 - lat2)
//h is the great circle distance in radians, great circle就是一个球体上的切面它的圆心即是球心的一个周长最大的圆。
val h = HaverSin(vLat) + Math.cos(lat1) * Math.cos(lat2) * HaverSin(vLon)
return 2 * EARTH_RADIUS * Math.asin(Math.sqrt(h))
val h = HaverSin(vLat) + cos(lat1) * cos(lat2) * HaverSin(vLon)
return 2 * EARTH_RADIUS * asin(sqrt(h))
}
/// <summary>
@@ -212,25 +211,25 @@ object MapTools {
val a = 6378137
fun getDestinceLonLat(lonlat: LonLat, angle: Double, dist: Float): LonLat {
var angleRadHeading = angle / 180 * Math.PI
val angleRadHeading = angle / 180 * Math.PI
var newLat = 0.0
var newLong = 0.0
val distRatio = dist / EARTH_RADIUS
val distRatioSine = Math.sin(distRatio)
val distRatioCosine = Math.cos(distRatio)
val distRatioSine = sin(distRatio)
val distRatioCosine = cos(distRatio)
val startLatRad = lonlat.lat / 180 * Math.PI
val startLonRad = lonlat.lon / 180 * Math.PI
val startLatCos = Math.cos(startLatRad)
val startLatSin = Math.sin(startLatRad)
val startLatCos = cos(startLatRad)
val startLatSin = sin(startLatRad)
val endLatRads = Math.asin(startLatSin * distRatioCosine + startLatCos * distRatioSine * Math.cos(angleRadHeading))
val endLatRads = asin(startLatSin * distRatioCosine + startLatCos * distRatioSine * cos(angleRadHeading))
val endLonRads = (startLonRad
+ Math.atan2(
Math.sin(angleRadHeading) * distRatioSine * startLatCos,
distRatioCosine - startLatSin * Math.sin(endLatRads)
+ atan2(
sin(angleRadHeading) * distRatioSine * startLatCos,
distRatioCosine - startLatSin * sin(endLatRads)
))
newLat = endLatRads / Math.PI * 180
newLong = endLonRads / Math.PI * 180
@@ -241,15 +240,15 @@ object MapTools {
fun getDistance(lastLonlat: LonLat, lonlat: LonLat): Double {
val x = lonlat.lat - lastLonlat.lat
val y = lonlat.lon - lastLonlat.lon
return Math.sqrt(x * x + y * y).absoluteValue
return sqrt(x * x + y * y).absoluteValue
}
fun getNextLonLat(lastLonlat: LonLat, lonlat: LonLat, length: Double): LonLat {
val x = lonlat.lat - lastLonlat.lat
val y = lonlat.lon - lastLonlat.lon
val distance = Math.sqrt(x * x + y * y).absoluteValue
val distance = sqrt(x * x + y * y).absoluteValue
val scale = length / distance
if(CompileConfig.DEBUG){
if(DEBUG){
Log.i(TAG,"centerop-mattop:length:${length},distance:${distance}scale:${scale}")
}
val lon = lastLonlat.lon + y * scale