diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index f8a5cfe..6ea5faa 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -67,7 +67,7 @@
+ android:value="2e964a64f7e7afe1f8520b0315919d1b" />
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index f8a5cfe..6ea5faa 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -67,7 +67,7 @@
+ android:value="2e964a64f7e7afe1f8520b0315919d1b" />
diff --git a/app/src/main/java/com/casic/br/ktd/fragment/HomePageFragment.kt b/app/src/main/java/com/casic/br/ktd/fragment/HomePageFragment.kt
index 8373e43..9a226a9 100644
--- a/app/src/main/java/com/casic/br/ktd/fragment/HomePageFragment.kt
+++ b/app/src/main/java/com/casic/br/ktd/fragment/HomePageFragment.kt
@@ -3,8 +3,6 @@
import android.annotation.SuppressLint
import android.graphics.Color
import android.os.Bundle
-import android.os.Handler
-import android.os.Message
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
@@ -14,6 +12,7 @@
import com.amap.api.maps.AMap
import com.amap.api.maps.AMapOptions
import com.amap.api.maps.CameraUpdateFactory
+import com.amap.api.maps.CoordinateConverter
import com.amap.api.maps.model.BitmapDescriptorFactory
import com.amap.api.maps.model.CameraPosition
import com.amap.api.maps.model.LatLng
@@ -24,41 +23,36 @@
import com.casic.br.ktd.databinding.FragmentHomeBinding
import com.casic.br.ktd.extensions.toChineseAddress
import com.casic.br.ktd.listener.OnGeocodeSearchListener
-import com.casic.br.ktd.model.DeviceListModel
import com.casic.br.ktd.model.TaskListModel
import com.casic.br.ktd.model.VehicleListModel
import com.casic.br.ktd.utils.ChartViewHub
import com.casic.br.ktd.utils.DateType
import com.casic.br.ktd.utils.LocaleConstant
-import com.casic.br.ktd.vm.DeviceViewModel
import com.casic.br.ktd.vm.TaskViewModel
import com.casic.br.ktd.vm.VehicleViewModel
import com.github.mikephil.charting.data.Entry
import com.pengxh.kt.lite.base.KotlinBaseFragment
+import com.pengxh.kt.lite.extensions.show
import com.pengxh.kt.lite.extensions.timestampToDate
import com.pengxh.kt.lite.extensions.timestampToLastMonthDate
import com.pengxh.kt.lite.extensions.toJson
import com.pengxh.kt.lite.utils.SaveKeyValues
-import com.pengxh.kt.lite.utils.WeakReferenceHandler
import com.qmuiteam.qmui.widget.roundwidget.QMUIRoundButton
import org.json.JSONObject
import java.text.DecimalFormat
@SuppressLint("SetTextI18n")
class HomePageFragment : KotlinBaseFragment(), AMap.OnMarkerClickListener,
- AMap.InfoWindowAdapter, Handler.Callback {
+ AMap.InfoWindowAdapter {
private val kTag = "HomePageFragment"
private val dFormat by lazy { DecimalFormat("0.00") }
private lateinit var vehicleViewModel: VehicleViewModel
- private lateinit var deviceViewModel: DeviceViewModel
private lateinit var taskViewModel: TaskViewModel
private lateinit var aMap: AMap
- private lateinit var weakReferenceHandler: WeakReferenceHandler
- private var isInfoWindowShow = false
+ private lateinit var v: View
+ private lateinit var vehicleModel: VehicleListModel.DataModel
private var taskModels: MutableList = ArrayList()
- private val handlerVehicleCode = 2023082501
- private val handlerDeviceCode = 2023082502
override fun initViewBinding(
inflater: LayoutInflater, container: ViewGroup?
@@ -80,31 +74,7 @@
// 点击marker弹出自定义popup
aMap.setInfoWindowAdapter(this)
- weakReferenceHandler = WeakReferenceHandler(this)
-
- vehicleViewModel = ViewModelProvider(this)[VehicleViewModel::class.java]
- vehicleViewModel.getVehicles()
- vehicleViewModel.vehicleList.observe(this) {
- if (it.code == 200) {
- if (it.data.rows.isNotEmpty()) {
- val message = weakReferenceHandler.obtainMessage()
- message.what = handlerVehicleCode
- message.obj = it.data.rows[0]
- weakReferenceHandler.sendMessage(message)
- }
- }
- }
-
- deviceViewModel = ViewModelProvider(this)[DeviceViewModel::class.java]
- deviceViewModel.deviceList.observe(this) {
- if (it.code == 200) {
- val message = weakReferenceHandler.obtainMessage()
- message.what = handlerDeviceCode
- message.obj = it.data.rows[0]
- weakReferenceHandler.sendMessage(message)
- }
- }
-
+ /***任务统计*************************************************************************/
taskViewModel = ViewModelProvider(this)[TaskViewModel::class.java]
val time = System.currentTimeMillis()
taskViewModel.getTaskCount(
@@ -123,6 +93,8 @@
binding.dayTaskDistanceView.text = dFormat.format(it.data.km)
}
}
+
+ /***任务趋势*************************************************************************/
taskViewModel.getTaskTrend("", "", "")
taskViewModel.taskTrendModel.observe(this) {
if (it.code == 200) {
@@ -141,126 +113,138 @@
ChartViewHub.setLineChartData(binding.taskTrendChart, xAxisLabels, strengthEntries)
}
}
+
+ /***地图车辆*************************************************************************/
+ vehicleViewModel = ViewModelProvider(this)[VehicleViewModel::class.java]
+ vehicleViewModel.getVehicles()
+ vehicleViewModel.vehicleList.observe(this) {
+ if (it.code == 200) {
+ if (it.data.isNotEmpty()) {
+ vehicleModel = it.data.first()
+
+ SaveKeyValues.putValue(LocaleConstant.CAR_NUMBER, vehicleModel.carPlate)
+ SaveKeyValues.putValue(LocaleConstant.CAR_ID, vehicleModel.id)
+
+ val marker = if (vehicleModel.status == "1") {
+ //在线
+ R.mipmap.vehicle_on
+ } else {
+ //离线
+ R.mipmap.vehicle_on
+ }
+
+ if (vehicleModel.latitude == "" || vehicleModel.longitude == "") {
+ "无法查询到最新的巡检任务车辆".show(requireContext())
+ return@observe
+ }
+
+ val latLng = LatLng(
+ vehicleModel.latitude.toDouble(), vehicleModel.longitude.toDouble()
+ )
+
+ val hashMap = HashMap()
+ hashMap["type"] = "Car"
+ hashMap["id"] = vehicleModel.id
+
+ addMarker(latLng, hashMap.toJson(), marker)
+
+ //移动到巡检车经纬度
+ val cameraPosition = CameraPosition(latLng, 16f, 0f, 0f)
+ val cameraUpdate = CameraUpdateFactory.newCameraPosition(cameraPosition)
+ aMap.animateCamera(cameraUpdate)
+ }
+ }
+ }
+
+ /***地图任务*************************************************************************/
taskViewModel.getTasksByPage("", "", "", "", 1)
taskViewModel.taskList.observe(this) {
if (it.code == 200) {
taskModels = it.data.rows!!
- taskModels.forEach { row ->
- if (row.latitude.isNotEmpty() && row.longitude.isNotEmpty()) {
+ taskModels.forEach { task ->
+ if (task.latitude.isNotEmpty() && task.longitude.isNotEmpty()) {
val latLng = LatLng(
- row.latitude.toDouble(), row.longitude.toDouble()
+ task.latitude.toDouble(), task.longitude.toDouble()
)
val hashMap = HashMap()
hashMap["type"] = "Task"
- hashMap["id"] = row.id
+ hashMap["id"] = task.id
addMarker(latLng, hashMap.toJson(), R.mipmap.task_on)
}
}
}
}
+
+ /***地图任务轨迹*************************************************************************/
vehicleViewModel.routeResult.observe(this) {
if (it.code == 200) {
//设置起点
val first = it.data.first()
- addMarker(
- LatLng(first.lagitude.toDouble(), first.longitude.toDouble()),
- "",
- R.mipmap.start
+ if (first.lagitude == "" || first.longitude == "") {
+ "任务起点经纬度异常".show(requireContext())
+ return@observe
+ }
+ aMap.addMarker(
+ MarkerOptions()
+ .position(LatLng(first.lagitude.toDouble(), first.longitude.toDouble()))
+ .icon(BitmapDescriptorFactory.fromResource(R.mipmap.start))
)
+
//设置终点
val last = it.data.last()
- addMarker(
- LatLng(last.lagitude.toDouble(), last.longitude.toDouble()),
- "",
- R.mipmap.end
+ if (last.lagitude == "" || last.longitude == "") {
+ "任务起点经纬度异常".show(requireContext())
+ return@observe
+ }
+ aMap.addMarker(
+ MarkerOptions()
+ .position(LatLng(last.lagitude.toDouble(), last.longitude.toDouble()))
+ .icon(BitmapDescriptorFactory.fromResource(R.mipmap.end))
)
it.data.forEach { task ->
if (task.lagitude.isNotEmpty() && task.longitude.isNotEmpty()) {
- //瞄点画线
- val latLngPoints = ArrayList()
- latLngPoints.add(
- LatLng(task.lagitude.toDouble(), task.longitude.toDouble())
- )
- aMap.addPolyline(
- PolylineOptions()
- .addAll(latLngPoints)
- .width(10.toFloat())
- .color(Color.RED)
- )
- }
- }
- }
- }
- }
-
- override fun handleMessage(msg: Message): Boolean {
- when (msg.what) {
- handlerVehicleCode -> {
- val vehicleModel = msg.obj as VehicleListModel.DataModel.RowsModel
-
- SaveKeyValues.putValue(LocaleConstant.CAR_NUMBER, vehicleModel.carPlate)
- SaveKeyValues.putValue(LocaleConstant.CAR_ID, vehicleModel.id)
-
- val marker = if (vehicleModel.status == "1") {
- //在线
- R.mipmap.vehicle_on
- } else {
- //离线
- R.mipmap.vehicle_on
- }
-
- val latLng = LatLng(
- vehicleModel.latitude.toDouble(), vehicleModel.longitude.toDouble()
- )
- val hashMap = HashMap()
- hashMap["type"] = "Car"
- hashMap["id"] = vehicleModel.id
-
- addMarker(latLng, hashMap.toJson(), marker)
-
- //移动到巡检车经纬度
- val cameraPosition = CameraPosition(latLng, 16f, 0f, 0f)
- val cameraUpdate = CameraUpdateFactory.newCameraPosition(cameraPosition)
- aMap.animateCamera(cameraUpdate, 1500, null)
-
- /**
- * 地图PopupWindow数据绑定
- * ****/
- if (isInfoWindowShow) {
- windowTitleView.text = vehicleModel.carPlate
- val state = if (vehicleModel.status == "1") {
- "状态:在线"
- } else {
- "状态:离线"
- }
- carStateView.text = state
-
- timeView.text = "时间:${vehicleModel.ts}"
- latLng.toChineseAddress(object : OnGeocodeSearchListener {
- override fun onRegionCodeSearched(address: String) {
- locationView.text = "位置:$address"
+ if (CoordinateConverter.isAMapDataAvailable(
+ task.lagitude.toDouble(), task.longitude.toDouble()
+ )
+ ) {
+ //瞄点画线
+ val latLngPoints = ArrayList()
+ latLngPoints.add(
+ LatLng(task.lagitude.toDouble(), task.longitude.toDouble())
+ )
+ aMap.addPolyline(
+ PolylineOptions()
+ .addAll(latLngPoints)
+ .width(10.toFloat())
+ .color(Color.RED)
+ )
}
- })
- }
- }
-
- handlerDeviceCode -> {
- if (isInfoWindowShow) {
- val deviceModel = msg.obj as DeviceListModel.DataModel.RowsModel
-
- deviceModelView.text = "云台型号:${deviceModel.deviceModel}"
+ }
}
}
}
- return true
}
override fun onMarkerClick(marker: Marker?): Boolean {
- //点击Marker显示自定义Popup
- marker?.showInfoWindow()
- return true
+ val clickedMarker = marker?.snippet
+ if (!clickedMarker.isNullOrEmpty()) {
+ val jsonObject = JSONObject(clickedMarker)
+ val type = jsonObject.getString("type")
+
+ v = if (type == "Car") {
+ LayoutInflater.from(requireContext()).inflate(R.layout.popu_map_car_window, null)
+ } else {
+ LayoutInflater.from(requireContext()).inflate(R.layout.popu_map_task_window, null)
+ }
+
+ //点击Marker显示自定义Popup
+ marker.showInfoWindow()
+ return true
+ }
+
+ return false
}
/**
@@ -268,64 +252,75 @@
* */
override fun getInfoContents(p0: Marker?): View? = null
- private lateinit var windowTitleView: TextView
- private lateinit var taskStateView: QMUIRoundButton
- private lateinit var carStateView: TextView
- private lateinit var deviceModelView: TextView
- private lateinit var timeView: TextView
- private lateinit var locationView: TextView
-
override fun getInfoWindow(marker: Marker?): View {
- isInfoWindowShow = true
+ val clickedMarker = marker?.snippet
- val v = LayoutInflater.from(requireContext()).inflate(R.layout.popu_map_car_window, null)
-
- windowTitleView = v.findViewById(R.id.windowTitleView)
- taskStateView = v.findViewById(R.id.taskStateView)
- val closeView = v.findViewById(R.id.closeView)
- carStateView = v.findViewById(R.id.carStateView)
- deviceModelView = v.findViewById(R.id.deviceModelView)
- timeView = v.findViewById(R.id.timeView)
- locationView = v.findViewById(R.id.locationView)
- val routeView = v.findViewById(R.id.routeView)
-
- if (!marker?.snippet.isNullOrEmpty()) {
- val hashMapJson = marker?.snippet!!
- val jsonObject = JSONObject(hashMapJson)
+ if (!clickedMarker.isNullOrEmpty()) {
+ val jsonObject = JSONObject(clickedMarker)
val type = jsonObject.getString("type")
val id = jsonObject.getString("id")
if (type == "Car") {
- taskStateView.visibility = View.GONE
- routeView.visibility = View.GONE
+ val windowTitleView = v.findViewById(R.id.windowTitleView)
+ val closeView = v.findViewById(R.id.closeView)
+ val carStateView = v.findViewById(R.id.carStateView)
+ val deviceModelView = v.findViewById(R.id.deviceModelView)
+ val timeView = v.findViewById(R.id.timeView)
+ val locationView = v.findViewById(R.id.locationView)
- vehicleViewModel.getVehicles()
+ windowTitleView.text = vehicleModel.carPlate
+ val state = if (vehicleModel.status == "1") {
+ "状态:在线"
+ } else {
+ "状态:离线"
+ }
+ carStateView.text = state
+ deviceModelView.text = "车载云台型号:${vehicleModel.deviceModel}"
+ timeView.text = "时间:${vehicleModel.ts}"
+ val latLng = LatLng(
+ vehicleModel.latitude.toDouble(), vehicleModel.longitude.toDouble()
+ )
- deviceViewModel.getDevices()
+ latLng.toChineseAddress(object : OnGeocodeSearchListener {
+ override fun onRegionCodeSearched(address: String) {
+ locationView.text = "位置:$address"
+ }
+ })
+
+ closeView.setOnClickListener {
+ marker.hideInfoWindow()
+ }
} else {
- taskStateView.visibility = View.VISIBLE
- routeView.visibility = View.VISIBLE
+ val windowTitleView = v.findViewById(R.id.windowTitleView)
+ val taskStateView = v.findViewById(R.id.taskStateView)
+ val closeView = v.findViewById(R.id.closeView)
+ val carNumberView = v.findViewById(R.id.carNumberView)
+ val deviceModelView = v.findViewById(R.id.deviceModelView)
+ val startTimeView = v.findViewById(R.id.startTimeView)
+ val endTimeView = v.findViewById(R.id.endTimeView)
+ val routeView = v.findViewById(R.id.routeView)
taskModels.forEach { task ->
if (task.id == id) {
- windowTitleView.text = "${task.taskName}(${id})"
- carStateView.text = "巡检车牌号:${task.carPlate}"
- deviceModelView.text = "云台型号:${task.modelName}"
- timeView.text = "开始时间:${task.beginDate}"
- locationView.text = "结束时间:${task.endDate}"
+ windowTitleView.text = task.taskName
+ taskStateView.text = task.statusName
+ carNumberView.text = "巡检车牌号:${task.carPlate}"
+ deviceModelView.text = "车载云台型号:${task.modelName}"
+ startTimeView.text = "开始时间:${task.beginDate}"
+ endTimeView.text = "结束时间:${task.endDate}"
}
}
+ closeView.setOnClickListener {
+ marker.hideInfoWindow()
+ }
+
routeView.setOnClickListener {
vehicleViewModel.getVehicleRoute(id)
}
}
}
- closeView.setOnClickListener {
- marker?.hideInfoWindow()
- isInfoWindowShow = false
- }
return v
}
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index f8a5cfe..6ea5faa 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -67,7 +67,7 @@
+ android:value="2e964a64f7e7afe1f8520b0315919d1b" />
diff --git a/app/src/main/java/com/casic/br/ktd/fragment/HomePageFragment.kt b/app/src/main/java/com/casic/br/ktd/fragment/HomePageFragment.kt
index 8373e43..9a226a9 100644
--- a/app/src/main/java/com/casic/br/ktd/fragment/HomePageFragment.kt
+++ b/app/src/main/java/com/casic/br/ktd/fragment/HomePageFragment.kt
@@ -3,8 +3,6 @@
import android.annotation.SuppressLint
import android.graphics.Color
import android.os.Bundle
-import android.os.Handler
-import android.os.Message
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
@@ -14,6 +12,7 @@
import com.amap.api.maps.AMap
import com.amap.api.maps.AMapOptions
import com.amap.api.maps.CameraUpdateFactory
+import com.amap.api.maps.CoordinateConverter
import com.amap.api.maps.model.BitmapDescriptorFactory
import com.amap.api.maps.model.CameraPosition
import com.amap.api.maps.model.LatLng
@@ -24,41 +23,36 @@
import com.casic.br.ktd.databinding.FragmentHomeBinding
import com.casic.br.ktd.extensions.toChineseAddress
import com.casic.br.ktd.listener.OnGeocodeSearchListener
-import com.casic.br.ktd.model.DeviceListModel
import com.casic.br.ktd.model.TaskListModel
import com.casic.br.ktd.model.VehicleListModel
import com.casic.br.ktd.utils.ChartViewHub
import com.casic.br.ktd.utils.DateType
import com.casic.br.ktd.utils.LocaleConstant
-import com.casic.br.ktd.vm.DeviceViewModel
import com.casic.br.ktd.vm.TaskViewModel
import com.casic.br.ktd.vm.VehicleViewModel
import com.github.mikephil.charting.data.Entry
import com.pengxh.kt.lite.base.KotlinBaseFragment
+import com.pengxh.kt.lite.extensions.show
import com.pengxh.kt.lite.extensions.timestampToDate
import com.pengxh.kt.lite.extensions.timestampToLastMonthDate
import com.pengxh.kt.lite.extensions.toJson
import com.pengxh.kt.lite.utils.SaveKeyValues
-import com.pengxh.kt.lite.utils.WeakReferenceHandler
import com.qmuiteam.qmui.widget.roundwidget.QMUIRoundButton
import org.json.JSONObject
import java.text.DecimalFormat
@SuppressLint("SetTextI18n")
class HomePageFragment : KotlinBaseFragment(), AMap.OnMarkerClickListener,
- AMap.InfoWindowAdapter, Handler.Callback {
+ AMap.InfoWindowAdapter {
private val kTag = "HomePageFragment"
private val dFormat by lazy { DecimalFormat("0.00") }
private lateinit var vehicleViewModel: VehicleViewModel
- private lateinit var deviceViewModel: DeviceViewModel
private lateinit var taskViewModel: TaskViewModel
private lateinit var aMap: AMap
- private lateinit var weakReferenceHandler: WeakReferenceHandler
- private var isInfoWindowShow = false
+ private lateinit var v: View
+ private lateinit var vehicleModel: VehicleListModel.DataModel
private var taskModels: MutableList = ArrayList()
- private val handlerVehicleCode = 2023082501
- private val handlerDeviceCode = 2023082502
override fun initViewBinding(
inflater: LayoutInflater, container: ViewGroup?
@@ -80,31 +74,7 @@
// 点击marker弹出自定义popup
aMap.setInfoWindowAdapter(this)
- weakReferenceHandler = WeakReferenceHandler(this)
-
- vehicleViewModel = ViewModelProvider(this)[VehicleViewModel::class.java]
- vehicleViewModel.getVehicles()
- vehicleViewModel.vehicleList.observe(this) {
- if (it.code == 200) {
- if (it.data.rows.isNotEmpty()) {
- val message = weakReferenceHandler.obtainMessage()
- message.what = handlerVehicleCode
- message.obj = it.data.rows[0]
- weakReferenceHandler.sendMessage(message)
- }
- }
- }
-
- deviceViewModel = ViewModelProvider(this)[DeviceViewModel::class.java]
- deviceViewModel.deviceList.observe(this) {
- if (it.code == 200) {
- val message = weakReferenceHandler.obtainMessage()
- message.what = handlerDeviceCode
- message.obj = it.data.rows[0]
- weakReferenceHandler.sendMessage(message)
- }
- }
-
+ /***任务统计*************************************************************************/
taskViewModel = ViewModelProvider(this)[TaskViewModel::class.java]
val time = System.currentTimeMillis()
taskViewModel.getTaskCount(
@@ -123,6 +93,8 @@
binding.dayTaskDistanceView.text = dFormat.format(it.data.km)
}
}
+
+ /***任务趋势*************************************************************************/
taskViewModel.getTaskTrend("", "", "")
taskViewModel.taskTrendModel.observe(this) {
if (it.code == 200) {
@@ -141,126 +113,138 @@
ChartViewHub.setLineChartData(binding.taskTrendChart, xAxisLabels, strengthEntries)
}
}
+
+ /***地图车辆*************************************************************************/
+ vehicleViewModel = ViewModelProvider(this)[VehicleViewModel::class.java]
+ vehicleViewModel.getVehicles()
+ vehicleViewModel.vehicleList.observe(this) {
+ if (it.code == 200) {
+ if (it.data.isNotEmpty()) {
+ vehicleModel = it.data.first()
+
+ SaveKeyValues.putValue(LocaleConstant.CAR_NUMBER, vehicleModel.carPlate)
+ SaveKeyValues.putValue(LocaleConstant.CAR_ID, vehicleModel.id)
+
+ val marker = if (vehicleModel.status == "1") {
+ //在线
+ R.mipmap.vehicle_on
+ } else {
+ //离线
+ R.mipmap.vehicle_on
+ }
+
+ if (vehicleModel.latitude == "" || vehicleModel.longitude == "") {
+ "无法查询到最新的巡检任务车辆".show(requireContext())
+ return@observe
+ }
+
+ val latLng = LatLng(
+ vehicleModel.latitude.toDouble(), vehicleModel.longitude.toDouble()
+ )
+
+ val hashMap = HashMap()
+ hashMap["type"] = "Car"
+ hashMap["id"] = vehicleModel.id
+
+ addMarker(latLng, hashMap.toJson(), marker)
+
+ //移动到巡检车经纬度
+ val cameraPosition = CameraPosition(latLng, 16f, 0f, 0f)
+ val cameraUpdate = CameraUpdateFactory.newCameraPosition(cameraPosition)
+ aMap.animateCamera(cameraUpdate)
+ }
+ }
+ }
+
+ /***地图任务*************************************************************************/
taskViewModel.getTasksByPage("", "", "", "", 1)
taskViewModel.taskList.observe(this) {
if (it.code == 200) {
taskModels = it.data.rows!!
- taskModels.forEach { row ->
- if (row.latitude.isNotEmpty() && row.longitude.isNotEmpty()) {
+ taskModels.forEach { task ->
+ if (task.latitude.isNotEmpty() && task.longitude.isNotEmpty()) {
val latLng = LatLng(
- row.latitude.toDouble(), row.longitude.toDouble()
+ task.latitude.toDouble(), task.longitude.toDouble()
)
val hashMap = HashMap()
hashMap["type"] = "Task"
- hashMap["id"] = row.id
+ hashMap["id"] = task.id
addMarker(latLng, hashMap.toJson(), R.mipmap.task_on)
}
}
}
}
+
+ /***地图任务轨迹*************************************************************************/
vehicleViewModel.routeResult.observe(this) {
if (it.code == 200) {
//设置起点
val first = it.data.first()
- addMarker(
- LatLng(first.lagitude.toDouble(), first.longitude.toDouble()),
- "",
- R.mipmap.start
+ if (first.lagitude == "" || first.longitude == "") {
+ "任务起点经纬度异常".show(requireContext())
+ return@observe
+ }
+ aMap.addMarker(
+ MarkerOptions()
+ .position(LatLng(first.lagitude.toDouble(), first.longitude.toDouble()))
+ .icon(BitmapDescriptorFactory.fromResource(R.mipmap.start))
)
+
//设置终点
val last = it.data.last()
- addMarker(
- LatLng(last.lagitude.toDouble(), last.longitude.toDouble()),
- "",
- R.mipmap.end
+ if (last.lagitude == "" || last.longitude == "") {
+ "任务起点经纬度异常".show(requireContext())
+ return@observe
+ }
+ aMap.addMarker(
+ MarkerOptions()
+ .position(LatLng(last.lagitude.toDouble(), last.longitude.toDouble()))
+ .icon(BitmapDescriptorFactory.fromResource(R.mipmap.end))
)
it.data.forEach { task ->
if (task.lagitude.isNotEmpty() && task.longitude.isNotEmpty()) {
- //瞄点画线
- val latLngPoints = ArrayList()
- latLngPoints.add(
- LatLng(task.lagitude.toDouble(), task.longitude.toDouble())
- )
- aMap.addPolyline(
- PolylineOptions()
- .addAll(latLngPoints)
- .width(10.toFloat())
- .color(Color.RED)
- )
- }
- }
- }
- }
- }
-
- override fun handleMessage(msg: Message): Boolean {
- when (msg.what) {
- handlerVehicleCode -> {
- val vehicleModel = msg.obj as VehicleListModel.DataModel.RowsModel
-
- SaveKeyValues.putValue(LocaleConstant.CAR_NUMBER, vehicleModel.carPlate)
- SaveKeyValues.putValue(LocaleConstant.CAR_ID, vehicleModel.id)
-
- val marker = if (vehicleModel.status == "1") {
- //在线
- R.mipmap.vehicle_on
- } else {
- //离线
- R.mipmap.vehicle_on
- }
-
- val latLng = LatLng(
- vehicleModel.latitude.toDouble(), vehicleModel.longitude.toDouble()
- )
- val hashMap = HashMap()
- hashMap["type"] = "Car"
- hashMap["id"] = vehicleModel.id
-
- addMarker(latLng, hashMap.toJson(), marker)
-
- //移动到巡检车经纬度
- val cameraPosition = CameraPosition(latLng, 16f, 0f, 0f)
- val cameraUpdate = CameraUpdateFactory.newCameraPosition(cameraPosition)
- aMap.animateCamera(cameraUpdate, 1500, null)
-
- /**
- * 地图PopupWindow数据绑定
- * ****/
- if (isInfoWindowShow) {
- windowTitleView.text = vehicleModel.carPlate
- val state = if (vehicleModel.status == "1") {
- "状态:在线"
- } else {
- "状态:离线"
- }
- carStateView.text = state
-
- timeView.text = "时间:${vehicleModel.ts}"
- latLng.toChineseAddress(object : OnGeocodeSearchListener {
- override fun onRegionCodeSearched(address: String) {
- locationView.text = "位置:$address"
+ if (CoordinateConverter.isAMapDataAvailable(
+ task.lagitude.toDouble(), task.longitude.toDouble()
+ )
+ ) {
+ //瞄点画线
+ val latLngPoints = ArrayList()
+ latLngPoints.add(
+ LatLng(task.lagitude.toDouble(), task.longitude.toDouble())
+ )
+ aMap.addPolyline(
+ PolylineOptions()
+ .addAll(latLngPoints)
+ .width(10.toFloat())
+ .color(Color.RED)
+ )
}
- })
- }
- }
-
- handlerDeviceCode -> {
- if (isInfoWindowShow) {
- val deviceModel = msg.obj as DeviceListModel.DataModel.RowsModel
-
- deviceModelView.text = "云台型号:${deviceModel.deviceModel}"
+ }
}
}
}
- return true
}
override fun onMarkerClick(marker: Marker?): Boolean {
- //点击Marker显示自定义Popup
- marker?.showInfoWindow()
- return true
+ val clickedMarker = marker?.snippet
+ if (!clickedMarker.isNullOrEmpty()) {
+ val jsonObject = JSONObject(clickedMarker)
+ val type = jsonObject.getString("type")
+
+ v = if (type == "Car") {
+ LayoutInflater.from(requireContext()).inflate(R.layout.popu_map_car_window, null)
+ } else {
+ LayoutInflater.from(requireContext()).inflate(R.layout.popu_map_task_window, null)
+ }
+
+ //点击Marker显示自定义Popup
+ marker.showInfoWindow()
+ return true
+ }
+
+ return false
}
/**
@@ -268,64 +252,75 @@
* */
override fun getInfoContents(p0: Marker?): View? = null
- private lateinit var windowTitleView: TextView
- private lateinit var taskStateView: QMUIRoundButton
- private lateinit var carStateView: TextView
- private lateinit var deviceModelView: TextView
- private lateinit var timeView: TextView
- private lateinit var locationView: TextView
-
override fun getInfoWindow(marker: Marker?): View {
- isInfoWindowShow = true
+ val clickedMarker = marker?.snippet
- val v = LayoutInflater.from(requireContext()).inflate(R.layout.popu_map_car_window, null)
-
- windowTitleView = v.findViewById(R.id.windowTitleView)
- taskStateView = v.findViewById(R.id.taskStateView)
- val closeView = v.findViewById(R.id.closeView)
- carStateView = v.findViewById(R.id.carStateView)
- deviceModelView = v.findViewById(R.id.deviceModelView)
- timeView = v.findViewById(R.id.timeView)
- locationView = v.findViewById(R.id.locationView)
- val routeView = v.findViewById(R.id.routeView)
-
- if (!marker?.snippet.isNullOrEmpty()) {
- val hashMapJson = marker?.snippet!!
- val jsonObject = JSONObject(hashMapJson)
+ if (!clickedMarker.isNullOrEmpty()) {
+ val jsonObject = JSONObject(clickedMarker)
val type = jsonObject.getString("type")
val id = jsonObject.getString("id")
if (type == "Car") {
- taskStateView.visibility = View.GONE
- routeView.visibility = View.GONE
+ val windowTitleView = v.findViewById(R.id.windowTitleView)
+ val closeView = v.findViewById(R.id.closeView)
+ val carStateView = v.findViewById(R.id.carStateView)
+ val deviceModelView = v.findViewById(R.id.deviceModelView)
+ val timeView = v.findViewById(R.id.timeView)
+ val locationView = v.findViewById(R.id.locationView)
- vehicleViewModel.getVehicles()
+ windowTitleView.text = vehicleModel.carPlate
+ val state = if (vehicleModel.status == "1") {
+ "状态:在线"
+ } else {
+ "状态:离线"
+ }
+ carStateView.text = state
+ deviceModelView.text = "车载云台型号:${vehicleModel.deviceModel}"
+ timeView.text = "时间:${vehicleModel.ts}"
+ val latLng = LatLng(
+ vehicleModel.latitude.toDouble(), vehicleModel.longitude.toDouble()
+ )
- deviceViewModel.getDevices()
+ latLng.toChineseAddress(object : OnGeocodeSearchListener {
+ override fun onRegionCodeSearched(address: String) {
+ locationView.text = "位置:$address"
+ }
+ })
+
+ closeView.setOnClickListener {
+ marker.hideInfoWindow()
+ }
} else {
- taskStateView.visibility = View.VISIBLE
- routeView.visibility = View.VISIBLE
+ val windowTitleView = v.findViewById(R.id.windowTitleView)
+ val taskStateView = v.findViewById(R.id.taskStateView)
+ val closeView = v.findViewById(R.id.closeView)
+ val carNumberView = v.findViewById(R.id.carNumberView)
+ val deviceModelView = v.findViewById(R.id.deviceModelView)
+ val startTimeView = v.findViewById(R.id.startTimeView)
+ val endTimeView = v.findViewById(R.id.endTimeView)
+ val routeView = v.findViewById(R.id.routeView)
taskModels.forEach { task ->
if (task.id == id) {
- windowTitleView.text = "${task.taskName}(${id})"
- carStateView.text = "巡检车牌号:${task.carPlate}"
- deviceModelView.text = "云台型号:${task.modelName}"
- timeView.text = "开始时间:${task.beginDate}"
- locationView.text = "结束时间:${task.endDate}"
+ windowTitleView.text = task.taskName
+ taskStateView.text = task.statusName
+ carNumberView.text = "巡检车牌号:${task.carPlate}"
+ deviceModelView.text = "车载云台型号:${task.modelName}"
+ startTimeView.text = "开始时间:${task.beginDate}"
+ endTimeView.text = "结束时间:${task.endDate}"
}
}
+ closeView.setOnClickListener {
+ marker.hideInfoWindow()
+ }
+
routeView.setOnClickListener {
vehicleViewModel.getVehicleRoute(id)
}
}
}
- closeView.setOnClickListener {
- marker?.hideInfoWindow()
- isInfoWindowShow = false
- }
return v
}
diff --git a/app/src/main/java/com/casic/br/ktd/model/VehicleListModel.java b/app/src/main/java/com/casic/br/ktd/model/VehicleListModel.java
index 835e082..e0a5990 100644
--- a/app/src/main/java/com/casic/br/ktd/model/VehicleListModel.java
+++ b/app/src/main/java/com/casic/br/ktd/model/VehicleListModel.java
@@ -5,7 +5,7 @@
public class VehicleListModel {
private Integer code;
- private DataModel data;
+ private List data;
private String message;
public Integer getCode() {
@@ -16,11 +16,11 @@
this.code = code;
}
- public DataModel getData() {
+ public List getData() {
return data;
}
- public void setData(DataModel data) {
+ public void setData(List data) {
this.data = data;
}
@@ -33,197 +33,104 @@
}
public static class DataModel {
- private List rows;
- private Integer total;
+ private String carName;
+ private String carPlate;
+ private String deptId;
+ private String description;
+ private String deviceModel;
+ private String id;
+ private String latitude;
+ private String longitude;
+ private String status;
+ private String ts;
+ private String valid;
- public List getRows() {
- return rows;
+ public String getCarName() {
+ return carName;
}
- public void setRows(List rows) {
- this.rows = rows;
+ public void setCarName(String carName) {
+ this.carName = carName;
}
- public Integer getTotal() {
- return total;
+ public String getCarPlate() {
+ return carPlate;
}
- public void setTotal(Integer total) {
- this.total = total;
+ public void setCarPlate(String carPlate) {
+ this.carPlate = carPlate;
}
- public static class RowsModel {
- private String beginDate;
- private String carId;
- private String carPlate;
- private String description;
- private String description1;
- private String description2;
- private String endDate;
- private String id;
- private String km;
- private String latitude;
- private String longitude;
- private String modelName;
- private String status;
- private String statusName;
- private String taskCode;
- private String taskName;
- private String ts;
- private String updateTime;
- private String valid;
+ public String getDeptId() {
+ return deptId;
+ }
- public String getBeginDate() {
- return beginDate;
- }
+ public void setDeptId(String deptId) {
+ this.deptId = deptId;
+ }
- public void setBeginDate(String beginDate) {
- this.beginDate = beginDate;
- }
+ public String getDescription() {
+ return description;
+ }
- public String getCarId() {
- return carId;
- }
+ public void setDescription(String description) {
+ this.description = description;
+ }
- public void setCarId(String carId) {
- this.carId = carId;
- }
+ public String getDeviceModel() {
+ return deviceModel;
+ }
- public String getCarPlate() {
- return carPlate;
- }
+ public void setDeviceModel(String deviceModel) {
+ this.deviceModel = deviceModel;
+ }
- public void setCarPlate(String carPlate) {
- this.carPlate = carPlate;
- }
+ public String getId() {
+ return id;
+ }
- public String getDescription() {
- return description;
- }
+ public void setId(String id) {
+ this.id = id;
+ }
- public void setDescription(String description) {
- this.description = description;
- }
+ public String getLatitude() {
+ return latitude;
+ }
- public String getDescription1() {
- return description1;
- }
+ public void setLatitude(String latitude) {
+ this.latitude = latitude;
+ }
- public void setDescription1(String description1) {
- this.description1 = description1;
- }
+ public String getLongitude() {
+ return longitude;
+ }
- public String getDescription2() {
- return description2;
- }
+ public void setLongitude(String longitude) {
+ this.longitude = longitude;
+ }
- public void setDescription2(String description2) {
- this.description2 = description2;
- }
+ public String getStatus() {
+ return status;
+ }
- public String getEndDate() {
- return endDate;
- }
+ public void setStatus(String status) {
+ this.status = status;
+ }
- public void setEndDate(String endDate) {
- this.endDate = endDate;
- }
+ public String getTs() {
+ return ts;
+ }
- public String getId() {
- return id;
- }
+ public void setTs(String ts) {
+ this.ts = ts;
+ }
- public void setId(String id) {
- this.id = id;
- }
+ public String getValid() {
+ return valid;
+ }
- public String getKm() {
- return km;
- }
-
- public void setKm(String km) {
- this.km = km;
- }
-
- public String getLatitude() {
- return latitude;
- }
-
- public void setLatitude(String latitude) {
- this.latitude = latitude;
- }
-
- public String getLongitude() {
- return longitude;
- }
-
- public void setLongitude(String longitude) {
- this.longitude = longitude;
- }
-
- public String getModelName() {
- return modelName;
- }
-
- public void setModelName(String modelName) {
- this.modelName = modelName;
- }
-
- public String getStatus() {
- return status;
- }
-
- public void setStatus(String status) {
- this.status = status;
- }
-
- public String getStatusName() {
- return statusName;
- }
-
- public void setStatusName(String statusName) {
- this.statusName = statusName;
- }
-
- public String getTaskCode() {
- return taskCode;
- }
-
- public void setTaskCode(String taskCode) {
- this.taskCode = taskCode;
- }
-
- public String getTaskName() {
- return taskName;
- }
-
- public void setTaskName(String taskName) {
- this.taskName = taskName;
- }
-
- public String getTs() {
- return ts;
- }
-
- public void setTs(String ts) {
- this.ts = ts;
- }
-
- public String getUpdateTime() {
- return updateTime;
- }
-
- public void setUpdateTime(String updateTime) {
- this.updateTime = updateTime;
- }
-
- public String getValid() {
- return valid;
- }
-
- public void setValid(String valid) {
- this.valid = valid;
- }
+ public void setValid(String valid) {
+ this.valid = valid;
}
}
}
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index f8a5cfe..6ea5faa 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -67,7 +67,7 @@
+ android:value="2e964a64f7e7afe1f8520b0315919d1b" />
diff --git a/app/src/main/java/com/casic/br/ktd/fragment/HomePageFragment.kt b/app/src/main/java/com/casic/br/ktd/fragment/HomePageFragment.kt
index 8373e43..9a226a9 100644
--- a/app/src/main/java/com/casic/br/ktd/fragment/HomePageFragment.kt
+++ b/app/src/main/java/com/casic/br/ktd/fragment/HomePageFragment.kt
@@ -3,8 +3,6 @@
import android.annotation.SuppressLint
import android.graphics.Color
import android.os.Bundle
-import android.os.Handler
-import android.os.Message
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
@@ -14,6 +12,7 @@
import com.amap.api.maps.AMap
import com.amap.api.maps.AMapOptions
import com.amap.api.maps.CameraUpdateFactory
+import com.amap.api.maps.CoordinateConverter
import com.amap.api.maps.model.BitmapDescriptorFactory
import com.amap.api.maps.model.CameraPosition
import com.amap.api.maps.model.LatLng
@@ -24,41 +23,36 @@
import com.casic.br.ktd.databinding.FragmentHomeBinding
import com.casic.br.ktd.extensions.toChineseAddress
import com.casic.br.ktd.listener.OnGeocodeSearchListener
-import com.casic.br.ktd.model.DeviceListModel
import com.casic.br.ktd.model.TaskListModel
import com.casic.br.ktd.model.VehicleListModel
import com.casic.br.ktd.utils.ChartViewHub
import com.casic.br.ktd.utils.DateType
import com.casic.br.ktd.utils.LocaleConstant
-import com.casic.br.ktd.vm.DeviceViewModel
import com.casic.br.ktd.vm.TaskViewModel
import com.casic.br.ktd.vm.VehicleViewModel
import com.github.mikephil.charting.data.Entry
import com.pengxh.kt.lite.base.KotlinBaseFragment
+import com.pengxh.kt.lite.extensions.show
import com.pengxh.kt.lite.extensions.timestampToDate
import com.pengxh.kt.lite.extensions.timestampToLastMonthDate
import com.pengxh.kt.lite.extensions.toJson
import com.pengxh.kt.lite.utils.SaveKeyValues
-import com.pengxh.kt.lite.utils.WeakReferenceHandler
import com.qmuiteam.qmui.widget.roundwidget.QMUIRoundButton
import org.json.JSONObject
import java.text.DecimalFormat
@SuppressLint("SetTextI18n")
class HomePageFragment : KotlinBaseFragment(), AMap.OnMarkerClickListener,
- AMap.InfoWindowAdapter, Handler.Callback {
+ AMap.InfoWindowAdapter {
private val kTag = "HomePageFragment"
private val dFormat by lazy { DecimalFormat("0.00") }
private lateinit var vehicleViewModel: VehicleViewModel
- private lateinit var deviceViewModel: DeviceViewModel
private lateinit var taskViewModel: TaskViewModel
private lateinit var aMap: AMap
- private lateinit var weakReferenceHandler: WeakReferenceHandler
- private var isInfoWindowShow = false
+ private lateinit var v: View
+ private lateinit var vehicleModel: VehicleListModel.DataModel
private var taskModels: MutableList = ArrayList()
- private val handlerVehicleCode = 2023082501
- private val handlerDeviceCode = 2023082502
override fun initViewBinding(
inflater: LayoutInflater, container: ViewGroup?
@@ -80,31 +74,7 @@
// 点击marker弹出自定义popup
aMap.setInfoWindowAdapter(this)
- weakReferenceHandler = WeakReferenceHandler(this)
-
- vehicleViewModel = ViewModelProvider(this)[VehicleViewModel::class.java]
- vehicleViewModel.getVehicles()
- vehicleViewModel.vehicleList.observe(this) {
- if (it.code == 200) {
- if (it.data.rows.isNotEmpty()) {
- val message = weakReferenceHandler.obtainMessage()
- message.what = handlerVehicleCode
- message.obj = it.data.rows[0]
- weakReferenceHandler.sendMessage(message)
- }
- }
- }
-
- deviceViewModel = ViewModelProvider(this)[DeviceViewModel::class.java]
- deviceViewModel.deviceList.observe(this) {
- if (it.code == 200) {
- val message = weakReferenceHandler.obtainMessage()
- message.what = handlerDeviceCode
- message.obj = it.data.rows[0]
- weakReferenceHandler.sendMessage(message)
- }
- }
-
+ /***任务统计*************************************************************************/
taskViewModel = ViewModelProvider(this)[TaskViewModel::class.java]
val time = System.currentTimeMillis()
taskViewModel.getTaskCount(
@@ -123,6 +93,8 @@
binding.dayTaskDistanceView.text = dFormat.format(it.data.km)
}
}
+
+ /***任务趋势*************************************************************************/
taskViewModel.getTaskTrend("", "", "")
taskViewModel.taskTrendModel.observe(this) {
if (it.code == 200) {
@@ -141,126 +113,138 @@
ChartViewHub.setLineChartData(binding.taskTrendChart, xAxisLabels, strengthEntries)
}
}
+
+ /***地图车辆*************************************************************************/
+ vehicleViewModel = ViewModelProvider(this)[VehicleViewModel::class.java]
+ vehicleViewModel.getVehicles()
+ vehicleViewModel.vehicleList.observe(this) {
+ if (it.code == 200) {
+ if (it.data.isNotEmpty()) {
+ vehicleModel = it.data.first()
+
+ SaveKeyValues.putValue(LocaleConstant.CAR_NUMBER, vehicleModel.carPlate)
+ SaveKeyValues.putValue(LocaleConstant.CAR_ID, vehicleModel.id)
+
+ val marker = if (vehicleModel.status == "1") {
+ //在线
+ R.mipmap.vehicle_on
+ } else {
+ //离线
+ R.mipmap.vehicle_on
+ }
+
+ if (vehicleModel.latitude == "" || vehicleModel.longitude == "") {
+ "无法查询到最新的巡检任务车辆".show(requireContext())
+ return@observe
+ }
+
+ val latLng = LatLng(
+ vehicleModel.latitude.toDouble(), vehicleModel.longitude.toDouble()
+ )
+
+ val hashMap = HashMap()
+ hashMap["type"] = "Car"
+ hashMap["id"] = vehicleModel.id
+
+ addMarker(latLng, hashMap.toJson(), marker)
+
+ //移动到巡检车经纬度
+ val cameraPosition = CameraPosition(latLng, 16f, 0f, 0f)
+ val cameraUpdate = CameraUpdateFactory.newCameraPosition(cameraPosition)
+ aMap.animateCamera(cameraUpdate)
+ }
+ }
+ }
+
+ /***地图任务*************************************************************************/
taskViewModel.getTasksByPage("", "", "", "", 1)
taskViewModel.taskList.observe(this) {
if (it.code == 200) {
taskModels = it.data.rows!!
- taskModels.forEach { row ->
- if (row.latitude.isNotEmpty() && row.longitude.isNotEmpty()) {
+ taskModels.forEach { task ->
+ if (task.latitude.isNotEmpty() && task.longitude.isNotEmpty()) {
val latLng = LatLng(
- row.latitude.toDouble(), row.longitude.toDouble()
+ task.latitude.toDouble(), task.longitude.toDouble()
)
val hashMap = HashMap()
hashMap["type"] = "Task"
- hashMap["id"] = row.id
+ hashMap["id"] = task.id
addMarker(latLng, hashMap.toJson(), R.mipmap.task_on)
}
}
}
}
+
+ /***地图任务轨迹*************************************************************************/
vehicleViewModel.routeResult.observe(this) {
if (it.code == 200) {
//设置起点
val first = it.data.first()
- addMarker(
- LatLng(first.lagitude.toDouble(), first.longitude.toDouble()),
- "",
- R.mipmap.start
+ if (first.lagitude == "" || first.longitude == "") {
+ "任务起点经纬度异常".show(requireContext())
+ return@observe
+ }
+ aMap.addMarker(
+ MarkerOptions()
+ .position(LatLng(first.lagitude.toDouble(), first.longitude.toDouble()))
+ .icon(BitmapDescriptorFactory.fromResource(R.mipmap.start))
)
+
//设置终点
val last = it.data.last()
- addMarker(
- LatLng(last.lagitude.toDouble(), last.longitude.toDouble()),
- "",
- R.mipmap.end
+ if (last.lagitude == "" || last.longitude == "") {
+ "任务起点经纬度异常".show(requireContext())
+ return@observe
+ }
+ aMap.addMarker(
+ MarkerOptions()
+ .position(LatLng(last.lagitude.toDouble(), last.longitude.toDouble()))
+ .icon(BitmapDescriptorFactory.fromResource(R.mipmap.end))
)
it.data.forEach { task ->
if (task.lagitude.isNotEmpty() && task.longitude.isNotEmpty()) {
- //瞄点画线
- val latLngPoints = ArrayList()
- latLngPoints.add(
- LatLng(task.lagitude.toDouble(), task.longitude.toDouble())
- )
- aMap.addPolyline(
- PolylineOptions()
- .addAll(latLngPoints)
- .width(10.toFloat())
- .color(Color.RED)
- )
- }
- }
- }
- }
- }
-
- override fun handleMessage(msg: Message): Boolean {
- when (msg.what) {
- handlerVehicleCode -> {
- val vehicleModel = msg.obj as VehicleListModel.DataModel.RowsModel
-
- SaveKeyValues.putValue(LocaleConstant.CAR_NUMBER, vehicleModel.carPlate)
- SaveKeyValues.putValue(LocaleConstant.CAR_ID, vehicleModel.id)
-
- val marker = if (vehicleModel.status == "1") {
- //在线
- R.mipmap.vehicle_on
- } else {
- //离线
- R.mipmap.vehicle_on
- }
-
- val latLng = LatLng(
- vehicleModel.latitude.toDouble(), vehicleModel.longitude.toDouble()
- )
- val hashMap = HashMap()
- hashMap["type"] = "Car"
- hashMap["id"] = vehicleModel.id
-
- addMarker(latLng, hashMap.toJson(), marker)
-
- //移动到巡检车经纬度
- val cameraPosition = CameraPosition(latLng, 16f, 0f, 0f)
- val cameraUpdate = CameraUpdateFactory.newCameraPosition(cameraPosition)
- aMap.animateCamera(cameraUpdate, 1500, null)
-
- /**
- * 地图PopupWindow数据绑定
- * ****/
- if (isInfoWindowShow) {
- windowTitleView.text = vehicleModel.carPlate
- val state = if (vehicleModel.status == "1") {
- "状态:在线"
- } else {
- "状态:离线"
- }
- carStateView.text = state
-
- timeView.text = "时间:${vehicleModel.ts}"
- latLng.toChineseAddress(object : OnGeocodeSearchListener {
- override fun onRegionCodeSearched(address: String) {
- locationView.text = "位置:$address"
+ if (CoordinateConverter.isAMapDataAvailable(
+ task.lagitude.toDouble(), task.longitude.toDouble()
+ )
+ ) {
+ //瞄点画线
+ val latLngPoints = ArrayList()
+ latLngPoints.add(
+ LatLng(task.lagitude.toDouble(), task.longitude.toDouble())
+ )
+ aMap.addPolyline(
+ PolylineOptions()
+ .addAll(latLngPoints)
+ .width(10.toFloat())
+ .color(Color.RED)
+ )
}
- })
- }
- }
-
- handlerDeviceCode -> {
- if (isInfoWindowShow) {
- val deviceModel = msg.obj as DeviceListModel.DataModel.RowsModel
-
- deviceModelView.text = "云台型号:${deviceModel.deviceModel}"
+ }
}
}
}
- return true
}
override fun onMarkerClick(marker: Marker?): Boolean {
- //点击Marker显示自定义Popup
- marker?.showInfoWindow()
- return true
+ val clickedMarker = marker?.snippet
+ if (!clickedMarker.isNullOrEmpty()) {
+ val jsonObject = JSONObject(clickedMarker)
+ val type = jsonObject.getString("type")
+
+ v = if (type == "Car") {
+ LayoutInflater.from(requireContext()).inflate(R.layout.popu_map_car_window, null)
+ } else {
+ LayoutInflater.from(requireContext()).inflate(R.layout.popu_map_task_window, null)
+ }
+
+ //点击Marker显示自定义Popup
+ marker.showInfoWindow()
+ return true
+ }
+
+ return false
}
/**
@@ -268,64 +252,75 @@
* */
override fun getInfoContents(p0: Marker?): View? = null
- private lateinit var windowTitleView: TextView
- private lateinit var taskStateView: QMUIRoundButton
- private lateinit var carStateView: TextView
- private lateinit var deviceModelView: TextView
- private lateinit var timeView: TextView
- private lateinit var locationView: TextView
-
override fun getInfoWindow(marker: Marker?): View {
- isInfoWindowShow = true
+ val clickedMarker = marker?.snippet
- val v = LayoutInflater.from(requireContext()).inflate(R.layout.popu_map_car_window, null)
-
- windowTitleView = v.findViewById(R.id.windowTitleView)
- taskStateView = v.findViewById(R.id.taskStateView)
- val closeView = v.findViewById(R.id.closeView)
- carStateView = v.findViewById(R.id.carStateView)
- deviceModelView = v.findViewById(R.id.deviceModelView)
- timeView = v.findViewById(R.id.timeView)
- locationView = v.findViewById(R.id.locationView)
- val routeView = v.findViewById(R.id.routeView)
-
- if (!marker?.snippet.isNullOrEmpty()) {
- val hashMapJson = marker?.snippet!!
- val jsonObject = JSONObject(hashMapJson)
+ if (!clickedMarker.isNullOrEmpty()) {
+ val jsonObject = JSONObject(clickedMarker)
val type = jsonObject.getString("type")
val id = jsonObject.getString("id")
if (type == "Car") {
- taskStateView.visibility = View.GONE
- routeView.visibility = View.GONE
+ val windowTitleView = v.findViewById(R.id.windowTitleView)
+ val closeView = v.findViewById(R.id.closeView)
+ val carStateView = v.findViewById(R.id.carStateView)
+ val deviceModelView = v.findViewById(R.id.deviceModelView)
+ val timeView = v.findViewById(R.id.timeView)
+ val locationView = v.findViewById(R.id.locationView)
- vehicleViewModel.getVehicles()
+ windowTitleView.text = vehicleModel.carPlate
+ val state = if (vehicleModel.status == "1") {
+ "状态:在线"
+ } else {
+ "状态:离线"
+ }
+ carStateView.text = state
+ deviceModelView.text = "车载云台型号:${vehicleModel.deviceModel}"
+ timeView.text = "时间:${vehicleModel.ts}"
+ val latLng = LatLng(
+ vehicleModel.latitude.toDouble(), vehicleModel.longitude.toDouble()
+ )
- deviceViewModel.getDevices()
+ latLng.toChineseAddress(object : OnGeocodeSearchListener {
+ override fun onRegionCodeSearched(address: String) {
+ locationView.text = "位置:$address"
+ }
+ })
+
+ closeView.setOnClickListener {
+ marker.hideInfoWindow()
+ }
} else {
- taskStateView.visibility = View.VISIBLE
- routeView.visibility = View.VISIBLE
+ val windowTitleView = v.findViewById(R.id.windowTitleView)
+ val taskStateView = v.findViewById(R.id.taskStateView)
+ val closeView = v.findViewById(R.id.closeView)
+ val carNumberView = v.findViewById(R.id.carNumberView)
+ val deviceModelView = v.findViewById(R.id.deviceModelView)
+ val startTimeView = v.findViewById(R.id.startTimeView)
+ val endTimeView = v.findViewById(R.id.endTimeView)
+ val routeView = v.findViewById(R.id.routeView)
taskModels.forEach { task ->
if (task.id == id) {
- windowTitleView.text = "${task.taskName}(${id})"
- carStateView.text = "巡检车牌号:${task.carPlate}"
- deviceModelView.text = "云台型号:${task.modelName}"
- timeView.text = "开始时间:${task.beginDate}"
- locationView.text = "结束时间:${task.endDate}"
+ windowTitleView.text = task.taskName
+ taskStateView.text = task.statusName
+ carNumberView.text = "巡检车牌号:${task.carPlate}"
+ deviceModelView.text = "车载云台型号:${task.modelName}"
+ startTimeView.text = "开始时间:${task.beginDate}"
+ endTimeView.text = "结束时间:${task.endDate}"
}
}
+ closeView.setOnClickListener {
+ marker.hideInfoWindow()
+ }
+
routeView.setOnClickListener {
vehicleViewModel.getVehicleRoute(id)
}
}
}
- closeView.setOnClickListener {
- marker?.hideInfoWindow()
- isInfoWindowShow = false
- }
return v
}
diff --git a/app/src/main/java/com/casic/br/ktd/model/VehicleListModel.java b/app/src/main/java/com/casic/br/ktd/model/VehicleListModel.java
index 835e082..e0a5990 100644
--- a/app/src/main/java/com/casic/br/ktd/model/VehicleListModel.java
+++ b/app/src/main/java/com/casic/br/ktd/model/VehicleListModel.java
@@ -5,7 +5,7 @@
public class VehicleListModel {
private Integer code;
- private DataModel data;
+ private List data;
private String message;
public Integer getCode() {
@@ -16,11 +16,11 @@
this.code = code;
}
- public DataModel getData() {
+ public List getData() {
return data;
}
- public void setData(DataModel data) {
+ public void setData(List data) {
this.data = data;
}
@@ -33,197 +33,104 @@
}
public static class DataModel {
- private List rows;
- private Integer total;
+ private String carName;
+ private String carPlate;
+ private String deptId;
+ private String description;
+ private String deviceModel;
+ private String id;
+ private String latitude;
+ private String longitude;
+ private String status;
+ private String ts;
+ private String valid;
- public List getRows() {
- return rows;
+ public String getCarName() {
+ return carName;
}
- public void setRows(List rows) {
- this.rows = rows;
+ public void setCarName(String carName) {
+ this.carName = carName;
}
- public Integer getTotal() {
- return total;
+ public String getCarPlate() {
+ return carPlate;
}
- public void setTotal(Integer total) {
- this.total = total;
+ public void setCarPlate(String carPlate) {
+ this.carPlate = carPlate;
}
- public static class RowsModel {
- private String beginDate;
- private String carId;
- private String carPlate;
- private String description;
- private String description1;
- private String description2;
- private String endDate;
- private String id;
- private String km;
- private String latitude;
- private String longitude;
- private String modelName;
- private String status;
- private String statusName;
- private String taskCode;
- private String taskName;
- private String ts;
- private String updateTime;
- private String valid;
+ public String getDeptId() {
+ return deptId;
+ }
- public String getBeginDate() {
- return beginDate;
- }
+ public void setDeptId(String deptId) {
+ this.deptId = deptId;
+ }
- public void setBeginDate(String beginDate) {
- this.beginDate = beginDate;
- }
+ public String getDescription() {
+ return description;
+ }
- public String getCarId() {
- return carId;
- }
+ public void setDescription(String description) {
+ this.description = description;
+ }
- public void setCarId(String carId) {
- this.carId = carId;
- }
+ public String getDeviceModel() {
+ return deviceModel;
+ }
- public String getCarPlate() {
- return carPlate;
- }
+ public void setDeviceModel(String deviceModel) {
+ this.deviceModel = deviceModel;
+ }
- public void setCarPlate(String carPlate) {
- this.carPlate = carPlate;
- }
+ public String getId() {
+ return id;
+ }
- public String getDescription() {
- return description;
- }
+ public void setId(String id) {
+ this.id = id;
+ }
- public void setDescription(String description) {
- this.description = description;
- }
+ public String getLatitude() {
+ return latitude;
+ }
- public String getDescription1() {
- return description1;
- }
+ public void setLatitude(String latitude) {
+ this.latitude = latitude;
+ }
- public void setDescription1(String description1) {
- this.description1 = description1;
- }
+ public String getLongitude() {
+ return longitude;
+ }
- public String getDescription2() {
- return description2;
- }
+ public void setLongitude(String longitude) {
+ this.longitude = longitude;
+ }
- public void setDescription2(String description2) {
- this.description2 = description2;
- }
+ public String getStatus() {
+ return status;
+ }
- public String getEndDate() {
- return endDate;
- }
+ public void setStatus(String status) {
+ this.status = status;
+ }
- public void setEndDate(String endDate) {
- this.endDate = endDate;
- }
+ public String getTs() {
+ return ts;
+ }
- public String getId() {
- return id;
- }
+ public void setTs(String ts) {
+ this.ts = ts;
+ }
- public void setId(String id) {
- this.id = id;
- }
+ public String getValid() {
+ return valid;
+ }
- public String getKm() {
- return km;
- }
-
- public void setKm(String km) {
- this.km = km;
- }
-
- public String getLatitude() {
- return latitude;
- }
-
- public void setLatitude(String latitude) {
- this.latitude = latitude;
- }
-
- public String getLongitude() {
- return longitude;
- }
-
- public void setLongitude(String longitude) {
- this.longitude = longitude;
- }
-
- public String getModelName() {
- return modelName;
- }
-
- public void setModelName(String modelName) {
- this.modelName = modelName;
- }
-
- public String getStatus() {
- return status;
- }
-
- public void setStatus(String status) {
- this.status = status;
- }
-
- public String getStatusName() {
- return statusName;
- }
-
- public void setStatusName(String statusName) {
- this.statusName = statusName;
- }
-
- public String getTaskCode() {
- return taskCode;
- }
-
- public void setTaskCode(String taskCode) {
- this.taskCode = taskCode;
- }
-
- public String getTaskName() {
- return taskName;
- }
-
- public void setTaskName(String taskName) {
- this.taskName = taskName;
- }
-
- public String getTs() {
- return ts;
- }
-
- public void setTs(String ts) {
- this.ts = ts;
- }
-
- public String getUpdateTime() {
- return updateTime;
- }
-
- public void setUpdateTime(String updateTime) {
- this.updateTime = updateTime;
- }
-
- public String getValid() {
- return valid;
- }
-
- public void setValid(String valid) {
- this.valid = valid;
- }
+ public void setValid(String valid) {
+ this.valid = valid;
}
}
}
diff --git a/app/src/main/java/com/casic/br/ktd/netty/udp/UdpClient.kt b/app/src/main/java/com/casic/br/ktd/netty/udp/UdpClient.kt
index 954e2cb..a733a74 100644
--- a/app/src/main/java/com/casic/br/ktd/netty/udp/UdpClient.kt
+++ b/app/src/main/java/com/casic/br/ktd/netty/udp/UdpClient.kt
@@ -52,7 +52,7 @@
CoroutineScope(Dispatchers.Main).launch {
withContext(Dispatchers.IO) {
val host = SaveKeyValues.getValue(
- LocaleConstant.LOCATION_UDP_SERVER, "192.168.1.123"
+ LocaleConstant.LOCATION_UDP_SERVER, "192.168.1.241"
).toString()
val datagramPacket = DatagramPacket(
Unpooled.copiedBuffer(value, CharsetUtil.UTF_8),
@@ -67,8 +67,7 @@
CoroutineScope(Dispatchers.Main).launch {
withContext(Dispatchers.IO) {
val host = SaveKeyValues.getValue(
-// LocaleConstant.LOCATION_UDP_SERVER, "192.168.1.222"
- LocaleConstant.LOCATION_UDP_SERVER, "192.168.1.123"
+ LocaleConstant.LOCATION_UDP_SERVER, "192.168.1.241"
).toString()
val datagramPacket = DatagramPacket(
Unpooled.copiedBuffer(value),
@@ -83,7 +82,7 @@
CoroutineScope(Dispatchers.Main).launch {
withContext(Dispatchers.IO) {
val host = SaveKeyValues.getValue(
- LocaleConstant.LOCATION_UDP_SERVER, "192.168.1.123"
+ LocaleConstant.LOCATION_UDP_SERVER, "192.168.1.241"
).toString()
val datagramPacket = DatagramPacket(
Unpooled.copiedBuffer(value),
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index f8a5cfe..6ea5faa 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -67,7 +67,7 @@
+ android:value="2e964a64f7e7afe1f8520b0315919d1b" />
diff --git a/app/src/main/java/com/casic/br/ktd/fragment/HomePageFragment.kt b/app/src/main/java/com/casic/br/ktd/fragment/HomePageFragment.kt
index 8373e43..9a226a9 100644
--- a/app/src/main/java/com/casic/br/ktd/fragment/HomePageFragment.kt
+++ b/app/src/main/java/com/casic/br/ktd/fragment/HomePageFragment.kt
@@ -3,8 +3,6 @@
import android.annotation.SuppressLint
import android.graphics.Color
import android.os.Bundle
-import android.os.Handler
-import android.os.Message
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
@@ -14,6 +12,7 @@
import com.amap.api.maps.AMap
import com.amap.api.maps.AMapOptions
import com.amap.api.maps.CameraUpdateFactory
+import com.amap.api.maps.CoordinateConverter
import com.amap.api.maps.model.BitmapDescriptorFactory
import com.amap.api.maps.model.CameraPosition
import com.amap.api.maps.model.LatLng
@@ -24,41 +23,36 @@
import com.casic.br.ktd.databinding.FragmentHomeBinding
import com.casic.br.ktd.extensions.toChineseAddress
import com.casic.br.ktd.listener.OnGeocodeSearchListener
-import com.casic.br.ktd.model.DeviceListModel
import com.casic.br.ktd.model.TaskListModel
import com.casic.br.ktd.model.VehicleListModel
import com.casic.br.ktd.utils.ChartViewHub
import com.casic.br.ktd.utils.DateType
import com.casic.br.ktd.utils.LocaleConstant
-import com.casic.br.ktd.vm.DeviceViewModel
import com.casic.br.ktd.vm.TaskViewModel
import com.casic.br.ktd.vm.VehicleViewModel
import com.github.mikephil.charting.data.Entry
import com.pengxh.kt.lite.base.KotlinBaseFragment
+import com.pengxh.kt.lite.extensions.show
import com.pengxh.kt.lite.extensions.timestampToDate
import com.pengxh.kt.lite.extensions.timestampToLastMonthDate
import com.pengxh.kt.lite.extensions.toJson
import com.pengxh.kt.lite.utils.SaveKeyValues
-import com.pengxh.kt.lite.utils.WeakReferenceHandler
import com.qmuiteam.qmui.widget.roundwidget.QMUIRoundButton
import org.json.JSONObject
import java.text.DecimalFormat
@SuppressLint("SetTextI18n")
class HomePageFragment : KotlinBaseFragment(), AMap.OnMarkerClickListener,
- AMap.InfoWindowAdapter, Handler.Callback {
+ AMap.InfoWindowAdapter {
private val kTag = "HomePageFragment"
private val dFormat by lazy { DecimalFormat("0.00") }
private lateinit var vehicleViewModel: VehicleViewModel
- private lateinit var deviceViewModel: DeviceViewModel
private lateinit var taskViewModel: TaskViewModel
private lateinit var aMap: AMap
- private lateinit var weakReferenceHandler: WeakReferenceHandler
- private var isInfoWindowShow = false
+ private lateinit var v: View
+ private lateinit var vehicleModel: VehicleListModel.DataModel
private var taskModels: MutableList = ArrayList()
- private val handlerVehicleCode = 2023082501
- private val handlerDeviceCode = 2023082502
override fun initViewBinding(
inflater: LayoutInflater, container: ViewGroup?
@@ -80,31 +74,7 @@
// 点击marker弹出自定义popup
aMap.setInfoWindowAdapter(this)
- weakReferenceHandler = WeakReferenceHandler(this)
-
- vehicleViewModel = ViewModelProvider(this)[VehicleViewModel::class.java]
- vehicleViewModel.getVehicles()
- vehicleViewModel.vehicleList.observe(this) {
- if (it.code == 200) {
- if (it.data.rows.isNotEmpty()) {
- val message = weakReferenceHandler.obtainMessage()
- message.what = handlerVehicleCode
- message.obj = it.data.rows[0]
- weakReferenceHandler.sendMessage(message)
- }
- }
- }
-
- deviceViewModel = ViewModelProvider(this)[DeviceViewModel::class.java]
- deviceViewModel.deviceList.observe(this) {
- if (it.code == 200) {
- val message = weakReferenceHandler.obtainMessage()
- message.what = handlerDeviceCode
- message.obj = it.data.rows[0]
- weakReferenceHandler.sendMessage(message)
- }
- }
-
+ /***任务统计*************************************************************************/
taskViewModel = ViewModelProvider(this)[TaskViewModel::class.java]
val time = System.currentTimeMillis()
taskViewModel.getTaskCount(
@@ -123,6 +93,8 @@
binding.dayTaskDistanceView.text = dFormat.format(it.data.km)
}
}
+
+ /***任务趋势*************************************************************************/
taskViewModel.getTaskTrend("", "", "")
taskViewModel.taskTrendModel.observe(this) {
if (it.code == 200) {
@@ -141,126 +113,138 @@
ChartViewHub.setLineChartData(binding.taskTrendChart, xAxisLabels, strengthEntries)
}
}
+
+ /***地图车辆*************************************************************************/
+ vehicleViewModel = ViewModelProvider(this)[VehicleViewModel::class.java]
+ vehicleViewModel.getVehicles()
+ vehicleViewModel.vehicleList.observe(this) {
+ if (it.code == 200) {
+ if (it.data.isNotEmpty()) {
+ vehicleModel = it.data.first()
+
+ SaveKeyValues.putValue(LocaleConstant.CAR_NUMBER, vehicleModel.carPlate)
+ SaveKeyValues.putValue(LocaleConstant.CAR_ID, vehicleModel.id)
+
+ val marker = if (vehicleModel.status == "1") {
+ //在线
+ R.mipmap.vehicle_on
+ } else {
+ //离线
+ R.mipmap.vehicle_on
+ }
+
+ if (vehicleModel.latitude == "" || vehicleModel.longitude == "") {
+ "无法查询到最新的巡检任务车辆".show(requireContext())
+ return@observe
+ }
+
+ val latLng = LatLng(
+ vehicleModel.latitude.toDouble(), vehicleModel.longitude.toDouble()
+ )
+
+ val hashMap = HashMap()
+ hashMap["type"] = "Car"
+ hashMap["id"] = vehicleModel.id
+
+ addMarker(latLng, hashMap.toJson(), marker)
+
+ //移动到巡检车经纬度
+ val cameraPosition = CameraPosition(latLng, 16f, 0f, 0f)
+ val cameraUpdate = CameraUpdateFactory.newCameraPosition(cameraPosition)
+ aMap.animateCamera(cameraUpdate)
+ }
+ }
+ }
+
+ /***地图任务*************************************************************************/
taskViewModel.getTasksByPage("", "", "", "", 1)
taskViewModel.taskList.observe(this) {
if (it.code == 200) {
taskModels = it.data.rows!!
- taskModels.forEach { row ->
- if (row.latitude.isNotEmpty() && row.longitude.isNotEmpty()) {
+ taskModels.forEach { task ->
+ if (task.latitude.isNotEmpty() && task.longitude.isNotEmpty()) {
val latLng = LatLng(
- row.latitude.toDouble(), row.longitude.toDouble()
+ task.latitude.toDouble(), task.longitude.toDouble()
)
val hashMap = HashMap()
hashMap["type"] = "Task"
- hashMap["id"] = row.id
+ hashMap["id"] = task.id
addMarker(latLng, hashMap.toJson(), R.mipmap.task_on)
}
}
}
}
+
+ /***地图任务轨迹*************************************************************************/
vehicleViewModel.routeResult.observe(this) {
if (it.code == 200) {
//设置起点
val first = it.data.first()
- addMarker(
- LatLng(first.lagitude.toDouble(), first.longitude.toDouble()),
- "",
- R.mipmap.start
+ if (first.lagitude == "" || first.longitude == "") {
+ "任务起点经纬度异常".show(requireContext())
+ return@observe
+ }
+ aMap.addMarker(
+ MarkerOptions()
+ .position(LatLng(first.lagitude.toDouble(), first.longitude.toDouble()))
+ .icon(BitmapDescriptorFactory.fromResource(R.mipmap.start))
)
+
//设置终点
val last = it.data.last()
- addMarker(
- LatLng(last.lagitude.toDouble(), last.longitude.toDouble()),
- "",
- R.mipmap.end
+ if (last.lagitude == "" || last.longitude == "") {
+ "任务起点经纬度异常".show(requireContext())
+ return@observe
+ }
+ aMap.addMarker(
+ MarkerOptions()
+ .position(LatLng(last.lagitude.toDouble(), last.longitude.toDouble()))
+ .icon(BitmapDescriptorFactory.fromResource(R.mipmap.end))
)
it.data.forEach { task ->
if (task.lagitude.isNotEmpty() && task.longitude.isNotEmpty()) {
- //瞄点画线
- val latLngPoints = ArrayList()
- latLngPoints.add(
- LatLng(task.lagitude.toDouble(), task.longitude.toDouble())
- )
- aMap.addPolyline(
- PolylineOptions()
- .addAll(latLngPoints)
- .width(10.toFloat())
- .color(Color.RED)
- )
- }
- }
- }
- }
- }
-
- override fun handleMessage(msg: Message): Boolean {
- when (msg.what) {
- handlerVehicleCode -> {
- val vehicleModel = msg.obj as VehicleListModel.DataModel.RowsModel
-
- SaveKeyValues.putValue(LocaleConstant.CAR_NUMBER, vehicleModel.carPlate)
- SaveKeyValues.putValue(LocaleConstant.CAR_ID, vehicleModel.id)
-
- val marker = if (vehicleModel.status == "1") {
- //在线
- R.mipmap.vehicle_on
- } else {
- //离线
- R.mipmap.vehicle_on
- }
-
- val latLng = LatLng(
- vehicleModel.latitude.toDouble(), vehicleModel.longitude.toDouble()
- )
- val hashMap = HashMap()
- hashMap["type"] = "Car"
- hashMap["id"] = vehicleModel.id
-
- addMarker(latLng, hashMap.toJson(), marker)
-
- //移动到巡检车经纬度
- val cameraPosition = CameraPosition(latLng, 16f, 0f, 0f)
- val cameraUpdate = CameraUpdateFactory.newCameraPosition(cameraPosition)
- aMap.animateCamera(cameraUpdate, 1500, null)
-
- /**
- * 地图PopupWindow数据绑定
- * ****/
- if (isInfoWindowShow) {
- windowTitleView.text = vehicleModel.carPlate
- val state = if (vehicleModel.status == "1") {
- "状态:在线"
- } else {
- "状态:离线"
- }
- carStateView.text = state
-
- timeView.text = "时间:${vehicleModel.ts}"
- latLng.toChineseAddress(object : OnGeocodeSearchListener {
- override fun onRegionCodeSearched(address: String) {
- locationView.text = "位置:$address"
+ if (CoordinateConverter.isAMapDataAvailable(
+ task.lagitude.toDouble(), task.longitude.toDouble()
+ )
+ ) {
+ //瞄点画线
+ val latLngPoints = ArrayList()
+ latLngPoints.add(
+ LatLng(task.lagitude.toDouble(), task.longitude.toDouble())
+ )
+ aMap.addPolyline(
+ PolylineOptions()
+ .addAll(latLngPoints)
+ .width(10.toFloat())
+ .color(Color.RED)
+ )
}
- })
- }
- }
-
- handlerDeviceCode -> {
- if (isInfoWindowShow) {
- val deviceModel = msg.obj as DeviceListModel.DataModel.RowsModel
-
- deviceModelView.text = "云台型号:${deviceModel.deviceModel}"
+ }
}
}
}
- return true
}
override fun onMarkerClick(marker: Marker?): Boolean {
- //点击Marker显示自定义Popup
- marker?.showInfoWindow()
- return true
+ val clickedMarker = marker?.snippet
+ if (!clickedMarker.isNullOrEmpty()) {
+ val jsonObject = JSONObject(clickedMarker)
+ val type = jsonObject.getString("type")
+
+ v = if (type == "Car") {
+ LayoutInflater.from(requireContext()).inflate(R.layout.popu_map_car_window, null)
+ } else {
+ LayoutInflater.from(requireContext()).inflate(R.layout.popu_map_task_window, null)
+ }
+
+ //点击Marker显示自定义Popup
+ marker.showInfoWindow()
+ return true
+ }
+
+ return false
}
/**
@@ -268,64 +252,75 @@
* */
override fun getInfoContents(p0: Marker?): View? = null
- private lateinit var windowTitleView: TextView
- private lateinit var taskStateView: QMUIRoundButton
- private lateinit var carStateView: TextView
- private lateinit var deviceModelView: TextView
- private lateinit var timeView: TextView
- private lateinit var locationView: TextView
-
override fun getInfoWindow(marker: Marker?): View {
- isInfoWindowShow = true
+ val clickedMarker = marker?.snippet
- val v = LayoutInflater.from(requireContext()).inflate(R.layout.popu_map_car_window, null)
-
- windowTitleView = v.findViewById(R.id.windowTitleView)
- taskStateView = v.findViewById(R.id.taskStateView)
- val closeView = v.findViewById(R.id.closeView)
- carStateView = v.findViewById(R.id.carStateView)
- deviceModelView = v.findViewById(R.id.deviceModelView)
- timeView = v.findViewById(R.id.timeView)
- locationView = v.findViewById(R.id.locationView)
- val routeView = v.findViewById(R.id.routeView)
-
- if (!marker?.snippet.isNullOrEmpty()) {
- val hashMapJson = marker?.snippet!!
- val jsonObject = JSONObject(hashMapJson)
+ if (!clickedMarker.isNullOrEmpty()) {
+ val jsonObject = JSONObject(clickedMarker)
val type = jsonObject.getString("type")
val id = jsonObject.getString("id")
if (type == "Car") {
- taskStateView.visibility = View.GONE
- routeView.visibility = View.GONE
+ val windowTitleView = v.findViewById(R.id.windowTitleView)
+ val closeView = v.findViewById(R.id.closeView)
+ val carStateView = v.findViewById(R.id.carStateView)
+ val deviceModelView = v.findViewById(R.id.deviceModelView)
+ val timeView = v.findViewById(R.id.timeView)
+ val locationView = v.findViewById(R.id.locationView)
- vehicleViewModel.getVehicles()
+ windowTitleView.text = vehicleModel.carPlate
+ val state = if (vehicleModel.status == "1") {
+ "状态:在线"
+ } else {
+ "状态:离线"
+ }
+ carStateView.text = state
+ deviceModelView.text = "车载云台型号:${vehicleModel.deviceModel}"
+ timeView.text = "时间:${vehicleModel.ts}"
+ val latLng = LatLng(
+ vehicleModel.latitude.toDouble(), vehicleModel.longitude.toDouble()
+ )
- deviceViewModel.getDevices()
+ latLng.toChineseAddress(object : OnGeocodeSearchListener {
+ override fun onRegionCodeSearched(address: String) {
+ locationView.text = "位置:$address"
+ }
+ })
+
+ closeView.setOnClickListener {
+ marker.hideInfoWindow()
+ }
} else {
- taskStateView.visibility = View.VISIBLE
- routeView.visibility = View.VISIBLE
+ val windowTitleView = v.findViewById(R.id.windowTitleView)
+ val taskStateView = v.findViewById(R.id.taskStateView)
+ val closeView = v.findViewById(R.id.closeView)
+ val carNumberView = v.findViewById(R.id.carNumberView)
+ val deviceModelView = v.findViewById(R.id.deviceModelView)
+ val startTimeView = v.findViewById(R.id.startTimeView)
+ val endTimeView = v.findViewById(R.id.endTimeView)
+ val routeView = v.findViewById(R.id.routeView)
taskModels.forEach { task ->
if (task.id == id) {
- windowTitleView.text = "${task.taskName}(${id})"
- carStateView.text = "巡检车牌号:${task.carPlate}"
- deviceModelView.text = "云台型号:${task.modelName}"
- timeView.text = "开始时间:${task.beginDate}"
- locationView.text = "结束时间:${task.endDate}"
+ windowTitleView.text = task.taskName
+ taskStateView.text = task.statusName
+ carNumberView.text = "巡检车牌号:${task.carPlate}"
+ deviceModelView.text = "车载云台型号:${task.modelName}"
+ startTimeView.text = "开始时间:${task.beginDate}"
+ endTimeView.text = "结束时间:${task.endDate}"
}
}
+ closeView.setOnClickListener {
+ marker.hideInfoWindow()
+ }
+
routeView.setOnClickListener {
vehicleViewModel.getVehicleRoute(id)
}
}
}
- closeView.setOnClickListener {
- marker?.hideInfoWindow()
- isInfoWindowShow = false
- }
return v
}
diff --git a/app/src/main/java/com/casic/br/ktd/model/VehicleListModel.java b/app/src/main/java/com/casic/br/ktd/model/VehicleListModel.java
index 835e082..e0a5990 100644
--- a/app/src/main/java/com/casic/br/ktd/model/VehicleListModel.java
+++ b/app/src/main/java/com/casic/br/ktd/model/VehicleListModel.java
@@ -5,7 +5,7 @@
public class VehicleListModel {
private Integer code;
- private DataModel data;
+ private List data;
private String message;
public Integer getCode() {
@@ -16,11 +16,11 @@
this.code = code;
}
- public DataModel getData() {
+ public List getData() {
return data;
}
- public void setData(DataModel data) {
+ public void setData(List data) {
this.data = data;
}
@@ -33,197 +33,104 @@
}
public static class DataModel {
- private List rows;
- private Integer total;
+ private String carName;
+ private String carPlate;
+ private String deptId;
+ private String description;
+ private String deviceModel;
+ private String id;
+ private String latitude;
+ private String longitude;
+ private String status;
+ private String ts;
+ private String valid;
- public List getRows() {
- return rows;
+ public String getCarName() {
+ return carName;
}
- public void setRows(List rows) {
- this.rows = rows;
+ public void setCarName(String carName) {
+ this.carName = carName;
}
- public Integer getTotal() {
- return total;
+ public String getCarPlate() {
+ return carPlate;
}
- public void setTotal(Integer total) {
- this.total = total;
+ public void setCarPlate(String carPlate) {
+ this.carPlate = carPlate;
}
- public static class RowsModel {
- private String beginDate;
- private String carId;
- private String carPlate;
- private String description;
- private String description1;
- private String description2;
- private String endDate;
- private String id;
- private String km;
- private String latitude;
- private String longitude;
- private String modelName;
- private String status;
- private String statusName;
- private String taskCode;
- private String taskName;
- private String ts;
- private String updateTime;
- private String valid;
+ public String getDeptId() {
+ return deptId;
+ }
- public String getBeginDate() {
- return beginDate;
- }
+ public void setDeptId(String deptId) {
+ this.deptId = deptId;
+ }
- public void setBeginDate(String beginDate) {
- this.beginDate = beginDate;
- }
+ public String getDescription() {
+ return description;
+ }
- public String getCarId() {
- return carId;
- }
+ public void setDescription(String description) {
+ this.description = description;
+ }
- public void setCarId(String carId) {
- this.carId = carId;
- }
+ public String getDeviceModel() {
+ return deviceModel;
+ }
- public String getCarPlate() {
- return carPlate;
- }
+ public void setDeviceModel(String deviceModel) {
+ this.deviceModel = deviceModel;
+ }
- public void setCarPlate(String carPlate) {
- this.carPlate = carPlate;
- }
+ public String getId() {
+ return id;
+ }
- public String getDescription() {
- return description;
- }
+ public void setId(String id) {
+ this.id = id;
+ }
- public void setDescription(String description) {
- this.description = description;
- }
+ public String getLatitude() {
+ return latitude;
+ }
- public String getDescription1() {
- return description1;
- }
+ public void setLatitude(String latitude) {
+ this.latitude = latitude;
+ }
- public void setDescription1(String description1) {
- this.description1 = description1;
- }
+ public String getLongitude() {
+ return longitude;
+ }
- public String getDescription2() {
- return description2;
- }
+ public void setLongitude(String longitude) {
+ this.longitude = longitude;
+ }
- public void setDescription2(String description2) {
- this.description2 = description2;
- }
+ public String getStatus() {
+ return status;
+ }
- public String getEndDate() {
- return endDate;
- }
+ public void setStatus(String status) {
+ this.status = status;
+ }
- public void setEndDate(String endDate) {
- this.endDate = endDate;
- }
+ public String getTs() {
+ return ts;
+ }
- public String getId() {
- return id;
- }
+ public void setTs(String ts) {
+ this.ts = ts;
+ }
- public void setId(String id) {
- this.id = id;
- }
+ public String getValid() {
+ return valid;
+ }
- public String getKm() {
- return km;
- }
-
- public void setKm(String km) {
- this.km = km;
- }
-
- public String getLatitude() {
- return latitude;
- }
-
- public void setLatitude(String latitude) {
- this.latitude = latitude;
- }
-
- public String getLongitude() {
- return longitude;
- }
-
- public void setLongitude(String longitude) {
- this.longitude = longitude;
- }
-
- public String getModelName() {
- return modelName;
- }
-
- public void setModelName(String modelName) {
- this.modelName = modelName;
- }
-
- public String getStatus() {
- return status;
- }
-
- public void setStatus(String status) {
- this.status = status;
- }
-
- public String getStatusName() {
- return statusName;
- }
-
- public void setStatusName(String statusName) {
- this.statusName = statusName;
- }
-
- public String getTaskCode() {
- return taskCode;
- }
-
- public void setTaskCode(String taskCode) {
- this.taskCode = taskCode;
- }
-
- public String getTaskName() {
- return taskName;
- }
-
- public void setTaskName(String taskName) {
- this.taskName = taskName;
- }
-
- public String getTs() {
- return ts;
- }
-
- public void setTs(String ts) {
- this.ts = ts;
- }
-
- public String getUpdateTime() {
- return updateTime;
- }
-
- public void setUpdateTime(String updateTime) {
- this.updateTime = updateTime;
- }
-
- public String getValid() {
- return valid;
- }
-
- public void setValid(String valid) {
- this.valid = valid;
- }
+ public void setValid(String valid) {
+ this.valid = valid;
}
}
}
diff --git a/app/src/main/java/com/casic/br/ktd/netty/udp/UdpClient.kt b/app/src/main/java/com/casic/br/ktd/netty/udp/UdpClient.kt
index 954e2cb..a733a74 100644
--- a/app/src/main/java/com/casic/br/ktd/netty/udp/UdpClient.kt
+++ b/app/src/main/java/com/casic/br/ktd/netty/udp/UdpClient.kt
@@ -52,7 +52,7 @@
CoroutineScope(Dispatchers.Main).launch {
withContext(Dispatchers.IO) {
val host = SaveKeyValues.getValue(
- LocaleConstant.LOCATION_UDP_SERVER, "192.168.1.123"
+ LocaleConstant.LOCATION_UDP_SERVER, "192.168.1.241"
).toString()
val datagramPacket = DatagramPacket(
Unpooled.copiedBuffer(value, CharsetUtil.UTF_8),
@@ -67,8 +67,7 @@
CoroutineScope(Dispatchers.Main).launch {
withContext(Dispatchers.IO) {
val host = SaveKeyValues.getValue(
-// LocaleConstant.LOCATION_UDP_SERVER, "192.168.1.222"
- LocaleConstant.LOCATION_UDP_SERVER, "192.168.1.123"
+ LocaleConstant.LOCATION_UDP_SERVER, "192.168.1.241"
).toString()
val datagramPacket = DatagramPacket(
Unpooled.copiedBuffer(value),
@@ -83,7 +82,7 @@
CoroutineScope(Dispatchers.Main).launch {
withContext(Dispatchers.IO) {
val host = SaveKeyValues.getValue(
- LocaleConstant.LOCATION_UDP_SERVER, "192.168.1.123"
+ LocaleConstant.LOCATION_UDP_SERVER, "192.168.1.241"
).toString()
val datagramPacket = DatagramPacket(
Unpooled.copiedBuffer(value),
diff --git a/app/src/main/res/layout/popu_map_car_window.xml b/app/src/main/res/layout/popu_map_car_window.xml
index 71ba8b7..8bad2c4 100644
--- a/app/src/main/res/layout/popu_map_car_window.xml
+++ b/app/src/main/res/layout/popu_map_car_window.xml
@@ -1,6 +1,5 @@
-
-
-
-
-
-
-
-
+
\ No newline at end of file
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index f8a5cfe..6ea5faa 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -67,7 +67,7 @@
+ android:value="2e964a64f7e7afe1f8520b0315919d1b" />
diff --git a/app/src/main/java/com/casic/br/ktd/fragment/HomePageFragment.kt b/app/src/main/java/com/casic/br/ktd/fragment/HomePageFragment.kt
index 8373e43..9a226a9 100644
--- a/app/src/main/java/com/casic/br/ktd/fragment/HomePageFragment.kt
+++ b/app/src/main/java/com/casic/br/ktd/fragment/HomePageFragment.kt
@@ -3,8 +3,6 @@
import android.annotation.SuppressLint
import android.graphics.Color
import android.os.Bundle
-import android.os.Handler
-import android.os.Message
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
@@ -14,6 +12,7 @@
import com.amap.api.maps.AMap
import com.amap.api.maps.AMapOptions
import com.amap.api.maps.CameraUpdateFactory
+import com.amap.api.maps.CoordinateConverter
import com.amap.api.maps.model.BitmapDescriptorFactory
import com.amap.api.maps.model.CameraPosition
import com.amap.api.maps.model.LatLng
@@ -24,41 +23,36 @@
import com.casic.br.ktd.databinding.FragmentHomeBinding
import com.casic.br.ktd.extensions.toChineseAddress
import com.casic.br.ktd.listener.OnGeocodeSearchListener
-import com.casic.br.ktd.model.DeviceListModel
import com.casic.br.ktd.model.TaskListModel
import com.casic.br.ktd.model.VehicleListModel
import com.casic.br.ktd.utils.ChartViewHub
import com.casic.br.ktd.utils.DateType
import com.casic.br.ktd.utils.LocaleConstant
-import com.casic.br.ktd.vm.DeviceViewModel
import com.casic.br.ktd.vm.TaskViewModel
import com.casic.br.ktd.vm.VehicleViewModel
import com.github.mikephil.charting.data.Entry
import com.pengxh.kt.lite.base.KotlinBaseFragment
+import com.pengxh.kt.lite.extensions.show
import com.pengxh.kt.lite.extensions.timestampToDate
import com.pengxh.kt.lite.extensions.timestampToLastMonthDate
import com.pengxh.kt.lite.extensions.toJson
import com.pengxh.kt.lite.utils.SaveKeyValues
-import com.pengxh.kt.lite.utils.WeakReferenceHandler
import com.qmuiteam.qmui.widget.roundwidget.QMUIRoundButton
import org.json.JSONObject
import java.text.DecimalFormat
@SuppressLint("SetTextI18n")
class HomePageFragment : KotlinBaseFragment(), AMap.OnMarkerClickListener,
- AMap.InfoWindowAdapter, Handler.Callback {
+ AMap.InfoWindowAdapter {
private val kTag = "HomePageFragment"
private val dFormat by lazy { DecimalFormat("0.00") }
private lateinit var vehicleViewModel: VehicleViewModel
- private lateinit var deviceViewModel: DeviceViewModel
private lateinit var taskViewModel: TaskViewModel
private lateinit var aMap: AMap
- private lateinit var weakReferenceHandler: WeakReferenceHandler
- private var isInfoWindowShow = false
+ private lateinit var v: View
+ private lateinit var vehicleModel: VehicleListModel.DataModel
private var taskModels: MutableList = ArrayList()
- private val handlerVehicleCode = 2023082501
- private val handlerDeviceCode = 2023082502
override fun initViewBinding(
inflater: LayoutInflater, container: ViewGroup?
@@ -80,31 +74,7 @@
// 点击marker弹出自定义popup
aMap.setInfoWindowAdapter(this)
- weakReferenceHandler = WeakReferenceHandler(this)
-
- vehicleViewModel = ViewModelProvider(this)[VehicleViewModel::class.java]
- vehicleViewModel.getVehicles()
- vehicleViewModel.vehicleList.observe(this) {
- if (it.code == 200) {
- if (it.data.rows.isNotEmpty()) {
- val message = weakReferenceHandler.obtainMessage()
- message.what = handlerVehicleCode
- message.obj = it.data.rows[0]
- weakReferenceHandler.sendMessage(message)
- }
- }
- }
-
- deviceViewModel = ViewModelProvider(this)[DeviceViewModel::class.java]
- deviceViewModel.deviceList.observe(this) {
- if (it.code == 200) {
- val message = weakReferenceHandler.obtainMessage()
- message.what = handlerDeviceCode
- message.obj = it.data.rows[0]
- weakReferenceHandler.sendMessage(message)
- }
- }
-
+ /***任务统计*************************************************************************/
taskViewModel = ViewModelProvider(this)[TaskViewModel::class.java]
val time = System.currentTimeMillis()
taskViewModel.getTaskCount(
@@ -123,6 +93,8 @@
binding.dayTaskDistanceView.text = dFormat.format(it.data.km)
}
}
+
+ /***任务趋势*************************************************************************/
taskViewModel.getTaskTrend("", "", "")
taskViewModel.taskTrendModel.observe(this) {
if (it.code == 200) {
@@ -141,126 +113,138 @@
ChartViewHub.setLineChartData(binding.taskTrendChart, xAxisLabels, strengthEntries)
}
}
+
+ /***地图车辆*************************************************************************/
+ vehicleViewModel = ViewModelProvider(this)[VehicleViewModel::class.java]
+ vehicleViewModel.getVehicles()
+ vehicleViewModel.vehicleList.observe(this) {
+ if (it.code == 200) {
+ if (it.data.isNotEmpty()) {
+ vehicleModel = it.data.first()
+
+ SaveKeyValues.putValue(LocaleConstant.CAR_NUMBER, vehicleModel.carPlate)
+ SaveKeyValues.putValue(LocaleConstant.CAR_ID, vehicleModel.id)
+
+ val marker = if (vehicleModel.status == "1") {
+ //在线
+ R.mipmap.vehicle_on
+ } else {
+ //离线
+ R.mipmap.vehicle_on
+ }
+
+ if (vehicleModel.latitude == "" || vehicleModel.longitude == "") {
+ "无法查询到最新的巡检任务车辆".show(requireContext())
+ return@observe
+ }
+
+ val latLng = LatLng(
+ vehicleModel.latitude.toDouble(), vehicleModel.longitude.toDouble()
+ )
+
+ val hashMap = HashMap()
+ hashMap["type"] = "Car"
+ hashMap["id"] = vehicleModel.id
+
+ addMarker(latLng, hashMap.toJson(), marker)
+
+ //移动到巡检车经纬度
+ val cameraPosition = CameraPosition(latLng, 16f, 0f, 0f)
+ val cameraUpdate = CameraUpdateFactory.newCameraPosition(cameraPosition)
+ aMap.animateCamera(cameraUpdate)
+ }
+ }
+ }
+
+ /***地图任务*************************************************************************/
taskViewModel.getTasksByPage("", "", "", "", 1)
taskViewModel.taskList.observe(this) {
if (it.code == 200) {
taskModels = it.data.rows!!
- taskModels.forEach { row ->
- if (row.latitude.isNotEmpty() && row.longitude.isNotEmpty()) {
+ taskModels.forEach { task ->
+ if (task.latitude.isNotEmpty() && task.longitude.isNotEmpty()) {
val latLng = LatLng(
- row.latitude.toDouble(), row.longitude.toDouble()
+ task.latitude.toDouble(), task.longitude.toDouble()
)
val hashMap = HashMap()
hashMap["type"] = "Task"
- hashMap["id"] = row.id
+ hashMap["id"] = task.id
addMarker(latLng, hashMap.toJson(), R.mipmap.task_on)
}
}
}
}
+
+ /***地图任务轨迹*************************************************************************/
vehicleViewModel.routeResult.observe(this) {
if (it.code == 200) {
//设置起点
val first = it.data.first()
- addMarker(
- LatLng(first.lagitude.toDouble(), first.longitude.toDouble()),
- "",
- R.mipmap.start
+ if (first.lagitude == "" || first.longitude == "") {
+ "任务起点经纬度异常".show(requireContext())
+ return@observe
+ }
+ aMap.addMarker(
+ MarkerOptions()
+ .position(LatLng(first.lagitude.toDouble(), first.longitude.toDouble()))
+ .icon(BitmapDescriptorFactory.fromResource(R.mipmap.start))
)
+
//设置终点
val last = it.data.last()
- addMarker(
- LatLng(last.lagitude.toDouble(), last.longitude.toDouble()),
- "",
- R.mipmap.end
+ if (last.lagitude == "" || last.longitude == "") {
+ "任务起点经纬度异常".show(requireContext())
+ return@observe
+ }
+ aMap.addMarker(
+ MarkerOptions()
+ .position(LatLng(last.lagitude.toDouble(), last.longitude.toDouble()))
+ .icon(BitmapDescriptorFactory.fromResource(R.mipmap.end))
)
it.data.forEach { task ->
if (task.lagitude.isNotEmpty() && task.longitude.isNotEmpty()) {
- //瞄点画线
- val latLngPoints = ArrayList()
- latLngPoints.add(
- LatLng(task.lagitude.toDouble(), task.longitude.toDouble())
- )
- aMap.addPolyline(
- PolylineOptions()
- .addAll(latLngPoints)
- .width(10.toFloat())
- .color(Color.RED)
- )
- }
- }
- }
- }
- }
-
- override fun handleMessage(msg: Message): Boolean {
- when (msg.what) {
- handlerVehicleCode -> {
- val vehicleModel = msg.obj as VehicleListModel.DataModel.RowsModel
-
- SaveKeyValues.putValue(LocaleConstant.CAR_NUMBER, vehicleModel.carPlate)
- SaveKeyValues.putValue(LocaleConstant.CAR_ID, vehicleModel.id)
-
- val marker = if (vehicleModel.status == "1") {
- //在线
- R.mipmap.vehicle_on
- } else {
- //离线
- R.mipmap.vehicle_on
- }
-
- val latLng = LatLng(
- vehicleModel.latitude.toDouble(), vehicleModel.longitude.toDouble()
- )
- val hashMap = HashMap()
- hashMap["type"] = "Car"
- hashMap["id"] = vehicleModel.id
-
- addMarker(latLng, hashMap.toJson(), marker)
-
- //移动到巡检车经纬度
- val cameraPosition = CameraPosition(latLng, 16f, 0f, 0f)
- val cameraUpdate = CameraUpdateFactory.newCameraPosition(cameraPosition)
- aMap.animateCamera(cameraUpdate, 1500, null)
-
- /**
- * 地图PopupWindow数据绑定
- * ****/
- if (isInfoWindowShow) {
- windowTitleView.text = vehicleModel.carPlate
- val state = if (vehicleModel.status == "1") {
- "状态:在线"
- } else {
- "状态:离线"
- }
- carStateView.text = state
-
- timeView.text = "时间:${vehicleModel.ts}"
- latLng.toChineseAddress(object : OnGeocodeSearchListener {
- override fun onRegionCodeSearched(address: String) {
- locationView.text = "位置:$address"
+ if (CoordinateConverter.isAMapDataAvailable(
+ task.lagitude.toDouble(), task.longitude.toDouble()
+ )
+ ) {
+ //瞄点画线
+ val latLngPoints = ArrayList()
+ latLngPoints.add(
+ LatLng(task.lagitude.toDouble(), task.longitude.toDouble())
+ )
+ aMap.addPolyline(
+ PolylineOptions()
+ .addAll(latLngPoints)
+ .width(10.toFloat())
+ .color(Color.RED)
+ )
}
- })
- }
- }
-
- handlerDeviceCode -> {
- if (isInfoWindowShow) {
- val deviceModel = msg.obj as DeviceListModel.DataModel.RowsModel
-
- deviceModelView.text = "云台型号:${deviceModel.deviceModel}"
+ }
}
}
}
- return true
}
override fun onMarkerClick(marker: Marker?): Boolean {
- //点击Marker显示自定义Popup
- marker?.showInfoWindow()
- return true
+ val clickedMarker = marker?.snippet
+ if (!clickedMarker.isNullOrEmpty()) {
+ val jsonObject = JSONObject(clickedMarker)
+ val type = jsonObject.getString("type")
+
+ v = if (type == "Car") {
+ LayoutInflater.from(requireContext()).inflate(R.layout.popu_map_car_window, null)
+ } else {
+ LayoutInflater.from(requireContext()).inflate(R.layout.popu_map_task_window, null)
+ }
+
+ //点击Marker显示自定义Popup
+ marker.showInfoWindow()
+ return true
+ }
+
+ return false
}
/**
@@ -268,64 +252,75 @@
* */
override fun getInfoContents(p0: Marker?): View? = null
- private lateinit var windowTitleView: TextView
- private lateinit var taskStateView: QMUIRoundButton
- private lateinit var carStateView: TextView
- private lateinit var deviceModelView: TextView
- private lateinit var timeView: TextView
- private lateinit var locationView: TextView
-
override fun getInfoWindow(marker: Marker?): View {
- isInfoWindowShow = true
+ val clickedMarker = marker?.snippet
- val v = LayoutInflater.from(requireContext()).inflate(R.layout.popu_map_car_window, null)
-
- windowTitleView = v.findViewById(R.id.windowTitleView)
- taskStateView = v.findViewById(R.id.taskStateView)
- val closeView = v.findViewById(R.id.closeView)
- carStateView = v.findViewById(R.id.carStateView)
- deviceModelView = v.findViewById(R.id.deviceModelView)
- timeView = v.findViewById(R.id.timeView)
- locationView = v.findViewById(R.id.locationView)
- val routeView = v.findViewById(R.id.routeView)
-
- if (!marker?.snippet.isNullOrEmpty()) {
- val hashMapJson = marker?.snippet!!
- val jsonObject = JSONObject(hashMapJson)
+ if (!clickedMarker.isNullOrEmpty()) {
+ val jsonObject = JSONObject(clickedMarker)
val type = jsonObject.getString("type")
val id = jsonObject.getString("id")
if (type == "Car") {
- taskStateView.visibility = View.GONE
- routeView.visibility = View.GONE
+ val windowTitleView = v.findViewById(R.id.windowTitleView)
+ val closeView = v.findViewById(R.id.closeView)
+ val carStateView = v.findViewById(R.id.carStateView)
+ val deviceModelView = v.findViewById(R.id.deviceModelView)
+ val timeView = v.findViewById(R.id.timeView)
+ val locationView = v.findViewById(R.id.locationView)
- vehicleViewModel.getVehicles()
+ windowTitleView.text = vehicleModel.carPlate
+ val state = if (vehicleModel.status == "1") {
+ "状态:在线"
+ } else {
+ "状态:离线"
+ }
+ carStateView.text = state
+ deviceModelView.text = "车载云台型号:${vehicleModel.deviceModel}"
+ timeView.text = "时间:${vehicleModel.ts}"
+ val latLng = LatLng(
+ vehicleModel.latitude.toDouble(), vehicleModel.longitude.toDouble()
+ )
- deviceViewModel.getDevices()
+ latLng.toChineseAddress(object : OnGeocodeSearchListener {
+ override fun onRegionCodeSearched(address: String) {
+ locationView.text = "位置:$address"
+ }
+ })
+
+ closeView.setOnClickListener {
+ marker.hideInfoWindow()
+ }
} else {
- taskStateView.visibility = View.VISIBLE
- routeView.visibility = View.VISIBLE
+ val windowTitleView = v.findViewById(R.id.windowTitleView)
+ val taskStateView = v.findViewById(R.id.taskStateView)
+ val closeView = v.findViewById(R.id.closeView)
+ val carNumberView = v.findViewById(R.id.carNumberView)
+ val deviceModelView = v.findViewById(R.id.deviceModelView)
+ val startTimeView = v.findViewById(R.id.startTimeView)
+ val endTimeView = v.findViewById(R.id.endTimeView)
+ val routeView = v.findViewById(R.id.routeView)
taskModels.forEach { task ->
if (task.id == id) {
- windowTitleView.text = "${task.taskName}(${id})"
- carStateView.text = "巡检车牌号:${task.carPlate}"
- deviceModelView.text = "云台型号:${task.modelName}"
- timeView.text = "开始时间:${task.beginDate}"
- locationView.text = "结束时间:${task.endDate}"
+ windowTitleView.text = task.taskName
+ taskStateView.text = task.statusName
+ carNumberView.text = "巡检车牌号:${task.carPlate}"
+ deviceModelView.text = "车载云台型号:${task.modelName}"
+ startTimeView.text = "开始时间:${task.beginDate}"
+ endTimeView.text = "结束时间:${task.endDate}"
}
}
+ closeView.setOnClickListener {
+ marker.hideInfoWindow()
+ }
+
routeView.setOnClickListener {
vehicleViewModel.getVehicleRoute(id)
}
}
}
- closeView.setOnClickListener {
- marker?.hideInfoWindow()
- isInfoWindowShow = false
- }
return v
}
diff --git a/app/src/main/java/com/casic/br/ktd/model/VehicleListModel.java b/app/src/main/java/com/casic/br/ktd/model/VehicleListModel.java
index 835e082..e0a5990 100644
--- a/app/src/main/java/com/casic/br/ktd/model/VehicleListModel.java
+++ b/app/src/main/java/com/casic/br/ktd/model/VehicleListModel.java
@@ -5,7 +5,7 @@
public class VehicleListModel {
private Integer code;
- private DataModel data;
+ private List data;
private String message;
public Integer getCode() {
@@ -16,11 +16,11 @@
this.code = code;
}
- public DataModel getData() {
+ public List getData() {
return data;
}
- public void setData(DataModel data) {
+ public void setData(List data) {
this.data = data;
}
@@ -33,197 +33,104 @@
}
public static class DataModel {
- private List rows;
- private Integer total;
+ private String carName;
+ private String carPlate;
+ private String deptId;
+ private String description;
+ private String deviceModel;
+ private String id;
+ private String latitude;
+ private String longitude;
+ private String status;
+ private String ts;
+ private String valid;
- public List getRows() {
- return rows;
+ public String getCarName() {
+ return carName;
}
- public void setRows(List rows) {
- this.rows = rows;
+ public void setCarName(String carName) {
+ this.carName = carName;
}
- public Integer getTotal() {
- return total;
+ public String getCarPlate() {
+ return carPlate;
}
- public void setTotal(Integer total) {
- this.total = total;
+ public void setCarPlate(String carPlate) {
+ this.carPlate = carPlate;
}
- public static class RowsModel {
- private String beginDate;
- private String carId;
- private String carPlate;
- private String description;
- private String description1;
- private String description2;
- private String endDate;
- private String id;
- private String km;
- private String latitude;
- private String longitude;
- private String modelName;
- private String status;
- private String statusName;
- private String taskCode;
- private String taskName;
- private String ts;
- private String updateTime;
- private String valid;
+ public String getDeptId() {
+ return deptId;
+ }
- public String getBeginDate() {
- return beginDate;
- }
+ public void setDeptId(String deptId) {
+ this.deptId = deptId;
+ }
- public void setBeginDate(String beginDate) {
- this.beginDate = beginDate;
- }
+ public String getDescription() {
+ return description;
+ }
- public String getCarId() {
- return carId;
- }
+ public void setDescription(String description) {
+ this.description = description;
+ }
- public void setCarId(String carId) {
- this.carId = carId;
- }
+ public String getDeviceModel() {
+ return deviceModel;
+ }
- public String getCarPlate() {
- return carPlate;
- }
+ public void setDeviceModel(String deviceModel) {
+ this.deviceModel = deviceModel;
+ }
- public void setCarPlate(String carPlate) {
- this.carPlate = carPlate;
- }
+ public String getId() {
+ return id;
+ }
- public String getDescription() {
- return description;
- }
+ public void setId(String id) {
+ this.id = id;
+ }
- public void setDescription(String description) {
- this.description = description;
- }
+ public String getLatitude() {
+ return latitude;
+ }
- public String getDescription1() {
- return description1;
- }
+ public void setLatitude(String latitude) {
+ this.latitude = latitude;
+ }
- public void setDescription1(String description1) {
- this.description1 = description1;
- }
+ public String getLongitude() {
+ return longitude;
+ }
- public String getDescription2() {
- return description2;
- }
+ public void setLongitude(String longitude) {
+ this.longitude = longitude;
+ }
- public void setDescription2(String description2) {
- this.description2 = description2;
- }
+ public String getStatus() {
+ return status;
+ }
- public String getEndDate() {
- return endDate;
- }
+ public void setStatus(String status) {
+ this.status = status;
+ }
- public void setEndDate(String endDate) {
- this.endDate = endDate;
- }
+ public String getTs() {
+ return ts;
+ }
- public String getId() {
- return id;
- }
+ public void setTs(String ts) {
+ this.ts = ts;
+ }
- public void setId(String id) {
- this.id = id;
- }
+ public String getValid() {
+ return valid;
+ }
- public String getKm() {
- return km;
- }
-
- public void setKm(String km) {
- this.km = km;
- }
-
- public String getLatitude() {
- return latitude;
- }
-
- public void setLatitude(String latitude) {
- this.latitude = latitude;
- }
-
- public String getLongitude() {
- return longitude;
- }
-
- public void setLongitude(String longitude) {
- this.longitude = longitude;
- }
-
- public String getModelName() {
- return modelName;
- }
-
- public void setModelName(String modelName) {
- this.modelName = modelName;
- }
-
- public String getStatus() {
- return status;
- }
-
- public void setStatus(String status) {
- this.status = status;
- }
-
- public String getStatusName() {
- return statusName;
- }
-
- public void setStatusName(String statusName) {
- this.statusName = statusName;
- }
-
- public String getTaskCode() {
- return taskCode;
- }
-
- public void setTaskCode(String taskCode) {
- this.taskCode = taskCode;
- }
-
- public String getTaskName() {
- return taskName;
- }
-
- public void setTaskName(String taskName) {
- this.taskName = taskName;
- }
-
- public String getTs() {
- return ts;
- }
-
- public void setTs(String ts) {
- this.ts = ts;
- }
-
- public String getUpdateTime() {
- return updateTime;
- }
-
- public void setUpdateTime(String updateTime) {
- this.updateTime = updateTime;
- }
-
- public String getValid() {
- return valid;
- }
-
- public void setValid(String valid) {
- this.valid = valid;
- }
+ public void setValid(String valid) {
+ this.valid = valid;
}
}
}
diff --git a/app/src/main/java/com/casic/br/ktd/netty/udp/UdpClient.kt b/app/src/main/java/com/casic/br/ktd/netty/udp/UdpClient.kt
index 954e2cb..a733a74 100644
--- a/app/src/main/java/com/casic/br/ktd/netty/udp/UdpClient.kt
+++ b/app/src/main/java/com/casic/br/ktd/netty/udp/UdpClient.kt
@@ -52,7 +52,7 @@
CoroutineScope(Dispatchers.Main).launch {
withContext(Dispatchers.IO) {
val host = SaveKeyValues.getValue(
- LocaleConstant.LOCATION_UDP_SERVER, "192.168.1.123"
+ LocaleConstant.LOCATION_UDP_SERVER, "192.168.1.241"
).toString()
val datagramPacket = DatagramPacket(
Unpooled.copiedBuffer(value, CharsetUtil.UTF_8),
@@ -67,8 +67,7 @@
CoroutineScope(Dispatchers.Main).launch {
withContext(Dispatchers.IO) {
val host = SaveKeyValues.getValue(
-// LocaleConstant.LOCATION_UDP_SERVER, "192.168.1.222"
- LocaleConstant.LOCATION_UDP_SERVER, "192.168.1.123"
+ LocaleConstant.LOCATION_UDP_SERVER, "192.168.1.241"
).toString()
val datagramPacket = DatagramPacket(
Unpooled.copiedBuffer(value),
@@ -83,7 +82,7 @@
CoroutineScope(Dispatchers.Main).launch {
withContext(Dispatchers.IO) {
val host = SaveKeyValues.getValue(
- LocaleConstant.LOCATION_UDP_SERVER, "192.168.1.123"
+ LocaleConstant.LOCATION_UDP_SERVER, "192.168.1.241"
).toString()
val datagramPacket = DatagramPacket(
Unpooled.copiedBuffer(value),
diff --git a/app/src/main/res/layout/popu_map_car_window.xml b/app/src/main/res/layout/popu_map_car_window.xml
index 71ba8b7..8bad2c4 100644
--- a/app/src/main/res/layout/popu_map_car_window.xml
+++ b/app/src/main/res/layout/popu_map_car_window.xml
@@ -1,6 +1,5 @@
-
-
-
-
-
-
-
-
+
\ No newline at end of file
diff --git a/app/src/main/res/layout/popu_map_task_window.xml b/app/src/main/res/layout/popu_map_task_window.xml
new file mode 100644
index 0000000..36c1fdd
--- /dev/null
+++ b/app/src/main/res/layout/popu_map_task_window.xml
@@ -0,0 +1,79 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file