diff --git a/app/src/main/java/com/casic/app/smartwell/fragment/HomePageHaveClusterFragment.kt b/app/src/main/java/com/casic/app/smartwell/fragment/HomePageHaveClusterFragment.kt index 06bd542..b1b0d6e 100644 --- a/app/src/main/java/com/casic/app/smartwell/fragment/HomePageHaveClusterFragment.kt +++ b/app/src/main/java/com/casic/app/smartwell/fragment/HomePageHaveClusterFragment.kt @@ -4,7 +4,6 @@ import android.graphics.drawable.BitmapDrawable import android.graphics.drawable.Drawable import android.os.Bundle -import android.util.Log import android.view.LayoutInflater import android.view.ViewGroup import androidx.lifecycle.ViewModelProvider @@ -117,10 +116,8 @@ lineViewModel.lineResult.observe(this) { if (it.code == 200) { //点太多,必须采用协程(线程也行) - it.data.rows.forEach { dot -> - if (dot.startLatitudeGd.isNullOrBlank() || dot.startLongitudeGd.isNullOrBlank()) { - Log.d(kTag, "initOnCreate => ${dot.pipelineName}起点经纬度为空") - } else { + it.data.forEach { dot -> + if (!dot.startLatitudeGd.isNullOrBlank() && !dot.startLongitudeGd.isNullOrBlank()) { if (CoordinateConverter.isAMapDataAvailable( dot.startLatitudeGd.toDouble(), dot.startLongitudeGd.toDouble() ) @@ -141,7 +138,7 @@ latLngPoints.add(endLatLng) val options = PolylineOptions().addAll(latLngPoints) - aMap.addPolyline(options.width(10f).color(Color.RED)) + aMap.addPolyline(options.width(5f).color(Color.RED)) } } } @@ -175,7 +172,7 @@ //计算所有点的中心点位置 val centerLatLng = LatLng(latitudeList.average(), longitudeList.average()) //移动到指定经纬度 - val cameraPosition = CameraPosition(centerLatLng, 16f, 0f, 0f) + val cameraPosition = CameraPosition(centerLatLng, 12f, 0f, 0f) val cameraUpdate = CameraUpdateFactory.newCameraPosition(cameraPosition) aMap.animateCamera(cameraUpdate, 1500, null) @@ -294,7 +291,7 @@ clusterOverlay = ClusterOverlay(requireContext(), aMap, clusterItems, regionRadius) clusterOverlay?.setClusterRender { clusterNum -> //聚合圆半径 - val radius = 100.dp2px(requireContext()) + val radius = 80.dp2px(requireContext()) if (clusterNum == 0) { var bitmapDrawable = backDrawables[0] if (bitmapDrawable == null) { diff --git a/app/src/main/java/com/casic/app/smartwell/fragment/HomePageHaveClusterFragment.kt b/app/src/main/java/com/casic/app/smartwell/fragment/HomePageHaveClusterFragment.kt index 06bd542..b1b0d6e 100644 --- a/app/src/main/java/com/casic/app/smartwell/fragment/HomePageHaveClusterFragment.kt +++ b/app/src/main/java/com/casic/app/smartwell/fragment/HomePageHaveClusterFragment.kt @@ -4,7 +4,6 @@ import android.graphics.drawable.BitmapDrawable import android.graphics.drawable.Drawable import android.os.Bundle -import android.util.Log import android.view.LayoutInflater import android.view.ViewGroup import androidx.lifecycle.ViewModelProvider @@ -117,10 +116,8 @@ lineViewModel.lineResult.observe(this) { if (it.code == 200) { //点太多,必须采用协程(线程也行) - it.data.rows.forEach { dot -> - if (dot.startLatitudeGd.isNullOrBlank() || dot.startLongitudeGd.isNullOrBlank()) { - Log.d(kTag, "initOnCreate => ${dot.pipelineName}起点经纬度为空") - } else { + it.data.forEach { dot -> + if (!dot.startLatitudeGd.isNullOrBlank() && !dot.startLongitudeGd.isNullOrBlank()) { if (CoordinateConverter.isAMapDataAvailable( dot.startLatitudeGd.toDouble(), dot.startLongitudeGd.toDouble() ) @@ -141,7 +138,7 @@ latLngPoints.add(endLatLng) val options = PolylineOptions().addAll(latLngPoints) - aMap.addPolyline(options.width(10f).color(Color.RED)) + aMap.addPolyline(options.width(5f).color(Color.RED)) } } } @@ -175,7 +172,7 @@ //计算所有点的中心点位置 val centerLatLng = LatLng(latitudeList.average(), longitudeList.average()) //移动到指定经纬度 - val cameraPosition = CameraPosition(centerLatLng, 16f, 0f, 0f) + val cameraPosition = CameraPosition(centerLatLng, 12f, 0f, 0f) val cameraUpdate = CameraUpdateFactory.newCameraPosition(cameraPosition) aMap.animateCamera(cameraUpdate, 1500, null) @@ -294,7 +291,7 @@ clusterOverlay = ClusterOverlay(requireContext(), aMap, clusterItems, regionRadius) clusterOverlay?.setClusterRender { clusterNum -> //聚合圆半径 - val radius = 100.dp2px(requireContext()) + val radius = 80.dp2px(requireContext()) if (clusterNum == 0) { var bitmapDrawable = backDrawables[0] if (bitmapDrawable == null) { diff --git a/app/src/main/java/com/casic/app/smartwell/fragment/HomePageNoClusterFragment.kt b/app/src/main/java/com/casic/app/smartwell/fragment/HomePageNoClusterFragment.kt index bfa7a57..67ccf3a 100644 --- a/app/src/main/java/com/casic/app/smartwell/fragment/HomePageNoClusterFragment.kt +++ b/app/src/main/java/com/casic/app/smartwell/fragment/HomePageNoClusterFragment.kt @@ -1,22 +1,22 @@ package com.casic.app.smartwell.fragment -import android.graphics.Point +import android.graphics.Color import android.os.Bundle -import android.os.CountDownTimer import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import android.widget.TextView import androidx.lifecycle.ViewModelProvider +import androidx.lifecycle.lifecycleScope 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 import com.amap.api.maps.model.Marker import com.amap.api.maps.model.MarkerOptions +import com.amap.api.maps.model.PolylineOptions import com.casic.app.smartwell.R import com.casic.app.smartwell.databinding.FragmentHomeBinding import com.casic.app.smartwell.extensions.initImmersionBar @@ -30,15 +30,19 @@ import com.casic.app.smartwell.view.WellManagementActivity import com.casic.app.smartwell.view.WellOperationActivity import com.casic.app.smartwell.vm.OrderViewModel +import com.casic.app.smartwell.vm.PipelineViewModel import com.casic.app.smartwell.vm.WellViewModel import com.pengxh.kt.lite.adapter.NormalRecyclerAdapter import com.pengxh.kt.lite.adapter.ViewHolder import com.pengxh.kt.lite.base.KotlinBaseFragment import com.pengxh.kt.lite.extensions.navigatePageTo import com.pengxh.kt.lite.extensions.show +import com.pengxh.kt.lite.utils.LoadState import com.pengxh.kt.lite.utils.LoadingDialogHub import com.pengxh.kt.lite.widget.EasyPopupWindow import com.pengxh.kt.lite.widget.dialog.AlertControlDialog +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.launch /** * 地图点位不带聚合效果 @@ -51,19 +55,10 @@ private val easyPopupWindow by lazy { EasyPopupWindow(requireContext()) } private lateinit var wellViewModel: WellViewModel private lateinit var orderViewModel: OrderViewModel + private lateinit var lineViewModel: PipelineViewModel private lateinit var aMap: AMap /** - * 所有的marker - */ - private var allMarkerOptions: MutableList = ArrayList() - - /** - * 视野内的marker - */ - private var markerOptionsInView: MutableList = ArrayList() - - /** * 自定义Marker弹出框 * */ private lateinit var v: View @@ -105,20 +100,56 @@ } }) - //初始化vm - wellViewModel = ViewModelProvider(this)[WellViewModel::class.java] - orderViewModel = ViewModelProvider(this)[OrderViewModel::class.java] - //地图初始化 initMap(savedInstanceState) - //获取所有窨井数据 - httpCountDownTimer.start() - LoadingDialogHub.show(requireActivity(), "数据加载中,请稍后...") + //初始化vm + wellViewModel = ViewModelProvider(this)[WellViewModel::class.java] + orderViewModel = ViewModelProvider(this)[OrderViewModel::class.java] + lineViewModel = ViewModelProvider(this)[PipelineViewModel::class.java] + + //获取管线数据 + lineViewModel.getPipeline() + lineViewModel.lineResult.observe(this) { + if (it.code == 200) { + //点太多,必须采用协程(线程也行) + it.data.forEach { dot -> + if (!dot.startLatitudeGd.isNullOrBlank() && !dot.startLongitudeGd.isNullOrBlank()) { + if (CoordinateConverter.isAMapDataAvailable( + dot.startLatitudeGd.toDouble(), dot.startLongitudeGd.toDouble() + ) + ) { + //瞄点画线 + val latLngPoints = ArrayList() + + val startLatLng = LatLng( + dot.startLatitudeGd.toDouble(), + dot.startLongitudeGd.toDouble() + ) + + val endLatLng = LatLng( + dot.endLatitudeGd.toDouble(), + dot.endLongitudeGd.toDouble() + ) + latLngPoints.add(startLatLng) + latLngPoints.add(endLatLng) + val options = PolylineOptions().addAll(latLngPoints) + + aMap.addPolyline(options.width(5f).color(Color.RED)) + } + } + } + } + } + //获取所有窨井数据 wellViewModel.getWellList() wellViewModel.totalWellModel.observe(this) { if (it.code == 200) { + /** + * 所有的marker + */ + val allMarkerOptions = ArrayList() val latitudeList: MutableList = ArrayList() val longitudeList: MutableList = ArrayList() it.data?.forEach { well -> @@ -136,33 +167,28 @@ longitudeList.add(longitude) //将所有设备信息转化缓存为Marker点 allMarkerOptions.add( - MarkerOptions().position(LatLng(latitude, longitude)) - .title(well.wellTypeName).snippet(well.wellName) + MarkerOptions() + .position(LatLng(latitude, longitude)) + .title(well.wellTypeName) + .snippet(well.wellName) ) } } } -// LocationHelper.obtainCurrentLocation(requireContext(), object : ILocationListener { -// override fun onAMapLocationGet(aMapLocation: AMapLocation?) { -// if (aMapLocation != null) { -// val centerLatLng = LatLng(aMapLocation.latitude, aMapLocation.longitude) -// //移动到指定经纬度 -// val cameraPosition = CameraPosition(centerLatLng, 12f, 0f, 0f) -// val cameraUpdate = CameraUpdateFactory.newCameraPosition(cameraPosition) -// aMap.animateCamera(cameraUpdate, 1500, null) -// } -// } -// }, false) //计算所有点的中心点位置 val centerLatLng = LatLng(latitudeList.average(), longitudeList.average()) //移动到指定经纬度 - val cameraPosition = CameraPosition(centerLatLng, 16f, 0f, 0f) + val cameraPosition = CameraPosition(centerLatLng, 14f, 0f, 0f) val cameraUpdate = CameraUpdateFactory.newCameraPosition(cameraPosition) aMap.animateCamera(cameraUpdate, 1500, null) - //显示点数据 - displayWellOnMap() + //采用协程显示点数据 + lifecycleScope.launch(Dispatchers.IO) { + allMarkerOptions.forEach { marker -> + aMap.addMarker(marker) + } + } } } @@ -252,50 +278,23 @@ } override fun observeRequestState() { + wellViewModel.loadState.observe(this) { + when (it) { + is LoadState.Loading -> LoadingDialogHub.show( + requireActivity(), "数据加载中,请稍后..." + ) + else -> LoadingDialogHub.dismiss() + } + } } override fun onCameraChange(p0: CameraPosition?) { } - /** - * http请求计时器 - * */ - private val httpCountDownTimer = object : CountDownTimer(15 * 1000, 1000) { - override fun onFinish() { - "请求服务器超时,请退出后重试".show(requireContext()) - LoadingDialogHub.dismiss() - } - - override fun onTick(millisUntilFinished: Long) { - - } - } - - //获取视野内的marker 根据聚合算法合成自定义的marker 显示视野内的marker override fun onCameraChangeFinish(p0: CameraPosition?) { - //地图缩放之后显示聚合点数据 - LoadingDialogHub.dismiss() - httpCountDownTimer.cancel() - } - private fun displayWellOnMap() { - val proj = aMap.projection - val dm = resources.displayMetrics - var screenLocation: Point - markerOptionsInView.clear() - // 获取在当前视野内的marker - 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.well_location).bitmap)) - markerOptionsInView.add(it) - } - } - markerOptionsInView.forEach { - aMap.addMarker(it) - } } override fun onMarkerClick(marker: Marker?): Boolean { @@ -316,9 +315,9 @@ val locationView = v.findViewById(R.id.locationView) //绑定数据 - val clickedLatLng = marker?.position!! + val clicked = marker?.position!! wellModels.forEach { well -> - if (clickedLatLng.latitude == well.latGaode!!.toDouble() && clickedLatLng.longitude == well.lngGaode!!.toDouble()) { + if (clicked.latitude == well.latGaode!!.toDouble() && clicked.longitude == well.lngGaode!!.toDouble()) { wellNameView.text = String.format("点位名称: ${well.wellName}") wellCodeView.text = String.format("点位编号: ${well.wellCode}") wellTypeView.text = String.format("点位类型: ${well.wellType.valueToType()}") @@ -340,8 +339,8 @@ * */ override fun getInfoContents(p0: Marker?): View? = null - override fun onInfoWindowClick(p0: Marker?) { - p0?.apply { + override fun onInfoWindowClick(marker: Marker?) { + marker?.apply { AlertControlDialog.Builder().setContext(requireContext()).setTitle("操作提示") .setMessage("确定要前往吗").setNegativeButton("取消").setPositiveButton("确定") .setOnDialogButtonClickListener(object : diff --git a/app/src/main/java/com/casic/app/smartwell/fragment/HomePageHaveClusterFragment.kt b/app/src/main/java/com/casic/app/smartwell/fragment/HomePageHaveClusterFragment.kt index 06bd542..b1b0d6e 100644 --- a/app/src/main/java/com/casic/app/smartwell/fragment/HomePageHaveClusterFragment.kt +++ b/app/src/main/java/com/casic/app/smartwell/fragment/HomePageHaveClusterFragment.kt @@ -4,7 +4,6 @@ import android.graphics.drawable.BitmapDrawable import android.graphics.drawable.Drawable import android.os.Bundle -import android.util.Log import android.view.LayoutInflater import android.view.ViewGroup import androidx.lifecycle.ViewModelProvider @@ -117,10 +116,8 @@ lineViewModel.lineResult.observe(this) { if (it.code == 200) { //点太多,必须采用协程(线程也行) - it.data.rows.forEach { dot -> - if (dot.startLatitudeGd.isNullOrBlank() || dot.startLongitudeGd.isNullOrBlank()) { - Log.d(kTag, "initOnCreate => ${dot.pipelineName}起点经纬度为空") - } else { + it.data.forEach { dot -> + if (!dot.startLatitudeGd.isNullOrBlank() && !dot.startLongitudeGd.isNullOrBlank()) { if (CoordinateConverter.isAMapDataAvailable( dot.startLatitudeGd.toDouble(), dot.startLongitudeGd.toDouble() ) @@ -141,7 +138,7 @@ latLngPoints.add(endLatLng) val options = PolylineOptions().addAll(latLngPoints) - aMap.addPolyline(options.width(10f).color(Color.RED)) + aMap.addPolyline(options.width(5f).color(Color.RED)) } } } @@ -175,7 +172,7 @@ //计算所有点的中心点位置 val centerLatLng = LatLng(latitudeList.average(), longitudeList.average()) //移动到指定经纬度 - val cameraPosition = CameraPosition(centerLatLng, 16f, 0f, 0f) + val cameraPosition = CameraPosition(centerLatLng, 12f, 0f, 0f) val cameraUpdate = CameraUpdateFactory.newCameraPosition(cameraPosition) aMap.animateCamera(cameraUpdate, 1500, null) @@ -294,7 +291,7 @@ clusterOverlay = ClusterOverlay(requireContext(), aMap, clusterItems, regionRadius) clusterOverlay?.setClusterRender { clusterNum -> //聚合圆半径 - val radius = 100.dp2px(requireContext()) + val radius = 80.dp2px(requireContext()) if (clusterNum == 0) { var bitmapDrawable = backDrawables[0] if (bitmapDrawable == null) { diff --git a/app/src/main/java/com/casic/app/smartwell/fragment/HomePageNoClusterFragment.kt b/app/src/main/java/com/casic/app/smartwell/fragment/HomePageNoClusterFragment.kt index bfa7a57..67ccf3a 100644 --- a/app/src/main/java/com/casic/app/smartwell/fragment/HomePageNoClusterFragment.kt +++ b/app/src/main/java/com/casic/app/smartwell/fragment/HomePageNoClusterFragment.kt @@ -1,22 +1,22 @@ package com.casic.app.smartwell.fragment -import android.graphics.Point +import android.graphics.Color import android.os.Bundle -import android.os.CountDownTimer import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import android.widget.TextView import androidx.lifecycle.ViewModelProvider +import androidx.lifecycle.lifecycleScope 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 import com.amap.api.maps.model.Marker import com.amap.api.maps.model.MarkerOptions +import com.amap.api.maps.model.PolylineOptions import com.casic.app.smartwell.R import com.casic.app.smartwell.databinding.FragmentHomeBinding import com.casic.app.smartwell.extensions.initImmersionBar @@ -30,15 +30,19 @@ import com.casic.app.smartwell.view.WellManagementActivity import com.casic.app.smartwell.view.WellOperationActivity import com.casic.app.smartwell.vm.OrderViewModel +import com.casic.app.smartwell.vm.PipelineViewModel import com.casic.app.smartwell.vm.WellViewModel import com.pengxh.kt.lite.adapter.NormalRecyclerAdapter import com.pengxh.kt.lite.adapter.ViewHolder import com.pengxh.kt.lite.base.KotlinBaseFragment import com.pengxh.kt.lite.extensions.navigatePageTo import com.pengxh.kt.lite.extensions.show +import com.pengxh.kt.lite.utils.LoadState import com.pengxh.kt.lite.utils.LoadingDialogHub import com.pengxh.kt.lite.widget.EasyPopupWindow import com.pengxh.kt.lite.widget.dialog.AlertControlDialog +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.launch /** * 地图点位不带聚合效果 @@ -51,19 +55,10 @@ private val easyPopupWindow by lazy { EasyPopupWindow(requireContext()) } private lateinit var wellViewModel: WellViewModel private lateinit var orderViewModel: OrderViewModel + private lateinit var lineViewModel: PipelineViewModel private lateinit var aMap: AMap /** - * 所有的marker - */ - private var allMarkerOptions: MutableList = ArrayList() - - /** - * 视野内的marker - */ - private var markerOptionsInView: MutableList = ArrayList() - - /** * 自定义Marker弹出框 * */ private lateinit var v: View @@ -105,20 +100,56 @@ } }) - //初始化vm - wellViewModel = ViewModelProvider(this)[WellViewModel::class.java] - orderViewModel = ViewModelProvider(this)[OrderViewModel::class.java] - //地图初始化 initMap(savedInstanceState) - //获取所有窨井数据 - httpCountDownTimer.start() - LoadingDialogHub.show(requireActivity(), "数据加载中,请稍后...") + //初始化vm + wellViewModel = ViewModelProvider(this)[WellViewModel::class.java] + orderViewModel = ViewModelProvider(this)[OrderViewModel::class.java] + lineViewModel = ViewModelProvider(this)[PipelineViewModel::class.java] + + //获取管线数据 + lineViewModel.getPipeline() + lineViewModel.lineResult.observe(this) { + if (it.code == 200) { + //点太多,必须采用协程(线程也行) + it.data.forEach { dot -> + if (!dot.startLatitudeGd.isNullOrBlank() && !dot.startLongitudeGd.isNullOrBlank()) { + if (CoordinateConverter.isAMapDataAvailable( + dot.startLatitudeGd.toDouble(), dot.startLongitudeGd.toDouble() + ) + ) { + //瞄点画线 + val latLngPoints = ArrayList() + + val startLatLng = LatLng( + dot.startLatitudeGd.toDouble(), + dot.startLongitudeGd.toDouble() + ) + + val endLatLng = LatLng( + dot.endLatitudeGd.toDouble(), + dot.endLongitudeGd.toDouble() + ) + latLngPoints.add(startLatLng) + latLngPoints.add(endLatLng) + val options = PolylineOptions().addAll(latLngPoints) + + aMap.addPolyline(options.width(5f).color(Color.RED)) + } + } + } + } + } + //获取所有窨井数据 wellViewModel.getWellList() wellViewModel.totalWellModel.observe(this) { if (it.code == 200) { + /** + * 所有的marker + */ + val allMarkerOptions = ArrayList() val latitudeList: MutableList = ArrayList() val longitudeList: MutableList = ArrayList() it.data?.forEach { well -> @@ -136,33 +167,28 @@ longitudeList.add(longitude) //将所有设备信息转化缓存为Marker点 allMarkerOptions.add( - MarkerOptions().position(LatLng(latitude, longitude)) - .title(well.wellTypeName).snippet(well.wellName) + MarkerOptions() + .position(LatLng(latitude, longitude)) + .title(well.wellTypeName) + .snippet(well.wellName) ) } } } -// LocationHelper.obtainCurrentLocation(requireContext(), object : ILocationListener { -// override fun onAMapLocationGet(aMapLocation: AMapLocation?) { -// if (aMapLocation != null) { -// val centerLatLng = LatLng(aMapLocation.latitude, aMapLocation.longitude) -// //移动到指定经纬度 -// val cameraPosition = CameraPosition(centerLatLng, 12f, 0f, 0f) -// val cameraUpdate = CameraUpdateFactory.newCameraPosition(cameraPosition) -// aMap.animateCamera(cameraUpdate, 1500, null) -// } -// } -// }, false) //计算所有点的中心点位置 val centerLatLng = LatLng(latitudeList.average(), longitudeList.average()) //移动到指定经纬度 - val cameraPosition = CameraPosition(centerLatLng, 16f, 0f, 0f) + val cameraPosition = CameraPosition(centerLatLng, 14f, 0f, 0f) val cameraUpdate = CameraUpdateFactory.newCameraPosition(cameraPosition) aMap.animateCamera(cameraUpdate, 1500, null) - //显示点数据 - displayWellOnMap() + //采用协程显示点数据 + lifecycleScope.launch(Dispatchers.IO) { + allMarkerOptions.forEach { marker -> + aMap.addMarker(marker) + } + } } } @@ -252,50 +278,23 @@ } override fun observeRequestState() { + wellViewModel.loadState.observe(this) { + when (it) { + is LoadState.Loading -> LoadingDialogHub.show( + requireActivity(), "数据加载中,请稍后..." + ) + else -> LoadingDialogHub.dismiss() + } + } } override fun onCameraChange(p0: CameraPosition?) { } - /** - * http请求计时器 - * */ - private val httpCountDownTimer = object : CountDownTimer(15 * 1000, 1000) { - override fun onFinish() { - "请求服务器超时,请退出后重试".show(requireContext()) - LoadingDialogHub.dismiss() - } - - override fun onTick(millisUntilFinished: Long) { - - } - } - - //获取视野内的marker 根据聚合算法合成自定义的marker 显示视野内的marker override fun onCameraChangeFinish(p0: CameraPosition?) { - //地图缩放之后显示聚合点数据 - LoadingDialogHub.dismiss() - httpCountDownTimer.cancel() - } - private fun displayWellOnMap() { - val proj = aMap.projection - val dm = resources.displayMetrics - var screenLocation: Point - markerOptionsInView.clear() - // 获取在当前视野内的marker - 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.well_location).bitmap)) - markerOptionsInView.add(it) - } - } - markerOptionsInView.forEach { - aMap.addMarker(it) - } } override fun onMarkerClick(marker: Marker?): Boolean { @@ -316,9 +315,9 @@ val locationView = v.findViewById(R.id.locationView) //绑定数据 - val clickedLatLng = marker?.position!! + val clicked = marker?.position!! wellModels.forEach { well -> - if (clickedLatLng.latitude == well.latGaode!!.toDouble() && clickedLatLng.longitude == well.lngGaode!!.toDouble()) { + if (clicked.latitude == well.latGaode!!.toDouble() && clicked.longitude == well.lngGaode!!.toDouble()) { wellNameView.text = String.format("点位名称: ${well.wellName}") wellCodeView.text = String.format("点位编号: ${well.wellCode}") wellTypeView.text = String.format("点位类型: ${well.wellType.valueToType()}") @@ -340,8 +339,8 @@ * */ override fun getInfoContents(p0: Marker?): View? = null - override fun onInfoWindowClick(p0: Marker?) { - p0?.apply { + override fun onInfoWindowClick(marker: Marker?) { + marker?.apply { AlertControlDialog.Builder().setContext(requireContext()).setTitle("操作提示") .setMessage("确定要前往吗").setNegativeButton("取消").setPositiveButton("确定") .setOnDialogButtonClickListener(object : diff --git a/app/src/main/java/com/casic/app/smartwell/model/PipelineModel.java b/app/src/main/java/com/casic/app/smartwell/model/PipelineModel.java index 215ac0c..bac4925 100644 --- a/app/src/main/java/com/casic/app/smartwell/model/PipelineModel.java +++ b/app/src/main/java/com/casic/app/smartwell/model/PipelineModel.java @@ -5,7 +5,7 @@ public class PipelineModel { private Integer code; - private DataModel data; + private List data; private String message; private Boolean success; @@ -17,11 +17,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; } @@ -42,287 +42,50 @@ } public static class DataModel { - private List rows; - private Integer total; + private String endLatitudeGd; + private String endLongitudeGd; + private String pipeCode; + private String startLatitudeGd; + private String startLongitudeGd; - public List getRows() { - return rows; + public String getEndLatitudeGd() { + return endLatitudeGd; } - public void setRows(List rows) { - this.rows = rows; + public void setEndLatitudeGd(String endLatitudeGd) { + this.endLatitudeGd = endLatitudeGd; } - public Integer getTotal() { - return total; + public String getEndLongitudeGd() { + return endLongitudeGd; } - public void setTotal(Integer total) { - this.total = total; + public void setEndLongitudeGd(String endLongitudeGd) { + this.endLongitudeGd = endLongitudeGd; } - public static class RowsModel { - private String buryMode; - private String constructEra; - private String deptName; - private String deptid; - private String designPressure; - private String endBuryDeep; - private String endGroundHeight; - private String endLatitude; - private String endLatitudeGd; - private String endLongitude; - private String endLongitudeGd; - private String endPipecrownHeight; - private String id; - private String instantaneousFlow; - private String material; - private String pipeDiameter; - private String pipelineCode; - private String pipelineName; - private String pipelinePosition; - private String pipelineType; - private String pipelineTypeName; - private String startBuryDeep; - private String startGroundHeight; - private String startLatitude; - private String startLatitudeGd; - private String startLongitude; - private String startLongitudeGd; - private String startPipecrownHeight; - private String ts; + public String getPipeCode() { + return pipeCode; + } - public String getBuryMode() { - return buryMode; - } + public void setPipeCode(String pipeCode) { + this.pipeCode = pipeCode; + } - public void setBuryMode(String buryMode) { - this.buryMode = buryMode; - } + public String getStartLatitudeGd() { + return startLatitudeGd; + } - public String getConstructEra() { - return constructEra; - } + public void setStartLatitudeGd(String startLatitudeGd) { + this.startLatitudeGd = startLatitudeGd; + } - public void setConstructEra(String constructEra) { - this.constructEra = constructEra; - } + public String getStartLongitudeGd() { + return startLongitudeGd; + } - public String getDeptName() { - return deptName; - } - - public void setDeptName(String deptName) { - this.deptName = deptName; - } - - public String getDeptid() { - return deptid; - } - - public void setDeptid(String deptid) { - this.deptid = deptid; - } - - public String getDesignPressure() { - return designPressure; - } - - public void setDesignPressure(String designPressure) { - this.designPressure = designPressure; - } - - public String getEndBuryDeep() { - return endBuryDeep; - } - - public void setEndBuryDeep(String endBuryDeep) { - this.endBuryDeep = endBuryDeep; - } - - public String getEndGroundHeight() { - return endGroundHeight; - } - - public void setEndGroundHeight(String endGroundHeight) { - this.endGroundHeight = endGroundHeight; - } - - public String getEndLatitude() { - return endLatitude; - } - - public void setEndLatitude(String endLatitude) { - this.endLatitude = endLatitude; - } - - public String getEndLatitudeGd() { - return endLatitudeGd; - } - - public void setEndLatitudeGd(String endLatitudeGd) { - this.endLatitudeGd = endLatitudeGd; - } - - public String getEndLongitude() { - return endLongitude; - } - - public void setEndLongitude(String endLongitude) { - this.endLongitude = endLongitude; - } - - public String getEndLongitudeGd() { - return endLongitudeGd; - } - - public void setEndLongitudeGd(String endLongitudeGd) { - this.endLongitudeGd = endLongitudeGd; - } - - public String getEndPipecrownHeight() { - return endPipecrownHeight; - } - - public void setEndPipecrownHeight(String endPipecrownHeight) { - this.endPipecrownHeight = endPipecrownHeight; - } - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public String getInstantaneousFlow() { - return instantaneousFlow; - } - - public void setInstantaneousFlow(String instantaneousFlow) { - this.instantaneousFlow = instantaneousFlow; - } - - public String getMaterial() { - return material; - } - - public void setMaterial(String material) { - this.material = material; - } - - public String getPipeDiameter() { - return pipeDiameter; - } - - public void setPipeDiameter(String pipeDiameter) { - this.pipeDiameter = pipeDiameter; - } - - public String getPipelineCode() { - return pipelineCode; - } - - public void setPipelineCode(String pipelineCode) { - this.pipelineCode = pipelineCode; - } - - public String getPipelineName() { - return pipelineName; - } - - public void setPipelineName(String pipelineName) { - this.pipelineName = pipelineName; - } - - public String getPipelinePosition() { - return pipelinePosition; - } - - public void setPipelinePosition(String pipelinePosition) { - this.pipelinePosition = pipelinePosition; - } - - public String getPipelineType() { - return pipelineType; - } - - public void setPipelineType(String pipelineType) { - this.pipelineType = pipelineType; - } - - public String getPipelineTypeName() { - return pipelineTypeName; - } - - public void setPipelineTypeName(String pipelineTypeName) { - this.pipelineTypeName = pipelineTypeName; - } - - public String getStartBuryDeep() { - return startBuryDeep; - } - - public void setStartBuryDeep(String startBuryDeep) { - this.startBuryDeep = startBuryDeep; - } - - public String getStartGroundHeight() { - return startGroundHeight; - } - - public void setStartGroundHeight(String startGroundHeight) { - this.startGroundHeight = startGroundHeight; - } - - public String getStartLatitude() { - return startLatitude; - } - - public void setStartLatitude(String startLatitude) { - this.startLatitude = startLatitude; - } - - public String getStartLatitudeGd() { - return startLatitudeGd; - } - - public void setStartLatitudeGd(String startLatitudeGd) { - this.startLatitudeGd = startLatitudeGd; - } - - public String getStartLongitude() { - return startLongitude; - } - - public void setStartLongitude(String startLongitude) { - this.startLongitude = startLongitude; - } - - public String getStartLongitudeGd() { - return startLongitudeGd; - } - - public void setStartLongitudeGd(String startLongitudeGd) { - this.startLongitudeGd = startLongitudeGd; - } - - public String getStartPipecrownHeight() { - return startPipecrownHeight; - } - - public void setStartPipecrownHeight(String startPipecrownHeight) { - this.startPipecrownHeight = startPipecrownHeight; - } - - public String getTs() { - return ts; - } - - public void setTs(String ts) { - this.ts = ts; - } + public void setStartLongitudeGd(String startLongitudeGd) { + this.startLongitudeGd = startLongitudeGd; } } } diff --git a/app/src/main/java/com/casic/app/smartwell/fragment/HomePageHaveClusterFragment.kt b/app/src/main/java/com/casic/app/smartwell/fragment/HomePageHaveClusterFragment.kt index 06bd542..b1b0d6e 100644 --- a/app/src/main/java/com/casic/app/smartwell/fragment/HomePageHaveClusterFragment.kt +++ b/app/src/main/java/com/casic/app/smartwell/fragment/HomePageHaveClusterFragment.kt @@ -4,7 +4,6 @@ import android.graphics.drawable.BitmapDrawable import android.graphics.drawable.Drawable import android.os.Bundle -import android.util.Log import android.view.LayoutInflater import android.view.ViewGroup import androidx.lifecycle.ViewModelProvider @@ -117,10 +116,8 @@ lineViewModel.lineResult.observe(this) { if (it.code == 200) { //点太多,必须采用协程(线程也行) - it.data.rows.forEach { dot -> - if (dot.startLatitudeGd.isNullOrBlank() || dot.startLongitudeGd.isNullOrBlank()) { - Log.d(kTag, "initOnCreate => ${dot.pipelineName}起点经纬度为空") - } else { + it.data.forEach { dot -> + if (!dot.startLatitudeGd.isNullOrBlank() && !dot.startLongitudeGd.isNullOrBlank()) { if (CoordinateConverter.isAMapDataAvailable( dot.startLatitudeGd.toDouble(), dot.startLongitudeGd.toDouble() ) @@ -141,7 +138,7 @@ latLngPoints.add(endLatLng) val options = PolylineOptions().addAll(latLngPoints) - aMap.addPolyline(options.width(10f).color(Color.RED)) + aMap.addPolyline(options.width(5f).color(Color.RED)) } } } @@ -175,7 +172,7 @@ //计算所有点的中心点位置 val centerLatLng = LatLng(latitudeList.average(), longitudeList.average()) //移动到指定经纬度 - val cameraPosition = CameraPosition(centerLatLng, 16f, 0f, 0f) + val cameraPosition = CameraPosition(centerLatLng, 12f, 0f, 0f) val cameraUpdate = CameraUpdateFactory.newCameraPosition(cameraPosition) aMap.animateCamera(cameraUpdate, 1500, null) @@ -294,7 +291,7 @@ clusterOverlay = ClusterOverlay(requireContext(), aMap, clusterItems, regionRadius) clusterOverlay?.setClusterRender { clusterNum -> //聚合圆半径 - val radius = 100.dp2px(requireContext()) + val radius = 80.dp2px(requireContext()) if (clusterNum == 0) { var bitmapDrawable = backDrawables[0] if (bitmapDrawable == null) { diff --git a/app/src/main/java/com/casic/app/smartwell/fragment/HomePageNoClusterFragment.kt b/app/src/main/java/com/casic/app/smartwell/fragment/HomePageNoClusterFragment.kt index bfa7a57..67ccf3a 100644 --- a/app/src/main/java/com/casic/app/smartwell/fragment/HomePageNoClusterFragment.kt +++ b/app/src/main/java/com/casic/app/smartwell/fragment/HomePageNoClusterFragment.kt @@ -1,22 +1,22 @@ package com.casic.app.smartwell.fragment -import android.graphics.Point +import android.graphics.Color import android.os.Bundle -import android.os.CountDownTimer import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import android.widget.TextView import androidx.lifecycle.ViewModelProvider +import androidx.lifecycle.lifecycleScope 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 import com.amap.api.maps.model.Marker import com.amap.api.maps.model.MarkerOptions +import com.amap.api.maps.model.PolylineOptions import com.casic.app.smartwell.R import com.casic.app.smartwell.databinding.FragmentHomeBinding import com.casic.app.smartwell.extensions.initImmersionBar @@ -30,15 +30,19 @@ import com.casic.app.smartwell.view.WellManagementActivity import com.casic.app.smartwell.view.WellOperationActivity import com.casic.app.smartwell.vm.OrderViewModel +import com.casic.app.smartwell.vm.PipelineViewModel import com.casic.app.smartwell.vm.WellViewModel import com.pengxh.kt.lite.adapter.NormalRecyclerAdapter import com.pengxh.kt.lite.adapter.ViewHolder import com.pengxh.kt.lite.base.KotlinBaseFragment import com.pengxh.kt.lite.extensions.navigatePageTo import com.pengxh.kt.lite.extensions.show +import com.pengxh.kt.lite.utils.LoadState import com.pengxh.kt.lite.utils.LoadingDialogHub import com.pengxh.kt.lite.widget.EasyPopupWindow import com.pengxh.kt.lite.widget.dialog.AlertControlDialog +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.launch /** * 地图点位不带聚合效果 @@ -51,19 +55,10 @@ private val easyPopupWindow by lazy { EasyPopupWindow(requireContext()) } private lateinit var wellViewModel: WellViewModel private lateinit var orderViewModel: OrderViewModel + private lateinit var lineViewModel: PipelineViewModel private lateinit var aMap: AMap /** - * 所有的marker - */ - private var allMarkerOptions: MutableList = ArrayList() - - /** - * 视野内的marker - */ - private var markerOptionsInView: MutableList = ArrayList() - - /** * 自定义Marker弹出框 * */ private lateinit var v: View @@ -105,20 +100,56 @@ } }) - //初始化vm - wellViewModel = ViewModelProvider(this)[WellViewModel::class.java] - orderViewModel = ViewModelProvider(this)[OrderViewModel::class.java] - //地图初始化 initMap(savedInstanceState) - //获取所有窨井数据 - httpCountDownTimer.start() - LoadingDialogHub.show(requireActivity(), "数据加载中,请稍后...") + //初始化vm + wellViewModel = ViewModelProvider(this)[WellViewModel::class.java] + orderViewModel = ViewModelProvider(this)[OrderViewModel::class.java] + lineViewModel = ViewModelProvider(this)[PipelineViewModel::class.java] + + //获取管线数据 + lineViewModel.getPipeline() + lineViewModel.lineResult.observe(this) { + if (it.code == 200) { + //点太多,必须采用协程(线程也行) + it.data.forEach { dot -> + if (!dot.startLatitudeGd.isNullOrBlank() && !dot.startLongitudeGd.isNullOrBlank()) { + if (CoordinateConverter.isAMapDataAvailable( + dot.startLatitudeGd.toDouble(), dot.startLongitudeGd.toDouble() + ) + ) { + //瞄点画线 + val latLngPoints = ArrayList() + + val startLatLng = LatLng( + dot.startLatitudeGd.toDouble(), + dot.startLongitudeGd.toDouble() + ) + + val endLatLng = LatLng( + dot.endLatitudeGd.toDouble(), + dot.endLongitudeGd.toDouble() + ) + latLngPoints.add(startLatLng) + latLngPoints.add(endLatLng) + val options = PolylineOptions().addAll(latLngPoints) + + aMap.addPolyline(options.width(5f).color(Color.RED)) + } + } + } + } + } + //获取所有窨井数据 wellViewModel.getWellList() wellViewModel.totalWellModel.observe(this) { if (it.code == 200) { + /** + * 所有的marker + */ + val allMarkerOptions = ArrayList() val latitudeList: MutableList = ArrayList() val longitudeList: MutableList = ArrayList() it.data?.forEach { well -> @@ -136,33 +167,28 @@ longitudeList.add(longitude) //将所有设备信息转化缓存为Marker点 allMarkerOptions.add( - MarkerOptions().position(LatLng(latitude, longitude)) - .title(well.wellTypeName).snippet(well.wellName) + MarkerOptions() + .position(LatLng(latitude, longitude)) + .title(well.wellTypeName) + .snippet(well.wellName) ) } } } -// LocationHelper.obtainCurrentLocation(requireContext(), object : ILocationListener { -// override fun onAMapLocationGet(aMapLocation: AMapLocation?) { -// if (aMapLocation != null) { -// val centerLatLng = LatLng(aMapLocation.latitude, aMapLocation.longitude) -// //移动到指定经纬度 -// val cameraPosition = CameraPosition(centerLatLng, 12f, 0f, 0f) -// val cameraUpdate = CameraUpdateFactory.newCameraPosition(cameraPosition) -// aMap.animateCamera(cameraUpdate, 1500, null) -// } -// } -// }, false) //计算所有点的中心点位置 val centerLatLng = LatLng(latitudeList.average(), longitudeList.average()) //移动到指定经纬度 - val cameraPosition = CameraPosition(centerLatLng, 16f, 0f, 0f) + val cameraPosition = CameraPosition(centerLatLng, 14f, 0f, 0f) val cameraUpdate = CameraUpdateFactory.newCameraPosition(cameraPosition) aMap.animateCamera(cameraUpdate, 1500, null) - //显示点数据 - displayWellOnMap() + //采用协程显示点数据 + lifecycleScope.launch(Dispatchers.IO) { + allMarkerOptions.forEach { marker -> + aMap.addMarker(marker) + } + } } } @@ -252,50 +278,23 @@ } override fun observeRequestState() { + wellViewModel.loadState.observe(this) { + when (it) { + is LoadState.Loading -> LoadingDialogHub.show( + requireActivity(), "数据加载中,请稍后..." + ) + else -> LoadingDialogHub.dismiss() + } + } } override fun onCameraChange(p0: CameraPosition?) { } - /** - * http请求计时器 - * */ - private val httpCountDownTimer = object : CountDownTimer(15 * 1000, 1000) { - override fun onFinish() { - "请求服务器超时,请退出后重试".show(requireContext()) - LoadingDialogHub.dismiss() - } - - override fun onTick(millisUntilFinished: Long) { - - } - } - - //获取视野内的marker 根据聚合算法合成自定义的marker 显示视野内的marker override fun onCameraChangeFinish(p0: CameraPosition?) { - //地图缩放之后显示聚合点数据 - LoadingDialogHub.dismiss() - httpCountDownTimer.cancel() - } - private fun displayWellOnMap() { - val proj = aMap.projection - val dm = resources.displayMetrics - var screenLocation: Point - markerOptionsInView.clear() - // 获取在当前视野内的marker - 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.well_location).bitmap)) - markerOptionsInView.add(it) - } - } - markerOptionsInView.forEach { - aMap.addMarker(it) - } } override fun onMarkerClick(marker: Marker?): Boolean { @@ -316,9 +315,9 @@ val locationView = v.findViewById(R.id.locationView) //绑定数据 - val clickedLatLng = marker?.position!! + val clicked = marker?.position!! wellModels.forEach { well -> - if (clickedLatLng.latitude == well.latGaode!!.toDouble() && clickedLatLng.longitude == well.lngGaode!!.toDouble()) { + if (clicked.latitude == well.latGaode!!.toDouble() && clicked.longitude == well.lngGaode!!.toDouble()) { wellNameView.text = String.format("点位名称: ${well.wellName}") wellCodeView.text = String.format("点位编号: ${well.wellCode}") wellTypeView.text = String.format("点位类型: ${well.wellType.valueToType()}") @@ -340,8 +339,8 @@ * */ override fun getInfoContents(p0: Marker?): View? = null - override fun onInfoWindowClick(p0: Marker?) { - p0?.apply { + override fun onInfoWindowClick(marker: Marker?) { + marker?.apply { AlertControlDialog.Builder().setContext(requireContext()).setTitle("操作提示") .setMessage("确定要前往吗").setNegativeButton("取消").setPositiveButton("确定") .setOnDialogButtonClickListener(object : diff --git a/app/src/main/java/com/casic/app/smartwell/model/PipelineModel.java b/app/src/main/java/com/casic/app/smartwell/model/PipelineModel.java index 215ac0c..bac4925 100644 --- a/app/src/main/java/com/casic/app/smartwell/model/PipelineModel.java +++ b/app/src/main/java/com/casic/app/smartwell/model/PipelineModel.java @@ -5,7 +5,7 @@ public class PipelineModel { private Integer code; - private DataModel data; + private List data; private String message; private Boolean success; @@ -17,11 +17,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; } @@ -42,287 +42,50 @@ } public static class DataModel { - private List rows; - private Integer total; + private String endLatitudeGd; + private String endLongitudeGd; + private String pipeCode; + private String startLatitudeGd; + private String startLongitudeGd; - public List getRows() { - return rows; + public String getEndLatitudeGd() { + return endLatitudeGd; } - public void setRows(List rows) { - this.rows = rows; + public void setEndLatitudeGd(String endLatitudeGd) { + this.endLatitudeGd = endLatitudeGd; } - public Integer getTotal() { - return total; + public String getEndLongitudeGd() { + return endLongitudeGd; } - public void setTotal(Integer total) { - this.total = total; + public void setEndLongitudeGd(String endLongitudeGd) { + this.endLongitudeGd = endLongitudeGd; } - public static class RowsModel { - private String buryMode; - private String constructEra; - private String deptName; - private String deptid; - private String designPressure; - private String endBuryDeep; - private String endGroundHeight; - private String endLatitude; - private String endLatitudeGd; - private String endLongitude; - private String endLongitudeGd; - private String endPipecrownHeight; - private String id; - private String instantaneousFlow; - private String material; - private String pipeDiameter; - private String pipelineCode; - private String pipelineName; - private String pipelinePosition; - private String pipelineType; - private String pipelineTypeName; - private String startBuryDeep; - private String startGroundHeight; - private String startLatitude; - private String startLatitudeGd; - private String startLongitude; - private String startLongitudeGd; - private String startPipecrownHeight; - private String ts; + public String getPipeCode() { + return pipeCode; + } - public String getBuryMode() { - return buryMode; - } + public void setPipeCode(String pipeCode) { + this.pipeCode = pipeCode; + } - public void setBuryMode(String buryMode) { - this.buryMode = buryMode; - } + public String getStartLatitudeGd() { + return startLatitudeGd; + } - public String getConstructEra() { - return constructEra; - } + public void setStartLatitudeGd(String startLatitudeGd) { + this.startLatitudeGd = startLatitudeGd; + } - public void setConstructEra(String constructEra) { - this.constructEra = constructEra; - } + public String getStartLongitudeGd() { + return startLongitudeGd; + } - public String getDeptName() { - return deptName; - } - - public void setDeptName(String deptName) { - this.deptName = deptName; - } - - public String getDeptid() { - return deptid; - } - - public void setDeptid(String deptid) { - this.deptid = deptid; - } - - public String getDesignPressure() { - return designPressure; - } - - public void setDesignPressure(String designPressure) { - this.designPressure = designPressure; - } - - public String getEndBuryDeep() { - return endBuryDeep; - } - - public void setEndBuryDeep(String endBuryDeep) { - this.endBuryDeep = endBuryDeep; - } - - public String getEndGroundHeight() { - return endGroundHeight; - } - - public void setEndGroundHeight(String endGroundHeight) { - this.endGroundHeight = endGroundHeight; - } - - public String getEndLatitude() { - return endLatitude; - } - - public void setEndLatitude(String endLatitude) { - this.endLatitude = endLatitude; - } - - public String getEndLatitudeGd() { - return endLatitudeGd; - } - - public void setEndLatitudeGd(String endLatitudeGd) { - this.endLatitudeGd = endLatitudeGd; - } - - public String getEndLongitude() { - return endLongitude; - } - - public void setEndLongitude(String endLongitude) { - this.endLongitude = endLongitude; - } - - public String getEndLongitudeGd() { - return endLongitudeGd; - } - - public void setEndLongitudeGd(String endLongitudeGd) { - this.endLongitudeGd = endLongitudeGd; - } - - public String getEndPipecrownHeight() { - return endPipecrownHeight; - } - - public void setEndPipecrownHeight(String endPipecrownHeight) { - this.endPipecrownHeight = endPipecrownHeight; - } - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public String getInstantaneousFlow() { - return instantaneousFlow; - } - - public void setInstantaneousFlow(String instantaneousFlow) { - this.instantaneousFlow = instantaneousFlow; - } - - public String getMaterial() { - return material; - } - - public void setMaterial(String material) { - this.material = material; - } - - public String getPipeDiameter() { - return pipeDiameter; - } - - public void setPipeDiameter(String pipeDiameter) { - this.pipeDiameter = pipeDiameter; - } - - public String getPipelineCode() { - return pipelineCode; - } - - public void setPipelineCode(String pipelineCode) { - this.pipelineCode = pipelineCode; - } - - public String getPipelineName() { - return pipelineName; - } - - public void setPipelineName(String pipelineName) { - this.pipelineName = pipelineName; - } - - public String getPipelinePosition() { - return pipelinePosition; - } - - public void setPipelinePosition(String pipelinePosition) { - this.pipelinePosition = pipelinePosition; - } - - public String getPipelineType() { - return pipelineType; - } - - public void setPipelineType(String pipelineType) { - this.pipelineType = pipelineType; - } - - public String getPipelineTypeName() { - return pipelineTypeName; - } - - public void setPipelineTypeName(String pipelineTypeName) { - this.pipelineTypeName = pipelineTypeName; - } - - public String getStartBuryDeep() { - return startBuryDeep; - } - - public void setStartBuryDeep(String startBuryDeep) { - this.startBuryDeep = startBuryDeep; - } - - public String getStartGroundHeight() { - return startGroundHeight; - } - - public void setStartGroundHeight(String startGroundHeight) { - this.startGroundHeight = startGroundHeight; - } - - public String getStartLatitude() { - return startLatitude; - } - - public void setStartLatitude(String startLatitude) { - this.startLatitude = startLatitude; - } - - public String getStartLatitudeGd() { - return startLatitudeGd; - } - - public void setStartLatitudeGd(String startLatitudeGd) { - this.startLatitudeGd = startLatitudeGd; - } - - public String getStartLongitude() { - return startLongitude; - } - - public void setStartLongitude(String startLongitude) { - this.startLongitude = startLongitude; - } - - public String getStartLongitudeGd() { - return startLongitudeGd; - } - - public void setStartLongitudeGd(String startLongitudeGd) { - this.startLongitudeGd = startLongitudeGd; - } - - public String getStartPipecrownHeight() { - return startPipecrownHeight; - } - - public void setStartPipecrownHeight(String startPipecrownHeight) { - this.startPipecrownHeight = startPipecrownHeight; - } - - public String getTs() { - return ts; - } - - public void setTs(String ts) { - this.ts = ts; - } + public void setStartLongitudeGd(String startLongitudeGd) { + this.startLongitudeGd = startLongitudeGd; } } } diff --git a/app/src/main/java/com/casic/app/smartwell/utils/LocaleConstant.kt b/app/src/main/java/com/casic/app/smartwell/utils/LocaleConstant.kt index f20782c..22e9e65 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/LocaleConstant.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/LocaleConstant.kt @@ -29,7 +29,7 @@ } const val FIVE_YEARS = 5L * 365 * 60 * 60 * 24 * 1000L - const val RADIUS_SIZE = 80 //相距多少米才聚合,单位:米 + const val RADIUS_SIZE = 100 //相距多少米才聚合,单位:米 const val PERMISSIONS_CODE = 999 const val PAGE_LIMIT = 20 const val PUSH_REGISTER = 2022082901 @@ -39,7 +39,7 @@ const val DEFAULT_SERVER_CONFIG = "defaultServerConfig" const val DEFAULT_SERVER = "http://60.208.121.150:5001" -// const val DEFAULT_SERVER = "http://111.198.10.15:11638" +// const val DEFAULT_SERVER = "http://192.168.75.39:11308" const val USER_DETAIL_MODEL = "userDetailModel" const val APP_AUTHORITY = "com.casic.zq.smartwell.fileprovider" diff --git a/app/src/main/java/com/casic/app/smartwell/fragment/HomePageHaveClusterFragment.kt b/app/src/main/java/com/casic/app/smartwell/fragment/HomePageHaveClusterFragment.kt index 06bd542..b1b0d6e 100644 --- a/app/src/main/java/com/casic/app/smartwell/fragment/HomePageHaveClusterFragment.kt +++ b/app/src/main/java/com/casic/app/smartwell/fragment/HomePageHaveClusterFragment.kt @@ -4,7 +4,6 @@ import android.graphics.drawable.BitmapDrawable import android.graphics.drawable.Drawable import android.os.Bundle -import android.util.Log import android.view.LayoutInflater import android.view.ViewGroup import androidx.lifecycle.ViewModelProvider @@ -117,10 +116,8 @@ lineViewModel.lineResult.observe(this) { if (it.code == 200) { //点太多,必须采用协程(线程也行) - it.data.rows.forEach { dot -> - if (dot.startLatitudeGd.isNullOrBlank() || dot.startLongitudeGd.isNullOrBlank()) { - Log.d(kTag, "initOnCreate => ${dot.pipelineName}起点经纬度为空") - } else { + it.data.forEach { dot -> + if (!dot.startLatitudeGd.isNullOrBlank() && !dot.startLongitudeGd.isNullOrBlank()) { if (CoordinateConverter.isAMapDataAvailable( dot.startLatitudeGd.toDouble(), dot.startLongitudeGd.toDouble() ) @@ -141,7 +138,7 @@ latLngPoints.add(endLatLng) val options = PolylineOptions().addAll(latLngPoints) - aMap.addPolyline(options.width(10f).color(Color.RED)) + aMap.addPolyline(options.width(5f).color(Color.RED)) } } } @@ -175,7 +172,7 @@ //计算所有点的中心点位置 val centerLatLng = LatLng(latitudeList.average(), longitudeList.average()) //移动到指定经纬度 - val cameraPosition = CameraPosition(centerLatLng, 16f, 0f, 0f) + val cameraPosition = CameraPosition(centerLatLng, 12f, 0f, 0f) val cameraUpdate = CameraUpdateFactory.newCameraPosition(cameraPosition) aMap.animateCamera(cameraUpdate, 1500, null) @@ -294,7 +291,7 @@ clusterOverlay = ClusterOverlay(requireContext(), aMap, clusterItems, regionRadius) clusterOverlay?.setClusterRender { clusterNum -> //聚合圆半径 - val radius = 100.dp2px(requireContext()) + val radius = 80.dp2px(requireContext()) if (clusterNum == 0) { var bitmapDrawable = backDrawables[0] if (bitmapDrawable == null) { diff --git a/app/src/main/java/com/casic/app/smartwell/fragment/HomePageNoClusterFragment.kt b/app/src/main/java/com/casic/app/smartwell/fragment/HomePageNoClusterFragment.kt index bfa7a57..67ccf3a 100644 --- a/app/src/main/java/com/casic/app/smartwell/fragment/HomePageNoClusterFragment.kt +++ b/app/src/main/java/com/casic/app/smartwell/fragment/HomePageNoClusterFragment.kt @@ -1,22 +1,22 @@ package com.casic.app.smartwell.fragment -import android.graphics.Point +import android.graphics.Color import android.os.Bundle -import android.os.CountDownTimer import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import android.widget.TextView import androidx.lifecycle.ViewModelProvider +import androidx.lifecycle.lifecycleScope 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 import com.amap.api.maps.model.Marker import com.amap.api.maps.model.MarkerOptions +import com.amap.api.maps.model.PolylineOptions import com.casic.app.smartwell.R import com.casic.app.smartwell.databinding.FragmentHomeBinding import com.casic.app.smartwell.extensions.initImmersionBar @@ -30,15 +30,19 @@ import com.casic.app.smartwell.view.WellManagementActivity import com.casic.app.smartwell.view.WellOperationActivity import com.casic.app.smartwell.vm.OrderViewModel +import com.casic.app.smartwell.vm.PipelineViewModel import com.casic.app.smartwell.vm.WellViewModel import com.pengxh.kt.lite.adapter.NormalRecyclerAdapter import com.pengxh.kt.lite.adapter.ViewHolder import com.pengxh.kt.lite.base.KotlinBaseFragment import com.pengxh.kt.lite.extensions.navigatePageTo import com.pengxh.kt.lite.extensions.show +import com.pengxh.kt.lite.utils.LoadState import com.pengxh.kt.lite.utils.LoadingDialogHub import com.pengxh.kt.lite.widget.EasyPopupWindow import com.pengxh.kt.lite.widget.dialog.AlertControlDialog +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.launch /** * 地图点位不带聚合效果 @@ -51,19 +55,10 @@ private val easyPopupWindow by lazy { EasyPopupWindow(requireContext()) } private lateinit var wellViewModel: WellViewModel private lateinit var orderViewModel: OrderViewModel + private lateinit var lineViewModel: PipelineViewModel private lateinit var aMap: AMap /** - * 所有的marker - */ - private var allMarkerOptions: MutableList = ArrayList() - - /** - * 视野内的marker - */ - private var markerOptionsInView: MutableList = ArrayList() - - /** * 自定义Marker弹出框 * */ private lateinit var v: View @@ -105,20 +100,56 @@ } }) - //初始化vm - wellViewModel = ViewModelProvider(this)[WellViewModel::class.java] - orderViewModel = ViewModelProvider(this)[OrderViewModel::class.java] - //地图初始化 initMap(savedInstanceState) - //获取所有窨井数据 - httpCountDownTimer.start() - LoadingDialogHub.show(requireActivity(), "数据加载中,请稍后...") + //初始化vm + wellViewModel = ViewModelProvider(this)[WellViewModel::class.java] + orderViewModel = ViewModelProvider(this)[OrderViewModel::class.java] + lineViewModel = ViewModelProvider(this)[PipelineViewModel::class.java] + + //获取管线数据 + lineViewModel.getPipeline() + lineViewModel.lineResult.observe(this) { + if (it.code == 200) { + //点太多,必须采用协程(线程也行) + it.data.forEach { dot -> + if (!dot.startLatitudeGd.isNullOrBlank() && !dot.startLongitudeGd.isNullOrBlank()) { + if (CoordinateConverter.isAMapDataAvailable( + dot.startLatitudeGd.toDouble(), dot.startLongitudeGd.toDouble() + ) + ) { + //瞄点画线 + val latLngPoints = ArrayList() + + val startLatLng = LatLng( + dot.startLatitudeGd.toDouble(), + dot.startLongitudeGd.toDouble() + ) + + val endLatLng = LatLng( + dot.endLatitudeGd.toDouble(), + dot.endLongitudeGd.toDouble() + ) + latLngPoints.add(startLatLng) + latLngPoints.add(endLatLng) + val options = PolylineOptions().addAll(latLngPoints) + + aMap.addPolyline(options.width(5f).color(Color.RED)) + } + } + } + } + } + //获取所有窨井数据 wellViewModel.getWellList() wellViewModel.totalWellModel.observe(this) { if (it.code == 200) { + /** + * 所有的marker + */ + val allMarkerOptions = ArrayList() val latitudeList: MutableList = ArrayList() val longitudeList: MutableList = ArrayList() it.data?.forEach { well -> @@ -136,33 +167,28 @@ longitudeList.add(longitude) //将所有设备信息转化缓存为Marker点 allMarkerOptions.add( - MarkerOptions().position(LatLng(latitude, longitude)) - .title(well.wellTypeName).snippet(well.wellName) + MarkerOptions() + .position(LatLng(latitude, longitude)) + .title(well.wellTypeName) + .snippet(well.wellName) ) } } } -// LocationHelper.obtainCurrentLocation(requireContext(), object : ILocationListener { -// override fun onAMapLocationGet(aMapLocation: AMapLocation?) { -// if (aMapLocation != null) { -// val centerLatLng = LatLng(aMapLocation.latitude, aMapLocation.longitude) -// //移动到指定经纬度 -// val cameraPosition = CameraPosition(centerLatLng, 12f, 0f, 0f) -// val cameraUpdate = CameraUpdateFactory.newCameraPosition(cameraPosition) -// aMap.animateCamera(cameraUpdate, 1500, null) -// } -// } -// }, false) //计算所有点的中心点位置 val centerLatLng = LatLng(latitudeList.average(), longitudeList.average()) //移动到指定经纬度 - val cameraPosition = CameraPosition(centerLatLng, 16f, 0f, 0f) + val cameraPosition = CameraPosition(centerLatLng, 14f, 0f, 0f) val cameraUpdate = CameraUpdateFactory.newCameraPosition(cameraPosition) aMap.animateCamera(cameraUpdate, 1500, null) - //显示点数据 - displayWellOnMap() + //采用协程显示点数据 + lifecycleScope.launch(Dispatchers.IO) { + allMarkerOptions.forEach { marker -> + aMap.addMarker(marker) + } + } } } @@ -252,50 +278,23 @@ } override fun observeRequestState() { + wellViewModel.loadState.observe(this) { + when (it) { + is LoadState.Loading -> LoadingDialogHub.show( + requireActivity(), "数据加载中,请稍后..." + ) + else -> LoadingDialogHub.dismiss() + } + } } override fun onCameraChange(p0: CameraPosition?) { } - /** - * http请求计时器 - * */ - private val httpCountDownTimer = object : CountDownTimer(15 * 1000, 1000) { - override fun onFinish() { - "请求服务器超时,请退出后重试".show(requireContext()) - LoadingDialogHub.dismiss() - } - - override fun onTick(millisUntilFinished: Long) { - - } - } - - //获取视野内的marker 根据聚合算法合成自定义的marker 显示视野内的marker override fun onCameraChangeFinish(p0: CameraPosition?) { - //地图缩放之后显示聚合点数据 - LoadingDialogHub.dismiss() - httpCountDownTimer.cancel() - } - private fun displayWellOnMap() { - val proj = aMap.projection - val dm = resources.displayMetrics - var screenLocation: Point - markerOptionsInView.clear() - // 获取在当前视野内的marker - 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.well_location).bitmap)) - markerOptionsInView.add(it) - } - } - markerOptionsInView.forEach { - aMap.addMarker(it) - } } override fun onMarkerClick(marker: Marker?): Boolean { @@ -316,9 +315,9 @@ val locationView = v.findViewById(R.id.locationView) //绑定数据 - val clickedLatLng = marker?.position!! + val clicked = marker?.position!! wellModels.forEach { well -> - if (clickedLatLng.latitude == well.latGaode!!.toDouble() && clickedLatLng.longitude == well.lngGaode!!.toDouble()) { + if (clicked.latitude == well.latGaode!!.toDouble() && clicked.longitude == well.lngGaode!!.toDouble()) { wellNameView.text = String.format("点位名称: ${well.wellName}") wellCodeView.text = String.format("点位编号: ${well.wellCode}") wellTypeView.text = String.format("点位类型: ${well.wellType.valueToType()}") @@ -340,8 +339,8 @@ * */ override fun getInfoContents(p0: Marker?): View? = null - override fun onInfoWindowClick(p0: Marker?) { - p0?.apply { + override fun onInfoWindowClick(marker: Marker?) { + marker?.apply { AlertControlDialog.Builder().setContext(requireContext()).setTitle("操作提示") .setMessage("确定要前往吗").setNegativeButton("取消").setPositiveButton("确定") .setOnDialogButtonClickListener(object : diff --git a/app/src/main/java/com/casic/app/smartwell/model/PipelineModel.java b/app/src/main/java/com/casic/app/smartwell/model/PipelineModel.java index 215ac0c..bac4925 100644 --- a/app/src/main/java/com/casic/app/smartwell/model/PipelineModel.java +++ b/app/src/main/java/com/casic/app/smartwell/model/PipelineModel.java @@ -5,7 +5,7 @@ public class PipelineModel { private Integer code; - private DataModel data; + private List data; private String message; private Boolean success; @@ -17,11 +17,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; } @@ -42,287 +42,50 @@ } public static class DataModel { - private List rows; - private Integer total; + private String endLatitudeGd; + private String endLongitudeGd; + private String pipeCode; + private String startLatitudeGd; + private String startLongitudeGd; - public List getRows() { - return rows; + public String getEndLatitudeGd() { + return endLatitudeGd; } - public void setRows(List rows) { - this.rows = rows; + public void setEndLatitudeGd(String endLatitudeGd) { + this.endLatitudeGd = endLatitudeGd; } - public Integer getTotal() { - return total; + public String getEndLongitudeGd() { + return endLongitudeGd; } - public void setTotal(Integer total) { - this.total = total; + public void setEndLongitudeGd(String endLongitudeGd) { + this.endLongitudeGd = endLongitudeGd; } - public static class RowsModel { - private String buryMode; - private String constructEra; - private String deptName; - private String deptid; - private String designPressure; - private String endBuryDeep; - private String endGroundHeight; - private String endLatitude; - private String endLatitudeGd; - private String endLongitude; - private String endLongitudeGd; - private String endPipecrownHeight; - private String id; - private String instantaneousFlow; - private String material; - private String pipeDiameter; - private String pipelineCode; - private String pipelineName; - private String pipelinePosition; - private String pipelineType; - private String pipelineTypeName; - private String startBuryDeep; - private String startGroundHeight; - private String startLatitude; - private String startLatitudeGd; - private String startLongitude; - private String startLongitudeGd; - private String startPipecrownHeight; - private String ts; + public String getPipeCode() { + return pipeCode; + } - public String getBuryMode() { - return buryMode; - } + public void setPipeCode(String pipeCode) { + this.pipeCode = pipeCode; + } - public void setBuryMode(String buryMode) { - this.buryMode = buryMode; - } + public String getStartLatitudeGd() { + return startLatitudeGd; + } - public String getConstructEra() { - return constructEra; - } + public void setStartLatitudeGd(String startLatitudeGd) { + this.startLatitudeGd = startLatitudeGd; + } - public void setConstructEra(String constructEra) { - this.constructEra = constructEra; - } + public String getStartLongitudeGd() { + return startLongitudeGd; + } - public String getDeptName() { - return deptName; - } - - public void setDeptName(String deptName) { - this.deptName = deptName; - } - - public String getDeptid() { - return deptid; - } - - public void setDeptid(String deptid) { - this.deptid = deptid; - } - - public String getDesignPressure() { - return designPressure; - } - - public void setDesignPressure(String designPressure) { - this.designPressure = designPressure; - } - - public String getEndBuryDeep() { - return endBuryDeep; - } - - public void setEndBuryDeep(String endBuryDeep) { - this.endBuryDeep = endBuryDeep; - } - - public String getEndGroundHeight() { - return endGroundHeight; - } - - public void setEndGroundHeight(String endGroundHeight) { - this.endGroundHeight = endGroundHeight; - } - - public String getEndLatitude() { - return endLatitude; - } - - public void setEndLatitude(String endLatitude) { - this.endLatitude = endLatitude; - } - - public String getEndLatitudeGd() { - return endLatitudeGd; - } - - public void setEndLatitudeGd(String endLatitudeGd) { - this.endLatitudeGd = endLatitudeGd; - } - - public String getEndLongitude() { - return endLongitude; - } - - public void setEndLongitude(String endLongitude) { - this.endLongitude = endLongitude; - } - - public String getEndLongitudeGd() { - return endLongitudeGd; - } - - public void setEndLongitudeGd(String endLongitudeGd) { - this.endLongitudeGd = endLongitudeGd; - } - - public String getEndPipecrownHeight() { - return endPipecrownHeight; - } - - public void setEndPipecrownHeight(String endPipecrownHeight) { - this.endPipecrownHeight = endPipecrownHeight; - } - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public String getInstantaneousFlow() { - return instantaneousFlow; - } - - public void setInstantaneousFlow(String instantaneousFlow) { - this.instantaneousFlow = instantaneousFlow; - } - - public String getMaterial() { - return material; - } - - public void setMaterial(String material) { - this.material = material; - } - - public String getPipeDiameter() { - return pipeDiameter; - } - - public void setPipeDiameter(String pipeDiameter) { - this.pipeDiameter = pipeDiameter; - } - - public String getPipelineCode() { - return pipelineCode; - } - - public void setPipelineCode(String pipelineCode) { - this.pipelineCode = pipelineCode; - } - - public String getPipelineName() { - return pipelineName; - } - - public void setPipelineName(String pipelineName) { - this.pipelineName = pipelineName; - } - - public String getPipelinePosition() { - return pipelinePosition; - } - - public void setPipelinePosition(String pipelinePosition) { - this.pipelinePosition = pipelinePosition; - } - - public String getPipelineType() { - return pipelineType; - } - - public void setPipelineType(String pipelineType) { - this.pipelineType = pipelineType; - } - - public String getPipelineTypeName() { - return pipelineTypeName; - } - - public void setPipelineTypeName(String pipelineTypeName) { - this.pipelineTypeName = pipelineTypeName; - } - - public String getStartBuryDeep() { - return startBuryDeep; - } - - public void setStartBuryDeep(String startBuryDeep) { - this.startBuryDeep = startBuryDeep; - } - - public String getStartGroundHeight() { - return startGroundHeight; - } - - public void setStartGroundHeight(String startGroundHeight) { - this.startGroundHeight = startGroundHeight; - } - - public String getStartLatitude() { - return startLatitude; - } - - public void setStartLatitude(String startLatitude) { - this.startLatitude = startLatitude; - } - - public String getStartLatitudeGd() { - return startLatitudeGd; - } - - public void setStartLatitudeGd(String startLatitudeGd) { - this.startLatitudeGd = startLatitudeGd; - } - - public String getStartLongitude() { - return startLongitude; - } - - public void setStartLongitude(String startLongitude) { - this.startLongitude = startLongitude; - } - - public String getStartLongitudeGd() { - return startLongitudeGd; - } - - public void setStartLongitudeGd(String startLongitudeGd) { - this.startLongitudeGd = startLongitudeGd; - } - - public String getStartPipecrownHeight() { - return startPipecrownHeight; - } - - public void setStartPipecrownHeight(String startPipecrownHeight) { - this.startPipecrownHeight = startPipecrownHeight; - } - - public String getTs() { - return ts; - } - - public void setTs(String ts) { - this.ts = ts; - } + public void setStartLongitudeGd(String startLongitudeGd) { + this.startLongitudeGd = startLongitudeGd; } } } diff --git a/app/src/main/java/com/casic/app/smartwell/utils/LocaleConstant.kt b/app/src/main/java/com/casic/app/smartwell/utils/LocaleConstant.kt index f20782c..22e9e65 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/LocaleConstant.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/LocaleConstant.kt @@ -29,7 +29,7 @@ } const val FIVE_YEARS = 5L * 365 * 60 * 60 * 24 * 1000L - const val RADIUS_SIZE = 80 //相距多少米才聚合,单位:米 + const val RADIUS_SIZE = 100 //相距多少米才聚合,单位:米 const val PERMISSIONS_CODE = 999 const val PAGE_LIMIT = 20 const val PUSH_REGISTER = 2022082901 @@ -39,7 +39,7 @@ const val DEFAULT_SERVER_CONFIG = "defaultServerConfig" const val DEFAULT_SERVER = "http://60.208.121.150:5001" -// const val DEFAULT_SERVER = "http://111.198.10.15:11638" +// const val DEFAULT_SERVER = "http://192.168.75.39:11308" const val USER_DETAIL_MODEL = "userDetailModel" const val APP_AUTHORITY = "com.casic.zq.smartwell.fileprovider" diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt index 991e1db..82bef29 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt @@ -316,7 +316,7 @@ /** * 管线位置数据 */ - @GET("/pipeline/listPage") + @GET("/pipeline/appList") suspend fun getPipeline( @Header("token") token: String, @Query("limit") limit: Int, diff --git a/app/src/main/java/com/casic/app/smartwell/fragment/HomePageHaveClusterFragment.kt b/app/src/main/java/com/casic/app/smartwell/fragment/HomePageHaveClusterFragment.kt index 06bd542..b1b0d6e 100644 --- a/app/src/main/java/com/casic/app/smartwell/fragment/HomePageHaveClusterFragment.kt +++ b/app/src/main/java/com/casic/app/smartwell/fragment/HomePageHaveClusterFragment.kt @@ -4,7 +4,6 @@ import android.graphics.drawable.BitmapDrawable import android.graphics.drawable.Drawable import android.os.Bundle -import android.util.Log import android.view.LayoutInflater import android.view.ViewGroup import androidx.lifecycle.ViewModelProvider @@ -117,10 +116,8 @@ lineViewModel.lineResult.observe(this) { if (it.code == 200) { //点太多,必须采用协程(线程也行) - it.data.rows.forEach { dot -> - if (dot.startLatitudeGd.isNullOrBlank() || dot.startLongitudeGd.isNullOrBlank()) { - Log.d(kTag, "initOnCreate => ${dot.pipelineName}起点经纬度为空") - } else { + it.data.forEach { dot -> + if (!dot.startLatitudeGd.isNullOrBlank() && !dot.startLongitudeGd.isNullOrBlank()) { if (CoordinateConverter.isAMapDataAvailable( dot.startLatitudeGd.toDouble(), dot.startLongitudeGd.toDouble() ) @@ -141,7 +138,7 @@ latLngPoints.add(endLatLng) val options = PolylineOptions().addAll(latLngPoints) - aMap.addPolyline(options.width(10f).color(Color.RED)) + aMap.addPolyline(options.width(5f).color(Color.RED)) } } } @@ -175,7 +172,7 @@ //计算所有点的中心点位置 val centerLatLng = LatLng(latitudeList.average(), longitudeList.average()) //移动到指定经纬度 - val cameraPosition = CameraPosition(centerLatLng, 16f, 0f, 0f) + val cameraPosition = CameraPosition(centerLatLng, 12f, 0f, 0f) val cameraUpdate = CameraUpdateFactory.newCameraPosition(cameraPosition) aMap.animateCamera(cameraUpdate, 1500, null) @@ -294,7 +291,7 @@ clusterOverlay = ClusterOverlay(requireContext(), aMap, clusterItems, regionRadius) clusterOverlay?.setClusterRender { clusterNum -> //聚合圆半径 - val radius = 100.dp2px(requireContext()) + val radius = 80.dp2px(requireContext()) if (clusterNum == 0) { var bitmapDrawable = backDrawables[0] if (bitmapDrawable == null) { diff --git a/app/src/main/java/com/casic/app/smartwell/fragment/HomePageNoClusterFragment.kt b/app/src/main/java/com/casic/app/smartwell/fragment/HomePageNoClusterFragment.kt index bfa7a57..67ccf3a 100644 --- a/app/src/main/java/com/casic/app/smartwell/fragment/HomePageNoClusterFragment.kt +++ b/app/src/main/java/com/casic/app/smartwell/fragment/HomePageNoClusterFragment.kt @@ -1,22 +1,22 @@ package com.casic.app.smartwell.fragment -import android.graphics.Point +import android.graphics.Color import android.os.Bundle -import android.os.CountDownTimer import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import android.widget.TextView import androidx.lifecycle.ViewModelProvider +import androidx.lifecycle.lifecycleScope 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 import com.amap.api.maps.model.Marker import com.amap.api.maps.model.MarkerOptions +import com.amap.api.maps.model.PolylineOptions import com.casic.app.smartwell.R import com.casic.app.smartwell.databinding.FragmentHomeBinding import com.casic.app.smartwell.extensions.initImmersionBar @@ -30,15 +30,19 @@ import com.casic.app.smartwell.view.WellManagementActivity import com.casic.app.smartwell.view.WellOperationActivity import com.casic.app.smartwell.vm.OrderViewModel +import com.casic.app.smartwell.vm.PipelineViewModel import com.casic.app.smartwell.vm.WellViewModel import com.pengxh.kt.lite.adapter.NormalRecyclerAdapter import com.pengxh.kt.lite.adapter.ViewHolder import com.pengxh.kt.lite.base.KotlinBaseFragment import com.pengxh.kt.lite.extensions.navigatePageTo import com.pengxh.kt.lite.extensions.show +import com.pengxh.kt.lite.utils.LoadState import com.pengxh.kt.lite.utils.LoadingDialogHub import com.pengxh.kt.lite.widget.EasyPopupWindow import com.pengxh.kt.lite.widget.dialog.AlertControlDialog +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.launch /** * 地图点位不带聚合效果 @@ -51,19 +55,10 @@ private val easyPopupWindow by lazy { EasyPopupWindow(requireContext()) } private lateinit var wellViewModel: WellViewModel private lateinit var orderViewModel: OrderViewModel + private lateinit var lineViewModel: PipelineViewModel private lateinit var aMap: AMap /** - * 所有的marker - */ - private var allMarkerOptions: MutableList = ArrayList() - - /** - * 视野内的marker - */ - private var markerOptionsInView: MutableList = ArrayList() - - /** * 自定义Marker弹出框 * */ private lateinit var v: View @@ -105,20 +100,56 @@ } }) - //初始化vm - wellViewModel = ViewModelProvider(this)[WellViewModel::class.java] - orderViewModel = ViewModelProvider(this)[OrderViewModel::class.java] - //地图初始化 initMap(savedInstanceState) - //获取所有窨井数据 - httpCountDownTimer.start() - LoadingDialogHub.show(requireActivity(), "数据加载中,请稍后...") + //初始化vm + wellViewModel = ViewModelProvider(this)[WellViewModel::class.java] + orderViewModel = ViewModelProvider(this)[OrderViewModel::class.java] + lineViewModel = ViewModelProvider(this)[PipelineViewModel::class.java] + + //获取管线数据 + lineViewModel.getPipeline() + lineViewModel.lineResult.observe(this) { + if (it.code == 200) { + //点太多,必须采用协程(线程也行) + it.data.forEach { dot -> + if (!dot.startLatitudeGd.isNullOrBlank() && !dot.startLongitudeGd.isNullOrBlank()) { + if (CoordinateConverter.isAMapDataAvailable( + dot.startLatitudeGd.toDouble(), dot.startLongitudeGd.toDouble() + ) + ) { + //瞄点画线 + val latLngPoints = ArrayList() + + val startLatLng = LatLng( + dot.startLatitudeGd.toDouble(), + dot.startLongitudeGd.toDouble() + ) + + val endLatLng = LatLng( + dot.endLatitudeGd.toDouble(), + dot.endLongitudeGd.toDouble() + ) + latLngPoints.add(startLatLng) + latLngPoints.add(endLatLng) + val options = PolylineOptions().addAll(latLngPoints) + + aMap.addPolyline(options.width(5f).color(Color.RED)) + } + } + } + } + } + //获取所有窨井数据 wellViewModel.getWellList() wellViewModel.totalWellModel.observe(this) { if (it.code == 200) { + /** + * 所有的marker + */ + val allMarkerOptions = ArrayList() val latitudeList: MutableList = ArrayList() val longitudeList: MutableList = ArrayList() it.data?.forEach { well -> @@ -136,33 +167,28 @@ longitudeList.add(longitude) //将所有设备信息转化缓存为Marker点 allMarkerOptions.add( - MarkerOptions().position(LatLng(latitude, longitude)) - .title(well.wellTypeName).snippet(well.wellName) + MarkerOptions() + .position(LatLng(latitude, longitude)) + .title(well.wellTypeName) + .snippet(well.wellName) ) } } } -// LocationHelper.obtainCurrentLocation(requireContext(), object : ILocationListener { -// override fun onAMapLocationGet(aMapLocation: AMapLocation?) { -// if (aMapLocation != null) { -// val centerLatLng = LatLng(aMapLocation.latitude, aMapLocation.longitude) -// //移动到指定经纬度 -// val cameraPosition = CameraPosition(centerLatLng, 12f, 0f, 0f) -// val cameraUpdate = CameraUpdateFactory.newCameraPosition(cameraPosition) -// aMap.animateCamera(cameraUpdate, 1500, null) -// } -// } -// }, false) //计算所有点的中心点位置 val centerLatLng = LatLng(latitudeList.average(), longitudeList.average()) //移动到指定经纬度 - val cameraPosition = CameraPosition(centerLatLng, 16f, 0f, 0f) + val cameraPosition = CameraPosition(centerLatLng, 14f, 0f, 0f) val cameraUpdate = CameraUpdateFactory.newCameraPosition(cameraPosition) aMap.animateCamera(cameraUpdate, 1500, null) - //显示点数据 - displayWellOnMap() + //采用协程显示点数据 + lifecycleScope.launch(Dispatchers.IO) { + allMarkerOptions.forEach { marker -> + aMap.addMarker(marker) + } + } } } @@ -252,50 +278,23 @@ } override fun observeRequestState() { + wellViewModel.loadState.observe(this) { + when (it) { + is LoadState.Loading -> LoadingDialogHub.show( + requireActivity(), "数据加载中,请稍后..." + ) + else -> LoadingDialogHub.dismiss() + } + } } override fun onCameraChange(p0: CameraPosition?) { } - /** - * http请求计时器 - * */ - private val httpCountDownTimer = object : CountDownTimer(15 * 1000, 1000) { - override fun onFinish() { - "请求服务器超时,请退出后重试".show(requireContext()) - LoadingDialogHub.dismiss() - } - - override fun onTick(millisUntilFinished: Long) { - - } - } - - //获取视野内的marker 根据聚合算法合成自定义的marker 显示视野内的marker override fun onCameraChangeFinish(p0: CameraPosition?) { - //地图缩放之后显示聚合点数据 - LoadingDialogHub.dismiss() - httpCountDownTimer.cancel() - } - private fun displayWellOnMap() { - val proj = aMap.projection - val dm = resources.displayMetrics - var screenLocation: Point - markerOptionsInView.clear() - // 获取在当前视野内的marker - 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.well_location).bitmap)) - markerOptionsInView.add(it) - } - } - markerOptionsInView.forEach { - aMap.addMarker(it) - } } override fun onMarkerClick(marker: Marker?): Boolean { @@ -316,9 +315,9 @@ val locationView = v.findViewById(R.id.locationView) //绑定数据 - val clickedLatLng = marker?.position!! + val clicked = marker?.position!! wellModels.forEach { well -> - if (clickedLatLng.latitude == well.latGaode!!.toDouble() && clickedLatLng.longitude == well.lngGaode!!.toDouble()) { + if (clicked.latitude == well.latGaode!!.toDouble() && clicked.longitude == well.lngGaode!!.toDouble()) { wellNameView.text = String.format("点位名称: ${well.wellName}") wellCodeView.text = String.format("点位编号: ${well.wellCode}") wellTypeView.text = String.format("点位类型: ${well.wellType.valueToType()}") @@ -340,8 +339,8 @@ * */ override fun getInfoContents(p0: Marker?): View? = null - override fun onInfoWindowClick(p0: Marker?) { - p0?.apply { + override fun onInfoWindowClick(marker: Marker?) { + marker?.apply { AlertControlDialog.Builder().setContext(requireContext()).setTitle("操作提示") .setMessage("确定要前往吗").setNegativeButton("取消").setPositiveButton("确定") .setOnDialogButtonClickListener(object : diff --git a/app/src/main/java/com/casic/app/smartwell/model/PipelineModel.java b/app/src/main/java/com/casic/app/smartwell/model/PipelineModel.java index 215ac0c..bac4925 100644 --- a/app/src/main/java/com/casic/app/smartwell/model/PipelineModel.java +++ b/app/src/main/java/com/casic/app/smartwell/model/PipelineModel.java @@ -5,7 +5,7 @@ public class PipelineModel { private Integer code; - private DataModel data; + private List data; private String message; private Boolean success; @@ -17,11 +17,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; } @@ -42,287 +42,50 @@ } public static class DataModel { - private List rows; - private Integer total; + private String endLatitudeGd; + private String endLongitudeGd; + private String pipeCode; + private String startLatitudeGd; + private String startLongitudeGd; - public List getRows() { - return rows; + public String getEndLatitudeGd() { + return endLatitudeGd; } - public void setRows(List rows) { - this.rows = rows; + public void setEndLatitudeGd(String endLatitudeGd) { + this.endLatitudeGd = endLatitudeGd; } - public Integer getTotal() { - return total; + public String getEndLongitudeGd() { + return endLongitudeGd; } - public void setTotal(Integer total) { - this.total = total; + public void setEndLongitudeGd(String endLongitudeGd) { + this.endLongitudeGd = endLongitudeGd; } - public static class RowsModel { - private String buryMode; - private String constructEra; - private String deptName; - private String deptid; - private String designPressure; - private String endBuryDeep; - private String endGroundHeight; - private String endLatitude; - private String endLatitudeGd; - private String endLongitude; - private String endLongitudeGd; - private String endPipecrownHeight; - private String id; - private String instantaneousFlow; - private String material; - private String pipeDiameter; - private String pipelineCode; - private String pipelineName; - private String pipelinePosition; - private String pipelineType; - private String pipelineTypeName; - private String startBuryDeep; - private String startGroundHeight; - private String startLatitude; - private String startLatitudeGd; - private String startLongitude; - private String startLongitudeGd; - private String startPipecrownHeight; - private String ts; + public String getPipeCode() { + return pipeCode; + } - public String getBuryMode() { - return buryMode; - } + public void setPipeCode(String pipeCode) { + this.pipeCode = pipeCode; + } - public void setBuryMode(String buryMode) { - this.buryMode = buryMode; - } + public String getStartLatitudeGd() { + return startLatitudeGd; + } - public String getConstructEra() { - return constructEra; - } + public void setStartLatitudeGd(String startLatitudeGd) { + this.startLatitudeGd = startLatitudeGd; + } - public void setConstructEra(String constructEra) { - this.constructEra = constructEra; - } + public String getStartLongitudeGd() { + return startLongitudeGd; + } - public String getDeptName() { - return deptName; - } - - public void setDeptName(String deptName) { - this.deptName = deptName; - } - - public String getDeptid() { - return deptid; - } - - public void setDeptid(String deptid) { - this.deptid = deptid; - } - - public String getDesignPressure() { - return designPressure; - } - - public void setDesignPressure(String designPressure) { - this.designPressure = designPressure; - } - - public String getEndBuryDeep() { - return endBuryDeep; - } - - public void setEndBuryDeep(String endBuryDeep) { - this.endBuryDeep = endBuryDeep; - } - - public String getEndGroundHeight() { - return endGroundHeight; - } - - public void setEndGroundHeight(String endGroundHeight) { - this.endGroundHeight = endGroundHeight; - } - - public String getEndLatitude() { - return endLatitude; - } - - public void setEndLatitude(String endLatitude) { - this.endLatitude = endLatitude; - } - - public String getEndLatitudeGd() { - return endLatitudeGd; - } - - public void setEndLatitudeGd(String endLatitudeGd) { - this.endLatitudeGd = endLatitudeGd; - } - - public String getEndLongitude() { - return endLongitude; - } - - public void setEndLongitude(String endLongitude) { - this.endLongitude = endLongitude; - } - - public String getEndLongitudeGd() { - return endLongitudeGd; - } - - public void setEndLongitudeGd(String endLongitudeGd) { - this.endLongitudeGd = endLongitudeGd; - } - - public String getEndPipecrownHeight() { - return endPipecrownHeight; - } - - public void setEndPipecrownHeight(String endPipecrownHeight) { - this.endPipecrownHeight = endPipecrownHeight; - } - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public String getInstantaneousFlow() { - return instantaneousFlow; - } - - public void setInstantaneousFlow(String instantaneousFlow) { - this.instantaneousFlow = instantaneousFlow; - } - - public String getMaterial() { - return material; - } - - public void setMaterial(String material) { - this.material = material; - } - - public String getPipeDiameter() { - return pipeDiameter; - } - - public void setPipeDiameter(String pipeDiameter) { - this.pipeDiameter = pipeDiameter; - } - - public String getPipelineCode() { - return pipelineCode; - } - - public void setPipelineCode(String pipelineCode) { - this.pipelineCode = pipelineCode; - } - - public String getPipelineName() { - return pipelineName; - } - - public void setPipelineName(String pipelineName) { - this.pipelineName = pipelineName; - } - - public String getPipelinePosition() { - return pipelinePosition; - } - - public void setPipelinePosition(String pipelinePosition) { - this.pipelinePosition = pipelinePosition; - } - - public String getPipelineType() { - return pipelineType; - } - - public void setPipelineType(String pipelineType) { - this.pipelineType = pipelineType; - } - - public String getPipelineTypeName() { - return pipelineTypeName; - } - - public void setPipelineTypeName(String pipelineTypeName) { - this.pipelineTypeName = pipelineTypeName; - } - - public String getStartBuryDeep() { - return startBuryDeep; - } - - public void setStartBuryDeep(String startBuryDeep) { - this.startBuryDeep = startBuryDeep; - } - - public String getStartGroundHeight() { - return startGroundHeight; - } - - public void setStartGroundHeight(String startGroundHeight) { - this.startGroundHeight = startGroundHeight; - } - - public String getStartLatitude() { - return startLatitude; - } - - public void setStartLatitude(String startLatitude) { - this.startLatitude = startLatitude; - } - - public String getStartLatitudeGd() { - return startLatitudeGd; - } - - public void setStartLatitudeGd(String startLatitudeGd) { - this.startLatitudeGd = startLatitudeGd; - } - - public String getStartLongitude() { - return startLongitude; - } - - public void setStartLongitude(String startLongitude) { - this.startLongitude = startLongitude; - } - - public String getStartLongitudeGd() { - return startLongitudeGd; - } - - public void setStartLongitudeGd(String startLongitudeGd) { - this.startLongitudeGd = startLongitudeGd; - } - - public String getStartPipecrownHeight() { - return startPipecrownHeight; - } - - public void setStartPipecrownHeight(String startPipecrownHeight) { - this.startPipecrownHeight = startPipecrownHeight; - } - - public String getTs() { - return ts; - } - - public void setTs(String ts) { - this.ts = ts; - } + public void setStartLongitudeGd(String startLongitudeGd) { + this.startLongitudeGd = startLongitudeGd; } } } diff --git a/app/src/main/java/com/casic/app/smartwell/utils/LocaleConstant.kt b/app/src/main/java/com/casic/app/smartwell/utils/LocaleConstant.kt index f20782c..22e9e65 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/LocaleConstant.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/LocaleConstant.kt @@ -29,7 +29,7 @@ } const val FIVE_YEARS = 5L * 365 * 60 * 60 * 24 * 1000L - const val RADIUS_SIZE = 80 //相距多少米才聚合,单位:米 + const val RADIUS_SIZE = 100 //相距多少米才聚合,单位:米 const val PERMISSIONS_CODE = 999 const val PAGE_LIMIT = 20 const val PUSH_REGISTER = 2022082901 @@ -39,7 +39,7 @@ const val DEFAULT_SERVER_CONFIG = "defaultServerConfig" const val DEFAULT_SERVER = "http://60.208.121.150:5001" -// const val DEFAULT_SERVER = "http://111.198.10.15:11638" +// const val DEFAULT_SERVER = "http://192.168.75.39:11308" const val USER_DETAIL_MODEL = "userDetailModel" const val APP_AUTHORITY = "com.casic.zq.smartwell.fileprovider" diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt index 991e1db..82bef29 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt @@ -316,7 +316,7 @@ /** * 管线位置数据 */ - @GET("/pipeline/listPage") + @GET("/pipeline/appList") suspend fun getPipeline( @Header("token") token: String, @Query("limit") limit: Int, diff --git a/app/src/main/java/com/casic/app/smartwell/view/MainActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/MainActivity.kt index 4ca5a5e..9270fa1 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/MainActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/MainActivity.kt @@ -10,7 +10,7 @@ import com.casic.app.smartwell.R import com.casic.app.smartwell.adapter.ViewPagerAdapter import com.casic.app.smartwell.databinding.ActivityMainBinding -import com.casic.app.smartwell.fragment.HomePageHaveClusterFragment +import com.casic.app.smartwell.fragment.HomePageNoClusterFragment import com.casic.app.smartwell.fragment.MinePageFragment import com.casic.app.smartwell.fragment.NoticePageFragment import com.casic.app.smartwell.fragment.OrderListFragment @@ -34,8 +34,8 @@ private lateinit var pushViewModel: PushViewModel init { -// fragmentPages.add(HomePageNoClusterFragment()) - fragmentPages.add(HomePageHaveClusterFragment()) + fragmentPages.add(HomePageNoClusterFragment()) +// fragmentPages.add(HomePageHaveClusterFragment()) fragmentPages.add(OrderListFragment()) fragmentPages.add(NoticePageFragment()) fragmentPages.add(MinePageFragment()) diff --git a/app/src/main/java/com/casic/app/smartwell/fragment/HomePageHaveClusterFragment.kt b/app/src/main/java/com/casic/app/smartwell/fragment/HomePageHaveClusterFragment.kt index 06bd542..b1b0d6e 100644 --- a/app/src/main/java/com/casic/app/smartwell/fragment/HomePageHaveClusterFragment.kt +++ b/app/src/main/java/com/casic/app/smartwell/fragment/HomePageHaveClusterFragment.kt @@ -4,7 +4,6 @@ import android.graphics.drawable.BitmapDrawable import android.graphics.drawable.Drawable import android.os.Bundle -import android.util.Log import android.view.LayoutInflater import android.view.ViewGroup import androidx.lifecycle.ViewModelProvider @@ -117,10 +116,8 @@ lineViewModel.lineResult.observe(this) { if (it.code == 200) { //点太多,必须采用协程(线程也行) - it.data.rows.forEach { dot -> - if (dot.startLatitudeGd.isNullOrBlank() || dot.startLongitudeGd.isNullOrBlank()) { - Log.d(kTag, "initOnCreate => ${dot.pipelineName}起点经纬度为空") - } else { + it.data.forEach { dot -> + if (!dot.startLatitudeGd.isNullOrBlank() && !dot.startLongitudeGd.isNullOrBlank()) { if (CoordinateConverter.isAMapDataAvailable( dot.startLatitudeGd.toDouble(), dot.startLongitudeGd.toDouble() ) @@ -141,7 +138,7 @@ latLngPoints.add(endLatLng) val options = PolylineOptions().addAll(latLngPoints) - aMap.addPolyline(options.width(10f).color(Color.RED)) + aMap.addPolyline(options.width(5f).color(Color.RED)) } } } @@ -175,7 +172,7 @@ //计算所有点的中心点位置 val centerLatLng = LatLng(latitudeList.average(), longitudeList.average()) //移动到指定经纬度 - val cameraPosition = CameraPosition(centerLatLng, 16f, 0f, 0f) + val cameraPosition = CameraPosition(centerLatLng, 12f, 0f, 0f) val cameraUpdate = CameraUpdateFactory.newCameraPosition(cameraPosition) aMap.animateCamera(cameraUpdate, 1500, null) @@ -294,7 +291,7 @@ clusterOverlay = ClusterOverlay(requireContext(), aMap, clusterItems, regionRadius) clusterOverlay?.setClusterRender { clusterNum -> //聚合圆半径 - val radius = 100.dp2px(requireContext()) + val radius = 80.dp2px(requireContext()) if (clusterNum == 0) { var bitmapDrawable = backDrawables[0] if (bitmapDrawable == null) { diff --git a/app/src/main/java/com/casic/app/smartwell/fragment/HomePageNoClusterFragment.kt b/app/src/main/java/com/casic/app/smartwell/fragment/HomePageNoClusterFragment.kt index bfa7a57..67ccf3a 100644 --- a/app/src/main/java/com/casic/app/smartwell/fragment/HomePageNoClusterFragment.kt +++ b/app/src/main/java/com/casic/app/smartwell/fragment/HomePageNoClusterFragment.kt @@ -1,22 +1,22 @@ package com.casic.app.smartwell.fragment -import android.graphics.Point +import android.graphics.Color import android.os.Bundle -import android.os.CountDownTimer import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import android.widget.TextView import androidx.lifecycle.ViewModelProvider +import androidx.lifecycle.lifecycleScope 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 import com.amap.api.maps.model.Marker import com.amap.api.maps.model.MarkerOptions +import com.amap.api.maps.model.PolylineOptions import com.casic.app.smartwell.R import com.casic.app.smartwell.databinding.FragmentHomeBinding import com.casic.app.smartwell.extensions.initImmersionBar @@ -30,15 +30,19 @@ import com.casic.app.smartwell.view.WellManagementActivity import com.casic.app.smartwell.view.WellOperationActivity import com.casic.app.smartwell.vm.OrderViewModel +import com.casic.app.smartwell.vm.PipelineViewModel import com.casic.app.smartwell.vm.WellViewModel import com.pengxh.kt.lite.adapter.NormalRecyclerAdapter import com.pengxh.kt.lite.adapter.ViewHolder import com.pengxh.kt.lite.base.KotlinBaseFragment import com.pengxh.kt.lite.extensions.navigatePageTo import com.pengxh.kt.lite.extensions.show +import com.pengxh.kt.lite.utils.LoadState import com.pengxh.kt.lite.utils.LoadingDialogHub import com.pengxh.kt.lite.widget.EasyPopupWindow import com.pengxh.kt.lite.widget.dialog.AlertControlDialog +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.launch /** * 地图点位不带聚合效果 @@ -51,19 +55,10 @@ private val easyPopupWindow by lazy { EasyPopupWindow(requireContext()) } private lateinit var wellViewModel: WellViewModel private lateinit var orderViewModel: OrderViewModel + private lateinit var lineViewModel: PipelineViewModel private lateinit var aMap: AMap /** - * 所有的marker - */ - private var allMarkerOptions: MutableList = ArrayList() - - /** - * 视野内的marker - */ - private var markerOptionsInView: MutableList = ArrayList() - - /** * 自定义Marker弹出框 * */ private lateinit var v: View @@ -105,20 +100,56 @@ } }) - //初始化vm - wellViewModel = ViewModelProvider(this)[WellViewModel::class.java] - orderViewModel = ViewModelProvider(this)[OrderViewModel::class.java] - //地图初始化 initMap(savedInstanceState) - //获取所有窨井数据 - httpCountDownTimer.start() - LoadingDialogHub.show(requireActivity(), "数据加载中,请稍后...") + //初始化vm + wellViewModel = ViewModelProvider(this)[WellViewModel::class.java] + orderViewModel = ViewModelProvider(this)[OrderViewModel::class.java] + lineViewModel = ViewModelProvider(this)[PipelineViewModel::class.java] + + //获取管线数据 + lineViewModel.getPipeline() + lineViewModel.lineResult.observe(this) { + if (it.code == 200) { + //点太多,必须采用协程(线程也行) + it.data.forEach { dot -> + if (!dot.startLatitudeGd.isNullOrBlank() && !dot.startLongitudeGd.isNullOrBlank()) { + if (CoordinateConverter.isAMapDataAvailable( + dot.startLatitudeGd.toDouble(), dot.startLongitudeGd.toDouble() + ) + ) { + //瞄点画线 + val latLngPoints = ArrayList() + + val startLatLng = LatLng( + dot.startLatitudeGd.toDouble(), + dot.startLongitudeGd.toDouble() + ) + + val endLatLng = LatLng( + dot.endLatitudeGd.toDouble(), + dot.endLongitudeGd.toDouble() + ) + latLngPoints.add(startLatLng) + latLngPoints.add(endLatLng) + val options = PolylineOptions().addAll(latLngPoints) + + aMap.addPolyline(options.width(5f).color(Color.RED)) + } + } + } + } + } + //获取所有窨井数据 wellViewModel.getWellList() wellViewModel.totalWellModel.observe(this) { if (it.code == 200) { + /** + * 所有的marker + */ + val allMarkerOptions = ArrayList() val latitudeList: MutableList = ArrayList() val longitudeList: MutableList = ArrayList() it.data?.forEach { well -> @@ -136,33 +167,28 @@ longitudeList.add(longitude) //将所有设备信息转化缓存为Marker点 allMarkerOptions.add( - MarkerOptions().position(LatLng(latitude, longitude)) - .title(well.wellTypeName).snippet(well.wellName) + MarkerOptions() + .position(LatLng(latitude, longitude)) + .title(well.wellTypeName) + .snippet(well.wellName) ) } } } -// LocationHelper.obtainCurrentLocation(requireContext(), object : ILocationListener { -// override fun onAMapLocationGet(aMapLocation: AMapLocation?) { -// if (aMapLocation != null) { -// val centerLatLng = LatLng(aMapLocation.latitude, aMapLocation.longitude) -// //移动到指定经纬度 -// val cameraPosition = CameraPosition(centerLatLng, 12f, 0f, 0f) -// val cameraUpdate = CameraUpdateFactory.newCameraPosition(cameraPosition) -// aMap.animateCamera(cameraUpdate, 1500, null) -// } -// } -// }, false) //计算所有点的中心点位置 val centerLatLng = LatLng(latitudeList.average(), longitudeList.average()) //移动到指定经纬度 - val cameraPosition = CameraPosition(centerLatLng, 16f, 0f, 0f) + val cameraPosition = CameraPosition(centerLatLng, 14f, 0f, 0f) val cameraUpdate = CameraUpdateFactory.newCameraPosition(cameraPosition) aMap.animateCamera(cameraUpdate, 1500, null) - //显示点数据 - displayWellOnMap() + //采用协程显示点数据 + lifecycleScope.launch(Dispatchers.IO) { + allMarkerOptions.forEach { marker -> + aMap.addMarker(marker) + } + } } } @@ -252,50 +278,23 @@ } override fun observeRequestState() { + wellViewModel.loadState.observe(this) { + when (it) { + is LoadState.Loading -> LoadingDialogHub.show( + requireActivity(), "数据加载中,请稍后..." + ) + else -> LoadingDialogHub.dismiss() + } + } } override fun onCameraChange(p0: CameraPosition?) { } - /** - * http请求计时器 - * */ - private val httpCountDownTimer = object : CountDownTimer(15 * 1000, 1000) { - override fun onFinish() { - "请求服务器超时,请退出后重试".show(requireContext()) - LoadingDialogHub.dismiss() - } - - override fun onTick(millisUntilFinished: Long) { - - } - } - - //获取视野内的marker 根据聚合算法合成自定义的marker 显示视野内的marker override fun onCameraChangeFinish(p0: CameraPosition?) { - //地图缩放之后显示聚合点数据 - LoadingDialogHub.dismiss() - httpCountDownTimer.cancel() - } - private fun displayWellOnMap() { - val proj = aMap.projection - val dm = resources.displayMetrics - var screenLocation: Point - markerOptionsInView.clear() - // 获取在当前视野内的marker - 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.well_location).bitmap)) - markerOptionsInView.add(it) - } - } - markerOptionsInView.forEach { - aMap.addMarker(it) - } } override fun onMarkerClick(marker: Marker?): Boolean { @@ -316,9 +315,9 @@ val locationView = v.findViewById(R.id.locationView) //绑定数据 - val clickedLatLng = marker?.position!! + val clicked = marker?.position!! wellModels.forEach { well -> - if (clickedLatLng.latitude == well.latGaode!!.toDouble() && clickedLatLng.longitude == well.lngGaode!!.toDouble()) { + if (clicked.latitude == well.latGaode!!.toDouble() && clicked.longitude == well.lngGaode!!.toDouble()) { wellNameView.text = String.format("点位名称: ${well.wellName}") wellCodeView.text = String.format("点位编号: ${well.wellCode}") wellTypeView.text = String.format("点位类型: ${well.wellType.valueToType()}") @@ -340,8 +339,8 @@ * */ override fun getInfoContents(p0: Marker?): View? = null - override fun onInfoWindowClick(p0: Marker?) { - p0?.apply { + override fun onInfoWindowClick(marker: Marker?) { + marker?.apply { AlertControlDialog.Builder().setContext(requireContext()).setTitle("操作提示") .setMessage("确定要前往吗").setNegativeButton("取消").setPositiveButton("确定") .setOnDialogButtonClickListener(object : diff --git a/app/src/main/java/com/casic/app/smartwell/model/PipelineModel.java b/app/src/main/java/com/casic/app/smartwell/model/PipelineModel.java index 215ac0c..bac4925 100644 --- a/app/src/main/java/com/casic/app/smartwell/model/PipelineModel.java +++ b/app/src/main/java/com/casic/app/smartwell/model/PipelineModel.java @@ -5,7 +5,7 @@ public class PipelineModel { private Integer code; - private DataModel data; + private List data; private String message; private Boolean success; @@ -17,11 +17,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; } @@ -42,287 +42,50 @@ } public static class DataModel { - private List rows; - private Integer total; + private String endLatitudeGd; + private String endLongitudeGd; + private String pipeCode; + private String startLatitudeGd; + private String startLongitudeGd; - public List getRows() { - return rows; + public String getEndLatitudeGd() { + return endLatitudeGd; } - public void setRows(List rows) { - this.rows = rows; + public void setEndLatitudeGd(String endLatitudeGd) { + this.endLatitudeGd = endLatitudeGd; } - public Integer getTotal() { - return total; + public String getEndLongitudeGd() { + return endLongitudeGd; } - public void setTotal(Integer total) { - this.total = total; + public void setEndLongitudeGd(String endLongitudeGd) { + this.endLongitudeGd = endLongitudeGd; } - public static class RowsModel { - private String buryMode; - private String constructEra; - private String deptName; - private String deptid; - private String designPressure; - private String endBuryDeep; - private String endGroundHeight; - private String endLatitude; - private String endLatitudeGd; - private String endLongitude; - private String endLongitudeGd; - private String endPipecrownHeight; - private String id; - private String instantaneousFlow; - private String material; - private String pipeDiameter; - private String pipelineCode; - private String pipelineName; - private String pipelinePosition; - private String pipelineType; - private String pipelineTypeName; - private String startBuryDeep; - private String startGroundHeight; - private String startLatitude; - private String startLatitudeGd; - private String startLongitude; - private String startLongitudeGd; - private String startPipecrownHeight; - private String ts; + public String getPipeCode() { + return pipeCode; + } - public String getBuryMode() { - return buryMode; - } + public void setPipeCode(String pipeCode) { + this.pipeCode = pipeCode; + } - public void setBuryMode(String buryMode) { - this.buryMode = buryMode; - } + public String getStartLatitudeGd() { + return startLatitudeGd; + } - public String getConstructEra() { - return constructEra; - } + public void setStartLatitudeGd(String startLatitudeGd) { + this.startLatitudeGd = startLatitudeGd; + } - public void setConstructEra(String constructEra) { - this.constructEra = constructEra; - } + public String getStartLongitudeGd() { + return startLongitudeGd; + } - public String getDeptName() { - return deptName; - } - - public void setDeptName(String deptName) { - this.deptName = deptName; - } - - public String getDeptid() { - return deptid; - } - - public void setDeptid(String deptid) { - this.deptid = deptid; - } - - public String getDesignPressure() { - return designPressure; - } - - public void setDesignPressure(String designPressure) { - this.designPressure = designPressure; - } - - public String getEndBuryDeep() { - return endBuryDeep; - } - - public void setEndBuryDeep(String endBuryDeep) { - this.endBuryDeep = endBuryDeep; - } - - public String getEndGroundHeight() { - return endGroundHeight; - } - - public void setEndGroundHeight(String endGroundHeight) { - this.endGroundHeight = endGroundHeight; - } - - public String getEndLatitude() { - return endLatitude; - } - - public void setEndLatitude(String endLatitude) { - this.endLatitude = endLatitude; - } - - public String getEndLatitudeGd() { - return endLatitudeGd; - } - - public void setEndLatitudeGd(String endLatitudeGd) { - this.endLatitudeGd = endLatitudeGd; - } - - public String getEndLongitude() { - return endLongitude; - } - - public void setEndLongitude(String endLongitude) { - this.endLongitude = endLongitude; - } - - public String getEndLongitudeGd() { - return endLongitudeGd; - } - - public void setEndLongitudeGd(String endLongitudeGd) { - this.endLongitudeGd = endLongitudeGd; - } - - public String getEndPipecrownHeight() { - return endPipecrownHeight; - } - - public void setEndPipecrownHeight(String endPipecrownHeight) { - this.endPipecrownHeight = endPipecrownHeight; - } - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public String getInstantaneousFlow() { - return instantaneousFlow; - } - - public void setInstantaneousFlow(String instantaneousFlow) { - this.instantaneousFlow = instantaneousFlow; - } - - public String getMaterial() { - return material; - } - - public void setMaterial(String material) { - this.material = material; - } - - public String getPipeDiameter() { - return pipeDiameter; - } - - public void setPipeDiameter(String pipeDiameter) { - this.pipeDiameter = pipeDiameter; - } - - public String getPipelineCode() { - return pipelineCode; - } - - public void setPipelineCode(String pipelineCode) { - this.pipelineCode = pipelineCode; - } - - public String getPipelineName() { - return pipelineName; - } - - public void setPipelineName(String pipelineName) { - this.pipelineName = pipelineName; - } - - public String getPipelinePosition() { - return pipelinePosition; - } - - public void setPipelinePosition(String pipelinePosition) { - this.pipelinePosition = pipelinePosition; - } - - public String getPipelineType() { - return pipelineType; - } - - public void setPipelineType(String pipelineType) { - this.pipelineType = pipelineType; - } - - public String getPipelineTypeName() { - return pipelineTypeName; - } - - public void setPipelineTypeName(String pipelineTypeName) { - this.pipelineTypeName = pipelineTypeName; - } - - public String getStartBuryDeep() { - return startBuryDeep; - } - - public void setStartBuryDeep(String startBuryDeep) { - this.startBuryDeep = startBuryDeep; - } - - public String getStartGroundHeight() { - return startGroundHeight; - } - - public void setStartGroundHeight(String startGroundHeight) { - this.startGroundHeight = startGroundHeight; - } - - public String getStartLatitude() { - return startLatitude; - } - - public void setStartLatitude(String startLatitude) { - this.startLatitude = startLatitude; - } - - public String getStartLatitudeGd() { - return startLatitudeGd; - } - - public void setStartLatitudeGd(String startLatitudeGd) { - this.startLatitudeGd = startLatitudeGd; - } - - public String getStartLongitude() { - return startLongitude; - } - - public void setStartLongitude(String startLongitude) { - this.startLongitude = startLongitude; - } - - public String getStartLongitudeGd() { - return startLongitudeGd; - } - - public void setStartLongitudeGd(String startLongitudeGd) { - this.startLongitudeGd = startLongitudeGd; - } - - public String getStartPipecrownHeight() { - return startPipecrownHeight; - } - - public void setStartPipecrownHeight(String startPipecrownHeight) { - this.startPipecrownHeight = startPipecrownHeight; - } - - public String getTs() { - return ts; - } - - public void setTs(String ts) { - this.ts = ts; - } + public void setStartLongitudeGd(String startLongitudeGd) { + this.startLongitudeGd = startLongitudeGd; } } } diff --git a/app/src/main/java/com/casic/app/smartwell/utils/LocaleConstant.kt b/app/src/main/java/com/casic/app/smartwell/utils/LocaleConstant.kt index f20782c..22e9e65 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/LocaleConstant.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/LocaleConstant.kt @@ -29,7 +29,7 @@ } const val FIVE_YEARS = 5L * 365 * 60 * 60 * 24 * 1000L - const val RADIUS_SIZE = 80 //相距多少米才聚合,单位:米 + const val RADIUS_SIZE = 100 //相距多少米才聚合,单位:米 const val PERMISSIONS_CODE = 999 const val PAGE_LIMIT = 20 const val PUSH_REGISTER = 2022082901 @@ -39,7 +39,7 @@ const val DEFAULT_SERVER_CONFIG = "defaultServerConfig" const val DEFAULT_SERVER = "http://60.208.121.150:5001" -// const val DEFAULT_SERVER = "http://111.198.10.15:11638" +// const val DEFAULT_SERVER = "http://192.168.75.39:11308" const val USER_DETAIL_MODEL = "userDetailModel" const val APP_AUTHORITY = "com.casic.zq.smartwell.fileprovider" diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt index 991e1db..82bef29 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt @@ -316,7 +316,7 @@ /** * 管线位置数据 */ - @GET("/pipeline/listPage") + @GET("/pipeline/appList") suspend fun getPipeline( @Header("token") token: String, @Query("limit") limit: Int, diff --git a/app/src/main/java/com/casic/app/smartwell/view/MainActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/MainActivity.kt index 4ca5a5e..9270fa1 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/MainActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/MainActivity.kt @@ -10,7 +10,7 @@ import com.casic.app.smartwell.R import com.casic.app.smartwell.adapter.ViewPagerAdapter import com.casic.app.smartwell.databinding.ActivityMainBinding -import com.casic.app.smartwell.fragment.HomePageHaveClusterFragment +import com.casic.app.smartwell.fragment.HomePageNoClusterFragment import com.casic.app.smartwell.fragment.MinePageFragment import com.casic.app.smartwell.fragment.NoticePageFragment import com.casic.app.smartwell.fragment.OrderListFragment @@ -34,8 +34,8 @@ private lateinit var pushViewModel: PushViewModel init { -// fragmentPages.add(HomePageNoClusterFragment()) - fragmentPages.add(HomePageHaveClusterFragment()) + fragmentPages.add(HomePageNoClusterFragment()) +// fragmentPages.add(HomePageHaveClusterFragment()) fragmentPages.add(OrderListFragment()) fragmentPages.add(NoticePageFragment()) fragmentPages.add(MinePageFragment()) diff --git a/app/src/main/java/com/casic/app/smartwell/widgets/MapWellPopup.kt b/app/src/main/java/com/casic/app/smartwell/widgets/MapWellPopup.kt index ec455dd..c7fde24 100644 --- a/app/src/main/java/com/casic/app/smartwell/widgets/MapWellPopup.kt +++ b/app/src/main/java/com/casic/app/smartwell/widgets/MapWellPopup.kt @@ -20,7 +20,7 @@ animationStyle = R.style.MapPopupAnimation setBackgroundDrawable(null) contentView = LayoutInflater.from(context).inflate( - R.layout.popup_map_info, null, false + R.layout.popup_map_info_2, null, false ) } diff --git a/app/src/main/java/com/casic/app/smartwell/fragment/HomePageHaveClusterFragment.kt b/app/src/main/java/com/casic/app/smartwell/fragment/HomePageHaveClusterFragment.kt index 06bd542..b1b0d6e 100644 --- a/app/src/main/java/com/casic/app/smartwell/fragment/HomePageHaveClusterFragment.kt +++ b/app/src/main/java/com/casic/app/smartwell/fragment/HomePageHaveClusterFragment.kt @@ -4,7 +4,6 @@ import android.graphics.drawable.BitmapDrawable import android.graphics.drawable.Drawable import android.os.Bundle -import android.util.Log import android.view.LayoutInflater import android.view.ViewGroup import androidx.lifecycle.ViewModelProvider @@ -117,10 +116,8 @@ lineViewModel.lineResult.observe(this) { if (it.code == 200) { //点太多,必须采用协程(线程也行) - it.data.rows.forEach { dot -> - if (dot.startLatitudeGd.isNullOrBlank() || dot.startLongitudeGd.isNullOrBlank()) { - Log.d(kTag, "initOnCreate => ${dot.pipelineName}起点经纬度为空") - } else { + it.data.forEach { dot -> + if (!dot.startLatitudeGd.isNullOrBlank() && !dot.startLongitudeGd.isNullOrBlank()) { if (CoordinateConverter.isAMapDataAvailable( dot.startLatitudeGd.toDouble(), dot.startLongitudeGd.toDouble() ) @@ -141,7 +138,7 @@ latLngPoints.add(endLatLng) val options = PolylineOptions().addAll(latLngPoints) - aMap.addPolyline(options.width(10f).color(Color.RED)) + aMap.addPolyline(options.width(5f).color(Color.RED)) } } } @@ -175,7 +172,7 @@ //计算所有点的中心点位置 val centerLatLng = LatLng(latitudeList.average(), longitudeList.average()) //移动到指定经纬度 - val cameraPosition = CameraPosition(centerLatLng, 16f, 0f, 0f) + val cameraPosition = CameraPosition(centerLatLng, 12f, 0f, 0f) val cameraUpdate = CameraUpdateFactory.newCameraPosition(cameraPosition) aMap.animateCamera(cameraUpdate, 1500, null) @@ -294,7 +291,7 @@ clusterOverlay = ClusterOverlay(requireContext(), aMap, clusterItems, regionRadius) clusterOverlay?.setClusterRender { clusterNum -> //聚合圆半径 - val radius = 100.dp2px(requireContext()) + val radius = 80.dp2px(requireContext()) if (clusterNum == 0) { var bitmapDrawable = backDrawables[0] if (bitmapDrawable == null) { diff --git a/app/src/main/java/com/casic/app/smartwell/fragment/HomePageNoClusterFragment.kt b/app/src/main/java/com/casic/app/smartwell/fragment/HomePageNoClusterFragment.kt index bfa7a57..67ccf3a 100644 --- a/app/src/main/java/com/casic/app/smartwell/fragment/HomePageNoClusterFragment.kt +++ b/app/src/main/java/com/casic/app/smartwell/fragment/HomePageNoClusterFragment.kt @@ -1,22 +1,22 @@ package com.casic.app.smartwell.fragment -import android.graphics.Point +import android.graphics.Color import android.os.Bundle -import android.os.CountDownTimer import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import android.widget.TextView import androidx.lifecycle.ViewModelProvider +import androidx.lifecycle.lifecycleScope 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 import com.amap.api.maps.model.Marker import com.amap.api.maps.model.MarkerOptions +import com.amap.api.maps.model.PolylineOptions import com.casic.app.smartwell.R import com.casic.app.smartwell.databinding.FragmentHomeBinding import com.casic.app.smartwell.extensions.initImmersionBar @@ -30,15 +30,19 @@ import com.casic.app.smartwell.view.WellManagementActivity import com.casic.app.smartwell.view.WellOperationActivity import com.casic.app.smartwell.vm.OrderViewModel +import com.casic.app.smartwell.vm.PipelineViewModel import com.casic.app.smartwell.vm.WellViewModel import com.pengxh.kt.lite.adapter.NormalRecyclerAdapter import com.pengxh.kt.lite.adapter.ViewHolder import com.pengxh.kt.lite.base.KotlinBaseFragment import com.pengxh.kt.lite.extensions.navigatePageTo import com.pengxh.kt.lite.extensions.show +import com.pengxh.kt.lite.utils.LoadState import com.pengxh.kt.lite.utils.LoadingDialogHub import com.pengxh.kt.lite.widget.EasyPopupWindow import com.pengxh.kt.lite.widget.dialog.AlertControlDialog +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.launch /** * 地图点位不带聚合效果 @@ -51,19 +55,10 @@ private val easyPopupWindow by lazy { EasyPopupWindow(requireContext()) } private lateinit var wellViewModel: WellViewModel private lateinit var orderViewModel: OrderViewModel + private lateinit var lineViewModel: PipelineViewModel private lateinit var aMap: AMap /** - * 所有的marker - */ - private var allMarkerOptions: MutableList = ArrayList() - - /** - * 视野内的marker - */ - private var markerOptionsInView: MutableList = ArrayList() - - /** * 自定义Marker弹出框 * */ private lateinit var v: View @@ -105,20 +100,56 @@ } }) - //初始化vm - wellViewModel = ViewModelProvider(this)[WellViewModel::class.java] - orderViewModel = ViewModelProvider(this)[OrderViewModel::class.java] - //地图初始化 initMap(savedInstanceState) - //获取所有窨井数据 - httpCountDownTimer.start() - LoadingDialogHub.show(requireActivity(), "数据加载中,请稍后...") + //初始化vm + wellViewModel = ViewModelProvider(this)[WellViewModel::class.java] + orderViewModel = ViewModelProvider(this)[OrderViewModel::class.java] + lineViewModel = ViewModelProvider(this)[PipelineViewModel::class.java] + + //获取管线数据 + lineViewModel.getPipeline() + lineViewModel.lineResult.observe(this) { + if (it.code == 200) { + //点太多,必须采用协程(线程也行) + it.data.forEach { dot -> + if (!dot.startLatitudeGd.isNullOrBlank() && !dot.startLongitudeGd.isNullOrBlank()) { + if (CoordinateConverter.isAMapDataAvailable( + dot.startLatitudeGd.toDouble(), dot.startLongitudeGd.toDouble() + ) + ) { + //瞄点画线 + val latLngPoints = ArrayList() + + val startLatLng = LatLng( + dot.startLatitudeGd.toDouble(), + dot.startLongitudeGd.toDouble() + ) + + val endLatLng = LatLng( + dot.endLatitudeGd.toDouble(), + dot.endLongitudeGd.toDouble() + ) + latLngPoints.add(startLatLng) + latLngPoints.add(endLatLng) + val options = PolylineOptions().addAll(latLngPoints) + + aMap.addPolyline(options.width(5f).color(Color.RED)) + } + } + } + } + } + //获取所有窨井数据 wellViewModel.getWellList() wellViewModel.totalWellModel.observe(this) { if (it.code == 200) { + /** + * 所有的marker + */ + val allMarkerOptions = ArrayList() val latitudeList: MutableList = ArrayList() val longitudeList: MutableList = ArrayList() it.data?.forEach { well -> @@ -136,33 +167,28 @@ longitudeList.add(longitude) //将所有设备信息转化缓存为Marker点 allMarkerOptions.add( - MarkerOptions().position(LatLng(latitude, longitude)) - .title(well.wellTypeName).snippet(well.wellName) + MarkerOptions() + .position(LatLng(latitude, longitude)) + .title(well.wellTypeName) + .snippet(well.wellName) ) } } } -// LocationHelper.obtainCurrentLocation(requireContext(), object : ILocationListener { -// override fun onAMapLocationGet(aMapLocation: AMapLocation?) { -// if (aMapLocation != null) { -// val centerLatLng = LatLng(aMapLocation.latitude, aMapLocation.longitude) -// //移动到指定经纬度 -// val cameraPosition = CameraPosition(centerLatLng, 12f, 0f, 0f) -// val cameraUpdate = CameraUpdateFactory.newCameraPosition(cameraPosition) -// aMap.animateCamera(cameraUpdate, 1500, null) -// } -// } -// }, false) //计算所有点的中心点位置 val centerLatLng = LatLng(latitudeList.average(), longitudeList.average()) //移动到指定经纬度 - val cameraPosition = CameraPosition(centerLatLng, 16f, 0f, 0f) + val cameraPosition = CameraPosition(centerLatLng, 14f, 0f, 0f) val cameraUpdate = CameraUpdateFactory.newCameraPosition(cameraPosition) aMap.animateCamera(cameraUpdate, 1500, null) - //显示点数据 - displayWellOnMap() + //采用协程显示点数据 + lifecycleScope.launch(Dispatchers.IO) { + allMarkerOptions.forEach { marker -> + aMap.addMarker(marker) + } + } } } @@ -252,50 +278,23 @@ } override fun observeRequestState() { + wellViewModel.loadState.observe(this) { + when (it) { + is LoadState.Loading -> LoadingDialogHub.show( + requireActivity(), "数据加载中,请稍后..." + ) + else -> LoadingDialogHub.dismiss() + } + } } override fun onCameraChange(p0: CameraPosition?) { } - /** - * http请求计时器 - * */ - private val httpCountDownTimer = object : CountDownTimer(15 * 1000, 1000) { - override fun onFinish() { - "请求服务器超时,请退出后重试".show(requireContext()) - LoadingDialogHub.dismiss() - } - - override fun onTick(millisUntilFinished: Long) { - - } - } - - //获取视野内的marker 根据聚合算法合成自定义的marker 显示视野内的marker override fun onCameraChangeFinish(p0: CameraPosition?) { - //地图缩放之后显示聚合点数据 - LoadingDialogHub.dismiss() - httpCountDownTimer.cancel() - } - private fun displayWellOnMap() { - val proj = aMap.projection - val dm = resources.displayMetrics - var screenLocation: Point - markerOptionsInView.clear() - // 获取在当前视野内的marker - 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.well_location).bitmap)) - markerOptionsInView.add(it) - } - } - markerOptionsInView.forEach { - aMap.addMarker(it) - } } override fun onMarkerClick(marker: Marker?): Boolean { @@ -316,9 +315,9 @@ val locationView = v.findViewById(R.id.locationView) //绑定数据 - val clickedLatLng = marker?.position!! + val clicked = marker?.position!! wellModels.forEach { well -> - if (clickedLatLng.latitude == well.latGaode!!.toDouble() && clickedLatLng.longitude == well.lngGaode!!.toDouble()) { + if (clicked.latitude == well.latGaode!!.toDouble() && clicked.longitude == well.lngGaode!!.toDouble()) { wellNameView.text = String.format("点位名称: ${well.wellName}") wellCodeView.text = String.format("点位编号: ${well.wellCode}") wellTypeView.text = String.format("点位类型: ${well.wellType.valueToType()}") @@ -340,8 +339,8 @@ * */ override fun getInfoContents(p0: Marker?): View? = null - override fun onInfoWindowClick(p0: Marker?) { - p0?.apply { + override fun onInfoWindowClick(marker: Marker?) { + marker?.apply { AlertControlDialog.Builder().setContext(requireContext()).setTitle("操作提示") .setMessage("确定要前往吗").setNegativeButton("取消").setPositiveButton("确定") .setOnDialogButtonClickListener(object : diff --git a/app/src/main/java/com/casic/app/smartwell/model/PipelineModel.java b/app/src/main/java/com/casic/app/smartwell/model/PipelineModel.java index 215ac0c..bac4925 100644 --- a/app/src/main/java/com/casic/app/smartwell/model/PipelineModel.java +++ b/app/src/main/java/com/casic/app/smartwell/model/PipelineModel.java @@ -5,7 +5,7 @@ public class PipelineModel { private Integer code; - private DataModel data; + private List data; private String message; private Boolean success; @@ -17,11 +17,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; } @@ -42,287 +42,50 @@ } public static class DataModel { - private List rows; - private Integer total; + private String endLatitudeGd; + private String endLongitudeGd; + private String pipeCode; + private String startLatitudeGd; + private String startLongitudeGd; - public List getRows() { - return rows; + public String getEndLatitudeGd() { + return endLatitudeGd; } - public void setRows(List rows) { - this.rows = rows; + public void setEndLatitudeGd(String endLatitudeGd) { + this.endLatitudeGd = endLatitudeGd; } - public Integer getTotal() { - return total; + public String getEndLongitudeGd() { + return endLongitudeGd; } - public void setTotal(Integer total) { - this.total = total; + public void setEndLongitudeGd(String endLongitudeGd) { + this.endLongitudeGd = endLongitudeGd; } - public static class RowsModel { - private String buryMode; - private String constructEra; - private String deptName; - private String deptid; - private String designPressure; - private String endBuryDeep; - private String endGroundHeight; - private String endLatitude; - private String endLatitudeGd; - private String endLongitude; - private String endLongitudeGd; - private String endPipecrownHeight; - private String id; - private String instantaneousFlow; - private String material; - private String pipeDiameter; - private String pipelineCode; - private String pipelineName; - private String pipelinePosition; - private String pipelineType; - private String pipelineTypeName; - private String startBuryDeep; - private String startGroundHeight; - private String startLatitude; - private String startLatitudeGd; - private String startLongitude; - private String startLongitudeGd; - private String startPipecrownHeight; - private String ts; + public String getPipeCode() { + return pipeCode; + } - public String getBuryMode() { - return buryMode; - } + public void setPipeCode(String pipeCode) { + this.pipeCode = pipeCode; + } - public void setBuryMode(String buryMode) { - this.buryMode = buryMode; - } + public String getStartLatitudeGd() { + return startLatitudeGd; + } - public String getConstructEra() { - return constructEra; - } + public void setStartLatitudeGd(String startLatitudeGd) { + this.startLatitudeGd = startLatitudeGd; + } - public void setConstructEra(String constructEra) { - this.constructEra = constructEra; - } + public String getStartLongitudeGd() { + return startLongitudeGd; + } - public String getDeptName() { - return deptName; - } - - public void setDeptName(String deptName) { - this.deptName = deptName; - } - - public String getDeptid() { - return deptid; - } - - public void setDeptid(String deptid) { - this.deptid = deptid; - } - - public String getDesignPressure() { - return designPressure; - } - - public void setDesignPressure(String designPressure) { - this.designPressure = designPressure; - } - - public String getEndBuryDeep() { - return endBuryDeep; - } - - public void setEndBuryDeep(String endBuryDeep) { - this.endBuryDeep = endBuryDeep; - } - - public String getEndGroundHeight() { - return endGroundHeight; - } - - public void setEndGroundHeight(String endGroundHeight) { - this.endGroundHeight = endGroundHeight; - } - - public String getEndLatitude() { - return endLatitude; - } - - public void setEndLatitude(String endLatitude) { - this.endLatitude = endLatitude; - } - - public String getEndLatitudeGd() { - return endLatitudeGd; - } - - public void setEndLatitudeGd(String endLatitudeGd) { - this.endLatitudeGd = endLatitudeGd; - } - - public String getEndLongitude() { - return endLongitude; - } - - public void setEndLongitude(String endLongitude) { - this.endLongitude = endLongitude; - } - - public String getEndLongitudeGd() { - return endLongitudeGd; - } - - public void setEndLongitudeGd(String endLongitudeGd) { - this.endLongitudeGd = endLongitudeGd; - } - - public String getEndPipecrownHeight() { - return endPipecrownHeight; - } - - public void setEndPipecrownHeight(String endPipecrownHeight) { - this.endPipecrownHeight = endPipecrownHeight; - } - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public String getInstantaneousFlow() { - return instantaneousFlow; - } - - public void setInstantaneousFlow(String instantaneousFlow) { - this.instantaneousFlow = instantaneousFlow; - } - - public String getMaterial() { - return material; - } - - public void setMaterial(String material) { - this.material = material; - } - - public String getPipeDiameter() { - return pipeDiameter; - } - - public void setPipeDiameter(String pipeDiameter) { - this.pipeDiameter = pipeDiameter; - } - - public String getPipelineCode() { - return pipelineCode; - } - - public void setPipelineCode(String pipelineCode) { - this.pipelineCode = pipelineCode; - } - - public String getPipelineName() { - return pipelineName; - } - - public void setPipelineName(String pipelineName) { - this.pipelineName = pipelineName; - } - - public String getPipelinePosition() { - return pipelinePosition; - } - - public void setPipelinePosition(String pipelinePosition) { - this.pipelinePosition = pipelinePosition; - } - - public String getPipelineType() { - return pipelineType; - } - - public void setPipelineType(String pipelineType) { - this.pipelineType = pipelineType; - } - - public String getPipelineTypeName() { - return pipelineTypeName; - } - - public void setPipelineTypeName(String pipelineTypeName) { - this.pipelineTypeName = pipelineTypeName; - } - - public String getStartBuryDeep() { - return startBuryDeep; - } - - public void setStartBuryDeep(String startBuryDeep) { - this.startBuryDeep = startBuryDeep; - } - - public String getStartGroundHeight() { - return startGroundHeight; - } - - public void setStartGroundHeight(String startGroundHeight) { - this.startGroundHeight = startGroundHeight; - } - - public String getStartLatitude() { - return startLatitude; - } - - public void setStartLatitude(String startLatitude) { - this.startLatitude = startLatitude; - } - - public String getStartLatitudeGd() { - return startLatitudeGd; - } - - public void setStartLatitudeGd(String startLatitudeGd) { - this.startLatitudeGd = startLatitudeGd; - } - - public String getStartLongitude() { - return startLongitude; - } - - public void setStartLongitude(String startLongitude) { - this.startLongitude = startLongitude; - } - - public String getStartLongitudeGd() { - return startLongitudeGd; - } - - public void setStartLongitudeGd(String startLongitudeGd) { - this.startLongitudeGd = startLongitudeGd; - } - - public String getStartPipecrownHeight() { - return startPipecrownHeight; - } - - public void setStartPipecrownHeight(String startPipecrownHeight) { - this.startPipecrownHeight = startPipecrownHeight; - } - - public String getTs() { - return ts; - } - - public void setTs(String ts) { - this.ts = ts; - } + public void setStartLongitudeGd(String startLongitudeGd) { + this.startLongitudeGd = startLongitudeGd; } } } diff --git a/app/src/main/java/com/casic/app/smartwell/utils/LocaleConstant.kt b/app/src/main/java/com/casic/app/smartwell/utils/LocaleConstant.kt index f20782c..22e9e65 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/LocaleConstant.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/LocaleConstant.kt @@ -29,7 +29,7 @@ } const val FIVE_YEARS = 5L * 365 * 60 * 60 * 24 * 1000L - const val RADIUS_SIZE = 80 //相距多少米才聚合,单位:米 + const val RADIUS_SIZE = 100 //相距多少米才聚合,单位:米 const val PERMISSIONS_CODE = 999 const val PAGE_LIMIT = 20 const val PUSH_REGISTER = 2022082901 @@ -39,7 +39,7 @@ const val DEFAULT_SERVER_CONFIG = "defaultServerConfig" const val DEFAULT_SERVER = "http://60.208.121.150:5001" -// const val DEFAULT_SERVER = "http://111.198.10.15:11638" +// const val DEFAULT_SERVER = "http://192.168.75.39:11308" const val USER_DETAIL_MODEL = "userDetailModel" const val APP_AUTHORITY = "com.casic.zq.smartwell.fileprovider" diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt index 991e1db..82bef29 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt @@ -316,7 +316,7 @@ /** * 管线位置数据 */ - @GET("/pipeline/listPage") + @GET("/pipeline/appList") suspend fun getPipeline( @Header("token") token: String, @Query("limit") limit: Int, diff --git a/app/src/main/java/com/casic/app/smartwell/view/MainActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/MainActivity.kt index 4ca5a5e..9270fa1 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/MainActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/MainActivity.kt @@ -10,7 +10,7 @@ import com.casic.app.smartwell.R import com.casic.app.smartwell.adapter.ViewPagerAdapter import com.casic.app.smartwell.databinding.ActivityMainBinding -import com.casic.app.smartwell.fragment.HomePageHaveClusterFragment +import com.casic.app.smartwell.fragment.HomePageNoClusterFragment import com.casic.app.smartwell.fragment.MinePageFragment import com.casic.app.smartwell.fragment.NoticePageFragment import com.casic.app.smartwell.fragment.OrderListFragment @@ -34,8 +34,8 @@ private lateinit var pushViewModel: PushViewModel init { -// fragmentPages.add(HomePageNoClusterFragment()) - fragmentPages.add(HomePageHaveClusterFragment()) + fragmentPages.add(HomePageNoClusterFragment()) +// fragmentPages.add(HomePageHaveClusterFragment()) fragmentPages.add(OrderListFragment()) fragmentPages.add(NoticePageFragment()) fragmentPages.add(MinePageFragment()) diff --git a/app/src/main/java/com/casic/app/smartwell/widgets/MapWellPopup.kt b/app/src/main/java/com/casic/app/smartwell/widgets/MapWellPopup.kt index ec455dd..c7fde24 100644 --- a/app/src/main/java/com/casic/app/smartwell/widgets/MapWellPopup.kt +++ b/app/src/main/java/com/casic/app/smartwell/widgets/MapWellPopup.kt @@ -20,7 +20,7 @@ animationStyle = R.style.MapPopupAnimation setBackgroundDrawable(null) contentView = LayoutInflater.from(context).inflate( - R.layout.popup_map_info, null, false + R.layout.popup_map_info_2, null, false ) } diff --git a/app/src/main/java/com/casic/app/smartwell/widgets/cluster/ClusterOverlay.java b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/ClusterOverlay.java index 40df562..0d95902 100644 --- a/app/src/main/java/com/casic/app/smartwell/widgets/cluster/ClusterOverlay.java +++ b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/ClusterOverlay.java @@ -271,8 +271,8 @@ textView.setText(tile); } textView.setGravity(Gravity.CENTER); - textView.setTextColor(Color.BLACK); - textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 15); + textView.setTextColor(Color.WHITE); + textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 16); if (clusterRender != null && clusterRender.getDrawableByCount(num) != null) { textView.setBackgroundDrawable(clusterRender.getDrawableByCount(num)); } else { diff --git a/app/src/main/java/com/casic/app/smartwell/fragment/HomePageHaveClusterFragment.kt b/app/src/main/java/com/casic/app/smartwell/fragment/HomePageHaveClusterFragment.kt index 06bd542..b1b0d6e 100644 --- a/app/src/main/java/com/casic/app/smartwell/fragment/HomePageHaveClusterFragment.kt +++ b/app/src/main/java/com/casic/app/smartwell/fragment/HomePageHaveClusterFragment.kt @@ -4,7 +4,6 @@ import android.graphics.drawable.BitmapDrawable import android.graphics.drawable.Drawable import android.os.Bundle -import android.util.Log import android.view.LayoutInflater import android.view.ViewGroup import androidx.lifecycle.ViewModelProvider @@ -117,10 +116,8 @@ lineViewModel.lineResult.observe(this) { if (it.code == 200) { //点太多,必须采用协程(线程也行) - it.data.rows.forEach { dot -> - if (dot.startLatitudeGd.isNullOrBlank() || dot.startLongitudeGd.isNullOrBlank()) { - Log.d(kTag, "initOnCreate => ${dot.pipelineName}起点经纬度为空") - } else { + it.data.forEach { dot -> + if (!dot.startLatitudeGd.isNullOrBlank() && !dot.startLongitudeGd.isNullOrBlank()) { if (CoordinateConverter.isAMapDataAvailable( dot.startLatitudeGd.toDouble(), dot.startLongitudeGd.toDouble() ) @@ -141,7 +138,7 @@ latLngPoints.add(endLatLng) val options = PolylineOptions().addAll(latLngPoints) - aMap.addPolyline(options.width(10f).color(Color.RED)) + aMap.addPolyline(options.width(5f).color(Color.RED)) } } } @@ -175,7 +172,7 @@ //计算所有点的中心点位置 val centerLatLng = LatLng(latitudeList.average(), longitudeList.average()) //移动到指定经纬度 - val cameraPosition = CameraPosition(centerLatLng, 16f, 0f, 0f) + val cameraPosition = CameraPosition(centerLatLng, 12f, 0f, 0f) val cameraUpdate = CameraUpdateFactory.newCameraPosition(cameraPosition) aMap.animateCamera(cameraUpdate, 1500, null) @@ -294,7 +291,7 @@ clusterOverlay = ClusterOverlay(requireContext(), aMap, clusterItems, regionRadius) clusterOverlay?.setClusterRender { clusterNum -> //聚合圆半径 - val radius = 100.dp2px(requireContext()) + val radius = 80.dp2px(requireContext()) if (clusterNum == 0) { var bitmapDrawable = backDrawables[0] if (bitmapDrawable == null) { diff --git a/app/src/main/java/com/casic/app/smartwell/fragment/HomePageNoClusterFragment.kt b/app/src/main/java/com/casic/app/smartwell/fragment/HomePageNoClusterFragment.kt index bfa7a57..67ccf3a 100644 --- a/app/src/main/java/com/casic/app/smartwell/fragment/HomePageNoClusterFragment.kt +++ b/app/src/main/java/com/casic/app/smartwell/fragment/HomePageNoClusterFragment.kt @@ -1,22 +1,22 @@ package com.casic.app.smartwell.fragment -import android.graphics.Point +import android.graphics.Color import android.os.Bundle -import android.os.CountDownTimer import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import android.widget.TextView import androidx.lifecycle.ViewModelProvider +import androidx.lifecycle.lifecycleScope 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 import com.amap.api.maps.model.Marker import com.amap.api.maps.model.MarkerOptions +import com.amap.api.maps.model.PolylineOptions import com.casic.app.smartwell.R import com.casic.app.smartwell.databinding.FragmentHomeBinding import com.casic.app.smartwell.extensions.initImmersionBar @@ -30,15 +30,19 @@ import com.casic.app.smartwell.view.WellManagementActivity import com.casic.app.smartwell.view.WellOperationActivity import com.casic.app.smartwell.vm.OrderViewModel +import com.casic.app.smartwell.vm.PipelineViewModel import com.casic.app.smartwell.vm.WellViewModel import com.pengxh.kt.lite.adapter.NormalRecyclerAdapter import com.pengxh.kt.lite.adapter.ViewHolder import com.pengxh.kt.lite.base.KotlinBaseFragment import com.pengxh.kt.lite.extensions.navigatePageTo import com.pengxh.kt.lite.extensions.show +import com.pengxh.kt.lite.utils.LoadState import com.pengxh.kt.lite.utils.LoadingDialogHub import com.pengxh.kt.lite.widget.EasyPopupWindow import com.pengxh.kt.lite.widget.dialog.AlertControlDialog +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.launch /** * 地图点位不带聚合效果 @@ -51,19 +55,10 @@ private val easyPopupWindow by lazy { EasyPopupWindow(requireContext()) } private lateinit var wellViewModel: WellViewModel private lateinit var orderViewModel: OrderViewModel + private lateinit var lineViewModel: PipelineViewModel private lateinit var aMap: AMap /** - * 所有的marker - */ - private var allMarkerOptions: MutableList = ArrayList() - - /** - * 视野内的marker - */ - private var markerOptionsInView: MutableList = ArrayList() - - /** * 自定义Marker弹出框 * */ private lateinit var v: View @@ -105,20 +100,56 @@ } }) - //初始化vm - wellViewModel = ViewModelProvider(this)[WellViewModel::class.java] - orderViewModel = ViewModelProvider(this)[OrderViewModel::class.java] - //地图初始化 initMap(savedInstanceState) - //获取所有窨井数据 - httpCountDownTimer.start() - LoadingDialogHub.show(requireActivity(), "数据加载中,请稍后...") + //初始化vm + wellViewModel = ViewModelProvider(this)[WellViewModel::class.java] + orderViewModel = ViewModelProvider(this)[OrderViewModel::class.java] + lineViewModel = ViewModelProvider(this)[PipelineViewModel::class.java] + + //获取管线数据 + lineViewModel.getPipeline() + lineViewModel.lineResult.observe(this) { + if (it.code == 200) { + //点太多,必须采用协程(线程也行) + it.data.forEach { dot -> + if (!dot.startLatitudeGd.isNullOrBlank() && !dot.startLongitudeGd.isNullOrBlank()) { + if (CoordinateConverter.isAMapDataAvailable( + dot.startLatitudeGd.toDouble(), dot.startLongitudeGd.toDouble() + ) + ) { + //瞄点画线 + val latLngPoints = ArrayList() + + val startLatLng = LatLng( + dot.startLatitudeGd.toDouble(), + dot.startLongitudeGd.toDouble() + ) + + val endLatLng = LatLng( + dot.endLatitudeGd.toDouble(), + dot.endLongitudeGd.toDouble() + ) + latLngPoints.add(startLatLng) + latLngPoints.add(endLatLng) + val options = PolylineOptions().addAll(latLngPoints) + + aMap.addPolyline(options.width(5f).color(Color.RED)) + } + } + } + } + } + //获取所有窨井数据 wellViewModel.getWellList() wellViewModel.totalWellModel.observe(this) { if (it.code == 200) { + /** + * 所有的marker + */ + val allMarkerOptions = ArrayList() val latitudeList: MutableList = ArrayList() val longitudeList: MutableList = ArrayList() it.data?.forEach { well -> @@ -136,33 +167,28 @@ longitudeList.add(longitude) //将所有设备信息转化缓存为Marker点 allMarkerOptions.add( - MarkerOptions().position(LatLng(latitude, longitude)) - .title(well.wellTypeName).snippet(well.wellName) + MarkerOptions() + .position(LatLng(latitude, longitude)) + .title(well.wellTypeName) + .snippet(well.wellName) ) } } } -// LocationHelper.obtainCurrentLocation(requireContext(), object : ILocationListener { -// override fun onAMapLocationGet(aMapLocation: AMapLocation?) { -// if (aMapLocation != null) { -// val centerLatLng = LatLng(aMapLocation.latitude, aMapLocation.longitude) -// //移动到指定经纬度 -// val cameraPosition = CameraPosition(centerLatLng, 12f, 0f, 0f) -// val cameraUpdate = CameraUpdateFactory.newCameraPosition(cameraPosition) -// aMap.animateCamera(cameraUpdate, 1500, null) -// } -// } -// }, false) //计算所有点的中心点位置 val centerLatLng = LatLng(latitudeList.average(), longitudeList.average()) //移动到指定经纬度 - val cameraPosition = CameraPosition(centerLatLng, 16f, 0f, 0f) + val cameraPosition = CameraPosition(centerLatLng, 14f, 0f, 0f) val cameraUpdate = CameraUpdateFactory.newCameraPosition(cameraPosition) aMap.animateCamera(cameraUpdate, 1500, null) - //显示点数据 - displayWellOnMap() + //采用协程显示点数据 + lifecycleScope.launch(Dispatchers.IO) { + allMarkerOptions.forEach { marker -> + aMap.addMarker(marker) + } + } } } @@ -252,50 +278,23 @@ } override fun observeRequestState() { + wellViewModel.loadState.observe(this) { + when (it) { + is LoadState.Loading -> LoadingDialogHub.show( + requireActivity(), "数据加载中,请稍后..." + ) + else -> LoadingDialogHub.dismiss() + } + } } override fun onCameraChange(p0: CameraPosition?) { } - /** - * http请求计时器 - * */ - private val httpCountDownTimer = object : CountDownTimer(15 * 1000, 1000) { - override fun onFinish() { - "请求服务器超时,请退出后重试".show(requireContext()) - LoadingDialogHub.dismiss() - } - - override fun onTick(millisUntilFinished: Long) { - - } - } - - //获取视野内的marker 根据聚合算法合成自定义的marker 显示视野内的marker override fun onCameraChangeFinish(p0: CameraPosition?) { - //地图缩放之后显示聚合点数据 - LoadingDialogHub.dismiss() - httpCountDownTimer.cancel() - } - private fun displayWellOnMap() { - val proj = aMap.projection - val dm = resources.displayMetrics - var screenLocation: Point - markerOptionsInView.clear() - // 获取在当前视野内的marker - 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.well_location).bitmap)) - markerOptionsInView.add(it) - } - } - markerOptionsInView.forEach { - aMap.addMarker(it) - } } override fun onMarkerClick(marker: Marker?): Boolean { @@ -316,9 +315,9 @@ val locationView = v.findViewById(R.id.locationView) //绑定数据 - val clickedLatLng = marker?.position!! + val clicked = marker?.position!! wellModels.forEach { well -> - if (clickedLatLng.latitude == well.latGaode!!.toDouble() && clickedLatLng.longitude == well.lngGaode!!.toDouble()) { + if (clicked.latitude == well.latGaode!!.toDouble() && clicked.longitude == well.lngGaode!!.toDouble()) { wellNameView.text = String.format("点位名称: ${well.wellName}") wellCodeView.text = String.format("点位编号: ${well.wellCode}") wellTypeView.text = String.format("点位类型: ${well.wellType.valueToType()}") @@ -340,8 +339,8 @@ * */ override fun getInfoContents(p0: Marker?): View? = null - override fun onInfoWindowClick(p0: Marker?) { - p0?.apply { + override fun onInfoWindowClick(marker: Marker?) { + marker?.apply { AlertControlDialog.Builder().setContext(requireContext()).setTitle("操作提示") .setMessage("确定要前往吗").setNegativeButton("取消").setPositiveButton("确定") .setOnDialogButtonClickListener(object : diff --git a/app/src/main/java/com/casic/app/smartwell/model/PipelineModel.java b/app/src/main/java/com/casic/app/smartwell/model/PipelineModel.java index 215ac0c..bac4925 100644 --- a/app/src/main/java/com/casic/app/smartwell/model/PipelineModel.java +++ b/app/src/main/java/com/casic/app/smartwell/model/PipelineModel.java @@ -5,7 +5,7 @@ public class PipelineModel { private Integer code; - private DataModel data; + private List data; private String message; private Boolean success; @@ -17,11 +17,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; } @@ -42,287 +42,50 @@ } public static class DataModel { - private List rows; - private Integer total; + private String endLatitudeGd; + private String endLongitudeGd; + private String pipeCode; + private String startLatitudeGd; + private String startLongitudeGd; - public List getRows() { - return rows; + public String getEndLatitudeGd() { + return endLatitudeGd; } - public void setRows(List rows) { - this.rows = rows; + public void setEndLatitudeGd(String endLatitudeGd) { + this.endLatitudeGd = endLatitudeGd; } - public Integer getTotal() { - return total; + public String getEndLongitudeGd() { + return endLongitudeGd; } - public void setTotal(Integer total) { - this.total = total; + public void setEndLongitudeGd(String endLongitudeGd) { + this.endLongitudeGd = endLongitudeGd; } - public static class RowsModel { - private String buryMode; - private String constructEra; - private String deptName; - private String deptid; - private String designPressure; - private String endBuryDeep; - private String endGroundHeight; - private String endLatitude; - private String endLatitudeGd; - private String endLongitude; - private String endLongitudeGd; - private String endPipecrownHeight; - private String id; - private String instantaneousFlow; - private String material; - private String pipeDiameter; - private String pipelineCode; - private String pipelineName; - private String pipelinePosition; - private String pipelineType; - private String pipelineTypeName; - private String startBuryDeep; - private String startGroundHeight; - private String startLatitude; - private String startLatitudeGd; - private String startLongitude; - private String startLongitudeGd; - private String startPipecrownHeight; - private String ts; + public String getPipeCode() { + return pipeCode; + } - public String getBuryMode() { - return buryMode; - } + public void setPipeCode(String pipeCode) { + this.pipeCode = pipeCode; + } - public void setBuryMode(String buryMode) { - this.buryMode = buryMode; - } + public String getStartLatitudeGd() { + return startLatitudeGd; + } - public String getConstructEra() { - return constructEra; - } + public void setStartLatitudeGd(String startLatitudeGd) { + this.startLatitudeGd = startLatitudeGd; + } - public void setConstructEra(String constructEra) { - this.constructEra = constructEra; - } + public String getStartLongitudeGd() { + return startLongitudeGd; + } - public String getDeptName() { - return deptName; - } - - public void setDeptName(String deptName) { - this.deptName = deptName; - } - - public String getDeptid() { - return deptid; - } - - public void setDeptid(String deptid) { - this.deptid = deptid; - } - - public String getDesignPressure() { - return designPressure; - } - - public void setDesignPressure(String designPressure) { - this.designPressure = designPressure; - } - - public String getEndBuryDeep() { - return endBuryDeep; - } - - public void setEndBuryDeep(String endBuryDeep) { - this.endBuryDeep = endBuryDeep; - } - - public String getEndGroundHeight() { - return endGroundHeight; - } - - public void setEndGroundHeight(String endGroundHeight) { - this.endGroundHeight = endGroundHeight; - } - - public String getEndLatitude() { - return endLatitude; - } - - public void setEndLatitude(String endLatitude) { - this.endLatitude = endLatitude; - } - - public String getEndLatitudeGd() { - return endLatitudeGd; - } - - public void setEndLatitudeGd(String endLatitudeGd) { - this.endLatitudeGd = endLatitudeGd; - } - - public String getEndLongitude() { - return endLongitude; - } - - public void setEndLongitude(String endLongitude) { - this.endLongitude = endLongitude; - } - - public String getEndLongitudeGd() { - return endLongitudeGd; - } - - public void setEndLongitudeGd(String endLongitudeGd) { - this.endLongitudeGd = endLongitudeGd; - } - - public String getEndPipecrownHeight() { - return endPipecrownHeight; - } - - public void setEndPipecrownHeight(String endPipecrownHeight) { - this.endPipecrownHeight = endPipecrownHeight; - } - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public String getInstantaneousFlow() { - return instantaneousFlow; - } - - public void setInstantaneousFlow(String instantaneousFlow) { - this.instantaneousFlow = instantaneousFlow; - } - - public String getMaterial() { - return material; - } - - public void setMaterial(String material) { - this.material = material; - } - - public String getPipeDiameter() { - return pipeDiameter; - } - - public void setPipeDiameter(String pipeDiameter) { - this.pipeDiameter = pipeDiameter; - } - - public String getPipelineCode() { - return pipelineCode; - } - - public void setPipelineCode(String pipelineCode) { - this.pipelineCode = pipelineCode; - } - - public String getPipelineName() { - return pipelineName; - } - - public void setPipelineName(String pipelineName) { - this.pipelineName = pipelineName; - } - - public String getPipelinePosition() { - return pipelinePosition; - } - - public void setPipelinePosition(String pipelinePosition) { - this.pipelinePosition = pipelinePosition; - } - - public String getPipelineType() { - return pipelineType; - } - - public void setPipelineType(String pipelineType) { - this.pipelineType = pipelineType; - } - - public String getPipelineTypeName() { - return pipelineTypeName; - } - - public void setPipelineTypeName(String pipelineTypeName) { - this.pipelineTypeName = pipelineTypeName; - } - - public String getStartBuryDeep() { - return startBuryDeep; - } - - public void setStartBuryDeep(String startBuryDeep) { - this.startBuryDeep = startBuryDeep; - } - - public String getStartGroundHeight() { - return startGroundHeight; - } - - public void setStartGroundHeight(String startGroundHeight) { - this.startGroundHeight = startGroundHeight; - } - - public String getStartLatitude() { - return startLatitude; - } - - public void setStartLatitude(String startLatitude) { - this.startLatitude = startLatitude; - } - - public String getStartLatitudeGd() { - return startLatitudeGd; - } - - public void setStartLatitudeGd(String startLatitudeGd) { - this.startLatitudeGd = startLatitudeGd; - } - - public String getStartLongitude() { - return startLongitude; - } - - public void setStartLongitude(String startLongitude) { - this.startLongitude = startLongitude; - } - - public String getStartLongitudeGd() { - return startLongitudeGd; - } - - public void setStartLongitudeGd(String startLongitudeGd) { - this.startLongitudeGd = startLongitudeGd; - } - - public String getStartPipecrownHeight() { - return startPipecrownHeight; - } - - public void setStartPipecrownHeight(String startPipecrownHeight) { - this.startPipecrownHeight = startPipecrownHeight; - } - - public String getTs() { - return ts; - } - - public void setTs(String ts) { - this.ts = ts; - } + public void setStartLongitudeGd(String startLongitudeGd) { + this.startLongitudeGd = startLongitudeGd; } } } diff --git a/app/src/main/java/com/casic/app/smartwell/utils/LocaleConstant.kt b/app/src/main/java/com/casic/app/smartwell/utils/LocaleConstant.kt index f20782c..22e9e65 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/LocaleConstant.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/LocaleConstant.kt @@ -29,7 +29,7 @@ } const val FIVE_YEARS = 5L * 365 * 60 * 60 * 24 * 1000L - const val RADIUS_SIZE = 80 //相距多少米才聚合,单位:米 + const val RADIUS_SIZE = 100 //相距多少米才聚合,单位:米 const val PERMISSIONS_CODE = 999 const val PAGE_LIMIT = 20 const val PUSH_REGISTER = 2022082901 @@ -39,7 +39,7 @@ const val DEFAULT_SERVER_CONFIG = "defaultServerConfig" const val DEFAULT_SERVER = "http://60.208.121.150:5001" -// const val DEFAULT_SERVER = "http://111.198.10.15:11638" +// const val DEFAULT_SERVER = "http://192.168.75.39:11308" const val USER_DETAIL_MODEL = "userDetailModel" const val APP_AUTHORITY = "com.casic.zq.smartwell.fileprovider" diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt index 991e1db..82bef29 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt @@ -316,7 +316,7 @@ /** * 管线位置数据 */ - @GET("/pipeline/listPage") + @GET("/pipeline/appList") suspend fun getPipeline( @Header("token") token: String, @Query("limit") limit: Int, diff --git a/app/src/main/java/com/casic/app/smartwell/view/MainActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/MainActivity.kt index 4ca5a5e..9270fa1 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/MainActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/MainActivity.kt @@ -10,7 +10,7 @@ import com.casic.app.smartwell.R import com.casic.app.smartwell.adapter.ViewPagerAdapter import com.casic.app.smartwell.databinding.ActivityMainBinding -import com.casic.app.smartwell.fragment.HomePageHaveClusterFragment +import com.casic.app.smartwell.fragment.HomePageNoClusterFragment import com.casic.app.smartwell.fragment.MinePageFragment import com.casic.app.smartwell.fragment.NoticePageFragment import com.casic.app.smartwell.fragment.OrderListFragment @@ -34,8 +34,8 @@ private lateinit var pushViewModel: PushViewModel init { -// fragmentPages.add(HomePageNoClusterFragment()) - fragmentPages.add(HomePageHaveClusterFragment()) + fragmentPages.add(HomePageNoClusterFragment()) +// fragmentPages.add(HomePageHaveClusterFragment()) fragmentPages.add(OrderListFragment()) fragmentPages.add(NoticePageFragment()) fragmentPages.add(MinePageFragment()) diff --git a/app/src/main/java/com/casic/app/smartwell/widgets/MapWellPopup.kt b/app/src/main/java/com/casic/app/smartwell/widgets/MapWellPopup.kt index ec455dd..c7fde24 100644 --- a/app/src/main/java/com/casic/app/smartwell/widgets/MapWellPopup.kt +++ b/app/src/main/java/com/casic/app/smartwell/widgets/MapWellPopup.kt @@ -20,7 +20,7 @@ animationStyle = R.style.MapPopupAnimation setBackgroundDrawable(null) contentView = LayoutInflater.from(context).inflate( - R.layout.popup_map_info, null, false + R.layout.popup_map_info_2, null, false ) } diff --git a/app/src/main/java/com/casic/app/smartwell/widgets/cluster/ClusterOverlay.java b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/ClusterOverlay.java index 40df562..0d95902 100644 --- a/app/src/main/java/com/casic/app/smartwell/widgets/cluster/ClusterOverlay.java +++ b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/ClusterOverlay.java @@ -271,8 +271,8 @@ textView.setText(tile); } textView.setGravity(Gravity.CENTER); - textView.setTextColor(Color.BLACK); - textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 15); + textView.setTextColor(Color.WHITE); + textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 16); if (clusterRender != null && clusterRender.getDrawableByCount(num) != null) { textView.setBackgroundDrawable(clusterRender.getDrawableByCount(num)); } else { diff --git a/app/src/main/res/drawable/bg_solid_layout_transparent_bottom_radius_5.xml b/app/src/main/res/drawable/bg_solid_layout_transparent_bottom_radius_5.xml new file mode 100644 index 0000000..18c1e99 --- /dev/null +++ b/app/src/main/res/drawable/bg_solid_layout_transparent_bottom_radius_5.xml @@ -0,0 +1,10 @@ + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/fragment/HomePageHaveClusterFragment.kt b/app/src/main/java/com/casic/app/smartwell/fragment/HomePageHaveClusterFragment.kt index 06bd542..b1b0d6e 100644 --- a/app/src/main/java/com/casic/app/smartwell/fragment/HomePageHaveClusterFragment.kt +++ b/app/src/main/java/com/casic/app/smartwell/fragment/HomePageHaveClusterFragment.kt @@ -4,7 +4,6 @@ import android.graphics.drawable.BitmapDrawable import android.graphics.drawable.Drawable import android.os.Bundle -import android.util.Log import android.view.LayoutInflater import android.view.ViewGroup import androidx.lifecycle.ViewModelProvider @@ -117,10 +116,8 @@ lineViewModel.lineResult.observe(this) { if (it.code == 200) { //点太多,必须采用协程(线程也行) - it.data.rows.forEach { dot -> - if (dot.startLatitudeGd.isNullOrBlank() || dot.startLongitudeGd.isNullOrBlank()) { - Log.d(kTag, "initOnCreate => ${dot.pipelineName}起点经纬度为空") - } else { + it.data.forEach { dot -> + if (!dot.startLatitudeGd.isNullOrBlank() && !dot.startLongitudeGd.isNullOrBlank()) { if (CoordinateConverter.isAMapDataAvailable( dot.startLatitudeGd.toDouble(), dot.startLongitudeGd.toDouble() ) @@ -141,7 +138,7 @@ latLngPoints.add(endLatLng) val options = PolylineOptions().addAll(latLngPoints) - aMap.addPolyline(options.width(10f).color(Color.RED)) + aMap.addPolyline(options.width(5f).color(Color.RED)) } } } @@ -175,7 +172,7 @@ //计算所有点的中心点位置 val centerLatLng = LatLng(latitudeList.average(), longitudeList.average()) //移动到指定经纬度 - val cameraPosition = CameraPosition(centerLatLng, 16f, 0f, 0f) + val cameraPosition = CameraPosition(centerLatLng, 12f, 0f, 0f) val cameraUpdate = CameraUpdateFactory.newCameraPosition(cameraPosition) aMap.animateCamera(cameraUpdate, 1500, null) @@ -294,7 +291,7 @@ clusterOverlay = ClusterOverlay(requireContext(), aMap, clusterItems, regionRadius) clusterOverlay?.setClusterRender { clusterNum -> //聚合圆半径 - val radius = 100.dp2px(requireContext()) + val radius = 80.dp2px(requireContext()) if (clusterNum == 0) { var bitmapDrawable = backDrawables[0] if (bitmapDrawable == null) { diff --git a/app/src/main/java/com/casic/app/smartwell/fragment/HomePageNoClusterFragment.kt b/app/src/main/java/com/casic/app/smartwell/fragment/HomePageNoClusterFragment.kt index bfa7a57..67ccf3a 100644 --- a/app/src/main/java/com/casic/app/smartwell/fragment/HomePageNoClusterFragment.kt +++ b/app/src/main/java/com/casic/app/smartwell/fragment/HomePageNoClusterFragment.kt @@ -1,22 +1,22 @@ package com.casic.app.smartwell.fragment -import android.graphics.Point +import android.graphics.Color import android.os.Bundle -import android.os.CountDownTimer import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import android.widget.TextView import androidx.lifecycle.ViewModelProvider +import androidx.lifecycle.lifecycleScope 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 import com.amap.api.maps.model.Marker import com.amap.api.maps.model.MarkerOptions +import com.amap.api.maps.model.PolylineOptions import com.casic.app.smartwell.R import com.casic.app.smartwell.databinding.FragmentHomeBinding import com.casic.app.smartwell.extensions.initImmersionBar @@ -30,15 +30,19 @@ import com.casic.app.smartwell.view.WellManagementActivity import com.casic.app.smartwell.view.WellOperationActivity import com.casic.app.smartwell.vm.OrderViewModel +import com.casic.app.smartwell.vm.PipelineViewModel import com.casic.app.smartwell.vm.WellViewModel import com.pengxh.kt.lite.adapter.NormalRecyclerAdapter import com.pengxh.kt.lite.adapter.ViewHolder import com.pengxh.kt.lite.base.KotlinBaseFragment import com.pengxh.kt.lite.extensions.navigatePageTo import com.pengxh.kt.lite.extensions.show +import com.pengxh.kt.lite.utils.LoadState import com.pengxh.kt.lite.utils.LoadingDialogHub import com.pengxh.kt.lite.widget.EasyPopupWindow import com.pengxh.kt.lite.widget.dialog.AlertControlDialog +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.launch /** * 地图点位不带聚合效果 @@ -51,19 +55,10 @@ private val easyPopupWindow by lazy { EasyPopupWindow(requireContext()) } private lateinit var wellViewModel: WellViewModel private lateinit var orderViewModel: OrderViewModel + private lateinit var lineViewModel: PipelineViewModel private lateinit var aMap: AMap /** - * 所有的marker - */ - private var allMarkerOptions: MutableList = ArrayList() - - /** - * 视野内的marker - */ - private var markerOptionsInView: MutableList = ArrayList() - - /** * 自定义Marker弹出框 * */ private lateinit var v: View @@ -105,20 +100,56 @@ } }) - //初始化vm - wellViewModel = ViewModelProvider(this)[WellViewModel::class.java] - orderViewModel = ViewModelProvider(this)[OrderViewModel::class.java] - //地图初始化 initMap(savedInstanceState) - //获取所有窨井数据 - httpCountDownTimer.start() - LoadingDialogHub.show(requireActivity(), "数据加载中,请稍后...") + //初始化vm + wellViewModel = ViewModelProvider(this)[WellViewModel::class.java] + orderViewModel = ViewModelProvider(this)[OrderViewModel::class.java] + lineViewModel = ViewModelProvider(this)[PipelineViewModel::class.java] + + //获取管线数据 + lineViewModel.getPipeline() + lineViewModel.lineResult.observe(this) { + if (it.code == 200) { + //点太多,必须采用协程(线程也行) + it.data.forEach { dot -> + if (!dot.startLatitudeGd.isNullOrBlank() && !dot.startLongitudeGd.isNullOrBlank()) { + if (CoordinateConverter.isAMapDataAvailable( + dot.startLatitudeGd.toDouble(), dot.startLongitudeGd.toDouble() + ) + ) { + //瞄点画线 + val latLngPoints = ArrayList() + + val startLatLng = LatLng( + dot.startLatitudeGd.toDouble(), + dot.startLongitudeGd.toDouble() + ) + + val endLatLng = LatLng( + dot.endLatitudeGd.toDouble(), + dot.endLongitudeGd.toDouble() + ) + latLngPoints.add(startLatLng) + latLngPoints.add(endLatLng) + val options = PolylineOptions().addAll(latLngPoints) + + aMap.addPolyline(options.width(5f).color(Color.RED)) + } + } + } + } + } + //获取所有窨井数据 wellViewModel.getWellList() wellViewModel.totalWellModel.observe(this) { if (it.code == 200) { + /** + * 所有的marker + */ + val allMarkerOptions = ArrayList() val latitudeList: MutableList = ArrayList() val longitudeList: MutableList = ArrayList() it.data?.forEach { well -> @@ -136,33 +167,28 @@ longitudeList.add(longitude) //将所有设备信息转化缓存为Marker点 allMarkerOptions.add( - MarkerOptions().position(LatLng(latitude, longitude)) - .title(well.wellTypeName).snippet(well.wellName) + MarkerOptions() + .position(LatLng(latitude, longitude)) + .title(well.wellTypeName) + .snippet(well.wellName) ) } } } -// LocationHelper.obtainCurrentLocation(requireContext(), object : ILocationListener { -// override fun onAMapLocationGet(aMapLocation: AMapLocation?) { -// if (aMapLocation != null) { -// val centerLatLng = LatLng(aMapLocation.latitude, aMapLocation.longitude) -// //移动到指定经纬度 -// val cameraPosition = CameraPosition(centerLatLng, 12f, 0f, 0f) -// val cameraUpdate = CameraUpdateFactory.newCameraPosition(cameraPosition) -// aMap.animateCamera(cameraUpdate, 1500, null) -// } -// } -// }, false) //计算所有点的中心点位置 val centerLatLng = LatLng(latitudeList.average(), longitudeList.average()) //移动到指定经纬度 - val cameraPosition = CameraPosition(centerLatLng, 16f, 0f, 0f) + val cameraPosition = CameraPosition(centerLatLng, 14f, 0f, 0f) val cameraUpdate = CameraUpdateFactory.newCameraPosition(cameraPosition) aMap.animateCamera(cameraUpdate, 1500, null) - //显示点数据 - displayWellOnMap() + //采用协程显示点数据 + lifecycleScope.launch(Dispatchers.IO) { + allMarkerOptions.forEach { marker -> + aMap.addMarker(marker) + } + } } } @@ -252,50 +278,23 @@ } override fun observeRequestState() { + wellViewModel.loadState.observe(this) { + when (it) { + is LoadState.Loading -> LoadingDialogHub.show( + requireActivity(), "数据加载中,请稍后..." + ) + else -> LoadingDialogHub.dismiss() + } + } } override fun onCameraChange(p0: CameraPosition?) { } - /** - * http请求计时器 - * */ - private val httpCountDownTimer = object : CountDownTimer(15 * 1000, 1000) { - override fun onFinish() { - "请求服务器超时,请退出后重试".show(requireContext()) - LoadingDialogHub.dismiss() - } - - override fun onTick(millisUntilFinished: Long) { - - } - } - - //获取视野内的marker 根据聚合算法合成自定义的marker 显示视野内的marker override fun onCameraChangeFinish(p0: CameraPosition?) { - //地图缩放之后显示聚合点数据 - LoadingDialogHub.dismiss() - httpCountDownTimer.cancel() - } - private fun displayWellOnMap() { - val proj = aMap.projection - val dm = resources.displayMetrics - var screenLocation: Point - markerOptionsInView.clear() - // 获取在当前视野内的marker - 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.well_location).bitmap)) - markerOptionsInView.add(it) - } - } - markerOptionsInView.forEach { - aMap.addMarker(it) - } } override fun onMarkerClick(marker: Marker?): Boolean { @@ -316,9 +315,9 @@ val locationView = v.findViewById(R.id.locationView) //绑定数据 - val clickedLatLng = marker?.position!! + val clicked = marker?.position!! wellModels.forEach { well -> - if (clickedLatLng.latitude == well.latGaode!!.toDouble() && clickedLatLng.longitude == well.lngGaode!!.toDouble()) { + if (clicked.latitude == well.latGaode!!.toDouble() && clicked.longitude == well.lngGaode!!.toDouble()) { wellNameView.text = String.format("点位名称: ${well.wellName}") wellCodeView.text = String.format("点位编号: ${well.wellCode}") wellTypeView.text = String.format("点位类型: ${well.wellType.valueToType()}") @@ -340,8 +339,8 @@ * */ override fun getInfoContents(p0: Marker?): View? = null - override fun onInfoWindowClick(p0: Marker?) { - p0?.apply { + override fun onInfoWindowClick(marker: Marker?) { + marker?.apply { AlertControlDialog.Builder().setContext(requireContext()).setTitle("操作提示") .setMessage("确定要前往吗").setNegativeButton("取消").setPositiveButton("确定") .setOnDialogButtonClickListener(object : diff --git a/app/src/main/java/com/casic/app/smartwell/model/PipelineModel.java b/app/src/main/java/com/casic/app/smartwell/model/PipelineModel.java index 215ac0c..bac4925 100644 --- a/app/src/main/java/com/casic/app/smartwell/model/PipelineModel.java +++ b/app/src/main/java/com/casic/app/smartwell/model/PipelineModel.java @@ -5,7 +5,7 @@ public class PipelineModel { private Integer code; - private DataModel data; + private List data; private String message; private Boolean success; @@ -17,11 +17,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; } @@ -42,287 +42,50 @@ } public static class DataModel { - private List rows; - private Integer total; + private String endLatitudeGd; + private String endLongitudeGd; + private String pipeCode; + private String startLatitudeGd; + private String startLongitudeGd; - public List getRows() { - return rows; + public String getEndLatitudeGd() { + return endLatitudeGd; } - public void setRows(List rows) { - this.rows = rows; + public void setEndLatitudeGd(String endLatitudeGd) { + this.endLatitudeGd = endLatitudeGd; } - public Integer getTotal() { - return total; + public String getEndLongitudeGd() { + return endLongitudeGd; } - public void setTotal(Integer total) { - this.total = total; + public void setEndLongitudeGd(String endLongitudeGd) { + this.endLongitudeGd = endLongitudeGd; } - public static class RowsModel { - private String buryMode; - private String constructEra; - private String deptName; - private String deptid; - private String designPressure; - private String endBuryDeep; - private String endGroundHeight; - private String endLatitude; - private String endLatitudeGd; - private String endLongitude; - private String endLongitudeGd; - private String endPipecrownHeight; - private String id; - private String instantaneousFlow; - private String material; - private String pipeDiameter; - private String pipelineCode; - private String pipelineName; - private String pipelinePosition; - private String pipelineType; - private String pipelineTypeName; - private String startBuryDeep; - private String startGroundHeight; - private String startLatitude; - private String startLatitudeGd; - private String startLongitude; - private String startLongitudeGd; - private String startPipecrownHeight; - private String ts; + public String getPipeCode() { + return pipeCode; + } - public String getBuryMode() { - return buryMode; - } + public void setPipeCode(String pipeCode) { + this.pipeCode = pipeCode; + } - public void setBuryMode(String buryMode) { - this.buryMode = buryMode; - } + public String getStartLatitudeGd() { + return startLatitudeGd; + } - public String getConstructEra() { - return constructEra; - } + public void setStartLatitudeGd(String startLatitudeGd) { + this.startLatitudeGd = startLatitudeGd; + } - public void setConstructEra(String constructEra) { - this.constructEra = constructEra; - } + public String getStartLongitudeGd() { + return startLongitudeGd; + } - public String getDeptName() { - return deptName; - } - - public void setDeptName(String deptName) { - this.deptName = deptName; - } - - public String getDeptid() { - return deptid; - } - - public void setDeptid(String deptid) { - this.deptid = deptid; - } - - public String getDesignPressure() { - return designPressure; - } - - public void setDesignPressure(String designPressure) { - this.designPressure = designPressure; - } - - public String getEndBuryDeep() { - return endBuryDeep; - } - - public void setEndBuryDeep(String endBuryDeep) { - this.endBuryDeep = endBuryDeep; - } - - public String getEndGroundHeight() { - return endGroundHeight; - } - - public void setEndGroundHeight(String endGroundHeight) { - this.endGroundHeight = endGroundHeight; - } - - public String getEndLatitude() { - return endLatitude; - } - - public void setEndLatitude(String endLatitude) { - this.endLatitude = endLatitude; - } - - public String getEndLatitudeGd() { - return endLatitudeGd; - } - - public void setEndLatitudeGd(String endLatitudeGd) { - this.endLatitudeGd = endLatitudeGd; - } - - public String getEndLongitude() { - return endLongitude; - } - - public void setEndLongitude(String endLongitude) { - this.endLongitude = endLongitude; - } - - public String getEndLongitudeGd() { - return endLongitudeGd; - } - - public void setEndLongitudeGd(String endLongitudeGd) { - this.endLongitudeGd = endLongitudeGd; - } - - public String getEndPipecrownHeight() { - return endPipecrownHeight; - } - - public void setEndPipecrownHeight(String endPipecrownHeight) { - this.endPipecrownHeight = endPipecrownHeight; - } - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public String getInstantaneousFlow() { - return instantaneousFlow; - } - - public void setInstantaneousFlow(String instantaneousFlow) { - this.instantaneousFlow = instantaneousFlow; - } - - public String getMaterial() { - return material; - } - - public void setMaterial(String material) { - this.material = material; - } - - public String getPipeDiameter() { - return pipeDiameter; - } - - public void setPipeDiameter(String pipeDiameter) { - this.pipeDiameter = pipeDiameter; - } - - public String getPipelineCode() { - return pipelineCode; - } - - public void setPipelineCode(String pipelineCode) { - this.pipelineCode = pipelineCode; - } - - public String getPipelineName() { - return pipelineName; - } - - public void setPipelineName(String pipelineName) { - this.pipelineName = pipelineName; - } - - public String getPipelinePosition() { - return pipelinePosition; - } - - public void setPipelinePosition(String pipelinePosition) { - this.pipelinePosition = pipelinePosition; - } - - public String getPipelineType() { - return pipelineType; - } - - public void setPipelineType(String pipelineType) { - this.pipelineType = pipelineType; - } - - public String getPipelineTypeName() { - return pipelineTypeName; - } - - public void setPipelineTypeName(String pipelineTypeName) { - this.pipelineTypeName = pipelineTypeName; - } - - public String getStartBuryDeep() { - return startBuryDeep; - } - - public void setStartBuryDeep(String startBuryDeep) { - this.startBuryDeep = startBuryDeep; - } - - public String getStartGroundHeight() { - return startGroundHeight; - } - - public void setStartGroundHeight(String startGroundHeight) { - this.startGroundHeight = startGroundHeight; - } - - public String getStartLatitude() { - return startLatitude; - } - - public void setStartLatitude(String startLatitude) { - this.startLatitude = startLatitude; - } - - public String getStartLatitudeGd() { - return startLatitudeGd; - } - - public void setStartLatitudeGd(String startLatitudeGd) { - this.startLatitudeGd = startLatitudeGd; - } - - public String getStartLongitude() { - return startLongitude; - } - - public void setStartLongitude(String startLongitude) { - this.startLongitude = startLongitude; - } - - public String getStartLongitudeGd() { - return startLongitudeGd; - } - - public void setStartLongitudeGd(String startLongitudeGd) { - this.startLongitudeGd = startLongitudeGd; - } - - public String getStartPipecrownHeight() { - return startPipecrownHeight; - } - - public void setStartPipecrownHeight(String startPipecrownHeight) { - this.startPipecrownHeight = startPipecrownHeight; - } - - public String getTs() { - return ts; - } - - public void setTs(String ts) { - this.ts = ts; - } + public void setStartLongitudeGd(String startLongitudeGd) { + this.startLongitudeGd = startLongitudeGd; } } } diff --git a/app/src/main/java/com/casic/app/smartwell/utils/LocaleConstant.kt b/app/src/main/java/com/casic/app/smartwell/utils/LocaleConstant.kt index f20782c..22e9e65 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/LocaleConstant.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/LocaleConstant.kt @@ -29,7 +29,7 @@ } const val FIVE_YEARS = 5L * 365 * 60 * 60 * 24 * 1000L - const val RADIUS_SIZE = 80 //相距多少米才聚合,单位:米 + const val RADIUS_SIZE = 100 //相距多少米才聚合,单位:米 const val PERMISSIONS_CODE = 999 const val PAGE_LIMIT = 20 const val PUSH_REGISTER = 2022082901 @@ -39,7 +39,7 @@ const val DEFAULT_SERVER_CONFIG = "defaultServerConfig" const val DEFAULT_SERVER = "http://60.208.121.150:5001" -// const val DEFAULT_SERVER = "http://111.198.10.15:11638" +// const val DEFAULT_SERVER = "http://192.168.75.39:11308" const val USER_DETAIL_MODEL = "userDetailModel" const val APP_AUTHORITY = "com.casic.zq.smartwell.fileprovider" diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt index 991e1db..82bef29 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt @@ -316,7 +316,7 @@ /** * 管线位置数据 */ - @GET("/pipeline/listPage") + @GET("/pipeline/appList") suspend fun getPipeline( @Header("token") token: String, @Query("limit") limit: Int, diff --git a/app/src/main/java/com/casic/app/smartwell/view/MainActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/MainActivity.kt index 4ca5a5e..9270fa1 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/MainActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/MainActivity.kt @@ -10,7 +10,7 @@ import com.casic.app.smartwell.R import com.casic.app.smartwell.adapter.ViewPagerAdapter import com.casic.app.smartwell.databinding.ActivityMainBinding -import com.casic.app.smartwell.fragment.HomePageHaveClusterFragment +import com.casic.app.smartwell.fragment.HomePageNoClusterFragment import com.casic.app.smartwell.fragment.MinePageFragment import com.casic.app.smartwell.fragment.NoticePageFragment import com.casic.app.smartwell.fragment.OrderListFragment @@ -34,8 +34,8 @@ private lateinit var pushViewModel: PushViewModel init { -// fragmentPages.add(HomePageNoClusterFragment()) - fragmentPages.add(HomePageHaveClusterFragment()) + fragmentPages.add(HomePageNoClusterFragment()) +// fragmentPages.add(HomePageHaveClusterFragment()) fragmentPages.add(OrderListFragment()) fragmentPages.add(NoticePageFragment()) fragmentPages.add(MinePageFragment()) diff --git a/app/src/main/java/com/casic/app/smartwell/widgets/MapWellPopup.kt b/app/src/main/java/com/casic/app/smartwell/widgets/MapWellPopup.kt index ec455dd..c7fde24 100644 --- a/app/src/main/java/com/casic/app/smartwell/widgets/MapWellPopup.kt +++ b/app/src/main/java/com/casic/app/smartwell/widgets/MapWellPopup.kt @@ -20,7 +20,7 @@ animationStyle = R.style.MapPopupAnimation setBackgroundDrawable(null) contentView = LayoutInflater.from(context).inflate( - R.layout.popup_map_info, null, false + R.layout.popup_map_info_2, null, false ) } diff --git a/app/src/main/java/com/casic/app/smartwell/widgets/cluster/ClusterOverlay.java b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/ClusterOverlay.java index 40df562..0d95902 100644 --- a/app/src/main/java/com/casic/app/smartwell/widgets/cluster/ClusterOverlay.java +++ b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/ClusterOverlay.java @@ -271,8 +271,8 @@ textView.setText(tile); } textView.setGravity(Gravity.CENTER); - textView.setTextColor(Color.BLACK); - textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 15); + textView.setTextColor(Color.WHITE); + textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 16); if (clusterRender != null && clusterRender.getDrawableByCount(num) != null) { textView.setBackgroundDrawable(clusterRender.getDrawableByCount(num)); } else { diff --git a/app/src/main/res/drawable/bg_solid_layout_transparent_bottom_radius_5.xml b/app/src/main/res/drawable/bg_solid_layout_transparent_bottom_radius_5.xml new file mode 100644 index 0000000..18c1e99 --- /dev/null +++ b/app/src/main/res/drawable/bg_solid_layout_transparent_bottom_radius_5.xml @@ -0,0 +1,10 @@ + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/bg_solid_layout_transparent_radius_5.xml b/app/src/main/res/drawable/bg_solid_layout_transparent_radius_5.xml index 18c1e99..cce39da 100644 --- a/app/src/main/res/drawable/bg_solid_layout_transparent_radius_5.xml +++ b/app/src/main/res/drawable/bg_solid_layout_transparent_radius_5.xml @@ -4,7 +4,5 @@ - + \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/fragment/HomePageHaveClusterFragment.kt b/app/src/main/java/com/casic/app/smartwell/fragment/HomePageHaveClusterFragment.kt index 06bd542..b1b0d6e 100644 --- a/app/src/main/java/com/casic/app/smartwell/fragment/HomePageHaveClusterFragment.kt +++ b/app/src/main/java/com/casic/app/smartwell/fragment/HomePageHaveClusterFragment.kt @@ -4,7 +4,6 @@ import android.graphics.drawable.BitmapDrawable import android.graphics.drawable.Drawable import android.os.Bundle -import android.util.Log import android.view.LayoutInflater import android.view.ViewGroup import androidx.lifecycle.ViewModelProvider @@ -117,10 +116,8 @@ lineViewModel.lineResult.observe(this) { if (it.code == 200) { //点太多,必须采用协程(线程也行) - it.data.rows.forEach { dot -> - if (dot.startLatitudeGd.isNullOrBlank() || dot.startLongitudeGd.isNullOrBlank()) { - Log.d(kTag, "initOnCreate => ${dot.pipelineName}起点经纬度为空") - } else { + it.data.forEach { dot -> + if (!dot.startLatitudeGd.isNullOrBlank() && !dot.startLongitudeGd.isNullOrBlank()) { if (CoordinateConverter.isAMapDataAvailable( dot.startLatitudeGd.toDouble(), dot.startLongitudeGd.toDouble() ) @@ -141,7 +138,7 @@ latLngPoints.add(endLatLng) val options = PolylineOptions().addAll(latLngPoints) - aMap.addPolyline(options.width(10f).color(Color.RED)) + aMap.addPolyline(options.width(5f).color(Color.RED)) } } } @@ -175,7 +172,7 @@ //计算所有点的中心点位置 val centerLatLng = LatLng(latitudeList.average(), longitudeList.average()) //移动到指定经纬度 - val cameraPosition = CameraPosition(centerLatLng, 16f, 0f, 0f) + val cameraPosition = CameraPosition(centerLatLng, 12f, 0f, 0f) val cameraUpdate = CameraUpdateFactory.newCameraPosition(cameraPosition) aMap.animateCamera(cameraUpdate, 1500, null) @@ -294,7 +291,7 @@ clusterOverlay = ClusterOverlay(requireContext(), aMap, clusterItems, regionRadius) clusterOverlay?.setClusterRender { clusterNum -> //聚合圆半径 - val radius = 100.dp2px(requireContext()) + val radius = 80.dp2px(requireContext()) if (clusterNum == 0) { var bitmapDrawable = backDrawables[0] if (bitmapDrawable == null) { diff --git a/app/src/main/java/com/casic/app/smartwell/fragment/HomePageNoClusterFragment.kt b/app/src/main/java/com/casic/app/smartwell/fragment/HomePageNoClusterFragment.kt index bfa7a57..67ccf3a 100644 --- a/app/src/main/java/com/casic/app/smartwell/fragment/HomePageNoClusterFragment.kt +++ b/app/src/main/java/com/casic/app/smartwell/fragment/HomePageNoClusterFragment.kt @@ -1,22 +1,22 @@ package com.casic.app.smartwell.fragment -import android.graphics.Point +import android.graphics.Color import android.os.Bundle -import android.os.CountDownTimer import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import android.widget.TextView import androidx.lifecycle.ViewModelProvider +import androidx.lifecycle.lifecycleScope 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 import com.amap.api.maps.model.Marker import com.amap.api.maps.model.MarkerOptions +import com.amap.api.maps.model.PolylineOptions import com.casic.app.smartwell.R import com.casic.app.smartwell.databinding.FragmentHomeBinding import com.casic.app.smartwell.extensions.initImmersionBar @@ -30,15 +30,19 @@ import com.casic.app.smartwell.view.WellManagementActivity import com.casic.app.smartwell.view.WellOperationActivity import com.casic.app.smartwell.vm.OrderViewModel +import com.casic.app.smartwell.vm.PipelineViewModel import com.casic.app.smartwell.vm.WellViewModel import com.pengxh.kt.lite.adapter.NormalRecyclerAdapter import com.pengxh.kt.lite.adapter.ViewHolder import com.pengxh.kt.lite.base.KotlinBaseFragment import com.pengxh.kt.lite.extensions.navigatePageTo import com.pengxh.kt.lite.extensions.show +import com.pengxh.kt.lite.utils.LoadState import com.pengxh.kt.lite.utils.LoadingDialogHub import com.pengxh.kt.lite.widget.EasyPopupWindow import com.pengxh.kt.lite.widget.dialog.AlertControlDialog +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.launch /** * 地图点位不带聚合效果 @@ -51,19 +55,10 @@ private val easyPopupWindow by lazy { EasyPopupWindow(requireContext()) } private lateinit var wellViewModel: WellViewModel private lateinit var orderViewModel: OrderViewModel + private lateinit var lineViewModel: PipelineViewModel private lateinit var aMap: AMap /** - * 所有的marker - */ - private var allMarkerOptions: MutableList = ArrayList() - - /** - * 视野内的marker - */ - private var markerOptionsInView: MutableList = ArrayList() - - /** * 自定义Marker弹出框 * */ private lateinit var v: View @@ -105,20 +100,56 @@ } }) - //初始化vm - wellViewModel = ViewModelProvider(this)[WellViewModel::class.java] - orderViewModel = ViewModelProvider(this)[OrderViewModel::class.java] - //地图初始化 initMap(savedInstanceState) - //获取所有窨井数据 - httpCountDownTimer.start() - LoadingDialogHub.show(requireActivity(), "数据加载中,请稍后...") + //初始化vm + wellViewModel = ViewModelProvider(this)[WellViewModel::class.java] + orderViewModel = ViewModelProvider(this)[OrderViewModel::class.java] + lineViewModel = ViewModelProvider(this)[PipelineViewModel::class.java] + + //获取管线数据 + lineViewModel.getPipeline() + lineViewModel.lineResult.observe(this) { + if (it.code == 200) { + //点太多,必须采用协程(线程也行) + it.data.forEach { dot -> + if (!dot.startLatitudeGd.isNullOrBlank() && !dot.startLongitudeGd.isNullOrBlank()) { + if (CoordinateConverter.isAMapDataAvailable( + dot.startLatitudeGd.toDouble(), dot.startLongitudeGd.toDouble() + ) + ) { + //瞄点画线 + val latLngPoints = ArrayList() + + val startLatLng = LatLng( + dot.startLatitudeGd.toDouble(), + dot.startLongitudeGd.toDouble() + ) + + val endLatLng = LatLng( + dot.endLatitudeGd.toDouble(), + dot.endLongitudeGd.toDouble() + ) + latLngPoints.add(startLatLng) + latLngPoints.add(endLatLng) + val options = PolylineOptions().addAll(latLngPoints) + + aMap.addPolyline(options.width(5f).color(Color.RED)) + } + } + } + } + } + //获取所有窨井数据 wellViewModel.getWellList() wellViewModel.totalWellModel.observe(this) { if (it.code == 200) { + /** + * 所有的marker + */ + val allMarkerOptions = ArrayList() val latitudeList: MutableList = ArrayList() val longitudeList: MutableList = ArrayList() it.data?.forEach { well -> @@ -136,33 +167,28 @@ longitudeList.add(longitude) //将所有设备信息转化缓存为Marker点 allMarkerOptions.add( - MarkerOptions().position(LatLng(latitude, longitude)) - .title(well.wellTypeName).snippet(well.wellName) + MarkerOptions() + .position(LatLng(latitude, longitude)) + .title(well.wellTypeName) + .snippet(well.wellName) ) } } } -// LocationHelper.obtainCurrentLocation(requireContext(), object : ILocationListener { -// override fun onAMapLocationGet(aMapLocation: AMapLocation?) { -// if (aMapLocation != null) { -// val centerLatLng = LatLng(aMapLocation.latitude, aMapLocation.longitude) -// //移动到指定经纬度 -// val cameraPosition = CameraPosition(centerLatLng, 12f, 0f, 0f) -// val cameraUpdate = CameraUpdateFactory.newCameraPosition(cameraPosition) -// aMap.animateCamera(cameraUpdate, 1500, null) -// } -// } -// }, false) //计算所有点的中心点位置 val centerLatLng = LatLng(latitudeList.average(), longitudeList.average()) //移动到指定经纬度 - val cameraPosition = CameraPosition(centerLatLng, 16f, 0f, 0f) + val cameraPosition = CameraPosition(centerLatLng, 14f, 0f, 0f) val cameraUpdate = CameraUpdateFactory.newCameraPosition(cameraPosition) aMap.animateCamera(cameraUpdate, 1500, null) - //显示点数据 - displayWellOnMap() + //采用协程显示点数据 + lifecycleScope.launch(Dispatchers.IO) { + allMarkerOptions.forEach { marker -> + aMap.addMarker(marker) + } + } } } @@ -252,50 +278,23 @@ } override fun observeRequestState() { + wellViewModel.loadState.observe(this) { + when (it) { + is LoadState.Loading -> LoadingDialogHub.show( + requireActivity(), "数据加载中,请稍后..." + ) + else -> LoadingDialogHub.dismiss() + } + } } override fun onCameraChange(p0: CameraPosition?) { } - /** - * http请求计时器 - * */ - private val httpCountDownTimer = object : CountDownTimer(15 * 1000, 1000) { - override fun onFinish() { - "请求服务器超时,请退出后重试".show(requireContext()) - LoadingDialogHub.dismiss() - } - - override fun onTick(millisUntilFinished: Long) { - - } - } - - //获取视野内的marker 根据聚合算法合成自定义的marker 显示视野内的marker override fun onCameraChangeFinish(p0: CameraPosition?) { - //地图缩放之后显示聚合点数据 - LoadingDialogHub.dismiss() - httpCountDownTimer.cancel() - } - private fun displayWellOnMap() { - val proj = aMap.projection - val dm = resources.displayMetrics - var screenLocation: Point - markerOptionsInView.clear() - // 获取在当前视野内的marker - 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.well_location).bitmap)) - markerOptionsInView.add(it) - } - } - markerOptionsInView.forEach { - aMap.addMarker(it) - } } override fun onMarkerClick(marker: Marker?): Boolean { @@ -316,9 +315,9 @@ val locationView = v.findViewById(R.id.locationView) //绑定数据 - val clickedLatLng = marker?.position!! + val clicked = marker?.position!! wellModels.forEach { well -> - if (clickedLatLng.latitude == well.latGaode!!.toDouble() && clickedLatLng.longitude == well.lngGaode!!.toDouble()) { + if (clicked.latitude == well.latGaode!!.toDouble() && clicked.longitude == well.lngGaode!!.toDouble()) { wellNameView.text = String.format("点位名称: ${well.wellName}") wellCodeView.text = String.format("点位编号: ${well.wellCode}") wellTypeView.text = String.format("点位类型: ${well.wellType.valueToType()}") @@ -340,8 +339,8 @@ * */ override fun getInfoContents(p0: Marker?): View? = null - override fun onInfoWindowClick(p0: Marker?) { - p0?.apply { + override fun onInfoWindowClick(marker: Marker?) { + marker?.apply { AlertControlDialog.Builder().setContext(requireContext()).setTitle("操作提示") .setMessage("确定要前往吗").setNegativeButton("取消").setPositiveButton("确定") .setOnDialogButtonClickListener(object : diff --git a/app/src/main/java/com/casic/app/smartwell/model/PipelineModel.java b/app/src/main/java/com/casic/app/smartwell/model/PipelineModel.java index 215ac0c..bac4925 100644 --- a/app/src/main/java/com/casic/app/smartwell/model/PipelineModel.java +++ b/app/src/main/java/com/casic/app/smartwell/model/PipelineModel.java @@ -5,7 +5,7 @@ public class PipelineModel { private Integer code; - private DataModel data; + private List data; private String message; private Boolean success; @@ -17,11 +17,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; } @@ -42,287 +42,50 @@ } public static class DataModel { - private List rows; - private Integer total; + private String endLatitudeGd; + private String endLongitudeGd; + private String pipeCode; + private String startLatitudeGd; + private String startLongitudeGd; - public List getRows() { - return rows; + public String getEndLatitudeGd() { + return endLatitudeGd; } - public void setRows(List rows) { - this.rows = rows; + public void setEndLatitudeGd(String endLatitudeGd) { + this.endLatitudeGd = endLatitudeGd; } - public Integer getTotal() { - return total; + public String getEndLongitudeGd() { + return endLongitudeGd; } - public void setTotal(Integer total) { - this.total = total; + public void setEndLongitudeGd(String endLongitudeGd) { + this.endLongitudeGd = endLongitudeGd; } - public static class RowsModel { - private String buryMode; - private String constructEra; - private String deptName; - private String deptid; - private String designPressure; - private String endBuryDeep; - private String endGroundHeight; - private String endLatitude; - private String endLatitudeGd; - private String endLongitude; - private String endLongitudeGd; - private String endPipecrownHeight; - private String id; - private String instantaneousFlow; - private String material; - private String pipeDiameter; - private String pipelineCode; - private String pipelineName; - private String pipelinePosition; - private String pipelineType; - private String pipelineTypeName; - private String startBuryDeep; - private String startGroundHeight; - private String startLatitude; - private String startLatitudeGd; - private String startLongitude; - private String startLongitudeGd; - private String startPipecrownHeight; - private String ts; + public String getPipeCode() { + return pipeCode; + } - public String getBuryMode() { - return buryMode; - } + public void setPipeCode(String pipeCode) { + this.pipeCode = pipeCode; + } - public void setBuryMode(String buryMode) { - this.buryMode = buryMode; - } + public String getStartLatitudeGd() { + return startLatitudeGd; + } - public String getConstructEra() { - return constructEra; - } + public void setStartLatitudeGd(String startLatitudeGd) { + this.startLatitudeGd = startLatitudeGd; + } - public void setConstructEra(String constructEra) { - this.constructEra = constructEra; - } + public String getStartLongitudeGd() { + return startLongitudeGd; + } - public String getDeptName() { - return deptName; - } - - public void setDeptName(String deptName) { - this.deptName = deptName; - } - - public String getDeptid() { - return deptid; - } - - public void setDeptid(String deptid) { - this.deptid = deptid; - } - - public String getDesignPressure() { - return designPressure; - } - - public void setDesignPressure(String designPressure) { - this.designPressure = designPressure; - } - - public String getEndBuryDeep() { - return endBuryDeep; - } - - public void setEndBuryDeep(String endBuryDeep) { - this.endBuryDeep = endBuryDeep; - } - - public String getEndGroundHeight() { - return endGroundHeight; - } - - public void setEndGroundHeight(String endGroundHeight) { - this.endGroundHeight = endGroundHeight; - } - - public String getEndLatitude() { - return endLatitude; - } - - public void setEndLatitude(String endLatitude) { - this.endLatitude = endLatitude; - } - - public String getEndLatitudeGd() { - return endLatitudeGd; - } - - public void setEndLatitudeGd(String endLatitudeGd) { - this.endLatitudeGd = endLatitudeGd; - } - - public String getEndLongitude() { - return endLongitude; - } - - public void setEndLongitude(String endLongitude) { - this.endLongitude = endLongitude; - } - - public String getEndLongitudeGd() { - return endLongitudeGd; - } - - public void setEndLongitudeGd(String endLongitudeGd) { - this.endLongitudeGd = endLongitudeGd; - } - - public String getEndPipecrownHeight() { - return endPipecrownHeight; - } - - public void setEndPipecrownHeight(String endPipecrownHeight) { - this.endPipecrownHeight = endPipecrownHeight; - } - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public String getInstantaneousFlow() { - return instantaneousFlow; - } - - public void setInstantaneousFlow(String instantaneousFlow) { - this.instantaneousFlow = instantaneousFlow; - } - - public String getMaterial() { - return material; - } - - public void setMaterial(String material) { - this.material = material; - } - - public String getPipeDiameter() { - return pipeDiameter; - } - - public void setPipeDiameter(String pipeDiameter) { - this.pipeDiameter = pipeDiameter; - } - - public String getPipelineCode() { - return pipelineCode; - } - - public void setPipelineCode(String pipelineCode) { - this.pipelineCode = pipelineCode; - } - - public String getPipelineName() { - return pipelineName; - } - - public void setPipelineName(String pipelineName) { - this.pipelineName = pipelineName; - } - - public String getPipelinePosition() { - return pipelinePosition; - } - - public void setPipelinePosition(String pipelinePosition) { - this.pipelinePosition = pipelinePosition; - } - - public String getPipelineType() { - return pipelineType; - } - - public void setPipelineType(String pipelineType) { - this.pipelineType = pipelineType; - } - - public String getPipelineTypeName() { - return pipelineTypeName; - } - - public void setPipelineTypeName(String pipelineTypeName) { - this.pipelineTypeName = pipelineTypeName; - } - - public String getStartBuryDeep() { - return startBuryDeep; - } - - public void setStartBuryDeep(String startBuryDeep) { - this.startBuryDeep = startBuryDeep; - } - - public String getStartGroundHeight() { - return startGroundHeight; - } - - public void setStartGroundHeight(String startGroundHeight) { - this.startGroundHeight = startGroundHeight; - } - - public String getStartLatitude() { - return startLatitude; - } - - public void setStartLatitude(String startLatitude) { - this.startLatitude = startLatitude; - } - - public String getStartLatitudeGd() { - return startLatitudeGd; - } - - public void setStartLatitudeGd(String startLatitudeGd) { - this.startLatitudeGd = startLatitudeGd; - } - - public String getStartLongitude() { - return startLongitude; - } - - public void setStartLongitude(String startLongitude) { - this.startLongitude = startLongitude; - } - - public String getStartLongitudeGd() { - return startLongitudeGd; - } - - public void setStartLongitudeGd(String startLongitudeGd) { - this.startLongitudeGd = startLongitudeGd; - } - - public String getStartPipecrownHeight() { - return startPipecrownHeight; - } - - public void setStartPipecrownHeight(String startPipecrownHeight) { - this.startPipecrownHeight = startPipecrownHeight; - } - - public String getTs() { - return ts; - } - - public void setTs(String ts) { - this.ts = ts; - } + public void setStartLongitudeGd(String startLongitudeGd) { + this.startLongitudeGd = startLongitudeGd; } } } diff --git a/app/src/main/java/com/casic/app/smartwell/utils/LocaleConstant.kt b/app/src/main/java/com/casic/app/smartwell/utils/LocaleConstant.kt index f20782c..22e9e65 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/LocaleConstant.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/LocaleConstant.kt @@ -29,7 +29,7 @@ } const val FIVE_YEARS = 5L * 365 * 60 * 60 * 24 * 1000L - const val RADIUS_SIZE = 80 //相距多少米才聚合,单位:米 + const val RADIUS_SIZE = 100 //相距多少米才聚合,单位:米 const val PERMISSIONS_CODE = 999 const val PAGE_LIMIT = 20 const val PUSH_REGISTER = 2022082901 @@ -39,7 +39,7 @@ const val DEFAULT_SERVER_CONFIG = "defaultServerConfig" const val DEFAULT_SERVER = "http://60.208.121.150:5001" -// const val DEFAULT_SERVER = "http://111.198.10.15:11638" +// const val DEFAULT_SERVER = "http://192.168.75.39:11308" const val USER_DETAIL_MODEL = "userDetailModel" const val APP_AUTHORITY = "com.casic.zq.smartwell.fileprovider" diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt index 991e1db..82bef29 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt @@ -316,7 +316,7 @@ /** * 管线位置数据 */ - @GET("/pipeline/listPage") + @GET("/pipeline/appList") suspend fun getPipeline( @Header("token") token: String, @Query("limit") limit: Int, diff --git a/app/src/main/java/com/casic/app/smartwell/view/MainActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/MainActivity.kt index 4ca5a5e..9270fa1 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/MainActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/MainActivity.kt @@ -10,7 +10,7 @@ import com.casic.app.smartwell.R import com.casic.app.smartwell.adapter.ViewPagerAdapter import com.casic.app.smartwell.databinding.ActivityMainBinding -import com.casic.app.smartwell.fragment.HomePageHaveClusterFragment +import com.casic.app.smartwell.fragment.HomePageNoClusterFragment import com.casic.app.smartwell.fragment.MinePageFragment import com.casic.app.smartwell.fragment.NoticePageFragment import com.casic.app.smartwell.fragment.OrderListFragment @@ -34,8 +34,8 @@ private lateinit var pushViewModel: PushViewModel init { -// fragmentPages.add(HomePageNoClusterFragment()) - fragmentPages.add(HomePageHaveClusterFragment()) + fragmentPages.add(HomePageNoClusterFragment()) +// fragmentPages.add(HomePageHaveClusterFragment()) fragmentPages.add(OrderListFragment()) fragmentPages.add(NoticePageFragment()) fragmentPages.add(MinePageFragment()) diff --git a/app/src/main/java/com/casic/app/smartwell/widgets/MapWellPopup.kt b/app/src/main/java/com/casic/app/smartwell/widgets/MapWellPopup.kt index ec455dd..c7fde24 100644 --- a/app/src/main/java/com/casic/app/smartwell/widgets/MapWellPopup.kt +++ b/app/src/main/java/com/casic/app/smartwell/widgets/MapWellPopup.kt @@ -20,7 +20,7 @@ animationStyle = R.style.MapPopupAnimation setBackgroundDrawable(null) contentView = LayoutInflater.from(context).inflate( - R.layout.popup_map_info, null, false + R.layout.popup_map_info_2, null, false ) } diff --git a/app/src/main/java/com/casic/app/smartwell/widgets/cluster/ClusterOverlay.java b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/ClusterOverlay.java index 40df562..0d95902 100644 --- a/app/src/main/java/com/casic/app/smartwell/widgets/cluster/ClusterOverlay.java +++ b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/ClusterOverlay.java @@ -271,8 +271,8 @@ textView.setText(tile); } textView.setGravity(Gravity.CENTER); - textView.setTextColor(Color.BLACK); - textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 15); + textView.setTextColor(Color.WHITE); + textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 16); if (clusterRender != null && clusterRender.getDrawableByCount(num) != null) { textView.setBackgroundDrawable(clusterRender.getDrawableByCount(num)); } else { diff --git a/app/src/main/res/drawable/bg_solid_layout_transparent_bottom_radius_5.xml b/app/src/main/res/drawable/bg_solid_layout_transparent_bottom_radius_5.xml new file mode 100644 index 0000000..18c1e99 --- /dev/null +++ b/app/src/main/res/drawable/bg_solid_layout_transparent_bottom_radius_5.xml @@ -0,0 +1,10 @@ + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/bg_solid_layout_transparent_radius_5.xml b/app/src/main/res/drawable/bg_solid_layout_transparent_radius_5.xml index 18c1e99..cce39da 100644 --- a/app/src/main/res/drawable/bg_solid_layout_transparent_radius_5.xml +++ b/app/src/main/res/drawable/bg_solid_layout_transparent_radius_5.xml @@ -4,7 +4,5 @@ - + \ No newline at end of file diff --git a/app/src/main/res/layout/popup_map_info_2.xml b/app/src/main/res/layout/popup_map_info_2.xml new file mode 100644 index 0000000..60b4ee2 --- /dev/null +++ b/app/src/main/res/layout/popup_map_info_2.xml @@ -0,0 +1,39 @@ + + + + + + + + + + + + + + + \ No newline at end of file