路线选择时,要素距离计算

This commit is contained in:
squallzhjch
2023-09-20 16:21:26 +08:00
parent 427e36bb8a
commit 7d29ce2309
5 changed files with 78 additions and 9 deletions

View File

@@ -32,7 +32,8 @@
"name": "道路线", "name": "道路线",
"zoomMin": 15, "zoomMin": 15,
"zoomMax": 17, "zoomMax": 17,
"catch":true "catch":true,
"checkLinkId": true
}, },
"2002": { "2002": {
"table": "OMDB_RD_LINK_FUNCTION_CLASS", "table": "OMDB_RD_LINK_FUNCTION_CLASS",

View File

@@ -424,7 +424,7 @@ class MainActivity : BaseActivity() {
} }
} }
viewModel.listDataMessage.observe(this) { viewModel.liveDataMessage.observe(this) {
Toast.makeText(this, it, Toast.LENGTH_SHORT).show() Toast.makeText(this, it, Toast.LENGTH_SHORT).show()
} }

View File

@@ -57,6 +57,7 @@ import kotlinx.coroutines.launch
import kotlinx.coroutines.sync.Mutex import kotlinx.coroutines.sync.Mutex
import kotlinx.coroutines.withContext import kotlinx.coroutines.withContext
import org.locationtech.jts.geom.Geometry import org.locationtech.jts.geom.Geometry
import org.locationtech.jts.geom.LineString
import org.oscim.core.GeoPoint import org.oscim.core.GeoPoint
import org.oscim.core.MapPosition import org.oscim.core.MapPosition
import org.oscim.map.Map import org.oscim.map.Map
@@ -122,7 +123,7 @@ class MainViewModel @Inject constructor(
/** /**
* 提示信息 * 提示信息
*/ */
val listDataMessage = MutableLiveData<String>() val liveDataMessage = MutableLiveData<String>()
private var traceTag: String = "TRACE_TAG" private var traceTag: String = "TRACE_TAG"
@@ -426,8 +427,10 @@ class MainViewModel @Inject constructor(
} }
}) })
naviEngine!!.planningPath(currentTaskBean!!) naviEngine!!.planningPath(currentTaskBean!!)
naviMutex.unlock() } else {
liveDataMessage.postValue("请先安装任务数据")
} }
naviMutex.unlock()
} }
} }
@@ -435,8 +438,11 @@ class MainViewModel @Inject constructor(
override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences, key: String) { override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences, key: String) {
if (key == Constant.SELECT_TASK_ID) { if (key == Constant.SELECT_TASK_ID) {
viewModelScope.launch(Dispatchers.IO) { viewModelScope.launch(Dispatchers.IO) {
naviMutex.lock()
naviEngineStatus = 0
getTaskBean() getTaskBean()
initQsRecordData() initQsRecordData()
naviMutex.unlock()
} }
} }
} }
@@ -680,7 +686,8 @@ class MainViewModel @Inject constructor(
bottomRightText = SignUtil.getSignBottomRightText(element), bottomRightText = SignUtil.getSignBottomRightText(element),
renderEntity = element, renderEntity = element,
isMoreInfo = SignUtil.isMoreInfo(element), isMoreInfo = SignUtil.isMoreInfo(element),
index = SignUtil.getRoadInfoIndex(element) index = SignUtil.getRoadInfoIndex(element),
) )
topSignList.add( topSignList.add(
signBean signBean
@@ -708,10 +715,11 @@ class MainViewModel @Inject constructor(
* 捕获道路和面板 * 捕获道路和面板
*/ */
private suspend fun captureLink(point: GeoPoint) { private suspend fun captureLink(point: GeoPoint) {
if (captureLinkState) { if (captureLinkState) {
return return
} }
mapController.markerHandle.addMarker(point, "selectLink")
try { try {
captureLinkState = true captureLinkState = true
@@ -731,6 +739,8 @@ class MainViewModel @Inject constructor(
if (linkIdCache != linkId) { if (linkIdCache != linkId) {
mapController.lineHandler.showLine(link.geometry) mapController.lineHandler.showLine(link.geometry)
val lineString:Geometry = GeometryTools.createGeometry(link.geometry)
val footAndDistance = GeometryTools.pointToLineDistance(point,lineString)
linkId?.let { linkId?.let {
var elementList = realmOperateHelper.queryLinkByLinkPid(it) var elementList = realmOperateHelper.queryLinkByLinkPid(it)
for (element in elementList) { for (element in elementList) {
@@ -748,7 +758,8 @@ class MainViewModel @Inject constructor(
bottomRightText = SignUtil.getSignBottomRightText(element), bottomRightText = SignUtil.getSignBottomRightText(element),
renderEntity = element, renderEntity = element,
isMoreInfo = SignUtil.isMoreInfo(element), isMoreInfo = SignUtil.isMoreInfo(element),
index = SignUtil.getRoadInfoIndex(element) index = SignUtil.getRoadInfoIndex(element),
distance = SignUtil.getDistance(footAndDistance,lineString,element)
) )
// Log.e("jingo", "捕捉到的数据code ${element.code}") // Log.e("jingo", "捕捉到的数据code ${element.code}")
when (element.code) { when (element.code) {
@@ -829,7 +840,8 @@ class MainViewModel @Inject constructor(
RenderEntity::class.java, RenderEntity::class.java,
true true
) )
.equalTo("table", DataCodeEnum.OMDB_RD_LINK_KIND.name).and() .equalTo("table", DataCodeEnum.OMDB_RD_LINK_KIND.name)
.and()
.equalTo( .equalTo(
"properties['${RenderEntity.Companion.LinkTable.linkPid}']", "properties['${RenderEntity.Companion.LinkTable.linkPid}']",
outLink outLink
@@ -1050,6 +1062,7 @@ class MainViewModel @Inject constructor(
linkIdCache = "" linkIdCache = ""
mapController.lineHandler.removeLine() mapController.lineHandler.removeLine()
liveDataSignList.value = mutableListOf() liveDataSignList.value = mutableListOf()
mapController.markerHandle.removeMarker("selectLink")
if (bSelectRoad && naviEngineStatus == 1) { if (bSelectRoad && naviEngineStatus == 1) {
naviEngineStatus = 2 naviEngineStatus = 2
} else if (naviEngineStatus == 2) { } else if (naviEngineStatus == 2) {

View File

@@ -1,9 +1,10 @@
package com.navinfo.omqs.util package com.navinfo.omqs.util
import android.provider.ContactsContract.Data
import android.util.Log import android.util.Log
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.FootAndDistance
import com.navinfo.collect.library.utils.GeometryTools
import com.navinfo.omqs.R import com.navinfo.omqs.R
import com.navinfo.omqs.bean.RoadNameBean import com.navinfo.omqs.bean.RoadNameBean
import com.navinfo.omqs.bean.SignBean import com.navinfo.omqs.bean.SignBean
@@ -13,6 +14,10 @@ import com.navinfo.omqs.ui.fragment.signMoreInfo.TwoItemAdapter
import com.navinfo.omqs.ui.fragment.signMoreInfo.TwoItemAdapterItem import com.navinfo.omqs.ui.fragment.signMoreInfo.TwoItemAdapterItem
import org.json.JSONArray import org.json.JSONArray
import org.json.JSONObject import org.json.JSONObject
import org.locationtech.jts.geom.Geometry
import org.locationtech.jts.geom.GeometryFactory
import org.locationtech.jts.geom.LineString
import org.oscim.core.Point
import java.lang.reflect.Field import java.lang.reflect.Field
class SignUtil { class SignUtil {
@@ -1552,6 +1557,47 @@ class SignUtil {
return list return list
} }
/**
* 计算捕捉点到
*/
fun getDistance(
footAndDistance: FootAndDistance,
lineString: Geometry,
element: RenderEntity
): Int {
footAndDistance.footIndex
val itemGeometry = GeometryTools.createGeoPoint(element.geometry)
if (itemGeometry is Point) {
val itemFoot = GeometryTools.pointToLineDistance(itemGeometry, lineString)
var dis = GeometryTools.getDistance(
footAndDistance.getCoordinate(0).getY(),
footAndDistance.getCoordinate(0).getX(),
itemFoot.getCoordinate(0).getY(),
itemFoot.getCoordinate(0).getX(),
)
return if (footAndDistance.footIndex > itemFoot.footIndex) {
dis.toInt()
} else {
-dis.toInt()
}
}else if(itemGeometry is LineString){
val factory = GeometryFactory()
val geo: Geometry = factory.createPoint(lineString.coordinates[0])
val itemFoot = GeometryTools.pointToLineDistance(itemGeometry, geo)
var dis = GeometryTools.getDistance(
footAndDistance.getCoordinate(0).getY(),
footAndDistance.getCoordinate(0).getX(),
itemFoot.getCoordinate(0).getY(),
itemFoot.getCoordinate(0).getX(),
)
return if (footAndDistance.footIndex > itemFoot.footIndex) {
dis.toInt()
} else {
-dis.toInt()
}
}
return 0
}
} }

View File

@@ -443,6 +443,15 @@ public class GeometryTools {
} }
public static double distanceToDouble(Geometry startGeoPoint, Geometry endGeoPoint) {
if (startGeoPoint != null && endGeoPoint != null) {
double d = startGeoPoint.distance(endGeoPoint);
return convertDistanceToDegree(d, startGeoPoint.getCoordinate().y);
}
return 0;
}
/** /**
* LINESTRING (116.4206899999999933 39.9620999999999995, * LINESTRING (116.4206899999999933 39.9620999999999995,