优化数据库查询

1、去掉了RenderEntity表的主键
2、去掉了ReferenceEntity表的主键和 与RenderEntity表的关联外键
3、去掉了上面两个表的set,map集合改为int,String基础字段
4、对properties字段进行了压缩
5、将properties表中的linkpid字段移到RenderEntity中
6、查询语句修改
This commit is contained in:
squallzhjch 2023-10-26 09:18:02 +08:00
parent c7122376cf
commit 1b5da9e536
15 changed files with 267 additions and 410 deletions

View File

@ -154,17 +154,13 @@ class ImportOMDBHelper @AssistedInject constructor(
suspend fun importOmdbZipFile(omdbZipFile: File, task: TaskBean): Flow<String> = suspend fun importOmdbZipFile(omdbZipFile: File, task: TaskBean): Flow<String> =
withContext(Dispatchers.IO) { withContext(Dispatchers.IO) {
installTaskid = task.id.toString() installTaskid = task.id.toString()
// currentInstallTaskFolder = File(Constant.USER_DATA_PATH + "/$installTaskid") currentInstallTaskFolder = File(Constant.USER_DATA_PATH + "/$installTaskid")
currentInstallTaskFolder = File(Constant.USER_DATA_PATH + "/237")
if (!currentInstallTaskFolder.exists()) currentInstallTaskFolder.mkdirs() if (!currentInstallTaskFolder.exists()) currentInstallTaskFolder.mkdirs()
currentInstallTaskConfig = currentInstallTaskConfig =
RealmConfiguration.Builder() RealmConfiguration.Builder().directory(currentInstallTaskFolder).name("OMQS.realm")
.directory(currentInstallTaskFolder)
.name("OMQS.realm")
.encryptionKey(Constant.PASSWORD) .encryptionKey(Constant.PASSWORD)
// .allowQueriesOnUiThread(true) // .allowQueriesOnUiThread(true)
.schemaVersion(2) .schemaVersion(2).build()
.build()
val unZipFolder = File(omdbZipFile.parentFile, "result") val unZipFolder = File(omdbZipFile.parentFile, "result")
flow { flow {
@ -207,7 +203,6 @@ class ImportOMDBHelper @AssistedInject constructor(
val resHashMap: HashMap<String, RenderEntity> = HashMap() //define empty hashmap val resHashMap: HashMap<String, RenderEntity> = HashMap() //define empty hashmap
val listRenderEntity = mutableListOf<RenderEntity>() val listRenderEntity = mutableListOf<RenderEntity>()
val listRenderEntity1 = mutableListOf<RenderEntity1>()
try { try {
// var multipLine = MultiLineString(lineList, GeometryFactory()) // var multipLine = MultiLineString(lineList, GeometryFactory())
@ -320,8 +315,7 @@ class ImportOMDBHelper @AssistedInject constructor(
is Double -> renderEntity.properties[key] = is Double -> renderEntity.properties[key] =
value.toDouble().toString() value.toDouble().toString()
else -> renderEntity.properties[key] = else -> renderEntity.properties[key] = value.toString()
value.toString()
} }
} }
// Log.d("ImportOMDBHelper", "解析===2处理属性") // Log.d("ImportOMDBHelper", "解析===2处理属性")
@ -336,79 +330,76 @@ class ImportOMDBHelper @AssistedInject constructor(
if (currentConfig.filterData) { if (currentConfig.filterData) {
when (renderEntity.code.toInt()) { when (renderEntity.code.toInt()) {
// DataCodeEnum.OMDB_POLE.code.toInt() -> { DataCodeEnum.OMDB_POLE.code.toInt() -> {
// //过滤树类型的杆状物,无需导入到数据库中 //过滤树类型的杆状物,无需导入到数据库中
// val poleType = val poleType = renderEntity.properties["poleType"]
// renderEntity.properties["poleType"] if (poleType != null && poleType.toInt() == 2) {
// if (poleType != null && poleType.toInt() == 2) { line = bufferedReader.readLine()
// line = bufferedReader.readLine() continue
// continue }
// } }
// }
// DataCodeEnum.OMDB_LANE_MARK_BOUNDARYTYPE.code.toInt() -> { DataCodeEnum.OMDB_LANE_MARK_BOUNDARYTYPE.code.toInt() -> {
// val boundaryType = val boundaryType =
// renderEntity.properties["boundaryType"] renderEntity.properties["boundaryType"]
// if (boundaryType != null) { if (boundaryType != null) {
// when (boundaryType.toInt()) { when (boundaryType.toInt()) {
// 0, 1, 6, 8, 9 -> { 0, 1, 6, 8, 9 -> {
// renderEntity.enable = 0 renderEntity.enable = 0
//// Log.e( // Log.e(
//// "qj", // "qj",
//// "过滤不显示数据${renderEntity.table}" // "过滤不显示数据${renderEntity.table}"
//// ) // )
// line = bufferedReader.readLine() line = bufferedReader.readLine()
// continue continue
// } }
// } }
// } }
// } }
// DataCodeEnum.OMDB_RDBOUND_BOUNDARYTYPE.code.toInt() -> { DataCodeEnum.OMDB_RDBOUND_BOUNDARYTYPE.code.toInt() -> {
// val boundaryType = val boundaryType =
// renderEntity.properties["boundaryType"] renderEntity.properties["boundaryType"]
// if (boundaryType != null) { if (boundaryType != null) {
// when (boundaryType.toInt()) { when (boundaryType.toInt()) {
// 0, 1, 3, 4, 5, 7, 9 -> { 0, 1, 3, 4, 5, 7, 9 -> {
// renderEntity.enable = 0 renderEntity.enable = 0
//// Log.e( // Log.e(
//// "qj", // "qj",
//// "过滤不显示数据${renderEntity.table}" // "过滤不显示数据${renderEntity.table}"
//// ) // )
// line = bufferedReader.readLine() line = bufferedReader.readLine()
// continue continue
// } }
// } }
// } }
// } }
// DataCodeEnum.OMDB_OBJECT_STOPLOCATION.code.toInt() -> { DataCodeEnum.OMDB_OBJECT_STOPLOCATION.code.toInt() -> {
// val locationType = val locationType =
// renderEntity.properties["locationType"] renderEntity.properties["locationType"]
// if (locationType != null) { if (locationType != null) {
// when (locationType.toInt()) { when (locationType.toInt()) {
// 3, 4 -> { 3, 4 -> {
// renderEntity.enable = 0 renderEntity.enable = 0
//// Log.e( // Log.e(
//// "qj", // "qj",
//// "过滤不显示数据${renderEntity.table}" // "过滤不显示数据${renderEntity.table}"
//// ) // )
// line = bufferedReader.readLine() line = bufferedReader.readLine()
// continue continue
// } }
// } }
// } }
// } }
DataCodeEnum.OMDB_RESTRICTION.code.toInt() -> { DataCodeEnum.OMDB_RESTRICTION.code.toInt() -> {
if (renderEntity.properties.containsKey("linkIn") && renderEntity.properties.containsKey( if (renderEntity.properties.containsKey("linkIn") && renderEntity.properties.containsKey(
"linkOut" "linkOut"
) )
) { ) {
val linkIn = val linkIn = renderEntity.properties["linkIn"]
renderEntity.properties["linkIn"] val linkOut = renderEntity.properties["linkOut"]
val linkOut =
renderEntity.properties["linkOut"]
if (linkIn != null && linkOut != null) { if (linkIn != null && linkOut != null) {
val checkMsg = "$linkIn$linkOut" val checkMsg = "$linkIn$linkOut"
if (resHashMap.containsKey(checkMsg)) { if (resHashMap.containsKey(checkMsg)) {
@ -479,8 +470,7 @@ class ImportOMDBHelper @AssistedInject constructor(
// "linkList==开始${renderEntity.name}==${renderEntity.properties["linkList"]}}" // "linkList==开始${renderEntity.name}==${renderEntity.properties["linkList"]}}"
// ) // )
val linkList = val linkList = renderEntity.properties["linkList"]
renderEntity.properties["linkList"]
if (!linkList.isNullOrEmpty() && linkList != "null") { if (!linkList.isNullOrEmpty() && linkList != "null") {
@ -491,8 +481,7 @@ class ImportOMDBHelper @AssistedInject constructor(
val list: List<LinkList> = gson.fromJson( val list: List<LinkList> = gson.fromJson(
linkList, linkList,
object : object : TypeToken<List<LinkList>>() {}.type
TypeToken<List<LinkList>>() {}.type
) )
m@ for (link in list) { m@ for (link in list) {
@ -507,21 +496,20 @@ class ImportOMDBHelper @AssistedInject constructor(
} }
} }
} }
} else {
//不包括linkPid直接过滤
line = bufferedReader.readLine()
continue
}
//过滤掉非任务路线上的数据
if (renderEntity.enable != 1) {
// Log.e(
// "qj",
// "${renderEntity.name}==过滤不包括任务路线上的数据"
// )
line = bufferedReader.readLine()
continue
} }
// else {
// //不包括linkPid直接过滤
// line = bufferedReader.readLine()
// continue
// }
// //过滤掉非任务路线上的数据
// if (renderEntity.enable != 1) {
//// Log.e(
//// "qj",
//// "${renderEntity.name}==过滤不包括任务路线上的数据"
//// )
// line = bufferedReader.readLine()
// continue
// }
} else { } else {
renderEntity.enable = 1 renderEntity.enable = 1
@ -593,19 +581,18 @@ class ImportOMDBHelper @AssistedInject constructor(
renderEntity.zoomMin = 15 renderEntity.zoomMin = 15
renderEntity.zoomMax = 17 renderEntity.zoomMax = 17
// Log.e("qj", "道路属性===4") // Log.e("qj", "道路属性===4")
} else {
renderEntity.enable = 0
renderEntity.zoomMin = 15
renderEntity.zoomMax = 17
// Log.e(
// "qj",
// "过滤不显示数据${renderEntity.table}"
// )
// Log.e("qj", "道路属性===5")
line = bufferedReader.readLine()
continue
} }
// else {
// renderEntity.enable = 0
// renderEntity.zoomMin = 15
// renderEntity.zoomMax = 17
//// Log.e(
//// "qj",
//// "过滤不显示数据${renderEntity.table}"
//// )
//// Log.e("qj", "道路属性===5")
// line = bufferedReader.readLine()
// continue
// }
} }
} }
} }
@ -733,39 +720,38 @@ class ImportOMDBHelper @AssistedInject constructor(
} }
} }
// if (renderEntity.table == DataCodeEnum.OMDB_NODE_FORM.name) {//特殊处理因为code相同使用表名判断 if (renderEntity.table == DataCodeEnum.OMDB_NODE_FORM.name) {//特殊处理因为code相同使用表名判断
// //过滤不需要渲染的要素 //过滤不需要渲染的要素
// val formOfWay = val formOfWay = renderEntity.properties["formOfWay"]
// renderEntity.properties["formOfWay"] if (formOfWay != null && formOfWay.toInt() == 30) {
// if (formOfWay != null && formOfWay.toInt() == 30) { renderEntity.enable = 2
// renderEntity.enable = 2 renderEntity.code =
// renderEntity.code = DataCodeEnum.OMDB_NODE_FORM.code
// DataCodeEnum.OMDB_NODE_FORM.code } else {
// } else { // Log.e(
//// Log.e( // "qj",
//// "qj", // "过滤不显示数据${renderEntity.table}"
//// "过滤不显示数据${renderEntity.table}" // )
//// ) line = bufferedReader.readLine()
// line = bufferedReader.readLine() continue
// continue }
// } } else if (renderEntity.table == DataCodeEnum.OMDB_NODE_PA.name) {//特殊处理因为code相同使用表名判断
// } else if (renderEntity.table == DataCodeEnum.OMDB_NODE_PA.name) {//特殊处理因为code相同使用表名判断 //过滤不需要渲染的要素
// //过滤不需要渲染的要素 val attributeType =
// val attributeType = renderEntity.properties["attributeType"]
// renderEntity.properties["attributeType"] if (attributeType != null && attributeType.toInt() == 30) {
// if (attributeType != null && attributeType.toInt() == 30) { renderEntity.enable = 2
// renderEntity.enable = 2 renderEntity.code =
// renderEntity.code = DataCodeEnum.OMDB_NODE_PA.code
// DataCodeEnum.OMDB_NODE_PA.code } else {
// } else { // Log.e(
//// Log.e( // "qj",
//// "qj", // "过滤不显示数据${renderEntity.table}"
//// "过滤不显示数据${renderEntity.table}" // )
//// ) line = bufferedReader.readLine()
// line = bufferedReader.readLine() continue
// continue }
// } }
// }
} }
// Log.d("ImportOMDBHelper", "解析===2子code处理") // Log.d("ImportOMDBHelper", "解析===2子code处理")
@ -798,92 +784,26 @@ class ImportOMDBHelper @AssistedInject constructor(
gson.toJson(renderEntity.properties).toString() gson.toJson(renderEntity.properties).toString()
) )
when (renderEntity.code) { listRenderEntity.add(renderEntity)
DataCodeEnum.OMDB_LANE_LINK_LG.code,
DataCodeEnum.OMDB_LINK_SPEEDLIMIT.code,
DataCodeEnum.OMDB_POLE.code,
DataCodeEnum.OMDB_LINK_DIRECT.code,
DataCodeEnum.OMDB_RD_LINK_FUNCTION_CLASS.code,
DataCodeEnum.OMDB_LINK_NAME.code,
DataCodeEnum.OMDB_OBJECT_ARROW.code,
DataCodeEnum.OMDB_TRAFFICLIGHT.code -> {
val renderEntity1 = RenderEntity1()
renderEntity1.code = resultEntity.code
renderEntity1.linkPid = renderEntity.linkPid
renderEntity1.table = renderEntity.table
renderEntity1.name = renderEntity.name
renderEntity1.linkRelation =
renderEntity.linkRelation
renderEntity1.catchEnable = renderEntity.catchEnable
renderEntity1.enable = renderEntity.enable
renderEntity1.geometry = renderEntity.geometry
renderEntity1.taskId = renderEntity.taskId
// renderEntity1.tileX = renderEntity.tileX
// renderEntity1.tileY = renderEntity.tileY
renderEntity1.tileXMin = renderEntity.tileXMin
renderEntity1.tileXMax = renderEntity.tileXMax
renderEntity1.tileYMin = renderEntity.tileYMin
renderEntity1.tileYMax = renderEntity.tileYMax
// renderEntity1.wkt = renderEntity.wkt
renderEntity1.zoomMin = renderEntity.zoomMin
renderEntity1.zoomMax = renderEntity.zoomMax
renderEntity1.propertiesDb =
renderEntity.propertiesDb
listRenderEntity1.add(renderEntity1)
}
else -> listRenderEntity.add(renderEntity)
}
// Log.d("ImportOMDBHelper", "解析===1insert")
// realm.insert(renderEntity)
// Log.d("ImportOMDBHelper", "解析===2insert")
} }
// if (currentConfig.code == DataCodeEnum.OMDB_RD_LINK.code.toInt()) {
// listResult.add(renderEntity)
// }
if (listRenderEntity.size > 10000) { if (listRenderEntity.size > 10000) {
Log.e( Log.e(
"jingo", "20000刷新" "jingo", "10000刷新"
) )
realm.copyToRealm(listRenderEntity) realm.copyToRealm(listRenderEntity)
realm.commitTransaction() realm.commitTransaction()
realm.close() realm.close()
listRenderEntity.clear() listRenderEntity.clear()
insertIndex = 0 insertIndex = 0
delay(100)
// Realm.compactRealm(currentInstallTaskConfig)
realm = Realm.getInstance(currentInstallTaskConfig)
realm.beginTransaction()
}
if (listRenderEntity1.size > 10000) {
Log.e(
"jingo", "20000刷新"
)
realm.copyToRealm(listRenderEntity1)
realm.commitTransaction()
realm.close()
listRenderEntity1.clear()
insertIndex = 0
delay(100)
// Realm.compactRealm(currentInstallTaskConfig) // Realm.compactRealm(currentInstallTaskConfig)
realm = Realm.getInstance(currentInstallTaskConfig) realm = Realm.getInstance(currentInstallTaskConfig)
realm.beginTransaction() realm.beginTransaction()
// Log.d(
// "ImportOMDBHelper",
// "表解析===结束用时时间===事物结束"
// )
} }
line = bufferedReader.readLine() line = bufferedReader.readLine()
} }
bufferedReader.close() bufferedReader.close()
} }

