修改定位,修改提前看板
This commit is contained in:
parent
3dc650a76b
commit
894732ee45
@ -79,16 +79,14 @@ class RealmOperateHelper() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
suspend fun queryLink(
|
suspend fun queryLink(linkPid: String): RenderEntity? {
|
||||||
linkPid: String,
|
|
||||||
): RenderEntity? {
|
|
||||||
var link: RenderEntity? = null
|
var link: RenderEntity? = null
|
||||||
withContext(Dispatchers.IO) {
|
withContext(Dispatchers.IO) {
|
||||||
val realm = Realm.getDefaultInstance()
|
val realm = Realm.getDefaultInstance()
|
||||||
val realmR = realm.where(RenderEntity::class.java)
|
val realmR = realm.where(RenderEntity::class.java)
|
||||||
.equalTo("table", "OMDB_RD_LINK")
|
.equalTo("table", "OMDB_RD_LINK")
|
||||||
.and()
|
.and()
|
||||||
.rawPredicate("properties['${LinkTable.linkPid}']=$linkPid")
|
.equalTo("properties['${LinkTable.linkPid}']", linkPid)
|
||||||
.findFirst()
|
.findFirst()
|
||||||
if (realmR != null) {
|
if (realmR != null) {
|
||||||
link = realm.copyFromRealm(realmR)
|
link = realm.copyFromRealm(realmR)
|
||||||
|
@ -6,6 +6,7 @@ import androidx.room.Room
|
|||||||
import com.google.gson.Gson
|
import com.google.gson.Gson
|
||||||
import com.google.gson.GsonBuilder
|
import com.google.gson.GsonBuilder
|
||||||
import com.google.gson.reflect.TypeToken
|
import com.google.gson.reflect.TypeToken
|
||||||
|
import com.navinfo.collect.library.data.dao.impl.TraceDataBase
|
||||||
import com.navinfo.omqs.Constant
|
import com.navinfo.omqs.Constant
|
||||||
import com.navinfo.omqs.OMQSApplication
|
import com.navinfo.omqs.OMQSApplication
|
||||||
import com.navinfo.omqs.db.RoomAppDatabase
|
import com.navinfo.omqs.db.RoomAppDatabase
|
||||||
@ -90,7 +91,7 @@ class GlobalModule {
|
|||||||
@Provides
|
@Provides
|
||||||
@Singleton
|
@Singleton
|
||||||
fun provideGson(): Gson = GsonBuilder()
|
fun provideGson(): Gson = GsonBuilder()
|
||||||
// 解决解析Json时将int类型自动转换为Double的问题
|
// 解决解析Json时将int类型自动转换为Double的问题
|
||||||
.registerTypeAdapter(object : TypeToken<Map<String, Any?>>() {}.getType(), IntTypeAdapter())
|
.registerTypeAdapter(object : TypeToken<Map<String, Any?>>() {}.getType(), IntTypeAdapter())
|
||||||
.registerTypeAdapter(object : TypeToken<Map<String, Any>>() {}.getType(), IntTypeAdapter())
|
.registerTypeAdapter(object : TypeToken<Map<String, Any>>() {}.getType(), IntTypeAdapter())
|
||||||
.registerTypeAdapter(object : TypeToken<Map<Any, Any>>() {}.getType(), IntTypeAdapter())
|
.registerTypeAdapter(object : TypeToken<Map<Any, Any>>() {}.getType(), IntTypeAdapter())
|
||||||
@ -137,6 +138,15 @@ class GlobalModule {
|
|||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Singleton
|
||||||
|
@Provides
|
||||||
|
fun provideTraceDatabase(context: Application): TraceDataBase {
|
||||||
|
return TraceDataBase.getDatabase(
|
||||||
|
context,
|
||||||
|
Constant.USER_DATA_PATH + "/trace.sqlite"
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
// /**
|
// /**
|
||||||
// * realm 注册
|
// * realm 注册
|
||||||
// */
|
// */
|
||||||
|
@ -1,10 +1,13 @@
|
|||||||
package com.navinfo.omqs.ui.activity.map
|
package com.navinfo.omqs.ui.activity.map
|
||||||
|
|
||||||
|
import android.os.Build
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import androidx.activity.viewModels
|
import androidx.activity.viewModels
|
||||||
|
import androidx.annotation.RequiresApi
|
||||||
import androidx.core.view.WindowCompat
|
import androidx.core.view.WindowCompat
|
||||||
import androidx.databinding.DataBindingUtil
|
import androidx.databinding.DataBindingUtil
|
||||||
import androidx.navigation.findNavController
|
import androidx.navigation.findNavController
|
||||||
|
import androidx.recyclerview.widget.LinearLayoutManager
|
||||||
import com.blankj.utilcode.util.ToastUtils
|
import com.blankj.utilcode.util.ToastUtils
|
||||||
import com.navinfo.collect.library.map.NIMapController
|
import com.navinfo.collect.library.map.NIMapController
|
||||||
import com.navinfo.collect.library.map.handler.NiLocationListener
|
import com.navinfo.collect.library.map.handler.NiLocationListener
|
||||||
@ -32,6 +35,7 @@ class MainActivity : BaseActivity() {
|
|||||||
@Inject
|
@Inject
|
||||||
lateinit var offlineMapDownloadManager: OfflineMapDownloadManager
|
lateinit var offlineMapDownloadManager: OfflineMapDownloadManager
|
||||||
|
|
||||||
|
private val signAdapter by lazy { SignAdapter() }
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
WindowCompat.setDecorFitsSystemWindows(window, false)
|
WindowCompat.setDecorFitsSystemWindows(window, false)
|
||||||
@ -43,7 +47,7 @@ class MainActivity : BaseActivity() {
|
|||||||
binding.mainActivityMap,
|
binding.mainActivityMap,
|
||||||
null,
|
null,
|
||||||
Constant.MAP_PATH,
|
Constant.MAP_PATH,
|
||||||
Constant.USER_DATA_PATH+"/trace.sqlite"
|
Constant.USER_DATA_PATH + "/trace.sqlite"
|
||||||
)
|
)
|
||||||
//关联生命周期
|
//关联生命周期
|
||||||
binding.lifecycleOwner = this
|
binding.lifecycleOwner = this
|
||||||
@ -56,7 +60,11 @@ class MainActivity : BaseActivity() {
|
|||||||
//处理页面跳转
|
//处理页面跳转
|
||||||
viewModel.navigation(this, it)
|
viewModel.navigation(this, it)
|
||||||
}
|
}
|
||||||
|
binding.mainActivitySignRecyclerview.layoutManager = LinearLayoutManager(this)
|
||||||
|
binding.mainActivitySignRecyclerview.adapter = signAdapter
|
||||||
|
viewModel.liveDataSignList.observe(this) {
|
||||||
|
signAdapter.refreshData(it)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onStart() {
|
override fun onStart() {
|
||||||
@ -64,15 +72,10 @@ class MainActivity : BaseActivity() {
|
|||||||
|
|
||||||
//开启定位
|
//开启定位
|
||||||
mapController.locationLayerHandler.startLocation()
|
mapController.locationLayerHandler.startLocation()
|
||||||
|
|
||||||
//启动轨迹存储
|
//启动轨迹存储
|
||||||
mapController.locationLayerHandler.setNiLocationListener(NiLocationListener {
|
// viewModel.startSaveTraceThread(this)
|
||||||
//ToastUtils.showLong("定位${it.longitude}")
|
|
||||||
binding!!.viewModel!!.addSaveTrace(it)
|
|
||||||
binding!!.viewModel!!.startSaveTraceThread(this)
|
|
||||||
})
|
|
||||||
//显示轨迹图层
|
|
||||||
// mapController.layerManagerHandler.showNiLocationLayer(Constant.DATA_PATH+ SystemConstant.USER_ID+"/trace.sqlite")
|
|
||||||
mapController.layerManagerHandler.showNiLocationLayer()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onPause() {
|
override fun onPause() {
|
||||||
@ -103,7 +106,7 @@ class MainActivity : BaseActivity() {
|
|||||||
*/
|
*/
|
||||||
fun openCamera() {
|
fun openCamera() {
|
||||||
//显示轨迹图层
|
//显示轨迹图层
|
||||||
binding!!.viewModel!!.onClickCameraButton(this)
|
viewModel.onClickCameraButton(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -2,23 +2,33 @@ package com.navinfo.omqs.ui.activity.map
|
|||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.DialogInterface
|
import android.content.DialogInterface
|
||||||
|
import android.os.Build
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
|
import androidx.annotation.RequiresApi
|
||||||
import androidx.lifecycle.MutableLiveData
|
import androidx.lifecycle.MutableLiveData
|
||||||
import androidx.lifecycle.ViewModel
|
import androidx.lifecycle.ViewModel
|
||||||
|
import androidx.lifecycle.viewModelScope
|
||||||
import androidx.navigation.findNavController
|
import androidx.navigation.findNavController
|
||||||
import com.navinfo.collect.library.data.dao.impl.TraceDataBase
|
import com.navinfo.collect.library.data.dao.impl.TraceDataBase
|
||||||
import com.navinfo.collect.library.data.entity.NiLocation
|
import com.navinfo.collect.library.data.entity.NiLocation
|
||||||
|
import com.navinfo.collect.library.data.entity.RenderEntity
|
||||||
import com.navinfo.collect.library.map.NIMapController
|
import com.navinfo.collect.library.map.NIMapController
|
||||||
|
import com.navinfo.collect.library.map.handler.NiLocationListener
|
||||||
import com.navinfo.collect.library.map.handler.OnQsRecordItemClickListener
|
import com.navinfo.collect.library.map.handler.OnQsRecordItemClickListener
|
||||||
import com.navinfo.collect.library.utils.GeometryTools
|
import com.navinfo.collect.library.utils.GeometryTools
|
||||||
import com.navinfo.collect.library.utils.GeometryToolsKt
|
import com.navinfo.collect.library.utils.GeometryToolsKt
|
||||||
import com.navinfo.omqs.Constant
|
import com.navinfo.omqs.Constant
|
||||||
import com.navinfo.omqs.R
|
import com.navinfo.omqs.R
|
||||||
|
import com.navinfo.omqs.db.RealmOperateHelper
|
||||||
import com.navinfo.omqs.ui.dialog.CommonDialog
|
import com.navinfo.omqs.ui.dialog.CommonDialog
|
||||||
import com.navinfo.omqs.ui.manager.TakePhotoManager
|
import com.navinfo.omqs.ui.manager.TakePhotoManager
|
||||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||||
|
import dagger.hilt.android.qualifiers.ActivityContext
|
||||||
|
import dagger.hilt.android.qualifiers.ApplicationContext
|
||||||
import io.realm.RealmSet
|
import io.realm.RealmSet
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
import org.oscim.core.GeoPoint
|
import org.oscim.core.GeoPoint
|
||||||
import org.videolan.libvlc.LibVlcUtil
|
import org.videolan.libvlc.LibVlcUtil
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
@ -26,15 +36,25 @@ import javax.inject.Inject
|
|||||||
/**
|
/**
|
||||||
* 创建Activity全局viewmode
|
* 创建Activity全局viewmode
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@HiltViewModel
|
@HiltViewModel
|
||||||
class MainViewModel @Inject constructor(
|
class MainViewModel @Inject constructor(
|
||||||
private val mapController: NIMapController,
|
private val mapController: NIMapController,
|
||||||
|
private val traceDataBase: TraceDataBase,
|
||||||
|
private val realmOperateHelper: RealmOperateHelper
|
||||||
) : ViewModel() {
|
) : ViewModel() {
|
||||||
|
|
||||||
val liveDataQsRecordIdList = MutableLiveData<List<String>>()
|
|
||||||
private var mCameraDialog: CommonDialog? = null
|
private var mCameraDialog: CommonDialog? = null
|
||||||
|
|
||||||
private var niLocationList: MutableList<NiLocation> = ArrayList<NiLocation>()
|
//地图点击捕捉到的质检数据ID列表
|
||||||
|
val liveDataQsRecordIdList = MutableLiveData<List<String>>()
|
||||||
|
|
||||||
|
//看板数据
|
||||||
|
val liveDataSignList = MutableLiveData<List<SignBean>>()
|
||||||
|
|
||||||
|
|
||||||
|
// private var niLocationList: MutableList<NiLocation> = ArrayList<NiLocation>()
|
||||||
|
var testPoint = GeoPoint(0, 0)
|
||||||
|
|
||||||
init {
|
init {
|
||||||
mapController.markerHandle.setOnQsRecordItemClickListener(object :
|
mapController.markerHandle.setOnQsRecordItemClickListener(object :
|
||||||
@ -43,6 +63,93 @@ class MainViewModel @Inject constructor(
|
|||||||
liveDataQsRecordIdList.value = list
|
liveDataQsRecordIdList.value = list
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
initLocation()
|
||||||
|
viewModelScope.launch {
|
||||||
|
mapController.onMapClickFlow.collect {
|
||||||
|
testPoint = it
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun initLocation() {
|
||||||
|
// mapController.locationLayerHandler.setNiLocationListener(NiLocationListener {
|
||||||
|
// addSaveTrace(it)
|
||||||
|
//
|
||||||
|
// })
|
||||||
|
//用于定位点存储到数据库
|
||||||
|
viewModelScope.launch(Dispatchers.Default) {
|
||||||
|
mapController.locationLayerHandler.niLocationFlow.collect { location ->
|
||||||
|
location.longitude = testPoint.longitude
|
||||||
|
location.latitude = testPoint.latitude
|
||||||
|
val geometry = GeometryTools.createGeometry(
|
||||||
|
GeoPoint(
|
||||||
|
location.latitude,
|
||||||
|
location.longitude
|
||||||
|
)
|
||||||
|
)
|
||||||
|
val tileX = RealmSet<Int>()
|
||||||
|
GeometryToolsKt.getTileXByGeometry(geometry.toString(), tileX)
|
||||||
|
val tileY = RealmSet<Int>()
|
||||||
|
GeometryToolsKt.getTileYByGeometry(geometry.toString(), tileY)
|
||||||
|
|
||||||
|
//遍历存储tile对应的x与y的值
|
||||||
|
tileX.forEach { x ->
|
||||||
|
tileY.forEach { y ->
|
||||||
|
location.tilex = x
|
||||||
|
location.tiley = y
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Log.e("jingo", "定位点插入 ${Thread.currentThread().name}")
|
||||||
|
traceDataBase.niLocationDao.insert(location)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//用于定位点捕捉道路
|
||||||
|
viewModelScope.launch(Dispatchers.Default) {
|
||||||
|
mapController.locationLayerHandler.niLocationFlow.collect { location ->
|
||||||
|
Log.e("jingo", "定位点绑定道路 ${Thread.currentThread().name}")
|
||||||
|
location.longitude = testPoint.longitude
|
||||||
|
location.latitude = testPoint.latitude
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
||||||
|
val linkList = realmOperateHelper.queryLink(
|
||||||
|
point = GeometryTools.createPoint(
|
||||||
|
location.longitude,
|
||||||
|
location.latitude
|
||||||
|
),
|
||||||
|
)
|
||||||
|
//看板数据
|
||||||
|
val signList = mutableListOf<SignBean>()
|
||||||
|
if (linkList.isNotEmpty()) {
|
||||||
|
val link = linkList[0]
|
||||||
|
val linkId = link.properties[RenderEntity.Companion.LinkTable.linkPid]
|
||||||
|
mapController.lineHandler.showLine(link.geometry)
|
||||||
|
linkId?.let {
|
||||||
|
var elementList = realmOperateHelper.queryLinkByLinkPid(it)
|
||||||
|
for (element in elementList) {
|
||||||
|
val distance = GeometryTools.distanceToDouble(
|
||||||
|
GeoPoint(
|
||||||
|
location.latitude, location.longitude,
|
||||||
|
),
|
||||||
|
GeometryTools.createGeoPoint(element.geometry)
|
||||||
|
)
|
||||||
|
signList.add(
|
||||||
|
SignBean(
|
||||||
|
iconId = R.drawable.icon_speed_limit,
|
||||||
|
iconText = element.name,
|
||||||
|
distance = distance.toInt(),
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
liveDataSignList.postValue(signList)
|
||||||
|
Log.e("jingo", "自动捕捉数据 共${elementList.size}条")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//显示轨迹图层
|
||||||
|
mapController.layerManagerHandler.showNiLocationLayer()
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -54,6 +161,9 @@ class MainViewModel @Inject constructor(
|
|||||||
|
|
||||||
override fun onCleared() {
|
override fun onCleared() {
|
||||||
super.onCleared()
|
super.onCleared()
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||||
|
mapController.lineHandler.removeLine()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//点击相机按钮
|
//点击相机按钮
|
||||||
@ -96,49 +206,61 @@ class MainViewModel @Inject constructor(
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fun startSaveTraceThread(context: Context) {
|
|
||||||
Thread(Runnable {
|
|
||||||
try {
|
|
||||||
while (true) {
|
|
||||||
|
|
||||||
if (niLocationList != null && niLocationList.size > 0) {
|
// fun startSaveTraceThread(context: Context) {
|
||||||
|
// Thread(Runnable {
|
||||||
|
// try {
|
||||||
|
// while (true) {
|
||||||
|
//
|
||||||
|
// if (niLocationList != null && niLocationList.size > 0) {
|
||||||
|
//
|
||||||
|
// var niLocation = niLocationList[0]
|
||||||
|
// val geometry = GeometryTools.createGeometry(
|
||||||
|
// GeoPoint(
|
||||||
|
// niLocation.latitude,
|
||||||
|
// niLocation.longitude
|
||||||
|
// )
|
||||||
|
// )
|
||||||
|
// val tileX = RealmSet<Int>()
|
||||||
|
// GeometryToolsKt.getTileXByGeometry(geometry.toString(), tileX)
|
||||||
|
// val tileY = RealmSet<Int>()
|
||||||
|
// GeometryToolsKt.getTileYByGeometry(geometry.toString(), tileY)
|
||||||
|
//
|
||||||
|
// //遍历存储tile对应的x与y的值
|
||||||
|
// tileX.forEach { x ->
|
||||||
|
// tileY.forEach { y ->
|
||||||
|
// niLocation.tilex = x
|
||||||
|
// niLocation.tiley = y
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// TraceDataBase.getDatabase(
|
||||||
|
// context,
|
||||||
|
// Constant.USER_DATA_PATH + "/trace.sqlite"
|
||||||
|
// ).niLocationDao.insert(niLocation)
|
||||||
|
// niLocationList.remove(niLocation)
|
||||||
|
//
|
||||||
|
// Log.e("qj", "saveTrace==${niLocationList.size}")
|
||||||
|
// }
|
||||||
|
// Thread.sleep(30)
|
||||||
|
// }
|
||||||
|
// } catch (e: InterruptedException) {
|
||||||
|
// e.printStackTrace()
|
||||||
|
// Log.e("qj", "异常==${e.message}")
|
||||||
|
// }
|
||||||
|
// }).start()
|
||||||
|
// }
|
||||||
|
|
||||||
var niLocation = niLocationList[0]
|
// //增加轨迹存储
|
||||||
val geometry = GeometryTools.createGeometry(GeoPoint(niLocation.latitude,niLocation.longitude))
|
// fun addSaveTrace(niLocation: NiLocation) {
|
||||||
val tileX = RealmSet<Int>()
|
// if (niLocation != null && niLocationList != null) {
|
||||||
GeometryToolsKt.getTileXByGeometry(geometry.toString(), tileX)
|
// niLocationList.add(niLocation)
|
||||||
val tileY = RealmSet<Int>()
|
// }
|
||||||
GeometryToolsKt.getTileYByGeometry(geometry.toString(), tileY)
|
// }
|
||||||
|
|
||||||
//遍历存储tile对应的x与y的值
|
|
||||||
tileX.forEach { x ->
|
|
||||||
tileY.forEach { y ->
|
|
||||||
niLocation.tilex = x
|
|
||||||
niLocation.tiley = y
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
TraceDataBase.getDatabase(context, Constant.USER_DATA_PATH + "/trace.sqlite").niLocationDao.insert(niLocation)
|
|
||||||
niLocationList.remove(niLocation)
|
|
||||||
|
|
||||||
Log.e("qj", "saveTrace==${niLocationList.size}")
|
|
||||||
}
|
|
||||||
Thread.sleep(30)
|
|
||||||
}
|
|
||||||
} catch (e: InterruptedException) {
|
|
||||||
e.printStackTrace()
|
|
||||||
Log.e("qj", "异常==${e.message}")
|
|
||||||
}
|
|
||||||
}).start()
|
|
||||||
}
|
|
||||||
|
|
||||||
//增加轨迹存储
|
|
||||||
fun addSaveTrace(niLocation: NiLocation) {
|
|
||||||
if (niLocation != null && niLocationList != null) {
|
|
||||||
niLocationList.add(niLocation)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 处理页面调转
|
||||||
|
*/
|
||||||
fun navigation(activity: MainActivity, list: List<String>) {
|
fun navigation(activity: MainActivity, list: List<String>) {
|
||||||
//获取右侧fragment容器
|
//获取右侧fragment容器
|
||||||
val naviController = activity.findNavController(R.id.main_activity_right_fragment)
|
val naviController = activity.findNavController(R.id.main_activity_right_fragment)
|
||||||
|
@ -0,0 +1,28 @@
|
|||||||
|
package com.navinfo.omqs.ui.activity.map
|
||||||
|
|
||||||
|
import android.view.LayoutInflater
|
||||||
|
import android.view.ViewGroup
|
||||||
|
import com.navinfo.omqs.R
|
||||||
|
import com.navinfo.omqs.databinding.AdapterSignBinding
|
||||||
|
import com.navinfo.omqs.ui.other.BaseRecyclerViewAdapter
|
||||||
|
import com.navinfo.omqs.ui.other.BaseViewHolder
|
||||||
|
|
||||||
|
class SignAdapter : BaseRecyclerViewAdapter<SignBean>() {
|
||||||
|
override fun getItemViewRes(position: Int): Int {
|
||||||
|
return R.layout.adapter_sign
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): BaseViewHolder {
|
||||||
|
val viewBinding =
|
||||||
|
AdapterSignBinding.inflate(LayoutInflater.from(parent.context), parent, false)
|
||||||
|
return BaseViewHolder(viewBinding)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onBindViewHolder(holder: BaseViewHolder, position: Int) {
|
||||||
|
val bd = holder.viewBinding as AdapterSignBinding
|
||||||
|
val item = data[position]
|
||||||
|
bd.signMainIcon.background = holder.viewBinding.root.context.getDrawable(item.iconId)
|
||||||
|
bd.signMainIcon.text = item.iconText
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,8 @@
|
|||||||
|
package com.navinfo.omqs.ui.activity.map
|
||||||
|
|
||||||
|
data class SignBean(
|
||||||
|
//图标ID
|
||||||
|
val iconId: Int,
|
||||||
|
val distance: Int = 0,
|
||||||
|
val iconText: String = ""
|
||||||
|
)
|
@ -8,7 +8,6 @@ import androidx.lifecycle.ViewModel
|
|||||||
import androidx.lifecycle.viewModelScope
|
import androidx.lifecycle.viewModelScope
|
||||||
import com.navinfo.collect.library.data.entity.QsRecordBean
|
import com.navinfo.collect.library.data.entity.QsRecordBean
|
||||||
import com.navinfo.collect.library.data.entity.RenderEntity.Companion.LinkTable
|
import com.navinfo.collect.library.data.entity.RenderEntity.Companion.LinkTable
|
||||||
import com.navinfo.collect.library.map.GeoPoint
|
|
||||||
import com.navinfo.collect.library.map.NIMapController
|
import com.navinfo.collect.library.map.NIMapController
|
||||||
import com.navinfo.collect.library.utils.GeometryTools
|
import com.navinfo.collect.library.utils.GeometryTools
|
||||||
import com.navinfo.omqs.db.RealmOperateHelper
|
import com.navinfo.omqs.db.RealmOperateHelper
|
||||||
@ -18,10 +17,10 @@ import io.realm.Realm
|
|||||||
import io.realm.kotlin.where
|
import io.realm.kotlin.where
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
import org.oscim.core.GeoPoint
|
||||||
import java.util.*
|
import java.util.*
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
@RequiresApi(Build.VERSION_CODES.N)
|
|
||||||
@HiltViewModel
|
@HiltViewModel
|
||||||
class EvaluationResultViewModel @Inject constructor(
|
class EvaluationResultViewModel @Inject constructor(
|
||||||
private val roomAppDatabase: RoomAppDatabase,
|
private val roomAppDatabase: RoomAppDatabase,
|
||||||
@ -59,24 +58,24 @@ class EvaluationResultViewModel @Inject constructor(
|
|||||||
init {
|
init {
|
||||||
liveDataQsRecordBean.value = QsRecordBean(id = UUID.randomUUID().toString())
|
liveDataQsRecordBean.value = QsRecordBean(id = UUID.randomUUID().toString())
|
||||||
Log.e("jingo", "EvaluationResultViewModel 创建了 ${hashCode()}")
|
Log.e("jingo", "EvaluationResultViewModel 创建了 ${hashCode()}")
|
||||||
mapController.markerHandle.run {
|
viewModelScope.launch {
|
||||||
setOnMapClickListener {
|
mapController.onMapClickFlow.collect {
|
||||||
liveDataQsRecordBean.value!!.geometry = it.toGeometry()
|
liveDataQsRecordBean.value!!.geometry = GeometryTools.createGeometry(it).toText()
|
||||||
addMarker(it, markerTitle)
|
mapController.markerHandle.addMarker(it, markerTitle)
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
captureLink(it.longitude, it.latitude)
|
captureLink(it.longitude, it.latitude)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onCleared() {
|
override fun onCleared() {
|
||||||
super.onCleared()
|
super.onCleared()
|
||||||
Log.e("jingo", "EvaluationResultViewModel 销毁了 ${hashCode()}")
|
Log.e("jingo", "EvaluationResultViewModel 销毁了 ${hashCode()}")
|
||||||
mapController.markerHandle.removeMarker(markerTitle)
|
mapController.markerHandle.removeMarker(markerTitle)
|
||||||
mapController.markerHandle.removeOnMapClickListener()
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||||
mapController.lineHandler.removeLine()
|
mapController.lineHandler.removeLine()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -90,7 +89,7 @@ class EvaluationResultViewModel @Inject constructor(
|
|||||||
}
|
}
|
||||||
val geoPoint = mapController.locationLayerHandler.getCurrentGeoPoint()
|
val geoPoint = mapController.locationLayerHandler.getCurrentGeoPoint()
|
||||||
geoPoint?.let {
|
geoPoint?.let {
|
||||||
liveDataQsRecordBean.value!!.geometry = it.toGeometry()
|
liveDataQsRecordBean.value!!.geometry = GeometryTools.createGeometry(it).toText()
|
||||||
mapController.markerHandle.addMarker(geoPoint, markerTitle)
|
mapController.markerHandle.addMarker(geoPoint, markerTitle)
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
captureLink(geoPoint.longitude, geoPoint.latitude)
|
captureLink(geoPoint.longitude, geoPoint.latitude)
|
||||||
@ -102,20 +101,23 @@ class EvaluationResultViewModel @Inject constructor(
|
|||||||
* 捕捉到路
|
* 捕捉到路
|
||||||
*/
|
*/
|
||||||
private suspend fun captureLink(longitude: Double, latitude: Double) {
|
private suspend fun captureLink(longitude: Double, latitude: Double) {
|
||||||
val linkList = realmOperateHelper.queryLink(
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
||||||
point = GeometryTools.createPoint(
|
val linkList = realmOperateHelper.queryLink(
|
||||||
longitude,
|
point = GeometryTools.createPoint(
|
||||||
latitude
|
longitude,
|
||||||
),
|
latitude
|
||||||
)
|
),
|
||||||
liveDataQsRecordBean.value?.let {
|
)
|
||||||
if (linkList.isNotEmpty()) {
|
|
||||||
it.linkId =
|
liveDataQsRecordBean.value?.let {
|
||||||
linkList[0].properties[LinkTable.linkPid] ?: ""
|
if (linkList.isNotEmpty()) {
|
||||||
mapController.lineHandler.showLine(linkList[0].geometry)
|
it.linkId =
|
||||||
} else {
|
linkList[0].properties[LinkTable.linkPid] ?: ""
|
||||||
it.linkId = ""
|
mapController.lineHandler.showLine(linkList[0].geometry)
|
||||||
mapController.lineHandler.removeLine()
|
} else {
|
||||||
|
it.linkId = ""
|
||||||
|
mapController.lineHandler.removeLine()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -276,23 +278,26 @@ class EvaluationResultViewModel @Inject constructor(
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
fun initData(id: String) {
|
fun initData(id: String) {
|
||||||
viewModelScope.launch(Dispatchers.IO) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
||||||
val realm = Realm.getDefaultInstance()
|
viewModelScope.launch(Dispatchers.IO) {
|
||||||
val objects = realm.where<QsRecordBean>().equalTo("id", id).findFirst()
|
val realm = Realm.getDefaultInstance()
|
||||||
|
val objects = realm.where<QsRecordBean>().equalTo("id", id).findFirst()
|
||||||
|
|
||||||
if (objects != null) {
|
if (objects != null) {
|
||||||
oldBean = realm.copyFromRealm(objects)
|
oldBean = realm.copyFromRealm(objects)
|
||||||
oldBean?.let {
|
oldBean?.let {
|
||||||
liveDataQsRecordBean.postValue(it.copy())
|
liveDataQsRecordBean.postValue(it.copy())
|
||||||
val p = GeometryTools.createGeoPoint(it.geometry)
|
val p = GeometryTools.createGeoPoint(it.geometry)
|
||||||
mapController.markerHandle.addMarker(
|
mapController.markerHandle.addMarker(
|
||||||
GeoPoint(p.longitude, p.latitude),
|
GeoPoint(p.latitude, p.longitude),
|
||||||
markerTitle
|
markerTitle
|
||||||
)
|
)
|
||||||
if (it.linkId.isNotEmpty()) {
|
|
||||||
val link = realmOperateHelper.queryLink(it.linkId)
|
if (it.linkId.isNotEmpty()) {
|
||||||
link?.let { l ->
|
val link = realmOperateHelper.queryLink(it.linkId)
|
||||||
mapController.lineHandler.showLine(l.geometry)
|
link?.let { l ->
|
||||||
|
mapController.lineHandler.showLine(l.geometry)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,9 @@
|
|||||||
package com.navinfo.omqs.ui.fragment.evaluationresult
|
package com.navinfo.omqs.ui.fragment.evaluationresult
|
||||||
|
|
||||||
|
import android.os.Build
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
|
import androidx.annotation.RequiresApi
|
||||||
import com.navinfo.omqs.R
|
import com.navinfo.omqs.R
|
||||||
import com.navinfo.omqs.databinding.TextItemSelectBinding
|
import com.navinfo.omqs.databinding.TextItemSelectBinding
|
||||||
import com.navinfo.omqs.ui.other.BaseRecyclerViewAdapter
|
import com.navinfo.omqs.ui.other.BaseRecyclerViewAdapter
|
||||||
@ -21,6 +23,7 @@ class MiddleAdapter(private var itemListener: ((Int, String) -> Unit?)? = null)
|
|||||||
return BaseViewHolder(viewBinding)
|
return BaseViewHolder(viewBinding)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@RequiresApi(Build.VERSION_CODES.M)
|
||||||
override fun onBindViewHolder(holder: BaseViewHolder, position: Int) {
|
override fun onBindViewHolder(holder: BaseViewHolder, position: Int) {
|
||||||
val bd = holder.viewBinding as TextItemSelectBinding
|
val bd = holder.viewBinding as TextItemSelectBinding
|
||||||
val title = data[position]
|
val title = data[position]
|
||||||
|
12
app/src/main/res/drawable/icon_speed_limit.xml
Normal file
12
app/src/main/res/drawable/icon_speed_limit.xml
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:shape="oval"
|
||||||
|
android:useLevel="false">
|
||||||
|
<stroke
|
||||||
|
android:width="1.33dp"
|
||||||
|
android:color="#DB4646" />
|
||||||
|
<size
|
||||||
|
android:width="24dp"
|
||||||
|
android:height="24dp" />
|
||||||
|
<solid android:color="@color/white" />
|
||||||
|
|
||||||
|
</shape>
|
@ -35,6 +35,7 @@
|
|||||||
app:layout_constraintRight_toRightOf="parent"
|
app:layout_constraintRight_toRightOf="parent"
|
||||||
app:layout_constraintTop_toTopOf="parent" />
|
app:layout_constraintTop_toTopOf="parent" />
|
||||||
|
|
||||||
|
|
||||||
<ImageButton
|
<ImageButton
|
||||||
android:id="@+id/main_activity_person_center"
|
android:id="@+id/main_activity_person_center"
|
||||||
android:layout_width="48dp"
|
android:layout_width="48dp"
|
||||||
@ -46,6 +47,14 @@
|
|||||||
app:layout_constraintLeft_toLeftOf="parent"
|
app:layout_constraintLeft_toLeftOf="parent"
|
||||||
app:layout_constraintTop_toTopOf="parent" />
|
app:layout_constraintTop_toTopOf="parent" />
|
||||||
|
|
||||||
|
<androidx.recyclerview.widget.RecyclerView
|
||||||
|
android:id="@+id/main_activity_sign_recyclerview"
|
||||||
|
android:layout_width="150dp"
|
||||||
|
android:layout_height="350dp"
|
||||||
|
android:layout_marginTop="10dp"
|
||||||
|
app:layout_constraintLeft_toLeftOf="@id/main_activity_person_center"
|
||||||
|
app:layout_constraintTop_toBottomOf="@id/main_activity_person_center" />
|
||||||
|
|
||||||
<ImageButton
|
<ImageButton
|
||||||
android:id="@+id/main_activity_location"
|
android:id="@+id/main_activity_location"
|
||||||
android:layout_width="48dp"
|
android:layout_width="48dp"
|
||||||
@ -68,6 +77,16 @@
|
|||||||
app:layout_constraintBottom_toBottomOf="parent"
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
app:layout_constraintRight_toRightOf="parent" />
|
app:layout_constraintRight_toRightOf="parent" />
|
||||||
|
|
||||||
|
<ImageButton
|
||||||
|
android:id="@+id/main_activity_line"
|
||||||
|
android:layout_width="48dp"
|
||||||
|
android:layout_height="48dp"
|
||||||
|
android:layout_marginBottom="10dp"
|
||||||
|
android:onClick="@{()->mainActivity.voiceOnclick()}"
|
||||||
|
android:src="@drawable/baseline_keyboard_voice_24"
|
||||||
|
app:layout_constraintBottom_toTopOf="@id/main_activity_voice"
|
||||||
|
app:layout_constraintRight_toRightOf="@id/main_activity_voice" />
|
||||||
|
|
||||||
<fragment
|
<fragment
|
||||||
android:id="@+id/main_activity_middle_fragment"
|
android:id="@+id/main_activity_middle_fragment"
|
||||||
android:name="androidx.navigation.fragment.NavHostFragment"
|
android:name="androidx.navigation.fragment.NavHostFragment"
|
||||||
@ -107,11 +126,11 @@
|
|||||||
android:id="@+id/main_activity_camera2"
|
android:id="@+id/main_activity_camera2"
|
||||||
android:layout_width="48dp"
|
android:layout_width="48dp"
|
||||||
android:layout_height="48dp"
|
android:layout_height="48dp"
|
||||||
android:visibility="gone"
|
|
||||||
android:layout_marginLeft="20dp"
|
android:layout_marginLeft="20dp"
|
||||||
android:layout_marginTop="20dp"
|
android:layout_marginTop="20dp"
|
||||||
android:onClick="@{()->mainActivity.openCamera()}"
|
android:onClick="@{()->mainActivity.openCamera()}"
|
||||||
android:src="@drawable/baseline_person_24"
|
android:src="@drawable/baseline_person_24"
|
||||||
|
android:visibility="gone"
|
||||||
app:layout_constraintRight_toRightOf="parent"
|
app:layout_constraintRight_toRightOf="parent"
|
||||||
app:layout_constraintTop_toTopOf="parent" />
|
app:layout_constraintTop_toTopOf="parent" />
|
||||||
|
|
||||||
|
20
app/src/main/res/layout/adapter_sign.xml
Normal file
20
app/src/main/res/layout/adapter_sign.xml
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:background="@mipmap/bg_sign"
|
||||||
|
tools:context="com.navinfo.omqs.ui.activity.map.SignAdapter">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/sign_main_icon"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginLeft="19dp"
|
||||||
|
android:layout_marginTop="4dp"
|
||||||
|
android:background="@drawable/icon_speed_limit"
|
||||||
|
android:gravity="center"
|
||||||
|
android:text="80"
|
||||||
|
android:textColor="#2F2F2F"
|
||||||
|
android:textSize="14.67sp" />
|
||||||
|
</RelativeLayout>
|
BIN
app/src/main/res/mipmap-xxhdpi/bg_sign.png
Normal file
BIN
app/src/main/res/mipmap-xxhdpi/bg_sign.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 11 KiB |
@ -1,14 +1,14 @@
|
|||||||
package com.navinfo.collect.library.map
|
//package com.navinfo.collect.library.map
|
||||||
|
//
|
||||||
import android.os.Parcelable
|
//import android.os.Parcelable
|
||||||
import kotlinx.parcelize.Parcelize
|
//import kotlinx.parcelize.Parcelize
|
||||||
|
//
|
||||||
@Parcelize
|
//@Parcelize
|
||||||
data class GeoPoint(
|
//data class GeoPoint(
|
||||||
var latitude: Double = 0.0,
|
// var latitude: Double = 0.0,
|
||||||
var longitude: Double = 0.0
|
// var longitude: Double = 0.0
|
||||||
) : Parcelable {
|
//) : Parcelable {
|
||||||
fun toGeometry(): String {
|
// fun toGeometry(): String {
|
||||||
return "POINT($longitude $latitude)"
|
// return "POINT($longitude $latitude)"
|
||||||
}
|
// }
|
||||||
}
|
//}
|
@ -1,14 +1,20 @@
|
|||||||
package com.navinfo.collect.library.map
|
package com.navinfo.collect.library.map
|
||||||
|
|
||||||
import android.content.Context
|
import android.os.Build
|
||||||
import android.util.Log
|
import androidx.annotation.RequiresApi
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
|
import androidx.lifecycle.lifecycleScope
|
||||||
import com.navinfo.collect.library.data.entity.NiLocation
|
import com.navinfo.collect.library.data.entity.NiLocation
|
||||||
import com.navinfo.collect.library.data.handler.DataNiLocationHandler
|
import com.navinfo.collect.library.data.handler.DataNiLocationHandler
|
||||||
|
import com.navinfo.collect.library.map.NIMapView.OnMapClickListener
|
||||||
import com.navinfo.collect.library.map.handler.*
|
import com.navinfo.collect.library.map.handler.*
|
||||||
import com.navinfo.collect.library.map.maphandler.MeasureLayerHandler
|
import com.navinfo.collect.library.map.handler.MeasureLayerHandler
|
||||||
import com.navinfo.collect.library.map.handler.ViewportHandler
|
import com.navinfo.collect.library.map.handler.ViewportHandler
|
||||||
import com.navinfo.collect.library.system.Constant
|
import com.navinfo.collect.library.system.Constant
|
||||||
|
import kotlinx.coroutines.flow.MutableSharedFlow
|
||||||
|
import kotlinx.coroutines.flow.SharedFlow
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
|
import org.oscim.core.GeoPoint
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 地图控制器
|
* 地图控制器
|
||||||
@ -25,19 +31,35 @@ class NIMapController {
|
|||||||
lateinit var viewportHandler: ViewportHandler
|
lateinit var viewportHandler: ViewportHandler
|
||||||
lateinit var measureLayerHandler: MeasureLayerHandler
|
lateinit var measureLayerHandler: MeasureLayerHandler
|
||||||
|
|
||||||
fun init(context: AppCompatActivity, mapView: NIMapView, options: NIMapOptions? = null, mapPath: String, tracePath: String) {
|
val onMapClickFlow = MutableSharedFlow<GeoPoint>()
|
||||||
|
|
||||||
|
fun init(
|
||||||
|
context: AppCompatActivity,
|
||||||
|
mapView: NIMapView,
|
||||||
|
options: NIMapOptions? = null,
|
||||||
|
mapPath: String,
|
||||||
|
tracePath: String
|
||||||
|
) {
|
||||||
Constant.MAP_PATH = mapPath
|
Constant.MAP_PATH = mapPath
|
||||||
layerManagerHandler = LayerManagerHandler(context, mapView, tracePath)
|
layerManagerHandler = LayerManagerHandler(context, mapView, tracePath)
|
||||||
locationLayerHandler = LocationLayerHandler(context, mapView)
|
locationLayerHandler = LocationLayerHandler(context, mapView)
|
||||||
animationHandler = AnimationHandler(context, mapView)
|
animationHandler = AnimationHandler(context, mapView)
|
||||||
markerHandle = MarkHandler(context, mapView)
|
markerHandle = MarkHandler(context, mapView)
|
||||||
lineHandler = LineHandler(context, mapView)
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||||
|
lineHandler = LineHandler(context, mapView)
|
||||||
|
}
|
||||||
polygonHandler = PolygonHandler(context, mapView)
|
polygonHandler = PolygonHandler(context, mapView)
|
||||||
viewportHandler = ViewportHandler(context, mapView)
|
viewportHandler = ViewportHandler(context, mapView)
|
||||||
measureLayerHandler = MeasureLayerHandler(context, mapView)
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||||
|
measureLayerHandler = MeasureLayerHandler(context, mapView)
|
||||||
|
}
|
||||||
mMapView = mapView
|
mMapView = mapView
|
||||||
|
mMapView.setOnMapClickListener {
|
||||||
|
context.lifecycleScope.launch {
|
||||||
|
onMapClickFlow.emit(it)
|
||||||
|
}
|
||||||
|
}
|
||||||
mapView.setOptions(options)
|
mapView.setOptions(options)
|
||||||
mMapView.vtmMap.viewport().maxZoomLevel = Constant.MAX_ZOOM // 设置地图的最大级别
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package com.navinfo.collect.library.map
|
package com.navinfo.collect.library.map
|
||||||
|
|
||||||
|
import com.navinfo.collect.library.system.Constant
|
||||||
import org.json.JSONObject
|
import org.json.JSONObject
|
||||||
|
|
||||||
|
|
||||||
@ -8,6 +9,7 @@ data class NIMapOptions(
|
|||||||
val showZoomControl: Boolean = true, //是否显示zoom按钮
|
val showZoomControl: Boolean = true, //是否显示zoom按钮
|
||||||
val zoomLevel: Double = 13.0, /// 地图比例尺初始级别
|
val zoomLevel: Double = 13.0, /// 地图比例尺初始级别
|
||||||
val coordinate: NICoordinate = NICoordinate(39.907375, 116.391349),
|
val coordinate: NICoordinate = NICoordinate(39.907375, 116.391349),
|
||||||
|
val maxZoom: Int = Constant.MAX_ZOOM
|
||||||
) {
|
) {
|
||||||
companion object {
|
companion object {
|
||||||
fun fromJson(json: String): NIMapOptions {
|
fun fromJson(json: String): NIMapOptions {
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package com.navinfo.collect.library.map;
|
package com.navinfo.collect.library.map;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
@ -121,7 +122,7 @@ public final class NIMapView extends RelativeLayout {
|
|||||||
*
|
*
|
||||||
* @param point
|
* @param point
|
||||||
*/
|
*/
|
||||||
void onMapClick(com.navinfo.collect.library.map.GeoPoint point);
|
void onMapClick(GeoPoint point);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 地图内 Poi 单击事件回调函数
|
* 地图内 Poi 单击事件回调函数
|
||||||
@ -358,6 +359,7 @@ public final class NIMapView extends RelativeLayout {
|
|||||||
}
|
}
|
||||||
MapPosition mapPosition = getVtmMap().getMapPosition();
|
MapPosition mapPosition = getVtmMap().getMapPosition();
|
||||||
mapPosition.setZoom(options.getZoomLevel());
|
mapPosition.setZoom(options.getZoomLevel());
|
||||||
|
getVtmMap().viewport().setMaxZoomLevel(options.getMaxZoom());
|
||||||
mapPosition.setPosition(options.getCoordinate().getLatitude(), options.getCoordinate().getLongitude());
|
mapPosition.setPosition(options.getCoordinate().getLatitude(), options.getCoordinate().getLongitude());
|
||||||
getVtmMap().animator().animateTo(100, mapPosition);
|
getVtmMap().animator().animateTo(100, mapPosition);
|
||||||
}
|
}
|
||||||
@ -819,7 +821,9 @@ public final class NIMapView extends RelativeLayout {
|
|||||||
LayoutParams layoutParams = (LayoutParams) view.getLayoutParams();
|
LayoutParams layoutParams = (LayoutParams) view.getLayoutParams();
|
||||||
if (layoutParams.getRules() != null) {
|
if (layoutParams.getRules() != null) {
|
||||||
for (int i = 0; i < layoutParams.getRules().length; i++) {
|
for (int i = 0; i < layoutParams.getRules().length; i++) {
|
||||||
layoutParams.removeRule(i);
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
|
||||||
|
layoutParams.removeRule(i);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
switch (position) {
|
switch (position) {
|
||||||
@ -926,7 +930,7 @@ public final class NIMapView extends RelativeLayout {
|
|||||||
GeoPoint geoPoint = mMap.viewport().fromScreenPoint(e.getX(), e.getY());
|
GeoPoint geoPoint = mMap.viewport().fromScreenPoint(e.getX(), e.getY());
|
||||||
if (g instanceof Gesture.Tap) { // 单击事件
|
if (g instanceof Gesture.Tap) { // 单击事件
|
||||||
if (mapClickListener != null) {
|
if (mapClickListener != null) {
|
||||||
mapClickListener.onMapClick(new com.navinfo.collect.library.map.GeoPoint(geoPoint.getLatitude(), geoPoint.getLongitude()));
|
mapClickListener.onMapClick(geoPoint);
|
||||||
}
|
}
|
||||||
} else if (g instanceof Gesture.DoubleTap) { // 双击
|
} else if (g instanceof Gesture.DoubleTap) { // 双击
|
||||||
if (mapDoubleClickListener != null) {
|
if (mapDoubleClickListener != null) {
|
||||||
|
@ -20,11 +20,11 @@ abstract class BaseHandler(context: AppCompatActivity, mapView: NIMapView) {
|
|||||||
mMapView.vtmMap.layers().remove(layer)
|
mMapView.vtmMap.layers().remove(layer)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun setOnMapClickListener(listener: NIMapView.OnMapClickListener) {
|
// fun setOnMapClickListener(listener: NIMapView.OnMapClickListener) {
|
||||||
mMapView.setOnMapClickListener(listener)
|
// mMapView.setOnMapClickListener(listener)
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
fun removeOnMapClickListener() {
|
// fun removeOnMapClickListener() {
|
||||||
mMapView.setOnMapClickListener(null)
|
// mMapView.setOnMapClickListener(null)
|
||||||
}
|
// }
|
||||||
}
|
}
|
@ -24,7 +24,7 @@ import java.io.File
|
|||||||
class LayerManagerHandler(context: AppCompatActivity, mapView: NIMapView,tracePath: String) : BaseHandler(context, mapView) {
|
class LayerManagerHandler(context: AppCompatActivity, mapView: NIMapView,tracePath: String) : BaseHandler(context, mapView) {
|
||||||
private var baseGroupLayer // 用于盛放所有基础底图的图层组,便于统一管理
|
private var baseGroupLayer // 用于盛放所有基础底图的图层组,便于统一管理
|
||||||
: GroupLayer? = null
|
: GroupLayer? = null
|
||||||
protected val mTracePath:String = tracePath
|
private val mTracePath:String = tracePath
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 轨迹渲染图层
|
* 轨迹渲染图层
|
||||||
|
@ -137,13 +137,12 @@ class LineHandler(context: AppCompatActivity, mapView: NIMapView) : BaseHandler(
|
|||||||
|
|
||||||
fun showLine(geometry: String) {
|
fun showLine(geometry: String) {
|
||||||
try {
|
try {
|
||||||
|
mDefaultPathLayer.clearPath()
|
||||||
|
mDefaultPathLayer.setPoints(GeometryTools.getGeoPoints(geometry))
|
||||||
|
mDefaultPathLayer.isEnabled = true
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
Toast.makeText(mContext, "高亮路线失败 ${e.message}", Toast.LENGTH_SHORT).show()
|
Toast.makeText(mContext, "高亮路线失败 ${e.message}", Toast.LENGTH_SHORT).show()
|
||||||
}
|
}
|
||||||
val g = GeometryTools.getGeoPoints(geometry)
|
|
||||||
mDefaultPathLayer.setPoints(g)
|
|
||||||
mDefaultPathLayer.isEnabled = true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun removeLine() {
|
fun removeLine() {
|
||||||
|
@ -1,27 +1,34 @@
|
|||||||
package com.navinfo.collect.library.map.handler
|
package com.navinfo.collect.library.map.handler
|
||||||
|
|
||||||
import android.content.Context
|
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
|
import androidx.lifecycle.lifecycleScope
|
||||||
import com.baidu.location.BDAbstractLocationListener
|
import com.baidu.location.BDAbstractLocationListener
|
||||||
import com.baidu.location.BDLocation
|
import com.baidu.location.BDLocation
|
||||||
import com.baidu.location.LocationClient
|
import com.baidu.location.LocationClient
|
||||||
import com.baidu.location.LocationClientOption
|
import com.baidu.location.LocationClientOption
|
||||||
import com.baidu.location.LocationClientOption.LocationMode
|
import com.baidu.location.LocationClientOption.LocationMode
|
||||||
import com.navinfo.collect.library.data.entity.NiLocation
|
import com.navinfo.collect.library.data.entity.NiLocation
|
||||||
import com.navinfo.collect.library.map.GeoPoint
|
|
||||||
import com.navinfo.collect.library.map.NIMapView
|
import com.navinfo.collect.library.map.NIMapView
|
||||||
|
import kotlinx.coroutines.flow.MutableSharedFlow
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
|
import org.oscim.core.GeoPoint
|
||||||
import org.oscim.layers.LocationLayer
|
import org.oscim.layers.LocationLayer
|
||||||
|
|
||||||
|
|
||||||
class LocationLayerHandler(context: AppCompatActivity, mapView: NIMapView) : BaseHandler(context, mapView) {
|
class LocationLayerHandler(context: AppCompatActivity, mapView: NIMapView) :
|
||||||
|
BaseHandler(context, mapView) {
|
||||||
|
|
||||||
private var mCurrentLocation: BDLocation? = null
|
private var mCurrentLocation: BDLocation? = null
|
||||||
private var bFirst = true
|
private var bFirst = true
|
||||||
private val mLocationLayer: LocationLayer = LocationLayer(mMapView.vtmMap)
|
private val mLocationLayer: LocationLayer = LocationLayer(mMapView.vtmMap)
|
||||||
private lateinit var locationClient: LocationClient
|
private lateinit var locationClient: LocationClient
|
||||||
private lateinit var niLocationListener: NiLocationListener
|
// private var niLocationListener: NiLocationListener by lazy{
|
||||||
|
//
|
||||||
|
// }
|
||||||
|
|
||||||
|
val niLocationFlow = MutableSharedFlow<NiLocation>(5)
|
||||||
|
|
||||||
init {
|
init {
|
||||||
///添加定位图层到地图,[NIMapView.LAYER_GROUPS.NAVIGATION] 是最上层layer组
|
///添加定位图层到地图,[NIMapView.LAYER_GROUPS.NAVIGATION] 是最上层layer组
|
||||||
@ -47,20 +54,29 @@ class LocationLayerHandler(context: AppCompatActivity, mapView: NIMapView) : Bas
|
|||||||
//更多结果信息获取说明,请参照类参考中BDLocation类中的说明
|
//更多结果信息获取说明,请参照类参考中BDLocation类中的说明
|
||||||
|
|
||||||
//获取纬度信息
|
//获取纬度信息
|
||||||
val latitude = it.latitude
|
// val latitude = it.latitude
|
||||||
//获取经度信息
|
//获取经度信息
|
||||||
val longitude = it.longitude
|
// val longitude = it.longitude
|
||||||
//获取定位精度,默认值为0.0f
|
//获取定位精度,默认值为0.0f
|
||||||
val radius = it.radius
|
// val radius = it.radius
|
||||||
//获取经纬度坐标类型,以LocationClientOption中设置过的坐标类型为准
|
//获取经纬度坐标类型,以LocationClientOption中设置过的坐标类型为准
|
||||||
val coorType = it.coorType
|
// val coorType = it.coorType
|
||||||
//获取定位类型、定位错误返回码,具体信息可参照类参考中BDLocation类中的说明
|
//获取定位类型、定位错误返回码,具体信息可参照类参考中BDLocation类中的说明
|
||||||
val errorCode = it.locType
|
val errorCode = it.locType
|
||||||
mCurrentLocation = it
|
mCurrentLocation = it
|
||||||
mLocationLayer.setPosition(it.latitude, it.longitude, it.radius)
|
mLocationLayer.setPosition(it.latitude, it.longitude, it.radius)
|
||||||
Log.e("qj","location==${it.longitude}==errorCode===$errorCode===${it.locTypeDescription}")
|
// Log.e(
|
||||||
if(niLocationListener!=null){
|
// "qj",
|
||||||
getCurrentNiLocation()?.let { it1 -> niLocationListener.call(it1) }
|
// "location==${it.longitude}==errorCode===$errorCode===${it.locTypeDescription}"
|
||||||
|
// )
|
||||||
|
|
||||||
|
// if (niLocationListener != null) {
|
||||||
|
getCurrentNiLocation()?.let { it1 ->
|
||||||
|
mContext.lifecycleScope.launch {
|
||||||
|
niLocationFlow.emit(it1)
|
||||||
|
}
|
||||||
|
|
||||||
|
// }// niLocationListener.call(it1) }
|
||||||
}
|
}
|
||||||
//第一次定位成功显示当前位置
|
//第一次定位成功显示当前位置
|
||||||
if (this.bFirst) {
|
if (this.bFirst) {
|
||||||
@ -107,7 +123,7 @@ class LocationLayerHandler(context: AppCompatActivity, mapView: NIMapView) : Bas
|
|||||||
locationClient.locOption = locationOption
|
locationClient.locOption = locationOption
|
||||||
} catch (e: Throwable) {
|
} catch (e: Throwable) {
|
||||||
Toast.makeText(mContext, "定位初始化失败 $e", Toast.LENGTH_SHORT)
|
Toast.makeText(mContext, "定位初始化失败 $e", Toast.LENGTH_SHORT)
|
||||||
Log.e("qj","定位初始化失败$e")
|
Log.e("qj", "定位初始化失败$e")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -160,8 +176,8 @@ class LocationLayerHandler(context: AppCompatActivity, mapView: NIMapView) : Bas
|
|||||||
|
|
||||||
//获取当前定位对象
|
//获取当前定位对象
|
||||||
fun getCurrentNiLocation(): NiLocation? {
|
fun getCurrentNiLocation(): NiLocation? {
|
||||||
if(mCurrentLocation!=null){
|
if (mCurrentLocation != null) {
|
||||||
val niLocation:NiLocation = NiLocation()
|
val niLocation: NiLocation = NiLocation()
|
||||||
niLocation.longitude = mCurrentLocation!!.longitude
|
niLocation.longitude = mCurrentLocation!!.longitude
|
||||||
niLocation.latitude = mCurrentLocation!!.latitude
|
niLocation.latitude = mCurrentLocation!!.latitude
|
||||||
niLocation.direction = mCurrentLocation!!.direction.toDouble()
|
niLocation.direction = mCurrentLocation!!.direction.toDouble()
|
||||||
@ -186,10 +202,10 @@ class LocationLayerHandler(context: AppCompatActivity, mapView: NIMapView) : Bas
|
|||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
//设置定位回调
|
// //设置定位回调
|
||||||
fun setNiLocationListener(listener: NiLocationListener){
|
// fun setNiLocationListener(listener: NiLocationListener) {
|
||||||
niLocationListener = listener
|
// niLocationListener = listener
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -205,7 +221,7 @@ private class MyLocationListener(callback: (BDLocation) -> Unit) : BDAbstractLoc
|
|||||||
/**
|
/**
|
||||||
* 实现定位回调
|
* 实现定位回调
|
||||||
*/
|
*/
|
||||||
public class NiLocationListener(callback: (NiLocation) -> Unit){
|
class NiLocationListener(callback: (NiLocation) -> Unit) {
|
||||||
val call = callback;
|
val call = callback;
|
||||||
fun onReceiveLocation(location: NiLocation) {
|
fun onReceiveLocation(location: NiLocation) {
|
||||||
call(location)
|
call(location)
|
||||||
|
@ -10,7 +10,6 @@ import androidx.core.content.res.ResourcesCompat
|
|||||||
import androidx.lifecycle.lifecycleScope
|
import androidx.lifecycle.lifecycleScope
|
||||||
import com.navinfo.collect.library.R
|
import com.navinfo.collect.library.R
|
||||||
import com.navinfo.collect.library.data.entity.QsRecordBean
|
import com.navinfo.collect.library.data.entity.QsRecordBean
|
||||||
import com.navinfo.collect.library.map.GeoPoint
|
|
||||||
import com.navinfo.collect.library.map.NIMapView
|
import com.navinfo.collect.library.map.NIMapView
|
||||||
import com.navinfo.collect.library.map.cluster.ClusterMarkerItem
|
import com.navinfo.collect.library.map.cluster.ClusterMarkerItem
|
||||||
import com.navinfo.collect.library.map.cluster.ClusterMarkerRenderer
|
import com.navinfo.collect.library.map.cluster.ClusterMarkerRenderer
|
||||||
@ -27,6 +26,7 @@ import org.oscim.android.canvas.AndroidBitmap
|
|||||||
import org.oscim.backend.CanvasAdapter
|
import org.oscim.backend.CanvasAdapter
|
||||||
import org.oscim.backend.canvas.Bitmap
|
import org.oscim.backend.canvas.Bitmap
|
||||||
import org.oscim.backend.canvas.Paint
|
import org.oscim.backend.canvas.Paint
|
||||||
|
import org.oscim.core.GeoPoint
|
||||||
import org.oscim.layers.marker.*
|
import org.oscim.layers.marker.*
|
||||||
import org.oscim.layers.marker.ItemizedLayer.OnItemGestureListener
|
import org.oscim.layers.marker.ItemizedLayer.OnItemGestureListener
|
||||||
import org.oscim.map.Map
|
import org.oscim.map.Map
|
||||||
@ -90,9 +90,10 @@ class MarkHandler(context: AppCompatActivity, mapView: NIMapView) :
|
|||||||
|
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
addLayer(mDefaultMarkerLayer, NIMapView.LAYER_GROUPS.OPERATE);
|
|
||||||
//初始化之间数据图层
|
//初始化之间数据图层
|
||||||
initQsRecordDataLayer()
|
initQsRecordDataLayer()
|
||||||
|
addLayer(mDefaultMarkerLayer, NIMapView.LAYER_GROUPS.OPERATE);
|
||||||
// 设置矢量图层均在12级以上才显示
|
// 设置矢量图层均在12级以上才显示
|
||||||
mMapView.vtmMap.events.bind(Map.UpdateListener { e, mapPosition ->
|
mMapView.vtmMap.events.bind(Map.UpdateListener { e, mapPosition ->
|
||||||
if (e == Map.SCALE_EVENT) {
|
if (e == Map.SCALE_EVENT) {
|
||||||
@ -127,13 +128,13 @@ class MarkHandler(context: AppCompatActivity, mapView: NIMapView) :
|
|||||||
val marker = MarkerItem(
|
val marker = MarkerItem(
|
||||||
tempTitle,
|
tempTitle,
|
||||||
description,
|
description,
|
||||||
org.oscim.core.GeoPoint(geoPoint.latitude, geoPoint.longitude)
|
geoPoint
|
||||||
)
|
)
|
||||||
mDefaultMarkerLayer.addItem(marker);
|
mDefaultMarkerLayer.addItem(marker);
|
||||||
mMapView.vtmMap.updateMap(true)
|
mMapView.vtmMap.updateMap(true)
|
||||||
} else {
|
} else {
|
||||||
marker.description = description
|
marker.description = description
|
||||||
marker.geoPoint = org.oscim.core.GeoPoint(geoPoint.latitude, geoPoint.longitude)
|
marker.geoPoint = geoPoint
|
||||||
mDefaultMarkerLayer.removeItem(marker)
|
mDefaultMarkerLayer.removeItem(marker)
|
||||||
mDefaultMarkerLayer.addItem(marker)
|
mDefaultMarkerLayer.addItem(marker)
|
||||||
mMapView.vtmMap.updateMap(true)
|
mMapView.vtmMap.updateMap(true)
|
||||||
|
@ -1,19 +1,17 @@
|
|||||||
package com.navinfo.collect.library.map.maphandler
|
package com.navinfo.collect.library.map.handler
|
||||||
|
|
||||||
import android.content.Context
|
|
||||||
import android.graphics.BitmapFactory
|
import android.graphics.BitmapFactory
|
||||||
import android.graphics.Canvas
|
import android.graphics.Canvas
|
||||||
import android.graphics.Color
|
import android.graphics.Color
|
||||||
|
import android.os.Build
|
||||||
import android.text.TextPaint
|
import android.text.TextPaint
|
||||||
import android.widget.Toast
|
import androidx.annotation.RequiresApi
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
import com.navinfo.collect.library.R
|
import com.navinfo.collect.library.R
|
||||||
import com.navinfo.collect.library.map.NIMapView
|
import com.navinfo.collect.library.map.NIMapView
|
||||||
import com.navinfo.collect.library.map.handler.BaseHandler
|
|
||||||
import com.navinfo.collect.library.map.layers.NIPolygonLayer
|
import com.navinfo.collect.library.map.layers.NIPolygonLayer
|
||||||
import com.navinfo.collect.library.utils.DistanceUtil
|
import com.navinfo.collect.library.utils.DistanceUtil
|
||||||
import com.navinfo.collect.library.utils.GeometryTools
|
import com.navinfo.collect.library.utils.GeometryTools
|
||||||
import com.navinfo.collect.library.utils.StringUtil.Companion.createUUID
|
|
||||||
import org.oscim.android.canvas.AndroidBitmap
|
import org.oscim.android.canvas.AndroidBitmap
|
||||||
import org.oscim.backend.CanvasAdapter
|
import org.oscim.backend.CanvasAdapter
|
||||||
import org.oscim.backend.canvas.Bitmap
|
import org.oscim.backend.canvas.Bitmap
|
||||||
@ -30,6 +28,7 @@ import org.oscim.layers.vector.geometries.Style
|
|||||||
import org.oscim.map.Map
|
import org.oscim.map.Map
|
||||||
import java.math.BigDecimal
|
import java.math.BigDecimal
|
||||||
|
|
||||||
|
@RequiresApi(Build.VERSION_CODES.M)
|
||||||
open class MeasureLayerHandler(context: AppCompatActivity, mapView: NIMapView) :
|
open class MeasureLayerHandler(context: AppCompatActivity, mapView: NIMapView) :
|
||||||
BaseHandler(context, mapView), Map.UpdateListener {
|
BaseHandler(context, mapView), Map.UpdateListener {
|
||||||
|
|
||||||
|
@ -418,7 +418,7 @@ public class GeometryTools {
|
|||||||
Geometry startGeo = createGeometry(startGeoPoint);
|
Geometry startGeo = createGeometry(startGeoPoint);
|
||||||
Geometry endGeo = createGeometry(endGeoPoint);
|
Geometry endGeo = createGeometry(endGeoPoint);
|
||||||
double d = startGeo.distance(endGeo);
|
double d = startGeo.distance(endGeo);
|
||||||
return d * 100000;
|
return convertDistanceToDegree(d,startGeoPoint.getLatitude());
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user