Merge branch 'master' of gitlab.navinfo.com:CollectVehicle/OneMapQS

 Conflicts:
	app/src/main/java/com/navinfo/omqs/ui/activity/map/MainViewModel.kt
This commit is contained in:
squallzhjch
2023-11-06 16:33:56 +08:00
28 changed files with 918 additions and 210 deletions

View File

@@ -107,6 +107,7 @@ dependencies {
// implementation 'javax.xml.stream:stax-api:1.0-2'
// implementation 'com.bea.xml.stream:com.bea.xml.stream:1.0.0'
implementation 'commons-io:commons-io:2.11.0'
implementation 'com.alibaba:fastjson:1.2.73'
// 读取spatialite文件
implementation 'com.github.sevar83:android-spatialite:2.0.1'

View File

@@ -150,17 +150,23 @@
"code": 2092,
"name": "车道类型",
"catch": true,
"isDependOnOtherTable": true,
"isDependOnOtherTable": false,
"zoomMin": 18,
"zoomMax": 20,
"transformer": [
{
"k": "geometry",
"v": "~",
"klib": "geometry",
"vlib": "generateLaneTypeAccessS2ERefPoint()"
}
]
"transformer": [
{
"k": "geometry",
"v": "~",
"klib": "geometry",
"vlib": "filterLaneTypeAccess()"
},
{
"k": "geometry",
"v": "~",
"klib": "geometry",
"vlib": "generateLaneTypeAccessS2ERefPoint()"
}
]
},
"2097": {
"table": "OMDB_PHY_LANENUM",
@@ -173,7 +179,7 @@
"name": "桥",
"catch": true,
"existSubCode": true,
"isDependOnOtherTable": true,
"isDependOnOtherTable": false,
"zoomMin": 15,
"zoomMax": 20,
"transformer": [
@@ -350,7 +356,7 @@
"code": 4001,
"name": "路口",
"zoomMin": 15,
"isDependOnOtherTable": true,
"isDependOnOtherTable": false,
"zoomMax": 17,
"catch": true,
"transformer": [
@@ -492,7 +498,7 @@
"code": 4009,
"name": "警示信息",
"catch": true,
"isDependOnOtherTable": true,
"isDependOnOtherTable": false,
"zoomMin": 15,
"zoomMax": 20,
"transformer": [
@@ -581,7 +587,7 @@
"code": 4601,
"name": "车信",
"catch": true,
"isDependOnOtherTable": true,
"isDependOnOtherTable": false,
"zoomMin": 15,
"zoomMax": 17,
"transformer": [
@@ -609,8 +615,8 @@
"table": "OMDB_LANE_LINK_LG",
"code": 5001,
"name": "车道中心线",
"catch": false,
"isDependOnOtherTable": true,
"catch": true,
"isDependOnOtherTable": false,
"checkLinkId": false,
"zoomMin": 18,
"zoomMax": 20,

View File

@@ -40,12 +40,19 @@ class Constant {
*/
lateinit var USER_DATA_PATH: String
/**
* 用户数据安装标识
*/
var INSTALL_DATA: Boolean = false
/**
* 轨迹渲染个数统计
*/
var TRACE_COUNT : Int = 0
var TRACE_COUNT_TIME : Int = 10
var TRACE_COUNT_TIME : Int = 9
var TRACE_COUNT_MORE_TIME : Int = 24
/**
* 当前安装任务

View File

@@ -3,12 +3,13 @@ package com.navinfo.omqs.db
import android.content.Context
import android.database.Cursor.*
import android.util.Log
import com.alibaba.fastjson.JSON
import com.blankj.utilcode.util.ZipUtils
import com.google.gson.Gson
import com.google.gson.reflect.TypeToken
import com.navinfo.collect.library.data.entity.*
import com.navinfo.collect.library.enums.DataCodeEnum
import com.navinfo.collect.library.utils.StrZipUtil
import com.navinfo.collect.library.utils.DeflaterUtil
import com.navinfo.omqs.Constant
import com.navinfo.omqs.Constant.Companion.currentInstallTaskConfig
import com.navinfo.omqs.Constant.Companion.currentInstallTaskFolder
@@ -24,18 +25,34 @@ import io.realm.Realm
import io.realm.RealmConfiguration
import kotlinx.coroutines.*
import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.FlowCollector
import kotlinx.coroutines.flow.channelFlow
import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.sync.Mutex
import org.spatialite.database.SQLiteDatabase
import kotlinx.coroutines.channels.awaitClose
import kotlinx.coroutines.channels.trySendBlocking
import kotlinx.coroutines.flow.callbackFlow
import kotlinx.coroutines.flow.conflate
import java.io.BufferedReader
import java.io.File
import java.io.FileReader
import java.util.*
import javax.inject.Inject
//定义一个接口
sealed interface Event
class OnProgress(val value:Int):Event
class OnError(val t:Throwable):Event
class OnResult<T>(val value:T):Event
object OnComplete:Event
interface MultiPathsCallback<T>{
fun onProgress(value: Int)
fun onResult(value: T)
fun onError(t:Throwable)
fun onComplete()
}
/**
* 导入omdb数据的帮助类
* */
@@ -147,8 +164,9 @@ class ImportOMDBHelper @AssistedInject constructor(
* @param configFile 对应的配置文件
* */
suspend fun importOmdbZipFile(
omdbZipFile: File, task: TaskBean, scope: CoroutineScope
): Boolean {
omdbZipFile: File, task: TaskBean, scope: CoroutineScope,callback: MultiPathsCallback<String>
) {
val channel = Channel<List<RenderEntity>>(Channel.RENDEZVOUS)
installTaskid = task.id.toString()
@@ -190,7 +208,11 @@ class ImportOMDBHelper @AssistedInject constructor(
mutableMapOf<MutableMap.MutableEntry<String, TableInfo>, ImportConfig>()
//协程池
val listJob = mutableListOf<Job>()
try {
CMLog.writeLogtoFile(ImportOMDBHelper::class.java.name, "数据安装", "开始安装数据")
Constant.INSTALL_DATA = true
for (importConfig in importConfigList) {
for ((index, currentEntry) in importConfig.tableMap.entries.withIndex()) {
if (currentEntry.value.isDependOnOtherTable) {
@@ -198,14 +220,64 @@ class ImportOMDBHelper @AssistedInject constructor(
continue
}
val job = scope.launch(Dispatchers.IO) {
importData(
startTaskAsFlow(
channel,
unZipFiles,
currentEntry,
task,
importConfig,
hashMap
)
hashMap,
true).collect{
when(it){
OnComplete->{
processIndex ++
callback.onResult("$processIndex|$tableNum")
Log.e("jingo", "安装==$processIndex===$tableNum")
if(tableNum-processIndex==listDependOnEntry.size){
for ((currentEntry, importConfig) in listDependOnEntry) {
processIndex++
if(processIndex==tableNum){
importData(
channel,
unZipFiles,
currentEntry,
task,
importConfig,
hashMap,
false, callback
)
}else{
callback.onResult("$processIndex|$tableNum")
importData(
channel,
unZipFiles,
currentEntry,
task,
importConfig,
hashMap,
false, null)
}
}
Log.e("jingo", "安装结束")
CMLog.writeLogtoFile(ImportOMDBHelper::class.java.name, "数据安装", "安装结束")
Constant.INSTALL_DATA = false
}
}
is OnProgress->{
callback.onProgress(it.value)
Log.e("qj","progress==${it.value}")
}
is OnResult<*>->{
callback.onResult(it.value.toString())
}
is OnError->{
callback.onError(it.t)
}
}
}
}
listJob.add(job)
}
@@ -220,31 +292,49 @@ class ImportOMDBHelper @AssistedInject constructor(
}
realm.close()
}
}
listJob.joinAll()
channel.close()
channelJob.join()
Log.e("jingo", "channel close 等待结束")
for ((currentEntry, importConfig) in listDependOnEntry) {
importData(
channel,
unZipFiles,
currentEntry,
task,
importConfig,
hashMap,
false
)
}
Log.e("jingo", "安装结束")
} catch (e: Exception) {
Log.e("jingo", "安装报错1 ${e.message}")
return false
callback.onError(e)
Constant.INSTALL_DATA = false
}
return true
}
private fun startTaskAsFlow(
f: Channel<List<RenderEntity>>,
unZipFiles: List<File>,
currentEntry: MutableMap.MutableEntry<String, TableInfo>,
task: TaskBean,
importConfig: ImportConfig,
hashMap: HashMap<Long, HadLinkDvoBean>,
isEmit: Boolean = true) = callbackFlow <Event>{
val cancellable= importData(f,unZipFiles,currentEntry,task,importConfig,hashMap,isEmit,object :MultiPathsCallback<String>{
override fun onProgress(value: Int) {
trySendBlocking(OnProgress(value))
Log.e("jingo","=====$value")
}
override fun onError(t: Throwable) {
trySendBlocking(OnError(t))
}
override fun onComplete() {
trySendBlocking(OnComplete)
}
override fun onResult(value: String) {
trySendBlocking(OnResult(value))
}
})
awaitClose {
}
}.conflate()
private suspend fun importData(
f: Channel<List<RenderEntity>>,
@@ -253,18 +343,20 @@ class ImportOMDBHelper @AssistedInject constructor(
task: TaskBean,
importConfig: ImportConfig,
hashMap: HashMap<Long, HadLinkDvoBean>,
isEmit: Boolean = true
) {
isEmit: Boolean = true, callback: MultiPathsCallback<String>?
):NonCancellable {
val resHashMap: HashMap<String, RenderEntity> = HashMap() //define empty hashmap
var listRenderEntity = mutableListOf<RenderEntity>()
//单个表要素统计
var elementIndex = 0
val currentConfig = currentEntry.value
// CMLog.writeLogtoFile(
// ImportOMDBHelper::class.java.name,
// "importOmdbZipFile",
// "${currentConfig.table}开始"
// )
CMLog.writeLogtoFile(
ImportOMDBHelper::class.java.name,
"importOmdbZipFile",
"${currentConfig.table}开始"
)
try {
var realm: Realm? = null
if (!isEmit) {
@@ -286,12 +378,18 @@ class ImportOMDBHelper @AssistedInject constructor(
continue
}
newTime = System.currentTimeMillis()
Log.e(
"jingo",
"安装数据 ${currentConfig.table} $elementIndex ${listRenderEntity.size} ${newTime - time}"
)
if (elementIndex % 50 == 0) {
Log.e(
"jingo",
"安装数据 ${currentConfig.table} $elementIndex ${listRenderEntity.size} ${newTime - time}"
)
}
time = newTime
elementIndex += 1
val map = gson.fromJson<Map<String, Any>>(
line, object : TypeToken<Map<String, Any>>() {}.type
).toMutableMap()
@@ -480,6 +578,8 @@ class ImportOMDBHelper @AssistedInject constructor(
// 对renderEntity做预处理后再保存
val resultEntity = importConfig.transformProperties(renderEntity, realm)
//车道中心线不在主表写入
if (resultEntity != null) {
//对code编码需要特殊处理 存在多个属性值时渲染优先级SA>PA,存在多个属性值时渲染优先级FRONTAGE>MAIN_SIDE_A CCESS
@@ -526,6 +626,7 @@ class ImportOMDBHelper @AssistedInject constructor(
when (renderEntity.properties["bridgeType"]) {
"1" -> renderEntity.code =
DataCodeEnum.OMDB_BRIDGE_1.code
"2" -> renderEntity.code =
DataCodeEnum.OMDB_BRIDGE_2.code
// "3" -> renderEntity.code = DataCodeEnum.OMDB_BRIDGE_3.code
@@ -669,6 +770,21 @@ class ImportOMDBHelper @AssistedInject constructor(
renderEntity.properties.remove("linkPid")
}
//去掉暂用控件较大的字段多余属性字段
if (renderEntity.properties.containsKey("shapeList")) {
renderEntity.properties.remove("shapeList")
}
//只保留link表相关的pid
if (currentConfig.code != DataCodeEnum.OMDB_RD_LINK.code.toInt() && currentConfig.code != DataCodeEnum.OMDB_RD_LINK_KIND.code.toInt() && renderEntity.properties.containsKey(
"linkPid"
)
) {
if (renderEntity.properties.containsKey("mesh")) {
renderEntity.properties.remove("mesh")
}
}
// 如果当前解析的是OMDB_RD_LINK数据将其缓存在预处理类中以便后续处理其他要素时使用
if (currentConfig.code == DataCodeEnum.OMDB_RD_LINK.code.toInt()) {
if (renderEntity.linkRelation == null) {
@@ -681,15 +797,11 @@ class ImportOMDBHelper @AssistedInject constructor(
renderEntity.properties["enodePid"]
}
//去掉暂用控件较大的字段多余属性字段
if (renderEntity.properties.containsKey("shapeList")) {
renderEntity.properties.remove("shapeList")
}
renderEntity.propertiesDb =
DeflaterUtil.zipString(JSON.toJSONString(renderEntity.properties))
renderEntity.propertiesDb = StrZipUtil.compress(
gson.toJson(renderEntity.properties).toString()
)
listRenderEntity.add(renderEntity)
}
if (listRenderEntity.size > 20000) {
@@ -700,32 +812,36 @@ class ImportOMDBHelper @AssistedInject constructor(
if (isEmit) {
f.send(listRenderEntity)
delay(20)
callback?.onProgress(elementIndex)
} else {
realm!!.copyToRealm(listRenderEntity)
realm!!.commitTransaction()
realm!!.close()
realm = Realm.getInstance(currentInstallTaskConfig)
realm.beginTransaction()
callback?.onProgress(elementIndex)
}
listRenderEntity = mutableListOf()
//
}
line = bufferedReader.readLine()
}
// CMLog.writeLogtoFile(
// ImportOMDBHelper::class.java.name,
// "importOmdbZipFile",
// "结束===总量$elementIndex"
// )
CMLog.writeLogtoFile(
ImportOMDBHelper::class.java.name,
"importOmdbZipFile",
"${currentConfig.table}结束===总量$elementIndex"
)
if (isEmit) {
f.send(listRenderEntity)
delay(20)
callback?.onProgress(elementIndex)
} else {
bufferedReader.close()
realm!!.copyToRealm(listRenderEntity)
realm!!.commitTransaction()
callback?.onProgress(elementIndex)
}
}
if (!isEmit) {
@@ -735,7 +851,12 @@ class ImportOMDBHelper @AssistedInject constructor(
Log.e("jingo", "安装报错 ${currentConfig.table} ${elementIndex} ${e.message}")
throw e
}
Log.e("jingo", "完成 ${currentConfig.table}")
callback?.onComplete()
return NonCancellable
}

View File

@@ -1,11 +1,13 @@
package com.navinfo.omqs.db
import android.util.Log
import com.alibaba.fastjson.JSON
import com.google.gson.Gson
import com.navinfo.collect.library.data.entity.LinkRelation
import com.navinfo.collect.library.data.entity.ReferenceEntity
import com.navinfo.collect.library.data.entity.RenderEntity
import com.navinfo.collect.library.enums.DataCodeEnum
import com.navinfo.collect.library.utils.DeflaterUtil
import com.navinfo.collect.library.utils.GeometryTools
import com.navinfo.collect.library.utils.StrZipUtil
import com.navinfo.omqs.Constant
@@ -240,19 +242,32 @@ class ImportPreProcess {
startEndReference.properties["qi_table"] = renderEntity.table
startEndReference.properties["type"] = "s_2_e"
val listResult = mutableListOf<ReferenceEntity>()
startEndReference.propertiesDb = StrZipUtil.compress(
gson.toJson(startEndReference.properties).toString()
)
listResult.add(startEndReference)
insertData(listResult)
startEndReference.propertiesDb = DeflaterUtil.zipString(JSON.toJSONString(startEndReference.properties))
renderEntity.referenceEntitys?.add(startEndReference)
//listResult.add(startEndReference)
//insertData(listResult)
}
/**
* 过滤车道类型数据,只保留加速车道、减速车道和自行车道
* */
fun filterLaneTypeAccess(renderEntity: RenderEntity): Boolean {
if (renderEntity.properties["laneType"]!!.toInt() and (0b1100) > 0 || renderEntity.properties["laneType"]!!.toInt() and (0b1 shl 19) > 0) { // 是加速车道/减速车道/自行车道
// 如果是自行车道需要在properties中增加新的属性用于渲染自行车道的特殊线型
if (renderEntity.properties["laneType"]!!.toInt() and (0b1 shl 19) > 0) {
renderEntity.properties["bike"] = "true"
}
return true
}
return false
}
/**
* 生成车道类型起终点参考数据
* */
fun generateLaneTypeAccessS2ERefPoint(renderEntity: RenderEntity) {
// 如果车道类型非常规车道(第0bit的数据),则需要生成辅助数据
if (renderEntity.properties["laneType"]!!.toInt()>0) {
// 只需要生成加速车道和减速车道的起终点辅助数据
if (renderEntity.properties["laneType"]!!.toInt() and (0b1100) > 0) { // 是加速车道或者减速车道
val geometry = GeometryTools.createGeometry(renderEntity.properties["geometry"])
val pointEnd = geometry!!.coordinates[geometry.numPoints - 1] // 获取这个geometry对应的结束点坐标
@@ -273,7 +288,7 @@ class ImportPreProcess {
startReference.geometry =
GeometryTools.createGeometry(GeoPoint(pointStart.y, pointStart.x)).toString()
startReference.properties["qi_table"] = renderEntity.table
startReference.properties["type"] = "s_2_p"
startReference.properties["type"] = "s${if (renderEntity.properties["laneType"]!!.toInt() and (0b1000)>0) "_dec" else "_acc"}"
startReference.properties["geometry"] = startReference.geometry
listResult.add(startReference)
@@ -291,11 +306,11 @@ class ImportPreProcess {
endReference.geometry =
GeometryTools.createGeometry(GeoPoint(pointEnd.y, pointEnd.x)).toString()
endReference.properties["qi_table"] = renderEntity.table
endReference.properties["type"] = "e_2_p"
endReference.properties["type"] = "e${if (renderEntity.properties["laneType"]!!.toInt() and (0b1000)>0) "_dec" else "_acc"}"
endReference.properties["geometry"] = endReference.geometry
listResult.add(endReference)
insertData(listResult)
renderEntity.referenceEntitys?.add(endReference)
//listResult.add(endReference)
//insertData(listResult)
}
}
@@ -344,9 +359,7 @@ class ImportPreProcess {
Log.e("qj", "generateS2EReferencePoint===${startReference.geometry}")
startReference.properties["geometry"] = startReference.geometry
startReference.propertiesDb = StrZipUtil.compress(
gson.toJson(startReference.properties).toString()
)
startReference.propertiesDb = DeflaterUtil.zipString(JSON.toJSONString(startReference.properties))
listResult.add(startReference)
Log.e("qj", "generateS2EReferencePoint===1")
@@ -381,12 +394,11 @@ class ImportPreProcess {
Log.e("qj", "generateS2EReferencePoint===e_2_p${renderEntity.name}")
}
endReference.properties["geometry"] = endReference.geometry
endReference.propertiesDb = StrZipUtil.compress(
gson.toJson(endReference.properties).toString()
)
listResult.add(endReference)
endReference.propertiesDb = DeflaterUtil.zipString(JSON.toJSONString(endReference.properties))
renderEntity.referenceEntitys?.add(endReference)
//listResult.add(endReference)
Log.e("qj", "generateS2EReferencePoint===4")
insertData(listResult)
//insertData(listResult)
}
/**
@@ -482,12 +494,11 @@ class ImportPreProcess {
WKTWriter(3).write(GeometryTools.createLineString(arrayOf(pointStart, coorEnd)))
angleReference.properties["qi_table"] = renderEntity.table
angleReference.properties["type"] = "angle"
angleReference.propertiesDb = StrZipUtil.compress(
gson.toJson(angleReference.properties).toString()
)
listResult.add(angleReference)
angleReference.propertiesDb = DeflaterUtil.zipString(JSON.toJSONString(angleReference.properties))
renderEntity.referenceEntitys?.add(angleReference)
//listResult.add(angleReference)
}
insertData(listResult)
//insertData(listResult)
}
fun addAngleFromGeometry(renderEntity: RenderEntity): String {
@@ -642,12 +653,11 @@ class ImportPreProcess {
referenceEntity.properties["symbol"] =
"assets:omdb/4601/${type}/1301_${referenceEntity.properties["currentDirect"]}.svg"
Log.d("unpackingLaneInfo", referenceEntity.properties["symbol"].toString())
referenceEntity.propertiesDb = StrZipUtil.compress(
gson.toJson(referenceEntity.properties).toString()
)
listResult.add(referenceEntity)
referenceEntity.propertiesDb = DeflaterUtil.zipString(JSON.toJSONString(referenceEntity.properties))
renderEntity.referenceEntitys?.add(referenceEntity)
//listResult.add(referenceEntity)
}
insertData(listResult)
//insertData(listResult)
}
}
}
@@ -745,9 +755,8 @@ class ImportPreProcess {
angleReference.table = renderEntity.table
angleReference.code = renderEntity.code
Log.e("jingo", "几何转换开始")
angleReference.geometry =
GeometryTools.createGeometry(renderEntity.geometry).buffer(0.000010)
.toString()//GeometryTools.computeLine(0.000035,0.000035,renderEntity.geometry)
//angleReference.geometry = renderEntity.geometry
angleReference.geometry = GeometryTools.computeLine(0.000035,0.000035,renderEntity.geometry)
Log.e("jingo", "几何转换结束")
angleReference.properties["qi_table"] = renderEntity.table
angleReference.properties["widthProperties"] = "3"
@@ -756,12 +765,10 @@ class ImportPreProcess {
angleReference.taskId = renderEntity.taskId
angleReference.enable = renderEntity.enable
val listResult = mutableListOf<ReferenceEntity>()
angleReference.propertiesDb = StrZipUtil.compress(
gson.toJson(angleReference.properties).toString()
)
listResult.add(angleReference)
insertData(listResult)
angleReference.propertiesDb = DeflaterUtil.zipString(JSON.toJSONString(angleReference.properties))
renderEntity.referenceEntitys?.add(angleReference)
//listResult.add(angleReference)
//insertData(listResult)
}
@@ -790,12 +797,11 @@ class ImportPreProcess {
GeometryTools.createGeometry(nodeJSONObject["geometry"].toString()).toString()
intersectionReference.properties["qi_table"] = renderEntity.table
intersectionReference.properties["type"] = "node"
intersectionReference.propertiesDb = StrZipUtil.compress(
gson.toJson(intersectionReference.properties).toString()
)
listResult.add(intersectionReference)
intersectionReference.propertiesDb = DeflaterUtil.zipString(JSON.toJSONString(intersectionReference.properties))
renderEntity.referenceEntitys?.add(intersectionReference)
//listResult.add(intersectionReference)
}
insertData(listResult)
//insertData(listResult)
}
}
@@ -962,12 +968,11 @@ class ImportPreProcess {
dynamicSrcReference.properties["type"] = "dynamicSrc"
val code = renderEntity.properties[codeName]
dynamicSrcReference.properties["src"] = "${prefix}${code}${suffix}"
dynamicSrcReference.propertiesDb = StrZipUtil.compress(
gson.toJson(dynamicSrcReference.properties).toString()
)
listResult.add(dynamicSrcReference)
dynamicSrcReference.propertiesDb = DeflaterUtil.zipString(JSON.toJSONString(dynamicSrcReference.properties))
renderEntity.referenceEntitys?.add(dynamicSrcReference)
//listResult.add(dynamicSrcReference)
}
insertData(listResult)
//insertData(listResult)
}
private fun insertData(list: List<RealmModel>) {
@@ -1111,4 +1116,118 @@ class ImportPreProcess {
renderEntity.properties["ref"] = "${renderEntity.properties["maxSpeed"]}|${renderEntity.properties["minSpeed"]}"
}
}
/**
* 生成立交的辅助图层数据
* */
fun obtainZLevelReference(renderEntity: RenderEntity) {
if(renderEntity!=null&&renderEntity.properties.containsKey("zlevelList")) {
// 获取ZLevelList数据
val zLevelList = JSONArray(renderEntity.properties["zlevelList"])
for (i in 0 until zLevelList.length()) {
val zLevelObject = zLevelList.getJSONObject(i)
// 获取ZLevelObject的startEnd字段值
val startEnd = zLevelObject.optInt("startEnd", 0)
val zLevel = zLevelObject.optInt("zlevel", 0)
val shpSeqNum = zLevelObject.optInt("shpSeqNum", 0)
val linkGeometry = GeometryTools.createGeometry(zLevelObject.optString("linkGeometry"))
val coordinates = linkGeometry!!.coordinates
val referenceEntityList = mutableListOf<ReferenceEntity>()
// 判断当前数据的startEnd如果是0则向前和向后都绘制线如果是1起点则只绘制前两个点组成的线如果是2终点则只绘制后两个点组成的线
if (startEnd == 0 || startEnd == 1) { // 处理向后的线
val zLevelReference = createZLevelReference(renderEntity)
zLevelReference.properties["type"] = "zlevelLine"
// zLevelReference.properties["name"] = zLevel.toString()
// 根据shpSeqNum获取对应的点位
if (shpSeqNum < coordinates.size-1) {
val currentCoordinate = coordinates[shpSeqNum]
var nextCoordinate = coordinates[shpSeqNum+1]
// 计算两个点的距离,如果小于指定阈值,程序按照方向计算延长线
// if (GeometryTools.getDistance(currentCoordinate.y, currentCoordinate.x, nextCoordinate.y, nextCoordinate.x) < 3.0) {
// 获取当前点到下一个点的线方向
val angle = Angle.angle(currentCoordinate, nextCoordinate)
// 计算偏移距离
val dx: Double = GeometryTools.convertDistanceToDegree(
3.0,
currentCoordinate.y!!
) * Math.cos(angle)
val dy: Double = GeometryTools.convertDistanceToDegree(
3.0,
currentCoordinate.y!!
) * Math.sin(angle)
// 计算偏移后的点
nextCoordinate =
Coordinate(currentCoordinate.getX() + dx, currentCoordinate.getY() + dy)
// }
zLevelReference.geometry = GeometryTools.createLineString(arrayListOf(GeoPoint(currentCoordinate.y, currentCoordinate.x), GeoPoint(nextCoordinate.y, nextCoordinate.x))).toString()
referenceEntityList.add(zLevelReference)
val zLevelNameReference = createZLevelReference(renderEntity)
zLevelNameReference.properties["type"] = "zlevelName"
zLevelNameReference.properties["name"] = zLevel.toString()
zLevelNameReference.geometry = GeometryTools.createGeometry(GeoPoint(nextCoordinate.y, nextCoordinate.x)).toString()
referenceEntityList.add(zLevelNameReference)
}
}
if (startEnd == 0 || startEnd == 2) { // 处理向前的线
val zLevelReference = createZLevelReference(renderEntity)
zLevelReference.properties["type"] = "zlevelLine"
// zLevelReference.properties["name"] = zLevel.toString()
// 根据shpSeqNum获取对应的点位
if (shpSeqNum < coordinates.size&&shpSeqNum>0) {
val currentCoordinate = coordinates[shpSeqNum]
var preCoordinate = coordinates[shpSeqNum-1]
// 计算两个点的距离,如果小于指定阈值,程序按照方向计算延长线
// if (GeometryTools.getDistance(currentCoordinate.y, currentCoordinate.x, preCoordinate.y, preCoordinate.x) < 3.0) {
// 获取当前点到下一个点的线方向
val angle = Angle.angle(currentCoordinate, preCoordinate)
// 计算偏移距离
val dx: Double = GeometryTools.convertDistanceToDegree(
3.0,
currentCoordinate.y!!
) * Math.cos(angle)
val dy: Double = GeometryTools.convertDistanceToDegree(
3.0,
currentCoordinate.y!!
) * Math.sin(angle)
// 计算偏移后的点
preCoordinate =
Coordinate(currentCoordinate.getX() + dx, currentCoordinate.getY() + dy)
// }
zLevelReference.geometry = GeometryTools.createLineString(arrayListOf(GeoPoint(currentCoordinate.y, currentCoordinate.x), GeoPoint(preCoordinate.y, preCoordinate.x))).toString()
referenceEntityList.add(zLevelReference)
val zLevelNameReference = createZLevelReference(renderEntity)
zLevelNameReference.properties["type"] = "zlevelName"
zLevelNameReference.properties["name"] = zLevel.toString()
zLevelNameReference.geometry = GeometryTools.createGeometry(GeoPoint(preCoordinate.y, preCoordinate.x)).toString()
referenceEntityList.add(zLevelNameReference)
}
}
insertData(referenceEntityList)
// 移除zlevelList减小原始数据大小
renderEntity.properties.remove("zlevelList")
}
}
}
private fun createZLevelReference(renderEntity: RenderEntity): ReferenceEntity {
val zLevelReference = ReferenceEntity()
zLevelReference.renderEntityId = renderEntity.id
zLevelReference.name = "${renderEntity.name}参考点"
zLevelReference.code = renderEntity.code
zLevelReference.table = renderEntity.table
zLevelReference.zoomMin = renderEntity.zoomMin
zLevelReference.zoomMax = renderEntity.zoomMax
zLevelReference.taskId = renderEntity.taskId
zLevelReference.enable = renderEntity.enable
zLevelReference.properties["qi_table"] = renderEntity.table
return zLevelReference
}
}

View File

@@ -1,14 +1,18 @@
package com.navinfo.omqs.http.taskdownload
import android.os.Handler
import android.os.Message
import android.util.Log
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.Observer
import androidx.lifecycle.viewmodel.viewModelFactory
import com.blankj.utilcode.util.MapUtils
import com.navinfo.collect.library.data.entity.TaskBean
import com.navinfo.collect.library.utils.MapParamUtils
import com.navinfo.omqs.Constant
import com.navinfo.omqs.db.ImportOMDBHelper
import com.navinfo.omqs.db.MultiPathsCallback
import com.navinfo.omqs.db.RealmOperateHelper
import com.navinfo.omqs.tools.FileManager
import com.navinfo.omqs.tools.FileManager.Companion.FileDownloadStatus
@@ -155,20 +159,50 @@ class TaskDownloadScope(
fileNew
)
if (task != null) {
if (importOMDBHelper.importOmdbZipFile(importOMDBHelper.omdbFile, task, this)) {
// if (it == "finish") {
change(FileDownloadStatus.DONE)
Log.e("jingo", "数据安装结束")
withContext(Dispatchers.Main) {
//任务与当前一致,需要更新渲染图层
if (MapParamUtils.getTaskId() == taskBean.id) {
downloadManager.mapController.layerManagerHandler.updateOMDBVectorTileLayer()
importOMDBHelper.importOmdbZipFile(
importOMDBHelper.omdbFile,
task,
this,
object : MultiPathsCallback<String> {
override fun onProgress(value: Int) {
Log.e("jingo", "安装====$value")
}
}
} else {
change(FileDownloadStatus.IMPORTING, "anzhuang")
}
// }
override fun onError(t: Throwable) {
}
override fun onComplete() {
taskBean.status = FileDownloadStatus.DONE
downloadData.postValue(taskBean)
//任务与当前一致,需要更新渲染图层
if (MapParamUtils.getTaskId() == taskBean.id) {
downloadManager.mapController.layerManagerHandler.updateOMDBVectorTileLayer()
}
val realm = realmOperateHelper.getRealmDefaultInstance()
realm.executeTransaction { r ->
val newTask =
realm.where(TaskBean::class.java).equalTo("id", taskBean.id)
.findFirst()
newTask?.let {
it.syncStatus = taskBean.syncStatus
it.status = taskBean.status
it.errMsg = taskBean.errMsg
//赋值时间,用于查询过滤
it.operationTime = taskBean.operationTime
r.copyToRealmOrUpdate(it)
taskBean = realm.copyFromRealm(it)
}
}
realm.close()
}
override fun onResult(value: String) {
taskBean.status = FileDownloadStatus.IMPORTING
taskBean.message = value
downloadData.postValue(taskBean)
}
})
}
} catch (e: Exception) {
Log.e("jingo", "数据安装失败 ${e.toString()}")

File diff suppressed because one or more lines are too long

View File

@@ -70,6 +70,18 @@ import kotlin.concurrent.fixedRateTimer
* 创建Activity全局viewmode
*/
enum class LoadDataStatus {
/**
* 加载开始
*/
LOAD_DATA_STATUS_BEGIN,
/**
* 加载结束
*/
LOAD_DATA_STATUS_FISISH,
}
@HiltViewModel
class MainViewModel @Inject constructor(
private val mapController: NIMapController,
@@ -97,6 +109,9 @@ class MainViewModel @Inject constructor(
//地图点击捕捉到的轨迹列表
val liveDataNILocationList = MutableLiveData<NiLocation>()
//加载数据
val liveDataLoadData = MutableLiveData<LoadDataStatus>()
//左侧看板数据
val liveDataSignList = MutableLiveData<List<SignBean>>()
@@ -251,8 +266,6 @@ class MainViewModel @Inject constructor(
private val naviMutex = Mutex()
private var testRealm: Realm? = null;
private var traceCount = 0
init {
mapController.mMapView.vtmMap.events.bind(Map.UpdateListener { e, mapPosition ->
when (e) {
@@ -279,6 +292,10 @@ class MainViewModel @Inject constructor(
object : OnGeoPointClickListener {
override fun onMapClick(tag: String, point: GeoPoint) {
if (tag == TAG) {
//数据安装时不允许操作数据
if(Constant.INSTALL_DATA){
return
}
if (bMeasuringTool) {
mapController.measureLayerHandler.addPoint(measuringType, point)
} else {
@@ -329,6 +346,7 @@ class MainViewModel @Inject constructor(
})
viewModelScope.launch(Dispatchers.IO) {
liveDataLoadData.postValue(LoadDataStatus.LOAD_DATA_STATUS_BEGIN)
getTaskBean()
//初始化选中的任务高亮高亮
if (currentTaskBean != null) {
@@ -337,6 +355,7 @@ class MainViewModel @Inject constructor(
initQsRecordData()
initNoteData()
initNILocationData()
liveDataLoadData.postValue(LoadDataStatus.LOAD_DATA_STATUS_FISISH)
}
sharedPreferences.registerOnSharedPreferenceChangeListener(this)
MapParamUtils.setTaskId(sharedPreferences.getInt(Constant.SELECT_TASK_ID, -1))
@@ -568,12 +587,18 @@ class MainViewModel @Inject constructor(
for (location in list) {
Constant.TRACE_COUNT++
if(Constant.TRACE_COUNT%Constant.TRACE_COUNT_MORE_TIME==0){
mapController.markerHandle.addNiLocationMarkerItemRough(location)
Log.e("qj","${Constant.TRACE_COUNT}===轨迹")
}
if(Constant.TRACE_COUNT%Constant.TRACE_COUNT_TIME==0){
mapController.markerHandle.addNiLocationMarkerItemSimple(location)
Log.e("qj","${Constant.TRACE_COUNT}===轨迹")
}
mapController.markerHandle.addNiLocationMarkerItem(location)
if (Constant.TRACE_COUNT % Constant.TRACE_COUNT_TIME == 0) {
mapController.markerHandle.addNiLocationMarkerItemSimple(location)
Log.e("qj", "$traceCount===轨迹")
}
}
}
}
@@ -636,23 +661,22 @@ class MainViewModel @Inject constructor(
lastNiLocaion!!.longitude
)
}
//室内整理工具时不能进行轨迹存储,判断轨迹间隔要超过2.5并小于60米
if (Constant.INDOOR_IP.isEmpty() && (disance == 0.0 || (disance > 2.5 && disance < 60))) {
traceCount++
//室内整理工具时不能进行轨迹存储,判断轨迹间隔要超过6并小于60米
if (Constant.INDOOR_IP.isEmpty() && (disance == 0.0 || (disance > 6.0 && disance < 60))) {
Log.e("jingo", "轨迹插入开始")
CMLog.writeLogtoFile(MainViewModel::class.java.name, "insertTrace", "开始")
CMLog.writeLogtoFile(MainViewModel::class.java.name,"insertTrace","开始")
traceDataBase.niLocationDao.insert(location)
mapController.markerHandle.addNiLocationMarkerItem(location)
if (Constant.TRACE_COUNT % Constant.TRACE_COUNT_TIME == 0) {
if(Constant.TRACE_COUNT%Constant.TRACE_COUNT_TIME==0){
mapController.markerHandle.addNiLocationMarkerItemSimple(location)
}
if(Constant.TRACE_COUNT%Constant.TRACE_COUNT_MORE_TIME==0){
mapController.markerHandle.addNiLocationMarkerItemRough(location)
}
mapController.mMapView.vtmMap.updateMap(true)
lastNiLocaion = location
CMLog.writeLogtoFile(
MainViewModel::class.java.name,
"insertTrace",
gson.toJson(location)
)
CMLog.writeLogtoFile(MainViewModel::class.java.name,"insertTrace",gson.toJson(location))
Log.e("jingo", "轨迹插入结束")
}
}
@@ -830,7 +854,7 @@ class MainViewModel @Inject constructor(
*/
private suspend fun captureLink(point: GeoPoint) {
if (captureLinkState) {
if (captureLinkState||Constant.INSTALL_DATA) {
return
}

View File

@@ -196,7 +196,7 @@ class PersonalCenterFragment(private var indoorDataListener: ((Boolean) -> Unit?
// 定位到指定位置
niMapController.mMapView.vtmMap.animator()
// .animateTo(GeoPoint( 40.05108004733645, 116.29187746293708 ))
.animateTo(GeoPoint(31.205913609396507, 121.56955739056055 ))
.animateTo(GeoPoint(39.63769191655024, 115.58991663847937))
}
R.id.personal_center_menu_open_all_layer -> {

View File

@@ -11,6 +11,7 @@ import com.navinfo.omqs.bean.ScProblemTypeBean
import com.navinfo.omqs.bean.ScRootCauseAnalysisBean
import com.navinfo.omqs.bean.ScWarningCodeBean
import com.navinfo.omqs.db.ImportOMDBHelper
import com.navinfo.omqs.db.MultiPathsCallback
import com.navinfo.omqs.db.RealmOperateHelper
import com.navinfo.omqs.db.RoomAppDatabase
import com.navinfo.omqs.tools.MetadataUtils
@@ -152,11 +153,36 @@ class PersonalCenterViewModel @Inject constructor(
viewModelScope.launch(Dispatchers.IO) {
Log.d("OMQSApplication", "开始导入数据")
if (task != null) {
importOMDBHelper.importOmdbZipFile(importOMDBHelper.omdbFile, task, this)
importOMDBHelper.importOmdbZipFile(importOMDBHelper.omdbFile, task, this,object :MultiPathsCallback<String>{
override fun onProgress(value: Int) {
}
override fun onResult(value: String) {
}
override fun onError(t: Throwable) {
}
override fun onComplete() {
}
})
} else {
val newTask = TaskBean()
newTask.id = -1
importOMDBHelper.importOmdbZipFile(importOMDBHelper.omdbFile, newTask, this)
importOMDBHelper.importOmdbZipFile(importOMDBHelper.omdbFile, newTask, this,object :MultiPathsCallback<String>{
override fun onProgress(value: Int) {
}
override fun onResult(value: String) {
}
override fun onError(t: Throwable) {
}
override fun onComplete() {
}
})
}
Log.d("OMQSApplication", "导入数据完成")

View File

@@ -325,18 +325,19 @@ class TaskListAdapter(
if (binding.taskProgressText.visibility != View.VISIBLE) binding.taskProgressText.visibility =
View.VISIBLE
binding.taskDownloadBtn.setText("安装中")
Log.e("jingo", "更新进度条 ${taskBean.message}")
val split = taskBean.message.split("/")
if (split.size == 2) {
try {
val index = split[0].toInt()
val count = split[1].toInt()
binding.taskProgressText.text =
"${index * 100 / count}%"
Log.e("jingo", "更新进度条 $index====$count")
binding.taskProgressText.text = "${index * 100 / count}%"
} catch (e: Exception) {
Log.e("jingo", "更新进度条 $e")
}
} else {
binding.taskProgressText.text = "0%"
binding.taskProgressText.text = taskBean.message
}
val errMsg = taskBean.errMsg
if (errMsg != null && errMsg.isNotEmpty()) {

View File

@@ -145,6 +145,17 @@ class TaskListFragment : BaseFragment() {
binding.taskListRecyclerview.smoothScrollToPosition(position)
}
viewModel.liveDataLoadTask.observe(viewLifecycleOwner){
when(it){
TaskLoadStatus.TASK_LOAD_STATUS_BEGIN->{
showLoadingDialog("正在切换任务")
}
TaskLoadStatus.TASK_LOAD_STATUS_FISISH->{
hideLoadingDialog()
}
}
}
viewModel.liveDataCloseTask.observe(viewLifecycleOwner){
when(it){
TaskDelStatus.TASK_DEL_STATUS_BEGIN->{

View File

@@ -59,6 +59,18 @@ enum class TaskDelStatus {
TASK_DEL_STATUS_CANCEL,
}
enum class TaskLoadStatus {
/**
* 加载开始
*/
TASK_LOAD_STATUS_BEGIN,
/**
* 加载结束
*/
TASK_LOAD_STATUS_FISISH,
}
@HiltViewModel
class TaskViewModel @Inject constructor(
private val networkService: NetworkService,
@@ -90,6 +102,11 @@ class TaskViewModel @Inject constructor(
*/
val liveDataCloseTask = MutableLiveData<TaskDelStatus>()
/**
* 用来确定是否加载
*/
val liveDataLoadTask = MutableLiveData<TaskLoadStatus>()
/**
* 用来更新任务
*/
@@ -317,7 +334,11 @@ class TaskViewModel @Inject constructor(
currentSelectTaskBean = taskBean
liveDataTaskLinks.value = taskBean.hadLinkDvoList
liveDataLoadTask.postValue(TaskLoadStatus.TASK_LOAD_STATUS_BEGIN)
showTaskLinks(taskBean)
//重新加载轨迹
viewModelScope.launch(Dispatchers.IO) {
Constant.TRACE_COUNT = 0
@@ -328,22 +349,30 @@ class TaskViewModel @Inject constructor(
Constant.TRACE_COUNT ++
mapController.markerHandle.addNiLocationMarkerItem(it)
if(Constant.TRACE_COUNT%Constant.TRACE_COUNT_MORE_TIME==0){
mapController.markerHandle.addNiLocationMarkerItemRough(it)
}
if(Constant.TRACE_COUNT%Constant.TRACE_COUNT_TIME==0){
mapController.markerHandle.addNiLocationMarkerItemSimple(it)
}
mapController.markerHandle.addNiLocationMarkerItem(it)
}
liveDataLoadTask.postValue(TaskLoadStatus.TASK_LOAD_STATUS_FISISH)
withContext(Dispatchers.Main){
MapParamUtils.setTaskId(taskBean.id)
Constant.currentSelectTaskFolder = File(Constant.USER_DATA_PATH + "/${taskBean.id}")
Constant.currentSelectTaskConfig =
RealmConfiguration.Builder().directory(Constant.currentSelectTaskFolder)
.name("OMQS.realm").encryptionKey(Constant.PASSWORD).allowQueriesOnUiThread(true)
.schemaVersion(2).build()
MapParamUtils.setTaskConfig(Constant.currentSelectTaskConfig)
mapController.layerManagerHandler.updateOMDBVectorTileLayer()
mapController.mMapView.updateMap(true)
}
}
MapParamUtils.setTaskId(taskBean.id)
Constant.currentSelectTaskFolder = File(Constant.USER_DATA_PATH + "/${taskBean.id}")
Constant.currentSelectTaskConfig =
RealmConfiguration.Builder().directory(Constant.currentSelectTaskFolder)
.name("OMQS.realm").encryptionKey(Constant.PASSWORD).allowQueriesOnUiThread(true)
.schemaVersion(2).build()
MapParamUtils.setTaskConfig(Constant.currentSelectTaskConfig)
mapController.layerManagerHandler.updateOMDBVectorTileLayer()
mapController.mMapView.updateMap(true)
}