地图模块适配

This commit is contained in:
jiaguofeng
2023-08-11 14:51:19 +08:00
parent 661816af8f
commit 74c0a81e68
30 changed files with 452 additions and 674 deletions

View File

@@ -1,6 +1,5 @@
package com.autonavi.nge;
import static com.amap.api.navi.AmapNaviPage.TAG;
import android.util.Log;
@@ -8,6 +7,7 @@ import com.zhidaoauto.map.sdk.inner.CompileConfig;
import com.zhidaoauto.map.sdk.inner.road.RoadResultController;
public class MapBox {
private static final String TAG = "MapBox";
static {
System.loadLibrary("map");
}

View File

@@ -1,58 +1,58 @@
package com.autonavi.nge.guidance
import android.util.Log
import android.view.View
import android.widget.ImageView
import android.widget.LinearLayout
import android.widget.TextView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.zhidaoauto.map.sdk.R
import com.zhidaoauto.map.sdk.inner.CompileConfig
import java.text.DecimalFormat
class RouteBookAdapter : BaseQuickAdapter<RouteBookItem, BaseViewHolder>(R.layout.routebook_child_item) {
private val TAG = javaClass.simpleName
override fun getDefItemCount(): Int {
return super.getDefItemCount()
}
override fun convert(helper: BaseViewHolder, item: RouteBookItem) {
if (CompileConfig.DEBUG) {
Log.i(TAG, "routebookop--helper.adapterPosition:${helper.adapterPosition}")
}
when (helper.adapterPosition) {
0 -> {
helper.getView<LinearLayout>(R.id.routebook_child_item_info_ll).visibility = View.VISIBLE
helper.getView<ImageView>(R.id.imgView).setImageResource(NaviDirRes.getResID(501))
helper.getView<TextView>(R.id.orientation).text = "${item.routeName?:"起点"}出发"
helper.getView<TextView>(R.id.length).visibility = View.GONE
}
else -> {
helper.getView<TextView>(R.id.orientation).text = item.routeName
helper.getView<ImageView>(R.id.imgView).setImageResource(NaviDirRes.getResID(item.turnID))
if (item.routeName == "目的地") {
helper.getView<TextView>(R.id.length).visibility = View.GONE
} else {
helper.getView<TextView>(R.id.length).visibility = View.VISIBLE
val i = item.routelength
if (i > 1000) {
val df = DecimalFormat("#.0")
val string = df.format(i.toDouble() / 1000)
val strs = string.split(".")
if (strs.size >= 2 && strs[1] == "0") {
helper.getView<TextView>(R.id.length).text = """继续前行${strs[0]}km${item.routeSpeech}""".trimIndent()
} else {
helper.getView<TextView>(R.id.length).text = """继续前行${string}km${item.routeSpeech}""".trimIndent()
}
} else {
helper.getView<TextView>(R.id.length).text = """继续前行${i}m${item.routeSpeech}""".trimIndent()
}
}
}
}
}
}
//package com.autonavi.nge.guidance
//
//import android.util.Log
//import android.view.View
//import android.widget.ImageView
//import android.widget.LinearLayout
//import android.widget.TextView
//import com.chad.library.adapter.base.BaseQuickAdapter
//import com.chad.library.adapter.base.viewholder.BaseViewHolder
//import com.zhidaoauto.map.sdk.R
//import com.zhidaoauto.map.sdk.inner.CompileConfig
//import java.text.DecimalFormat
//
//class RouteBookAdapter : BaseQuickAdapter<RouteBookItem, BaseViewHolder>(R.layout.routebook_child_item) {
//
// private val TAG = javaClass.simpleName
//
//
// override fun getDefItemCount(): Int {
// return super.getDefItemCount()
// }
//
// override fun convert(helper: BaseViewHolder, item: RouteBookItem) {
// if (CompileConfig.DEBUG) {
// Log.i(TAG, "routebookop--helper.adapterPosition:${helper.adapterPosition}")
// }
// when (helper.adapterPosition) {
// 0 -> {
// helper.getView<LinearLayout>(R.id.routebook_child_item_info_ll).visibility = View.VISIBLE
// helper.getView<ImageView>(R.id.imgView).setImageResource(NaviDirRes.getResID(501))
// helper.getView<TextView>(R.id.orientation).text = "从${item.routeName?:"起点"}出发"
// helper.getView<TextView>(R.id.length).visibility = View.GONE
// }
// else -> {
// helper.getView<TextView>(R.id.orientation).text = item.routeName
// helper.getView<ImageView>(R.id.imgView).setImageResource(NaviDirRes.getResID(item.turnID))
// if (item.routeName == "目的地") {
// helper.getView<TextView>(R.id.length).visibility = View.GONE
// } else {
// helper.getView<TextView>(R.id.length).visibility = View.VISIBLE
// val i = item.routelength
// if (i > 1000) {
// val df = DecimalFormat("#.0")
// val string = df.format(i.toDouble() / 1000)
// val strs = string.split(".")
// if (strs.size >= 2 && strs[1] == "0") {
// helper.getView<TextView>(R.id.length).text = """继续前行${strs[0]}km${item.routeSpeech}""".trimIndent()
// } else {
// helper.getView<TextView>(R.id.length).text = """继续前行${string}km${item.routeSpeech}""".trimIndent()
// }
// } else {
// helper.getView<TextView>(R.id.length).text = """继续前行${i}m${item.routeSpeech}""".trimIndent()
// }
// }
// }
// }
// }
//}

View File

@@ -113,8 +113,8 @@ class MapView(context: Context, private val mMapStyleParams: IMapStyleParams, pr
// 地图POI是否允许点击。
private var mPoiTouchEnable = true
private var viewWidth = 1920
private var viewHeight = 1040
private var mViewWidth = 1920
private var mViewHeight = 1040
var mLonLat: LonLat? = null
private val ZOOM_CHANGE = 0x7F
private val FOCUS_CHANGE = 0x9F
@@ -123,6 +123,7 @@ class MapView(context: Context, private val mMapStyleParams: IMapStyleParams, pr
private val RENDER_COMPLETE = 0x15F
private val LOAD_COMPLETE = 0x17F
private val RENDER_CHANGE = 0x19F
private val INIT_COMPLETE = 0x21F
private val LISTENER_TYPE_SCREEN = 0x5F
private val DELAY_TIME: Long = 500
private val VELOCITY_MEASURE: Float = 3000f
@@ -183,6 +184,13 @@ class MapView(context: Context, private val mMapStyleParams: IMapStyleParams, pr
// CommonController.instance.naviAutoView?.mNaviViewListener?.onNaviViewLoaded()
}
INIT_COMPLETE -> {
if (DEBUG) {
Log.i(TAG, "mapop--init complete-start")
}
mEventController?.dispatchMapLoadedInitListener()
}
else -> {
}
}
@@ -628,7 +636,7 @@ class MapView(context: Context, private val mMapStyleParams: IMapStyleParams, pr
if(mMapStyleParams.getStyleMode() == MapAutoApi.MAP_STYLE_NIGHT_VR || mMapStyleParams.getStyleMode() == MapAutoApi.MAP_STYLE_DAY_VR) {
mMapController?.setMapViewVisualAngle(mMapStyleParams.getDefaultPerspective())
}
mEventController?.dispatchMapLoadedInitListener()
mHandler.sendEmptyMessage(INIT_COMPLETE)
if(DEBUG){
Log.i(TAG, "mapop-surfaceop--onDrawFramethreadop:${Thread.currentThread().id}")
}
@@ -658,14 +666,14 @@ class MapView(context: Context, private val mMapStyleParams: IMapStyleParams, pr
if (DEBUG) {
Log.i(TAG, "mapop--surfaceop--resize:${width},${height}")
}
if (width == 0 || height == 0 || (viewWidth == width && viewHeight == height)) {
if (width == 0 || height == 0 || (mViewWidth == width && mViewHeight == height)) {
return
}
// gl.glViewport(0, 0, width, height)
viewWidth = width
viewHeight = height
MapTools.viewHeight = viewWidth
MapTools.viewWidth = viewHeight
mViewWidth = width
mViewHeight = height
MapTools.viewHeight = mViewWidth
MapTools.viewWidth = mViewHeight
if (DEBUG) {
Log.i(TAG, "mapop--surfaceop--resize:${width},${height}")
}
@@ -1129,6 +1137,14 @@ class MapView(context: Context, private val mMapStyleParams: IMapStyleParams, pr
return isTouchingFlag
}
override fun getViewWidth(): Int{
return mViewWidth
}
override fun getViewHeight(): Int{
return mViewHeight
}
override fun isCanZoom(): Boolean {
return isCanZoom
}
@@ -1232,10 +1248,6 @@ class MapView(context: Context, private val mMapStyleParams: IMapStyleParams, pr
mStylePath = path
}
override fun resizeP(w: Int, h: Int) {
mMapEngine.resize(w, h)
}
override fun renderP() {
mMapEngine.render()
}
@@ -1324,7 +1336,6 @@ class MapView(context: Context, private val mMapStyleParams: IMapStyleParams, pr
init {
System.loadLibrary("map")
System.loadLibrary("common")
}
init {

View File

@@ -18,8 +18,8 @@ interface IMapView {
fun isSurfaceCreated(): Boolean
fun isLoaded(): Boolean
fun isTouching(): Boolean
fun getWidth(): Int
fun getHeight(): Int
fun getViewWidth(): Int
fun getViewHeight(): Int
fun getTilt(): Float
@@ -27,8 +27,6 @@ interface IMapView {
fun unloadP()
fun resizeP(w: Int, h: Int)
fun renderP()
// fun renderLocationP(lon: Float, lat: Float, providerType: Int): Int

View File

@@ -29,7 +29,7 @@ class MarkerNativeInterface(private val mMapController: IMapController): IMarker
private val infoWindowClickListenerMap: MutableMap<String, OnInfoWindowClickListener> = HashMap<String, OnInfoWindowClickListener>()
private val animationListenerMap: MutableMap<String, OnAnimationListener> = HashMap<String, OnAnimationListener>()
private val markDragListenerMap: MutableMap<String, OnMarkerDragListener> = HashMap()
private val markerIconCacheMap = HashMap<Int,String>()
private val markerIconCacheMap = ConcurrentHashMap<Int,String>()
private val markerInfoCacheMap = ConcurrentHashMap<String,String>()
//点击infoview区域
@@ -329,12 +329,20 @@ class MarkerNativeInterface(private val mMapController: IMapController): IMarker
fun getRoateAngle(id: String?): Float {
val rotateAngle = getMarkerProperty(id!!, "rotateAngle")
return java.lang.Float.valueOf(rotateAngle)
return if (TextUtils.isEmpty(rotateAngle)) {
0f
} else {
rotateAngle.toFloat()
}
}
fun getDraggable(id: String?): Boolean {
val draggable = getMarkerProperty(id!!, "draggable")
return draggable!!.toBoolean()
return if (TextUtils.isEmpty(draggable)) {
false
} else {
draggable.toBoolean()
}
}
fun setPeriod(id: String?, period: Int) {
@@ -343,7 +351,11 @@ class MarkerNativeInterface(private val mMapController: IMapController): IMarker
fun getPeriod(id: String?): Int {
val period = getMarkerProperty(id!!, "period")
return period!!.toInt()
return if (TextUtils.isEmpty(period)) {
0
} else {
period.toInt()
}
}
fun showInfoWindow(id: String?) {

View File

@@ -26,7 +26,7 @@ class MapDataProvider : ContentProvider() {
if (CompileConfig.DEBUG) {
Log.i(TAG, "queryop MapDataProvider onCreate")
}
mMatcher.addURI(context.packageName+ConstantExt.AUTHORITY, ConstantExt.STR_QUERY, ConstantExt.CODE_QUERY)
mMatcher.addURI(context?.packageName+ConstantExt.AUTHORITY, ConstantExt.STR_QUERY, ConstantExt.CODE_QUERY)
return true
}

View File

@@ -25,7 +25,6 @@ import android.widget.TextView
import android.widget.Toast
import androidx.recyclerview.widget.RecyclerView
import com.autonavi.nge.guidance.RouteBook
import com.autonavi.nge.guidance.RouteBookAdapter
import com.autonavi.nge.obj.SubCategory
import com.autonavi.nge.routing.RoutingProvider
import com.zhidaoauto.map.sdk.R
@@ -288,7 +287,7 @@ object Constant {
Environment.MEDIA_MOUNTED
) {
mbExternalStorage = true
res = context.externalCacheDir.absolutePath +"/map/"
res = context.externalCacheDir?.absolutePath +"/map/"
// res = (Environment.getExternalStorageDirectory().absolutePath
// + "/Android/data/" + context.packageName+"/map/")
} else {
@@ -415,54 +414,6 @@ object Constant {
return viewDialog
}
@JvmStatic
fun getRouteBookDialog(act: Activity): Dialog {
val dialog = Dialog(act, R.style.Dialog_Fullscreen)
var routebook: RouteBook? = null
try {
// routebook = CommonController.instance.iNavigationCore?.Guidance_RouteBook(0, 0, 4)
} catch (e: RemoteException) {
e.printStackTrace()
}
val adapter = RouteBookAdapter()
val view = RecyclerView(act)
view.adapter = adapter
adapter.setDiffNewData(routebook?.bookdata)
// 线性布局
val layout = LinearLayout(act)
// 设置布局垂直方向
layout.orientation = LinearLayout.VERTICAL
val m_TextView = TextView(act)
m_TextView.layoutParams = LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.WRAP_CONTENT
)
m_TextView.setBackgroundColor(Color.BLACK)
m_TextView.textSize = 18f
m_TextView.setTextColor(Color.WHITE)
m_TextView.text = "距离:" + getDisString(routebook?.totalLength ?: 0) + " 时间:" + getTimeString(routebook?.totalTime ?: 0)
m_TextView.gravity = Gravity.CENTER_HORIZONTAL
m_TextView.setPadding(0, 10, 0, 20)
layout.addView(
m_TextView,
LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.WRAP_CONTENT
)
)
layout.addView(
view,
LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.MATCH_PARENT
)
)
dialog.setContentView(layout)
dialog.setOnCancelListener { dialog.dismiss() }
dialog.setOnKeyListener { paramDialogInterface, paramInt, paramKeyEvent -> false }
return dialog
}
fun getNaviDialog(act: Activity): Dialog {
val items =
arrayOf<CharSequence>("开始导航", "模拟导航", "路线详情", "导航设置", "语音设置")

View File

@@ -30,7 +30,7 @@ object FileUtils {
if (!mWorkingPath.exists()) {
mWorkingPath.mkdirs()
}
var files: Array<String>
var files: Array<String>?
try {
// 获得Assets文件夹下指定文件夹一共有多少文件
files = assetManager.list(assetDir);
@@ -225,7 +225,7 @@ object FileUtils {
val file = File(path)
for (dirFile in subDirFile) {
val secondList = assetManager.list("${assetDir}/${file.name}")
if (secondList.isNotEmpty() && dirFile.isDirectory && file.name.equals(dirFile.name)) {
if (secondList != null && secondList.isNotEmpty() && dirFile.isDirectory && file.name.equals(dirFile.name)) {
if (isSame(assetManager, "${assetDir}/${file.name}", dirFile.path)) {
count++
subDirFile.remove(dirFile)

View File

@@ -189,7 +189,7 @@ object Recorder {
} else {
val context:Context? = MapDataApi.getContext()
if(context != null){
context.externalCacheDir.absolutePath +"/map/$name"
context.externalCacheDir?.absolutePath +"/map/$name"
}else{
Environment.getExternalStorageDirectory().absolutePath + "/Android/data/map/$name"

View File

@@ -1,9 +1,6 @@
package com.zhidaoauto.map.sdk.inner.utils
import android.content.Context
import com.amap.api.location.CoordinateConverter
import com.amap.api.location.CoordinateConverter.CoordType
import com.amap.api.location.DPoint
import com.zhidaoauto.map.sdk.inner.abs.IMapController
import java.math.BigDecimal
@@ -201,41 +198,10 @@ object TransformUtils {
}
fun tempTrans(param:DoubleArray,context: Context?){
var doubleArrayParam = param
// System.out.println("origin:${doubleArrayParam.joinToString() }");
transform(doubleArrayParam,context)
// System.out.println("middle:${index},${if(index%2==0){"GPS:"}else{"GCJ:"}}--${doubleArrayParam.joinToString()}")
// System.out.println("result:${doubleArrayParam.joinToString()}")
}
fun transform(doubleArray: DoubleArray,context: Context?){
System.out.println("origin:${doubleArray.joinToString()}")
val point = gd_Transform(context, DPoint(doubleArray[1],doubleArray[0]))
val gdarray = doubleArrayOf(point.longitude,point.latitude)
System.out.println("gaode:${gdarray.joinToString()}")
val mogo = transformWgs84ToGcj02(doubleArray[1], doubleArray[0])
System.out.println("mogo:${mogo.joinToString()}")
val gaodetoOrigin = transformGcj02toWgs84(gdarray[1], gdarray[0])
System.out.println("gaode-to-origin:${gaodetoOrigin.joinToString()}")
val mogotoOrigin = transformGcj02toWgs84(mogo[1], mogo[0])
System.out.println("mogo-to-origin:${mogotoOrigin.joinToString()}")
}
fun gd_Transform(context: Context?,sourceLatLng:DPoint):DPoint{
val converter = CoordinateConverter(context)
// CoordType.GPS 待转换坐标类型
converter.from(CoordType.GPS)
// sourceLatLng待转换坐标点 LatLng类型
converter.coord(sourceLatLng)
// 执行转换操作
return converter.convert()
}
fun outOfScreen(context: Context, lon: Double, lat: Double,mapController: IMapController?): Boolean{
val displayMetrics = context.resources.getDisplayMetrics()

View File

@@ -113,32 +113,28 @@ object MapAutoApi {
CommonController.instance.init(context)
Recorder.i("common","$mapParams")
val customPath = context.filesDir.absolutePath
if (com.zhidaoauto.map.sdk.BuildConfig.ONLINE) {
if (TextUtils.isEmpty(mapParams.getStyleDir())) {
val stylePath = "${customPath}/shmdata/mogo_style"
mapParams.setStyleDir(stylePath)
MapStyleHelper.copyAssetsToSdcard(context, "style", stylePath)
}else{
MapStyleHelper.loadStyleOver.set(true)
}
if (!TextUtils.isEmpty(mapParams.getCachePath())) {
MapDataHelper.updateData(context, mapParams.getCachePath()!!)
}else{
MapDataHelper.updateData(context, CommonUtils.getCachePath(context))
}
if (TextUtils.isEmpty(mapParams.getStyleDir())) {
val stylePath = "${customPath}/shmdata/mogo_style"
mapParams.setStyleDir(stylePath)
MapStyleHelper.copyAssetsToSdcard(context, "style", stylePath)
}else{
MapStyleHelper.loadStyleOver.set(true)
}
if (!TextUtils.isEmpty(mapParams.getCachePath())) {
MapDataHelper.updateData(context, mapParams.getCachePath()!!)
}else{
MapDataHelper.updateData(context, CommonUtils.getCachePath(context))
}
if (com.zhidaoauto.map.sdk.BuildConfig.MODE == 3) {
// VR
if(mapParams.getDataFileSource() == 0){
MapHdDataHelper.initDataMgr(context)
}else if (TextUtils.isEmpty(mapParams.getHdmapPath())) {
mapParams.setHdmapPath("${customPath}/shmdata")
MapHdDataHelper.copyAssetsToSdcard(context, "hdmapData", "${customPath}/shmdata/hdmapData")
}else{
MapHdDataHelper.loadDataOver.set(true)
}
// VR
if(mapParams.getDataFileSource() == 0){
MapHdDataHelper.initDataMgr(context)
}else if (TextUtils.isEmpty(mapParams.getHdmapPath())) {
mapParams.setHdmapPath("${customPath}/shmdata")
MapHdDataHelper.copyAssetsToSdcard(context, "hdmapData", "${customPath}/shmdata/hdmapData")
}else{
MapHdDataHelper.loadDataOver.set(true)
}
MapHelper.init(mapParams)
}

View File

@@ -34,7 +34,7 @@ object MapDataApi {
return mContext
}
fun startZeus(context: Context) {
fun startZeus(context: Context?) {
if (CompileConfig.DEBUG) {
Log.i(TAG, "mapop-start")
}

View File

@@ -4,6 +4,7 @@ import android.Manifest
import android.content.Context
import android.content.pm.PackageManager
import android.location.Criteria
import android.location.Location
import android.location.LocationManager
import android.os.Bundle
import android.text.TextUtils
@@ -243,7 +244,7 @@ class LocationClient : android.location.LocationListener {
}
//使用外部数据 coor是坐标系
fun setExtraGPSData(coor: Int, location: android.location.Location) {
fun setExtraGPSData(coor: Int, location: Location) {
if (!mIsUseExtraGPSData.get()) {
return
}
@@ -253,13 +254,13 @@ class LocationClient : android.location.LocationListener {
var localLocation = MogoLocation()
localLocation.lon = lon
localLocation.lat = lat
localLocation.provider = location.provider
localLocation.provider = location.provider?:"gps"
localLocation.speed = location.speed
localLocation.altitude = location.altitude
// mContext?.let {
// SharedPrefsMgr.getInstance(it).putString(ConstantExt.SHARED_KEY_LOCATION, JSON.toJSONString(location))
// }
optimizeLocation(localLocation, TextUtils.equals(location.provider, Constant.GPS_RTK),location.provider.contains("RTK"))
optimizeLocation(localLocation, TextUtils.equals(location.provider, Constant.GPS_RTK),location.provider?.contains("RTK")?:false)
}
//使用外部数据 coor是坐标系
@@ -273,7 +274,7 @@ class LocationClient : android.location.LocationListener {
optimizeLocation(location, TextUtils.equals(location.provider, Constant.GPS_RTK),location.provider.contains("RTK"))
}
override fun onLocationChanged(alocation: android.location.Location?) {
override fun onLocationChanged(alocation: Location) {
if (mIsUseExtraGPSData.get()) {
return;
}
@@ -304,10 +305,10 @@ class LocationClient : android.location.LocationListener {
override fun onStatusChanged(provider: String?, status: Int, extras: Bundle?) {
}
override fun onProviderEnabled(provider: String?) {
override fun onProviderEnabled(provider: String) {
}
override fun onProviderDisabled(provider: String?) {
override fun onProviderDisabled(provider: String) {
}

View File

@@ -12,9 +12,11 @@ import com.zhidaoauto.map.sdk.inner.abs.IMapController
import com.zhidaoauto.map.sdk.inner.abs.IMarkerController
import com.zhidaoauto.map.sdk.inner.utils.BitmapUtils
import com.zhidaoauto.map.sdk.inner.utils.Constants
import com.zhidaoauto.map.sdk.inner.utils.TransformUtils
import com.zhidaoauto.map.sdk.open.marker.Marker
import com.zhidaoauto.map.sdk.open.marker.MarkerOptions
import com.zhidaoauto.map.sdk.open.query.LonLatPoint
import java.util.concurrent.atomic.AtomicBoolean
class MyLocationStyle(private var mContext:Context?,private var mMarkerController: IMarkerController?,private var mMapController: IMapController?) {
val TAG = javaClass.simpleName
@@ -57,12 +59,12 @@ class MyLocationStyle(private var mContext:Context?,private var mMarkerControlle
// 3D夜间资源
var car3DResId: Int = R.raw.car
//执行标记
private var executeFlag:AtomicBoolean = AtomicBoolean()
var guangquanResId: Int = R.raw.guangquan
var locationPath: String? = null
//执行标记
private var executeFlag: AtomicBoolean = AtomicBoolean(false)
private var animWaitFrame = ANIM_WAIT_FRAME_NIGHT
private var animPeriod = ANIM_PERIOD_NIGHT
@@ -212,6 +214,9 @@ class MyLocationStyle(private var mContext:Context?,private var mMarkerControlle
fun setLonLat(lonLat: LonLat, angle: Double) {
mMapController?.getClerk()?.add("${lonLat.lon},${lonLat.lat},${angle}")
if(TransformUtils.outOfChina(lonLat.lat, lonLat.lon)){
return
}
if (CompileConfig.DEBUG) {
Log.i(TAG, "autoop--markerop---selfop-setLonLat-${lonLat},mMarker:${mMarker?.getId()}")
}
@@ -394,6 +399,7 @@ class MyLocationStyle(private var mContext:Context?,private var mMarkerControlle
}
fun exit() {
mMapController?.getClerk()?.add()
executeFlag.set(false)
mMarker?.remove()
mMarker?.destroy()
@@ -406,10 +412,11 @@ class MyLocationStyle(private var mContext:Context?,private var mMarkerControlle
}
if(mMarker == null){
executeFlag.set(true)
mMarker = MarkerHelper.addSelfCar(markerOptions)
mMarker = mMarkerController?.addSelfCar(markerOptions)
executeFlag.set(false)
}
}
}

View File

@@ -1,314 +0,0 @@
package com.zhidaoauto.map.sdk.open.location.sys
import android.Manifest
import android.annotation.SuppressLint
import android.app.Service
import android.content.Context
import android.content.Intent
import android.content.pm.PackageManager
import android.location.*
import android.os.Bundle
import android.provider.Settings
import android.util.Log
import android.widget.Toast
import androidx.core.app.ActivityCompat
import com.zhidaoauto.map.sdk.inner.CompileConfig
import java.io.IOException
import java.util.*
object LocationApi {
val TAG = javaClass.simpleName
var mLocationManager: LocationManager? = null
var mListener: OnLocationChangeListener? = null
var myLocationListener: LocationListener? = null
fun init(context: Context) {
var locationManager = context.getSystemService(Service.LOCATION_SERVICE) as LocationManager
val providerEnabled: Boolean = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)
if (providerEnabled) {
if (ActivityCompat.checkSelfPermission(context, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED
&& ActivityCompat.checkSelfPermission(context, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
return
}
locationManager.requestLocationUpdates(
LocationManager.GPS_PROVIDER,
0,
0.0f,
object : LocationListener {
override fun onLocationChanged(location: Location?) {
if (CompileConfig.DEBUG) {
Log.i(TAG, "locationop-onLocationChanged-${location}")
}
}
override fun onStatusChanged(provider: String?, status: Int, extras: Bundle?) {
if (CompileConfig.DEBUG) {
Log.i(
TAG,
"locationop-onStatusChanged-provider:${provider},status:${status}"
)
}
}
override fun onProviderEnabled(provider: String?) {
if (CompileConfig.DEBUG) {
Log.i(TAG, "locationop-onProviderEnabled-${provider}")
}
}
override fun onProviderDisabled(provider: String?) {
if (CompileConfig.DEBUG) {
Log.i(TAG, "locationop-onProviderDisabled-${provider}")
}
}
})
}
}
/**
* 判断Gps是否可用
*
* @return {@code true}: 是<br>{@code false}: 否
*/
fun isGpsEnabled(context: Context): Boolean {
var lm = context.getSystemService(Context.LOCATION_SERVICE) as LocationManager
return lm.isProviderEnabled(LocationManager.GPS_PROVIDER);
}
/**
* 判断定位是否可用
*
* @return {@code true}: 是<br>{@code false}: 否
*/
fun isLocationEnabled(context: Context): Boolean {
var lm = context.getSystemService(Context.LOCATION_SERVICE) as LocationManager
return lm.isProviderEnabled(LocationManager.NETWORK_PROVIDER) || lm.isProviderEnabled(
LocationManager.GPS_PROVIDER
)
}
/**
* 打开Gps设置界面
*/
fun openGpsSettings(context: Context) {
var intent = Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS)
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
context.startActivity(intent)
}
/**
* 注册
* <p>使用完记得调用{@link #unregister()}</p>
* <p>需添加权限 {@code <uses-permission android:name="android.permission.INTERNET"/>}</p>
* <p>需添加权限 {@code <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>}</p>
* <p>需添加权限 {@code <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>}</p>
* <p>如果{@code minDistance}为0则通过{@code minTime}来定时更新;</p>
* <p>{@code minDistance}不为0则以{@code minDistance}为准;</p>
* <p>两者都为0则随时刷新。</p>
*
* @param minTime 位置信息更新周期(单位:毫秒)
* @param minDistance 位置变化最小距离:当位置距离变化超过此值时,将更新位置信息(单位:米)
* @param listener 位置刷新的回调接口
* @return {@code true}: 初始化成功<br>{@code false}: 初始化失败
*/
@SuppressLint("MissingPermission") fun register(
context: Context,
minTime: Long,
minDistance: Float,
listener: OnLocationChangeListener?
): Boolean {
if (CompileConfig.DEBUG) {
Log.e(TAG, "locationop-register")
}
if (listener == null)
return false
mLocationManager = context.getSystemService(Context.LOCATION_SERVICE) as LocationManager
mListener = listener
if (!isLocationEnabled(context)) {
Toast.makeText(context, "无法定位,请打开定位服务", Toast.LENGTH_SHORT).show();
return false;
}
var provider = mLocationManager?.getBestProvider(getCriteria(), true);
var location = mLocationManager?.getLastKnownLocation(provider);
if (location != null) {
Log.i(TAG,"locationop-getLastKnownLocation-${location}")
listener.getLastKnownLocation(location);
}
myLocationListener = object : LocationListener {
override fun onLocationChanged(location: Location?) {
Log.i(TAG,"locationop-onLocationChanged-${location}")
mListener?.onLocationChanged(location)
}
override fun onStatusChanged(provider: String?, status: Int, extras: Bundle?) {
mListener?.onStatusChanged(provider, status, extras)
when (status) {
LocationProvider.AVAILABLE ->
if (CompileConfig.DEBUG) {
Log.e("onStatusChanged", "locationop-当前GPS状态为可见状态")
};
LocationProvider.OUT_OF_SERVICE ->
if (CompileConfig.DEBUG) {
Log.e("onStatusChanged", "locationop-当前GPS状态为服务区外状态")
}
LocationProvider.TEMPORARILY_UNAVAILABLE ->
if (CompileConfig.DEBUG) {
Log.e("onStatusChanged", "locationop-当前GPS状态为暂停服务状态")
};
}
}
override fun onProviderEnabled(provider: String?) {
}
override fun onProviderDisabled(provider: String?) {
}
}
mLocationManager?.requestLocationUpdates(
provider,
minTime,
minDistance,
myLocationListener
);
return true;
}
/**
* 注销
*/
fun unregister() {
if (mLocationManager != null) {
if (myLocationListener != null) {
mLocationManager?.removeUpdates(myLocationListener);
myLocationListener = null;
}
mLocationManager = null;
}
}
/**
* 设置定位参数
*
* @return {@link Criteria}
*/
fun getCriteria(): Criteria {
var criteria = Criteria()
//设置定位精确度 Criteria.ACCURACY_COARSE比较粗略Criteria.ACCURACY_FINE则比较精细
criteria.setAccuracy(Criteria.ACCURACY_FINE);
//设置是否要求速度
criteria.setSpeedRequired(true);
// 设置是否允许运营商收费
criteria.setCostAllowed(true);
//设置是否需要方位信息
criteria.setBearingRequired(true);
//设置是否需要海拔信息
criteria.setAltitudeRequired(true);
// 设置对电源的需求
criteria.setPowerRequirement(Criteria.POWER_HIGH);
return criteria;
}
/**
* 根据经纬度获取地理位置
*
* @param context 上下文
* @param latitude 纬度
* @param longitude 经度
* @return {@link Address}
*/
fun getAddress(context: Context, latitude: Double, longitude: Double): Address? {
var geocoder = Geocoder(context, Locale.getDefault());
try {
var addresses = geocoder.getFromLocation(latitude, longitude, 1)
if (addresses.size > 0)
return addresses.get(0);
} catch (e: IOException) {
e.printStackTrace();
}
return null
}
/**
* 根据经纬度获取所在国家
*
* @param context 上下文
* @param latitude 纬度
* @param longitude 经度
* @return 所在国家
*/
fun getCountryName(context: Context, latitude: Double, longitude: Double): String {
var address = getAddress(context, latitude, longitude);
address?.let {
return it.getCountryName()
}
return "unknown"
}
/**
* 根据经纬度获取所在地
*
* @param context 上下文
* @param latitude 纬度
* @param longitude 经度
* @return 所在地
*/
fun getLocality(context: Context, latitude: Double, longitude: Double): String {
var address = getAddress(context, latitude, longitude)
address?.let {
return it.getLocality()
}
return "unknown"
}
/**
* 根据经纬度获取所在街道
*
* @param context 上下文
* @param latitude 纬度
* @param longitude 经度
* @return 所在街道
*/
fun getStreet(context: Context, latitude: Double, longitude: Double): String {
var address = getAddress(context, latitude, longitude)
address?.let {
return it.getAddressLine(0)
}
return "unknown"
}
interface OnLocationChangeListener {
/**
* 获取最后一次保留的坐标
*
* @param location 坐标
*/
fun getLastKnownLocation(location: Location)
/**
* 当坐标改变时触发此函数如果Provider传进相同的坐标它就不会被触发
*
* @param location 坐标
*/
fun onLocationChanged(location: Location?)
/**
* provider的在可用、暂时不可用和无服务三个状态直接切换时触发此函数
*
* @param provider 提供者
* @param status 状态
* @param extras provider可选包
*/
fun onStatusChanged(provider: String?, status: Int, extras: Bundle?);//位置状态发生改变
}
}

View File

@@ -34,19 +34,22 @@ public class BitmapDescriptor : Parcelable, Cloneable {
}
public override fun clone(): BitmapDescriptor {
return try {
BitmapDescriptor(
Bitmap.createBitmap(bitmap),
width,
height
)
} catch (var3: Throwable) {
return BitmapDescriptor(
Bitmap.createBitmap(bitmap),
width,
height
)
bitmap?.let {
return try {
BitmapDescriptor(
Bitmap.createBitmap(it),
width,
height
)
} catch (var3: Throwable) {
return BitmapDescriptor(
Bitmap.createBitmap(it),
width,
height
)
}
}
return BitmapDescriptor(bitmap)
}
/**

View File

@@ -57,7 +57,7 @@ public class Marker(private var markerOptions: MarkerOptions,private var mMapCon
private var historyLocationList: ArrayList<LonLatPoint>? = null
private var mHandler: Handler = object : Handler(Looper.getMainLooper()) {
override fun handleMessage(msg: Message?) {
override fun handleMessage(msg: Message) {
super.handleMessage(msg)
var type = msg?.arg1
var animation: Animation? = markerAnimationMap.get(type)

View File

@@ -12,6 +12,7 @@ import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import java.util.concurrent.ConcurrentHashMap
import java.util.concurrent.CopyOnWriteArrayList
import java.util.concurrent.atomic.AtomicBoolean
class MarkerCacheController(private val mapAutoView: MapAutoView) {
@@ -19,7 +20,8 @@ class MarkerCacheController(private val mapAutoView: MapAutoView) {
private var taskJob: Job? = null
var cacheInterval = 300
private var exit: Boolean = false
private var isExecuting: AtomicBoolean = AtomicBoolean()
//设置是否开启更新锚点策略,默认关闭
var delayStrategy: Boolean = false
@@ -53,7 +55,7 @@ class MarkerCacheController(private val mapAutoView: MapAutoView) {
init {
lastPreTime = 0L
exit = false
isExecuting.set(false)
lastPreTime = 0L
}
@@ -119,7 +121,9 @@ class MarkerCacheController(private val mapAutoView: MapAutoView) {
fun addCache(dataSet: MarkerDataSet?) {
if(taskJob == null){
execute()
if(!isExecuting.get()){
execute()
}
}
if (dataSet == null) {
return
@@ -155,7 +159,9 @@ class MarkerCacheController(private val mapAutoView: MapAutoView) {
@Synchronized
fun addCache(originBatchData: MarkerBatchData?) {
if(taskJob == null){
execute()
if(!isExecuting.get()){
execute()
}
}
if (CompileConfig.DEBUG) {
Log.i(TAG, "addCache:life-start")
@@ -420,8 +426,8 @@ class MarkerCacheController(private val mapAutoView: MapAutoView) {
}
fun destory() {
exit = true
taskJob?.cancel()
isExecuting.set(false)
taskJob = null
timeList.clear()
cacheMap.clear()
@@ -433,9 +439,10 @@ class MarkerCacheController(private val mapAutoView: MapAutoView) {
@Synchronized
private fun execute() {
isExecuting.set(true)
taskJob?.cancel()
taskJob = mapAutoView.getMapController()?.getDemaningScope()?.launch(Dispatchers.IO) {
while (!exit) {
while (isExecuting.get()) {
if (dataStrategy) {
if (!timeList.isEmpty() && !cacheMap.isEmpty()) {

View File

@@ -122,17 +122,23 @@ class TmcBarView : View {
////计算tmcBar在绘制过程中每一小段的长度
val itemHeight = Math.round(trafficStatus.getLength() * rateDistanceToViewHeight * 100.0f) * 0.01f
realDistanceSum += itemHeight
canvas.drawRect(0.0f, realDistanceSum - itemHeight, width.toFloat(), realDistanceSum, getPaintInColor(getColor(trafficStatus.getStatus())))
getPaintInColor(getColor(trafficStatus.getStatus()))?.let {
canvas.drawRect(0.0f, realDistanceSum - itemHeight, width.toFloat(), realDistanceSum, it)
}
--tmcBarLength
}
tmcBarLength = height + (mCarHeight shr 1)
//补全光柱图,使用颜色==第一段的颜色
if (realDistanceSum < tmcBarLength.toFloat()) {
canvas.drawRect(0.0f, realDistanceSum, width.toFloat(), tmcBarLength.toFloat(), getPaintInColor(getColor((mTmcBarItems!![0]).getStatus())))
getPaintInColor(getColor((mTmcBarItems!![0]).getStatus()))?.let {
canvas.drawRect(0.0f, realDistanceSum, width.toFloat(), tmcBarLength.toFloat(), it)
}
}
//补全光柱图,使用颜色==第一段的颜色
if (this.height.toFloat() > mCursorPos) {
canvas.drawRect(0.0f, mCursorPos + (mCarHeight shr 1).toFloat(), width.toFloat(), this.height.toFloat(), getPaintInColor(getColor(-1)))
getPaintInColor(getColor(-1))?.let {
canvas.drawRect(0.0f, mCursorPos + (mCarHeight shr 1).toFloat(), width.toFloat(), this.height.toFloat(), it)
}
}
if (mTmcBarListener != null) {
mTmcBarListener!!.dismissBottomTag()

View File

@@ -12,13 +12,13 @@ import kotlinx.android.synthetic.main.view_trafficbar.view.tmcBarTxt
import kotlinx.android.synthetic.main.view_trafficbar.view.tmcBarView
class TrafficProgressBar : FrameLayout {
constructor(context: Context?, attrs: AttributeSet?, defStyle: Int) : super(context, attrs, defStyle) {
constructor(context: Context, attrs: AttributeSet?, defStyle: Int) : super(context, attrs, defStyle) {
init()
}
constructor(context: Context?) : super(context) {
constructor(context: Context) : super(context) {
init()
}
constructor(context: Context?, attrs: AttributeSet?) : super(context, attrs) {
constructor(context: Context, attrs: AttributeSet?) : super(context, attrs) {
init()
}

View File

@@ -2,13 +2,16 @@ package com.zhidaoauto.map.sdk.open.tools
import android.content.Context
import android.util.Log
import android.widget.FrameLayout
import com.zhidaoauto.map.sdk.inner.CompileConfig
import com.zhidaoauto.map.sdk.open.view.MapAutoView
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import java.io.IOException
import kotlin.random.Random
class MonitorPressApi {
@@ -94,7 +97,7 @@ class MonitorPressApi {
TaskManager.instance.resetTask()
val rv = (Math.random() * 16).toInt()
val rv = (Math.random() * 17).toInt()
var trackIndex = (Math.random() * (mFiles!!.size - 1)).toInt()
if(CompileConfig.DEBUG){
Log.i(TAG, "onClick--randomop: rv:${rv},trackIndex:${trackIndex}")
@@ -152,6 +155,20 @@ class MonitorPressApi {
// TaskManager.instance.monitorMarkerAdd(trackIndex,mapAutoView)
TaskManager.instance.monitorCancleCacheHdData()
}
16 -> {
withContext(Dispatchers.Main){
val per = Random.nextDouble()
val layoutParams = mapAutoView.layoutParams as FrameLayout.LayoutParams
layoutParams.width = (2560 * per).toInt()
layoutParams.height = (1400 * per).toInt()
mapAutoView.layoutParams = layoutParams
if(CompileConfig.DEBUG){
Log.i(TAG, "resizeop:${layoutParams.width},${layoutParams.height}--${layoutParams}")
}
mapAutoView.postInvalidate()
}
}
else -> {
TaskManager.instance.monitor2DMarkerAdd(trackIndex,mapAutoView)

View File

@@ -230,7 +230,7 @@ open class MapAutoView : FrameLayout, LonLatPointListener, ITraffic,ILockLocatio
*/
private fun handlerInitMapView() {
//BuildConfig.MODE: 1.offline 2.online 3.VR
if (MapStyleHelper.loadStyleOver.get() && ((MapHdDataHelper.loadDataOver.get() && BuildConfig.MODE >= 3) || BuildConfig.MODE < 3)) {
if (MapStyleHelper.loadStyleOver.get() && MapHdDataHelper.loadDataOver.get()) {
initMapView()
} else {
mHandler.removeCallbacksAndMessages(MSG_MAP_INIT)
@@ -293,7 +293,7 @@ open class MapAutoView : FrameLayout, LonLatPointListener, ITraffic,ILockLocatio
}
fun initMapView() {
private fun initMapView() {
if (CompileConfig.DEBUG) {
Log.i(TAG, "autoop-mapop-initMapView--start")
}
@@ -363,7 +363,9 @@ open class MapAutoView : FrameLayout, LonLatPointListener, ITraffic,ILockLocatio
}
}
}
if(mogoLocation.lon == 0.0 || mogoLocation.lat == 0.0){
return
}
val lonLatPoint = LonLatPoint(mogoLocation.lon, mogoLocation.lat,mogoLocation.altitude,mogoLocation.heading)
lonLatPoint.provider = mogoLocation.provider
if (CompileConfig.DEBUG) {
@@ -388,7 +390,9 @@ open class MapAutoView : FrameLayout, LonLatPointListener, ITraffic,ILockLocatio
}
}
}
if(lonLatPoint.longitude == 0.0 || lonLatPoint.latitude == 0.0){
return
}
if(CompileConfig.DEBUG) {
Log.i(TAG, "autoop-locationop-lockop-onLocationChanged-location:${lonLatPoint}")
}