开发路径导航功能
This commit is contained in:
43
app/src/main/java/com/navinfo/omqs/bean/NaviRoute.kt
Normal file
43
app/src/main/java/com/navinfo/omqs/bean/NaviRoute.kt
Normal file
@@ -0,0 +1,43 @@
|
||||
package com.navinfo.omqs.bean
|
||||
|
||||
import com.navinfo.collect.library.data.entity.RenderEntity
|
||||
import com.navinfo.collect.library.utils.GeometryTools
|
||||
import org.oscim.core.GeoPoint
|
||||
|
||||
data class NaviRoute(
|
||||
//我是整条路径中的第几段路径
|
||||
var indexInPath: Int = -1,
|
||||
//link id
|
||||
val linkId: String,
|
||||
//起点id
|
||||
var sNode: String = "",
|
||||
//终点id
|
||||
var eNode: String = "",
|
||||
//方向
|
||||
var direct: Int = 0,
|
||||
//道路名称
|
||||
var name: String = "",
|
||||
//路段总长
|
||||
var length: Double = 0.0,
|
||||
//当前link在整段路径中的起点
|
||||
var startIndexInPath: Int = -1,
|
||||
//当前link在整段路径中的终点
|
||||
var endIndexIntPath: Int = -1,
|
||||
var itemList: MutableList<NaviRouteItem>? = null
|
||||
) {
|
||||
var pointList: MutableList<GeoPoint> = mutableListOf()
|
||||
get() {
|
||||
return field
|
||||
}
|
||||
set(value) {
|
||||
length = GeometryTools.getDistance(value)
|
||||
field = value
|
||||
}
|
||||
}
|
||||
|
||||
data class NaviRouteItem(
|
||||
var index: Int,
|
||||
val data: RenderEntity,
|
||||
val linkId: String,
|
||||
var distance: Int = -1
|
||||
)
|
||||
@@ -1,24 +0,0 @@
|
||||
package com.navinfo.omqs.bean
|
||||
|
||||
import com.navinfo.collect.library.utils.GeometryTools
|
||||
import com.navinfo.collect.library.utils.GeometryToolsKt
|
||||
import org.locationtech.jts.geom.Geometry
|
||||
import org.oscim.core.GeoPoint
|
||||
|
||||
data class Route(
|
||||
val linkId: String,
|
||||
var sNode: String = "",
|
||||
var eNode: String = "",
|
||||
var direct: Int = 0,
|
||||
var name: String = "",
|
||||
var length: Double = 0.0,
|
||||
) {
|
||||
var pointList: MutableList<GeoPoint> = mutableListOf()
|
||||
get() {
|
||||
return field
|
||||
}
|
||||
set(value) {
|
||||
length = GeometryTools.getDistance(value)
|
||||
field = value
|
||||
}
|
||||
}
|
||||
@@ -388,8 +388,12 @@ class MainActivity : BaseActivity() {
|
||||
}
|
||||
}
|
||||
|
||||
viewModel.listDataMessage.observe(this) {
|
||||
Toast.makeText(this, it, Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
|
||||
viewModel.liveDataItemList.observe(this) {
|
||||
if(it.isNotEmpty()) {
|
||||
if (it.isNotEmpty()) {
|
||||
if (leftFragment == null || leftFragment !is ItemListFragment) {
|
||||
leftFragment = ItemListFragment {
|
||||
binding.mainActivityLeftFragment.visibility = View.GONE
|
||||
|
||||
@@ -123,6 +123,11 @@ class MainViewModel @Inject constructor(
|
||||
*/
|
||||
val liveDataItemList = MutableLiveData<List<RenderEntity>>()
|
||||
|
||||
/**
|
||||
* 提示信息
|
||||
*/
|
||||
val listDataMessage = MutableLiveData<String>()
|
||||
|
||||
private var traceTag: String = "TRACE_TAG"
|
||||
|
||||
/**
|
||||
@@ -217,15 +222,15 @@ class MainViewModel @Inject constructor(
|
||||
private var currentMapZoomLevel: Int = 0
|
||||
|
||||
//导航信息
|
||||
private var naviEngine: NaviEngine = NaviEngine()
|
||||
private var naviEngine: NaviEngine? = null
|
||||
|
||||
//规划成功
|
||||
private var naviPathSuccess = false
|
||||
|
||||
// 定义一个互斥锁
|
||||
private val naviMutex = Mutex()
|
||||
|
||||
|
||||
init {
|
||||
|
||||
|
||||
mapController.mMapView.vtmMap.events.bind(Map.UpdateListener { e, mapPosition ->
|
||||
when (e) {
|
||||
Map.SCALE_EVENT, Map.MOVE_EVENT, Map.ROTATE_EVENT -> liveDataCenterPoint.value =
|
||||
@@ -317,45 +322,28 @@ class MainViewModel @Inject constructor(
|
||||
MapParamUtils.setTaskId(sharedPreferences.getInt(Constant.SELECT_TASK_ID, -1))
|
||||
socketServer = SocketServer(mapController, traceDataBase, sharedPreferences)
|
||||
|
||||
// viewModelScope.launch(Dispatchers.Default) {
|
||||
// naviTestFlow().collect {
|
||||
// naviMutex.lock()
|
||||
// if (naviEngine.geometry != null) {
|
||||
// //定义垂线
|
||||
// val pointPairDistance = PointPairDistance()
|
||||
// val coordinate = Coordinate(it.longitude, it.latitude)
|
||||
// DistanceToPoint.computeDistance(
|
||||
// naviEngine.geometry,
|
||||
// coordinate,
|
||||
// pointPairDistance
|
||||
// )
|
||||
// if (pointPairDistance.getCoordinate(0) !== null) {
|
||||
// val line = GeometryTools.createLineString(
|
||||
// mutableListOf(
|
||||
// it,
|
||||
// GeoPoint(
|
||||
// pointPairDistance.getCoordinate(0).y,
|
||||
// pointPairDistance.getCoordinate(0).x
|
||||
// )
|
||||
// )
|
||||
// )
|
||||
// mapController.lineHandler.showLine(line.toText())
|
||||
viewModelScope.launch(Dispatchers.Default) {
|
||||
// naviTestFlow().collect { point ->
|
||||
// if (naviPathSuccess) {
|
||||
// naviEngine?.let {
|
||||
// naviMutex.lock()
|
||||
// it.bindingRoute(null, point)
|
||||
// naviMutex.unlock()
|
||||
// }
|
||||
// }
|
||||
// naviMutex.unlock()
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
|
||||
fun naviTestFlow(): Flow<GeoPoint> = flow {
|
||||
|
||||
while (true) {
|
||||
emit(mapController.mMapView.vtmMap.mapPosition.geoPoint)
|
||||
delay(1000)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// fun naviTestFlow(): Flow<GeoPoint> = flow {
|
||||
//
|
||||
// while (true) {
|
||||
// emit(mapController.mMapView.vtmMap.mapPosition.geoPoint)
|
||||
// delay(1000)
|
||||
// }
|
||||
// }
|
||||
|
||||
/**
|
||||
* 获取当前任务
|
||||
*/
|
||||
@@ -365,7 +353,7 @@ class MainViewModel @Inject constructor(
|
||||
val res = realm.where(TaskBean::class.java).equalTo("id", id).findFirst()
|
||||
if (res != null) {
|
||||
currentTaskBean = realm.copyFromRealm(res)
|
||||
planningPath(currentTaskBean!!)
|
||||
// planningPath(currentTaskBean!!)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -375,135 +363,44 @@ class MainViewModel @Inject constructor(
|
||||
// Toast.makeText(context, "正在计算导航路径", Toast.LENGTH_SHORT).show()
|
||||
viewModelScope.launch(Dispatchers.Default) {
|
||||
naviMutex.lock()
|
||||
naviEngine = NaviEngine()
|
||||
val pathList = mutableListOf<Route>()
|
||||
val realm = Realm.getDefaultInstance()
|
||||
for (link in taskBean.hadLinkDvoList) {
|
||||
//测线不参与导航
|
||||
if (link.linkStatus == 3) {
|
||||
continue
|
||||
}
|
||||
val route = Route(
|
||||
linkId = link.linkPid,
|
||||
)
|
||||
route.pointList = GeometryTools.getGeoPoints(link.geometry)
|
||||
//查询每条link的snode,enode
|
||||
val res1 = realm.where(RenderEntity::class.java)
|
||||
.equalTo("table", DataCodeEnum.OMDB_RD_LINK.name).and()
|
||||
.equalTo("properties['linkPid']", link.linkPid).findFirst()
|
||||
res1?.let {
|
||||
naviEngine = NaviEngine(
|
||||
niMapController = mapController,
|
||||
callback = object : OnNaviEngineCallbackListener {
|
||||
override fun planningPathSuccess() {
|
||||
naviPathSuccess = true
|
||||
listDataMessage.postValue("导航路径规划完成")
|
||||
}
|
||||
|
||||
val snodePid = it.properties["snodePid"]
|
||||
if (snodePid != null) {
|
||||
route.sNode = snodePid
|
||||
override fun planningPathError(errorCode: Int, errorMessage: String) {
|
||||
naviPathSuccess = false
|
||||
listDataMessage.postValue(errorMessage)
|
||||
}
|
||||
val enodePid = it.properties["enodePid"]
|
||||
if (enodePid != null) {
|
||||
route.eNode = enodePid
|
||||
}
|
||||
}
|
||||
//查询每条link的方向
|
||||
val res2 = realm.where(RenderEntity::class.java)
|
||||
.equalTo("table", DataCodeEnum.OMDB_LINK_DIRECT.name).and()
|
||||
.equalTo("properties['linkPid']", link.linkPid).findFirst()
|
||||
res2?.let {
|
||||
val direct = it.properties["direct"]
|
||||
if (direct != null) {
|
||||
route.direct = direct.toInt()
|
||||
}
|
||||
}
|
||||
//查询每条link的名称
|
||||
val res3 = realm.where(RenderEntity::class.java)
|
||||
.equalTo("table", DataCodeEnum.OMDB_LINK_NAME.name).and()
|
||||
.equalTo("properties['linkPid']", link.linkPid).findFirst()
|
||||
res3?.let {
|
||||
route.name = "${it.properties["name"]}"
|
||||
}
|
||||
pathList.add(route)
|
||||
}
|
||||
//用来存储最终的导航路径
|
||||
val newRouteList = mutableListOf<Route>()
|
||||
//比对路径排序用的
|
||||
val tempRouteList = pathList.toMutableList()
|
||||
//先找到一根有方向的link,确定起终点
|
||||
var routeStart: Route? = null
|
||||
for (i in tempRouteList.indices) {
|
||||
val route = pathList[i]
|
||||
//只要时单方向的就行
|
||||
if (route.direct == 2 || route.direct == 3) {
|
||||
routeStart = route
|
||||
tempRouteList.removeAt(i)
|
||||
break
|
||||
}
|
||||
}
|
||||
if (routeStart != null) {
|
||||
var sNode = ""
|
||||
var eNode = ""
|
||||
//如果snode,enode是顺方向,geometry 不动,否则反转
|
||||
if (routeStart.direct == 3) {
|
||||
routeStart.pointList.reverse()
|
||||
sNode = routeStart.eNode
|
||||
eNode = routeStart.sNode
|
||||
} else {
|
||||
sNode = routeStart.sNode
|
||||
eNode = routeStart.eNode
|
||||
}
|
||||
newRouteList.add(routeStart)
|
||||
var bBreak = true
|
||||
while (bBreak) {
|
||||
//先找其实link的后续link
|
||||
var bHasNext = false
|
||||
for (route in tempRouteList) {
|
||||
//如果是link 的e 对下个link的s,方向不用动,否则下个link的geometry反转
|
||||
if (route.sNode != "" && eNode == route.sNode) {
|
||||
newRouteList.add(route)
|
||||
tempRouteList.remove(route)
|
||||
eNode = route.eNode
|
||||
bHasNext = true
|
||||
break
|
||||
} else if (route.eNode != "" && eNode == route.eNode) {
|
||||
route.pointList.reverse()
|
||||
newRouteList.add(route)
|
||||
tempRouteList.remove(route)
|
||||
eNode = route.sNode
|
||||
bHasNext = true
|
||||
break
|
||||
|
||||
override fun bindingResults(list: List<NaviRouteItem>) {
|
||||
val signList = mutableListOf<SignBean>()
|
||||
for (naviRouteItem in list) {
|
||||
val signBean = SignBean(
|
||||
iconId = SignUtil.getSignIcon(naviRouteItem.data),
|
||||
iconText = SignUtil.getSignIconText(naviRouteItem.data),
|
||||
linkId = naviRouteItem.linkId,
|
||||
distance = naviRouteItem.distance,
|
||||
name = SignUtil.getSignNameText(naviRouteItem.data),
|
||||
bottomRightText = SignUtil.getSignBottomRightText(naviRouteItem.data),
|
||||
renderEntity = naviRouteItem.data,
|
||||
isMoreInfo = SignUtil.isMoreInfo(naviRouteItem.data),
|
||||
index = SignUtil.getRoadInfoIndex(naviRouteItem.data)
|
||||
)
|
||||
signList.add(signBean)
|
||||
}
|
||||
liveDataSignList.postValue(signList)
|
||||
}
|
||||
//先找其实link的起始link
|
||||
var bHasLast = false
|
||||
for (route in tempRouteList) {
|
||||
//如果是link 的s 对上个link的e,方向不用动,否则下个link的geometry反转
|
||||
if (route.eNode != "" && sNode == route.eNode) {
|
||||
newRouteList.add(0, route)
|
||||
tempRouteList.remove(route)
|
||||
sNode = route.sNode
|
||||
bHasLast = true
|
||||
break
|
||||
} else if (route.sNode != "" && sNode == route.sNode) {
|
||||
route.pointList.reverse()
|
||||
newRouteList.add(0, route)
|
||||
tempRouteList.remove(route)
|
||||
sNode = route.eNode
|
||||
bHasLast = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if (tempRouteList.size == 0) {
|
||||
bBreak = false
|
||||
} else {
|
||||
if (!bHasLast && !bHasNext) {
|
||||
bBreak = false
|
||||
//TODO 处理错误,路径不完整
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
naviEngine.routeList = newRouteList
|
||||
})
|
||||
listDataMessage.postValue("开始导航路径规划")
|
||||
naviEngine!!.planningPath(taskBean)
|
||||
naviMutex.unlock()
|
||||
}
|
||||
} else {
|
||||
// Toast.makeText(context, "数据未安装,无法计算导航路径", Toast.LENGTH_SHORT).show()
|
||||
listDataMessage.postValue("数据未安装,无法计算导航路径")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -720,14 +617,9 @@ class MainViewModel @Inject constructor(
|
||||
continue
|
||||
}
|
||||
|
||||
val distance = GeometryTools.distanceToDouble(
|
||||
point, GeometryTools.createGeoPoint(element.geometry)
|
||||
)
|
||||
|
||||
val signBean = SignBean(
|
||||
iconId = SignUtil.getSignIcon(element),
|
||||
iconText = SignUtil.getSignIconText(element),
|
||||
distance = distance.toInt(),
|
||||
linkId = linkId,
|
||||
name = SignUtil.getSignNameText(element),
|
||||
bottomRightText = SignUtil.getSignBottomRightText(element),
|
||||
@@ -735,7 +627,7 @@ class MainViewModel @Inject constructor(
|
||||
isMoreInfo = SignUtil.isMoreInfo(element),
|
||||
index = SignUtil.getRoadInfoIndex(element)
|
||||
)
|
||||
Log.e("jingo", "捕捉到的数据code ${element.code}")
|
||||
// Log.e("jingo", "捕捉到的数据code ${element.code}")
|
||||
when (element.code) {
|
||||
DataCodeEnum.OMDB_MULTI_DIGITIZED.code,//上下线分离
|
||||
DataCodeEnum.OMDB_CON_ACCESS.code,//全封闭
|
||||
@@ -864,6 +756,7 @@ class MainViewModel @Inject constructor(
|
||||
*/
|
||||
fun onClickLocationButton() {
|
||||
mapController.locationLayerHandler.animateToCurrentPosition()
|
||||
planningPath(currentTaskBean!!)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -872,6 +765,7 @@ class MainViewModel @Inject constructor(
|
||||
fun onClickMenu() {
|
||||
menuState = !menuState
|
||||
liveDataMenuState.postValue(menuState)
|
||||
naviEngine!!.bindingRoute(null, mapController.mMapView.vtmMap.mapPosition.geoPoint)
|
||||
}
|
||||
|
||||
override fun onCleared() {
|
||||
@@ -1004,7 +898,7 @@ class MainViewModel @Inject constructor(
|
||||
* */
|
||||
fun refreshOMDBLayer(layerConfigList: List<ImportConfig>) {
|
||||
// 根据获取到的配置信息,筛选未勾选的图层名称
|
||||
if (layerConfigList != null && !layerConfigList.isEmpty()) {
|
||||
if (layerConfigList != null && layerConfigList.isNotEmpty()) {
|
||||
val omdbVisibleList = mutableListOf<String>()
|
||||
layerConfigList.forEach {
|
||||
omdbVisibleList.addAll(it.tableMap.filter { entry ->
|
||||
|
||||
@@ -128,6 +128,7 @@ class SignAdapter(private var listener: OnSignAdapterClickListener?) :
|
||||
} else {
|
||||
bd.signMainInfo.visibility = View.GONE
|
||||
}
|
||||
bd.signDistanceText.text = "${item.distance}米"
|
||||
bd.signSecondIcon.text = ""
|
||||
if (item.renderEntity.code == DataCodeEnum.OMDB_SPEEDLIMIT.code) {
|
||||
val minSpeed = SignUtil.getSpeedLimitMinText(item.renderEntity)
|
||||
|
||||
@@ -12,18 +12,15 @@ import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import com.navinfo.collect.library.data.dao.impl.TraceDataBase
|
||||
import com.navinfo.collect.library.data.entity.*
|
||||
import com.navinfo.collect.library.enums.DataCodeEnum
|
||||
import com.navinfo.collect.library.map.NIMapController
|
||||
import com.navinfo.collect.library.map.OnGeoPointClickListener
|
||||
import com.navinfo.collect.library.utils.GeometryTools
|
||||
import com.navinfo.collect.library.utils.MapParamUtils
|
||||
import com.navinfo.omqs.Constant
|
||||
import com.navinfo.omqs.bean.Route
|
||||
import com.navinfo.omqs.db.RealmOperateHelper
|
||||
import com.navinfo.omqs.http.NetResult
|
||||
import com.navinfo.omqs.http.NetworkService
|
||||
import com.navinfo.omqs.tools.FileManager
|
||||
import com.navinfo.omqs.ui.activity.login.LoginStatus
|
||||
import com.navinfo.omqs.ui.dialog.FirstDialog
|
||||
import com.navinfo.omqs.util.DateTimeUtil
|
||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||
|
||||
@@ -1,25 +1,626 @@
|
||||
package com.navinfo.omqs.util
|
||||
|
||||
import android.util.Log
|
||||
import com.navinfo.collect.library.data.entity.NiLocation
|
||||
import com.navinfo.collect.library.data.entity.RenderEntity
|
||||
import com.navinfo.collect.library.data.entity.TaskBean
|
||||
import com.navinfo.collect.library.enums.DataCodeEnum
|
||||
import com.navinfo.collect.library.map.NIMapController
|
||||
import com.navinfo.collect.library.utils.GeometryTools
|
||||
import com.navinfo.omqs.bean.Route
|
||||
import com.navinfo.omqs.bean.NaviRoute
|
||||
import com.navinfo.omqs.bean.NaviRouteItem
|
||||
import io.realm.Realm
|
||||
import io.realm.RealmQuery
|
||||
import org.locationtech.jts.geom.LineString
|
||||
import org.locationtech.jts.geom.Point
|
||||
import org.oscim.core.GeoPoint
|
||||
|
||||
class NaviEngine {
|
||||
public interface OnNaviEngineCallbackListener {
|
||||
fun planningPathSuccess()
|
||||
fun planningPathError(errorCode: Int, errorMessage: String)
|
||||
fun bindingResults(list: List<NaviRouteItem>)
|
||||
}
|
||||
|
||||
|
||||
class NaviEngine(val niMapController: NIMapController, val callback: OnNaviEngineCallbackListener) {
|
||||
|
||||
|
||||
private val QUERY_KEY_LIST = arrayOf(
|
||||
DataCodeEnum.OMDB_SPEEDLIMIT.name,
|
||||
DataCodeEnum.OMDB_SPEEDLIMIT_COND.name,
|
||||
DataCodeEnum.OMDB_SPEEDLIMIT_VAR.name,
|
||||
DataCodeEnum.OMDB_TRAFFICLIGHT.name,
|
||||
DataCodeEnum.OMDB_RESTRICTION.name,
|
||||
DataCodeEnum.OMDB_LANEINFO.name,
|
||||
DataCodeEnum.OMDB_TRAFFIC_SIGN.name,
|
||||
DataCodeEnum.OMDB_WARNINGSIGN.name,
|
||||
DataCodeEnum.OMDB_TOLLGATE.name
|
||||
)
|
||||
|
||||
/**
|
||||
* 偏离距离 单位:米
|
||||
*/
|
||||
private val DEVIATION_DISTANCE = 150000
|
||||
|
||||
/**
|
||||
* 偏离次数上限
|
||||
*/
|
||||
private val DEVIATION_COUNT = 3
|
||||
|
||||
/**
|
||||
* 局部匹配时,走过的路段还记录100米
|
||||
*/
|
||||
private val PASSED_ROUTE_DISTANCE = 100
|
||||
|
||||
/**
|
||||
* 局部匹配时,没走过的路段还记录1000米
|
||||
*/
|
||||
private val NEXT_ROUTE_DISTANCE = 1000
|
||||
|
||||
/**
|
||||
* 最远显示距离 米
|
||||
*/
|
||||
private val FARTHEST_DISPLAY_DISTANCE = 550
|
||||
|
||||
/**
|
||||
* 绑定失败次数
|
||||
*/
|
||||
private var errorCount = 0
|
||||
|
||||
/**
|
||||
* 当前邦定的那段route
|
||||
*/
|
||||
private var routeIndex = -1
|
||||
|
||||
/**
|
||||
* 当前绑定的link上哪个point
|
||||
*/
|
||||
private var footIndex = -1
|
||||
|
||||
/**
|
||||
* 绑定的垂足坐标
|
||||
*/
|
||||
private var footPoint: GeoPoint? = null
|
||||
|
||||
/**
|
||||
* 上一次定位绑到路线的距离
|
||||
*/
|
||||
private var lastDistance = -1
|
||||
|
||||
/**
|
||||
* 整条路的几何
|
||||
*/
|
||||
var geometry: LineString? = null
|
||||
var routeList = mutableListOf<Route>()
|
||||
|
||||
/**
|
||||
* 临时路径
|
||||
*/
|
||||
var tempGeometry: LineString? = null
|
||||
|
||||
/**
|
||||
* 定位点集合
|
||||
*/
|
||||
private var locationList: MutableList<NiLocation> = mutableListOf()
|
||||
|
||||
/**
|
||||
* 局部匹配时的路段
|
||||
*/
|
||||
var tempRoutList = mutableListOf<NaviRoute>()
|
||||
|
||||
/**
|
||||
* 所有路段集合
|
||||
*/
|
||||
var routeList = mutableListOf<NaviRoute>()
|
||||
get() {
|
||||
return field
|
||||
}
|
||||
set(value) {
|
||||
val list = mutableListOf<GeoPoint>()
|
||||
list.addAll(value[0].pointList)
|
||||
val fRoute = value[0]
|
||||
//第一个路段加入
|
||||
list.addAll(fRoute.pointList)
|
||||
//起始点位置
|
||||
fRoute.startIndexInPath = 0
|
||||
var startPoint = fRoute.pointList.size - 1
|
||||
//终点位置
|
||||
fRoute.endIndexIntPath = startPoint
|
||||
fRoute.indexInPath = 0
|
||||
|
||||
for (i in 1 until value.size) {
|
||||
val list2 = value[i].pointList
|
||||
val route = value[i]
|
||||
route.startIndexInPath = startPoint
|
||||
if (route.itemList != null) {
|
||||
for (naviItem in route.itemList!!) {
|
||||
naviItem.index += startPoint
|
||||
}
|
||||
}
|
||||
startPoint += route.pointList.size - 1
|
||||
route.endIndexIntPath = startPoint
|
||||
route.indexInPath = i
|
||||
val list2 = ArrayList(route.pointList.toList())
|
||||
list2.removeAt(0)
|
||||
list.addAll(list2)
|
||||
}
|
||||
geometry = GeometryTools.createLineString(list)
|
||||
field = value
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算路径
|
||||
*/
|
||||
suspend fun planningPath(taskBean: TaskBean) {
|
||||
|
||||
val pathList = mutableListOf<NaviRoute>()
|
||||
val realm = Realm.getDefaultInstance()
|
||||
for (link in taskBean.hadLinkDvoList) {
|
||||
//测线不参与导航
|
||||
if (link.linkStatus == 3) {
|
||||
continue
|
||||
}
|
||||
val route = NaviRoute(
|
||||
linkId = link.linkPid,
|
||||
)
|
||||
|
||||
route.pointList = GeometryTools.getGeoPoints(link.geometry)
|
||||
//查询每条link的snode,enode
|
||||
val res1 = realm.where(RenderEntity::class.java)
|
||||
.equalTo("table", DataCodeEnum.OMDB_RD_LINK.name).and()
|
||||
.equalTo("properties['linkPid']", link.linkPid).findFirst()
|
||||
res1?.let {
|
||||
|
||||
val snodePid = it.properties["snodePid"]
|
||||
if (snodePid != null) {
|
||||
route.sNode = snodePid
|
||||
}
|
||||
val enodePid = it.properties["enodePid"]
|
||||
if (enodePid != null) {
|
||||
route.eNode = enodePid
|
||||
}
|
||||
}
|
||||
//查询每条link的方向
|
||||
val res2 = realm.where(RenderEntity::class.java)
|
||||
.equalTo("table", DataCodeEnum.OMDB_LINK_DIRECT.name).and()
|
||||
.equalTo("properties['linkPid']", link.linkPid).findFirst()
|
||||
res2?.let {
|
||||
val direct = it.properties["direct"]
|
||||
if (direct != null) {
|
||||
route.direct = direct.toInt()
|
||||
}
|
||||
}
|
||||
//查询每条link的名称
|
||||
val res3 = realm.where(RenderEntity::class.java)
|
||||
.equalTo("table", DataCodeEnum.OMDB_LINK_NAME.name).and()
|
||||
.equalTo("properties['linkPid']", link.linkPid).findFirst()
|
||||
res3?.let {
|
||||
route.name = "${it.properties["name"]}"
|
||||
}
|
||||
pathList.add(route)
|
||||
}
|
||||
//用来存储最终的导航路径
|
||||
val newRouteList = mutableListOf<NaviRoute>()
|
||||
//比对路径排序用的
|
||||
val tempRouteList = pathList.toMutableList()
|
||||
//先找到一根有方向的link,确定起终点
|
||||
var routeStart: NaviRoute? = null
|
||||
for (i in tempRouteList.indices) {
|
||||
val route = pathList[i]
|
||||
//只要时单方向的就行
|
||||
if (route.direct == 2 || route.direct == 3) {
|
||||
routeStart = route
|
||||
tempRouteList.removeAt(i)
|
||||
break
|
||||
}
|
||||
}
|
||||
if (routeStart != null) {
|
||||
var sNode = ""
|
||||
var eNode = ""
|
||||
//如果sNode,eNode是顺方向,geometry 不动,否则反转
|
||||
if (routeStart.direct == 3) {
|
||||
routeStart.pointList.reverse()
|
||||
sNode = routeStart.eNode
|
||||
eNode = routeStart.sNode
|
||||
} else {
|
||||
sNode = routeStart.sNode
|
||||
eNode = routeStart.eNode
|
||||
}
|
||||
newRouteList.add(routeStart)
|
||||
var bBreak = true
|
||||
while (bBreak) {
|
||||
//先找其实link的后续link
|
||||
var bHasNext = false
|
||||
for (route in tempRouteList) {
|
||||
//如果是link 的e 对下个link的s,方向不用动,否则下个link的geometry反转
|
||||
if (route.sNode != "" && eNode == route.sNode) {
|
||||
newRouteList.add(route)
|
||||
tempRouteList.remove(route)
|
||||
eNode = route.eNode
|
||||
bHasNext = true
|
||||
break
|
||||
} else if (route.eNode != "" && eNode == route.eNode) {
|
||||
route.pointList.reverse()
|
||||
newRouteList.add(route)
|
||||
tempRouteList.remove(route)
|
||||
eNode = route.sNode
|
||||
bHasNext = true
|
||||
break
|
||||
}
|
||||
}
|
||||
//先找其实link的起始link
|
||||
var bHasLast = false
|
||||
for (route in tempRouteList) {
|
||||
//如果是link 的s 对上个link的e,方向不用动,否则下个link的geometry反转
|
||||
if (route.eNode != "" && sNode == route.eNode) {
|
||||
newRouteList.add(0, route)
|
||||
tempRouteList.remove(route)
|
||||
sNode = route.sNode
|
||||
bHasLast = true
|
||||
break
|
||||
} else if (route.sNode != "" && sNode == route.sNode) {
|
||||
route.pointList.reverse()
|
||||
newRouteList.add(0, route)
|
||||
tempRouteList.remove(route)
|
||||
sNode = route.eNode
|
||||
bHasLast = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if (tempRouteList.size == 0) {
|
||||
bBreak = false
|
||||
} else {
|
||||
if (!bHasLast && !bHasNext) {
|
||||
bBreak = false
|
||||
callback.planningPathError(1, "路径不连通!")
|
||||
realm.close()
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
val itemMap: MutableMap<GeoPoint, MutableList<RenderEntity>> = mutableMapOf()
|
||||
//查询每根link上的关联要素
|
||||
for (route in newRouteList) {
|
||||
//常规点限速
|
||||
var res = realm.where(RenderEntity::class.java)
|
||||
.equalTo("properties['linkPid']", route.linkId).and().`in`(
|
||||
"table",
|
||||
QUERY_KEY_LIST
|
||||
).findAll()
|
||||
if (res != null) {
|
||||
Log.e("jingo", "道路查询预警要素 ${route.linkId} ${res.size}条数据")
|
||||
for (r in res) {
|
||||
Log.e("jingo", "道路查询预警要素 ${r.name}")
|
||||
insertItemToRoute(realm, route, r, itemMap)
|
||||
}
|
||||
}
|
||||
// //条件点限速
|
||||
// res = realm.where(RenderEntity::class.java)
|
||||
// .equalTo("table", DataCodeEnum.OMDB_SPEEDLIMIT_COND.name).and()
|
||||
// .equalTo("properties['linkPid']", route.linkId).findAll()
|
||||
// if(res != null){
|
||||
// for(r in res)
|
||||
// insertItemToRoute(realm, route, r, itemMap)
|
||||
// }
|
||||
// //可变点限速
|
||||
// res = realm.where(RenderEntity::class.java)
|
||||
// .equalTo("table", DataCodeEnum.OMDB_SPEEDLIMIT_VAR.name).and()
|
||||
// .equalTo("properties['linkPid']", route.linkId).findAll()
|
||||
// if(res != null){
|
||||
// for(r in res)
|
||||
// insertItemToRoute(realm, route, r, itemMap)
|
||||
// }
|
||||
// //交通灯
|
||||
// res = realm.where(RenderEntity::class.java)
|
||||
// .equalTo("table", DataCodeEnum.OMDB_TRAFFICLIGHT.name).and()
|
||||
// .equalTo("properties['linkPid']", route.linkId).findAll()
|
||||
// if(res != null){
|
||||
// for(r in res)
|
||||
// insertItemToRoute(realm, route, r, itemMap)
|
||||
// }
|
||||
// //普通交限
|
||||
// res = realm.where(RenderEntity::class.java)
|
||||
// .equalTo("table", DataCodeEnum.OMDB_RESTRICTION.name).and()
|
||||
// .equalTo("properties['linkPid']", route.linkId).findAll()
|
||||
// if(res != null){
|
||||
// for(r in res)
|
||||
// insertItemToRoute(realm, route, r, itemMap)
|
||||
// }
|
||||
// //车信
|
||||
// res = realm.where(RenderEntity::class.java)
|
||||
// .equalTo("table", DataCodeEnum.OMDB_LANEINFO.name).and()
|
||||
// .equalTo("properties['linkPid']", route.linkId).findAll()
|
||||
// if(res != null){
|
||||
// for(r in res)
|
||||
// insertItemToRoute(realm, route, r, itemMap)
|
||||
// }
|
||||
// //交通标牌
|
||||
// res = realm.where(RenderEntity::class.java)
|
||||
// .equalTo("table", DataCodeEnum.OMDB_TRAFFIC_SIGN.name).and()
|
||||
// .equalTo("properties['linkPid']", route.linkId).findAll()
|
||||
// if(res != null){
|
||||
// for(r in res)
|
||||
// insertItemToRoute(realm, route, r, itemMap)
|
||||
// }
|
||||
// //警示信息
|
||||
// res = realm.where(RenderEntity::class.java)
|
||||
// .equalTo("table", DataCodeEnum.OMDB_WARNINGSIGN.name).and()
|
||||
// .equalTo("properties['linkPid']", route.linkId).findAll()
|
||||
// if(res != null){
|
||||
// for(r in res)
|
||||
// insertItemToRoute(realm, route, r, itemMap)
|
||||
// }
|
||||
// //OMDB_TOLLGATE
|
||||
// res = realm.where(RenderEntity::class.java)
|
||||
// .equalTo("table", DataCodeEnum.OMDB_TOLLGATE.name).and()
|
||||
// .equalTo("properties['linkPid']", route.linkId).findAll()
|
||||
// if(res != null){
|
||||
// for(r in res)
|
||||
// insertItemToRoute(realm, route, r, itemMap)
|
||||
// }
|
||||
//对路径上的要素进行排序
|
||||
if (itemMap.isNotEmpty()) {
|
||||
route.itemList = mutableListOf()
|
||||
for (i in route.pointList.indices) {
|
||||
val point = route.pointList[i]
|
||||
if (itemMap.containsKey(point)) {
|
||||
val rEList = itemMap[point]
|
||||
for (item in rEList!!) {
|
||||
val naviRouteItem = NaviRouteItem(i, item, route.linkId)
|
||||
route.itemList!!.add(naviRouteItem)
|
||||
}
|
||||
}
|
||||
}
|
||||
route.itemList!!.sortBy { it.index }
|
||||
}
|
||||
}
|
||||
realm.close()
|
||||
routeList = newRouteList
|
||||
callback.planningPathSuccess()
|
||||
niMapController.lineHandler.showLine(geometry!!.toText())
|
||||
}
|
||||
|
||||
/**
|
||||
* 将要素绑定到路径上
|
||||
*/
|
||||
private fun insertItemToRoute(
|
||||
realm: Realm,
|
||||
route: NaviRoute,
|
||||
res: RenderEntity?,
|
||||
itemMap: MutableMap<GeoPoint, MutableList<RenderEntity>>
|
||||
) {
|
||||
if (res != null) {
|
||||
val geometry = GeometryTools.createGeometry(res.geometry)
|
||||
if (geometry is Point) {
|
||||
//获取一个垂足点
|
||||
val footAndDistance = GeometryTools.pointToLineDistance(
|
||||
GeoPoint(
|
||||
geometry.coordinate.y, geometry.coordinate.x
|
||||
), GeometryTools.createLineString(route.pointList)
|
||||
)
|
||||
val point = GeoPoint(
|
||||
footAndDistance.getCoordinate(0).y, footAndDistance.getCoordinate(0).x
|
||||
)
|
||||
niMapController.markerHandle.addMarker(point, res.id, res.name)
|
||||
route.pointList.add(footAndDistance.footIndex + 1, point)
|
||||
if (itemMap.containsKey(point)) {
|
||||
itemMap[point]!!.add(realm.copyFromRealm(res))
|
||||
} else {
|
||||
itemMap[point] = mutableListOf(realm.copyFromRealm(res))
|
||||
}
|
||||
} else if (geometry is LineString) {
|
||||
//如果是线型数据,取路径的最后一个点
|
||||
val endPoint = route.pointList.last()
|
||||
if (itemMap.containsKey(endPoint)) {
|
||||
itemMap[endPoint]!!.add(realm.copyFromRealm(res))
|
||||
} else {
|
||||
itemMap[endPoint] = mutableListOf(realm.copyFromRealm(res))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 绑定道路
|
||||
*/
|
||||
fun bindingRoute(location: NiLocation?, point: GeoPoint) {
|
||||
if (geometry != null) {
|
||||
//还没有绑定到路径的时候
|
||||
if (routeIndex < 0) {
|
||||
val pointPairDistance = GeometryTools.pointToLineDistance(point, geometry)
|
||||
//定义垂线
|
||||
//定位点到垂足距离不超过30米
|
||||
if (pointPairDistance.getMeterDistance() < DEVIATION_DISTANCE) {
|
||||
footIndex = pointPairDistance.footIndex
|
||||
Log.e(
|
||||
"jingo",
|
||||
"当前绑定到了整条路线的第 $footIndex 点 ${pointPairDistance.getMeterDistance()} "
|
||||
)
|
||||
val lastRouteIndex = routeIndex
|
||||
for (i in routeList.indices) {
|
||||
val route = routeList[i]
|
||||
if (route.startIndexInPath <= footIndex && route.endIndexIntPath >= footIndex) {
|
||||
routeIndex = route.indexInPath
|
||||
Log.e(
|
||||
"jingo",
|
||||
"当前绑定到了整条路线id ${route.linkId} "
|
||||
)
|
||||
niMapController.lineHandler.showLine(route.pointList)
|
||||
footPoint = GeoPoint(
|
||||
pointPairDistance.getCoordinate(0).y,
|
||||
pointPairDistance.getCoordinate(0).x
|
||||
)
|
||||
val listPoint = mutableListOf(point, footPoint!!)
|
||||
niMapController.lineHandler.showLine(
|
||||
listPoint
|
||||
)
|
||||
|
||||
if (lastRouteIndex != routeIndex) {
|
||||
createTempPath()
|
||||
}
|
||||
matchingItem()
|
||||
errorCount = 0
|
||||
break
|
||||
}
|
||||
}
|
||||
} else {
|
||||
deviationUp()
|
||||
}
|
||||
} else if (tempGeometry != null && tempRoutList.isNotEmpty()) {
|
||||
val pointPairDistance = GeometryTools.pointToLineDistance(point, tempGeometry)
|
||||
//定义垂线
|
||||
//定位点到垂足距离不超过30米
|
||||
if (pointPairDistance.getMeterDistance() < DEVIATION_DISTANCE) {
|
||||
footIndex = pointPairDistance.footIndex + tempRoutList[0].startIndexInPath
|
||||
Log.e("jingo", "局部 当前绑定到了整条路线的第 $footIndex 点")
|
||||
val lastRouteIndex = routeIndex
|
||||
for (i in tempRoutList.indices) {
|
||||
val route = tempRoutList[i]
|
||||
if (route.startIndexInPath <= footIndex && route.endIndexIntPath >= footIndex) {
|
||||
routeIndex = route.indexInPath
|
||||
Log.e(
|
||||
"jingo",
|
||||
"局部 当前绑定到了整条路线id ${route.linkId} "
|
||||
)
|
||||
niMapController.lineHandler.showLine(route.pointList)
|
||||
footPoint = GeoPoint(
|
||||
pointPairDistance.getCoordinate(0).y,
|
||||
pointPairDistance.getCoordinate(0).x
|
||||
)
|
||||
|
||||
val listPoint = mutableListOf(point, footPoint!!)
|
||||
niMapController.lineHandler.showLine(
|
||||
listPoint
|
||||
)
|
||||
|
||||
if (lastRouteIndex != routeIndex) {
|
||||
createTempPath()
|
||||
}
|
||||
matchingItem()
|
||||
errorCount = 0
|
||||
break
|
||||
}
|
||||
}
|
||||
} else {
|
||||
deviationUp()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 匹配要素
|
||||
* @point:定位点
|
||||
*/
|
||||
private fun matchingItem() {
|
||||
if (routeIndex > -1 && tempRoutList.isNotEmpty() && tempGeometry != null) {
|
||||
//道路前方一定距离范围内的要素信息
|
||||
val bindingItemList = mutableListOf<NaviRouteItem>()
|
||||
//临时局部路径的游标对应整条路径的游标
|
||||
val tempFootIndex = footIndex + tempRoutList[0].startIndexInPath
|
||||
//定位点到要素的路径距离
|
||||
var distance = 0.0
|
||||
//计算要素路径距离的点集合
|
||||
val disPoints = mutableListOf(footPoint!!)
|
||||
//下一个要素的起点游标
|
||||
var tempIndex = footIndex + 1
|
||||
for(route in tempRoutList) {
|
||||
if( route.indexInPath < routeIndex)
|
||||
continue
|
||||
if (route.itemList != null && route.itemList!!.isNotEmpty()) {
|
||||
for (naviItem in route.itemList!!) {
|
||||
if (naviItem.index > tempFootIndex) {
|
||||
val rightI = naviItem.index - tempRoutList[0].startIndexInPath + 1
|
||||
for (i in tempIndex until rightI) {
|
||||
val geo = tempGeometry!!.coordinates[i]
|
||||
disPoints.add(GeoPoint(geo.y, geo.x))
|
||||
}
|
||||
tempIndex = rightI
|
||||
distance = GeometryTools.getDistance(disPoints)
|
||||
if (distance < FARTHEST_DISPLAY_DISTANCE && distance > -1) {
|
||||
naviItem.distance = distance.toInt()
|
||||
bindingItemList.add(naviItem)
|
||||
} else {
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
if(distance >= FARTHEST_DISPLAY_DISTANCE){
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
callback.bindingResults(bindingItemList)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建临时局部路径
|
||||
*/
|
||||
private fun createTempPath() {
|
||||
tempRoutList.clear()
|
||||
tempGeometry = null
|
||||
if (routeIndex > -1 && routeIndex < routeList.size && footPoint != null) {
|
||||
val route = routeList[routeIndex]
|
||||
//当前垂足点在这个路段中是第几个坐标
|
||||
tempRoutList.add(route)
|
||||
var distance = 0.0
|
||||
//已经走过的路是否有100米
|
||||
var i = routeIndex - 1
|
||||
while (i >= 0 && distance < PASSED_ROUTE_DISTANCE) {
|
||||
val routeT = routeList[i]
|
||||
tempRoutList.add(0, routeT)
|
||||
distance += routeT.length
|
||||
i--
|
||||
}
|
||||
distance = 0.0
|
||||
//没走过的路是否有1000米
|
||||
var j = routeIndex + 1
|
||||
while (j < routeList.size && distance < NEXT_ROUTE_DISTANCE) {
|
||||
val routeT = routeList[j]
|
||||
tempRoutList.add(routeT)
|
||||
distance += routeT.length
|
||||
j++
|
||||
}
|
||||
}
|
||||
val list = mutableListOf<GeoPoint>()
|
||||
val fRoute = tempRoutList[0]
|
||||
//第一个路段加入
|
||||
list.addAll(fRoute.pointList)
|
||||
|
||||
for (i in 1 until tempRoutList.size) {
|
||||
val route = tempRoutList[i]
|
||||
val list2 = ArrayList(route.pointList.toList())
|
||||
list2.removeAt(0)
|
||||
list.addAll(list2)
|
||||
}
|
||||
tempGeometry = GeometryTools.createLineString(list)
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断是否完全偏离
|
||||
*/
|
||||
private fun deviationUp() {
|
||||
errorCount++
|
||||
if (errorCount >= DEVIATION_COUNT) {
|
||||
bindingReset()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 绑定重置
|
||||
*/
|
||||
private fun bindingReset() {
|
||||
//绑定失败次数
|
||||
errorCount = 0
|
||||
//当前邦定的那段route
|
||||
routeIndex = -1
|
||||
//当前绑定的link上哪个point
|
||||
footIndex = -1
|
||||
//上一次定位绑到路线的距离
|
||||
lastDistance = -1
|
||||
//垂足坐标
|
||||
footPoint = null
|
||||
//定位点集合
|
||||
locationList.clear()
|
||||
}
|
||||
|
||||
}
|
||||
BIN
app/src/main/res/drawable-xxhdpi/t0201000.png
Normal file
BIN
app/src/main/res/drawable-xxhdpi/t0201000.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 4.6 KiB |
@@ -29,16 +29,29 @@
|
||||
android:textColor="#2F2F2F"
|
||||
android:textSize="16sp" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/sign_distance_text"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="40dp"
|
||||
android:layout_alignRight="@id/sign_main_bg"
|
||||
android:layout_marginTop="4dp"
|
||||
android:layout_marginRight="19dp"
|
||||
android:gravity="center"
|
||||
android:text="范围外"
|
||||
android:textColor="#3736DB"
|
||||
android:textSize="16sp" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/sign_second_icon"
|
||||
android:layout_width="40dp"
|
||||
android:layout_height="40dp"
|
||||
android:gravity="center"
|
||||
android:layout_marginTop="10dp"
|
||||
android:layout_toRightOf="@id/sign_main_icon"
|
||||
android:gravity="center"
|
||||
android:text=""
|
||||
android:textColor="@color/white"
|
||||
android:textSize="16sp" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/sign_bottom_text"
|
||||
android:layout_width="wrap_content"
|
||||
@@ -69,8 +82,8 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignBottom="@id/sign_main_bg"
|
||||
android:layout_marginLeft="2dp"
|
||||
android:padding="4dp"
|
||||
android:layout_toRightOf="@id/sign_main_bg"
|
||||
android:padding="4dp"
|
||||
android:src="@drawable/icon_sign_info"
|
||||
android:visibility="gone" />
|
||||
|
||||
@@ -81,7 +94,7 @@
|
||||
android:layout_alignParentTop="true"
|
||||
android:layout_marginLeft="172dp"
|
||||
android:layout_marginTop="4dp"
|
||||
android:visibility="gone"
|
||||
android:background="@drawable/icon_evaluation" />
|
||||
android:background="@drawable/icon_evaluation"
|
||||
android:visibility="gone" />
|
||||
|
||||
</RelativeLayout>
|
||||
Reference in New Issue
Block a user