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

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": "道路线",
"zoomMin": 15,
"zoomMax": 17,
"catch":true
"catch":true,
"checkLinkId": true
},
"2002": {
"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()
}

View File

@ -57,6 +57,7 @@ import kotlinx.coroutines.launch
import kotlinx.coroutines.sync.Mutex
import kotlinx.coroutines.withContext
import org.locationtech.jts.geom.Geometry
import org.locationtech.jts.geom.LineString
import org.oscim.core.GeoPoint
import org.oscim.core.MapPosition
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"
@ -426,8 +427,10 @@ class MainViewModel @Inject constructor(
}
})
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) {
if (key == Constant.SELECT_TASK_ID) {
viewModelScope.launch(Dispatchers.IO) {
naviMutex.lock()
naviEngineStatus = 0
getTaskBean()
initQsRecordData()
naviMutex.unlock()
}
}
}
@ -680,7 +686,8 @@ class MainViewModel @Inject constructor(
bottomRightText = SignUtil.getSignBottomRightText(element),
renderEntity = element,
isMoreInfo = SignUtil.isMoreInfo(element),
index = SignUtil.getRoadInfoIndex(element)
index = SignUtil.getRoadInfoIndex(element),
)
topSignList.add(
signBean
@ -708,10 +715,11 @@ class MainViewModel @Inject constructor(
* 捕获道路和面板
*/
private suspend fun captureLink(point: GeoPoint) {
if (captureLinkState) {
return
}
mapController.markerHandle.addMarker(point, "selectLink")
try {
captureLinkState = true
@ -731,6 +739,8 @@ class MainViewModel @Inject constructor(
if (linkIdCache != linkId) {
mapController.lineHandler.showLine(link.geometry)
val lineString:Geometry = GeometryTools.createGeometry(link.geometry)
val footAndDistance = GeometryTools.pointToLineDistance(point,lineString)
linkId?.let {
var elementList = realmOperateHelper.queryLinkByLinkPid(it)
for (element in elementList) {
@ -748,7 +758,8 @@ class MainViewModel @Inject constructor(
bottomRightText = SignUtil.getSignBottomRightText(element),
renderEntity = 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}")
when (element.code) {
@ -829,7 +840,8 @@ class MainViewModel @Inject constructor(
RenderEntity::class.java,
true
)
.equalTo("table", DataCodeEnum.OMDB_RD_LINK_KIND.name).and()
.equalTo("table", DataCodeEnum.OMDB_RD_LINK_KIND.name)
.and()
.equalTo(
"properties['${RenderEntity.Companion.LinkTable.linkPid}']",
outLink
@ -1050,6 +1062,7 @@ class MainViewModel @Inject constructor(
linkIdCache = ""
mapController.lineHandler.removeLine()
liveDataSignList.value = mutableListOf()
mapController.markerHandle.removeMarker("selectLink")
if (bSelectRoad && naviEngineStatus == 1) {
naviEngineStatus = 2
} else if (naviEngineStatus == 2) {

View File

@ -1,9 +1,10 @@
package com.navinfo.omqs.util
import android.provider.ContactsContract.Data
import android.util.Log
import com.navinfo.collect.library.data.entity.RenderEntity
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.bean.RoadNameBean
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 org.json.JSONArray
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
class SignUtil {
@ -1552,6 +1557,47 @@ class SignUtil {
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,