diff --git a/app/src/main/java/com/casic/smart/town/sanxi/fragment/HomePageFragment.kt b/app/src/main/java/com/casic/smart/town/sanxi/fragment/HomePageFragment.kt index 19d2e85..397b2bd 100644 --- a/app/src/main/java/com/casic/smart/town/sanxi/fragment/HomePageFragment.kt +++ b/app/src/main/java/com/casic/smart/town/sanxi/fragment/HomePageFragment.kt @@ -2,7 +2,6 @@ import android.graphics.Color import android.os.Bundle -import android.util.Log import android.view.LayoutInflater import android.view.View import android.view.ViewGroup @@ -21,7 +20,6 @@ import com.amap.api.maps.model.MyLocationStyle import com.casic.smart.town.sanxi.R import com.casic.smart.town.sanxi.databinding.FragmentHomeBinding -import com.casic.smart.town.sanxi.extensions.valueToType import com.casic.smart.town.sanxi.model.MapAlarmModel import com.casic.smart.town.sanxi.model.MapDeviceModel import com.casic.smart.town.sanxi.util.ILocationListener @@ -29,12 +27,12 @@ import com.casic.smart.town.sanxi.util.LocationHub import com.casic.smart.town.sanxi.vm.DeviceViewModel import com.pengxh.kt.lite.base.KotlinBaseFragment -import com.pengxh.kt.lite.extensions.toJson import com.pengxh.kt.lite.vm.LoadState class HomePageFragment : KotlinBaseFragment(), AMap.OnMapLoadedListener, - AMap.OnCameraChangeListener, AMap.OnMarkerClickListener, AMap.InfoWindowAdapter { + AMap.OnCameraChangeListener, AMap.OnMarkerClickListener, AMap.InfoWindowAdapter, + AMap.OnInfoWindowClickListener { private val kTag = "HomePageFragment" private lateinit var aMap: AMap @@ -51,7 +49,7 @@ /** * 自定义Marker弹出框 * */ - private var infoWindow: View? = null + private lateinit var v: View override fun initViewBinding( inflater: LayoutInflater, container: ViewGroup? @@ -100,6 +98,8 @@ aMap.addOnMarkerClickListener(this) // 点击marker弹出自定义popup aMap.setInfoWindowAdapter(this) + // 点击popup + aMap.setOnInfoWindowClickListener(this) //显示定位小蓝点 val locationStyle = MyLocationStyle() @@ -135,13 +135,13 @@ //将所有设备信息转化缓存为Marker点 allMarkerOptions.add( MarkerOptions().position(LatLng(latitude, longitude)) - .title(device.deviceName).snippet(device.wellCode) + .title(device.deviceTypeName).snippet(device.wellCode) ) } //移动到指定经纬度 val centerLatLng = LatLng(latitudeList.average(), longitudeList.average()) - val cameraPosition = CameraPosition(centerLatLng, 16f, 0f, 0f) + val cameraPosition = CameraPosition(centerLatLng, 17f, 0f, 0f) val cameraUpdate = CameraUpdateFactory.newCameraPosition(cameraPosition) aMap.animateCamera(cameraUpdate) } @@ -227,59 +227,61 @@ } override fun onMarkerClick(marker: Marker?): Boolean { + val clickedMarker = marker?.snippet.toString() + v = if (clickedMarker.startsWith("GX")) { + LayoutInflater.from(requireContext()).inflate(R.layout.popu_map_device_info, null) + } else { + LayoutInflater.from(requireContext()).inflate(R.layout.popu_map_alarm_info, null) + } + //显示闸井信息 marker?.showInfoWindow() return true } override fun getInfoWindow(marker: Marker?): View? { - if (infoWindow == null) { - infoWindow = LayoutInflater.from(requireContext()).inflate(R.layout.popu_map_info, null) - } - val v = infoWindow!! - - //反射得到popup里面的控件对象 - val wellNameView = v.findViewById(R.id.wellNameView) - val wellCodeView = v.findViewById(R.id.wellCodeView) - val wellTypeView = v.findViewById(R.id.wellTypeView) - val wellStateView = v.findViewById(R.id.wellStateView) - val deepView = v.findViewById(R.id.deepView) - val locationView = v.findViewById(R.id.locationView) - val clickedMarker = marker?.snippet.toString() - Log.d(kTag, clickedMarker) if (clickedMarker.startsWith("GX")) { + val deviceNameView = v.findViewById(R.id.deviceNameView) + val deviceCodeView = v.findViewById(R.id.deviceCodeView) + val deviceTypeView = v.findViewById(R.id.deviceTypeView) + val deptNameView = v.findViewById(R.id.deptNameView) + val updateDataView = v.findViewById(R.id.updateDataView) + val locationView = v.findViewById(R.id.locationView) + //搜设备 for (device in deviceInfoModels) { - if (clickedMarker == device.devcode) { + if (clickedMarker == device.wellCode) { - Log.d(kTag, device.toJson()) - - wellNameView.text = String.format("设备名称: ${device.deviceName}") - wellCodeView.text = String.format("设备编号: ${device.devcode}") - wellTypeView.text = String.format("设备类型: ${device.deviceTypeName}") - wellStateView.text = String.format("权属单位: ${device.deptName}") - deepView.text = String.format("更新时间: ${device.realtimeData}") + deviceNameView.text = String.format("设备名称: ${device.deviceName}") + deviceCodeView.text = String.format("设备编号: ${device.devcode}") + deviceTypeView.text = String.format("设备类型: ${device.deviceTypeName}") + deptNameView.text = String.format("权属单位: ${device.deptName}") + updateDataView.text = String.format("更新时间: ${device.realtimeData}") locationView.text = String.format("详细位置: ${device.position}") - return infoWindow + return v } } } else { //搜报警 + val alarmContentView = v.findViewById(R.id.alarmContentView) + val deviceCodeView = v.findViewById(R.id.deviceCodeView) + val deviceTypeView = v.findViewById(R.id.deviceTypeView) + val alarmDateView = v.findViewById(R.id.alarmDateView) + val locationView = v.findViewById(R.id.locationView) + for (alarm in alarmInfoModels) { if (clickedMarker == alarm.alarmId) { - Log.d(kTag, alarm.toJson()) - wellNameView.text = String.format("报警内容: ${alarm.alarmContent}") - wellCodeView.text = String.format("设备编号: ${alarm.wellCode}") - wellTypeView.text = String.format("设备类型: ${alarm.wellType.valueToType()}") -// wellStateView.text = String.format("布/撤防状态: $bfztName") - deepView.text = String.format("报警时间: ${alarm.alarmTimeDate}") + alarmContentView.text = String.format("报警内容: ${alarm.alarmContent}") + deviceCodeView.text = String.format("设备编号: ${alarm.devcode}") + deviceTypeView.text = String.format("设备类型: ${alarm.deviceType}") + alarmDateView.text = String.format("报警时间: ${alarm.alarmTimeDate}") locationView.text = String.format("详细位置: ${alarm.position}") - return infoWindow + return v } } } @@ -287,6 +289,10 @@ return null } + override fun onInfoWindowClick(marker: Marker?) { + marker?.hideInfoWindow() + } + /** * 此方法不能修改整个 InfoWindow 的背景和边框,无论自定义的样式是什么样,SDK 都会在最外层添加一个默认的边框 * */ diff --git a/app/src/main/java/com/casic/smart/town/sanxi/fragment/HomePageFragment.kt b/app/src/main/java/com/casic/smart/town/sanxi/fragment/HomePageFragment.kt index 19d2e85..397b2bd 100644 --- a/app/src/main/java/com/casic/smart/town/sanxi/fragment/HomePageFragment.kt +++ b/app/src/main/java/com/casic/smart/town/sanxi/fragment/HomePageFragment.kt @@ -2,7 +2,6 @@ import android.graphics.Color import android.os.Bundle -import android.util.Log import android.view.LayoutInflater import android.view.View import android.view.ViewGroup @@ -21,7 +20,6 @@ import com.amap.api.maps.model.MyLocationStyle import com.casic.smart.town.sanxi.R import com.casic.smart.town.sanxi.databinding.FragmentHomeBinding -import com.casic.smart.town.sanxi.extensions.valueToType import com.casic.smart.town.sanxi.model.MapAlarmModel import com.casic.smart.town.sanxi.model.MapDeviceModel import com.casic.smart.town.sanxi.util.ILocationListener @@ -29,12 +27,12 @@ import com.casic.smart.town.sanxi.util.LocationHub import com.casic.smart.town.sanxi.vm.DeviceViewModel import com.pengxh.kt.lite.base.KotlinBaseFragment -import com.pengxh.kt.lite.extensions.toJson import com.pengxh.kt.lite.vm.LoadState class HomePageFragment : KotlinBaseFragment(), AMap.OnMapLoadedListener, - AMap.OnCameraChangeListener, AMap.OnMarkerClickListener, AMap.InfoWindowAdapter { + AMap.OnCameraChangeListener, AMap.OnMarkerClickListener, AMap.InfoWindowAdapter, + AMap.OnInfoWindowClickListener { private val kTag = "HomePageFragment" private lateinit var aMap: AMap @@ -51,7 +49,7 @@ /** * 自定义Marker弹出框 * */ - private var infoWindow: View? = null + private lateinit var v: View override fun initViewBinding( inflater: LayoutInflater, container: ViewGroup? @@ -100,6 +98,8 @@ aMap.addOnMarkerClickListener(this) // 点击marker弹出自定义popup aMap.setInfoWindowAdapter(this) + // 点击popup + aMap.setOnInfoWindowClickListener(this) //显示定位小蓝点 val locationStyle = MyLocationStyle() @@ -135,13 +135,13 @@ //将所有设备信息转化缓存为Marker点 allMarkerOptions.add( MarkerOptions().position(LatLng(latitude, longitude)) - .title(device.deviceName).snippet(device.wellCode) + .title(device.deviceTypeName).snippet(device.wellCode) ) } //移动到指定经纬度 val centerLatLng = LatLng(latitudeList.average(), longitudeList.average()) - val cameraPosition = CameraPosition(centerLatLng, 16f, 0f, 0f) + val cameraPosition = CameraPosition(centerLatLng, 17f, 0f, 0f) val cameraUpdate = CameraUpdateFactory.newCameraPosition(cameraPosition) aMap.animateCamera(cameraUpdate) } @@ -227,59 +227,61 @@ } override fun onMarkerClick(marker: Marker?): Boolean { + val clickedMarker = marker?.snippet.toString() + v = if (clickedMarker.startsWith("GX")) { + LayoutInflater.from(requireContext()).inflate(R.layout.popu_map_device_info, null) + } else { + LayoutInflater.from(requireContext()).inflate(R.layout.popu_map_alarm_info, null) + } + //显示闸井信息 marker?.showInfoWindow() return true } override fun getInfoWindow(marker: Marker?): View? { - if (infoWindow == null) { - infoWindow = LayoutInflater.from(requireContext()).inflate(R.layout.popu_map_info, null) - } - val v = infoWindow!! - - //反射得到popup里面的控件对象 - val wellNameView = v.findViewById(R.id.wellNameView) - val wellCodeView = v.findViewById(R.id.wellCodeView) - val wellTypeView = v.findViewById(R.id.wellTypeView) - val wellStateView = v.findViewById(R.id.wellStateView) - val deepView = v.findViewById(R.id.deepView) - val locationView = v.findViewById(R.id.locationView) - val clickedMarker = marker?.snippet.toString() - Log.d(kTag, clickedMarker) if (clickedMarker.startsWith("GX")) { + val deviceNameView = v.findViewById(R.id.deviceNameView) + val deviceCodeView = v.findViewById(R.id.deviceCodeView) + val deviceTypeView = v.findViewById(R.id.deviceTypeView) + val deptNameView = v.findViewById(R.id.deptNameView) + val updateDataView = v.findViewById(R.id.updateDataView) + val locationView = v.findViewById(R.id.locationView) + //搜设备 for (device in deviceInfoModels) { - if (clickedMarker == device.devcode) { + if (clickedMarker == device.wellCode) { - Log.d(kTag, device.toJson()) - - wellNameView.text = String.format("设备名称: ${device.deviceName}") - wellCodeView.text = String.format("设备编号: ${device.devcode}") - wellTypeView.text = String.format("设备类型: ${device.deviceTypeName}") - wellStateView.text = String.format("权属单位: ${device.deptName}") - deepView.text = String.format("更新时间: ${device.realtimeData}") + deviceNameView.text = String.format("设备名称: ${device.deviceName}") + deviceCodeView.text = String.format("设备编号: ${device.devcode}") + deviceTypeView.text = String.format("设备类型: ${device.deviceTypeName}") + deptNameView.text = String.format("权属单位: ${device.deptName}") + updateDataView.text = String.format("更新时间: ${device.realtimeData}") locationView.text = String.format("详细位置: ${device.position}") - return infoWindow + return v } } } else { //搜报警 + val alarmContentView = v.findViewById(R.id.alarmContentView) + val deviceCodeView = v.findViewById(R.id.deviceCodeView) + val deviceTypeView = v.findViewById(R.id.deviceTypeView) + val alarmDateView = v.findViewById(R.id.alarmDateView) + val locationView = v.findViewById(R.id.locationView) + for (alarm in alarmInfoModels) { if (clickedMarker == alarm.alarmId) { - Log.d(kTag, alarm.toJson()) - wellNameView.text = String.format("报警内容: ${alarm.alarmContent}") - wellCodeView.text = String.format("设备编号: ${alarm.wellCode}") - wellTypeView.text = String.format("设备类型: ${alarm.wellType.valueToType()}") -// wellStateView.text = String.format("布/撤防状态: $bfztName") - deepView.text = String.format("报警时间: ${alarm.alarmTimeDate}") + alarmContentView.text = String.format("报警内容: ${alarm.alarmContent}") + deviceCodeView.text = String.format("设备编号: ${alarm.devcode}") + deviceTypeView.text = String.format("设备类型: ${alarm.deviceType}") + alarmDateView.text = String.format("报警时间: ${alarm.alarmTimeDate}") locationView.text = String.format("详细位置: ${alarm.position}") - return infoWindow + return v } } } @@ -287,6 +289,10 @@ return null } + override fun onInfoWindowClick(marker: Marker?) { + marker?.hideInfoWindow() + } + /** * 此方法不能修改整个 InfoWindow 的背景和边框,无论自定义的样式是什么样,SDK 都会在最外层添加一个默认的边框 * */ diff --git a/app/src/main/java/com/casic/smart/town/sanxi/view/AllWellActivity.kt b/app/src/main/java/com/casic/smart/town/sanxi/view/AllWellActivity.kt index b77a48d..4b1d246 100644 --- a/app/src/main/java/com/casic/smart/town/sanxi/view/AllWellActivity.kt +++ b/app/src/main/java/com/casic/smart/town/sanxi/view/AllWellActivity.kt @@ -27,7 +27,8 @@ import com.pengxh.kt.lite.vm.LoadState class AllWellActivity : KotlinBaseActivity(), AMap.OnMapLoadedListener, - AMap.OnCameraChangeListener, AMap.OnMarkerClickListener, AMap.InfoWindowAdapter { + AMap.OnCameraChangeListener, AMap.OnMarkerClickListener, AMap.InfoWindowAdapter, + AMap.OnInfoWindowClickListener { private lateinit var wellViewModel: WellViewModel private lateinit var aMap: AMap @@ -50,7 +51,7 @@ /** * 自定义Marker弹出框 * */ - private var infoWindow: View? = null + private lateinit var v: View override fun initViewBinding(): ActivityAllWellBinding { return ActivityAllWellBinding.inflate(layoutInflater) @@ -105,7 +106,7 @@ val centerLatLng = LatLng(latitudeList.average(), longitudeList.average()) val cameraPosition = CameraPosition(centerLatLng, 17f, 0f, 0f) val cameraUpdate = CameraUpdateFactory.newCameraPosition(cameraPosition) - aMap.animateCamera(cameraUpdate, 2000, null) + aMap.animateCamera(cameraUpdate) } } } @@ -133,6 +134,8 @@ aMap.addOnMarkerClickListener(this) // 点击marker弹出自定义popup aMap.setInfoWindowAdapter(this) + // 点击popup + aMap.setOnInfoWindowClickListener(this) } override fun onMapLoaded() { @@ -156,7 +159,7 @@ allMarkerOptions.forEach { screenLocation = proj.toScreenLocation(it.position) if (screenLocation.x >= 0 && screenLocation.y >= 0 && screenLocation.x <= dm.widthPixels && screenLocation.y <= dm.heightPixels) { - it.icon(BitmapDescriptorFactory.fromBitmap(BitmapDescriptorFactory.fromResource(R.mipmap.map_pin).bitmap)) + it.icon(BitmapDescriptorFactory.fromBitmap(BitmapDescriptorFactory.fromResource(R.mipmap.map_device).bitmap)) markerOptionsInView.add(it) } } @@ -166,17 +169,14 @@ } override fun onMarkerClick(marker: Marker?): Boolean { + v = LayoutInflater.from(this).inflate(R.layout.popu_map_info, null) + //显示闸井信息 marker?.showInfoWindow() return true } override fun getInfoWindow(marker: Marker?): View? { - if (infoWindow == null) { - infoWindow = LayoutInflater.from(this).inflate(R.layout.popu_map_info, null) - } - val v = infoWindow!! - //反射得到popup里面的控件对象 val wellNameView = v.findViewById(R.id.wellNameView) val wellCodeView = v.findViewById(R.id.wellCodeView) val wellTypeView = v.findViewById(R.id.wellTypeView) @@ -207,6 +207,10 @@ return null } + override fun onInfoWindowClick(marker: Marker?) { + marker?.hideInfoWindow() + } + /** * 此方法不能修改整个 InfoWindow 的背景和边框,无论自定义的样式是什么样,SDK 都会在最外层添加一个默认的边框 * */ diff --git a/app/src/main/java/com/casic/smart/town/sanxi/fragment/HomePageFragment.kt b/app/src/main/java/com/casic/smart/town/sanxi/fragment/HomePageFragment.kt index 19d2e85..397b2bd 100644 --- a/app/src/main/java/com/casic/smart/town/sanxi/fragment/HomePageFragment.kt +++ b/app/src/main/java/com/casic/smart/town/sanxi/fragment/HomePageFragment.kt @@ -2,7 +2,6 @@ import android.graphics.Color import android.os.Bundle -import android.util.Log import android.view.LayoutInflater import android.view.View import android.view.ViewGroup @@ -21,7 +20,6 @@ import com.amap.api.maps.model.MyLocationStyle import com.casic.smart.town.sanxi.R import com.casic.smart.town.sanxi.databinding.FragmentHomeBinding -import com.casic.smart.town.sanxi.extensions.valueToType import com.casic.smart.town.sanxi.model.MapAlarmModel import com.casic.smart.town.sanxi.model.MapDeviceModel import com.casic.smart.town.sanxi.util.ILocationListener @@ -29,12 +27,12 @@ import com.casic.smart.town.sanxi.util.LocationHub import com.casic.smart.town.sanxi.vm.DeviceViewModel import com.pengxh.kt.lite.base.KotlinBaseFragment -import com.pengxh.kt.lite.extensions.toJson import com.pengxh.kt.lite.vm.LoadState class HomePageFragment : KotlinBaseFragment(), AMap.OnMapLoadedListener, - AMap.OnCameraChangeListener, AMap.OnMarkerClickListener, AMap.InfoWindowAdapter { + AMap.OnCameraChangeListener, AMap.OnMarkerClickListener, AMap.InfoWindowAdapter, + AMap.OnInfoWindowClickListener { private val kTag = "HomePageFragment" private lateinit var aMap: AMap @@ -51,7 +49,7 @@ /** * 自定义Marker弹出框 * */ - private var infoWindow: View? = null + private lateinit var v: View override fun initViewBinding( inflater: LayoutInflater, container: ViewGroup? @@ -100,6 +98,8 @@ aMap.addOnMarkerClickListener(this) // 点击marker弹出自定义popup aMap.setInfoWindowAdapter(this) + // 点击popup + aMap.setOnInfoWindowClickListener(this) //显示定位小蓝点 val locationStyle = MyLocationStyle() @@ -135,13 +135,13 @@ //将所有设备信息转化缓存为Marker点 allMarkerOptions.add( MarkerOptions().position(LatLng(latitude, longitude)) - .title(device.deviceName).snippet(device.wellCode) + .title(device.deviceTypeName).snippet(device.wellCode) ) } //移动到指定经纬度 val centerLatLng = LatLng(latitudeList.average(), longitudeList.average()) - val cameraPosition = CameraPosition(centerLatLng, 16f, 0f, 0f) + val cameraPosition = CameraPosition(centerLatLng, 17f, 0f, 0f) val cameraUpdate = CameraUpdateFactory.newCameraPosition(cameraPosition) aMap.animateCamera(cameraUpdate) } @@ -227,59 +227,61 @@ } override fun onMarkerClick(marker: Marker?): Boolean { + val clickedMarker = marker?.snippet.toString() + v = if (clickedMarker.startsWith("GX")) { + LayoutInflater.from(requireContext()).inflate(R.layout.popu_map_device_info, null) + } else { + LayoutInflater.from(requireContext()).inflate(R.layout.popu_map_alarm_info, null) + } + //显示闸井信息 marker?.showInfoWindow() return true } override fun getInfoWindow(marker: Marker?): View? { - if (infoWindow == null) { - infoWindow = LayoutInflater.from(requireContext()).inflate(R.layout.popu_map_info, null) - } - val v = infoWindow!! - - //反射得到popup里面的控件对象 - val wellNameView = v.findViewById(R.id.wellNameView) - val wellCodeView = v.findViewById(R.id.wellCodeView) - val wellTypeView = v.findViewById(R.id.wellTypeView) - val wellStateView = v.findViewById(R.id.wellStateView) - val deepView = v.findViewById(R.id.deepView) - val locationView = v.findViewById(R.id.locationView) - val clickedMarker = marker?.snippet.toString() - Log.d(kTag, clickedMarker) if (clickedMarker.startsWith("GX")) { + val deviceNameView = v.findViewById(R.id.deviceNameView) + val deviceCodeView = v.findViewById(R.id.deviceCodeView) + val deviceTypeView = v.findViewById(R.id.deviceTypeView) + val deptNameView = v.findViewById(R.id.deptNameView) + val updateDataView = v.findViewById(R.id.updateDataView) + val locationView = v.findViewById(R.id.locationView) + //搜设备 for (device in deviceInfoModels) { - if (clickedMarker == device.devcode) { + if (clickedMarker == device.wellCode) { - Log.d(kTag, device.toJson()) - - wellNameView.text = String.format("设备名称: ${device.deviceName}") - wellCodeView.text = String.format("设备编号: ${device.devcode}") - wellTypeView.text = String.format("设备类型: ${device.deviceTypeName}") - wellStateView.text = String.format("权属单位: ${device.deptName}") - deepView.text = String.format("更新时间: ${device.realtimeData}") + deviceNameView.text = String.format("设备名称: ${device.deviceName}") + deviceCodeView.text = String.format("设备编号: ${device.devcode}") + deviceTypeView.text = String.format("设备类型: ${device.deviceTypeName}") + deptNameView.text = String.format("权属单位: ${device.deptName}") + updateDataView.text = String.format("更新时间: ${device.realtimeData}") locationView.text = String.format("详细位置: ${device.position}") - return infoWindow + return v } } } else { //搜报警 + val alarmContentView = v.findViewById(R.id.alarmContentView) + val deviceCodeView = v.findViewById(R.id.deviceCodeView) + val deviceTypeView = v.findViewById(R.id.deviceTypeView) + val alarmDateView = v.findViewById(R.id.alarmDateView) + val locationView = v.findViewById(R.id.locationView) + for (alarm in alarmInfoModels) { if (clickedMarker == alarm.alarmId) { - Log.d(kTag, alarm.toJson()) - wellNameView.text = String.format("报警内容: ${alarm.alarmContent}") - wellCodeView.text = String.format("设备编号: ${alarm.wellCode}") - wellTypeView.text = String.format("设备类型: ${alarm.wellType.valueToType()}") -// wellStateView.text = String.format("布/撤防状态: $bfztName") - deepView.text = String.format("报警时间: ${alarm.alarmTimeDate}") + alarmContentView.text = String.format("报警内容: ${alarm.alarmContent}") + deviceCodeView.text = String.format("设备编号: ${alarm.devcode}") + deviceTypeView.text = String.format("设备类型: ${alarm.deviceType}") + alarmDateView.text = String.format("报警时间: ${alarm.alarmTimeDate}") locationView.text = String.format("详细位置: ${alarm.position}") - return infoWindow + return v } } } @@ -287,6 +289,10 @@ return null } + override fun onInfoWindowClick(marker: Marker?) { + marker?.hideInfoWindow() + } + /** * 此方法不能修改整个 InfoWindow 的背景和边框,无论自定义的样式是什么样,SDK 都会在最外层添加一个默认的边框 * */ diff --git a/app/src/main/java/com/casic/smart/town/sanxi/view/AllWellActivity.kt b/app/src/main/java/com/casic/smart/town/sanxi/view/AllWellActivity.kt index b77a48d..4b1d246 100644 --- a/app/src/main/java/com/casic/smart/town/sanxi/view/AllWellActivity.kt +++ b/app/src/main/java/com/casic/smart/town/sanxi/view/AllWellActivity.kt @@ -27,7 +27,8 @@ import com.pengxh.kt.lite.vm.LoadState class AllWellActivity : KotlinBaseActivity(), AMap.OnMapLoadedListener, - AMap.OnCameraChangeListener, AMap.OnMarkerClickListener, AMap.InfoWindowAdapter { + AMap.OnCameraChangeListener, AMap.OnMarkerClickListener, AMap.InfoWindowAdapter, + AMap.OnInfoWindowClickListener { private lateinit var wellViewModel: WellViewModel private lateinit var aMap: AMap @@ -50,7 +51,7 @@ /** * 自定义Marker弹出框 * */ - private var infoWindow: View? = null + private lateinit var v: View override fun initViewBinding(): ActivityAllWellBinding { return ActivityAllWellBinding.inflate(layoutInflater) @@ -105,7 +106,7 @@ val centerLatLng = LatLng(latitudeList.average(), longitudeList.average()) val cameraPosition = CameraPosition(centerLatLng, 17f, 0f, 0f) val cameraUpdate = CameraUpdateFactory.newCameraPosition(cameraPosition) - aMap.animateCamera(cameraUpdate, 2000, null) + aMap.animateCamera(cameraUpdate) } } } @@ -133,6 +134,8 @@ aMap.addOnMarkerClickListener(this) // 点击marker弹出自定义popup aMap.setInfoWindowAdapter(this) + // 点击popup + aMap.setOnInfoWindowClickListener(this) } override fun onMapLoaded() { @@ -156,7 +159,7 @@ allMarkerOptions.forEach { screenLocation = proj.toScreenLocation(it.position) if (screenLocation.x >= 0 && screenLocation.y >= 0 && screenLocation.x <= dm.widthPixels && screenLocation.y <= dm.heightPixels) { - it.icon(BitmapDescriptorFactory.fromBitmap(BitmapDescriptorFactory.fromResource(R.mipmap.map_pin).bitmap)) + it.icon(BitmapDescriptorFactory.fromBitmap(BitmapDescriptorFactory.fromResource(R.mipmap.map_device).bitmap)) markerOptionsInView.add(it) } } @@ -166,17 +169,14 @@ } override fun onMarkerClick(marker: Marker?): Boolean { + v = LayoutInflater.from(this).inflate(R.layout.popu_map_info, null) + //显示闸井信息 marker?.showInfoWindow() return true } override fun getInfoWindow(marker: Marker?): View? { - if (infoWindow == null) { - infoWindow = LayoutInflater.from(this).inflate(R.layout.popu_map_info, null) - } - val v = infoWindow!! - //反射得到popup里面的控件对象 val wellNameView = v.findViewById(R.id.wellNameView) val wellCodeView = v.findViewById(R.id.wellCodeView) val wellTypeView = v.findViewById(R.id.wellTypeView) @@ -207,6 +207,10 @@ return null } + override fun onInfoWindowClick(marker: Marker?) { + marker?.hideInfoWindow() + } + /** * 此方法不能修改整个 InfoWindow 的背景和边框,无论自定义的样式是什么样,SDK 都会在最外层添加一个默认的边框 * */ diff --git a/app/src/main/java/com/casic/smart/town/sanxi/view/BFWellActivity.kt b/app/src/main/java/com/casic/smart/town/sanxi/view/BFWellActivity.kt index a3f1c6a..686c93b 100644 --- a/app/src/main/java/com/casic/smart/town/sanxi/view/BFWellActivity.kt +++ b/app/src/main/java/com/casic/smart/town/sanxi/view/BFWellActivity.kt @@ -27,7 +27,8 @@ import com.pengxh.kt.lite.vm.LoadState class BFWellActivity : KotlinBaseActivity(), AMap.OnMapLoadedListener, - AMap.OnCameraChangeListener, AMap.OnMarkerClickListener, AMap.InfoWindowAdapter { + AMap.OnCameraChangeListener, AMap.OnMarkerClickListener, AMap.InfoWindowAdapter, + AMap.OnInfoWindowClickListener { private lateinit var wellViewModel: WellViewModel private lateinit var aMap: AMap @@ -50,7 +51,7 @@ /** * 自定义Marker弹出框 * */ - private var infoWindow: View? = null + private lateinit var v: View override fun initViewBinding(): ActivityBfWellBinding { return ActivityBfWellBinding.inflate(layoutInflater) @@ -110,7 +111,7 @@ LatLng(latitudeList.average(), longitudeList.average()) val cameraPosition = CameraPosition(centerLatLng, 17f, 0f, 0f) val cameraUpdate = CameraUpdateFactory.newCameraPosition(cameraPosition) - aMap.animateCamera(cameraUpdate, 2000, null) + aMap.animateCamera(cameraUpdate) } } } @@ -139,6 +140,8 @@ aMap.addOnMarkerClickListener(this) // 点击marker弹出自定义popup aMap.setInfoWindowAdapter(this) + // 点击marker弹出自定义popup + aMap.setInfoWindowAdapter(this) } override fun onMapLoaded() { @@ -162,7 +165,7 @@ allMarkerOptions.forEach { screenLocation = proj.toScreenLocation(it.position) if (screenLocation.x >= 0 && screenLocation.y >= 0 && screenLocation.x <= dm.widthPixels && screenLocation.y <= dm.heightPixels) { - it.icon(BitmapDescriptorFactory.fromBitmap(BitmapDescriptorFactory.fromResource(R.mipmap.map_pin).bitmap)) + it.icon(BitmapDescriptorFactory.fromBitmap(BitmapDescriptorFactory.fromResource(R.mipmap.map_device).bitmap)) markerOptionsInView.add(it) } } @@ -172,17 +175,14 @@ } override fun onMarkerClick(marker: Marker?): Boolean { + v = LayoutInflater.from(this).inflate(R.layout.popu_map_info, null) + //显示闸井信息 marker?.showInfoWindow() return true } override fun getInfoWindow(marker: Marker?): View? { - if (infoWindow == null) { - infoWindow = LayoutInflater.from(this).inflate(R.layout.popu_map_info, null) - } - val v = infoWindow!! - //反射得到popup里面的控件对象 val wellNameView = v.findViewById(R.id.wellNameView) val wellCodeView = v.findViewById(R.id.wellCodeView) val wellTypeView = v.findViewById(R.id.wellTypeView) @@ -214,6 +214,10 @@ return null } + override fun onInfoWindowClick(marker: Marker?) { + marker?.hideInfoWindow() + } + /** * 此方法不能修改整个 InfoWindow 的背景和边框,无论自定义的样式是什么样,SDK 都会在最外层添加一个默认的边框 * */ diff --git a/app/src/main/java/com/casic/smart/town/sanxi/fragment/HomePageFragment.kt b/app/src/main/java/com/casic/smart/town/sanxi/fragment/HomePageFragment.kt index 19d2e85..397b2bd 100644 --- a/app/src/main/java/com/casic/smart/town/sanxi/fragment/HomePageFragment.kt +++ b/app/src/main/java/com/casic/smart/town/sanxi/fragment/HomePageFragment.kt @@ -2,7 +2,6 @@ import android.graphics.Color import android.os.Bundle -import android.util.Log import android.view.LayoutInflater import android.view.View import android.view.ViewGroup @@ -21,7 +20,6 @@ import com.amap.api.maps.model.MyLocationStyle import com.casic.smart.town.sanxi.R import com.casic.smart.town.sanxi.databinding.FragmentHomeBinding -import com.casic.smart.town.sanxi.extensions.valueToType import com.casic.smart.town.sanxi.model.MapAlarmModel import com.casic.smart.town.sanxi.model.MapDeviceModel import com.casic.smart.town.sanxi.util.ILocationListener @@ -29,12 +27,12 @@ import com.casic.smart.town.sanxi.util.LocationHub import com.casic.smart.town.sanxi.vm.DeviceViewModel import com.pengxh.kt.lite.base.KotlinBaseFragment -import com.pengxh.kt.lite.extensions.toJson import com.pengxh.kt.lite.vm.LoadState class HomePageFragment : KotlinBaseFragment(), AMap.OnMapLoadedListener, - AMap.OnCameraChangeListener, AMap.OnMarkerClickListener, AMap.InfoWindowAdapter { + AMap.OnCameraChangeListener, AMap.OnMarkerClickListener, AMap.InfoWindowAdapter, + AMap.OnInfoWindowClickListener { private val kTag = "HomePageFragment" private lateinit var aMap: AMap @@ -51,7 +49,7 @@ /** * 自定义Marker弹出框 * */ - private var infoWindow: View? = null + private lateinit var v: View override fun initViewBinding( inflater: LayoutInflater, container: ViewGroup? @@ -100,6 +98,8 @@ aMap.addOnMarkerClickListener(this) // 点击marker弹出自定义popup aMap.setInfoWindowAdapter(this) + // 点击popup + aMap.setOnInfoWindowClickListener(this) //显示定位小蓝点 val locationStyle = MyLocationStyle() @@ -135,13 +135,13 @@ //将所有设备信息转化缓存为Marker点 allMarkerOptions.add( MarkerOptions().position(LatLng(latitude, longitude)) - .title(device.deviceName).snippet(device.wellCode) + .title(device.deviceTypeName).snippet(device.wellCode) ) } //移动到指定经纬度 val centerLatLng = LatLng(latitudeList.average(), longitudeList.average()) - val cameraPosition = CameraPosition(centerLatLng, 16f, 0f, 0f) + val cameraPosition = CameraPosition(centerLatLng, 17f, 0f, 0f) val cameraUpdate = CameraUpdateFactory.newCameraPosition(cameraPosition) aMap.animateCamera(cameraUpdate) } @@ -227,59 +227,61 @@ } override fun onMarkerClick(marker: Marker?): Boolean { + val clickedMarker = marker?.snippet.toString() + v = if (clickedMarker.startsWith("GX")) { + LayoutInflater.from(requireContext()).inflate(R.layout.popu_map_device_info, null) + } else { + LayoutInflater.from(requireContext()).inflate(R.layout.popu_map_alarm_info, null) + } + //显示闸井信息 marker?.showInfoWindow() return true } override fun getInfoWindow(marker: Marker?): View? { - if (infoWindow == null) { - infoWindow = LayoutInflater.from(requireContext()).inflate(R.layout.popu_map_info, null) - } - val v = infoWindow!! - - //反射得到popup里面的控件对象 - val wellNameView = v.findViewById(R.id.wellNameView) - val wellCodeView = v.findViewById(R.id.wellCodeView) - val wellTypeView = v.findViewById(R.id.wellTypeView) - val wellStateView = v.findViewById(R.id.wellStateView) - val deepView = v.findViewById(R.id.deepView) - val locationView = v.findViewById(R.id.locationView) - val clickedMarker = marker?.snippet.toString() - Log.d(kTag, clickedMarker) if (clickedMarker.startsWith("GX")) { + val deviceNameView = v.findViewById(R.id.deviceNameView) + val deviceCodeView = v.findViewById(R.id.deviceCodeView) + val deviceTypeView = v.findViewById(R.id.deviceTypeView) + val deptNameView = v.findViewById(R.id.deptNameView) + val updateDataView = v.findViewById(R.id.updateDataView) + val locationView = v.findViewById(R.id.locationView) + //搜设备 for (device in deviceInfoModels) { - if (clickedMarker == device.devcode) { + if (clickedMarker == device.wellCode) { - Log.d(kTag, device.toJson()) - - wellNameView.text = String.format("设备名称: ${device.deviceName}") - wellCodeView.text = String.format("设备编号: ${device.devcode}") - wellTypeView.text = String.format("设备类型: ${device.deviceTypeName}") - wellStateView.text = String.format("权属单位: ${device.deptName}") - deepView.text = String.format("更新时间: ${device.realtimeData}") + deviceNameView.text = String.format("设备名称: ${device.deviceName}") + deviceCodeView.text = String.format("设备编号: ${device.devcode}") + deviceTypeView.text = String.format("设备类型: ${device.deviceTypeName}") + deptNameView.text = String.format("权属单位: ${device.deptName}") + updateDataView.text = String.format("更新时间: ${device.realtimeData}") locationView.text = String.format("详细位置: ${device.position}") - return infoWindow + return v } } } else { //搜报警 + val alarmContentView = v.findViewById(R.id.alarmContentView) + val deviceCodeView = v.findViewById(R.id.deviceCodeView) + val deviceTypeView = v.findViewById(R.id.deviceTypeView) + val alarmDateView = v.findViewById(R.id.alarmDateView) + val locationView = v.findViewById(R.id.locationView) + for (alarm in alarmInfoModels) { if (clickedMarker == alarm.alarmId) { - Log.d(kTag, alarm.toJson()) - wellNameView.text = String.format("报警内容: ${alarm.alarmContent}") - wellCodeView.text = String.format("设备编号: ${alarm.wellCode}") - wellTypeView.text = String.format("设备类型: ${alarm.wellType.valueToType()}") -// wellStateView.text = String.format("布/撤防状态: $bfztName") - deepView.text = String.format("报警时间: ${alarm.alarmTimeDate}") + alarmContentView.text = String.format("报警内容: ${alarm.alarmContent}") + deviceCodeView.text = String.format("设备编号: ${alarm.devcode}") + deviceTypeView.text = String.format("设备类型: ${alarm.deviceType}") + alarmDateView.text = String.format("报警时间: ${alarm.alarmTimeDate}") locationView.text = String.format("详细位置: ${alarm.position}") - return infoWindow + return v } } } @@ -287,6 +289,10 @@ return null } + override fun onInfoWindowClick(marker: Marker?) { + marker?.hideInfoWindow() + } + /** * 此方法不能修改整个 InfoWindow 的背景和边框,无论自定义的样式是什么样,SDK 都会在最外层添加一个默认的边框 * */ diff --git a/app/src/main/java/com/casic/smart/town/sanxi/view/AllWellActivity.kt b/app/src/main/java/com/casic/smart/town/sanxi/view/AllWellActivity.kt index b77a48d..4b1d246 100644 --- a/app/src/main/java/com/casic/smart/town/sanxi/view/AllWellActivity.kt +++ b/app/src/main/java/com/casic/smart/town/sanxi/view/AllWellActivity.kt @@ -27,7 +27,8 @@ import com.pengxh.kt.lite.vm.LoadState class AllWellActivity : KotlinBaseActivity(), AMap.OnMapLoadedListener, - AMap.OnCameraChangeListener, AMap.OnMarkerClickListener, AMap.InfoWindowAdapter { + AMap.OnCameraChangeListener, AMap.OnMarkerClickListener, AMap.InfoWindowAdapter, + AMap.OnInfoWindowClickListener { private lateinit var wellViewModel: WellViewModel private lateinit var aMap: AMap @@ -50,7 +51,7 @@ /** * 自定义Marker弹出框 * */ - private var infoWindow: View? = null + private lateinit var v: View override fun initViewBinding(): ActivityAllWellBinding { return ActivityAllWellBinding.inflate(layoutInflater) @@ -105,7 +106,7 @@ val centerLatLng = LatLng(latitudeList.average(), longitudeList.average()) val cameraPosition = CameraPosition(centerLatLng, 17f, 0f, 0f) val cameraUpdate = CameraUpdateFactory.newCameraPosition(cameraPosition) - aMap.animateCamera(cameraUpdate, 2000, null) + aMap.animateCamera(cameraUpdate) } } } @@ -133,6 +134,8 @@ aMap.addOnMarkerClickListener(this) // 点击marker弹出自定义popup aMap.setInfoWindowAdapter(this) + // 点击popup + aMap.setOnInfoWindowClickListener(this) } override fun onMapLoaded() { @@ -156,7 +159,7 @@ allMarkerOptions.forEach { screenLocation = proj.toScreenLocation(it.position) if (screenLocation.x >= 0 && screenLocation.y >= 0 && screenLocation.x <= dm.widthPixels && screenLocation.y <= dm.heightPixels) { - it.icon(BitmapDescriptorFactory.fromBitmap(BitmapDescriptorFactory.fromResource(R.mipmap.map_pin).bitmap)) + it.icon(BitmapDescriptorFactory.fromBitmap(BitmapDescriptorFactory.fromResource(R.mipmap.map_device).bitmap)) markerOptionsInView.add(it) } } @@ -166,17 +169,14 @@ } override fun onMarkerClick(marker: Marker?): Boolean { + v = LayoutInflater.from(this).inflate(R.layout.popu_map_info, null) + //显示闸井信息 marker?.showInfoWindow() return true } override fun getInfoWindow(marker: Marker?): View? { - if (infoWindow == null) { - infoWindow = LayoutInflater.from(this).inflate(R.layout.popu_map_info, null) - } - val v = infoWindow!! - //反射得到popup里面的控件对象 val wellNameView = v.findViewById(R.id.wellNameView) val wellCodeView = v.findViewById(R.id.wellCodeView) val wellTypeView = v.findViewById(R.id.wellTypeView) @@ -207,6 +207,10 @@ return null } + override fun onInfoWindowClick(marker: Marker?) { + marker?.hideInfoWindow() + } + /** * 此方法不能修改整个 InfoWindow 的背景和边框,无论自定义的样式是什么样,SDK 都会在最外层添加一个默认的边框 * */ diff --git a/app/src/main/java/com/casic/smart/town/sanxi/view/BFWellActivity.kt b/app/src/main/java/com/casic/smart/town/sanxi/view/BFWellActivity.kt index a3f1c6a..686c93b 100644 --- a/app/src/main/java/com/casic/smart/town/sanxi/view/BFWellActivity.kt +++ b/app/src/main/java/com/casic/smart/town/sanxi/view/BFWellActivity.kt @@ -27,7 +27,8 @@ import com.pengxh.kt.lite.vm.LoadState class BFWellActivity : KotlinBaseActivity(), AMap.OnMapLoadedListener, - AMap.OnCameraChangeListener, AMap.OnMarkerClickListener, AMap.InfoWindowAdapter { + AMap.OnCameraChangeListener, AMap.OnMarkerClickListener, AMap.InfoWindowAdapter, + AMap.OnInfoWindowClickListener { private lateinit var wellViewModel: WellViewModel private lateinit var aMap: AMap @@ -50,7 +51,7 @@ /** * 自定义Marker弹出框 * */ - private var infoWindow: View? = null + private lateinit var v: View override fun initViewBinding(): ActivityBfWellBinding { return ActivityBfWellBinding.inflate(layoutInflater) @@ -110,7 +111,7 @@ LatLng(latitudeList.average(), longitudeList.average()) val cameraPosition = CameraPosition(centerLatLng, 17f, 0f, 0f) val cameraUpdate = CameraUpdateFactory.newCameraPosition(cameraPosition) - aMap.animateCamera(cameraUpdate, 2000, null) + aMap.animateCamera(cameraUpdate) } } } @@ -139,6 +140,8 @@ aMap.addOnMarkerClickListener(this) // 点击marker弹出自定义popup aMap.setInfoWindowAdapter(this) + // 点击marker弹出自定义popup + aMap.setInfoWindowAdapter(this) } override fun onMapLoaded() { @@ -162,7 +165,7 @@ allMarkerOptions.forEach { screenLocation = proj.toScreenLocation(it.position) if (screenLocation.x >= 0 && screenLocation.y >= 0 && screenLocation.x <= dm.widthPixels && screenLocation.y <= dm.heightPixels) { - it.icon(BitmapDescriptorFactory.fromBitmap(BitmapDescriptorFactory.fromResource(R.mipmap.map_pin).bitmap)) + it.icon(BitmapDescriptorFactory.fromBitmap(BitmapDescriptorFactory.fromResource(R.mipmap.map_device).bitmap)) markerOptionsInView.add(it) } } @@ -172,17 +175,14 @@ } override fun onMarkerClick(marker: Marker?): Boolean { + v = LayoutInflater.from(this).inflate(R.layout.popu_map_info, null) + //显示闸井信息 marker?.showInfoWindow() return true } override fun getInfoWindow(marker: Marker?): View? { - if (infoWindow == null) { - infoWindow = LayoutInflater.from(this).inflate(R.layout.popu_map_info, null) - } - val v = infoWindow!! - //反射得到popup里面的控件对象 val wellNameView = v.findViewById(R.id.wellNameView) val wellCodeView = v.findViewById(R.id.wellCodeView) val wellTypeView = v.findViewById(R.id.wellTypeView) @@ -214,6 +214,10 @@ return null } + override fun onInfoWindowClick(marker: Marker?) { + marker?.hideInfoWindow() + } + /** * 此方法不能修改整个 InfoWindow 的背景和边框,无论自定义的样式是什么样,SDK 都会在最外层添加一个默认的边框 * */ diff --git a/app/src/main/java/com/casic/smart/town/sanxi/view/CFWellActivity.kt b/app/src/main/java/com/casic/smart/town/sanxi/view/CFWellActivity.kt index f98a065..346e5f0 100644 --- a/app/src/main/java/com/casic/smart/town/sanxi/view/CFWellActivity.kt +++ b/app/src/main/java/com/casic/smart/town/sanxi/view/CFWellActivity.kt @@ -28,7 +28,8 @@ import com.pengxh.kt.lite.vm.LoadState class CFWellActivity : KotlinBaseActivity(), AMap.OnMapLoadedListener, - AMap.OnCameraChangeListener, AMap.OnMarkerClickListener, AMap.InfoWindowAdapter { + AMap.OnCameraChangeListener, AMap.OnMarkerClickListener, AMap.InfoWindowAdapter, + AMap.OnInfoWindowClickListener { private lateinit var wellViewModel: WellViewModel private lateinit var aMap: AMap @@ -51,7 +52,7 @@ /** * 自定义Marker弹出框 * */ - private var infoWindow: View? = null + private lateinit var v: View override fun initViewBinding(): ActivityCfWellBinding { return ActivityCfWellBinding.inflate(layoutInflater) @@ -111,7 +112,7 @@ LatLng(latitudeList.average(), longitudeList.average()) val cameraPosition = CameraPosition(centerLatLng, 17f, 0f, 0f) val cameraUpdate = CameraUpdateFactory.newCameraPosition(cameraPosition) - aMap.animateCamera(cameraUpdate, 2000, null) + aMap.animateCamera(cameraUpdate) } } } @@ -140,6 +141,8 @@ aMap.addOnMarkerClickListener(this) // 点击marker弹出自定义popup aMap.setInfoWindowAdapter(this) + // 点击marker弹出自定义popup + aMap.setInfoWindowAdapter(this) } override fun onMapLoaded() { @@ -163,7 +166,7 @@ allMarkerOptions.forEach { screenLocation = proj.toScreenLocation(it.position) if (screenLocation.x >= 0 && screenLocation.y >= 0 && screenLocation.x <= dm.widthPixels && screenLocation.y <= dm.heightPixels) { - it.icon(BitmapDescriptorFactory.fromBitmap(BitmapDescriptorFactory.fromResource(R.mipmap.map_pin).bitmap)) + it.icon(BitmapDescriptorFactory.fromBitmap(BitmapDescriptorFactory.fromResource(R.mipmap.map_device).bitmap)) markerOptionsInView.add(it) } } @@ -173,17 +176,14 @@ } override fun onMarkerClick(marker: Marker?): Boolean { + v = LayoutInflater.from(this).inflate(R.layout.popu_map_info, null) + //显示闸井信息 marker?.showInfoWindow() return true } override fun getInfoWindow(marker: Marker?): View? { - if (infoWindow == null) { - infoWindow = LayoutInflater.from(this).inflate(R.layout.popu_map_info, null) - } - val v = infoWindow!! - //反射得到popup里面的控件对象 val wellNameView = v.findViewById(R.id.wellNameView) val wellCodeView = v.findViewById(R.id.wellCodeView) val wellTypeView = v.findViewById(R.id.wellTypeView) @@ -215,6 +215,10 @@ return null } + override fun onInfoWindowClick(marker: Marker?) { + marker?.hideInfoWindow() + } + /** * 此方法不能修改整个 InfoWindow 的背景和边框,无论自定义的样式是什么样,SDK 都会在最外层添加一个默认的边框 * */ diff --git a/app/src/main/java/com/casic/smart/town/sanxi/fragment/HomePageFragment.kt b/app/src/main/java/com/casic/smart/town/sanxi/fragment/HomePageFragment.kt index 19d2e85..397b2bd 100644 --- a/app/src/main/java/com/casic/smart/town/sanxi/fragment/HomePageFragment.kt +++ b/app/src/main/java/com/casic/smart/town/sanxi/fragment/HomePageFragment.kt @@ -2,7 +2,6 @@ import android.graphics.Color import android.os.Bundle -import android.util.Log import android.view.LayoutInflater import android.view.View import android.view.ViewGroup @@ -21,7 +20,6 @@ import com.amap.api.maps.model.MyLocationStyle import com.casic.smart.town.sanxi.R import com.casic.smart.town.sanxi.databinding.FragmentHomeBinding -import com.casic.smart.town.sanxi.extensions.valueToType import com.casic.smart.town.sanxi.model.MapAlarmModel import com.casic.smart.town.sanxi.model.MapDeviceModel import com.casic.smart.town.sanxi.util.ILocationListener @@ -29,12 +27,12 @@ import com.casic.smart.town.sanxi.util.LocationHub import com.casic.smart.town.sanxi.vm.DeviceViewModel import com.pengxh.kt.lite.base.KotlinBaseFragment -import com.pengxh.kt.lite.extensions.toJson import com.pengxh.kt.lite.vm.LoadState class HomePageFragment : KotlinBaseFragment(), AMap.OnMapLoadedListener, - AMap.OnCameraChangeListener, AMap.OnMarkerClickListener, AMap.InfoWindowAdapter { + AMap.OnCameraChangeListener, AMap.OnMarkerClickListener, AMap.InfoWindowAdapter, + AMap.OnInfoWindowClickListener { private val kTag = "HomePageFragment" private lateinit var aMap: AMap @@ -51,7 +49,7 @@ /** * 自定义Marker弹出框 * */ - private var infoWindow: View? = null + private lateinit var v: View override fun initViewBinding( inflater: LayoutInflater, container: ViewGroup? @@ -100,6 +98,8 @@ aMap.addOnMarkerClickListener(this) // 点击marker弹出自定义popup aMap.setInfoWindowAdapter(this) + // 点击popup + aMap.setOnInfoWindowClickListener(this) //显示定位小蓝点 val locationStyle = MyLocationStyle() @@ -135,13 +135,13 @@ //将所有设备信息转化缓存为Marker点 allMarkerOptions.add( MarkerOptions().position(LatLng(latitude, longitude)) - .title(device.deviceName).snippet(device.wellCode) + .title(device.deviceTypeName).snippet(device.wellCode) ) } //移动到指定经纬度 val centerLatLng = LatLng(latitudeList.average(), longitudeList.average()) - val cameraPosition = CameraPosition(centerLatLng, 16f, 0f, 0f) + val cameraPosition = CameraPosition(centerLatLng, 17f, 0f, 0f) val cameraUpdate = CameraUpdateFactory.newCameraPosition(cameraPosition) aMap.animateCamera(cameraUpdate) } @@ -227,59 +227,61 @@ } override fun onMarkerClick(marker: Marker?): Boolean { + val clickedMarker = marker?.snippet.toString() + v = if (clickedMarker.startsWith("GX")) { + LayoutInflater.from(requireContext()).inflate(R.layout.popu_map_device_info, null) + } else { + LayoutInflater.from(requireContext()).inflate(R.layout.popu_map_alarm_info, null) + } + //显示闸井信息 marker?.showInfoWindow() return true } override fun getInfoWindow(marker: Marker?): View? { - if (infoWindow == null) { - infoWindow = LayoutInflater.from(requireContext()).inflate(R.layout.popu_map_info, null) - } - val v = infoWindow!! - - //反射得到popup里面的控件对象 - val wellNameView = v.findViewById(R.id.wellNameView) - val wellCodeView = v.findViewById(R.id.wellCodeView) - val wellTypeView = v.findViewById(R.id.wellTypeView) - val wellStateView = v.findViewById(R.id.wellStateView) - val deepView = v.findViewById(R.id.deepView) - val locationView = v.findViewById(R.id.locationView) - val clickedMarker = marker?.snippet.toString() - Log.d(kTag, clickedMarker) if (clickedMarker.startsWith("GX")) { + val deviceNameView = v.findViewById(R.id.deviceNameView) + val deviceCodeView = v.findViewById(R.id.deviceCodeView) + val deviceTypeView = v.findViewById(R.id.deviceTypeView) + val deptNameView = v.findViewById(R.id.deptNameView) + val updateDataView = v.findViewById(R.id.updateDataView) + val locationView = v.findViewById(R.id.locationView) + //搜设备 for (device in deviceInfoModels) { - if (clickedMarker == device.devcode) { + if (clickedMarker == device.wellCode) { - Log.d(kTag, device.toJson()) - - wellNameView.text = String.format("设备名称: ${device.deviceName}") - wellCodeView.text = String.format("设备编号: ${device.devcode}") - wellTypeView.text = String.format("设备类型: ${device.deviceTypeName}") - wellStateView.text = String.format("权属单位: ${device.deptName}") - deepView.text = String.format("更新时间: ${device.realtimeData}") + deviceNameView.text = String.format("设备名称: ${device.deviceName}") + deviceCodeView.text = String.format("设备编号: ${device.devcode}") + deviceTypeView.text = String.format("设备类型: ${device.deviceTypeName}") + deptNameView.text = String.format("权属单位: ${device.deptName}") + updateDataView.text = String.format("更新时间: ${device.realtimeData}") locationView.text = String.format("详细位置: ${device.position}") - return infoWindow + return v } } } else { //搜报警 + val alarmContentView = v.findViewById(R.id.alarmContentView) + val deviceCodeView = v.findViewById(R.id.deviceCodeView) + val deviceTypeView = v.findViewById(R.id.deviceTypeView) + val alarmDateView = v.findViewById(R.id.alarmDateView) + val locationView = v.findViewById(R.id.locationView) + for (alarm in alarmInfoModels) { if (clickedMarker == alarm.alarmId) { - Log.d(kTag, alarm.toJson()) - wellNameView.text = String.format("报警内容: ${alarm.alarmContent}") - wellCodeView.text = String.format("设备编号: ${alarm.wellCode}") - wellTypeView.text = String.format("设备类型: ${alarm.wellType.valueToType()}") -// wellStateView.text = String.format("布/撤防状态: $bfztName") - deepView.text = String.format("报警时间: ${alarm.alarmTimeDate}") + alarmContentView.text = String.format("报警内容: ${alarm.alarmContent}") + deviceCodeView.text = String.format("设备编号: ${alarm.devcode}") + deviceTypeView.text = String.format("设备类型: ${alarm.deviceType}") + alarmDateView.text = String.format("报警时间: ${alarm.alarmTimeDate}") locationView.text = String.format("详细位置: ${alarm.position}") - return infoWindow + return v } } } @@ -287,6 +289,10 @@ return null } + override fun onInfoWindowClick(marker: Marker?) { + marker?.hideInfoWindow() + } + /** * 此方法不能修改整个 InfoWindow 的背景和边框,无论自定义的样式是什么样,SDK 都会在最外层添加一个默认的边框 * */ diff --git a/app/src/main/java/com/casic/smart/town/sanxi/view/AllWellActivity.kt b/app/src/main/java/com/casic/smart/town/sanxi/view/AllWellActivity.kt index b77a48d..4b1d246 100644 --- a/app/src/main/java/com/casic/smart/town/sanxi/view/AllWellActivity.kt +++ b/app/src/main/java/com/casic/smart/town/sanxi/view/AllWellActivity.kt @@ -27,7 +27,8 @@ import com.pengxh.kt.lite.vm.LoadState class AllWellActivity : KotlinBaseActivity(), AMap.OnMapLoadedListener, - AMap.OnCameraChangeListener, AMap.OnMarkerClickListener, AMap.InfoWindowAdapter { + AMap.OnCameraChangeListener, AMap.OnMarkerClickListener, AMap.InfoWindowAdapter, + AMap.OnInfoWindowClickListener { private lateinit var wellViewModel: WellViewModel private lateinit var aMap: AMap @@ -50,7 +51,7 @@ /** * 自定义Marker弹出框 * */ - private var infoWindow: View? = null + private lateinit var v: View override fun initViewBinding(): ActivityAllWellBinding { return ActivityAllWellBinding.inflate(layoutInflater) @@ -105,7 +106,7 @@ val centerLatLng = LatLng(latitudeList.average(), longitudeList.average()) val cameraPosition = CameraPosition(centerLatLng, 17f, 0f, 0f) val cameraUpdate = CameraUpdateFactory.newCameraPosition(cameraPosition) - aMap.animateCamera(cameraUpdate, 2000, null) + aMap.animateCamera(cameraUpdate) } } } @@ -133,6 +134,8 @@ aMap.addOnMarkerClickListener(this) // 点击marker弹出自定义popup aMap.setInfoWindowAdapter(this) + // 点击popup + aMap.setOnInfoWindowClickListener(this) } override fun onMapLoaded() { @@ -156,7 +159,7 @@ allMarkerOptions.forEach { screenLocation = proj.toScreenLocation(it.position) if (screenLocation.x >= 0 && screenLocation.y >= 0 && screenLocation.x <= dm.widthPixels && screenLocation.y <= dm.heightPixels) { - it.icon(BitmapDescriptorFactory.fromBitmap(BitmapDescriptorFactory.fromResource(R.mipmap.map_pin).bitmap)) + it.icon(BitmapDescriptorFactory.fromBitmap(BitmapDescriptorFactory.fromResource(R.mipmap.map_device).bitmap)) markerOptionsInView.add(it) } } @@ -166,17 +169,14 @@ } override fun onMarkerClick(marker: Marker?): Boolean { + v = LayoutInflater.from(this).inflate(R.layout.popu_map_info, null) + //显示闸井信息 marker?.showInfoWindow() return true } override fun getInfoWindow(marker: Marker?): View? { - if (infoWindow == null) { - infoWindow = LayoutInflater.from(this).inflate(R.layout.popu_map_info, null) - } - val v = infoWindow!! - //反射得到popup里面的控件对象 val wellNameView = v.findViewById(R.id.wellNameView) val wellCodeView = v.findViewById(R.id.wellCodeView) val wellTypeView = v.findViewById(R.id.wellTypeView) @@ -207,6 +207,10 @@ return null } + override fun onInfoWindowClick(marker: Marker?) { + marker?.hideInfoWindow() + } + /** * 此方法不能修改整个 InfoWindow 的背景和边框,无论自定义的样式是什么样,SDK 都会在最外层添加一个默认的边框 * */ diff --git a/app/src/main/java/com/casic/smart/town/sanxi/view/BFWellActivity.kt b/app/src/main/java/com/casic/smart/town/sanxi/view/BFWellActivity.kt index a3f1c6a..686c93b 100644 --- a/app/src/main/java/com/casic/smart/town/sanxi/view/BFWellActivity.kt +++ b/app/src/main/java/com/casic/smart/town/sanxi/view/BFWellActivity.kt @@ -27,7 +27,8 @@ import com.pengxh.kt.lite.vm.LoadState class BFWellActivity : KotlinBaseActivity(), AMap.OnMapLoadedListener, - AMap.OnCameraChangeListener, AMap.OnMarkerClickListener, AMap.InfoWindowAdapter { + AMap.OnCameraChangeListener, AMap.OnMarkerClickListener, AMap.InfoWindowAdapter, + AMap.OnInfoWindowClickListener { private lateinit var wellViewModel: WellViewModel private lateinit var aMap: AMap @@ -50,7 +51,7 @@ /** * 自定义Marker弹出框 * */ - private var infoWindow: View? = null + private lateinit var v: View override fun initViewBinding(): ActivityBfWellBinding { return ActivityBfWellBinding.inflate(layoutInflater) @@ -110,7 +111,7 @@ LatLng(latitudeList.average(), longitudeList.average()) val cameraPosition = CameraPosition(centerLatLng, 17f, 0f, 0f) val cameraUpdate = CameraUpdateFactory.newCameraPosition(cameraPosition) - aMap.animateCamera(cameraUpdate, 2000, null) + aMap.animateCamera(cameraUpdate) } } } @@ -139,6 +140,8 @@ aMap.addOnMarkerClickListener(this) // 点击marker弹出自定义popup aMap.setInfoWindowAdapter(this) + // 点击marker弹出自定义popup + aMap.setInfoWindowAdapter(this) } override fun onMapLoaded() { @@ -162,7 +165,7 @@ allMarkerOptions.forEach { screenLocation = proj.toScreenLocation(it.position) if (screenLocation.x >= 0 && screenLocation.y >= 0 && screenLocation.x <= dm.widthPixels && screenLocation.y <= dm.heightPixels) { - it.icon(BitmapDescriptorFactory.fromBitmap(BitmapDescriptorFactory.fromResource(R.mipmap.map_pin).bitmap)) + it.icon(BitmapDescriptorFactory.fromBitmap(BitmapDescriptorFactory.fromResource(R.mipmap.map_device).bitmap)) markerOptionsInView.add(it) } } @@ -172,17 +175,14 @@ } override fun onMarkerClick(marker: Marker?): Boolean { + v = LayoutInflater.from(this).inflate(R.layout.popu_map_info, null) + //显示闸井信息 marker?.showInfoWindow() return true } override fun getInfoWindow(marker: Marker?): View? { - if (infoWindow == null) { - infoWindow = LayoutInflater.from(this).inflate(R.layout.popu_map_info, null) - } - val v = infoWindow!! - //反射得到popup里面的控件对象 val wellNameView = v.findViewById(R.id.wellNameView) val wellCodeView = v.findViewById(R.id.wellCodeView) val wellTypeView = v.findViewById(R.id.wellTypeView) @@ -214,6 +214,10 @@ return null } + override fun onInfoWindowClick(marker: Marker?) { + marker?.hideInfoWindow() + } + /** * 此方法不能修改整个 InfoWindow 的背景和边框,无论自定义的样式是什么样,SDK 都会在最外层添加一个默认的边框 * */ diff --git a/app/src/main/java/com/casic/smart/town/sanxi/view/CFWellActivity.kt b/app/src/main/java/com/casic/smart/town/sanxi/view/CFWellActivity.kt index f98a065..346e5f0 100644 --- a/app/src/main/java/com/casic/smart/town/sanxi/view/CFWellActivity.kt +++ b/app/src/main/java/com/casic/smart/town/sanxi/view/CFWellActivity.kt @@ -28,7 +28,8 @@ import com.pengxh.kt.lite.vm.LoadState class CFWellActivity : KotlinBaseActivity(), AMap.OnMapLoadedListener, - AMap.OnCameraChangeListener, AMap.OnMarkerClickListener, AMap.InfoWindowAdapter { + AMap.OnCameraChangeListener, AMap.OnMarkerClickListener, AMap.InfoWindowAdapter, + AMap.OnInfoWindowClickListener { private lateinit var wellViewModel: WellViewModel private lateinit var aMap: AMap @@ -51,7 +52,7 @@ /** * 自定义Marker弹出框 * */ - private var infoWindow: View? = null + private lateinit var v: View override fun initViewBinding(): ActivityCfWellBinding { return ActivityCfWellBinding.inflate(layoutInflater) @@ -111,7 +112,7 @@ LatLng(latitudeList.average(), longitudeList.average()) val cameraPosition = CameraPosition(centerLatLng, 17f, 0f, 0f) val cameraUpdate = CameraUpdateFactory.newCameraPosition(cameraPosition) - aMap.animateCamera(cameraUpdate, 2000, null) + aMap.animateCamera(cameraUpdate) } } } @@ -140,6 +141,8 @@ aMap.addOnMarkerClickListener(this) // 点击marker弹出自定义popup aMap.setInfoWindowAdapter(this) + // 点击marker弹出自定义popup + aMap.setInfoWindowAdapter(this) } override fun onMapLoaded() { @@ -163,7 +166,7 @@ allMarkerOptions.forEach { screenLocation = proj.toScreenLocation(it.position) if (screenLocation.x >= 0 && screenLocation.y >= 0 && screenLocation.x <= dm.widthPixels && screenLocation.y <= dm.heightPixels) { - it.icon(BitmapDescriptorFactory.fromBitmap(BitmapDescriptorFactory.fromResource(R.mipmap.map_pin).bitmap)) + it.icon(BitmapDescriptorFactory.fromBitmap(BitmapDescriptorFactory.fromResource(R.mipmap.map_device).bitmap)) markerOptionsInView.add(it) } } @@ -173,17 +176,14 @@ } override fun onMarkerClick(marker: Marker?): Boolean { + v = LayoutInflater.from(this).inflate(R.layout.popu_map_info, null) + //显示闸井信息 marker?.showInfoWindow() return true } override fun getInfoWindow(marker: Marker?): View? { - if (infoWindow == null) { - infoWindow = LayoutInflater.from(this).inflate(R.layout.popu_map_info, null) - } - val v = infoWindow!! - //反射得到popup里面的控件对象 val wellNameView = v.findViewById(R.id.wellNameView) val wellCodeView = v.findViewById(R.id.wellCodeView) val wellTypeView = v.findViewById(R.id.wellTypeView) @@ -215,6 +215,10 @@ return null } + override fun onInfoWindowClick(marker: Marker?) { + marker?.hideInfoWindow() + } + /** * 此方法不能修改整个 InfoWindow 的背景和边框,无论自定义的样式是什么样,SDK 都会在最外层添加一个默认的边框 * */ diff --git a/app/src/main/res/layout/popu_map_alarm_info.xml b/app/src/main/res/layout/popu_map_alarm_info.xml new file mode 100644 index 0000000..1e2d654 --- /dev/null +++ b/app/src/main/res/layout/popu_map_alarm_info.xml @@ -0,0 +1,33 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/com/casic/smart/town/sanxi/fragment/HomePageFragment.kt b/app/src/main/java/com/casic/smart/town/sanxi/fragment/HomePageFragment.kt index 19d2e85..397b2bd 100644 --- a/app/src/main/java/com/casic/smart/town/sanxi/fragment/HomePageFragment.kt +++ b/app/src/main/java/com/casic/smart/town/sanxi/fragment/HomePageFragment.kt @@ -2,7 +2,6 @@ import android.graphics.Color import android.os.Bundle -import android.util.Log import android.view.LayoutInflater import android.view.View import android.view.ViewGroup @@ -21,7 +20,6 @@ import com.amap.api.maps.model.MyLocationStyle import com.casic.smart.town.sanxi.R import com.casic.smart.town.sanxi.databinding.FragmentHomeBinding -import com.casic.smart.town.sanxi.extensions.valueToType import com.casic.smart.town.sanxi.model.MapAlarmModel import com.casic.smart.town.sanxi.model.MapDeviceModel import com.casic.smart.town.sanxi.util.ILocationListener @@ -29,12 +27,12 @@ import com.casic.smart.town.sanxi.util.LocationHub import com.casic.smart.town.sanxi.vm.DeviceViewModel import com.pengxh.kt.lite.base.KotlinBaseFragment -import com.pengxh.kt.lite.extensions.toJson import com.pengxh.kt.lite.vm.LoadState class HomePageFragment : KotlinBaseFragment(), AMap.OnMapLoadedListener, - AMap.OnCameraChangeListener, AMap.OnMarkerClickListener, AMap.InfoWindowAdapter { + AMap.OnCameraChangeListener, AMap.OnMarkerClickListener, AMap.InfoWindowAdapter, + AMap.OnInfoWindowClickListener { private val kTag = "HomePageFragment" private lateinit var aMap: AMap @@ -51,7 +49,7 @@ /** * 自定义Marker弹出框 * */ - private var infoWindow: View? = null + private lateinit var v: View override fun initViewBinding( inflater: LayoutInflater, container: ViewGroup? @@ -100,6 +98,8 @@ aMap.addOnMarkerClickListener(this) // 点击marker弹出自定义popup aMap.setInfoWindowAdapter(this) + // 点击popup + aMap.setOnInfoWindowClickListener(this) //显示定位小蓝点 val locationStyle = MyLocationStyle() @@ -135,13 +135,13 @@ //将所有设备信息转化缓存为Marker点 allMarkerOptions.add( MarkerOptions().position(LatLng(latitude, longitude)) - .title(device.deviceName).snippet(device.wellCode) + .title(device.deviceTypeName).snippet(device.wellCode) ) } //移动到指定经纬度 val centerLatLng = LatLng(latitudeList.average(), longitudeList.average()) - val cameraPosition = CameraPosition(centerLatLng, 16f, 0f, 0f) + val cameraPosition = CameraPosition(centerLatLng, 17f, 0f, 0f) val cameraUpdate = CameraUpdateFactory.newCameraPosition(cameraPosition) aMap.animateCamera(cameraUpdate) } @@ -227,59 +227,61 @@ } override fun onMarkerClick(marker: Marker?): Boolean { + val clickedMarker = marker?.snippet.toString() + v = if (clickedMarker.startsWith("GX")) { + LayoutInflater.from(requireContext()).inflate(R.layout.popu_map_device_info, null) + } else { + LayoutInflater.from(requireContext()).inflate(R.layout.popu_map_alarm_info, null) + } + //显示闸井信息 marker?.showInfoWindow() return true } override fun getInfoWindow(marker: Marker?): View? { - if (infoWindow == null) { - infoWindow = LayoutInflater.from(requireContext()).inflate(R.layout.popu_map_info, null) - } - val v = infoWindow!! - - //反射得到popup里面的控件对象 - val wellNameView = v.findViewById(R.id.wellNameView) - val wellCodeView = v.findViewById(R.id.wellCodeView) - val wellTypeView = v.findViewById(R.id.wellTypeView) - val wellStateView = v.findViewById(R.id.wellStateView) - val deepView = v.findViewById(R.id.deepView) - val locationView = v.findViewById(R.id.locationView) - val clickedMarker = marker?.snippet.toString() - Log.d(kTag, clickedMarker) if (clickedMarker.startsWith("GX")) { + val deviceNameView = v.findViewById(R.id.deviceNameView) + val deviceCodeView = v.findViewById(R.id.deviceCodeView) + val deviceTypeView = v.findViewById(R.id.deviceTypeView) + val deptNameView = v.findViewById(R.id.deptNameView) + val updateDataView = v.findViewById(R.id.updateDataView) + val locationView = v.findViewById(R.id.locationView) + //搜设备 for (device in deviceInfoModels) { - if (clickedMarker == device.devcode) { + if (clickedMarker == device.wellCode) { - Log.d(kTag, device.toJson()) - - wellNameView.text = String.format("设备名称: ${device.deviceName}") - wellCodeView.text = String.format("设备编号: ${device.devcode}") - wellTypeView.text = String.format("设备类型: ${device.deviceTypeName}") - wellStateView.text = String.format("权属单位: ${device.deptName}") - deepView.text = String.format("更新时间: ${device.realtimeData}") + deviceNameView.text = String.format("设备名称: ${device.deviceName}") + deviceCodeView.text = String.format("设备编号: ${device.devcode}") + deviceTypeView.text = String.format("设备类型: ${device.deviceTypeName}") + deptNameView.text = String.format("权属单位: ${device.deptName}") + updateDataView.text = String.format("更新时间: ${device.realtimeData}") locationView.text = String.format("详细位置: ${device.position}") - return infoWindow + return v } } } else { //搜报警 + val alarmContentView = v.findViewById(R.id.alarmContentView) + val deviceCodeView = v.findViewById(R.id.deviceCodeView) + val deviceTypeView = v.findViewById(R.id.deviceTypeView) + val alarmDateView = v.findViewById(R.id.alarmDateView) + val locationView = v.findViewById(R.id.locationView) + for (alarm in alarmInfoModels) { if (clickedMarker == alarm.alarmId) { - Log.d(kTag, alarm.toJson()) - wellNameView.text = String.format("报警内容: ${alarm.alarmContent}") - wellCodeView.text = String.format("设备编号: ${alarm.wellCode}") - wellTypeView.text = String.format("设备类型: ${alarm.wellType.valueToType()}") -// wellStateView.text = String.format("布/撤防状态: $bfztName") - deepView.text = String.format("报警时间: ${alarm.alarmTimeDate}") + alarmContentView.text = String.format("报警内容: ${alarm.alarmContent}") + deviceCodeView.text = String.format("设备编号: ${alarm.devcode}") + deviceTypeView.text = String.format("设备类型: ${alarm.deviceType}") + alarmDateView.text = String.format("报警时间: ${alarm.alarmTimeDate}") locationView.text = String.format("详细位置: ${alarm.position}") - return infoWindow + return v } } } @@ -287,6 +289,10 @@ return null } + override fun onInfoWindowClick(marker: Marker?) { + marker?.hideInfoWindow() + } + /** * 此方法不能修改整个 InfoWindow 的背景和边框,无论自定义的样式是什么样,SDK 都会在最外层添加一个默认的边框 * */ diff --git a/app/src/main/java/com/casic/smart/town/sanxi/view/AllWellActivity.kt b/app/src/main/java/com/casic/smart/town/sanxi/view/AllWellActivity.kt index b77a48d..4b1d246 100644 --- a/app/src/main/java/com/casic/smart/town/sanxi/view/AllWellActivity.kt +++ b/app/src/main/java/com/casic/smart/town/sanxi/view/AllWellActivity.kt @@ -27,7 +27,8 @@ import com.pengxh.kt.lite.vm.LoadState class AllWellActivity : KotlinBaseActivity(), AMap.OnMapLoadedListener, - AMap.OnCameraChangeListener, AMap.OnMarkerClickListener, AMap.InfoWindowAdapter { + AMap.OnCameraChangeListener, AMap.OnMarkerClickListener, AMap.InfoWindowAdapter, + AMap.OnInfoWindowClickListener { private lateinit var wellViewModel: WellViewModel private lateinit var aMap: AMap @@ -50,7 +51,7 @@ /** * 自定义Marker弹出框 * */ - private var infoWindow: View? = null + private lateinit var v: View override fun initViewBinding(): ActivityAllWellBinding { return ActivityAllWellBinding.inflate(layoutInflater) @@ -105,7 +106,7 @@ val centerLatLng = LatLng(latitudeList.average(), longitudeList.average()) val cameraPosition = CameraPosition(centerLatLng, 17f, 0f, 0f) val cameraUpdate = CameraUpdateFactory.newCameraPosition(cameraPosition) - aMap.animateCamera(cameraUpdate, 2000, null) + aMap.animateCamera(cameraUpdate) } } } @@ -133,6 +134,8 @@ aMap.addOnMarkerClickListener(this) // 点击marker弹出自定义popup aMap.setInfoWindowAdapter(this) + // 点击popup + aMap.setOnInfoWindowClickListener(this) } override fun onMapLoaded() { @@ -156,7 +159,7 @@ allMarkerOptions.forEach { screenLocation = proj.toScreenLocation(it.position) if (screenLocation.x >= 0 && screenLocation.y >= 0 && screenLocation.x <= dm.widthPixels && screenLocation.y <= dm.heightPixels) { - it.icon(BitmapDescriptorFactory.fromBitmap(BitmapDescriptorFactory.fromResource(R.mipmap.map_pin).bitmap)) + it.icon(BitmapDescriptorFactory.fromBitmap(BitmapDescriptorFactory.fromResource(R.mipmap.map_device).bitmap)) markerOptionsInView.add(it) } } @@ -166,17 +169,14 @@ } override fun onMarkerClick(marker: Marker?): Boolean { + v = LayoutInflater.from(this).inflate(R.layout.popu_map_info, null) + //显示闸井信息 marker?.showInfoWindow() return true } override fun getInfoWindow(marker: Marker?): View? { - if (infoWindow == null) { - infoWindow = LayoutInflater.from(this).inflate(R.layout.popu_map_info, null) - } - val v = infoWindow!! - //反射得到popup里面的控件对象 val wellNameView = v.findViewById(R.id.wellNameView) val wellCodeView = v.findViewById(R.id.wellCodeView) val wellTypeView = v.findViewById(R.id.wellTypeView) @@ -207,6 +207,10 @@ return null } + override fun onInfoWindowClick(marker: Marker?) { + marker?.hideInfoWindow() + } + /** * 此方法不能修改整个 InfoWindow 的背景和边框,无论自定义的样式是什么样,SDK 都会在最外层添加一个默认的边框 * */ diff --git a/app/src/main/java/com/casic/smart/town/sanxi/view/BFWellActivity.kt b/app/src/main/java/com/casic/smart/town/sanxi/view/BFWellActivity.kt index a3f1c6a..686c93b 100644 --- a/app/src/main/java/com/casic/smart/town/sanxi/view/BFWellActivity.kt +++ b/app/src/main/java/com/casic/smart/town/sanxi/view/BFWellActivity.kt @@ -27,7 +27,8 @@ import com.pengxh.kt.lite.vm.LoadState class BFWellActivity : KotlinBaseActivity(), AMap.OnMapLoadedListener, - AMap.OnCameraChangeListener, AMap.OnMarkerClickListener, AMap.InfoWindowAdapter { + AMap.OnCameraChangeListener, AMap.OnMarkerClickListener, AMap.InfoWindowAdapter, + AMap.OnInfoWindowClickListener { private lateinit var wellViewModel: WellViewModel private lateinit var aMap: AMap @@ -50,7 +51,7 @@ /** * 自定义Marker弹出框 * */ - private var infoWindow: View? = null + private lateinit var v: View override fun initViewBinding(): ActivityBfWellBinding { return ActivityBfWellBinding.inflate(layoutInflater) @@ -110,7 +111,7 @@ LatLng(latitudeList.average(), longitudeList.average()) val cameraPosition = CameraPosition(centerLatLng, 17f, 0f, 0f) val cameraUpdate = CameraUpdateFactory.newCameraPosition(cameraPosition) - aMap.animateCamera(cameraUpdate, 2000, null) + aMap.animateCamera(cameraUpdate) } } } @@ -139,6 +140,8 @@ aMap.addOnMarkerClickListener(this) // 点击marker弹出自定义popup aMap.setInfoWindowAdapter(this) + // 点击marker弹出自定义popup + aMap.setInfoWindowAdapter(this) } override fun onMapLoaded() { @@ -162,7 +165,7 @@ allMarkerOptions.forEach { screenLocation = proj.toScreenLocation(it.position) if (screenLocation.x >= 0 && screenLocation.y >= 0 && screenLocation.x <= dm.widthPixels && screenLocation.y <= dm.heightPixels) { - it.icon(BitmapDescriptorFactory.fromBitmap(BitmapDescriptorFactory.fromResource(R.mipmap.map_pin).bitmap)) + it.icon(BitmapDescriptorFactory.fromBitmap(BitmapDescriptorFactory.fromResource(R.mipmap.map_device).bitmap)) markerOptionsInView.add(it) } } @@ -172,17 +175,14 @@ } override fun onMarkerClick(marker: Marker?): Boolean { + v = LayoutInflater.from(this).inflate(R.layout.popu_map_info, null) + //显示闸井信息 marker?.showInfoWindow() return true } override fun getInfoWindow(marker: Marker?): View? { - if (infoWindow == null) { - infoWindow = LayoutInflater.from(this).inflate(R.layout.popu_map_info, null) - } - val v = infoWindow!! - //反射得到popup里面的控件对象 val wellNameView = v.findViewById(R.id.wellNameView) val wellCodeView = v.findViewById(R.id.wellCodeView) val wellTypeView = v.findViewById(R.id.wellTypeView) @@ -214,6 +214,10 @@ return null } + override fun onInfoWindowClick(marker: Marker?) { + marker?.hideInfoWindow() + } + /** * 此方法不能修改整个 InfoWindow 的背景和边框,无论自定义的样式是什么样,SDK 都会在最外层添加一个默认的边框 * */ diff --git a/app/src/main/java/com/casic/smart/town/sanxi/view/CFWellActivity.kt b/app/src/main/java/com/casic/smart/town/sanxi/view/CFWellActivity.kt index f98a065..346e5f0 100644 --- a/app/src/main/java/com/casic/smart/town/sanxi/view/CFWellActivity.kt +++ b/app/src/main/java/com/casic/smart/town/sanxi/view/CFWellActivity.kt @@ -28,7 +28,8 @@ import com.pengxh.kt.lite.vm.LoadState class CFWellActivity : KotlinBaseActivity(), AMap.OnMapLoadedListener, - AMap.OnCameraChangeListener, AMap.OnMarkerClickListener, AMap.InfoWindowAdapter { + AMap.OnCameraChangeListener, AMap.OnMarkerClickListener, AMap.InfoWindowAdapter, + AMap.OnInfoWindowClickListener { private lateinit var wellViewModel: WellViewModel private lateinit var aMap: AMap @@ -51,7 +52,7 @@ /** * 自定义Marker弹出框 * */ - private var infoWindow: View? = null + private lateinit var v: View override fun initViewBinding(): ActivityCfWellBinding { return ActivityCfWellBinding.inflate(layoutInflater) @@ -111,7 +112,7 @@ LatLng(latitudeList.average(), longitudeList.average()) val cameraPosition = CameraPosition(centerLatLng, 17f, 0f, 0f) val cameraUpdate = CameraUpdateFactory.newCameraPosition(cameraPosition) - aMap.animateCamera(cameraUpdate, 2000, null) + aMap.animateCamera(cameraUpdate) } } } @@ -140,6 +141,8 @@ aMap.addOnMarkerClickListener(this) // 点击marker弹出自定义popup aMap.setInfoWindowAdapter(this) + // 点击marker弹出自定义popup + aMap.setInfoWindowAdapter(this) } override fun onMapLoaded() { @@ -163,7 +166,7 @@ allMarkerOptions.forEach { screenLocation = proj.toScreenLocation(it.position) if (screenLocation.x >= 0 && screenLocation.y >= 0 && screenLocation.x <= dm.widthPixels && screenLocation.y <= dm.heightPixels) { - it.icon(BitmapDescriptorFactory.fromBitmap(BitmapDescriptorFactory.fromResource(R.mipmap.map_pin).bitmap)) + it.icon(BitmapDescriptorFactory.fromBitmap(BitmapDescriptorFactory.fromResource(R.mipmap.map_device).bitmap)) markerOptionsInView.add(it) } } @@ -173,17 +176,14 @@ } override fun onMarkerClick(marker: Marker?): Boolean { + v = LayoutInflater.from(this).inflate(R.layout.popu_map_info, null) + //显示闸井信息 marker?.showInfoWindow() return true } override fun getInfoWindow(marker: Marker?): View? { - if (infoWindow == null) { - infoWindow = LayoutInflater.from(this).inflate(R.layout.popu_map_info, null) - } - val v = infoWindow!! - //反射得到popup里面的控件对象 val wellNameView = v.findViewById(R.id.wellNameView) val wellCodeView = v.findViewById(R.id.wellCodeView) val wellTypeView = v.findViewById(R.id.wellTypeView) @@ -215,6 +215,10 @@ return null } + override fun onInfoWindowClick(marker: Marker?) { + marker?.hideInfoWindow() + } + /** * 此方法不能修改整个 InfoWindow 的背景和边框,无论自定义的样式是什么样,SDK 都会在最外层添加一个默认的边框 * */ diff --git a/app/src/main/res/layout/popu_map_alarm_info.xml b/app/src/main/res/layout/popu_map_alarm_info.xml new file mode 100644 index 0000000..1e2d654 --- /dev/null +++ b/app/src/main/res/layout/popu_map_alarm_info.xml @@ -0,0 +1,33 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/popu_map_device_info.xml b/app/src/main/res/layout/popu_map_device_info.xml new file mode 100644 index 0000000..4b13c59 --- /dev/null +++ b/app/src/main/res/layout/popu_map_device_info.xml @@ -0,0 +1,38 @@ + + + + + + + + + + + + + + + \ No newline at end of file