增加高亮图层

This commit is contained in:
squallzhjch
2023-04-27 15:01:57 +08:00
parent 977b4b54da
commit b028975221
8 changed files with 201 additions and 119 deletions

View File

@@ -59,7 +59,7 @@ class EvaluationResultFragment : BaseFragment(), View.OnClickListener {
if (arguments != null) {
val id = requireArguments().getString("QsId")
if (id != null) {
viewModel.loadData(id)
viewModel.initData(id)
} else {
viewModel.initNewData()
}

View File

@@ -1,10 +1,14 @@
package com.navinfo.omqs.ui.fragment.evaluationresult
import android.os.Build
import android.util.Log
import androidx.annotation.RequiresApi
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.navinfo.collect.library.data.entity.QsRecordBean
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.utils.GeometryTools
import com.navinfo.omqs.db.RealmOperateHelper
@@ -14,10 +18,10 @@ import io.realm.Realm
import io.realm.kotlin.where
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import org.locationtech.jts.geom.Point
import java.util.*
import javax.inject.Inject
@RequiresApi(Build.VERSION_CODES.N)
@HiltViewModel
class EvaluationResultViewModel @Inject constructor(
private val roomAppDatabase: RoomAppDatabase,
@@ -60,15 +64,7 @@ class EvaluationResultViewModel @Inject constructor(
liveDataQsRecordBean.value!!.geometry = it.toGeometry()
addMarker(it, markerTitle)
viewModelScope.launch {
val linkList = realmOperateHelper.queryLink(
point = GeometryTools.createPoint(
it.longitude,
it.latitude
), sort = true
)
if (linkList.isNotEmpty()) {
liveDataQsRecordBean.value!!.linkId = linkList[0].id
}
captureLink(it.longitude, it.latitude)
}
}
}
@@ -80,6 +76,7 @@ class EvaluationResultViewModel @Inject constructor(
Log.e("jingo", "EvaluationResultViewModel 销毁了 ${hashCode()}")
mapController.markerHandle.removeMarker(markerTitle)
mapController.markerHandle.removeOnMapClickListener()
mapController.lineHandler.removeLine()
}
@@ -96,15 +93,29 @@ class EvaluationResultViewModel @Inject constructor(
liveDataQsRecordBean.value!!.geometry = it.toGeometry()
mapController.markerHandle.addMarker(geoPoint, markerTitle)
viewModelScope.launch {
val linkList = realmOperateHelper.queryLink(
GeometryTools.createPoint(
geoPoint.longitude,
geoPoint.latitude
)
)
if (linkList.isNotEmpty()) {
liveDataQsRecordBean.value!!.linkId = linkList[0].id
}
captureLink(geoPoint.longitude, geoPoint.latitude)
}
}
}
/**
* 捕捉到路
*/
private suspend fun captureLink(longitude: Double, latitude: Double) {
val linkList = realmOperateHelper.queryLink(
point = GeometryTools.createPoint(
longitude,
latitude
),
)
liveDataQsRecordBean.value?.let {
if (linkList.isNotEmpty()) {
it.linkId =
linkList[0].properties[LinkTable.linkPid] ?: ""
mapController.lineHandler.showLine(linkList[0].geometry)
} else {
it.linkId = ""
mapController.lineHandler.removeLine()
}
}
}
@@ -263,14 +274,28 @@ class EvaluationResultViewModel @Inject constructor(
/**
* 根据数据id查询数据
*/
fun loadData(id: String) {
fun initData(id: String) {
viewModelScope.launch(Dispatchers.IO) {
val realm = Realm.getDefaultInstance()
val objects = realm.where<QsRecordBean>().equalTo("id", id).findFirst()
if (objects != null) {
oldBean = realm.copyFromRealm(objects)
liveDataQsRecordBean.postValue(oldBean!!.copy())
oldBean?.let {
liveDataQsRecordBean.postValue(it.copy())
val p = GeometryTools.createGeoPoint(it.geometry)
mapController.markerHandle.addMarker(
GeoPoint(p.longitude, p.latitude),
markerTitle
)
if (it.linkId.isNotEmpty()) {
val link = realmOperateHelper.queryLink(it.linkId)
link?.let { l ->
mapController.lineHandler.showLine(l.geometry)
}
}
}
}
}
}