View File

@ -1,11 +1,13 @@
package com.navinfo.omqs.db package com.navinfo.omqs.db
import android.util.Log import android.util.Log
import com.google.gson.Gson
import com.navinfo.collect.library.data.entity.LinkRelation import com.navinfo.collect.library.data.entity.LinkRelation
import com.navinfo.collect.library.data.entity.ReferenceEntity import com.navinfo.collect.library.data.entity.ReferenceEntity
import com.navinfo.collect.library.data.entity.RenderEntity import com.navinfo.collect.library.data.entity.RenderEntity
import com.navinfo.collect.library.enums.DataCodeEnum import com.navinfo.collect.library.enums.DataCodeEnum
import com.navinfo.collect.library.utils.GeometryTools import com.navinfo.collect.library.utils.GeometryTools
import com.navinfo.collect.library.utils.StrZipUtil
import com.navinfo.omqs.Constant import com.navinfo.omqs.Constant
import io.realm.Realm import io.realm.Realm
import org.json.JSONArray import org.json.JSONArray
@ -25,6 +27,7 @@ class ImportPreProcess {
val defaultTranslateDistance = 3.0 val defaultTranslateDistance = 3.0
val testFlag: Boolean = false val testFlag: Boolean = false
var realm: Realm? = null var realm: Realm? = null
val gson = Gson()
fun checkCircleRoad(renderEntity: RenderEntity): Boolean { fun checkCircleRoad(renderEntity: RenderEntity): Boolean {
val linkInId = renderEntity.properties["linkIn"] val linkInId = renderEntity.properties["linkIn"]
val linkOutId = renderEntity.properties["linkOut"] val linkOutId = renderEntity.properties["linkOut"]
@ -238,6 +241,9 @@ class ImportPreProcess {
startEndReference.properties["qi_table"] = renderEntity.table startEndReference.properties["qi_table"] = renderEntity.table
startEndReference.properties["type"] = "s_2_e" startEndReference.properties["type"] = "s_2_e"
val listResult = mutableListOf<ReferenceEntity>() val listResult = mutableListOf<ReferenceEntity>()
startEndReference.propertiesDb = StrZipUtil.compress(
gson.toJson(startEndReference.properties).toString()
)
listResult.add(startEndReference) listResult.add(startEndReference)
insertData(listResult) insertData(listResult)
} }
@ -287,6 +293,9 @@ class ImportPreProcess {
Log.e("qj", "generateS2EReferencePoint===${startReference.geometry}") Log.e("qj", "generateS2EReferencePoint===${startReference.geometry}")
startReference.properties["geometry"] = startReference.geometry startReference.properties["geometry"] = startReference.geometry
startReference.propertiesDb = StrZipUtil.compress(
gson.toJson(startReference.properties).toString()
)
listResult.add(startReference) listResult.add(startReference)
Log.e("qj", "generateS2EReferencePoint===1") Log.e("qj", "generateS2EReferencePoint===1")
@ -321,7 +330,9 @@ class ImportPreProcess {
Log.e("qj", "generateS2EReferencePoint===e_2_p${renderEntity.name}") Log.e("qj", "generateS2EReferencePoint===e_2_p${renderEntity.name}")
} }
endReference.properties["geometry"] = endReference.geometry endReference.properties["geometry"] = endReference.geometry
endReference.propertiesDb = StrZipUtil.compress(
gson.toJson(endReference.properties).toString()
)
listResult.add(endReference) listResult.add(endReference)
Log.e("qj", "generateS2EReferencePoint===4") Log.e("qj", "generateS2EReferencePoint===4")
insertData(listResult) insertData(listResult)
@ -419,6 +430,9 @@ class ImportPreProcess {
WKTWriter(3).write(GeometryTools.createLineString(arrayOf(pointStart, coorEnd))) WKTWriter(3).write(GeometryTools.createLineString(arrayOf(pointStart, coorEnd)))
angleReference.properties["qi_table"] = renderEntity.table angleReference.properties["qi_table"] = renderEntity.table
angleReference.properties["type"] = "angle" angleReference.properties["type"] = "angle"
angleReference.propertiesDb = StrZipUtil.compress(
gson.toJson(angleReference.properties).toString()
)
listResult.add(angleReference) listResult.add(angleReference)
} }
insertData(listResult) insertData(listResult)
@ -513,6 +527,9 @@ class ImportPreProcess {
referenceEntity.properties["symbol"] = referenceEntity.properties["symbol"] =
"assets:omdb/4601/${type}/1301_${referenceEntity.properties["currentDirect"]}.svg" "assets:omdb/4601/${type}/1301_${referenceEntity.properties["currentDirect"]}.svg"
Log.d("unpackingLaneInfo", referenceEntity.properties["symbol"].toString()) Log.d("unpackingLaneInfo", referenceEntity.properties["symbol"].toString())
referenceEntity.propertiesDb = StrZipUtil.compress(
gson.toJson(referenceEntity.properties).toString()
)
listResult.add(referenceEntity) listResult.add(referenceEntity)
} }
insertData(listResult) insertData(listResult)
@ -644,6 +661,9 @@ class ImportPreProcess {
angleReference.taskId = renderEntity.taskId angleReference.taskId = renderEntity.taskId
angleReference.enable = renderEntity.enable angleReference.enable = renderEntity.enable
val listResult = mutableListOf<ReferenceEntity>() val listResult = mutableListOf<ReferenceEntity>()
angleReference.propertiesDb = StrZipUtil.compress(
gson.toJson(angleReference.properties).toString()
)
listResult.add(angleReference) listResult.add(angleReference)
insertData(listResult) insertData(listResult)
} catch (e: Exception) { } catch (e: Exception) {
@ -678,6 +698,9 @@ class ImportPreProcess {
GeometryTools.createGeometry(nodeJSONObject["geometry"].toString()).toString() GeometryTools.createGeometry(nodeJSONObject["geometry"].toString()).toString()
intersectionReference.properties["qi_table"] = renderEntity.table intersectionReference.properties["qi_table"] = renderEntity.table
intersectionReference.properties["type"] = "node" intersectionReference.properties["type"] = "node"
intersectionReference.propertiesDb = StrZipUtil.compress(
gson.toJson(intersectionReference.properties).toString()
)
listResult.add(intersectionReference) listResult.add(intersectionReference)
} }
insertData(listResult) insertData(listResult)
@ -846,6 +869,9 @@ class ImportPreProcess {
dynamicSrcReference.properties["type"] = "dynamicSrc" dynamicSrcReference.properties["type"] = "dynamicSrc"
val code = renderEntity.properties[codeName] val code = renderEntity.properties[codeName]
dynamicSrcReference.properties["src"] = "${prefix}${code}${suffix}" dynamicSrcReference.properties["src"] = "${prefix}${code}${suffix}"
dynamicSrcReference.propertiesDb = StrZipUtil.compress(
gson.toJson(dynamicSrcReference.properties).toString()
)
listResult.add(dynamicSrcReference) listResult.add(dynamicSrcReference)
} }
insertData(listResult) insertData(listResult)
@ -856,7 +882,7 @@ class ImportPreProcess {
Log.e("qj", "子表插入==") Log.e("qj", "子表插入==")
if (list != null && list.isNotEmpty()) { if (list != null && list.isNotEmpty()) {
Log.e("qj", "子表插入开始==") Log.e("qj", "子表插入开始==")
it.insert(list) it.copyToRealm(list)
Log.e("qj", "子表插入结束==") Log.e("qj", "子表插入结束==")
} }
} }

