Commit 95b6efec authored by p x's avatar p x
Browse files

模拟泊车路径

parent 374a24ad
{
"code": "1",
"msg": "执行成功",
"result": {
"vehicleId": "9",
"parkingPlaceId": "421",
"routes": [
{
"routeId": 1,
"origin": [
116.50254394816011,
39.809039362307594
],
"destination": [
116.50257504818846,
39.80900097735677
],
"gear": 3,
"polyline": [
[
116.50254394816011,
39.809039362307594,
0.5,
148.10218269263586
],
[
116.50254457016067,
39.80903859460858,
0.5,
148.10218229911192
],
[
116.50254519216124,
39.80903782690956,
0.5,
148.1021822250557
],
[
116.5025458141618,
39.80903705921054,
0.5,
148.10218183153174
],
[
116.50254643616238,
39.80903629151153,
0.5,
148.10218154449709
],
[
116.50254705816295,
39.80903552381251,
0.5,
148.10218115097314
],
[
116.50254768016352,
39.8090347561135,
0.5,
148.10218086393846
],
[
116.50254830216409,
39.809033988414484,
0.5,
148.10218194783928
],
[
116.50254892416464,
39.809033220715456,
0.5,
148.10217902542288
],
[
116.50254954616523,
39.80903245301645,
0.5,
148.10218126728074
],
[
116.50255016816578,
39.80903168531743,
0.5,
148.10218076726758
],
[
116.50255079016634,
39.809030917618415,
0.5,
148.10217964174365
],
[
116.50255141216691,
39.809030149919394,
0.5,
148.10217924821978
],
[
116.50255203416748,
39.80902938222038,
0.5,
148.10217885469592
],
[
116.50255265616805,
39.80902861452137,
0.5,
148.10217878063978
],
[
116.50255327816862,
39.809027846822346,
0.5,
148.10217943858373
],
[
116.50255390016918,
39.809027079123325,
0.5,
148.10217788710278
],
[
116.50255452216973,
39.80902631142431,
0.5,
148.1021780260252
],
[
116.50255514417032,
39.8090255437253,
0.5,
148.1021773130336
],
[
116.50255576617087,
39.80902477602628,
0.5,
148.1021772389775
],
[
116.50255638817144,
39.80902400832726,
0.5,
148.1021769519429
],
[
116.50255701017201,
39.80902324062825,
0.5,
148.10217677139758
],
[
116.5025576321726,
39.80902247292923,
0.5,
148.10217637787377
],
[
116.50255825417315,
39.809021705230215,
0.5,
148.10217598434994
],
[
116.50255887617372,
39.8090209375312,
0.5,
148.10217601678315
],
[
116.50255949817429,
39.80902016983218,
0.5,
148.10217635525942
],
[
116.50256012017485,
39.80901940213316,
0.5,
148.1021741782677
],
[
116.50256074217543,
39.80901863443415,
0.5,
148.10217620714738
],
[
116.50256136417599,
39.80901786673513,
0.5,
148.10217465566646
],
[
116.50256198617654,
39.80901709903611,
0.5,
148.10217426214265
],
[
116.50256260817713,
39.8090163313371,
0.5,
148.10217502657602
],
[
116.50256323017769,
39.809015563638084,
0.5,
148.10217400754144
],
[
116.50256385217826,
39.80901479593906,
0.5,
148.1021734010391
],
[
116.50256447417883,
39.80901402824005,
0.5,
148.10217300751535
],
[
116.50256509617938,
39.809013260541036,
0.5,
148.10217293345937
],
[
116.50256571817995,
39.809012492842015,
0.5,
148.10217264642492
],
[
116.50256634018052,
39.809011725143,
0.5,
148.1021734108583
],
[
116.50256696218108,
39.80901095744399,
0.5,
148.10217207235593
],
[
116.50256758418166,
39.80901018974497,
0.5,
148.10217210478928
],
[
116.50256820618223,
39.809009422045946,
0.5,
148.1021711788192
],
[
116.50256882818279,
39.80900865434693,
0.5,
148.10217121125254
],
[
116.50256945018336,
39.80900788664792,
0.5,
148.10217071123955
],
[
116.50257007218393,
39.809007118948905,
0.5,
148.10217127611924
],
[
116.50257069418448,
39.80900635124988,
0.5,
148.10217024365994
],
[
116.50257131618505,
39.809005583550864,
0.5,
148.10216995662552
],
[
116.50257193818562,
39.80900481585185,
0.5,
148.10216988256963
],
[
116.5025725601862,
39.80900404815283,
0.5,
148.10216948904593
],
[
116.50257318218677,
39.809003280453815,
0.5,
148.10216898903298
],
[
116.50257380418734,
39.8090025127548,
0.5,
148.10217017942364
],
[
116.50257442618789,
39.80900174505578,
0.5,
148.10216841496418
],
[
116.50257504818846,
39.80900097735677,
0.5,
148.10216841496418
]
]
},
{
"routeId": 2,
"origin": [
116.50257504818846,
39.80900097735677
],
"destination": [
116.5024625,
39.8090317
],
"gear": 1,
"polyline": [
[
116.50257504818846,
39.80900097735677,
0.5,
150.47794433755706
],
[
116.50257218918523,
39.80900485570903,
0.5,
154.27310728039356
],
[
116.5025697015945,
39.80900882155232,
0.5,
156.67295798187433
],
[
116.50256745223952,
39.80901282852125,
0.5,
157.8133738046629
],
[
116.50256532727003,
39.80901683117987,
0.5,
157.84012669821846
],
[
116.50256323087986,
39.80902078528453,
0.5,
156.88041033745833
],
[
116.50256108403372,
39.80902464804938,
0.5,
155.0349202584366
],
[
116.50255882320319,
39.80902837841471,
0.5,
152.37984099954474
],
[
116.50255639911234,
39.809031937318096,
0.5,
148.9730402515233
],
[
116.50255377549128,
39.80903528796794,
0.5,
144.86214711490197
],
[
116.50255092784093,
39.8090383961204,
0.5,
140.09356276594684
],
[
116.50254784220454,
39.80904123035833,
0.5,
134.7219998248488
],
[
116.50254451395082,
39.8090437623737,
0.5,
128.81951628621687
],
[
116.5025409465643,
39.80904596725211,
0.5,
122.48239643592717
],
[
116.50253715044603,
39.809047823760544,
0.5,
115.83350619337386
],
[
116.50253314172312,
39.80904931463762,
0.5,
109.01823320278112
],
[
116.50252894106745,
39.809050426886664,
0.5,
102.19391587555128
],
[
116.50252457252354,
39.80905115207155,
0.5,
95.5153521727076
],
[
116.50252006234572,
39.80905148661524,
0.5,
89.12084176468869
],
[
116.50251543784445,
39.80905143210117,
0.5,
83.12290608687363
],
[
116.50251072624177,
39.80905099557725,
0.5,
77.60560229976858
],
[
116.5025059535361,
39.80905018986276,
0.5,
72.62772394588927
],
[
116.50250114337594,
39.80904903385788,
0.5,
68.22973689932553
],
[
116.50249631594309,
39.80904755285604,
0.5,
64.44221270751927
],
[
116.50249148684485,
39.80904577885904,
0.5,
61.29429364132028
],
[
116.50248666601549,
39.8090437508948,
0.5,
58.821619453979906
],
[
116.50248185662682,
39.80904151533802,
0.5,
57.07376338261474
],
[
116.50247705400817,
39.809039126233515,
0.5,
56.12142584978807
],
[
116.50247224457523,
39.80903664562224,
0.5,
56.063314828195246
],
[
116.50246740476837,
39.8090341438702,
0.5,
57.03146193036804
],
[
116.5024625,
39.8090317,
0.5,
57.03146193036804
]
]
}
],
"points": null,
"execType": null,
"execTypeDesc": null,
"vehicleInfo": null,
"time": null,
"parkingPlace": null
}
}
\ No newline at end of file
package com.sd.cavphmi.bean.mock
//模拟倒车路径
data class ParkPath(
val code: String,
val msg: String,
val result: PResult
)
data class PResult(
val execType: Any,
val execTypeDesc: Any,
val parkingPlace: Any,
val parkingPlaceId: String,
val points: Any,
val routes: List<PRoute>,
val time: Any,
val vehicleId: String,
val vehicleInfo: Any
)
data class PRoute(
val destination: List<Double>,
val gear: Int,//3=前进 1=后退
val origin: List<Double>,
val polyline: List<List<Double>>,
val routeId: Int
)
\ No newline at end of file
......@@ -119,7 +119,7 @@ object HighMapApi {
/**
* 设置相机角度
*/
fun setSetCameraAngle(angle: Float = 30f) {
fun setCameraAngle(angle: Float = 30f) {
UnityPlayer.UnitySendMessage(MODELNAME, "SetCameraAngle", "$angle")
}
......@@ -160,7 +160,7 @@ object HighMapApi {
var parkComplete = ParkComplete().apply {
this.complete = complete
}
UnityPlayer.UnitySendMessage(MODELNAME, "SetParking", gson.toJson(parkComplete))
UnityPlayer.UnitySendMessage(MODELNAME, "SetParkComplete", gson.toJson(parkComplete))
}
// 设置地锁状态
......
......@@ -44,7 +44,7 @@ class TileJsonBean {
//四维的
/* var host = "http://gz.tasks.city/3dtiles"
/* var host = "http://gz.tasks.city/3dtiles"
var tiles3d = listOf(
// "/1/CurbStrip/tileset.json",
"/1/LanePolygon/tileset.json",
......
......@@ -55,6 +55,7 @@ class LoginActivity : AppCompatActivity() {
//直接到首页
binding.btMain.setOnClickListener {
startActivity(Intent(this, MainActivity::class.java))
finish()
}
}
......
......@@ -142,7 +142,7 @@ class MainActivity : BaseActivity<ActivityMainBinding, MyBaseViewModel>() {
// mineMap?.enableSatelliteLayer(true)
mainVm.mMineMap = mineMap
mockVM.mMineMap = mineMap
mineMap?.setZoomLevel(12f)
mineMap?.setZoomLevel(14f)
//设置中心点
val point = Tools.latLngToPoint(LatLng(39.80913878, 116.50166926))
mineMap?.setPointToCenter(point.x, point.y)
......@@ -283,7 +283,6 @@ class MainActivity : BaseActivity<ActivityMainBinding, MyBaseViewModel>() {
}
}
private fun mockBt() {
//获取AVP状态
binding.btAvpStatu.setOnClickListener {
......@@ -303,6 +302,9 @@ class MainActivity : BaseActivity<ActivityMainBinding, MyBaseViewModel>() {
}
//车位四周流光
binding.btParkround.setOnClickListener {
HighMapApi.setCameraAngle(75f)
lifecycleScope.launch {
HighMapApi.parkRoundLight("B021")
delay(5000)
......@@ -324,17 +326,17 @@ class MainActivity : BaseActivity<ActivityMainBinding, MyBaseViewModel>() {
binding.btLock.setOnClickListener {
var lockStatu = LockStatu().apply {
code = "B021"
up = true
isHide=false
}
HighMapApi.setLockStatus(lockStatu)
lifecycleScope.launch {
/* lifecycleScope.launch {
delay(3000)
lockStatu.up = false
HighMapApi.setLockStatus(lockStatu)
delay(3000)
lockStatu.isHide = true
HighMapApi.setLockStatus(lockStatu)
}
}*/
}
//模拟移动
// binding.btMove.setOnClickListener {
......
......@@ -11,7 +11,6 @@ import androidx.fragment.app.activityViewModels
import com.sd.cavphmi.viewmodels.UnityMapVm
import com.unity3d.player.IUnityPlayerLifecycleEvents
import com.unity3d.player.UnityPlayer
import kotlin.getValue
/**
......@@ -46,7 +45,7 @@ class UnityFragment : Fragment(), IUnityPlayerLifecycleEvents {
super.onDestroy()
try {
this.mUnityPlayer.destroy()
}catch (e: Exception){
} catch (e: Exception) {
}
}
......@@ -82,13 +81,14 @@ class UnityFragment : Fragment(), IUnityPlayerLifecycleEvents {
// UnityPlayer 实例
private lateinit var mUnityPlayer: UnityPlayer
//UNITY map 控制类
private val unityMapVm: UnityMapVm by activityViewModels()
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
mUnityPlayer = UnityPlayer(requireContext(),this)
mUnityPlayer = UnityPlayer(requireContext(), this)
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
......@@ -97,7 +97,12 @@ class UnityFragment : Fragment(), IUnityPlayerLifecycleEvents {
mUnityPlayer.windowFocusChanged(true)
// mUnityPlayer.requestFocus()
//使用拼接服务器资源加载地图
unityMapVm.loadTileJson()
mUnityPlayer.post {
try {
unityMapVm.loadTileJson()
} catch (e: Exception) {
}
}
}
......
......@@ -78,7 +78,7 @@ object FileIoUtils {
/**
* 读取asset 文件
*/
fun getAsset(context: Context, fileName: String): String {
suspend fun getAsset(context: Context, fileName: String): String {
val assetManager = context.assets
var inputStream: InputStream? = null
var str = ""
......
......@@ -2,7 +2,6 @@ package com.sd.cavphmi.viewmodels
import android.content.Context
import android.graphics.BitmapFactory
import android.graphics.Color
import android.graphics.Point
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
......@@ -14,7 +13,6 @@ import com.minedata.minenavi.map.MineMap
import com.minedata.minenavi.map.MyLocationStyle
import com.minedata.minenavi.map.Overlay
import com.minedata.minenavi.map.Polyline
import com.minedata.minenavi.map.PolylineOptions
import com.minedata.minenavi.mapdal.LatLng
import com.minedata.minenavi.mapdal.NativeEnv
import com.minedata.minenavi.mapdal.NdsPoint
......@@ -25,10 +23,12 @@ import com.sd.cavphmi.bean.CarVehicleItem
import com.sd.cavphmi.bean.PerceptionBean
import com.sd.cavphmi.bean.V2xStartBean
import com.sd.cavphmi.bean.mock.MRoutes
import com.sd.cavphmi.bean.mock.ParkPath
import com.sd.cavphmi.highmap.AllLine
import com.sd.cavphmi.highmap.HighMapApi
import com.sd.cavphmi.highmap.LockStatu
import com.sd.cavphmi.highmap.ParkStatu
import com.sd.cavphmi.highmap.ReverCar
import com.sd.cavphmi.highmap.Spinfo
import com.sd.cavphmi.utils.FileIoUtils
import com.sd.cavphmi.utils.MyMapUtils
......@@ -66,7 +66,10 @@ class MockVM @Inject constructor(
fun onVehicleMock(
carVehicle: MutableLiveData<CarVehicle>
) {
HighMapApi.setCameraAngle(30f)
viewModelScope.launch {
var cCar: CarVehicleItem? = null
var gson = Gson()
var str =
FileIoUtils.getAsset(context, "mock/Car_fangzhen.txt") //Qgis里取的点和四维取得点混合
......@@ -83,13 +86,13 @@ class MockVM @Inject constructor(
}
HighMapApi.setCarNavPath(lines, showdistance = 200)
//开启流光效果
HighMapApi.parkRoundLight("B021")
HighMapApi.parkRoundLight("B017")
//2旁车辆占用
var spinfos = listOf(Spinfo().apply {
code = "B020"
code = "B016"
state = true
}, Spinfo().apply {
code = "B022"
code = "B018"
state = true
})
HighMapApi.setParkStatu(ParkStatu(spinfos))
......@@ -106,7 +109,7 @@ class MockVM @Inject constructor(
LatLng(pc[1], pc[0])
)
}
var cCar = CarVehicleItem().apply {
cCar = CarVehicleItem().apply {
if ((head - oldHead).absoluteValue < 45) {
this.heading = head
}
......@@ -128,17 +131,83 @@ class MockVM @Inject constructor(
upSmallLine(index, mRoutes)
delay(300)
}
//地锁绘制
var lockStatu = LockStatu().apply {
code = "B021"
up = false
}
HighMapApi.setLockStatus(lockStatu)
delay(5000)
lockStatu.isHide = true
HighMapApi.setLockStatus(lockStatu)
//消除全局路径
HighMapApi.setCarNavPath(listOf())
//删除终点mark
deleteEndMarker()
//删除导航小地图小车
// deleteNavingCar()
//地锁绘制(升起)
// var lockStatu = LockStatu().apply {
// code = "B017"
// up = false
// }
// HighMapApi.setLockStatus(lockStatu)
//开始泊车
var parkStr = FileIoUtils.getAsset(context, "mock/parkpath.txt") //Qgis里取的点和四维取得点混合
val parkPath = gson.fromJson<ParkPath>(parkStr, ParkPath::class.java)
//改变镜头角度
HighMapApi.setCameraAngle(60f)
//前进
var forword = parkPath.result.routes.find { it.gear == 3 }
forword?.polyline?.forEach { poly ->
cCar = CarVehicleItem().apply {
latitude = poly.get(1)
longitude = poly.get(0)
heading = poly.get(3)
}
var carV = CarVehicle().apply {
add(cCar)
}
//更新主车位置
carVehicle.value = carV
//更新小地图小车
showNavingCarPosition(
Tools.latLngToNdsPoint(LatLng(cCar.latitude, cCar.longitude)),
cCar.heading.toFloat()
)
delay(300)
}
//绘制倒车路径
var reverCar = ReverCar().apply {
this.cenLat = 39.80903159
this.cenLng = 116.50246079
this.code = "B017"
}
HighMapApi.setParkRever(reverCar)
//改变镜头角度
HighMapApi.setCameraAngle(90f)
//开始后退
var fBack = parkPath.result.routes.find { it.gear == 1 }
fBack?.polyline?.forEach { poly ->
cCar = CarVehicleItem().apply {
latitude = poly.get(1)
longitude = poly.get(0)
heading = poly.get(3)
}
var carV = CarVehicle().apply {
add(cCar)
}
//更新主车位置
carVehicle.value = carV
//更新小地图小车
showNavingCarPosition(
Tools.latLngToNdsPoint(LatLng(cCar.latitude, cCar.longitude)),
cCar.heading.toFloat()
)
delay(300)
}
delay(3000)
//删除导航小地图小车
deleteNavingCar()
//关闭流光效果
HighMapApi.parkRoundLight("")
//结束泊车
HighMapApi.setParkComplete(true)
//降地锁
// lockStatu.up = false
// HighMapApi.setLockStatus(lockStatu)
//
}
}
......@@ -180,7 +249,7 @@ class MockVM @Inject constructor(
fun addEndMarker(
mEndPoint: LatLng
) {
//删除终点marker
//删除终点marker
deleteEndMarker()
val end_icon = BitmapFactory.decodeResource(context.resources, R.drawable.plan_end)
// var endlatLng = Tools.pointToLatLng(mEndPoint)
......@@ -189,11 +258,13 @@ class MockVM @Inject constructor(
)
}
private var mSmallMapCar: MyLocationStyle? = null
//画小地图小车
fun drawNavingCar(point: Point) {
if (mSmallMapCar == null) {
// mSmallMapCar = MyLocationStyle(R.drawable.angle_blue, true)
mSmallMapCar = MyLocationStyle("res/icons/carIconInSmallMap.png", true)
mSmallMapCar?.myLocationType(MyLocationStyle.LOCATION_TYPE_EXTERNAL)
val scaleFactor = -
......
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners android:radius="4dp"/>
<stroke
android:width="3dp"
android:color="@color/white"/>
</shape>
\ No newline at end of file
......@@ -106,7 +106,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="地锁绘制"
android:visibility="gone" />
android:visibility="visible" />
<!-- <Button-->
<!-- android:id="@+id/bt_move"-->
......@@ -138,15 +138,25 @@
android:layout_marginBottom="10dp"
android:background="@drawable/rect_no_col_10" />
<!-- 小地图-->
<com.minedata.minenavi.map.MapView
android:id="@+id/mapView"
<FrameLayout
android:layout_width="@dimen/small_map_width"
android:layout_height="@dimen/small_map_height"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginRight="@dimen/dp_10"
android:layout_marginBottom="10dp" />
android:layout_marginEnd="@dimen/dp_10"
android:layout_marginBottom="@dimen/dp_10"
android:background="@drawable/rect_white_small_map_4"
android:padding="3dp">
<!-- 小地图-->
<com.minedata.minenavi.map.MapView
android:id="@+id/mapView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</FrameLayout>
</RelativeLayout>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment