diff --git a/app/src/main/java/com/casic/br/operationsite/view/WorkSiteTabActivity.kt b/app/src/main/java/com/casic/br/operationsite/view/WorkSiteTabActivity.kt index 5d48ff9..963c092 100644 --- a/app/src/main/java/com/casic/br/operationsite/view/WorkSiteTabActivity.kt +++ b/app/src/main/java/com/casic/br/operationsite/view/WorkSiteTabActivity.kt @@ -13,6 +13,7 @@ import com.casic.br.operationsite.R import com.casic.br.operationsite.extensions.initLayoutImmersionBar import com.casic.br.operationsite.model.DeviceConfigModel +import com.casic.br.operationsite.model.WorkSiteAreaModel import com.casic.br.operationsite.model.WorkerModel import com.casic.br.operationsite.utils.DeviceType import com.casic.br.operationsite.utils.LoadingDialogHub @@ -41,11 +42,7 @@ private val polygonOptions by lazy { PolygonOptions() } private val latlngs: MutableList = ArrayList() private val workers: MutableList = ArrayList() - - /** - * 自定义Marker弹出框 - * */ - private var infoWindow: View? = null + private val safetyTrees: MutableList = ArrayList() override fun initLayoutView(): Int = R.layout.activity_site_tab @@ -129,10 +126,27 @@ val latitudeList: MutableList = ArrayList() val longitudeList: MutableList = ArrayList() it.data.forEach { data -> - latitudeList.add(data.lat.toDouble()) - longitudeList.add(data.lng.toDouble()) + val lat = data.lat.toDouble() + val lng = data.lng.toDouble() - latlngs.add(LatLng(data.lat.toDouble(), data.lng.toDouble())) + latitudeList.add(lat) + longitudeList.add(lng) + + val latLng = LatLng(lat, lng) + + safetyTrees.add(data) + //安全树围起来的区域范围 + latlngs.add(latLng) + + //标记安全树 + aMap.addMarker( + MarkerOptions().position(latLng).title(data.deviceCode) + .icon( + BitmapDescriptorFactory.fromBitmap( + BitmapDescriptorFactory.fromResource(R.mipmap.map_pin).bitmap + ) + ) + ) } //计算所有点的中心点位置 val centerLatLng = LatLng(latitudeList.average(), longitudeList.average()) @@ -176,31 +190,46 @@ } override fun getInfoWindow(marker: Marker?): View? { - if (infoWindow == null) { - infoWindow = LayoutInflater.from(this).inflate(R.layout.popu_worker_info, null) - } - val v = infoWindow!! - //反射得到popup里面的控件对象 - val workerNameView = v.findViewById(R.id.workerNameView) - val heartRateView = v.findViewById(R.id.heartRateView) - val bloodOxygenView = v.findViewById(R.id.bloodOxygenView) - val timeView = v.findViewById(R.id.timeView) + if (marker?.options?.title.toString().startsWith("AQS")) { + val v = LayoutInflater.from(this).inflate(R.layout.popu_safety_tree_info, null) + //反射得到popup里面的控件对象 + val deviceNameView = v.findViewById(R.id.deviceNameView) + val alarmValueView = v.findViewById(R.id.alarmValueView) + val timeView = v.findViewById(R.id.timeView) - val workerId = marker?.options?.title - workers.forEach { - if (it.workerId == workerId) { - val workerName = if (it.workerName.isNullOrBlank()) { - "张三" - } else { - it.workerName + val deviceCode = marker?.options?.title + safetyTrees.forEach { + if (it.deviceCode == deviceCode) { + deviceNameView.text = "设备名称:安全树-${it.deviceCode}" + alarmValueView.text = "甲烷浓度:${it.gasValue}" + timeView.text = "报警时间:${it.time}" } - workerNameView.text = "名称:$workerName" - heartRateView.text = "心率:${it.heartRate}次/min" - bloodOxygenView.text = "血氧浓度:${it.bloodOxygen}%" - timeView.text = "时间:${it.time}" } + return v + } else { + val v = LayoutInflater.from(this).inflate(R.layout.popu_worker_info, null) + //反射得到popup里面的控件对象 + val workerNameView = v.findViewById(R.id.workerNameView) + val heartRateView = v.findViewById(R.id.heartRateView) + val bloodOxygenView = v.findViewById(R.id.bloodOxygenView) + val timeView = v.findViewById(R.id.timeView) + + val workerId = marker?.options?.title + workers.forEach { + if (it.workerId == workerId) { + val workerName = if (it.workerName.isNullOrBlank()) { + "张三" + } else { + it.workerName + } + workerNameView.text = "名称:$workerName" + heartRateView.text = "心率:${it.heartRate}次/min" + bloodOxygenView.text = "血氧浓度:${it.bloodOxygen}%" + timeView.text = "时间:${it.time}" + } + } + return v } - return infoWindow } /** diff --git a/app/src/main/java/com/casic/br/operationsite/view/WorkSiteTabActivity.kt b/app/src/main/java/com/casic/br/operationsite/view/WorkSiteTabActivity.kt index 5d48ff9..963c092 100644 --- a/app/src/main/java/com/casic/br/operationsite/view/WorkSiteTabActivity.kt +++ b/app/src/main/java/com/casic/br/operationsite/view/WorkSiteTabActivity.kt @@ -13,6 +13,7 @@ import com.casic.br.operationsite.R import com.casic.br.operationsite.extensions.initLayoutImmersionBar import com.casic.br.operationsite.model.DeviceConfigModel +import com.casic.br.operationsite.model.WorkSiteAreaModel import com.casic.br.operationsite.model.WorkerModel import com.casic.br.operationsite.utils.DeviceType import com.casic.br.operationsite.utils.LoadingDialogHub @@ -41,11 +42,7 @@ private val polygonOptions by lazy { PolygonOptions() } private val latlngs: MutableList = ArrayList() private val workers: MutableList = ArrayList() - - /** - * 自定义Marker弹出框 - * */ - private var infoWindow: View? = null + private val safetyTrees: MutableList = ArrayList() override fun initLayoutView(): Int = R.layout.activity_site_tab @@ -129,10 +126,27 @@ val latitudeList: MutableList = ArrayList() val longitudeList: MutableList = ArrayList() it.data.forEach { data -> - latitudeList.add(data.lat.toDouble()) - longitudeList.add(data.lng.toDouble()) + val lat = data.lat.toDouble() + val lng = data.lng.toDouble() - latlngs.add(LatLng(data.lat.toDouble(), data.lng.toDouble())) + latitudeList.add(lat) + longitudeList.add(lng) + + val latLng = LatLng(lat, lng) + + safetyTrees.add(data) + //安全树围起来的区域范围 + latlngs.add(latLng) + + //标记安全树 + aMap.addMarker( + MarkerOptions().position(latLng).title(data.deviceCode) + .icon( + BitmapDescriptorFactory.fromBitmap( + BitmapDescriptorFactory.fromResource(R.mipmap.map_pin).bitmap + ) + ) + ) } //计算所有点的中心点位置 val centerLatLng = LatLng(latitudeList.average(), longitudeList.average()) @@ -176,31 +190,46 @@ } override fun getInfoWindow(marker: Marker?): View? { - if (infoWindow == null) { - infoWindow = LayoutInflater.from(this).inflate(R.layout.popu_worker_info, null) - } - val v = infoWindow!! - //反射得到popup里面的控件对象 - val workerNameView = v.findViewById(R.id.workerNameView) - val heartRateView = v.findViewById(R.id.heartRateView) - val bloodOxygenView = v.findViewById(R.id.bloodOxygenView) - val timeView = v.findViewById(R.id.timeView) + if (marker?.options?.title.toString().startsWith("AQS")) { + val v = LayoutInflater.from(this).inflate(R.layout.popu_safety_tree_info, null) + //反射得到popup里面的控件对象 + val deviceNameView = v.findViewById(R.id.deviceNameView) + val alarmValueView = v.findViewById(R.id.alarmValueView) + val timeView = v.findViewById(R.id.timeView) - val workerId = marker?.options?.title - workers.forEach { - if (it.workerId == workerId) { - val workerName = if (it.workerName.isNullOrBlank()) { - "张三" - } else { - it.workerName + val deviceCode = marker?.options?.title + safetyTrees.forEach { + if (it.deviceCode == deviceCode) { + deviceNameView.text = "设备名称:安全树-${it.deviceCode}" + alarmValueView.text = "甲烷浓度:${it.gasValue}" + timeView.text = "报警时间:${it.time}" } - workerNameView.text = "名称:$workerName" - heartRateView.text = "心率:${it.heartRate}次/min" - bloodOxygenView.text = "血氧浓度:${it.bloodOxygen}%" - timeView.text = "时间:${it.time}" } + return v + } else { + val v = LayoutInflater.from(this).inflate(R.layout.popu_worker_info, null) + //反射得到popup里面的控件对象 + val workerNameView = v.findViewById(R.id.workerNameView) + val heartRateView = v.findViewById(R.id.heartRateView) + val bloodOxygenView = v.findViewById(R.id.bloodOxygenView) + val timeView = v.findViewById(R.id.timeView) + + val workerId = marker?.options?.title + workers.forEach { + if (it.workerId == workerId) { + val workerName = if (it.workerName.isNullOrBlank()) { + "张三" + } else { + it.workerName + } + workerNameView.text = "名称:$workerName" + heartRateView.text = "心率:${it.heartRate}次/min" + bloodOxygenView.text = "血氧浓度:${it.bloodOxygen}%" + timeView.text = "时间:${it.time}" + } + } + return v } - return infoWindow } /** diff --git a/app/src/main/res/layout/popu_safety_tree_info.xml b/app/src/main/res/layout/popu_safety_tree_info.xml new file mode 100644 index 0000000..9b7a516 --- /dev/null +++ b/app/src/main/res/layout/popu_safety_tree_info.xml @@ -0,0 +1,23 @@ + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/com/casic/br/operationsite/view/WorkSiteTabActivity.kt b/app/src/main/java/com/casic/br/operationsite/view/WorkSiteTabActivity.kt index 5d48ff9..963c092 100644 --- a/app/src/main/java/com/casic/br/operationsite/view/WorkSiteTabActivity.kt +++ b/app/src/main/java/com/casic/br/operationsite/view/WorkSiteTabActivity.kt @@ -13,6 +13,7 @@ import com.casic.br.operationsite.R import com.casic.br.operationsite.extensions.initLayoutImmersionBar import com.casic.br.operationsite.model.DeviceConfigModel +import com.casic.br.operationsite.model.WorkSiteAreaModel import com.casic.br.operationsite.model.WorkerModel import com.casic.br.operationsite.utils.DeviceType import com.casic.br.operationsite.utils.LoadingDialogHub @@ -41,11 +42,7 @@ private val polygonOptions by lazy { PolygonOptions() } private val latlngs: MutableList = ArrayList() private val workers: MutableList = ArrayList() - - /** - * 自定义Marker弹出框 - * */ - private var infoWindow: View? = null + private val safetyTrees: MutableList = ArrayList() override fun initLayoutView(): Int = R.layout.activity_site_tab @@ -129,10 +126,27 @@ val latitudeList: MutableList = ArrayList() val longitudeList: MutableList = ArrayList() it.data.forEach { data -> - latitudeList.add(data.lat.toDouble()) - longitudeList.add(data.lng.toDouble()) + val lat = data.lat.toDouble() + val lng = data.lng.toDouble() - latlngs.add(LatLng(data.lat.toDouble(), data.lng.toDouble())) + latitudeList.add(lat) + longitudeList.add(lng) + + val latLng = LatLng(lat, lng) + + safetyTrees.add(data) + //安全树围起来的区域范围 + latlngs.add(latLng) + + //标记安全树 + aMap.addMarker( + MarkerOptions().position(latLng).title(data.deviceCode) + .icon( + BitmapDescriptorFactory.fromBitmap( + BitmapDescriptorFactory.fromResource(R.mipmap.map_pin).bitmap + ) + ) + ) } //计算所有点的中心点位置 val centerLatLng = LatLng(latitudeList.average(), longitudeList.average()) @@ -176,31 +190,46 @@ } override fun getInfoWindow(marker: Marker?): View? { - if (infoWindow == null) { - infoWindow = LayoutInflater.from(this).inflate(R.layout.popu_worker_info, null) - } - val v = infoWindow!! - //反射得到popup里面的控件对象 - val workerNameView = v.findViewById(R.id.workerNameView) - val heartRateView = v.findViewById(R.id.heartRateView) - val bloodOxygenView = v.findViewById(R.id.bloodOxygenView) - val timeView = v.findViewById(R.id.timeView) + if (marker?.options?.title.toString().startsWith("AQS")) { + val v = LayoutInflater.from(this).inflate(R.layout.popu_safety_tree_info, null) + //反射得到popup里面的控件对象 + val deviceNameView = v.findViewById(R.id.deviceNameView) + val alarmValueView = v.findViewById(R.id.alarmValueView) + val timeView = v.findViewById(R.id.timeView) - val workerId = marker?.options?.title - workers.forEach { - if (it.workerId == workerId) { - val workerName = if (it.workerName.isNullOrBlank()) { - "张三" - } else { - it.workerName + val deviceCode = marker?.options?.title + safetyTrees.forEach { + if (it.deviceCode == deviceCode) { + deviceNameView.text = "设备名称:安全树-${it.deviceCode}" + alarmValueView.text = "甲烷浓度:${it.gasValue}" + timeView.text = "报警时间:${it.time}" } - workerNameView.text = "名称:$workerName" - heartRateView.text = "心率:${it.heartRate}次/min" - bloodOxygenView.text = "血氧浓度:${it.bloodOxygen}%" - timeView.text = "时间:${it.time}" } + return v + } else { + val v = LayoutInflater.from(this).inflate(R.layout.popu_worker_info, null) + //反射得到popup里面的控件对象 + val workerNameView = v.findViewById(R.id.workerNameView) + val heartRateView = v.findViewById(R.id.heartRateView) + val bloodOxygenView = v.findViewById(R.id.bloodOxygenView) + val timeView = v.findViewById(R.id.timeView) + + val workerId = marker?.options?.title + workers.forEach { + if (it.workerId == workerId) { + val workerName = if (it.workerName.isNullOrBlank()) { + "张三" + } else { + it.workerName + } + workerNameView.text = "名称:$workerName" + heartRateView.text = "心率:${it.heartRate}次/min" + bloodOxygenView.text = "血氧浓度:${it.bloodOxygen}%" + timeView.text = "时间:${it.time}" + } + } + return v } - return infoWindow } /** diff --git a/app/src/main/res/layout/popu_safety_tree_info.xml b/app/src/main/res/layout/popu_safety_tree_info.xml new file mode 100644 index 0000000..9b7a516 --- /dev/null +++ b/app/src/main/res/layout/popu_safety_tree_info.xml @@ -0,0 +1,23 @@ + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/mipmap-xxhdpi/map_pin.png b/app/src/main/res/mipmap-xxhdpi/map_pin.png new file mode 100644 index 0000000..674c628 --- /dev/null +++ b/app/src/main/res/mipmap-xxhdpi/map_pin.png Binary files differ