View File

@ -6,7 +6,6 @@ import androidx.annotation.RequiresApi
import com.navinfo.collect.library.data.entity.HadLinkDvoBean import com.navinfo.collect.library.data.entity.HadLinkDvoBean
import com.navinfo.collect.library.data.entity.QsRecordBean import com.navinfo.collect.library.data.entity.QsRecordBean
import com.navinfo.collect.library.data.entity.RenderEntity import com.navinfo.collect.library.data.entity.RenderEntity
import com.navinfo.collect.library.data.entity.RenderEntity.Companion.LinkTable
import com.navinfo.collect.library.enums.DataCodeEnum import com.navinfo.collect.library.enums.DataCodeEnum
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
@ -206,7 +205,7 @@ class RealmOperateHelper() {
val realm = getSelectTaskRealmInstance() val realm = getSelectTaskRealmInstance()
val realmR = val realmR =
realm.where(RenderEntity::class.java).equalTo("table", "OMDB_RD_LINK_KIND") realm.where(RenderEntity::class.java).equalTo("table", "OMDB_RD_LINK_KIND")
.equalTo("properties['${LinkTable.linkPid}']", linkPid).findFirst() .equalTo("linkPid", linkPid).findFirst()
if (realmR != null) { if (realmR != null) {
link = realm.copyFromRealm(realmR) link = realm.copyFromRealm(realmR)
} }
@ -238,7 +237,7 @@ class RealmOperateHelper() {
// val realm = getSelectTaskRealmInstance() // val realm = getSelectTaskRealmInstance()
val realmR = getSelectTaskRealmTools(realm, RenderEntity::class.java, true) val realmR = getSelectTaskRealmTools(realm, RenderEntity::class.java, true)
.equalTo("properties['${LinkTable.linkPid}']", linkPid).findAll() .equalTo("linkPid", linkPid).findAll()
val dataList = realm.copyFromRealm(realmR) val dataList = realm.copyFromRealm(realmR)

View File

@ -577,62 +577,62 @@ class MainViewModel @Inject constructor(
viewModelScope.launch(Dispatchers.Default) { viewModelScope.launch(Dispatchers.Default) {
//用于定位点捕捉道路 //用于定位点捕捉道路
mapController.locationLayerHandler.niLocationFlow.collect { location -> mapController.locationLayerHandler.niLocationFlow.collect { location ->
//
// //过滤掉无效点 //过滤掉无效点
// if (!naviLocationTest && !GeometryTools.isCheckError( if (!naviLocationTest && !GeometryTools.isCheckError(
// location.longitude, location.longitude,
// location.latitude location.latitude
// ) )
// ) { ) {
// val geometry = GeometryTools.createGeometry( val geometry = GeometryTools.createGeometry(
// GeoPoint( GeoPoint(
// location.latitude, location.longitude location.latitude, location.longitude
// ) )
// ) )
// val tileX = RealmSet<Int>() val tileX = RealmSet<Int>()
// GeometryToolsKt.getTileXByGeometry(geometry.toString(), tileX) GeometryToolsKt.getTileXByGeometry(geometry.toString(), tileX)
// val tileY = RealmSet<Int>() val tileY = RealmSet<Int>()
// GeometryToolsKt.getTileYByGeometry(geometry.toString(), tileY) GeometryToolsKt.getTileYByGeometry(geometry.toString(), tileY)
//
// //遍历存储tile对应的x与y的值 //遍历存储tile对应的x与y的值
// tileX.forEach { x -> tileX.forEach { x ->
// tileY.forEach { y -> tileY.forEach { y ->
// location.tilex = x location.tilex = x
// location.tiley = y location.tiley = y
// } }
// } }
// location.groupId = uuid location.groupId = uuid
// try { try {
// location.timeStamp = DateTimeUtil.getTime(location.time).toString() location.timeStamp = DateTimeUtil.getTime(location.time).toString()
// } catch (e: Exception) { } catch (e: Exception) {
//
// } }
//
// location.taskId = location.taskId =
// sharedPreferences.getInt(Constant.SELECT_TASK_ID, -1).toString() sharedPreferences.getInt(Constant.SELECT_TASK_ID, -1).toString()
//
// //判断如果是连接状态并处于录像模式,标记为有效点 //判断如果是连接状态并处于录像模式,标记为有效点
// if (shareUtil?.connectstate == true && shareUtil?.takeCameraMode == 0) { if (shareUtil?.connectstate == true && shareUtil?.takeCameraMode == 0) {
// location.media = 1 location.media = 1
// } }
// var disance = 0.0 var disance = 0.0
// //增加间距判断 //增加间距判断
// if (lastNiLocaion != null) { if (lastNiLocaion != null) {
// disance = GeometryTools.getDistance( disance = GeometryTools.getDistance(
// location.latitude, location.latitude,
// location.longitude, location.longitude,
// lastNiLocaion!!.latitude, lastNiLocaion!!.latitude,
// lastNiLocaion!!.longitude lastNiLocaion!!.longitude
// ) )
// } }
// //室内整理工具时不能进行轨迹存储判断轨迹间隔要超过2.5并小于60米 //室内整理工具时不能进行轨迹存储判断轨迹间隔要超过2.5并小于60米
// if (Constant.INDOOR_IP.isEmpty() && (disance == 0.0 || (disance > 2.5 && disance < 60))) { if (Constant.INDOOR_IP.isEmpty() && (disance == 0.0 || (disance > 2.5 && disance < 60))) {
// traceDataBase.niLocationDao.insert(location) traceDataBase.niLocationDao.insert(location)
// mapController.markerHandle.addNiLocationMarkerItem(location) mapController.markerHandle.addNiLocationMarkerItem(location)
// mapController.mMapView.vtmMap.updateMap(true) mapController.mMapView.vtmMap.updateMap(true)
// lastNiLocaion = location lastNiLocaion = location
// } }
// } }
} }
} }
@ -654,11 +654,11 @@ class MainViewModel @Inject constructor(
naviEngine!!.bindingRoute(location, point) naviEngine!!.bindingRoute(location, point)
naviMutex.unlock() naviMutex.unlock()
} else { } else {
// captureLink( captureLink(
// GeoPoint( GeoPoint(
// location.latitude, location.longitude location.latitude, location.longitude
// ) )
// ) )
} }
} }
} }
@ -823,7 +823,7 @@ class MainViewModel @Inject constructor(
if (linkList.isNotEmpty()) { if (linkList.isNotEmpty()) {
val link = linkList[0] val link = linkList[0]
val linkId = link.properties[RenderEntity.Companion.LinkTable.linkPid] val linkId = link.linkPid
//看板数据 //看板数据
val signList = mutableListOf<SignBean>() val signList = mutableListOf<SignBean>()
val topSignList = mutableListOf<SignBean>() val topSignList = mutableListOf<SignBean>()
@ -971,7 +971,7 @@ class MainViewModel @Inject constructor(
.equalTo("table", DataCodeEnum.OMDB_RD_LINK_KIND.name) .equalTo("table", DataCodeEnum.OMDB_RD_LINK_KIND.name)
.and() .and()
.equalTo( .equalTo(
"properties['${RenderEntity.Companion.LinkTable.linkPid}']", "linkPid",
outLink outLink
).findFirst() ).findFirst()
if (linkOutEntity != null) { if (linkOutEntity != null) {

View File

@ -23,7 +23,6 @@ import com.blankj.utilcode.util.ToastUtils
import com.navinfo.collect.library.data.entity.AttachmentBean import com.navinfo.collect.library.data.entity.AttachmentBean
import com.navinfo.collect.library.data.entity.HadLinkDvoBean import com.navinfo.collect.library.data.entity.HadLinkDvoBean
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.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.map.OnGeoPointClickListener import com.navinfo.collect.library.map.OnGeoPointClickListener
@ -236,7 +235,7 @@ class EvaluationResultViewModel @Inject constructor(
} else { } else {
val linkList = realmOperateHelper.queryLink(realm, point = point) val linkList = realmOperateHelper.queryLink(realm, point = point)
if (linkList.isNotEmpty()) { if (linkList.isNotEmpty()) {
it.linkId = linkList[0].properties[LinkTable.linkPid] ?: "" it.linkId = linkList[0].linkPid
mapController.lineHandler.showLine(linkList[0].geometry) mapController.lineHandler.showLine(linkList[0].geometry)
Log.e("jingo", "捕捉道路EEE 2") Log.e("jingo", "捕捉道路EEE 2")
return return

View File

@ -114,7 +114,7 @@ class TaskViewModel @Inject constructor(
if (links.isNotEmpty()) { if (links.isNotEmpty()) {
val l = links[0] val l = links[0]
for (link in currentSelectTaskBean!!.hadLinkDvoList) { for (link in currentSelectTaskBean!!.hadLinkDvoList) {
if (link.linkPid == l.properties["linkPid"]) { if (link.linkPid == l.linkPid) {
return@launch return@launch
} }
} }
@ -132,7 +132,7 @@ class TaskViewModel @Inject constructor(
if (links.isNotEmpty()) { if (links.isNotEmpty()) {
val l = links[0] val l = links[0]
for (link in currentSelectTaskBean!!.hadLinkDvoList) { for (link in currentSelectTaskBean!!.hadLinkDvoList) {
if (link.linkPid == l.properties["linkPid"]) { if (link.linkPid == l.linkPid) {
liveDataSelectLink.postValue(link.linkPid) liveDataSelectLink.postValue(link.linkPid)
mapController.lineHandler.showLine(link.geometry) mapController.lineHandler.showLine(link.geometry)
break break
@ -274,8 +274,7 @@ class TaskViewModel @Inject constructor(
liveDataTaskLinks.value = taskBean.hadLinkDvoList liveDataTaskLinks.value = taskBean.hadLinkDvoList
showTaskLinks(taskBean) showTaskLinks(taskBean)
MapParamUtils.setTaskId(taskBean.id) MapParamUtils.setTaskId(taskBean.id)
// Constant.currentSelectTaskFolder = File(Constant.USER_DATA_PATH + "/${taskBean.id}") Constant.currentSelectTaskFolder = File(Constant.USER_DATA_PATH + "/${taskBean.id}")
Constant.currentSelectTaskFolder = File(Constant.USER_DATA_PATH + "/237")
Constant.currentSelectTaskConfig = Constant.currentSelectTaskConfig =
RealmConfiguration.Builder() RealmConfiguration.Builder()
.directory(Constant.currentSelectTaskFolder) .directory(Constant.currentSelectTaskFolder)
@ -566,7 +565,7 @@ class TaskViewModel @Inject constructor(
viewModelScope.launch(Dispatchers.IO) { viewModelScope.launch(Dispatchers.IO) {
val hadLinkDvoBean = HadLinkDvoBean( val hadLinkDvoBean = HadLinkDvoBean(
taskId = currentSelectTaskBean!!.id, taskId = currentSelectTaskBean!!.id,
linkPid = data.properties["linkPid"]!!, linkPid = data.linkPid,
geometry = data.geometry, geometry = data.geometry,
linkStatus = 2 linkStatus = 2
) )
@ -579,7 +578,7 @@ class TaskViewModel @Inject constructor(
r.copyToRealmOrUpdate(currentSelectTaskBean!!) r.copyToRealmOrUpdate(currentSelectTaskBean!!)
} }
//根据Link数据查询对应数据上要素对要素进行显示重置 //根据Link数据查询对应数据上要素对要素进行显示重置
data.properties["linkPid"]?.let { data.linkPid.let {
realmOperateHelper.queryLinkToMutableRenderEntityList(realm, it) realmOperateHelper.queryLinkToMutableRenderEntityList(realm, it)
?.forEach { renderEntity -> ?.forEach { renderEntity ->
if (renderEntity.enable != 1) { if (renderEntity.enable != 1) {

View File

@ -222,7 +222,7 @@ class NaviEngine(
route.pointList = GeometryTools.getGeoPoints(link.geometry) route.pointList = GeometryTools.getGeoPoints(link.geometry)
val res = realm.where(RenderEntity::class.java).`in`("table", QUERY_KEY_LINK_INFO_LIST) val res = realm.where(RenderEntity::class.java).`in`("table", QUERY_KEY_LINK_INFO_LIST)
.equalTo("properties['linkPid']", link.linkPid).findAll() .equalTo("linkPid", link.linkPid).findAll()
var bHasNode = false var bHasNode = false
var bHasDir = false var bHasDir = false
var bHasName = false var bHasName = false
@ -373,7 +373,7 @@ class NaviEngine(
itemMap.clear() itemMap.clear()
//常规点限速 //常规点限速
val res = realm.where(RenderEntity::class.java) val res = realm.where(RenderEntity::class.java)
.equalTo("properties['linkPid']", route.linkId).and().`in`( .equalTo("linkPid", route.linkId).and().`in`(
"table", "table",
QUERY_KEY_ITEM_LIST QUERY_KEY_ITEM_LIST
).findAll() ).findAll()

View File

@ -54,16 +54,10 @@ class NaviEngineNew(
latestRoute?.let { latestRoute?.let {
var lastTime = System.currentTimeMillis()
var nowTime = System.currentTimeMillis()
Log.e("jingo","打开数据库 ${nowTime - lastTime}")
lastTime = nowTime
val res2 = val res2 =
realm.where(RenderEntity::class.java).`in`("table", QUERY_KEY_LINK_INFO_LIST) realm.where(RenderEntity::class.java).`in`("table", QUERY_KEY_LINK_INFO_LIST)
.equalTo("properties['linkPid']", it.linkPid).findAll() .equalTo("linkPid", it.linkPid).findAll()
nowTime = System.currentTimeMillis()
Log.e("jingo", "第一种 耗时 ${nowTime - lastTime}")
if (res2 != null) { if (res2 != null) {
for (entity in res2) { for (entity in res2) {
when (entity.code) { when (entity.code) {

View File

@ -35,7 +35,7 @@ class SignUtil {
return SignBean( return SignBean(
iconId = getSignIcon(element), iconId = getSignIcon(element),
iconText = getSignIconText(element), iconText = getSignIconText(element),
linkId = element.properties[RenderEntity.Companion.LinkTable.linkPid] linkId = element.linkPid
?: "", ?: "",
name = getSignNameText(element), name = getSignNameText(element),
bottomRightText = getSignBottomRightText( bottomRightText = getSignBottomRightText(
@ -207,7 +207,7 @@ class SignUtil {
DataCodeEnum.OMDB_RD_LINK.code -> { DataCodeEnum.OMDB_RD_LINK.code -> {
list.add( list.add(
TwoItemAdapterItem( TwoItemAdapterItem(
title = "linkPid", text = "${data.properties["linkPid"]}" title = "linkPid", text = "${data.linkPid}"
) )
) )
list.add( list.add(
@ -225,7 +225,7 @@ class SignUtil {
DataCodeEnum.OMDB_RD_LINK_KIND.code -> { DataCodeEnum.OMDB_RD_LINK_KIND.code -> {
list.add( list.add(
TwoItemAdapterItem( TwoItemAdapterItem(
title = "linkPid", text = "${data.properties["linkPid"]}" title = "linkPid", text = "${data.linkPid}"
) )
) )
try { try {
@ -243,7 +243,7 @@ class SignUtil {
DataCodeEnum.OMDB_LINK_DIRECT.code -> { DataCodeEnum.OMDB_LINK_DIRECT.code -> {
list.add( list.add(
TwoItemAdapterItem( TwoItemAdapterItem(
title = "linkPid", text = "${data.properties["linkPid"]}" title = "linkPid", text = "${data.linkPid}"
) )
) )
try { try {
@ -331,7 +331,7 @@ class SignUtil {
DataCodeEnum.OMDB_LINK_CONSTRUCTION.code -> { DataCodeEnum.OMDB_LINK_CONSTRUCTION.code -> {
list.add( list.add(
TwoItemAdapterItem( TwoItemAdapterItem(
title = "linkPid", text = "${data.properties["linkPid"]}" title = "linkPid", text = "${data.linkPid}"
) )
) )
@ -384,7 +384,7 @@ class SignUtil {
DataCodeEnum.OMDB_WARNINGSIGN.code -> { DataCodeEnum.OMDB_WARNINGSIGN.code -> {
list.add( list.add(
TwoItemAdapterItem( TwoItemAdapterItem(
title = "linkPid", text = "${data.properties["linkPid"]}" title = "linkPid", text = "${data.linkPid}"
) )
) )
list.add( list.add(
@ -749,7 +749,7 @@ class SignUtil {
fun getTollgateInfo(renderEntity: RenderEntity): List<LaneBoundaryItem> { fun getTollgateInfo(renderEntity: RenderEntity): List<LaneBoundaryItem> {
val list = mutableListOf<LaneBoundaryItem>() val list = mutableListOf<LaneBoundaryItem>()
list.add( list.add(
LaneBoundaryItem("linkPid", "${renderEntity.properties["linkPid"]}", null) LaneBoundaryItem("linkPid", "${renderEntity.linkPid}", null)
) )
list.add( list.add(
LaneBoundaryItem("收费站号码", "${renderEntity.properties["tollgatePid"]}", null) LaneBoundaryItem("收费站号码", "${renderEntity.properties["tollgatePid"]}", null)

View File

@ -1,7 +1,11 @@
package com.navinfo.collect.library.data.entity package com.navinfo.collect.library.data.entity
import android.util.Log
import com.google.gson.Gson
import com.google.gson.reflect.TypeToken
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.collect.library.utils.StrZipUtil
import io.realm.RealmDictionary import io.realm.RealmDictionary
import io.realm.RealmObject import io.realm.RealmObject
import io.realm.RealmSet import io.realm.RealmSet
@ -20,9 +24,12 @@ open class ReferenceEntity() : RealmObject() {
@Ignore @Ignore
lateinit var name: String //要素名 lateinit var name: String //要素名
lateinit var table: String //要素表名 lateinit var table: String //要素表名
var propertiesDb: String = ""
var code: String = "0" // 要素编码 var code: String = "0" // 要素编码
@Ignore @Ignore
var zoomMin: Int = 18 //显示最小级别 var zoomMin: Int = 18 //显示最小级别
@Ignore @Ignore
var zoomMax: Int = 23 //显示最大级别 var zoomMax: Int = 23 //显示最大级别
var taskId: Int = 0 //任务ID var taskId: Int = 0 //任务ID
@ -68,8 +75,21 @@ open class ReferenceEntity() : RealmObject() {
} }
return field return field
} }
@Ignore @Ignore
var properties: RealmDictionary<String> = RealmDictionary() var properties: RealmDictionary<String> = RealmDictionary()
get() {
if (propertiesDb.isNotEmpty() && field.isEmpty()) {
try {
val gson = Gson()
val type = object : TypeToken<RealmDictionary<String>>() {}.type
field = gson.fromJson(StrZipUtil.uncompress(propertiesDb), type)
} catch (e: Exception) {
Log.e("jingo","ReferenceEntity 转 properties $e")
}
}
return field
}
@Ignore @Ignore
var tileX: RealmSet<Int> = RealmSet() // x方向的tile编码 var tileX: RealmSet<Int> = RealmSet() // x方向的tile编码

View File

@ -1,6 +1,7 @@
package com.navinfo.collect.library.data.entity package com.navinfo.collect.library.data.entity
import android.os.Parcelable import android.os.Parcelable
import android.util.Log
import com.google.gson.Gson import com.google.gson.Gson
import com.google.gson.reflect.TypeToken import com.google.gson.reflect.TypeToken
import com.navinfo.collect.library.system.Constant import com.navinfo.collect.library.system.Constant
@ -30,8 +31,7 @@ open class RenderEntity() : RealmObject(), Parcelable {
lateinit var name: String //要素名 lateinit var name: String //要素名
lateinit var table: String //要素表名 lateinit var table: String //要素表名
var code: String = "0" // 要素编码 var code: String = "0" // 要素编码
// var geometryDb: String = "" var propertiesDb: String = ""
var geometry: String = var geometry: String =
"" // 要素渲染参考的geometry该数据可能会在导入预处理环节被修改原始geometry会保存在properties的geometry字段下 "" // 要素渲染参考的geometry该数据可能会在导入预处理环节被修改原始geometry会保存在properties的geometry字段下
get() { get() {
@ -73,7 +73,7 @@ open class RenderEntity() : RealmObject(), Parcelable {
try { try {
field = GeometryTools.createGeometry(geometry) field = GeometryTools.createGeometry(geometry)
} catch (e: Exception) { } catch (e: Exception) {
Log.e("jingo","RenderEntity 转 wkt失败 $e")
} }
} }
return field return field
@ -85,16 +85,15 @@ open class RenderEntity() : RealmObject(), Parcelable {
if (propertiesDb != null && propertiesDb.isNotEmpty() && field.isEmpty()) { if (propertiesDb != null && propertiesDb.isNotEmpty() && field.isEmpty()) {
try { try {
val gson = Gson() val gson = Gson()
val type = object : TypeToken<List<RealmDictionary<String>>>() {}.type val type = object : TypeToken<RealmDictionary<String>>() {}.type
field = gson.fromJson(StrZipUtil.uncompress(propertiesDb), type) field = gson.fromJson(StrZipUtil.uncompress(propertiesDb), type)
} catch (e: Exception) { } catch (e: Exception) {
Log.e("jingo","RenderEntity 转 properties $e")
} }
} }
return field return field
} }
var propertiesDb: String = ""
@Ignore @Ignore
var tileX: RealmSet<Int> = RealmSet() // x方向的tile编码 var tileX: RealmSet<Int> = RealmSet() // x方向的tile编码
@ -117,19 +116,4 @@ open class RenderEntity() : RealmObject(), Parcelable {
constructor(name: String) : this() { constructor(name: String) : this() {
this.name = name this.name = name
} }
companion object {
object LinkTable {
//道路linkId
const val linkPid = "linkPid"
}
object LimitTable {
const val linkPid = "linkPid"
}
object KindCodeTable {
const val linkPid = "linkPid"
}
}
} }

View File

@ -1,40 +0,0 @@
package com.navinfo.collect.library.data.entity
import android.os.Parcelable
import com.navinfo.collect.library.utils.GeometryTools
import com.navinfo.collect.library.utils.GeometryToolsKt
import io.realm.RealmDictionary
import io.realm.RealmObject
import io.realm.RealmSet
import io.realm.annotations.Ignore
import io.realm.annotations.Index
import kotlinx.parcelize.Parcelize
import org.locationtech.jts.geom.Geometry
/**
* 渲染要素对应的实体
* */
@Parcelize
open class RenderEntity1() : RealmObject(), Parcelable {
lateinit var name: String //要素名
lateinit var table: String //要素表名
var code: String = "0" // 要素编码
var geometry: String = ""
var propertiesDb: String = ""
var tileXMin: Int = 0
var tileXMax: Int = 0
var tileYMin: Int = 0
var tileYMax: Int = 0
var taskId: Int = 0 //任务ID
var zoomMin: Int = 18 //显示最小级别
var zoomMax: Int = 23 //显示最大级别
var enable: Int = 0 // 默认0不是显示 1为渲染显示 2为常显
var catchEnable: Int = 0 // 0不捕捉 1捕捉
var linkPid: String = "" // RenderEntity关联的linkPid集合(可能会关联多个)
var linkRelation: LinkRelation? = null
constructor(name: String) : this() {
this.name = name
}
}

View File

@ -43,6 +43,8 @@ public class OMDBReferenceDataSource implements ITileDataSource {
@RequiresApi(api = Build.VERSION_CODES.N) @RequiresApi(api = Build.VERSION_CODES.N)
@Override @Override
public void query(MapTile tile, ITileDataSink mapDataSink) { public void query(MapTile tile, ITileDataSink mapDataSink) {
if(MapParamUtils.getTaskConfig() == null)
return;
// 获取tile对应的坐标范围 // 获取tile对应的坐标范围
if (tile.zoomLevel >= Constant.OMDB_MIN_ZOOM && tile.zoomLevel <= Constant.DATA_ZOOM) { if (tile.zoomLevel >= Constant.OMDB_MIN_ZOOM && tile.zoomLevel <= Constant.DATA_ZOOM) {
Realm realm = Realm.getInstance(MapParamUtils.getTaskConfig()); Realm realm = Realm.getInstance(MapParamUtils.getTaskConfig());

View File

@ -64,16 +64,12 @@ public class OMDBTileDataSource implements ITileDataSource {
@RequiresApi(api = Build.VERSION_CODES.N) @RequiresApi(api = Build.VERSION_CODES.N)
@Override @Override
public void query(MapTile tile, ITileDataSink mapDataSink) { public void query(MapTile tile, ITileDataSink mapDataSink) {
if(MapParamUtils.getTaskConfig() == null)
return;
// 获取tile对应的坐标范围 // 获取tile对应的坐标范围
if (tile.zoomLevel >= Constant.OMDB_MIN_ZOOM && tile.zoomLevel <= Constant.DATA_ZOOM) { if (tile.zoomLevel >= Constant.OMDB_MIN_ZOOM && tile.zoomLevel <= Constant.DATA_ZOOM) {
Realm realm = null; Realm realm = null;
int threadCode = Thread.currentThread().hashCode(); int threadCode = Thread.currentThread().hashCode();
// MapPosition pos = new MapPosition();
// viewport.getMapPosition(pos);
// DataObject newDataObject = new DataObject();
// newDataObject.zoom = tile.zoomLevel;
// newDataObject.threadCode = threadCode;
// newDataObject.lonLat = pos.getX() + "," + pos.getY();
synchronized (realmObjectList) { synchronized (realmObjectList) {
int configCode = MapParamUtils.getTaskConfig().hashCode(); int configCode = MapParamUtils.getTaskConfig().hashCode();
for (RealmObject object : realmObjectList) { for (RealmObject object : realmObjectList) {
@ -96,7 +92,6 @@ public class OMDBTileDataSource implements ITileDataSource {
realmObjectList.add(o); realmObjectList.add(o);
} }
} }
// Log.e("jingo", " " + Realm.getDefaultInstance().hashCode() + " " + Realm.getInstance(MapParamUtils.getTaskConfig()).hashCode());
// Realm realm = Realm.getInstance(MapParamUtils.getTaskConfig()); // Realm realm = Realm.getInstance(MapParamUtils.getTaskConfig());
RealmQuery<RenderEntity> realmQuery = realm.where(RenderEntity.class); RealmQuery<RenderEntity> realmQuery = realm.where(RenderEntity.class);
@ -112,7 +107,6 @@ public class OMDBTileDataSource implements ITileDataSource {
yEnd = (int) (yEnd << m); yEnd = (int) (yEnd << m);
} }
final int currentTileX = xStart;
if (isUpdate) { if (isUpdate) {
realm.refresh(); realm.refresh();
isUpdate = false; isUpdate = false;
@ -124,18 +118,9 @@ public class OMDBTileDataSource implements ITileDataSource {
} else { } else {
sql += " and enable>=0"; sql += " and enable>=0";
} }
realmQuery.rawPredicate(sql); realmQuery.rawPredicate(sql);
if (MapParamUtils.getDataLayerEnum() != null) {
MapParamUtils.getDataLayerEnum().getSql();
}
// realmQuery.greaterThanOrEqualTo("tileXMin", xStart); // 筛选不显示的数据
// realmQuery.lessThanOrEqualTo("tileXMax", xEnd);
// realmQuery.greaterThanOrEqualTo("tileYMin", yStart);
// realmQuery.lessThanOrEqualTo("tileYMax", yEnd);
// realmQuery.like("geometry","116.31509664888955 39.83318797612014 0");
// 筛选不显示的数据
if (Constant.HAD_LAYER_INVISIABLE_ARRAY != null && Constant.HAD_LAYER_INVISIABLE_ARRAY.length > 0) { if (Constant.HAD_LAYER_INVISIABLE_ARRAY != null && Constant.HAD_LAYER_INVISIABLE_ARRAY.length > 0) {
realmQuery.beginGroup(); realmQuery.beginGroup();
for (String type : Constant.HAD_LAYER_INVISIABLE_ARRAY) { for (String type : Constant.HAD_LAYER_INVISIABLE_ARRAY) {
@ -144,43 +129,13 @@ public class OMDBTileDataSource implements ITileDataSource {
realmQuery.endGroup(); realmQuery.endGroup();
} }
long time = System.currentTimeMillis(); long time = System.currentTimeMillis();
List<RenderEntity> listResult = realmQuery/*.distinct("id")*/.findAll(); List<RenderEntity> listResult = realmQuery.findAll();
long newTime = System.currentTimeMillis() - time; long newTime = System.currentTimeMillis() - time;
Log.e("jingo", "当前OMDBTileDataSource " + Thread.currentThread().hashCode() + " 当前realm " + realm.hashCode() + " 查询耗时" + newTime ); Log.e("jingo", "当前OMDBTileDataSource " + Thread.currentThread().hashCode() + " 当前realm " + realm.hashCode() + " 查询耗时" + newTime + " 条数" + listResult.size());
// 数据记录的tile号是以正外接tile号列表此处过滤并未与当前tile相交的数据 // 数据记录的tile号是以正外接tile号列表此处过滤并未与当前tile相交的数据
if (!listResult.isEmpty()) { if (!listResult.isEmpty()) {
Polygon tilePolygon = GeometryTools.getTilePolygon(tile); Polygon tilePolygon = GeometryTools.getTilePolygon(tile);
// System.out.println("第一条数据的最小x值:" + listResult.get(0).getTileX().stream().min(Integer::compare).get());
// System.out.println("当前tile的:" + listResult.get(0).getTileX().stream().min(Integer::compare).get());
// synchronized (dataObjectList) {
// int index = -1;
// for (int i = 0; i < dataObjectList.size(); i++) {
// DataObject dataObject = dataObjectList.get(i);
// if (dataObject.threadCode == newDataObject.threadCode) {
// index = i;
// } else if (dataObject.zoom == tile.zoomLevel && dataObject.lonLat.equals(newDataObject.lonLat)) {
// listResult = listResult.stream().filter((RenderEntity renderEntity) -> {
// for (String id : dataObject.listIds) {
// if (id.equals(renderEntity.getId())) {
// return false;
// }
// }
// return renderEntity.getWkt().intersects(tilePolygon);
// })
// /*过滤数据只有最小x屏幕的最小x或数据的最小x会被渲染跨Tile的其他数据不再重复渲染*/
//// .filter((RenderEntity renderEntity) -> MercatorProjection.longitudeToTileX(viewport.fromScreenPoint(0,0).getLongitude(), (byte) Constant.DATA_ZOOM) == currentTileX || renderEntity.getTileX().stream().min(Integer::compare).get() == currentTileX)
// .collect(Collectors.toList());
// }
// }
// if (index > -1) {
// dataObjectList.remove(index);
// }
// for (RenderEntity renderEntity : listResult) {
// newDataObject.listIds.add(renderEntity.getId());
// }
// dataObjectList.add(newDataObject);
// }
listResult = listResult.stream().filter((RenderEntity renderEntity) -> listResult = listResult.stream().filter((RenderEntity renderEntity) ->
renderEntity.getWkt().intersects(tilePolygon) renderEntity.getWkt().intersects(tilePolygon)
) )
@ -192,12 +147,10 @@ public class OMDBTileDataSource implements ITileDataSource {
} else { } else {
mapDataSink.completed(QueryResult.SUCCESS); mapDataSink.completed(QueryResult.SUCCESS);
} }
// realm.close(); // realm.close();
} else { } else {
mapDataSink.completed(QueryResult.SUCCESS); mapDataSink.completed(QueryResult.SUCCESS);
} }
} }
@Override @Override

View File

@ -35,6 +35,7 @@ public class RealmDBTileDataSource implements ITileDataSource {
public void query(MapTile tile, ITileDataSink mapDataSink) { public void query(MapTile tile, ITileDataSink mapDataSink) {
// 获取tile对应的坐标范围 // 获取tile对应的坐标范围
if (tile.zoomLevel>=15&&tile.zoomLevel<=Constant.OVER_ZOOM) { if (tile.zoomLevel>=15&&tile.zoomLevel<=Constant.OVER_ZOOM) {
Log.e("jingo","RealmDBTileDataSource RealmDBTileDataSource RealmDBTileDataSource");
// int m = Constant.OVER_ZOOM-tile.zoomLevel; // int m = Constant.OVER_ZOOM-tile.zoomLevel;
// int xStart = (int)tile.tileX<<m; // int xStart = (int)tile.tileX<<m;
// int xEnd = (int)((tile.tileX+1)<<m); // int xEnd = (int)((tile.tileX+1)<<m);