Conflicts:
	app/src/main/java/com/navinfo/omqs/ui/activity/map/MainActivity.kt
	app/src/main/java/com/navinfo/omqs/ui/activity/map/MainViewModel.kt
	collect-library/src/main/java/com/navinfo/collect/library/map/handler/MarkHandler.kt
This commit is contained in:
qiji4215 2023-07-18 15:54:06 +08:00
commit 44d1473a4a
15 changed files with 337 additions and 191 deletions

View File

@ -210,7 +210,7 @@ class MainActivity : BaseActivity() {
} }
} }
//捕捉列表变化回调 //捕捉列表变化回调
viewModel.liveDataNoteIdList.observe(this) { viewModel.liveDataNoteId.observe(this) {
//跳转到质检数据页面 //跳转到质检数据页面
//获取右侧fragment容器 //获取右侧fragment容器
val naviController = findNavController(R.id.main_activity_right_fragment) val naviController = findNavController(R.id.main_activity_right_fragment)
@ -218,14 +218,21 @@ class MainActivity : BaseActivity() {
naviController.currentDestination?.let { navDestination -> naviController.currentDestination?.let { navDestination ->
when (navDestination.id) { when (navDestination.id) {
R.id.RightEmptyFragment -> { R.id.RightEmptyFragment -> {
if (it.size == 1) {
val bundle = Bundle() val bundle = Bundle()
bundle.putString("NoteId", it[0]) bundle.putString("NoteId", it)
naviController.navigate(R.id.NoteFragment, bundle) naviController.navigate(R.id.NoteFragment, bundle)
} }
} }
} }
} }
viewModel.liveDataTaskLink.observe(this) {
val bundle = Bundle()
bundle.putString("TaskLinkId", it)
findNavController(R.id.main_activity_right_fragment).navigate(
R.id.TaskLinkFragment,
bundle
)
} }
//捕捉列表变化回调 //捕捉列表变化回调

View File

@ -23,13 +23,10 @@ import androidx.lifecycle.viewModelScope
import androidx.navigation.findNavController import androidx.navigation.findNavController
import com.blankj.utilcode.util.ToastUtils import com.blankj.utilcode.util.ToastUtils
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.*
import com.navinfo.collect.library.data.entity.NoteBean
import com.navinfo.collect.library.data.entity.QsRecordBean
import com.navinfo.collect.library.data.entity.RenderEntity
import com.navinfo.collect.library.data.entity.TaskBean
import com.navinfo.collect.library.map.NIMapController import com.navinfo.collect.library.map.NIMapController
import com.navinfo.collect.library.map.handler.OnQsRecordItemClickListener import com.navinfo.collect.library.map.handler.OnQsRecordItemClickListener
import com.navinfo.collect.library.map.handler.OnTaskLinkItemClickListener
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
@ -76,7 +73,6 @@ class MainViewModel @Inject constructor(
private val mapController: NIMapController, private val mapController: NIMapController,
private val traceDataBase: TraceDataBase, private val traceDataBase: TraceDataBase,
private val realmOperateHelper: RealmOperateHelper, private val realmOperateHelper: RealmOperateHelper,
private val networkService: NetworkService,
private val sharedPreferences: SharedPreferences private val sharedPreferences: SharedPreferences
) : ViewModel() { ) : ViewModel() {
@ -86,7 +82,7 @@ class MainViewModel @Inject constructor(
val liveDataQsRecordIdList = MutableLiveData<List<String>>() val liveDataQsRecordIdList = MutableLiveData<List<String>>()
//地图点击捕捉到的标签ID列表 //地图点击捕捉到的标签ID列表
val liveDataNoteIdList = MutableLiveData<List<String>>() val liveDataNoteId = MutableLiveData<String>()
//地图点击捕捉到的轨迹列表 //地图点击捕捉到的轨迹列表
val liveDataNILocationList = MutableLiveData<NiLocation>() val liveDataNILocationList = MutableLiveData<NiLocation>()
@ -100,6 +96,9 @@ class MainViewModel @Inject constructor(
//道路名 //道路名
val liveDataRoadName = MutableLiveData<RenderEntity?>() val liveDataRoadName = MutableLiveData<RenderEntity?>()
//捕捉到新增的link
val liveDataTaskLink = MutableLiveData<String>()
/** /**
* 当前选中的要展示的详细信息的要素 * 当前选中的要展示的详细信息的要素
*/ */
@ -174,13 +173,12 @@ class MainViewModel @Inject constructor(
liveDataQsRecordIdList.value = list liveDataQsRecordIdList.value = list
} }
override fun onNoteList(list: MutableList<String>) { override fun onNote(id: String) {
liveDataNoteIdList.value = list liveDataNoteId.value = id
} }
override fun onNiLocation(index: Int, item: NiLocation) { override fun onNiLocation(index: Int, item: NiLocation) {
liveDataNILocationList.value = item liveDataNILocationList.value = item
currentIndexNiLocation = index
} }
}) })
@ -191,11 +189,11 @@ class MainViewModel @Inject constructor(
mapController.onMapClickFlow.collectLatest { mapController.onMapClickFlow.collectLatest {
// testPoint = it // testPoint = it
//线选择状态 //线选择状态
/* if (bSelectRoad) { if (bSelectRoad) {
captureLink(it) captureLink(it)
} else { } else {
captureItem(it) captureItem(it)
}*/ }
} }
} }
viewModelScope.launch(Dispatchers.IO) { viewModelScope.launch(Dispatchers.IO) {
@ -257,11 +255,12 @@ class MainViewModel @Inject constructor(
//加载轨迹数据 //加载轨迹数据
val id = sharedPreferences.getInt(Constant.SELECT_TASK_ID, -1) val id = sharedPreferences.getInt(Constant.SELECT_TASK_ID, -1)
val list: List<NiLocation>? = TraceDataBase.getDatabase( val list: List<NiLocation>? = TraceDataBase.getDatabase(
mapController.mMapView.context, mapController.mMapView.context, Constant.USER_DATA_PATH
Constant.USER_DATA_PATH
).niLocationDao.findToTaskIdAll(id.toString()) ).niLocationDao.findToTaskIdAll(id.toString())
list!!.forEach { if (list != null) {
mapController.markerHandle.addNiLocationMarkerItem(it) for (location in list) {
mapController.markerHandle.addNiLocationMarkerItem(location)
}
} }
} }
@ -272,6 +271,19 @@ class MainViewModel @Inject constructor(
private fun initLocation() { private fun initLocation() {
//用于定位点存储到数据库 //用于定位点存储到数据库
viewModelScope.launch(Dispatchers.Default) { viewModelScope.launch(Dispatchers.Default) {
//用于定位点捕捉道路
mapController.locationLayerHandler.niLocationFlow.collectLatest { location ->
if (!isSelectRoad() && !GeometryTools.isCheckError(
location.longitude, location.latitude
)
) {
captureLink(
GeoPoint(
location.latitude, location.longitude
)
)
}
}
mapController.locationLayerHandler.niLocationFlow.collect { location -> mapController.locationLayerHandler.niLocationFlow.collect { location ->
//过滤掉无效点 //过滤掉无效点
@ -512,12 +524,10 @@ class MainViewModel @Inject constructor(
try { try {
if (!mCameraDialog!!.getmShareUtil().connectstate) { if (!mCameraDialog!!.getmShareUtil().connectstate) {
mCameraDialog!!.updateCameraResources( mCameraDialog!!.updateCameraResources(
1, 1, mCameraDialog!!.getmDeviceNum()
mCameraDialog!!.getmDeviceNum()
) )
} }
TakePhotoManager.getInstance() TakePhotoManager.getInstance().getCameraVedioClent(mCameraDialog!!.getmDeviceNum())
.getCameraVedioClent(mCameraDialog!!.getmDeviceNum())
.StopSearch() .StopSearch()
} catch (e: Exception) { } catch (e: Exception) {
} }

View File

@ -39,6 +39,7 @@ import dagger.hilt.android.lifecycle.HiltViewModel
import io.realm.Realm import io.realm.Realm
import io.realm.RealmList import io.realm.RealmList
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import org.oscim.core.GeoPoint import org.oscim.core.GeoPoint
import java.io.File import java.io.File
@ -109,7 +110,7 @@ class EvaluationResultViewModel @Inject constructor(
init { init {
liveDataQsRecordBean.value = QsRecordBean(id = UUID.randomUUID().toString()) liveDataQsRecordBean.value = QsRecordBean(id = UUID.randomUUID().toString())
viewModelScope.launch { viewModelScope.launch {
mapController.onMapClickFlow.collect { mapController.onMapClickFlow.collectLatest {
liveDataQsRecordBean.value!!.geometry = GeometryTools.createGeometry(it).toText() liveDataQsRecordBean.value!!.geometry = GeometryTools.createGeometry(it).toText()
mapController.markerHandle.addMarker(it, markerTitle) mapController.markerHandle.addMarker(it, markerTitle)
viewModelScope.launch { viewModelScope.launch {

View File

@ -36,6 +36,13 @@ class TaskLinkFragment : BaseFragment(), View.OnClickListener {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
arguments?.let {
val id = it.getString("TaskLinkId")
if (id != null && id.isNotEmpty()){
viewModel.initData(id)
}
}
binding.taskLinkAddPoint.setOnClickListener(this) binding.taskLinkAddPoint.setOnClickListener(this)
binding.taskLinkKind.setOnClickListener(this) binding.taskLinkKind.setOnClickListener(this)
binding.taskLinkFunctionalLevel.setOnClickListener(this) binding.taskLinkFunctionalLevel.setOnClickListener(this)
@ -44,6 +51,8 @@ class TaskLinkFragment : BaseFragment(), View.OnClickListener {
binding.taskLinkBarSave.setOnClickListener(this) binding.taskLinkBarSave.setOnClickListener(this)
binding.taskLinkBack.setOnClickListener(this) binding.taskLinkBack.setOnClickListener(this)
binding.taskLinkClear.setOnClickListener(this) binding.taskLinkClear.setOnClickListener(this)
binding.taskLinkBarDelete.setOnClickListener(this)
/** /**
* 数据操作结束 * 数据操作结束
*/ */
@ -150,6 +159,9 @@ class TaskLinkFragment : BaseFragment(), View.OnClickListener {
binding.taskLinkClear -> { binding.taskLinkClear -> {
viewModel.clearLink() viewModel.clearLink()
} }
binding.taskLinkBarDelete ->{
viewModel.deleteData(requireContext())
}
} }
} }

View File

@ -1,5 +1,7 @@
package com.navinfo.omqs.ui.fragment.tasklink package com.navinfo.omqs.ui.fragment.tasklink
import android.app.Dialog
import android.content.Context
import android.content.SharedPreferences import android.content.SharedPreferences
import android.os.Build import android.os.Build
import androidx.annotation.RequiresApi import androidx.annotation.RequiresApi
@ -8,15 +10,18 @@ import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope import androidx.lifecycle.viewModelScope
import com.navinfo.collect.library.data.entity.HadLinkDvoBean import com.navinfo.collect.library.data.entity.HadLinkDvoBean
import com.navinfo.collect.library.data.entity.LinkInfoBean import com.navinfo.collect.library.data.entity.LinkInfoBean
import com.navinfo.collect.library.data.entity.QsRecordBean
import com.navinfo.collect.library.data.entity.TaskBean import com.navinfo.collect.library.data.entity.TaskBean
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.Constant import com.navinfo.omqs.Constant
import com.navinfo.omqs.ui.dialog.FirstDialog
import dagger.hilt.android.lifecycle.HiltViewModel import dagger.hilt.android.lifecycle.HiltViewModel
import io.realm.Realm import io.realm.Realm
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.collectLatest import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import org.bson.codecs.UuidCodec import org.bson.codecs.UuidCodec
import org.bson.internal.UuidHelper import org.bson.internal.UuidHelper
import org.oscim.core.GeoPoint import org.oscim.core.GeoPoint
@ -102,6 +107,11 @@ class TaskLinkViewModel @Inject constructor(
*/ */
val liveDataTaskBean = MutableLiveData<TaskBean?>() val liveDataTaskBean = MutableLiveData<TaskBean?>()
/**
* 当前正在编辑的线
*/
private var hadLinkDvoBean: HadLinkDvoBean? = null
/** /**
* 当前正在选择哪个数据 1种别 2功能等级 3数据等级 * 当前正在选择哪个数据 1种别 2功能等级 3数据等级
*/ */
@ -184,8 +194,28 @@ class TaskLinkViewModel @Inject constructor(
liveDataToastMessage.postValue("请选择数据等级!") liveDataToastMessage.postValue("请选择数据等级!")
return@launch return@launch
} }
val linkBean = HadLinkDvoBean( val task: TaskBean = liveDataTaskBean.value!!
// taskId = liveDataTaskBean.value!!.id, if (hadLinkDvoBean != null) {
hadLinkDvoBean!!.taskId = liveDataTaskBean.value!!.id
hadLinkDvoBean!!.length =
mapController.measureLayerHandler.lineLengthLiveData.value!!
hadLinkDvoBean!!.geometry =
GeometryTools.getLineString(mapController.measureLayerHandler.mPathLayer.points)
hadLinkDvoBean!!.linkInfo = LinkInfoBean(
kind = liveDataSelectKind.value!!.type,
functionLevel = liveDataSelectFunctionLevel.value!!.type,
dataLevel = liveDataSelectDataLevel.value!!.type,
)
for (l in task.hadLinkDvoList) {
if (l.linkPid == hadLinkDvoBean!!.linkPid) {
task.hadLinkDvoList.remove(l)
task.hadLinkDvoList.add(hadLinkDvoBean)
break
}
}
} else {
hadLinkDvoBean = HadLinkDvoBean(
taskId = liveDataTaskBean.value!!.id,
linkPid = UUID.randomUUID().toString(), linkPid = UUID.randomUUID().toString(),
linkStatus = 3, linkStatus = 3,
length = mapController.measureLayerHandler.lineLengthLiveData.value!!, length = mapController.measureLayerHandler.lineLengthLiveData.value!!,
@ -196,14 +226,18 @@ class TaskLinkViewModel @Inject constructor(
dataLevel = liveDataSelectDataLevel.value!!.type, dataLevel = liveDataSelectDataLevel.value!!.type,
) )
) )
val task: TaskBean = liveDataTaskBean.value!! task.hadLinkDvoList.add(hadLinkDvoBean)
task.hadLinkDvoList.add(linkBean) }
val realm = Realm.getDefaultInstance() val realm = Realm.getDefaultInstance()
realm.executeTransaction { realm.executeTransaction {
it.copyToRealmOrUpdate(hadLinkDvoBean)
it.copyToRealmOrUpdate(task) it.copyToRealmOrUpdate(task)
} }
mapController.lineHandler.addTaskLink(linkBean) mapController.lineHandler.addTaskLink(hadLinkDvoBean!!)
sharedPreferences.edit().putString(Constant.SHARED_SYNC_TASK_LINK_ID, linkBean.linkPid) sharedPreferences.edit()
.putString(Constant.SHARED_SYNC_TASK_LINK_ID, hadLinkDvoBean!!.linkPid)
.apply() .apply()
liveDataFinish.postValue(true) liveDataFinish.postValue(true)
} }
@ -231,4 +265,87 @@ class TaskLinkViewModel @Inject constructor(
fun clearLink() { fun clearLink() {
mapController.measureLayerHandler.clear() mapController.measureLayerHandler.clear()
} }
/**
* 初始化数据
*/
fun initData(id: String) {
viewModelScope.launch(Dispatchers.IO) {
val realm = Realm.getDefaultInstance()
val objects =
realm.where(HadLinkDvoBean::class.java).equalTo("linkPid", id)
.findFirst()
objects?.linkInfo?.let {
for (kind in kindList) {
if (kind.type == it.kind) {
liveDataSelectKind.postValue(kind)
break
}
}
for (function in functionLevelList) {
if (function.type == it.functionLevel) {
liveDataSelectFunctionLevel.postValue(function)
break
}
}
for (data in dataLevelList) {
if (data.type == it.dataLevel) {
liveDataSelectDataLevel.postValue(data)
break
}
}
}
val task =
realm.where(TaskBean::class.java).equalTo("id", objects?.taskId)
.findFirst()
if (task != null) {
liveDataTaskBean.postValue(realm.copyFromRealm(task))
}
hadLinkDvoBean = realm.copyFromRealm(objects)
withContext(Dispatchers.Main) {
mapController.measureLayerHandler.initPathLine(hadLinkDvoBean?.geometry!!)
}
}
}
/**
* 删除数据
*/
fun deleteData(context: Context) {
if(hadLinkDvoBean == null){
liveDataFinish.value = true
return
}
val mDialog = FirstDialog(context)
mDialog.setTitle("提示?")
mDialog.setMessage("是否删除Mark请确认")
mDialog.setPositiveButton("确定"
) { _, _ ->
mDialog.dismiss()
viewModelScope.launch(Dispatchers.IO) {
val realm = Realm.getDefaultInstance()
realm.executeTransaction {
val task = it.where(TaskBean::class.java).equalTo("id",hadLinkDvoBean!!.taskId).findFirst()
if(task != null) {
for (h in task.hadLinkDvoList) {
if(h.linkPid == hadLinkDvoBean!!.linkPid)
task.hadLinkDvoList.remove(h)
break
}
realm.copyToRealmOrUpdate(task)
}
// val objects = it.where(HadLinkDvoBean::class.java)
// .equalTo("linkPid", hadLinkDvoBean!!.linkPid).findFirst()
// objects?.deleteFromRealm()
}
mapController.lineHandler.removeTaskLink(hadLinkDvoBean!!.linkPid)
mapController.mMapView.vtmMap.updateMap(true)
liveDataFinish.postValue(true)
}
}
mDialog.setNegativeButton("取消", null)
mDialog.show()
}
} }

View File

@ -1690,7 +1690,7 @@
<m k="speedFlag" v="1"> <m k="speedFlag" v="1">
<caption fill="#000000" k="maxSpeed" priority="0" size="12" stroke="#ffffff" <caption fill="#000000" k="maxSpeed" priority="0" size="12" stroke="#ffffff"
stroke-width="1.0"></caption> stroke-width="1.0"></caption>
<symbol src="assets:omdb/icon_4004_1.png" symbol-height="46" <symbol src="assets:omdb/icon_4004_0.svg" symbol-height="46"
symbol-width="46"></symbol> symbol-width="46"></symbol>
<!-- <caption k="minSpeed" dy="-28" fill="#000000" priority="0" size="14" stroke="#ffffff"--> <!-- <caption k="minSpeed" dy="-28" fill="#000000" priority="0" size="14" stroke="#ffffff"-->
<!-- stroke-width="1.0"></caption>--> <!-- stroke-width="1.0"></caption>-->

View File

@ -1,12 +1,13 @@
package com.navinfo.collect.library.data.entity package com.navinfo.collect.library.data.entity
import io.realm.RealmObject import io.realm.RealmObject
import io.realm.annotations.PrimaryKey
open class HadLinkDvoBean @JvmOverloads constructor( open class HadLinkDvoBean @JvmOverloads constructor(
// /** /**
// * 任务id方便捕捉查询 * 任务id方便捕捉查询
// */ */
// var taskId: Int = 0, var taskId: Int = 0,
/** /**
* 图幅号 * 图幅号
*/ */
@ -14,6 +15,7 @@ open class HadLinkDvoBean @JvmOverloads constructor(
/** /**
* linkPid * linkPid
*/ */
@PrimaryKey
var linkPid: String = "", var linkPid: String = "",
/** /**
* (几何)加偏后 * (几何)加偏后

View File

@ -1,6 +1,5 @@
package com.navinfo.collect.library.map package com.navinfo.collect.library.map
import android.os.Build
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import androidx.lifecycle.lifecycleScope import androidx.lifecycle.lifecycleScope
import com.navinfo.collect.library.map.handler.* import com.navinfo.collect.library.map.handler.*

View File

@ -1,6 +1,6 @@
package com.navinfo.collect.library.map.handler package com.navinfo.collect.library.map.handler
import android.content.Context import android.util.Log
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import com.navinfo.collect.library.map.NIMapView import com.navinfo.collect.library.map.NIMapView
import org.oscim.layers.Layer import org.oscim.layers.Layer
@ -10,6 +10,7 @@ abstract class BaseHandler(context: AppCompatActivity, mapView: NIMapView) {
protected val mMapView: NIMapView = mapView protected val mMapView: NIMapView = mapView
fun addLayer(layer: Layer, groupType: NIMapView.LAYER_GROUPS) { fun addLayer(layer: Layer, groupType: NIMapView.LAYER_GROUPS) {
Log.e("jingo", "增加了图层 ${layer.toString()}")
mMapView.vtmMap.layers().add( mMapView.vtmMap.layers().add(
layer, layer,
groupType.groupIndex groupType.groupIndex
@ -17,11 +18,11 @@ abstract class BaseHandler(context: AppCompatActivity, mapView: NIMapView) {
} }
fun removeLayer(layer: Layer) { fun removeLayer(layer: Layer) {
Log.e("jingo", "移除了图层 ${layer.toString()}")
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)
// } // }

View File

@ -36,6 +36,7 @@ class LineHandler(context: AppCompatActivity, mapView: NIMapView) : BaseHandler(
onTaskLinkItemClickListener = listener onTaskLinkItemClickListener = listener
} }
/** /**
* 路口高亮 * 路口高亮
*/ */
@ -183,6 +184,12 @@ class LineHandler(context: AppCompatActivity, mapView: NIMapView) : BaseHandler(
* 增加一条任务高亮线 * 增加一条任务高亮线
*/ */
fun addTaskLink(linkBean: HadLinkDvoBean) { fun addTaskLink(linkBean: HadLinkDvoBean) {
for (marker in omdbTaskMarkerLayer.itemList) {
if ((marker as MarkerItem).title == linkBean.linkPid) {
omdbTaskMarkerLayer.removeItem(marker)
break
}
}
if (linkBean.linkStatus == 3) { if (linkBean.linkStatus == 3) {
val pointList = GeometryTools.getGeoPoints(linkBean.geometry) val pointList = GeometryTools.getGeoPoints(linkBean.geometry)
val geoPoint = if (pointList.size < 3) { val geoPoint = if (pointList.size < 3) {
@ -197,7 +204,10 @@ class LineHandler(context: AppCompatActivity, mapView: NIMapView) : BaseHandler(
) )
omdbTaskMarkerLayer.addItem(marker) omdbTaskMarkerLayer.addItem(marker)
} }
omdbTaskLinkLayer.removeLine(linkBean.linkPid)
omdbTaskLinkLayer.addLine(linkBean) omdbTaskLinkLayer.addLine(linkBean)
omdbTaskLinkLayer.update()
mMapView.vtmMap.updateMap(true)
} }
/** /**
@ -211,6 +221,8 @@ class LineHandler(context: AppCompatActivity, mapView: NIMapView) : BaseHandler(
} }
} }
omdbTaskLinkLayer.removeLine(linkBeanId) omdbTaskLinkLayer.removeLine(linkBeanId)
omdbTaskLinkLayer.update()
mMapView.vtmMap.updateMap(true)
} }
} }

View File

@ -12,6 +12,7 @@ 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.NIMapView import com.navinfo.collect.library.map.NIMapView
import com.navinfo.collect.library.utils.DateUtils import com.navinfo.collect.library.utils.DateUtils
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.MutableSharedFlow import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import org.oscim.core.GeoPoint import org.oscim.core.GeoPoint
@ -29,7 +30,7 @@ class LocationLayerHandler(context: AppCompatActivity, mapView: NIMapView) :
// //
// } // }
val niLocationFlow = MutableSharedFlow<NiLocation>(5) val niLocationFlow = MutableSharedFlow<NiLocation>(3)
init { init {
///添加定位图层到地图,[NIMapView.LAYER_GROUPS.NAVIGATION] 是最上层layer组 ///添加定位图层到地图,[NIMapView.LAYER_GROUPS.NAVIGATION] 是最上层layer组
@ -73,7 +74,7 @@ class LocationLayerHandler(context: AppCompatActivity, mapView: NIMapView) :
// if (niLocationListener != null) { // if (niLocationListener != null) {
getCurrentNiLocation()?.let { it1 -> getCurrentNiLocation()?.let { it1 ->
mContext.lifecycleScope.launch { mContext.lifecycleScope.launch(Dispatchers.Default) {
niLocationFlow.emit(it1) niLocationFlow.emit(it1)
} }

View File

@ -4,6 +4,7 @@ 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.util.Log
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.res.ResourcesCompat import androidx.core.content.res.ResourcesCompat
import com.navinfo.collect.library.R import com.navinfo.collect.library.R
@ -25,19 +26,11 @@ 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.core.GeoPoint
import org.oscim.layers.marker.ItemizedLayer import org.oscim.layers.marker.*
import org.oscim.layers.marker.ItemizedLayer.OnItemGestureListener import org.oscim.layers.marker.ItemizedLayer.OnItemGestureListener
import org.oscim.layers.marker.MarkerInterface import org.oscim.layers.vector.geometries.*
import org.oscim.layers.marker.MarkerItem
import org.oscim.layers.marker.MarkerRendererFactory
import org.oscim.layers.marker.MarkerSymbol
import org.oscim.layers.vector.geometries.Drawable
import org.oscim.layers.vector.geometries.LineDrawable
import org.oscim.layers.vector.geometries.PointDrawable
import org.oscim.layers.vector.geometries.PolygonDrawable
import org.oscim.layers.vector.geometries.Style
import org.oscim.map.Map import org.oscim.map.Map
import java.util.Locale import java.util.*
/** /**
* marker 操作 * marker 操作
@ -65,9 +58,7 @@ class MarkHandler(context: AppCompatActivity, mapView: NIMapView) :
/** /**
* 画布 * 画布
*/ */
private val canvas: org.oscim.backend.canvas.Canvas by lazy { private val canvas: org.oscim.backend.canvas.Canvas = CanvasAdapter.newCanvas()
CanvasAdapter.newCanvas()
}
/** /**
* 默认marker图层 * 默认marker图层
@ -79,36 +70,72 @@ class MarkHandler(context: AppCompatActivity, mapView: NIMapView) :
val markerSymbol = MarkerSymbol( val markerSymbol = MarkerSymbol(
mDefaultBitmap, mDefaultBitmap,
MarkerSymbol.HotspotPlace.BOTTOM_CENTER MarkerSymbol.HotspotPlace.CENTER
) )
val layer = ItemizedLayer( val layer = ItemizedLayer(
mapView.vtmMap, mapView.vtmMap,
ArrayList(),
markerSymbol, markerSymbol,
object : OnItemGestureListener<MarkerInterface> {
override fun onItemSingleTapUp(index: Int, item: MarkerInterface?): Boolean {
return false
}
override fun onItemLongPress(index: Int, item: MarkerInterface?): Boolean {
return false
}
}
) )
addLayer(layer, NIMapView.LAYER_GROUPS.OPERATE_MARKER) addLayer(layer, NIMapView.LAYER_GROUPS.OPERATE_MARKER)
layer layer
} }
private var niLocationBitmap: Bitmap? = null private val niLocationBitmap: Bitmap by lazy {
private var niLocationBitmap1: Bitmap? = null AndroidBitmap(
private var niLocationBitmap2: Bitmap? = null BitmapFactory.decodeResource(
private var niLocationBitmap3: Bitmap? = null context.resources,
R.mipmap.icon_gps
)
)
}
private val niLocationBitmap1: Bitmap by lazy {
AndroidBitmap(
BitmapFactory.decodeResource(
context.resources,
R.mipmap.icon_gps_1
)
)
}
private val niLocationBitmap2: Bitmap by lazy {
AndroidBitmap(
BitmapFactory.decodeResource(
context.resources,
R.mipmap.icon_nilocation
)
)
}
private val niLocationBitmap3: Bitmap by lazy {
AndroidBitmap(
BitmapFactory.decodeResource(
context.resources,
R.mipmap.icon_nilocation_1
)
)
}
/** /**
* 评测数据marker 图层 * 评测数据marker 图层
*/ */
private val qsRecordItemizedLayer: MyItemizedLayer by lazy { private val qsRecordItemizedLayer: MyItemizedLayer by lazy {
val bitmapPoi: Bitmap = AndroidBitmap(
BitmapFactory.decodeResource(
mContext.resources,
R.mipmap.map_icon_blue2
)
)
val symbol = MarkerSymbol(bitmapPoi, MarkerSymbol.HotspotPlace.BOTTOM_CENTER)
val markerRendererFactory = MarkerRendererFactory { markerLayer ->
object : ClusterMarkerRenderer(
mContext,
markerLayer,
symbol,
ClusterStyle(
org.oscim.backend.canvas.Color.WHITE,
org.oscim.backend.canvas.Color.BLUE
)
) {
}
}
val layer = MyItemizedLayer( val layer = MyItemizedLayer(
mMapView.vtmMap, mMapView.vtmMap,
mutableListOf(), mutableListOf(),
@ -151,27 +178,15 @@ class MarkHandler(context: AppCompatActivity, mapView: NIMapView) :
*/ */
private val niLocationItemizedLayer: ItemizedLayer by lazy { private val niLocationItemizedLayer: ItemizedLayer by lazy {
niLocationBitmap = val symbol = MarkerSymbol(niLocationBitmap, MarkerSymbol.HotspotPlace.CENTER)
AndroidBitmap(BitmapFactory.decodeResource(context.resources, R.mipmap.icon_gps))
niLocationBitmap1 =
AndroidBitmap(BitmapFactory.decodeResource(context.resources, R.mipmap.icon_gps_1))
niLocationBitmap2 =
AndroidBitmap(BitmapFactory.decodeResource(context.resources, R.mipmap.icon_nilocation))
niLocationBitmap3 = AndroidBitmap(
BitmapFactory.decodeResource(
context.resources,
R.mipmap.icon_nilocation_1
)
)
val layer = ItemizedLayer( val layer = ItemizedLayer(
mapView.vtmMap, mapView.vtmMap,
mutableListOf(), symbol,
markerRendererFactory, )
object : OnItemGestureListener<MarkerInterface> { layer.setOnItemGestureListener(object : OnItemGestureListener<MarkerInterface> {
override fun onItemSingleTapUp(index: Int, item: MarkerInterface?): Boolean { override fun onItemSingleTapUp(index: Int, item: MarkerInterface?): Boolean {
itemListener?.let { itemListener?.let {
it.onNiLocation(index,(niLocationItemizedLayer.itemList[index] as MarkerItem).uid as NiLocation) it.onNiLocation((niLocationItemizedLayer.itemList[index] as MarkerItem).uid as NiLocation)
} }
return true return true
} }
@ -198,69 +213,33 @@ class MarkHandler(context: AppCompatActivity, mapView: NIMapView) :
/** /**
* 便签图标图层 * 便签图标图层
*/ */
private val noteLayer: MyItemizedLayer by lazy { private val noteLayer: ItemizedLayer by lazy {
val bitmap =
val layer = MyItemizedLayer( AndroidBitmap(BitmapFactory.decodeResource(context.resources, noteResId))
val symbol = MarkerSymbol(bitmap, MarkerSymbol.HotspotPlace.CENTER)
val layer = ItemizedLayer(
mMapView.vtmMap, mMapView.vtmMap,
mutableListOf(), symbol,
markerRendererFactory, )
object : MyItemizedLayer.OnItemGestureListener { layer.setOnItemGestureListener(object : OnItemGestureListener<MarkerInterface> {
override fun onItemSingleTapUp( override fun onItemSingleTapUp(index: Int, item: MarkerInterface?): Boolean {
list: MutableList<Int>,
nearest: Int
): Boolean {
itemListener?.let { itemListener?.let {
val idList = mutableListOf<String>() val marker = layer.itemList[index]
if (list.size == 0) { if (marker is MarkerItem)
it.onNote(marker.title)
} else {
for (i in list) {
val markerInterface: MarkerInterface =
noteLayer.itemList[i]
if (markerInterface is MarkerItem) {
idList.add(markerInterface.title)
}
}
it.onNoteList(idList.distinct().toMutableList())
}
} }
return true return true
} }
override fun onItemLongPress( override fun onItemLongPress(index: Int, item: MarkerInterface?): Boolean {
list: MutableList<Int>?,
nearest: Int
): Boolean {
return true return true
} }
}) })
addLayer(layer, NIMapView.LAYER_GROUPS.OPERATE_MARKER) addLayer(layer, NIMapView.LAYER_GROUPS.OPERATE_MARKER)
layer layer
} }
private val markerRendererFactory: MarkerRendererFactory by lazy {
val bitmapPoi: Bitmap = AndroidBitmap(
BitmapFactory.decodeResource(
mContext.resources,
R.mipmap.map_icon_blue2
)
)
val symbol = MarkerSymbol(bitmapPoi, MarkerSymbol.HotspotPlace.BOTTOM_CENTER)
MarkerRendererFactory { markerLayer ->
object : ClusterMarkerRenderer(
mContext,
markerLayer,
symbol,
ClusterStyle(
org.oscim.backend.canvas.Color.WHITE,
org.oscim.backend.canvas.Color.BLUE
)
) {
}
}
}
private val resId = R.mipmap.map_icon_report private val resId = R.mipmap.map_icon_report
private val noteResId = R.drawable.icon_note_marker private val noteResId = R.drawable.icon_note_marker
private var itemListener: OnQsRecordItemClickListener? = null private var itemListener: OnQsRecordItemClickListener? = null
@ -437,26 +416,6 @@ class MarkHandler(context: AppCompatActivity, mapView: NIMapView) :
} }
// /**
// * 初始话质检数据图层
// */
// private fun initQsRecordDataLayer() {
//
// mContext.lifecycleScope.launch(Dispatchers.IO) {
// var list = mutableListOf<QsRecordBean>()
// val realm = Realm.getDefaultInstance()
// realm.executeTransaction {
// val objects = realm.where<QsRecordBean>().findAll()
// list = realm.copyFromRealm(objects)
// }
// for (item in list) {
// createMarkerItem(item)
// }
// }
//
// }
/** /**
* 添加质检数据marker * 添加质检数据marker
*/ */
@ -523,10 +482,12 @@ class MarkHandler(context: AppCompatActivity, mapView: NIMapView) :
* 添加质检数据marker * 添加质检数据marker
*/ */
fun addNiLocationMarkerItem(niLocation: NiLocation) { fun addNiLocationMarkerItem(niLocation: NiLocation) {
synchronized(this) {
var geoMarkerItem = createNILocationBitmap(niLocation) var geoMarkerItem = createNILocationBitmap(niLocation)
niLocationItemizedLayer.addItem(geoMarkerItem) niLocationItemizedLayer.addItem(geoMarkerItem)
niLocationItemizedLayer.update() niLocationItemizedLayer.update()
} }
}
private fun createNILocationBitmap(niLocation: NiLocation): MarkerItem{ private fun createNILocationBitmap(niLocation: NiLocation): MarkerItem{
@ -810,6 +771,6 @@ class MarkHandler(context: AppCompatActivity, mapView: NIMapView) :
interface OnQsRecordItemClickListener { interface OnQsRecordItemClickListener {
fun onQsRecordList(list: MutableList<String>) fun onQsRecordList(list: MutableList<String>)
fun onNoteList(list: MutableList<String>) fun onNote(noteId: String)
fun onNiLocation(index:Int,it: NiLocation) fun onNiLocation(index:Int,it: NiLocation)
} }

View File

@ -3,11 +3,9 @@ package com.navinfo.collect.library.map.handler
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.util.Log import android.util.Log
import android.widget.Toast import android.widget.Toast
import androidx.annotation.RequiresApi
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import androidx.lifecycle.MutableLiveData import androidx.lifecycle.MutableLiveData
import com.navinfo.collect.library.R import com.navinfo.collect.library.R
@ -453,6 +451,32 @@ open class MeasureLayerHandler(context: AppCompatActivity, mapView: NIMapView) :
} }
} }
/**
* 初始化线数据 用来二次编辑
*/
fun initPathLine(geometry: String) {
bDrawLine = true
mPathLayer.isEnabled = true
mPathLayerTemp.isEnabled = true
val pointList = GeometryTools.getGeoPoints(geometry)
mPathLayer.setPoints(pointList)
for (point in pointList) {
val markerItem = MarkerItem(createUUID(), "", "", point)
markerLayer.addItem(markerItem)
mPathMakers.add(markerItem)
}
if (mPathLayer.points.size > 1) {
val distance: Double = GeometryTools.getDistance(mPathLayer.points)
val bg = BigDecimal(distance)
val f1 = bg.setScale(3, BigDecimal.ROUND_HALF_UP).toDouble()
lineLengthLiveData.value = f1
tempLineDistanceLiveData.value = "${f1}"
} else {
lineLengthLiveData.value = 0.000
}
mMapView.updateMap(true)
}
private val itemGestureListener: OnItemGestureListener<MarkerInterface> = private val itemGestureListener: OnItemGestureListener<MarkerInterface> =
object : OnItemGestureListener<MarkerInterface> { object : OnItemGestureListener<MarkerInterface> {
override fun onItemSingleTapUp(index: Int, item: MarkerInterface): Boolean { override fun onItemSingleTapUp(index: Int, item: MarkerInterface): Boolean {

View File

@ -59,12 +59,11 @@ class OmdbTaskLinkLayer(map: Map, private var style: Style) : VectorLayer(map) {
update() update()
} }
fun removeLine(linkPid: String): Boolean { fun removeLine(linkPid: String) {
if (lineMap.containsKey(linkPid)) { if (lineMap.containsKey(linkPid)) {
super.remove(lineMap[linkPid]) super.remove(lineMap[linkPid])
lineMap.remove(linkPid) lineMap.remove(linkPid)
} }
return false
} }
fun removeLine(geometry: Geometry) { fun removeLine(geometry: Geometry) {

2
vtm

@ -1 +1 @@
Subproject commit dd13e533c38b5738ab404c2737d7ccadeff01323 Subproject commit 1ee201a41f78f169873848209a3f3bdac36f185a