修改任务线刷新,数据安装刷新

This commit is contained in:
squallzhjch 2023-05-06 11:01:50 +08:00
parent 752550f376
commit d86ec46943
15 changed files with 160 additions and 84 deletions

View File

@ -129,7 +129,7 @@ class ImportOMDBHelper @AssistedInject constructor(
// 开始解压zip文件
val unZipFiles = ZipUtils.unzipFile(omdbZipFile, unZipFolder)
// 将listResult数据插入到Realm数据库中
Realm.getDefaultInstance().beginTransaction()
val realm = Realm.getDefaultInstance()
// 遍历解压后的文件,读取该数据返回
for ((index, currentConfig) in importConfig.tables.withIndex()) {
val txtFile = unZipFiles.find {

View File

@ -13,8 +13,6 @@ import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import org.locationtech.jts.geom.*
import org.locationtech.jts.operation.buffer.BufferOp
import org.locationtech.spatial4j.context.SpatialContext
import org.locationtech.spatial4j.distance.DistanceUtils
import org.oscim.core.GeoPoint
import org.oscim.core.MercatorProjection
import javax.inject.Inject
@ -33,14 +31,18 @@ class RealmOperateHelper() {
* */
@RequiresApi(Build.VERSION_CODES.N)
suspend fun queryLink(
point: Point,
point: GeoPoint,
buffer: Double = DEFAULT_BUFFER,
bufferType: BUFFER_TYPE = DEFAULT_BUFFER_TYPE,
sort: Boolean = true
): MutableList<RenderEntity> {
val result = mutableListOf<RenderEntity>()
withContext(Dispatchers.IO) {
val polygon = getPolygonFromPoint(point, buffer, bufferType)
val polygon = getPolygonFromPoint(
GeometryTools.createPoint(point.longitude, point.latitude),
buffer,
bufferType
)
// 根据polygon查询相交的tile号
val tileXSet = mutableSetOf<Int>()
tileXSet.toString()
@ -68,7 +70,14 @@ class RealmOperateHelper() {
queryResult?.let {
if (sort) {
result.addAll(sortRenderEntity(point, it))
result.addAll(
sortRenderEntity(
GeometryTools.createPoint(
point.longitude,
point.latitude
), it
)
)
} else {
result.addAll(it)
}
@ -172,6 +181,7 @@ class RealmOperateHelper() {
* @param unSortList 未排序的数据
* @return 排序后的数据
* */
@RequiresApi(Build.VERSION_CODES.N)
fun sortRenderEntity(point: Point, unSortList: List<RenderEntity>): List<RenderEntity> {
val sortList = unSortList.stream().sorted { renderEntity, renderEntity2 ->
val near = point.distance(renderEntity.wkt) - point.distance(renderEntity2.wkt)

View File

@ -46,8 +46,9 @@ class ActivityModule {
fun providesTaskListDownloadManager(
networkServiceAPI: RetrofitNetworkServiceAPI,
importFactory: ImportOMDBHiltFactory,
mapController: NIMapController
): TaskDownloadManager =
TaskDownloadManager(importFactory, networkServiceAPI)
TaskDownloadManager(importFactory, networkServiceAPI, mapController)
/**
* 注入任务下载

View File

@ -67,7 +67,7 @@ class GlobalModule {
}.apply {
level = if (Constant.DEBUG) {
//坑 下载文件时打印log 内存不足
HttpLoggingInterceptor.Level.BODY
HttpLoggingInterceptor.Level.BASIC
} else {
HttpLoggingInterceptor.Level.NONE
}

View File

@ -3,6 +3,7 @@ package com.navinfo.omqs.http.taskdownload
import android.content.Context
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.Observer
import com.navinfo.collect.library.map.NIMapController
import com.navinfo.omqs.bean.TaskBean
import com.navinfo.omqs.hilt.ImportOMDBHiltFactory
import com.navinfo.omqs.hilt.OMDBDataBaseHiltFactory
@ -19,6 +20,7 @@ import javax.inject.Inject
class TaskDownloadManager constructor(
val importFactory: ImportOMDBHiltFactory,
val netApi: RetrofitNetworkServiceAPI,
val mapController:NIMapController
) {
lateinit var context: Context

View File

@ -131,6 +131,9 @@ class TaskDownloadScope(
Log.e("jingo", "数据安装 $it")
if (it == "finish") {
change(FileDownloadStatus.DONE)
withContext(Dispatchers.Main) {
downloadManager.mapController.mMapView.updateMap(true)
}
} else {
change(FileDownloadStatus.IMPORTING, it)
}
@ -138,6 +141,8 @@ class TaskDownloadScope(
} catch (e: Exception) {
Log.e("jingo", "数据安装失败 ${e.toString()}")
change(FileDownloadStatus.ERROR)
}finally {
}
Log.e("jingo", "importData EEE")

View File

@ -115,15 +115,16 @@ class TaskUploadScope(
taskBean.hadLinkDvoList.forEach { hadLinkDvoBean ->
val objects = realm.where(QsRecordBean::class.java)
.equalTo("linkId", /*"84207223282277331"*/hadLinkDvoBean.linkPid).findAll()
if(objects.size == 0){
// change(FileUploadStatus.NONE)
if (objects.size == 0) {
if (taskBean.syncStatus == FileUploadStatus.WAITING)
change(FileUploadStatus.NONE)
return
}
val bodyList: MutableList<EvaluationInfo> = ArrayList()
if (objects != null) {
val copyList =realm.copyFromRealm(objects)
val copyList = realm.copyFromRealm(objects)
copyList.forEach {
val evaluationInfo = EvaluationInfo(
taskBean.id.toString(),

View File

@ -227,8 +227,15 @@ class MainActivity : BaseActivity() {
* 点击录音按钮
*/
fun voiceOnclick() {
/* val naviController = findNavController(R.id.main_activity_right_fragment)
naviController.navigate(R.id.EvaluationResultFragment)*/
val naviController = findNavController(R.id.main_activity_right_fragment)
naviController.navigate(R.id.EvaluationResultFragment)
}
/**
* 点击线选择
*/
fun selectLineOnclick(){
viewModel.setSelectRoad(!viewModel.isSelectRoad())
}
fun voiceOnTouchStart() {

View File

@ -37,14 +37,12 @@ import com.navinfo.omqs.ui.dialog.CommonDialog
import com.navinfo.omqs.ui.manager.TakePhotoManager
import com.navinfo.omqs.ui.widget.SignUtil
import com.navinfo.omqs.util.DateTimeUtil
import com.navinfo.omqs.util.FlowEventBus
import com.navinfo.omqs.util.SoundMeter
import com.navinfo.omqs.util.SpeakMode
import dagger.hilt.android.lifecycle.HiltViewModel
import io.realm.Realm
import io.realm.RealmSet
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.launch
import org.oscim.core.GeoPoint
@ -72,7 +70,7 @@ class MainViewModel @Inject constructor(
//看板数据
val liveDataSignList = MutableLiveData<List<SignBean>>()
var testPoint = GeoPoint(0, 0)
// var testPoint = GeoPoint(0, 0)
//语音窗体
private var pop: PopupWindow? = null
@ -83,10 +81,15 @@ class MainViewModel @Inject constructor(
var volume: ImageView? = null
var mSoundMeter: SoundMeter? = null
var menuState :Boolean = false
var menuState: Boolean = false
val liveDataMenuState = MutableLiveData<Boolean>()
/**
* 是不是线选择模式
*/
private var bSelectRoad = false
init {
mapController.markerHandle.setOnQsRecordItemClickListener(object :
OnQsRecordItemClickListener {
@ -97,7 +100,10 @@ class MainViewModel @Inject constructor(
initLocation()
viewModelScope.launch {
mapController.onMapClickFlow.collectLatest {
testPoint = it
// testPoint = it
if (bSelectRoad) {
captureLink(it)
}
}
}
@ -140,8 +146,8 @@ class MainViewModel @Inject constructor(
//用于定位点存储到数据库
viewModelScope.launch(Dispatchers.Default) {
mapController.locationLayerHandler.niLocationFlow.collect { location ->
location.longitude = testPoint.longitude
location.latitude = testPoint.latitude
// location.longitude = testPoint.longitude
// location.latitude = testPoint.latitude
val geometry = GeometryTools.createGeometry(
GeoPoint(
location.latitude,
@ -168,48 +174,10 @@ class MainViewModel @Inject constructor(
//用于定位点捕捉道路
viewModelScope.launch(Dispatchers.Default) {
mapController.locationLayerHandler.niLocationFlow.collectLatest { 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 = SignUtil.getSignIcon(element),
iconText = SignUtil.getSignIconText(element),
distance = distance.toInt(),
elementId = element.id,
linkId = linkId,
geometry = element.geometry,
bottomText = SignUtil.getSignBottomText(element)
)
)
}
liveDataSignList.postValue(signList)
Log.e("jingo", "自动捕捉数据 共${elementList.size}")
}
}
}
// location.longitude = testPoint.longitude
// location.latitude = testPoint.latitude
if (!isSelectRoad())
captureLink(GeoPoint(location.latitude, location.longitude))
}
}
@ -218,6 +186,47 @@ class MainViewModel @Inject constructor(
}
/**
* 捕获道路和面板
*/
private suspend fun captureLink(point: GeoPoint) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
val linkList = realmOperateHelper.queryLink(
point = point,
)
//看板数据
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(
point,
GeometryTools.createGeoPoint(element.geometry)
)
signList.add(
SignBean(
iconId = SignUtil.getSignIcon(element),
iconText = SignUtil.getSignIconText(element),
distance = distance.toInt(),
elementId = element.id,
linkId = linkId,
geometry = element.geometry,
bottomText = SignUtil.getSignBottomText(element)
)
)
}
}
}
liveDataSignList.postValue(signList)
Log.e("jingo", "自动捕捉数据 共${signList.size}")
}
}
/**
* 点击我的位置回到我的位置
*/
@ -360,15 +369,16 @@ class MainViewModel @Inject constructor(
* */
fun refreshOMDBLayer(layerConfigList: List<ImportConfig>) {
// 根据获取到的配置信息,筛选未勾选的图层名称
if (layerConfigList!=null && !layerConfigList.isEmpty()) {
val omdbVisibleList = layerConfigList.filter { importConfig->
if (layerConfigList != null && !layerConfigList.isEmpty()) {
val omdbVisibleList = layerConfigList.filter { importConfig ->
importConfig.tableGroupName == "OMDB数据"
}.first().tables.filter { tableInfo ->
!tableInfo.checked
}.map {
tableInfo -> tableInfo.table
}.map { tableInfo ->
tableInfo.table
}.toList()
com.navinfo.collect.library.system.Constant.HAD_LAYER_INVISIABLE_ARRAY = omdbVisibleList.toTypedArray()
com.navinfo.collect.library.system.Constant.HAD_LAYER_INVISIABLE_ARRAY =
omdbVisibleList.toTypedArray()
// 刷新地图
mapController.mMapView.vtmMap.clearMap()
}
@ -409,4 +419,16 @@ class MainViewModel @Inject constructor(
}
}
}
/**
* 开启线选择
*/
fun setSelectRoad(select: Boolean) {
bSelectRoad = select
}
fun isSelectRoad(): Boolean {
return bSelectRoad
}
}

View File

@ -25,6 +25,7 @@ class SignAdapter(private var itemListener: ((Int, SignBean) -> Unit?)? = null)
val item = data[position]
bd.signMainIcon.background = holder.viewBinding.root.context.getDrawable(item.iconId)
bd.signMainIcon.text = item.iconText
bd.signBottomText.text = item.bottomText
bd.root.setOnClickListener {
itemListener?.invoke(position, item)
}

View File

@ -4,9 +4,7 @@ import android.app.Activity
import android.content.Context
import android.graphics.drawable.AnimationDrawable
import android.graphics.drawable.BitmapDrawable
import android.net.Uri
import android.os.Build
import android.os.Bundle
import android.text.TextUtils
import android.util.Log
import android.view.Gravity
@ -15,11 +13,9 @@ import android.view.ViewGroup
import android.widget.ImageView
import android.widget.PopupWindow
import androidx.annotation.RequiresApi
import androidx.core.util.rangeTo
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import androidx.navigation.findNavController
import com.blankj.utilcode.util.ToastUtils
import com.navinfo.collect.library.data.entity.AttachmentBean
import com.navinfo.collect.library.data.entity.QsRecordBean
@ -130,7 +126,9 @@ class EvaluationResultViewModel @Inject constructor(
geoPoint?.let {
liveDataQsRecordBean.value!!.geometry = GeometryTools.createGeometry(it).toText()
mapController.markerHandle.addMarker(geoPoint, markerTitle)
mapController.animationHandler.animationByLonLat(geoPoint.latitude,geoPoint.longitude)
mapController.animationHandler.animationByLonLat(
geoPoint.latitude, geoPoint.longitude
)
viewModelScope.launch {
captureLink(geoPoint.longitude, geoPoint.latitude)
}
@ -152,7 +150,7 @@ class EvaluationResultViewModel @Inject constructor(
}
val point = GeometryTools.createGeoPoint(bean.geometry)
liveDataQsRecordBean.value!!.geometry = GeometryTools.createGeometry(point).toText()
mapController.animationHandler.animationByLonLat(point.latitude,point.longitude)
mapController.animationHandler.animationByLonLat(point.latitude, point.longitude)
mapController.markerHandle.addMarker(point, markerTitle)
}
@ -165,16 +163,12 @@ class EvaluationResultViewModel @Inject constructor(
private suspend fun captureLink(longitude: Double, latitude: Double) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
val linkList = realmOperateHelper.queryLink(
point = GeometryTools.createPoint(
longitude,
latitude
),
point = GeoPoint(latitude, longitude),
)
liveDataQsRecordBean.value?.let {
if (linkList.isNotEmpty()) {
it.linkId =
linkList[0].properties[LinkTable.linkPid] ?: ""
it.linkId = linkList[0].properties[LinkTable.linkPid] ?: ""
mapController.lineHandler.showLine(linkList[0].geometry)
Log.e("jingo", "捕捉到的linkId = ${it.linkId}")
} else {
@ -328,8 +322,9 @@ class EvaluationResultViewModel @Inject constructor(
val realm = Realm.getDefaultInstance()
Log.e("jingo", "realm hashCOde ${realm.hashCode()}")
realm.executeTransaction {
val objects = it.where(QsRecordBean::class.java)
.equalTo("id", liveDataQsRecordBean.value?.id).findFirst()
val objects =
it.where(QsRecordBean::class.java).equalTo("id", liveDataQsRecordBean.value?.id)
.findFirst()
objects?.deleteFromRealm()
}
// realm.close()
@ -354,8 +349,7 @@ class EvaluationResultViewModel @Inject constructor(
liveDataQsRecordBean.postValue(it.copy())
val p = GeometryTools.createGeoPoint(it.geometry)
mapController.markerHandle.addMarker(
GeoPoint(p.latitude, p.longitude),
markerTitle
GeoPoint(p.latitude, p.longitude), markerTitle
)
if (it.linkId.isNotEmpty()) {

View File

@ -2,6 +2,7 @@ package com.navinfo.omqs.ui.fragment.tasklist
import android.content.Context
import android.graphics.Color
import android.os.Build
import android.util.Log
import android.widget.Toast
import androidx.lifecycle.MutableLiveData
@ -23,7 +24,7 @@ import javax.inject.Inject
@HiltViewModel
class TaskListViewModel @Inject constructor(
private val networkService: NetworkService,
private val niMapController: NIMapController
private val mapController: NIMapController
) : ViewModel() {
val liveDataTaskList = MutableLiveData<List<TaskBean>>()
@ -66,6 +67,7 @@ class TaskListViewModel @Inject constructor(
}
val objects = realm.where(TaskBean::class.java).findAll()
taskList = realm.copyFromRealm(objects)
}
}
}
@ -95,6 +97,14 @@ class TaskListViewModel @Inject constructor(
// }
// niMapController.lineHandler.omdbTaskLinkLayer.update()
liveDataTaskList.postValue(taskList)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
mapController.lineHandler.omdbTaskLinkLayer.removeAll()
for (item in taskList) {
mapController.lineHandler.omdbTaskLinkLayer.setLineColor(Color.valueOf(item.color))
mapController.lineHandler.omdbTaskLinkLayer.addLineList(item.hadLinkDvoList)
}
}
}
}

View File

@ -0,0 +1,5 @@
<vector android:height="24dp" android:tint="#3756DF"
android:viewportHeight="24" android:viewportWidth="24"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="@android:color/white" android:pathData="M23,8c0,1.1 -0.9,2 -2,2c-0.18,0 -0.35,-0.02 -0.51,-0.07l-3.56,3.55C16.98,13.64 17,13.82 17,14c0,1.1 -0.9,2 -2,2s-2,-0.9 -2,-2c0,-0.18 0.02,-0.36 0.07,-0.52l-2.55,-2.55C10.36,10.98 10.18,11 10,11s-0.36,-0.02 -0.52,-0.07l-4.55,4.56C4.98,15.65 5,15.82 5,16c0,1.1 -0.9,2 -2,2s-2,-0.9 -2,-2s0.9,-2 2,-2c0.18,0 0.35,0.02 0.51,0.07l4.56,-4.55C8.02,9.36 8,9.18 8,9c0,-1.1 0.9,-2 2,-2s2,0.9 2,2c0,0.18 -0.02,0.36 -0.07,0.52l2.55,2.55C14.64,12.02 14.82,12 15,12s0.36,0.02 0.52,0.07l3.55,-3.56C19.02,8.35 19,8.18 19,8c0,-1.1 0.9,-2 2,-2S23,6.9 23,8z"/>
</vector>

View File

@ -133,6 +133,13 @@
app:layout_constraintRight_toRightOf="parent"
tools:ignore="MissingConstraints">
<ImageButton
android:id="@+id/main_activity_select_line"
android:layout_width="48dp"
android:layout_height="48dp"
android:src="@drawable/baseline_timeline_24"
android:onClick="@{()->mainActivity.selectLineOnclick()}"
android:background="@drawable/shape_card_bg_default" />
<ImageButton
android:id="@+id/main_activity_voice"

View File

@ -17,4 +17,15 @@
android:text="80"
android:textColor="#2F2F2F"
android:textSize="14.67sp" />
<TextView
android:id="@+id/sign_bottom_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_marginLeft="15dp"
android:layout_marginBottom="5dp"
android:text="道路名"
android:layout_alignParentBottom="true"
android:textColor="@color/white"
android:textSize="14.67sp" />
</RelativeLayout>