Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
p x
MapMultiEngine
Commits
3ebc9c25
Commit
3ebc9c25
authored
Oct 31, 2025
by
p x
Browse files
添加在线地图网联车
parent
a0061ae5
Changes
14
Hide whitespace changes
Inline
Side-by-side
app/src/main/AndroidManifest.xml
View file @
3ebc9c25
...
@@ -39,6 +39,9 @@
...
@@ -39,6 +39,9 @@
android:supportsRtl=
"true"
android:supportsRtl=
"true"
android:theme=
"@style/Theme.MapMultiEngine"
android:theme=
"@style/Theme.MapMultiEngine"
tools:targetApi=
"31"
>
tools:targetApi=
"31"
>
<activity
android:name=
".ui.OnLineMapActivity"
android:exported=
"false"
/>
<activity
<activity
android:name=
".ui.ControlActivity"
android:name=
".ui.ControlActivity"
android:exported=
"false"
/>
android:exported=
"false"
/>
...
...
app/src/main/java/com/sd/demo/MainActivity.kt
View file @
3ebc9c25
...
@@ -14,6 +14,7 @@ import com.sd.demo.ui.ChangeMapCenterAct
...
@@ -14,6 +14,7 @@ import com.sd.demo.ui.ChangeMapCenterAct
import
com.sd.demo.ui.ControlActivity
import
com.sd.demo.ui.ControlActivity
import
com.sd.demo.ui.DisplayMapActivity
import
com.sd.demo.ui.DisplayMapActivity
import
com.sd.demo.ui.GestureDemo
import
com.sd.demo.ui.GestureDemo
import
com.sd.demo.ui.OnLineMapActivity
import
com.sd.demo.ui.PartRoadActivity
import
com.sd.demo.ui.PartRoadActivity
import
com.sd.demo.ui.TCircelActivity
import
com.sd.demo.ui.TCircelActivity
import
com.sd.demo.ui.TDriveRouteActivity
import
com.sd.demo.ui.TDriveRouteActivity
...
@@ -71,9 +72,10 @@ class MainActivity : AppCompatActivity() {
...
@@ -71,9 +72,10 @@ class MainActivity : AppCompatActivity() {
DemoDetails
(
"加载wms"
,
WmsActivity
::
class
.
java
),
DemoDetails
(
"加载wms"
,
WmsActivity
::
class
.
java
),
DemoDetails
(
"驾车路线规划(导航)"
,
TDriveRouteActivity
::
class
.
java
),
DemoDetails
(
"驾车路线规划(导航)"
,
TDriveRouteActivity
::
class
.
java
),
DemoDetails
(
"测试业务类相关"
,
null
),
DemoDetails
(
"局部地图"
,
PartRoadActivity
::
class
.
java
),
DemoDetails
(
"局部地图"
,
PartRoadActivity
::
class
.
java
),
// DemoDetails("加载局部地图", null),
DemoDetails
(
"高精地图"
,
THighMapActivity
::
class
.
java
),
DemoDetails
(
"高精地图"
,
THighMapActivity
::
class
.
java
),
DemoDetails
(
"在线地图"
,
OnLineMapActivity
::
class
.
java
),
// DemoDetails("业务相关", null),
// DemoDetails("业务相关", null),
// DemoDetails("在线地图显示小车", ShowCarOnlineActivity::class.java),
// DemoDetails("在线地图显示小车", ShowCarOnlineActivity::class.java),
...
@@ -152,6 +154,4 @@ class MainActivity : AppCompatActivity() {
...
@@ -152,6 +154,4 @@ class MainActivity : AppCompatActivity() {
}
}
}
}
\ No newline at end of file
app/src/main/java/com/sd/demo/ui/OnLineMapActivity.kt
0 → 100644
View file @
3ebc9c25
package
com.sd.demo.ui
import
android.os.Bundle
import
androidx.appcompat.app.AppCompatActivity
import
androidx.lifecycle.lifecycleScope
import
com.google.gson.Gson
import
com.sd.api.maps.MSCalcuMapUtil
import
com.sd.api.maps.MethodAdv
import
com.sd.api.maps.cdata.MSLatLng
import
com.sd.api.scenario.CucsVehicle
import
com.sd.api.scenario.VehicleModel
import
com.sd.api.scenario.VehiclePos
import
com.sd.api.ui.MapMultiView.OnMapReadyLis
import
com.sd.api.ui.MapReadyView
import
com.sd.demo.bean.mock.MRoutes
import
com.sd.demo.databinding.ActivityOnLineMapBinding
import
com.sd.demo.ui.PartRoadActivity
import
com.sd.demo.utils.FileIoUtils
import
kotlinx.coroutines.delay
import
kotlinx.coroutines.launch
import
kotlin.coroutines.cancellation.CancellationException
import
kotlin.math.absoluteValue
//测试在线地图业务
class
OnLineMapActivity
:
AppCompatActivity
()
{
private
lateinit
var
binding
:
ActivityOnLineMapBinding
var
mapReadView
:
MapReadyView
?
=
null
override
fun
onCreate
(
savedInstanceState
:
Bundle
?)
{
super
.
onCreate
(
savedInstanceState
)
binding
=
ActivityOnLineMapBinding
.
inflate
(
layoutInflater
)
setContentView
(
binding
.
root
)
binding
.
mapMultiView
.
addMapRenderCallback
(
object
:
OnMapReadyLis
{
override
fun
onMapReady
(
mapReadyView
:
MapReadyView
)
{
this
@OnLineMapActivity
.
mapReadView
=
mapReadyView
}
})
setListener
()
}
private
fun
setListener
()
{
binding
.
bt1
.
setOnClickListener
{
// //移动网联车
mockFzLine
()
}
}
fun
mockFzLine
()
{
lifecycleScope
.
launch
{
try
{
var
gson
=
Gson
()
var
str
=
FileIoUtils
.
getAsset
(
this
@OnLineMapActivity
,
"mock/Car_fangzhen1.txt"
)
//获取车辆位姿
val
mRoutes
=
gson
.
fromJson
<
MRoutes
>(
str
,
MRoutes
::
class
.
java
)
var
head
=
0.0
var
oldHead
=
0.0
mRoutes
.
rs
.
forEachIndexed
{
index
,
it
->
// println("---------it[0] = ${it[0]} it[1] = ${it[1]} index = ${index}")
if
(
index
>
0
)
{
var
p1
=
mRoutes
.
rs
.
get
(
index
-
1
)
var
pc
=
mRoutes
.
rs
.
get
(
index
)
head
=
MSCalcuMapUtil
.
calculateBearing
(
MSLatLng
(
p1
[
1
],
p1
[
0
]),
MSLatLng
(
pc
[
1
],
pc
[
0
])
)
VehiclePos
.
instance
.
apply
{
lat
=
pc
[
1
]
lng
=
pc
[
0
]
if
((
head
-
oldHead
).
absoluteValue
<
45
)
{
heading
=
head
}
}
CucsVehicle
.
moveCar
(
VehiclePos
.
instance
,
3
)
MethodAdv
.
setMapCenter
(
VehiclePos
.
instance
.
lat
,
VehiclePos
.
instance
.
lng
)
oldHead
=
head
delay
(
600
)
}
}
}
catch
(
e
:
CancellationException
)
{
}
}
}
}
\ No newline at end of file
app/src/main/java/com/sd/demo/ui/PartRoadActivity.kt
View file @
3ebc9c25
...
@@ -149,16 +149,6 @@ class PartRoadActivity : AppCompatActivity() {
...
@@ -149,16 +149,6 @@ class PartRoadActivity : AppCompatActivity() {
// evel = 20.80189
// evel = 20.80189
}
}
// RoadPos.instance.apply {
// lat = it[1]
// lng = it[0]
// if ((head - oldHead).absoluteValue < 45) {
// bearing = head.toFloat()
// }
// // println("-----bearing = ${bearing}")
// //高程
//// altitude = 20.802828
// }
CucsVehicle
.
moveCar
(
VehiclePos
.
instance
,
2
)
CucsVehicle
.
moveCar
(
VehiclePos
.
instance
,
2
)
//更新车辆位置.主车是否添加回调
//更新车辆位置.主车是否添加回调
// MsParkRoad.updateMainCar(RoadPos.instance, object : OnPrAddCar {
// MsParkRoad.updateMainCar(RoadPos.instance, object : OnPrAddCar {
...
...
app/src/main/java/com/sd/demo/ui/THighMapActivity.kt
View file @
3ebc9c25
...
@@ -6,7 +6,7 @@ import androidx.lifecycle.lifecycleScope
...
@@ -6,7 +6,7 @@ import androidx.lifecycle.lifecycleScope
import
com.google.gson.Gson
import
com.google.gson.Gson
import
com.sd.api.highmap.AllLine
import
com.sd.api.highmap.AllLine
import
com.sd.api.highmap.CarNavPath
import
com.sd.api.highmap.CarNavPath
import
com.sd.api.highmap.HighMap
Api
import
com.sd.api.highmap.HighMap
import
com.sd.api.highmap.UnityPtc
import
com.sd.api.highmap.UnityPtc
import
com.sd.api.highmap.WarnPtc
import
com.sd.api.highmap.WarnPtc
import
com.sd.api.maps.MSCalcuMapUtil
import
com.sd.api.maps.MSCalcuMapUtil
...
@@ -41,7 +41,7 @@ class THighMapActivity : AppCompatActivity() {
...
@@ -41,7 +41,7 @@ class THighMapActivity : AppCompatActivity() {
override
fun
onMapReady
(
mapReadyView
:
MapReadyView
)
{
override
fun
onMapReady
(
mapReadyView
:
MapReadyView
)
{
this
@THighMapActivity
.
mapReadView
=
mapReadyView
this
@THighMapActivity
.
mapReadView
=
mapReadyView
//传入3d tile加载地图 1= 亦庄示范区
//传入3d tile加载地图 1= 亦庄示范区
HighMap
Api
.
setTileInit
(
1
)
HighMap
.
setTileInit
(
1
)
}
}
})
})
...
@@ -71,6 +71,7 @@ class THighMapActivity : AppCompatActivity() {
...
@@ -71,6 +71,7 @@ class THighMapActivity : AppCompatActivity() {
var
carNavPath
=
CarNavPath
().
apply
{
var
carNavPath
=
CarNavPath
().
apply
{
this
.
lines
=
lines
this
.
lines
=
lines
}
}
//设置全局路径
CucsVehicle
.
setCarNaiPath
(
carNavPath
)
CucsVehicle
.
setCarNaiPath
(
carNavPath
)
//模拟车辆移动
//模拟车辆移动
var
head
=
0.0
var
head
=
0.0
...
@@ -94,6 +95,9 @@ class THighMapActivity : AppCompatActivity() {
...
@@ -94,6 +95,9 @@ class THighMapActivity : AppCompatActivity() {
evel
=
20.80189
evel
=
20.80189
}
}
}
}
if
(
index
>
10
){
CucsVehicle
.
clearCarNaiPath
()
}
// HighMapApi.setCarPosition(head, it[1], it[0], 20.80189)
// HighMapApi.setCarPosition(head, it[1], it[0], 20.80189)
CucsVehicle
.
moveCar
(
VehiclePos
.
instance
,
1
)
CucsVehicle
.
moveCar
(
VehiclePos
.
instance
,
1
)
oldHead
=
head
oldHead
=
head
...
@@ -125,7 +129,7 @@ class THighMapActivity : AppCompatActivity() {
...
@@ -125,7 +129,7 @@ class THighMapActivity : AppCompatActivity() {
heading
=
it
.
heading
heading
=
it
.
heading
}
}
}
}
HighMap
Api
.
setPtcData
(
pres
)
HighMap
.
setPtcData
(
pres
)
delay
(
1000
)
delay
(
1000
)
}
}
...
@@ -152,10 +156,10 @@ class THighMapActivity : AppCompatActivity() {
...
@@ -152,10 +156,10 @@ class THighMapActivity : AppCompatActivity() {
isRed
=
true
isRed
=
true
}
}
var
warns
=
listOf
(
warnPtc
)
var
warns
=
listOf
(
warnPtc
)
HighMap
Api
.
setWarnPtc
(
warns
)
HighMap
.
setWarnPtc
(
warns
)
delay
(
5000
)
delay
(
5000
)
warnPtc
.
isRed
=
false
warnPtc
.
isRed
=
false
HighMap
Api
.
setWarnPtc
(
warns
)
HighMap
.
setWarnPtc
(
warns
)
}
}
toggleCircleRadar
(
2
)
toggleCircleRadar
(
2
)
}
}
...
@@ -165,12 +169,12 @@ class THighMapActivity : AppCompatActivity() {
...
@@ -165,12 +169,12 @@ class THighMapActivity : AppCompatActivity() {
* @param dirent 0=关闭 1=左前 2=正前 3=右前 4=右后 5=正后 6=左后
* @param dirent 0=关闭 1=左前 2=正前 3=右前 4=右后 5=正后 6=左后
* */
* */
fun
toggleCircleRadar
(
dirent
:
Int
)
{
fun
toggleCircleRadar
(
dirent
:
Int
)
{
HighMap
Api
.
setCarBottomCircle
(
true
)
HighMap
.
setCarBottomCircle
(
true
)
HighMap
Api
.
setCarRadarDirection
(
dirent
)
HighMap
.
setCarRadarDirection
(
dirent
)
lifecycleScope
.
launch
{
lifecycleScope
.
launch
{
delay
(
5000
)
delay
(
5000
)
HighMap
Api
.
setCarBottomCircle
(
false
)
HighMap
.
setCarBottomCircle
(
false
)
HighMap
Api
.
setCarRadarDirection
(
0
)
HighMap
.
setCarRadarDirection
(
0
)
}
}
}
}
...
...
app/src/main/res/layout/activity_on_line_map.xml
0 → 100644
View file @
3ebc9c25
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android=
"http://schemas.android.com/apk/res/android"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
android:orientation=
"vertical"
>
<LinearLayout
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
>
<Button
android:id=
"@+id/bt1"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:text=
"车辆移动"
/>
</LinearLayout>
<com.sd.api.ui.MapMultiView
android:id=
"@+id/mapMultiView"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
/>
</LinearLayout>
\ No newline at end of file
mapapi/src/main/java/com/sd/api/highmap/HighMap
Api
.kt
→
mapapi/src/main/java/com/sd/api/highmap/HighMap.kt
View file @
3ebc9c25
...
@@ -8,9 +8,9 @@ import com.unity3d.player.UnityPlayer
...
@@ -8,9 +8,9 @@ import com.unity3d.player.UnityPlayer
/**
/**
* 四维高精地图
Api
* 四维高精地图
操作
*/
*/
object
HighMap
Api
:
MsOperationParent
()
{
object
HighMap
:
MsOperationParent
()
{
private
var
gson
=
Gson
()
private
var
gson
=
Gson
()
...
...
mapapi/src/main/java/com/sd/api/maps/MSNavi.kt
View file @
3ebc9c25
...
@@ -65,6 +65,19 @@ object MSNavi {
...
@@ -65,6 +65,19 @@ object MSNavi {
}
}
}
}
/**结束导航**/
fun
endNavi
()
{
when
(
MSDKInitializer
.
getMapType
())
{
MAP_TYPE
.
MINE
->
{
}
MAP_TYPE
.
AMAP
->
{
}
}
}
fun
startSimNavi
(
fun
startSimNavi
(
mapReadView
:
MapReadyView
?,
mapReadView
:
MapReadyView
?,
...
...
mapapi/src/main/java/com/sd/api/maps/amap/AmapRoutePlans.kt
View file @
3ebc9c25
...
@@ -131,6 +131,14 @@ class AmapRoutePlans {
...
@@ -131,6 +131,14 @@ class AmapRoutePlans {
}
}
/***删除路径*/
fun
deleteRoute
()
{
if
(
routeOverlay
!=
null
)
{
routeOverlay
?.
removeFromMap
()
routeOverlay
=
null
}
}
// private fun drawRoutes(
// private fun drawRoutes(
// routeId: Int,
// routeId: Int,
// path: AMapNaviPath,
// path: AMapNaviPath,
...
...
mapapi/src/main/java/com/sd/api/maps/mine/MineNai.kt
View file @
3ebc9c25
...
@@ -113,8 +113,6 @@ object MineNai {
...
@@ -113,8 +113,6 @@ object MineNai {
context
?.
startActivity
(
inten
)
context
?.
startActivity
(
inten
)
}
}
//是否正在导航
private
var
mIsInNavigation
=
false
/**
/**
* 直接使用RouteBase开启导航
* 直接使用RouteBase开启导航
...
@@ -132,12 +130,10 @@ object MineNai {
...
@@ -132,12 +130,10 @@ object MineNai {
// mNaviSession?.addMineNaviListener(myMineNaviListener)
// mNaviSession?.addMineNaviListener(myMineNaviListener)
val
starPoint
=
Tools
.
latLngToPoint
(
LatLng
(
mStartPoint
.
lat
,
mStartPoint
.
lng
))
val
starPoint
=
Tools
.
latLngToPoint
(
LatLng
(
mStartPoint
.
lat
,
mStartPoint
.
lng
))
drawNavingCar
(
starPoint
)
drawNavingCar
(
starPoint
)
mIsInNavigation
=
true
mNaviSession
?.
takeRoute
(
routeBase
)
mNaviSession
?.
takeRoute
(
routeBase
)
}
}
fun
stopNavi
()
{
fun
stopNavi
()
{
mIsInNavigation
=
false
mNaviSession
?.
removeRoute
()
mNaviSession
?.
removeRoute
()
}
}
...
...
mapapi/src/main/java/com/sd/api/maps/mine/MineRoutePlans.kt
View file @
3ebc9c25
...
@@ -16,6 +16,7 @@ import com.minedata.minenavi.util.Tools
...
@@ -16,6 +16,7 @@ import com.minedata.minenavi.util.Tools
import
com.sd.api.bean.DriverRouteBean
import
com.sd.api.bean.DriverRouteBean
import
com.sd.api.bean.WayPoi
import
com.sd.api.bean.WayPoi
import
com.sd.api.intfaces.MyMineNaviListener
import
com.sd.api.intfaces.MyMineNaviListener
import
com.sd.api.maps.MsOperationParent
import
com.sd.api.maps.cdata.MSLatLng
import
com.sd.api.maps.cdata.MSLatLng
import
com.sd.api.maps.inters.OnDriveRoute
import
com.sd.api.maps.inters.OnDriveRoute
import
com.sd.api.ui.MapReadyView
import
com.sd.api.ui.MapReadyView
...
@@ -152,6 +153,13 @@ object MineRoutePlans {
...
@@ -152,6 +153,13 @@ object MineRoutePlans {
// mapReadView?.mMineMap?.setElevation(0f)
// mapReadView?.mMineMap?.setElevation(0f)
}
}
/***删除路径*/
fun
deleteRoute
()
{
if
(
mRoute
!=
null
)
{
mapReadView
?.
mMineMap
?.
removeOverlay
(
mRoute
)
mRoute
=
null
}
}
// /**自定义驾车路线返回*/
// /**自定义驾车路线返回*/
// interface OnDriveRoute {
// interface OnDriveRoute {
...
...
mapapi/src/main/java/com/sd/api/scenario/CucsVehicle.kt
View file @
3ebc9c25
package
com.sd.api.scenario
package
com.sd.api.scenario
import
androidx.lifecycle.viewModelScope
import
com.minedata.minenavi.mapdal.LatLng
import
com.sd.api.highmap.CarNavPath
import
com.sd.api.highmap.CarNavPath
import
com.sd.api.highmap.HighMap
Api
import
com.sd.api.highmap.HighMap
import
com.sd.api.highmap.HighPos
import
com.sd.api.highmap.HighPos
import
com.sd.api.parkroad.MsParkRoad
import
com.sd.api.parkroad.MsParkRoad
import
com.sd.api.parkroad.RoadPos
import
com.sd.api.parkroad.RoadPos
import
com.sd.api.utils.SmoothMoveUtils
import
kotlinx.coroutines.CoroutineScope
import
kotlinx.coroutines.CoroutineScope
import
kotlinx.coroutines.Dispatchers
import
kotlinx.coroutines.Dispatchers
import
kotlinx.coroutines.launch
import
kotlinx.coroutines.launch
...
@@ -14,36 +17,111 @@ object CucsVehicle {
...
@@ -14,36 +17,111 @@ object CucsVehicle {
private
var
stopCar
=
false
private
var
stopCar
=
false
//动画是否开始
private
var
isAniStart
=
false
//前一次位置
private
var
fromLoc
:
VehiclePos
?
=
null
//当前位置
private
var
cvPos
:
VehiclePos
?
=
null
//保存上一次位置的时间
private
var
oldTime
=
0L
//2次定位的时间差,默认1000毫秒
private
var
vehTimeDiff
=
1000L
/**
/**
* 移动车辆
* 移动车辆
* @param
car
Pos 车辆位置
* @param
v
Pos 车辆位置
* @param moveType 1=高精地图 2= 局部地图
-1=两者都包括
* @param moveType 1=高精地图 2= 局部地图
3=在线地图
*/
*/
fun
moveCar
(
vehiclePos
:
VehiclePos
,
moveType
:
Int
)
{
fun
moveCar
(
vPos
:
VehiclePos
,
moveType
:
Int
)
{
cvPos
=
vPos
var
highPos
=
HighPos
.
instance
.
apply
{
var
highPos
=
HighPos
.
instance
.
apply
{
heading
=
v
ehicle
Pos
.
heading
heading
=
vPos
.
heading
lat
=
v
ehicle
Pos
.
lat
lat
=
vPos
.
lat
lon
=
v
ehicle
Pos
.
lng
lon
=
vPos
.
lng
evel
=
v
ehicle
Pos
.
evel
evel
=
vPos
.
evel
}
}
var
roadPos
=
RoadPos
.
instance
.
apply
{
var
roadPos
=
RoadPos
.
instance
.
apply
{
lat
=
v
ehicle
Pos
.
lat
lat
=
vPos
.
lat
lng
=
v
ehicle
Pos
.
lng
lng
=
vPos
.
lng
bearing
=
v
ehicle
Pos
.
heading
.
toFloat
()
bearing
=
vPos
.
heading
.
toFloat
()
}
}
if
(
moveType
==
1
)
{
if
(
moveType
==
1
)
{
HighMap
Api
.
setCarPosition
(
highPos
)
HighMap
.
setCarPosition
(
highPos
)
}
else
if
(
moveType
==
2
)
{
}
else
if
(
moveType
==
2
)
{
MsParkRoad
.
updateMainCar
(
roadPos
,
null
)
MsParkRoad
.
updateMainCar
(
roadPos
,
null
)
}
else
if
(
moveType
==
-
1
)
{
}
else
if
(
moveType
==
3
)
{
CoroutineScope
(
Dispatchers
.
Default
).
launch
{
if
(
fromLoc
==
null
||
fromLoc
?.
lng
==
0.0
)
{
HighMapApi
.
setCarPosition
(
highPos
)
setFromMyLoc
(
vPos
)
//设置起始位置
MsParkRoad
.
updateMainCar
(
roadPos
,
null
)
}
//计算2次定位时间差
calTimeDiff
()
if
(
isAniStart
==
false
)
{
isAniStart
=
true
SmoothMoveUtils
.
startSmoothMove
(
LatLng
(
fromLoc
!!
.
lat
,
fromLoc
!!
.
lng
),
LatLng
(
vPos
.
lat
,
vPos
.
lng
),
vehTimeDiff
,
sCarSmooth
)
}
}
}
//在线地图主车平滑移动
private
var
sCarSmooth
=
object
:
SmoothMoveUtils
.
OnPositionUpdateListener
{
override
fun
onUpdate
(
iLatLng
:
LatLng
,
bearing
:
Float
)
{
//在线地图主车平滑移动
VehicleModel
.
upMyLocCarModel
(
iLatLng
.
latitude
,
iLatLng
.
longitude
,
cvPos
?.
heading
?.
toFloat
()
?:
0f
)
}
override
fun
onFinish
()
{
// println("--------------动画完成")
setFromMyLoc
(
cvPos
!!
)
isAniStart
=
false
}
}
//计算2次拿到车辆定位的时间差
fun
calTimeDiff
()
{
CoroutineScope
(
Dispatchers
.
Default
).
launch
{
if
(
oldTime
!=
0L
)
{
vehTimeDiff
=
System
.
currentTimeMillis
()
-
oldTime
// println("-------定位时间差 = ${vehTimeDiff}")
}
}
oldTime
=
System
.
currentTimeMillis
()
}
}
}
}
//设置前一个点
private
fun
setFromMyLoc
(
myloc
:
VehiclePos
)
{
if
(
fromLoc
==
null
)
{
fromLoc
=
VehiclePos
()
}
fromLoc
!!
.
run
{
this
.
lat
=
myloc
.
lat
this
.
lng
=
myloc
.
lng
this
.
heading
=
myloc
.
heading
this
.
evel
=
myloc
.
evel
}
}
/**
* 停止车辆移动
*/
fun
stopCar
()
{
fun
stopCar
()
{
stopCar
=
true
stopCar
=
true
}
}
...
@@ -54,7 +132,7 @@ object CucsVehicle {
...
@@ -54,7 +132,7 @@ object CucsVehicle {
* @param carNavPath
* @param carNavPath
*/
*/
fun
setCarNaiPath
(
carNavPath
:
CarNavPath
)
{
fun
setCarNaiPath
(
carNavPath
:
CarNavPath
)
{
HighMap
Api
.
setCarNavPath
(
carNavPath
)
HighMap
.
setCarNavPath
(
carNavPath
)
}
}
/**
/**
...
@@ -62,7 +140,7 @@ object CucsVehicle {
...
@@ -62,7 +140,7 @@ object CucsVehicle {
*/
*/
fun
clearCarNaiPath
()
{
fun
clearCarNaiPath
()
{
var
carNavPath
=
CarNavPath
()
var
carNavPath
=
CarNavPath
()
HighMap
Api
.
setCarNavPath
(
carNavPath
)
HighMap
.
setCarNavPath
(
carNavPath
)
}
}
}
}
\ No newline at end of file
mapapi/src/main/java/com/sd/api/scenario/VehicleModel.kt
0 → 100644
View file @
3ebc9c25
package
com.sd.api.scenario
import
android.util.Log
import
androidx.lifecycle.viewModelScope
import
com.minedata.minenavi.map.Model
import
com.minedata.minenavi.map.ModelOptions
import
com.minedata.minenavi.map.Overlay
import
com.minedata.minenavi.mapdal.LatLng
import
com.sd.api.MAP_TYPE
import
com.sd.api.MSDKInitializer
import
com.sd.api.UserCtx
import
com.sd.api.maps.MsOperationParent
import
com.sd.api.utils.FileIoUtils
import
com.unity3d.player.UnityPlayer
import
kotlinx.coroutines.CoroutineScope
import
kotlinx.coroutines.Dispatchers
import
kotlinx.coroutines.launch
import
java.io.File
import
java.io.IOException
/**网联车模型**/
object
VehicleModel
:
MsOperationParent
()
{
//在线地图用户当前位置模型
private
var
mainCarMo
:
Model
?
=
null
//主车obj模型
private
var
objPath
=
""
//在线地图小车是否加载完毕
private
var
loadAddCar
=
false
/****加载主车特斯拉模型***/
suspend
fun
loadMainCar
()
{
var
context
=
UserCtx
.
instance
.
mContext
// CoroutineScope(Dispatchers.IO).launch {
try
{
var
parentFileDir
=
File
(
context
?.
filesDir
,
"models/car_model"
)
if
(!
parentFileDir
.
exists
())
parentFileDir
.
mkdirs
()
objPath
=
FileIoUtils
.
assetFilePath
(
context
!!
,
"models/car_model/gszh_xyz.obj"
)
// Log.d("-----", "✅ OBJ文件复制成功: " + objPath)
var
path
=
FileIoUtils
.
assetFilePath
(
context
,
"models/car_model/gszh_xyz.mtl"
)
// Log.d("-----", "✅ 纹理文件复制成功: " + path)
path
=
FileIoUtils
.
assetFilePath
(
context
,
"models/car_model/Binary_0.jpeg"
)
// Log.d("-----", "✅ 材质文件复制成功: " + path)
}
catch
(
e
:
IOException
)
{
e
.
printStackTrace
()
}
// }
}
/****更新模型位置**/
fun
upMyLocCarModel
(
lat
:
Double
,
lng
:
Double
,
heading
:
Float
)
{
when
(
MSDKInitializer
.
getMapType
())
{
MAP_TYPE
.
MINE
->
{
CoroutineScope
(
Dispatchers
.
Default
).
launch
{
loadMainCar
()
if
(!
loadAddCar
)
{
loadAddCar
=
true
addMyLocCarModel
(
lat
,
lng
,
heading
)
}
var
cHeading
=
0f
-
180f
-
heading
mainCarMo
?.
setPosition
(
LatLng
(
lat
,
lng
))
mainCarMo
?.
setHeading
(
cHeading
)
}
}
MAP_TYPE
.
AMAP
->
{
}
}
}
/****添加我的定位小车模型
* 这小车模型航向角0是冲下的
* ***/
suspend
fun
addMyLocCarModel
(
lat
:
Double
,
lng
:
Double
,
heading
:
Float
)
{
when
(
MSDKInitializer
.
getMapType
())
{
MAP_TYPE
.
MINE
->
{
if
(
objPath
.
isEmpty
()
||
lat
==
0.0
||
lng
==
0.0
)
return
if
(
mainCarMo
!=
null
)
return
var
mMineMap
=
getMapReadView
()
?.
mMineMap
// 模型文件相对路径
var
modelOptions
=
ModelOptions
()
.
objFile
(
objPath
)
.
position
(
LatLng
(
lat
,
lng
))
.
layer
(
Overlay
.
Layer
.
aboveMarker
)
.
heading
(
heading
)
.
keepScaleSize
(
8f
)
// 保持尺寸的比例尺
.
scaleFactor
(
0.007f
)
// 缩放因子
.
visible
(
true
)
mainCarMo
=
mMineMap
?.
addModel
(
modelOptions
)
}
MAP_TYPE
.
AMAP
->
{
}
}
}
//删除互联网地图上的车模型
fun
deleteMyLocModel
()
{
if
(
mainCarMo
!=
null
)
{
var
mMineMap
=
getMapReadView
()
?.
mMineMap
mMineMap
?.
removeOverlay
(
mainCarMo
)
mainCarMo
=
null
}
}
}
\ No newline at end of file
mapapi/src/main/java/com/sd/api/utils/SmoothMoveUtils.java
View file @
3ebc9c25
...
@@ -35,7 +35,7 @@ public class SmoothMoveUtils {
...
@@ -35,7 +35,7 @@ public class SmoothMoveUtils {
animator
.
setDuration
(
durationMillis
);
animator
.
setDuration
(
durationMillis
);
animator
.
setInterpolator
(
new
LinearInterpolator
());
animator
.
setInterpolator
(
new
LinearInterpolator
());
float
bearing
=
calculateBearing
(
from
,
to
);
//
float bearing = calculateBearing(from, to);
animator
.
addUpdateListener
(
animation
->
{
animator
.
addUpdateListener
(
animation
->
{
float
fraction
=
(
float
)
animation
.
getAnimatedValue
();
float
fraction
=
(
float
)
animation
.
getAnimatedValue
();
...
@@ -44,7 +44,7 @@ public class SmoothMoveUtils {
...
@@ -44,7 +44,7 @@ public class SmoothMoveUtils {
double
lng
=
from
.
longitude
+
(
to
.
longitude
-
from
.
longitude
)
*
fraction
;
double
lng
=
from
.
longitude
+
(
to
.
longitude
-
from
.
longitude
)
*
fraction
;
LatLng
interpolated
=
new
LatLng
(
lat
,
lng
);
LatLng
interpolated
=
new
LatLng
(
lat
,
lng
);
listener
.
onUpdate
(
interpolated
,
bearing
);
// 实时位置 + 朝向角
listener
.
onUpdate
(
interpolated
,
0
);
// 实时位置 + 朝向角
});
});
animator
.
addListener
(
new
AnimatorListenerAdapter
()
{
animator
.
addListener
(
new
AnimatorListenerAdapter
()
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment