diff --git a/app/src/main/java/com/casic/app/smartwell/extensions/Int.kt b/app/src/main/java/com/casic/app/smartwell/extensions/Int.kt index de0617b..a0a5e33 100644 --- a/app/src/main/java/com/casic/app/smartwell/extensions/Int.kt +++ b/app/src/main/java/com/casic/app/smartwell/extensions/Int.kt @@ -1,9 +1,24 @@ package com.casic.app.smartwell.extensions +import android.graphics.Bitmap +import android.graphics.Canvas +import android.graphics.Paint +import android.graphics.RectF + fun Int.toLevel(): String { return if (this == 0) { "" } else { this.toString() } +} + +fun Int.drawCircle(color: Int): Bitmap? { + val bitmap = Bitmap.createBitmap(this * 2, this * 2, Bitmap.Config.ARGB_8888) + val canvas = Canvas(bitmap) + val paint = Paint() + val rectF = RectF(0f, 0f, (this * 2).toFloat(), (this * 2).toFloat()) + paint.color = color + canvas.drawArc(rectF, 0f, 360f, true, paint) + return bitmap } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/extensions/Int.kt b/app/src/main/java/com/casic/app/smartwell/extensions/Int.kt index de0617b..a0a5e33 100644 --- a/app/src/main/java/com/casic/app/smartwell/extensions/Int.kt +++ b/app/src/main/java/com/casic/app/smartwell/extensions/Int.kt @@ -1,9 +1,24 @@ package com.casic.app.smartwell.extensions +import android.graphics.Bitmap +import android.graphics.Canvas +import android.graphics.Paint +import android.graphics.RectF + fun Int.toLevel(): String { return if (this == 0) { "" } else { this.toString() } +} + +fun Int.drawCircle(color: Int): Bitmap? { + val bitmap = Bitmap.createBitmap(this * 2, this * 2, Bitmap.Config.ARGB_8888) + val canvas = Canvas(bitmap) + val paint = Paint() + val rectF = RectF(0f, 0f, (this * 2).toFloat(), (this * 2).toFloat()) + paint.color = color + canvas.drawArc(rectF, 0f, 360f, true, paint) + return bitmap } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt index 6b6ca3e..5e45534 100644 --- a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt +++ b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt @@ -2,17 +2,13 @@ import android.content.Context import com.casic.app.smartwell.callback.OnImageCompressListener -import com.casic.app.smartwell.model.ErrorMessageModel import com.casic.app.smartwell.utils.LocaleConstant -import com.google.gson.Gson -import com.google.gson.reflect.TypeToken +import com.google.gson.JsonParser import com.pengxh.kt.lite.extensions.createCompressImageDir import com.pengxh.kt.lite.utils.SaveKeyValues -import org.json.JSONObject import top.zibin.luban.Luban import top.zibin.luban.OnCompressListener import java.io.File -import java.util.Locale /** * String扩展方法 @@ -74,18 +70,22 @@ } } -fun String.separateResponseCode(): Int { +fun String.getResponseCode(): Int { if (this.isBlank()) { return 404 } - return JSONObject(this).getInt("code") + val element = JsonParser.parseString(this) + val jsonObject = element.asJsonObject + return jsonObject.get("code").asInt } -fun String.toErrorMessage(): String { - val errorModel = Gson().fromJson( - this, object : TypeToken() {}.type - ) - return errorModel.message.toString() +fun String.getResponseMessage(): String { + if (this.isBlank()) { + return "" + } + val element = JsonParser.parseString(this) + val jsonObject = element.asJsonObject + return jsonObject.get("message").asString } fun String.compressImage(context: Context, listener: OnImageCompressListener) { @@ -93,9 +93,6 @@ .load(this) .ignoreBy(100) .setTargetDir(context.createCompressImageDir().toString()) - .filter { - !(it.isBlank() || it.lowercase(Locale.getDefault()).endsWith(".gif")) - } .setCompressListener(object : OnCompressListener { override fun onStart() { diff --git a/app/src/main/java/com/casic/app/smartwell/extensions/Int.kt b/app/src/main/java/com/casic/app/smartwell/extensions/Int.kt index de0617b..a0a5e33 100644 --- a/app/src/main/java/com/casic/app/smartwell/extensions/Int.kt +++ b/app/src/main/java/com/casic/app/smartwell/extensions/Int.kt @@ -1,9 +1,24 @@ package com.casic.app.smartwell.extensions +import android.graphics.Bitmap +import android.graphics.Canvas +import android.graphics.Paint +import android.graphics.RectF + fun Int.toLevel(): String { return if (this == 0) { "" } else { this.toString() } +} + +fun Int.drawCircle(color: Int): Bitmap? { + val bitmap = Bitmap.createBitmap(this * 2, this * 2, Bitmap.Config.ARGB_8888) + val canvas = Canvas(bitmap) + val paint = Paint() + val rectF = RectF(0f, 0f, (this * 2).toFloat(), (this * 2).toFloat()) + paint.color = color + canvas.drawArc(rectF, 0f, 360f, true, paint) + return bitmap } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt index 6b6ca3e..5e45534 100644 --- a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt +++ b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt @@ -2,17 +2,13 @@ import android.content.Context import com.casic.app.smartwell.callback.OnImageCompressListener -import com.casic.app.smartwell.model.ErrorMessageModel import com.casic.app.smartwell.utils.LocaleConstant -import com.google.gson.Gson -import com.google.gson.reflect.TypeToken +import com.google.gson.JsonParser import com.pengxh.kt.lite.extensions.createCompressImageDir import com.pengxh.kt.lite.utils.SaveKeyValues -import org.json.JSONObject import top.zibin.luban.Luban import top.zibin.luban.OnCompressListener import java.io.File -import java.util.Locale /** * String扩展方法 @@ -74,18 +70,22 @@ } } -fun String.separateResponseCode(): Int { +fun String.getResponseCode(): Int { if (this.isBlank()) { return 404 } - return JSONObject(this).getInt("code") + val element = JsonParser.parseString(this) + val jsonObject = element.asJsonObject + return jsonObject.get("code").asInt } -fun String.toErrorMessage(): String { - val errorModel = Gson().fromJson( - this, object : TypeToken() {}.type - ) - return errorModel.message.toString() +fun String.getResponseMessage(): String { + if (this.isBlank()) { + return "" + } + val element = JsonParser.parseString(this) + val jsonObject = element.asJsonObject + return jsonObject.get("message").asString } fun String.compressImage(context: Context, listener: OnImageCompressListener) { @@ -93,9 +93,6 @@ .load(this) .ignoreBy(100) .setTargetDir(context.createCompressImageDir().toString()) - .filter { - !(it.isBlank() || it.lowercase(Locale.getDefault()).endsWith(".gif")) - } .setCompressListener(object : OnCompressListener { override fun onStart() { 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 96df110..cd25fca 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 @@ -1,26 +1,25 @@ package com.casic.app.smartwell.fragment -import android.graphics.Point +import android.graphics.Color +import android.graphics.drawable.BitmapDrawable +import android.graphics.drawable.Drawable 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 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.LatLngBounds import com.amap.api.maps.model.Marker -import com.amap.api.maps.model.MarkerOptions import com.casic.app.smartwell.R import com.casic.app.smartwell.databinding.FragmentHomeBinding +import com.casic.app.smartwell.extensions.drawCircle import com.casic.app.smartwell.extensions.initImmersionBar -import com.casic.app.smartwell.extensions.valueToType import com.casic.app.smartwell.model.MapWellListModel import com.casic.app.smartwell.utils.LocaleConstant import com.casic.app.smartwell.utils.RouteOnMap @@ -31,9 +30,16 @@ import com.casic.app.smartwell.view.WellOperationActivity import com.casic.app.smartwell.vm.OrderViewModel import com.casic.app.smartwell.vm.WellViewModel +import com.casic.app.smartwell.widgets.MapWellPopup +import com.casic.app.smartwell.widgets.cluster.ClusterItem +import com.casic.app.smartwell.widgets.cluster.ClusterOnClickListener +import com.casic.app.smartwell.widgets.cluster.ClusterOverlay +import com.casic.app.smartwell.widgets.cluster.RegionItem 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.convertDrawable +import com.pengxh.kt.lite.extensions.dp2px import com.pengxh.kt.lite.extensions.navigatePageTo import com.pengxh.kt.lite.extensions.show import com.pengxh.kt.lite.utils.LoadingDialogHub @@ -43,35 +49,23 @@ /** * 地图点位带聚合效果 * */ -class HomePageHaveClusterFragment : KotlinBaseFragment(), AMap.OnMapLoadedListener, - AMap.OnCameraChangeListener, AMap.OnMarkerClickListener, AMap.InfoWindowAdapter, - AMap.OnInfoWindowClickListener { +class HomePageHaveClusterFragment : KotlinBaseFragment(), + AMap.OnCameraChangeListener { private val kTag = "HaveClusterFragment" private val easyPopupWindow by lazy { EasyPopupWindow(requireContext()) } - private lateinit var wellViewModel: WellViewModel - private lateinit var orderViewModel: OrderViewModel - private lateinit var aMap: AMap - - /** - * 所有的marker - */ - private var allMarkerOptions: MutableList = ArrayList() - - /** - * 视野内的marker - */ - private var markerOptionsInView: MutableList = ArrayList() - - /** - * 自定义Marker弹出框 - * */ - private lateinit var v: View + private val regionRadius by lazy { LocaleConstant.RADIUS_SIZE.dp2px(requireContext()) } + private val infoPopup by lazy { MapWellPopup(requireContext()) } /** * 所有窨井列表信息集合 * */ - private var wellModels: MutableList = ArrayList() + private val wellModels = ArrayList() + private val backDrawables = HashMap() + private lateinit var wellViewModel: WellViewModel + private lateinit var orderViewModel: OrderViewModel + private lateinit var aMap: AMap + private var clusterOverlay: ClusterOverlay? = null override fun initViewBinding( inflater: LayoutInflater, @@ -106,6 +100,9 @@ } }) + //地图初始化 + initMap(savedInstanceState) + //初始化vm wellViewModel = ViewModelProvider(this)[WellViewModel::class.java] orderViewModel = ViewModelProvider(this)[OrderViewModel::class.java] @@ -120,25 +117,19 @@ val latitudeList: MutableList = ArrayList() val longitudeList: MutableList = ArrayList() it.data?.forEach { well -> - val lat = well.latGaode.toString() - val lng = well.lngGaode.toString() + val lat = well.latGaode + val lng = well.lngGaode if (lat.isNotBlank() && lng.isNotBlank()) { //返回true代表当前位置在大陆、港澳地区,反之不在 val latitude = lat.toDouble() val longitude = lng.toDouble() if (CoordinateConverter.isAMapDataAvailable(latitude, longitude)) { - //缓存所有设备详情,点击Marker时候需要 + //缓存所有井 wellModels.add(well) + //分别缓存经、纬度 latitudeList.add(latitude) longitudeList.add(longitude) - //将所有设备信息转化缓存为Marker点 - allMarkerOptions.add( - MarkerOptions() - .position(LatLng(latitude, longitude)) - .title(well.wellTypeName) - .snippet(well.wellName) - ) } } } @@ -160,12 +151,12 @@ val cameraPosition = CameraPosition(centerLatLng, 16f, 0f, 0f) val cameraUpdate = CameraUpdateFactory.newCameraPosition(cameraPosition) aMap.animateCamera(cameraUpdate, 1500, null) + + //显示点数据 + displayWellOnMap() } } - //地图初始化 - initMap(savedInstanceState) - //获取窨井监控数据 wellViewModel.countResultModel.observe(this) { binding.deployedWellView.text = it["bfWell"] @@ -220,17 +211,10 @@ uiSettings.isCompassEnabled = true uiSettings.zoomPosition = AMapOptions.ZOOM_POSITION_RIGHT_CENTER uiSettings.isTiltGesturesEnabled = false//不许地图随手势倾斜角度 + uiSettings.isRotateGesturesEnabled = false//不允许地图随手势改变方位 - // 地图加载成功监听 - aMap.addOnMapLoadedListener(this) // 地图缩放监听 aMap.addOnCameraChangeListener(this) - // marker 点击事件监听 - aMap.addOnMarkerClickListener(this) - // 点击marker弹出自定义popup - aMap.setInfoWindowAdapter(this) - //信息窗点击事件 - aMap.addOnInfoWindowClickListener(this) } override fun initEvent() { @@ -259,9 +243,111 @@ } - override fun onMapLoaded() { - //地图加载成功之后显示聚合点数据 - initClustersMarkers() + private fun displayWellOnMap() { + clusterOverlay?.onDestroy() + val clusterItems = ArrayList() + + wellModels.forEach { + val latitude = it.latGaode.toDouble() + val longitude = it.lngGaode.toDouble() + + val latLng = LatLng(latitude, longitude, false) + val regionItem = RegionItem(latLng, it) + clusterItems.add(regionItem) + } + + clusterOverlay = ClusterOverlay(requireContext(), aMap, clusterItems, regionRadius) + clusterOverlay?.setClusterRender { clusterNum -> + //聚合圆半径 + val radius = 100.dp2px(requireContext()) + if (clusterNum == 0) { + var bitmapDrawable = backDrawables[0] + if (bitmapDrawable == null) { + bitmapDrawable = BitmapDrawable( + null, radius.drawCircle(Color.argb(159, 100, 149, 237)) + ) + backDrawables[0] = bitmapDrawable + } + bitmapDrawable + } + if (clusterNum == 1) { + var bitmapDrawable = backDrawables[1] + if (bitmapDrawable == null) { + bitmapDrawable = R.mipmap.well_location.convertDrawable(requireContext())!! + backDrawables[1] = bitmapDrawable + } + bitmapDrawable + } else if (clusterNum < 5) { + var bitmapDrawable = backDrawables[2] + if (bitmapDrawable == null) { + bitmapDrawable = BitmapDrawable( + null, radius.drawCircle(Color.argb(159, 100, 149, 237)) + ) + backDrawables[2] = bitmapDrawable + } + bitmapDrawable + } else if (clusterNum < 10) { + var bitmapDrawable = backDrawables[3] + if (bitmapDrawable == null) { + bitmapDrawable = BitmapDrawable( + null, radius.drawCircle(Color.argb(199, 30, 144, 255)) + ) + backDrawables[3] = bitmapDrawable + } + bitmapDrawable + } else { + var bitmapDrawable = backDrawables[4] + if (bitmapDrawable == null) { + bitmapDrawable = BitmapDrawable( + null, radius.drawCircle(Color.argb(235, 65, 105, 225)) + ) + backDrawables[4] = bitmapDrawable + } + bitmapDrawable + } + } + + clusterOverlay?.setOnClusterClickListener(object : ClusterOnClickListener { + override fun onMarkerClicked(marker: Marker?, items: List) { + if (items.size > 1) { + "请缩放地图比例在查看数据".show(requireContext()) + return + } + + var item: RegionItem? = null + val builder = LatLngBounds.Builder() + for (clusterItem in items) { + builder.include(clusterItem.position) + item = clusterItem as RegionItem + } + + item?.apply { + showWellPopup(well) + } + } + }) + } + + private fun showWellPopup(well: MapWellListModel.DataModel) { + infoPopup.set(well, object : MapWellPopup.OnPopupWindowClickListener { + override fun onPopupClicked(lat: Double, lng: Double) { + AlertControlDialog.Builder().setContext(requireContext()).setTitle("操作提示") + .setMessage("确定要前往吗").setNegativeButton("取消").setPositiveButton("确定") + .setOnDialogButtonClickListener(object : + AlertControlDialog.OnDialogButtonClickListener { + override fun onConfirmClick() { + RouteOnMap.startNavigation( + requireContext(), "", LatLng(lat, lng) + ) + } + + override fun onCancelClick() { + + } + }).build().show() + } + }) + infoPopup.showAsDropDown(binding.rightOptionView) } override fun onCameraChange(p0: CameraPosition?) { @@ -282,103 +368,10 @@ } } - //获取视野内的marker 根据聚合算法合成自定义的marker 显示视野内的marker override fun onCameraChangeFinish(p0: CameraPosition?) { //地图缩放之后显示聚合点数据 LoadingDialogHub.dismiss() httpCountDownTimer.cancel() - initClustersMarkers() - } - - private fun initClustersMarkers() { - 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 { - v = LayoutInflater.from(requireContext()).inflate(R.layout.popup_map_info, null) - - //显示闸井信息 - marker?.showInfoWindow() - return true - } - - override fun getInfoWindow(marker: Marker?): View { - //反射得到popup里面的控件对象 - val wellNameView = v.findViewById(R.id.wellNameView) - val wellCodeView = v.findViewById(R.id.wellCodeView) - val wellTypeView = v.findViewById(R.id.wellTypeView) - val wellStateView = v.findViewById(R.id.wellStateView) - val deepView = v.findViewById(R.id.deepView) - val locationView = v.findViewById(R.id.locationView) - - //绑定数据 - val clickedLatLng = marker?.position!! - wellModels.forEach { well -> - if (clickedLatLng.latitude == well.latGaode!!.toDouble() - && clickedLatLng.longitude == well.lngGaode!!.toDouble() - ) { - wellNameView.text = String.format("点位名称: ${well.wellName}") - wellCodeView.text = String.format("点位编号: ${well.wellCode}") - wellTypeView.text = String.format("点位类型: ${well.wellType.valueToType()}") - val bfztName = if (well.bfzt == "1") { - "已布防" - } else { - "已撤防" - } - wellStateView.text = String.format("布/撤防状态: $bfztName") - deepView.text = String.format("点位深度: ${well.deep}m") - locationView.text = String.format("详细位置: ${well.position}") - } - } - return v - } - - /** - * 此方法不能修改整个 InfoWindow 的背景和边框,无论自定义的样式是什么样,SDK 都会在最外层添加一个默认的边框 - * */ - override fun getInfoContents(p0: Marker?): View? = null - - override fun onInfoWindowClick(p0: Marker?) { - p0?.apply { - AlertControlDialog.Builder() - .setContext(requireContext()) - .setTitle("操作提示") - .setMessage("确定要前往吗") - .setNegativeButton("取消") - .setPositiveButton("确定") - .setOnDialogButtonClickListener(object : - AlertControlDialog.OnDialogButtonClickListener { - override fun onConfirmClick() { - val lat = position.latitude.toString() - val lng = position.longitude.toString() - if (lat.isBlank() || lng.isBlank()) { - "点位经纬度异常,无法开启导航".show(requireContext()) - return - } - RouteOnMap.startNavigation( - requireContext(), snippet, LatLng(lat.toDouble(), lng.toDouble()) - ) - } - - override fun onCancelClick() { - - } - }).build().show() - } } /***以下是地图生命周期管理************************************************************************/ diff --git a/app/src/main/java/com/casic/app/smartwell/extensions/Int.kt b/app/src/main/java/com/casic/app/smartwell/extensions/Int.kt index de0617b..a0a5e33 100644 --- a/app/src/main/java/com/casic/app/smartwell/extensions/Int.kt +++ b/app/src/main/java/com/casic/app/smartwell/extensions/Int.kt @@ -1,9 +1,24 @@ package com.casic.app.smartwell.extensions +import android.graphics.Bitmap +import android.graphics.Canvas +import android.graphics.Paint +import android.graphics.RectF + fun Int.toLevel(): String { return if (this == 0) { "" } else { this.toString() } +} + +fun Int.drawCircle(color: Int): Bitmap? { + val bitmap = Bitmap.createBitmap(this * 2, this * 2, Bitmap.Config.ARGB_8888) + val canvas = Canvas(bitmap) + val paint = Paint() + val rectF = RectF(0f, 0f, (this * 2).toFloat(), (this * 2).toFloat()) + paint.color = color + canvas.drawArc(rectF, 0f, 360f, true, paint) + return bitmap } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt index 6b6ca3e..5e45534 100644 --- a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt +++ b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt @@ -2,17 +2,13 @@ import android.content.Context import com.casic.app.smartwell.callback.OnImageCompressListener -import com.casic.app.smartwell.model.ErrorMessageModel import com.casic.app.smartwell.utils.LocaleConstant -import com.google.gson.Gson -import com.google.gson.reflect.TypeToken +import com.google.gson.JsonParser import com.pengxh.kt.lite.extensions.createCompressImageDir import com.pengxh.kt.lite.utils.SaveKeyValues -import org.json.JSONObject import top.zibin.luban.Luban import top.zibin.luban.OnCompressListener import java.io.File -import java.util.Locale /** * String扩展方法 @@ -74,18 +70,22 @@ } } -fun String.separateResponseCode(): Int { +fun String.getResponseCode(): Int { if (this.isBlank()) { return 404 } - return JSONObject(this).getInt("code") + val element = JsonParser.parseString(this) + val jsonObject = element.asJsonObject + return jsonObject.get("code").asInt } -fun String.toErrorMessage(): String { - val errorModel = Gson().fromJson( - this, object : TypeToken() {}.type - ) - return errorModel.message.toString() +fun String.getResponseMessage(): String { + if (this.isBlank()) { + return "" + } + val element = JsonParser.parseString(this) + val jsonObject = element.asJsonObject + return jsonObject.get("message").asString } fun String.compressImage(context: Context, listener: OnImageCompressListener) { @@ -93,9 +93,6 @@ .load(this) .ignoreBy(100) .setTargetDir(context.createCompressImageDir().toString()) - .filter { - !(it.isBlank() || it.lowercase(Locale.getDefault()).endsWith(".gif")) - } .setCompressListener(object : OnCompressListener { override fun onStart() { 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 96df110..cd25fca 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 @@ -1,26 +1,25 @@ package com.casic.app.smartwell.fragment -import android.graphics.Point +import android.graphics.Color +import android.graphics.drawable.BitmapDrawable +import android.graphics.drawable.Drawable 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 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.LatLngBounds import com.amap.api.maps.model.Marker -import com.amap.api.maps.model.MarkerOptions import com.casic.app.smartwell.R import com.casic.app.smartwell.databinding.FragmentHomeBinding +import com.casic.app.smartwell.extensions.drawCircle import com.casic.app.smartwell.extensions.initImmersionBar -import com.casic.app.smartwell.extensions.valueToType import com.casic.app.smartwell.model.MapWellListModel import com.casic.app.smartwell.utils.LocaleConstant import com.casic.app.smartwell.utils.RouteOnMap @@ -31,9 +30,16 @@ import com.casic.app.smartwell.view.WellOperationActivity import com.casic.app.smartwell.vm.OrderViewModel import com.casic.app.smartwell.vm.WellViewModel +import com.casic.app.smartwell.widgets.MapWellPopup +import com.casic.app.smartwell.widgets.cluster.ClusterItem +import com.casic.app.smartwell.widgets.cluster.ClusterOnClickListener +import com.casic.app.smartwell.widgets.cluster.ClusterOverlay +import com.casic.app.smartwell.widgets.cluster.RegionItem 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.convertDrawable +import com.pengxh.kt.lite.extensions.dp2px import com.pengxh.kt.lite.extensions.navigatePageTo import com.pengxh.kt.lite.extensions.show import com.pengxh.kt.lite.utils.LoadingDialogHub @@ -43,35 +49,23 @@ /** * 地图点位带聚合效果 * */ -class HomePageHaveClusterFragment : KotlinBaseFragment(), AMap.OnMapLoadedListener, - AMap.OnCameraChangeListener, AMap.OnMarkerClickListener, AMap.InfoWindowAdapter, - AMap.OnInfoWindowClickListener { +class HomePageHaveClusterFragment : KotlinBaseFragment(), + AMap.OnCameraChangeListener { private val kTag = "HaveClusterFragment" private val easyPopupWindow by lazy { EasyPopupWindow(requireContext()) } - private lateinit var wellViewModel: WellViewModel - private lateinit var orderViewModel: OrderViewModel - private lateinit var aMap: AMap - - /** - * 所有的marker - */ - private var allMarkerOptions: MutableList = ArrayList() - - /** - * 视野内的marker - */ - private var markerOptionsInView: MutableList = ArrayList() - - /** - * 自定义Marker弹出框 - * */ - private lateinit var v: View + private val regionRadius by lazy { LocaleConstant.RADIUS_SIZE.dp2px(requireContext()) } + private val infoPopup by lazy { MapWellPopup(requireContext()) } /** * 所有窨井列表信息集合 * */ - private var wellModels: MutableList = ArrayList() + private val wellModels = ArrayList() + private val backDrawables = HashMap() + private lateinit var wellViewModel: WellViewModel + private lateinit var orderViewModel: OrderViewModel + private lateinit var aMap: AMap + private var clusterOverlay: ClusterOverlay? = null override fun initViewBinding( inflater: LayoutInflater, @@ -106,6 +100,9 @@ } }) + //地图初始化 + initMap(savedInstanceState) + //初始化vm wellViewModel = ViewModelProvider(this)[WellViewModel::class.java] orderViewModel = ViewModelProvider(this)[OrderViewModel::class.java] @@ -120,25 +117,19 @@ val latitudeList: MutableList = ArrayList() val longitudeList: MutableList = ArrayList() it.data?.forEach { well -> - val lat = well.latGaode.toString() - val lng = well.lngGaode.toString() + val lat = well.latGaode + val lng = well.lngGaode if (lat.isNotBlank() && lng.isNotBlank()) { //返回true代表当前位置在大陆、港澳地区,反之不在 val latitude = lat.toDouble() val longitude = lng.toDouble() if (CoordinateConverter.isAMapDataAvailable(latitude, longitude)) { - //缓存所有设备详情,点击Marker时候需要 + //缓存所有井 wellModels.add(well) + //分别缓存经、纬度 latitudeList.add(latitude) longitudeList.add(longitude) - //将所有设备信息转化缓存为Marker点 - allMarkerOptions.add( - MarkerOptions() - .position(LatLng(latitude, longitude)) - .title(well.wellTypeName) - .snippet(well.wellName) - ) } } } @@ -160,12 +151,12 @@ val cameraPosition = CameraPosition(centerLatLng, 16f, 0f, 0f) val cameraUpdate = CameraUpdateFactory.newCameraPosition(cameraPosition) aMap.animateCamera(cameraUpdate, 1500, null) + + //显示点数据 + displayWellOnMap() } } - //地图初始化 - initMap(savedInstanceState) - //获取窨井监控数据 wellViewModel.countResultModel.observe(this) { binding.deployedWellView.text = it["bfWell"] @@ -220,17 +211,10 @@ uiSettings.isCompassEnabled = true uiSettings.zoomPosition = AMapOptions.ZOOM_POSITION_RIGHT_CENTER uiSettings.isTiltGesturesEnabled = false//不许地图随手势倾斜角度 + uiSettings.isRotateGesturesEnabled = false//不允许地图随手势改变方位 - // 地图加载成功监听 - aMap.addOnMapLoadedListener(this) // 地图缩放监听 aMap.addOnCameraChangeListener(this) - // marker 点击事件监听 - aMap.addOnMarkerClickListener(this) - // 点击marker弹出自定义popup - aMap.setInfoWindowAdapter(this) - //信息窗点击事件 - aMap.addOnInfoWindowClickListener(this) } override fun initEvent() { @@ -259,9 +243,111 @@ } - override fun onMapLoaded() { - //地图加载成功之后显示聚合点数据 - initClustersMarkers() + private fun displayWellOnMap() { + clusterOverlay?.onDestroy() + val clusterItems = ArrayList() + + wellModels.forEach { + val latitude = it.latGaode.toDouble() + val longitude = it.lngGaode.toDouble() + + val latLng = LatLng(latitude, longitude, false) + val regionItem = RegionItem(latLng, it) + clusterItems.add(regionItem) + } + + clusterOverlay = ClusterOverlay(requireContext(), aMap, clusterItems, regionRadius) + clusterOverlay?.setClusterRender { clusterNum -> + //聚合圆半径 + val radius = 100.dp2px(requireContext()) + if (clusterNum == 0) { + var bitmapDrawable = backDrawables[0] + if (bitmapDrawable == null) { + bitmapDrawable = BitmapDrawable( + null, radius.drawCircle(Color.argb(159, 100, 149, 237)) + ) + backDrawables[0] = bitmapDrawable + } + bitmapDrawable + } + if (clusterNum == 1) { + var bitmapDrawable = backDrawables[1] + if (bitmapDrawable == null) { + bitmapDrawable = R.mipmap.well_location.convertDrawable(requireContext())!! + backDrawables[1] = bitmapDrawable + } + bitmapDrawable + } else if (clusterNum < 5) { + var bitmapDrawable = backDrawables[2] + if (bitmapDrawable == null) { + bitmapDrawable = BitmapDrawable( + null, radius.drawCircle(Color.argb(159, 100, 149, 237)) + ) + backDrawables[2] = bitmapDrawable + } + bitmapDrawable + } else if (clusterNum < 10) { + var bitmapDrawable = backDrawables[3] + if (bitmapDrawable == null) { + bitmapDrawable = BitmapDrawable( + null, radius.drawCircle(Color.argb(199, 30, 144, 255)) + ) + backDrawables[3] = bitmapDrawable + } + bitmapDrawable + } else { + var bitmapDrawable = backDrawables[4] + if (bitmapDrawable == null) { + bitmapDrawable = BitmapDrawable( + null, radius.drawCircle(Color.argb(235, 65, 105, 225)) + ) + backDrawables[4] = bitmapDrawable + } + bitmapDrawable + } + } + + clusterOverlay?.setOnClusterClickListener(object : ClusterOnClickListener { + override fun onMarkerClicked(marker: Marker?, items: List) { + if (items.size > 1) { + "请缩放地图比例在查看数据".show(requireContext()) + return + } + + var item: RegionItem? = null + val builder = LatLngBounds.Builder() + for (clusterItem in items) { + builder.include(clusterItem.position) + item = clusterItem as RegionItem + } + + item?.apply { + showWellPopup(well) + } + } + }) + } + + private fun showWellPopup(well: MapWellListModel.DataModel) { + infoPopup.set(well, object : MapWellPopup.OnPopupWindowClickListener { + override fun onPopupClicked(lat: Double, lng: Double) { + AlertControlDialog.Builder().setContext(requireContext()).setTitle("操作提示") + .setMessage("确定要前往吗").setNegativeButton("取消").setPositiveButton("确定") + .setOnDialogButtonClickListener(object : + AlertControlDialog.OnDialogButtonClickListener { + override fun onConfirmClick() { + RouteOnMap.startNavigation( + requireContext(), "", LatLng(lat, lng) + ) + } + + override fun onCancelClick() { + + } + }).build().show() + } + }) + infoPopup.showAsDropDown(binding.rightOptionView) } override fun onCameraChange(p0: CameraPosition?) { @@ -282,103 +368,10 @@ } } - //获取视野内的marker 根据聚合算法合成自定义的marker 显示视野内的marker override fun onCameraChangeFinish(p0: CameraPosition?) { //地图缩放之后显示聚合点数据 LoadingDialogHub.dismiss() httpCountDownTimer.cancel() - initClustersMarkers() - } - - private fun initClustersMarkers() { - 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 { - v = LayoutInflater.from(requireContext()).inflate(R.layout.popup_map_info, null) - - //显示闸井信息 - marker?.showInfoWindow() - return true - } - - override fun getInfoWindow(marker: Marker?): View { - //反射得到popup里面的控件对象 - val wellNameView = v.findViewById(R.id.wellNameView) - val wellCodeView = v.findViewById(R.id.wellCodeView) - val wellTypeView = v.findViewById(R.id.wellTypeView) - val wellStateView = v.findViewById(R.id.wellStateView) - val deepView = v.findViewById(R.id.deepView) - val locationView = v.findViewById(R.id.locationView) - - //绑定数据 - val clickedLatLng = marker?.position!! - wellModels.forEach { well -> - if (clickedLatLng.latitude == well.latGaode!!.toDouble() - && clickedLatLng.longitude == well.lngGaode!!.toDouble() - ) { - wellNameView.text = String.format("点位名称: ${well.wellName}") - wellCodeView.text = String.format("点位编号: ${well.wellCode}") - wellTypeView.text = String.format("点位类型: ${well.wellType.valueToType()}") - val bfztName = if (well.bfzt == "1") { - "已布防" - } else { - "已撤防" - } - wellStateView.text = String.format("布/撤防状态: $bfztName") - deepView.text = String.format("点位深度: ${well.deep}m") - locationView.text = String.format("详细位置: ${well.position}") - } - } - return v - } - - /** - * 此方法不能修改整个 InfoWindow 的背景和边框,无论自定义的样式是什么样,SDK 都会在最外层添加一个默认的边框 - * */ - override fun getInfoContents(p0: Marker?): View? = null - - override fun onInfoWindowClick(p0: Marker?) { - p0?.apply { - AlertControlDialog.Builder() - .setContext(requireContext()) - .setTitle("操作提示") - .setMessage("确定要前往吗") - .setNegativeButton("取消") - .setPositiveButton("确定") - .setOnDialogButtonClickListener(object : - AlertControlDialog.OnDialogButtonClickListener { - override fun onConfirmClick() { - val lat = position.latitude.toString() - val lng = position.longitude.toString() - if (lat.isBlank() || lng.isBlank()) { - "点位经纬度异常,无法开启导航".show(requireContext()) - return - } - RouteOnMap.startNavigation( - requireContext(), snippet, LatLng(lat.toDouble(), lng.toDouble()) - ) - } - - override fun onCancelClick() { - - } - }).build().show() - } } /***以下是地图生命周期管理************************************************************************/ 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 a54d213..bfa7a57 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 @@ -44,8 +44,8 @@ * 地图点位不带聚合效果 * */ class HomePageNoClusterFragment : KotlinBaseFragment(), - AMap.OnMapLoadedListener, AMap.OnCameraChangeListener, AMap.OnMarkerClickListener, - AMap.InfoWindowAdapter, AMap.OnInfoWindowClickListener { + AMap.OnCameraChangeListener, AMap.OnMarkerClickListener, AMap.InfoWindowAdapter, + AMap.OnInfoWindowClickListener { private val kTag = "NoClusterFragment" private val easyPopupWindow by lazy { EasyPopupWindow(requireContext()) } @@ -109,6 +109,9 @@ wellViewModel = ViewModelProvider(this)[WellViewModel::class.java] orderViewModel = ViewModelProvider(this)[OrderViewModel::class.java] + //地图初始化 + initMap(savedInstanceState) + //获取所有窨井数据 httpCountDownTimer.start() LoadingDialogHub.show(requireActivity(), "数据加载中,请稍后...") @@ -157,12 +160,12 @@ val cameraPosition = CameraPosition(centerLatLng, 16f, 0f, 0f) val cameraUpdate = CameraUpdateFactory.newCameraPosition(cameraPosition) aMap.animateCamera(cameraUpdate, 1500, null) + + //显示点数据 + displayWellOnMap() } } - //地图初始化 - initMap(savedInstanceState) - //获取窨井监控数据 wellViewModel.countResultModel.observe(this) { binding.deployedWellView.text = it["bfWell"] @@ -214,9 +217,8 @@ uiSettings.isCompassEnabled = true uiSettings.zoomPosition = AMapOptions.ZOOM_POSITION_RIGHT_CENTER uiSettings.isTiltGesturesEnabled = false//不许地图随手势倾斜角度 + uiSettings.isRotateGesturesEnabled = false//不允许地图随手势改变方位 - // 地图加载成功监听 - aMap.addOnMapLoadedListener(this) // 地图缩放监听 aMap.addOnCameraChangeListener(this) // marker 点击事件监听 @@ -253,11 +255,6 @@ } - override fun onMapLoaded() { - //地图加载成功之后显示聚合点数据 - initClustersMarkers() - } - override fun onCameraChange(p0: CameraPosition?) { } @@ -281,10 +278,9 @@ //地图缩放之后显示聚合点数据 LoadingDialogHub.dismiss() httpCountDownTimer.cancel() - initClustersMarkers() } - private fun initClustersMarkers() { + private fun displayWellOnMap() { val proj = aMap.projection val dm = resources.displayMetrics var screenLocation: Point diff --git a/app/src/main/java/com/casic/app/smartwell/extensions/Int.kt b/app/src/main/java/com/casic/app/smartwell/extensions/Int.kt index de0617b..a0a5e33 100644 --- a/app/src/main/java/com/casic/app/smartwell/extensions/Int.kt +++ b/app/src/main/java/com/casic/app/smartwell/extensions/Int.kt @@ -1,9 +1,24 @@ package com.casic.app.smartwell.extensions +import android.graphics.Bitmap +import android.graphics.Canvas +import android.graphics.Paint +import android.graphics.RectF + fun Int.toLevel(): String { return if (this == 0) { "" } else { this.toString() } +} + +fun Int.drawCircle(color: Int): Bitmap? { + val bitmap = Bitmap.createBitmap(this * 2, this * 2, Bitmap.Config.ARGB_8888) + val canvas = Canvas(bitmap) + val paint = Paint() + val rectF = RectF(0f, 0f, (this * 2).toFloat(), (this * 2).toFloat()) + paint.color = color + canvas.drawArc(rectF, 0f, 360f, true, paint) + return bitmap } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt index 6b6ca3e..5e45534 100644 --- a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt +++ b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt @@ -2,17 +2,13 @@ import android.content.Context import com.casic.app.smartwell.callback.OnImageCompressListener -import com.casic.app.smartwell.model.ErrorMessageModel import com.casic.app.smartwell.utils.LocaleConstant -import com.google.gson.Gson -import com.google.gson.reflect.TypeToken +import com.google.gson.JsonParser import com.pengxh.kt.lite.extensions.createCompressImageDir import com.pengxh.kt.lite.utils.SaveKeyValues -import org.json.JSONObject import top.zibin.luban.Luban import top.zibin.luban.OnCompressListener import java.io.File -import java.util.Locale /** * String扩展方法 @@ -74,18 +70,22 @@ } } -fun String.separateResponseCode(): Int { +fun String.getResponseCode(): Int { if (this.isBlank()) { return 404 } - return JSONObject(this).getInt("code") + val element = JsonParser.parseString(this) + val jsonObject = element.asJsonObject + return jsonObject.get("code").asInt } -fun String.toErrorMessage(): String { - val errorModel = Gson().fromJson( - this, object : TypeToken() {}.type - ) - return errorModel.message.toString() +fun String.getResponseMessage(): String { + if (this.isBlank()) { + return "" + } + val element = JsonParser.parseString(this) + val jsonObject = element.asJsonObject + return jsonObject.get("message").asString } fun String.compressImage(context: Context, listener: OnImageCompressListener) { @@ -93,9 +93,6 @@ .load(this) .ignoreBy(100) .setTargetDir(context.createCompressImageDir().toString()) - .filter { - !(it.isBlank() || it.lowercase(Locale.getDefault()).endsWith(".gif")) - } .setCompressListener(object : OnCompressListener { override fun onStart() { 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 96df110..cd25fca 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 @@ -1,26 +1,25 @@ package com.casic.app.smartwell.fragment -import android.graphics.Point +import android.graphics.Color +import android.graphics.drawable.BitmapDrawable +import android.graphics.drawable.Drawable 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 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.LatLngBounds import com.amap.api.maps.model.Marker -import com.amap.api.maps.model.MarkerOptions import com.casic.app.smartwell.R import com.casic.app.smartwell.databinding.FragmentHomeBinding +import com.casic.app.smartwell.extensions.drawCircle import com.casic.app.smartwell.extensions.initImmersionBar -import com.casic.app.smartwell.extensions.valueToType import com.casic.app.smartwell.model.MapWellListModel import com.casic.app.smartwell.utils.LocaleConstant import com.casic.app.smartwell.utils.RouteOnMap @@ -31,9 +30,16 @@ import com.casic.app.smartwell.view.WellOperationActivity import com.casic.app.smartwell.vm.OrderViewModel import com.casic.app.smartwell.vm.WellViewModel +import com.casic.app.smartwell.widgets.MapWellPopup +import com.casic.app.smartwell.widgets.cluster.ClusterItem +import com.casic.app.smartwell.widgets.cluster.ClusterOnClickListener +import com.casic.app.smartwell.widgets.cluster.ClusterOverlay +import com.casic.app.smartwell.widgets.cluster.RegionItem 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.convertDrawable +import com.pengxh.kt.lite.extensions.dp2px import com.pengxh.kt.lite.extensions.navigatePageTo import com.pengxh.kt.lite.extensions.show import com.pengxh.kt.lite.utils.LoadingDialogHub @@ -43,35 +49,23 @@ /** * 地图点位带聚合效果 * */ -class HomePageHaveClusterFragment : KotlinBaseFragment(), AMap.OnMapLoadedListener, - AMap.OnCameraChangeListener, AMap.OnMarkerClickListener, AMap.InfoWindowAdapter, - AMap.OnInfoWindowClickListener { +class HomePageHaveClusterFragment : KotlinBaseFragment(), + AMap.OnCameraChangeListener { private val kTag = "HaveClusterFragment" private val easyPopupWindow by lazy { EasyPopupWindow(requireContext()) } - private lateinit var wellViewModel: WellViewModel - private lateinit var orderViewModel: OrderViewModel - private lateinit var aMap: AMap - - /** - * 所有的marker - */ - private var allMarkerOptions: MutableList = ArrayList() - - /** - * 视野内的marker - */ - private var markerOptionsInView: MutableList = ArrayList() - - /** - * 自定义Marker弹出框 - * */ - private lateinit var v: View + private val regionRadius by lazy { LocaleConstant.RADIUS_SIZE.dp2px(requireContext()) } + private val infoPopup by lazy { MapWellPopup(requireContext()) } /** * 所有窨井列表信息集合 * */ - private var wellModels: MutableList = ArrayList() + private val wellModels = ArrayList() + private val backDrawables = HashMap() + private lateinit var wellViewModel: WellViewModel + private lateinit var orderViewModel: OrderViewModel + private lateinit var aMap: AMap + private var clusterOverlay: ClusterOverlay? = null override fun initViewBinding( inflater: LayoutInflater, @@ -106,6 +100,9 @@ } }) + //地图初始化 + initMap(savedInstanceState) + //初始化vm wellViewModel = ViewModelProvider(this)[WellViewModel::class.java] orderViewModel = ViewModelProvider(this)[OrderViewModel::class.java] @@ -120,25 +117,19 @@ val latitudeList: MutableList = ArrayList() val longitudeList: MutableList = ArrayList() it.data?.forEach { well -> - val lat = well.latGaode.toString() - val lng = well.lngGaode.toString() + val lat = well.latGaode + val lng = well.lngGaode if (lat.isNotBlank() && lng.isNotBlank()) { //返回true代表当前位置在大陆、港澳地区,反之不在 val latitude = lat.toDouble() val longitude = lng.toDouble() if (CoordinateConverter.isAMapDataAvailable(latitude, longitude)) { - //缓存所有设备详情,点击Marker时候需要 + //缓存所有井 wellModels.add(well) + //分别缓存经、纬度 latitudeList.add(latitude) longitudeList.add(longitude) - //将所有设备信息转化缓存为Marker点 - allMarkerOptions.add( - MarkerOptions() - .position(LatLng(latitude, longitude)) - .title(well.wellTypeName) - .snippet(well.wellName) - ) } } } @@ -160,12 +151,12 @@ val cameraPosition = CameraPosition(centerLatLng, 16f, 0f, 0f) val cameraUpdate = CameraUpdateFactory.newCameraPosition(cameraPosition) aMap.animateCamera(cameraUpdate, 1500, null) + + //显示点数据 + displayWellOnMap() } } - //地图初始化 - initMap(savedInstanceState) - //获取窨井监控数据 wellViewModel.countResultModel.observe(this) { binding.deployedWellView.text = it["bfWell"] @@ -220,17 +211,10 @@ uiSettings.isCompassEnabled = true uiSettings.zoomPosition = AMapOptions.ZOOM_POSITION_RIGHT_CENTER uiSettings.isTiltGesturesEnabled = false//不许地图随手势倾斜角度 + uiSettings.isRotateGesturesEnabled = false//不允许地图随手势改变方位 - // 地图加载成功监听 - aMap.addOnMapLoadedListener(this) // 地图缩放监听 aMap.addOnCameraChangeListener(this) - // marker 点击事件监听 - aMap.addOnMarkerClickListener(this) - // 点击marker弹出自定义popup - aMap.setInfoWindowAdapter(this) - //信息窗点击事件 - aMap.addOnInfoWindowClickListener(this) } override fun initEvent() { @@ -259,9 +243,111 @@ } - override fun onMapLoaded() { - //地图加载成功之后显示聚合点数据 - initClustersMarkers() + private fun displayWellOnMap() { + clusterOverlay?.onDestroy() + val clusterItems = ArrayList() + + wellModels.forEach { + val latitude = it.latGaode.toDouble() + val longitude = it.lngGaode.toDouble() + + val latLng = LatLng(latitude, longitude, false) + val regionItem = RegionItem(latLng, it) + clusterItems.add(regionItem) + } + + clusterOverlay = ClusterOverlay(requireContext(), aMap, clusterItems, regionRadius) + clusterOverlay?.setClusterRender { clusterNum -> + //聚合圆半径 + val radius = 100.dp2px(requireContext()) + if (clusterNum == 0) { + var bitmapDrawable = backDrawables[0] + if (bitmapDrawable == null) { + bitmapDrawable = BitmapDrawable( + null, radius.drawCircle(Color.argb(159, 100, 149, 237)) + ) + backDrawables[0] = bitmapDrawable + } + bitmapDrawable + } + if (clusterNum == 1) { + var bitmapDrawable = backDrawables[1] + if (bitmapDrawable == null) { + bitmapDrawable = R.mipmap.well_location.convertDrawable(requireContext())!! + backDrawables[1] = bitmapDrawable + } + bitmapDrawable + } else if (clusterNum < 5) { + var bitmapDrawable = backDrawables[2] + if (bitmapDrawable == null) { + bitmapDrawable = BitmapDrawable( + null, radius.drawCircle(Color.argb(159, 100, 149, 237)) + ) + backDrawables[2] = bitmapDrawable + } + bitmapDrawable + } else if (clusterNum < 10) { + var bitmapDrawable = backDrawables[3] + if (bitmapDrawable == null) { + bitmapDrawable = BitmapDrawable( + null, radius.drawCircle(Color.argb(199, 30, 144, 255)) + ) + backDrawables[3] = bitmapDrawable + } + bitmapDrawable + } else { + var bitmapDrawable = backDrawables[4] + if (bitmapDrawable == null) { + bitmapDrawable = BitmapDrawable( + null, radius.drawCircle(Color.argb(235, 65, 105, 225)) + ) + backDrawables[4] = bitmapDrawable + } + bitmapDrawable + } + } + + clusterOverlay?.setOnClusterClickListener(object : ClusterOnClickListener { + override fun onMarkerClicked(marker: Marker?, items: List) { + if (items.size > 1) { + "请缩放地图比例在查看数据".show(requireContext()) + return + } + + var item: RegionItem? = null + val builder = LatLngBounds.Builder() + for (clusterItem in items) { + builder.include(clusterItem.position) + item = clusterItem as RegionItem + } + + item?.apply { + showWellPopup(well) + } + } + }) + } + + private fun showWellPopup(well: MapWellListModel.DataModel) { + infoPopup.set(well, object : MapWellPopup.OnPopupWindowClickListener { + override fun onPopupClicked(lat: Double, lng: Double) { + AlertControlDialog.Builder().setContext(requireContext()).setTitle("操作提示") + .setMessage("确定要前往吗").setNegativeButton("取消").setPositiveButton("确定") + .setOnDialogButtonClickListener(object : + AlertControlDialog.OnDialogButtonClickListener { + override fun onConfirmClick() { + RouteOnMap.startNavigation( + requireContext(), "", LatLng(lat, lng) + ) + } + + override fun onCancelClick() { + + } + }).build().show() + } + }) + infoPopup.showAsDropDown(binding.rightOptionView) } override fun onCameraChange(p0: CameraPosition?) { @@ -282,103 +368,10 @@ } } - //获取视野内的marker 根据聚合算法合成自定义的marker 显示视野内的marker override fun onCameraChangeFinish(p0: CameraPosition?) { //地图缩放之后显示聚合点数据 LoadingDialogHub.dismiss() httpCountDownTimer.cancel() - initClustersMarkers() - } - - private fun initClustersMarkers() { - 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 { - v = LayoutInflater.from(requireContext()).inflate(R.layout.popup_map_info, null) - - //显示闸井信息 - marker?.showInfoWindow() - return true - } - - override fun getInfoWindow(marker: Marker?): View { - //反射得到popup里面的控件对象 - val wellNameView = v.findViewById(R.id.wellNameView) - val wellCodeView = v.findViewById(R.id.wellCodeView) - val wellTypeView = v.findViewById(R.id.wellTypeView) - val wellStateView = v.findViewById(R.id.wellStateView) - val deepView = v.findViewById(R.id.deepView) - val locationView = v.findViewById(R.id.locationView) - - //绑定数据 - val clickedLatLng = marker?.position!! - wellModels.forEach { well -> - if (clickedLatLng.latitude == well.latGaode!!.toDouble() - && clickedLatLng.longitude == well.lngGaode!!.toDouble() - ) { - wellNameView.text = String.format("点位名称: ${well.wellName}") - wellCodeView.text = String.format("点位编号: ${well.wellCode}") - wellTypeView.text = String.format("点位类型: ${well.wellType.valueToType()}") - val bfztName = if (well.bfzt == "1") { - "已布防" - } else { - "已撤防" - } - wellStateView.text = String.format("布/撤防状态: $bfztName") - deepView.text = String.format("点位深度: ${well.deep}m") - locationView.text = String.format("详细位置: ${well.position}") - } - } - return v - } - - /** - * 此方法不能修改整个 InfoWindow 的背景和边框,无论自定义的样式是什么样,SDK 都会在最外层添加一个默认的边框 - * */ - override fun getInfoContents(p0: Marker?): View? = null - - override fun onInfoWindowClick(p0: Marker?) { - p0?.apply { - AlertControlDialog.Builder() - .setContext(requireContext()) - .setTitle("操作提示") - .setMessage("确定要前往吗") - .setNegativeButton("取消") - .setPositiveButton("确定") - .setOnDialogButtonClickListener(object : - AlertControlDialog.OnDialogButtonClickListener { - override fun onConfirmClick() { - val lat = position.latitude.toString() - val lng = position.longitude.toString() - if (lat.isBlank() || lng.isBlank()) { - "点位经纬度异常,无法开启导航".show(requireContext()) - return - } - RouteOnMap.startNavigation( - requireContext(), snippet, LatLng(lat.toDouble(), lng.toDouble()) - ) - } - - override fun onCancelClick() { - - } - }).build().show() - } } /***以下是地图生命周期管理************************************************************************/ 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 a54d213..bfa7a57 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 @@ -44,8 +44,8 @@ * 地图点位不带聚合效果 * */ class HomePageNoClusterFragment : KotlinBaseFragment(), - AMap.OnMapLoadedListener, AMap.OnCameraChangeListener, AMap.OnMarkerClickListener, - AMap.InfoWindowAdapter, AMap.OnInfoWindowClickListener { + AMap.OnCameraChangeListener, AMap.OnMarkerClickListener, AMap.InfoWindowAdapter, + AMap.OnInfoWindowClickListener { private val kTag = "NoClusterFragment" private val easyPopupWindow by lazy { EasyPopupWindow(requireContext()) } @@ -109,6 +109,9 @@ wellViewModel = ViewModelProvider(this)[WellViewModel::class.java] orderViewModel = ViewModelProvider(this)[OrderViewModel::class.java] + //地图初始化 + initMap(savedInstanceState) + //获取所有窨井数据 httpCountDownTimer.start() LoadingDialogHub.show(requireActivity(), "数据加载中,请稍后...") @@ -157,12 +160,12 @@ val cameraPosition = CameraPosition(centerLatLng, 16f, 0f, 0f) val cameraUpdate = CameraUpdateFactory.newCameraPosition(cameraPosition) aMap.animateCamera(cameraUpdate, 1500, null) + + //显示点数据 + displayWellOnMap() } } - //地图初始化 - initMap(savedInstanceState) - //获取窨井监控数据 wellViewModel.countResultModel.observe(this) { binding.deployedWellView.text = it["bfWell"] @@ -214,9 +217,8 @@ uiSettings.isCompassEnabled = true uiSettings.zoomPosition = AMapOptions.ZOOM_POSITION_RIGHT_CENTER uiSettings.isTiltGesturesEnabled = false//不许地图随手势倾斜角度 + uiSettings.isRotateGesturesEnabled = false//不允许地图随手势改变方位 - // 地图加载成功监听 - aMap.addOnMapLoadedListener(this) // 地图缩放监听 aMap.addOnCameraChangeListener(this) // marker 点击事件监听 @@ -253,11 +255,6 @@ } - override fun onMapLoaded() { - //地图加载成功之后显示聚合点数据 - initClustersMarkers() - } - override fun onCameraChange(p0: CameraPosition?) { } @@ -281,10 +278,9 @@ //地图缩放之后显示聚合点数据 LoadingDialogHub.dismiss() httpCountDownTimer.cancel() - initClustersMarkers() } - private fun initClustersMarkers() { + private fun displayWellOnMap() { val proj = aMap.projection val dm = resources.displayMetrics var screenLocation: Point diff --git a/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.java b/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.java deleted file mode 100644 index d8b18ef..0000000 --- a/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.java +++ /dev/null @@ -1,50 +0,0 @@ -package com.casic.app.smartwell.model; - -public class ErrorMessageModel { - - private int code; - private String data; - private String exceptionClazz; - private String message; - private boolean success; - - public int getCode() { - return code; - } - - public void setCode(int code) { - this.code = code; - } - - public String getData() { - return data; - } - - public void setData(String data) { - this.data = data; - } - - public String getExceptionClazz() { - return exceptionClazz; - } - - public void setExceptionClazz(String exceptionClazz) { - this.exceptionClazz = exceptionClazz; - } - - public String getMessage() { - return message; - } - - public void setMessage(String message) { - this.message = message; - } - - public boolean isSuccess() { - return success; - } - - public void setSuccess(boolean success) { - this.success = success; - } -} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/extensions/Int.kt b/app/src/main/java/com/casic/app/smartwell/extensions/Int.kt index de0617b..a0a5e33 100644 --- a/app/src/main/java/com/casic/app/smartwell/extensions/Int.kt +++ b/app/src/main/java/com/casic/app/smartwell/extensions/Int.kt @@ -1,9 +1,24 @@ package com.casic.app.smartwell.extensions +import android.graphics.Bitmap +import android.graphics.Canvas +import android.graphics.Paint +import android.graphics.RectF + fun Int.toLevel(): String { return if (this == 0) { "" } else { this.toString() } +} + +fun Int.drawCircle(color: Int): Bitmap? { + val bitmap = Bitmap.createBitmap(this * 2, this * 2, Bitmap.Config.ARGB_8888) + val canvas = Canvas(bitmap) + val paint = Paint() + val rectF = RectF(0f, 0f, (this * 2).toFloat(), (this * 2).toFloat()) + paint.color = color + canvas.drawArc(rectF, 0f, 360f, true, paint) + return bitmap } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt index 6b6ca3e..5e45534 100644 --- a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt +++ b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt @@ -2,17 +2,13 @@ import android.content.Context import com.casic.app.smartwell.callback.OnImageCompressListener -import com.casic.app.smartwell.model.ErrorMessageModel import com.casic.app.smartwell.utils.LocaleConstant -import com.google.gson.Gson -import com.google.gson.reflect.TypeToken +import com.google.gson.JsonParser import com.pengxh.kt.lite.extensions.createCompressImageDir import com.pengxh.kt.lite.utils.SaveKeyValues -import org.json.JSONObject import top.zibin.luban.Luban import top.zibin.luban.OnCompressListener import java.io.File -import java.util.Locale /** * String扩展方法 @@ -74,18 +70,22 @@ } } -fun String.separateResponseCode(): Int { +fun String.getResponseCode(): Int { if (this.isBlank()) { return 404 } - return JSONObject(this).getInt("code") + val element = JsonParser.parseString(this) + val jsonObject = element.asJsonObject + return jsonObject.get("code").asInt } -fun String.toErrorMessage(): String { - val errorModel = Gson().fromJson( - this, object : TypeToken() {}.type - ) - return errorModel.message.toString() +fun String.getResponseMessage(): String { + if (this.isBlank()) { + return "" + } + val element = JsonParser.parseString(this) + val jsonObject = element.asJsonObject + return jsonObject.get("message").asString } fun String.compressImage(context: Context, listener: OnImageCompressListener) { @@ -93,9 +93,6 @@ .load(this) .ignoreBy(100) .setTargetDir(context.createCompressImageDir().toString()) - .filter { - !(it.isBlank() || it.lowercase(Locale.getDefault()).endsWith(".gif")) - } .setCompressListener(object : OnCompressListener { override fun onStart() { 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 96df110..cd25fca 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 @@ -1,26 +1,25 @@ package com.casic.app.smartwell.fragment -import android.graphics.Point +import android.graphics.Color +import android.graphics.drawable.BitmapDrawable +import android.graphics.drawable.Drawable 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 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.LatLngBounds import com.amap.api.maps.model.Marker -import com.amap.api.maps.model.MarkerOptions import com.casic.app.smartwell.R import com.casic.app.smartwell.databinding.FragmentHomeBinding +import com.casic.app.smartwell.extensions.drawCircle import com.casic.app.smartwell.extensions.initImmersionBar -import com.casic.app.smartwell.extensions.valueToType import com.casic.app.smartwell.model.MapWellListModel import com.casic.app.smartwell.utils.LocaleConstant import com.casic.app.smartwell.utils.RouteOnMap @@ -31,9 +30,16 @@ import com.casic.app.smartwell.view.WellOperationActivity import com.casic.app.smartwell.vm.OrderViewModel import com.casic.app.smartwell.vm.WellViewModel +import com.casic.app.smartwell.widgets.MapWellPopup +import com.casic.app.smartwell.widgets.cluster.ClusterItem +import com.casic.app.smartwell.widgets.cluster.ClusterOnClickListener +import com.casic.app.smartwell.widgets.cluster.ClusterOverlay +import com.casic.app.smartwell.widgets.cluster.RegionItem 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.convertDrawable +import com.pengxh.kt.lite.extensions.dp2px import com.pengxh.kt.lite.extensions.navigatePageTo import com.pengxh.kt.lite.extensions.show import com.pengxh.kt.lite.utils.LoadingDialogHub @@ -43,35 +49,23 @@ /** * 地图点位带聚合效果 * */ -class HomePageHaveClusterFragment : KotlinBaseFragment(), AMap.OnMapLoadedListener, - AMap.OnCameraChangeListener, AMap.OnMarkerClickListener, AMap.InfoWindowAdapter, - AMap.OnInfoWindowClickListener { +class HomePageHaveClusterFragment : KotlinBaseFragment(), + AMap.OnCameraChangeListener { private val kTag = "HaveClusterFragment" private val easyPopupWindow by lazy { EasyPopupWindow(requireContext()) } - private lateinit var wellViewModel: WellViewModel - private lateinit var orderViewModel: OrderViewModel - private lateinit var aMap: AMap - - /** - * 所有的marker - */ - private var allMarkerOptions: MutableList = ArrayList() - - /** - * 视野内的marker - */ - private var markerOptionsInView: MutableList = ArrayList() - - /** - * 自定义Marker弹出框 - * */ - private lateinit var v: View + private val regionRadius by lazy { LocaleConstant.RADIUS_SIZE.dp2px(requireContext()) } + private val infoPopup by lazy { MapWellPopup(requireContext()) } /** * 所有窨井列表信息集合 * */ - private var wellModels: MutableList = ArrayList() + private val wellModels = ArrayList() + private val backDrawables = HashMap() + private lateinit var wellViewModel: WellViewModel + private lateinit var orderViewModel: OrderViewModel + private lateinit var aMap: AMap + private var clusterOverlay: ClusterOverlay? = null override fun initViewBinding( inflater: LayoutInflater, @@ -106,6 +100,9 @@ } }) + //地图初始化 + initMap(savedInstanceState) + //初始化vm wellViewModel = ViewModelProvider(this)[WellViewModel::class.java] orderViewModel = ViewModelProvider(this)[OrderViewModel::class.java] @@ -120,25 +117,19 @@ val latitudeList: MutableList = ArrayList() val longitudeList: MutableList = ArrayList() it.data?.forEach { well -> - val lat = well.latGaode.toString() - val lng = well.lngGaode.toString() + val lat = well.latGaode + val lng = well.lngGaode if (lat.isNotBlank() && lng.isNotBlank()) { //返回true代表当前位置在大陆、港澳地区,反之不在 val latitude = lat.toDouble() val longitude = lng.toDouble() if (CoordinateConverter.isAMapDataAvailable(latitude, longitude)) { - //缓存所有设备详情,点击Marker时候需要 + //缓存所有井 wellModels.add(well) + //分别缓存经、纬度 latitudeList.add(latitude) longitudeList.add(longitude) - //将所有设备信息转化缓存为Marker点 - allMarkerOptions.add( - MarkerOptions() - .position(LatLng(latitude, longitude)) - .title(well.wellTypeName) - .snippet(well.wellName) - ) } } } @@ -160,12 +151,12 @@ val cameraPosition = CameraPosition(centerLatLng, 16f, 0f, 0f) val cameraUpdate = CameraUpdateFactory.newCameraPosition(cameraPosition) aMap.animateCamera(cameraUpdate, 1500, null) + + //显示点数据 + displayWellOnMap() } } - //地图初始化 - initMap(savedInstanceState) - //获取窨井监控数据 wellViewModel.countResultModel.observe(this) { binding.deployedWellView.text = it["bfWell"] @@ -220,17 +211,10 @@ uiSettings.isCompassEnabled = true uiSettings.zoomPosition = AMapOptions.ZOOM_POSITION_RIGHT_CENTER uiSettings.isTiltGesturesEnabled = false//不许地图随手势倾斜角度 + uiSettings.isRotateGesturesEnabled = false//不允许地图随手势改变方位 - // 地图加载成功监听 - aMap.addOnMapLoadedListener(this) // 地图缩放监听 aMap.addOnCameraChangeListener(this) - // marker 点击事件监听 - aMap.addOnMarkerClickListener(this) - // 点击marker弹出自定义popup - aMap.setInfoWindowAdapter(this) - //信息窗点击事件 - aMap.addOnInfoWindowClickListener(this) } override fun initEvent() { @@ -259,9 +243,111 @@ } - override fun onMapLoaded() { - //地图加载成功之后显示聚合点数据 - initClustersMarkers() + private fun displayWellOnMap() { + clusterOverlay?.onDestroy() + val clusterItems = ArrayList() + + wellModels.forEach { + val latitude = it.latGaode.toDouble() + val longitude = it.lngGaode.toDouble() + + val latLng = LatLng(latitude, longitude, false) + val regionItem = RegionItem(latLng, it) + clusterItems.add(regionItem) + } + + clusterOverlay = ClusterOverlay(requireContext(), aMap, clusterItems, regionRadius) + clusterOverlay?.setClusterRender { clusterNum -> + //聚合圆半径 + val radius = 100.dp2px(requireContext()) + if (clusterNum == 0) { + var bitmapDrawable = backDrawables[0] + if (bitmapDrawable == null) { + bitmapDrawable = BitmapDrawable( + null, radius.drawCircle(Color.argb(159, 100, 149, 237)) + ) + backDrawables[0] = bitmapDrawable + } + bitmapDrawable + } + if (clusterNum == 1) { + var bitmapDrawable = backDrawables[1] + if (bitmapDrawable == null) { + bitmapDrawable = R.mipmap.well_location.convertDrawable(requireContext())!! + backDrawables[1] = bitmapDrawable + } + bitmapDrawable + } else if (clusterNum < 5) { + var bitmapDrawable = backDrawables[2] + if (bitmapDrawable == null) { + bitmapDrawable = BitmapDrawable( + null, radius.drawCircle(Color.argb(159, 100, 149, 237)) + ) + backDrawables[2] = bitmapDrawable + } + bitmapDrawable + } else if (clusterNum < 10) { + var bitmapDrawable = backDrawables[3] + if (bitmapDrawable == null) { + bitmapDrawable = BitmapDrawable( + null, radius.drawCircle(Color.argb(199, 30, 144, 255)) + ) + backDrawables[3] = bitmapDrawable + } + bitmapDrawable + } else { + var bitmapDrawable = backDrawables[4] + if (bitmapDrawable == null) { + bitmapDrawable = BitmapDrawable( + null, radius.drawCircle(Color.argb(235, 65, 105, 225)) + ) + backDrawables[4] = bitmapDrawable + } + bitmapDrawable + } + } + + clusterOverlay?.setOnClusterClickListener(object : ClusterOnClickListener { + override fun onMarkerClicked(marker: Marker?, items: List) { + if (items.size > 1) { + "请缩放地图比例在查看数据".show(requireContext()) + return + } + + var item: RegionItem? = null + val builder = LatLngBounds.Builder() + for (clusterItem in items) { + builder.include(clusterItem.position) + item = clusterItem as RegionItem + } + + item?.apply { + showWellPopup(well) + } + } + }) + } + + private fun showWellPopup(well: MapWellListModel.DataModel) { + infoPopup.set(well, object : MapWellPopup.OnPopupWindowClickListener { + override fun onPopupClicked(lat: Double, lng: Double) { + AlertControlDialog.Builder().setContext(requireContext()).setTitle("操作提示") + .setMessage("确定要前往吗").setNegativeButton("取消").setPositiveButton("确定") + .setOnDialogButtonClickListener(object : + AlertControlDialog.OnDialogButtonClickListener { + override fun onConfirmClick() { + RouteOnMap.startNavigation( + requireContext(), "", LatLng(lat, lng) + ) + } + + override fun onCancelClick() { + + } + }).build().show() + } + }) + infoPopup.showAsDropDown(binding.rightOptionView) } override fun onCameraChange(p0: CameraPosition?) { @@ -282,103 +368,10 @@ } } - //获取视野内的marker 根据聚合算法合成自定义的marker 显示视野内的marker override fun onCameraChangeFinish(p0: CameraPosition?) { //地图缩放之后显示聚合点数据 LoadingDialogHub.dismiss() httpCountDownTimer.cancel() - initClustersMarkers() - } - - private fun initClustersMarkers() { - 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 { - v = LayoutInflater.from(requireContext()).inflate(R.layout.popup_map_info, null) - - //显示闸井信息 - marker?.showInfoWindow() - return true - } - - override fun getInfoWindow(marker: Marker?): View { - //反射得到popup里面的控件对象 - val wellNameView = v.findViewById(R.id.wellNameView) - val wellCodeView = v.findViewById(R.id.wellCodeView) - val wellTypeView = v.findViewById(R.id.wellTypeView) - val wellStateView = v.findViewById(R.id.wellStateView) - val deepView = v.findViewById(R.id.deepView) - val locationView = v.findViewById(R.id.locationView) - - //绑定数据 - val clickedLatLng = marker?.position!! - wellModels.forEach { well -> - if (clickedLatLng.latitude == well.latGaode!!.toDouble() - && clickedLatLng.longitude == well.lngGaode!!.toDouble() - ) { - wellNameView.text = String.format("点位名称: ${well.wellName}") - wellCodeView.text = String.format("点位编号: ${well.wellCode}") - wellTypeView.text = String.format("点位类型: ${well.wellType.valueToType()}") - val bfztName = if (well.bfzt == "1") { - "已布防" - } else { - "已撤防" - } - wellStateView.text = String.format("布/撤防状态: $bfztName") - deepView.text = String.format("点位深度: ${well.deep}m") - locationView.text = String.format("详细位置: ${well.position}") - } - } - return v - } - - /** - * 此方法不能修改整个 InfoWindow 的背景和边框,无论自定义的样式是什么样,SDK 都会在最外层添加一个默认的边框 - * */ - override fun getInfoContents(p0: Marker?): View? = null - - override fun onInfoWindowClick(p0: Marker?) { - p0?.apply { - AlertControlDialog.Builder() - .setContext(requireContext()) - .setTitle("操作提示") - .setMessage("确定要前往吗") - .setNegativeButton("取消") - .setPositiveButton("确定") - .setOnDialogButtonClickListener(object : - AlertControlDialog.OnDialogButtonClickListener { - override fun onConfirmClick() { - val lat = position.latitude.toString() - val lng = position.longitude.toString() - if (lat.isBlank() || lng.isBlank()) { - "点位经纬度异常,无法开启导航".show(requireContext()) - return - } - RouteOnMap.startNavigation( - requireContext(), snippet, LatLng(lat.toDouble(), lng.toDouble()) - ) - } - - override fun onCancelClick() { - - } - }).build().show() - } } /***以下是地图生命周期管理************************************************************************/ 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 a54d213..bfa7a57 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 @@ -44,8 +44,8 @@ * 地图点位不带聚合效果 * */ class HomePageNoClusterFragment : KotlinBaseFragment(), - AMap.OnMapLoadedListener, AMap.OnCameraChangeListener, AMap.OnMarkerClickListener, - AMap.InfoWindowAdapter, AMap.OnInfoWindowClickListener { + AMap.OnCameraChangeListener, AMap.OnMarkerClickListener, AMap.InfoWindowAdapter, + AMap.OnInfoWindowClickListener { private val kTag = "NoClusterFragment" private val easyPopupWindow by lazy { EasyPopupWindow(requireContext()) } @@ -109,6 +109,9 @@ wellViewModel = ViewModelProvider(this)[WellViewModel::class.java] orderViewModel = ViewModelProvider(this)[OrderViewModel::class.java] + //地图初始化 + initMap(savedInstanceState) + //获取所有窨井数据 httpCountDownTimer.start() LoadingDialogHub.show(requireActivity(), "数据加载中,请稍后...") @@ -157,12 +160,12 @@ val cameraPosition = CameraPosition(centerLatLng, 16f, 0f, 0f) val cameraUpdate = CameraUpdateFactory.newCameraPosition(cameraPosition) aMap.animateCamera(cameraUpdate, 1500, null) + + //显示点数据 + displayWellOnMap() } } - //地图初始化 - initMap(savedInstanceState) - //获取窨井监控数据 wellViewModel.countResultModel.observe(this) { binding.deployedWellView.text = it["bfWell"] @@ -214,9 +217,8 @@ uiSettings.isCompassEnabled = true uiSettings.zoomPosition = AMapOptions.ZOOM_POSITION_RIGHT_CENTER uiSettings.isTiltGesturesEnabled = false//不许地图随手势倾斜角度 + uiSettings.isRotateGesturesEnabled = false//不允许地图随手势改变方位 - // 地图加载成功监听 - aMap.addOnMapLoadedListener(this) // 地图缩放监听 aMap.addOnCameraChangeListener(this) // marker 点击事件监听 @@ -253,11 +255,6 @@ } - override fun onMapLoaded() { - //地图加载成功之后显示聚合点数据 - initClustersMarkers() - } - override fun onCameraChange(p0: CameraPosition?) { } @@ -281,10 +278,9 @@ //地图缩放之后显示聚合点数据 LoadingDialogHub.dismiss() httpCountDownTimer.cancel() - initClustersMarkers() } - private fun initClustersMarkers() { + private fun displayWellOnMap() { val proj = aMap.projection val dm = resources.displayMetrics var screenLocation: Point diff --git a/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.java b/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.java deleted file mode 100644 index d8b18ef..0000000 --- a/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.java +++ /dev/null @@ -1,50 +0,0 @@ -package com.casic.app.smartwell.model; - -public class ErrorMessageModel { - - private int code; - private String data; - private String exceptionClazz; - private String message; - private boolean success; - - public int getCode() { - return code; - } - - public void setCode(int code) { - this.code = code; - } - - public String getData() { - return data; - } - - public void setData(String data) { - this.data = data; - } - - public String getExceptionClazz() { - return exceptionClazz; - } - - public void setExceptionClazz(String exceptionClazz) { - this.exceptionClazz = exceptionClazz; - } - - public String getMessage() { - return message; - } - - public void setMessage(String message) { - this.message = message; - } - - public boolean isSuccess() { - return success; - } - - public void setSuccess(boolean success) { - this.success = success; - } -} \ No newline at end of file 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 new file mode 100644 index 0000000..215ac0c --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/PipelineModel.java @@ -0,0 +1,328 @@ +package com.casic.app.smartwell.model; + +import java.util.List; + +public class PipelineModel { + + private Integer code; + private DataModel data; + private String message; + private Boolean success; + + public Integer getCode() { + return code; + } + + public void setCode(Integer code) { + this.code = code; + } + + public DataModel getData() { + return data; + } + + public void setData(DataModel data) { + this.data = data; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + public Boolean getSuccess() { + return success; + } + + public void setSuccess(Boolean success) { + this.success = success; + } + + public static class DataModel { + private List rows; + private Integer total; + + public List getRows() { + return rows; + } + + public void setRows(List rows) { + this.rows = rows; + } + + public Integer getTotal() { + return total; + } + + public void setTotal(Integer total) { + this.total = total; + } + + 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 getBuryMode() { + return buryMode; + } + + public void setBuryMode(String buryMode) { + this.buryMode = buryMode; + } + + public String getConstructEra() { + return constructEra; + } + + public void setConstructEra(String constructEra) { + this.constructEra = constructEra; + } + + 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; + } + } + } +} diff --git a/app/src/main/java/com/casic/app/smartwell/extensions/Int.kt b/app/src/main/java/com/casic/app/smartwell/extensions/Int.kt index de0617b..a0a5e33 100644 --- a/app/src/main/java/com/casic/app/smartwell/extensions/Int.kt +++ b/app/src/main/java/com/casic/app/smartwell/extensions/Int.kt @@ -1,9 +1,24 @@ package com.casic.app.smartwell.extensions +import android.graphics.Bitmap +import android.graphics.Canvas +import android.graphics.Paint +import android.graphics.RectF + fun Int.toLevel(): String { return if (this == 0) { "" } else { this.toString() } +} + +fun Int.drawCircle(color: Int): Bitmap? { + val bitmap = Bitmap.createBitmap(this * 2, this * 2, Bitmap.Config.ARGB_8888) + val canvas = Canvas(bitmap) + val paint = Paint() + val rectF = RectF(0f, 0f, (this * 2).toFloat(), (this * 2).toFloat()) + paint.color = color + canvas.drawArc(rectF, 0f, 360f, true, paint) + return bitmap } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt index 6b6ca3e..5e45534 100644 --- a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt +++ b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt @@ -2,17 +2,13 @@ import android.content.Context import com.casic.app.smartwell.callback.OnImageCompressListener -import com.casic.app.smartwell.model.ErrorMessageModel import com.casic.app.smartwell.utils.LocaleConstant -import com.google.gson.Gson -import com.google.gson.reflect.TypeToken +import com.google.gson.JsonParser import com.pengxh.kt.lite.extensions.createCompressImageDir import com.pengxh.kt.lite.utils.SaveKeyValues -import org.json.JSONObject import top.zibin.luban.Luban import top.zibin.luban.OnCompressListener import java.io.File -import java.util.Locale /** * String扩展方法 @@ -74,18 +70,22 @@ } } -fun String.separateResponseCode(): Int { +fun String.getResponseCode(): Int { if (this.isBlank()) { return 404 } - return JSONObject(this).getInt("code") + val element = JsonParser.parseString(this) + val jsonObject = element.asJsonObject + return jsonObject.get("code").asInt } -fun String.toErrorMessage(): String { - val errorModel = Gson().fromJson( - this, object : TypeToken() {}.type - ) - return errorModel.message.toString() +fun String.getResponseMessage(): String { + if (this.isBlank()) { + return "" + } + val element = JsonParser.parseString(this) + val jsonObject = element.asJsonObject + return jsonObject.get("message").asString } fun String.compressImage(context: Context, listener: OnImageCompressListener) { @@ -93,9 +93,6 @@ .load(this) .ignoreBy(100) .setTargetDir(context.createCompressImageDir().toString()) - .filter { - !(it.isBlank() || it.lowercase(Locale.getDefault()).endsWith(".gif")) - } .setCompressListener(object : OnCompressListener { override fun onStart() { 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 96df110..cd25fca 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 @@ -1,26 +1,25 @@ package com.casic.app.smartwell.fragment -import android.graphics.Point +import android.graphics.Color +import android.graphics.drawable.BitmapDrawable +import android.graphics.drawable.Drawable 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 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.LatLngBounds import com.amap.api.maps.model.Marker -import com.amap.api.maps.model.MarkerOptions import com.casic.app.smartwell.R import com.casic.app.smartwell.databinding.FragmentHomeBinding +import com.casic.app.smartwell.extensions.drawCircle import com.casic.app.smartwell.extensions.initImmersionBar -import com.casic.app.smartwell.extensions.valueToType import com.casic.app.smartwell.model.MapWellListModel import com.casic.app.smartwell.utils.LocaleConstant import com.casic.app.smartwell.utils.RouteOnMap @@ -31,9 +30,16 @@ import com.casic.app.smartwell.view.WellOperationActivity import com.casic.app.smartwell.vm.OrderViewModel import com.casic.app.smartwell.vm.WellViewModel +import com.casic.app.smartwell.widgets.MapWellPopup +import com.casic.app.smartwell.widgets.cluster.ClusterItem +import com.casic.app.smartwell.widgets.cluster.ClusterOnClickListener +import com.casic.app.smartwell.widgets.cluster.ClusterOverlay +import com.casic.app.smartwell.widgets.cluster.RegionItem 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.convertDrawable +import com.pengxh.kt.lite.extensions.dp2px import com.pengxh.kt.lite.extensions.navigatePageTo import com.pengxh.kt.lite.extensions.show import com.pengxh.kt.lite.utils.LoadingDialogHub @@ -43,35 +49,23 @@ /** * 地图点位带聚合效果 * */ -class HomePageHaveClusterFragment : KotlinBaseFragment(), AMap.OnMapLoadedListener, - AMap.OnCameraChangeListener, AMap.OnMarkerClickListener, AMap.InfoWindowAdapter, - AMap.OnInfoWindowClickListener { +class HomePageHaveClusterFragment : KotlinBaseFragment(), + AMap.OnCameraChangeListener { private val kTag = "HaveClusterFragment" private val easyPopupWindow by lazy { EasyPopupWindow(requireContext()) } - private lateinit var wellViewModel: WellViewModel - private lateinit var orderViewModel: OrderViewModel - private lateinit var aMap: AMap - - /** - * 所有的marker - */ - private var allMarkerOptions: MutableList = ArrayList() - - /** - * 视野内的marker - */ - private var markerOptionsInView: MutableList = ArrayList() - - /** - * 自定义Marker弹出框 - * */ - private lateinit var v: View + private val regionRadius by lazy { LocaleConstant.RADIUS_SIZE.dp2px(requireContext()) } + private val infoPopup by lazy { MapWellPopup(requireContext()) } /** * 所有窨井列表信息集合 * */ - private var wellModels: MutableList = ArrayList() + private val wellModels = ArrayList() + private val backDrawables = HashMap() + private lateinit var wellViewModel: WellViewModel + private lateinit var orderViewModel: OrderViewModel + private lateinit var aMap: AMap + private var clusterOverlay: ClusterOverlay? = null override fun initViewBinding( inflater: LayoutInflater, @@ -106,6 +100,9 @@ } }) + //地图初始化 + initMap(savedInstanceState) + //初始化vm wellViewModel = ViewModelProvider(this)[WellViewModel::class.java] orderViewModel = ViewModelProvider(this)[OrderViewModel::class.java] @@ -120,25 +117,19 @@ val latitudeList: MutableList = ArrayList() val longitudeList: MutableList = ArrayList() it.data?.forEach { well -> - val lat = well.latGaode.toString() - val lng = well.lngGaode.toString() + val lat = well.latGaode + val lng = well.lngGaode if (lat.isNotBlank() && lng.isNotBlank()) { //返回true代表当前位置在大陆、港澳地区,反之不在 val latitude = lat.toDouble() val longitude = lng.toDouble() if (CoordinateConverter.isAMapDataAvailable(latitude, longitude)) { - //缓存所有设备详情,点击Marker时候需要 + //缓存所有井 wellModels.add(well) + //分别缓存经、纬度 latitudeList.add(latitude) longitudeList.add(longitude) - //将所有设备信息转化缓存为Marker点 - allMarkerOptions.add( - MarkerOptions() - .position(LatLng(latitude, longitude)) - .title(well.wellTypeName) - .snippet(well.wellName) - ) } } } @@ -160,12 +151,12 @@ val cameraPosition = CameraPosition(centerLatLng, 16f, 0f, 0f) val cameraUpdate = CameraUpdateFactory.newCameraPosition(cameraPosition) aMap.animateCamera(cameraUpdate, 1500, null) + + //显示点数据 + displayWellOnMap() } } - //地图初始化 - initMap(savedInstanceState) - //获取窨井监控数据 wellViewModel.countResultModel.observe(this) { binding.deployedWellView.text = it["bfWell"] @@ -220,17 +211,10 @@ uiSettings.isCompassEnabled = true uiSettings.zoomPosition = AMapOptions.ZOOM_POSITION_RIGHT_CENTER uiSettings.isTiltGesturesEnabled = false//不许地图随手势倾斜角度 + uiSettings.isRotateGesturesEnabled = false//不允许地图随手势改变方位 - // 地图加载成功监听 - aMap.addOnMapLoadedListener(this) // 地图缩放监听 aMap.addOnCameraChangeListener(this) - // marker 点击事件监听 - aMap.addOnMarkerClickListener(this) - // 点击marker弹出自定义popup - aMap.setInfoWindowAdapter(this) - //信息窗点击事件 - aMap.addOnInfoWindowClickListener(this) } override fun initEvent() { @@ -259,9 +243,111 @@ } - override fun onMapLoaded() { - //地图加载成功之后显示聚合点数据 - initClustersMarkers() + private fun displayWellOnMap() { + clusterOverlay?.onDestroy() + val clusterItems = ArrayList() + + wellModels.forEach { + val latitude = it.latGaode.toDouble() + val longitude = it.lngGaode.toDouble() + + val latLng = LatLng(latitude, longitude, false) + val regionItem = RegionItem(latLng, it) + clusterItems.add(regionItem) + } + + clusterOverlay = ClusterOverlay(requireContext(), aMap, clusterItems, regionRadius) + clusterOverlay?.setClusterRender { clusterNum -> + //聚合圆半径 + val radius = 100.dp2px(requireContext()) + if (clusterNum == 0) { + var bitmapDrawable = backDrawables[0] + if (bitmapDrawable == null) { + bitmapDrawable = BitmapDrawable( + null, radius.drawCircle(Color.argb(159, 100, 149, 237)) + ) + backDrawables[0] = bitmapDrawable + } + bitmapDrawable + } + if (clusterNum == 1) { + var bitmapDrawable = backDrawables[1] + if (bitmapDrawable == null) { + bitmapDrawable = R.mipmap.well_location.convertDrawable(requireContext())!! + backDrawables[1] = bitmapDrawable + } + bitmapDrawable + } else if (clusterNum < 5) { + var bitmapDrawable = backDrawables[2] + if (bitmapDrawable == null) { + bitmapDrawable = BitmapDrawable( + null, radius.drawCircle(Color.argb(159, 100, 149, 237)) + ) + backDrawables[2] = bitmapDrawable + } + bitmapDrawable + } else if (clusterNum < 10) { + var bitmapDrawable = backDrawables[3] + if (bitmapDrawable == null) { + bitmapDrawable = BitmapDrawable( + null, radius.drawCircle(Color.argb(199, 30, 144, 255)) + ) + backDrawables[3] = bitmapDrawable + } + bitmapDrawable + } else { + var bitmapDrawable = backDrawables[4] + if (bitmapDrawable == null) { + bitmapDrawable = BitmapDrawable( + null, radius.drawCircle(Color.argb(235, 65, 105, 225)) + ) + backDrawables[4] = bitmapDrawable + } + bitmapDrawable + } + } + + clusterOverlay?.setOnClusterClickListener(object : ClusterOnClickListener { + override fun onMarkerClicked(marker: Marker?, items: List) { + if (items.size > 1) { + "请缩放地图比例在查看数据".show(requireContext()) + return + } + + var item: RegionItem? = null + val builder = LatLngBounds.Builder() + for (clusterItem in items) { + builder.include(clusterItem.position) + item = clusterItem as RegionItem + } + + item?.apply { + showWellPopup(well) + } + } + }) + } + + private fun showWellPopup(well: MapWellListModel.DataModel) { + infoPopup.set(well, object : MapWellPopup.OnPopupWindowClickListener { + override fun onPopupClicked(lat: Double, lng: Double) { + AlertControlDialog.Builder().setContext(requireContext()).setTitle("操作提示") + .setMessage("确定要前往吗").setNegativeButton("取消").setPositiveButton("确定") + .setOnDialogButtonClickListener(object : + AlertControlDialog.OnDialogButtonClickListener { + override fun onConfirmClick() { + RouteOnMap.startNavigation( + requireContext(), "", LatLng(lat, lng) + ) + } + + override fun onCancelClick() { + + } + }).build().show() + } + }) + infoPopup.showAsDropDown(binding.rightOptionView) } override fun onCameraChange(p0: CameraPosition?) { @@ -282,103 +368,10 @@ } } - //获取视野内的marker 根据聚合算法合成自定义的marker 显示视野内的marker override fun onCameraChangeFinish(p0: CameraPosition?) { //地图缩放之后显示聚合点数据 LoadingDialogHub.dismiss() httpCountDownTimer.cancel() - initClustersMarkers() - } - - private fun initClustersMarkers() { - 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 { - v = LayoutInflater.from(requireContext()).inflate(R.layout.popup_map_info, null) - - //显示闸井信息 - marker?.showInfoWindow() - return true - } - - override fun getInfoWindow(marker: Marker?): View { - //反射得到popup里面的控件对象 - val wellNameView = v.findViewById(R.id.wellNameView) - val wellCodeView = v.findViewById(R.id.wellCodeView) - val wellTypeView = v.findViewById(R.id.wellTypeView) - val wellStateView = v.findViewById(R.id.wellStateView) - val deepView = v.findViewById(R.id.deepView) - val locationView = v.findViewById(R.id.locationView) - - //绑定数据 - val clickedLatLng = marker?.position!! - wellModels.forEach { well -> - if (clickedLatLng.latitude == well.latGaode!!.toDouble() - && clickedLatLng.longitude == well.lngGaode!!.toDouble() - ) { - wellNameView.text = String.format("点位名称: ${well.wellName}") - wellCodeView.text = String.format("点位编号: ${well.wellCode}") - wellTypeView.text = String.format("点位类型: ${well.wellType.valueToType()}") - val bfztName = if (well.bfzt == "1") { - "已布防" - } else { - "已撤防" - } - wellStateView.text = String.format("布/撤防状态: $bfztName") - deepView.text = String.format("点位深度: ${well.deep}m") - locationView.text = String.format("详细位置: ${well.position}") - } - } - return v - } - - /** - * 此方法不能修改整个 InfoWindow 的背景和边框,无论自定义的样式是什么样,SDK 都会在最外层添加一个默认的边框 - * */ - override fun getInfoContents(p0: Marker?): View? = null - - override fun onInfoWindowClick(p0: Marker?) { - p0?.apply { - AlertControlDialog.Builder() - .setContext(requireContext()) - .setTitle("操作提示") - .setMessage("确定要前往吗") - .setNegativeButton("取消") - .setPositiveButton("确定") - .setOnDialogButtonClickListener(object : - AlertControlDialog.OnDialogButtonClickListener { - override fun onConfirmClick() { - val lat = position.latitude.toString() - val lng = position.longitude.toString() - if (lat.isBlank() || lng.isBlank()) { - "点位经纬度异常,无法开启导航".show(requireContext()) - return - } - RouteOnMap.startNavigation( - requireContext(), snippet, LatLng(lat.toDouble(), lng.toDouble()) - ) - } - - override fun onCancelClick() { - - } - }).build().show() - } } /***以下是地图生命周期管理************************************************************************/ 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 a54d213..bfa7a57 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 @@ -44,8 +44,8 @@ * 地图点位不带聚合效果 * */ class HomePageNoClusterFragment : KotlinBaseFragment(), - AMap.OnMapLoadedListener, AMap.OnCameraChangeListener, AMap.OnMarkerClickListener, - AMap.InfoWindowAdapter, AMap.OnInfoWindowClickListener { + AMap.OnCameraChangeListener, AMap.OnMarkerClickListener, AMap.InfoWindowAdapter, + AMap.OnInfoWindowClickListener { private val kTag = "NoClusterFragment" private val easyPopupWindow by lazy { EasyPopupWindow(requireContext()) } @@ -109,6 +109,9 @@ wellViewModel = ViewModelProvider(this)[WellViewModel::class.java] orderViewModel = ViewModelProvider(this)[OrderViewModel::class.java] + //地图初始化 + initMap(savedInstanceState) + //获取所有窨井数据 httpCountDownTimer.start() LoadingDialogHub.show(requireActivity(), "数据加载中,请稍后...") @@ -157,12 +160,12 @@ val cameraPosition = CameraPosition(centerLatLng, 16f, 0f, 0f) val cameraUpdate = CameraUpdateFactory.newCameraPosition(cameraPosition) aMap.animateCamera(cameraUpdate, 1500, null) + + //显示点数据 + displayWellOnMap() } } - //地图初始化 - initMap(savedInstanceState) - //获取窨井监控数据 wellViewModel.countResultModel.observe(this) { binding.deployedWellView.text = it["bfWell"] @@ -214,9 +217,8 @@ uiSettings.isCompassEnabled = true uiSettings.zoomPosition = AMapOptions.ZOOM_POSITION_RIGHT_CENTER uiSettings.isTiltGesturesEnabled = false//不许地图随手势倾斜角度 + uiSettings.isRotateGesturesEnabled = false//不允许地图随手势改变方位 - // 地图加载成功监听 - aMap.addOnMapLoadedListener(this) // 地图缩放监听 aMap.addOnCameraChangeListener(this) // marker 点击事件监听 @@ -253,11 +255,6 @@ } - override fun onMapLoaded() { - //地图加载成功之后显示聚合点数据 - initClustersMarkers() - } - override fun onCameraChange(p0: CameraPosition?) { } @@ -281,10 +278,9 @@ //地图缩放之后显示聚合点数据 LoadingDialogHub.dismiss() httpCountDownTimer.cancel() - initClustersMarkers() } - private fun initClustersMarkers() { + private fun displayWellOnMap() { val proj = aMap.projection val dm = resources.displayMetrics var screenLocation: Point diff --git a/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.java b/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.java deleted file mode 100644 index d8b18ef..0000000 --- a/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.java +++ /dev/null @@ -1,50 +0,0 @@ -package com.casic.app.smartwell.model; - -public class ErrorMessageModel { - - private int code; - private String data; - private String exceptionClazz; - private String message; - private boolean success; - - public int getCode() { - return code; - } - - public void setCode(int code) { - this.code = code; - } - - public String getData() { - return data; - } - - public void setData(String data) { - this.data = data; - } - - public String getExceptionClazz() { - return exceptionClazz; - } - - public void setExceptionClazz(String exceptionClazz) { - this.exceptionClazz = exceptionClazz; - } - - public String getMessage() { - return message; - } - - public void setMessage(String message) { - this.message = message; - } - - public boolean isSuccess() { - return success; - } - - public void setSuccess(boolean success) { - this.success = success; - } -} \ No newline at end of file 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 new file mode 100644 index 0000000..215ac0c --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/PipelineModel.java @@ -0,0 +1,328 @@ +package com.casic.app.smartwell.model; + +import java.util.List; + +public class PipelineModel { + + private Integer code; + private DataModel data; + private String message; + private Boolean success; + + public Integer getCode() { + return code; + } + + public void setCode(Integer code) { + this.code = code; + } + + public DataModel getData() { + return data; + } + + public void setData(DataModel data) { + this.data = data; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + public Boolean getSuccess() { + return success; + } + + public void setSuccess(Boolean success) { + this.success = success; + } + + public static class DataModel { + private List rows; + private Integer total; + + public List getRows() { + return rows; + } + + public void setRows(List rows) { + this.rows = rows; + } + + public Integer getTotal() { + return total; + } + + public void setTotal(Integer total) { + this.total = total; + } + + 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 getBuryMode() { + return buryMode; + } + + public void setBuryMode(String buryMode) { + this.buryMode = buryMode; + } + + public String getConstructEra() { + return constructEra; + } + + public void setConstructEra(String constructEra) { + this.constructEra = constructEra; + } + + 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; + } + } + } +} 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 06d3d2b..4f38a2c 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 = 100 //相距多少米才聚合,单位:米 + const val RADIUS_SIZE = 80 //相距多少米才聚合,单位:米 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:11308" + // 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/extensions/Int.kt b/app/src/main/java/com/casic/app/smartwell/extensions/Int.kt index de0617b..a0a5e33 100644 --- a/app/src/main/java/com/casic/app/smartwell/extensions/Int.kt +++ b/app/src/main/java/com/casic/app/smartwell/extensions/Int.kt @@ -1,9 +1,24 @@ package com.casic.app.smartwell.extensions +import android.graphics.Bitmap +import android.graphics.Canvas +import android.graphics.Paint +import android.graphics.RectF + fun Int.toLevel(): String { return if (this == 0) { "" } else { this.toString() } +} + +fun Int.drawCircle(color: Int): Bitmap? { + val bitmap = Bitmap.createBitmap(this * 2, this * 2, Bitmap.Config.ARGB_8888) + val canvas = Canvas(bitmap) + val paint = Paint() + val rectF = RectF(0f, 0f, (this * 2).toFloat(), (this * 2).toFloat()) + paint.color = color + canvas.drawArc(rectF, 0f, 360f, true, paint) + return bitmap } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt index 6b6ca3e..5e45534 100644 --- a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt +++ b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt @@ -2,17 +2,13 @@ import android.content.Context import com.casic.app.smartwell.callback.OnImageCompressListener -import com.casic.app.smartwell.model.ErrorMessageModel import com.casic.app.smartwell.utils.LocaleConstant -import com.google.gson.Gson -import com.google.gson.reflect.TypeToken +import com.google.gson.JsonParser import com.pengxh.kt.lite.extensions.createCompressImageDir import com.pengxh.kt.lite.utils.SaveKeyValues -import org.json.JSONObject import top.zibin.luban.Luban import top.zibin.luban.OnCompressListener import java.io.File -import java.util.Locale /** * String扩展方法 @@ -74,18 +70,22 @@ } } -fun String.separateResponseCode(): Int { +fun String.getResponseCode(): Int { if (this.isBlank()) { return 404 } - return JSONObject(this).getInt("code") + val element = JsonParser.parseString(this) + val jsonObject = element.asJsonObject + return jsonObject.get("code").asInt } -fun String.toErrorMessage(): String { - val errorModel = Gson().fromJson( - this, object : TypeToken() {}.type - ) - return errorModel.message.toString() +fun String.getResponseMessage(): String { + if (this.isBlank()) { + return "" + } + val element = JsonParser.parseString(this) + val jsonObject = element.asJsonObject + return jsonObject.get("message").asString } fun String.compressImage(context: Context, listener: OnImageCompressListener) { @@ -93,9 +93,6 @@ .load(this) .ignoreBy(100) .setTargetDir(context.createCompressImageDir().toString()) - .filter { - !(it.isBlank() || it.lowercase(Locale.getDefault()).endsWith(".gif")) - } .setCompressListener(object : OnCompressListener { override fun onStart() { 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 96df110..cd25fca 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 @@ -1,26 +1,25 @@ package com.casic.app.smartwell.fragment -import android.graphics.Point +import android.graphics.Color +import android.graphics.drawable.BitmapDrawable +import android.graphics.drawable.Drawable 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 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.LatLngBounds import com.amap.api.maps.model.Marker -import com.amap.api.maps.model.MarkerOptions import com.casic.app.smartwell.R import com.casic.app.smartwell.databinding.FragmentHomeBinding +import com.casic.app.smartwell.extensions.drawCircle import com.casic.app.smartwell.extensions.initImmersionBar -import com.casic.app.smartwell.extensions.valueToType import com.casic.app.smartwell.model.MapWellListModel import com.casic.app.smartwell.utils.LocaleConstant import com.casic.app.smartwell.utils.RouteOnMap @@ -31,9 +30,16 @@ import com.casic.app.smartwell.view.WellOperationActivity import com.casic.app.smartwell.vm.OrderViewModel import com.casic.app.smartwell.vm.WellViewModel +import com.casic.app.smartwell.widgets.MapWellPopup +import com.casic.app.smartwell.widgets.cluster.ClusterItem +import com.casic.app.smartwell.widgets.cluster.ClusterOnClickListener +import com.casic.app.smartwell.widgets.cluster.ClusterOverlay +import com.casic.app.smartwell.widgets.cluster.RegionItem 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.convertDrawable +import com.pengxh.kt.lite.extensions.dp2px import com.pengxh.kt.lite.extensions.navigatePageTo import com.pengxh.kt.lite.extensions.show import com.pengxh.kt.lite.utils.LoadingDialogHub @@ -43,35 +49,23 @@ /** * 地图点位带聚合效果 * */ -class HomePageHaveClusterFragment : KotlinBaseFragment(), AMap.OnMapLoadedListener, - AMap.OnCameraChangeListener, AMap.OnMarkerClickListener, AMap.InfoWindowAdapter, - AMap.OnInfoWindowClickListener { +class HomePageHaveClusterFragment : KotlinBaseFragment(), + AMap.OnCameraChangeListener { private val kTag = "HaveClusterFragment" private val easyPopupWindow by lazy { EasyPopupWindow(requireContext()) } - private lateinit var wellViewModel: WellViewModel - private lateinit var orderViewModel: OrderViewModel - private lateinit var aMap: AMap - - /** - * 所有的marker - */ - private var allMarkerOptions: MutableList = ArrayList() - - /** - * 视野内的marker - */ - private var markerOptionsInView: MutableList = ArrayList() - - /** - * 自定义Marker弹出框 - * */ - private lateinit var v: View + private val regionRadius by lazy { LocaleConstant.RADIUS_SIZE.dp2px(requireContext()) } + private val infoPopup by lazy { MapWellPopup(requireContext()) } /** * 所有窨井列表信息集合 * */ - private var wellModels: MutableList = ArrayList() + private val wellModels = ArrayList() + private val backDrawables = HashMap() + private lateinit var wellViewModel: WellViewModel + private lateinit var orderViewModel: OrderViewModel + private lateinit var aMap: AMap + private var clusterOverlay: ClusterOverlay? = null override fun initViewBinding( inflater: LayoutInflater, @@ -106,6 +100,9 @@ } }) + //地图初始化 + initMap(savedInstanceState) + //初始化vm wellViewModel = ViewModelProvider(this)[WellViewModel::class.java] orderViewModel = ViewModelProvider(this)[OrderViewModel::class.java] @@ -120,25 +117,19 @@ val latitudeList: MutableList = ArrayList() val longitudeList: MutableList = ArrayList() it.data?.forEach { well -> - val lat = well.latGaode.toString() - val lng = well.lngGaode.toString() + val lat = well.latGaode + val lng = well.lngGaode if (lat.isNotBlank() && lng.isNotBlank()) { //返回true代表当前位置在大陆、港澳地区,反之不在 val latitude = lat.toDouble() val longitude = lng.toDouble() if (CoordinateConverter.isAMapDataAvailable(latitude, longitude)) { - //缓存所有设备详情,点击Marker时候需要 + //缓存所有井 wellModels.add(well) + //分别缓存经、纬度 latitudeList.add(latitude) longitudeList.add(longitude) - //将所有设备信息转化缓存为Marker点 - allMarkerOptions.add( - MarkerOptions() - .position(LatLng(latitude, longitude)) - .title(well.wellTypeName) - .snippet(well.wellName) - ) } } } @@ -160,12 +151,12 @@ val cameraPosition = CameraPosition(centerLatLng, 16f, 0f, 0f) val cameraUpdate = CameraUpdateFactory.newCameraPosition(cameraPosition) aMap.animateCamera(cameraUpdate, 1500, null) + + //显示点数据 + displayWellOnMap() } } - //地图初始化 - initMap(savedInstanceState) - //获取窨井监控数据 wellViewModel.countResultModel.observe(this) { binding.deployedWellView.text = it["bfWell"] @@ -220,17 +211,10 @@ uiSettings.isCompassEnabled = true uiSettings.zoomPosition = AMapOptions.ZOOM_POSITION_RIGHT_CENTER uiSettings.isTiltGesturesEnabled = false//不许地图随手势倾斜角度 + uiSettings.isRotateGesturesEnabled = false//不允许地图随手势改变方位 - // 地图加载成功监听 - aMap.addOnMapLoadedListener(this) // 地图缩放监听 aMap.addOnCameraChangeListener(this) - // marker 点击事件监听 - aMap.addOnMarkerClickListener(this) - // 点击marker弹出自定义popup - aMap.setInfoWindowAdapter(this) - //信息窗点击事件 - aMap.addOnInfoWindowClickListener(this) } override fun initEvent() { @@ -259,9 +243,111 @@ } - override fun onMapLoaded() { - //地图加载成功之后显示聚合点数据 - initClustersMarkers() + private fun displayWellOnMap() { + clusterOverlay?.onDestroy() + val clusterItems = ArrayList() + + wellModels.forEach { + val latitude = it.latGaode.toDouble() + val longitude = it.lngGaode.toDouble() + + val latLng = LatLng(latitude, longitude, false) + val regionItem = RegionItem(latLng, it) + clusterItems.add(regionItem) + } + + clusterOverlay = ClusterOverlay(requireContext(), aMap, clusterItems, regionRadius) + clusterOverlay?.setClusterRender { clusterNum -> + //聚合圆半径 + val radius = 100.dp2px(requireContext()) + if (clusterNum == 0) { + var bitmapDrawable = backDrawables[0] + if (bitmapDrawable == null) { + bitmapDrawable = BitmapDrawable( + null, radius.drawCircle(Color.argb(159, 100, 149, 237)) + ) + backDrawables[0] = bitmapDrawable + } + bitmapDrawable + } + if (clusterNum == 1) { + var bitmapDrawable = backDrawables[1] + if (bitmapDrawable == null) { + bitmapDrawable = R.mipmap.well_location.convertDrawable(requireContext())!! + backDrawables[1] = bitmapDrawable + } + bitmapDrawable + } else if (clusterNum < 5) { + var bitmapDrawable = backDrawables[2] + if (bitmapDrawable == null) { + bitmapDrawable = BitmapDrawable( + null, radius.drawCircle(Color.argb(159, 100, 149, 237)) + ) + backDrawables[2] = bitmapDrawable + } + bitmapDrawable + } else if (clusterNum < 10) { + var bitmapDrawable = backDrawables[3] + if (bitmapDrawable == null) { + bitmapDrawable = BitmapDrawable( + null, radius.drawCircle(Color.argb(199, 30, 144, 255)) + ) + backDrawables[3] = bitmapDrawable + } + bitmapDrawable + } else { + var bitmapDrawable = backDrawables[4] + if (bitmapDrawable == null) { + bitmapDrawable = BitmapDrawable( + null, radius.drawCircle(Color.argb(235, 65, 105, 225)) + ) + backDrawables[4] = bitmapDrawable + } + bitmapDrawable + } + } + + clusterOverlay?.setOnClusterClickListener(object : ClusterOnClickListener { + override fun onMarkerClicked(marker: Marker?, items: List) { + if (items.size > 1) { + "请缩放地图比例在查看数据".show(requireContext()) + return + } + + var item: RegionItem? = null + val builder = LatLngBounds.Builder() + for (clusterItem in items) { + builder.include(clusterItem.position) + item = clusterItem as RegionItem + } + + item?.apply { + showWellPopup(well) + } + } + }) + } + + private fun showWellPopup(well: MapWellListModel.DataModel) { + infoPopup.set(well, object : MapWellPopup.OnPopupWindowClickListener { + override fun onPopupClicked(lat: Double, lng: Double) { + AlertControlDialog.Builder().setContext(requireContext()).setTitle("操作提示") + .setMessage("确定要前往吗").setNegativeButton("取消").setPositiveButton("确定") + .setOnDialogButtonClickListener(object : + AlertControlDialog.OnDialogButtonClickListener { + override fun onConfirmClick() { + RouteOnMap.startNavigation( + requireContext(), "", LatLng(lat, lng) + ) + } + + override fun onCancelClick() { + + } + }).build().show() + } + }) + infoPopup.showAsDropDown(binding.rightOptionView) } override fun onCameraChange(p0: CameraPosition?) { @@ -282,103 +368,10 @@ } } - //获取视野内的marker 根据聚合算法合成自定义的marker 显示视野内的marker override fun onCameraChangeFinish(p0: CameraPosition?) { //地图缩放之后显示聚合点数据 LoadingDialogHub.dismiss() httpCountDownTimer.cancel() - initClustersMarkers() - } - - private fun initClustersMarkers() { - 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 { - v = LayoutInflater.from(requireContext()).inflate(R.layout.popup_map_info, null) - - //显示闸井信息 - marker?.showInfoWindow() - return true - } - - override fun getInfoWindow(marker: Marker?): View { - //反射得到popup里面的控件对象 - val wellNameView = v.findViewById(R.id.wellNameView) - val wellCodeView = v.findViewById(R.id.wellCodeView) - val wellTypeView = v.findViewById(R.id.wellTypeView) - val wellStateView = v.findViewById(R.id.wellStateView) - val deepView = v.findViewById(R.id.deepView) - val locationView = v.findViewById(R.id.locationView) - - //绑定数据 - val clickedLatLng = marker?.position!! - wellModels.forEach { well -> - if (clickedLatLng.latitude == well.latGaode!!.toDouble() - && clickedLatLng.longitude == well.lngGaode!!.toDouble() - ) { - wellNameView.text = String.format("点位名称: ${well.wellName}") - wellCodeView.text = String.format("点位编号: ${well.wellCode}") - wellTypeView.text = String.format("点位类型: ${well.wellType.valueToType()}") - val bfztName = if (well.bfzt == "1") { - "已布防" - } else { - "已撤防" - } - wellStateView.text = String.format("布/撤防状态: $bfztName") - deepView.text = String.format("点位深度: ${well.deep}m") - locationView.text = String.format("详细位置: ${well.position}") - } - } - return v - } - - /** - * 此方法不能修改整个 InfoWindow 的背景和边框,无论自定义的样式是什么样,SDK 都会在最外层添加一个默认的边框 - * */ - override fun getInfoContents(p0: Marker?): View? = null - - override fun onInfoWindowClick(p0: Marker?) { - p0?.apply { - AlertControlDialog.Builder() - .setContext(requireContext()) - .setTitle("操作提示") - .setMessage("确定要前往吗") - .setNegativeButton("取消") - .setPositiveButton("确定") - .setOnDialogButtonClickListener(object : - AlertControlDialog.OnDialogButtonClickListener { - override fun onConfirmClick() { - val lat = position.latitude.toString() - val lng = position.longitude.toString() - if (lat.isBlank() || lng.isBlank()) { - "点位经纬度异常,无法开启导航".show(requireContext()) - return - } - RouteOnMap.startNavigation( - requireContext(), snippet, LatLng(lat.toDouble(), lng.toDouble()) - ) - } - - override fun onCancelClick() { - - } - }).build().show() - } } /***以下是地图生命周期管理************************************************************************/ 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 a54d213..bfa7a57 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 @@ -44,8 +44,8 @@ * 地图点位不带聚合效果 * */ class HomePageNoClusterFragment : KotlinBaseFragment(), - AMap.OnMapLoadedListener, AMap.OnCameraChangeListener, AMap.OnMarkerClickListener, - AMap.InfoWindowAdapter, AMap.OnInfoWindowClickListener { + AMap.OnCameraChangeListener, AMap.OnMarkerClickListener, AMap.InfoWindowAdapter, + AMap.OnInfoWindowClickListener { private val kTag = "NoClusterFragment" private val easyPopupWindow by lazy { EasyPopupWindow(requireContext()) } @@ -109,6 +109,9 @@ wellViewModel = ViewModelProvider(this)[WellViewModel::class.java] orderViewModel = ViewModelProvider(this)[OrderViewModel::class.java] + //地图初始化 + initMap(savedInstanceState) + //获取所有窨井数据 httpCountDownTimer.start() LoadingDialogHub.show(requireActivity(), "数据加载中,请稍后...") @@ -157,12 +160,12 @@ val cameraPosition = CameraPosition(centerLatLng, 16f, 0f, 0f) val cameraUpdate = CameraUpdateFactory.newCameraPosition(cameraPosition) aMap.animateCamera(cameraUpdate, 1500, null) + + //显示点数据 + displayWellOnMap() } } - //地图初始化 - initMap(savedInstanceState) - //获取窨井监控数据 wellViewModel.countResultModel.observe(this) { binding.deployedWellView.text = it["bfWell"] @@ -214,9 +217,8 @@ uiSettings.isCompassEnabled = true uiSettings.zoomPosition = AMapOptions.ZOOM_POSITION_RIGHT_CENTER uiSettings.isTiltGesturesEnabled = false//不许地图随手势倾斜角度 + uiSettings.isRotateGesturesEnabled = false//不允许地图随手势改变方位 - // 地图加载成功监听 - aMap.addOnMapLoadedListener(this) // 地图缩放监听 aMap.addOnCameraChangeListener(this) // marker 点击事件监听 @@ -253,11 +255,6 @@ } - override fun onMapLoaded() { - //地图加载成功之后显示聚合点数据 - initClustersMarkers() - } - override fun onCameraChange(p0: CameraPosition?) { } @@ -281,10 +278,9 @@ //地图缩放之后显示聚合点数据 LoadingDialogHub.dismiss() httpCountDownTimer.cancel() - initClustersMarkers() } - private fun initClustersMarkers() { + private fun displayWellOnMap() { val proj = aMap.projection val dm = resources.displayMetrics var screenLocation: Point diff --git a/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.java b/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.java deleted file mode 100644 index d8b18ef..0000000 --- a/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.java +++ /dev/null @@ -1,50 +0,0 @@ -package com.casic.app.smartwell.model; - -public class ErrorMessageModel { - - private int code; - private String data; - private String exceptionClazz; - private String message; - private boolean success; - - public int getCode() { - return code; - } - - public void setCode(int code) { - this.code = code; - } - - public String getData() { - return data; - } - - public void setData(String data) { - this.data = data; - } - - public String getExceptionClazz() { - return exceptionClazz; - } - - public void setExceptionClazz(String exceptionClazz) { - this.exceptionClazz = exceptionClazz; - } - - public String getMessage() { - return message; - } - - public void setMessage(String message) { - this.message = message; - } - - public boolean isSuccess() { - return success; - } - - public void setSuccess(boolean success) { - this.success = success; - } -} \ No newline at end of file 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 new file mode 100644 index 0000000..215ac0c --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/PipelineModel.java @@ -0,0 +1,328 @@ +package com.casic.app.smartwell.model; + +import java.util.List; + +public class PipelineModel { + + private Integer code; + private DataModel data; + private String message; + private Boolean success; + + public Integer getCode() { + return code; + } + + public void setCode(Integer code) { + this.code = code; + } + + public DataModel getData() { + return data; + } + + public void setData(DataModel data) { + this.data = data; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + public Boolean getSuccess() { + return success; + } + + public void setSuccess(Boolean success) { + this.success = success; + } + + public static class DataModel { + private List rows; + private Integer total; + + public List getRows() { + return rows; + } + + public void setRows(List rows) { + this.rows = rows; + } + + public Integer getTotal() { + return total; + } + + public void setTotal(Integer total) { + this.total = total; + } + + 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 getBuryMode() { + return buryMode; + } + + public void setBuryMode(String buryMode) { + this.buryMode = buryMode; + } + + public String getConstructEra() { + return constructEra; + } + + public void setConstructEra(String constructEra) { + this.constructEra = constructEra; + } + + 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; + } + } + } +} 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 06d3d2b..4f38a2c 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 = 100 //相距多少米才聚合,单位:米 + const val RADIUS_SIZE = 80 //相距多少米才聚合,单位:米 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:11308" + // 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 0d5f3fa..991e1db 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 @@ -312,4 +312,14 @@ @Header("token") token: String, @Field("clientid") deviceCode: String ): String + + /** + * 管线位置数据 + */ + @GET("/pipeline/listPage") + suspend fun getPipeline( + @Header("token") token: String, + @Query("limit") limit: Int, + @Query("offset") offset: Int + ): String } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/extensions/Int.kt b/app/src/main/java/com/casic/app/smartwell/extensions/Int.kt index de0617b..a0a5e33 100644 --- a/app/src/main/java/com/casic/app/smartwell/extensions/Int.kt +++ b/app/src/main/java/com/casic/app/smartwell/extensions/Int.kt @@ -1,9 +1,24 @@ package com.casic.app.smartwell.extensions +import android.graphics.Bitmap +import android.graphics.Canvas +import android.graphics.Paint +import android.graphics.RectF + fun Int.toLevel(): String { return if (this == 0) { "" } else { this.toString() } +} + +fun Int.drawCircle(color: Int): Bitmap? { + val bitmap = Bitmap.createBitmap(this * 2, this * 2, Bitmap.Config.ARGB_8888) + val canvas = Canvas(bitmap) + val paint = Paint() + val rectF = RectF(0f, 0f, (this * 2).toFloat(), (this * 2).toFloat()) + paint.color = color + canvas.drawArc(rectF, 0f, 360f, true, paint) + return bitmap } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt index 6b6ca3e..5e45534 100644 --- a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt +++ b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt @@ -2,17 +2,13 @@ import android.content.Context import com.casic.app.smartwell.callback.OnImageCompressListener -import com.casic.app.smartwell.model.ErrorMessageModel import com.casic.app.smartwell.utils.LocaleConstant -import com.google.gson.Gson -import com.google.gson.reflect.TypeToken +import com.google.gson.JsonParser import com.pengxh.kt.lite.extensions.createCompressImageDir import com.pengxh.kt.lite.utils.SaveKeyValues -import org.json.JSONObject import top.zibin.luban.Luban import top.zibin.luban.OnCompressListener import java.io.File -import java.util.Locale /** * String扩展方法 @@ -74,18 +70,22 @@ } } -fun String.separateResponseCode(): Int { +fun String.getResponseCode(): Int { if (this.isBlank()) { return 404 } - return JSONObject(this).getInt("code") + val element = JsonParser.parseString(this) + val jsonObject = element.asJsonObject + return jsonObject.get("code").asInt } -fun String.toErrorMessage(): String { - val errorModel = Gson().fromJson( - this, object : TypeToken() {}.type - ) - return errorModel.message.toString() +fun String.getResponseMessage(): String { + if (this.isBlank()) { + return "" + } + val element = JsonParser.parseString(this) + val jsonObject = element.asJsonObject + return jsonObject.get("message").asString } fun String.compressImage(context: Context, listener: OnImageCompressListener) { @@ -93,9 +93,6 @@ .load(this) .ignoreBy(100) .setTargetDir(context.createCompressImageDir().toString()) - .filter { - !(it.isBlank() || it.lowercase(Locale.getDefault()).endsWith(".gif")) - } .setCompressListener(object : OnCompressListener { override fun onStart() { 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 96df110..cd25fca 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 @@ -1,26 +1,25 @@ package com.casic.app.smartwell.fragment -import android.graphics.Point +import android.graphics.Color +import android.graphics.drawable.BitmapDrawable +import android.graphics.drawable.Drawable 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 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.LatLngBounds import com.amap.api.maps.model.Marker -import com.amap.api.maps.model.MarkerOptions import com.casic.app.smartwell.R import com.casic.app.smartwell.databinding.FragmentHomeBinding +import com.casic.app.smartwell.extensions.drawCircle import com.casic.app.smartwell.extensions.initImmersionBar -import com.casic.app.smartwell.extensions.valueToType import com.casic.app.smartwell.model.MapWellListModel import com.casic.app.smartwell.utils.LocaleConstant import com.casic.app.smartwell.utils.RouteOnMap @@ -31,9 +30,16 @@ import com.casic.app.smartwell.view.WellOperationActivity import com.casic.app.smartwell.vm.OrderViewModel import com.casic.app.smartwell.vm.WellViewModel +import com.casic.app.smartwell.widgets.MapWellPopup +import com.casic.app.smartwell.widgets.cluster.ClusterItem +import com.casic.app.smartwell.widgets.cluster.ClusterOnClickListener +import com.casic.app.smartwell.widgets.cluster.ClusterOverlay +import com.casic.app.smartwell.widgets.cluster.RegionItem 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.convertDrawable +import com.pengxh.kt.lite.extensions.dp2px import com.pengxh.kt.lite.extensions.navigatePageTo import com.pengxh.kt.lite.extensions.show import com.pengxh.kt.lite.utils.LoadingDialogHub @@ -43,35 +49,23 @@ /** * 地图点位带聚合效果 * */ -class HomePageHaveClusterFragment : KotlinBaseFragment(), AMap.OnMapLoadedListener, - AMap.OnCameraChangeListener, AMap.OnMarkerClickListener, AMap.InfoWindowAdapter, - AMap.OnInfoWindowClickListener { +class HomePageHaveClusterFragment : KotlinBaseFragment(), + AMap.OnCameraChangeListener { private val kTag = "HaveClusterFragment" private val easyPopupWindow by lazy { EasyPopupWindow(requireContext()) } - private lateinit var wellViewModel: WellViewModel - private lateinit var orderViewModel: OrderViewModel - private lateinit var aMap: AMap - - /** - * 所有的marker - */ - private var allMarkerOptions: MutableList = ArrayList() - - /** - * 视野内的marker - */ - private var markerOptionsInView: MutableList = ArrayList() - - /** - * 自定义Marker弹出框 - * */ - private lateinit var v: View + private val regionRadius by lazy { LocaleConstant.RADIUS_SIZE.dp2px(requireContext()) } + private val infoPopup by lazy { MapWellPopup(requireContext()) } /** * 所有窨井列表信息集合 * */ - private var wellModels: MutableList = ArrayList() + private val wellModels = ArrayList() + private val backDrawables = HashMap() + private lateinit var wellViewModel: WellViewModel + private lateinit var orderViewModel: OrderViewModel + private lateinit var aMap: AMap + private var clusterOverlay: ClusterOverlay? = null override fun initViewBinding( inflater: LayoutInflater, @@ -106,6 +100,9 @@ } }) + //地图初始化 + initMap(savedInstanceState) + //初始化vm wellViewModel = ViewModelProvider(this)[WellViewModel::class.java] orderViewModel = ViewModelProvider(this)[OrderViewModel::class.java] @@ -120,25 +117,19 @@ val latitudeList: MutableList = ArrayList() val longitudeList: MutableList = ArrayList() it.data?.forEach { well -> - val lat = well.latGaode.toString() - val lng = well.lngGaode.toString() + val lat = well.latGaode + val lng = well.lngGaode if (lat.isNotBlank() && lng.isNotBlank()) { //返回true代表当前位置在大陆、港澳地区,反之不在 val latitude = lat.toDouble() val longitude = lng.toDouble() if (CoordinateConverter.isAMapDataAvailable(latitude, longitude)) { - //缓存所有设备详情,点击Marker时候需要 + //缓存所有井 wellModels.add(well) + //分别缓存经、纬度 latitudeList.add(latitude) longitudeList.add(longitude) - //将所有设备信息转化缓存为Marker点 - allMarkerOptions.add( - MarkerOptions() - .position(LatLng(latitude, longitude)) - .title(well.wellTypeName) - .snippet(well.wellName) - ) } } } @@ -160,12 +151,12 @@ val cameraPosition = CameraPosition(centerLatLng, 16f, 0f, 0f) val cameraUpdate = CameraUpdateFactory.newCameraPosition(cameraPosition) aMap.animateCamera(cameraUpdate, 1500, null) + + //显示点数据 + displayWellOnMap() } } - //地图初始化 - initMap(savedInstanceState) - //获取窨井监控数据 wellViewModel.countResultModel.observe(this) { binding.deployedWellView.text = it["bfWell"] @@ -220,17 +211,10 @@ uiSettings.isCompassEnabled = true uiSettings.zoomPosition = AMapOptions.ZOOM_POSITION_RIGHT_CENTER uiSettings.isTiltGesturesEnabled = false//不许地图随手势倾斜角度 + uiSettings.isRotateGesturesEnabled = false//不允许地图随手势改变方位 - // 地图加载成功监听 - aMap.addOnMapLoadedListener(this) // 地图缩放监听 aMap.addOnCameraChangeListener(this) - // marker 点击事件监听 - aMap.addOnMarkerClickListener(this) - // 点击marker弹出自定义popup - aMap.setInfoWindowAdapter(this) - //信息窗点击事件 - aMap.addOnInfoWindowClickListener(this) } override fun initEvent() { @@ -259,9 +243,111 @@ } - override fun onMapLoaded() { - //地图加载成功之后显示聚合点数据 - initClustersMarkers() + private fun displayWellOnMap() { + clusterOverlay?.onDestroy() + val clusterItems = ArrayList() + + wellModels.forEach { + val latitude = it.latGaode.toDouble() + val longitude = it.lngGaode.toDouble() + + val latLng = LatLng(latitude, longitude, false) + val regionItem = RegionItem(latLng, it) + clusterItems.add(regionItem) + } + + clusterOverlay = ClusterOverlay(requireContext(), aMap, clusterItems, regionRadius) + clusterOverlay?.setClusterRender { clusterNum -> + //聚合圆半径 + val radius = 100.dp2px(requireContext()) + if (clusterNum == 0) { + var bitmapDrawable = backDrawables[0] + if (bitmapDrawable == null) { + bitmapDrawable = BitmapDrawable( + null, radius.drawCircle(Color.argb(159, 100, 149, 237)) + ) + backDrawables[0] = bitmapDrawable + } + bitmapDrawable + } + if (clusterNum == 1) { + var bitmapDrawable = backDrawables[1] + if (bitmapDrawable == null) { + bitmapDrawable = R.mipmap.well_location.convertDrawable(requireContext())!! + backDrawables[1] = bitmapDrawable + } + bitmapDrawable + } else if (clusterNum < 5) { + var bitmapDrawable = backDrawables[2] + if (bitmapDrawable == null) { + bitmapDrawable = BitmapDrawable( + null, radius.drawCircle(Color.argb(159, 100, 149, 237)) + ) + backDrawables[2] = bitmapDrawable + } + bitmapDrawable + } else if (clusterNum < 10) { + var bitmapDrawable = backDrawables[3] + if (bitmapDrawable == null) { + bitmapDrawable = BitmapDrawable( + null, radius.drawCircle(Color.argb(199, 30, 144, 255)) + ) + backDrawables[3] = bitmapDrawable + } + bitmapDrawable + } else { + var bitmapDrawable = backDrawables[4] + if (bitmapDrawable == null) { + bitmapDrawable = BitmapDrawable( + null, radius.drawCircle(Color.argb(235, 65, 105, 225)) + ) + backDrawables[4] = bitmapDrawable + } + bitmapDrawable + } + } + + clusterOverlay?.setOnClusterClickListener(object : ClusterOnClickListener { + override fun onMarkerClicked(marker: Marker?, items: List) { + if (items.size > 1) { + "请缩放地图比例在查看数据".show(requireContext()) + return + } + + var item: RegionItem? = null + val builder = LatLngBounds.Builder() + for (clusterItem in items) { + builder.include(clusterItem.position) + item = clusterItem as RegionItem + } + + item?.apply { + showWellPopup(well) + } + } + }) + } + + private fun showWellPopup(well: MapWellListModel.DataModel) { + infoPopup.set(well, object : MapWellPopup.OnPopupWindowClickListener { + override fun onPopupClicked(lat: Double, lng: Double) { + AlertControlDialog.Builder().setContext(requireContext()).setTitle("操作提示") + .setMessage("确定要前往吗").setNegativeButton("取消").setPositiveButton("确定") + .setOnDialogButtonClickListener(object : + AlertControlDialog.OnDialogButtonClickListener { + override fun onConfirmClick() { + RouteOnMap.startNavigation( + requireContext(), "", LatLng(lat, lng) + ) + } + + override fun onCancelClick() { + + } + }).build().show() + } + }) + infoPopup.showAsDropDown(binding.rightOptionView) } override fun onCameraChange(p0: CameraPosition?) { @@ -282,103 +368,10 @@ } } - //获取视野内的marker 根据聚合算法合成自定义的marker 显示视野内的marker override fun onCameraChangeFinish(p0: CameraPosition?) { //地图缩放之后显示聚合点数据 LoadingDialogHub.dismiss() httpCountDownTimer.cancel() - initClustersMarkers() - } - - private fun initClustersMarkers() { - 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 { - v = LayoutInflater.from(requireContext()).inflate(R.layout.popup_map_info, null) - - //显示闸井信息 - marker?.showInfoWindow() - return true - } - - override fun getInfoWindow(marker: Marker?): View { - //反射得到popup里面的控件对象 - val wellNameView = v.findViewById(R.id.wellNameView) - val wellCodeView = v.findViewById(R.id.wellCodeView) - val wellTypeView = v.findViewById(R.id.wellTypeView) - val wellStateView = v.findViewById(R.id.wellStateView) - val deepView = v.findViewById(R.id.deepView) - val locationView = v.findViewById(R.id.locationView) - - //绑定数据 - val clickedLatLng = marker?.position!! - wellModels.forEach { well -> - if (clickedLatLng.latitude == well.latGaode!!.toDouble() - && clickedLatLng.longitude == well.lngGaode!!.toDouble() - ) { - wellNameView.text = String.format("点位名称: ${well.wellName}") - wellCodeView.text = String.format("点位编号: ${well.wellCode}") - wellTypeView.text = String.format("点位类型: ${well.wellType.valueToType()}") - val bfztName = if (well.bfzt == "1") { - "已布防" - } else { - "已撤防" - } - wellStateView.text = String.format("布/撤防状态: $bfztName") - deepView.text = String.format("点位深度: ${well.deep}m") - locationView.text = String.format("详细位置: ${well.position}") - } - } - return v - } - - /** - * 此方法不能修改整个 InfoWindow 的背景和边框,无论自定义的样式是什么样,SDK 都会在最外层添加一个默认的边框 - * */ - override fun getInfoContents(p0: Marker?): View? = null - - override fun onInfoWindowClick(p0: Marker?) { - p0?.apply { - AlertControlDialog.Builder() - .setContext(requireContext()) - .setTitle("操作提示") - .setMessage("确定要前往吗") - .setNegativeButton("取消") - .setPositiveButton("确定") - .setOnDialogButtonClickListener(object : - AlertControlDialog.OnDialogButtonClickListener { - override fun onConfirmClick() { - val lat = position.latitude.toString() - val lng = position.longitude.toString() - if (lat.isBlank() || lng.isBlank()) { - "点位经纬度异常,无法开启导航".show(requireContext()) - return - } - RouteOnMap.startNavigation( - requireContext(), snippet, LatLng(lat.toDouble(), lng.toDouble()) - ) - } - - override fun onCancelClick() { - - } - }).build().show() - } } /***以下是地图生命周期管理************************************************************************/ 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 a54d213..bfa7a57 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 @@ -44,8 +44,8 @@ * 地图点位不带聚合效果 * */ class HomePageNoClusterFragment : KotlinBaseFragment(), - AMap.OnMapLoadedListener, AMap.OnCameraChangeListener, AMap.OnMarkerClickListener, - AMap.InfoWindowAdapter, AMap.OnInfoWindowClickListener { + AMap.OnCameraChangeListener, AMap.OnMarkerClickListener, AMap.InfoWindowAdapter, + AMap.OnInfoWindowClickListener { private val kTag = "NoClusterFragment" private val easyPopupWindow by lazy { EasyPopupWindow(requireContext()) } @@ -109,6 +109,9 @@ wellViewModel = ViewModelProvider(this)[WellViewModel::class.java] orderViewModel = ViewModelProvider(this)[OrderViewModel::class.java] + //地图初始化 + initMap(savedInstanceState) + //获取所有窨井数据 httpCountDownTimer.start() LoadingDialogHub.show(requireActivity(), "数据加载中,请稍后...") @@ -157,12 +160,12 @@ val cameraPosition = CameraPosition(centerLatLng, 16f, 0f, 0f) val cameraUpdate = CameraUpdateFactory.newCameraPosition(cameraPosition) aMap.animateCamera(cameraUpdate, 1500, null) + + //显示点数据 + displayWellOnMap() } } - //地图初始化 - initMap(savedInstanceState) - //获取窨井监控数据 wellViewModel.countResultModel.observe(this) { binding.deployedWellView.text = it["bfWell"] @@ -214,9 +217,8 @@ uiSettings.isCompassEnabled = true uiSettings.zoomPosition = AMapOptions.ZOOM_POSITION_RIGHT_CENTER uiSettings.isTiltGesturesEnabled = false//不许地图随手势倾斜角度 + uiSettings.isRotateGesturesEnabled = false//不允许地图随手势改变方位 - // 地图加载成功监听 - aMap.addOnMapLoadedListener(this) // 地图缩放监听 aMap.addOnCameraChangeListener(this) // marker 点击事件监听 @@ -253,11 +255,6 @@ } - override fun onMapLoaded() { - //地图加载成功之后显示聚合点数据 - initClustersMarkers() - } - override fun onCameraChange(p0: CameraPosition?) { } @@ -281,10 +278,9 @@ //地图缩放之后显示聚合点数据 LoadingDialogHub.dismiss() httpCountDownTimer.cancel() - initClustersMarkers() } - private fun initClustersMarkers() { + private fun displayWellOnMap() { val proj = aMap.projection val dm = resources.displayMetrics var screenLocation: Point diff --git a/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.java b/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.java deleted file mode 100644 index d8b18ef..0000000 --- a/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.java +++ /dev/null @@ -1,50 +0,0 @@ -package com.casic.app.smartwell.model; - -public class ErrorMessageModel { - - private int code; - private String data; - private String exceptionClazz; - private String message; - private boolean success; - - public int getCode() { - return code; - } - - public void setCode(int code) { - this.code = code; - } - - public String getData() { - return data; - } - - public void setData(String data) { - this.data = data; - } - - public String getExceptionClazz() { - return exceptionClazz; - } - - public void setExceptionClazz(String exceptionClazz) { - this.exceptionClazz = exceptionClazz; - } - - public String getMessage() { - return message; - } - - public void setMessage(String message) { - this.message = message; - } - - public boolean isSuccess() { - return success; - } - - public void setSuccess(boolean success) { - this.success = success; - } -} \ No newline at end of file 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 new file mode 100644 index 0000000..215ac0c --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/PipelineModel.java @@ -0,0 +1,328 @@ +package com.casic.app.smartwell.model; + +import java.util.List; + +public class PipelineModel { + + private Integer code; + private DataModel data; + private String message; + private Boolean success; + + public Integer getCode() { + return code; + } + + public void setCode(Integer code) { + this.code = code; + } + + public DataModel getData() { + return data; + } + + public void setData(DataModel data) { + this.data = data; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + public Boolean getSuccess() { + return success; + } + + public void setSuccess(Boolean success) { + this.success = success; + } + + public static class DataModel { + private List rows; + private Integer total; + + public List getRows() { + return rows; + } + + public void setRows(List rows) { + this.rows = rows; + } + + public Integer getTotal() { + return total; + } + + public void setTotal(Integer total) { + this.total = total; + } + + 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 getBuryMode() { + return buryMode; + } + + public void setBuryMode(String buryMode) { + this.buryMode = buryMode; + } + + public String getConstructEra() { + return constructEra; + } + + public void setConstructEra(String constructEra) { + this.constructEra = constructEra; + } + + 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; + } + } + } +} 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 06d3d2b..4f38a2c 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 = 100 //相距多少米才聚合,单位:米 + const val RADIUS_SIZE = 80 //相距多少米才聚合,单位:米 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:11308" + // 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 0d5f3fa..991e1db 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 @@ -312,4 +312,14 @@ @Header("token") token: String, @Field("clientid") deviceCode: String ): String + + /** + * 管线位置数据 + */ + @GET("/pipeline/listPage") + suspend fun getPipeline( + @Header("token") token: String, + @Query("limit") limit: Int, + @Query("offset") offset: Int + ): String } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt index 1a0ce22..4050067 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt @@ -294,4 +294,11 @@ suspend fun registerPush(clientId: String): String { return api.registerPush(AuthenticationHelper.token!!, clientId) } + + /** + * 管线位置数据 + */ + suspend fun getPipeline(): String { + return api.getPipeline(AuthenticationHelper.token!!, 2000, 1) + } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/extensions/Int.kt b/app/src/main/java/com/casic/app/smartwell/extensions/Int.kt index de0617b..a0a5e33 100644 --- a/app/src/main/java/com/casic/app/smartwell/extensions/Int.kt +++ b/app/src/main/java/com/casic/app/smartwell/extensions/Int.kt @@ -1,9 +1,24 @@ package com.casic.app.smartwell.extensions +import android.graphics.Bitmap +import android.graphics.Canvas +import android.graphics.Paint +import android.graphics.RectF + fun Int.toLevel(): String { return if (this == 0) { "" } else { this.toString() } +} + +fun Int.drawCircle(color: Int): Bitmap? { + val bitmap = Bitmap.createBitmap(this * 2, this * 2, Bitmap.Config.ARGB_8888) + val canvas = Canvas(bitmap) + val paint = Paint() + val rectF = RectF(0f, 0f, (this * 2).toFloat(), (this * 2).toFloat()) + paint.color = color + canvas.drawArc(rectF, 0f, 360f, true, paint) + return bitmap } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt index 6b6ca3e..5e45534 100644 --- a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt +++ b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt @@ -2,17 +2,13 @@ import android.content.Context import com.casic.app.smartwell.callback.OnImageCompressListener -import com.casic.app.smartwell.model.ErrorMessageModel import com.casic.app.smartwell.utils.LocaleConstant -import com.google.gson.Gson -import com.google.gson.reflect.TypeToken +import com.google.gson.JsonParser import com.pengxh.kt.lite.extensions.createCompressImageDir import com.pengxh.kt.lite.utils.SaveKeyValues -import org.json.JSONObject import top.zibin.luban.Luban import top.zibin.luban.OnCompressListener import java.io.File -import java.util.Locale /** * String扩展方法 @@ -74,18 +70,22 @@ } } -fun String.separateResponseCode(): Int { +fun String.getResponseCode(): Int { if (this.isBlank()) { return 404 } - return JSONObject(this).getInt("code") + val element = JsonParser.parseString(this) + val jsonObject = element.asJsonObject + return jsonObject.get("code").asInt } -fun String.toErrorMessage(): String { - val errorModel = Gson().fromJson( - this, object : TypeToken() {}.type - ) - return errorModel.message.toString() +fun String.getResponseMessage(): String { + if (this.isBlank()) { + return "" + } + val element = JsonParser.parseString(this) + val jsonObject = element.asJsonObject + return jsonObject.get("message").asString } fun String.compressImage(context: Context, listener: OnImageCompressListener) { @@ -93,9 +93,6 @@ .load(this) .ignoreBy(100) .setTargetDir(context.createCompressImageDir().toString()) - .filter { - !(it.isBlank() || it.lowercase(Locale.getDefault()).endsWith(".gif")) - } .setCompressListener(object : OnCompressListener { override fun onStart() { 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 96df110..cd25fca 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 @@ -1,26 +1,25 @@ package com.casic.app.smartwell.fragment -import android.graphics.Point +import android.graphics.Color +import android.graphics.drawable.BitmapDrawable +import android.graphics.drawable.Drawable 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 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.LatLngBounds import com.amap.api.maps.model.Marker -import com.amap.api.maps.model.MarkerOptions import com.casic.app.smartwell.R import com.casic.app.smartwell.databinding.FragmentHomeBinding +import com.casic.app.smartwell.extensions.drawCircle import com.casic.app.smartwell.extensions.initImmersionBar -import com.casic.app.smartwell.extensions.valueToType import com.casic.app.smartwell.model.MapWellListModel import com.casic.app.smartwell.utils.LocaleConstant import com.casic.app.smartwell.utils.RouteOnMap @@ -31,9 +30,16 @@ import com.casic.app.smartwell.view.WellOperationActivity import com.casic.app.smartwell.vm.OrderViewModel import com.casic.app.smartwell.vm.WellViewModel +import com.casic.app.smartwell.widgets.MapWellPopup +import com.casic.app.smartwell.widgets.cluster.ClusterItem +import com.casic.app.smartwell.widgets.cluster.ClusterOnClickListener +import com.casic.app.smartwell.widgets.cluster.ClusterOverlay +import com.casic.app.smartwell.widgets.cluster.RegionItem 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.convertDrawable +import com.pengxh.kt.lite.extensions.dp2px import com.pengxh.kt.lite.extensions.navigatePageTo import com.pengxh.kt.lite.extensions.show import com.pengxh.kt.lite.utils.LoadingDialogHub @@ -43,35 +49,23 @@ /** * 地图点位带聚合效果 * */ -class HomePageHaveClusterFragment : KotlinBaseFragment(), AMap.OnMapLoadedListener, - AMap.OnCameraChangeListener, AMap.OnMarkerClickListener, AMap.InfoWindowAdapter, - AMap.OnInfoWindowClickListener { +class HomePageHaveClusterFragment : KotlinBaseFragment(), + AMap.OnCameraChangeListener { private val kTag = "HaveClusterFragment" private val easyPopupWindow by lazy { EasyPopupWindow(requireContext()) } - private lateinit var wellViewModel: WellViewModel - private lateinit var orderViewModel: OrderViewModel - private lateinit var aMap: AMap - - /** - * 所有的marker - */ - private var allMarkerOptions: MutableList = ArrayList() - - /** - * 视野内的marker - */ - private var markerOptionsInView: MutableList = ArrayList() - - /** - * 自定义Marker弹出框 - * */ - private lateinit var v: View + private val regionRadius by lazy { LocaleConstant.RADIUS_SIZE.dp2px(requireContext()) } + private val infoPopup by lazy { MapWellPopup(requireContext()) } /** * 所有窨井列表信息集合 * */ - private var wellModels: MutableList = ArrayList() + private val wellModels = ArrayList() + private val backDrawables = HashMap() + private lateinit var wellViewModel: WellViewModel + private lateinit var orderViewModel: OrderViewModel + private lateinit var aMap: AMap + private var clusterOverlay: ClusterOverlay? = null override fun initViewBinding( inflater: LayoutInflater, @@ -106,6 +100,9 @@ } }) + //地图初始化 + initMap(savedInstanceState) + //初始化vm wellViewModel = ViewModelProvider(this)[WellViewModel::class.java] orderViewModel = ViewModelProvider(this)[OrderViewModel::class.java] @@ -120,25 +117,19 @@ val latitudeList: MutableList = ArrayList() val longitudeList: MutableList = ArrayList() it.data?.forEach { well -> - val lat = well.latGaode.toString() - val lng = well.lngGaode.toString() + val lat = well.latGaode + val lng = well.lngGaode if (lat.isNotBlank() && lng.isNotBlank()) { //返回true代表当前位置在大陆、港澳地区,反之不在 val latitude = lat.toDouble() val longitude = lng.toDouble() if (CoordinateConverter.isAMapDataAvailable(latitude, longitude)) { - //缓存所有设备详情,点击Marker时候需要 + //缓存所有井 wellModels.add(well) + //分别缓存经、纬度 latitudeList.add(latitude) longitudeList.add(longitude) - //将所有设备信息转化缓存为Marker点 - allMarkerOptions.add( - MarkerOptions() - .position(LatLng(latitude, longitude)) - .title(well.wellTypeName) - .snippet(well.wellName) - ) } } } @@ -160,12 +151,12 @@ val cameraPosition = CameraPosition(centerLatLng, 16f, 0f, 0f) val cameraUpdate = CameraUpdateFactory.newCameraPosition(cameraPosition) aMap.animateCamera(cameraUpdate, 1500, null) + + //显示点数据 + displayWellOnMap() } } - //地图初始化 - initMap(savedInstanceState) - //获取窨井监控数据 wellViewModel.countResultModel.observe(this) { binding.deployedWellView.text = it["bfWell"] @@ -220,17 +211,10 @@ uiSettings.isCompassEnabled = true uiSettings.zoomPosition = AMapOptions.ZOOM_POSITION_RIGHT_CENTER uiSettings.isTiltGesturesEnabled = false//不许地图随手势倾斜角度 + uiSettings.isRotateGesturesEnabled = false//不允许地图随手势改变方位 - // 地图加载成功监听 - aMap.addOnMapLoadedListener(this) // 地图缩放监听 aMap.addOnCameraChangeListener(this) - // marker 点击事件监听 - aMap.addOnMarkerClickListener(this) - // 点击marker弹出自定义popup - aMap.setInfoWindowAdapter(this) - //信息窗点击事件 - aMap.addOnInfoWindowClickListener(this) } override fun initEvent() { @@ -259,9 +243,111 @@ } - override fun onMapLoaded() { - //地图加载成功之后显示聚合点数据 - initClustersMarkers() + private fun displayWellOnMap() { + clusterOverlay?.onDestroy() + val clusterItems = ArrayList() + + wellModels.forEach { + val latitude = it.latGaode.toDouble() + val longitude = it.lngGaode.toDouble() + + val latLng = LatLng(latitude, longitude, false) + val regionItem = RegionItem(latLng, it) + clusterItems.add(regionItem) + } + + clusterOverlay = ClusterOverlay(requireContext(), aMap, clusterItems, regionRadius) + clusterOverlay?.setClusterRender { clusterNum -> + //聚合圆半径 + val radius = 100.dp2px(requireContext()) + if (clusterNum == 0) { + var bitmapDrawable = backDrawables[0] + if (bitmapDrawable == null) { + bitmapDrawable = BitmapDrawable( + null, radius.drawCircle(Color.argb(159, 100, 149, 237)) + ) + backDrawables[0] = bitmapDrawable + } + bitmapDrawable + } + if (clusterNum == 1) { + var bitmapDrawable = backDrawables[1] + if (bitmapDrawable == null) { + bitmapDrawable = R.mipmap.well_location.convertDrawable(requireContext())!! + backDrawables[1] = bitmapDrawable + } + bitmapDrawable + } else if (clusterNum < 5) { + var bitmapDrawable = backDrawables[2] + if (bitmapDrawable == null) { + bitmapDrawable = BitmapDrawable( + null, radius.drawCircle(Color.argb(159, 100, 149, 237)) + ) + backDrawables[2] = bitmapDrawable + } + bitmapDrawable + } else if (clusterNum < 10) { + var bitmapDrawable = backDrawables[3] + if (bitmapDrawable == null) { + bitmapDrawable = BitmapDrawable( + null, radius.drawCircle(Color.argb(199, 30, 144, 255)) + ) + backDrawables[3] = bitmapDrawable + } + bitmapDrawable + } else { + var bitmapDrawable = backDrawables[4] + if (bitmapDrawable == null) { + bitmapDrawable = BitmapDrawable( + null, radius.drawCircle(Color.argb(235, 65, 105, 225)) + ) + backDrawables[4] = bitmapDrawable + } + bitmapDrawable + } + } + + clusterOverlay?.setOnClusterClickListener(object : ClusterOnClickListener { + override fun onMarkerClicked(marker: Marker?, items: List) { + if (items.size > 1) { + "请缩放地图比例在查看数据".show(requireContext()) + return + } + + var item: RegionItem? = null + val builder = LatLngBounds.Builder() + for (clusterItem in items) { + builder.include(clusterItem.position) + item = clusterItem as RegionItem + } + + item?.apply { + showWellPopup(well) + } + } + }) + } + + private fun showWellPopup(well: MapWellListModel.DataModel) { + infoPopup.set(well, object : MapWellPopup.OnPopupWindowClickListener { + override fun onPopupClicked(lat: Double, lng: Double) { + AlertControlDialog.Builder().setContext(requireContext()).setTitle("操作提示") + .setMessage("确定要前往吗").setNegativeButton("取消").setPositiveButton("确定") + .setOnDialogButtonClickListener(object : + AlertControlDialog.OnDialogButtonClickListener { + override fun onConfirmClick() { + RouteOnMap.startNavigation( + requireContext(), "", LatLng(lat, lng) + ) + } + + override fun onCancelClick() { + + } + }).build().show() + } + }) + infoPopup.showAsDropDown(binding.rightOptionView) } override fun onCameraChange(p0: CameraPosition?) { @@ -282,103 +368,10 @@ } } - //获取视野内的marker 根据聚合算法合成自定义的marker 显示视野内的marker override fun onCameraChangeFinish(p0: CameraPosition?) { //地图缩放之后显示聚合点数据 LoadingDialogHub.dismiss() httpCountDownTimer.cancel() - initClustersMarkers() - } - - private fun initClustersMarkers() { - 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 { - v = LayoutInflater.from(requireContext()).inflate(R.layout.popup_map_info, null) - - //显示闸井信息 - marker?.showInfoWindow() - return true - } - - override fun getInfoWindow(marker: Marker?): View { - //反射得到popup里面的控件对象 - val wellNameView = v.findViewById(R.id.wellNameView) - val wellCodeView = v.findViewById(R.id.wellCodeView) - val wellTypeView = v.findViewById(R.id.wellTypeView) - val wellStateView = v.findViewById(R.id.wellStateView) - val deepView = v.findViewById(R.id.deepView) - val locationView = v.findViewById(R.id.locationView) - - //绑定数据 - val clickedLatLng = marker?.position!! - wellModels.forEach { well -> - if (clickedLatLng.latitude == well.latGaode!!.toDouble() - && clickedLatLng.longitude == well.lngGaode!!.toDouble() - ) { - wellNameView.text = String.format("点位名称: ${well.wellName}") - wellCodeView.text = String.format("点位编号: ${well.wellCode}") - wellTypeView.text = String.format("点位类型: ${well.wellType.valueToType()}") - val bfztName = if (well.bfzt == "1") { - "已布防" - } else { - "已撤防" - } - wellStateView.text = String.format("布/撤防状态: $bfztName") - deepView.text = String.format("点位深度: ${well.deep}m") - locationView.text = String.format("详细位置: ${well.position}") - } - } - return v - } - - /** - * 此方法不能修改整个 InfoWindow 的背景和边框,无论自定义的样式是什么样,SDK 都会在最外层添加一个默认的边框 - * */ - override fun getInfoContents(p0: Marker?): View? = null - - override fun onInfoWindowClick(p0: Marker?) { - p0?.apply { - AlertControlDialog.Builder() - .setContext(requireContext()) - .setTitle("操作提示") - .setMessage("确定要前往吗") - .setNegativeButton("取消") - .setPositiveButton("确定") - .setOnDialogButtonClickListener(object : - AlertControlDialog.OnDialogButtonClickListener { - override fun onConfirmClick() { - val lat = position.latitude.toString() - val lng = position.longitude.toString() - if (lat.isBlank() || lng.isBlank()) { - "点位经纬度异常,无法开启导航".show(requireContext()) - return - } - RouteOnMap.startNavigation( - requireContext(), snippet, LatLng(lat.toDouble(), lng.toDouble()) - ) - } - - override fun onCancelClick() { - - } - }).build().show() - } } /***以下是地图生命周期管理************************************************************************/ 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 a54d213..bfa7a57 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 @@ -44,8 +44,8 @@ * 地图点位不带聚合效果 * */ class HomePageNoClusterFragment : KotlinBaseFragment(), - AMap.OnMapLoadedListener, AMap.OnCameraChangeListener, AMap.OnMarkerClickListener, - AMap.InfoWindowAdapter, AMap.OnInfoWindowClickListener { + AMap.OnCameraChangeListener, AMap.OnMarkerClickListener, AMap.InfoWindowAdapter, + AMap.OnInfoWindowClickListener { private val kTag = "NoClusterFragment" private val easyPopupWindow by lazy { EasyPopupWindow(requireContext()) } @@ -109,6 +109,9 @@ wellViewModel = ViewModelProvider(this)[WellViewModel::class.java] orderViewModel = ViewModelProvider(this)[OrderViewModel::class.java] + //地图初始化 + initMap(savedInstanceState) + //获取所有窨井数据 httpCountDownTimer.start() LoadingDialogHub.show(requireActivity(), "数据加载中,请稍后...") @@ -157,12 +160,12 @@ val cameraPosition = CameraPosition(centerLatLng, 16f, 0f, 0f) val cameraUpdate = CameraUpdateFactory.newCameraPosition(cameraPosition) aMap.animateCamera(cameraUpdate, 1500, null) + + //显示点数据 + displayWellOnMap() } } - //地图初始化 - initMap(savedInstanceState) - //获取窨井监控数据 wellViewModel.countResultModel.observe(this) { binding.deployedWellView.text = it["bfWell"] @@ -214,9 +217,8 @@ uiSettings.isCompassEnabled = true uiSettings.zoomPosition = AMapOptions.ZOOM_POSITION_RIGHT_CENTER uiSettings.isTiltGesturesEnabled = false//不许地图随手势倾斜角度 + uiSettings.isRotateGesturesEnabled = false//不允许地图随手势改变方位 - // 地图加载成功监听 - aMap.addOnMapLoadedListener(this) // 地图缩放监听 aMap.addOnCameraChangeListener(this) // marker 点击事件监听 @@ -253,11 +255,6 @@ } - override fun onMapLoaded() { - //地图加载成功之后显示聚合点数据 - initClustersMarkers() - } - override fun onCameraChange(p0: CameraPosition?) { } @@ -281,10 +278,9 @@ //地图缩放之后显示聚合点数据 LoadingDialogHub.dismiss() httpCountDownTimer.cancel() - initClustersMarkers() } - private fun initClustersMarkers() { + private fun displayWellOnMap() { val proj = aMap.projection val dm = resources.displayMetrics var screenLocation: Point diff --git a/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.java b/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.java deleted file mode 100644 index d8b18ef..0000000 --- a/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.java +++ /dev/null @@ -1,50 +0,0 @@ -package com.casic.app.smartwell.model; - -public class ErrorMessageModel { - - private int code; - private String data; - private String exceptionClazz; - private String message; - private boolean success; - - public int getCode() { - return code; - } - - public void setCode(int code) { - this.code = code; - } - - public String getData() { - return data; - } - - public void setData(String data) { - this.data = data; - } - - public String getExceptionClazz() { - return exceptionClazz; - } - - public void setExceptionClazz(String exceptionClazz) { - this.exceptionClazz = exceptionClazz; - } - - public String getMessage() { - return message; - } - - public void setMessage(String message) { - this.message = message; - } - - public boolean isSuccess() { - return success; - } - - public void setSuccess(boolean success) { - this.success = success; - } -} \ No newline at end of file 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 new file mode 100644 index 0000000..215ac0c --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/PipelineModel.java @@ -0,0 +1,328 @@ +package com.casic.app.smartwell.model; + +import java.util.List; + +public class PipelineModel { + + private Integer code; + private DataModel data; + private String message; + private Boolean success; + + public Integer getCode() { + return code; + } + + public void setCode(Integer code) { + this.code = code; + } + + public DataModel getData() { + return data; + } + + public void setData(DataModel data) { + this.data = data; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + public Boolean getSuccess() { + return success; + } + + public void setSuccess(Boolean success) { + this.success = success; + } + + public static class DataModel { + private List rows; + private Integer total; + + public List getRows() { + return rows; + } + + public void setRows(List rows) { + this.rows = rows; + } + + public Integer getTotal() { + return total; + } + + public void setTotal(Integer total) { + this.total = total; + } + + 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 getBuryMode() { + return buryMode; + } + + public void setBuryMode(String buryMode) { + this.buryMode = buryMode; + } + + public String getConstructEra() { + return constructEra; + } + + public void setConstructEra(String constructEra) { + this.constructEra = constructEra; + } + + 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; + } + } + } +} 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 06d3d2b..4f38a2c 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 = 100 //相距多少米才聚合,单位:米 + const val RADIUS_SIZE = 80 //相距多少米才聚合,单位:米 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:11308" + // 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 0d5f3fa..991e1db 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 @@ -312,4 +312,14 @@ @Header("token") token: String, @Field("clientid") deviceCode: String ): String + + /** + * 管线位置数据 + */ + @GET("/pipeline/listPage") + suspend fun getPipeline( + @Header("token") token: String, + @Query("limit") limit: Int, + @Query("offset") offset: Int + ): String } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt index 1a0ce22..4050067 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt @@ -294,4 +294,11 @@ suspend fun registerPush(clientId: String): String { return api.registerPush(AuthenticationHelper.token!!, clientId) } + + /** + * 管线位置数据 + */ + suspend fun getPipeline(): String { + return api.getPipeline(AuthenticationHelper.token!!, 2000, 1) + } } \ No newline at end of file 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 9270fa1..4ca5a5e 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.HomePageNoClusterFragment +import com.casic.app.smartwell.fragment.HomePageHaveClusterFragment 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/extensions/Int.kt b/app/src/main/java/com/casic/app/smartwell/extensions/Int.kt index de0617b..a0a5e33 100644 --- a/app/src/main/java/com/casic/app/smartwell/extensions/Int.kt +++ b/app/src/main/java/com/casic/app/smartwell/extensions/Int.kt @@ -1,9 +1,24 @@ package com.casic.app.smartwell.extensions +import android.graphics.Bitmap +import android.graphics.Canvas +import android.graphics.Paint +import android.graphics.RectF + fun Int.toLevel(): String { return if (this == 0) { "" } else { this.toString() } +} + +fun Int.drawCircle(color: Int): Bitmap? { + val bitmap = Bitmap.createBitmap(this * 2, this * 2, Bitmap.Config.ARGB_8888) + val canvas = Canvas(bitmap) + val paint = Paint() + val rectF = RectF(0f, 0f, (this * 2).toFloat(), (this * 2).toFloat()) + paint.color = color + canvas.drawArc(rectF, 0f, 360f, true, paint) + return bitmap } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt index 6b6ca3e..5e45534 100644 --- a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt +++ b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt @@ -2,17 +2,13 @@ import android.content.Context import com.casic.app.smartwell.callback.OnImageCompressListener -import com.casic.app.smartwell.model.ErrorMessageModel import com.casic.app.smartwell.utils.LocaleConstant -import com.google.gson.Gson -import com.google.gson.reflect.TypeToken +import com.google.gson.JsonParser import com.pengxh.kt.lite.extensions.createCompressImageDir import com.pengxh.kt.lite.utils.SaveKeyValues -import org.json.JSONObject import top.zibin.luban.Luban import top.zibin.luban.OnCompressListener import java.io.File -import java.util.Locale /** * String扩展方法 @@ -74,18 +70,22 @@ } } -fun String.separateResponseCode(): Int { +fun String.getResponseCode(): Int { if (this.isBlank()) { return 404 } - return JSONObject(this).getInt("code") + val element = JsonParser.parseString(this) + val jsonObject = element.asJsonObject + return jsonObject.get("code").asInt } -fun String.toErrorMessage(): String { - val errorModel = Gson().fromJson( - this, object : TypeToken() {}.type - ) - return errorModel.message.toString() +fun String.getResponseMessage(): String { + if (this.isBlank()) { + return "" + } + val element = JsonParser.parseString(this) + val jsonObject = element.asJsonObject + return jsonObject.get("message").asString } fun String.compressImage(context: Context, listener: OnImageCompressListener) { @@ -93,9 +93,6 @@ .load(this) .ignoreBy(100) .setTargetDir(context.createCompressImageDir().toString()) - .filter { - !(it.isBlank() || it.lowercase(Locale.getDefault()).endsWith(".gif")) - } .setCompressListener(object : OnCompressListener { override fun onStart() { 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 96df110..cd25fca 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 @@ -1,26 +1,25 @@ package com.casic.app.smartwell.fragment -import android.graphics.Point +import android.graphics.Color +import android.graphics.drawable.BitmapDrawable +import android.graphics.drawable.Drawable 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 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.LatLngBounds import com.amap.api.maps.model.Marker -import com.amap.api.maps.model.MarkerOptions import com.casic.app.smartwell.R import com.casic.app.smartwell.databinding.FragmentHomeBinding +import com.casic.app.smartwell.extensions.drawCircle import com.casic.app.smartwell.extensions.initImmersionBar -import com.casic.app.smartwell.extensions.valueToType import com.casic.app.smartwell.model.MapWellListModel import com.casic.app.smartwell.utils.LocaleConstant import com.casic.app.smartwell.utils.RouteOnMap @@ -31,9 +30,16 @@ import com.casic.app.smartwell.view.WellOperationActivity import com.casic.app.smartwell.vm.OrderViewModel import com.casic.app.smartwell.vm.WellViewModel +import com.casic.app.smartwell.widgets.MapWellPopup +import com.casic.app.smartwell.widgets.cluster.ClusterItem +import com.casic.app.smartwell.widgets.cluster.ClusterOnClickListener +import com.casic.app.smartwell.widgets.cluster.ClusterOverlay +import com.casic.app.smartwell.widgets.cluster.RegionItem 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.convertDrawable +import com.pengxh.kt.lite.extensions.dp2px import com.pengxh.kt.lite.extensions.navigatePageTo import com.pengxh.kt.lite.extensions.show import com.pengxh.kt.lite.utils.LoadingDialogHub @@ -43,35 +49,23 @@ /** * 地图点位带聚合效果 * */ -class HomePageHaveClusterFragment : KotlinBaseFragment(), AMap.OnMapLoadedListener, - AMap.OnCameraChangeListener, AMap.OnMarkerClickListener, AMap.InfoWindowAdapter, - AMap.OnInfoWindowClickListener { +class HomePageHaveClusterFragment : KotlinBaseFragment(), + AMap.OnCameraChangeListener { private val kTag = "HaveClusterFragment" private val easyPopupWindow by lazy { EasyPopupWindow(requireContext()) } - private lateinit var wellViewModel: WellViewModel - private lateinit var orderViewModel: OrderViewModel - private lateinit var aMap: AMap - - /** - * 所有的marker - */ - private var allMarkerOptions: MutableList = ArrayList() - - /** - * 视野内的marker - */ - private var markerOptionsInView: MutableList = ArrayList() - - /** - * 自定义Marker弹出框 - * */ - private lateinit var v: View + private val regionRadius by lazy { LocaleConstant.RADIUS_SIZE.dp2px(requireContext()) } + private val infoPopup by lazy { MapWellPopup(requireContext()) } /** * 所有窨井列表信息集合 * */ - private var wellModels: MutableList = ArrayList() + private val wellModels = ArrayList() + private val backDrawables = HashMap() + private lateinit var wellViewModel: WellViewModel + private lateinit var orderViewModel: OrderViewModel + private lateinit var aMap: AMap + private var clusterOverlay: ClusterOverlay? = null override fun initViewBinding( inflater: LayoutInflater, @@ -106,6 +100,9 @@ } }) + //地图初始化 + initMap(savedInstanceState) + //初始化vm wellViewModel = ViewModelProvider(this)[WellViewModel::class.java] orderViewModel = ViewModelProvider(this)[OrderViewModel::class.java] @@ -120,25 +117,19 @@ val latitudeList: MutableList = ArrayList() val longitudeList: MutableList = ArrayList() it.data?.forEach { well -> - val lat = well.latGaode.toString() - val lng = well.lngGaode.toString() + val lat = well.latGaode + val lng = well.lngGaode if (lat.isNotBlank() && lng.isNotBlank()) { //返回true代表当前位置在大陆、港澳地区,反之不在 val latitude = lat.toDouble() val longitude = lng.toDouble() if (CoordinateConverter.isAMapDataAvailable(latitude, longitude)) { - //缓存所有设备详情,点击Marker时候需要 + //缓存所有井 wellModels.add(well) + //分别缓存经、纬度 latitudeList.add(latitude) longitudeList.add(longitude) - //将所有设备信息转化缓存为Marker点 - allMarkerOptions.add( - MarkerOptions() - .position(LatLng(latitude, longitude)) - .title(well.wellTypeName) - .snippet(well.wellName) - ) } } } @@ -160,12 +151,12 @@ val cameraPosition = CameraPosition(centerLatLng, 16f, 0f, 0f) val cameraUpdate = CameraUpdateFactory.newCameraPosition(cameraPosition) aMap.animateCamera(cameraUpdate, 1500, null) + + //显示点数据 + displayWellOnMap() } } - //地图初始化 - initMap(savedInstanceState) - //获取窨井监控数据 wellViewModel.countResultModel.observe(this) { binding.deployedWellView.text = it["bfWell"] @@ -220,17 +211,10 @@ uiSettings.isCompassEnabled = true uiSettings.zoomPosition = AMapOptions.ZOOM_POSITION_RIGHT_CENTER uiSettings.isTiltGesturesEnabled = false//不许地图随手势倾斜角度 + uiSettings.isRotateGesturesEnabled = false//不允许地图随手势改变方位 - // 地图加载成功监听 - aMap.addOnMapLoadedListener(this) // 地图缩放监听 aMap.addOnCameraChangeListener(this) - // marker 点击事件监听 - aMap.addOnMarkerClickListener(this) - // 点击marker弹出自定义popup - aMap.setInfoWindowAdapter(this) - //信息窗点击事件 - aMap.addOnInfoWindowClickListener(this) } override fun initEvent() { @@ -259,9 +243,111 @@ } - override fun onMapLoaded() { - //地图加载成功之后显示聚合点数据 - initClustersMarkers() + private fun displayWellOnMap() { + clusterOverlay?.onDestroy() + val clusterItems = ArrayList() + + wellModels.forEach { + val latitude = it.latGaode.toDouble() + val longitude = it.lngGaode.toDouble() + + val latLng = LatLng(latitude, longitude, false) + val regionItem = RegionItem(latLng, it) + clusterItems.add(regionItem) + } + + clusterOverlay = ClusterOverlay(requireContext(), aMap, clusterItems, regionRadius) + clusterOverlay?.setClusterRender { clusterNum -> + //聚合圆半径 + val radius = 100.dp2px(requireContext()) + if (clusterNum == 0) { + var bitmapDrawable = backDrawables[0] + if (bitmapDrawable == null) { + bitmapDrawable = BitmapDrawable( + null, radius.drawCircle(Color.argb(159, 100, 149, 237)) + ) + backDrawables[0] = bitmapDrawable + } + bitmapDrawable + } + if (clusterNum == 1) { + var bitmapDrawable = backDrawables[1] + if (bitmapDrawable == null) { + bitmapDrawable = R.mipmap.well_location.convertDrawable(requireContext())!! + backDrawables[1] = bitmapDrawable + } + bitmapDrawable + } else if (clusterNum < 5) { + var bitmapDrawable = backDrawables[2] + if (bitmapDrawable == null) { + bitmapDrawable = BitmapDrawable( + null, radius.drawCircle(Color.argb(159, 100, 149, 237)) + ) + backDrawables[2] = bitmapDrawable + } + bitmapDrawable + } else if (clusterNum < 10) { + var bitmapDrawable = backDrawables[3] + if (bitmapDrawable == null) { + bitmapDrawable = BitmapDrawable( + null, radius.drawCircle(Color.argb(199, 30, 144, 255)) + ) + backDrawables[3] = bitmapDrawable + } + bitmapDrawable + } else { + var bitmapDrawable = backDrawables[4] + if (bitmapDrawable == null) { + bitmapDrawable = BitmapDrawable( + null, radius.drawCircle(Color.argb(235, 65, 105, 225)) + ) + backDrawables[4] = bitmapDrawable + } + bitmapDrawable + } + } + + clusterOverlay?.setOnClusterClickListener(object : ClusterOnClickListener { + override fun onMarkerClicked(marker: Marker?, items: List) { + if (items.size > 1) { + "请缩放地图比例在查看数据".show(requireContext()) + return + } + + var item: RegionItem? = null + val builder = LatLngBounds.Builder() + for (clusterItem in items) { + builder.include(clusterItem.position) + item = clusterItem as RegionItem + } + + item?.apply { + showWellPopup(well) + } + } + }) + } + + private fun showWellPopup(well: MapWellListModel.DataModel) { + infoPopup.set(well, object : MapWellPopup.OnPopupWindowClickListener { + override fun onPopupClicked(lat: Double, lng: Double) { + AlertControlDialog.Builder().setContext(requireContext()).setTitle("操作提示") + .setMessage("确定要前往吗").setNegativeButton("取消").setPositiveButton("确定") + .setOnDialogButtonClickListener(object : + AlertControlDialog.OnDialogButtonClickListener { + override fun onConfirmClick() { + RouteOnMap.startNavigation( + requireContext(), "", LatLng(lat, lng) + ) + } + + override fun onCancelClick() { + + } + }).build().show() + } + }) + infoPopup.showAsDropDown(binding.rightOptionView) } override fun onCameraChange(p0: CameraPosition?) { @@ -282,103 +368,10 @@ } } - //获取视野内的marker 根据聚合算法合成自定义的marker 显示视野内的marker override fun onCameraChangeFinish(p0: CameraPosition?) { //地图缩放之后显示聚合点数据 LoadingDialogHub.dismiss() httpCountDownTimer.cancel() - initClustersMarkers() - } - - private fun initClustersMarkers() { - 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 { - v = LayoutInflater.from(requireContext()).inflate(R.layout.popup_map_info, null) - - //显示闸井信息 - marker?.showInfoWindow() - return true - } - - override fun getInfoWindow(marker: Marker?): View { - //反射得到popup里面的控件对象 - val wellNameView = v.findViewById(R.id.wellNameView) - val wellCodeView = v.findViewById(R.id.wellCodeView) - val wellTypeView = v.findViewById(R.id.wellTypeView) - val wellStateView = v.findViewById(R.id.wellStateView) - val deepView = v.findViewById(R.id.deepView) - val locationView = v.findViewById(R.id.locationView) - - //绑定数据 - val clickedLatLng = marker?.position!! - wellModels.forEach { well -> - if (clickedLatLng.latitude == well.latGaode!!.toDouble() - && clickedLatLng.longitude == well.lngGaode!!.toDouble() - ) { - wellNameView.text = String.format("点位名称: ${well.wellName}") - wellCodeView.text = String.format("点位编号: ${well.wellCode}") - wellTypeView.text = String.format("点位类型: ${well.wellType.valueToType()}") - val bfztName = if (well.bfzt == "1") { - "已布防" - } else { - "已撤防" - } - wellStateView.text = String.format("布/撤防状态: $bfztName") - deepView.text = String.format("点位深度: ${well.deep}m") - locationView.text = String.format("详细位置: ${well.position}") - } - } - return v - } - - /** - * 此方法不能修改整个 InfoWindow 的背景和边框,无论自定义的样式是什么样,SDK 都会在最外层添加一个默认的边框 - * */ - override fun getInfoContents(p0: Marker?): View? = null - - override fun onInfoWindowClick(p0: Marker?) { - p0?.apply { - AlertControlDialog.Builder() - .setContext(requireContext()) - .setTitle("操作提示") - .setMessage("确定要前往吗") - .setNegativeButton("取消") - .setPositiveButton("确定") - .setOnDialogButtonClickListener(object : - AlertControlDialog.OnDialogButtonClickListener { - override fun onConfirmClick() { - val lat = position.latitude.toString() - val lng = position.longitude.toString() - if (lat.isBlank() || lng.isBlank()) { - "点位经纬度异常,无法开启导航".show(requireContext()) - return - } - RouteOnMap.startNavigation( - requireContext(), snippet, LatLng(lat.toDouble(), lng.toDouble()) - ) - } - - override fun onCancelClick() { - - } - }).build().show() - } } /***以下是地图生命周期管理************************************************************************/ 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 a54d213..bfa7a57 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 @@ -44,8 +44,8 @@ * 地图点位不带聚合效果 * */ class HomePageNoClusterFragment : KotlinBaseFragment(), - AMap.OnMapLoadedListener, AMap.OnCameraChangeListener, AMap.OnMarkerClickListener, - AMap.InfoWindowAdapter, AMap.OnInfoWindowClickListener { + AMap.OnCameraChangeListener, AMap.OnMarkerClickListener, AMap.InfoWindowAdapter, + AMap.OnInfoWindowClickListener { private val kTag = "NoClusterFragment" private val easyPopupWindow by lazy { EasyPopupWindow(requireContext()) } @@ -109,6 +109,9 @@ wellViewModel = ViewModelProvider(this)[WellViewModel::class.java] orderViewModel = ViewModelProvider(this)[OrderViewModel::class.java] + //地图初始化 + initMap(savedInstanceState) + //获取所有窨井数据 httpCountDownTimer.start() LoadingDialogHub.show(requireActivity(), "数据加载中,请稍后...") @@ -157,12 +160,12 @@ val cameraPosition = CameraPosition(centerLatLng, 16f, 0f, 0f) val cameraUpdate = CameraUpdateFactory.newCameraPosition(cameraPosition) aMap.animateCamera(cameraUpdate, 1500, null) + + //显示点数据 + displayWellOnMap() } } - //地图初始化 - initMap(savedInstanceState) - //获取窨井监控数据 wellViewModel.countResultModel.observe(this) { binding.deployedWellView.text = it["bfWell"] @@ -214,9 +217,8 @@ uiSettings.isCompassEnabled = true uiSettings.zoomPosition = AMapOptions.ZOOM_POSITION_RIGHT_CENTER uiSettings.isTiltGesturesEnabled = false//不许地图随手势倾斜角度 + uiSettings.isRotateGesturesEnabled = false//不允许地图随手势改变方位 - // 地图加载成功监听 - aMap.addOnMapLoadedListener(this) // 地图缩放监听 aMap.addOnCameraChangeListener(this) // marker 点击事件监听 @@ -253,11 +255,6 @@ } - override fun onMapLoaded() { - //地图加载成功之后显示聚合点数据 - initClustersMarkers() - } - override fun onCameraChange(p0: CameraPosition?) { } @@ -281,10 +278,9 @@ //地图缩放之后显示聚合点数据 LoadingDialogHub.dismiss() httpCountDownTimer.cancel() - initClustersMarkers() } - private fun initClustersMarkers() { + private fun displayWellOnMap() { val proj = aMap.projection val dm = resources.displayMetrics var screenLocation: Point diff --git a/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.java b/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.java deleted file mode 100644 index d8b18ef..0000000 --- a/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.java +++ /dev/null @@ -1,50 +0,0 @@ -package com.casic.app.smartwell.model; - -public class ErrorMessageModel { - - private int code; - private String data; - private String exceptionClazz; - private String message; - private boolean success; - - public int getCode() { - return code; - } - - public void setCode(int code) { - this.code = code; - } - - public String getData() { - return data; - } - - public void setData(String data) { - this.data = data; - } - - public String getExceptionClazz() { - return exceptionClazz; - } - - public void setExceptionClazz(String exceptionClazz) { - this.exceptionClazz = exceptionClazz; - } - - public String getMessage() { - return message; - } - - public void setMessage(String message) { - this.message = message; - } - - public boolean isSuccess() { - return success; - } - - public void setSuccess(boolean success) { - this.success = success; - } -} \ No newline at end of file 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 new file mode 100644 index 0000000..215ac0c --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/PipelineModel.java @@ -0,0 +1,328 @@ +package com.casic.app.smartwell.model; + +import java.util.List; + +public class PipelineModel { + + private Integer code; + private DataModel data; + private String message; + private Boolean success; + + public Integer getCode() { + return code; + } + + public void setCode(Integer code) { + this.code = code; + } + + public DataModel getData() { + return data; + } + + public void setData(DataModel data) { + this.data = data; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + public Boolean getSuccess() { + return success; + } + + public void setSuccess(Boolean success) { + this.success = success; + } + + public static class DataModel { + private List rows; + private Integer total; + + public List getRows() { + return rows; + } + + public void setRows(List rows) { + this.rows = rows; + } + + public Integer getTotal() { + return total; + } + + public void setTotal(Integer total) { + this.total = total; + } + + 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 getBuryMode() { + return buryMode; + } + + public void setBuryMode(String buryMode) { + this.buryMode = buryMode; + } + + public String getConstructEra() { + return constructEra; + } + + public void setConstructEra(String constructEra) { + this.constructEra = constructEra; + } + + 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; + } + } + } +} 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 06d3d2b..4f38a2c 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 = 100 //相距多少米才聚合,单位:米 + const val RADIUS_SIZE = 80 //相距多少米才聚合,单位:米 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:11308" + // 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 0d5f3fa..991e1db 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 @@ -312,4 +312,14 @@ @Header("token") token: String, @Field("clientid") deviceCode: String ): String + + /** + * 管线位置数据 + */ + @GET("/pipeline/listPage") + suspend fun getPipeline( + @Header("token") token: String, + @Query("limit") limit: Int, + @Query("offset") offset: Int + ): String } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt index 1a0ce22..4050067 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt @@ -294,4 +294,11 @@ suspend fun registerPush(clientId: String): String { return api.registerPush(AuthenticationHelper.token!!, clientId) } + + /** + * 管线位置数据 + */ + suspend fun getPipeline(): String { + return api.getPipeline(AuthenticationHelper.token!!, 2000, 1) + } } \ No newline at end of file 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 9270fa1..4ca5a5e 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.HomePageNoClusterFragment +import com.casic.app.smartwell.fragment.HomePageHaveClusterFragment 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/vm/AlarmViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/AlarmViewModel.kt index 9cff08c..e7acc17 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/AlarmViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/AlarmViewModel.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.AlarmContentModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager import com.google.gson.Gson @@ -16,7 +16,7 @@ fun getAlarmContentType(alarmType: String) = launch({ val response = RetrofitServiceManager.getAlarmContentType(alarmType) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { listModel.value = gson.fromJson( response, object : TypeToken() {}.type diff --git a/app/src/main/java/com/casic/app/smartwell/extensions/Int.kt b/app/src/main/java/com/casic/app/smartwell/extensions/Int.kt index de0617b..a0a5e33 100644 --- a/app/src/main/java/com/casic/app/smartwell/extensions/Int.kt +++ b/app/src/main/java/com/casic/app/smartwell/extensions/Int.kt @@ -1,9 +1,24 @@ package com.casic.app.smartwell.extensions +import android.graphics.Bitmap +import android.graphics.Canvas +import android.graphics.Paint +import android.graphics.RectF + fun Int.toLevel(): String { return if (this == 0) { "" } else { this.toString() } +} + +fun Int.drawCircle(color: Int): Bitmap? { + val bitmap = Bitmap.createBitmap(this * 2, this * 2, Bitmap.Config.ARGB_8888) + val canvas = Canvas(bitmap) + val paint = Paint() + val rectF = RectF(0f, 0f, (this * 2).toFloat(), (this * 2).toFloat()) + paint.color = color + canvas.drawArc(rectF, 0f, 360f, true, paint) + return bitmap } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt index 6b6ca3e..5e45534 100644 --- a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt +++ b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt @@ -2,17 +2,13 @@ import android.content.Context import com.casic.app.smartwell.callback.OnImageCompressListener -import com.casic.app.smartwell.model.ErrorMessageModel import com.casic.app.smartwell.utils.LocaleConstant -import com.google.gson.Gson -import com.google.gson.reflect.TypeToken +import com.google.gson.JsonParser import com.pengxh.kt.lite.extensions.createCompressImageDir import com.pengxh.kt.lite.utils.SaveKeyValues -import org.json.JSONObject import top.zibin.luban.Luban import top.zibin.luban.OnCompressListener import java.io.File -import java.util.Locale /** * String扩展方法 @@ -74,18 +70,22 @@ } } -fun String.separateResponseCode(): Int { +fun String.getResponseCode(): Int { if (this.isBlank()) { return 404 } - return JSONObject(this).getInt("code") + val element = JsonParser.parseString(this) + val jsonObject = element.asJsonObject + return jsonObject.get("code").asInt } -fun String.toErrorMessage(): String { - val errorModel = Gson().fromJson( - this, object : TypeToken() {}.type - ) - return errorModel.message.toString() +fun String.getResponseMessage(): String { + if (this.isBlank()) { + return "" + } + val element = JsonParser.parseString(this) + val jsonObject = element.asJsonObject + return jsonObject.get("message").asString } fun String.compressImage(context: Context, listener: OnImageCompressListener) { @@ -93,9 +93,6 @@ .load(this) .ignoreBy(100) .setTargetDir(context.createCompressImageDir().toString()) - .filter { - !(it.isBlank() || it.lowercase(Locale.getDefault()).endsWith(".gif")) - } .setCompressListener(object : OnCompressListener { override fun onStart() { 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 96df110..cd25fca 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 @@ -1,26 +1,25 @@ package com.casic.app.smartwell.fragment -import android.graphics.Point +import android.graphics.Color +import android.graphics.drawable.BitmapDrawable +import android.graphics.drawable.Drawable 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 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.LatLngBounds import com.amap.api.maps.model.Marker -import com.amap.api.maps.model.MarkerOptions import com.casic.app.smartwell.R import com.casic.app.smartwell.databinding.FragmentHomeBinding +import com.casic.app.smartwell.extensions.drawCircle import com.casic.app.smartwell.extensions.initImmersionBar -import com.casic.app.smartwell.extensions.valueToType import com.casic.app.smartwell.model.MapWellListModel import com.casic.app.smartwell.utils.LocaleConstant import com.casic.app.smartwell.utils.RouteOnMap @@ -31,9 +30,16 @@ import com.casic.app.smartwell.view.WellOperationActivity import com.casic.app.smartwell.vm.OrderViewModel import com.casic.app.smartwell.vm.WellViewModel +import com.casic.app.smartwell.widgets.MapWellPopup +import com.casic.app.smartwell.widgets.cluster.ClusterItem +import com.casic.app.smartwell.widgets.cluster.ClusterOnClickListener +import com.casic.app.smartwell.widgets.cluster.ClusterOverlay +import com.casic.app.smartwell.widgets.cluster.RegionItem 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.convertDrawable +import com.pengxh.kt.lite.extensions.dp2px import com.pengxh.kt.lite.extensions.navigatePageTo import com.pengxh.kt.lite.extensions.show import com.pengxh.kt.lite.utils.LoadingDialogHub @@ -43,35 +49,23 @@ /** * 地图点位带聚合效果 * */ -class HomePageHaveClusterFragment : KotlinBaseFragment(), AMap.OnMapLoadedListener, - AMap.OnCameraChangeListener, AMap.OnMarkerClickListener, AMap.InfoWindowAdapter, - AMap.OnInfoWindowClickListener { +class HomePageHaveClusterFragment : KotlinBaseFragment(), + AMap.OnCameraChangeListener { private val kTag = "HaveClusterFragment" private val easyPopupWindow by lazy { EasyPopupWindow(requireContext()) } - private lateinit var wellViewModel: WellViewModel - private lateinit var orderViewModel: OrderViewModel - private lateinit var aMap: AMap - - /** - * 所有的marker - */ - private var allMarkerOptions: MutableList = ArrayList() - - /** - * 视野内的marker - */ - private var markerOptionsInView: MutableList = ArrayList() - - /** - * 自定义Marker弹出框 - * */ - private lateinit var v: View + private val regionRadius by lazy { LocaleConstant.RADIUS_SIZE.dp2px(requireContext()) } + private val infoPopup by lazy { MapWellPopup(requireContext()) } /** * 所有窨井列表信息集合 * */ - private var wellModels: MutableList = ArrayList() + private val wellModels = ArrayList() + private val backDrawables = HashMap() + private lateinit var wellViewModel: WellViewModel + private lateinit var orderViewModel: OrderViewModel + private lateinit var aMap: AMap + private var clusterOverlay: ClusterOverlay? = null override fun initViewBinding( inflater: LayoutInflater, @@ -106,6 +100,9 @@ } }) + //地图初始化 + initMap(savedInstanceState) + //初始化vm wellViewModel = ViewModelProvider(this)[WellViewModel::class.java] orderViewModel = ViewModelProvider(this)[OrderViewModel::class.java] @@ -120,25 +117,19 @@ val latitudeList: MutableList = ArrayList() val longitudeList: MutableList = ArrayList() it.data?.forEach { well -> - val lat = well.latGaode.toString() - val lng = well.lngGaode.toString() + val lat = well.latGaode + val lng = well.lngGaode if (lat.isNotBlank() && lng.isNotBlank()) { //返回true代表当前位置在大陆、港澳地区,反之不在 val latitude = lat.toDouble() val longitude = lng.toDouble() if (CoordinateConverter.isAMapDataAvailable(latitude, longitude)) { - //缓存所有设备详情,点击Marker时候需要 + //缓存所有井 wellModels.add(well) + //分别缓存经、纬度 latitudeList.add(latitude) longitudeList.add(longitude) - //将所有设备信息转化缓存为Marker点 - allMarkerOptions.add( - MarkerOptions() - .position(LatLng(latitude, longitude)) - .title(well.wellTypeName) - .snippet(well.wellName) - ) } } } @@ -160,12 +151,12 @@ val cameraPosition = CameraPosition(centerLatLng, 16f, 0f, 0f) val cameraUpdate = CameraUpdateFactory.newCameraPosition(cameraPosition) aMap.animateCamera(cameraUpdate, 1500, null) + + //显示点数据 + displayWellOnMap() } } - //地图初始化 - initMap(savedInstanceState) - //获取窨井监控数据 wellViewModel.countResultModel.observe(this) { binding.deployedWellView.text = it["bfWell"] @@ -220,17 +211,10 @@ uiSettings.isCompassEnabled = true uiSettings.zoomPosition = AMapOptions.ZOOM_POSITION_RIGHT_CENTER uiSettings.isTiltGesturesEnabled = false//不许地图随手势倾斜角度 + uiSettings.isRotateGesturesEnabled = false//不允许地图随手势改变方位 - // 地图加载成功监听 - aMap.addOnMapLoadedListener(this) // 地图缩放监听 aMap.addOnCameraChangeListener(this) - // marker 点击事件监听 - aMap.addOnMarkerClickListener(this) - // 点击marker弹出自定义popup - aMap.setInfoWindowAdapter(this) - //信息窗点击事件 - aMap.addOnInfoWindowClickListener(this) } override fun initEvent() { @@ -259,9 +243,111 @@ } - override fun onMapLoaded() { - //地图加载成功之后显示聚合点数据 - initClustersMarkers() + private fun displayWellOnMap() { + clusterOverlay?.onDestroy() + val clusterItems = ArrayList() + + wellModels.forEach { + val latitude = it.latGaode.toDouble() + val longitude = it.lngGaode.toDouble() + + val latLng = LatLng(latitude, longitude, false) + val regionItem = RegionItem(latLng, it) + clusterItems.add(regionItem) + } + + clusterOverlay = ClusterOverlay(requireContext(), aMap, clusterItems, regionRadius) + clusterOverlay?.setClusterRender { clusterNum -> + //聚合圆半径 + val radius = 100.dp2px(requireContext()) + if (clusterNum == 0) { + var bitmapDrawable = backDrawables[0] + if (bitmapDrawable == null) { + bitmapDrawable = BitmapDrawable( + null, radius.drawCircle(Color.argb(159, 100, 149, 237)) + ) + backDrawables[0] = bitmapDrawable + } + bitmapDrawable + } + if (clusterNum == 1) { + var bitmapDrawable = backDrawables[1] + if (bitmapDrawable == null) { + bitmapDrawable = R.mipmap.well_location.convertDrawable(requireContext())!! + backDrawables[1] = bitmapDrawable + } + bitmapDrawable + } else if (clusterNum < 5) { + var bitmapDrawable = backDrawables[2] + if (bitmapDrawable == null) { + bitmapDrawable = BitmapDrawable( + null, radius.drawCircle(Color.argb(159, 100, 149, 237)) + ) + backDrawables[2] = bitmapDrawable + } + bitmapDrawable + } else if (clusterNum < 10) { + var bitmapDrawable = backDrawables[3] + if (bitmapDrawable == null) { + bitmapDrawable = BitmapDrawable( + null, radius.drawCircle(Color.argb(199, 30, 144, 255)) + ) + backDrawables[3] = bitmapDrawable + } + bitmapDrawable + } else { + var bitmapDrawable = backDrawables[4] + if (bitmapDrawable == null) { + bitmapDrawable = BitmapDrawable( + null, radius.drawCircle(Color.argb(235, 65, 105, 225)) + ) + backDrawables[4] = bitmapDrawable + } + bitmapDrawable + } + } + + clusterOverlay?.setOnClusterClickListener(object : ClusterOnClickListener { + override fun onMarkerClicked(marker: Marker?, items: List) { + if (items.size > 1) { + "请缩放地图比例在查看数据".show(requireContext()) + return + } + + var item: RegionItem? = null + val builder = LatLngBounds.Builder() + for (clusterItem in items) { + builder.include(clusterItem.position) + item = clusterItem as RegionItem + } + + item?.apply { + showWellPopup(well) + } + } + }) + } + + private fun showWellPopup(well: MapWellListModel.DataModel) { + infoPopup.set(well, object : MapWellPopup.OnPopupWindowClickListener { + override fun onPopupClicked(lat: Double, lng: Double) { + AlertControlDialog.Builder().setContext(requireContext()).setTitle("操作提示") + .setMessage("确定要前往吗").setNegativeButton("取消").setPositiveButton("确定") + .setOnDialogButtonClickListener(object : + AlertControlDialog.OnDialogButtonClickListener { + override fun onConfirmClick() { + RouteOnMap.startNavigation( + requireContext(), "", LatLng(lat, lng) + ) + } + + override fun onCancelClick() { + + } + }).build().show() + } + }) + infoPopup.showAsDropDown(binding.rightOptionView) } override fun onCameraChange(p0: CameraPosition?) { @@ -282,103 +368,10 @@ } } - //获取视野内的marker 根据聚合算法合成自定义的marker 显示视野内的marker override fun onCameraChangeFinish(p0: CameraPosition?) { //地图缩放之后显示聚合点数据 LoadingDialogHub.dismiss() httpCountDownTimer.cancel() - initClustersMarkers() - } - - private fun initClustersMarkers() { - 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 { - v = LayoutInflater.from(requireContext()).inflate(R.layout.popup_map_info, null) - - //显示闸井信息 - marker?.showInfoWindow() - return true - } - - override fun getInfoWindow(marker: Marker?): View { - //反射得到popup里面的控件对象 - val wellNameView = v.findViewById(R.id.wellNameView) - val wellCodeView = v.findViewById(R.id.wellCodeView) - val wellTypeView = v.findViewById(R.id.wellTypeView) - val wellStateView = v.findViewById(R.id.wellStateView) - val deepView = v.findViewById(R.id.deepView) - val locationView = v.findViewById(R.id.locationView) - - //绑定数据 - val clickedLatLng = marker?.position!! - wellModels.forEach { well -> - if (clickedLatLng.latitude == well.latGaode!!.toDouble() - && clickedLatLng.longitude == well.lngGaode!!.toDouble() - ) { - wellNameView.text = String.format("点位名称: ${well.wellName}") - wellCodeView.text = String.format("点位编号: ${well.wellCode}") - wellTypeView.text = String.format("点位类型: ${well.wellType.valueToType()}") - val bfztName = if (well.bfzt == "1") { - "已布防" - } else { - "已撤防" - } - wellStateView.text = String.format("布/撤防状态: $bfztName") - deepView.text = String.format("点位深度: ${well.deep}m") - locationView.text = String.format("详细位置: ${well.position}") - } - } - return v - } - - /** - * 此方法不能修改整个 InfoWindow 的背景和边框,无论自定义的样式是什么样,SDK 都会在最外层添加一个默认的边框 - * */ - override fun getInfoContents(p0: Marker?): View? = null - - override fun onInfoWindowClick(p0: Marker?) { - p0?.apply { - AlertControlDialog.Builder() - .setContext(requireContext()) - .setTitle("操作提示") - .setMessage("确定要前往吗") - .setNegativeButton("取消") - .setPositiveButton("确定") - .setOnDialogButtonClickListener(object : - AlertControlDialog.OnDialogButtonClickListener { - override fun onConfirmClick() { - val lat = position.latitude.toString() - val lng = position.longitude.toString() - if (lat.isBlank() || lng.isBlank()) { - "点位经纬度异常,无法开启导航".show(requireContext()) - return - } - RouteOnMap.startNavigation( - requireContext(), snippet, LatLng(lat.toDouble(), lng.toDouble()) - ) - } - - override fun onCancelClick() { - - } - }).build().show() - } } /***以下是地图生命周期管理************************************************************************/ 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 a54d213..bfa7a57 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 @@ -44,8 +44,8 @@ * 地图点位不带聚合效果 * */ class HomePageNoClusterFragment : KotlinBaseFragment(), - AMap.OnMapLoadedListener, AMap.OnCameraChangeListener, AMap.OnMarkerClickListener, - AMap.InfoWindowAdapter, AMap.OnInfoWindowClickListener { + AMap.OnCameraChangeListener, AMap.OnMarkerClickListener, AMap.InfoWindowAdapter, + AMap.OnInfoWindowClickListener { private val kTag = "NoClusterFragment" private val easyPopupWindow by lazy { EasyPopupWindow(requireContext()) } @@ -109,6 +109,9 @@ wellViewModel = ViewModelProvider(this)[WellViewModel::class.java] orderViewModel = ViewModelProvider(this)[OrderViewModel::class.java] + //地图初始化 + initMap(savedInstanceState) + //获取所有窨井数据 httpCountDownTimer.start() LoadingDialogHub.show(requireActivity(), "数据加载中,请稍后...") @@ -157,12 +160,12 @@ val cameraPosition = CameraPosition(centerLatLng, 16f, 0f, 0f) val cameraUpdate = CameraUpdateFactory.newCameraPosition(cameraPosition) aMap.animateCamera(cameraUpdate, 1500, null) + + //显示点数据 + displayWellOnMap() } } - //地图初始化 - initMap(savedInstanceState) - //获取窨井监控数据 wellViewModel.countResultModel.observe(this) { binding.deployedWellView.text = it["bfWell"] @@ -214,9 +217,8 @@ uiSettings.isCompassEnabled = true uiSettings.zoomPosition = AMapOptions.ZOOM_POSITION_RIGHT_CENTER uiSettings.isTiltGesturesEnabled = false//不许地图随手势倾斜角度 + uiSettings.isRotateGesturesEnabled = false//不允许地图随手势改变方位 - // 地图加载成功监听 - aMap.addOnMapLoadedListener(this) // 地图缩放监听 aMap.addOnCameraChangeListener(this) // marker 点击事件监听 @@ -253,11 +255,6 @@ } - override fun onMapLoaded() { - //地图加载成功之后显示聚合点数据 - initClustersMarkers() - } - override fun onCameraChange(p0: CameraPosition?) { } @@ -281,10 +278,9 @@ //地图缩放之后显示聚合点数据 LoadingDialogHub.dismiss() httpCountDownTimer.cancel() - initClustersMarkers() } - private fun initClustersMarkers() { + private fun displayWellOnMap() { val proj = aMap.projection val dm = resources.displayMetrics var screenLocation: Point diff --git a/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.java b/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.java deleted file mode 100644 index d8b18ef..0000000 --- a/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.java +++ /dev/null @@ -1,50 +0,0 @@ -package com.casic.app.smartwell.model; - -public class ErrorMessageModel { - - private int code; - private String data; - private String exceptionClazz; - private String message; - private boolean success; - - public int getCode() { - return code; - } - - public void setCode(int code) { - this.code = code; - } - - public String getData() { - return data; - } - - public void setData(String data) { - this.data = data; - } - - public String getExceptionClazz() { - return exceptionClazz; - } - - public void setExceptionClazz(String exceptionClazz) { - this.exceptionClazz = exceptionClazz; - } - - public String getMessage() { - return message; - } - - public void setMessage(String message) { - this.message = message; - } - - public boolean isSuccess() { - return success; - } - - public void setSuccess(boolean success) { - this.success = success; - } -} \ No newline at end of file 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 new file mode 100644 index 0000000..215ac0c --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/PipelineModel.java @@ -0,0 +1,328 @@ +package com.casic.app.smartwell.model; + +import java.util.List; + +public class PipelineModel { + + private Integer code; + private DataModel data; + private String message; + private Boolean success; + + public Integer getCode() { + return code; + } + + public void setCode(Integer code) { + this.code = code; + } + + public DataModel getData() { + return data; + } + + public void setData(DataModel data) { + this.data = data; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + public Boolean getSuccess() { + return success; + } + + public void setSuccess(Boolean success) { + this.success = success; + } + + public static class DataModel { + private List rows; + private Integer total; + + public List getRows() { + return rows; + } + + public void setRows(List rows) { + this.rows = rows; + } + + public Integer getTotal() { + return total; + } + + public void setTotal(Integer total) { + this.total = total; + } + + 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 getBuryMode() { + return buryMode; + } + + public void setBuryMode(String buryMode) { + this.buryMode = buryMode; + } + + public String getConstructEra() { + return constructEra; + } + + public void setConstructEra(String constructEra) { + this.constructEra = constructEra; + } + + 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; + } + } + } +} 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 06d3d2b..4f38a2c 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 = 100 //相距多少米才聚合,单位:米 + const val RADIUS_SIZE = 80 //相距多少米才聚合,单位:米 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:11308" + // 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 0d5f3fa..991e1db 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 @@ -312,4 +312,14 @@ @Header("token") token: String, @Field("clientid") deviceCode: String ): String + + /** + * 管线位置数据 + */ + @GET("/pipeline/listPage") + suspend fun getPipeline( + @Header("token") token: String, + @Query("limit") limit: Int, + @Query("offset") offset: Int + ): String } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt index 1a0ce22..4050067 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt @@ -294,4 +294,11 @@ suspend fun registerPush(clientId: String): String { return api.registerPush(AuthenticationHelper.token!!, clientId) } + + /** + * 管线位置数据 + */ + suspend fun getPipeline(): String { + return api.getPipeline(AuthenticationHelper.token!!, 2000, 1) + } } \ No newline at end of file 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 9270fa1..4ca5a5e 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.HomePageNoClusterFragment +import com.casic.app.smartwell.fragment.HomePageHaveClusterFragment 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/vm/AlarmViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/AlarmViewModel.kt index 9cff08c..e7acc17 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/AlarmViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/AlarmViewModel.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.AlarmContentModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager import com.google.gson.Gson @@ -16,7 +16,7 @@ fun getAlarmContentType(alarmType: String) = launch({ val response = RetrofitServiceManager.getAlarmContentType(alarmType) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { listModel.value = gson.fromJson( response, object : TypeToken() {}.type diff --git a/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt index 5e5b163..895dedd 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.PublicKeyModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager import com.google.gson.Gson @@ -18,7 +18,7 @@ fun getPublicKey() = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.authenticate() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { keyModel.value = gson.fromJson( response, object : TypeToken() {}.type diff --git a/app/src/main/java/com/casic/app/smartwell/extensions/Int.kt b/app/src/main/java/com/casic/app/smartwell/extensions/Int.kt index de0617b..a0a5e33 100644 --- a/app/src/main/java/com/casic/app/smartwell/extensions/Int.kt +++ b/app/src/main/java/com/casic/app/smartwell/extensions/Int.kt @@ -1,9 +1,24 @@ package com.casic.app.smartwell.extensions +import android.graphics.Bitmap +import android.graphics.Canvas +import android.graphics.Paint +import android.graphics.RectF + fun Int.toLevel(): String { return if (this == 0) { "" } else { this.toString() } +} + +fun Int.drawCircle(color: Int): Bitmap? { + val bitmap = Bitmap.createBitmap(this * 2, this * 2, Bitmap.Config.ARGB_8888) + val canvas = Canvas(bitmap) + val paint = Paint() + val rectF = RectF(0f, 0f, (this * 2).toFloat(), (this * 2).toFloat()) + paint.color = color + canvas.drawArc(rectF, 0f, 360f, true, paint) + return bitmap } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt index 6b6ca3e..5e45534 100644 --- a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt +++ b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt @@ -2,17 +2,13 @@ import android.content.Context import com.casic.app.smartwell.callback.OnImageCompressListener -import com.casic.app.smartwell.model.ErrorMessageModel import com.casic.app.smartwell.utils.LocaleConstant -import com.google.gson.Gson -import com.google.gson.reflect.TypeToken +import com.google.gson.JsonParser import com.pengxh.kt.lite.extensions.createCompressImageDir import com.pengxh.kt.lite.utils.SaveKeyValues -import org.json.JSONObject import top.zibin.luban.Luban import top.zibin.luban.OnCompressListener import java.io.File -import java.util.Locale /** * String扩展方法 @@ -74,18 +70,22 @@ } } -fun String.separateResponseCode(): Int { +fun String.getResponseCode(): Int { if (this.isBlank()) { return 404 } - return JSONObject(this).getInt("code") + val element = JsonParser.parseString(this) + val jsonObject = element.asJsonObject + return jsonObject.get("code").asInt } -fun String.toErrorMessage(): String { - val errorModel = Gson().fromJson( - this, object : TypeToken() {}.type - ) - return errorModel.message.toString() +fun String.getResponseMessage(): String { + if (this.isBlank()) { + return "" + } + val element = JsonParser.parseString(this) + val jsonObject = element.asJsonObject + return jsonObject.get("message").asString } fun String.compressImage(context: Context, listener: OnImageCompressListener) { @@ -93,9 +93,6 @@ .load(this) .ignoreBy(100) .setTargetDir(context.createCompressImageDir().toString()) - .filter { - !(it.isBlank() || it.lowercase(Locale.getDefault()).endsWith(".gif")) - } .setCompressListener(object : OnCompressListener { override fun onStart() { 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 96df110..cd25fca 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 @@ -1,26 +1,25 @@ package com.casic.app.smartwell.fragment -import android.graphics.Point +import android.graphics.Color +import android.graphics.drawable.BitmapDrawable +import android.graphics.drawable.Drawable 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 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.LatLngBounds import com.amap.api.maps.model.Marker -import com.amap.api.maps.model.MarkerOptions import com.casic.app.smartwell.R import com.casic.app.smartwell.databinding.FragmentHomeBinding +import com.casic.app.smartwell.extensions.drawCircle import com.casic.app.smartwell.extensions.initImmersionBar -import com.casic.app.smartwell.extensions.valueToType import com.casic.app.smartwell.model.MapWellListModel import com.casic.app.smartwell.utils.LocaleConstant import com.casic.app.smartwell.utils.RouteOnMap @@ -31,9 +30,16 @@ import com.casic.app.smartwell.view.WellOperationActivity import com.casic.app.smartwell.vm.OrderViewModel import com.casic.app.smartwell.vm.WellViewModel +import com.casic.app.smartwell.widgets.MapWellPopup +import com.casic.app.smartwell.widgets.cluster.ClusterItem +import com.casic.app.smartwell.widgets.cluster.ClusterOnClickListener +import com.casic.app.smartwell.widgets.cluster.ClusterOverlay +import com.casic.app.smartwell.widgets.cluster.RegionItem 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.convertDrawable +import com.pengxh.kt.lite.extensions.dp2px import com.pengxh.kt.lite.extensions.navigatePageTo import com.pengxh.kt.lite.extensions.show import com.pengxh.kt.lite.utils.LoadingDialogHub @@ -43,35 +49,23 @@ /** * 地图点位带聚合效果 * */ -class HomePageHaveClusterFragment : KotlinBaseFragment(), AMap.OnMapLoadedListener, - AMap.OnCameraChangeListener, AMap.OnMarkerClickListener, AMap.InfoWindowAdapter, - AMap.OnInfoWindowClickListener { +class HomePageHaveClusterFragment : KotlinBaseFragment(), + AMap.OnCameraChangeListener { private val kTag = "HaveClusterFragment" private val easyPopupWindow by lazy { EasyPopupWindow(requireContext()) } - private lateinit var wellViewModel: WellViewModel - private lateinit var orderViewModel: OrderViewModel - private lateinit var aMap: AMap - - /** - * 所有的marker - */ - private var allMarkerOptions: MutableList = ArrayList() - - /** - * 视野内的marker - */ - private var markerOptionsInView: MutableList = ArrayList() - - /** - * 自定义Marker弹出框 - * */ - private lateinit var v: View + private val regionRadius by lazy { LocaleConstant.RADIUS_SIZE.dp2px(requireContext()) } + private val infoPopup by lazy { MapWellPopup(requireContext()) } /** * 所有窨井列表信息集合 * */ - private var wellModels: MutableList = ArrayList() + private val wellModels = ArrayList() + private val backDrawables = HashMap() + private lateinit var wellViewModel: WellViewModel + private lateinit var orderViewModel: OrderViewModel + private lateinit var aMap: AMap + private var clusterOverlay: ClusterOverlay? = null override fun initViewBinding( inflater: LayoutInflater, @@ -106,6 +100,9 @@ } }) + //地图初始化 + initMap(savedInstanceState) + //初始化vm wellViewModel = ViewModelProvider(this)[WellViewModel::class.java] orderViewModel = ViewModelProvider(this)[OrderViewModel::class.java] @@ -120,25 +117,19 @@ val latitudeList: MutableList = ArrayList() val longitudeList: MutableList = ArrayList() it.data?.forEach { well -> - val lat = well.latGaode.toString() - val lng = well.lngGaode.toString() + val lat = well.latGaode + val lng = well.lngGaode if (lat.isNotBlank() && lng.isNotBlank()) { //返回true代表当前位置在大陆、港澳地区,反之不在 val latitude = lat.toDouble() val longitude = lng.toDouble() if (CoordinateConverter.isAMapDataAvailable(latitude, longitude)) { - //缓存所有设备详情,点击Marker时候需要 + //缓存所有井 wellModels.add(well) + //分别缓存经、纬度 latitudeList.add(latitude) longitudeList.add(longitude) - //将所有设备信息转化缓存为Marker点 - allMarkerOptions.add( - MarkerOptions() - .position(LatLng(latitude, longitude)) - .title(well.wellTypeName) - .snippet(well.wellName) - ) } } } @@ -160,12 +151,12 @@ val cameraPosition = CameraPosition(centerLatLng, 16f, 0f, 0f) val cameraUpdate = CameraUpdateFactory.newCameraPosition(cameraPosition) aMap.animateCamera(cameraUpdate, 1500, null) + + //显示点数据 + displayWellOnMap() } } - //地图初始化 - initMap(savedInstanceState) - //获取窨井监控数据 wellViewModel.countResultModel.observe(this) { binding.deployedWellView.text = it["bfWell"] @@ -220,17 +211,10 @@ uiSettings.isCompassEnabled = true uiSettings.zoomPosition = AMapOptions.ZOOM_POSITION_RIGHT_CENTER uiSettings.isTiltGesturesEnabled = false//不许地图随手势倾斜角度 + uiSettings.isRotateGesturesEnabled = false//不允许地图随手势改变方位 - // 地图加载成功监听 - aMap.addOnMapLoadedListener(this) // 地图缩放监听 aMap.addOnCameraChangeListener(this) - // marker 点击事件监听 - aMap.addOnMarkerClickListener(this) - // 点击marker弹出自定义popup - aMap.setInfoWindowAdapter(this) - //信息窗点击事件 - aMap.addOnInfoWindowClickListener(this) } override fun initEvent() { @@ -259,9 +243,111 @@ } - override fun onMapLoaded() { - //地图加载成功之后显示聚合点数据 - initClustersMarkers() + private fun displayWellOnMap() { + clusterOverlay?.onDestroy() + val clusterItems = ArrayList() + + wellModels.forEach { + val latitude = it.latGaode.toDouble() + val longitude = it.lngGaode.toDouble() + + val latLng = LatLng(latitude, longitude, false) + val regionItem = RegionItem(latLng, it) + clusterItems.add(regionItem) + } + + clusterOverlay = ClusterOverlay(requireContext(), aMap, clusterItems, regionRadius) + clusterOverlay?.setClusterRender { clusterNum -> + //聚合圆半径 + val radius = 100.dp2px(requireContext()) + if (clusterNum == 0) { + var bitmapDrawable = backDrawables[0] + if (bitmapDrawable == null) { + bitmapDrawable = BitmapDrawable( + null, radius.drawCircle(Color.argb(159, 100, 149, 237)) + ) + backDrawables[0] = bitmapDrawable + } + bitmapDrawable + } + if (clusterNum == 1) { + var bitmapDrawable = backDrawables[1] + if (bitmapDrawable == null) { + bitmapDrawable = R.mipmap.well_location.convertDrawable(requireContext())!! + backDrawables[1] = bitmapDrawable + } + bitmapDrawable + } else if (clusterNum < 5) { + var bitmapDrawable = backDrawables[2] + if (bitmapDrawable == null) { + bitmapDrawable = BitmapDrawable( + null, radius.drawCircle(Color.argb(159, 100, 149, 237)) + ) + backDrawables[2] = bitmapDrawable + } + bitmapDrawable + } else if (clusterNum < 10) { + var bitmapDrawable = backDrawables[3] + if (bitmapDrawable == null) { + bitmapDrawable = BitmapDrawable( + null, radius.drawCircle(Color.argb(199, 30, 144, 255)) + ) + backDrawables[3] = bitmapDrawable + } + bitmapDrawable + } else { + var bitmapDrawable = backDrawables[4] + if (bitmapDrawable == null) { + bitmapDrawable = BitmapDrawable( + null, radius.drawCircle(Color.argb(235, 65, 105, 225)) + ) + backDrawables[4] = bitmapDrawable + } + bitmapDrawable + } + } + + clusterOverlay?.setOnClusterClickListener(object : ClusterOnClickListener { + override fun onMarkerClicked(marker: Marker?, items: List) { + if (items.size > 1) { + "请缩放地图比例在查看数据".show(requireContext()) + return + } + + var item: RegionItem? = null + val builder = LatLngBounds.Builder() + for (clusterItem in items) { + builder.include(clusterItem.position) + item = clusterItem as RegionItem + } + + item?.apply { + showWellPopup(well) + } + } + }) + } + + private fun showWellPopup(well: MapWellListModel.DataModel) { + infoPopup.set(well, object : MapWellPopup.OnPopupWindowClickListener { + override fun onPopupClicked(lat: Double, lng: Double) { + AlertControlDialog.Builder().setContext(requireContext()).setTitle("操作提示") + .setMessage("确定要前往吗").setNegativeButton("取消").setPositiveButton("确定") + .setOnDialogButtonClickListener(object : + AlertControlDialog.OnDialogButtonClickListener { + override fun onConfirmClick() { + RouteOnMap.startNavigation( + requireContext(), "", LatLng(lat, lng) + ) + } + + override fun onCancelClick() { + + } + }).build().show() + } + }) + infoPopup.showAsDropDown(binding.rightOptionView) } override fun onCameraChange(p0: CameraPosition?) { @@ -282,103 +368,10 @@ } } - //获取视野内的marker 根据聚合算法合成自定义的marker 显示视野内的marker override fun onCameraChangeFinish(p0: CameraPosition?) { //地图缩放之后显示聚合点数据 LoadingDialogHub.dismiss() httpCountDownTimer.cancel() - initClustersMarkers() - } - - private fun initClustersMarkers() { - 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 { - v = LayoutInflater.from(requireContext()).inflate(R.layout.popup_map_info, null) - - //显示闸井信息 - marker?.showInfoWindow() - return true - } - - override fun getInfoWindow(marker: Marker?): View { - //反射得到popup里面的控件对象 - val wellNameView = v.findViewById(R.id.wellNameView) - val wellCodeView = v.findViewById(R.id.wellCodeView) - val wellTypeView = v.findViewById(R.id.wellTypeView) - val wellStateView = v.findViewById(R.id.wellStateView) - val deepView = v.findViewById(R.id.deepView) - val locationView = v.findViewById(R.id.locationView) - - //绑定数据 - val clickedLatLng = marker?.position!! - wellModels.forEach { well -> - if (clickedLatLng.latitude == well.latGaode!!.toDouble() - && clickedLatLng.longitude == well.lngGaode!!.toDouble() - ) { - wellNameView.text = String.format("点位名称: ${well.wellName}") - wellCodeView.text = String.format("点位编号: ${well.wellCode}") - wellTypeView.text = String.format("点位类型: ${well.wellType.valueToType()}") - val bfztName = if (well.bfzt == "1") { - "已布防" - } else { - "已撤防" - } - wellStateView.text = String.format("布/撤防状态: $bfztName") - deepView.text = String.format("点位深度: ${well.deep}m") - locationView.text = String.format("详细位置: ${well.position}") - } - } - return v - } - - /** - * 此方法不能修改整个 InfoWindow 的背景和边框,无论自定义的样式是什么样,SDK 都会在最外层添加一个默认的边框 - * */ - override fun getInfoContents(p0: Marker?): View? = null - - override fun onInfoWindowClick(p0: Marker?) { - p0?.apply { - AlertControlDialog.Builder() - .setContext(requireContext()) - .setTitle("操作提示") - .setMessage("确定要前往吗") - .setNegativeButton("取消") - .setPositiveButton("确定") - .setOnDialogButtonClickListener(object : - AlertControlDialog.OnDialogButtonClickListener { - override fun onConfirmClick() { - val lat = position.latitude.toString() - val lng = position.longitude.toString() - if (lat.isBlank() || lng.isBlank()) { - "点位经纬度异常,无法开启导航".show(requireContext()) - return - } - RouteOnMap.startNavigation( - requireContext(), snippet, LatLng(lat.toDouble(), lng.toDouble()) - ) - } - - override fun onCancelClick() { - - } - }).build().show() - } } /***以下是地图生命周期管理************************************************************************/ 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 a54d213..bfa7a57 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 @@ -44,8 +44,8 @@ * 地图点位不带聚合效果 * */ class HomePageNoClusterFragment : KotlinBaseFragment(), - AMap.OnMapLoadedListener, AMap.OnCameraChangeListener, AMap.OnMarkerClickListener, - AMap.InfoWindowAdapter, AMap.OnInfoWindowClickListener { + AMap.OnCameraChangeListener, AMap.OnMarkerClickListener, AMap.InfoWindowAdapter, + AMap.OnInfoWindowClickListener { private val kTag = "NoClusterFragment" private val easyPopupWindow by lazy { EasyPopupWindow(requireContext()) } @@ -109,6 +109,9 @@ wellViewModel = ViewModelProvider(this)[WellViewModel::class.java] orderViewModel = ViewModelProvider(this)[OrderViewModel::class.java] + //地图初始化 + initMap(savedInstanceState) + //获取所有窨井数据 httpCountDownTimer.start() LoadingDialogHub.show(requireActivity(), "数据加载中,请稍后...") @@ -157,12 +160,12 @@ val cameraPosition = CameraPosition(centerLatLng, 16f, 0f, 0f) val cameraUpdate = CameraUpdateFactory.newCameraPosition(cameraPosition) aMap.animateCamera(cameraUpdate, 1500, null) + + //显示点数据 + displayWellOnMap() } } - //地图初始化 - initMap(savedInstanceState) - //获取窨井监控数据 wellViewModel.countResultModel.observe(this) { binding.deployedWellView.text = it["bfWell"] @@ -214,9 +217,8 @@ uiSettings.isCompassEnabled = true uiSettings.zoomPosition = AMapOptions.ZOOM_POSITION_RIGHT_CENTER uiSettings.isTiltGesturesEnabled = false//不许地图随手势倾斜角度 + uiSettings.isRotateGesturesEnabled = false//不允许地图随手势改变方位 - // 地图加载成功监听 - aMap.addOnMapLoadedListener(this) // 地图缩放监听 aMap.addOnCameraChangeListener(this) // marker 点击事件监听 @@ -253,11 +255,6 @@ } - override fun onMapLoaded() { - //地图加载成功之后显示聚合点数据 - initClustersMarkers() - } - override fun onCameraChange(p0: CameraPosition?) { } @@ -281,10 +278,9 @@ //地图缩放之后显示聚合点数据 LoadingDialogHub.dismiss() httpCountDownTimer.cancel() - initClustersMarkers() } - private fun initClustersMarkers() { + private fun displayWellOnMap() { val proj = aMap.projection val dm = resources.displayMetrics var screenLocation: Point diff --git a/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.java b/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.java deleted file mode 100644 index d8b18ef..0000000 --- a/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.java +++ /dev/null @@ -1,50 +0,0 @@ -package com.casic.app.smartwell.model; - -public class ErrorMessageModel { - - private int code; - private String data; - private String exceptionClazz; - private String message; - private boolean success; - - public int getCode() { - return code; - } - - public void setCode(int code) { - this.code = code; - } - - public String getData() { - return data; - } - - public void setData(String data) { - this.data = data; - } - - public String getExceptionClazz() { - return exceptionClazz; - } - - public void setExceptionClazz(String exceptionClazz) { - this.exceptionClazz = exceptionClazz; - } - - public String getMessage() { - return message; - } - - public void setMessage(String message) { - this.message = message; - } - - public boolean isSuccess() { - return success; - } - - public void setSuccess(boolean success) { - this.success = success; - } -} \ No newline at end of file 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 new file mode 100644 index 0000000..215ac0c --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/PipelineModel.java @@ -0,0 +1,328 @@ +package com.casic.app.smartwell.model; + +import java.util.List; + +public class PipelineModel { + + private Integer code; + private DataModel data; + private String message; + private Boolean success; + + public Integer getCode() { + return code; + } + + public void setCode(Integer code) { + this.code = code; + } + + public DataModel getData() { + return data; + } + + public void setData(DataModel data) { + this.data = data; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + public Boolean getSuccess() { + return success; + } + + public void setSuccess(Boolean success) { + this.success = success; + } + + public static class DataModel { + private List rows; + private Integer total; + + public List getRows() { + return rows; + } + + public void setRows(List rows) { + this.rows = rows; + } + + public Integer getTotal() { + return total; + } + + public void setTotal(Integer total) { + this.total = total; + } + + 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 getBuryMode() { + return buryMode; + } + + public void setBuryMode(String buryMode) { + this.buryMode = buryMode; + } + + public String getConstructEra() { + return constructEra; + } + + public void setConstructEra(String constructEra) { + this.constructEra = constructEra; + } + + 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; + } + } + } +} 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 06d3d2b..4f38a2c 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 = 100 //相距多少米才聚合,单位:米 + const val RADIUS_SIZE = 80 //相距多少米才聚合,单位:米 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:11308" + // 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 0d5f3fa..991e1db 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 @@ -312,4 +312,14 @@ @Header("token") token: String, @Field("clientid") deviceCode: String ): String + + /** + * 管线位置数据 + */ + @GET("/pipeline/listPage") + suspend fun getPipeline( + @Header("token") token: String, + @Query("limit") limit: Int, + @Query("offset") offset: Int + ): String } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt index 1a0ce22..4050067 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt @@ -294,4 +294,11 @@ suspend fun registerPush(clientId: String): String { return api.registerPush(AuthenticationHelper.token!!, clientId) } + + /** + * 管线位置数据 + */ + suspend fun getPipeline(): String { + return api.getPipeline(AuthenticationHelper.token!!, 2000, 1) + } } \ No newline at end of file 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 9270fa1..4ca5a5e 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.HomePageNoClusterFragment +import com.casic.app.smartwell.fragment.HomePageHaveClusterFragment 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/vm/AlarmViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/AlarmViewModel.kt index 9cff08c..e7acc17 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/AlarmViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/AlarmViewModel.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.AlarmContentModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager import com.google.gson.Gson @@ -16,7 +16,7 @@ fun getAlarmContentType(alarmType: String) = launch({ val response = RetrofitServiceManager.getAlarmContentType(alarmType) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { listModel.value = gson.fromJson( response, object : TypeToken() {}.type diff --git a/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt index 5e5b163..895dedd 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.PublicKeyModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager import com.google.gson.Gson @@ -18,7 +18,7 @@ fun getPublicKey() = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.authenticate() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { keyModel.value = gson.fromJson( response, object : TypeToken() {}.type diff --git a/app/src/main/java/com/casic/app/smartwell/vm/DeviceViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/DeviceViewModel.kt index db5ccf6..899a962 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/DeviceViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/DeviceViewModel.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.DeviceDetailModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager import com.google.gson.Gson @@ -16,7 +16,7 @@ fun getDeviceDetail(deviceCode: String) = launch({ val response = RetrofitServiceManager.getDeviceDetail(deviceCode) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { detailModel.value = gson.fromJson( response, object : TypeToken() {}.type diff --git a/app/src/main/java/com/casic/app/smartwell/extensions/Int.kt b/app/src/main/java/com/casic/app/smartwell/extensions/Int.kt index de0617b..a0a5e33 100644 --- a/app/src/main/java/com/casic/app/smartwell/extensions/Int.kt +++ b/app/src/main/java/com/casic/app/smartwell/extensions/Int.kt @@ -1,9 +1,24 @@ package com.casic.app.smartwell.extensions +import android.graphics.Bitmap +import android.graphics.Canvas +import android.graphics.Paint +import android.graphics.RectF + fun Int.toLevel(): String { return if (this == 0) { "" } else { this.toString() } +} + +fun Int.drawCircle(color: Int): Bitmap? { + val bitmap = Bitmap.createBitmap(this * 2, this * 2, Bitmap.Config.ARGB_8888) + val canvas = Canvas(bitmap) + val paint = Paint() + val rectF = RectF(0f, 0f, (this * 2).toFloat(), (this * 2).toFloat()) + paint.color = color + canvas.drawArc(rectF, 0f, 360f, true, paint) + return bitmap } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt index 6b6ca3e..5e45534 100644 --- a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt +++ b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt @@ -2,17 +2,13 @@ import android.content.Context import com.casic.app.smartwell.callback.OnImageCompressListener -import com.casic.app.smartwell.model.ErrorMessageModel import com.casic.app.smartwell.utils.LocaleConstant -import com.google.gson.Gson -import com.google.gson.reflect.TypeToken +import com.google.gson.JsonParser import com.pengxh.kt.lite.extensions.createCompressImageDir import com.pengxh.kt.lite.utils.SaveKeyValues -import org.json.JSONObject import top.zibin.luban.Luban import top.zibin.luban.OnCompressListener import java.io.File -import java.util.Locale /** * String扩展方法 @@ -74,18 +70,22 @@ } } -fun String.separateResponseCode(): Int { +fun String.getResponseCode(): Int { if (this.isBlank()) { return 404 } - return JSONObject(this).getInt("code") + val element = JsonParser.parseString(this) + val jsonObject = element.asJsonObject + return jsonObject.get("code").asInt } -fun String.toErrorMessage(): String { - val errorModel = Gson().fromJson( - this, object : TypeToken() {}.type - ) - return errorModel.message.toString() +fun String.getResponseMessage(): String { + if (this.isBlank()) { + return "" + } + val element = JsonParser.parseString(this) + val jsonObject = element.asJsonObject + return jsonObject.get("message").asString } fun String.compressImage(context: Context, listener: OnImageCompressListener) { @@ -93,9 +93,6 @@ .load(this) .ignoreBy(100) .setTargetDir(context.createCompressImageDir().toString()) - .filter { - !(it.isBlank() || it.lowercase(Locale.getDefault()).endsWith(".gif")) - } .setCompressListener(object : OnCompressListener { override fun onStart() { 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 96df110..cd25fca 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 @@ -1,26 +1,25 @@ package com.casic.app.smartwell.fragment -import android.graphics.Point +import android.graphics.Color +import android.graphics.drawable.BitmapDrawable +import android.graphics.drawable.Drawable 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 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.LatLngBounds import com.amap.api.maps.model.Marker -import com.amap.api.maps.model.MarkerOptions import com.casic.app.smartwell.R import com.casic.app.smartwell.databinding.FragmentHomeBinding +import com.casic.app.smartwell.extensions.drawCircle import com.casic.app.smartwell.extensions.initImmersionBar -import com.casic.app.smartwell.extensions.valueToType import com.casic.app.smartwell.model.MapWellListModel import com.casic.app.smartwell.utils.LocaleConstant import com.casic.app.smartwell.utils.RouteOnMap @@ -31,9 +30,16 @@ import com.casic.app.smartwell.view.WellOperationActivity import com.casic.app.smartwell.vm.OrderViewModel import com.casic.app.smartwell.vm.WellViewModel +import com.casic.app.smartwell.widgets.MapWellPopup +import com.casic.app.smartwell.widgets.cluster.ClusterItem +import com.casic.app.smartwell.widgets.cluster.ClusterOnClickListener +import com.casic.app.smartwell.widgets.cluster.ClusterOverlay +import com.casic.app.smartwell.widgets.cluster.RegionItem 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.convertDrawable +import com.pengxh.kt.lite.extensions.dp2px import com.pengxh.kt.lite.extensions.navigatePageTo import com.pengxh.kt.lite.extensions.show import com.pengxh.kt.lite.utils.LoadingDialogHub @@ -43,35 +49,23 @@ /** * 地图点位带聚合效果 * */ -class HomePageHaveClusterFragment : KotlinBaseFragment(), AMap.OnMapLoadedListener, - AMap.OnCameraChangeListener, AMap.OnMarkerClickListener, AMap.InfoWindowAdapter, - AMap.OnInfoWindowClickListener { +class HomePageHaveClusterFragment : KotlinBaseFragment(), + AMap.OnCameraChangeListener { private val kTag = "HaveClusterFragment" private val easyPopupWindow by lazy { EasyPopupWindow(requireContext()) } - private lateinit var wellViewModel: WellViewModel - private lateinit var orderViewModel: OrderViewModel - private lateinit var aMap: AMap - - /** - * 所有的marker - */ - private var allMarkerOptions: MutableList = ArrayList() - - /** - * 视野内的marker - */ - private var markerOptionsInView: MutableList = ArrayList() - - /** - * 自定义Marker弹出框 - * */ - private lateinit var v: View + private val regionRadius by lazy { LocaleConstant.RADIUS_SIZE.dp2px(requireContext()) } + private val infoPopup by lazy { MapWellPopup(requireContext()) } /** * 所有窨井列表信息集合 * */ - private var wellModels: MutableList = ArrayList() + private val wellModels = ArrayList() + private val backDrawables = HashMap() + private lateinit var wellViewModel: WellViewModel + private lateinit var orderViewModel: OrderViewModel + private lateinit var aMap: AMap + private var clusterOverlay: ClusterOverlay? = null override fun initViewBinding( inflater: LayoutInflater, @@ -106,6 +100,9 @@ } }) + //地图初始化 + initMap(savedInstanceState) + //初始化vm wellViewModel = ViewModelProvider(this)[WellViewModel::class.java] orderViewModel = ViewModelProvider(this)[OrderViewModel::class.java] @@ -120,25 +117,19 @@ val latitudeList: MutableList = ArrayList() val longitudeList: MutableList = ArrayList() it.data?.forEach { well -> - val lat = well.latGaode.toString() - val lng = well.lngGaode.toString() + val lat = well.latGaode + val lng = well.lngGaode if (lat.isNotBlank() && lng.isNotBlank()) { //返回true代表当前位置在大陆、港澳地区,反之不在 val latitude = lat.toDouble() val longitude = lng.toDouble() if (CoordinateConverter.isAMapDataAvailable(latitude, longitude)) { - //缓存所有设备详情,点击Marker时候需要 + //缓存所有井 wellModels.add(well) + //分别缓存经、纬度 latitudeList.add(latitude) longitudeList.add(longitude) - //将所有设备信息转化缓存为Marker点 - allMarkerOptions.add( - MarkerOptions() - .position(LatLng(latitude, longitude)) - .title(well.wellTypeName) - .snippet(well.wellName) - ) } } } @@ -160,12 +151,12 @@ val cameraPosition = CameraPosition(centerLatLng, 16f, 0f, 0f) val cameraUpdate = CameraUpdateFactory.newCameraPosition(cameraPosition) aMap.animateCamera(cameraUpdate, 1500, null) + + //显示点数据 + displayWellOnMap() } } - //地图初始化 - initMap(savedInstanceState) - //获取窨井监控数据 wellViewModel.countResultModel.observe(this) { binding.deployedWellView.text = it["bfWell"] @@ -220,17 +211,10 @@ uiSettings.isCompassEnabled = true uiSettings.zoomPosition = AMapOptions.ZOOM_POSITION_RIGHT_CENTER uiSettings.isTiltGesturesEnabled = false//不许地图随手势倾斜角度 + uiSettings.isRotateGesturesEnabled = false//不允许地图随手势改变方位 - // 地图加载成功监听 - aMap.addOnMapLoadedListener(this) // 地图缩放监听 aMap.addOnCameraChangeListener(this) - // marker 点击事件监听 - aMap.addOnMarkerClickListener(this) - // 点击marker弹出自定义popup - aMap.setInfoWindowAdapter(this) - //信息窗点击事件 - aMap.addOnInfoWindowClickListener(this) } override fun initEvent() { @@ -259,9 +243,111 @@ } - override fun onMapLoaded() { - //地图加载成功之后显示聚合点数据 - initClustersMarkers() + private fun displayWellOnMap() { + clusterOverlay?.onDestroy() + val clusterItems = ArrayList() + + wellModels.forEach { + val latitude = it.latGaode.toDouble() + val longitude = it.lngGaode.toDouble() + + val latLng = LatLng(latitude, longitude, false) + val regionItem = RegionItem(latLng, it) + clusterItems.add(regionItem) + } + + clusterOverlay = ClusterOverlay(requireContext(), aMap, clusterItems, regionRadius) + clusterOverlay?.setClusterRender { clusterNum -> + //聚合圆半径 + val radius = 100.dp2px(requireContext()) + if (clusterNum == 0) { + var bitmapDrawable = backDrawables[0] + if (bitmapDrawable == null) { + bitmapDrawable = BitmapDrawable( + null, radius.drawCircle(Color.argb(159, 100, 149, 237)) + ) + backDrawables[0] = bitmapDrawable + } + bitmapDrawable + } + if (clusterNum == 1) { + var bitmapDrawable = backDrawables[1] + if (bitmapDrawable == null) { + bitmapDrawable = R.mipmap.well_location.convertDrawable(requireContext())!! + backDrawables[1] = bitmapDrawable + } + bitmapDrawable + } else if (clusterNum < 5) { + var bitmapDrawable = backDrawables[2] + if (bitmapDrawable == null) { + bitmapDrawable = BitmapDrawable( + null, radius.drawCircle(Color.argb(159, 100, 149, 237)) + ) + backDrawables[2] = bitmapDrawable + } + bitmapDrawable + } else if (clusterNum < 10) { + var bitmapDrawable = backDrawables[3] + if (bitmapDrawable == null) { + bitmapDrawable = BitmapDrawable( + null, radius.drawCircle(Color.argb(199, 30, 144, 255)) + ) + backDrawables[3] = bitmapDrawable + } + bitmapDrawable + } else { + var bitmapDrawable = backDrawables[4] + if (bitmapDrawable == null) { + bitmapDrawable = BitmapDrawable( + null, radius.drawCircle(Color.argb(235, 65, 105, 225)) + ) + backDrawables[4] = bitmapDrawable + } + bitmapDrawable + } + } + + clusterOverlay?.setOnClusterClickListener(object : ClusterOnClickListener { + override fun onMarkerClicked(marker: Marker?, items: List) { + if (items.size > 1) { + "请缩放地图比例在查看数据".show(requireContext()) + return + } + + var item: RegionItem? = null + val builder = LatLngBounds.Builder() + for (clusterItem in items) { + builder.include(clusterItem.position) + item = clusterItem as RegionItem + } + + item?.apply { + showWellPopup(well) + } + } + }) + } + + private fun showWellPopup(well: MapWellListModel.DataModel) { + infoPopup.set(well, object : MapWellPopup.OnPopupWindowClickListener { + override fun onPopupClicked(lat: Double, lng: Double) { + AlertControlDialog.Builder().setContext(requireContext()).setTitle("操作提示") + .setMessage("确定要前往吗").setNegativeButton("取消").setPositiveButton("确定") + .setOnDialogButtonClickListener(object : + AlertControlDialog.OnDialogButtonClickListener { + override fun onConfirmClick() { + RouteOnMap.startNavigation( + requireContext(), "", LatLng(lat, lng) + ) + } + + override fun onCancelClick() { + + } + }).build().show() + } + }) + infoPopup.showAsDropDown(binding.rightOptionView) } override fun onCameraChange(p0: CameraPosition?) { @@ -282,103 +368,10 @@ } } - //获取视野内的marker 根据聚合算法合成自定义的marker 显示视野内的marker override fun onCameraChangeFinish(p0: CameraPosition?) { //地图缩放之后显示聚合点数据 LoadingDialogHub.dismiss() httpCountDownTimer.cancel() - initClustersMarkers() - } - - private fun initClustersMarkers() { - 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 { - v = LayoutInflater.from(requireContext()).inflate(R.layout.popup_map_info, null) - - //显示闸井信息 - marker?.showInfoWindow() - return true - } - - override fun getInfoWindow(marker: Marker?): View { - //反射得到popup里面的控件对象 - val wellNameView = v.findViewById(R.id.wellNameView) - val wellCodeView = v.findViewById(R.id.wellCodeView) - val wellTypeView = v.findViewById(R.id.wellTypeView) - val wellStateView = v.findViewById(R.id.wellStateView) - val deepView = v.findViewById(R.id.deepView) - val locationView = v.findViewById(R.id.locationView) - - //绑定数据 - val clickedLatLng = marker?.position!! - wellModels.forEach { well -> - if (clickedLatLng.latitude == well.latGaode!!.toDouble() - && clickedLatLng.longitude == well.lngGaode!!.toDouble() - ) { - wellNameView.text = String.format("点位名称: ${well.wellName}") - wellCodeView.text = String.format("点位编号: ${well.wellCode}") - wellTypeView.text = String.format("点位类型: ${well.wellType.valueToType()}") - val bfztName = if (well.bfzt == "1") { - "已布防" - } else { - "已撤防" - } - wellStateView.text = String.format("布/撤防状态: $bfztName") - deepView.text = String.format("点位深度: ${well.deep}m") - locationView.text = String.format("详细位置: ${well.position}") - } - } - return v - } - - /** - * 此方法不能修改整个 InfoWindow 的背景和边框,无论自定义的样式是什么样,SDK 都会在最外层添加一个默认的边框 - * */ - override fun getInfoContents(p0: Marker?): View? = null - - override fun onInfoWindowClick(p0: Marker?) { - p0?.apply { - AlertControlDialog.Builder() - .setContext(requireContext()) - .setTitle("操作提示") - .setMessage("确定要前往吗") - .setNegativeButton("取消") - .setPositiveButton("确定") - .setOnDialogButtonClickListener(object : - AlertControlDialog.OnDialogButtonClickListener { - override fun onConfirmClick() { - val lat = position.latitude.toString() - val lng = position.longitude.toString() - if (lat.isBlank() || lng.isBlank()) { - "点位经纬度异常,无法开启导航".show(requireContext()) - return - } - RouteOnMap.startNavigation( - requireContext(), snippet, LatLng(lat.toDouble(), lng.toDouble()) - ) - } - - override fun onCancelClick() { - - } - }).build().show() - } } /***以下是地图生命周期管理************************************************************************/ 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 a54d213..bfa7a57 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 @@ -44,8 +44,8 @@ * 地图点位不带聚合效果 * */ class HomePageNoClusterFragment : KotlinBaseFragment(), - AMap.OnMapLoadedListener, AMap.OnCameraChangeListener, AMap.OnMarkerClickListener, - AMap.InfoWindowAdapter, AMap.OnInfoWindowClickListener { + AMap.OnCameraChangeListener, AMap.OnMarkerClickListener, AMap.InfoWindowAdapter, + AMap.OnInfoWindowClickListener { private val kTag = "NoClusterFragment" private val easyPopupWindow by lazy { EasyPopupWindow(requireContext()) } @@ -109,6 +109,9 @@ wellViewModel = ViewModelProvider(this)[WellViewModel::class.java] orderViewModel = ViewModelProvider(this)[OrderViewModel::class.java] + //地图初始化 + initMap(savedInstanceState) + //获取所有窨井数据 httpCountDownTimer.start() LoadingDialogHub.show(requireActivity(), "数据加载中,请稍后...") @@ -157,12 +160,12 @@ val cameraPosition = CameraPosition(centerLatLng, 16f, 0f, 0f) val cameraUpdate = CameraUpdateFactory.newCameraPosition(cameraPosition) aMap.animateCamera(cameraUpdate, 1500, null) + + //显示点数据 + displayWellOnMap() } } - //地图初始化 - initMap(savedInstanceState) - //获取窨井监控数据 wellViewModel.countResultModel.observe(this) { binding.deployedWellView.text = it["bfWell"] @@ -214,9 +217,8 @@ uiSettings.isCompassEnabled = true uiSettings.zoomPosition = AMapOptions.ZOOM_POSITION_RIGHT_CENTER uiSettings.isTiltGesturesEnabled = false//不许地图随手势倾斜角度 + uiSettings.isRotateGesturesEnabled = false//不允许地图随手势改变方位 - // 地图加载成功监听 - aMap.addOnMapLoadedListener(this) // 地图缩放监听 aMap.addOnCameraChangeListener(this) // marker 点击事件监听 @@ -253,11 +255,6 @@ } - override fun onMapLoaded() { - //地图加载成功之后显示聚合点数据 - initClustersMarkers() - } - override fun onCameraChange(p0: CameraPosition?) { } @@ -281,10 +278,9 @@ //地图缩放之后显示聚合点数据 LoadingDialogHub.dismiss() httpCountDownTimer.cancel() - initClustersMarkers() } - private fun initClustersMarkers() { + private fun displayWellOnMap() { val proj = aMap.projection val dm = resources.displayMetrics var screenLocation: Point diff --git a/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.java b/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.java deleted file mode 100644 index d8b18ef..0000000 --- a/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.java +++ /dev/null @@ -1,50 +0,0 @@ -package com.casic.app.smartwell.model; - -public class ErrorMessageModel { - - private int code; - private String data; - private String exceptionClazz; - private String message; - private boolean success; - - public int getCode() { - return code; - } - - public void setCode(int code) { - this.code = code; - } - - public String getData() { - return data; - } - - public void setData(String data) { - this.data = data; - } - - public String getExceptionClazz() { - return exceptionClazz; - } - - public void setExceptionClazz(String exceptionClazz) { - this.exceptionClazz = exceptionClazz; - } - - public String getMessage() { - return message; - } - - public void setMessage(String message) { - this.message = message; - } - - public boolean isSuccess() { - return success; - } - - public void setSuccess(boolean success) { - this.success = success; - } -} \ No newline at end of file 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 new file mode 100644 index 0000000..215ac0c --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/PipelineModel.java @@ -0,0 +1,328 @@ +package com.casic.app.smartwell.model; + +import java.util.List; + +public class PipelineModel { + + private Integer code; + private DataModel data; + private String message; + private Boolean success; + + public Integer getCode() { + return code; + } + + public void setCode(Integer code) { + this.code = code; + } + + public DataModel getData() { + return data; + } + + public void setData(DataModel data) { + this.data = data; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + public Boolean getSuccess() { + return success; + } + + public void setSuccess(Boolean success) { + this.success = success; + } + + public static class DataModel { + private List rows; + private Integer total; + + public List getRows() { + return rows; + } + + public void setRows(List rows) { + this.rows = rows; + } + + public Integer getTotal() { + return total; + } + + public void setTotal(Integer total) { + this.total = total; + } + + 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 getBuryMode() { + return buryMode; + } + + public void setBuryMode(String buryMode) { + this.buryMode = buryMode; + } + + public String getConstructEra() { + return constructEra; + } + + public void setConstructEra(String constructEra) { + this.constructEra = constructEra; + } + + 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; + } + } + } +} 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 06d3d2b..4f38a2c 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 = 100 //相距多少米才聚合,单位:米 + const val RADIUS_SIZE = 80 //相距多少米才聚合,单位:米 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:11308" + // 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 0d5f3fa..991e1db 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 @@ -312,4 +312,14 @@ @Header("token") token: String, @Field("clientid") deviceCode: String ): String + + /** + * 管线位置数据 + */ + @GET("/pipeline/listPage") + suspend fun getPipeline( + @Header("token") token: String, + @Query("limit") limit: Int, + @Query("offset") offset: Int + ): String } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt index 1a0ce22..4050067 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt @@ -294,4 +294,11 @@ suspend fun registerPush(clientId: String): String { return api.registerPush(AuthenticationHelper.token!!, clientId) } + + /** + * 管线位置数据 + */ + suspend fun getPipeline(): String { + return api.getPipeline(AuthenticationHelper.token!!, 2000, 1) + } } \ No newline at end of file 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 9270fa1..4ca5a5e 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.HomePageNoClusterFragment +import com.casic.app.smartwell.fragment.HomePageHaveClusterFragment 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/vm/AlarmViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/AlarmViewModel.kt index 9cff08c..e7acc17 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/AlarmViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/AlarmViewModel.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.AlarmContentModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager import com.google.gson.Gson @@ -16,7 +16,7 @@ fun getAlarmContentType(alarmType: String) = launch({ val response = RetrofitServiceManager.getAlarmContentType(alarmType) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { listModel.value = gson.fromJson( response, object : TypeToken() {}.type diff --git a/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt index 5e5b163..895dedd 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.PublicKeyModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager import com.google.gson.Gson @@ -18,7 +18,7 @@ fun getPublicKey() = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.authenticate() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { keyModel.value = gson.fromJson( response, object : TypeToken() {}.type diff --git a/app/src/main/java/com/casic/app/smartwell/vm/DeviceViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/DeviceViewModel.kt index db5ccf6..899a962 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/DeviceViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/DeviceViewModel.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.DeviceDetailModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager import com.google.gson.Gson @@ -16,7 +16,7 @@ fun getDeviceDetail(deviceCode: String) = launch({ val response = RetrofitServiceManager.getDeviceDetail(deviceCode) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { detailModel.value = gson.fromJson( response, object : TypeToken() {}.type diff --git a/app/src/main/java/com/casic/app/smartwell/vm/LoginViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/LoginViewModel.kt index cd8b8a9..a417398 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/LoginViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/LoginViewModel.kt @@ -2,7 +2,7 @@ import androidx.lifecycle.MutableLiveData import com.casic.app.smartwell.base.BaseApplication -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.CommonResultModel import com.casic.app.smartwell.model.LoginResultModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -21,7 +21,7 @@ fun enter(account: String, secretKey: String) = launch({ val response = RetrofitServiceManager.login(account, secretKey) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success enterResultModel.value = gson.fromJson( @@ -38,7 +38,7 @@ fun out() = launch({ val response = RetrofitServiceManager.loginOut() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { outResultModel.value = gson.fromJson( response, object : TypeToken() {}.type diff --git a/app/src/main/java/com/casic/app/smartwell/extensions/Int.kt b/app/src/main/java/com/casic/app/smartwell/extensions/Int.kt index de0617b..a0a5e33 100644 --- a/app/src/main/java/com/casic/app/smartwell/extensions/Int.kt +++ b/app/src/main/java/com/casic/app/smartwell/extensions/Int.kt @@ -1,9 +1,24 @@ package com.casic.app.smartwell.extensions +import android.graphics.Bitmap +import android.graphics.Canvas +import android.graphics.Paint +import android.graphics.RectF + fun Int.toLevel(): String { return if (this == 0) { "" } else { this.toString() } +} + +fun Int.drawCircle(color: Int): Bitmap? { + val bitmap = Bitmap.createBitmap(this * 2, this * 2, Bitmap.Config.ARGB_8888) + val canvas = Canvas(bitmap) + val paint = Paint() + val rectF = RectF(0f, 0f, (this * 2).toFloat(), (this * 2).toFloat()) + paint.color = color + canvas.drawArc(rectF, 0f, 360f, true, paint) + return bitmap } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt index 6b6ca3e..5e45534 100644 --- a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt +++ b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt @@ -2,17 +2,13 @@ import android.content.Context import com.casic.app.smartwell.callback.OnImageCompressListener -import com.casic.app.smartwell.model.ErrorMessageModel import com.casic.app.smartwell.utils.LocaleConstant -import com.google.gson.Gson -import com.google.gson.reflect.TypeToken +import com.google.gson.JsonParser import com.pengxh.kt.lite.extensions.createCompressImageDir import com.pengxh.kt.lite.utils.SaveKeyValues -import org.json.JSONObject import top.zibin.luban.Luban import top.zibin.luban.OnCompressListener import java.io.File -import java.util.Locale /** * String扩展方法 @@ -74,18 +70,22 @@ } } -fun String.separateResponseCode(): Int { +fun String.getResponseCode(): Int { if (this.isBlank()) { return 404 } - return JSONObject(this).getInt("code") + val element = JsonParser.parseString(this) + val jsonObject = element.asJsonObject + return jsonObject.get("code").asInt } -fun String.toErrorMessage(): String { - val errorModel = Gson().fromJson( - this, object : TypeToken() {}.type - ) - return errorModel.message.toString() +fun String.getResponseMessage(): String { + if (this.isBlank()) { + return "" + } + val element = JsonParser.parseString(this) + val jsonObject = element.asJsonObject + return jsonObject.get("message").asString } fun String.compressImage(context: Context, listener: OnImageCompressListener) { @@ -93,9 +93,6 @@ .load(this) .ignoreBy(100) .setTargetDir(context.createCompressImageDir().toString()) - .filter { - !(it.isBlank() || it.lowercase(Locale.getDefault()).endsWith(".gif")) - } .setCompressListener(object : OnCompressListener { override fun onStart() { 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 96df110..cd25fca 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 @@ -1,26 +1,25 @@ package com.casic.app.smartwell.fragment -import android.graphics.Point +import android.graphics.Color +import android.graphics.drawable.BitmapDrawable +import android.graphics.drawable.Drawable 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 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.LatLngBounds import com.amap.api.maps.model.Marker -import com.amap.api.maps.model.MarkerOptions import com.casic.app.smartwell.R import com.casic.app.smartwell.databinding.FragmentHomeBinding +import com.casic.app.smartwell.extensions.drawCircle import com.casic.app.smartwell.extensions.initImmersionBar -import com.casic.app.smartwell.extensions.valueToType import com.casic.app.smartwell.model.MapWellListModel import com.casic.app.smartwell.utils.LocaleConstant import com.casic.app.smartwell.utils.RouteOnMap @@ -31,9 +30,16 @@ import com.casic.app.smartwell.view.WellOperationActivity import com.casic.app.smartwell.vm.OrderViewModel import com.casic.app.smartwell.vm.WellViewModel +import com.casic.app.smartwell.widgets.MapWellPopup +import com.casic.app.smartwell.widgets.cluster.ClusterItem +import com.casic.app.smartwell.widgets.cluster.ClusterOnClickListener +import com.casic.app.smartwell.widgets.cluster.ClusterOverlay +import com.casic.app.smartwell.widgets.cluster.RegionItem 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.convertDrawable +import com.pengxh.kt.lite.extensions.dp2px import com.pengxh.kt.lite.extensions.navigatePageTo import com.pengxh.kt.lite.extensions.show import com.pengxh.kt.lite.utils.LoadingDialogHub @@ -43,35 +49,23 @@ /** * 地图点位带聚合效果 * */ -class HomePageHaveClusterFragment : KotlinBaseFragment(), AMap.OnMapLoadedListener, - AMap.OnCameraChangeListener, AMap.OnMarkerClickListener, AMap.InfoWindowAdapter, - AMap.OnInfoWindowClickListener { +class HomePageHaveClusterFragment : KotlinBaseFragment(), + AMap.OnCameraChangeListener { private val kTag = "HaveClusterFragment" private val easyPopupWindow by lazy { EasyPopupWindow(requireContext()) } - private lateinit var wellViewModel: WellViewModel - private lateinit var orderViewModel: OrderViewModel - private lateinit var aMap: AMap - - /** - * 所有的marker - */ - private var allMarkerOptions: MutableList = ArrayList() - - /** - * 视野内的marker - */ - private var markerOptionsInView: MutableList = ArrayList() - - /** - * 自定义Marker弹出框 - * */ - private lateinit var v: View + private val regionRadius by lazy { LocaleConstant.RADIUS_SIZE.dp2px(requireContext()) } + private val infoPopup by lazy { MapWellPopup(requireContext()) } /** * 所有窨井列表信息集合 * */ - private var wellModels: MutableList = ArrayList() + private val wellModels = ArrayList() + private val backDrawables = HashMap() + private lateinit var wellViewModel: WellViewModel + private lateinit var orderViewModel: OrderViewModel + private lateinit var aMap: AMap + private var clusterOverlay: ClusterOverlay? = null override fun initViewBinding( inflater: LayoutInflater, @@ -106,6 +100,9 @@ } }) + //地图初始化 + initMap(savedInstanceState) + //初始化vm wellViewModel = ViewModelProvider(this)[WellViewModel::class.java] orderViewModel = ViewModelProvider(this)[OrderViewModel::class.java] @@ -120,25 +117,19 @@ val latitudeList: MutableList = ArrayList() val longitudeList: MutableList = ArrayList() it.data?.forEach { well -> - val lat = well.latGaode.toString() - val lng = well.lngGaode.toString() + val lat = well.latGaode + val lng = well.lngGaode if (lat.isNotBlank() && lng.isNotBlank()) { //返回true代表当前位置在大陆、港澳地区,反之不在 val latitude = lat.toDouble() val longitude = lng.toDouble() if (CoordinateConverter.isAMapDataAvailable(latitude, longitude)) { - //缓存所有设备详情,点击Marker时候需要 + //缓存所有井 wellModels.add(well) + //分别缓存经、纬度 latitudeList.add(latitude) longitudeList.add(longitude) - //将所有设备信息转化缓存为Marker点 - allMarkerOptions.add( - MarkerOptions() - .position(LatLng(latitude, longitude)) - .title(well.wellTypeName) - .snippet(well.wellName) - ) } } } @@ -160,12 +151,12 @@ val cameraPosition = CameraPosition(centerLatLng, 16f, 0f, 0f) val cameraUpdate = CameraUpdateFactory.newCameraPosition(cameraPosition) aMap.animateCamera(cameraUpdate, 1500, null) + + //显示点数据 + displayWellOnMap() } } - //地图初始化 - initMap(savedInstanceState) - //获取窨井监控数据 wellViewModel.countResultModel.observe(this) { binding.deployedWellView.text = it["bfWell"] @@ -220,17 +211,10 @@ uiSettings.isCompassEnabled = true uiSettings.zoomPosition = AMapOptions.ZOOM_POSITION_RIGHT_CENTER uiSettings.isTiltGesturesEnabled = false//不许地图随手势倾斜角度 + uiSettings.isRotateGesturesEnabled = false//不允许地图随手势改变方位 - // 地图加载成功监听 - aMap.addOnMapLoadedListener(this) // 地图缩放监听 aMap.addOnCameraChangeListener(this) - // marker 点击事件监听 - aMap.addOnMarkerClickListener(this) - // 点击marker弹出自定义popup - aMap.setInfoWindowAdapter(this) - //信息窗点击事件 - aMap.addOnInfoWindowClickListener(this) } override fun initEvent() { @@ -259,9 +243,111 @@ } - override fun onMapLoaded() { - //地图加载成功之后显示聚合点数据 - initClustersMarkers() + private fun displayWellOnMap() { + clusterOverlay?.onDestroy() + val clusterItems = ArrayList() + + wellModels.forEach { + val latitude = it.latGaode.toDouble() + val longitude = it.lngGaode.toDouble() + + val latLng = LatLng(latitude, longitude, false) + val regionItem = RegionItem(latLng, it) + clusterItems.add(regionItem) + } + + clusterOverlay = ClusterOverlay(requireContext(), aMap, clusterItems, regionRadius) + clusterOverlay?.setClusterRender { clusterNum -> + //聚合圆半径 + val radius = 100.dp2px(requireContext()) + if (clusterNum == 0) { + var bitmapDrawable = backDrawables[0] + if (bitmapDrawable == null) { + bitmapDrawable = BitmapDrawable( + null, radius.drawCircle(Color.argb(159, 100, 149, 237)) + ) + backDrawables[0] = bitmapDrawable + } + bitmapDrawable + } + if (clusterNum == 1) { + var bitmapDrawable = backDrawables[1] + if (bitmapDrawable == null) { + bitmapDrawable = R.mipmap.well_location.convertDrawable(requireContext())!! + backDrawables[1] = bitmapDrawable + } + bitmapDrawable + } else if (clusterNum < 5) { + var bitmapDrawable = backDrawables[2] + if (bitmapDrawable == null) { + bitmapDrawable = BitmapDrawable( + null, radius.drawCircle(Color.argb(159, 100, 149, 237)) + ) + backDrawables[2] = bitmapDrawable + } + bitmapDrawable + } else if (clusterNum < 10) { + var bitmapDrawable = backDrawables[3] + if (bitmapDrawable == null) { + bitmapDrawable = BitmapDrawable( + null, radius.drawCircle(Color.argb(199, 30, 144, 255)) + ) + backDrawables[3] = bitmapDrawable + } + bitmapDrawable + } else { + var bitmapDrawable = backDrawables[4] + if (bitmapDrawable == null) { + bitmapDrawable = BitmapDrawable( + null, radius.drawCircle(Color.argb(235, 65, 105, 225)) + ) + backDrawables[4] = bitmapDrawable + } + bitmapDrawable + } + } + + clusterOverlay?.setOnClusterClickListener(object : ClusterOnClickListener { + override fun onMarkerClicked(marker: Marker?, items: List) { + if (items.size > 1) { + "请缩放地图比例在查看数据".show(requireContext()) + return + } + + var item: RegionItem? = null + val builder = LatLngBounds.Builder() + for (clusterItem in items) { + builder.include(clusterItem.position) + item = clusterItem as RegionItem + } + + item?.apply { + showWellPopup(well) + } + } + }) + } + + private fun showWellPopup(well: MapWellListModel.DataModel) { + infoPopup.set(well, object : MapWellPopup.OnPopupWindowClickListener { + override fun onPopupClicked(lat: Double, lng: Double) { + AlertControlDialog.Builder().setContext(requireContext()).setTitle("操作提示") + .setMessage("确定要前往吗").setNegativeButton("取消").setPositiveButton("确定") + .setOnDialogButtonClickListener(object : + AlertControlDialog.OnDialogButtonClickListener { + override fun onConfirmClick() { + RouteOnMap.startNavigation( + requireContext(), "", LatLng(lat, lng) + ) + } + + override fun onCancelClick() { + + } + }).build().show() + } + }) + infoPopup.showAsDropDown(binding.rightOptionView) } override fun onCameraChange(p0: CameraPosition?) { @@ -282,103 +368,10 @@ } } - //获取视野内的marker 根据聚合算法合成自定义的marker 显示视野内的marker override fun onCameraChangeFinish(p0: CameraPosition?) { //地图缩放之后显示聚合点数据 LoadingDialogHub.dismiss() httpCountDownTimer.cancel() - initClustersMarkers() - } - - private fun initClustersMarkers() { - 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 { - v = LayoutInflater.from(requireContext()).inflate(R.layout.popup_map_info, null) - - //显示闸井信息 - marker?.showInfoWindow() - return true - } - - override fun getInfoWindow(marker: Marker?): View { - //反射得到popup里面的控件对象 - val wellNameView = v.findViewById(R.id.wellNameView) - val wellCodeView = v.findViewById(R.id.wellCodeView) - val wellTypeView = v.findViewById(R.id.wellTypeView) - val wellStateView = v.findViewById(R.id.wellStateView) - val deepView = v.findViewById(R.id.deepView) - val locationView = v.findViewById(R.id.locationView) - - //绑定数据 - val clickedLatLng = marker?.position!! - wellModels.forEach { well -> - if (clickedLatLng.latitude == well.latGaode!!.toDouble() - && clickedLatLng.longitude == well.lngGaode!!.toDouble() - ) { - wellNameView.text = String.format("点位名称: ${well.wellName}") - wellCodeView.text = String.format("点位编号: ${well.wellCode}") - wellTypeView.text = String.format("点位类型: ${well.wellType.valueToType()}") - val bfztName = if (well.bfzt == "1") { - "已布防" - } else { - "已撤防" - } - wellStateView.text = String.format("布/撤防状态: $bfztName") - deepView.text = String.format("点位深度: ${well.deep}m") - locationView.text = String.format("详细位置: ${well.position}") - } - } - return v - } - - /** - * 此方法不能修改整个 InfoWindow 的背景和边框,无论自定义的样式是什么样,SDK 都会在最外层添加一个默认的边框 - * */ - override fun getInfoContents(p0: Marker?): View? = null - - override fun onInfoWindowClick(p0: Marker?) { - p0?.apply { - AlertControlDialog.Builder() - .setContext(requireContext()) - .setTitle("操作提示") - .setMessage("确定要前往吗") - .setNegativeButton("取消") - .setPositiveButton("确定") - .setOnDialogButtonClickListener(object : - AlertControlDialog.OnDialogButtonClickListener { - override fun onConfirmClick() { - val lat = position.latitude.toString() - val lng = position.longitude.toString() - if (lat.isBlank() || lng.isBlank()) { - "点位经纬度异常,无法开启导航".show(requireContext()) - return - } - RouteOnMap.startNavigation( - requireContext(), snippet, LatLng(lat.toDouble(), lng.toDouble()) - ) - } - - override fun onCancelClick() { - - } - }).build().show() - } } /***以下是地图生命周期管理************************************************************************/ 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 a54d213..bfa7a57 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 @@ -44,8 +44,8 @@ * 地图点位不带聚合效果 * */ class HomePageNoClusterFragment : KotlinBaseFragment(), - AMap.OnMapLoadedListener, AMap.OnCameraChangeListener, AMap.OnMarkerClickListener, - AMap.InfoWindowAdapter, AMap.OnInfoWindowClickListener { + AMap.OnCameraChangeListener, AMap.OnMarkerClickListener, AMap.InfoWindowAdapter, + AMap.OnInfoWindowClickListener { private val kTag = "NoClusterFragment" private val easyPopupWindow by lazy { EasyPopupWindow(requireContext()) } @@ -109,6 +109,9 @@ wellViewModel = ViewModelProvider(this)[WellViewModel::class.java] orderViewModel = ViewModelProvider(this)[OrderViewModel::class.java] + //地图初始化 + initMap(savedInstanceState) + //获取所有窨井数据 httpCountDownTimer.start() LoadingDialogHub.show(requireActivity(), "数据加载中,请稍后...") @@ -157,12 +160,12 @@ val cameraPosition = CameraPosition(centerLatLng, 16f, 0f, 0f) val cameraUpdate = CameraUpdateFactory.newCameraPosition(cameraPosition) aMap.animateCamera(cameraUpdate, 1500, null) + + //显示点数据 + displayWellOnMap() } } - //地图初始化 - initMap(savedInstanceState) - //获取窨井监控数据 wellViewModel.countResultModel.observe(this) { binding.deployedWellView.text = it["bfWell"] @@ -214,9 +217,8 @@ uiSettings.isCompassEnabled = true uiSettings.zoomPosition = AMapOptions.ZOOM_POSITION_RIGHT_CENTER uiSettings.isTiltGesturesEnabled = false//不许地图随手势倾斜角度 + uiSettings.isRotateGesturesEnabled = false//不允许地图随手势改变方位 - // 地图加载成功监听 - aMap.addOnMapLoadedListener(this) // 地图缩放监听 aMap.addOnCameraChangeListener(this) // marker 点击事件监听 @@ -253,11 +255,6 @@ } - override fun onMapLoaded() { - //地图加载成功之后显示聚合点数据 - initClustersMarkers() - } - override fun onCameraChange(p0: CameraPosition?) { } @@ -281,10 +278,9 @@ //地图缩放之后显示聚合点数据 LoadingDialogHub.dismiss() httpCountDownTimer.cancel() - initClustersMarkers() } - private fun initClustersMarkers() { + private fun displayWellOnMap() { val proj = aMap.projection val dm = resources.displayMetrics var screenLocation: Point diff --git a/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.java b/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.java deleted file mode 100644 index d8b18ef..0000000 --- a/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.java +++ /dev/null @@ -1,50 +0,0 @@ -package com.casic.app.smartwell.model; - -public class ErrorMessageModel { - - private int code; - private String data; - private String exceptionClazz; - private String message; - private boolean success; - - public int getCode() { - return code; - } - - public void setCode(int code) { - this.code = code; - } - - public String getData() { - return data; - } - - public void setData(String data) { - this.data = data; - } - - public String getExceptionClazz() { - return exceptionClazz; - } - - public void setExceptionClazz(String exceptionClazz) { - this.exceptionClazz = exceptionClazz; - } - - public String getMessage() { - return message; - } - - public void setMessage(String message) { - this.message = message; - } - - public boolean isSuccess() { - return success; - } - - public void setSuccess(boolean success) { - this.success = success; - } -} \ No newline at end of file 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 new file mode 100644 index 0000000..215ac0c --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/PipelineModel.java @@ -0,0 +1,328 @@ +package com.casic.app.smartwell.model; + +import java.util.List; + +public class PipelineModel { + + private Integer code; + private DataModel data; + private String message; + private Boolean success; + + public Integer getCode() { + return code; + } + + public void setCode(Integer code) { + this.code = code; + } + + public DataModel getData() { + return data; + } + + public void setData(DataModel data) { + this.data = data; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + public Boolean getSuccess() { + return success; + } + + public void setSuccess(Boolean success) { + this.success = success; + } + + public static class DataModel { + private List rows; + private Integer total; + + public List getRows() { + return rows; + } + + public void setRows(List rows) { + this.rows = rows; + } + + public Integer getTotal() { + return total; + } + + public void setTotal(Integer total) { + this.total = total; + } + + 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 getBuryMode() { + return buryMode; + } + + public void setBuryMode(String buryMode) { + this.buryMode = buryMode; + } + + public String getConstructEra() { + return constructEra; + } + + public void setConstructEra(String constructEra) { + this.constructEra = constructEra; + } + + 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; + } + } + } +} 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 06d3d2b..4f38a2c 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 = 100 //相距多少米才聚合,单位:米 + const val RADIUS_SIZE = 80 //相距多少米才聚合,单位:米 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:11308" + // 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 0d5f3fa..991e1db 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 @@ -312,4 +312,14 @@ @Header("token") token: String, @Field("clientid") deviceCode: String ): String + + /** + * 管线位置数据 + */ + @GET("/pipeline/listPage") + suspend fun getPipeline( + @Header("token") token: String, + @Query("limit") limit: Int, + @Query("offset") offset: Int + ): String } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt index 1a0ce22..4050067 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt @@ -294,4 +294,11 @@ suspend fun registerPush(clientId: String): String { return api.registerPush(AuthenticationHelper.token!!, clientId) } + + /** + * 管线位置数据 + */ + suspend fun getPipeline(): String { + return api.getPipeline(AuthenticationHelper.token!!, 2000, 1) + } } \ No newline at end of file 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 9270fa1..4ca5a5e 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.HomePageNoClusterFragment +import com.casic.app.smartwell.fragment.HomePageHaveClusterFragment 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/vm/AlarmViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/AlarmViewModel.kt index 9cff08c..e7acc17 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/AlarmViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/AlarmViewModel.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.AlarmContentModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager import com.google.gson.Gson @@ -16,7 +16,7 @@ fun getAlarmContentType(alarmType: String) = launch({ val response = RetrofitServiceManager.getAlarmContentType(alarmType) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { listModel.value = gson.fromJson( response, object : TypeToken() {}.type diff --git a/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt index 5e5b163..895dedd 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.PublicKeyModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager import com.google.gson.Gson @@ -18,7 +18,7 @@ fun getPublicKey() = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.authenticate() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { keyModel.value = gson.fromJson( response, object : TypeToken() {}.type diff --git a/app/src/main/java/com/casic/app/smartwell/vm/DeviceViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/DeviceViewModel.kt index db5ccf6..899a962 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/DeviceViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/DeviceViewModel.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.DeviceDetailModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager import com.google.gson.Gson @@ -16,7 +16,7 @@ fun getDeviceDetail(deviceCode: String) = launch({ val response = RetrofitServiceManager.getDeviceDetail(deviceCode) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { detailModel.value = gson.fromJson( response, object : TypeToken() {}.type diff --git a/app/src/main/java/com/casic/app/smartwell/vm/LoginViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/LoginViewModel.kt index cd8b8a9..a417398 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/LoginViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/LoginViewModel.kt @@ -2,7 +2,7 @@ import androidx.lifecycle.MutableLiveData import com.casic.app.smartwell.base.BaseApplication -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.CommonResultModel import com.casic.app.smartwell.model.LoginResultModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -21,7 +21,7 @@ fun enter(account: String, secretKey: String) = launch({ val response = RetrofitServiceManager.login(account, secretKey) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success enterResultModel.value = gson.fromJson( @@ -38,7 +38,7 @@ fun out() = launch({ val response = RetrofitServiceManager.loginOut() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { outResultModel.value = gson.fromJson( response, object : TypeToken() {}.type diff --git a/app/src/main/java/com/casic/app/smartwell/vm/OperationViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/OperationViewModel.kt index 8943ed3..37e115f 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/OperationViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/OperationViewModel.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.vm import com.casic.app.smartwell.base.BaseApplication -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager import com.pengxh.kt.lite.base.BaseViewModel import com.pengxh.kt.lite.extensions.launch @@ -16,7 +16,7 @@ fun acceptWorkOrder(id: String) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.acceptWorkOrder(id) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success "接单成功".show(BaseApplication.get()) @@ -35,7 +35,7 @@ loadState.value = LoadState.Loading val response = RetrofitServiceManager.confirmWorkOrder(id, firstState, firstStatePhotos, needHandle) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success "工单确认成功".show(BaseApplication.get()) @@ -50,7 +50,7 @@ fun transferWorkOrder(id: String, userId: String) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.transferWorkOrder(id, userId) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success "转单成功".show(BaseApplication.get()) @@ -65,7 +65,7 @@ fun completeWorkOrder(id: String, handleMessage: String, handlePhotos: String) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.completeWorkOrder(id, handleMessage, handlePhotos) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success "工单处理成功".show(BaseApplication.get()) diff --git a/app/src/main/java/com/casic/app/smartwell/extensions/Int.kt b/app/src/main/java/com/casic/app/smartwell/extensions/Int.kt index de0617b..a0a5e33 100644 --- a/app/src/main/java/com/casic/app/smartwell/extensions/Int.kt +++ b/app/src/main/java/com/casic/app/smartwell/extensions/Int.kt @@ -1,9 +1,24 @@ package com.casic.app.smartwell.extensions +import android.graphics.Bitmap +import android.graphics.Canvas +import android.graphics.Paint +import android.graphics.RectF + fun Int.toLevel(): String { return if (this == 0) { "" } else { this.toString() } +} + +fun Int.drawCircle(color: Int): Bitmap? { + val bitmap = Bitmap.createBitmap(this * 2, this * 2, Bitmap.Config.ARGB_8888) + val canvas = Canvas(bitmap) + val paint = Paint() + val rectF = RectF(0f, 0f, (this * 2).toFloat(), (this * 2).toFloat()) + paint.color = color + canvas.drawArc(rectF, 0f, 360f, true, paint) + return bitmap } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt index 6b6ca3e..5e45534 100644 --- a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt +++ b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt @@ -2,17 +2,13 @@ import android.content.Context import com.casic.app.smartwell.callback.OnImageCompressListener -import com.casic.app.smartwell.model.ErrorMessageModel import com.casic.app.smartwell.utils.LocaleConstant -import com.google.gson.Gson -import com.google.gson.reflect.TypeToken +import com.google.gson.JsonParser import com.pengxh.kt.lite.extensions.createCompressImageDir import com.pengxh.kt.lite.utils.SaveKeyValues -import org.json.JSONObject import top.zibin.luban.Luban import top.zibin.luban.OnCompressListener import java.io.File -import java.util.Locale /** * String扩展方法 @@ -74,18 +70,22 @@ } } -fun String.separateResponseCode(): Int { +fun String.getResponseCode(): Int { if (this.isBlank()) { return 404 } - return JSONObject(this).getInt("code") + val element = JsonParser.parseString(this) + val jsonObject = element.asJsonObject + return jsonObject.get("code").asInt } -fun String.toErrorMessage(): String { - val errorModel = Gson().fromJson( - this, object : TypeToken() {}.type - ) - return errorModel.message.toString() +fun String.getResponseMessage(): String { + if (this.isBlank()) { + return "" + } + val element = JsonParser.parseString(this) + val jsonObject = element.asJsonObject + return jsonObject.get("message").asString } fun String.compressImage(context: Context, listener: OnImageCompressListener) { @@ -93,9 +93,6 @@ .load(this) .ignoreBy(100) .setTargetDir(context.createCompressImageDir().toString()) - .filter { - !(it.isBlank() || it.lowercase(Locale.getDefault()).endsWith(".gif")) - } .setCompressListener(object : OnCompressListener { override fun onStart() { 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 96df110..cd25fca 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 @@ -1,26 +1,25 @@ package com.casic.app.smartwell.fragment -import android.graphics.Point +import android.graphics.Color +import android.graphics.drawable.BitmapDrawable +import android.graphics.drawable.Drawable 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 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.LatLngBounds import com.amap.api.maps.model.Marker -import com.amap.api.maps.model.MarkerOptions import com.casic.app.smartwell.R import com.casic.app.smartwell.databinding.FragmentHomeBinding +import com.casic.app.smartwell.extensions.drawCircle import com.casic.app.smartwell.extensions.initImmersionBar -import com.casic.app.smartwell.extensions.valueToType import com.casic.app.smartwell.model.MapWellListModel import com.casic.app.smartwell.utils.LocaleConstant import com.casic.app.smartwell.utils.RouteOnMap @@ -31,9 +30,16 @@ import com.casic.app.smartwell.view.WellOperationActivity import com.casic.app.smartwell.vm.OrderViewModel import com.casic.app.smartwell.vm.WellViewModel +import com.casic.app.smartwell.widgets.MapWellPopup +import com.casic.app.smartwell.widgets.cluster.ClusterItem +import com.casic.app.smartwell.widgets.cluster.ClusterOnClickListener +import com.casic.app.smartwell.widgets.cluster.ClusterOverlay +import com.casic.app.smartwell.widgets.cluster.RegionItem 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.convertDrawable +import com.pengxh.kt.lite.extensions.dp2px import com.pengxh.kt.lite.extensions.navigatePageTo import com.pengxh.kt.lite.extensions.show import com.pengxh.kt.lite.utils.LoadingDialogHub @@ -43,35 +49,23 @@ /** * 地图点位带聚合效果 * */ -class HomePageHaveClusterFragment : KotlinBaseFragment(), AMap.OnMapLoadedListener, - AMap.OnCameraChangeListener, AMap.OnMarkerClickListener, AMap.InfoWindowAdapter, - AMap.OnInfoWindowClickListener { +class HomePageHaveClusterFragment : KotlinBaseFragment(), + AMap.OnCameraChangeListener { private val kTag = "HaveClusterFragment" private val easyPopupWindow by lazy { EasyPopupWindow(requireContext()) } - private lateinit var wellViewModel: WellViewModel - private lateinit var orderViewModel: OrderViewModel - private lateinit var aMap: AMap - - /** - * 所有的marker - */ - private var allMarkerOptions: MutableList = ArrayList() - - /** - * 视野内的marker - */ - private var markerOptionsInView: MutableList = ArrayList() - - /** - * 自定义Marker弹出框 - * */ - private lateinit var v: View + private val regionRadius by lazy { LocaleConstant.RADIUS_SIZE.dp2px(requireContext()) } + private val infoPopup by lazy { MapWellPopup(requireContext()) } /** * 所有窨井列表信息集合 * */ - private var wellModels: MutableList = ArrayList() + private val wellModels = ArrayList() + private val backDrawables = HashMap() + private lateinit var wellViewModel: WellViewModel + private lateinit var orderViewModel: OrderViewModel + private lateinit var aMap: AMap + private var clusterOverlay: ClusterOverlay? = null override fun initViewBinding( inflater: LayoutInflater, @@ -106,6 +100,9 @@ } }) + //地图初始化 + initMap(savedInstanceState) + //初始化vm wellViewModel = ViewModelProvider(this)[WellViewModel::class.java] orderViewModel = ViewModelProvider(this)[OrderViewModel::class.java] @@ -120,25 +117,19 @@ val latitudeList: MutableList = ArrayList() val longitudeList: MutableList = ArrayList() it.data?.forEach { well -> - val lat = well.latGaode.toString() - val lng = well.lngGaode.toString() + val lat = well.latGaode + val lng = well.lngGaode if (lat.isNotBlank() && lng.isNotBlank()) { //返回true代表当前位置在大陆、港澳地区,反之不在 val latitude = lat.toDouble() val longitude = lng.toDouble() if (CoordinateConverter.isAMapDataAvailable(latitude, longitude)) { - //缓存所有设备详情,点击Marker时候需要 + //缓存所有井 wellModels.add(well) + //分别缓存经、纬度 latitudeList.add(latitude) longitudeList.add(longitude) - //将所有设备信息转化缓存为Marker点 - allMarkerOptions.add( - MarkerOptions() - .position(LatLng(latitude, longitude)) - .title(well.wellTypeName) - .snippet(well.wellName) - ) } } } @@ -160,12 +151,12 @@ val cameraPosition = CameraPosition(centerLatLng, 16f, 0f, 0f) val cameraUpdate = CameraUpdateFactory.newCameraPosition(cameraPosition) aMap.animateCamera(cameraUpdate, 1500, null) + + //显示点数据 + displayWellOnMap() } } - //地图初始化 - initMap(savedInstanceState) - //获取窨井监控数据 wellViewModel.countResultModel.observe(this) { binding.deployedWellView.text = it["bfWell"] @@ -220,17 +211,10 @@ uiSettings.isCompassEnabled = true uiSettings.zoomPosition = AMapOptions.ZOOM_POSITION_RIGHT_CENTER uiSettings.isTiltGesturesEnabled = false//不许地图随手势倾斜角度 + uiSettings.isRotateGesturesEnabled = false//不允许地图随手势改变方位 - // 地图加载成功监听 - aMap.addOnMapLoadedListener(this) // 地图缩放监听 aMap.addOnCameraChangeListener(this) - // marker 点击事件监听 - aMap.addOnMarkerClickListener(this) - // 点击marker弹出自定义popup - aMap.setInfoWindowAdapter(this) - //信息窗点击事件 - aMap.addOnInfoWindowClickListener(this) } override fun initEvent() { @@ -259,9 +243,111 @@ } - override fun onMapLoaded() { - //地图加载成功之后显示聚合点数据 - initClustersMarkers() + private fun displayWellOnMap() { + clusterOverlay?.onDestroy() + val clusterItems = ArrayList() + + wellModels.forEach { + val latitude = it.latGaode.toDouble() + val longitude = it.lngGaode.toDouble() + + val latLng = LatLng(latitude, longitude, false) + val regionItem = RegionItem(latLng, it) + clusterItems.add(regionItem) + } + + clusterOverlay = ClusterOverlay(requireContext(), aMap, clusterItems, regionRadius) + clusterOverlay?.setClusterRender { clusterNum -> + //聚合圆半径 + val radius = 100.dp2px(requireContext()) + if (clusterNum == 0) { + var bitmapDrawable = backDrawables[0] + if (bitmapDrawable == null) { + bitmapDrawable = BitmapDrawable( + null, radius.drawCircle(Color.argb(159, 100, 149, 237)) + ) + backDrawables[0] = bitmapDrawable + } + bitmapDrawable + } + if (clusterNum == 1) { + var bitmapDrawable = backDrawables[1] + if (bitmapDrawable == null) { + bitmapDrawable = R.mipmap.well_location.convertDrawable(requireContext())!! + backDrawables[1] = bitmapDrawable + } + bitmapDrawable + } else if (clusterNum < 5) { + var bitmapDrawable = backDrawables[2] + if (bitmapDrawable == null) { + bitmapDrawable = BitmapDrawable( + null, radius.drawCircle(Color.argb(159, 100, 149, 237)) + ) + backDrawables[2] = bitmapDrawable + } + bitmapDrawable + } else if (clusterNum < 10) { + var bitmapDrawable = backDrawables[3] + if (bitmapDrawable == null) { + bitmapDrawable = BitmapDrawable( + null, radius.drawCircle(Color.argb(199, 30, 144, 255)) + ) + backDrawables[3] = bitmapDrawable + } + bitmapDrawable + } else { + var bitmapDrawable = backDrawables[4] + if (bitmapDrawable == null) { + bitmapDrawable = BitmapDrawable( + null, radius.drawCircle(Color.argb(235, 65, 105, 225)) + ) + backDrawables[4] = bitmapDrawable + } + bitmapDrawable + } + } + + clusterOverlay?.setOnClusterClickListener(object : ClusterOnClickListener { + override fun onMarkerClicked(marker: Marker?, items: List) { + if (items.size > 1) { + "请缩放地图比例在查看数据".show(requireContext()) + return + } + + var item: RegionItem? = null + val builder = LatLngBounds.Builder() + for (clusterItem in items) { + builder.include(clusterItem.position) + item = clusterItem as RegionItem + } + + item?.apply { + showWellPopup(well) + } + } + }) + } + + private fun showWellPopup(well: MapWellListModel.DataModel) { + infoPopup.set(well, object : MapWellPopup.OnPopupWindowClickListener { + override fun onPopupClicked(lat: Double, lng: Double) { + AlertControlDialog.Builder().setContext(requireContext()).setTitle("操作提示") + .setMessage("确定要前往吗").setNegativeButton("取消").setPositiveButton("确定") + .setOnDialogButtonClickListener(object : + AlertControlDialog.OnDialogButtonClickListener { + override fun onConfirmClick() { + RouteOnMap.startNavigation( + requireContext(), "", LatLng(lat, lng) + ) + } + + override fun onCancelClick() { + + } + }).build().show() + } + }) + infoPopup.showAsDropDown(binding.rightOptionView) } override fun onCameraChange(p0: CameraPosition?) { @@ -282,103 +368,10 @@ } } - //获取视野内的marker 根据聚合算法合成自定义的marker 显示视野内的marker override fun onCameraChangeFinish(p0: CameraPosition?) { //地图缩放之后显示聚合点数据 LoadingDialogHub.dismiss() httpCountDownTimer.cancel() - initClustersMarkers() - } - - private fun initClustersMarkers() { - 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 { - v = LayoutInflater.from(requireContext()).inflate(R.layout.popup_map_info, null) - - //显示闸井信息 - marker?.showInfoWindow() - return true - } - - override fun getInfoWindow(marker: Marker?): View { - //反射得到popup里面的控件对象 - val wellNameView = v.findViewById(R.id.wellNameView) - val wellCodeView = v.findViewById(R.id.wellCodeView) - val wellTypeView = v.findViewById(R.id.wellTypeView) - val wellStateView = v.findViewById(R.id.wellStateView) - val deepView = v.findViewById(R.id.deepView) - val locationView = v.findViewById(R.id.locationView) - - //绑定数据 - val clickedLatLng = marker?.position!! - wellModels.forEach { well -> - if (clickedLatLng.latitude == well.latGaode!!.toDouble() - && clickedLatLng.longitude == well.lngGaode!!.toDouble() - ) { - wellNameView.text = String.format("点位名称: ${well.wellName}") - wellCodeView.text = String.format("点位编号: ${well.wellCode}") - wellTypeView.text = String.format("点位类型: ${well.wellType.valueToType()}") - val bfztName = if (well.bfzt == "1") { - "已布防" - } else { - "已撤防" - } - wellStateView.text = String.format("布/撤防状态: $bfztName") - deepView.text = String.format("点位深度: ${well.deep}m") - locationView.text = String.format("详细位置: ${well.position}") - } - } - return v - } - - /** - * 此方法不能修改整个 InfoWindow 的背景和边框,无论自定义的样式是什么样,SDK 都会在最外层添加一个默认的边框 - * */ - override fun getInfoContents(p0: Marker?): View? = null - - override fun onInfoWindowClick(p0: Marker?) { - p0?.apply { - AlertControlDialog.Builder() - .setContext(requireContext()) - .setTitle("操作提示") - .setMessage("确定要前往吗") - .setNegativeButton("取消") - .setPositiveButton("确定") - .setOnDialogButtonClickListener(object : - AlertControlDialog.OnDialogButtonClickListener { - override fun onConfirmClick() { - val lat = position.latitude.toString() - val lng = position.longitude.toString() - if (lat.isBlank() || lng.isBlank()) { - "点位经纬度异常,无法开启导航".show(requireContext()) - return - } - RouteOnMap.startNavigation( - requireContext(), snippet, LatLng(lat.toDouble(), lng.toDouble()) - ) - } - - override fun onCancelClick() { - - } - }).build().show() - } } /***以下是地图生命周期管理************************************************************************/ 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 a54d213..bfa7a57 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 @@ -44,8 +44,8 @@ * 地图点位不带聚合效果 * */ class HomePageNoClusterFragment : KotlinBaseFragment(), - AMap.OnMapLoadedListener, AMap.OnCameraChangeListener, AMap.OnMarkerClickListener, - AMap.InfoWindowAdapter, AMap.OnInfoWindowClickListener { + AMap.OnCameraChangeListener, AMap.OnMarkerClickListener, AMap.InfoWindowAdapter, + AMap.OnInfoWindowClickListener { private val kTag = "NoClusterFragment" private val easyPopupWindow by lazy { EasyPopupWindow(requireContext()) } @@ -109,6 +109,9 @@ wellViewModel = ViewModelProvider(this)[WellViewModel::class.java] orderViewModel = ViewModelProvider(this)[OrderViewModel::class.java] + //地图初始化 + initMap(savedInstanceState) + //获取所有窨井数据 httpCountDownTimer.start() LoadingDialogHub.show(requireActivity(), "数据加载中,请稍后...") @@ -157,12 +160,12 @@ val cameraPosition = CameraPosition(centerLatLng, 16f, 0f, 0f) val cameraUpdate = CameraUpdateFactory.newCameraPosition(cameraPosition) aMap.animateCamera(cameraUpdate, 1500, null) + + //显示点数据 + displayWellOnMap() } } - //地图初始化 - initMap(savedInstanceState) - //获取窨井监控数据 wellViewModel.countResultModel.observe(this) { binding.deployedWellView.text = it["bfWell"] @@ -214,9 +217,8 @@ uiSettings.isCompassEnabled = true uiSettings.zoomPosition = AMapOptions.ZOOM_POSITION_RIGHT_CENTER uiSettings.isTiltGesturesEnabled = false//不许地图随手势倾斜角度 + uiSettings.isRotateGesturesEnabled = false//不允许地图随手势改变方位 - // 地图加载成功监听 - aMap.addOnMapLoadedListener(this) // 地图缩放监听 aMap.addOnCameraChangeListener(this) // marker 点击事件监听 @@ -253,11 +255,6 @@ } - override fun onMapLoaded() { - //地图加载成功之后显示聚合点数据 - initClustersMarkers() - } - override fun onCameraChange(p0: CameraPosition?) { } @@ -281,10 +278,9 @@ //地图缩放之后显示聚合点数据 LoadingDialogHub.dismiss() httpCountDownTimer.cancel() - initClustersMarkers() } - private fun initClustersMarkers() { + private fun displayWellOnMap() { val proj = aMap.projection val dm = resources.displayMetrics var screenLocation: Point diff --git a/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.java b/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.java deleted file mode 100644 index d8b18ef..0000000 --- a/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.java +++ /dev/null @@ -1,50 +0,0 @@ -package com.casic.app.smartwell.model; - -public class ErrorMessageModel { - - private int code; - private String data; - private String exceptionClazz; - private String message; - private boolean success; - - public int getCode() { - return code; - } - - public void setCode(int code) { - this.code = code; - } - - public String getData() { - return data; - } - - public void setData(String data) { - this.data = data; - } - - public String getExceptionClazz() { - return exceptionClazz; - } - - public void setExceptionClazz(String exceptionClazz) { - this.exceptionClazz = exceptionClazz; - } - - public String getMessage() { - return message; - } - - public void setMessage(String message) { - this.message = message; - } - - public boolean isSuccess() { - return success; - } - - public void setSuccess(boolean success) { - this.success = success; - } -} \ No newline at end of file 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 new file mode 100644 index 0000000..215ac0c --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/PipelineModel.java @@ -0,0 +1,328 @@ +package com.casic.app.smartwell.model; + +import java.util.List; + +public class PipelineModel { + + private Integer code; + private DataModel data; + private String message; + private Boolean success; + + public Integer getCode() { + return code; + } + + public void setCode(Integer code) { + this.code = code; + } + + public DataModel getData() { + return data; + } + + public void setData(DataModel data) { + this.data = data; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + public Boolean getSuccess() { + return success; + } + + public void setSuccess(Boolean success) { + this.success = success; + } + + public static class DataModel { + private List rows; + private Integer total; + + public List getRows() { + return rows; + } + + public void setRows(List rows) { + this.rows = rows; + } + + public Integer getTotal() { + return total; + } + + public void setTotal(Integer total) { + this.total = total; + } + + 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 getBuryMode() { + return buryMode; + } + + public void setBuryMode(String buryMode) { + this.buryMode = buryMode; + } + + public String getConstructEra() { + return constructEra; + } + + public void setConstructEra(String constructEra) { + this.constructEra = constructEra; + } + + 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; + } + } + } +} 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 06d3d2b..4f38a2c 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 = 100 //相距多少米才聚合,单位:米 + const val RADIUS_SIZE = 80 //相距多少米才聚合,单位:米 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:11308" + // 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 0d5f3fa..991e1db 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 @@ -312,4 +312,14 @@ @Header("token") token: String, @Field("clientid") deviceCode: String ): String + + /** + * 管线位置数据 + */ + @GET("/pipeline/listPage") + suspend fun getPipeline( + @Header("token") token: String, + @Query("limit") limit: Int, + @Query("offset") offset: Int + ): String } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt index 1a0ce22..4050067 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt @@ -294,4 +294,11 @@ suspend fun registerPush(clientId: String): String { return api.registerPush(AuthenticationHelper.token!!, clientId) } + + /** + * 管线位置数据 + */ + suspend fun getPipeline(): String { + return api.getPipeline(AuthenticationHelper.token!!, 2000, 1) + } } \ No newline at end of file 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 9270fa1..4ca5a5e 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.HomePageNoClusterFragment +import com.casic.app.smartwell.fragment.HomePageHaveClusterFragment 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/vm/AlarmViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/AlarmViewModel.kt index 9cff08c..e7acc17 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/AlarmViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/AlarmViewModel.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.AlarmContentModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager import com.google.gson.Gson @@ -16,7 +16,7 @@ fun getAlarmContentType(alarmType: String) = launch({ val response = RetrofitServiceManager.getAlarmContentType(alarmType) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { listModel.value = gson.fromJson( response, object : TypeToken() {}.type diff --git a/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt index 5e5b163..895dedd 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.PublicKeyModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager import com.google.gson.Gson @@ -18,7 +18,7 @@ fun getPublicKey() = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.authenticate() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { keyModel.value = gson.fromJson( response, object : TypeToken() {}.type diff --git a/app/src/main/java/com/casic/app/smartwell/vm/DeviceViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/DeviceViewModel.kt index db5ccf6..899a962 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/DeviceViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/DeviceViewModel.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.DeviceDetailModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager import com.google.gson.Gson @@ -16,7 +16,7 @@ fun getDeviceDetail(deviceCode: String) = launch({ val response = RetrofitServiceManager.getDeviceDetail(deviceCode) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { detailModel.value = gson.fromJson( response, object : TypeToken() {}.type diff --git a/app/src/main/java/com/casic/app/smartwell/vm/LoginViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/LoginViewModel.kt index cd8b8a9..a417398 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/LoginViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/LoginViewModel.kt @@ -2,7 +2,7 @@ import androidx.lifecycle.MutableLiveData import com.casic.app.smartwell.base.BaseApplication -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.CommonResultModel import com.casic.app.smartwell.model.LoginResultModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -21,7 +21,7 @@ fun enter(account: String, secretKey: String) = launch({ val response = RetrofitServiceManager.login(account, secretKey) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success enterResultModel.value = gson.fromJson( @@ -38,7 +38,7 @@ fun out() = launch({ val response = RetrofitServiceManager.loginOut() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { outResultModel.value = gson.fromJson( response, object : TypeToken() {}.type diff --git a/app/src/main/java/com/casic/app/smartwell/vm/OperationViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/OperationViewModel.kt index 8943ed3..37e115f 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/OperationViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/OperationViewModel.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.vm import com.casic.app.smartwell.base.BaseApplication -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager import com.pengxh.kt.lite.base.BaseViewModel import com.pengxh.kt.lite.extensions.launch @@ -16,7 +16,7 @@ fun acceptWorkOrder(id: String) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.acceptWorkOrder(id) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success "接单成功".show(BaseApplication.get()) @@ -35,7 +35,7 @@ loadState.value = LoadState.Loading val response = RetrofitServiceManager.confirmWorkOrder(id, firstState, firstStatePhotos, needHandle) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success "工单确认成功".show(BaseApplication.get()) @@ -50,7 +50,7 @@ fun transferWorkOrder(id: String, userId: String) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.transferWorkOrder(id, userId) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success "转单成功".show(BaseApplication.get()) @@ -65,7 +65,7 @@ fun completeWorkOrder(id: String, handleMessage: String, handlePhotos: String) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.completeWorkOrder(id, handleMessage, handlePhotos) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success "工单处理成功".show(BaseApplication.get()) diff --git a/app/src/main/java/com/casic/app/smartwell/vm/OrderViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/OrderViewModel.kt index 4cb26b7..d2fad86 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/OrderViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/OrderViewModel.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.OrderDetailModel import com.casic.app.smartwell.model.OrderListModel import com.casic.app.smartwell.model.OrderStatusModel @@ -37,7 +37,7 @@ val response = RetrofitServiceManager.getSearchResult( keywords, alarmContent, alarmLevel, jobStatus, deptId, beginTime, endTime, offset ) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success searchResult.value = gson.fromJson( @@ -53,7 +53,7 @@ fun getWorkOrderListByState(jobStatus: String, page: Int) = launch({ val response = RetrofitServiceManager.getWorkOrderList(jobStatus, page) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { orderList.value = gson.fromJson( response, object : TypeToken() {}.type @@ -65,7 +65,7 @@ fun getNotAcceptOderList(page: Int) = launch({ val response = RetrofitServiceManager.getNotAcceptOderList(page) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { orderList.value = gson.fromJson( response, object : TypeToken() {}.type @@ -77,7 +77,7 @@ fun getNotHandleOderList(page: Int) = launch({ val response = RetrofitServiceManager.getNotHandleOderList(page) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { orderList.value = gson.fromJson( response, object : TypeToken() {}.type @@ -89,7 +89,7 @@ fun countWorkOrderByState() = launch({ val response = RetrofitServiceManager.countWorkOrderByState() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { val map = HashMap(4) @@ -107,7 +107,7 @@ fun getOrderStatus() = launch({ val response = RetrofitServiceManager.getOrderStatus() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { orderStatusModel.value = gson.fromJson( response, object : TypeToken() {}.type @@ -120,7 +120,7 @@ fun getWorkOrderDetail(id: String) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.getWorkOrderDetail(id) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success detailModel.value = gson.fromJson( diff --git a/app/src/main/java/com/casic/app/smartwell/extensions/Int.kt b/app/src/main/java/com/casic/app/smartwell/extensions/Int.kt index de0617b..a0a5e33 100644 --- a/app/src/main/java/com/casic/app/smartwell/extensions/Int.kt +++ b/app/src/main/java/com/casic/app/smartwell/extensions/Int.kt @@ -1,9 +1,24 @@ package com.casic.app.smartwell.extensions +import android.graphics.Bitmap +import android.graphics.Canvas +import android.graphics.Paint +import android.graphics.RectF + fun Int.toLevel(): String { return if (this == 0) { "" } else { this.toString() } +} + +fun Int.drawCircle(color: Int): Bitmap? { + val bitmap = Bitmap.createBitmap(this * 2, this * 2, Bitmap.Config.ARGB_8888) + val canvas = Canvas(bitmap) + val paint = Paint() + val rectF = RectF(0f, 0f, (this * 2).toFloat(), (this * 2).toFloat()) + paint.color = color + canvas.drawArc(rectF, 0f, 360f, true, paint) + return bitmap } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt index 6b6ca3e..5e45534 100644 --- a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt +++ b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt @@ -2,17 +2,13 @@ import android.content.Context import com.casic.app.smartwell.callback.OnImageCompressListener -import com.casic.app.smartwell.model.ErrorMessageModel import com.casic.app.smartwell.utils.LocaleConstant -import com.google.gson.Gson -import com.google.gson.reflect.TypeToken +import com.google.gson.JsonParser import com.pengxh.kt.lite.extensions.createCompressImageDir import com.pengxh.kt.lite.utils.SaveKeyValues -import org.json.JSONObject import top.zibin.luban.Luban import top.zibin.luban.OnCompressListener import java.io.File -import java.util.Locale /** * String扩展方法 @@ -74,18 +70,22 @@ } } -fun String.separateResponseCode(): Int { +fun String.getResponseCode(): Int { if (this.isBlank()) { return 404 } - return JSONObject(this).getInt("code") + val element = JsonParser.parseString(this) + val jsonObject = element.asJsonObject + return jsonObject.get("code").asInt } -fun String.toErrorMessage(): String { - val errorModel = Gson().fromJson( - this, object : TypeToken() {}.type - ) - return errorModel.message.toString() +fun String.getResponseMessage(): String { + if (this.isBlank()) { + return "" + } + val element = JsonParser.parseString(this) + val jsonObject = element.asJsonObject + return jsonObject.get("message").asString } fun String.compressImage(context: Context, listener: OnImageCompressListener) { @@ -93,9 +93,6 @@ .load(this) .ignoreBy(100) .setTargetDir(context.createCompressImageDir().toString()) - .filter { - !(it.isBlank() || it.lowercase(Locale.getDefault()).endsWith(".gif")) - } .setCompressListener(object : OnCompressListener { override fun onStart() { 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 96df110..cd25fca 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 @@ -1,26 +1,25 @@ package com.casic.app.smartwell.fragment -import android.graphics.Point +import android.graphics.Color +import android.graphics.drawable.BitmapDrawable +import android.graphics.drawable.Drawable 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 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.LatLngBounds import com.amap.api.maps.model.Marker -import com.amap.api.maps.model.MarkerOptions import com.casic.app.smartwell.R import com.casic.app.smartwell.databinding.FragmentHomeBinding +import com.casic.app.smartwell.extensions.drawCircle import com.casic.app.smartwell.extensions.initImmersionBar -import com.casic.app.smartwell.extensions.valueToType import com.casic.app.smartwell.model.MapWellListModel import com.casic.app.smartwell.utils.LocaleConstant import com.casic.app.smartwell.utils.RouteOnMap @@ -31,9 +30,16 @@ import com.casic.app.smartwell.view.WellOperationActivity import com.casic.app.smartwell.vm.OrderViewModel import com.casic.app.smartwell.vm.WellViewModel +import com.casic.app.smartwell.widgets.MapWellPopup +import com.casic.app.smartwell.widgets.cluster.ClusterItem +import com.casic.app.smartwell.widgets.cluster.ClusterOnClickListener +import com.casic.app.smartwell.widgets.cluster.ClusterOverlay +import com.casic.app.smartwell.widgets.cluster.RegionItem 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.convertDrawable +import com.pengxh.kt.lite.extensions.dp2px import com.pengxh.kt.lite.extensions.navigatePageTo import com.pengxh.kt.lite.extensions.show import com.pengxh.kt.lite.utils.LoadingDialogHub @@ -43,35 +49,23 @@ /** * 地图点位带聚合效果 * */ -class HomePageHaveClusterFragment : KotlinBaseFragment(), AMap.OnMapLoadedListener, - AMap.OnCameraChangeListener, AMap.OnMarkerClickListener, AMap.InfoWindowAdapter, - AMap.OnInfoWindowClickListener { +class HomePageHaveClusterFragment : KotlinBaseFragment(), + AMap.OnCameraChangeListener { private val kTag = "HaveClusterFragment" private val easyPopupWindow by lazy { EasyPopupWindow(requireContext()) } - private lateinit var wellViewModel: WellViewModel - private lateinit var orderViewModel: OrderViewModel - private lateinit var aMap: AMap - - /** - * 所有的marker - */ - private var allMarkerOptions: MutableList = ArrayList() - - /** - * 视野内的marker - */ - private var markerOptionsInView: MutableList = ArrayList() - - /** - * 自定义Marker弹出框 - * */ - private lateinit var v: View + private val regionRadius by lazy { LocaleConstant.RADIUS_SIZE.dp2px(requireContext()) } + private val infoPopup by lazy { MapWellPopup(requireContext()) } /** * 所有窨井列表信息集合 * */ - private var wellModels: MutableList = ArrayList() + private val wellModels = ArrayList() + private val backDrawables = HashMap() + private lateinit var wellViewModel: WellViewModel + private lateinit var orderViewModel: OrderViewModel + private lateinit var aMap: AMap + private var clusterOverlay: ClusterOverlay? = null override fun initViewBinding( inflater: LayoutInflater, @@ -106,6 +100,9 @@ } }) + //地图初始化 + initMap(savedInstanceState) + //初始化vm wellViewModel = ViewModelProvider(this)[WellViewModel::class.java] orderViewModel = ViewModelProvider(this)[OrderViewModel::class.java] @@ -120,25 +117,19 @@ val latitudeList: MutableList = ArrayList() val longitudeList: MutableList = ArrayList() it.data?.forEach { well -> - val lat = well.latGaode.toString() - val lng = well.lngGaode.toString() + val lat = well.latGaode + val lng = well.lngGaode if (lat.isNotBlank() && lng.isNotBlank()) { //返回true代表当前位置在大陆、港澳地区,反之不在 val latitude = lat.toDouble() val longitude = lng.toDouble() if (CoordinateConverter.isAMapDataAvailable(latitude, longitude)) { - //缓存所有设备详情,点击Marker时候需要 + //缓存所有井 wellModels.add(well) + //分别缓存经、纬度 latitudeList.add(latitude) longitudeList.add(longitude) - //将所有设备信息转化缓存为Marker点 - allMarkerOptions.add( - MarkerOptions() - .position(LatLng(latitude, longitude)) - .title(well.wellTypeName) - .snippet(well.wellName) - ) } } } @@ -160,12 +151,12 @@ val cameraPosition = CameraPosition(centerLatLng, 16f, 0f, 0f) val cameraUpdate = CameraUpdateFactory.newCameraPosition(cameraPosition) aMap.animateCamera(cameraUpdate, 1500, null) + + //显示点数据 + displayWellOnMap() } } - //地图初始化 - initMap(savedInstanceState) - //获取窨井监控数据 wellViewModel.countResultModel.observe(this) { binding.deployedWellView.text = it["bfWell"] @@ -220,17 +211,10 @@ uiSettings.isCompassEnabled = true uiSettings.zoomPosition = AMapOptions.ZOOM_POSITION_RIGHT_CENTER uiSettings.isTiltGesturesEnabled = false//不许地图随手势倾斜角度 + uiSettings.isRotateGesturesEnabled = false//不允许地图随手势改变方位 - // 地图加载成功监听 - aMap.addOnMapLoadedListener(this) // 地图缩放监听 aMap.addOnCameraChangeListener(this) - // marker 点击事件监听 - aMap.addOnMarkerClickListener(this) - // 点击marker弹出自定义popup - aMap.setInfoWindowAdapter(this) - //信息窗点击事件 - aMap.addOnInfoWindowClickListener(this) } override fun initEvent() { @@ -259,9 +243,111 @@ } - override fun onMapLoaded() { - //地图加载成功之后显示聚合点数据 - initClustersMarkers() + private fun displayWellOnMap() { + clusterOverlay?.onDestroy() + val clusterItems = ArrayList() + + wellModels.forEach { + val latitude = it.latGaode.toDouble() + val longitude = it.lngGaode.toDouble() + + val latLng = LatLng(latitude, longitude, false) + val regionItem = RegionItem(latLng, it) + clusterItems.add(regionItem) + } + + clusterOverlay = ClusterOverlay(requireContext(), aMap, clusterItems, regionRadius) + clusterOverlay?.setClusterRender { clusterNum -> + //聚合圆半径 + val radius = 100.dp2px(requireContext()) + if (clusterNum == 0) { + var bitmapDrawable = backDrawables[0] + if (bitmapDrawable == null) { + bitmapDrawable = BitmapDrawable( + null, radius.drawCircle(Color.argb(159, 100, 149, 237)) + ) + backDrawables[0] = bitmapDrawable + } + bitmapDrawable + } + if (clusterNum == 1) { + var bitmapDrawable = backDrawables[1] + if (bitmapDrawable == null) { + bitmapDrawable = R.mipmap.well_location.convertDrawable(requireContext())!! + backDrawables[1] = bitmapDrawable + } + bitmapDrawable + } else if (clusterNum < 5) { + var bitmapDrawable = backDrawables[2] + if (bitmapDrawable == null) { + bitmapDrawable = BitmapDrawable( + null, radius.drawCircle(Color.argb(159, 100, 149, 237)) + ) + backDrawables[2] = bitmapDrawable + } + bitmapDrawable + } else if (clusterNum < 10) { + var bitmapDrawable = backDrawables[3] + if (bitmapDrawable == null) { + bitmapDrawable = BitmapDrawable( + null, radius.drawCircle(Color.argb(199, 30, 144, 255)) + ) + backDrawables[3] = bitmapDrawable + } + bitmapDrawable + } else { + var bitmapDrawable = backDrawables[4] + if (bitmapDrawable == null) { + bitmapDrawable = BitmapDrawable( + null, radius.drawCircle(Color.argb(235, 65, 105, 225)) + ) + backDrawables[4] = bitmapDrawable + } + bitmapDrawable + } + } + + clusterOverlay?.setOnClusterClickListener(object : ClusterOnClickListener { + override fun onMarkerClicked(marker: Marker?, items: List) { + if (items.size > 1) { + "请缩放地图比例在查看数据".show(requireContext()) + return + } + + var item: RegionItem? = null + val builder = LatLngBounds.Builder() + for (clusterItem in items) { + builder.include(clusterItem.position) + item = clusterItem as RegionItem + } + + item?.apply { + showWellPopup(well) + } + } + }) + } + + private fun showWellPopup(well: MapWellListModel.DataModel) { + infoPopup.set(well, object : MapWellPopup.OnPopupWindowClickListener { + override fun onPopupClicked(lat: Double, lng: Double) { + AlertControlDialog.Builder().setContext(requireContext()).setTitle("操作提示") + .setMessage("确定要前往吗").setNegativeButton("取消").setPositiveButton("确定") + .setOnDialogButtonClickListener(object : + AlertControlDialog.OnDialogButtonClickListener { + override fun onConfirmClick() { + RouteOnMap.startNavigation( + requireContext(), "", LatLng(lat, lng) + ) + } + + override fun onCancelClick() { + + } + }).build().show() + } + }) + infoPopup.showAsDropDown(binding.rightOptionView) } override fun onCameraChange(p0: CameraPosition?) { @@ -282,103 +368,10 @@ } } - //获取视野内的marker 根据聚合算法合成自定义的marker 显示视野内的marker override fun onCameraChangeFinish(p0: CameraPosition?) { //地图缩放之后显示聚合点数据 LoadingDialogHub.dismiss() httpCountDownTimer.cancel() - initClustersMarkers() - } - - private fun initClustersMarkers() { - 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 { - v = LayoutInflater.from(requireContext()).inflate(R.layout.popup_map_info, null) - - //显示闸井信息 - marker?.showInfoWindow() - return true - } - - override fun getInfoWindow(marker: Marker?): View { - //反射得到popup里面的控件对象 - val wellNameView = v.findViewById(R.id.wellNameView) - val wellCodeView = v.findViewById(R.id.wellCodeView) - val wellTypeView = v.findViewById(R.id.wellTypeView) - val wellStateView = v.findViewById(R.id.wellStateView) - val deepView = v.findViewById(R.id.deepView) - val locationView = v.findViewById(R.id.locationView) - - //绑定数据 - val clickedLatLng = marker?.position!! - wellModels.forEach { well -> - if (clickedLatLng.latitude == well.latGaode!!.toDouble() - && clickedLatLng.longitude == well.lngGaode!!.toDouble() - ) { - wellNameView.text = String.format("点位名称: ${well.wellName}") - wellCodeView.text = String.format("点位编号: ${well.wellCode}") - wellTypeView.text = String.format("点位类型: ${well.wellType.valueToType()}") - val bfztName = if (well.bfzt == "1") { - "已布防" - } else { - "已撤防" - } - wellStateView.text = String.format("布/撤防状态: $bfztName") - deepView.text = String.format("点位深度: ${well.deep}m") - locationView.text = String.format("详细位置: ${well.position}") - } - } - return v - } - - /** - * 此方法不能修改整个 InfoWindow 的背景和边框,无论自定义的样式是什么样,SDK 都会在最外层添加一个默认的边框 - * */ - override fun getInfoContents(p0: Marker?): View? = null - - override fun onInfoWindowClick(p0: Marker?) { - p0?.apply { - AlertControlDialog.Builder() - .setContext(requireContext()) - .setTitle("操作提示") - .setMessage("确定要前往吗") - .setNegativeButton("取消") - .setPositiveButton("确定") - .setOnDialogButtonClickListener(object : - AlertControlDialog.OnDialogButtonClickListener { - override fun onConfirmClick() { - val lat = position.latitude.toString() - val lng = position.longitude.toString() - if (lat.isBlank() || lng.isBlank()) { - "点位经纬度异常,无法开启导航".show(requireContext()) - return - } - RouteOnMap.startNavigation( - requireContext(), snippet, LatLng(lat.toDouble(), lng.toDouble()) - ) - } - - override fun onCancelClick() { - - } - }).build().show() - } } /***以下是地图生命周期管理************************************************************************/ 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 a54d213..bfa7a57 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 @@ -44,8 +44,8 @@ * 地图点位不带聚合效果 * */ class HomePageNoClusterFragment : KotlinBaseFragment(), - AMap.OnMapLoadedListener, AMap.OnCameraChangeListener, AMap.OnMarkerClickListener, - AMap.InfoWindowAdapter, AMap.OnInfoWindowClickListener { + AMap.OnCameraChangeListener, AMap.OnMarkerClickListener, AMap.InfoWindowAdapter, + AMap.OnInfoWindowClickListener { private val kTag = "NoClusterFragment" private val easyPopupWindow by lazy { EasyPopupWindow(requireContext()) } @@ -109,6 +109,9 @@ wellViewModel = ViewModelProvider(this)[WellViewModel::class.java] orderViewModel = ViewModelProvider(this)[OrderViewModel::class.java] + //地图初始化 + initMap(savedInstanceState) + //获取所有窨井数据 httpCountDownTimer.start() LoadingDialogHub.show(requireActivity(), "数据加载中,请稍后...") @@ -157,12 +160,12 @@ val cameraPosition = CameraPosition(centerLatLng, 16f, 0f, 0f) val cameraUpdate = CameraUpdateFactory.newCameraPosition(cameraPosition) aMap.animateCamera(cameraUpdate, 1500, null) + + //显示点数据 + displayWellOnMap() } } - //地图初始化 - initMap(savedInstanceState) - //获取窨井监控数据 wellViewModel.countResultModel.observe(this) { binding.deployedWellView.text = it["bfWell"] @@ -214,9 +217,8 @@ uiSettings.isCompassEnabled = true uiSettings.zoomPosition = AMapOptions.ZOOM_POSITION_RIGHT_CENTER uiSettings.isTiltGesturesEnabled = false//不许地图随手势倾斜角度 + uiSettings.isRotateGesturesEnabled = false//不允许地图随手势改变方位 - // 地图加载成功监听 - aMap.addOnMapLoadedListener(this) // 地图缩放监听 aMap.addOnCameraChangeListener(this) // marker 点击事件监听 @@ -253,11 +255,6 @@ } - override fun onMapLoaded() { - //地图加载成功之后显示聚合点数据 - initClustersMarkers() - } - override fun onCameraChange(p0: CameraPosition?) { } @@ -281,10 +278,9 @@ //地图缩放之后显示聚合点数据 LoadingDialogHub.dismiss() httpCountDownTimer.cancel() - initClustersMarkers() } - private fun initClustersMarkers() { + private fun displayWellOnMap() { val proj = aMap.projection val dm = resources.displayMetrics var screenLocation: Point diff --git a/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.java b/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.java deleted file mode 100644 index d8b18ef..0000000 --- a/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.java +++ /dev/null @@ -1,50 +0,0 @@ -package com.casic.app.smartwell.model; - -public class ErrorMessageModel { - - private int code; - private String data; - private String exceptionClazz; - private String message; - private boolean success; - - public int getCode() { - return code; - } - - public void setCode(int code) { - this.code = code; - } - - public String getData() { - return data; - } - - public void setData(String data) { - this.data = data; - } - - public String getExceptionClazz() { - return exceptionClazz; - } - - public void setExceptionClazz(String exceptionClazz) { - this.exceptionClazz = exceptionClazz; - } - - public String getMessage() { - return message; - } - - public void setMessage(String message) { - this.message = message; - } - - public boolean isSuccess() { - return success; - } - - public void setSuccess(boolean success) { - this.success = success; - } -} \ No newline at end of file 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 new file mode 100644 index 0000000..215ac0c --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/PipelineModel.java @@ -0,0 +1,328 @@ +package com.casic.app.smartwell.model; + +import java.util.List; + +public class PipelineModel { + + private Integer code; + private DataModel data; + private String message; + private Boolean success; + + public Integer getCode() { + return code; + } + + public void setCode(Integer code) { + this.code = code; + } + + public DataModel getData() { + return data; + } + + public void setData(DataModel data) { + this.data = data; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + public Boolean getSuccess() { + return success; + } + + public void setSuccess(Boolean success) { + this.success = success; + } + + public static class DataModel { + private List rows; + private Integer total; + + public List getRows() { + return rows; + } + + public void setRows(List rows) { + this.rows = rows; + } + + public Integer getTotal() { + return total; + } + + public void setTotal(Integer total) { + this.total = total; + } + + 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 getBuryMode() { + return buryMode; + } + + public void setBuryMode(String buryMode) { + this.buryMode = buryMode; + } + + public String getConstructEra() { + return constructEra; + } + + public void setConstructEra(String constructEra) { + this.constructEra = constructEra; + } + + 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; + } + } + } +} 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 06d3d2b..4f38a2c 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 = 100 //相距多少米才聚合,单位:米 + const val RADIUS_SIZE = 80 //相距多少米才聚合,单位:米 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:11308" + // 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 0d5f3fa..991e1db 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 @@ -312,4 +312,14 @@ @Header("token") token: String, @Field("clientid") deviceCode: String ): String + + /** + * 管线位置数据 + */ + @GET("/pipeline/listPage") + suspend fun getPipeline( + @Header("token") token: String, + @Query("limit") limit: Int, + @Query("offset") offset: Int + ): String } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt index 1a0ce22..4050067 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt @@ -294,4 +294,11 @@ suspend fun registerPush(clientId: String): String { return api.registerPush(AuthenticationHelper.token!!, clientId) } + + /** + * 管线位置数据 + */ + suspend fun getPipeline(): String { + return api.getPipeline(AuthenticationHelper.token!!, 2000, 1) + } } \ No newline at end of file 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 9270fa1..4ca5a5e 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.HomePageNoClusterFragment +import com.casic.app.smartwell.fragment.HomePageHaveClusterFragment 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/vm/AlarmViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/AlarmViewModel.kt index 9cff08c..e7acc17 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/AlarmViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/AlarmViewModel.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.AlarmContentModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager import com.google.gson.Gson @@ -16,7 +16,7 @@ fun getAlarmContentType(alarmType: String) = launch({ val response = RetrofitServiceManager.getAlarmContentType(alarmType) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { listModel.value = gson.fromJson( response, object : TypeToken() {}.type diff --git a/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt index 5e5b163..895dedd 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.PublicKeyModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager import com.google.gson.Gson @@ -18,7 +18,7 @@ fun getPublicKey() = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.authenticate() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { keyModel.value = gson.fromJson( response, object : TypeToken() {}.type diff --git a/app/src/main/java/com/casic/app/smartwell/vm/DeviceViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/DeviceViewModel.kt index db5ccf6..899a962 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/DeviceViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/DeviceViewModel.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.DeviceDetailModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager import com.google.gson.Gson @@ -16,7 +16,7 @@ fun getDeviceDetail(deviceCode: String) = launch({ val response = RetrofitServiceManager.getDeviceDetail(deviceCode) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { detailModel.value = gson.fromJson( response, object : TypeToken() {}.type diff --git a/app/src/main/java/com/casic/app/smartwell/vm/LoginViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/LoginViewModel.kt index cd8b8a9..a417398 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/LoginViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/LoginViewModel.kt @@ -2,7 +2,7 @@ import androidx.lifecycle.MutableLiveData import com.casic.app.smartwell.base.BaseApplication -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.CommonResultModel import com.casic.app.smartwell.model.LoginResultModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -21,7 +21,7 @@ fun enter(account: String, secretKey: String) = launch({ val response = RetrofitServiceManager.login(account, secretKey) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success enterResultModel.value = gson.fromJson( @@ -38,7 +38,7 @@ fun out() = launch({ val response = RetrofitServiceManager.loginOut() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { outResultModel.value = gson.fromJson( response, object : TypeToken() {}.type diff --git a/app/src/main/java/com/casic/app/smartwell/vm/OperationViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/OperationViewModel.kt index 8943ed3..37e115f 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/OperationViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/OperationViewModel.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.vm import com.casic.app.smartwell.base.BaseApplication -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager import com.pengxh.kt.lite.base.BaseViewModel import com.pengxh.kt.lite.extensions.launch @@ -16,7 +16,7 @@ fun acceptWorkOrder(id: String) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.acceptWorkOrder(id) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success "接单成功".show(BaseApplication.get()) @@ -35,7 +35,7 @@ loadState.value = LoadState.Loading val response = RetrofitServiceManager.confirmWorkOrder(id, firstState, firstStatePhotos, needHandle) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success "工单确认成功".show(BaseApplication.get()) @@ -50,7 +50,7 @@ fun transferWorkOrder(id: String, userId: String) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.transferWorkOrder(id, userId) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success "转单成功".show(BaseApplication.get()) @@ -65,7 +65,7 @@ fun completeWorkOrder(id: String, handleMessage: String, handlePhotos: String) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.completeWorkOrder(id, handleMessage, handlePhotos) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success "工单处理成功".show(BaseApplication.get()) diff --git a/app/src/main/java/com/casic/app/smartwell/vm/OrderViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/OrderViewModel.kt index 4cb26b7..d2fad86 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/OrderViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/OrderViewModel.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.OrderDetailModel import com.casic.app.smartwell.model.OrderListModel import com.casic.app.smartwell.model.OrderStatusModel @@ -37,7 +37,7 @@ val response = RetrofitServiceManager.getSearchResult( keywords, alarmContent, alarmLevel, jobStatus, deptId, beginTime, endTime, offset ) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success searchResult.value = gson.fromJson( @@ -53,7 +53,7 @@ fun getWorkOrderListByState(jobStatus: String, page: Int) = launch({ val response = RetrofitServiceManager.getWorkOrderList(jobStatus, page) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { orderList.value = gson.fromJson( response, object : TypeToken() {}.type @@ -65,7 +65,7 @@ fun getNotAcceptOderList(page: Int) = launch({ val response = RetrofitServiceManager.getNotAcceptOderList(page) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { orderList.value = gson.fromJson( response, object : TypeToken() {}.type @@ -77,7 +77,7 @@ fun getNotHandleOderList(page: Int) = launch({ val response = RetrofitServiceManager.getNotHandleOderList(page) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { orderList.value = gson.fromJson( response, object : TypeToken() {}.type @@ -89,7 +89,7 @@ fun countWorkOrderByState() = launch({ val response = RetrofitServiceManager.countWorkOrderByState() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { val map = HashMap(4) @@ -107,7 +107,7 @@ fun getOrderStatus() = launch({ val response = RetrofitServiceManager.getOrderStatus() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { orderStatusModel.value = gson.fromJson( response, object : TypeToken() {}.type @@ -120,7 +120,7 @@ fun getWorkOrderDetail(id: String) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.getWorkOrderDetail(id) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success detailModel.value = gson.fromJson( diff --git a/app/src/main/java/com/casic/app/smartwell/vm/PipelineViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/PipelineViewModel.kt new file mode 100644 index 0000000..60c1e2f --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/vm/PipelineViewModel.kt @@ -0,0 +1,28 @@ +package com.casic.app.smartwell.vm + +import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.extensions.getResponseCode +import com.casic.app.smartwell.model.PipelineModel +import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken +import com.pengxh.kt.lite.base.BaseViewModel +import com.pengxh.kt.lite.extensions.launch + +class PipelineViewModel : BaseViewModel() { + + private val gson by lazy { Gson() } + val lineResult = MutableLiveData() + + fun getPipeline() = launch({ + val response = RetrofitServiceManager.getPipeline() + val responseCode = response.getResponseCode() + if (responseCode == 200) { + lineResult.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } + }, { + it.printStackTrace() + }) +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/extensions/Int.kt b/app/src/main/java/com/casic/app/smartwell/extensions/Int.kt index de0617b..a0a5e33 100644 --- a/app/src/main/java/com/casic/app/smartwell/extensions/Int.kt +++ b/app/src/main/java/com/casic/app/smartwell/extensions/Int.kt @@ -1,9 +1,24 @@ package com.casic.app.smartwell.extensions +import android.graphics.Bitmap +import android.graphics.Canvas +import android.graphics.Paint +import android.graphics.RectF + fun Int.toLevel(): String { return if (this == 0) { "" } else { this.toString() } +} + +fun Int.drawCircle(color: Int): Bitmap? { + val bitmap = Bitmap.createBitmap(this * 2, this * 2, Bitmap.Config.ARGB_8888) + val canvas = Canvas(bitmap) + val paint = Paint() + val rectF = RectF(0f, 0f, (this * 2).toFloat(), (this * 2).toFloat()) + paint.color = color + canvas.drawArc(rectF, 0f, 360f, true, paint) + return bitmap } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt index 6b6ca3e..5e45534 100644 --- a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt +++ b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt @@ -2,17 +2,13 @@ import android.content.Context import com.casic.app.smartwell.callback.OnImageCompressListener -import com.casic.app.smartwell.model.ErrorMessageModel import com.casic.app.smartwell.utils.LocaleConstant -import com.google.gson.Gson -import com.google.gson.reflect.TypeToken +import com.google.gson.JsonParser import com.pengxh.kt.lite.extensions.createCompressImageDir import com.pengxh.kt.lite.utils.SaveKeyValues -import org.json.JSONObject import top.zibin.luban.Luban import top.zibin.luban.OnCompressListener import java.io.File -import java.util.Locale /** * String扩展方法 @@ -74,18 +70,22 @@ } } -fun String.separateResponseCode(): Int { +fun String.getResponseCode(): Int { if (this.isBlank()) { return 404 } - return JSONObject(this).getInt("code") + val element = JsonParser.parseString(this) + val jsonObject = element.asJsonObject + return jsonObject.get("code").asInt } -fun String.toErrorMessage(): String { - val errorModel = Gson().fromJson( - this, object : TypeToken() {}.type - ) - return errorModel.message.toString() +fun String.getResponseMessage(): String { + if (this.isBlank()) { + return "" + } + val element = JsonParser.parseString(this) + val jsonObject = element.asJsonObject + return jsonObject.get("message").asString } fun String.compressImage(context: Context, listener: OnImageCompressListener) { @@ -93,9 +93,6 @@ .load(this) .ignoreBy(100) .setTargetDir(context.createCompressImageDir().toString()) - .filter { - !(it.isBlank() || it.lowercase(Locale.getDefault()).endsWith(".gif")) - } .setCompressListener(object : OnCompressListener { override fun onStart() { 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 96df110..cd25fca 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 @@ -1,26 +1,25 @@ package com.casic.app.smartwell.fragment -import android.graphics.Point +import android.graphics.Color +import android.graphics.drawable.BitmapDrawable +import android.graphics.drawable.Drawable 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 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.LatLngBounds import com.amap.api.maps.model.Marker -import com.amap.api.maps.model.MarkerOptions import com.casic.app.smartwell.R import com.casic.app.smartwell.databinding.FragmentHomeBinding +import com.casic.app.smartwell.extensions.drawCircle import com.casic.app.smartwell.extensions.initImmersionBar -import com.casic.app.smartwell.extensions.valueToType import com.casic.app.smartwell.model.MapWellListModel import com.casic.app.smartwell.utils.LocaleConstant import com.casic.app.smartwell.utils.RouteOnMap @@ -31,9 +30,16 @@ import com.casic.app.smartwell.view.WellOperationActivity import com.casic.app.smartwell.vm.OrderViewModel import com.casic.app.smartwell.vm.WellViewModel +import com.casic.app.smartwell.widgets.MapWellPopup +import com.casic.app.smartwell.widgets.cluster.ClusterItem +import com.casic.app.smartwell.widgets.cluster.ClusterOnClickListener +import com.casic.app.smartwell.widgets.cluster.ClusterOverlay +import com.casic.app.smartwell.widgets.cluster.RegionItem 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.convertDrawable +import com.pengxh.kt.lite.extensions.dp2px import com.pengxh.kt.lite.extensions.navigatePageTo import com.pengxh.kt.lite.extensions.show import com.pengxh.kt.lite.utils.LoadingDialogHub @@ -43,35 +49,23 @@ /** * 地图点位带聚合效果 * */ -class HomePageHaveClusterFragment : KotlinBaseFragment(), AMap.OnMapLoadedListener, - AMap.OnCameraChangeListener, AMap.OnMarkerClickListener, AMap.InfoWindowAdapter, - AMap.OnInfoWindowClickListener { +class HomePageHaveClusterFragment : KotlinBaseFragment(), + AMap.OnCameraChangeListener { private val kTag = "HaveClusterFragment" private val easyPopupWindow by lazy { EasyPopupWindow(requireContext()) } - private lateinit var wellViewModel: WellViewModel - private lateinit var orderViewModel: OrderViewModel - private lateinit var aMap: AMap - - /** - * 所有的marker - */ - private var allMarkerOptions: MutableList = ArrayList() - - /** - * 视野内的marker - */ - private var markerOptionsInView: MutableList = ArrayList() - - /** - * 自定义Marker弹出框 - * */ - private lateinit var v: View + private val regionRadius by lazy { LocaleConstant.RADIUS_SIZE.dp2px(requireContext()) } + private val infoPopup by lazy { MapWellPopup(requireContext()) } /** * 所有窨井列表信息集合 * */ - private var wellModels: MutableList = ArrayList() + private val wellModels = ArrayList() + private val backDrawables = HashMap() + private lateinit var wellViewModel: WellViewModel + private lateinit var orderViewModel: OrderViewModel + private lateinit var aMap: AMap + private var clusterOverlay: ClusterOverlay? = null override fun initViewBinding( inflater: LayoutInflater, @@ -106,6 +100,9 @@ } }) + //地图初始化 + initMap(savedInstanceState) + //初始化vm wellViewModel = ViewModelProvider(this)[WellViewModel::class.java] orderViewModel = ViewModelProvider(this)[OrderViewModel::class.java] @@ -120,25 +117,19 @@ val latitudeList: MutableList = ArrayList() val longitudeList: MutableList = ArrayList() it.data?.forEach { well -> - val lat = well.latGaode.toString() - val lng = well.lngGaode.toString() + val lat = well.latGaode + val lng = well.lngGaode if (lat.isNotBlank() && lng.isNotBlank()) { //返回true代表当前位置在大陆、港澳地区,反之不在 val latitude = lat.toDouble() val longitude = lng.toDouble() if (CoordinateConverter.isAMapDataAvailable(latitude, longitude)) { - //缓存所有设备详情,点击Marker时候需要 + //缓存所有井 wellModels.add(well) + //分别缓存经、纬度 latitudeList.add(latitude) longitudeList.add(longitude) - //将所有设备信息转化缓存为Marker点 - allMarkerOptions.add( - MarkerOptions() - .position(LatLng(latitude, longitude)) - .title(well.wellTypeName) - .snippet(well.wellName) - ) } } } @@ -160,12 +151,12 @@ val cameraPosition = CameraPosition(centerLatLng, 16f, 0f, 0f) val cameraUpdate = CameraUpdateFactory.newCameraPosition(cameraPosition) aMap.animateCamera(cameraUpdate, 1500, null) + + //显示点数据 + displayWellOnMap() } } - //地图初始化 - initMap(savedInstanceState) - //获取窨井监控数据 wellViewModel.countResultModel.observe(this) { binding.deployedWellView.text = it["bfWell"] @@ -220,17 +211,10 @@ uiSettings.isCompassEnabled = true uiSettings.zoomPosition = AMapOptions.ZOOM_POSITION_RIGHT_CENTER uiSettings.isTiltGesturesEnabled = false//不许地图随手势倾斜角度 + uiSettings.isRotateGesturesEnabled = false//不允许地图随手势改变方位 - // 地图加载成功监听 - aMap.addOnMapLoadedListener(this) // 地图缩放监听 aMap.addOnCameraChangeListener(this) - // marker 点击事件监听 - aMap.addOnMarkerClickListener(this) - // 点击marker弹出自定义popup - aMap.setInfoWindowAdapter(this) - //信息窗点击事件 - aMap.addOnInfoWindowClickListener(this) } override fun initEvent() { @@ -259,9 +243,111 @@ } - override fun onMapLoaded() { - //地图加载成功之后显示聚合点数据 - initClustersMarkers() + private fun displayWellOnMap() { + clusterOverlay?.onDestroy() + val clusterItems = ArrayList() + + wellModels.forEach { + val latitude = it.latGaode.toDouble() + val longitude = it.lngGaode.toDouble() + + val latLng = LatLng(latitude, longitude, false) + val regionItem = RegionItem(latLng, it) + clusterItems.add(regionItem) + } + + clusterOverlay = ClusterOverlay(requireContext(), aMap, clusterItems, regionRadius) + clusterOverlay?.setClusterRender { clusterNum -> + //聚合圆半径 + val radius = 100.dp2px(requireContext()) + if (clusterNum == 0) { + var bitmapDrawable = backDrawables[0] + if (bitmapDrawable == null) { + bitmapDrawable = BitmapDrawable( + null, radius.drawCircle(Color.argb(159, 100, 149, 237)) + ) + backDrawables[0] = bitmapDrawable + } + bitmapDrawable + } + if (clusterNum == 1) { + var bitmapDrawable = backDrawables[1] + if (bitmapDrawable == null) { + bitmapDrawable = R.mipmap.well_location.convertDrawable(requireContext())!! + backDrawables[1] = bitmapDrawable + } + bitmapDrawable + } else if (clusterNum < 5) { + var bitmapDrawable = backDrawables[2] + if (bitmapDrawable == null) { + bitmapDrawable = BitmapDrawable( + null, radius.drawCircle(Color.argb(159, 100, 149, 237)) + ) + backDrawables[2] = bitmapDrawable + } + bitmapDrawable + } else if (clusterNum < 10) { + var bitmapDrawable = backDrawables[3] + if (bitmapDrawable == null) { + bitmapDrawable = BitmapDrawable( + null, radius.drawCircle(Color.argb(199, 30, 144, 255)) + ) + backDrawables[3] = bitmapDrawable + } + bitmapDrawable + } else { + var bitmapDrawable = backDrawables[4] + if (bitmapDrawable == null) { + bitmapDrawable = BitmapDrawable( + null, radius.drawCircle(Color.argb(235, 65, 105, 225)) + ) + backDrawables[4] = bitmapDrawable + } + bitmapDrawable + } + } + + clusterOverlay?.setOnClusterClickListener(object : ClusterOnClickListener { + override fun onMarkerClicked(marker: Marker?, items: List) { + if (items.size > 1) { + "请缩放地图比例在查看数据".show(requireContext()) + return + } + + var item: RegionItem? = null + val builder = LatLngBounds.Builder() + for (clusterItem in items) { + builder.include(clusterItem.position) + item = clusterItem as RegionItem + } + + item?.apply { + showWellPopup(well) + } + } + }) + } + + private fun showWellPopup(well: MapWellListModel.DataModel) { + infoPopup.set(well, object : MapWellPopup.OnPopupWindowClickListener { + override fun onPopupClicked(lat: Double, lng: Double) { + AlertControlDialog.Builder().setContext(requireContext()).setTitle("操作提示") + .setMessage("确定要前往吗").setNegativeButton("取消").setPositiveButton("确定") + .setOnDialogButtonClickListener(object : + AlertControlDialog.OnDialogButtonClickListener { + override fun onConfirmClick() { + RouteOnMap.startNavigation( + requireContext(), "", LatLng(lat, lng) + ) + } + + override fun onCancelClick() { + + } + }).build().show() + } + }) + infoPopup.showAsDropDown(binding.rightOptionView) } override fun onCameraChange(p0: CameraPosition?) { @@ -282,103 +368,10 @@ } } - //获取视野内的marker 根据聚合算法合成自定义的marker 显示视野内的marker override fun onCameraChangeFinish(p0: CameraPosition?) { //地图缩放之后显示聚合点数据 LoadingDialogHub.dismiss() httpCountDownTimer.cancel() - initClustersMarkers() - } - - private fun initClustersMarkers() { - 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 { - v = LayoutInflater.from(requireContext()).inflate(R.layout.popup_map_info, null) - - //显示闸井信息 - marker?.showInfoWindow() - return true - } - - override fun getInfoWindow(marker: Marker?): View { - //反射得到popup里面的控件对象 - val wellNameView = v.findViewById(R.id.wellNameView) - val wellCodeView = v.findViewById(R.id.wellCodeView) - val wellTypeView = v.findViewById(R.id.wellTypeView) - val wellStateView = v.findViewById(R.id.wellStateView) - val deepView = v.findViewById(R.id.deepView) - val locationView = v.findViewById(R.id.locationView) - - //绑定数据 - val clickedLatLng = marker?.position!! - wellModels.forEach { well -> - if (clickedLatLng.latitude == well.latGaode!!.toDouble() - && clickedLatLng.longitude == well.lngGaode!!.toDouble() - ) { - wellNameView.text = String.format("点位名称: ${well.wellName}") - wellCodeView.text = String.format("点位编号: ${well.wellCode}") - wellTypeView.text = String.format("点位类型: ${well.wellType.valueToType()}") - val bfztName = if (well.bfzt == "1") { - "已布防" - } else { - "已撤防" - } - wellStateView.text = String.format("布/撤防状态: $bfztName") - deepView.text = String.format("点位深度: ${well.deep}m") - locationView.text = String.format("详细位置: ${well.position}") - } - } - return v - } - - /** - * 此方法不能修改整个 InfoWindow 的背景和边框,无论自定义的样式是什么样,SDK 都会在最外层添加一个默认的边框 - * */ - override fun getInfoContents(p0: Marker?): View? = null - - override fun onInfoWindowClick(p0: Marker?) { - p0?.apply { - AlertControlDialog.Builder() - .setContext(requireContext()) - .setTitle("操作提示") - .setMessage("确定要前往吗") - .setNegativeButton("取消") - .setPositiveButton("确定") - .setOnDialogButtonClickListener(object : - AlertControlDialog.OnDialogButtonClickListener { - override fun onConfirmClick() { - val lat = position.latitude.toString() - val lng = position.longitude.toString() - if (lat.isBlank() || lng.isBlank()) { - "点位经纬度异常,无法开启导航".show(requireContext()) - return - } - RouteOnMap.startNavigation( - requireContext(), snippet, LatLng(lat.toDouble(), lng.toDouble()) - ) - } - - override fun onCancelClick() { - - } - }).build().show() - } } /***以下是地图生命周期管理************************************************************************/ 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 a54d213..bfa7a57 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 @@ -44,8 +44,8 @@ * 地图点位不带聚合效果 * */ class HomePageNoClusterFragment : KotlinBaseFragment(), - AMap.OnMapLoadedListener, AMap.OnCameraChangeListener, AMap.OnMarkerClickListener, - AMap.InfoWindowAdapter, AMap.OnInfoWindowClickListener { + AMap.OnCameraChangeListener, AMap.OnMarkerClickListener, AMap.InfoWindowAdapter, + AMap.OnInfoWindowClickListener { private val kTag = "NoClusterFragment" private val easyPopupWindow by lazy { EasyPopupWindow(requireContext()) } @@ -109,6 +109,9 @@ wellViewModel = ViewModelProvider(this)[WellViewModel::class.java] orderViewModel = ViewModelProvider(this)[OrderViewModel::class.java] + //地图初始化 + initMap(savedInstanceState) + //获取所有窨井数据 httpCountDownTimer.start() LoadingDialogHub.show(requireActivity(), "数据加载中,请稍后...") @@ -157,12 +160,12 @@ val cameraPosition = CameraPosition(centerLatLng, 16f, 0f, 0f) val cameraUpdate = CameraUpdateFactory.newCameraPosition(cameraPosition) aMap.animateCamera(cameraUpdate, 1500, null) + + //显示点数据 + displayWellOnMap() } } - //地图初始化 - initMap(savedInstanceState) - //获取窨井监控数据 wellViewModel.countResultModel.observe(this) { binding.deployedWellView.text = it["bfWell"] @@ -214,9 +217,8 @@ uiSettings.isCompassEnabled = true uiSettings.zoomPosition = AMapOptions.ZOOM_POSITION_RIGHT_CENTER uiSettings.isTiltGesturesEnabled = false//不许地图随手势倾斜角度 + uiSettings.isRotateGesturesEnabled = false//不允许地图随手势改变方位 - // 地图加载成功监听 - aMap.addOnMapLoadedListener(this) // 地图缩放监听 aMap.addOnCameraChangeListener(this) // marker 点击事件监听 @@ -253,11 +255,6 @@ } - override fun onMapLoaded() { - //地图加载成功之后显示聚合点数据 - initClustersMarkers() - } - override fun onCameraChange(p0: CameraPosition?) { } @@ -281,10 +278,9 @@ //地图缩放之后显示聚合点数据 LoadingDialogHub.dismiss() httpCountDownTimer.cancel() - initClustersMarkers() } - private fun initClustersMarkers() { + private fun displayWellOnMap() { val proj = aMap.projection val dm = resources.displayMetrics var screenLocation: Point diff --git a/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.java b/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.java deleted file mode 100644 index d8b18ef..0000000 --- a/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.java +++ /dev/null @@ -1,50 +0,0 @@ -package com.casic.app.smartwell.model; - -public class ErrorMessageModel { - - private int code; - private String data; - private String exceptionClazz; - private String message; - private boolean success; - - public int getCode() { - return code; - } - - public void setCode(int code) { - this.code = code; - } - - public String getData() { - return data; - } - - public void setData(String data) { - this.data = data; - } - - public String getExceptionClazz() { - return exceptionClazz; - } - - public void setExceptionClazz(String exceptionClazz) { - this.exceptionClazz = exceptionClazz; - } - - public String getMessage() { - return message; - } - - public void setMessage(String message) { - this.message = message; - } - - public boolean isSuccess() { - return success; - } - - public void setSuccess(boolean success) { - this.success = success; - } -} \ No newline at end of file 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 new file mode 100644 index 0000000..215ac0c --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/PipelineModel.java @@ -0,0 +1,328 @@ +package com.casic.app.smartwell.model; + +import java.util.List; + +public class PipelineModel { + + private Integer code; + private DataModel data; + private String message; + private Boolean success; + + public Integer getCode() { + return code; + } + + public void setCode(Integer code) { + this.code = code; + } + + public DataModel getData() { + return data; + } + + public void setData(DataModel data) { + this.data = data; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + public Boolean getSuccess() { + return success; + } + + public void setSuccess(Boolean success) { + this.success = success; + } + + public static class DataModel { + private List rows; + private Integer total; + + public List getRows() { + return rows; + } + + public void setRows(List rows) { + this.rows = rows; + } + + public Integer getTotal() { + return total; + } + + public void setTotal(Integer total) { + this.total = total; + } + + 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 getBuryMode() { + return buryMode; + } + + public void setBuryMode(String buryMode) { + this.buryMode = buryMode; + } + + public String getConstructEra() { + return constructEra; + } + + public void setConstructEra(String constructEra) { + this.constructEra = constructEra; + } + + 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; + } + } + } +} 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 06d3d2b..4f38a2c 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 = 100 //相距多少米才聚合,单位:米 + const val RADIUS_SIZE = 80 //相距多少米才聚合,单位:米 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:11308" + // 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 0d5f3fa..991e1db 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 @@ -312,4 +312,14 @@ @Header("token") token: String, @Field("clientid") deviceCode: String ): String + + /** + * 管线位置数据 + */ + @GET("/pipeline/listPage") + suspend fun getPipeline( + @Header("token") token: String, + @Query("limit") limit: Int, + @Query("offset") offset: Int + ): String } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt index 1a0ce22..4050067 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt @@ -294,4 +294,11 @@ suspend fun registerPush(clientId: String): String { return api.registerPush(AuthenticationHelper.token!!, clientId) } + + /** + * 管线位置数据 + */ + suspend fun getPipeline(): String { + return api.getPipeline(AuthenticationHelper.token!!, 2000, 1) + } } \ No newline at end of file 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 9270fa1..4ca5a5e 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.HomePageNoClusterFragment +import com.casic.app.smartwell.fragment.HomePageHaveClusterFragment 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/vm/AlarmViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/AlarmViewModel.kt index 9cff08c..e7acc17 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/AlarmViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/AlarmViewModel.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.AlarmContentModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager import com.google.gson.Gson @@ -16,7 +16,7 @@ fun getAlarmContentType(alarmType: String) = launch({ val response = RetrofitServiceManager.getAlarmContentType(alarmType) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { listModel.value = gson.fromJson( response, object : TypeToken() {}.type diff --git a/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt index 5e5b163..895dedd 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.PublicKeyModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager import com.google.gson.Gson @@ -18,7 +18,7 @@ fun getPublicKey() = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.authenticate() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { keyModel.value = gson.fromJson( response, object : TypeToken() {}.type diff --git a/app/src/main/java/com/casic/app/smartwell/vm/DeviceViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/DeviceViewModel.kt index db5ccf6..899a962 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/DeviceViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/DeviceViewModel.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.DeviceDetailModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager import com.google.gson.Gson @@ -16,7 +16,7 @@ fun getDeviceDetail(deviceCode: String) = launch({ val response = RetrofitServiceManager.getDeviceDetail(deviceCode) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { detailModel.value = gson.fromJson( response, object : TypeToken() {}.type diff --git a/app/src/main/java/com/casic/app/smartwell/vm/LoginViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/LoginViewModel.kt index cd8b8a9..a417398 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/LoginViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/LoginViewModel.kt @@ -2,7 +2,7 @@ import androidx.lifecycle.MutableLiveData import com.casic.app.smartwell.base.BaseApplication -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.CommonResultModel import com.casic.app.smartwell.model.LoginResultModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -21,7 +21,7 @@ fun enter(account: String, secretKey: String) = launch({ val response = RetrofitServiceManager.login(account, secretKey) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success enterResultModel.value = gson.fromJson( @@ -38,7 +38,7 @@ fun out() = launch({ val response = RetrofitServiceManager.loginOut() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { outResultModel.value = gson.fromJson( response, object : TypeToken() {}.type diff --git a/app/src/main/java/com/casic/app/smartwell/vm/OperationViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/OperationViewModel.kt index 8943ed3..37e115f 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/OperationViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/OperationViewModel.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.vm import com.casic.app.smartwell.base.BaseApplication -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager import com.pengxh.kt.lite.base.BaseViewModel import com.pengxh.kt.lite.extensions.launch @@ -16,7 +16,7 @@ fun acceptWorkOrder(id: String) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.acceptWorkOrder(id) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success "接单成功".show(BaseApplication.get()) @@ -35,7 +35,7 @@ loadState.value = LoadState.Loading val response = RetrofitServiceManager.confirmWorkOrder(id, firstState, firstStatePhotos, needHandle) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success "工单确认成功".show(BaseApplication.get()) @@ -50,7 +50,7 @@ fun transferWorkOrder(id: String, userId: String) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.transferWorkOrder(id, userId) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success "转单成功".show(BaseApplication.get()) @@ -65,7 +65,7 @@ fun completeWorkOrder(id: String, handleMessage: String, handlePhotos: String) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.completeWorkOrder(id, handleMessage, handlePhotos) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success "工单处理成功".show(BaseApplication.get()) diff --git a/app/src/main/java/com/casic/app/smartwell/vm/OrderViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/OrderViewModel.kt index 4cb26b7..d2fad86 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/OrderViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/OrderViewModel.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.OrderDetailModel import com.casic.app.smartwell.model.OrderListModel import com.casic.app.smartwell.model.OrderStatusModel @@ -37,7 +37,7 @@ val response = RetrofitServiceManager.getSearchResult( keywords, alarmContent, alarmLevel, jobStatus, deptId, beginTime, endTime, offset ) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success searchResult.value = gson.fromJson( @@ -53,7 +53,7 @@ fun getWorkOrderListByState(jobStatus: String, page: Int) = launch({ val response = RetrofitServiceManager.getWorkOrderList(jobStatus, page) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { orderList.value = gson.fromJson( response, object : TypeToken() {}.type @@ -65,7 +65,7 @@ fun getNotAcceptOderList(page: Int) = launch({ val response = RetrofitServiceManager.getNotAcceptOderList(page) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { orderList.value = gson.fromJson( response, object : TypeToken() {}.type @@ -77,7 +77,7 @@ fun getNotHandleOderList(page: Int) = launch({ val response = RetrofitServiceManager.getNotHandleOderList(page) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { orderList.value = gson.fromJson( response, object : TypeToken() {}.type @@ -89,7 +89,7 @@ fun countWorkOrderByState() = launch({ val response = RetrofitServiceManager.countWorkOrderByState() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { val map = HashMap(4) @@ -107,7 +107,7 @@ fun getOrderStatus() = launch({ val response = RetrofitServiceManager.getOrderStatus() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { orderStatusModel.value = gson.fromJson( response, object : TypeToken() {}.type @@ -120,7 +120,7 @@ fun getWorkOrderDetail(id: String) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.getWorkOrderDetail(id) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success detailModel.value = gson.fromJson( diff --git a/app/src/main/java/com/casic/app/smartwell/vm/PipelineViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/PipelineViewModel.kt new file mode 100644 index 0000000..60c1e2f --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/vm/PipelineViewModel.kt @@ -0,0 +1,28 @@ +package com.casic.app.smartwell.vm + +import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.extensions.getResponseCode +import com.casic.app.smartwell.model.PipelineModel +import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken +import com.pengxh.kt.lite.base.BaseViewModel +import com.pengxh.kt.lite.extensions.launch + +class PipelineViewModel : BaseViewModel() { + + private val gson by lazy { Gson() } + val lineResult = MutableLiveData() + + fun getPipeline() = launch({ + val response = RetrofitServiceManager.getPipeline() + val responseCode = response.getResponseCode() + if (responseCode == 200) { + lineResult.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } + }, { + it.printStackTrace() + }) +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/PushViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/PushViewModel.kt index 9279815..12fd610 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/PushViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/PushViewModel.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.CommonResultModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager import com.google.gson.Gson @@ -16,7 +16,7 @@ fun registerPush(clientId: String) = launch({ val response = RetrofitServiceManager.registerPush(clientId) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { registerResultModel.value = gson.fromJson( response, object : TypeToken() {}.type diff --git a/app/src/main/java/com/casic/app/smartwell/extensions/Int.kt b/app/src/main/java/com/casic/app/smartwell/extensions/Int.kt index de0617b..a0a5e33 100644 --- a/app/src/main/java/com/casic/app/smartwell/extensions/Int.kt +++ b/app/src/main/java/com/casic/app/smartwell/extensions/Int.kt @@ -1,9 +1,24 @@ package com.casic.app.smartwell.extensions +import android.graphics.Bitmap +import android.graphics.Canvas +import android.graphics.Paint +import android.graphics.RectF + fun Int.toLevel(): String { return if (this == 0) { "" } else { this.toString() } +} + +fun Int.drawCircle(color: Int): Bitmap? { + val bitmap = Bitmap.createBitmap(this * 2, this * 2, Bitmap.Config.ARGB_8888) + val canvas = Canvas(bitmap) + val paint = Paint() + val rectF = RectF(0f, 0f, (this * 2).toFloat(), (this * 2).toFloat()) + paint.color = color + canvas.drawArc(rectF, 0f, 360f, true, paint) + return bitmap } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt index 6b6ca3e..5e45534 100644 --- a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt +++ b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt @@ -2,17 +2,13 @@ import android.content.Context import com.casic.app.smartwell.callback.OnImageCompressListener -import com.casic.app.smartwell.model.ErrorMessageModel import com.casic.app.smartwell.utils.LocaleConstant -import com.google.gson.Gson -import com.google.gson.reflect.TypeToken +import com.google.gson.JsonParser import com.pengxh.kt.lite.extensions.createCompressImageDir import com.pengxh.kt.lite.utils.SaveKeyValues -import org.json.JSONObject import top.zibin.luban.Luban import top.zibin.luban.OnCompressListener import java.io.File -import java.util.Locale /** * String扩展方法 @@ -74,18 +70,22 @@ } } -fun String.separateResponseCode(): Int { +fun String.getResponseCode(): Int { if (this.isBlank()) { return 404 } - return JSONObject(this).getInt("code") + val element = JsonParser.parseString(this) + val jsonObject = element.asJsonObject + return jsonObject.get("code").asInt } -fun String.toErrorMessage(): String { - val errorModel = Gson().fromJson( - this, object : TypeToken() {}.type - ) - return errorModel.message.toString() +fun String.getResponseMessage(): String { + if (this.isBlank()) { + return "" + } + val element = JsonParser.parseString(this) + val jsonObject = element.asJsonObject + return jsonObject.get("message").asString } fun String.compressImage(context: Context, listener: OnImageCompressListener) { @@ -93,9 +93,6 @@ .load(this) .ignoreBy(100) .setTargetDir(context.createCompressImageDir().toString()) - .filter { - !(it.isBlank() || it.lowercase(Locale.getDefault()).endsWith(".gif")) - } .setCompressListener(object : OnCompressListener { override fun onStart() { 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 96df110..cd25fca 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 @@ -1,26 +1,25 @@ package com.casic.app.smartwell.fragment -import android.graphics.Point +import android.graphics.Color +import android.graphics.drawable.BitmapDrawable +import android.graphics.drawable.Drawable 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 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.LatLngBounds import com.amap.api.maps.model.Marker -import com.amap.api.maps.model.MarkerOptions import com.casic.app.smartwell.R import com.casic.app.smartwell.databinding.FragmentHomeBinding +import com.casic.app.smartwell.extensions.drawCircle import com.casic.app.smartwell.extensions.initImmersionBar -import com.casic.app.smartwell.extensions.valueToType import com.casic.app.smartwell.model.MapWellListModel import com.casic.app.smartwell.utils.LocaleConstant import com.casic.app.smartwell.utils.RouteOnMap @@ -31,9 +30,16 @@ import com.casic.app.smartwell.view.WellOperationActivity import com.casic.app.smartwell.vm.OrderViewModel import com.casic.app.smartwell.vm.WellViewModel +import com.casic.app.smartwell.widgets.MapWellPopup +import com.casic.app.smartwell.widgets.cluster.ClusterItem +import com.casic.app.smartwell.widgets.cluster.ClusterOnClickListener +import com.casic.app.smartwell.widgets.cluster.ClusterOverlay +import com.casic.app.smartwell.widgets.cluster.RegionItem 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.convertDrawable +import com.pengxh.kt.lite.extensions.dp2px import com.pengxh.kt.lite.extensions.navigatePageTo import com.pengxh.kt.lite.extensions.show import com.pengxh.kt.lite.utils.LoadingDialogHub @@ -43,35 +49,23 @@ /** * 地图点位带聚合效果 * */ -class HomePageHaveClusterFragment : KotlinBaseFragment(), AMap.OnMapLoadedListener, - AMap.OnCameraChangeListener, AMap.OnMarkerClickListener, AMap.InfoWindowAdapter, - AMap.OnInfoWindowClickListener { +class HomePageHaveClusterFragment : KotlinBaseFragment(), + AMap.OnCameraChangeListener { private val kTag = "HaveClusterFragment" private val easyPopupWindow by lazy { EasyPopupWindow(requireContext()) } - private lateinit var wellViewModel: WellViewModel - private lateinit var orderViewModel: OrderViewModel - private lateinit var aMap: AMap - - /** - * 所有的marker - */ - private var allMarkerOptions: MutableList = ArrayList() - - /** - * 视野内的marker - */ - private var markerOptionsInView: MutableList = ArrayList() - - /** - * 自定义Marker弹出框 - * */ - private lateinit var v: View + private val regionRadius by lazy { LocaleConstant.RADIUS_SIZE.dp2px(requireContext()) } + private val infoPopup by lazy { MapWellPopup(requireContext()) } /** * 所有窨井列表信息集合 * */ - private var wellModels: MutableList = ArrayList() + private val wellModels = ArrayList() + private val backDrawables = HashMap() + private lateinit var wellViewModel: WellViewModel + private lateinit var orderViewModel: OrderViewModel + private lateinit var aMap: AMap + private var clusterOverlay: ClusterOverlay? = null override fun initViewBinding( inflater: LayoutInflater, @@ -106,6 +100,9 @@ } }) + //地图初始化 + initMap(savedInstanceState) + //初始化vm wellViewModel = ViewModelProvider(this)[WellViewModel::class.java] orderViewModel = ViewModelProvider(this)[OrderViewModel::class.java] @@ -120,25 +117,19 @@ val latitudeList: MutableList = ArrayList() val longitudeList: MutableList = ArrayList() it.data?.forEach { well -> - val lat = well.latGaode.toString() - val lng = well.lngGaode.toString() + val lat = well.latGaode + val lng = well.lngGaode if (lat.isNotBlank() && lng.isNotBlank()) { //返回true代表当前位置在大陆、港澳地区,反之不在 val latitude = lat.toDouble() val longitude = lng.toDouble() if (CoordinateConverter.isAMapDataAvailable(latitude, longitude)) { - //缓存所有设备详情,点击Marker时候需要 + //缓存所有井 wellModels.add(well) + //分别缓存经、纬度 latitudeList.add(latitude) longitudeList.add(longitude) - //将所有设备信息转化缓存为Marker点 - allMarkerOptions.add( - MarkerOptions() - .position(LatLng(latitude, longitude)) - .title(well.wellTypeName) - .snippet(well.wellName) - ) } } } @@ -160,12 +151,12 @@ val cameraPosition = CameraPosition(centerLatLng, 16f, 0f, 0f) val cameraUpdate = CameraUpdateFactory.newCameraPosition(cameraPosition) aMap.animateCamera(cameraUpdate, 1500, null) + + //显示点数据 + displayWellOnMap() } } - //地图初始化 - initMap(savedInstanceState) - //获取窨井监控数据 wellViewModel.countResultModel.observe(this) { binding.deployedWellView.text = it["bfWell"] @@ -220,17 +211,10 @@ uiSettings.isCompassEnabled = true uiSettings.zoomPosition = AMapOptions.ZOOM_POSITION_RIGHT_CENTER uiSettings.isTiltGesturesEnabled = false//不许地图随手势倾斜角度 + uiSettings.isRotateGesturesEnabled = false//不允许地图随手势改变方位 - // 地图加载成功监听 - aMap.addOnMapLoadedListener(this) // 地图缩放监听 aMap.addOnCameraChangeListener(this) - // marker 点击事件监听 - aMap.addOnMarkerClickListener(this) - // 点击marker弹出自定义popup - aMap.setInfoWindowAdapter(this) - //信息窗点击事件 - aMap.addOnInfoWindowClickListener(this) } override fun initEvent() { @@ -259,9 +243,111 @@ } - override fun onMapLoaded() { - //地图加载成功之后显示聚合点数据 - initClustersMarkers() + private fun displayWellOnMap() { + clusterOverlay?.onDestroy() + val clusterItems = ArrayList() + + wellModels.forEach { + val latitude = it.latGaode.toDouble() + val longitude = it.lngGaode.toDouble() + + val latLng = LatLng(latitude, longitude, false) + val regionItem = RegionItem(latLng, it) + clusterItems.add(regionItem) + } + + clusterOverlay = ClusterOverlay(requireContext(), aMap, clusterItems, regionRadius) + clusterOverlay?.setClusterRender { clusterNum -> + //聚合圆半径 + val radius = 100.dp2px(requireContext()) + if (clusterNum == 0) { + var bitmapDrawable = backDrawables[0] + if (bitmapDrawable == null) { + bitmapDrawable = BitmapDrawable( + null, radius.drawCircle(Color.argb(159, 100, 149, 237)) + ) + backDrawables[0] = bitmapDrawable + } + bitmapDrawable + } + if (clusterNum == 1) { + var bitmapDrawable = backDrawables[1] + if (bitmapDrawable == null) { + bitmapDrawable = R.mipmap.well_location.convertDrawable(requireContext())!! + backDrawables[1] = bitmapDrawable + } + bitmapDrawable + } else if (clusterNum < 5) { + var bitmapDrawable = backDrawables[2] + if (bitmapDrawable == null) { + bitmapDrawable = BitmapDrawable( + null, radius.drawCircle(Color.argb(159, 100, 149, 237)) + ) + backDrawables[2] = bitmapDrawable + } + bitmapDrawable + } else if (clusterNum < 10) { + var bitmapDrawable = backDrawables[3] + if (bitmapDrawable == null) { + bitmapDrawable = BitmapDrawable( + null, radius.drawCircle(Color.argb(199, 30, 144, 255)) + ) + backDrawables[3] = bitmapDrawable + } + bitmapDrawable + } else { + var bitmapDrawable = backDrawables[4] + if (bitmapDrawable == null) { + bitmapDrawable = BitmapDrawable( + null, radius.drawCircle(Color.argb(235, 65, 105, 225)) + ) + backDrawables[4] = bitmapDrawable + } + bitmapDrawable + } + } + + clusterOverlay?.setOnClusterClickListener(object : ClusterOnClickListener { + override fun onMarkerClicked(marker: Marker?, items: List) { + if (items.size > 1) { + "请缩放地图比例在查看数据".show(requireContext()) + return + } + + var item: RegionItem? = null + val builder = LatLngBounds.Builder() + for (clusterItem in items) { + builder.include(clusterItem.position) + item = clusterItem as RegionItem + } + + item?.apply { + showWellPopup(well) + } + } + }) + } + + private fun showWellPopup(well: MapWellListModel.DataModel) { + infoPopup.set(well, object : MapWellPopup.OnPopupWindowClickListener { + override fun onPopupClicked(lat: Double, lng: Double) { + AlertControlDialog.Builder().setContext(requireContext()).setTitle("操作提示") + .setMessage("确定要前往吗").setNegativeButton("取消").setPositiveButton("确定") + .setOnDialogButtonClickListener(object : + AlertControlDialog.OnDialogButtonClickListener { + override fun onConfirmClick() { + RouteOnMap.startNavigation( + requireContext(), "", LatLng(lat, lng) + ) + } + + override fun onCancelClick() { + + } + }).build().show() + } + }) + infoPopup.showAsDropDown(binding.rightOptionView) } override fun onCameraChange(p0: CameraPosition?) { @@ -282,103 +368,10 @@ } } - //获取视野内的marker 根据聚合算法合成自定义的marker 显示视野内的marker override fun onCameraChangeFinish(p0: CameraPosition?) { //地图缩放之后显示聚合点数据 LoadingDialogHub.dismiss() httpCountDownTimer.cancel() - initClustersMarkers() - } - - private fun initClustersMarkers() { - 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 { - v = LayoutInflater.from(requireContext()).inflate(R.layout.popup_map_info, null) - - //显示闸井信息 - marker?.showInfoWindow() - return true - } - - override fun getInfoWindow(marker: Marker?): View { - //反射得到popup里面的控件对象 - val wellNameView = v.findViewById(R.id.wellNameView) - val wellCodeView = v.findViewById(R.id.wellCodeView) - val wellTypeView = v.findViewById(R.id.wellTypeView) - val wellStateView = v.findViewById(R.id.wellStateView) - val deepView = v.findViewById(R.id.deepView) - val locationView = v.findViewById(R.id.locationView) - - //绑定数据 - val clickedLatLng = marker?.position!! - wellModels.forEach { well -> - if (clickedLatLng.latitude == well.latGaode!!.toDouble() - && clickedLatLng.longitude == well.lngGaode!!.toDouble() - ) { - wellNameView.text = String.format("点位名称: ${well.wellName}") - wellCodeView.text = String.format("点位编号: ${well.wellCode}") - wellTypeView.text = String.format("点位类型: ${well.wellType.valueToType()}") - val bfztName = if (well.bfzt == "1") { - "已布防" - } else { - "已撤防" - } - wellStateView.text = String.format("布/撤防状态: $bfztName") - deepView.text = String.format("点位深度: ${well.deep}m") - locationView.text = String.format("详细位置: ${well.position}") - } - } - return v - } - - /** - * 此方法不能修改整个 InfoWindow 的背景和边框,无论自定义的样式是什么样,SDK 都会在最外层添加一个默认的边框 - * */ - override fun getInfoContents(p0: Marker?): View? = null - - override fun onInfoWindowClick(p0: Marker?) { - p0?.apply { - AlertControlDialog.Builder() - .setContext(requireContext()) - .setTitle("操作提示") - .setMessage("确定要前往吗") - .setNegativeButton("取消") - .setPositiveButton("确定") - .setOnDialogButtonClickListener(object : - AlertControlDialog.OnDialogButtonClickListener { - override fun onConfirmClick() { - val lat = position.latitude.toString() - val lng = position.longitude.toString() - if (lat.isBlank() || lng.isBlank()) { - "点位经纬度异常,无法开启导航".show(requireContext()) - return - } - RouteOnMap.startNavigation( - requireContext(), snippet, LatLng(lat.toDouble(), lng.toDouble()) - ) - } - - override fun onCancelClick() { - - } - }).build().show() - } } /***以下是地图生命周期管理************************************************************************/ 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 a54d213..bfa7a57 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 @@ -44,8 +44,8 @@ * 地图点位不带聚合效果 * */ class HomePageNoClusterFragment : KotlinBaseFragment(), - AMap.OnMapLoadedListener, AMap.OnCameraChangeListener, AMap.OnMarkerClickListener, - AMap.InfoWindowAdapter, AMap.OnInfoWindowClickListener { + AMap.OnCameraChangeListener, AMap.OnMarkerClickListener, AMap.InfoWindowAdapter, + AMap.OnInfoWindowClickListener { private val kTag = "NoClusterFragment" private val easyPopupWindow by lazy { EasyPopupWindow(requireContext()) } @@ -109,6 +109,9 @@ wellViewModel = ViewModelProvider(this)[WellViewModel::class.java] orderViewModel = ViewModelProvider(this)[OrderViewModel::class.java] + //地图初始化 + initMap(savedInstanceState) + //获取所有窨井数据 httpCountDownTimer.start() LoadingDialogHub.show(requireActivity(), "数据加载中,请稍后...") @@ -157,12 +160,12 @@ val cameraPosition = CameraPosition(centerLatLng, 16f, 0f, 0f) val cameraUpdate = CameraUpdateFactory.newCameraPosition(cameraPosition) aMap.animateCamera(cameraUpdate, 1500, null) + + //显示点数据 + displayWellOnMap() } } - //地图初始化 - initMap(savedInstanceState) - //获取窨井监控数据 wellViewModel.countResultModel.observe(this) { binding.deployedWellView.text = it["bfWell"] @@ -214,9 +217,8 @@ uiSettings.isCompassEnabled = true uiSettings.zoomPosition = AMapOptions.ZOOM_POSITION_RIGHT_CENTER uiSettings.isTiltGesturesEnabled = false//不许地图随手势倾斜角度 + uiSettings.isRotateGesturesEnabled = false//不允许地图随手势改变方位 - // 地图加载成功监听 - aMap.addOnMapLoadedListener(this) // 地图缩放监听 aMap.addOnCameraChangeListener(this) // marker 点击事件监听 @@ -253,11 +255,6 @@ } - override fun onMapLoaded() { - //地图加载成功之后显示聚合点数据 - initClustersMarkers() - } - override fun onCameraChange(p0: CameraPosition?) { } @@ -281,10 +278,9 @@ //地图缩放之后显示聚合点数据 LoadingDialogHub.dismiss() httpCountDownTimer.cancel() - initClustersMarkers() } - private fun initClustersMarkers() { + private fun displayWellOnMap() { val proj = aMap.projection val dm = resources.displayMetrics var screenLocation: Point diff --git a/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.java b/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.java deleted file mode 100644 index d8b18ef..0000000 --- a/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.java +++ /dev/null @@ -1,50 +0,0 @@ -package com.casic.app.smartwell.model; - -public class ErrorMessageModel { - - private int code; - private String data; - private String exceptionClazz; - private String message; - private boolean success; - - public int getCode() { - return code; - } - - public void setCode(int code) { - this.code = code; - } - - public String getData() { - return data; - } - - public void setData(String data) { - this.data = data; - } - - public String getExceptionClazz() { - return exceptionClazz; - } - - public void setExceptionClazz(String exceptionClazz) { - this.exceptionClazz = exceptionClazz; - } - - public String getMessage() { - return message; - } - - public void setMessage(String message) { - this.message = message; - } - - public boolean isSuccess() { - return success; - } - - public void setSuccess(boolean success) { - this.success = success; - } -} \ No newline at end of file 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 new file mode 100644 index 0000000..215ac0c --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/PipelineModel.java @@ -0,0 +1,328 @@ +package com.casic.app.smartwell.model; + +import java.util.List; + +public class PipelineModel { + + private Integer code; + private DataModel data; + private String message; + private Boolean success; + + public Integer getCode() { + return code; + } + + public void setCode(Integer code) { + this.code = code; + } + + public DataModel getData() { + return data; + } + + public void setData(DataModel data) { + this.data = data; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + public Boolean getSuccess() { + return success; + } + + public void setSuccess(Boolean success) { + this.success = success; + } + + public static class DataModel { + private List rows; + private Integer total; + + public List getRows() { + return rows; + } + + public void setRows(List rows) { + this.rows = rows; + } + + public Integer getTotal() { + return total; + } + + public void setTotal(Integer total) { + this.total = total; + } + + 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 getBuryMode() { + return buryMode; + } + + public void setBuryMode(String buryMode) { + this.buryMode = buryMode; + } + + public String getConstructEra() { + return constructEra; + } + + public void setConstructEra(String constructEra) { + this.constructEra = constructEra; + } + + 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; + } + } + } +} 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 06d3d2b..4f38a2c 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 = 100 //相距多少米才聚合,单位:米 + const val RADIUS_SIZE = 80 //相距多少米才聚合,单位:米 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:11308" + // 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 0d5f3fa..991e1db 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 @@ -312,4 +312,14 @@ @Header("token") token: String, @Field("clientid") deviceCode: String ): String + + /** + * 管线位置数据 + */ + @GET("/pipeline/listPage") + suspend fun getPipeline( + @Header("token") token: String, + @Query("limit") limit: Int, + @Query("offset") offset: Int + ): String } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt index 1a0ce22..4050067 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt @@ -294,4 +294,11 @@ suspend fun registerPush(clientId: String): String { return api.registerPush(AuthenticationHelper.token!!, clientId) } + + /** + * 管线位置数据 + */ + suspend fun getPipeline(): String { + return api.getPipeline(AuthenticationHelper.token!!, 2000, 1) + } } \ No newline at end of file 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 9270fa1..4ca5a5e 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.HomePageNoClusterFragment +import com.casic.app.smartwell.fragment.HomePageHaveClusterFragment 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/vm/AlarmViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/AlarmViewModel.kt index 9cff08c..e7acc17 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/AlarmViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/AlarmViewModel.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.AlarmContentModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager import com.google.gson.Gson @@ -16,7 +16,7 @@ fun getAlarmContentType(alarmType: String) = launch({ val response = RetrofitServiceManager.getAlarmContentType(alarmType) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { listModel.value = gson.fromJson( response, object : TypeToken() {}.type diff --git a/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt index 5e5b163..895dedd 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.PublicKeyModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager import com.google.gson.Gson @@ -18,7 +18,7 @@ fun getPublicKey() = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.authenticate() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { keyModel.value = gson.fromJson( response, object : TypeToken() {}.type diff --git a/app/src/main/java/com/casic/app/smartwell/vm/DeviceViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/DeviceViewModel.kt index db5ccf6..899a962 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/DeviceViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/DeviceViewModel.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.DeviceDetailModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager import com.google.gson.Gson @@ -16,7 +16,7 @@ fun getDeviceDetail(deviceCode: String) = launch({ val response = RetrofitServiceManager.getDeviceDetail(deviceCode) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { detailModel.value = gson.fromJson( response, object : TypeToken() {}.type diff --git a/app/src/main/java/com/casic/app/smartwell/vm/LoginViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/LoginViewModel.kt index cd8b8a9..a417398 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/LoginViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/LoginViewModel.kt @@ -2,7 +2,7 @@ import androidx.lifecycle.MutableLiveData import com.casic.app.smartwell.base.BaseApplication -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.CommonResultModel import com.casic.app.smartwell.model.LoginResultModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -21,7 +21,7 @@ fun enter(account: String, secretKey: String) = launch({ val response = RetrofitServiceManager.login(account, secretKey) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success enterResultModel.value = gson.fromJson( @@ -38,7 +38,7 @@ fun out() = launch({ val response = RetrofitServiceManager.loginOut() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { outResultModel.value = gson.fromJson( response, object : TypeToken() {}.type diff --git a/app/src/main/java/com/casic/app/smartwell/vm/OperationViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/OperationViewModel.kt index 8943ed3..37e115f 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/OperationViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/OperationViewModel.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.vm import com.casic.app.smartwell.base.BaseApplication -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager import com.pengxh.kt.lite.base.BaseViewModel import com.pengxh.kt.lite.extensions.launch @@ -16,7 +16,7 @@ fun acceptWorkOrder(id: String) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.acceptWorkOrder(id) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success "接单成功".show(BaseApplication.get()) @@ -35,7 +35,7 @@ loadState.value = LoadState.Loading val response = RetrofitServiceManager.confirmWorkOrder(id, firstState, firstStatePhotos, needHandle) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success "工单确认成功".show(BaseApplication.get()) @@ -50,7 +50,7 @@ fun transferWorkOrder(id: String, userId: String) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.transferWorkOrder(id, userId) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success "转单成功".show(BaseApplication.get()) @@ -65,7 +65,7 @@ fun completeWorkOrder(id: String, handleMessage: String, handlePhotos: String) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.completeWorkOrder(id, handleMessage, handlePhotos) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success "工单处理成功".show(BaseApplication.get()) diff --git a/app/src/main/java/com/casic/app/smartwell/vm/OrderViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/OrderViewModel.kt index 4cb26b7..d2fad86 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/OrderViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/OrderViewModel.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.OrderDetailModel import com.casic.app.smartwell.model.OrderListModel import com.casic.app.smartwell.model.OrderStatusModel @@ -37,7 +37,7 @@ val response = RetrofitServiceManager.getSearchResult( keywords, alarmContent, alarmLevel, jobStatus, deptId, beginTime, endTime, offset ) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success searchResult.value = gson.fromJson( @@ -53,7 +53,7 @@ fun getWorkOrderListByState(jobStatus: String, page: Int) = launch({ val response = RetrofitServiceManager.getWorkOrderList(jobStatus, page) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { orderList.value = gson.fromJson( response, object : TypeToken() {}.type @@ -65,7 +65,7 @@ fun getNotAcceptOderList(page: Int) = launch({ val response = RetrofitServiceManager.getNotAcceptOderList(page) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { orderList.value = gson.fromJson( response, object : TypeToken() {}.type @@ -77,7 +77,7 @@ fun getNotHandleOderList(page: Int) = launch({ val response = RetrofitServiceManager.getNotHandleOderList(page) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { orderList.value = gson.fromJson( response, object : TypeToken() {}.type @@ -89,7 +89,7 @@ fun countWorkOrderByState() = launch({ val response = RetrofitServiceManager.countWorkOrderByState() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { val map = HashMap(4) @@ -107,7 +107,7 @@ fun getOrderStatus() = launch({ val response = RetrofitServiceManager.getOrderStatus() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { orderStatusModel.value = gson.fromJson( response, object : TypeToken() {}.type @@ -120,7 +120,7 @@ fun getWorkOrderDetail(id: String) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.getWorkOrderDetail(id) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success detailModel.value = gson.fromJson( diff --git a/app/src/main/java/com/casic/app/smartwell/vm/PipelineViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/PipelineViewModel.kt new file mode 100644 index 0000000..60c1e2f --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/vm/PipelineViewModel.kt @@ -0,0 +1,28 @@ +package com.casic.app.smartwell.vm + +import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.extensions.getResponseCode +import com.casic.app.smartwell.model.PipelineModel +import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken +import com.pengxh.kt.lite.base.BaseViewModel +import com.pengxh.kt.lite.extensions.launch + +class PipelineViewModel : BaseViewModel() { + + private val gson by lazy { Gson() } + val lineResult = MutableLiveData() + + fun getPipeline() = launch({ + val response = RetrofitServiceManager.getPipeline() + val responseCode = response.getResponseCode() + if (responseCode == 200) { + lineResult.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } + }, { + it.printStackTrace() + }) +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/PushViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/PushViewModel.kt index 9279815..12fd610 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/PushViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/PushViewModel.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.CommonResultModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager import com.google.gson.Gson @@ -16,7 +16,7 @@ fun registerPush(clientId: String) = launch({ val response = RetrofitServiceManager.registerPush(clientId) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { registerResultModel.value = gson.fromJson( response, object : TypeToken() {}.type diff --git a/app/src/main/java/com/casic/app/smartwell/vm/UploadImageViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/UploadImageViewModel.kt index 8d6744e..9707eeb 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/UploadImageViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/UploadImageViewModel.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.CommonResultModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager import com.google.gson.Gson @@ -19,7 +19,7 @@ fun uploadImage(image: File) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.uploadImage(image) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success resultModel.value = gson.fromJson( diff --git a/app/src/main/java/com/casic/app/smartwell/extensions/Int.kt b/app/src/main/java/com/casic/app/smartwell/extensions/Int.kt index de0617b..a0a5e33 100644 --- a/app/src/main/java/com/casic/app/smartwell/extensions/Int.kt +++ b/app/src/main/java/com/casic/app/smartwell/extensions/Int.kt @@ -1,9 +1,24 @@ package com.casic.app.smartwell.extensions +import android.graphics.Bitmap +import android.graphics.Canvas +import android.graphics.Paint +import android.graphics.RectF + fun Int.toLevel(): String { return if (this == 0) { "" } else { this.toString() } +} + +fun Int.drawCircle(color: Int): Bitmap? { + val bitmap = Bitmap.createBitmap(this * 2, this * 2, Bitmap.Config.ARGB_8888) + val canvas = Canvas(bitmap) + val paint = Paint() + val rectF = RectF(0f, 0f, (this * 2).toFloat(), (this * 2).toFloat()) + paint.color = color + canvas.drawArc(rectF, 0f, 360f, true, paint) + return bitmap } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt index 6b6ca3e..5e45534 100644 --- a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt +++ b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt @@ -2,17 +2,13 @@ import android.content.Context import com.casic.app.smartwell.callback.OnImageCompressListener -import com.casic.app.smartwell.model.ErrorMessageModel import com.casic.app.smartwell.utils.LocaleConstant -import com.google.gson.Gson -import com.google.gson.reflect.TypeToken +import com.google.gson.JsonParser import com.pengxh.kt.lite.extensions.createCompressImageDir import com.pengxh.kt.lite.utils.SaveKeyValues -import org.json.JSONObject import top.zibin.luban.Luban import top.zibin.luban.OnCompressListener import java.io.File -import java.util.Locale /** * String扩展方法 @@ -74,18 +70,22 @@ } } -fun String.separateResponseCode(): Int { +fun String.getResponseCode(): Int { if (this.isBlank()) { return 404 } - return JSONObject(this).getInt("code") + val element = JsonParser.parseString(this) + val jsonObject = element.asJsonObject + return jsonObject.get("code").asInt } -fun String.toErrorMessage(): String { - val errorModel = Gson().fromJson( - this, object : TypeToken() {}.type - ) - return errorModel.message.toString() +fun String.getResponseMessage(): String { + if (this.isBlank()) { + return "" + } + val element = JsonParser.parseString(this) + val jsonObject = element.asJsonObject + return jsonObject.get("message").asString } fun String.compressImage(context: Context, listener: OnImageCompressListener) { @@ -93,9 +93,6 @@ .load(this) .ignoreBy(100) .setTargetDir(context.createCompressImageDir().toString()) - .filter { - !(it.isBlank() || it.lowercase(Locale.getDefault()).endsWith(".gif")) - } .setCompressListener(object : OnCompressListener { override fun onStart() { 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 96df110..cd25fca 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 @@ -1,26 +1,25 @@ package com.casic.app.smartwell.fragment -import android.graphics.Point +import android.graphics.Color +import android.graphics.drawable.BitmapDrawable +import android.graphics.drawable.Drawable 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 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.LatLngBounds import com.amap.api.maps.model.Marker -import com.amap.api.maps.model.MarkerOptions import com.casic.app.smartwell.R import com.casic.app.smartwell.databinding.FragmentHomeBinding +import com.casic.app.smartwell.extensions.drawCircle import com.casic.app.smartwell.extensions.initImmersionBar -import com.casic.app.smartwell.extensions.valueToType import com.casic.app.smartwell.model.MapWellListModel import com.casic.app.smartwell.utils.LocaleConstant import com.casic.app.smartwell.utils.RouteOnMap @@ -31,9 +30,16 @@ import com.casic.app.smartwell.view.WellOperationActivity import com.casic.app.smartwell.vm.OrderViewModel import com.casic.app.smartwell.vm.WellViewModel +import com.casic.app.smartwell.widgets.MapWellPopup +import com.casic.app.smartwell.widgets.cluster.ClusterItem +import com.casic.app.smartwell.widgets.cluster.ClusterOnClickListener +import com.casic.app.smartwell.widgets.cluster.ClusterOverlay +import com.casic.app.smartwell.widgets.cluster.RegionItem 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.convertDrawable +import com.pengxh.kt.lite.extensions.dp2px import com.pengxh.kt.lite.extensions.navigatePageTo import com.pengxh.kt.lite.extensions.show import com.pengxh.kt.lite.utils.LoadingDialogHub @@ -43,35 +49,23 @@ /** * 地图点位带聚合效果 * */ -class HomePageHaveClusterFragment : KotlinBaseFragment(), AMap.OnMapLoadedListener, - AMap.OnCameraChangeListener, AMap.OnMarkerClickListener, AMap.InfoWindowAdapter, - AMap.OnInfoWindowClickListener { +class HomePageHaveClusterFragment : KotlinBaseFragment(), + AMap.OnCameraChangeListener { private val kTag = "HaveClusterFragment" private val easyPopupWindow by lazy { EasyPopupWindow(requireContext()) } - private lateinit var wellViewModel: WellViewModel - private lateinit var orderViewModel: OrderViewModel - private lateinit var aMap: AMap - - /** - * 所有的marker - */ - private var allMarkerOptions: MutableList = ArrayList() - - /** - * 视野内的marker - */ - private var markerOptionsInView: MutableList = ArrayList() - - /** - * 自定义Marker弹出框 - * */ - private lateinit var v: View + private val regionRadius by lazy { LocaleConstant.RADIUS_SIZE.dp2px(requireContext()) } + private val infoPopup by lazy { MapWellPopup(requireContext()) } /** * 所有窨井列表信息集合 * */ - private var wellModels: MutableList = ArrayList() + private val wellModels = ArrayList() + private val backDrawables = HashMap() + private lateinit var wellViewModel: WellViewModel + private lateinit var orderViewModel: OrderViewModel + private lateinit var aMap: AMap + private var clusterOverlay: ClusterOverlay? = null override fun initViewBinding( inflater: LayoutInflater, @@ -106,6 +100,9 @@ } }) + //地图初始化 + initMap(savedInstanceState) + //初始化vm wellViewModel = ViewModelProvider(this)[WellViewModel::class.java] orderViewModel = ViewModelProvider(this)[OrderViewModel::class.java] @@ -120,25 +117,19 @@ val latitudeList: MutableList = ArrayList() val longitudeList: MutableList = ArrayList() it.data?.forEach { well -> - val lat = well.latGaode.toString() - val lng = well.lngGaode.toString() + val lat = well.latGaode + val lng = well.lngGaode if (lat.isNotBlank() && lng.isNotBlank()) { //返回true代表当前位置在大陆、港澳地区,反之不在 val latitude = lat.toDouble() val longitude = lng.toDouble() if (CoordinateConverter.isAMapDataAvailable(latitude, longitude)) { - //缓存所有设备详情,点击Marker时候需要 + //缓存所有井 wellModels.add(well) + //分别缓存经、纬度 latitudeList.add(latitude) longitudeList.add(longitude) - //将所有设备信息转化缓存为Marker点 - allMarkerOptions.add( - MarkerOptions() - .position(LatLng(latitude, longitude)) - .title(well.wellTypeName) - .snippet(well.wellName) - ) } } } @@ -160,12 +151,12 @@ val cameraPosition = CameraPosition(centerLatLng, 16f, 0f, 0f) val cameraUpdate = CameraUpdateFactory.newCameraPosition(cameraPosition) aMap.animateCamera(cameraUpdate, 1500, null) + + //显示点数据 + displayWellOnMap() } } - //地图初始化 - initMap(savedInstanceState) - //获取窨井监控数据 wellViewModel.countResultModel.observe(this) { binding.deployedWellView.text = it["bfWell"] @@ -220,17 +211,10 @@ uiSettings.isCompassEnabled = true uiSettings.zoomPosition = AMapOptions.ZOOM_POSITION_RIGHT_CENTER uiSettings.isTiltGesturesEnabled = false//不许地图随手势倾斜角度 + uiSettings.isRotateGesturesEnabled = false//不允许地图随手势改变方位 - // 地图加载成功监听 - aMap.addOnMapLoadedListener(this) // 地图缩放监听 aMap.addOnCameraChangeListener(this) - // marker 点击事件监听 - aMap.addOnMarkerClickListener(this) - // 点击marker弹出自定义popup - aMap.setInfoWindowAdapter(this) - //信息窗点击事件 - aMap.addOnInfoWindowClickListener(this) } override fun initEvent() { @@ -259,9 +243,111 @@ } - override fun onMapLoaded() { - //地图加载成功之后显示聚合点数据 - initClustersMarkers() + private fun displayWellOnMap() { + clusterOverlay?.onDestroy() + val clusterItems = ArrayList() + + wellModels.forEach { + val latitude = it.latGaode.toDouble() + val longitude = it.lngGaode.toDouble() + + val latLng = LatLng(latitude, longitude, false) + val regionItem = RegionItem(latLng, it) + clusterItems.add(regionItem) + } + + clusterOverlay = ClusterOverlay(requireContext(), aMap, clusterItems, regionRadius) + clusterOverlay?.setClusterRender { clusterNum -> + //聚合圆半径 + val radius = 100.dp2px(requireContext()) + if (clusterNum == 0) { + var bitmapDrawable = backDrawables[0] + if (bitmapDrawable == null) { + bitmapDrawable = BitmapDrawable( + null, radius.drawCircle(Color.argb(159, 100, 149, 237)) + ) + backDrawables[0] = bitmapDrawable + } + bitmapDrawable + } + if (clusterNum == 1) { + var bitmapDrawable = backDrawables[1] + if (bitmapDrawable == null) { + bitmapDrawable = R.mipmap.well_location.convertDrawable(requireContext())!! + backDrawables[1] = bitmapDrawable + } + bitmapDrawable + } else if (clusterNum < 5) { + var bitmapDrawable = backDrawables[2] + if (bitmapDrawable == null) { + bitmapDrawable = BitmapDrawable( + null, radius.drawCircle(Color.argb(159, 100, 149, 237)) + ) + backDrawables[2] = bitmapDrawable + } + bitmapDrawable + } else if (clusterNum < 10) { + var bitmapDrawable = backDrawables[3] + if (bitmapDrawable == null) { + bitmapDrawable = BitmapDrawable( + null, radius.drawCircle(Color.argb(199, 30, 144, 255)) + ) + backDrawables[3] = bitmapDrawable + } + bitmapDrawable + } else { + var bitmapDrawable = backDrawables[4] + if (bitmapDrawable == null) { + bitmapDrawable = BitmapDrawable( + null, radius.drawCircle(Color.argb(235, 65, 105, 225)) + ) + backDrawables[4] = bitmapDrawable + } + bitmapDrawable + } + } + + clusterOverlay?.setOnClusterClickListener(object : ClusterOnClickListener { + override fun onMarkerClicked(marker: Marker?, items: List) { + if (items.size > 1) { + "请缩放地图比例在查看数据".show(requireContext()) + return + } + + var item: RegionItem? = null + val builder = LatLngBounds.Builder() + for (clusterItem in items) { + builder.include(clusterItem.position) + item = clusterItem as RegionItem + } + + item?.apply { + showWellPopup(well) + } + } + }) + } + + private fun showWellPopup(well: MapWellListModel.DataModel) { + infoPopup.set(well, object : MapWellPopup.OnPopupWindowClickListener { + override fun onPopupClicked(lat: Double, lng: Double) { + AlertControlDialog.Builder().setContext(requireContext()).setTitle("操作提示") + .setMessage("确定要前往吗").setNegativeButton("取消").setPositiveButton("确定") + .setOnDialogButtonClickListener(object : + AlertControlDialog.OnDialogButtonClickListener { + override fun onConfirmClick() { + RouteOnMap.startNavigation( + requireContext(), "", LatLng(lat, lng) + ) + } + + override fun onCancelClick() { + + } + }).build().show() + } + }) + infoPopup.showAsDropDown(binding.rightOptionView) } override fun onCameraChange(p0: CameraPosition?) { @@ -282,103 +368,10 @@ } } - //获取视野内的marker 根据聚合算法合成自定义的marker 显示视野内的marker override fun onCameraChangeFinish(p0: CameraPosition?) { //地图缩放之后显示聚合点数据 LoadingDialogHub.dismiss() httpCountDownTimer.cancel() - initClustersMarkers() - } - - private fun initClustersMarkers() { - 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 { - v = LayoutInflater.from(requireContext()).inflate(R.layout.popup_map_info, null) - - //显示闸井信息 - marker?.showInfoWindow() - return true - } - - override fun getInfoWindow(marker: Marker?): View { - //反射得到popup里面的控件对象 - val wellNameView = v.findViewById(R.id.wellNameView) - val wellCodeView = v.findViewById(R.id.wellCodeView) - val wellTypeView = v.findViewById(R.id.wellTypeView) - val wellStateView = v.findViewById(R.id.wellStateView) - val deepView = v.findViewById(R.id.deepView) - val locationView = v.findViewById(R.id.locationView) - - //绑定数据 - val clickedLatLng = marker?.position!! - wellModels.forEach { well -> - if (clickedLatLng.latitude == well.latGaode!!.toDouble() - && clickedLatLng.longitude == well.lngGaode!!.toDouble() - ) { - wellNameView.text = String.format("点位名称: ${well.wellName}") - wellCodeView.text = String.format("点位编号: ${well.wellCode}") - wellTypeView.text = String.format("点位类型: ${well.wellType.valueToType()}") - val bfztName = if (well.bfzt == "1") { - "已布防" - } else { - "已撤防" - } - wellStateView.text = String.format("布/撤防状态: $bfztName") - deepView.text = String.format("点位深度: ${well.deep}m") - locationView.text = String.format("详细位置: ${well.position}") - } - } - return v - } - - /** - * 此方法不能修改整个 InfoWindow 的背景和边框,无论自定义的样式是什么样,SDK 都会在最外层添加一个默认的边框 - * */ - override fun getInfoContents(p0: Marker?): View? = null - - override fun onInfoWindowClick(p0: Marker?) { - p0?.apply { - AlertControlDialog.Builder() - .setContext(requireContext()) - .setTitle("操作提示") - .setMessage("确定要前往吗") - .setNegativeButton("取消") - .setPositiveButton("确定") - .setOnDialogButtonClickListener(object : - AlertControlDialog.OnDialogButtonClickListener { - override fun onConfirmClick() { - val lat = position.latitude.toString() - val lng = position.longitude.toString() - if (lat.isBlank() || lng.isBlank()) { - "点位经纬度异常,无法开启导航".show(requireContext()) - return - } - RouteOnMap.startNavigation( - requireContext(), snippet, LatLng(lat.toDouble(), lng.toDouble()) - ) - } - - override fun onCancelClick() { - - } - }).build().show() - } } /***以下是地图生命周期管理************************************************************************/ 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 a54d213..bfa7a57 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 @@ -44,8 +44,8 @@ * 地图点位不带聚合效果 * */ class HomePageNoClusterFragment : KotlinBaseFragment(), - AMap.OnMapLoadedListener, AMap.OnCameraChangeListener, AMap.OnMarkerClickListener, - AMap.InfoWindowAdapter, AMap.OnInfoWindowClickListener { + AMap.OnCameraChangeListener, AMap.OnMarkerClickListener, AMap.InfoWindowAdapter, + AMap.OnInfoWindowClickListener { private val kTag = "NoClusterFragment" private val easyPopupWindow by lazy { EasyPopupWindow(requireContext()) } @@ -109,6 +109,9 @@ wellViewModel = ViewModelProvider(this)[WellViewModel::class.java] orderViewModel = ViewModelProvider(this)[OrderViewModel::class.java] + //地图初始化 + initMap(savedInstanceState) + //获取所有窨井数据 httpCountDownTimer.start() LoadingDialogHub.show(requireActivity(), "数据加载中,请稍后...") @@ -157,12 +160,12 @@ val cameraPosition = CameraPosition(centerLatLng, 16f, 0f, 0f) val cameraUpdate = CameraUpdateFactory.newCameraPosition(cameraPosition) aMap.animateCamera(cameraUpdate, 1500, null) + + //显示点数据 + displayWellOnMap() } } - //地图初始化 - initMap(savedInstanceState) - //获取窨井监控数据 wellViewModel.countResultModel.observe(this) { binding.deployedWellView.text = it["bfWell"] @@ -214,9 +217,8 @@ uiSettings.isCompassEnabled = true uiSettings.zoomPosition = AMapOptions.ZOOM_POSITION_RIGHT_CENTER uiSettings.isTiltGesturesEnabled = false//不许地图随手势倾斜角度 + uiSettings.isRotateGesturesEnabled = false//不允许地图随手势改变方位 - // 地图加载成功监听 - aMap.addOnMapLoadedListener(this) // 地图缩放监听 aMap.addOnCameraChangeListener(this) // marker 点击事件监听 @@ -253,11 +255,6 @@ } - override fun onMapLoaded() { - //地图加载成功之后显示聚合点数据 - initClustersMarkers() - } - override fun onCameraChange(p0: CameraPosition?) { } @@ -281,10 +278,9 @@ //地图缩放之后显示聚合点数据 LoadingDialogHub.dismiss() httpCountDownTimer.cancel() - initClustersMarkers() } - private fun initClustersMarkers() { + private fun displayWellOnMap() { val proj = aMap.projection val dm = resources.displayMetrics var screenLocation: Point diff --git a/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.java b/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.java deleted file mode 100644 index d8b18ef..0000000 --- a/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.java +++ /dev/null @@ -1,50 +0,0 @@ -package com.casic.app.smartwell.model; - -public class ErrorMessageModel { - - private int code; - private String data; - private String exceptionClazz; - private String message; - private boolean success; - - public int getCode() { - return code; - } - - public void setCode(int code) { - this.code = code; - } - - public String getData() { - return data; - } - - public void setData(String data) { - this.data = data; - } - - public String getExceptionClazz() { - return exceptionClazz; - } - - public void setExceptionClazz(String exceptionClazz) { - this.exceptionClazz = exceptionClazz; - } - - public String getMessage() { - return message; - } - - public void setMessage(String message) { - this.message = message; - } - - public boolean isSuccess() { - return success; - } - - public void setSuccess(boolean success) { - this.success = success; - } -} \ No newline at end of file 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 new file mode 100644 index 0000000..215ac0c --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/PipelineModel.java @@ -0,0 +1,328 @@ +package com.casic.app.smartwell.model; + +import java.util.List; + +public class PipelineModel { + + private Integer code; + private DataModel data; + private String message; + private Boolean success; + + public Integer getCode() { + return code; + } + + public void setCode(Integer code) { + this.code = code; + } + + public DataModel getData() { + return data; + } + + public void setData(DataModel data) { + this.data = data; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + public Boolean getSuccess() { + return success; + } + + public void setSuccess(Boolean success) { + this.success = success; + } + + public static class DataModel { + private List rows; + private Integer total; + + public List getRows() { + return rows; + } + + public void setRows(List rows) { + this.rows = rows; + } + + public Integer getTotal() { + return total; + } + + public void setTotal(Integer total) { + this.total = total; + } + + 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 getBuryMode() { + return buryMode; + } + + public void setBuryMode(String buryMode) { + this.buryMode = buryMode; + } + + public String getConstructEra() { + return constructEra; + } + + public void setConstructEra(String constructEra) { + this.constructEra = constructEra; + } + + 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; + } + } + } +} 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 06d3d2b..4f38a2c 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 = 100 //相距多少米才聚合,单位:米 + const val RADIUS_SIZE = 80 //相距多少米才聚合,单位:米 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:11308" + // 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 0d5f3fa..991e1db 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 @@ -312,4 +312,14 @@ @Header("token") token: String, @Field("clientid") deviceCode: String ): String + + /** + * 管线位置数据 + */ + @GET("/pipeline/listPage") + suspend fun getPipeline( + @Header("token") token: String, + @Query("limit") limit: Int, + @Query("offset") offset: Int + ): String } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt index 1a0ce22..4050067 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt @@ -294,4 +294,11 @@ suspend fun registerPush(clientId: String): String { return api.registerPush(AuthenticationHelper.token!!, clientId) } + + /** + * 管线位置数据 + */ + suspend fun getPipeline(): String { + return api.getPipeline(AuthenticationHelper.token!!, 2000, 1) + } } \ No newline at end of file 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 9270fa1..4ca5a5e 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.HomePageNoClusterFragment +import com.casic.app.smartwell.fragment.HomePageHaveClusterFragment 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/vm/AlarmViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/AlarmViewModel.kt index 9cff08c..e7acc17 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/AlarmViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/AlarmViewModel.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.AlarmContentModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager import com.google.gson.Gson @@ -16,7 +16,7 @@ fun getAlarmContentType(alarmType: String) = launch({ val response = RetrofitServiceManager.getAlarmContentType(alarmType) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { listModel.value = gson.fromJson( response, object : TypeToken() {}.type diff --git a/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt index 5e5b163..895dedd 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.PublicKeyModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager import com.google.gson.Gson @@ -18,7 +18,7 @@ fun getPublicKey() = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.authenticate() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { keyModel.value = gson.fromJson( response, object : TypeToken() {}.type diff --git a/app/src/main/java/com/casic/app/smartwell/vm/DeviceViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/DeviceViewModel.kt index db5ccf6..899a962 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/DeviceViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/DeviceViewModel.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.DeviceDetailModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager import com.google.gson.Gson @@ -16,7 +16,7 @@ fun getDeviceDetail(deviceCode: String) = launch({ val response = RetrofitServiceManager.getDeviceDetail(deviceCode) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { detailModel.value = gson.fromJson( response, object : TypeToken() {}.type diff --git a/app/src/main/java/com/casic/app/smartwell/vm/LoginViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/LoginViewModel.kt index cd8b8a9..a417398 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/LoginViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/LoginViewModel.kt @@ -2,7 +2,7 @@ import androidx.lifecycle.MutableLiveData import com.casic.app.smartwell.base.BaseApplication -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.CommonResultModel import com.casic.app.smartwell.model.LoginResultModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -21,7 +21,7 @@ fun enter(account: String, secretKey: String) = launch({ val response = RetrofitServiceManager.login(account, secretKey) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success enterResultModel.value = gson.fromJson( @@ -38,7 +38,7 @@ fun out() = launch({ val response = RetrofitServiceManager.loginOut() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { outResultModel.value = gson.fromJson( response, object : TypeToken() {}.type diff --git a/app/src/main/java/com/casic/app/smartwell/vm/OperationViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/OperationViewModel.kt index 8943ed3..37e115f 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/OperationViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/OperationViewModel.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.vm import com.casic.app.smartwell.base.BaseApplication -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager import com.pengxh.kt.lite.base.BaseViewModel import com.pengxh.kt.lite.extensions.launch @@ -16,7 +16,7 @@ fun acceptWorkOrder(id: String) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.acceptWorkOrder(id) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success "接单成功".show(BaseApplication.get()) @@ -35,7 +35,7 @@ loadState.value = LoadState.Loading val response = RetrofitServiceManager.confirmWorkOrder(id, firstState, firstStatePhotos, needHandle) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success "工单确认成功".show(BaseApplication.get()) @@ -50,7 +50,7 @@ fun transferWorkOrder(id: String, userId: String) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.transferWorkOrder(id, userId) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success "转单成功".show(BaseApplication.get()) @@ -65,7 +65,7 @@ fun completeWorkOrder(id: String, handleMessage: String, handlePhotos: String) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.completeWorkOrder(id, handleMessage, handlePhotos) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success "工单处理成功".show(BaseApplication.get()) diff --git a/app/src/main/java/com/casic/app/smartwell/vm/OrderViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/OrderViewModel.kt index 4cb26b7..d2fad86 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/OrderViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/OrderViewModel.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.OrderDetailModel import com.casic.app.smartwell.model.OrderListModel import com.casic.app.smartwell.model.OrderStatusModel @@ -37,7 +37,7 @@ val response = RetrofitServiceManager.getSearchResult( keywords, alarmContent, alarmLevel, jobStatus, deptId, beginTime, endTime, offset ) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success searchResult.value = gson.fromJson( @@ -53,7 +53,7 @@ fun getWorkOrderListByState(jobStatus: String, page: Int) = launch({ val response = RetrofitServiceManager.getWorkOrderList(jobStatus, page) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { orderList.value = gson.fromJson( response, object : TypeToken() {}.type @@ -65,7 +65,7 @@ fun getNotAcceptOderList(page: Int) = launch({ val response = RetrofitServiceManager.getNotAcceptOderList(page) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { orderList.value = gson.fromJson( response, object : TypeToken() {}.type @@ -77,7 +77,7 @@ fun getNotHandleOderList(page: Int) = launch({ val response = RetrofitServiceManager.getNotHandleOderList(page) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { orderList.value = gson.fromJson( response, object : TypeToken() {}.type @@ -89,7 +89,7 @@ fun countWorkOrderByState() = launch({ val response = RetrofitServiceManager.countWorkOrderByState() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { val map = HashMap(4) @@ -107,7 +107,7 @@ fun getOrderStatus() = launch({ val response = RetrofitServiceManager.getOrderStatus() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { orderStatusModel.value = gson.fromJson( response, object : TypeToken() {}.type @@ -120,7 +120,7 @@ fun getWorkOrderDetail(id: String) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.getWorkOrderDetail(id) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success detailModel.value = gson.fromJson( diff --git a/app/src/main/java/com/casic/app/smartwell/vm/PipelineViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/PipelineViewModel.kt new file mode 100644 index 0000000..60c1e2f --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/vm/PipelineViewModel.kt @@ -0,0 +1,28 @@ +package com.casic.app.smartwell.vm + +import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.extensions.getResponseCode +import com.casic.app.smartwell.model.PipelineModel +import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken +import com.pengxh.kt.lite.base.BaseViewModel +import com.pengxh.kt.lite.extensions.launch + +class PipelineViewModel : BaseViewModel() { + + private val gson by lazy { Gson() } + val lineResult = MutableLiveData() + + fun getPipeline() = launch({ + val response = RetrofitServiceManager.getPipeline() + val responseCode = response.getResponseCode() + if (responseCode == 200) { + lineResult.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } + }, { + it.printStackTrace() + }) +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/PushViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/PushViewModel.kt index 9279815..12fd610 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/PushViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/PushViewModel.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.CommonResultModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager import com.google.gson.Gson @@ -16,7 +16,7 @@ fun registerPush(clientId: String) = launch({ val response = RetrofitServiceManager.registerPush(clientId) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { registerResultModel.value = gson.fromJson( response, object : TypeToken() {}.type diff --git a/app/src/main/java/com/casic/app/smartwell/vm/UploadImageViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/UploadImageViewModel.kt index 8d6744e..9707eeb 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/UploadImageViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/UploadImageViewModel.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.CommonResultModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager import com.google.gson.Gson @@ -19,7 +19,7 @@ fun uploadImage(image: File) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.uploadImage(image) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success resultModel.value = gson.fromJson( diff --git a/app/src/main/java/com/casic/app/smartwell/vm/UserViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/UserViewModel.kt index 31a4d4c..070c35a 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/UserViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/UserViewModel.kt @@ -2,7 +2,7 @@ import androidx.lifecycle.MutableLiveData import com.casic.app.smartwell.base.BaseApplication -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.SubordinateModel import com.casic.app.smartwell.model.UserDetailModel import com.casic.app.smartwell.model.VersionResultModel @@ -25,7 +25,7 @@ fun getUserDetail() = launch({ val response = RetrofitServiceManager.getUserDetail() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { val userDetail = gson.fromJson( response, object : TypeToken() {}.type @@ -48,7 +48,7 @@ * */ fun getSubordinate(hasMine: String?, deptId: String?, roleTips: String?) = launch({ val response = RetrofitServiceManager.getSubordinate(hasMine, deptId, roleTips) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { subordinateModel.value = gson.fromJson( response, object : TypeToken() {}.type @@ -61,7 +61,7 @@ fun changePassword(oldPwd: String, newPwd: String) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.changePassword(oldPwd, newPwd) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success "修改成功,请重新登录".show(BaseApplication.get()) @@ -76,7 +76,7 @@ fun updateVersion() = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.updateVersion() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success versionResultModel.value = gson.fromJson( diff --git a/app/src/main/java/com/casic/app/smartwell/extensions/Int.kt b/app/src/main/java/com/casic/app/smartwell/extensions/Int.kt index de0617b..a0a5e33 100644 --- a/app/src/main/java/com/casic/app/smartwell/extensions/Int.kt +++ b/app/src/main/java/com/casic/app/smartwell/extensions/Int.kt @@ -1,9 +1,24 @@ package com.casic.app.smartwell.extensions +import android.graphics.Bitmap +import android.graphics.Canvas +import android.graphics.Paint +import android.graphics.RectF + fun Int.toLevel(): String { return if (this == 0) { "" } else { this.toString() } +} + +fun Int.drawCircle(color: Int): Bitmap? { + val bitmap = Bitmap.createBitmap(this * 2, this * 2, Bitmap.Config.ARGB_8888) + val canvas = Canvas(bitmap) + val paint = Paint() + val rectF = RectF(0f, 0f, (this * 2).toFloat(), (this * 2).toFloat()) + paint.color = color + canvas.drawArc(rectF, 0f, 360f, true, paint) + return bitmap } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt index 6b6ca3e..5e45534 100644 --- a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt +++ b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt @@ -2,17 +2,13 @@ import android.content.Context import com.casic.app.smartwell.callback.OnImageCompressListener -import com.casic.app.smartwell.model.ErrorMessageModel import com.casic.app.smartwell.utils.LocaleConstant -import com.google.gson.Gson -import com.google.gson.reflect.TypeToken +import com.google.gson.JsonParser import com.pengxh.kt.lite.extensions.createCompressImageDir import com.pengxh.kt.lite.utils.SaveKeyValues -import org.json.JSONObject import top.zibin.luban.Luban import top.zibin.luban.OnCompressListener import java.io.File -import java.util.Locale /** * String扩展方法 @@ -74,18 +70,22 @@ } } -fun String.separateResponseCode(): Int { +fun String.getResponseCode(): Int { if (this.isBlank()) { return 404 } - return JSONObject(this).getInt("code") + val element = JsonParser.parseString(this) + val jsonObject = element.asJsonObject + return jsonObject.get("code").asInt } -fun String.toErrorMessage(): String { - val errorModel = Gson().fromJson( - this, object : TypeToken() {}.type - ) - return errorModel.message.toString() +fun String.getResponseMessage(): String { + if (this.isBlank()) { + return "" + } + val element = JsonParser.parseString(this) + val jsonObject = element.asJsonObject + return jsonObject.get("message").asString } fun String.compressImage(context: Context, listener: OnImageCompressListener) { @@ -93,9 +93,6 @@ .load(this) .ignoreBy(100) .setTargetDir(context.createCompressImageDir().toString()) - .filter { - !(it.isBlank() || it.lowercase(Locale.getDefault()).endsWith(".gif")) - } .setCompressListener(object : OnCompressListener { override fun onStart() { 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 96df110..cd25fca 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 @@ -1,26 +1,25 @@ package com.casic.app.smartwell.fragment -import android.graphics.Point +import android.graphics.Color +import android.graphics.drawable.BitmapDrawable +import android.graphics.drawable.Drawable 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 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.LatLngBounds import com.amap.api.maps.model.Marker -import com.amap.api.maps.model.MarkerOptions import com.casic.app.smartwell.R import com.casic.app.smartwell.databinding.FragmentHomeBinding +import com.casic.app.smartwell.extensions.drawCircle import com.casic.app.smartwell.extensions.initImmersionBar -import com.casic.app.smartwell.extensions.valueToType import com.casic.app.smartwell.model.MapWellListModel import com.casic.app.smartwell.utils.LocaleConstant import com.casic.app.smartwell.utils.RouteOnMap @@ -31,9 +30,16 @@ import com.casic.app.smartwell.view.WellOperationActivity import com.casic.app.smartwell.vm.OrderViewModel import com.casic.app.smartwell.vm.WellViewModel +import com.casic.app.smartwell.widgets.MapWellPopup +import com.casic.app.smartwell.widgets.cluster.ClusterItem +import com.casic.app.smartwell.widgets.cluster.ClusterOnClickListener +import com.casic.app.smartwell.widgets.cluster.ClusterOverlay +import com.casic.app.smartwell.widgets.cluster.RegionItem 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.convertDrawable +import com.pengxh.kt.lite.extensions.dp2px import com.pengxh.kt.lite.extensions.navigatePageTo import com.pengxh.kt.lite.extensions.show import com.pengxh.kt.lite.utils.LoadingDialogHub @@ -43,35 +49,23 @@ /** * 地图点位带聚合效果 * */ -class HomePageHaveClusterFragment : KotlinBaseFragment(), AMap.OnMapLoadedListener, - AMap.OnCameraChangeListener, AMap.OnMarkerClickListener, AMap.InfoWindowAdapter, - AMap.OnInfoWindowClickListener { +class HomePageHaveClusterFragment : KotlinBaseFragment(), + AMap.OnCameraChangeListener { private val kTag = "HaveClusterFragment" private val easyPopupWindow by lazy { EasyPopupWindow(requireContext()) } - private lateinit var wellViewModel: WellViewModel - private lateinit var orderViewModel: OrderViewModel - private lateinit var aMap: AMap - - /** - * 所有的marker - */ - private var allMarkerOptions: MutableList = ArrayList() - - /** - * 视野内的marker - */ - private var markerOptionsInView: MutableList = ArrayList() - - /** - * 自定义Marker弹出框 - * */ - private lateinit var v: View + private val regionRadius by lazy { LocaleConstant.RADIUS_SIZE.dp2px(requireContext()) } + private val infoPopup by lazy { MapWellPopup(requireContext()) } /** * 所有窨井列表信息集合 * */ - private var wellModels: MutableList = ArrayList() + private val wellModels = ArrayList() + private val backDrawables = HashMap() + private lateinit var wellViewModel: WellViewModel + private lateinit var orderViewModel: OrderViewModel + private lateinit var aMap: AMap + private var clusterOverlay: ClusterOverlay? = null override fun initViewBinding( inflater: LayoutInflater, @@ -106,6 +100,9 @@ } }) + //地图初始化 + initMap(savedInstanceState) + //初始化vm wellViewModel = ViewModelProvider(this)[WellViewModel::class.java] orderViewModel = ViewModelProvider(this)[OrderViewModel::class.java] @@ -120,25 +117,19 @@ val latitudeList: MutableList = ArrayList() val longitudeList: MutableList = ArrayList() it.data?.forEach { well -> - val lat = well.latGaode.toString() - val lng = well.lngGaode.toString() + val lat = well.latGaode + val lng = well.lngGaode if (lat.isNotBlank() && lng.isNotBlank()) { //返回true代表当前位置在大陆、港澳地区,反之不在 val latitude = lat.toDouble() val longitude = lng.toDouble() if (CoordinateConverter.isAMapDataAvailable(latitude, longitude)) { - //缓存所有设备详情,点击Marker时候需要 + //缓存所有井 wellModels.add(well) + //分别缓存经、纬度 latitudeList.add(latitude) longitudeList.add(longitude) - //将所有设备信息转化缓存为Marker点 - allMarkerOptions.add( - MarkerOptions() - .position(LatLng(latitude, longitude)) - .title(well.wellTypeName) - .snippet(well.wellName) - ) } } } @@ -160,12 +151,12 @@ val cameraPosition = CameraPosition(centerLatLng, 16f, 0f, 0f) val cameraUpdate = CameraUpdateFactory.newCameraPosition(cameraPosition) aMap.animateCamera(cameraUpdate, 1500, null) + + //显示点数据 + displayWellOnMap() } } - //地图初始化 - initMap(savedInstanceState) - //获取窨井监控数据 wellViewModel.countResultModel.observe(this) { binding.deployedWellView.text = it["bfWell"] @@ -220,17 +211,10 @@ uiSettings.isCompassEnabled = true uiSettings.zoomPosition = AMapOptions.ZOOM_POSITION_RIGHT_CENTER uiSettings.isTiltGesturesEnabled = false//不许地图随手势倾斜角度 + uiSettings.isRotateGesturesEnabled = false//不允许地图随手势改变方位 - // 地图加载成功监听 - aMap.addOnMapLoadedListener(this) // 地图缩放监听 aMap.addOnCameraChangeListener(this) - // marker 点击事件监听 - aMap.addOnMarkerClickListener(this) - // 点击marker弹出自定义popup - aMap.setInfoWindowAdapter(this) - //信息窗点击事件 - aMap.addOnInfoWindowClickListener(this) } override fun initEvent() { @@ -259,9 +243,111 @@ } - override fun onMapLoaded() { - //地图加载成功之后显示聚合点数据 - initClustersMarkers() + private fun displayWellOnMap() { + clusterOverlay?.onDestroy() + val clusterItems = ArrayList() + + wellModels.forEach { + val latitude = it.latGaode.toDouble() + val longitude = it.lngGaode.toDouble() + + val latLng = LatLng(latitude, longitude, false) + val regionItem = RegionItem(latLng, it) + clusterItems.add(regionItem) + } + + clusterOverlay = ClusterOverlay(requireContext(), aMap, clusterItems, regionRadius) + clusterOverlay?.setClusterRender { clusterNum -> + //聚合圆半径 + val radius = 100.dp2px(requireContext()) + if (clusterNum == 0) { + var bitmapDrawable = backDrawables[0] + if (bitmapDrawable == null) { + bitmapDrawable = BitmapDrawable( + null, radius.drawCircle(Color.argb(159, 100, 149, 237)) + ) + backDrawables[0] = bitmapDrawable + } + bitmapDrawable + } + if (clusterNum == 1) { + var bitmapDrawable = backDrawables[1] + if (bitmapDrawable == null) { + bitmapDrawable = R.mipmap.well_location.convertDrawable(requireContext())!! + backDrawables[1] = bitmapDrawable + } + bitmapDrawable + } else if (clusterNum < 5) { + var bitmapDrawable = backDrawables[2] + if (bitmapDrawable == null) { + bitmapDrawable = BitmapDrawable( + null, radius.drawCircle(Color.argb(159, 100, 149, 237)) + ) + backDrawables[2] = bitmapDrawable + } + bitmapDrawable + } else if (clusterNum < 10) { + var bitmapDrawable = backDrawables[3] + if (bitmapDrawable == null) { + bitmapDrawable = BitmapDrawable( + null, radius.drawCircle(Color.argb(199, 30, 144, 255)) + ) + backDrawables[3] = bitmapDrawable + } + bitmapDrawable + } else { + var bitmapDrawable = backDrawables[4] + if (bitmapDrawable == null) { + bitmapDrawable = BitmapDrawable( + null, radius.drawCircle(Color.argb(235, 65, 105, 225)) + ) + backDrawables[4] = bitmapDrawable + } + bitmapDrawable + } + } + + clusterOverlay?.setOnClusterClickListener(object : ClusterOnClickListener { + override fun onMarkerClicked(marker: Marker?, items: List) { + if (items.size > 1) { + "请缩放地图比例在查看数据".show(requireContext()) + return + } + + var item: RegionItem? = null + val builder = LatLngBounds.Builder() + for (clusterItem in items) { + builder.include(clusterItem.position) + item = clusterItem as RegionItem + } + + item?.apply { + showWellPopup(well) + } + } + }) + } + + private fun showWellPopup(well: MapWellListModel.DataModel) { + infoPopup.set(well, object : MapWellPopup.OnPopupWindowClickListener { + override fun onPopupClicked(lat: Double, lng: Double) { + AlertControlDialog.Builder().setContext(requireContext()).setTitle("操作提示") + .setMessage("确定要前往吗").setNegativeButton("取消").setPositiveButton("确定") + .setOnDialogButtonClickListener(object : + AlertControlDialog.OnDialogButtonClickListener { + override fun onConfirmClick() { + RouteOnMap.startNavigation( + requireContext(), "", LatLng(lat, lng) + ) + } + + override fun onCancelClick() { + + } + }).build().show() + } + }) + infoPopup.showAsDropDown(binding.rightOptionView) } override fun onCameraChange(p0: CameraPosition?) { @@ -282,103 +368,10 @@ } } - //获取视野内的marker 根据聚合算法合成自定义的marker 显示视野内的marker override fun onCameraChangeFinish(p0: CameraPosition?) { //地图缩放之后显示聚合点数据 LoadingDialogHub.dismiss() httpCountDownTimer.cancel() - initClustersMarkers() - } - - private fun initClustersMarkers() { - 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 { - v = LayoutInflater.from(requireContext()).inflate(R.layout.popup_map_info, null) - - //显示闸井信息 - marker?.showInfoWindow() - return true - } - - override fun getInfoWindow(marker: Marker?): View { - //反射得到popup里面的控件对象 - val wellNameView = v.findViewById(R.id.wellNameView) - val wellCodeView = v.findViewById(R.id.wellCodeView) - val wellTypeView = v.findViewById(R.id.wellTypeView) - val wellStateView = v.findViewById(R.id.wellStateView) - val deepView = v.findViewById(R.id.deepView) - val locationView = v.findViewById(R.id.locationView) - - //绑定数据 - val clickedLatLng = marker?.position!! - wellModels.forEach { well -> - if (clickedLatLng.latitude == well.latGaode!!.toDouble() - && clickedLatLng.longitude == well.lngGaode!!.toDouble() - ) { - wellNameView.text = String.format("点位名称: ${well.wellName}") - wellCodeView.text = String.format("点位编号: ${well.wellCode}") - wellTypeView.text = String.format("点位类型: ${well.wellType.valueToType()}") - val bfztName = if (well.bfzt == "1") { - "已布防" - } else { - "已撤防" - } - wellStateView.text = String.format("布/撤防状态: $bfztName") - deepView.text = String.format("点位深度: ${well.deep}m") - locationView.text = String.format("详细位置: ${well.position}") - } - } - return v - } - - /** - * 此方法不能修改整个 InfoWindow 的背景和边框,无论自定义的样式是什么样,SDK 都会在最外层添加一个默认的边框 - * */ - override fun getInfoContents(p0: Marker?): View? = null - - override fun onInfoWindowClick(p0: Marker?) { - p0?.apply { - AlertControlDialog.Builder() - .setContext(requireContext()) - .setTitle("操作提示") - .setMessage("确定要前往吗") - .setNegativeButton("取消") - .setPositiveButton("确定") - .setOnDialogButtonClickListener(object : - AlertControlDialog.OnDialogButtonClickListener { - override fun onConfirmClick() { - val lat = position.latitude.toString() - val lng = position.longitude.toString() - if (lat.isBlank() || lng.isBlank()) { - "点位经纬度异常,无法开启导航".show(requireContext()) - return - } - RouteOnMap.startNavigation( - requireContext(), snippet, LatLng(lat.toDouble(), lng.toDouble()) - ) - } - - override fun onCancelClick() { - - } - }).build().show() - } } /***以下是地图生命周期管理************************************************************************/ 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 a54d213..bfa7a57 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 @@ -44,8 +44,8 @@ * 地图点位不带聚合效果 * */ class HomePageNoClusterFragment : KotlinBaseFragment(), - AMap.OnMapLoadedListener, AMap.OnCameraChangeListener, AMap.OnMarkerClickListener, - AMap.InfoWindowAdapter, AMap.OnInfoWindowClickListener { + AMap.OnCameraChangeListener, AMap.OnMarkerClickListener, AMap.InfoWindowAdapter, + AMap.OnInfoWindowClickListener { private val kTag = "NoClusterFragment" private val easyPopupWindow by lazy { EasyPopupWindow(requireContext()) } @@ -109,6 +109,9 @@ wellViewModel = ViewModelProvider(this)[WellViewModel::class.java] orderViewModel = ViewModelProvider(this)[OrderViewModel::class.java] + //地图初始化 + initMap(savedInstanceState) + //获取所有窨井数据 httpCountDownTimer.start() LoadingDialogHub.show(requireActivity(), "数据加载中,请稍后...") @@ -157,12 +160,12 @@ val cameraPosition = CameraPosition(centerLatLng, 16f, 0f, 0f) val cameraUpdate = CameraUpdateFactory.newCameraPosition(cameraPosition) aMap.animateCamera(cameraUpdate, 1500, null) + + //显示点数据 + displayWellOnMap() } } - //地图初始化 - initMap(savedInstanceState) - //获取窨井监控数据 wellViewModel.countResultModel.observe(this) { binding.deployedWellView.text = it["bfWell"] @@ -214,9 +217,8 @@ uiSettings.isCompassEnabled = true uiSettings.zoomPosition = AMapOptions.ZOOM_POSITION_RIGHT_CENTER uiSettings.isTiltGesturesEnabled = false//不许地图随手势倾斜角度 + uiSettings.isRotateGesturesEnabled = false//不允许地图随手势改变方位 - // 地图加载成功监听 - aMap.addOnMapLoadedListener(this) // 地图缩放监听 aMap.addOnCameraChangeListener(this) // marker 点击事件监听 @@ -253,11 +255,6 @@ } - override fun onMapLoaded() { - //地图加载成功之后显示聚合点数据 - initClustersMarkers() - } - override fun onCameraChange(p0: CameraPosition?) { } @@ -281,10 +278,9 @@ //地图缩放之后显示聚合点数据 LoadingDialogHub.dismiss() httpCountDownTimer.cancel() - initClustersMarkers() } - private fun initClustersMarkers() { + private fun displayWellOnMap() { val proj = aMap.projection val dm = resources.displayMetrics var screenLocation: Point diff --git a/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.java b/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.java deleted file mode 100644 index d8b18ef..0000000 --- a/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.java +++ /dev/null @@ -1,50 +0,0 @@ -package com.casic.app.smartwell.model; - -public class ErrorMessageModel { - - private int code; - private String data; - private String exceptionClazz; - private String message; - private boolean success; - - public int getCode() { - return code; - } - - public void setCode(int code) { - this.code = code; - } - - public String getData() { - return data; - } - - public void setData(String data) { - this.data = data; - } - - public String getExceptionClazz() { - return exceptionClazz; - } - - public void setExceptionClazz(String exceptionClazz) { - this.exceptionClazz = exceptionClazz; - } - - public String getMessage() { - return message; - } - - public void setMessage(String message) { - this.message = message; - } - - public boolean isSuccess() { - return success; - } - - public void setSuccess(boolean success) { - this.success = success; - } -} \ No newline at end of file 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 new file mode 100644 index 0000000..215ac0c --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/PipelineModel.java @@ -0,0 +1,328 @@ +package com.casic.app.smartwell.model; + +import java.util.List; + +public class PipelineModel { + + private Integer code; + private DataModel data; + private String message; + private Boolean success; + + public Integer getCode() { + return code; + } + + public void setCode(Integer code) { + this.code = code; + } + + public DataModel getData() { + return data; + } + + public void setData(DataModel data) { + this.data = data; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + public Boolean getSuccess() { + return success; + } + + public void setSuccess(Boolean success) { + this.success = success; + } + + public static class DataModel { + private List rows; + private Integer total; + + public List getRows() { + return rows; + } + + public void setRows(List rows) { + this.rows = rows; + } + + public Integer getTotal() { + return total; + } + + public void setTotal(Integer total) { + this.total = total; + } + + 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 getBuryMode() { + return buryMode; + } + + public void setBuryMode(String buryMode) { + this.buryMode = buryMode; + } + + public String getConstructEra() { + return constructEra; + } + + public void setConstructEra(String constructEra) { + this.constructEra = constructEra; + } + + 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; + } + } + } +} 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 06d3d2b..4f38a2c 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 = 100 //相距多少米才聚合,单位:米 + const val RADIUS_SIZE = 80 //相距多少米才聚合,单位:米 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:11308" + // 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 0d5f3fa..991e1db 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 @@ -312,4 +312,14 @@ @Header("token") token: String, @Field("clientid") deviceCode: String ): String + + /** + * 管线位置数据 + */ + @GET("/pipeline/listPage") + suspend fun getPipeline( + @Header("token") token: String, + @Query("limit") limit: Int, + @Query("offset") offset: Int + ): String } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt index 1a0ce22..4050067 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt @@ -294,4 +294,11 @@ suspend fun registerPush(clientId: String): String { return api.registerPush(AuthenticationHelper.token!!, clientId) } + + /** + * 管线位置数据 + */ + suspend fun getPipeline(): String { + return api.getPipeline(AuthenticationHelper.token!!, 2000, 1) + } } \ No newline at end of file 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 9270fa1..4ca5a5e 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.HomePageNoClusterFragment +import com.casic.app.smartwell.fragment.HomePageHaveClusterFragment 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/vm/AlarmViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/AlarmViewModel.kt index 9cff08c..e7acc17 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/AlarmViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/AlarmViewModel.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.AlarmContentModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager import com.google.gson.Gson @@ -16,7 +16,7 @@ fun getAlarmContentType(alarmType: String) = launch({ val response = RetrofitServiceManager.getAlarmContentType(alarmType) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { listModel.value = gson.fromJson( response, object : TypeToken() {}.type diff --git a/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt index 5e5b163..895dedd 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.PublicKeyModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager import com.google.gson.Gson @@ -18,7 +18,7 @@ fun getPublicKey() = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.authenticate() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { keyModel.value = gson.fromJson( response, object : TypeToken() {}.type diff --git a/app/src/main/java/com/casic/app/smartwell/vm/DeviceViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/DeviceViewModel.kt index db5ccf6..899a962 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/DeviceViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/DeviceViewModel.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.DeviceDetailModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager import com.google.gson.Gson @@ -16,7 +16,7 @@ fun getDeviceDetail(deviceCode: String) = launch({ val response = RetrofitServiceManager.getDeviceDetail(deviceCode) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { detailModel.value = gson.fromJson( response, object : TypeToken() {}.type diff --git a/app/src/main/java/com/casic/app/smartwell/vm/LoginViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/LoginViewModel.kt index cd8b8a9..a417398 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/LoginViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/LoginViewModel.kt @@ -2,7 +2,7 @@ import androidx.lifecycle.MutableLiveData import com.casic.app.smartwell.base.BaseApplication -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.CommonResultModel import com.casic.app.smartwell.model.LoginResultModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -21,7 +21,7 @@ fun enter(account: String, secretKey: String) = launch({ val response = RetrofitServiceManager.login(account, secretKey) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success enterResultModel.value = gson.fromJson( @@ -38,7 +38,7 @@ fun out() = launch({ val response = RetrofitServiceManager.loginOut() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { outResultModel.value = gson.fromJson( response, object : TypeToken() {}.type diff --git a/app/src/main/java/com/casic/app/smartwell/vm/OperationViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/OperationViewModel.kt index 8943ed3..37e115f 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/OperationViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/OperationViewModel.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.vm import com.casic.app.smartwell.base.BaseApplication -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager import com.pengxh.kt.lite.base.BaseViewModel import com.pengxh.kt.lite.extensions.launch @@ -16,7 +16,7 @@ fun acceptWorkOrder(id: String) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.acceptWorkOrder(id) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success "接单成功".show(BaseApplication.get()) @@ -35,7 +35,7 @@ loadState.value = LoadState.Loading val response = RetrofitServiceManager.confirmWorkOrder(id, firstState, firstStatePhotos, needHandle) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success "工单确认成功".show(BaseApplication.get()) @@ -50,7 +50,7 @@ fun transferWorkOrder(id: String, userId: String) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.transferWorkOrder(id, userId) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success "转单成功".show(BaseApplication.get()) @@ -65,7 +65,7 @@ fun completeWorkOrder(id: String, handleMessage: String, handlePhotos: String) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.completeWorkOrder(id, handleMessage, handlePhotos) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success "工单处理成功".show(BaseApplication.get()) diff --git a/app/src/main/java/com/casic/app/smartwell/vm/OrderViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/OrderViewModel.kt index 4cb26b7..d2fad86 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/OrderViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/OrderViewModel.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.OrderDetailModel import com.casic.app.smartwell.model.OrderListModel import com.casic.app.smartwell.model.OrderStatusModel @@ -37,7 +37,7 @@ val response = RetrofitServiceManager.getSearchResult( keywords, alarmContent, alarmLevel, jobStatus, deptId, beginTime, endTime, offset ) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success searchResult.value = gson.fromJson( @@ -53,7 +53,7 @@ fun getWorkOrderListByState(jobStatus: String, page: Int) = launch({ val response = RetrofitServiceManager.getWorkOrderList(jobStatus, page) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { orderList.value = gson.fromJson( response, object : TypeToken() {}.type @@ -65,7 +65,7 @@ fun getNotAcceptOderList(page: Int) = launch({ val response = RetrofitServiceManager.getNotAcceptOderList(page) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { orderList.value = gson.fromJson( response, object : TypeToken() {}.type @@ -77,7 +77,7 @@ fun getNotHandleOderList(page: Int) = launch({ val response = RetrofitServiceManager.getNotHandleOderList(page) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { orderList.value = gson.fromJson( response, object : TypeToken() {}.type @@ -89,7 +89,7 @@ fun countWorkOrderByState() = launch({ val response = RetrofitServiceManager.countWorkOrderByState() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { val map = HashMap(4) @@ -107,7 +107,7 @@ fun getOrderStatus() = launch({ val response = RetrofitServiceManager.getOrderStatus() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { orderStatusModel.value = gson.fromJson( response, object : TypeToken() {}.type @@ -120,7 +120,7 @@ fun getWorkOrderDetail(id: String) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.getWorkOrderDetail(id) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success detailModel.value = gson.fromJson( diff --git a/app/src/main/java/com/casic/app/smartwell/vm/PipelineViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/PipelineViewModel.kt new file mode 100644 index 0000000..60c1e2f --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/vm/PipelineViewModel.kt @@ -0,0 +1,28 @@ +package com.casic.app.smartwell.vm + +import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.extensions.getResponseCode +import com.casic.app.smartwell.model.PipelineModel +import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken +import com.pengxh.kt.lite.base.BaseViewModel +import com.pengxh.kt.lite.extensions.launch + +class PipelineViewModel : BaseViewModel() { + + private val gson by lazy { Gson() } + val lineResult = MutableLiveData() + + fun getPipeline() = launch({ + val response = RetrofitServiceManager.getPipeline() + val responseCode = response.getResponseCode() + if (responseCode == 200) { + lineResult.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } + }, { + it.printStackTrace() + }) +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/PushViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/PushViewModel.kt index 9279815..12fd610 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/PushViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/PushViewModel.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.CommonResultModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager import com.google.gson.Gson @@ -16,7 +16,7 @@ fun registerPush(clientId: String) = launch({ val response = RetrofitServiceManager.registerPush(clientId) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { registerResultModel.value = gson.fromJson( response, object : TypeToken() {}.type diff --git a/app/src/main/java/com/casic/app/smartwell/vm/UploadImageViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/UploadImageViewModel.kt index 8d6744e..9707eeb 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/UploadImageViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/UploadImageViewModel.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.CommonResultModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager import com.google.gson.Gson @@ -19,7 +19,7 @@ fun uploadImage(image: File) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.uploadImage(image) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success resultModel.value = gson.fromJson( diff --git a/app/src/main/java/com/casic/app/smartwell/vm/UserViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/UserViewModel.kt index 31a4d4c..070c35a 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/UserViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/UserViewModel.kt @@ -2,7 +2,7 @@ import androidx.lifecycle.MutableLiveData import com.casic.app.smartwell.base.BaseApplication -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.SubordinateModel import com.casic.app.smartwell.model.UserDetailModel import com.casic.app.smartwell.model.VersionResultModel @@ -25,7 +25,7 @@ fun getUserDetail() = launch({ val response = RetrofitServiceManager.getUserDetail() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { val userDetail = gson.fromJson( response, object : TypeToken() {}.type @@ -48,7 +48,7 @@ * */ fun getSubordinate(hasMine: String?, deptId: String?, roleTips: String?) = launch({ val response = RetrofitServiceManager.getSubordinate(hasMine, deptId, roleTips) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { subordinateModel.value = gson.fromJson( response, object : TypeToken() {}.type @@ -61,7 +61,7 @@ fun changePassword(oldPwd: String, newPwd: String) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.changePassword(oldPwd, newPwd) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success "修改成功,请重新登录".show(BaseApplication.get()) @@ -76,7 +76,7 @@ fun updateVersion() = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.updateVersion() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success versionResultModel.value = gson.fromJson( diff --git a/app/src/main/java/com/casic/app/smartwell/vm/WellViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/WellViewModel.kt index 3d41e9b..9e42e36 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/WellViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/WellViewModel.kt @@ -2,8 +2,7 @@ import androidx.lifecycle.MutableLiveData import com.casic.app.smartwell.base.BaseApplication -import com.casic.app.smartwell.extensions.separateResponseCode -import com.casic.app.smartwell.extensions.toErrorMessage +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.AuthorDeptModel import com.casic.app.smartwell.model.CommonResultModel import com.casic.app.smartwell.model.MapWellListModel @@ -32,7 +31,7 @@ fun countWellByState() = launch({ val response = RetrofitServiceManager.countWellByState() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { val map = HashMap(3) @@ -57,7 +56,7 @@ fun getWellType() = launch({ val response = RetrofitServiceManager.getWellType() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { wellTypeModel.value = gson.fromJson( response, object : TypeToken() {}.type @@ -70,7 +69,7 @@ fun getWellDetail(id: String) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.getWellDetail(id) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success wellDetailModel.value = gson.fromJson( @@ -87,7 +86,7 @@ fun getOperationResult(id: String, state: String) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.getOperationResult(id, state) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success "操作成功".show(BaseApplication.get()) @@ -105,7 +104,7 @@ fun getMonitorResult(id: String) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.getMonitorResult(id) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success monitorModel.value = gson.fromJson( @@ -125,7 +124,7 @@ val response = RetrofitServiceManager.getWellListByPage( keywords, wellType, deptid, bfzt, page ) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { listModel.value = gson.fromJson( response, object : TypeToken() {}.type @@ -137,13 +136,11 @@ fun getWellList() = launch({ val response = RetrofitServiceManager.getWellList() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { totalWellModel.value = gson.fromJson( response, object : TypeToken() {}.type ) - } else { - response.toErrorMessage().show(BaseApplication.get()) } }, { it.printStackTrace() diff --git a/app/src/main/java/com/casic/app/smartwell/extensions/Int.kt b/app/src/main/java/com/casic/app/smartwell/extensions/Int.kt index de0617b..a0a5e33 100644 --- a/app/src/main/java/com/casic/app/smartwell/extensions/Int.kt +++ b/app/src/main/java/com/casic/app/smartwell/extensions/Int.kt @@ -1,9 +1,24 @@ package com.casic.app.smartwell.extensions +import android.graphics.Bitmap +import android.graphics.Canvas +import android.graphics.Paint +import android.graphics.RectF + fun Int.toLevel(): String { return if (this == 0) { "" } else { this.toString() } +} + +fun Int.drawCircle(color: Int): Bitmap? { + val bitmap = Bitmap.createBitmap(this * 2, this * 2, Bitmap.Config.ARGB_8888) + val canvas = Canvas(bitmap) + val paint = Paint() + val rectF = RectF(0f, 0f, (this * 2).toFloat(), (this * 2).toFloat()) + paint.color = color + canvas.drawArc(rectF, 0f, 360f, true, paint) + return bitmap } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt index 6b6ca3e..5e45534 100644 --- a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt +++ b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt @@ -2,17 +2,13 @@ import android.content.Context import com.casic.app.smartwell.callback.OnImageCompressListener -import com.casic.app.smartwell.model.ErrorMessageModel import com.casic.app.smartwell.utils.LocaleConstant -import com.google.gson.Gson -import com.google.gson.reflect.TypeToken +import com.google.gson.JsonParser import com.pengxh.kt.lite.extensions.createCompressImageDir import com.pengxh.kt.lite.utils.SaveKeyValues -import org.json.JSONObject import top.zibin.luban.Luban import top.zibin.luban.OnCompressListener import java.io.File -import java.util.Locale /** * String扩展方法 @@ -74,18 +70,22 @@ } } -fun String.separateResponseCode(): Int { +fun String.getResponseCode(): Int { if (this.isBlank()) { return 404 } - return JSONObject(this).getInt("code") + val element = JsonParser.parseString(this) + val jsonObject = element.asJsonObject + return jsonObject.get("code").asInt } -fun String.toErrorMessage(): String { - val errorModel = Gson().fromJson( - this, object : TypeToken() {}.type - ) - return errorModel.message.toString() +fun String.getResponseMessage(): String { + if (this.isBlank()) { + return "" + } + val element = JsonParser.parseString(this) + val jsonObject = element.asJsonObject + return jsonObject.get("message").asString } fun String.compressImage(context: Context, listener: OnImageCompressListener) { @@ -93,9 +93,6 @@ .load(this) .ignoreBy(100) .setTargetDir(context.createCompressImageDir().toString()) - .filter { - !(it.isBlank() || it.lowercase(Locale.getDefault()).endsWith(".gif")) - } .setCompressListener(object : OnCompressListener { override fun onStart() { 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 96df110..cd25fca 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 @@ -1,26 +1,25 @@ package com.casic.app.smartwell.fragment -import android.graphics.Point +import android.graphics.Color +import android.graphics.drawable.BitmapDrawable +import android.graphics.drawable.Drawable 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 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.LatLngBounds import com.amap.api.maps.model.Marker -import com.amap.api.maps.model.MarkerOptions import com.casic.app.smartwell.R import com.casic.app.smartwell.databinding.FragmentHomeBinding +import com.casic.app.smartwell.extensions.drawCircle import com.casic.app.smartwell.extensions.initImmersionBar -import com.casic.app.smartwell.extensions.valueToType import com.casic.app.smartwell.model.MapWellListModel import com.casic.app.smartwell.utils.LocaleConstant import com.casic.app.smartwell.utils.RouteOnMap @@ -31,9 +30,16 @@ import com.casic.app.smartwell.view.WellOperationActivity import com.casic.app.smartwell.vm.OrderViewModel import com.casic.app.smartwell.vm.WellViewModel +import com.casic.app.smartwell.widgets.MapWellPopup +import com.casic.app.smartwell.widgets.cluster.ClusterItem +import com.casic.app.smartwell.widgets.cluster.ClusterOnClickListener +import com.casic.app.smartwell.widgets.cluster.ClusterOverlay +import com.casic.app.smartwell.widgets.cluster.RegionItem 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.convertDrawable +import com.pengxh.kt.lite.extensions.dp2px import com.pengxh.kt.lite.extensions.navigatePageTo import com.pengxh.kt.lite.extensions.show import com.pengxh.kt.lite.utils.LoadingDialogHub @@ -43,35 +49,23 @@ /** * 地图点位带聚合效果 * */ -class HomePageHaveClusterFragment : KotlinBaseFragment(), AMap.OnMapLoadedListener, - AMap.OnCameraChangeListener, AMap.OnMarkerClickListener, AMap.InfoWindowAdapter, - AMap.OnInfoWindowClickListener { +class HomePageHaveClusterFragment : KotlinBaseFragment(), + AMap.OnCameraChangeListener { private val kTag = "HaveClusterFragment" private val easyPopupWindow by lazy { EasyPopupWindow(requireContext()) } - private lateinit var wellViewModel: WellViewModel - private lateinit var orderViewModel: OrderViewModel - private lateinit var aMap: AMap - - /** - * 所有的marker - */ - private var allMarkerOptions: MutableList = ArrayList() - - /** - * 视野内的marker - */ - private var markerOptionsInView: MutableList = ArrayList() - - /** - * 自定义Marker弹出框 - * */ - private lateinit var v: View + private val regionRadius by lazy { LocaleConstant.RADIUS_SIZE.dp2px(requireContext()) } + private val infoPopup by lazy { MapWellPopup(requireContext()) } /** * 所有窨井列表信息集合 * */ - private var wellModels: MutableList = ArrayList() + private val wellModels = ArrayList() + private val backDrawables = HashMap() + private lateinit var wellViewModel: WellViewModel + private lateinit var orderViewModel: OrderViewModel + private lateinit var aMap: AMap + private var clusterOverlay: ClusterOverlay? = null override fun initViewBinding( inflater: LayoutInflater, @@ -106,6 +100,9 @@ } }) + //地图初始化 + initMap(savedInstanceState) + //初始化vm wellViewModel = ViewModelProvider(this)[WellViewModel::class.java] orderViewModel = ViewModelProvider(this)[OrderViewModel::class.java] @@ -120,25 +117,19 @@ val latitudeList: MutableList = ArrayList() val longitudeList: MutableList = ArrayList() it.data?.forEach { well -> - val lat = well.latGaode.toString() - val lng = well.lngGaode.toString() + val lat = well.latGaode + val lng = well.lngGaode if (lat.isNotBlank() && lng.isNotBlank()) { //返回true代表当前位置在大陆、港澳地区,反之不在 val latitude = lat.toDouble() val longitude = lng.toDouble() if (CoordinateConverter.isAMapDataAvailable(latitude, longitude)) { - //缓存所有设备详情,点击Marker时候需要 + //缓存所有井 wellModels.add(well) + //分别缓存经、纬度 latitudeList.add(latitude) longitudeList.add(longitude) - //将所有设备信息转化缓存为Marker点 - allMarkerOptions.add( - MarkerOptions() - .position(LatLng(latitude, longitude)) - .title(well.wellTypeName) - .snippet(well.wellName) - ) } } } @@ -160,12 +151,12 @@ val cameraPosition = CameraPosition(centerLatLng, 16f, 0f, 0f) val cameraUpdate = CameraUpdateFactory.newCameraPosition(cameraPosition) aMap.animateCamera(cameraUpdate, 1500, null) + + //显示点数据 + displayWellOnMap() } } - //地图初始化 - initMap(savedInstanceState) - //获取窨井监控数据 wellViewModel.countResultModel.observe(this) { binding.deployedWellView.text = it["bfWell"] @@ -220,17 +211,10 @@ uiSettings.isCompassEnabled = true uiSettings.zoomPosition = AMapOptions.ZOOM_POSITION_RIGHT_CENTER uiSettings.isTiltGesturesEnabled = false//不许地图随手势倾斜角度 + uiSettings.isRotateGesturesEnabled = false//不允许地图随手势改变方位 - // 地图加载成功监听 - aMap.addOnMapLoadedListener(this) // 地图缩放监听 aMap.addOnCameraChangeListener(this) - // marker 点击事件监听 - aMap.addOnMarkerClickListener(this) - // 点击marker弹出自定义popup - aMap.setInfoWindowAdapter(this) - //信息窗点击事件 - aMap.addOnInfoWindowClickListener(this) } override fun initEvent() { @@ -259,9 +243,111 @@ } - override fun onMapLoaded() { - //地图加载成功之后显示聚合点数据 - initClustersMarkers() + private fun displayWellOnMap() { + clusterOverlay?.onDestroy() + val clusterItems = ArrayList() + + wellModels.forEach { + val latitude = it.latGaode.toDouble() + val longitude = it.lngGaode.toDouble() + + val latLng = LatLng(latitude, longitude, false) + val regionItem = RegionItem(latLng, it) + clusterItems.add(regionItem) + } + + clusterOverlay = ClusterOverlay(requireContext(), aMap, clusterItems, regionRadius) + clusterOverlay?.setClusterRender { clusterNum -> + //聚合圆半径 + val radius = 100.dp2px(requireContext()) + if (clusterNum == 0) { + var bitmapDrawable = backDrawables[0] + if (bitmapDrawable == null) { + bitmapDrawable = BitmapDrawable( + null, radius.drawCircle(Color.argb(159, 100, 149, 237)) + ) + backDrawables[0] = bitmapDrawable + } + bitmapDrawable + } + if (clusterNum == 1) { + var bitmapDrawable = backDrawables[1] + if (bitmapDrawable == null) { + bitmapDrawable = R.mipmap.well_location.convertDrawable(requireContext())!! + backDrawables[1] = bitmapDrawable + } + bitmapDrawable + } else if (clusterNum < 5) { + var bitmapDrawable = backDrawables[2] + if (bitmapDrawable == null) { + bitmapDrawable = BitmapDrawable( + null, radius.drawCircle(Color.argb(159, 100, 149, 237)) + ) + backDrawables[2] = bitmapDrawable + } + bitmapDrawable + } else if (clusterNum < 10) { + var bitmapDrawable = backDrawables[3] + if (bitmapDrawable == null) { + bitmapDrawable = BitmapDrawable( + null, radius.drawCircle(Color.argb(199, 30, 144, 255)) + ) + backDrawables[3] = bitmapDrawable + } + bitmapDrawable + } else { + var bitmapDrawable = backDrawables[4] + if (bitmapDrawable == null) { + bitmapDrawable = BitmapDrawable( + null, radius.drawCircle(Color.argb(235, 65, 105, 225)) + ) + backDrawables[4] = bitmapDrawable + } + bitmapDrawable + } + } + + clusterOverlay?.setOnClusterClickListener(object : ClusterOnClickListener { + override fun onMarkerClicked(marker: Marker?, items: List) { + if (items.size > 1) { + "请缩放地图比例在查看数据".show(requireContext()) + return + } + + var item: RegionItem? = null + val builder = LatLngBounds.Builder() + for (clusterItem in items) { + builder.include(clusterItem.position) + item = clusterItem as RegionItem + } + + item?.apply { + showWellPopup(well) + } + } + }) + } + + private fun showWellPopup(well: MapWellListModel.DataModel) { + infoPopup.set(well, object : MapWellPopup.OnPopupWindowClickListener { + override fun onPopupClicked(lat: Double, lng: Double) { + AlertControlDialog.Builder().setContext(requireContext()).setTitle("操作提示") + .setMessage("确定要前往吗").setNegativeButton("取消").setPositiveButton("确定") + .setOnDialogButtonClickListener(object : + AlertControlDialog.OnDialogButtonClickListener { + override fun onConfirmClick() { + RouteOnMap.startNavigation( + requireContext(), "", LatLng(lat, lng) + ) + } + + override fun onCancelClick() { + + } + }).build().show() + } + }) + infoPopup.showAsDropDown(binding.rightOptionView) } override fun onCameraChange(p0: CameraPosition?) { @@ -282,103 +368,10 @@ } } - //获取视野内的marker 根据聚合算法合成自定义的marker 显示视野内的marker override fun onCameraChangeFinish(p0: CameraPosition?) { //地图缩放之后显示聚合点数据 LoadingDialogHub.dismiss() httpCountDownTimer.cancel() - initClustersMarkers() - } - - private fun initClustersMarkers() { - 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 { - v = LayoutInflater.from(requireContext()).inflate(R.layout.popup_map_info, null) - - //显示闸井信息 - marker?.showInfoWindow() - return true - } - - override fun getInfoWindow(marker: Marker?): View { - //反射得到popup里面的控件对象 - val wellNameView = v.findViewById(R.id.wellNameView) - val wellCodeView = v.findViewById(R.id.wellCodeView) - val wellTypeView = v.findViewById(R.id.wellTypeView) - val wellStateView = v.findViewById(R.id.wellStateView) - val deepView = v.findViewById(R.id.deepView) - val locationView = v.findViewById(R.id.locationView) - - //绑定数据 - val clickedLatLng = marker?.position!! - wellModels.forEach { well -> - if (clickedLatLng.latitude == well.latGaode!!.toDouble() - && clickedLatLng.longitude == well.lngGaode!!.toDouble() - ) { - wellNameView.text = String.format("点位名称: ${well.wellName}") - wellCodeView.text = String.format("点位编号: ${well.wellCode}") - wellTypeView.text = String.format("点位类型: ${well.wellType.valueToType()}") - val bfztName = if (well.bfzt == "1") { - "已布防" - } else { - "已撤防" - } - wellStateView.text = String.format("布/撤防状态: $bfztName") - deepView.text = String.format("点位深度: ${well.deep}m") - locationView.text = String.format("详细位置: ${well.position}") - } - } - return v - } - - /** - * 此方法不能修改整个 InfoWindow 的背景和边框,无论自定义的样式是什么样,SDK 都会在最外层添加一个默认的边框 - * */ - override fun getInfoContents(p0: Marker?): View? = null - - override fun onInfoWindowClick(p0: Marker?) { - p0?.apply { - AlertControlDialog.Builder() - .setContext(requireContext()) - .setTitle("操作提示") - .setMessage("确定要前往吗") - .setNegativeButton("取消") - .setPositiveButton("确定") - .setOnDialogButtonClickListener(object : - AlertControlDialog.OnDialogButtonClickListener { - override fun onConfirmClick() { - val lat = position.latitude.toString() - val lng = position.longitude.toString() - if (lat.isBlank() || lng.isBlank()) { - "点位经纬度异常,无法开启导航".show(requireContext()) - return - } - RouteOnMap.startNavigation( - requireContext(), snippet, LatLng(lat.toDouble(), lng.toDouble()) - ) - } - - override fun onCancelClick() { - - } - }).build().show() - } } /***以下是地图生命周期管理************************************************************************/ 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 a54d213..bfa7a57 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 @@ -44,8 +44,8 @@ * 地图点位不带聚合效果 * */ class HomePageNoClusterFragment : KotlinBaseFragment(), - AMap.OnMapLoadedListener, AMap.OnCameraChangeListener, AMap.OnMarkerClickListener, - AMap.InfoWindowAdapter, AMap.OnInfoWindowClickListener { + AMap.OnCameraChangeListener, AMap.OnMarkerClickListener, AMap.InfoWindowAdapter, + AMap.OnInfoWindowClickListener { private val kTag = "NoClusterFragment" private val easyPopupWindow by lazy { EasyPopupWindow(requireContext()) } @@ -109,6 +109,9 @@ wellViewModel = ViewModelProvider(this)[WellViewModel::class.java] orderViewModel = ViewModelProvider(this)[OrderViewModel::class.java] + //地图初始化 + initMap(savedInstanceState) + //获取所有窨井数据 httpCountDownTimer.start() LoadingDialogHub.show(requireActivity(), "数据加载中,请稍后...") @@ -157,12 +160,12 @@ val cameraPosition = CameraPosition(centerLatLng, 16f, 0f, 0f) val cameraUpdate = CameraUpdateFactory.newCameraPosition(cameraPosition) aMap.animateCamera(cameraUpdate, 1500, null) + + //显示点数据 + displayWellOnMap() } } - //地图初始化 - initMap(savedInstanceState) - //获取窨井监控数据 wellViewModel.countResultModel.observe(this) { binding.deployedWellView.text = it["bfWell"] @@ -214,9 +217,8 @@ uiSettings.isCompassEnabled = true uiSettings.zoomPosition = AMapOptions.ZOOM_POSITION_RIGHT_CENTER uiSettings.isTiltGesturesEnabled = false//不许地图随手势倾斜角度 + uiSettings.isRotateGesturesEnabled = false//不允许地图随手势改变方位 - // 地图加载成功监听 - aMap.addOnMapLoadedListener(this) // 地图缩放监听 aMap.addOnCameraChangeListener(this) // marker 点击事件监听 @@ -253,11 +255,6 @@ } - override fun onMapLoaded() { - //地图加载成功之后显示聚合点数据 - initClustersMarkers() - } - override fun onCameraChange(p0: CameraPosition?) { } @@ -281,10 +278,9 @@ //地图缩放之后显示聚合点数据 LoadingDialogHub.dismiss() httpCountDownTimer.cancel() - initClustersMarkers() } - private fun initClustersMarkers() { + private fun displayWellOnMap() { val proj = aMap.projection val dm = resources.displayMetrics var screenLocation: Point diff --git a/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.java b/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.java deleted file mode 100644 index d8b18ef..0000000 --- a/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.java +++ /dev/null @@ -1,50 +0,0 @@ -package com.casic.app.smartwell.model; - -public class ErrorMessageModel { - - private int code; - private String data; - private String exceptionClazz; - private String message; - private boolean success; - - public int getCode() { - return code; - } - - public void setCode(int code) { - this.code = code; - } - - public String getData() { - return data; - } - - public void setData(String data) { - this.data = data; - } - - public String getExceptionClazz() { - return exceptionClazz; - } - - public void setExceptionClazz(String exceptionClazz) { - this.exceptionClazz = exceptionClazz; - } - - public String getMessage() { - return message; - } - - public void setMessage(String message) { - this.message = message; - } - - public boolean isSuccess() { - return success; - } - - public void setSuccess(boolean success) { - this.success = success; - } -} \ No newline at end of file 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 new file mode 100644 index 0000000..215ac0c --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/PipelineModel.java @@ -0,0 +1,328 @@ +package com.casic.app.smartwell.model; + +import java.util.List; + +public class PipelineModel { + + private Integer code; + private DataModel data; + private String message; + private Boolean success; + + public Integer getCode() { + return code; + } + + public void setCode(Integer code) { + this.code = code; + } + + public DataModel getData() { + return data; + } + + public void setData(DataModel data) { + this.data = data; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + public Boolean getSuccess() { + return success; + } + + public void setSuccess(Boolean success) { + this.success = success; + } + + public static class DataModel { + private List rows; + private Integer total; + + public List getRows() { + return rows; + } + + public void setRows(List rows) { + this.rows = rows; + } + + public Integer getTotal() { + return total; + } + + public void setTotal(Integer total) { + this.total = total; + } + + 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 getBuryMode() { + return buryMode; + } + + public void setBuryMode(String buryMode) { + this.buryMode = buryMode; + } + + public String getConstructEra() { + return constructEra; + } + + public void setConstructEra(String constructEra) { + this.constructEra = constructEra; + } + + 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; + } + } + } +} 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 06d3d2b..4f38a2c 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 = 100 //相距多少米才聚合,单位:米 + const val RADIUS_SIZE = 80 //相距多少米才聚合,单位:米 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:11308" + // 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 0d5f3fa..991e1db 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 @@ -312,4 +312,14 @@ @Header("token") token: String, @Field("clientid") deviceCode: String ): String + + /** + * 管线位置数据 + */ + @GET("/pipeline/listPage") + suspend fun getPipeline( + @Header("token") token: String, + @Query("limit") limit: Int, + @Query("offset") offset: Int + ): String } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt index 1a0ce22..4050067 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt @@ -294,4 +294,11 @@ suspend fun registerPush(clientId: String): String { return api.registerPush(AuthenticationHelper.token!!, clientId) } + + /** + * 管线位置数据 + */ + suspend fun getPipeline(): String { + return api.getPipeline(AuthenticationHelper.token!!, 2000, 1) + } } \ No newline at end of file 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 9270fa1..4ca5a5e 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.HomePageNoClusterFragment +import com.casic.app.smartwell.fragment.HomePageHaveClusterFragment 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/vm/AlarmViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/AlarmViewModel.kt index 9cff08c..e7acc17 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/AlarmViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/AlarmViewModel.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.AlarmContentModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager import com.google.gson.Gson @@ -16,7 +16,7 @@ fun getAlarmContentType(alarmType: String) = launch({ val response = RetrofitServiceManager.getAlarmContentType(alarmType) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { listModel.value = gson.fromJson( response, object : TypeToken() {}.type diff --git a/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt index 5e5b163..895dedd 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.PublicKeyModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager import com.google.gson.Gson @@ -18,7 +18,7 @@ fun getPublicKey() = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.authenticate() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { keyModel.value = gson.fromJson( response, object : TypeToken() {}.type diff --git a/app/src/main/java/com/casic/app/smartwell/vm/DeviceViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/DeviceViewModel.kt index db5ccf6..899a962 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/DeviceViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/DeviceViewModel.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.DeviceDetailModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager import com.google.gson.Gson @@ -16,7 +16,7 @@ fun getDeviceDetail(deviceCode: String) = launch({ val response = RetrofitServiceManager.getDeviceDetail(deviceCode) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { detailModel.value = gson.fromJson( response, object : TypeToken() {}.type diff --git a/app/src/main/java/com/casic/app/smartwell/vm/LoginViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/LoginViewModel.kt index cd8b8a9..a417398 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/LoginViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/LoginViewModel.kt @@ -2,7 +2,7 @@ import androidx.lifecycle.MutableLiveData import com.casic.app.smartwell.base.BaseApplication -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.CommonResultModel import com.casic.app.smartwell.model.LoginResultModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -21,7 +21,7 @@ fun enter(account: String, secretKey: String) = launch({ val response = RetrofitServiceManager.login(account, secretKey) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success enterResultModel.value = gson.fromJson( @@ -38,7 +38,7 @@ fun out() = launch({ val response = RetrofitServiceManager.loginOut() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { outResultModel.value = gson.fromJson( response, object : TypeToken() {}.type diff --git a/app/src/main/java/com/casic/app/smartwell/vm/OperationViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/OperationViewModel.kt index 8943ed3..37e115f 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/OperationViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/OperationViewModel.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.vm import com.casic.app.smartwell.base.BaseApplication -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager import com.pengxh.kt.lite.base.BaseViewModel import com.pengxh.kt.lite.extensions.launch @@ -16,7 +16,7 @@ fun acceptWorkOrder(id: String) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.acceptWorkOrder(id) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success "接单成功".show(BaseApplication.get()) @@ -35,7 +35,7 @@ loadState.value = LoadState.Loading val response = RetrofitServiceManager.confirmWorkOrder(id, firstState, firstStatePhotos, needHandle) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success "工单确认成功".show(BaseApplication.get()) @@ -50,7 +50,7 @@ fun transferWorkOrder(id: String, userId: String) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.transferWorkOrder(id, userId) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success "转单成功".show(BaseApplication.get()) @@ -65,7 +65,7 @@ fun completeWorkOrder(id: String, handleMessage: String, handlePhotos: String) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.completeWorkOrder(id, handleMessage, handlePhotos) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success "工单处理成功".show(BaseApplication.get()) diff --git a/app/src/main/java/com/casic/app/smartwell/vm/OrderViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/OrderViewModel.kt index 4cb26b7..d2fad86 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/OrderViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/OrderViewModel.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.OrderDetailModel import com.casic.app.smartwell.model.OrderListModel import com.casic.app.smartwell.model.OrderStatusModel @@ -37,7 +37,7 @@ val response = RetrofitServiceManager.getSearchResult( keywords, alarmContent, alarmLevel, jobStatus, deptId, beginTime, endTime, offset ) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success searchResult.value = gson.fromJson( @@ -53,7 +53,7 @@ fun getWorkOrderListByState(jobStatus: String, page: Int) = launch({ val response = RetrofitServiceManager.getWorkOrderList(jobStatus, page) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { orderList.value = gson.fromJson( response, object : TypeToken() {}.type @@ -65,7 +65,7 @@ fun getNotAcceptOderList(page: Int) = launch({ val response = RetrofitServiceManager.getNotAcceptOderList(page) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { orderList.value = gson.fromJson( response, object : TypeToken() {}.type @@ -77,7 +77,7 @@ fun getNotHandleOderList(page: Int) = launch({ val response = RetrofitServiceManager.getNotHandleOderList(page) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { orderList.value = gson.fromJson( response, object : TypeToken() {}.type @@ -89,7 +89,7 @@ fun countWorkOrderByState() = launch({ val response = RetrofitServiceManager.countWorkOrderByState() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { val map = HashMap(4) @@ -107,7 +107,7 @@ fun getOrderStatus() = launch({ val response = RetrofitServiceManager.getOrderStatus() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { orderStatusModel.value = gson.fromJson( response, object : TypeToken() {}.type @@ -120,7 +120,7 @@ fun getWorkOrderDetail(id: String) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.getWorkOrderDetail(id) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success detailModel.value = gson.fromJson( diff --git a/app/src/main/java/com/casic/app/smartwell/vm/PipelineViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/PipelineViewModel.kt new file mode 100644 index 0000000..60c1e2f --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/vm/PipelineViewModel.kt @@ -0,0 +1,28 @@ +package com.casic.app.smartwell.vm + +import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.extensions.getResponseCode +import com.casic.app.smartwell.model.PipelineModel +import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken +import com.pengxh.kt.lite.base.BaseViewModel +import com.pengxh.kt.lite.extensions.launch + +class PipelineViewModel : BaseViewModel() { + + private val gson by lazy { Gson() } + val lineResult = MutableLiveData() + + fun getPipeline() = launch({ + val response = RetrofitServiceManager.getPipeline() + val responseCode = response.getResponseCode() + if (responseCode == 200) { + lineResult.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } + }, { + it.printStackTrace() + }) +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/PushViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/PushViewModel.kt index 9279815..12fd610 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/PushViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/PushViewModel.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.CommonResultModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager import com.google.gson.Gson @@ -16,7 +16,7 @@ fun registerPush(clientId: String) = launch({ val response = RetrofitServiceManager.registerPush(clientId) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { registerResultModel.value = gson.fromJson( response, object : TypeToken() {}.type diff --git a/app/src/main/java/com/casic/app/smartwell/vm/UploadImageViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/UploadImageViewModel.kt index 8d6744e..9707eeb 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/UploadImageViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/UploadImageViewModel.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.CommonResultModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager import com.google.gson.Gson @@ -19,7 +19,7 @@ fun uploadImage(image: File) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.uploadImage(image) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success resultModel.value = gson.fromJson( diff --git a/app/src/main/java/com/casic/app/smartwell/vm/UserViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/UserViewModel.kt index 31a4d4c..070c35a 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/UserViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/UserViewModel.kt @@ -2,7 +2,7 @@ import androidx.lifecycle.MutableLiveData import com.casic.app.smartwell.base.BaseApplication -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.SubordinateModel import com.casic.app.smartwell.model.UserDetailModel import com.casic.app.smartwell.model.VersionResultModel @@ -25,7 +25,7 @@ fun getUserDetail() = launch({ val response = RetrofitServiceManager.getUserDetail() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { val userDetail = gson.fromJson( response, object : TypeToken() {}.type @@ -48,7 +48,7 @@ * */ fun getSubordinate(hasMine: String?, deptId: String?, roleTips: String?) = launch({ val response = RetrofitServiceManager.getSubordinate(hasMine, deptId, roleTips) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { subordinateModel.value = gson.fromJson( response, object : TypeToken() {}.type @@ -61,7 +61,7 @@ fun changePassword(oldPwd: String, newPwd: String) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.changePassword(oldPwd, newPwd) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success "修改成功,请重新登录".show(BaseApplication.get()) @@ -76,7 +76,7 @@ fun updateVersion() = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.updateVersion() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success versionResultModel.value = gson.fromJson( diff --git a/app/src/main/java/com/casic/app/smartwell/vm/WellViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/WellViewModel.kt index 3d41e9b..9e42e36 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/WellViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/WellViewModel.kt @@ -2,8 +2,7 @@ import androidx.lifecycle.MutableLiveData import com.casic.app.smartwell.base.BaseApplication -import com.casic.app.smartwell.extensions.separateResponseCode -import com.casic.app.smartwell.extensions.toErrorMessage +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.AuthorDeptModel import com.casic.app.smartwell.model.CommonResultModel import com.casic.app.smartwell.model.MapWellListModel @@ -32,7 +31,7 @@ fun countWellByState() = launch({ val response = RetrofitServiceManager.countWellByState() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { val map = HashMap(3) @@ -57,7 +56,7 @@ fun getWellType() = launch({ val response = RetrofitServiceManager.getWellType() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { wellTypeModel.value = gson.fromJson( response, object : TypeToken() {}.type @@ -70,7 +69,7 @@ fun getWellDetail(id: String) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.getWellDetail(id) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success wellDetailModel.value = gson.fromJson( @@ -87,7 +86,7 @@ fun getOperationResult(id: String, state: String) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.getOperationResult(id, state) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success "操作成功".show(BaseApplication.get()) @@ -105,7 +104,7 @@ fun getMonitorResult(id: String) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.getMonitorResult(id) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success monitorModel.value = gson.fromJson( @@ -125,7 +124,7 @@ val response = RetrofitServiceManager.getWellListByPage( keywords, wellType, deptid, bfzt, page ) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { listModel.value = gson.fromJson( response, object : TypeToken() {}.type @@ -137,13 +136,11 @@ fun getWellList() = launch({ val response = RetrofitServiceManager.getWellList() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { totalWellModel.value = gson.fromJson( response, object : TypeToken() {}.type ) - } else { - response.toErrorMessage().show(BaseApplication.get()) } }, { it.printStackTrace() diff --git a/app/src/main/java/com/casic/app/smartwell/widgets/GaoDeClusterMarkerView.kt b/app/src/main/java/com/casic/app/smartwell/widgets/GaoDeClusterMarkerView.kt deleted file mode 100644 index 1f375df..0000000 --- a/app/src/main/java/com/casic/app/smartwell/widgets/GaoDeClusterMarkerView.kt +++ /dev/null @@ -1,100 +0,0 @@ -package com.casic.app.smartwell.widgets - -import android.content.Context -import android.graphics.Bitmap -import android.graphics.Point -import android.view.Gravity -import android.view.LayoutInflater -import android.view.View -import android.widget.TextView -import com.amap.api.maps.Projection -import com.amap.api.maps.model.BitmapDescriptorFactory -import com.amap.api.maps.model.LatLng -import com.amap.api.maps.model.LatLngBounds -import com.amap.api.maps.model.MarkerOptions -import com.casic.app.smartwell.R -import com.pengxh.kt.lite.extensions.toBitmap -import java.util.* - -class GaoDeClusterMarkerView( - private val context: Context, firstMarkers: MarkerOptions, projection: Projection, gridSize: Int -) { - //当前可观区域里的 聚合过之后的集合 - private val includeMarkers: ArrayList - - // 创建区域 - val bounds: LatLngBounds - var options: MarkerOptions = MarkerOptions() - - init { - val screenLocation = projection.toScreenLocation(firstMarkers.position) - //范围类 - val southwestPoint = Point(screenLocation.x - gridSize, screenLocation.y + gridSize) - //范围类 - val northeastPoint = Point(screenLocation.x + gridSize, screenLocation.y - gridSize) - bounds = LatLngBounds( - projection.fromScreenLocation(southwestPoint), - projection.fromScreenLocation(northeastPoint) - ) - //设置初始化marker属性 - options.anchor(0.5f, 1.3f) - .title(firstMarkers.title) - .position(firstMarkers.position) - .icon(firstMarkers.icon) - .snippet(firstMarkers.snippet) - .draggable(false) - includeMarkers = ArrayList() - includeMarkers.add(firstMarkers) - } - - /** - * 添加marker - */ - fun addMarker(markerOptions: MarkerOptions) { - includeMarkers.add(markerOptions) // 添加到列表中 - } - - /** - * 设置聚合点的中心位置以及图标 - */ - fun setPositionAndIcon() { - val size = includeMarkers.size - var lat = 0.0 - var lng = 0.0 - // 一个的时候 - if (size == 1) { //设置marker单个属性 - // 设置marker位置 - options.position( - LatLng( - includeMarkers[0].position.latitude, includeMarkers[0].position.longitude - ) - ) - } else { // 聚合的时候 - //设置marker聚合属性 - for (op in includeMarkers) { - lat += op.position.latitude - lng += op.position.longitude - } - // 设置marker的位置为中心位置为聚集点的平均位置 - options.position(LatLng(lat / size, lng / size)) - } - options.icon(BitmapDescriptorFactory.fromBitmap(getBitmap(size))) - } - - /** - * marker视图 - */ - private fun getBitmap(num: Int): Bitmap? { - val view = LayoutInflater.from(context).inflate(R.layout.marker_gaode, null) - val wellCountView = view.findViewById(R.id.wellCountView) - return if (num > 1) { - wellCountView.visibility = View.VISIBLE - wellCountView.text = String.format("${num}个") - wellCountView.gravity = Gravity.CENTER - view.toBitmap() - } else { - wellCountView.visibility = View.GONE - BitmapDescriptorFactory.fromResource(R.mipmap.well_location).bitmap - } - } -} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/extensions/Int.kt b/app/src/main/java/com/casic/app/smartwell/extensions/Int.kt index de0617b..a0a5e33 100644 --- a/app/src/main/java/com/casic/app/smartwell/extensions/Int.kt +++ b/app/src/main/java/com/casic/app/smartwell/extensions/Int.kt @@ -1,9 +1,24 @@ package com.casic.app.smartwell.extensions +import android.graphics.Bitmap +import android.graphics.Canvas +import android.graphics.Paint +import android.graphics.RectF + fun Int.toLevel(): String { return if (this == 0) { "" } else { this.toString() } +} + +fun Int.drawCircle(color: Int): Bitmap? { + val bitmap = Bitmap.createBitmap(this * 2, this * 2, Bitmap.Config.ARGB_8888) + val canvas = Canvas(bitmap) + val paint = Paint() + val rectF = RectF(0f, 0f, (this * 2).toFloat(), (this * 2).toFloat()) + paint.color = color + canvas.drawArc(rectF, 0f, 360f, true, paint) + return bitmap } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt index 6b6ca3e..5e45534 100644 --- a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt +++ b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt @@ -2,17 +2,13 @@ import android.content.Context import com.casic.app.smartwell.callback.OnImageCompressListener -import com.casic.app.smartwell.model.ErrorMessageModel import com.casic.app.smartwell.utils.LocaleConstant -import com.google.gson.Gson -import com.google.gson.reflect.TypeToken +import com.google.gson.JsonParser import com.pengxh.kt.lite.extensions.createCompressImageDir import com.pengxh.kt.lite.utils.SaveKeyValues -import org.json.JSONObject import top.zibin.luban.Luban import top.zibin.luban.OnCompressListener import java.io.File -import java.util.Locale /** * String扩展方法 @@ -74,18 +70,22 @@ } } -fun String.separateResponseCode(): Int { +fun String.getResponseCode(): Int { if (this.isBlank()) { return 404 } - return JSONObject(this).getInt("code") + val element = JsonParser.parseString(this) + val jsonObject = element.asJsonObject + return jsonObject.get("code").asInt } -fun String.toErrorMessage(): String { - val errorModel = Gson().fromJson( - this, object : TypeToken() {}.type - ) - return errorModel.message.toString() +fun String.getResponseMessage(): String { + if (this.isBlank()) { + return "" + } + val element = JsonParser.parseString(this) + val jsonObject = element.asJsonObject + return jsonObject.get("message").asString } fun String.compressImage(context: Context, listener: OnImageCompressListener) { @@ -93,9 +93,6 @@ .load(this) .ignoreBy(100) .setTargetDir(context.createCompressImageDir().toString()) - .filter { - !(it.isBlank() || it.lowercase(Locale.getDefault()).endsWith(".gif")) - } .setCompressListener(object : OnCompressListener { override fun onStart() { 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 96df110..cd25fca 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 @@ -1,26 +1,25 @@ package com.casic.app.smartwell.fragment -import android.graphics.Point +import android.graphics.Color +import android.graphics.drawable.BitmapDrawable +import android.graphics.drawable.Drawable 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 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.LatLngBounds import com.amap.api.maps.model.Marker -import com.amap.api.maps.model.MarkerOptions import com.casic.app.smartwell.R import com.casic.app.smartwell.databinding.FragmentHomeBinding +import com.casic.app.smartwell.extensions.drawCircle import com.casic.app.smartwell.extensions.initImmersionBar -import com.casic.app.smartwell.extensions.valueToType import com.casic.app.smartwell.model.MapWellListModel import com.casic.app.smartwell.utils.LocaleConstant import com.casic.app.smartwell.utils.RouteOnMap @@ -31,9 +30,16 @@ import com.casic.app.smartwell.view.WellOperationActivity import com.casic.app.smartwell.vm.OrderViewModel import com.casic.app.smartwell.vm.WellViewModel +import com.casic.app.smartwell.widgets.MapWellPopup +import com.casic.app.smartwell.widgets.cluster.ClusterItem +import com.casic.app.smartwell.widgets.cluster.ClusterOnClickListener +import com.casic.app.smartwell.widgets.cluster.ClusterOverlay +import com.casic.app.smartwell.widgets.cluster.RegionItem 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.convertDrawable +import com.pengxh.kt.lite.extensions.dp2px import com.pengxh.kt.lite.extensions.navigatePageTo import com.pengxh.kt.lite.extensions.show import com.pengxh.kt.lite.utils.LoadingDialogHub @@ -43,35 +49,23 @@ /** * 地图点位带聚合效果 * */ -class HomePageHaveClusterFragment : KotlinBaseFragment(), AMap.OnMapLoadedListener, - AMap.OnCameraChangeListener, AMap.OnMarkerClickListener, AMap.InfoWindowAdapter, - AMap.OnInfoWindowClickListener { +class HomePageHaveClusterFragment : KotlinBaseFragment(), + AMap.OnCameraChangeListener { private val kTag = "HaveClusterFragment" private val easyPopupWindow by lazy { EasyPopupWindow(requireContext()) } - private lateinit var wellViewModel: WellViewModel - private lateinit var orderViewModel: OrderViewModel - private lateinit var aMap: AMap - - /** - * 所有的marker - */ - private var allMarkerOptions: MutableList = ArrayList() - - /** - * 视野内的marker - */ - private var markerOptionsInView: MutableList = ArrayList() - - /** - * 自定义Marker弹出框 - * */ - private lateinit var v: View + private val regionRadius by lazy { LocaleConstant.RADIUS_SIZE.dp2px(requireContext()) } + private val infoPopup by lazy { MapWellPopup(requireContext()) } /** * 所有窨井列表信息集合 * */ - private var wellModels: MutableList = ArrayList() + private val wellModels = ArrayList() + private val backDrawables = HashMap() + private lateinit var wellViewModel: WellViewModel + private lateinit var orderViewModel: OrderViewModel + private lateinit var aMap: AMap + private var clusterOverlay: ClusterOverlay? = null override fun initViewBinding( inflater: LayoutInflater, @@ -106,6 +100,9 @@ } }) + //地图初始化 + initMap(savedInstanceState) + //初始化vm wellViewModel = ViewModelProvider(this)[WellViewModel::class.java] orderViewModel = ViewModelProvider(this)[OrderViewModel::class.java] @@ -120,25 +117,19 @@ val latitudeList: MutableList = ArrayList() val longitudeList: MutableList = ArrayList() it.data?.forEach { well -> - val lat = well.latGaode.toString() - val lng = well.lngGaode.toString() + val lat = well.latGaode + val lng = well.lngGaode if (lat.isNotBlank() && lng.isNotBlank()) { //返回true代表当前位置在大陆、港澳地区,反之不在 val latitude = lat.toDouble() val longitude = lng.toDouble() if (CoordinateConverter.isAMapDataAvailable(latitude, longitude)) { - //缓存所有设备详情,点击Marker时候需要 + //缓存所有井 wellModels.add(well) + //分别缓存经、纬度 latitudeList.add(latitude) longitudeList.add(longitude) - //将所有设备信息转化缓存为Marker点 - allMarkerOptions.add( - MarkerOptions() - .position(LatLng(latitude, longitude)) - .title(well.wellTypeName) - .snippet(well.wellName) - ) } } } @@ -160,12 +151,12 @@ val cameraPosition = CameraPosition(centerLatLng, 16f, 0f, 0f) val cameraUpdate = CameraUpdateFactory.newCameraPosition(cameraPosition) aMap.animateCamera(cameraUpdate, 1500, null) + + //显示点数据 + displayWellOnMap() } } - //地图初始化 - initMap(savedInstanceState) - //获取窨井监控数据 wellViewModel.countResultModel.observe(this) { binding.deployedWellView.text = it["bfWell"] @@ -220,17 +211,10 @@ uiSettings.isCompassEnabled = true uiSettings.zoomPosition = AMapOptions.ZOOM_POSITION_RIGHT_CENTER uiSettings.isTiltGesturesEnabled = false//不许地图随手势倾斜角度 + uiSettings.isRotateGesturesEnabled = false//不允许地图随手势改变方位 - // 地图加载成功监听 - aMap.addOnMapLoadedListener(this) // 地图缩放监听 aMap.addOnCameraChangeListener(this) - // marker 点击事件监听 - aMap.addOnMarkerClickListener(this) - // 点击marker弹出自定义popup - aMap.setInfoWindowAdapter(this) - //信息窗点击事件 - aMap.addOnInfoWindowClickListener(this) } override fun initEvent() { @@ -259,9 +243,111 @@ } - override fun onMapLoaded() { - //地图加载成功之后显示聚合点数据 - initClustersMarkers() + private fun displayWellOnMap() { + clusterOverlay?.onDestroy() + val clusterItems = ArrayList() + + wellModels.forEach { + val latitude = it.latGaode.toDouble() + val longitude = it.lngGaode.toDouble() + + val latLng = LatLng(latitude, longitude, false) + val regionItem = RegionItem(latLng, it) + clusterItems.add(regionItem) + } + + clusterOverlay = ClusterOverlay(requireContext(), aMap, clusterItems, regionRadius) + clusterOverlay?.setClusterRender { clusterNum -> + //聚合圆半径 + val radius = 100.dp2px(requireContext()) + if (clusterNum == 0) { + var bitmapDrawable = backDrawables[0] + if (bitmapDrawable == null) { + bitmapDrawable = BitmapDrawable( + null, radius.drawCircle(Color.argb(159, 100, 149, 237)) + ) + backDrawables[0] = bitmapDrawable + } + bitmapDrawable + } + if (clusterNum == 1) { + var bitmapDrawable = backDrawables[1] + if (bitmapDrawable == null) { + bitmapDrawable = R.mipmap.well_location.convertDrawable(requireContext())!! + backDrawables[1] = bitmapDrawable + } + bitmapDrawable + } else if (clusterNum < 5) { + var bitmapDrawable = backDrawables[2] + if (bitmapDrawable == null) { + bitmapDrawable = BitmapDrawable( + null, radius.drawCircle(Color.argb(159, 100, 149, 237)) + ) + backDrawables[2] = bitmapDrawable + } + bitmapDrawable + } else if (clusterNum < 10) { + var bitmapDrawable = backDrawables[3] + if (bitmapDrawable == null) { + bitmapDrawable = BitmapDrawable( + null, radius.drawCircle(Color.argb(199, 30, 144, 255)) + ) + backDrawables[3] = bitmapDrawable + } + bitmapDrawable + } else { + var bitmapDrawable = backDrawables[4] + if (bitmapDrawable == null) { + bitmapDrawable = BitmapDrawable( + null, radius.drawCircle(Color.argb(235, 65, 105, 225)) + ) + backDrawables[4] = bitmapDrawable + } + bitmapDrawable + } + } + + clusterOverlay?.setOnClusterClickListener(object : ClusterOnClickListener { + override fun onMarkerClicked(marker: Marker?, items: List) { + if (items.size > 1) { + "请缩放地图比例在查看数据".show(requireContext()) + return + } + + var item: RegionItem? = null + val builder = LatLngBounds.Builder() + for (clusterItem in items) { + builder.include(clusterItem.position) + item = clusterItem as RegionItem + } + + item?.apply { + showWellPopup(well) + } + } + }) + } + + private fun showWellPopup(well: MapWellListModel.DataModel) { + infoPopup.set(well, object : MapWellPopup.OnPopupWindowClickListener { + override fun onPopupClicked(lat: Double, lng: Double) { + AlertControlDialog.Builder().setContext(requireContext()).setTitle("操作提示") + .setMessage("确定要前往吗").setNegativeButton("取消").setPositiveButton("确定") + .setOnDialogButtonClickListener(object : + AlertControlDialog.OnDialogButtonClickListener { + override fun onConfirmClick() { + RouteOnMap.startNavigation( + requireContext(), "", LatLng(lat, lng) + ) + } + + override fun onCancelClick() { + + } + }).build().show() + } + }) + infoPopup.showAsDropDown(binding.rightOptionView) } override fun onCameraChange(p0: CameraPosition?) { @@ -282,103 +368,10 @@ } } - //获取视野内的marker 根据聚合算法合成自定义的marker 显示视野内的marker override fun onCameraChangeFinish(p0: CameraPosition?) { //地图缩放之后显示聚合点数据 LoadingDialogHub.dismiss() httpCountDownTimer.cancel() - initClustersMarkers() - } - - private fun initClustersMarkers() { - 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 { - v = LayoutInflater.from(requireContext()).inflate(R.layout.popup_map_info, null) - - //显示闸井信息 - marker?.showInfoWindow() - return true - } - - override fun getInfoWindow(marker: Marker?): View { - //反射得到popup里面的控件对象 - val wellNameView = v.findViewById(R.id.wellNameView) - val wellCodeView = v.findViewById(R.id.wellCodeView) - val wellTypeView = v.findViewById(R.id.wellTypeView) - val wellStateView = v.findViewById(R.id.wellStateView) - val deepView = v.findViewById(R.id.deepView) - val locationView = v.findViewById(R.id.locationView) - - //绑定数据 - val clickedLatLng = marker?.position!! - wellModels.forEach { well -> - if (clickedLatLng.latitude == well.latGaode!!.toDouble() - && clickedLatLng.longitude == well.lngGaode!!.toDouble() - ) { - wellNameView.text = String.format("点位名称: ${well.wellName}") - wellCodeView.text = String.format("点位编号: ${well.wellCode}") - wellTypeView.text = String.format("点位类型: ${well.wellType.valueToType()}") - val bfztName = if (well.bfzt == "1") { - "已布防" - } else { - "已撤防" - } - wellStateView.text = String.format("布/撤防状态: $bfztName") - deepView.text = String.format("点位深度: ${well.deep}m") - locationView.text = String.format("详细位置: ${well.position}") - } - } - return v - } - - /** - * 此方法不能修改整个 InfoWindow 的背景和边框,无论自定义的样式是什么样,SDK 都会在最外层添加一个默认的边框 - * */ - override fun getInfoContents(p0: Marker?): View? = null - - override fun onInfoWindowClick(p0: Marker?) { - p0?.apply { - AlertControlDialog.Builder() - .setContext(requireContext()) - .setTitle("操作提示") - .setMessage("确定要前往吗") - .setNegativeButton("取消") - .setPositiveButton("确定") - .setOnDialogButtonClickListener(object : - AlertControlDialog.OnDialogButtonClickListener { - override fun onConfirmClick() { - val lat = position.latitude.toString() - val lng = position.longitude.toString() - if (lat.isBlank() || lng.isBlank()) { - "点位经纬度异常,无法开启导航".show(requireContext()) - return - } - RouteOnMap.startNavigation( - requireContext(), snippet, LatLng(lat.toDouble(), lng.toDouble()) - ) - } - - override fun onCancelClick() { - - } - }).build().show() - } } /***以下是地图生命周期管理************************************************************************/ 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 a54d213..bfa7a57 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 @@ -44,8 +44,8 @@ * 地图点位不带聚合效果 * */ class HomePageNoClusterFragment : KotlinBaseFragment(), - AMap.OnMapLoadedListener, AMap.OnCameraChangeListener, AMap.OnMarkerClickListener, - AMap.InfoWindowAdapter, AMap.OnInfoWindowClickListener { + AMap.OnCameraChangeListener, AMap.OnMarkerClickListener, AMap.InfoWindowAdapter, + AMap.OnInfoWindowClickListener { private val kTag = "NoClusterFragment" private val easyPopupWindow by lazy { EasyPopupWindow(requireContext()) } @@ -109,6 +109,9 @@ wellViewModel = ViewModelProvider(this)[WellViewModel::class.java] orderViewModel = ViewModelProvider(this)[OrderViewModel::class.java] + //地图初始化 + initMap(savedInstanceState) + //获取所有窨井数据 httpCountDownTimer.start() LoadingDialogHub.show(requireActivity(), "数据加载中,请稍后...") @@ -157,12 +160,12 @@ val cameraPosition = CameraPosition(centerLatLng, 16f, 0f, 0f) val cameraUpdate = CameraUpdateFactory.newCameraPosition(cameraPosition) aMap.animateCamera(cameraUpdate, 1500, null) + + //显示点数据 + displayWellOnMap() } } - //地图初始化 - initMap(savedInstanceState) - //获取窨井监控数据 wellViewModel.countResultModel.observe(this) { binding.deployedWellView.text = it["bfWell"] @@ -214,9 +217,8 @@ uiSettings.isCompassEnabled = true uiSettings.zoomPosition = AMapOptions.ZOOM_POSITION_RIGHT_CENTER uiSettings.isTiltGesturesEnabled = false//不许地图随手势倾斜角度 + uiSettings.isRotateGesturesEnabled = false//不允许地图随手势改变方位 - // 地图加载成功监听 - aMap.addOnMapLoadedListener(this) // 地图缩放监听 aMap.addOnCameraChangeListener(this) // marker 点击事件监听 @@ -253,11 +255,6 @@ } - override fun onMapLoaded() { - //地图加载成功之后显示聚合点数据 - initClustersMarkers() - } - override fun onCameraChange(p0: CameraPosition?) { } @@ -281,10 +278,9 @@ //地图缩放之后显示聚合点数据 LoadingDialogHub.dismiss() httpCountDownTimer.cancel() - initClustersMarkers() } - private fun initClustersMarkers() { + private fun displayWellOnMap() { val proj = aMap.projection val dm = resources.displayMetrics var screenLocation: Point diff --git a/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.java b/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.java deleted file mode 100644 index d8b18ef..0000000 --- a/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.java +++ /dev/null @@ -1,50 +0,0 @@ -package com.casic.app.smartwell.model; - -public class ErrorMessageModel { - - private int code; - private String data; - private String exceptionClazz; - private String message; - private boolean success; - - public int getCode() { - return code; - } - - public void setCode(int code) { - this.code = code; - } - - public String getData() { - return data; - } - - public void setData(String data) { - this.data = data; - } - - public String getExceptionClazz() { - return exceptionClazz; - } - - public void setExceptionClazz(String exceptionClazz) { - this.exceptionClazz = exceptionClazz; - } - - public String getMessage() { - return message; - } - - public void setMessage(String message) { - this.message = message; - } - - public boolean isSuccess() { - return success; - } - - public void setSuccess(boolean success) { - this.success = success; - } -} \ No newline at end of file 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 new file mode 100644 index 0000000..215ac0c --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/PipelineModel.java @@ -0,0 +1,328 @@ +package com.casic.app.smartwell.model; + +import java.util.List; + +public class PipelineModel { + + private Integer code; + private DataModel data; + private String message; + private Boolean success; + + public Integer getCode() { + return code; + } + + public void setCode(Integer code) { + this.code = code; + } + + public DataModel getData() { + return data; + } + + public void setData(DataModel data) { + this.data = data; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + public Boolean getSuccess() { + return success; + } + + public void setSuccess(Boolean success) { + this.success = success; + } + + public static class DataModel { + private List rows; + private Integer total; + + public List getRows() { + return rows; + } + + public void setRows(List rows) { + this.rows = rows; + } + + public Integer getTotal() { + return total; + } + + public void setTotal(Integer total) { + this.total = total; + } + + 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 getBuryMode() { + return buryMode; + } + + public void setBuryMode(String buryMode) { + this.buryMode = buryMode; + } + + public String getConstructEra() { + return constructEra; + } + + public void setConstructEra(String constructEra) { + this.constructEra = constructEra; + } + + 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; + } + } + } +} 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 06d3d2b..4f38a2c 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 = 100 //相距多少米才聚合,单位:米 + const val RADIUS_SIZE = 80 //相距多少米才聚合,单位:米 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:11308" + // 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 0d5f3fa..991e1db 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 @@ -312,4 +312,14 @@ @Header("token") token: String, @Field("clientid") deviceCode: String ): String + + /** + * 管线位置数据 + */ + @GET("/pipeline/listPage") + suspend fun getPipeline( + @Header("token") token: String, + @Query("limit") limit: Int, + @Query("offset") offset: Int + ): String } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt index 1a0ce22..4050067 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt @@ -294,4 +294,11 @@ suspend fun registerPush(clientId: String): String { return api.registerPush(AuthenticationHelper.token!!, clientId) } + + /** + * 管线位置数据 + */ + suspend fun getPipeline(): String { + return api.getPipeline(AuthenticationHelper.token!!, 2000, 1) + } } \ No newline at end of file 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 9270fa1..4ca5a5e 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.HomePageNoClusterFragment +import com.casic.app.smartwell.fragment.HomePageHaveClusterFragment 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/vm/AlarmViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/AlarmViewModel.kt index 9cff08c..e7acc17 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/AlarmViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/AlarmViewModel.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.AlarmContentModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager import com.google.gson.Gson @@ -16,7 +16,7 @@ fun getAlarmContentType(alarmType: String) = launch({ val response = RetrofitServiceManager.getAlarmContentType(alarmType) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { listModel.value = gson.fromJson( response, object : TypeToken() {}.type diff --git a/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt index 5e5b163..895dedd 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.PublicKeyModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager import com.google.gson.Gson @@ -18,7 +18,7 @@ fun getPublicKey() = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.authenticate() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { keyModel.value = gson.fromJson( response, object : TypeToken() {}.type diff --git a/app/src/main/java/com/casic/app/smartwell/vm/DeviceViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/DeviceViewModel.kt index db5ccf6..899a962 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/DeviceViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/DeviceViewModel.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.DeviceDetailModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager import com.google.gson.Gson @@ -16,7 +16,7 @@ fun getDeviceDetail(deviceCode: String) = launch({ val response = RetrofitServiceManager.getDeviceDetail(deviceCode) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { detailModel.value = gson.fromJson( response, object : TypeToken() {}.type diff --git a/app/src/main/java/com/casic/app/smartwell/vm/LoginViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/LoginViewModel.kt index cd8b8a9..a417398 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/LoginViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/LoginViewModel.kt @@ -2,7 +2,7 @@ import androidx.lifecycle.MutableLiveData import com.casic.app.smartwell.base.BaseApplication -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.CommonResultModel import com.casic.app.smartwell.model.LoginResultModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -21,7 +21,7 @@ fun enter(account: String, secretKey: String) = launch({ val response = RetrofitServiceManager.login(account, secretKey) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success enterResultModel.value = gson.fromJson( @@ -38,7 +38,7 @@ fun out() = launch({ val response = RetrofitServiceManager.loginOut() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { outResultModel.value = gson.fromJson( response, object : TypeToken() {}.type diff --git a/app/src/main/java/com/casic/app/smartwell/vm/OperationViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/OperationViewModel.kt index 8943ed3..37e115f 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/OperationViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/OperationViewModel.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.vm import com.casic.app.smartwell.base.BaseApplication -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager import com.pengxh.kt.lite.base.BaseViewModel import com.pengxh.kt.lite.extensions.launch @@ -16,7 +16,7 @@ fun acceptWorkOrder(id: String) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.acceptWorkOrder(id) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success "接单成功".show(BaseApplication.get()) @@ -35,7 +35,7 @@ loadState.value = LoadState.Loading val response = RetrofitServiceManager.confirmWorkOrder(id, firstState, firstStatePhotos, needHandle) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success "工单确认成功".show(BaseApplication.get()) @@ -50,7 +50,7 @@ fun transferWorkOrder(id: String, userId: String) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.transferWorkOrder(id, userId) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success "转单成功".show(BaseApplication.get()) @@ -65,7 +65,7 @@ fun completeWorkOrder(id: String, handleMessage: String, handlePhotos: String) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.completeWorkOrder(id, handleMessage, handlePhotos) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success "工单处理成功".show(BaseApplication.get()) diff --git a/app/src/main/java/com/casic/app/smartwell/vm/OrderViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/OrderViewModel.kt index 4cb26b7..d2fad86 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/OrderViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/OrderViewModel.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.OrderDetailModel import com.casic.app.smartwell.model.OrderListModel import com.casic.app.smartwell.model.OrderStatusModel @@ -37,7 +37,7 @@ val response = RetrofitServiceManager.getSearchResult( keywords, alarmContent, alarmLevel, jobStatus, deptId, beginTime, endTime, offset ) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success searchResult.value = gson.fromJson( @@ -53,7 +53,7 @@ fun getWorkOrderListByState(jobStatus: String, page: Int) = launch({ val response = RetrofitServiceManager.getWorkOrderList(jobStatus, page) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { orderList.value = gson.fromJson( response, object : TypeToken() {}.type @@ -65,7 +65,7 @@ fun getNotAcceptOderList(page: Int) = launch({ val response = RetrofitServiceManager.getNotAcceptOderList(page) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { orderList.value = gson.fromJson( response, object : TypeToken() {}.type @@ -77,7 +77,7 @@ fun getNotHandleOderList(page: Int) = launch({ val response = RetrofitServiceManager.getNotHandleOderList(page) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { orderList.value = gson.fromJson( response, object : TypeToken() {}.type @@ -89,7 +89,7 @@ fun countWorkOrderByState() = launch({ val response = RetrofitServiceManager.countWorkOrderByState() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { val map = HashMap(4) @@ -107,7 +107,7 @@ fun getOrderStatus() = launch({ val response = RetrofitServiceManager.getOrderStatus() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { orderStatusModel.value = gson.fromJson( response, object : TypeToken() {}.type @@ -120,7 +120,7 @@ fun getWorkOrderDetail(id: String) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.getWorkOrderDetail(id) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success detailModel.value = gson.fromJson( diff --git a/app/src/main/java/com/casic/app/smartwell/vm/PipelineViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/PipelineViewModel.kt new file mode 100644 index 0000000..60c1e2f --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/vm/PipelineViewModel.kt @@ -0,0 +1,28 @@ +package com.casic.app.smartwell.vm + +import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.extensions.getResponseCode +import com.casic.app.smartwell.model.PipelineModel +import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken +import com.pengxh.kt.lite.base.BaseViewModel +import com.pengxh.kt.lite.extensions.launch + +class PipelineViewModel : BaseViewModel() { + + private val gson by lazy { Gson() } + val lineResult = MutableLiveData() + + fun getPipeline() = launch({ + val response = RetrofitServiceManager.getPipeline() + val responseCode = response.getResponseCode() + if (responseCode == 200) { + lineResult.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } + }, { + it.printStackTrace() + }) +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/PushViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/PushViewModel.kt index 9279815..12fd610 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/PushViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/PushViewModel.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.CommonResultModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager import com.google.gson.Gson @@ -16,7 +16,7 @@ fun registerPush(clientId: String) = launch({ val response = RetrofitServiceManager.registerPush(clientId) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { registerResultModel.value = gson.fromJson( response, object : TypeToken() {}.type diff --git a/app/src/main/java/com/casic/app/smartwell/vm/UploadImageViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/UploadImageViewModel.kt index 8d6744e..9707eeb 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/UploadImageViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/UploadImageViewModel.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.CommonResultModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager import com.google.gson.Gson @@ -19,7 +19,7 @@ fun uploadImage(image: File) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.uploadImage(image) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success resultModel.value = gson.fromJson( diff --git a/app/src/main/java/com/casic/app/smartwell/vm/UserViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/UserViewModel.kt index 31a4d4c..070c35a 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/UserViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/UserViewModel.kt @@ -2,7 +2,7 @@ import androidx.lifecycle.MutableLiveData import com.casic.app.smartwell.base.BaseApplication -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.SubordinateModel import com.casic.app.smartwell.model.UserDetailModel import com.casic.app.smartwell.model.VersionResultModel @@ -25,7 +25,7 @@ fun getUserDetail() = launch({ val response = RetrofitServiceManager.getUserDetail() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { val userDetail = gson.fromJson( response, object : TypeToken() {}.type @@ -48,7 +48,7 @@ * */ fun getSubordinate(hasMine: String?, deptId: String?, roleTips: String?) = launch({ val response = RetrofitServiceManager.getSubordinate(hasMine, deptId, roleTips) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { subordinateModel.value = gson.fromJson( response, object : TypeToken() {}.type @@ -61,7 +61,7 @@ fun changePassword(oldPwd: String, newPwd: String) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.changePassword(oldPwd, newPwd) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success "修改成功,请重新登录".show(BaseApplication.get()) @@ -76,7 +76,7 @@ fun updateVersion() = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.updateVersion() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success versionResultModel.value = gson.fromJson( diff --git a/app/src/main/java/com/casic/app/smartwell/vm/WellViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/WellViewModel.kt index 3d41e9b..9e42e36 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/WellViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/WellViewModel.kt @@ -2,8 +2,7 @@ import androidx.lifecycle.MutableLiveData import com.casic.app.smartwell.base.BaseApplication -import com.casic.app.smartwell.extensions.separateResponseCode -import com.casic.app.smartwell.extensions.toErrorMessage +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.AuthorDeptModel import com.casic.app.smartwell.model.CommonResultModel import com.casic.app.smartwell.model.MapWellListModel @@ -32,7 +31,7 @@ fun countWellByState() = launch({ val response = RetrofitServiceManager.countWellByState() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { val map = HashMap(3) @@ -57,7 +56,7 @@ fun getWellType() = launch({ val response = RetrofitServiceManager.getWellType() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { wellTypeModel.value = gson.fromJson( response, object : TypeToken() {}.type @@ -70,7 +69,7 @@ fun getWellDetail(id: String) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.getWellDetail(id) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success wellDetailModel.value = gson.fromJson( @@ -87,7 +86,7 @@ fun getOperationResult(id: String, state: String) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.getOperationResult(id, state) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success "操作成功".show(BaseApplication.get()) @@ -105,7 +104,7 @@ fun getMonitorResult(id: String) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.getMonitorResult(id) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success monitorModel.value = gson.fromJson( @@ -125,7 +124,7 @@ val response = RetrofitServiceManager.getWellListByPage( keywords, wellType, deptid, bfzt, page ) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { listModel.value = gson.fromJson( response, object : TypeToken() {}.type @@ -137,13 +136,11 @@ fun getWellList() = launch({ val response = RetrofitServiceManager.getWellList() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { totalWellModel.value = gson.fromJson( response, object : TypeToken() {}.type ) - } else { - response.toErrorMessage().show(BaseApplication.get()) } }, { it.printStackTrace() diff --git a/app/src/main/java/com/casic/app/smartwell/widgets/GaoDeClusterMarkerView.kt b/app/src/main/java/com/casic/app/smartwell/widgets/GaoDeClusterMarkerView.kt deleted file mode 100644 index 1f375df..0000000 --- a/app/src/main/java/com/casic/app/smartwell/widgets/GaoDeClusterMarkerView.kt +++ /dev/null @@ -1,100 +0,0 @@ -package com.casic.app.smartwell.widgets - -import android.content.Context -import android.graphics.Bitmap -import android.graphics.Point -import android.view.Gravity -import android.view.LayoutInflater -import android.view.View -import android.widget.TextView -import com.amap.api.maps.Projection -import com.amap.api.maps.model.BitmapDescriptorFactory -import com.amap.api.maps.model.LatLng -import com.amap.api.maps.model.LatLngBounds -import com.amap.api.maps.model.MarkerOptions -import com.casic.app.smartwell.R -import com.pengxh.kt.lite.extensions.toBitmap -import java.util.* - -class GaoDeClusterMarkerView( - private val context: Context, firstMarkers: MarkerOptions, projection: Projection, gridSize: Int -) { - //当前可观区域里的 聚合过之后的集合 - private val includeMarkers: ArrayList - - // 创建区域 - val bounds: LatLngBounds - var options: MarkerOptions = MarkerOptions() - - init { - val screenLocation = projection.toScreenLocation(firstMarkers.position) - //范围类 - val southwestPoint = Point(screenLocation.x - gridSize, screenLocation.y + gridSize) - //范围类 - val northeastPoint = Point(screenLocation.x + gridSize, screenLocation.y - gridSize) - bounds = LatLngBounds( - projection.fromScreenLocation(southwestPoint), - projection.fromScreenLocation(northeastPoint) - ) - //设置初始化marker属性 - options.anchor(0.5f, 1.3f) - .title(firstMarkers.title) - .position(firstMarkers.position) - .icon(firstMarkers.icon) - .snippet(firstMarkers.snippet) - .draggable(false) - includeMarkers = ArrayList() - includeMarkers.add(firstMarkers) - } - - /** - * 添加marker - */ - fun addMarker(markerOptions: MarkerOptions) { - includeMarkers.add(markerOptions) // 添加到列表中 - } - - /** - * 设置聚合点的中心位置以及图标 - */ - fun setPositionAndIcon() { - val size = includeMarkers.size - var lat = 0.0 - var lng = 0.0 - // 一个的时候 - if (size == 1) { //设置marker单个属性 - // 设置marker位置 - options.position( - LatLng( - includeMarkers[0].position.latitude, includeMarkers[0].position.longitude - ) - ) - } else { // 聚合的时候 - //设置marker聚合属性 - for (op in includeMarkers) { - lat += op.position.latitude - lng += op.position.longitude - } - // 设置marker的位置为中心位置为聚集点的平均位置 - options.position(LatLng(lat / size, lng / size)) - } - options.icon(BitmapDescriptorFactory.fromBitmap(getBitmap(size))) - } - - /** - * marker视图 - */ - private fun getBitmap(num: Int): Bitmap? { - val view = LayoutInflater.from(context).inflate(R.layout.marker_gaode, null) - val wellCountView = view.findViewById(R.id.wellCountView) - return if (num > 1) { - wellCountView.visibility = View.VISIBLE - wellCountView.text = String.format("${num}个") - wellCountView.gravity = Gravity.CENTER - view.toBitmap() - } else { - wellCountView.visibility = View.GONE - BitmapDescriptorFactory.fromResource(R.mipmap.well_location).bitmap - } - } -} \ No newline at end of file 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 new file mode 100644 index 0000000..ec455dd --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/widgets/MapWellPopup.kt @@ -0,0 +1,58 @@ +package com.casic.app.smartwell.widgets + +import android.content.Context +import android.view.LayoutInflater +import android.view.ViewGroup +import android.widget.LinearLayout +import android.widget.PopupWindow +import android.widget.TextView +import com.casic.app.smartwell.R +import com.casic.app.smartwell.extensions.valueToType +import com.casic.app.smartwell.model.MapWellListModel + +class MapWellPopup constructor(context: Context) : PopupWindow() { + + init { + width = ViewGroup.LayoutParams.MATCH_PARENT + height = ViewGroup.LayoutParams.WRAP_CONTENT + isOutsideTouchable = true + isFocusable = true + animationStyle = R.style.MapPopupAnimation + setBackgroundDrawable(null) + contentView = LayoutInflater.from(context).inflate( + R.layout.popup_map_info, null, false + ) + } + + fun set(well: MapWellListModel.DataModel, windowClickListener: OnPopupWindowClickListener) { + //反射得到popup里面的控件对象 + val rootView = contentView.findViewById(R.id.rootView) + val wellNameView = contentView.findViewById(R.id.wellNameView) + val wellCodeView = contentView.findViewById(R.id.wellCodeView) + val wellTypeView = contentView.findViewById(R.id.wellTypeView) + val wellStateView = contentView.findViewById(R.id.wellStateView) + val deepView = contentView.findViewById(R.id.deepView) + val locationView = contentView.findViewById(R.id.locationView) + + //绑定数据 + wellNameView.text = String.format("点位名称: ${well.wellName}") + wellCodeView.text = String.format("点位编号: ${well.wellCode}") + wellTypeView.text = String.format("点位类型: ${well.wellType.valueToType()}") + val bfztName = if (well.bfzt == "1") { + "已布防" + } else { + "已撤防" + } + wellStateView.text = String.format("布/撤防状态: $bfztName") + deepView.text = String.format("点位深度: ${well.deep}m") + locationView.text = String.format("详细位置: ${well.position}") + + rootView.setOnClickListener { + windowClickListener.onPopupClicked(well.latGaode.toDouble(), well.lngGaode.toDouble()) + } + } + + interface OnPopupWindowClickListener { + fun onPopupClicked(lat: Double, lng: Double) + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/extensions/Int.kt b/app/src/main/java/com/casic/app/smartwell/extensions/Int.kt index de0617b..a0a5e33 100644 --- a/app/src/main/java/com/casic/app/smartwell/extensions/Int.kt +++ b/app/src/main/java/com/casic/app/smartwell/extensions/Int.kt @@ -1,9 +1,24 @@ package com.casic.app.smartwell.extensions +import android.graphics.Bitmap +import android.graphics.Canvas +import android.graphics.Paint +import android.graphics.RectF + fun Int.toLevel(): String { return if (this == 0) { "" } else { this.toString() } +} + +fun Int.drawCircle(color: Int): Bitmap? { + val bitmap = Bitmap.createBitmap(this * 2, this * 2, Bitmap.Config.ARGB_8888) + val canvas = Canvas(bitmap) + val paint = Paint() + val rectF = RectF(0f, 0f, (this * 2).toFloat(), (this * 2).toFloat()) + paint.color = color + canvas.drawArc(rectF, 0f, 360f, true, paint) + return bitmap } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt index 6b6ca3e..5e45534 100644 --- a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt +++ b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt @@ -2,17 +2,13 @@ import android.content.Context import com.casic.app.smartwell.callback.OnImageCompressListener -import com.casic.app.smartwell.model.ErrorMessageModel import com.casic.app.smartwell.utils.LocaleConstant -import com.google.gson.Gson -import com.google.gson.reflect.TypeToken +import com.google.gson.JsonParser import com.pengxh.kt.lite.extensions.createCompressImageDir import com.pengxh.kt.lite.utils.SaveKeyValues -import org.json.JSONObject import top.zibin.luban.Luban import top.zibin.luban.OnCompressListener import java.io.File -import java.util.Locale /** * String扩展方法 @@ -74,18 +70,22 @@ } } -fun String.separateResponseCode(): Int { +fun String.getResponseCode(): Int { if (this.isBlank()) { return 404 } - return JSONObject(this).getInt("code") + val element = JsonParser.parseString(this) + val jsonObject = element.asJsonObject + return jsonObject.get("code").asInt } -fun String.toErrorMessage(): String { - val errorModel = Gson().fromJson( - this, object : TypeToken() {}.type - ) - return errorModel.message.toString() +fun String.getResponseMessage(): String { + if (this.isBlank()) { + return "" + } + val element = JsonParser.parseString(this) + val jsonObject = element.asJsonObject + return jsonObject.get("message").asString } fun String.compressImage(context: Context, listener: OnImageCompressListener) { @@ -93,9 +93,6 @@ .load(this) .ignoreBy(100) .setTargetDir(context.createCompressImageDir().toString()) - .filter { - !(it.isBlank() || it.lowercase(Locale.getDefault()).endsWith(".gif")) - } .setCompressListener(object : OnCompressListener { override fun onStart() { 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 96df110..cd25fca 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 @@ -1,26 +1,25 @@ package com.casic.app.smartwell.fragment -import android.graphics.Point +import android.graphics.Color +import android.graphics.drawable.BitmapDrawable +import android.graphics.drawable.Drawable 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 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.LatLngBounds import com.amap.api.maps.model.Marker -import com.amap.api.maps.model.MarkerOptions import com.casic.app.smartwell.R import com.casic.app.smartwell.databinding.FragmentHomeBinding +import com.casic.app.smartwell.extensions.drawCircle import com.casic.app.smartwell.extensions.initImmersionBar -import com.casic.app.smartwell.extensions.valueToType import com.casic.app.smartwell.model.MapWellListModel import com.casic.app.smartwell.utils.LocaleConstant import com.casic.app.smartwell.utils.RouteOnMap @@ -31,9 +30,16 @@ import com.casic.app.smartwell.view.WellOperationActivity import com.casic.app.smartwell.vm.OrderViewModel import com.casic.app.smartwell.vm.WellViewModel +import com.casic.app.smartwell.widgets.MapWellPopup +import com.casic.app.smartwell.widgets.cluster.ClusterItem +import com.casic.app.smartwell.widgets.cluster.ClusterOnClickListener +import com.casic.app.smartwell.widgets.cluster.ClusterOverlay +import com.casic.app.smartwell.widgets.cluster.RegionItem 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.convertDrawable +import com.pengxh.kt.lite.extensions.dp2px import com.pengxh.kt.lite.extensions.navigatePageTo import com.pengxh.kt.lite.extensions.show import com.pengxh.kt.lite.utils.LoadingDialogHub @@ -43,35 +49,23 @@ /** * 地图点位带聚合效果 * */ -class HomePageHaveClusterFragment : KotlinBaseFragment(), AMap.OnMapLoadedListener, - AMap.OnCameraChangeListener, AMap.OnMarkerClickListener, AMap.InfoWindowAdapter, - AMap.OnInfoWindowClickListener { +class HomePageHaveClusterFragment : KotlinBaseFragment(), + AMap.OnCameraChangeListener { private val kTag = "HaveClusterFragment" private val easyPopupWindow by lazy { EasyPopupWindow(requireContext()) } - private lateinit var wellViewModel: WellViewModel - private lateinit var orderViewModel: OrderViewModel - private lateinit var aMap: AMap - - /** - * 所有的marker - */ - private var allMarkerOptions: MutableList = ArrayList() - - /** - * 视野内的marker - */ - private var markerOptionsInView: MutableList = ArrayList() - - /** - * 自定义Marker弹出框 - * */ - private lateinit var v: View + private val regionRadius by lazy { LocaleConstant.RADIUS_SIZE.dp2px(requireContext()) } + private val infoPopup by lazy { MapWellPopup(requireContext()) } /** * 所有窨井列表信息集合 * */ - private var wellModels: MutableList = ArrayList() + private val wellModels = ArrayList() + private val backDrawables = HashMap() + private lateinit var wellViewModel: WellViewModel + private lateinit var orderViewModel: OrderViewModel + private lateinit var aMap: AMap + private var clusterOverlay: ClusterOverlay? = null override fun initViewBinding( inflater: LayoutInflater, @@ -106,6 +100,9 @@ } }) + //地图初始化 + initMap(savedInstanceState) + //初始化vm wellViewModel = ViewModelProvider(this)[WellViewModel::class.java] orderViewModel = ViewModelProvider(this)[OrderViewModel::class.java] @@ -120,25 +117,19 @@ val latitudeList: MutableList = ArrayList() val longitudeList: MutableList = ArrayList() it.data?.forEach { well -> - val lat = well.latGaode.toString() - val lng = well.lngGaode.toString() + val lat = well.latGaode + val lng = well.lngGaode if (lat.isNotBlank() && lng.isNotBlank()) { //返回true代表当前位置在大陆、港澳地区,反之不在 val latitude = lat.toDouble() val longitude = lng.toDouble() if (CoordinateConverter.isAMapDataAvailable(latitude, longitude)) { - //缓存所有设备详情,点击Marker时候需要 + //缓存所有井 wellModels.add(well) + //分别缓存经、纬度 latitudeList.add(latitude) longitudeList.add(longitude) - //将所有设备信息转化缓存为Marker点 - allMarkerOptions.add( - MarkerOptions() - .position(LatLng(latitude, longitude)) - .title(well.wellTypeName) - .snippet(well.wellName) - ) } } } @@ -160,12 +151,12 @@ val cameraPosition = CameraPosition(centerLatLng, 16f, 0f, 0f) val cameraUpdate = CameraUpdateFactory.newCameraPosition(cameraPosition) aMap.animateCamera(cameraUpdate, 1500, null) + + //显示点数据 + displayWellOnMap() } } - //地图初始化 - initMap(savedInstanceState) - //获取窨井监控数据 wellViewModel.countResultModel.observe(this) { binding.deployedWellView.text = it["bfWell"] @@ -220,17 +211,10 @@ uiSettings.isCompassEnabled = true uiSettings.zoomPosition = AMapOptions.ZOOM_POSITION_RIGHT_CENTER uiSettings.isTiltGesturesEnabled = false//不许地图随手势倾斜角度 + uiSettings.isRotateGesturesEnabled = false//不允许地图随手势改变方位 - // 地图加载成功监听 - aMap.addOnMapLoadedListener(this) // 地图缩放监听 aMap.addOnCameraChangeListener(this) - // marker 点击事件监听 - aMap.addOnMarkerClickListener(this) - // 点击marker弹出自定义popup - aMap.setInfoWindowAdapter(this) - //信息窗点击事件 - aMap.addOnInfoWindowClickListener(this) } override fun initEvent() { @@ -259,9 +243,111 @@ } - override fun onMapLoaded() { - //地图加载成功之后显示聚合点数据 - initClustersMarkers() + private fun displayWellOnMap() { + clusterOverlay?.onDestroy() + val clusterItems = ArrayList() + + wellModels.forEach { + val latitude = it.latGaode.toDouble() + val longitude = it.lngGaode.toDouble() + + val latLng = LatLng(latitude, longitude, false) + val regionItem = RegionItem(latLng, it) + clusterItems.add(regionItem) + } + + clusterOverlay = ClusterOverlay(requireContext(), aMap, clusterItems, regionRadius) + clusterOverlay?.setClusterRender { clusterNum -> + //聚合圆半径 + val radius = 100.dp2px(requireContext()) + if (clusterNum == 0) { + var bitmapDrawable = backDrawables[0] + if (bitmapDrawable == null) { + bitmapDrawable = BitmapDrawable( + null, radius.drawCircle(Color.argb(159, 100, 149, 237)) + ) + backDrawables[0] = bitmapDrawable + } + bitmapDrawable + } + if (clusterNum == 1) { + var bitmapDrawable = backDrawables[1] + if (bitmapDrawable == null) { + bitmapDrawable = R.mipmap.well_location.convertDrawable(requireContext())!! + backDrawables[1] = bitmapDrawable + } + bitmapDrawable + } else if (clusterNum < 5) { + var bitmapDrawable = backDrawables[2] + if (bitmapDrawable == null) { + bitmapDrawable = BitmapDrawable( + null, radius.drawCircle(Color.argb(159, 100, 149, 237)) + ) + backDrawables[2] = bitmapDrawable + } + bitmapDrawable + } else if (clusterNum < 10) { + var bitmapDrawable = backDrawables[3] + if (bitmapDrawable == null) { + bitmapDrawable = BitmapDrawable( + null, radius.drawCircle(Color.argb(199, 30, 144, 255)) + ) + backDrawables[3] = bitmapDrawable + } + bitmapDrawable + } else { + var bitmapDrawable = backDrawables[4] + if (bitmapDrawable == null) { + bitmapDrawable = BitmapDrawable( + null, radius.drawCircle(Color.argb(235, 65, 105, 225)) + ) + backDrawables[4] = bitmapDrawable + } + bitmapDrawable + } + } + + clusterOverlay?.setOnClusterClickListener(object : ClusterOnClickListener { + override fun onMarkerClicked(marker: Marker?, items: List) { + if (items.size > 1) { + "请缩放地图比例在查看数据".show(requireContext()) + return + } + + var item: RegionItem? = null + val builder = LatLngBounds.Builder() + for (clusterItem in items) { + builder.include(clusterItem.position) + item = clusterItem as RegionItem + } + + item?.apply { + showWellPopup(well) + } + } + }) + } + + private fun showWellPopup(well: MapWellListModel.DataModel) { + infoPopup.set(well, object : MapWellPopup.OnPopupWindowClickListener { + override fun onPopupClicked(lat: Double, lng: Double) { + AlertControlDialog.Builder().setContext(requireContext()).setTitle("操作提示") + .setMessage("确定要前往吗").setNegativeButton("取消").setPositiveButton("确定") + .setOnDialogButtonClickListener(object : + AlertControlDialog.OnDialogButtonClickListener { + override fun onConfirmClick() { + RouteOnMap.startNavigation( + requireContext(), "", LatLng(lat, lng) + ) + } + + override fun onCancelClick() { + + } + }).build().show() + } + }) + infoPopup.showAsDropDown(binding.rightOptionView) } override fun onCameraChange(p0: CameraPosition?) { @@ -282,103 +368,10 @@ } } - //获取视野内的marker 根据聚合算法合成自定义的marker 显示视野内的marker override fun onCameraChangeFinish(p0: CameraPosition?) { //地图缩放之后显示聚合点数据 LoadingDialogHub.dismiss() httpCountDownTimer.cancel() - initClustersMarkers() - } - - private fun initClustersMarkers() { - 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 { - v = LayoutInflater.from(requireContext()).inflate(R.layout.popup_map_info, null) - - //显示闸井信息 - marker?.showInfoWindow() - return true - } - - override fun getInfoWindow(marker: Marker?): View { - //反射得到popup里面的控件对象 - val wellNameView = v.findViewById(R.id.wellNameView) - val wellCodeView = v.findViewById(R.id.wellCodeView) - val wellTypeView = v.findViewById(R.id.wellTypeView) - val wellStateView = v.findViewById(R.id.wellStateView) - val deepView = v.findViewById(R.id.deepView) - val locationView = v.findViewById(R.id.locationView) - - //绑定数据 - val clickedLatLng = marker?.position!! - wellModels.forEach { well -> - if (clickedLatLng.latitude == well.latGaode!!.toDouble() - && clickedLatLng.longitude == well.lngGaode!!.toDouble() - ) { - wellNameView.text = String.format("点位名称: ${well.wellName}") - wellCodeView.text = String.format("点位编号: ${well.wellCode}") - wellTypeView.text = String.format("点位类型: ${well.wellType.valueToType()}") - val bfztName = if (well.bfzt == "1") { - "已布防" - } else { - "已撤防" - } - wellStateView.text = String.format("布/撤防状态: $bfztName") - deepView.text = String.format("点位深度: ${well.deep}m") - locationView.text = String.format("详细位置: ${well.position}") - } - } - return v - } - - /** - * 此方法不能修改整个 InfoWindow 的背景和边框,无论自定义的样式是什么样,SDK 都会在最外层添加一个默认的边框 - * */ - override fun getInfoContents(p0: Marker?): View? = null - - override fun onInfoWindowClick(p0: Marker?) { - p0?.apply { - AlertControlDialog.Builder() - .setContext(requireContext()) - .setTitle("操作提示") - .setMessage("确定要前往吗") - .setNegativeButton("取消") - .setPositiveButton("确定") - .setOnDialogButtonClickListener(object : - AlertControlDialog.OnDialogButtonClickListener { - override fun onConfirmClick() { - val lat = position.latitude.toString() - val lng = position.longitude.toString() - if (lat.isBlank() || lng.isBlank()) { - "点位经纬度异常,无法开启导航".show(requireContext()) - return - } - RouteOnMap.startNavigation( - requireContext(), snippet, LatLng(lat.toDouble(), lng.toDouble()) - ) - } - - override fun onCancelClick() { - - } - }).build().show() - } } /***以下是地图生命周期管理************************************************************************/ 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 a54d213..bfa7a57 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 @@ -44,8 +44,8 @@ * 地图点位不带聚合效果 * */ class HomePageNoClusterFragment : KotlinBaseFragment(), - AMap.OnMapLoadedListener, AMap.OnCameraChangeListener, AMap.OnMarkerClickListener, - AMap.InfoWindowAdapter, AMap.OnInfoWindowClickListener { + AMap.OnCameraChangeListener, AMap.OnMarkerClickListener, AMap.InfoWindowAdapter, + AMap.OnInfoWindowClickListener { private val kTag = "NoClusterFragment" private val easyPopupWindow by lazy { EasyPopupWindow(requireContext()) } @@ -109,6 +109,9 @@ wellViewModel = ViewModelProvider(this)[WellViewModel::class.java] orderViewModel = ViewModelProvider(this)[OrderViewModel::class.java] + //地图初始化 + initMap(savedInstanceState) + //获取所有窨井数据 httpCountDownTimer.start() LoadingDialogHub.show(requireActivity(), "数据加载中,请稍后...") @@ -157,12 +160,12 @@ val cameraPosition = CameraPosition(centerLatLng, 16f, 0f, 0f) val cameraUpdate = CameraUpdateFactory.newCameraPosition(cameraPosition) aMap.animateCamera(cameraUpdate, 1500, null) + + //显示点数据 + displayWellOnMap() } } - //地图初始化 - initMap(savedInstanceState) - //获取窨井监控数据 wellViewModel.countResultModel.observe(this) { binding.deployedWellView.text = it["bfWell"] @@ -214,9 +217,8 @@ uiSettings.isCompassEnabled = true uiSettings.zoomPosition = AMapOptions.ZOOM_POSITION_RIGHT_CENTER uiSettings.isTiltGesturesEnabled = false//不许地图随手势倾斜角度 + uiSettings.isRotateGesturesEnabled = false//不允许地图随手势改变方位 - // 地图加载成功监听 - aMap.addOnMapLoadedListener(this) // 地图缩放监听 aMap.addOnCameraChangeListener(this) // marker 点击事件监听 @@ -253,11 +255,6 @@ } - override fun onMapLoaded() { - //地图加载成功之后显示聚合点数据 - initClustersMarkers() - } - override fun onCameraChange(p0: CameraPosition?) { } @@ -281,10 +278,9 @@ //地图缩放之后显示聚合点数据 LoadingDialogHub.dismiss() httpCountDownTimer.cancel() - initClustersMarkers() } - private fun initClustersMarkers() { + private fun displayWellOnMap() { val proj = aMap.projection val dm = resources.displayMetrics var screenLocation: Point diff --git a/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.java b/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.java deleted file mode 100644 index d8b18ef..0000000 --- a/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.java +++ /dev/null @@ -1,50 +0,0 @@ -package com.casic.app.smartwell.model; - -public class ErrorMessageModel { - - private int code; - private String data; - private String exceptionClazz; - private String message; - private boolean success; - - public int getCode() { - return code; - } - - public void setCode(int code) { - this.code = code; - } - - public String getData() { - return data; - } - - public void setData(String data) { - this.data = data; - } - - public String getExceptionClazz() { - return exceptionClazz; - } - - public void setExceptionClazz(String exceptionClazz) { - this.exceptionClazz = exceptionClazz; - } - - public String getMessage() { - return message; - } - - public void setMessage(String message) { - this.message = message; - } - - public boolean isSuccess() { - return success; - } - - public void setSuccess(boolean success) { - this.success = success; - } -} \ No newline at end of file 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 new file mode 100644 index 0000000..215ac0c --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/PipelineModel.java @@ -0,0 +1,328 @@ +package com.casic.app.smartwell.model; + +import java.util.List; + +public class PipelineModel { + + private Integer code; + private DataModel data; + private String message; + private Boolean success; + + public Integer getCode() { + return code; + } + + public void setCode(Integer code) { + this.code = code; + } + + public DataModel getData() { + return data; + } + + public void setData(DataModel data) { + this.data = data; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + public Boolean getSuccess() { + return success; + } + + public void setSuccess(Boolean success) { + this.success = success; + } + + public static class DataModel { + private List rows; + private Integer total; + + public List getRows() { + return rows; + } + + public void setRows(List rows) { + this.rows = rows; + } + + public Integer getTotal() { + return total; + } + + public void setTotal(Integer total) { + this.total = total; + } + + 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 getBuryMode() { + return buryMode; + } + + public void setBuryMode(String buryMode) { + this.buryMode = buryMode; + } + + public String getConstructEra() { + return constructEra; + } + + public void setConstructEra(String constructEra) { + this.constructEra = constructEra; + } + + 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; + } + } + } +} 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 06d3d2b..4f38a2c 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 = 100 //相距多少米才聚合,单位:米 + const val RADIUS_SIZE = 80 //相距多少米才聚合,单位:米 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:11308" + // 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 0d5f3fa..991e1db 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 @@ -312,4 +312,14 @@ @Header("token") token: String, @Field("clientid") deviceCode: String ): String + + /** + * 管线位置数据 + */ + @GET("/pipeline/listPage") + suspend fun getPipeline( + @Header("token") token: String, + @Query("limit") limit: Int, + @Query("offset") offset: Int + ): String } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt index 1a0ce22..4050067 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt @@ -294,4 +294,11 @@ suspend fun registerPush(clientId: String): String { return api.registerPush(AuthenticationHelper.token!!, clientId) } + + /** + * 管线位置数据 + */ + suspend fun getPipeline(): String { + return api.getPipeline(AuthenticationHelper.token!!, 2000, 1) + } } \ No newline at end of file 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 9270fa1..4ca5a5e 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.HomePageNoClusterFragment +import com.casic.app.smartwell.fragment.HomePageHaveClusterFragment 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/vm/AlarmViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/AlarmViewModel.kt index 9cff08c..e7acc17 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/AlarmViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/AlarmViewModel.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.AlarmContentModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager import com.google.gson.Gson @@ -16,7 +16,7 @@ fun getAlarmContentType(alarmType: String) = launch({ val response = RetrofitServiceManager.getAlarmContentType(alarmType) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { listModel.value = gson.fromJson( response, object : TypeToken() {}.type diff --git a/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt index 5e5b163..895dedd 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.PublicKeyModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager import com.google.gson.Gson @@ -18,7 +18,7 @@ fun getPublicKey() = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.authenticate() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { keyModel.value = gson.fromJson( response, object : TypeToken() {}.type diff --git a/app/src/main/java/com/casic/app/smartwell/vm/DeviceViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/DeviceViewModel.kt index db5ccf6..899a962 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/DeviceViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/DeviceViewModel.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.DeviceDetailModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager import com.google.gson.Gson @@ -16,7 +16,7 @@ fun getDeviceDetail(deviceCode: String) = launch({ val response = RetrofitServiceManager.getDeviceDetail(deviceCode) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { detailModel.value = gson.fromJson( response, object : TypeToken() {}.type diff --git a/app/src/main/java/com/casic/app/smartwell/vm/LoginViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/LoginViewModel.kt index cd8b8a9..a417398 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/LoginViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/LoginViewModel.kt @@ -2,7 +2,7 @@ import androidx.lifecycle.MutableLiveData import com.casic.app.smartwell.base.BaseApplication -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.CommonResultModel import com.casic.app.smartwell.model.LoginResultModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -21,7 +21,7 @@ fun enter(account: String, secretKey: String) = launch({ val response = RetrofitServiceManager.login(account, secretKey) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success enterResultModel.value = gson.fromJson( @@ -38,7 +38,7 @@ fun out() = launch({ val response = RetrofitServiceManager.loginOut() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { outResultModel.value = gson.fromJson( response, object : TypeToken() {}.type diff --git a/app/src/main/java/com/casic/app/smartwell/vm/OperationViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/OperationViewModel.kt index 8943ed3..37e115f 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/OperationViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/OperationViewModel.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.vm import com.casic.app.smartwell.base.BaseApplication -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager import com.pengxh.kt.lite.base.BaseViewModel import com.pengxh.kt.lite.extensions.launch @@ -16,7 +16,7 @@ fun acceptWorkOrder(id: String) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.acceptWorkOrder(id) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success "接单成功".show(BaseApplication.get()) @@ -35,7 +35,7 @@ loadState.value = LoadState.Loading val response = RetrofitServiceManager.confirmWorkOrder(id, firstState, firstStatePhotos, needHandle) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success "工单确认成功".show(BaseApplication.get()) @@ -50,7 +50,7 @@ fun transferWorkOrder(id: String, userId: String) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.transferWorkOrder(id, userId) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success "转单成功".show(BaseApplication.get()) @@ -65,7 +65,7 @@ fun completeWorkOrder(id: String, handleMessage: String, handlePhotos: String) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.completeWorkOrder(id, handleMessage, handlePhotos) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success "工单处理成功".show(BaseApplication.get()) diff --git a/app/src/main/java/com/casic/app/smartwell/vm/OrderViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/OrderViewModel.kt index 4cb26b7..d2fad86 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/OrderViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/OrderViewModel.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.OrderDetailModel import com.casic.app.smartwell.model.OrderListModel import com.casic.app.smartwell.model.OrderStatusModel @@ -37,7 +37,7 @@ val response = RetrofitServiceManager.getSearchResult( keywords, alarmContent, alarmLevel, jobStatus, deptId, beginTime, endTime, offset ) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success searchResult.value = gson.fromJson( @@ -53,7 +53,7 @@ fun getWorkOrderListByState(jobStatus: String, page: Int) = launch({ val response = RetrofitServiceManager.getWorkOrderList(jobStatus, page) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { orderList.value = gson.fromJson( response, object : TypeToken() {}.type @@ -65,7 +65,7 @@ fun getNotAcceptOderList(page: Int) = launch({ val response = RetrofitServiceManager.getNotAcceptOderList(page) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { orderList.value = gson.fromJson( response, object : TypeToken() {}.type @@ -77,7 +77,7 @@ fun getNotHandleOderList(page: Int) = launch({ val response = RetrofitServiceManager.getNotHandleOderList(page) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { orderList.value = gson.fromJson( response, object : TypeToken() {}.type @@ -89,7 +89,7 @@ fun countWorkOrderByState() = launch({ val response = RetrofitServiceManager.countWorkOrderByState() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { val map = HashMap(4) @@ -107,7 +107,7 @@ fun getOrderStatus() = launch({ val response = RetrofitServiceManager.getOrderStatus() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { orderStatusModel.value = gson.fromJson( response, object : TypeToken() {}.type @@ -120,7 +120,7 @@ fun getWorkOrderDetail(id: String) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.getWorkOrderDetail(id) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success detailModel.value = gson.fromJson( diff --git a/app/src/main/java/com/casic/app/smartwell/vm/PipelineViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/PipelineViewModel.kt new file mode 100644 index 0000000..60c1e2f --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/vm/PipelineViewModel.kt @@ -0,0 +1,28 @@ +package com.casic.app.smartwell.vm + +import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.extensions.getResponseCode +import com.casic.app.smartwell.model.PipelineModel +import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken +import com.pengxh.kt.lite.base.BaseViewModel +import com.pengxh.kt.lite.extensions.launch + +class PipelineViewModel : BaseViewModel() { + + private val gson by lazy { Gson() } + val lineResult = MutableLiveData() + + fun getPipeline() = launch({ + val response = RetrofitServiceManager.getPipeline() + val responseCode = response.getResponseCode() + if (responseCode == 200) { + lineResult.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } + }, { + it.printStackTrace() + }) +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/PushViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/PushViewModel.kt index 9279815..12fd610 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/PushViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/PushViewModel.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.CommonResultModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager import com.google.gson.Gson @@ -16,7 +16,7 @@ fun registerPush(clientId: String) = launch({ val response = RetrofitServiceManager.registerPush(clientId) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { registerResultModel.value = gson.fromJson( response, object : TypeToken() {}.type diff --git a/app/src/main/java/com/casic/app/smartwell/vm/UploadImageViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/UploadImageViewModel.kt index 8d6744e..9707eeb 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/UploadImageViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/UploadImageViewModel.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.CommonResultModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager import com.google.gson.Gson @@ -19,7 +19,7 @@ fun uploadImage(image: File) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.uploadImage(image) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success resultModel.value = gson.fromJson( diff --git a/app/src/main/java/com/casic/app/smartwell/vm/UserViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/UserViewModel.kt index 31a4d4c..070c35a 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/UserViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/UserViewModel.kt @@ -2,7 +2,7 @@ import androidx.lifecycle.MutableLiveData import com.casic.app.smartwell.base.BaseApplication -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.SubordinateModel import com.casic.app.smartwell.model.UserDetailModel import com.casic.app.smartwell.model.VersionResultModel @@ -25,7 +25,7 @@ fun getUserDetail() = launch({ val response = RetrofitServiceManager.getUserDetail() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { val userDetail = gson.fromJson( response, object : TypeToken() {}.type @@ -48,7 +48,7 @@ * */ fun getSubordinate(hasMine: String?, deptId: String?, roleTips: String?) = launch({ val response = RetrofitServiceManager.getSubordinate(hasMine, deptId, roleTips) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { subordinateModel.value = gson.fromJson( response, object : TypeToken() {}.type @@ -61,7 +61,7 @@ fun changePassword(oldPwd: String, newPwd: String) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.changePassword(oldPwd, newPwd) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success "修改成功,请重新登录".show(BaseApplication.get()) @@ -76,7 +76,7 @@ fun updateVersion() = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.updateVersion() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success versionResultModel.value = gson.fromJson( diff --git a/app/src/main/java/com/casic/app/smartwell/vm/WellViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/WellViewModel.kt index 3d41e9b..9e42e36 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/WellViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/WellViewModel.kt @@ -2,8 +2,7 @@ import androidx.lifecycle.MutableLiveData import com.casic.app.smartwell.base.BaseApplication -import com.casic.app.smartwell.extensions.separateResponseCode -import com.casic.app.smartwell.extensions.toErrorMessage +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.AuthorDeptModel import com.casic.app.smartwell.model.CommonResultModel import com.casic.app.smartwell.model.MapWellListModel @@ -32,7 +31,7 @@ fun countWellByState() = launch({ val response = RetrofitServiceManager.countWellByState() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { val map = HashMap(3) @@ -57,7 +56,7 @@ fun getWellType() = launch({ val response = RetrofitServiceManager.getWellType() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { wellTypeModel.value = gson.fromJson( response, object : TypeToken() {}.type @@ -70,7 +69,7 @@ fun getWellDetail(id: String) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.getWellDetail(id) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success wellDetailModel.value = gson.fromJson( @@ -87,7 +86,7 @@ fun getOperationResult(id: String, state: String) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.getOperationResult(id, state) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success "操作成功".show(BaseApplication.get()) @@ -105,7 +104,7 @@ fun getMonitorResult(id: String) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.getMonitorResult(id) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success monitorModel.value = gson.fromJson( @@ -125,7 +124,7 @@ val response = RetrofitServiceManager.getWellListByPage( keywords, wellType, deptid, bfzt, page ) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { listModel.value = gson.fromJson( response, object : TypeToken() {}.type @@ -137,13 +136,11 @@ fun getWellList() = launch({ val response = RetrofitServiceManager.getWellList() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { totalWellModel.value = gson.fromJson( response, object : TypeToken() {}.type ) - } else { - response.toErrorMessage().show(BaseApplication.get()) } }, { it.printStackTrace() diff --git a/app/src/main/java/com/casic/app/smartwell/widgets/GaoDeClusterMarkerView.kt b/app/src/main/java/com/casic/app/smartwell/widgets/GaoDeClusterMarkerView.kt deleted file mode 100644 index 1f375df..0000000 --- a/app/src/main/java/com/casic/app/smartwell/widgets/GaoDeClusterMarkerView.kt +++ /dev/null @@ -1,100 +0,0 @@ -package com.casic.app.smartwell.widgets - -import android.content.Context -import android.graphics.Bitmap -import android.graphics.Point -import android.view.Gravity -import android.view.LayoutInflater -import android.view.View -import android.widget.TextView -import com.amap.api.maps.Projection -import com.amap.api.maps.model.BitmapDescriptorFactory -import com.amap.api.maps.model.LatLng -import com.amap.api.maps.model.LatLngBounds -import com.amap.api.maps.model.MarkerOptions -import com.casic.app.smartwell.R -import com.pengxh.kt.lite.extensions.toBitmap -import java.util.* - -class GaoDeClusterMarkerView( - private val context: Context, firstMarkers: MarkerOptions, projection: Projection, gridSize: Int -) { - //当前可观区域里的 聚合过之后的集合 - private val includeMarkers: ArrayList - - // 创建区域 - val bounds: LatLngBounds - var options: MarkerOptions = MarkerOptions() - - init { - val screenLocation = projection.toScreenLocation(firstMarkers.position) - //范围类 - val southwestPoint = Point(screenLocation.x - gridSize, screenLocation.y + gridSize) - //范围类 - val northeastPoint = Point(screenLocation.x + gridSize, screenLocation.y - gridSize) - bounds = LatLngBounds( - projection.fromScreenLocation(southwestPoint), - projection.fromScreenLocation(northeastPoint) - ) - //设置初始化marker属性 - options.anchor(0.5f, 1.3f) - .title(firstMarkers.title) - .position(firstMarkers.position) - .icon(firstMarkers.icon) - .snippet(firstMarkers.snippet) - .draggable(false) - includeMarkers = ArrayList() - includeMarkers.add(firstMarkers) - } - - /** - * 添加marker - */ - fun addMarker(markerOptions: MarkerOptions) { - includeMarkers.add(markerOptions) // 添加到列表中 - } - - /** - * 设置聚合点的中心位置以及图标 - */ - fun setPositionAndIcon() { - val size = includeMarkers.size - var lat = 0.0 - var lng = 0.0 - // 一个的时候 - if (size == 1) { //设置marker单个属性 - // 设置marker位置 - options.position( - LatLng( - includeMarkers[0].position.latitude, includeMarkers[0].position.longitude - ) - ) - } else { // 聚合的时候 - //设置marker聚合属性 - for (op in includeMarkers) { - lat += op.position.latitude - lng += op.position.longitude - } - // 设置marker的位置为中心位置为聚集点的平均位置 - options.position(LatLng(lat / size, lng / size)) - } - options.icon(BitmapDescriptorFactory.fromBitmap(getBitmap(size))) - } - - /** - * marker视图 - */ - private fun getBitmap(num: Int): Bitmap? { - val view = LayoutInflater.from(context).inflate(R.layout.marker_gaode, null) - val wellCountView = view.findViewById(R.id.wellCountView) - return if (num > 1) { - wellCountView.visibility = View.VISIBLE - wellCountView.text = String.format("${num}个") - wellCountView.gravity = Gravity.CENTER - view.toBitmap() - } else { - wellCountView.visibility = View.GONE - BitmapDescriptorFactory.fromResource(R.mipmap.well_location).bitmap - } - } -} \ No newline at end of file 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 new file mode 100644 index 0000000..ec455dd --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/widgets/MapWellPopup.kt @@ -0,0 +1,58 @@ +package com.casic.app.smartwell.widgets + +import android.content.Context +import android.view.LayoutInflater +import android.view.ViewGroup +import android.widget.LinearLayout +import android.widget.PopupWindow +import android.widget.TextView +import com.casic.app.smartwell.R +import com.casic.app.smartwell.extensions.valueToType +import com.casic.app.smartwell.model.MapWellListModel + +class MapWellPopup constructor(context: Context) : PopupWindow() { + + init { + width = ViewGroup.LayoutParams.MATCH_PARENT + height = ViewGroup.LayoutParams.WRAP_CONTENT + isOutsideTouchable = true + isFocusable = true + animationStyle = R.style.MapPopupAnimation + setBackgroundDrawable(null) + contentView = LayoutInflater.from(context).inflate( + R.layout.popup_map_info, null, false + ) + } + + fun set(well: MapWellListModel.DataModel, windowClickListener: OnPopupWindowClickListener) { + //反射得到popup里面的控件对象 + val rootView = contentView.findViewById(R.id.rootView) + val wellNameView = contentView.findViewById(R.id.wellNameView) + val wellCodeView = contentView.findViewById(R.id.wellCodeView) + val wellTypeView = contentView.findViewById(R.id.wellTypeView) + val wellStateView = contentView.findViewById(R.id.wellStateView) + val deepView = contentView.findViewById(R.id.deepView) + val locationView = contentView.findViewById(R.id.locationView) + + //绑定数据 + wellNameView.text = String.format("点位名称: ${well.wellName}") + wellCodeView.text = String.format("点位编号: ${well.wellCode}") + wellTypeView.text = String.format("点位类型: ${well.wellType.valueToType()}") + val bfztName = if (well.bfzt == "1") { + "已布防" + } else { + "已撤防" + } + wellStateView.text = String.format("布/撤防状态: $bfztName") + deepView.text = String.format("点位深度: ${well.deep}m") + locationView.text = String.format("详细位置: ${well.position}") + + rootView.setOnClickListener { + windowClickListener.onPopupClicked(well.latGaode.toDouble(), well.lngGaode.toDouble()) + } + } + + interface OnPopupWindowClickListener { + fun onPopupClicked(lat: Double, lng: Double) + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/widgets/cluster/Cluster.java b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/Cluster.java new file mode 100644 index 0000000..9455ccd --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/Cluster.java @@ -0,0 +1,43 @@ +package com.casic.app.smartwell.widgets.cluster; + +import com.amap.api.maps.model.LatLng; +import com.amap.api.maps.model.Marker; + +import java.util.ArrayList; +import java.util.List; + +public class Cluster { + private final LatLng latLng; + private final List clusterItems; + private Marker marker; + + + public Cluster(LatLng latLng) { + this.latLng = latLng; + clusterItems = new ArrayList<>(); + } + + public void addClusterItem(ClusterItem clusterItem) { + clusterItems.add(clusterItem); + } + + public int getClusterCount() { + return clusterItems.size(); + } + + public LatLng getCenterLatLng() { + return latLng; + } + + public void setMarker(Marker marker) { + this.marker = marker; + } + + public Marker getMarker() { + return marker; + } + + public List getClusterItems() { + return clusterItems; + } +} diff --git a/app/src/main/java/com/casic/app/smartwell/extensions/Int.kt b/app/src/main/java/com/casic/app/smartwell/extensions/Int.kt index de0617b..a0a5e33 100644 --- a/app/src/main/java/com/casic/app/smartwell/extensions/Int.kt +++ b/app/src/main/java/com/casic/app/smartwell/extensions/Int.kt @@ -1,9 +1,24 @@ package com.casic.app.smartwell.extensions +import android.graphics.Bitmap +import android.graphics.Canvas +import android.graphics.Paint +import android.graphics.RectF + fun Int.toLevel(): String { return if (this == 0) { "" } else { this.toString() } +} + +fun Int.drawCircle(color: Int): Bitmap? { + val bitmap = Bitmap.createBitmap(this * 2, this * 2, Bitmap.Config.ARGB_8888) + val canvas = Canvas(bitmap) + val paint = Paint() + val rectF = RectF(0f, 0f, (this * 2).toFloat(), (this * 2).toFloat()) + paint.color = color + canvas.drawArc(rectF, 0f, 360f, true, paint) + return bitmap } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt index 6b6ca3e..5e45534 100644 --- a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt +++ b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt @@ -2,17 +2,13 @@ import android.content.Context import com.casic.app.smartwell.callback.OnImageCompressListener -import com.casic.app.smartwell.model.ErrorMessageModel import com.casic.app.smartwell.utils.LocaleConstant -import com.google.gson.Gson -import com.google.gson.reflect.TypeToken +import com.google.gson.JsonParser import com.pengxh.kt.lite.extensions.createCompressImageDir import com.pengxh.kt.lite.utils.SaveKeyValues -import org.json.JSONObject import top.zibin.luban.Luban import top.zibin.luban.OnCompressListener import java.io.File -import java.util.Locale /** * String扩展方法 @@ -74,18 +70,22 @@ } } -fun String.separateResponseCode(): Int { +fun String.getResponseCode(): Int { if (this.isBlank()) { return 404 } - return JSONObject(this).getInt("code") + val element = JsonParser.parseString(this) + val jsonObject = element.asJsonObject + return jsonObject.get("code").asInt } -fun String.toErrorMessage(): String { - val errorModel = Gson().fromJson( - this, object : TypeToken() {}.type - ) - return errorModel.message.toString() +fun String.getResponseMessage(): String { + if (this.isBlank()) { + return "" + } + val element = JsonParser.parseString(this) + val jsonObject = element.asJsonObject + return jsonObject.get("message").asString } fun String.compressImage(context: Context, listener: OnImageCompressListener) { @@ -93,9 +93,6 @@ .load(this) .ignoreBy(100) .setTargetDir(context.createCompressImageDir().toString()) - .filter { - !(it.isBlank() || it.lowercase(Locale.getDefault()).endsWith(".gif")) - } .setCompressListener(object : OnCompressListener { override fun onStart() { 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 96df110..cd25fca 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 @@ -1,26 +1,25 @@ package com.casic.app.smartwell.fragment -import android.graphics.Point +import android.graphics.Color +import android.graphics.drawable.BitmapDrawable +import android.graphics.drawable.Drawable 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 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.LatLngBounds import com.amap.api.maps.model.Marker -import com.amap.api.maps.model.MarkerOptions import com.casic.app.smartwell.R import com.casic.app.smartwell.databinding.FragmentHomeBinding +import com.casic.app.smartwell.extensions.drawCircle import com.casic.app.smartwell.extensions.initImmersionBar -import com.casic.app.smartwell.extensions.valueToType import com.casic.app.smartwell.model.MapWellListModel import com.casic.app.smartwell.utils.LocaleConstant import com.casic.app.smartwell.utils.RouteOnMap @@ -31,9 +30,16 @@ import com.casic.app.smartwell.view.WellOperationActivity import com.casic.app.smartwell.vm.OrderViewModel import com.casic.app.smartwell.vm.WellViewModel +import com.casic.app.smartwell.widgets.MapWellPopup +import com.casic.app.smartwell.widgets.cluster.ClusterItem +import com.casic.app.smartwell.widgets.cluster.ClusterOnClickListener +import com.casic.app.smartwell.widgets.cluster.ClusterOverlay +import com.casic.app.smartwell.widgets.cluster.RegionItem 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.convertDrawable +import com.pengxh.kt.lite.extensions.dp2px import com.pengxh.kt.lite.extensions.navigatePageTo import com.pengxh.kt.lite.extensions.show import com.pengxh.kt.lite.utils.LoadingDialogHub @@ -43,35 +49,23 @@ /** * 地图点位带聚合效果 * */ -class HomePageHaveClusterFragment : KotlinBaseFragment(), AMap.OnMapLoadedListener, - AMap.OnCameraChangeListener, AMap.OnMarkerClickListener, AMap.InfoWindowAdapter, - AMap.OnInfoWindowClickListener { +class HomePageHaveClusterFragment : KotlinBaseFragment(), + AMap.OnCameraChangeListener { private val kTag = "HaveClusterFragment" private val easyPopupWindow by lazy { EasyPopupWindow(requireContext()) } - private lateinit var wellViewModel: WellViewModel - private lateinit var orderViewModel: OrderViewModel - private lateinit var aMap: AMap - - /** - * 所有的marker - */ - private var allMarkerOptions: MutableList = ArrayList() - - /** - * 视野内的marker - */ - private var markerOptionsInView: MutableList = ArrayList() - - /** - * 自定义Marker弹出框 - * */ - private lateinit var v: View + private val regionRadius by lazy { LocaleConstant.RADIUS_SIZE.dp2px(requireContext()) } + private val infoPopup by lazy { MapWellPopup(requireContext()) } /** * 所有窨井列表信息集合 * */ - private var wellModels: MutableList = ArrayList() + private val wellModels = ArrayList() + private val backDrawables = HashMap() + private lateinit var wellViewModel: WellViewModel + private lateinit var orderViewModel: OrderViewModel + private lateinit var aMap: AMap + private var clusterOverlay: ClusterOverlay? = null override fun initViewBinding( inflater: LayoutInflater, @@ -106,6 +100,9 @@ } }) + //地图初始化 + initMap(savedInstanceState) + //初始化vm wellViewModel = ViewModelProvider(this)[WellViewModel::class.java] orderViewModel = ViewModelProvider(this)[OrderViewModel::class.java] @@ -120,25 +117,19 @@ val latitudeList: MutableList = ArrayList() val longitudeList: MutableList = ArrayList() it.data?.forEach { well -> - val lat = well.latGaode.toString() - val lng = well.lngGaode.toString() + val lat = well.latGaode + val lng = well.lngGaode if (lat.isNotBlank() && lng.isNotBlank()) { //返回true代表当前位置在大陆、港澳地区,反之不在 val latitude = lat.toDouble() val longitude = lng.toDouble() if (CoordinateConverter.isAMapDataAvailable(latitude, longitude)) { - //缓存所有设备详情,点击Marker时候需要 + //缓存所有井 wellModels.add(well) + //分别缓存经、纬度 latitudeList.add(latitude) longitudeList.add(longitude) - //将所有设备信息转化缓存为Marker点 - allMarkerOptions.add( - MarkerOptions() - .position(LatLng(latitude, longitude)) - .title(well.wellTypeName) - .snippet(well.wellName) - ) } } } @@ -160,12 +151,12 @@ val cameraPosition = CameraPosition(centerLatLng, 16f, 0f, 0f) val cameraUpdate = CameraUpdateFactory.newCameraPosition(cameraPosition) aMap.animateCamera(cameraUpdate, 1500, null) + + //显示点数据 + displayWellOnMap() } } - //地图初始化 - initMap(savedInstanceState) - //获取窨井监控数据 wellViewModel.countResultModel.observe(this) { binding.deployedWellView.text = it["bfWell"] @@ -220,17 +211,10 @@ uiSettings.isCompassEnabled = true uiSettings.zoomPosition = AMapOptions.ZOOM_POSITION_RIGHT_CENTER uiSettings.isTiltGesturesEnabled = false//不许地图随手势倾斜角度 + uiSettings.isRotateGesturesEnabled = false//不允许地图随手势改变方位 - // 地图加载成功监听 - aMap.addOnMapLoadedListener(this) // 地图缩放监听 aMap.addOnCameraChangeListener(this) - // marker 点击事件监听 - aMap.addOnMarkerClickListener(this) - // 点击marker弹出自定义popup - aMap.setInfoWindowAdapter(this) - //信息窗点击事件 - aMap.addOnInfoWindowClickListener(this) } override fun initEvent() { @@ -259,9 +243,111 @@ } - override fun onMapLoaded() { - //地图加载成功之后显示聚合点数据 - initClustersMarkers() + private fun displayWellOnMap() { + clusterOverlay?.onDestroy() + val clusterItems = ArrayList() + + wellModels.forEach { + val latitude = it.latGaode.toDouble() + val longitude = it.lngGaode.toDouble() + + val latLng = LatLng(latitude, longitude, false) + val regionItem = RegionItem(latLng, it) + clusterItems.add(regionItem) + } + + clusterOverlay = ClusterOverlay(requireContext(), aMap, clusterItems, regionRadius) + clusterOverlay?.setClusterRender { clusterNum -> + //聚合圆半径 + val radius = 100.dp2px(requireContext()) + if (clusterNum == 0) { + var bitmapDrawable = backDrawables[0] + if (bitmapDrawable == null) { + bitmapDrawable = BitmapDrawable( + null, radius.drawCircle(Color.argb(159, 100, 149, 237)) + ) + backDrawables[0] = bitmapDrawable + } + bitmapDrawable + } + if (clusterNum == 1) { + var bitmapDrawable = backDrawables[1] + if (bitmapDrawable == null) { + bitmapDrawable = R.mipmap.well_location.convertDrawable(requireContext())!! + backDrawables[1] = bitmapDrawable + } + bitmapDrawable + } else if (clusterNum < 5) { + var bitmapDrawable = backDrawables[2] + if (bitmapDrawable == null) { + bitmapDrawable = BitmapDrawable( + null, radius.drawCircle(Color.argb(159, 100, 149, 237)) + ) + backDrawables[2] = bitmapDrawable + } + bitmapDrawable + } else if (clusterNum < 10) { + var bitmapDrawable = backDrawables[3] + if (bitmapDrawable == null) { + bitmapDrawable = BitmapDrawable( + null, radius.drawCircle(Color.argb(199, 30, 144, 255)) + ) + backDrawables[3] = bitmapDrawable + } + bitmapDrawable + } else { + var bitmapDrawable = backDrawables[4] + if (bitmapDrawable == null) { + bitmapDrawable = BitmapDrawable( + null, radius.drawCircle(Color.argb(235, 65, 105, 225)) + ) + backDrawables[4] = bitmapDrawable + } + bitmapDrawable + } + } + + clusterOverlay?.setOnClusterClickListener(object : ClusterOnClickListener { + override fun onMarkerClicked(marker: Marker?, items: List) { + if (items.size > 1) { + "请缩放地图比例在查看数据".show(requireContext()) + return + } + + var item: RegionItem? = null + val builder = LatLngBounds.Builder() + for (clusterItem in items) { + builder.include(clusterItem.position) + item = clusterItem as RegionItem + } + + item?.apply { + showWellPopup(well) + } + } + }) + } + + private fun showWellPopup(well: MapWellListModel.DataModel) { + infoPopup.set(well, object : MapWellPopup.OnPopupWindowClickListener { + override fun onPopupClicked(lat: Double, lng: Double) { + AlertControlDialog.Builder().setContext(requireContext()).setTitle("操作提示") + .setMessage("确定要前往吗").setNegativeButton("取消").setPositiveButton("确定") + .setOnDialogButtonClickListener(object : + AlertControlDialog.OnDialogButtonClickListener { + override fun onConfirmClick() { + RouteOnMap.startNavigation( + requireContext(), "", LatLng(lat, lng) + ) + } + + override fun onCancelClick() { + + } + }).build().show() + } + }) + infoPopup.showAsDropDown(binding.rightOptionView) } override fun onCameraChange(p0: CameraPosition?) { @@ -282,103 +368,10 @@ } } - //获取视野内的marker 根据聚合算法合成自定义的marker 显示视野内的marker override fun onCameraChangeFinish(p0: CameraPosition?) { //地图缩放之后显示聚合点数据 LoadingDialogHub.dismiss() httpCountDownTimer.cancel() - initClustersMarkers() - } - - private fun initClustersMarkers() { - 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 { - v = LayoutInflater.from(requireContext()).inflate(R.layout.popup_map_info, null) - - //显示闸井信息 - marker?.showInfoWindow() - return true - } - - override fun getInfoWindow(marker: Marker?): View { - //反射得到popup里面的控件对象 - val wellNameView = v.findViewById(R.id.wellNameView) - val wellCodeView = v.findViewById(R.id.wellCodeView) - val wellTypeView = v.findViewById(R.id.wellTypeView) - val wellStateView = v.findViewById(R.id.wellStateView) - val deepView = v.findViewById(R.id.deepView) - val locationView = v.findViewById(R.id.locationView) - - //绑定数据 - val clickedLatLng = marker?.position!! - wellModels.forEach { well -> - if (clickedLatLng.latitude == well.latGaode!!.toDouble() - && clickedLatLng.longitude == well.lngGaode!!.toDouble() - ) { - wellNameView.text = String.format("点位名称: ${well.wellName}") - wellCodeView.text = String.format("点位编号: ${well.wellCode}") - wellTypeView.text = String.format("点位类型: ${well.wellType.valueToType()}") - val bfztName = if (well.bfzt == "1") { - "已布防" - } else { - "已撤防" - } - wellStateView.text = String.format("布/撤防状态: $bfztName") - deepView.text = String.format("点位深度: ${well.deep}m") - locationView.text = String.format("详细位置: ${well.position}") - } - } - return v - } - - /** - * 此方法不能修改整个 InfoWindow 的背景和边框,无论自定义的样式是什么样,SDK 都会在最外层添加一个默认的边框 - * */ - override fun getInfoContents(p0: Marker?): View? = null - - override fun onInfoWindowClick(p0: Marker?) { - p0?.apply { - AlertControlDialog.Builder() - .setContext(requireContext()) - .setTitle("操作提示") - .setMessage("确定要前往吗") - .setNegativeButton("取消") - .setPositiveButton("确定") - .setOnDialogButtonClickListener(object : - AlertControlDialog.OnDialogButtonClickListener { - override fun onConfirmClick() { - val lat = position.latitude.toString() - val lng = position.longitude.toString() - if (lat.isBlank() || lng.isBlank()) { - "点位经纬度异常,无法开启导航".show(requireContext()) - return - } - RouteOnMap.startNavigation( - requireContext(), snippet, LatLng(lat.toDouble(), lng.toDouble()) - ) - } - - override fun onCancelClick() { - - } - }).build().show() - } } /***以下是地图生命周期管理************************************************************************/ 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 a54d213..bfa7a57 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 @@ -44,8 +44,8 @@ * 地图点位不带聚合效果 * */ class HomePageNoClusterFragment : KotlinBaseFragment(), - AMap.OnMapLoadedListener, AMap.OnCameraChangeListener, AMap.OnMarkerClickListener, - AMap.InfoWindowAdapter, AMap.OnInfoWindowClickListener { + AMap.OnCameraChangeListener, AMap.OnMarkerClickListener, AMap.InfoWindowAdapter, + AMap.OnInfoWindowClickListener { private val kTag = "NoClusterFragment" private val easyPopupWindow by lazy { EasyPopupWindow(requireContext()) } @@ -109,6 +109,9 @@ wellViewModel = ViewModelProvider(this)[WellViewModel::class.java] orderViewModel = ViewModelProvider(this)[OrderViewModel::class.java] + //地图初始化 + initMap(savedInstanceState) + //获取所有窨井数据 httpCountDownTimer.start() LoadingDialogHub.show(requireActivity(), "数据加载中,请稍后...") @@ -157,12 +160,12 @@ val cameraPosition = CameraPosition(centerLatLng, 16f, 0f, 0f) val cameraUpdate = CameraUpdateFactory.newCameraPosition(cameraPosition) aMap.animateCamera(cameraUpdate, 1500, null) + + //显示点数据 + displayWellOnMap() } } - //地图初始化 - initMap(savedInstanceState) - //获取窨井监控数据 wellViewModel.countResultModel.observe(this) { binding.deployedWellView.text = it["bfWell"] @@ -214,9 +217,8 @@ uiSettings.isCompassEnabled = true uiSettings.zoomPosition = AMapOptions.ZOOM_POSITION_RIGHT_CENTER uiSettings.isTiltGesturesEnabled = false//不许地图随手势倾斜角度 + uiSettings.isRotateGesturesEnabled = false//不允许地图随手势改变方位 - // 地图加载成功监听 - aMap.addOnMapLoadedListener(this) // 地图缩放监听 aMap.addOnCameraChangeListener(this) // marker 点击事件监听 @@ -253,11 +255,6 @@ } - override fun onMapLoaded() { - //地图加载成功之后显示聚合点数据 - initClustersMarkers() - } - override fun onCameraChange(p0: CameraPosition?) { } @@ -281,10 +278,9 @@ //地图缩放之后显示聚合点数据 LoadingDialogHub.dismiss() httpCountDownTimer.cancel() - initClustersMarkers() } - private fun initClustersMarkers() { + private fun displayWellOnMap() { val proj = aMap.projection val dm = resources.displayMetrics var screenLocation: Point diff --git a/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.java b/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.java deleted file mode 100644 index d8b18ef..0000000 --- a/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.java +++ /dev/null @@ -1,50 +0,0 @@ -package com.casic.app.smartwell.model; - -public class ErrorMessageModel { - - private int code; - private String data; - private String exceptionClazz; - private String message; - private boolean success; - - public int getCode() { - return code; - } - - public void setCode(int code) { - this.code = code; - } - - public String getData() { - return data; - } - - public void setData(String data) { - this.data = data; - } - - public String getExceptionClazz() { - return exceptionClazz; - } - - public void setExceptionClazz(String exceptionClazz) { - this.exceptionClazz = exceptionClazz; - } - - public String getMessage() { - return message; - } - - public void setMessage(String message) { - this.message = message; - } - - public boolean isSuccess() { - return success; - } - - public void setSuccess(boolean success) { - this.success = success; - } -} \ No newline at end of file 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 new file mode 100644 index 0000000..215ac0c --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/PipelineModel.java @@ -0,0 +1,328 @@ +package com.casic.app.smartwell.model; + +import java.util.List; + +public class PipelineModel { + + private Integer code; + private DataModel data; + private String message; + private Boolean success; + + public Integer getCode() { + return code; + } + + public void setCode(Integer code) { + this.code = code; + } + + public DataModel getData() { + return data; + } + + public void setData(DataModel data) { + this.data = data; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + public Boolean getSuccess() { + return success; + } + + public void setSuccess(Boolean success) { + this.success = success; + } + + public static class DataModel { + private List rows; + private Integer total; + + public List getRows() { + return rows; + } + + public void setRows(List rows) { + this.rows = rows; + } + + public Integer getTotal() { + return total; + } + + public void setTotal(Integer total) { + this.total = total; + } + + 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 getBuryMode() { + return buryMode; + } + + public void setBuryMode(String buryMode) { + this.buryMode = buryMode; + } + + public String getConstructEra() { + return constructEra; + } + + public void setConstructEra(String constructEra) { + this.constructEra = constructEra; + } + + 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; + } + } + } +} 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 06d3d2b..4f38a2c 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 = 100 //相距多少米才聚合,单位:米 + const val RADIUS_SIZE = 80 //相距多少米才聚合,单位:米 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:11308" + // 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 0d5f3fa..991e1db 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 @@ -312,4 +312,14 @@ @Header("token") token: String, @Field("clientid") deviceCode: String ): String + + /** + * 管线位置数据 + */ + @GET("/pipeline/listPage") + suspend fun getPipeline( + @Header("token") token: String, + @Query("limit") limit: Int, + @Query("offset") offset: Int + ): String } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt index 1a0ce22..4050067 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt @@ -294,4 +294,11 @@ suspend fun registerPush(clientId: String): String { return api.registerPush(AuthenticationHelper.token!!, clientId) } + + /** + * 管线位置数据 + */ + suspend fun getPipeline(): String { + return api.getPipeline(AuthenticationHelper.token!!, 2000, 1) + } } \ No newline at end of file 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 9270fa1..4ca5a5e 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.HomePageNoClusterFragment +import com.casic.app.smartwell.fragment.HomePageHaveClusterFragment 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/vm/AlarmViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/AlarmViewModel.kt index 9cff08c..e7acc17 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/AlarmViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/AlarmViewModel.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.AlarmContentModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager import com.google.gson.Gson @@ -16,7 +16,7 @@ fun getAlarmContentType(alarmType: String) = launch({ val response = RetrofitServiceManager.getAlarmContentType(alarmType) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { listModel.value = gson.fromJson( response, object : TypeToken() {}.type diff --git a/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt index 5e5b163..895dedd 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.PublicKeyModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager import com.google.gson.Gson @@ -18,7 +18,7 @@ fun getPublicKey() = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.authenticate() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { keyModel.value = gson.fromJson( response, object : TypeToken() {}.type diff --git a/app/src/main/java/com/casic/app/smartwell/vm/DeviceViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/DeviceViewModel.kt index db5ccf6..899a962 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/DeviceViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/DeviceViewModel.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.DeviceDetailModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager import com.google.gson.Gson @@ -16,7 +16,7 @@ fun getDeviceDetail(deviceCode: String) = launch({ val response = RetrofitServiceManager.getDeviceDetail(deviceCode) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { detailModel.value = gson.fromJson( response, object : TypeToken() {}.type diff --git a/app/src/main/java/com/casic/app/smartwell/vm/LoginViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/LoginViewModel.kt index cd8b8a9..a417398 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/LoginViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/LoginViewModel.kt @@ -2,7 +2,7 @@ import androidx.lifecycle.MutableLiveData import com.casic.app.smartwell.base.BaseApplication -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.CommonResultModel import com.casic.app.smartwell.model.LoginResultModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -21,7 +21,7 @@ fun enter(account: String, secretKey: String) = launch({ val response = RetrofitServiceManager.login(account, secretKey) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success enterResultModel.value = gson.fromJson( @@ -38,7 +38,7 @@ fun out() = launch({ val response = RetrofitServiceManager.loginOut() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { outResultModel.value = gson.fromJson( response, object : TypeToken() {}.type diff --git a/app/src/main/java/com/casic/app/smartwell/vm/OperationViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/OperationViewModel.kt index 8943ed3..37e115f 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/OperationViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/OperationViewModel.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.vm import com.casic.app.smartwell.base.BaseApplication -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager import com.pengxh.kt.lite.base.BaseViewModel import com.pengxh.kt.lite.extensions.launch @@ -16,7 +16,7 @@ fun acceptWorkOrder(id: String) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.acceptWorkOrder(id) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success "接单成功".show(BaseApplication.get()) @@ -35,7 +35,7 @@ loadState.value = LoadState.Loading val response = RetrofitServiceManager.confirmWorkOrder(id, firstState, firstStatePhotos, needHandle) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success "工单确认成功".show(BaseApplication.get()) @@ -50,7 +50,7 @@ fun transferWorkOrder(id: String, userId: String) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.transferWorkOrder(id, userId) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success "转单成功".show(BaseApplication.get()) @@ -65,7 +65,7 @@ fun completeWorkOrder(id: String, handleMessage: String, handlePhotos: String) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.completeWorkOrder(id, handleMessage, handlePhotos) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success "工单处理成功".show(BaseApplication.get()) diff --git a/app/src/main/java/com/casic/app/smartwell/vm/OrderViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/OrderViewModel.kt index 4cb26b7..d2fad86 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/OrderViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/OrderViewModel.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.OrderDetailModel import com.casic.app.smartwell.model.OrderListModel import com.casic.app.smartwell.model.OrderStatusModel @@ -37,7 +37,7 @@ val response = RetrofitServiceManager.getSearchResult( keywords, alarmContent, alarmLevel, jobStatus, deptId, beginTime, endTime, offset ) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success searchResult.value = gson.fromJson( @@ -53,7 +53,7 @@ fun getWorkOrderListByState(jobStatus: String, page: Int) = launch({ val response = RetrofitServiceManager.getWorkOrderList(jobStatus, page) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { orderList.value = gson.fromJson( response, object : TypeToken() {}.type @@ -65,7 +65,7 @@ fun getNotAcceptOderList(page: Int) = launch({ val response = RetrofitServiceManager.getNotAcceptOderList(page) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { orderList.value = gson.fromJson( response, object : TypeToken() {}.type @@ -77,7 +77,7 @@ fun getNotHandleOderList(page: Int) = launch({ val response = RetrofitServiceManager.getNotHandleOderList(page) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { orderList.value = gson.fromJson( response, object : TypeToken() {}.type @@ -89,7 +89,7 @@ fun countWorkOrderByState() = launch({ val response = RetrofitServiceManager.countWorkOrderByState() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { val map = HashMap(4) @@ -107,7 +107,7 @@ fun getOrderStatus() = launch({ val response = RetrofitServiceManager.getOrderStatus() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { orderStatusModel.value = gson.fromJson( response, object : TypeToken() {}.type @@ -120,7 +120,7 @@ fun getWorkOrderDetail(id: String) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.getWorkOrderDetail(id) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success detailModel.value = gson.fromJson( diff --git a/app/src/main/java/com/casic/app/smartwell/vm/PipelineViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/PipelineViewModel.kt new file mode 100644 index 0000000..60c1e2f --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/vm/PipelineViewModel.kt @@ -0,0 +1,28 @@ +package com.casic.app.smartwell.vm + +import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.extensions.getResponseCode +import com.casic.app.smartwell.model.PipelineModel +import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken +import com.pengxh.kt.lite.base.BaseViewModel +import com.pengxh.kt.lite.extensions.launch + +class PipelineViewModel : BaseViewModel() { + + private val gson by lazy { Gson() } + val lineResult = MutableLiveData() + + fun getPipeline() = launch({ + val response = RetrofitServiceManager.getPipeline() + val responseCode = response.getResponseCode() + if (responseCode == 200) { + lineResult.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } + }, { + it.printStackTrace() + }) +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/PushViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/PushViewModel.kt index 9279815..12fd610 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/PushViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/PushViewModel.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.CommonResultModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager import com.google.gson.Gson @@ -16,7 +16,7 @@ fun registerPush(clientId: String) = launch({ val response = RetrofitServiceManager.registerPush(clientId) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { registerResultModel.value = gson.fromJson( response, object : TypeToken() {}.type diff --git a/app/src/main/java/com/casic/app/smartwell/vm/UploadImageViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/UploadImageViewModel.kt index 8d6744e..9707eeb 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/UploadImageViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/UploadImageViewModel.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.CommonResultModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager import com.google.gson.Gson @@ -19,7 +19,7 @@ fun uploadImage(image: File) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.uploadImage(image) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success resultModel.value = gson.fromJson( diff --git a/app/src/main/java/com/casic/app/smartwell/vm/UserViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/UserViewModel.kt index 31a4d4c..070c35a 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/UserViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/UserViewModel.kt @@ -2,7 +2,7 @@ import androidx.lifecycle.MutableLiveData import com.casic.app.smartwell.base.BaseApplication -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.SubordinateModel import com.casic.app.smartwell.model.UserDetailModel import com.casic.app.smartwell.model.VersionResultModel @@ -25,7 +25,7 @@ fun getUserDetail() = launch({ val response = RetrofitServiceManager.getUserDetail() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { val userDetail = gson.fromJson( response, object : TypeToken() {}.type @@ -48,7 +48,7 @@ * */ fun getSubordinate(hasMine: String?, deptId: String?, roleTips: String?) = launch({ val response = RetrofitServiceManager.getSubordinate(hasMine, deptId, roleTips) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { subordinateModel.value = gson.fromJson( response, object : TypeToken() {}.type @@ -61,7 +61,7 @@ fun changePassword(oldPwd: String, newPwd: String) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.changePassword(oldPwd, newPwd) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success "修改成功,请重新登录".show(BaseApplication.get()) @@ -76,7 +76,7 @@ fun updateVersion() = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.updateVersion() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success versionResultModel.value = gson.fromJson( diff --git a/app/src/main/java/com/casic/app/smartwell/vm/WellViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/WellViewModel.kt index 3d41e9b..9e42e36 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/WellViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/WellViewModel.kt @@ -2,8 +2,7 @@ import androidx.lifecycle.MutableLiveData import com.casic.app.smartwell.base.BaseApplication -import com.casic.app.smartwell.extensions.separateResponseCode -import com.casic.app.smartwell.extensions.toErrorMessage +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.AuthorDeptModel import com.casic.app.smartwell.model.CommonResultModel import com.casic.app.smartwell.model.MapWellListModel @@ -32,7 +31,7 @@ fun countWellByState() = launch({ val response = RetrofitServiceManager.countWellByState() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { val map = HashMap(3) @@ -57,7 +56,7 @@ fun getWellType() = launch({ val response = RetrofitServiceManager.getWellType() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { wellTypeModel.value = gson.fromJson( response, object : TypeToken() {}.type @@ -70,7 +69,7 @@ fun getWellDetail(id: String) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.getWellDetail(id) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success wellDetailModel.value = gson.fromJson( @@ -87,7 +86,7 @@ fun getOperationResult(id: String, state: String) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.getOperationResult(id, state) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success "操作成功".show(BaseApplication.get()) @@ -105,7 +104,7 @@ fun getMonitorResult(id: String) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.getMonitorResult(id) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success monitorModel.value = gson.fromJson( @@ -125,7 +124,7 @@ val response = RetrofitServiceManager.getWellListByPage( keywords, wellType, deptid, bfzt, page ) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { listModel.value = gson.fromJson( response, object : TypeToken() {}.type @@ -137,13 +136,11 @@ fun getWellList() = launch({ val response = RetrofitServiceManager.getWellList() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { totalWellModel.value = gson.fromJson( response, object : TypeToken() {}.type ) - } else { - response.toErrorMessage().show(BaseApplication.get()) } }, { it.printStackTrace() diff --git a/app/src/main/java/com/casic/app/smartwell/widgets/GaoDeClusterMarkerView.kt b/app/src/main/java/com/casic/app/smartwell/widgets/GaoDeClusterMarkerView.kt deleted file mode 100644 index 1f375df..0000000 --- a/app/src/main/java/com/casic/app/smartwell/widgets/GaoDeClusterMarkerView.kt +++ /dev/null @@ -1,100 +0,0 @@ -package com.casic.app.smartwell.widgets - -import android.content.Context -import android.graphics.Bitmap -import android.graphics.Point -import android.view.Gravity -import android.view.LayoutInflater -import android.view.View -import android.widget.TextView -import com.amap.api.maps.Projection -import com.amap.api.maps.model.BitmapDescriptorFactory -import com.amap.api.maps.model.LatLng -import com.amap.api.maps.model.LatLngBounds -import com.amap.api.maps.model.MarkerOptions -import com.casic.app.smartwell.R -import com.pengxh.kt.lite.extensions.toBitmap -import java.util.* - -class GaoDeClusterMarkerView( - private val context: Context, firstMarkers: MarkerOptions, projection: Projection, gridSize: Int -) { - //当前可观区域里的 聚合过之后的集合 - private val includeMarkers: ArrayList - - // 创建区域 - val bounds: LatLngBounds - var options: MarkerOptions = MarkerOptions() - - init { - val screenLocation = projection.toScreenLocation(firstMarkers.position) - //范围类 - val southwestPoint = Point(screenLocation.x - gridSize, screenLocation.y + gridSize) - //范围类 - val northeastPoint = Point(screenLocation.x + gridSize, screenLocation.y - gridSize) - bounds = LatLngBounds( - projection.fromScreenLocation(southwestPoint), - projection.fromScreenLocation(northeastPoint) - ) - //设置初始化marker属性 - options.anchor(0.5f, 1.3f) - .title(firstMarkers.title) - .position(firstMarkers.position) - .icon(firstMarkers.icon) - .snippet(firstMarkers.snippet) - .draggable(false) - includeMarkers = ArrayList() - includeMarkers.add(firstMarkers) - } - - /** - * 添加marker - */ - fun addMarker(markerOptions: MarkerOptions) { - includeMarkers.add(markerOptions) // 添加到列表中 - } - - /** - * 设置聚合点的中心位置以及图标 - */ - fun setPositionAndIcon() { - val size = includeMarkers.size - var lat = 0.0 - var lng = 0.0 - // 一个的时候 - if (size == 1) { //设置marker单个属性 - // 设置marker位置 - options.position( - LatLng( - includeMarkers[0].position.latitude, includeMarkers[0].position.longitude - ) - ) - } else { // 聚合的时候 - //设置marker聚合属性 - for (op in includeMarkers) { - lat += op.position.latitude - lng += op.position.longitude - } - // 设置marker的位置为中心位置为聚集点的平均位置 - options.position(LatLng(lat / size, lng / size)) - } - options.icon(BitmapDescriptorFactory.fromBitmap(getBitmap(size))) - } - - /** - * marker视图 - */ - private fun getBitmap(num: Int): Bitmap? { - val view = LayoutInflater.from(context).inflate(R.layout.marker_gaode, null) - val wellCountView = view.findViewById(R.id.wellCountView) - return if (num > 1) { - wellCountView.visibility = View.VISIBLE - wellCountView.text = String.format("${num}个") - wellCountView.gravity = Gravity.CENTER - view.toBitmap() - } else { - wellCountView.visibility = View.GONE - BitmapDescriptorFactory.fromResource(R.mipmap.well_location).bitmap - } - } -} \ No newline at end of file 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 new file mode 100644 index 0000000..ec455dd --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/widgets/MapWellPopup.kt @@ -0,0 +1,58 @@ +package com.casic.app.smartwell.widgets + +import android.content.Context +import android.view.LayoutInflater +import android.view.ViewGroup +import android.widget.LinearLayout +import android.widget.PopupWindow +import android.widget.TextView +import com.casic.app.smartwell.R +import com.casic.app.smartwell.extensions.valueToType +import com.casic.app.smartwell.model.MapWellListModel + +class MapWellPopup constructor(context: Context) : PopupWindow() { + + init { + width = ViewGroup.LayoutParams.MATCH_PARENT + height = ViewGroup.LayoutParams.WRAP_CONTENT + isOutsideTouchable = true + isFocusable = true + animationStyle = R.style.MapPopupAnimation + setBackgroundDrawable(null) + contentView = LayoutInflater.from(context).inflate( + R.layout.popup_map_info, null, false + ) + } + + fun set(well: MapWellListModel.DataModel, windowClickListener: OnPopupWindowClickListener) { + //反射得到popup里面的控件对象 + val rootView = contentView.findViewById(R.id.rootView) + val wellNameView = contentView.findViewById(R.id.wellNameView) + val wellCodeView = contentView.findViewById(R.id.wellCodeView) + val wellTypeView = contentView.findViewById(R.id.wellTypeView) + val wellStateView = contentView.findViewById(R.id.wellStateView) + val deepView = contentView.findViewById(R.id.deepView) + val locationView = contentView.findViewById(R.id.locationView) + + //绑定数据 + wellNameView.text = String.format("点位名称: ${well.wellName}") + wellCodeView.text = String.format("点位编号: ${well.wellCode}") + wellTypeView.text = String.format("点位类型: ${well.wellType.valueToType()}") + val bfztName = if (well.bfzt == "1") { + "已布防" + } else { + "已撤防" + } + wellStateView.text = String.format("布/撤防状态: $bfztName") + deepView.text = String.format("点位深度: ${well.deep}m") + locationView.text = String.format("详细位置: ${well.position}") + + rootView.setOnClickListener { + windowClickListener.onPopupClicked(well.latGaode.toDouble(), well.lngGaode.toDouble()) + } + } + + interface OnPopupWindowClickListener { + fun onPopupClicked(lat: Double, lng: Double) + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/widgets/cluster/Cluster.java b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/Cluster.java new file mode 100644 index 0000000..9455ccd --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/Cluster.java @@ -0,0 +1,43 @@ +package com.casic.app.smartwell.widgets.cluster; + +import com.amap.api.maps.model.LatLng; +import com.amap.api.maps.model.Marker; + +import java.util.ArrayList; +import java.util.List; + +public class Cluster { + private final LatLng latLng; + private final List clusterItems; + private Marker marker; + + + public Cluster(LatLng latLng) { + this.latLng = latLng; + clusterItems = new ArrayList<>(); + } + + public void addClusterItem(ClusterItem clusterItem) { + clusterItems.add(clusterItem); + } + + public int getClusterCount() { + return clusterItems.size(); + } + + public LatLng getCenterLatLng() { + return latLng; + } + + public void setMarker(Marker marker) { + this.marker = marker; + } + + public Marker getMarker() { + return marker; + } + + public List getClusterItems() { + return clusterItems; + } +} diff --git a/app/src/main/java/com/casic/app/smartwell/widgets/cluster/ClusterItem.java b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/ClusterItem.java new file mode 100644 index 0000000..f5d9a9d --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/ClusterItem.java @@ -0,0 +1,10 @@ +package com.casic.app.smartwell.widgets.cluster; + +import com.amap.api.maps.model.LatLng; + +public interface ClusterItem { + /** + * 返回聚合元素的地理位置 + */ + LatLng getPosition(); +} diff --git a/app/src/main/java/com/casic/app/smartwell/extensions/Int.kt b/app/src/main/java/com/casic/app/smartwell/extensions/Int.kt index de0617b..a0a5e33 100644 --- a/app/src/main/java/com/casic/app/smartwell/extensions/Int.kt +++ b/app/src/main/java/com/casic/app/smartwell/extensions/Int.kt @@ -1,9 +1,24 @@ package com.casic.app.smartwell.extensions +import android.graphics.Bitmap +import android.graphics.Canvas +import android.graphics.Paint +import android.graphics.RectF + fun Int.toLevel(): String { return if (this == 0) { "" } else { this.toString() } +} + +fun Int.drawCircle(color: Int): Bitmap? { + val bitmap = Bitmap.createBitmap(this * 2, this * 2, Bitmap.Config.ARGB_8888) + val canvas = Canvas(bitmap) + val paint = Paint() + val rectF = RectF(0f, 0f, (this * 2).toFloat(), (this * 2).toFloat()) + paint.color = color + canvas.drawArc(rectF, 0f, 360f, true, paint) + return bitmap } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt index 6b6ca3e..5e45534 100644 --- a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt +++ b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt @@ -2,17 +2,13 @@ import android.content.Context import com.casic.app.smartwell.callback.OnImageCompressListener -import com.casic.app.smartwell.model.ErrorMessageModel import com.casic.app.smartwell.utils.LocaleConstant -import com.google.gson.Gson -import com.google.gson.reflect.TypeToken +import com.google.gson.JsonParser import com.pengxh.kt.lite.extensions.createCompressImageDir import com.pengxh.kt.lite.utils.SaveKeyValues -import org.json.JSONObject import top.zibin.luban.Luban import top.zibin.luban.OnCompressListener import java.io.File -import java.util.Locale /** * String扩展方法 @@ -74,18 +70,22 @@ } } -fun String.separateResponseCode(): Int { +fun String.getResponseCode(): Int { if (this.isBlank()) { return 404 } - return JSONObject(this).getInt("code") + val element = JsonParser.parseString(this) + val jsonObject = element.asJsonObject + return jsonObject.get("code").asInt } -fun String.toErrorMessage(): String { - val errorModel = Gson().fromJson( - this, object : TypeToken() {}.type - ) - return errorModel.message.toString() +fun String.getResponseMessage(): String { + if (this.isBlank()) { + return "" + } + val element = JsonParser.parseString(this) + val jsonObject = element.asJsonObject + return jsonObject.get("message").asString } fun String.compressImage(context: Context, listener: OnImageCompressListener) { @@ -93,9 +93,6 @@ .load(this) .ignoreBy(100) .setTargetDir(context.createCompressImageDir().toString()) - .filter { - !(it.isBlank() || it.lowercase(Locale.getDefault()).endsWith(".gif")) - } .setCompressListener(object : OnCompressListener { override fun onStart() { 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 96df110..cd25fca 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 @@ -1,26 +1,25 @@ package com.casic.app.smartwell.fragment -import android.graphics.Point +import android.graphics.Color +import android.graphics.drawable.BitmapDrawable +import android.graphics.drawable.Drawable 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 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.LatLngBounds import com.amap.api.maps.model.Marker -import com.amap.api.maps.model.MarkerOptions import com.casic.app.smartwell.R import com.casic.app.smartwell.databinding.FragmentHomeBinding +import com.casic.app.smartwell.extensions.drawCircle import com.casic.app.smartwell.extensions.initImmersionBar -import com.casic.app.smartwell.extensions.valueToType import com.casic.app.smartwell.model.MapWellListModel import com.casic.app.smartwell.utils.LocaleConstant import com.casic.app.smartwell.utils.RouteOnMap @@ -31,9 +30,16 @@ import com.casic.app.smartwell.view.WellOperationActivity import com.casic.app.smartwell.vm.OrderViewModel import com.casic.app.smartwell.vm.WellViewModel +import com.casic.app.smartwell.widgets.MapWellPopup +import com.casic.app.smartwell.widgets.cluster.ClusterItem +import com.casic.app.smartwell.widgets.cluster.ClusterOnClickListener +import com.casic.app.smartwell.widgets.cluster.ClusterOverlay +import com.casic.app.smartwell.widgets.cluster.RegionItem 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.convertDrawable +import com.pengxh.kt.lite.extensions.dp2px import com.pengxh.kt.lite.extensions.navigatePageTo import com.pengxh.kt.lite.extensions.show import com.pengxh.kt.lite.utils.LoadingDialogHub @@ -43,35 +49,23 @@ /** * 地图点位带聚合效果 * */ -class HomePageHaveClusterFragment : KotlinBaseFragment(), AMap.OnMapLoadedListener, - AMap.OnCameraChangeListener, AMap.OnMarkerClickListener, AMap.InfoWindowAdapter, - AMap.OnInfoWindowClickListener { +class HomePageHaveClusterFragment : KotlinBaseFragment(), + AMap.OnCameraChangeListener { private val kTag = "HaveClusterFragment" private val easyPopupWindow by lazy { EasyPopupWindow(requireContext()) } - private lateinit var wellViewModel: WellViewModel - private lateinit var orderViewModel: OrderViewModel - private lateinit var aMap: AMap - - /** - * 所有的marker - */ - private var allMarkerOptions: MutableList = ArrayList() - - /** - * 视野内的marker - */ - private var markerOptionsInView: MutableList = ArrayList() - - /** - * 自定义Marker弹出框 - * */ - private lateinit var v: View + private val regionRadius by lazy { LocaleConstant.RADIUS_SIZE.dp2px(requireContext()) } + private val infoPopup by lazy { MapWellPopup(requireContext()) } /** * 所有窨井列表信息集合 * */ - private var wellModels: MutableList = ArrayList() + private val wellModels = ArrayList() + private val backDrawables = HashMap() + private lateinit var wellViewModel: WellViewModel + private lateinit var orderViewModel: OrderViewModel + private lateinit var aMap: AMap + private var clusterOverlay: ClusterOverlay? = null override fun initViewBinding( inflater: LayoutInflater, @@ -106,6 +100,9 @@ } }) + //地图初始化 + initMap(savedInstanceState) + //初始化vm wellViewModel = ViewModelProvider(this)[WellViewModel::class.java] orderViewModel = ViewModelProvider(this)[OrderViewModel::class.java] @@ -120,25 +117,19 @@ val latitudeList: MutableList = ArrayList() val longitudeList: MutableList = ArrayList() it.data?.forEach { well -> - val lat = well.latGaode.toString() - val lng = well.lngGaode.toString() + val lat = well.latGaode + val lng = well.lngGaode if (lat.isNotBlank() && lng.isNotBlank()) { //返回true代表当前位置在大陆、港澳地区,反之不在 val latitude = lat.toDouble() val longitude = lng.toDouble() if (CoordinateConverter.isAMapDataAvailable(latitude, longitude)) { - //缓存所有设备详情,点击Marker时候需要 + //缓存所有井 wellModels.add(well) + //分别缓存经、纬度 latitudeList.add(latitude) longitudeList.add(longitude) - //将所有设备信息转化缓存为Marker点 - allMarkerOptions.add( - MarkerOptions() - .position(LatLng(latitude, longitude)) - .title(well.wellTypeName) - .snippet(well.wellName) - ) } } } @@ -160,12 +151,12 @@ val cameraPosition = CameraPosition(centerLatLng, 16f, 0f, 0f) val cameraUpdate = CameraUpdateFactory.newCameraPosition(cameraPosition) aMap.animateCamera(cameraUpdate, 1500, null) + + //显示点数据 + displayWellOnMap() } } - //地图初始化 - initMap(savedInstanceState) - //获取窨井监控数据 wellViewModel.countResultModel.observe(this) { binding.deployedWellView.text = it["bfWell"] @@ -220,17 +211,10 @@ uiSettings.isCompassEnabled = true uiSettings.zoomPosition = AMapOptions.ZOOM_POSITION_RIGHT_CENTER uiSettings.isTiltGesturesEnabled = false//不许地图随手势倾斜角度 + uiSettings.isRotateGesturesEnabled = false//不允许地图随手势改变方位 - // 地图加载成功监听 - aMap.addOnMapLoadedListener(this) // 地图缩放监听 aMap.addOnCameraChangeListener(this) - // marker 点击事件监听 - aMap.addOnMarkerClickListener(this) - // 点击marker弹出自定义popup - aMap.setInfoWindowAdapter(this) - //信息窗点击事件 - aMap.addOnInfoWindowClickListener(this) } override fun initEvent() { @@ -259,9 +243,111 @@ } - override fun onMapLoaded() { - //地图加载成功之后显示聚合点数据 - initClustersMarkers() + private fun displayWellOnMap() { + clusterOverlay?.onDestroy() + val clusterItems = ArrayList() + + wellModels.forEach { + val latitude = it.latGaode.toDouble() + val longitude = it.lngGaode.toDouble() + + val latLng = LatLng(latitude, longitude, false) + val regionItem = RegionItem(latLng, it) + clusterItems.add(regionItem) + } + + clusterOverlay = ClusterOverlay(requireContext(), aMap, clusterItems, regionRadius) + clusterOverlay?.setClusterRender { clusterNum -> + //聚合圆半径 + val radius = 100.dp2px(requireContext()) + if (clusterNum == 0) { + var bitmapDrawable = backDrawables[0] + if (bitmapDrawable == null) { + bitmapDrawable = BitmapDrawable( + null, radius.drawCircle(Color.argb(159, 100, 149, 237)) + ) + backDrawables[0] = bitmapDrawable + } + bitmapDrawable + } + if (clusterNum == 1) { + var bitmapDrawable = backDrawables[1] + if (bitmapDrawable == null) { + bitmapDrawable = R.mipmap.well_location.convertDrawable(requireContext())!! + backDrawables[1] = bitmapDrawable + } + bitmapDrawable + } else if (clusterNum < 5) { + var bitmapDrawable = backDrawables[2] + if (bitmapDrawable == null) { + bitmapDrawable = BitmapDrawable( + null, radius.drawCircle(Color.argb(159, 100, 149, 237)) + ) + backDrawables[2] = bitmapDrawable + } + bitmapDrawable + } else if (clusterNum < 10) { + var bitmapDrawable = backDrawables[3] + if (bitmapDrawable == null) { + bitmapDrawable = BitmapDrawable( + null, radius.drawCircle(Color.argb(199, 30, 144, 255)) + ) + backDrawables[3] = bitmapDrawable + } + bitmapDrawable + } else { + var bitmapDrawable = backDrawables[4] + if (bitmapDrawable == null) { + bitmapDrawable = BitmapDrawable( + null, radius.drawCircle(Color.argb(235, 65, 105, 225)) + ) + backDrawables[4] = bitmapDrawable + } + bitmapDrawable + } + } + + clusterOverlay?.setOnClusterClickListener(object : ClusterOnClickListener { + override fun onMarkerClicked(marker: Marker?, items: List) { + if (items.size > 1) { + "请缩放地图比例在查看数据".show(requireContext()) + return + } + + var item: RegionItem? = null + val builder = LatLngBounds.Builder() + for (clusterItem in items) { + builder.include(clusterItem.position) + item = clusterItem as RegionItem + } + + item?.apply { + showWellPopup(well) + } + } + }) + } + + private fun showWellPopup(well: MapWellListModel.DataModel) { + infoPopup.set(well, object : MapWellPopup.OnPopupWindowClickListener { + override fun onPopupClicked(lat: Double, lng: Double) { + AlertControlDialog.Builder().setContext(requireContext()).setTitle("操作提示") + .setMessage("确定要前往吗").setNegativeButton("取消").setPositiveButton("确定") + .setOnDialogButtonClickListener(object : + AlertControlDialog.OnDialogButtonClickListener { + override fun onConfirmClick() { + RouteOnMap.startNavigation( + requireContext(), "", LatLng(lat, lng) + ) + } + + override fun onCancelClick() { + + } + }).build().show() + } + }) + infoPopup.showAsDropDown(binding.rightOptionView) } override fun onCameraChange(p0: CameraPosition?) { @@ -282,103 +368,10 @@ } } - //获取视野内的marker 根据聚合算法合成自定义的marker 显示视野内的marker override fun onCameraChangeFinish(p0: CameraPosition?) { //地图缩放之后显示聚合点数据 LoadingDialogHub.dismiss() httpCountDownTimer.cancel() - initClustersMarkers() - } - - private fun initClustersMarkers() { - 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 { - v = LayoutInflater.from(requireContext()).inflate(R.layout.popup_map_info, null) - - //显示闸井信息 - marker?.showInfoWindow() - return true - } - - override fun getInfoWindow(marker: Marker?): View { - //反射得到popup里面的控件对象 - val wellNameView = v.findViewById(R.id.wellNameView) - val wellCodeView = v.findViewById(R.id.wellCodeView) - val wellTypeView = v.findViewById(R.id.wellTypeView) - val wellStateView = v.findViewById(R.id.wellStateView) - val deepView = v.findViewById(R.id.deepView) - val locationView = v.findViewById(R.id.locationView) - - //绑定数据 - val clickedLatLng = marker?.position!! - wellModels.forEach { well -> - if (clickedLatLng.latitude == well.latGaode!!.toDouble() - && clickedLatLng.longitude == well.lngGaode!!.toDouble() - ) { - wellNameView.text = String.format("点位名称: ${well.wellName}") - wellCodeView.text = String.format("点位编号: ${well.wellCode}") - wellTypeView.text = String.format("点位类型: ${well.wellType.valueToType()}") - val bfztName = if (well.bfzt == "1") { - "已布防" - } else { - "已撤防" - } - wellStateView.text = String.format("布/撤防状态: $bfztName") - deepView.text = String.format("点位深度: ${well.deep}m") - locationView.text = String.format("详细位置: ${well.position}") - } - } - return v - } - - /** - * 此方法不能修改整个 InfoWindow 的背景和边框,无论自定义的样式是什么样,SDK 都会在最外层添加一个默认的边框 - * */ - override fun getInfoContents(p0: Marker?): View? = null - - override fun onInfoWindowClick(p0: Marker?) { - p0?.apply { - AlertControlDialog.Builder() - .setContext(requireContext()) - .setTitle("操作提示") - .setMessage("确定要前往吗") - .setNegativeButton("取消") - .setPositiveButton("确定") - .setOnDialogButtonClickListener(object : - AlertControlDialog.OnDialogButtonClickListener { - override fun onConfirmClick() { - val lat = position.latitude.toString() - val lng = position.longitude.toString() - if (lat.isBlank() || lng.isBlank()) { - "点位经纬度异常,无法开启导航".show(requireContext()) - return - } - RouteOnMap.startNavigation( - requireContext(), snippet, LatLng(lat.toDouble(), lng.toDouble()) - ) - } - - override fun onCancelClick() { - - } - }).build().show() - } } /***以下是地图生命周期管理************************************************************************/ 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 a54d213..bfa7a57 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 @@ -44,8 +44,8 @@ * 地图点位不带聚合效果 * */ class HomePageNoClusterFragment : KotlinBaseFragment(), - AMap.OnMapLoadedListener, AMap.OnCameraChangeListener, AMap.OnMarkerClickListener, - AMap.InfoWindowAdapter, AMap.OnInfoWindowClickListener { + AMap.OnCameraChangeListener, AMap.OnMarkerClickListener, AMap.InfoWindowAdapter, + AMap.OnInfoWindowClickListener { private val kTag = "NoClusterFragment" private val easyPopupWindow by lazy { EasyPopupWindow(requireContext()) } @@ -109,6 +109,9 @@ wellViewModel = ViewModelProvider(this)[WellViewModel::class.java] orderViewModel = ViewModelProvider(this)[OrderViewModel::class.java] + //地图初始化 + initMap(savedInstanceState) + //获取所有窨井数据 httpCountDownTimer.start() LoadingDialogHub.show(requireActivity(), "数据加载中,请稍后...") @@ -157,12 +160,12 @@ val cameraPosition = CameraPosition(centerLatLng, 16f, 0f, 0f) val cameraUpdate = CameraUpdateFactory.newCameraPosition(cameraPosition) aMap.animateCamera(cameraUpdate, 1500, null) + + //显示点数据 + displayWellOnMap() } } - //地图初始化 - initMap(savedInstanceState) - //获取窨井监控数据 wellViewModel.countResultModel.observe(this) { binding.deployedWellView.text = it["bfWell"] @@ -214,9 +217,8 @@ uiSettings.isCompassEnabled = true uiSettings.zoomPosition = AMapOptions.ZOOM_POSITION_RIGHT_CENTER uiSettings.isTiltGesturesEnabled = false//不许地图随手势倾斜角度 + uiSettings.isRotateGesturesEnabled = false//不允许地图随手势改变方位 - // 地图加载成功监听 - aMap.addOnMapLoadedListener(this) // 地图缩放监听 aMap.addOnCameraChangeListener(this) // marker 点击事件监听 @@ -253,11 +255,6 @@ } - override fun onMapLoaded() { - //地图加载成功之后显示聚合点数据 - initClustersMarkers() - } - override fun onCameraChange(p0: CameraPosition?) { } @@ -281,10 +278,9 @@ //地图缩放之后显示聚合点数据 LoadingDialogHub.dismiss() httpCountDownTimer.cancel() - initClustersMarkers() } - private fun initClustersMarkers() { + private fun displayWellOnMap() { val proj = aMap.projection val dm = resources.displayMetrics var screenLocation: Point diff --git a/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.java b/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.java deleted file mode 100644 index d8b18ef..0000000 --- a/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.java +++ /dev/null @@ -1,50 +0,0 @@ -package com.casic.app.smartwell.model; - -public class ErrorMessageModel { - - private int code; - private String data; - private String exceptionClazz; - private String message; - private boolean success; - - public int getCode() { - return code; - } - - public void setCode(int code) { - this.code = code; - } - - public String getData() { - return data; - } - - public void setData(String data) { - this.data = data; - } - - public String getExceptionClazz() { - return exceptionClazz; - } - - public void setExceptionClazz(String exceptionClazz) { - this.exceptionClazz = exceptionClazz; - } - - public String getMessage() { - return message; - } - - public void setMessage(String message) { - this.message = message; - } - - public boolean isSuccess() { - return success; - } - - public void setSuccess(boolean success) { - this.success = success; - } -} \ No newline at end of file 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 new file mode 100644 index 0000000..215ac0c --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/PipelineModel.java @@ -0,0 +1,328 @@ +package com.casic.app.smartwell.model; + +import java.util.List; + +public class PipelineModel { + + private Integer code; + private DataModel data; + private String message; + private Boolean success; + + public Integer getCode() { + return code; + } + + public void setCode(Integer code) { + this.code = code; + } + + public DataModel getData() { + return data; + } + + public void setData(DataModel data) { + this.data = data; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + public Boolean getSuccess() { + return success; + } + + public void setSuccess(Boolean success) { + this.success = success; + } + + public static class DataModel { + private List rows; + private Integer total; + + public List getRows() { + return rows; + } + + public void setRows(List rows) { + this.rows = rows; + } + + public Integer getTotal() { + return total; + } + + public void setTotal(Integer total) { + this.total = total; + } + + 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 getBuryMode() { + return buryMode; + } + + public void setBuryMode(String buryMode) { + this.buryMode = buryMode; + } + + public String getConstructEra() { + return constructEra; + } + + public void setConstructEra(String constructEra) { + this.constructEra = constructEra; + } + + 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; + } + } + } +} 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 06d3d2b..4f38a2c 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 = 100 //相距多少米才聚合,单位:米 + const val RADIUS_SIZE = 80 //相距多少米才聚合,单位:米 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:11308" + // 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 0d5f3fa..991e1db 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 @@ -312,4 +312,14 @@ @Header("token") token: String, @Field("clientid") deviceCode: String ): String + + /** + * 管线位置数据 + */ + @GET("/pipeline/listPage") + suspend fun getPipeline( + @Header("token") token: String, + @Query("limit") limit: Int, + @Query("offset") offset: Int + ): String } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt index 1a0ce22..4050067 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt @@ -294,4 +294,11 @@ suspend fun registerPush(clientId: String): String { return api.registerPush(AuthenticationHelper.token!!, clientId) } + + /** + * 管线位置数据 + */ + suspend fun getPipeline(): String { + return api.getPipeline(AuthenticationHelper.token!!, 2000, 1) + } } \ No newline at end of file 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 9270fa1..4ca5a5e 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.HomePageNoClusterFragment +import com.casic.app.smartwell.fragment.HomePageHaveClusterFragment 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/vm/AlarmViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/AlarmViewModel.kt index 9cff08c..e7acc17 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/AlarmViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/AlarmViewModel.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.AlarmContentModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager import com.google.gson.Gson @@ -16,7 +16,7 @@ fun getAlarmContentType(alarmType: String) = launch({ val response = RetrofitServiceManager.getAlarmContentType(alarmType) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { listModel.value = gson.fromJson( response, object : TypeToken() {}.type diff --git a/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt index 5e5b163..895dedd 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.PublicKeyModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager import com.google.gson.Gson @@ -18,7 +18,7 @@ fun getPublicKey() = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.authenticate() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { keyModel.value = gson.fromJson( response, object : TypeToken() {}.type diff --git a/app/src/main/java/com/casic/app/smartwell/vm/DeviceViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/DeviceViewModel.kt index db5ccf6..899a962 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/DeviceViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/DeviceViewModel.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.DeviceDetailModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager import com.google.gson.Gson @@ -16,7 +16,7 @@ fun getDeviceDetail(deviceCode: String) = launch({ val response = RetrofitServiceManager.getDeviceDetail(deviceCode) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { detailModel.value = gson.fromJson( response, object : TypeToken() {}.type diff --git a/app/src/main/java/com/casic/app/smartwell/vm/LoginViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/LoginViewModel.kt index cd8b8a9..a417398 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/LoginViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/LoginViewModel.kt @@ -2,7 +2,7 @@ import androidx.lifecycle.MutableLiveData import com.casic.app.smartwell.base.BaseApplication -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.CommonResultModel import com.casic.app.smartwell.model.LoginResultModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -21,7 +21,7 @@ fun enter(account: String, secretKey: String) = launch({ val response = RetrofitServiceManager.login(account, secretKey) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success enterResultModel.value = gson.fromJson( @@ -38,7 +38,7 @@ fun out() = launch({ val response = RetrofitServiceManager.loginOut() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { outResultModel.value = gson.fromJson( response, object : TypeToken() {}.type diff --git a/app/src/main/java/com/casic/app/smartwell/vm/OperationViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/OperationViewModel.kt index 8943ed3..37e115f 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/OperationViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/OperationViewModel.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.vm import com.casic.app.smartwell.base.BaseApplication -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager import com.pengxh.kt.lite.base.BaseViewModel import com.pengxh.kt.lite.extensions.launch @@ -16,7 +16,7 @@ fun acceptWorkOrder(id: String) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.acceptWorkOrder(id) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success "接单成功".show(BaseApplication.get()) @@ -35,7 +35,7 @@ loadState.value = LoadState.Loading val response = RetrofitServiceManager.confirmWorkOrder(id, firstState, firstStatePhotos, needHandle) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success "工单确认成功".show(BaseApplication.get()) @@ -50,7 +50,7 @@ fun transferWorkOrder(id: String, userId: String) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.transferWorkOrder(id, userId) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success "转单成功".show(BaseApplication.get()) @@ -65,7 +65,7 @@ fun completeWorkOrder(id: String, handleMessage: String, handlePhotos: String) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.completeWorkOrder(id, handleMessage, handlePhotos) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success "工单处理成功".show(BaseApplication.get()) diff --git a/app/src/main/java/com/casic/app/smartwell/vm/OrderViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/OrderViewModel.kt index 4cb26b7..d2fad86 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/OrderViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/OrderViewModel.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.OrderDetailModel import com.casic.app.smartwell.model.OrderListModel import com.casic.app.smartwell.model.OrderStatusModel @@ -37,7 +37,7 @@ val response = RetrofitServiceManager.getSearchResult( keywords, alarmContent, alarmLevel, jobStatus, deptId, beginTime, endTime, offset ) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success searchResult.value = gson.fromJson( @@ -53,7 +53,7 @@ fun getWorkOrderListByState(jobStatus: String, page: Int) = launch({ val response = RetrofitServiceManager.getWorkOrderList(jobStatus, page) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { orderList.value = gson.fromJson( response, object : TypeToken() {}.type @@ -65,7 +65,7 @@ fun getNotAcceptOderList(page: Int) = launch({ val response = RetrofitServiceManager.getNotAcceptOderList(page) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { orderList.value = gson.fromJson( response, object : TypeToken() {}.type @@ -77,7 +77,7 @@ fun getNotHandleOderList(page: Int) = launch({ val response = RetrofitServiceManager.getNotHandleOderList(page) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { orderList.value = gson.fromJson( response, object : TypeToken() {}.type @@ -89,7 +89,7 @@ fun countWorkOrderByState() = launch({ val response = RetrofitServiceManager.countWorkOrderByState() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { val map = HashMap(4) @@ -107,7 +107,7 @@ fun getOrderStatus() = launch({ val response = RetrofitServiceManager.getOrderStatus() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { orderStatusModel.value = gson.fromJson( response, object : TypeToken() {}.type @@ -120,7 +120,7 @@ fun getWorkOrderDetail(id: String) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.getWorkOrderDetail(id) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success detailModel.value = gson.fromJson( diff --git a/app/src/main/java/com/casic/app/smartwell/vm/PipelineViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/PipelineViewModel.kt new file mode 100644 index 0000000..60c1e2f --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/vm/PipelineViewModel.kt @@ -0,0 +1,28 @@ +package com.casic.app.smartwell.vm + +import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.extensions.getResponseCode +import com.casic.app.smartwell.model.PipelineModel +import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken +import com.pengxh.kt.lite.base.BaseViewModel +import com.pengxh.kt.lite.extensions.launch + +class PipelineViewModel : BaseViewModel() { + + private val gson by lazy { Gson() } + val lineResult = MutableLiveData() + + fun getPipeline() = launch({ + val response = RetrofitServiceManager.getPipeline() + val responseCode = response.getResponseCode() + if (responseCode == 200) { + lineResult.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } + }, { + it.printStackTrace() + }) +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/PushViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/PushViewModel.kt index 9279815..12fd610 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/PushViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/PushViewModel.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.CommonResultModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager import com.google.gson.Gson @@ -16,7 +16,7 @@ fun registerPush(clientId: String) = launch({ val response = RetrofitServiceManager.registerPush(clientId) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { registerResultModel.value = gson.fromJson( response, object : TypeToken() {}.type diff --git a/app/src/main/java/com/casic/app/smartwell/vm/UploadImageViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/UploadImageViewModel.kt index 8d6744e..9707eeb 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/UploadImageViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/UploadImageViewModel.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.CommonResultModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager import com.google.gson.Gson @@ -19,7 +19,7 @@ fun uploadImage(image: File) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.uploadImage(image) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success resultModel.value = gson.fromJson( diff --git a/app/src/main/java/com/casic/app/smartwell/vm/UserViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/UserViewModel.kt index 31a4d4c..070c35a 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/UserViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/UserViewModel.kt @@ -2,7 +2,7 @@ import androidx.lifecycle.MutableLiveData import com.casic.app.smartwell.base.BaseApplication -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.SubordinateModel import com.casic.app.smartwell.model.UserDetailModel import com.casic.app.smartwell.model.VersionResultModel @@ -25,7 +25,7 @@ fun getUserDetail() = launch({ val response = RetrofitServiceManager.getUserDetail() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { val userDetail = gson.fromJson( response, object : TypeToken() {}.type @@ -48,7 +48,7 @@ * */ fun getSubordinate(hasMine: String?, deptId: String?, roleTips: String?) = launch({ val response = RetrofitServiceManager.getSubordinate(hasMine, deptId, roleTips) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { subordinateModel.value = gson.fromJson( response, object : TypeToken() {}.type @@ -61,7 +61,7 @@ fun changePassword(oldPwd: String, newPwd: String) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.changePassword(oldPwd, newPwd) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success "修改成功,请重新登录".show(BaseApplication.get()) @@ -76,7 +76,7 @@ fun updateVersion() = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.updateVersion() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success versionResultModel.value = gson.fromJson( diff --git a/app/src/main/java/com/casic/app/smartwell/vm/WellViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/WellViewModel.kt index 3d41e9b..9e42e36 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/WellViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/WellViewModel.kt @@ -2,8 +2,7 @@ import androidx.lifecycle.MutableLiveData import com.casic.app.smartwell.base.BaseApplication -import com.casic.app.smartwell.extensions.separateResponseCode -import com.casic.app.smartwell.extensions.toErrorMessage +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.AuthorDeptModel import com.casic.app.smartwell.model.CommonResultModel import com.casic.app.smartwell.model.MapWellListModel @@ -32,7 +31,7 @@ fun countWellByState() = launch({ val response = RetrofitServiceManager.countWellByState() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { val map = HashMap(3) @@ -57,7 +56,7 @@ fun getWellType() = launch({ val response = RetrofitServiceManager.getWellType() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { wellTypeModel.value = gson.fromJson( response, object : TypeToken() {}.type @@ -70,7 +69,7 @@ fun getWellDetail(id: String) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.getWellDetail(id) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success wellDetailModel.value = gson.fromJson( @@ -87,7 +86,7 @@ fun getOperationResult(id: String, state: String) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.getOperationResult(id, state) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success "操作成功".show(BaseApplication.get()) @@ -105,7 +104,7 @@ fun getMonitorResult(id: String) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.getMonitorResult(id) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success monitorModel.value = gson.fromJson( @@ -125,7 +124,7 @@ val response = RetrofitServiceManager.getWellListByPage( keywords, wellType, deptid, bfzt, page ) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { listModel.value = gson.fromJson( response, object : TypeToken() {}.type @@ -137,13 +136,11 @@ fun getWellList() = launch({ val response = RetrofitServiceManager.getWellList() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { totalWellModel.value = gson.fromJson( response, object : TypeToken() {}.type ) - } else { - response.toErrorMessage().show(BaseApplication.get()) } }, { it.printStackTrace() diff --git a/app/src/main/java/com/casic/app/smartwell/widgets/GaoDeClusterMarkerView.kt b/app/src/main/java/com/casic/app/smartwell/widgets/GaoDeClusterMarkerView.kt deleted file mode 100644 index 1f375df..0000000 --- a/app/src/main/java/com/casic/app/smartwell/widgets/GaoDeClusterMarkerView.kt +++ /dev/null @@ -1,100 +0,0 @@ -package com.casic.app.smartwell.widgets - -import android.content.Context -import android.graphics.Bitmap -import android.graphics.Point -import android.view.Gravity -import android.view.LayoutInflater -import android.view.View -import android.widget.TextView -import com.amap.api.maps.Projection -import com.amap.api.maps.model.BitmapDescriptorFactory -import com.amap.api.maps.model.LatLng -import com.amap.api.maps.model.LatLngBounds -import com.amap.api.maps.model.MarkerOptions -import com.casic.app.smartwell.R -import com.pengxh.kt.lite.extensions.toBitmap -import java.util.* - -class GaoDeClusterMarkerView( - private val context: Context, firstMarkers: MarkerOptions, projection: Projection, gridSize: Int -) { - //当前可观区域里的 聚合过之后的集合 - private val includeMarkers: ArrayList - - // 创建区域 - val bounds: LatLngBounds - var options: MarkerOptions = MarkerOptions() - - init { - val screenLocation = projection.toScreenLocation(firstMarkers.position) - //范围类 - val southwestPoint = Point(screenLocation.x - gridSize, screenLocation.y + gridSize) - //范围类 - val northeastPoint = Point(screenLocation.x + gridSize, screenLocation.y - gridSize) - bounds = LatLngBounds( - projection.fromScreenLocation(southwestPoint), - projection.fromScreenLocation(northeastPoint) - ) - //设置初始化marker属性 - options.anchor(0.5f, 1.3f) - .title(firstMarkers.title) - .position(firstMarkers.position) - .icon(firstMarkers.icon) - .snippet(firstMarkers.snippet) - .draggable(false) - includeMarkers = ArrayList() - includeMarkers.add(firstMarkers) - } - - /** - * 添加marker - */ - fun addMarker(markerOptions: MarkerOptions) { - includeMarkers.add(markerOptions) // 添加到列表中 - } - - /** - * 设置聚合点的中心位置以及图标 - */ - fun setPositionAndIcon() { - val size = includeMarkers.size - var lat = 0.0 - var lng = 0.0 - // 一个的时候 - if (size == 1) { //设置marker单个属性 - // 设置marker位置 - options.position( - LatLng( - includeMarkers[0].position.latitude, includeMarkers[0].position.longitude - ) - ) - } else { // 聚合的时候 - //设置marker聚合属性 - for (op in includeMarkers) { - lat += op.position.latitude - lng += op.position.longitude - } - // 设置marker的位置为中心位置为聚集点的平均位置 - options.position(LatLng(lat / size, lng / size)) - } - options.icon(BitmapDescriptorFactory.fromBitmap(getBitmap(size))) - } - - /** - * marker视图 - */ - private fun getBitmap(num: Int): Bitmap? { - val view = LayoutInflater.from(context).inflate(R.layout.marker_gaode, null) - val wellCountView = view.findViewById(R.id.wellCountView) - return if (num > 1) { - wellCountView.visibility = View.VISIBLE - wellCountView.text = String.format("${num}个") - wellCountView.gravity = Gravity.CENTER - view.toBitmap() - } else { - wellCountView.visibility = View.GONE - BitmapDescriptorFactory.fromResource(R.mipmap.well_location).bitmap - } - } -} \ No newline at end of file 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 new file mode 100644 index 0000000..ec455dd --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/widgets/MapWellPopup.kt @@ -0,0 +1,58 @@ +package com.casic.app.smartwell.widgets + +import android.content.Context +import android.view.LayoutInflater +import android.view.ViewGroup +import android.widget.LinearLayout +import android.widget.PopupWindow +import android.widget.TextView +import com.casic.app.smartwell.R +import com.casic.app.smartwell.extensions.valueToType +import com.casic.app.smartwell.model.MapWellListModel + +class MapWellPopup constructor(context: Context) : PopupWindow() { + + init { + width = ViewGroup.LayoutParams.MATCH_PARENT + height = ViewGroup.LayoutParams.WRAP_CONTENT + isOutsideTouchable = true + isFocusable = true + animationStyle = R.style.MapPopupAnimation + setBackgroundDrawable(null) + contentView = LayoutInflater.from(context).inflate( + R.layout.popup_map_info, null, false + ) + } + + fun set(well: MapWellListModel.DataModel, windowClickListener: OnPopupWindowClickListener) { + //反射得到popup里面的控件对象 + val rootView = contentView.findViewById(R.id.rootView) + val wellNameView = contentView.findViewById(R.id.wellNameView) + val wellCodeView = contentView.findViewById(R.id.wellCodeView) + val wellTypeView = contentView.findViewById(R.id.wellTypeView) + val wellStateView = contentView.findViewById(R.id.wellStateView) + val deepView = contentView.findViewById(R.id.deepView) + val locationView = contentView.findViewById(R.id.locationView) + + //绑定数据 + wellNameView.text = String.format("点位名称: ${well.wellName}") + wellCodeView.text = String.format("点位编号: ${well.wellCode}") + wellTypeView.text = String.format("点位类型: ${well.wellType.valueToType()}") + val bfztName = if (well.bfzt == "1") { + "已布防" + } else { + "已撤防" + } + wellStateView.text = String.format("布/撤防状态: $bfztName") + deepView.text = String.format("点位深度: ${well.deep}m") + locationView.text = String.format("详细位置: ${well.position}") + + rootView.setOnClickListener { + windowClickListener.onPopupClicked(well.latGaode.toDouble(), well.lngGaode.toDouble()) + } + } + + interface OnPopupWindowClickListener { + fun onPopupClicked(lat: Double, lng: Double) + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/widgets/cluster/Cluster.java b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/Cluster.java new file mode 100644 index 0000000..9455ccd --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/Cluster.java @@ -0,0 +1,43 @@ +package com.casic.app.smartwell.widgets.cluster; + +import com.amap.api.maps.model.LatLng; +import com.amap.api.maps.model.Marker; + +import java.util.ArrayList; +import java.util.List; + +public class Cluster { + private final LatLng latLng; + private final List clusterItems; + private Marker marker; + + + public Cluster(LatLng latLng) { + this.latLng = latLng; + clusterItems = new ArrayList<>(); + } + + public void addClusterItem(ClusterItem clusterItem) { + clusterItems.add(clusterItem); + } + + public int getClusterCount() { + return clusterItems.size(); + } + + public LatLng getCenterLatLng() { + return latLng; + } + + public void setMarker(Marker marker) { + this.marker = marker; + } + + public Marker getMarker() { + return marker; + } + + public List getClusterItems() { + return clusterItems; + } +} diff --git a/app/src/main/java/com/casic/app/smartwell/widgets/cluster/ClusterItem.java b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/ClusterItem.java new file mode 100644 index 0000000..f5d9a9d --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/ClusterItem.java @@ -0,0 +1,10 @@ +package com.casic.app.smartwell.widgets.cluster; + +import com.amap.api.maps.model.LatLng; + +public interface ClusterItem { + /** + * 返回聚合元素的地理位置 + */ + LatLng getPosition(); +} diff --git a/app/src/main/java/com/casic/app/smartwell/widgets/cluster/ClusterOnClickListener.java b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/ClusterOnClickListener.java new file mode 100644 index 0000000..0efa1f1 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/ClusterOnClickListener.java @@ -0,0 +1,15 @@ +package com.casic.app.smartwell.widgets.cluster; + +import com.amap.api.maps.model.Marker; + +import java.util.List; + +public interface ClusterOnClickListener { + /** + * 点击聚合点的回调处理函数 + * + * @param marker 点击的聚合点 + * @param items 聚合点所包含的元素 + */ + void onMarkerClicked(Marker marker, List items); +} diff --git a/app/src/main/java/com/casic/app/smartwell/extensions/Int.kt b/app/src/main/java/com/casic/app/smartwell/extensions/Int.kt index de0617b..a0a5e33 100644 --- a/app/src/main/java/com/casic/app/smartwell/extensions/Int.kt +++ b/app/src/main/java/com/casic/app/smartwell/extensions/Int.kt @@ -1,9 +1,24 @@ package com.casic.app.smartwell.extensions +import android.graphics.Bitmap +import android.graphics.Canvas +import android.graphics.Paint +import android.graphics.RectF + fun Int.toLevel(): String { return if (this == 0) { "" } else { this.toString() } +} + +fun Int.drawCircle(color: Int): Bitmap? { + val bitmap = Bitmap.createBitmap(this * 2, this * 2, Bitmap.Config.ARGB_8888) + val canvas = Canvas(bitmap) + val paint = Paint() + val rectF = RectF(0f, 0f, (this * 2).toFloat(), (this * 2).toFloat()) + paint.color = color + canvas.drawArc(rectF, 0f, 360f, true, paint) + return bitmap } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt index 6b6ca3e..5e45534 100644 --- a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt +++ b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt @@ -2,17 +2,13 @@ import android.content.Context import com.casic.app.smartwell.callback.OnImageCompressListener -import com.casic.app.smartwell.model.ErrorMessageModel import com.casic.app.smartwell.utils.LocaleConstant -import com.google.gson.Gson -import com.google.gson.reflect.TypeToken +import com.google.gson.JsonParser import com.pengxh.kt.lite.extensions.createCompressImageDir import com.pengxh.kt.lite.utils.SaveKeyValues -import org.json.JSONObject import top.zibin.luban.Luban import top.zibin.luban.OnCompressListener import java.io.File -import java.util.Locale /** * String扩展方法 @@ -74,18 +70,22 @@ } } -fun String.separateResponseCode(): Int { +fun String.getResponseCode(): Int { if (this.isBlank()) { return 404 } - return JSONObject(this).getInt("code") + val element = JsonParser.parseString(this) + val jsonObject = element.asJsonObject + return jsonObject.get("code").asInt } -fun String.toErrorMessage(): String { - val errorModel = Gson().fromJson( - this, object : TypeToken() {}.type - ) - return errorModel.message.toString() +fun String.getResponseMessage(): String { + if (this.isBlank()) { + return "" + } + val element = JsonParser.parseString(this) + val jsonObject = element.asJsonObject + return jsonObject.get("message").asString } fun String.compressImage(context: Context, listener: OnImageCompressListener) { @@ -93,9 +93,6 @@ .load(this) .ignoreBy(100) .setTargetDir(context.createCompressImageDir().toString()) - .filter { - !(it.isBlank() || it.lowercase(Locale.getDefault()).endsWith(".gif")) - } .setCompressListener(object : OnCompressListener { override fun onStart() { 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 96df110..cd25fca 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 @@ -1,26 +1,25 @@ package com.casic.app.smartwell.fragment -import android.graphics.Point +import android.graphics.Color +import android.graphics.drawable.BitmapDrawable +import android.graphics.drawable.Drawable 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 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.LatLngBounds import com.amap.api.maps.model.Marker -import com.amap.api.maps.model.MarkerOptions import com.casic.app.smartwell.R import com.casic.app.smartwell.databinding.FragmentHomeBinding +import com.casic.app.smartwell.extensions.drawCircle import com.casic.app.smartwell.extensions.initImmersionBar -import com.casic.app.smartwell.extensions.valueToType import com.casic.app.smartwell.model.MapWellListModel import com.casic.app.smartwell.utils.LocaleConstant import com.casic.app.smartwell.utils.RouteOnMap @@ -31,9 +30,16 @@ import com.casic.app.smartwell.view.WellOperationActivity import com.casic.app.smartwell.vm.OrderViewModel import com.casic.app.smartwell.vm.WellViewModel +import com.casic.app.smartwell.widgets.MapWellPopup +import com.casic.app.smartwell.widgets.cluster.ClusterItem +import com.casic.app.smartwell.widgets.cluster.ClusterOnClickListener +import com.casic.app.smartwell.widgets.cluster.ClusterOverlay +import com.casic.app.smartwell.widgets.cluster.RegionItem 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.convertDrawable +import com.pengxh.kt.lite.extensions.dp2px import com.pengxh.kt.lite.extensions.navigatePageTo import com.pengxh.kt.lite.extensions.show import com.pengxh.kt.lite.utils.LoadingDialogHub @@ -43,35 +49,23 @@ /** * 地图点位带聚合效果 * */ -class HomePageHaveClusterFragment : KotlinBaseFragment(), AMap.OnMapLoadedListener, - AMap.OnCameraChangeListener, AMap.OnMarkerClickListener, AMap.InfoWindowAdapter, - AMap.OnInfoWindowClickListener { +class HomePageHaveClusterFragment : KotlinBaseFragment(), + AMap.OnCameraChangeListener { private val kTag = "HaveClusterFragment" private val easyPopupWindow by lazy { EasyPopupWindow(requireContext()) } - private lateinit var wellViewModel: WellViewModel - private lateinit var orderViewModel: OrderViewModel - private lateinit var aMap: AMap - - /** - * 所有的marker - */ - private var allMarkerOptions: MutableList = ArrayList() - - /** - * 视野内的marker - */ - private var markerOptionsInView: MutableList = ArrayList() - - /** - * 自定义Marker弹出框 - * */ - private lateinit var v: View + private val regionRadius by lazy { LocaleConstant.RADIUS_SIZE.dp2px(requireContext()) } + private val infoPopup by lazy { MapWellPopup(requireContext()) } /** * 所有窨井列表信息集合 * */ - private var wellModels: MutableList = ArrayList() + private val wellModels = ArrayList() + private val backDrawables = HashMap() + private lateinit var wellViewModel: WellViewModel + private lateinit var orderViewModel: OrderViewModel + private lateinit var aMap: AMap + private var clusterOverlay: ClusterOverlay? = null override fun initViewBinding( inflater: LayoutInflater, @@ -106,6 +100,9 @@ } }) + //地图初始化 + initMap(savedInstanceState) + //初始化vm wellViewModel = ViewModelProvider(this)[WellViewModel::class.java] orderViewModel = ViewModelProvider(this)[OrderViewModel::class.java] @@ -120,25 +117,19 @@ val latitudeList: MutableList = ArrayList() val longitudeList: MutableList = ArrayList() it.data?.forEach { well -> - val lat = well.latGaode.toString() - val lng = well.lngGaode.toString() + val lat = well.latGaode + val lng = well.lngGaode if (lat.isNotBlank() && lng.isNotBlank()) { //返回true代表当前位置在大陆、港澳地区,反之不在 val latitude = lat.toDouble() val longitude = lng.toDouble() if (CoordinateConverter.isAMapDataAvailable(latitude, longitude)) { - //缓存所有设备详情,点击Marker时候需要 + //缓存所有井 wellModels.add(well) + //分别缓存经、纬度 latitudeList.add(latitude) longitudeList.add(longitude) - //将所有设备信息转化缓存为Marker点 - allMarkerOptions.add( - MarkerOptions() - .position(LatLng(latitude, longitude)) - .title(well.wellTypeName) - .snippet(well.wellName) - ) } } } @@ -160,12 +151,12 @@ val cameraPosition = CameraPosition(centerLatLng, 16f, 0f, 0f) val cameraUpdate = CameraUpdateFactory.newCameraPosition(cameraPosition) aMap.animateCamera(cameraUpdate, 1500, null) + + //显示点数据 + displayWellOnMap() } } - //地图初始化 - initMap(savedInstanceState) - //获取窨井监控数据 wellViewModel.countResultModel.observe(this) { binding.deployedWellView.text = it["bfWell"] @@ -220,17 +211,10 @@ uiSettings.isCompassEnabled = true uiSettings.zoomPosition = AMapOptions.ZOOM_POSITION_RIGHT_CENTER uiSettings.isTiltGesturesEnabled = false//不许地图随手势倾斜角度 + uiSettings.isRotateGesturesEnabled = false//不允许地图随手势改变方位 - // 地图加载成功监听 - aMap.addOnMapLoadedListener(this) // 地图缩放监听 aMap.addOnCameraChangeListener(this) - // marker 点击事件监听 - aMap.addOnMarkerClickListener(this) - // 点击marker弹出自定义popup - aMap.setInfoWindowAdapter(this) - //信息窗点击事件 - aMap.addOnInfoWindowClickListener(this) } override fun initEvent() { @@ -259,9 +243,111 @@ } - override fun onMapLoaded() { - //地图加载成功之后显示聚合点数据 - initClustersMarkers() + private fun displayWellOnMap() { + clusterOverlay?.onDestroy() + val clusterItems = ArrayList() + + wellModels.forEach { + val latitude = it.latGaode.toDouble() + val longitude = it.lngGaode.toDouble() + + val latLng = LatLng(latitude, longitude, false) + val regionItem = RegionItem(latLng, it) + clusterItems.add(regionItem) + } + + clusterOverlay = ClusterOverlay(requireContext(), aMap, clusterItems, regionRadius) + clusterOverlay?.setClusterRender { clusterNum -> + //聚合圆半径 + val radius = 100.dp2px(requireContext()) + if (clusterNum == 0) { + var bitmapDrawable = backDrawables[0] + if (bitmapDrawable == null) { + bitmapDrawable = BitmapDrawable( + null, radius.drawCircle(Color.argb(159, 100, 149, 237)) + ) + backDrawables[0] = bitmapDrawable + } + bitmapDrawable + } + if (clusterNum == 1) { + var bitmapDrawable = backDrawables[1] + if (bitmapDrawable == null) { + bitmapDrawable = R.mipmap.well_location.convertDrawable(requireContext())!! + backDrawables[1] = bitmapDrawable + } + bitmapDrawable + } else if (clusterNum < 5) { + var bitmapDrawable = backDrawables[2] + if (bitmapDrawable == null) { + bitmapDrawable = BitmapDrawable( + null, radius.drawCircle(Color.argb(159, 100, 149, 237)) + ) + backDrawables[2] = bitmapDrawable + } + bitmapDrawable + } else if (clusterNum < 10) { + var bitmapDrawable = backDrawables[3] + if (bitmapDrawable == null) { + bitmapDrawable = BitmapDrawable( + null, radius.drawCircle(Color.argb(199, 30, 144, 255)) + ) + backDrawables[3] = bitmapDrawable + } + bitmapDrawable + } else { + var bitmapDrawable = backDrawables[4] + if (bitmapDrawable == null) { + bitmapDrawable = BitmapDrawable( + null, radius.drawCircle(Color.argb(235, 65, 105, 225)) + ) + backDrawables[4] = bitmapDrawable + } + bitmapDrawable + } + } + + clusterOverlay?.setOnClusterClickListener(object : ClusterOnClickListener { + override fun onMarkerClicked(marker: Marker?, items: List) { + if (items.size > 1) { + "请缩放地图比例在查看数据".show(requireContext()) + return + } + + var item: RegionItem? = null + val builder = LatLngBounds.Builder() + for (clusterItem in items) { + builder.include(clusterItem.position) + item = clusterItem as RegionItem + } + + item?.apply { + showWellPopup(well) + } + } + }) + } + + private fun showWellPopup(well: MapWellListModel.DataModel) { + infoPopup.set(well, object : MapWellPopup.OnPopupWindowClickListener { + override fun onPopupClicked(lat: Double, lng: Double) { + AlertControlDialog.Builder().setContext(requireContext()).setTitle("操作提示") + .setMessage("确定要前往吗").setNegativeButton("取消").setPositiveButton("确定") + .setOnDialogButtonClickListener(object : + AlertControlDialog.OnDialogButtonClickListener { + override fun onConfirmClick() { + RouteOnMap.startNavigation( + requireContext(), "", LatLng(lat, lng) + ) + } + + override fun onCancelClick() { + + } + }).build().show() + } + }) + infoPopup.showAsDropDown(binding.rightOptionView) } override fun onCameraChange(p0: CameraPosition?) { @@ -282,103 +368,10 @@ } } - //获取视野内的marker 根据聚合算法合成自定义的marker 显示视野内的marker override fun onCameraChangeFinish(p0: CameraPosition?) { //地图缩放之后显示聚合点数据 LoadingDialogHub.dismiss() httpCountDownTimer.cancel() - initClustersMarkers() - } - - private fun initClustersMarkers() { - 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 { - v = LayoutInflater.from(requireContext()).inflate(R.layout.popup_map_info, null) - - //显示闸井信息 - marker?.showInfoWindow() - return true - } - - override fun getInfoWindow(marker: Marker?): View { - //反射得到popup里面的控件对象 - val wellNameView = v.findViewById(R.id.wellNameView) - val wellCodeView = v.findViewById(R.id.wellCodeView) - val wellTypeView = v.findViewById(R.id.wellTypeView) - val wellStateView = v.findViewById(R.id.wellStateView) - val deepView = v.findViewById(R.id.deepView) - val locationView = v.findViewById(R.id.locationView) - - //绑定数据 - val clickedLatLng = marker?.position!! - wellModels.forEach { well -> - if (clickedLatLng.latitude == well.latGaode!!.toDouble() - && clickedLatLng.longitude == well.lngGaode!!.toDouble() - ) { - wellNameView.text = String.format("点位名称: ${well.wellName}") - wellCodeView.text = String.format("点位编号: ${well.wellCode}") - wellTypeView.text = String.format("点位类型: ${well.wellType.valueToType()}") - val bfztName = if (well.bfzt == "1") { - "已布防" - } else { - "已撤防" - } - wellStateView.text = String.format("布/撤防状态: $bfztName") - deepView.text = String.format("点位深度: ${well.deep}m") - locationView.text = String.format("详细位置: ${well.position}") - } - } - return v - } - - /** - * 此方法不能修改整个 InfoWindow 的背景和边框,无论自定义的样式是什么样,SDK 都会在最外层添加一个默认的边框 - * */ - override fun getInfoContents(p0: Marker?): View? = null - - override fun onInfoWindowClick(p0: Marker?) { - p0?.apply { - AlertControlDialog.Builder() - .setContext(requireContext()) - .setTitle("操作提示") - .setMessage("确定要前往吗") - .setNegativeButton("取消") - .setPositiveButton("确定") - .setOnDialogButtonClickListener(object : - AlertControlDialog.OnDialogButtonClickListener { - override fun onConfirmClick() { - val lat = position.latitude.toString() - val lng = position.longitude.toString() - if (lat.isBlank() || lng.isBlank()) { - "点位经纬度异常,无法开启导航".show(requireContext()) - return - } - RouteOnMap.startNavigation( - requireContext(), snippet, LatLng(lat.toDouble(), lng.toDouble()) - ) - } - - override fun onCancelClick() { - - } - }).build().show() - } } /***以下是地图生命周期管理************************************************************************/ 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 a54d213..bfa7a57 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 @@ -44,8 +44,8 @@ * 地图点位不带聚合效果 * */ class HomePageNoClusterFragment : KotlinBaseFragment(), - AMap.OnMapLoadedListener, AMap.OnCameraChangeListener, AMap.OnMarkerClickListener, - AMap.InfoWindowAdapter, AMap.OnInfoWindowClickListener { + AMap.OnCameraChangeListener, AMap.OnMarkerClickListener, AMap.InfoWindowAdapter, + AMap.OnInfoWindowClickListener { private val kTag = "NoClusterFragment" private val easyPopupWindow by lazy { EasyPopupWindow(requireContext()) } @@ -109,6 +109,9 @@ wellViewModel = ViewModelProvider(this)[WellViewModel::class.java] orderViewModel = ViewModelProvider(this)[OrderViewModel::class.java] + //地图初始化 + initMap(savedInstanceState) + //获取所有窨井数据 httpCountDownTimer.start() LoadingDialogHub.show(requireActivity(), "数据加载中,请稍后...") @@ -157,12 +160,12 @@ val cameraPosition = CameraPosition(centerLatLng, 16f, 0f, 0f) val cameraUpdate = CameraUpdateFactory.newCameraPosition(cameraPosition) aMap.animateCamera(cameraUpdate, 1500, null) + + //显示点数据 + displayWellOnMap() } } - //地图初始化 - initMap(savedInstanceState) - //获取窨井监控数据 wellViewModel.countResultModel.observe(this) { binding.deployedWellView.text = it["bfWell"] @@ -214,9 +217,8 @@ uiSettings.isCompassEnabled = true uiSettings.zoomPosition = AMapOptions.ZOOM_POSITION_RIGHT_CENTER uiSettings.isTiltGesturesEnabled = false//不许地图随手势倾斜角度 + uiSettings.isRotateGesturesEnabled = false//不允许地图随手势改变方位 - // 地图加载成功监听 - aMap.addOnMapLoadedListener(this) // 地图缩放监听 aMap.addOnCameraChangeListener(this) // marker 点击事件监听 @@ -253,11 +255,6 @@ } - override fun onMapLoaded() { - //地图加载成功之后显示聚合点数据 - initClustersMarkers() - } - override fun onCameraChange(p0: CameraPosition?) { } @@ -281,10 +278,9 @@ //地图缩放之后显示聚合点数据 LoadingDialogHub.dismiss() httpCountDownTimer.cancel() - initClustersMarkers() } - private fun initClustersMarkers() { + private fun displayWellOnMap() { val proj = aMap.projection val dm = resources.displayMetrics var screenLocation: Point diff --git a/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.java b/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.java deleted file mode 100644 index d8b18ef..0000000 --- a/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.java +++ /dev/null @@ -1,50 +0,0 @@ -package com.casic.app.smartwell.model; - -public class ErrorMessageModel { - - private int code; - private String data; - private String exceptionClazz; - private String message; - private boolean success; - - public int getCode() { - return code; - } - - public void setCode(int code) { - this.code = code; - } - - public String getData() { - return data; - } - - public void setData(String data) { - this.data = data; - } - - public String getExceptionClazz() { - return exceptionClazz; - } - - public void setExceptionClazz(String exceptionClazz) { - this.exceptionClazz = exceptionClazz; - } - - public String getMessage() { - return message; - } - - public void setMessage(String message) { - this.message = message; - } - - public boolean isSuccess() { - return success; - } - - public void setSuccess(boolean success) { - this.success = success; - } -} \ No newline at end of file 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 new file mode 100644 index 0000000..215ac0c --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/PipelineModel.java @@ -0,0 +1,328 @@ +package com.casic.app.smartwell.model; + +import java.util.List; + +public class PipelineModel { + + private Integer code; + private DataModel data; + private String message; + private Boolean success; + + public Integer getCode() { + return code; + } + + public void setCode(Integer code) { + this.code = code; + } + + public DataModel getData() { + return data; + } + + public void setData(DataModel data) { + this.data = data; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + public Boolean getSuccess() { + return success; + } + + public void setSuccess(Boolean success) { + this.success = success; + } + + public static class DataModel { + private List rows; + private Integer total; + + public List getRows() { + return rows; + } + + public void setRows(List rows) { + this.rows = rows; + } + + public Integer getTotal() { + return total; + } + + public void setTotal(Integer total) { + this.total = total; + } + + 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 getBuryMode() { + return buryMode; + } + + public void setBuryMode(String buryMode) { + this.buryMode = buryMode; + } + + public String getConstructEra() { + return constructEra; + } + + public void setConstructEra(String constructEra) { + this.constructEra = constructEra; + } + + 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; + } + } + } +} 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 06d3d2b..4f38a2c 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 = 100 //相距多少米才聚合,单位:米 + const val RADIUS_SIZE = 80 //相距多少米才聚合,单位:米 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:11308" + // 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 0d5f3fa..991e1db 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 @@ -312,4 +312,14 @@ @Header("token") token: String, @Field("clientid") deviceCode: String ): String + + /** + * 管线位置数据 + */ + @GET("/pipeline/listPage") + suspend fun getPipeline( + @Header("token") token: String, + @Query("limit") limit: Int, + @Query("offset") offset: Int + ): String } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt index 1a0ce22..4050067 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt @@ -294,4 +294,11 @@ suspend fun registerPush(clientId: String): String { return api.registerPush(AuthenticationHelper.token!!, clientId) } + + /** + * 管线位置数据 + */ + suspend fun getPipeline(): String { + return api.getPipeline(AuthenticationHelper.token!!, 2000, 1) + } } \ No newline at end of file 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 9270fa1..4ca5a5e 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.HomePageNoClusterFragment +import com.casic.app.smartwell.fragment.HomePageHaveClusterFragment 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/vm/AlarmViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/AlarmViewModel.kt index 9cff08c..e7acc17 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/AlarmViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/AlarmViewModel.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.AlarmContentModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager import com.google.gson.Gson @@ -16,7 +16,7 @@ fun getAlarmContentType(alarmType: String) = launch({ val response = RetrofitServiceManager.getAlarmContentType(alarmType) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { listModel.value = gson.fromJson( response, object : TypeToken() {}.type diff --git a/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt index 5e5b163..895dedd 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.PublicKeyModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager import com.google.gson.Gson @@ -18,7 +18,7 @@ fun getPublicKey() = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.authenticate() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { keyModel.value = gson.fromJson( response, object : TypeToken() {}.type diff --git a/app/src/main/java/com/casic/app/smartwell/vm/DeviceViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/DeviceViewModel.kt index db5ccf6..899a962 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/DeviceViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/DeviceViewModel.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.DeviceDetailModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager import com.google.gson.Gson @@ -16,7 +16,7 @@ fun getDeviceDetail(deviceCode: String) = launch({ val response = RetrofitServiceManager.getDeviceDetail(deviceCode) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { detailModel.value = gson.fromJson( response, object : TypeToken() {}.type diff --git a/app/src/main/java/com/casic/app/smartwell/vm/LoginViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/LoginViewModel.kt index cd8b8a9..a417398 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/LoginViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/LoginViewModel.kt @@ -2,7 +2,7 @@ import androidx.lifecycle.MutableLiveData import com.casic.app.smartwell.base.BaseApplication -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.CommonResultModel import com.casic.app.smartwell.model.LoginResultModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -21,7 +21,7 @@ fun enter(account: String, secretKey: String) = launch({ val response = RetrofitServiceManager.login(account, secretKey) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success enterResultModel.value = gson.fromJson( @@ -38,7 +38,7 @@ fun out() = launch({ val response = RetrofitServiceManager.loginOut() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { outResultModel.value = gson.fromJson( response, object : TypeToken() {}.type diff --git a/app/src/main/java/com/casic/app/smartwell/vm/OperationViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/OperationViewModel.kt index 8943ed3..37e115f 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/OperationViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/OperationViewModel.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.vm import com.casic.app.smartwell.base.BaseApplication -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager import com.pengxh.kt.lite.base.BaseViewModel import com.pengxh.kt.lite.extensions.launch @@ -16,7 +16,7 @@ fun acceptWorkOrder(id: String) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.acceptWorkOrder(id) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success "接单成功".show(BaseApplication.get()) @@ -35,7 +35,7 @@ loadState.value = LoadState.Loading val response = RetrofitServiceManager.confirmWorkOrder(id, firstState, firstStatePhotos, needHandle) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success "工单确认成功".show(BaseApplication.get()) @@ -50,7 +50,7 @@ fun transferWorkOrder(id: String, userId: String) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.transferWorkOrder(id, userId) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success "转单成功".show(BaseApplication.get()) @@ -65,7 +65,7 @@ fun completeWorkOrder(id: String, handleMessage: String, handlePhotos: String) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.completeWorkOrder(id, handleMessage, handlePhotos) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success "工单处理成功".show(BaseApplication.get()) diff --git a/app/src/main/java/com/casic/app/smartwell/vm/OrderViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/OrderViewModel.kt index 4cb26b7..d2fad86 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/OrderViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/OrderViewModel.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.OrderDetailModel import com.casic.app.smartwell.model.OrderListModel import com.casic.app.smartwell.model.OrderStatusModel @@ -37,7 +37,7 @@ val response = RetrofitServiceManager.getSearchResult( keywords, alarmContent, alarmLevel, jobStatus, deptId, beginTime, endTime, offset ) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success searchResult.value = gson.fromJson( @@ -53,7 +53,7 @@ fun getWorkOrderListByState(jobStatus: String, page: Int) = launch({ val response = RetrofitServiceManager.getWorkOrderList(jobStatus, page) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { orderList.value = gson.fromJson( response, object : TypeToken() {}.type @@ -65,7 +65,7 @@ fun getNotAcceptOderList(page: Int) = launch({ val response = RetrofitServiceManager.getNotAcceptOderList(page) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { orderList.value = gson.fromJson( response, object : TypeToken() {}.type @@ -77,7 +77,7 @@ fun getNotHandleOderList(page: Int) = launch({ val response = RetrofitServiceManager.getNotHandleOderList(page) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { orderList.value = gson.fromJson( response, object : TypeToken() {}.type @@ -89,7 +89,7 @@ fun countWorkOrderByState() = launch({ val response = RetrofitServiceManager.countWorkOrderByState() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { val map = HashMap(4) @@ -107,7 +107,7 @@ fun getOrderStatus() = launch({ val response = RetrofitServiceManager.getOrderStatus() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { orderStatusModel.value = gson.fromJson( response, object : TypeToken() {}.type @@ -120,7 +120,7 @@ fun getWorkOrderDetail(id: String) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.getWorkOrderDetail(id) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success detailModel.value = gson.fromJson( diff --git a/app/src/main/java/com/casic/app/smartwell/vm/PipelineViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/PipelineViewModel.kt new file mode 100644 index 0000000..60c1e2f --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/vm/PipelineViewModel.kt @@ -0,0 +1,28 @@ +package com.casic.app.smartwell.vm + +import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.extensions.getResponseCode +import com.casic.app.smartwell.model.PipelineModel +import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken +import com.pengxh.kt.lite.base.BaseViewModel +import com.pengxh.kt.lite.extensions.launch + +class PipelineViewModel : BaseViewModel() { + + private val gson by lazy { Gson() } + val lineResult = MutableLiveData() + + fun getPipeline() = launch({ + val response = RetrofitServiceManager.getPipeline() + val responseCode = response.getResponseCode() + if (responseCode == 200) { + lineResult.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } + }, { + it.printStackTrace() + }) +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/PushViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/PushViewModel.kt index 9279815..12fd610 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/PushViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/PushViewModel.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.CommonResultModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager import com.google.gson.Gson @@ -16,7 +16,7 @@ fun registerPush(clientId: String) = launch({ val response = RetrofitServiceManager.registerPush(clientId) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { registerResultModel.value = gson.fromJson( response, object : TypeToken() {}.type diff --git a/app/src/main/java/com/casic/app/smartwell/vm/UploadImageViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/UploadImageViewModel.kt index 8d6744e..9707eeb 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/UploadImageViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/UploadImageViewModel.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.CommonResultModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager import com.google.gson.Gson @@ -19,7 +19,7 @@ fun uploadImage(image: File) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.uploadImage(image) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success resultModel.value = gson.fromJson( diff --git a/app/src/main/java/com/casic/app/smartwell/vm/UserViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/UserViewModel.kt index 31a4d4c..070c35a 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/UserViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/UserViewModel.kt @@ -2,7 +2,7 @@ import androidx.lifecycle.MutableLiveData import com.casic.app.smartwell.base.BaseApplication -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.SubordinateModel import com.casic.app.smartwell.model.UserDetailModel import com.casic.app.smartwell.model.VersionResultModel @@ -25,7 +25,7 @@ fun getUserDetail() = launch({ val response = RetrofitServiceManager.getUserDetail() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { val userDetail = gson.fromJson( response, object : TypeToken() {}.type @@ -48,7 +48,7 @@ * */ fun getSubordinate(hasMine: String?, deptId: String?, roleTips: String?) = launch({ val response = RetrofitServiceManager.getSubordinate(hasMine, deptId, roleTips) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { subordinateModel.value = gson.fromJson( response, object : TypeToken() {}.type @@ -61,7 +61,7 @@ fun changePassword(oldPwd: String, newPwd: String) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.changePassword(oldPwd, newPwd) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success "修改成功,请重新登录".show(BaseApplication.get()) @@ -76,7 +76,7 @@ fun updateVersion() = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.updateVersion() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success versionResultModel.value = gson.fromJson( diff --git a/app/src/main/java/com/casic/app/smartwell/vm/WellViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/WellViewModel.kt index 3d41e9b..9e42e36 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/WellViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/WellViewModel.kt @@ -2,8 +2,7 @@ import androidx.lifecycle.MutableLiveData import com.casic.app.smartwell.base.BaseApplication -import com.casic.app.smartwell.extensions.separateResponseCode -import com.casic.app.smartwell.extensions.toErrorMessage +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.AuthorDeptModel import com.casic.app.smartwell.model.CommonResultModel import com.casic.app.smartwell.model.MapWellListModel @@ -32,7 +31,7 @@ fun countWellByState() = launch({ val response = RetrofitServiceManager.countWellByState() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { val map = HashMap(3) @@ -57,7 +56,7 @@ fun getWellType() = launch({ val response = RetrofitServiceManager.getWellType() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { wellTypeModel.value = gson.fromJson( response, object : TypeToken() {}.type @@ -70,7 +69,7 @@ fun getWellDetail(id: String) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.getWellDetail(id) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success wellDetailModel.value = gson.fromJson( @@ -87,7 +86,7 @@ fun getOperationResult(id: String, state: String) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.getOperationResult(id, state) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success "操作成功".show(BaseApplication.get()) @@ -105,7 +104,7 @@ fun getMonitorResult(id: String) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.getMonitorResult(id) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success monitorModel.value = gson.fromJson( @@ -125,7 +124,7 @@ val response = RetrofitServiceManager.getWellListByPage( keywords, wellType, deptid, bfzt, page ) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { listModel.value = gson.fromJson( response, object : TypeToken() {}.type @@ -137,13 +136,11 @@ fun getWellList() = launch({ val response = RetrofitServiceManager.getWellList() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { totalWellModel.value = gson.fromJson( response, object : TypeToken() {}.type ) - } else { - response.toErrorMessage().show(BaseApplication.get()) } }, { it.printStackTrace() diff --git a/app/src/main/java/com/casic/app/smartwell/widgets/GaoDeClusterMarkerView.kt b/app/src/main/java/com/casic/app/smartwell/widgets/GaoDeClusterMarkerView.kt deleted file mode 100644 index 1f375df..0000000 --- a/app/src/main/java/com/casic/app/smartwell/widgets/GaoDeClusterMarkerView.kt +++ /dev/null @@ -1,100 +0,0 @@ -package com.casic.app.smartwell.widgets - -import android.content.Context -import android.graphics.Bitmap -import android.graphics.Point -import android.view.Gravity -import android.view.LayoutInflater -import android.view.View -import android.widget.TextView -import com.amap.api.maps.Projection -import com.amap.api.maps.model.BitmapDescriptorFactory -import com.amap.api.maps.model.LatLng -import com.amap.api.maps.model.LatLngBounds -import com.amap.api.maps.model.MarkerOptions -import com.casic.app.smartwell.R -import com.pengxh.kt.lite.extensions.toBitmap -import java.util.* - -class GaoDeClusterMarkerView( - private val context: Context, firstMarkers: MarkerOptions, projection: Projection, gridSize: Int -) { - //当前可观区域里的 聚合过之后的集合 - private val includeMarkers: ArrayList - - // 创建区域 - val bounds: LatLngBounds - var options: MarkerOptions = MarkerOptions() - - init { - val screenLocation = projection.toScreenLocation(firstMarkers.position) - //范围类 - val southwestPoint = Point(screenLocation.x - gridSize, screenLocation.y + gridSize) - //范围类 - val northeastPoint = Point(screenLocation.x + gridSize, screenLocation.y - gridSize) - bounds = LatLngBounds( - projection.fromScreenLocation(southwestPoint), - projection.fromScreenLocation(northeastPoint) - ) - //设置初始化marker属性 - options.anchor(0.5f, 1.3f) - .title(firstMarkers.title) - .position(firstMarkers.position) - .icon(firstMarkers.icon) - .snippet(firstMarkers.snippet) - .draggable(false) - includeMarkers = ArrayList() - includeMarkers.add(firstMarkers) - } - - /** - * 添加marker - */ - fun addMarker(markerOptions: MarkerOptions) { - includeMarkers.add(markerOptions) // 添加到列表中 - } - - /** - * 设置聚合点的中心位置以及图标 - */ - fun setPositionAndIcon() { - val size = includeMarkers.size - var lat = 0.0 - var lng = 0.0 - // 一个的时候 - if (size == 1) { //设置marker单个属性 - // 设置marker位置 - options.position( - LatLng( - includeMarkers[0].position.latitude, includeMarkers[0].position.longitude - ) - ) - } else { // 聚合的时候 - //设置marker聚合属性 - for (op in includeMarkers) { - lat += op.position.latitude - lng += op.position.longitude - } - // 设置marker的位置为中心位置为聚集点的平均位置 - options.position(LatLng(lat / size, lng / size)) - } - options.icon(BitmapDescriptorFactory.fromBitmap(getBitmap(size))) - } - - /** - * marker视图 - */ - private fun getBitmap(num: Int): Bitmap? { - val view = LayoutInflater.from(context).inflate(R.layout.marker_gaode, null) - val wellCountView = view.findViewById(R.id.wellCountView) - return if (num > 1) { - wellCountView.visibility = View.VISIBLE - wellCountView.text = String.format("${num}个") - wellCountView.gravity = Gravity.CENTER - view.toBitmap() - } else { - wellCountView.visibility = View.GONE - BitmapDescriptorFactory.fromResource(R.mipmap.well_location).bitmap - } - } -} \ No newline at end of file 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 new file mode 100644 index 0000000..ec455dd --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/widgets/MapWellPopup.kt @@ -0,0 +1,58 @@ +package com.casic.app.smartwell.widgets + +import android.content.Context +import android.view.LayoutInflater +import android.view.ViewGroup +import android.widget.LinearLayout +import android.widget.PopupWindow +import android.widget.TextView +import com.casic.app.smartwell.R +import com.casic.app.smartwell.extensions.valueToType +import com.casic.app.smartwell.model.MapWellListModel + +class MapWellPopup constructor(context: Context) : PopupWindow() { + + init { + width = ViewGroup.LayoutParams.MATCH_PARENT + height = ViewGroup.LayoutParams.WRAP_CONTENT + isOutsideTouchable = true + isFocusable = true + animationStyle = R.style.MapPopupAnimation + setBackgroundDrawable(null) + contentView = LayoutInflater.from(context).inflate( + R.layout.popup_map_info, null, false + ) + } + + fun set(well: MapWellListModel.DataModel, windowClickListener: OnPopupWindowClickListener) { + //反射得到popup里面的控件对象 + val rootView = contentView.findViewById(R.id.rootView) + val wellNameView = contentView.findViewById(R.id.wellNameView) + val wellCodeView = contentView.findViewById(R.id.wellCodeView) + val wellTypeView = contentView.findViewById(R.id.wellTypeView) + val wellStateView = contentView.findViewById(R.id.wellStateView) + val deepView = contentView.findViewById(R.id.deepView) + val locationView = contentView.findViewById(R.id.locationView) + + //绑定数据 + wellNameView.text = String.format("点位名称: ${well.wellName}") + wellCodeView.text = String.format("点位编号: ${well.wellCode}") + wellTypeView.text = String.format("点位类型: ${well.wellType.valueToType()}") + val bfztName = if (well.bfzt == "1") { + "已布防" + } else { + "已撤防" + } + wellStateView.text = String.format("布/撤防状态: $bfztName") + deepView.text = String.format("点位深度: ${well.deep}m") + locationView.text = String.format("详细位置: ${well.position}") + + rootView.setOnClickListener { + windowClickListener.onPopupClicked(well.latGaode.toDouble(), well.lngGaode.toDouble()) + } + } + + interface OnPopupWindowClickListener { + fun onPopupClicked(lat: Double, lng: Double) + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/widgets/cluster/Cluster.java b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/Cluster.java new file mode 100644 index 0000000..9455ccd --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/Cluster.java @@ -0,0 +1,43 @@ +package com.casic.app.smartwell.widgets.cluster; + +import com.amap.api.maps.model.LatLng; +import com.amap.api.maps.model.Marker; + +import java.util.ArrayList; +import java.util.List; + +public class Cluster { + private final LatLng latLng; + private final List clusterItems; + private Marker marker; + + + public Cluster(LatLng latLng) { + this.latLng = latLng; + clusterItems = new ArrayList<>(); + } + + public void addClusterItem(ClusterItem clusterItem) { + clusterItems.add(clusterItem); + } + + public int getClusterCount() { + return clusterItems.size(); + } + + public LatLng getCenterLatLng() { + return latLng; + } + + public void setMarker(Marker marker) { + this.marker = marker; + } + + public Marker getMarker() { + return marker; + } + + public List getClusterItems() { + return clusterItems; + } +} diff --git a/app/src/main/java/com/casic/app/smartwell/widgets/cluster/ClusterItem.java b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/ClusterItem.java new file mode 100644 index 0000000..f5d9a9d --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/ClusterItem.java @@ -0,0 +1,10 @@ +package com.casic.app.smartwell.widgets.cluster; + +import com.amap.api.maps.model.LatLng; + +public interface ClusterItem { + /** + * 返回聚合元素的地理位置 + */ + LatLng getPosition(); +} diff --git a/app/src/main/java/com/casic/app/smartwell/widgets/cluster/ClusterOnClickListener.java b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/ClusterOnClickListener.java new file mode 100644 index 0000000..0efa1f1 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/ClusterOnClickListener.java @@ -0,0 +1,15 @@ +package com.casic.app.smartwell.widgets.cluster; + +import com.amap.api.maps.model.Marker; + +import java.util.List; + +public interface ClusterOnClickListener { + /** + * 点击聚合点的回调处理函数 + * + * @param marker 点击的聚合点 + * @param items 聚合点所包含的元素 + */ + void onMarkerClicked(Marker marker, List items); +} 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 new file mode 100644 index 0000000..40df562 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/ClusterOverlay.java @@ -0,0 +1,349 @@ +package com.casic.app.smartwell.widgets.cluster; + +import android.content.Context; +import android.graphics.Color; +import android.os.Handler; +import android.os.HandlerThread; +import android.os.Looper; +import android.os.Message; +import android.util.TypedValue; +import android.view.Gravity; +import android.widget.TextView; + +import com.amap.api.maps.AMap; +import com.amap.api.maps.AMapUtils; +import com.amap.api.maps.model.BitmapDescriptor; +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.LatLngBounds; +import com.amap.api.maps.model.Marker; +import com.amap.api.maps.model.MarkerOptions; +import com.amap.api.maps.model.animation.AlphaAnimation; +import com.casic.app.smartwell.R; + +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.CopyOnWriteArrayList; + +/** + * 整体设计采用了两个线程,一个线程用于计算组织聚合数据,一个线程负责处理Marker相关操作 + */ +public class ClusterOverlay implements AMap.OnCameraChangeListener, AMap.OnMarkerClickListener { + private final AMap amap; + private final Context context; + private final List clusterItems; + private final List clusters; + private final int clusterSize; + private ClusterOnClickListener clusterClickListener; + private ClusterRender clusterRender; + private final CopyOnWriteArrayList addMarkers = new CopyOnWriteArrayList<>(); + private double clusterDistance; + private final HandlerThread markerHandlerThread = new HandlerThread("addMarker"); + private final HandlerThread signClusterThread = new HandlerThread("calculateCluster"); + private Handler markerHandler; + private Handler signClusterHandler; + private float pxInMeters; + private boolean isCanceled = false; + private final AlphaAnimation addAnimation = new AlphaAnimation(0, 1); + + /** + * 构造函数,批量添加聚合元素时,调用此构造函数 + */ + public ClusterOverlay(Context context, AMap amap, int clusterSize) { + this(context, amap, null, clusterSize); + } + + /** + * 构造函数,批量添加聚合元素时,调用此构造函数 + */ + public ClusterOverlay(Context context, AMap amap, List clusterItems, int clusterSize) { + if (clusterItems != null) { + this.clusterItems = clusterItems; + } else { + this.clusterItems = new ArrayList<>(); + } + this.context = context; + this.clusters = new ArrayList<>(); + this.amap = amap; + this.clusterSize = clusterSize; + this.pxInMeters = amap.getScalePerPixel(); + this.clusterDistance = pxInMeters * clusterSize; + amap.setOnCameraChangeListener(this); + amap.setOnMarkerClickListener(this); + initThreadHandler(); + assignClusters(); + } + + /** + * 设置聚合点的点击事件 + */ + public void setOnClusterClickListener(ClusterOnClickListener clusterClickListener) { + this.clusterClickListener = clusterClickListener; + } + + /** + * 添加一个聚合点 + */ + public void addClusterItem(ClusterItem item) { + Message message = Message.obtain(); + message.what = SignClusterHandler.CALCULATE_SINGLE_CLUSTER; + message.obj = item; + signClusterHandler.sendMessage(message); + } + + /** + * 设置聚合元素的渲染样式,不设置则默认为气泡加数字形式进行渲染 + */ + public void setClusterRender(ClusterRender render) { + this.clusterRender = render; + } + + public void onDestroy() { + isCanceled = true; + signClusterHandler.removeCallbacksAndMessages(null); + markerHandler.removeCallbacksAndMessages(null); + signClusterThread.quit(); + markerHandlerThread.quit(); + for (Marker marker : addMarkers) { + marker.remove(); + } + addMarkers.clear(); + } + + //初始化Handler + private void initThreadHandler() { + markerHandlerThread.start(); + signClusterThread.start(); + markerHandler = new MarkerHandler(markerHandlerThread.getLooper()); + signClusterHandler = new SignClusterHandler(signClusterThread.getLooper()); + } + + @Override + public void onCameraChange(CameraPosition arg0) { + + } + + @Override + public void onCameraChangeFinish(CameraPosition arg0) { + pxInMeters = amap.getScalePerPixel(); + clusterDistance = pxInMeters * clusterSize; + assignClusters(); + } + + @Override + public boolean onMarkerClick(Marker marker) { + if (clusterClickListener == null) { + return true; + } + Cluster cluster = (Cluster) marker.getObject(); + if (cluster != null) { + clusterClickListener.onMarkerClicked(marker, cluster.getClusterItems()); + return true; + } + return false; + } + + /** + * 将聚合元素添加至地图上 + */ + private void addClusterToMap(List clusters) { + ArrayList removeMarkers = new ArrayList<>(addMarkers); + AlphaAnimation alphaAnimation = new AlphaAnimation(1, 0); + RemoveAnimationListener removeAnimationListener = new RemoveAnimationListener(removeMarkers); + for (Marker marker : removeMarkers) { + marker.setAnimation(alphaAnimation); + marker.setAnimationListener(removeAnimationListener); + marker.startAnimation(); + } + + for (Cluster cluster : clusters) { + addSingleClusterToMap(cluster); + } + } + + /** + * 将单个聚合元素添加至地图显示 + */ + private void addSingleClusterToMap(Cluster cluster) { + LatLng latlng = cluster.getCenterLatLng(); + MarkerOptions markerOptions = new MarkerOptions(); + markerOptions.icon(getBitmapDes(cluster.getClusterCount())).position(latlng); + Marker marker = amap.addMarker(markerOptions); + marker.setAnimation(addAnimation); + marker.setObject(cluster); + + marker.startAnimation(); + cluster.setMarker(marker); + addMarkers.add(marker); + } + + private void calculateClusters() { + isCanceled = false; + clusters.clear(); + LatLngBounds visibleBounds = amap.getProjection().getVisibleRegion().latLngBounds; + for (ClusterItem clusterItem : clusterItems) { + if (isCanceled) { + return; + } + LatLng latlng = clusterItem.getPosition(); + if (visibleBounds.contains(latlng)) { + Cluster cluster = getCluster(latlng, clusters); + if (cluster == null) { + cluster = new Cluster(latlng); + clusters.add(cluster); + } + cluster.addClusterItem(clusterItem); + } + } + + //复制一份数据,规避同步 + List tempClusters = new ArrayList<>(clusters); + Message message = Message.obtain(); + message.what = MarkerHandler.ADD_CLUSTER_LIST; + message.obj = tempClusters; + if (isCanceled) { + return; + } + markerHandler.sendMessage(message); + } + + /** + * 对点进行聚合 + */ + private void assignClusters() { + isCanceled = true; + signClusterHandler.removeMessages(SignClusterHandler.CALCULATE_CLUSTER); + signClusterHandler.sendEmptyMessage(SignClusterHandler.CALCULATE_CLUSTER); + } + + /** + * 在已有的聚合基础上,对添加的单个元素进行聚合 + */ + private void calculateSingleCluster(ClusterItem clusterItem) { + LatLngBounds visibleBounds = amap.getProjection().getVisibleRegion().latLngBounds; + LatLng latlng = clusterItem.getPosition(); + if (!visibleBounds.contains(latlng)) { + return; + } + Cluster cluster = getCluster(latlng, clusters); + if (cluster != null) { + cluster.addClusterItem(clusterItem); + Message message = Message.obtain(); + message.what = MarkerHandler.UPDATE_SINGLE_CLUSTER; + + message.obj = cluster; + markerHandler.removeMessages(MarkerHandler.UPDATE_SINGLE_CLUSTER); + markerHandler.sendMessageDelayed(message, 5); + } else { + cluster = new Cluster(latlng); + clusters.add(cluster); + cluster.addClusterItem(clusterItem); + Message message = Message.obtain(); + message.what = MarkerHandler.ADD_SINGLE_CLUSTER; + message.obj = cluster; + markerHandler.sendMessage(message); + } + } + + /** + * 根据一个点获取是否可以依附的聚合点,没有则返回null + */ + private Cluster getCluster(LatLng latLng, List clusters) { + for (Cluster cluster : clusters) { + LatLng clusterCenterPoint = cluster.getCenterLatLng(); + double distance = AMapUtils.calculateLineDistance(latLng, clusterCenterPoint); + if (distance < clusterDistance && amap.getCameraPosition().zoom < 19) { + return cluster; + } + } + return null; + } + + + /** + * 获取每个聚合点的绘制样式 + */ + private BitmapDescriptor getBitmapDes(int num) { + TextView textView = new TextView(context); + if (num > 1) { + String tile = String.valueOf(num); + textView.setText(tile); + } + textView.setGravity(Gravity.CENTER); + textView.setTextColor(Color.BLACK); + textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 15); + if (clusterRender != null && clusterRender.getDrawableByCount(num) != null) { + textView.setBackgroundDrawable(clusterRender.getDrawableByCount(num)); + } else { + textView.setBackgroundResource(R.mipmap.well_location); + } + return BitmapDescriptorFactory.fromView(textView); + } + + /** + * 更新已加入地图聚合点的样式 + */ + private void updateCluster(Cluster cluster) { + Marker marker = cluster.getMarker(); + marker.setIcon(getBitmapDes(cluster.getClusterCount())); + } + + /** + * 处理market添加,更新等操作 + */ + class MarkerHandler extends Handler { + + static final int ADD_CLUSTER_LIST = 0; + + static final int ADD_SINGLE_CLUSTER = 1; + + static final int UPDATE_SINGLE_CLUSTER = 2; + + public MarkerHandler(Looper looper) { + super(looper); + } + + public void handleMessage(Message message) { + switch (message.what) { + case ADD_CLUSTER_LIST: + List clusters = (List) message.obj; + addClusterToMap(clusters); + break; + case ADD_SINGLE_CLUSTER: + Cluster cluster = (Cluster) message.obj; + addSingleClusterToMap(cluster); + break; + case UPDATE_SINGLE_CLUSTER: + Cluster updateCluster = (Cluster) message.obj; + updateCluster(updateCluster); + break; + } + } + } + + /** + * 处理聚合点算法线程 + */ + class SignClusterHandler extends Handler { + static final int CALCULATE_CLUSTER = 0; + static final int CALCULATE_SINGLE_CLUSTER = 1; + + public SignClusterHandler(Looper looper) { + super(looper); + } + + public void handleMessage(Message message) { + switch (message.what) { + case CALCULATE_CLUSTER: + calculateClusters(); + break; + case CALCULATE_SINGLE_CLUSTER: + ClusterItem item = (ClusterItem) message.obj; + clusterItems.add(item); + calculateSingleCluster(item); + break; + } + } + } +} diff --git a/app/src/main/java/com/casic/app/smartwell/extensions/Int.kt b/app/src/main/java/com/casic/app/smartwell/extensions/Int.kt index de0617b..a0a5e33 100644 --- a/app/src/main/java/com/casic/app/smartwell/extensions/Int.kt +++ b/app/src/main/java/com/casic/app/smartwell/extensions/Int.kt @@ -1,9 +1,24 @@ package com.casic.app.smartwell.extensions +import android.graphics.Bitmap +import android.graphics.Canvas +import android.graphics.Paint +import android.graphics.RectF + fun Int.toLevel(): String { return if (this == 0) { "" } else { this.toString() } +} + +fun Int.drawCircle(color: Int): Bitmap? { + val bitmap = Bitmap.createBitmap(this * 2, this * 2, Bitmap.Config.ARGB_8888) + val canvas = Canvas(bitmap) + val paint = Paint() + val rectF = RectF(0f, 0f, (this * 2).toFloat(), (this * 2).toFloat()) + paint.color = color + canvas.drawArc(rectF, 0f, 360f, true, paint) + return bitmap } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt index 6b6ca3e..5e45534 100644 --- a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt +++ b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt @@ -2,17 +2,13 @@ import android.content.Context import com.casic.app.smartwell.callback.OnImageCompressListener -import com.casic.app.smartwell.model.ErrorMessageModel import com.casic.app.smartwell.utils.LocaleConstant -import com.google.gson.Gson -import com.google.gson.reflect.TypeToken +import com.google.gson.JsonParser import com.pengxh.kt.lite.extensions.createCompressImageDir import com.pengxh.kt.lite.utils.SaveKeyValues -import org.json.JSONObject import top.zibin.luban.Luban import top.zibin.luban.OnCompressListener import java.io.File -import java.util.Locale /** * String扩展方法 @@ -74,18 +70,22 @@ } } -fun String.separateResponseCode(): Int { +fun String.getResponseCode(): Int { if (this.isBlank()) { return 404 } - return JSONObject(this).getInt("code") + val element = JsonParser.parseString(this) + val jsonObject = element.asJsonObject + return jsonObject.get("code").asInt } -fun String.toErrorMessage(): String { - val errorModel = Gson().fromJson( - this, object : TypeToken() {}.type - ) - return errorModel.message.toString() +fun String.getResponseMessage(): String { + if (this.isBlank()) { + return "" + } + val element = JsonParser.parseString(this) + val jsonObject = element.asJsonObject + return jsonObject.get("message").asString } fun String.compressImage(context: Context, listener: OnImageCompressListener) { @@ -93,9 +93,6 @@ .load(this) .ignoreBy(100) .setTargetDir(context.createCompressImageDir().toString()) - .filter { - !(it.isBlank() || it.lowercase(Locale.getDefault()).endsWith(".gif")) - } .setCompressListener(object : OnCompressListener { override fun onStart() { 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 96df110..cd25fca 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 @@ -1,26 +1,25 @@ package com.casic.app.smartwell.fragment -import android.graphics.Point +import android.graphics.Color +import android.graphics.drawable.BitmapDrawable +import android.graphics.drawable.Drawable 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 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.LatLngBounds import com.amap.api.maps.model.Marker -import com.amap.api.maps.model.MarkerOptions import com.casic.app.smartwell.R import com.casic.app.smartwell.databinding.FragmentHomeBinding +import com.casic.app.smartwell.extensions.drawCircle import com.casic.app.smartwell.extensions.initImmersionBar -import com.casic.app.smartwell.extensions.valueToType import com.casic.app.smartwell.model.MapWellListModel import com.casic.app.smartwell.utils.LocaleConstant import com.casic.app.smartwell.utils.RouteOnMap @@ -31,9 +30,16 @@ import com.casic.app.smartwell.view.WellOperationActivity import com.casic.app.smartwell.vm.OrderViewModel import com.casic.app.smartwell.vm.WellViewModel +import com.casic.app.smartwell.widgets.MapWellPopup +import com.casic.app.smartwell.widgets.cluster.ClusterItem +import com.casic.app.smartwell.widgets.cluster.ClusterOnClickListener +import com.casic.app.smartwell.widgets.cluster.ClusterOverlay +import com.casic.app.smartwell.widgets.cluster.RegionItem 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.convertDrawable +import com.pengxh.kt.lite.extensions.dp2px import com.pengxh.kt.lite.extensions.navigatePageTo import com.pengxh.kt.lite.extensions.show import com.pengxh.kt.lite.utils.LoadingDialogHub @@ -43,35 +49,23 @@ /** * 地图点位带聚合效果 * */ -class HomePageHaveClusterFragment : KotlinBaseFragment(), AMap.OnMapLoadedListener, - AMap.OnCameraChangeListener, AMap.OnMarkerClickListener, AMap.InfoWindowAdapter, - AMap.OnInfoWindowClickListener { +class HomePageHaveClusterFragment : KotlinBaseFragment(), + AMap.OnCameraChangeListener { private val kTag = "HaveClusterFragment" private val easyPopupWindow by lazy { EasyPopupWindow(requireContext()) } - private lateinit var wellViewModel: WellViewModel - private lateinit var orderViewModel: OrderViewModel - private lateinit var aMap: AMap - - /** - * 所有的marker - */ - private var allMarkerOptions: MutableList = ArrayList() - - /** - * 视野内的marker - */ - private var markerOptionsInView: MutableList = ArrayList() - - /** - * 自定义Marker弹出框 - * */ - private lateinit var v: View + private val regionRadius by lazy { LocaleConstant.RADIUS_SIZE.dp2px(requireContext()) } + private val infoPopup by lazy { MapWellPopup(requireContext()) } /** * 所有窨井列表信息集合 * */ - private var wellModels: MutableList = ArrayList() + private val wellModels = ArrayList() + private val backDrawables = HashMap() + private lateinit var wellViewModel: WellViewModel + private lateinit var orderViewModel: OrderViewModel + private lateinit var aMap: AMap + private var clusterOverlay: ClusterOverlay? = null override fun initViewBinding( inflater: LayoutInflater, @@ -106,6 +100,9 @@ } }) + //地图初始化 + initMap(savedInstanceState) + //初始化vm wellViewModel = ViewModelProvider(this)[WellViewModel::class.java] orderViewModel = ViewModelProvider(this)[OrderViewModel::class.java] @@ -120,25 +117,19 @@ val latitudeList: MutableList = ArrayList() val longitudeList: MutableList = ArrayList() it.data?.forEach { well -> - val lat = well.latGaode.toString() - val lng = well.lngGaode.toString() + val lat = well.latGaode + val lng = well.lngGaode if (lat.isNotBlank() && lng.isNotBlank()) { //返回true代表当前位置在大陆、港澳地区,反之不在 val latitude = lat.toDouble() val longitude = lng.toDouble() if (CoordinateConverter.isAMapDataAvailable(latitude, longitude)) { - //缓存所有设备详情,点击Marker时候需要 + //缓存所有井 wellModels.add(well) + //分别缓存经、纬度 latitudeList.add(latitude) longitudeList.add(longitude) - //将所有设备信息转化缓存为Marker点 - allMarkerOptions.add( - MarkerOptions() - .position(LatLng(latitude, longitude)) - .title(well.wellTypeName) - .snippet(well.wellName) - ) } } } @@ -160,12 +151,12 @@ val cameraPosition = CameraPosition(centerLatLng, 16f, 0f, 0f) val cameraUpdate = CameraUpdateFactory.newCameraPosition(cameraPosition) aMap.animateCamera(cameraUpdate, 1500, null) + + //显示点数据 + displayWellOnMap() } } - //地图初始化 - initMap(savedInstanceState) - //获取窨井监控数据 wellViewModel.countResultModel.observe(this) { binding.deployedWellView.text = it["bfWell"] @@ -220,17 +211,10 @@ uiSettings.isCompassEnabled = true uiSettings.zoomPosition = AMapOptions.ZOOM_POSITION_RIGHT_CENTER uiSettings.isTiltGesturesEnabled = false//不许地图随手势倾斜角度 + uiSettings.isRotateGesturesEnabled = false//不允许地图随手势改变方位 - // 地图加载成功监听 - aMap.addOnMapLoadedListener(this) // 地图缩放监听 aMap.addOnCameraChangeListener(this) - // marker 点击事件监听 - aMap.addOnMarkerClickListener(this) - // 点击marker弹出自定义popup - aMap.setInfoWindowAdapter(this) - //信息窗点击事件 - aMap.addOnInfoWindowClickListener(this) } override fun initEvent() { @@ -259,9 +243,111 @@ } - override fun onMapLoaded() { - //地图加载成功之后显示聚合点数据 - initClustersMarkers() + private fun displayWellOnMap() { + clusterOverlay?.onDestroy() + val clusterItems = ArrayList() + + wellModels.forEach { + val latitude = it.latGaode.toDouble() + val longitude = it.lngGaode.toDouble() + + val latLng = LatLng(latitude, longitude, false) + val regionItem = RegionItem(latLng, it) + clusterItems.add(regionItem) + } + + clusterOverlay = ClusterOverlay(requireContext(), aMap, clusterItems, regionRadius) + clusterOverlay?.setClusterRender { clusterNum -> + //聚合圆半径 + val radius = 100.dp2px(requireContext()) + if (clusterNum == 0) { + var bitmapDrawable = backDrawables[0] + if (bitmapDrawable == null) { + bitmapDrawable = BitmapDrawable( + null, radius.drawCircle(Color.argb(159, 100, 149, 237)) + ) + backDrawables[0] = bitmapDrawable + } + bitmapDrawable + } + if (clusterNum == 1) { + var bitmapDrawable = backDrawables[1] + if (bitmapDrawable == null) { + bitmapDrawable = R.mipmap.well_location.convertDrawable(requireContext())!! + backDrawables[1] = bitmapDrawable + } + bitmapDrawable + } else if (clusterNum < 5) { + var bitmapDrawable = backDrawables[2] + if (bitmapDrawable == null) { + bitmapDrawable = BitmapDrawable( + null, radius.drawCircle(Color.argb(159, 100, 149, 237)) + ) + backDrawables[2] = bitmapDrawable + } + bitmapDrawable + } else if (clusterNum < 10) { + var bitmapDrawable = backDrawables[3] + if (bitmapDrawable == null) { + bitmapDrawable = BitmapDrawable( + null, radius.drawCircle(Color.argb(199, 30, 144, 255)) + ) + backDrawables[3] = bitmapDrawable + } + bitmapDrawable + } else { + var bitmapDrawable = backDrawables[4] + if (bitmapDrawable == null) { + bitmapDrawable = BitmapDrawable( + null, radius.drawCircle(Color.argb(235, 65, 105, 225)) + ) + backDrawables[4] = bitmapDrawable + } + bitmapDrawable + } + } + + clusterOverlay?.setOnClusterClickListener(object : ClusterOnClickListener { + override fun onMarkerClicked(marker: Marker?, items: List) { + if (items.size > 1) { + "请缩放地图比例在查看数据".show(requireContext()) + return + } + + var item: RegionItem? = null + val builder = LatLngBounds.Builder() + for (clusterItem in items) { + builder.include(clusterItem.position) + item = clusterItem as RegionItem + } + + item?.apply { + showWellPopup(well) + } + } + }) + } + + private fun showWellPopup(well: MapWellListModel.DataModel) { + infoPopup.set(well, object : MapWellPopup.OnPopupWindowClickListener { + override fun onPopupClicked(lat: Double, lng: Double) { + AlertControlDialog.Builder().setContext(requireContext()).setTitle("操作提示") + .setMessage("确定要前往吗").setNegativeButton("取消").setPositiveButton("确定") + .setOnDialogButtonClickListener(object : + AlertControlDialog.OnDialogButtonClickListener { + override fun onConfirmClick() { + RouteOnMap.startNavigation( + requireContext(), "", LatLng(lat, lng) + ) + } + + override fun onCancelClick() { + + } + }).build().show() + } + }) + infoPopup.showAsDropDown(binding.rightOptionView) } override fun onCameraChange(p0: CameraPosition?) { @@ -282,103 +368,10 @@ } } - //获取视野内的marker 根据聚合算法合成自定义的marker 显示视野内的marker override fun onCameraChangeFinish(p0: CameraPosition?) { //地图缩放之后显示聚合点数据 LoadingDialogHub.dismiss() httpCountDownTimer.cancel() - initClustersMarkers() - } - - private fun initClustersMarkers() { - 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 { - v = LayoutInflater.from(requireContext()).inflate(R.layout.popup_map_info, null) - - //显示闸井信息 - marker?.showInfoWindow() - return true - } - - override fun getInfoWindow(marker: Marker?): View { - //反射得到popup里面的控件对象 - val wellNameView = v.findViewById(R.id.wellNameView) - val wellCodeView = v.findViewById(R.id.wellCodeView) - val wellTypeView = v.findViewById(R.id.wellTypeView) - val wellStateView = v.findViewById(R.id.wellStateView) - val deepView = v.findViewById(R.id.deepView) - val locationView = v.findViewById(R.id.locationView) - - //绑定数据 - val clickedLatLng = marker?.position!! - wellModels.forEach { well -> - if (clickedLatLng.latitude == well.latGaode!!.toDouble() - && clickedLatLng.longitude == well.lngGaode!!.toDouble() - ) { - wellNameView.text = String.format("点位名称: ${well.wellName}") - wellCodeView.text = String.format("点位编号: ${well.wellCode}") - wellTypeView.text = String.format("点位类型: ${well.wellType.valueToType()}") - val bfztName = if (well.bfzt == "1") { - "已布防" - } else { - "已撤防" - } - wellStateView.text = String.format("布/撤防状态: $bfztName") - deepView.text = String.format("点位深度: ${well.deep}m") - locationView.text = String.format("详细位置: ${well.position}") - } - } - return v - } - - /** - * 此方法不能修改整个 InfoWindow 的背景和边框,无论自定义的样式是什么样,SDK 都会在最外层添加一个默认的边框 - * */ - override fun getInfoContents(p0: Marker?): View? = null - - override fun onInfoWindowClick(p0: Marker?) { - p0?.apply { - AlertControlDialog.Builder() - .setContext(requireContext()) - .setTitle("操作提示") - .setMessage("确定要前往吗") - .setNegativeButton("取消") - .setPositiveButton("确定") - .setOnDialogButtonClickListener(object : - AlertControlDialog.OnDialogButtonClickListener { - override fun onConfirmClick() { - val lat = position.latitude.toString() - val lng = position.longitude.toString() - if (lat.isBlank() || lng.isBlank()) { - "点位经纬度异常,无法开启导航".show(requireContext()) - return - } - RouteOnMap.startNavigation( - requireContext(), snippet, LatLng(lat.toDouble(), lng.toDouble()) - ) - } - - override fun onCancelClick() { - - } - }).build().show() - } } /***以下是地图生命周期管理************************************************************************/ 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 a54d213..bfa7a57 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 @@ -44,8 +44,8 @@ * 地图点位不带聚合效果 * */ class HomePageNoClusterFragment : KotlinBaseFragment(), - AMap.OnMapLoadedListener, AMap.OnCameraChangeListener, AMap.OnMarkerClickListener, - AMap.InfoWindowAdapter, AMap.OnInfoWindowClickListener { + AMap.OnCameraChangeListener, AMap.OnMarkerClickListener, AMap.InfoWindowAdapter, + AMap.OnInfoWindowClickListener { private val kTag = "NoClusterFragment" private val easyPopupWindow by lazy { EasyPopupWindow(requireContext()) } @@ -109,6 +109,9 @@ wellViewModel = ViewModelProvider(this)[WellViewModel::class.java] orderViewModel = ViewModelProvider(this)[OrderViewModel::class.java] + //地图初始化 + initMap(savedInstanceState) + //获取所有窨井数据 httpCountDownTimer.start() LoadingDialogHub.show(requireActivity(), "数据加载中,请稍后...") @@ -157,12 +160,12 @@ val cameraPosition = CameraPosition(centerLatLng, 16f, 0f, 0f) val cameraUpdate = CameraUpdateFactory.newCameraPosition(cameraPosition) aMap.animateCamera(cameraUpdate, 1500, null) + + //显示点数据 + displayWellOnMap() } } - //地图初始化 - initMap(savedInstanceState) - //获取窨井监控数据 wellViewModel.countResultModel.observe(this) { binding.deployedWellView.text = it["bfWell"] @@ -214,9 +217,8 @@ uiSettings.isCompassEnabled = true uiSettings.zoomPosition = AMapOptions.ZOOM_POSITION_RIGHT_CENTER uiSettings.isTiltGesturesEnabled = false//不许地图随手势倾斜角度 + uiSettings.isRotateGesturesEnabled = false//不允许地图随手势改变方位 - // 地图加载成功监听 - aMap.addOnMapLoadedListener(this) // 地图缩放监听 aMap.addOnCameraChangeListener(this) // marker 点击事件监听 @@ -253,11 +255,6 @@ } - override fun onMapLoaded() { - //地图加载成功之后显示聚合点数据 - initClustersMarkers() - } - override fun onCameraChange(p0: CameraPosition?) { } @@ -281,10 +278,9 @@ //地图缩放之后显示聚合点数据 LoadingDialogHub.dismiss() httpCountDownTimer.cancel() - initClustersMarkers() } - private fun initClustersMarkers() { + private fun displayWellOnMap() { val proj = aMap.projection val dm = resources.displayMetrics var screenLocation: Point diff --git a/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.java b/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.java deleted file mode 100644 index d8b18ef..0000000 --- a/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.java +++ /dev/null @@ -1,50 +0,0 @@ -package com.casic.app.smartwell.model; - -public class ErrorMessageModel { - - private int code; - private String data; - private String exceptionClazz; - private String message; - private boolean success; - - public int getCode() { - return code; - } - - public void setCode(int code) { - this.code = code; - } - - public String getData() { - return data; - } - - public void setData(String data) { - this.data = data; - } - - public String getExceptionClazz() { - return exceptionClazz; - } - - public void setExceptionClazz(String exceptionClazz) { - this.exceptionClazz = exceptionClazz; - } - - public String getMessage() { - return message; - } - - public void setMessage(String message) { - this.message = message; - } - - public boolean isSuccess() { - return success; - } - - public void setSuccess(boolean success) { - this.success = success; - } -} \ No newline at end of file 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 new file mode 100644 index 0000000..215ac0c --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/PipelineModel.java @@ -0,0 +1,328 @@ +package com.casic.app.smartwell.model; + +import java.util.List; + +public class PipelineModel { + + private Integer code; + private DataModel data; + private String message; + private Boolean success; + + public Integer getCode() { + return code; + } + + public void setCode(Integer code) { + this.code = code; + } + + public DataModel getData() { + return data; + } + + public void setData(DataModel data) { + this.data = data; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + public Boolean getSuccess() { + return success; + } + + public void setSuccess(Boolean success) { + this.success = success; + } + + public static class DataModel { + private List rows; + private Integer total; + + public List getRows() { + return rows; + } + + public void setRows(List rows) { + this.rows = rows; + } + + public Integer getTotal() { + return total; + } + + public void setTotal(Integer total) { + this.total = total; + } + + 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 getBuryMode() { + return buryMode; + } + + public void setBuryMode(String buryMode) { + this.buryMode = buryMode; + } + + public String getConstructEra() { + return constructEra; + } + + public void setConstructEra(String constructEra) { + this.constructEra = constructEra; + } + + 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; + } + } + } +} 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 06d3d2b..4f38a2c 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 = 100 //相距多少米才聚合,单位:米 + const val RADIUS_SIZE = 80 //相距多少米才聚合,单位:米 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:11308" + // 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 0d5f3fa..991e1db 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 @@ -312,4 +312,14 @@ @Header("token") token: String, @Field("clientid") deviceCode: String ): String + + /** + * 管线位置数据 + */ + @GET("/pipeline/listPage") + suspend fun getPipeline( + @Header("token") token: String, + @Query("limit") limit: Int, + @Query("offset") offset: Int + ): String } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt index 1a0ce22..4050067 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt @@ -294,4 +294,11 @@ suspend fun registerPush(clientId: String): String { return api.registerPush(AuthenticationHelper.token!!, clientId) } + + /** + * 管线位置数据 + */ + suspend fun getPipeline(): String { + return api.getPipeline(AuthenticationHelper.token!!, 2000, 1) + } } \ No newline at end of file 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 9270fa1..4ca5a5e 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.HomePageNoClusterFragment +import com.casic.app.smartwell.fragment.HomePageHaveClusterFragment 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/vm/AlarmViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/AlarmViewModel.kt index 9cff08c..e7acc17 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/AlarmViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/AlarmViewModel.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.AlarmContentModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager import com.google.gson.Gson @@ -16,7 +16,7 @@ fun getAlarmContentType(alarmType: String) = launch({ val response = RetrofitServiceManager.getAlarmContentType(alarmType) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { listModel.value = gson.fromJson( response, object : TypeToken() {}.type diff --git a/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt index 5e5b163..895dedd 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.PublicKeyModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager import com.google.gson.Gson @@ -18,7 +18,7 @@ fun getPublicKey() = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.authenticate() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { keyModel.value = gson.fromJson( response, object : TypeToken() {}.type diff --git a/app/src/main/java/com/casic/app/smartwell/vm/DeviceViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/DeviceViewModel.kt index db5ccf6..899a962 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/DeviceViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/DeviceViewModel.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.DeviceDetailModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager import com.google.gson.Gson @@ -16,7 +16,7 @@ fun getDeviceDetail(deviceCode: String) = launch({ val response = RetrofitServiceManager.getDeviceDetail(deviceCode) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { detailModel.value = gson.fromJson( response, object : TypeToken() {}.type diff --git a/app/src/main/java/com/casic/app/smartwell/vm/LoginViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/LoginViewModel.kt index cd8b8a9..a417398 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/LoginViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/LoginViewModel.kt @@ -2,7 +2,7 @@ import androidx.lifecycle.MutableLiveData import com.casic.app.smartwell.base.BaseApplication -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.CommonResultModel import com.casic.app.smartwell.model.LoginResultModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -21,7 +21,7 @@ fun enter(account: String, secretKey: String) = launch({ val response = RetrofitServiceManager.login(account, secretKey) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success enterResultModel.value = gson.fromJson( @@ -38,7 +38,7 @@ fun out() = launch({ val response = RetrofitServiceManager.loginOut() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { outResultModel.value = gson.fromJson( response, object : TypeToken() {}.type diff --git a/app/src/main/java/com/casic/app/smartwell/vm/OperationViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/OperationViewModel.kt index 8943ed3..37e115f 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/OperationViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/OperationViewModel.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.vm import com.casic.app.smartwell.base.BaseApplication -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager import com.pengxh.kt.lite.base.BaseViewModel import com.pengxh.kt.lite.extensions.launch @@ -16,7 +16,7 @@ fun acceptWorkOrder(id: String) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.acceptWorkOrder(id) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success "接单成功".show(BaseApplication.get()) @@ -35,7 +35,7 @@ loadState.value = LoadState.Loading val response = RetrofitServiceManager.confirmWorkOrder(id, firstState, firstStatePhotos, needHandle) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success "工单确认成功".show(BaseApplication.get()) @@ -50,7 +50,7 @@ fun transferWorkOrder(id: String, userId: String) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.transferWorkOrder(id, userId) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success "转单成功".show(BaseApplication.get()) @@ -65,7 +65,7 @@ fun completeWorkOrder(id: String, handleMessage: String, handlePhotos: String) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.completeWorkOrder(id, handleMessage, handlePhotos) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success "工单处理成功".show(BaseApplication.get()) diff --git a/app/src/main/java/com/casic/app/smartwell/vm/OrderViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/OrderViewModel.kt index 4cb26b7..d2fad86 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/OrderViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/OrderViewModel.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.OrderDetailModel import com.casic.app.smartwell.model.OrderListModel import com.casic.app.smartwell.model.OrderStatusModel @@ -37,7 +37,7 @@ val response = RetrofitServiceManager.getSearchResult( keywords, alarmContent, alarmLevel, jobStatus, deptId, beginTime, endTime, offset ) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success searchResult.value = gson.fromJson( @@ -53,7 +53,7 @@ fun getWorkOrderListByState(jobStatus: String, page: Int) = launch({ val response = RetrofitServiceManager.getWorkOrderList(jobStatus, page) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { orderList.value = gson.fromJson( response, object : TypeToken() {}.type @@ -65,7 +65,7 @@ fun getNotAcceptOderList(page: Int) = launch({ val response = RetrofitServiceManager.getNotAcceptOderList(page) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { orderList.value = gson.fromJson( response, object : TypeToken() {}.type @@ -77,7 +77,7 @@ fun getNotHandleOderList(page: Int) = launch({ val response = RetrofitServiceManager.getNotHandleOderList(page) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { orderList.value = gson.fromJson( response, object : TypeToken() {}.type @@ -89,7 +89,7 @@ fun countWorkOrderByState() = launch({ val response = RetrofitServiceManager.countWorkOrderByState() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { val map = HashMap(4) @@ -107,7 +107,7 @@ fun getOrderStatus() = launch({ val response = RetrofitServiceManager.getOrderStatus() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { orderStatusModel.value = gson.fromJson( response, object : TypeToken() {}.type @@ -120,7 +120,7 @@ fun getWorkOrderDetail(id: String) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.getWorkOrderDetail(id) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success detailModel.value = gson.fromJson( diff --git a/app/src/main/java/com/casic/app/smartwell/vm/PipelineViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/PipelineViewModel.kt new file mode 100644 index 0000000..60c1e2f --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/vm/PipelineViewModel.kt @@ -0,0 +1,28 @@ +package com.casic.app.smartwell.vm + +import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.extensions.getResponseCode +import com.casic.app.smartwell.model.PipelineModel +import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken +import com.pengxh.kt.lite.base.BaseViewModel +import com.pengxh.kt.lite.extensions.launch + +class PipelineViewModel : BaseViewModel() { + + private val gson by lazy { Gson() } + val lineResult = MutableLiveData() + + fun getPipeline() = launch({ + val response = RetrofitServiceManager.getPipeline() + val responseCode = response.getResponseCode() + if (responseCode == 200) { + lineResult.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } + }, { + it.printStackTrace() + }) +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/PushViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/PushViewModel.kt index 9279815..12fd610 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/PushViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/PushViewModel.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.CommonResultModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager import com.google.gson.Gson @@ -16,7 +16,7 @@ fun registerPush(clientId: String) = launch({ val response = RetrofitServiceManager.registerPush(clientId) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { registerResultModel.value = gson.fromJson( response, object : TypeToken() {}.type diff --git a/app/src/main/java/com/casic/app/smartwell/vm/UploadImageViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/UploadImageViewModel.kt index 8d6744e..9707eeb 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/UploadImageViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/UploadImageViewModel.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.CommonResultModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager import com.google.gson.Gson @@ -19,7 +19,7 @@ fun uploadImage(image: File) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.uploadImage(image) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success resultModel.value = gson.fromJson( diff --git a/app/src/main/java/com/casic/app/smartwell/vm/UserViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/UserViewModel.kt index 31a4d4c..070c35a 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/UserViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/UserViewModel.kt @@ -2,7 +2,7 @@ import androidx.lifecycle.MutableLiveData import com.casic.app.smartwell.base.BaseApplication -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.SubordinateModel import com.casic.app.smartwell.model.UserDetailModel import com.casic.app.smartwell.model.VersionResultModel @@ -25,7 +25,7 @@ fun getUserDetail() = launch({ val response = RetrofitServiceManager.getUserDetail() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { val userDetail = gson.fromJson( response, object : TypeToken() {}.type @@ -48,7 +48,7 @@ * */ fun getSubordinate(hasMine: String?, deptId: String?, roleTips: String?) = launch({ val response = RetrofitServiceManager.getSubordinate(hasMine, deptId, roleTips) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { subordinateModel.value = gson.fromJson( response, object : TypeToken() {}.type @@ -61,7 +61,7 @@ fun changePassword(oldPwd: String, newPwd: String) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.changePassword(oldPwd, newPwd) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success "修改成功,请重新登录".show(BaseApplication.get()) @@ -76,7 +76,7 @@ fun updateVersion() = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.updateVersion() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success versionResultModel.value = gson.fromJson( diff --git a/app/src/main/java/com/casic/app/smartwell/vm/WellViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/WellViewModel.kt index 3d41e9b..9e42e36 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/WellViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/WellViewModel.kt @@ -2,8 +2,7 @@ import androidx.lifecycle.MutableLiveData import com.casic.app.smartwell.base.BaseApplication -import com.casic.app.smartwell.extensions.separateResponseCode -import com.casic.app.smartwell.extensions.toErrorMessage +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.AuthorDeptModel import com.casic.app.smartwell.model.CommonResultModel import com.casic.app.smartwell.model.MapWellListModel @@ -32,7 +31,7 @@ fun countWellByState() = launch({ val response = RetrofitServiceManager.countWellByState() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { val map = HashMap(3) @@ -57,7 +56,7 @@ fun getWellType() = launch({ val response = RetrofitServiceManager.getWellType() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { wellTypeModel.value = gson.fromJson( response, object : TypeToken() {}.type @@ -70,7 +69,7 @@ fun getWellDetail(id: String) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.getWellDetail(id) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success wellDetailModel.value = gson.fromJson( @@ -87,7 +86,7 @@ fun getOperationResult(id: String, state: String) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.getOperationResult(id, state) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success "操作成功".show(BaseApplication.get()) @@ -105,7 +104,7 @@ fun getMonitorResult(id: String) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.getMonitorResult(id) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success monitorModel.value = gson.fromJson( @@ -125,7 +124,7 @@ val response = RetrofitServiceManager.getWellListByPage( keywords, wellType, deptid, bfzt, page ) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { listModel.value = gson.fromJson( response, object : TypeToken() {}.type @@ -137,13 +136,11 @@ fun getWellList() = launch({ val response = RetrofitServiceManager.getWellList() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { totalWellModel.value = gson.fromJson( response, object : TypeToken() {}.type ) - } else { - response.toErrorMessage().show(BaseApplication.get()) } }, { it.printStackTrace() diff --git a/app/src/main/java/com/casic/app/smartwell/widgets/GaoDeClusterMarkerView.kt b/app/src/main/java/com/casic/app/smartwell/widgets/GaoDeClusterMarkerView.kt deleted file mode 100644 index 1f375df..0000000 --- a/app/src/main/java/com/casic/app/smartwell/widgets/GaoDeClusterMarkerView.kt +++ /dev/null @@ -1,100 +0,0 @@ -package com.casic.app.smartwell.widgets - -import android.content.Context -import android.graphics.Bitmap -import android.graphics.Point -import android.view.Gravity -import android.view.LayoutInflater -import android.view.View -import android.widget.TextView -import com.amap.api.maps.Projection -import com.amap.api.maps.model.BitmapDescriptorFactory -import com.amap.api.maps.model.LatLng -import com.amap.api.maps.model.LatLngBounds -import com.amap.api.maps.model.MarkerOptions -import com.casic.app.smartwell.R -import com.pengxh.kt.lite.extensions.toBitmap -import java.util.* - -class GaoDeClusterMarkerView( - private val context: Context, firstMarkers: MarkerOptions, projection: Projection, gridSize: Int -) { - //当前可观区域里的 聚合过之后的集合 - private val includeMarkers: ArrayList - - // 创建区域 - val bounds: LatLngBounds - var options: MarkerOptions = MarkerOptions() - - init { - val screenLocation = projection.toScreenLocation(firstMarkers.position) - //范围类 - val southwestPoint = Point(screenLocation.x - gridSize, screenLocation.y + gridSize) - //范围类 - val northeastPoint = Point(screenLocation.x + gridSize, screenLocation.y - gridSize) - bounds = LatLngBounds( - projection.fromScreenLocation(southwestPoint), - projection.fromScreenLocation(northeastPoint) - ) - //设置初始化marker属性 - options.anchor(0.5f, 1.3f) - .title(firstMarkers.title) - .position(firstMarkers.position) - .icon(firstMarkers.icon) - .snippet(firstMarkers.snippet) - .draggable(false) - includeMarkers = ArrayList() - includeMarkers.add(firstMarkers) - } - - /** - * 添加marker - */ - fun addMarker(markerOptions: MarkerOptions) { - includeMarkers.add(markerOptions) // 添加到列表中 - } - - /** - * 设置聚合点的中心位置以及图标 - */ - fun setPositionAndIcon() { - val size = includeMarkers.size - var lat = 0.0 - var lng = 0.0 - // 一个的时候 - if (size == 1) { //设置marker单个属性 - // 设置marker位置 - options.position( - LatLng( - includeMarkers[0].position.latitude, includeMarkers[0].position.longitude - ) - ) - } else { // 聚合的时候 - //设置marker聚合属性 - for (op in includeMarkers) { - lat += op.position.latitude - lng += op.position.longitude - } - // 设置marker的位置为中心位置为聚集点的平均位置 - options.position(LatLng(lat / size, lng / size)) - } - options.icon(BitmapDescriptorFactory.fromBitmap(getBitmap(size))) - } - - /** - * marker视图 - */ - private fun getBitmap(num: Int): Bitmap? { - val view = LayoutInflater.from(context).inflate(R.layout.marker_gaode, null) - val wellCountView = view.findViewById(R.id.wellCountView) - return if (num > 1) { - wellCountView.visibility = View.VISIBLE - wellCountView.text = String.format("${num}个") - wellCountView.gravity = Gravity.CENTER - view.toBitmap() - } else { - wellCountView.visibility = View.GONE - BitmapDescriptorFactory.fromResource(R.mipmap.well_location).bitmap - } - } -} \ No newline at end of file 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 new file mode 100644 index 0000000..ec455dd --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/widgets/MapWellPopup.kt @@ -0,0 +1,58 @@ +package com.casic.app.smartwell.widgets + +import android.content.Context +import android.view.LayoutInflater +import android.view.ViewGroup +import android.widget.LinearLayout +import android.widget.PopupWindow +import android.widget.TextView +import com.casic.app.smartwell.R +import com.casic.app.smartwell.extensions.valueToType +import com.casic.app.smartwell.model.MapWellListModel + +class MapWellPopup constructor(context: Context) : PopupWindow() { + + init { + width = ViewGroup.LayoutParams.MATCH_PARENT + height = ViewGroup.LayoutParams.WRAP_CONTENT + isOutsideTouchable = true + isFocusable = true + animationStyle = R.style.MapPopupAnimation + setBackgroundDrawable(null) + contentView = LayoutInflater.from(context).inflate( + R.layout.popup_map_info, null, false + ) + } + + fun set(well: MapWellListModel.DataModel, windowClickListener: OnPopupWindowClickListener) { + //反射得到popup里面的控件对象 + val rootView = contentView.findViewById(R.id.rootView) + val wellNameView = contentView.findViewById(R.id.wellNameView) + val wellCodeView = contentView.findViewById(R.id.wellCodeView) + val wellTypeView = contentView.findViewById(R.id.wellTypeView) + val wellStateView = contentView.findViewById(R.id.wellStateView) + val deepView = contentView.findViewById(R.id.deepView) + val locationView = contentView.findViewById(R.id.locationView) + + //绑定数据 + wellNameView.text = String.format("点位名称: ${well.wellName}") + wellCodeView.text = String.format("点位编号: ${well.wellCode}") + wellTypeView.text = String.format("点位类型: ${well.wellType.valueToType()}") + val bfztName = if (well.bfzt == "1") { + "已布防" + } else { + "已撤防" + } + wellStateView.text = String.format("布/撤防状态: $bfztName") + deepView.text = String.format("点位深度: ${well.deep}m") + locationView.text = String.format("详细位置: ${well.position}") + + rootView.setOnClickListener { + windowClickListener.onPopupClicked(well.latGaode.toDouble(), well.lngGaode.toDouble()) + } + } + + interface OnPopupWindowClickListener { + fun onPopupClicked(lat: Double, lng: Double) + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/widgets/cluster/Cluster.java b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/Cluster.java new file mode 100644 index 0000000..9455ccd --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/Cluster.java @@ -0,0 +1,43 @@ +package com.casic.app.smartwell.widgets.cluster; + +import com.amap.api.maps.model.LatLng; +import com.amap.api.maps.model.Marker; + +import java.util.ArrayList; +import java.util.List; + +public class Cluster { + private final LatLng latLng; + private final List clusterItems; + private Marker marker; + + + public Cluster(LatLng latLng) { + this.latLng = latLng; + clusterItems = new ArrayList<>(); + } + + public void addClusterItem(ClusterItem clusterItem) { + clusterItems.add(clusterItem); + } + + public int getClusterCount() { + return clusterItems.size(); + } + + public LatLng getCenterLatLng() { + return latLng; + } + + public void setMarker(Marker marker) { + this.marker = marker; + } + + public Marker getMarker() { + return marker; + } + + public List getClusterItems() { + return clusterItems; + } +} diff --git a/app/src/main/java/com/casic/app/smartwell/widgets/cluster/ClusterItem.java b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/ClusterItem.java new file mode 100644 index 0000000..f5d9a9d --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/ClusterItem.java @@ -0,0 +1,10 @@ +package com.casic.app.smartwell.widgets.cluster; + +import com.amap.api.maps.model.LatLng; + +public interface ClusterItem { + /** + * 返回聚合元素的地理位置 + */ + LatLng getPosition(); +} diff --git a/app/src/main/java/com/casic/app/smartwell/widgets/cluster/ClusterOnClickListener.java b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/ClusterOnClickListener.java new file mode 100644 index 0000000..0efa1f1 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/ClusterOnClickListener.java @@ -0,0 +1,15 @@ +package com.casic.app.smartwell.widgets.cluster; + +import com.amap.api.maps.model.Marker; + +import java.util.List; + +public interface ClusterOnClickListener { + /** + * 点击聚合点的回调处理函数 + * + * @param marker 点击的聚合点 + * @param items 聚合点所包含的元素 + */ + void onMarkerClicked(Marker marker, List items); +} 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 new file mode 100644 index 0000000..40df562 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/ClusterOverlay.java @@ -0,0 +1,349 @@ +package com.casic.app.smartwell.widgets.cluster; + +import android.content.Context; +import android.graphics.Color; +import android.os.Handler; +import android.os.HandlerThread; +import android.os.Looper; +import android.os.Message; +import android.util.TypedValue; +import android.view.Gravity; +import android.widget.TextView; + +import com.amap.api.maps.AMap; +import com.amap.api.maps.AMapUtils; +import com.amap.api.maps.model.BitmapDescriptor; +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.LatLngBounds; +import com.amap.api.maps.model.Marker; +import com.amap.api.maps.model.MarkerOptions; +import com.amap.api.maps.model.animation.AlphaAnimation; +import com.casic.app.smartwell.R; + +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.CopyOnWriteArrayList; + +/** + * 整体设计采用了两个线程,一个线程用于计算组织聚合数据,一个线程负责处理Marker相关操作 + */ +public class ClusterOverlay implements AMap.OnCameraChangeListener, AMap.OnMarkerClickListener { + private final AMap amap; + private final Context context; + private final List clusterItems; + private final List clusters; + private final int clusterSize; + private ClusterOnClickListener clusterClickListener; + private ClusterRender clusterRender; + private final CopyOnWriteArrayList addMarkers = new CopyOnWriteArrayList<>(); + private double clusterDistance; + private final HandlerThread markerHandlerThread = new HandlerThread("addMarker"); + private final HandlerThread signClusterThread = new HandlerThread("calculateCluster"); + private Handler markerHandler; + private Handler signClusterHandler; + private float pxInMeters; + private boolean isCanceled = false; + private final AlphaAnimation addAnimation = new AlphaAnimation(0, 1); + + /** + * 构造函数,批量添加聚合元素时,调用此构造函数 + */ + public ClusterOverlay(Context context, AMap amap, int clusterSize) { + this(context, amap, null, clusterSize); + } + + /** + * 构造函数,批量添加聚合元素时,调用此构造函数 + */ + public ClusterOverlay(Context context, AMap amap, List clusterItems, int clusterSize) { + if (clusterItems != null) { + this.clusterItems = clusterItems; + } else { + this.clusterItems = new ArrayList<>(); + } + this.context = context; + this.clusters = new ArrayList<>(); + this.amap = amap; + this.clusterSize = clusterSize; + this.pxInMeters = amap.getScalePerPixel(); + this.clusterDistance = pxInMeters * clusterSize; + amap.setOnCameraChangeListener(this); + amap.setOnMarkerClickListener(this); + initThreadHandler(); + assignClusters(); + } + + /** + * 设置聚合点的点击事件 + */ + public void setOnClusterClickListener(ClusterOnClickListener clusterClickListener) { + this.clusterClickListener = clusterClickListener; + } + + /** + * 添加一个聚合点 + */ + public void addClusterItem(ClusterItem item) { + Message message = Message.obtain(); + message.what = SignClusterHandler.CALCULATE_SINGLE_CLUSTER; + message.obj = item; + signClusterHandler.sendMessage(message); + } + + /** + * 设置聚合元素的渲染样式,不设置则默认为气泡加数字形式进行渲染 + */ + public void setClusterRender(ClusterRender render) { + this.clusterRender = render; + } + + public void onDestroy() { + isCanceled = true; + signClusterHandler.removeCallbacksAndMessages(null); + markerHandler.removeCallbacksAndMessages(null); + signClusterThread.quit(); + markerHandlerThread.quit(); + for (Marker marker : addMarkers) { + marker.remove(); + } + addMarkers.clear(); + } + + //初始化Handler + private void initThreadHandler() { + markerHandlerThread.start(); + signClusterThread.start(); + markerHandler = new MarkerHandler(markerHandlerThread.getLooper()); + signClusterHandler = new SignClusterHandler(signClusterThread.getLooper()); + } + + @Override + public void onCameraChange(CameraPosition arg0) { + + } + + @Override + public void onCameraChangeFinish(CameraPosition arg0) { + pxInMeters = amap.getScalePerPixel(); + clusterDistance = pxInMeters * clusterSize; + assignClusters(); + } + + @Override + public boolean onMarkerClick(Marker marker) { + if (clusterClickListener == null) { + return true; + } + Cluster cluster = (Cluster) marker.getObject(); + if (cluster != null) { + clusterClickListener.onMarkerClicked(marker, cluster.getClusterItems()); + return true; + } + return false; + } + + /** + * 将聚合元素添加至地图上 + */ + private void addClusterToMap(List clusters) { + ArrayList removeMarkers = new ArrayList<>(addMarkers); + AlphaAnimation alphaAnimation = new AlphaAnimation(1, 0); + RemoveAnimationListener removeAnimationListener = new RemoveAnimationListener(removeMarkers); + for (Marker marker : removeMarkers) { + marker.setAnimation(alphaAnimation); + marker.setAnimationListener(removeAnimationListener); + marker.startAnimation(); + } + + for (Cluster cluster : clusters) { + addSingleClusterToMap(cluster); + } + } + + /** + * 将单个聚合元素添加至地图显示 + */ + private void addSingleClusterToMap(Cluster cluster) { + LatLng latlng = cluster.getCenterLatLng(); + MarkerOptions markerOptions = new MarkerOptions(); + markerOptions.icon(getBitmapDes(cluster.getClusterCount())).position(latlng); + Marker marker = amap.addMarker(markerOptions); + marker.setAnimation(addAnimation); + marker.setObject(cluster); + + marker.startAnimation(); + cluster.setMarker(marker); + addMarkers.add(marker); + } + + private void calculateClusters() { + isCanceled = false; + clusters.clear(); + LatLngBounds visibleBounds = amap.getProjection().getVisibleRegion().latLngBounds; + for (ClusterItem clusterItem : clusterItems) { + if (isCanceled) { + return; + } + LatLng latlng = clusterItem.getPosition(); + if (visibleBounds.contains(latlng)) { + Cluster cluster = getCluster(latlng, clusters); + if (cluster == null) { + cluster = new Cluster(latlng); + clusters.add(cluster); + } + cluster.addClusterItem(clusterItem); + } + } + + //复制一份数据,规避同步 + List tempClusters = new ArrayList<>(clusters); + Message message = Message.obtain(); + message.what = MarkerHandler.ADD_CLUSTER_LIST; + message.obj = tempClusters; + if (isCanceled) { + return; + } + markerHandler.sendMessage(message); + } + + /** + * 对点进行聚合 + */ + private void assignClusters() { + isCanceled = true; + signClusterHandler.removeMessages(SignClusterHandler.CALCULATE_CLUSTER); + signClusterHandler.sendEmptyMessage(SignClusterHandler.CALCULATE_CLUSTER); + } + + /** + * 在已有的聚合基础上,对添加的单个元素进行聚合 + */ + private void calculateSingleCluster(ClusterItem clusterItem) { + LatLngBounds visibleBounds = amap.getProjection().getVisibleRegion().latLngBounds; + LatLng latlng = clusterItem.getPosition(); + if (!visibleBounds.contains(latlng)) { + return; + } + Cluster cluster = getCluster(latlng, clusters); + if (cluster != null) { + cluster.addClusterItem(clusterItem); + Message message = Message.obtain(); + message.what = MarkerHandler.UPDATE_SINGLE_CLUSTER; + + message.obj = cluster; + markerHandler.removeMessages(MarkerHandler.UPDATE_SINGLE_CLUSTER); + markerHandler.sendMessageDelayed(message, 5); + } else { + cluster = new Cluster(latlng); + clusters.add(cluster); + cluster.addClusterItem(clusterItem); + Message message = Message.obtain(); + message.what = MarkerHandler.ADD_SINGLE_CLUSTER; + message.obj = cluster; + markerHandler.sendMessage(message); + } + } + + /** + * 根据一个点获取是否可以依附的聚合点,没有则返回null + */ + private Cluster getCluster(LatLng latLng, List clusters) { + for (Cluster cluster : clusters) { + LatLng clusterCenterPoint = cluster.getCenterLatLng(); + double distance = AMapUtils.calculateLineDistance(latLng, clusterCenterPoint); + if (distance < clusterDistance && amap.getCameraPosition().zoom < 19) { + return cluster; + } + } + return null; + } + + + /** + * 获取每个聚合点的绘制样式 + */ + private BitmapDescriptor getBitmapDes(int num) { + TextView textView = new TextView(context); + if (num > 1) { + String tile = String.valueOf(num); + textView.setText(tile); + } + textView.setGravity(Gravity.CENTER); + textView.setTextColor(Color.BLACK); + textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 15); + if (clusterRender != null && clusterRender.getDrawableByCount(num) != null) { + textView.setBackgroundDrawable(clusterRender.getDrawableByCount(num)); + } else { + textView.setBackgroundResource(R.mipmap.well_location); + } + return BitmapDescriptorFactory.fromView(textView); + } + + /** + * 更新已加入地图聚合点的样式 + */ + private void updateCluster(Cluster cluster) { + Marker marker = cluster.getMarker(); + marker.setIcon(getBitmapDes(cluster.getClusterCount())); + } + + /** + * 处理market添加,更新等操作 + */ + class MarkerHandler extends Handler { + + static final int ADD_CLUSTER_LIST = 0; + + static final int ADD_SINGLE_CLUSTER = 1; + + static final int UPDATE_SINGLE_CLUSTER = 2; + + public MarkerHandler(Looper looper) { + super(looper); + } + + public void handleMessage(Message message) { + switch (message.what) { + case ADD_CLUSTER_LIST: + List clusters = (List) message.obj; + addClusterToMap(clusters); + break; + case ADD_SINGLE_CLUSTER: + Cluster cluster = (Cluster) message.obj; + addSingleClusterToMap(cluster); + break; + case UPDATE_SINGLE_CLUSTER: + Cluster updateCluster = (Cluster) message.obj; + updateCluster(updateCluster); + break; + } + } + } + + /** + * 处理聚合点算法线程 + */ + class SignClusterHandler extends Handler { + static final int CALCULATE_CLUSTER = 0; + static final int CALCULATE_SINGLE_CLUSTER = 1; + + public SignClusterHandler(Looper looper) { + super(looper); + } + + public void handleMessage(Message message) { + switch (message.what) { + case CALCULATE_CLUSTER: + calculateClusters(); + break; + case CALCULATE_SINGLE_CLUSTER: + ClusterItem item = (ClusterItem) message.obj; + clusterItems.add(item); + calculateSingleCluster(item); + break; + } + } + } +} diff --git a/app/src/main/java/com/casic/app/smartwell/widgets/cluster/ClusterRender.java b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/ClusterRender.java new file mode 100644 index 0000000..427ff14 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/ClusterRender.java @@ -0,0 +1,10 @@ +package com.casic.app.smartwell.widgets.cluster; + +import android.graphics.drawable.Drawable; + +public interface ClusterRender { + /** + * 根据聚合点的元素数目返回渲染背景样式 + */ + Drawable getDrawableByCount(int clusterNum); +} diff --git a/app/src/main/java/com/casic/app/smartwell/extensions/Int.kt b/app/src/main/java/com/casic/app/smartwell/extensions/Int.kt index de0617b..a0a5e33 100644 --- a/app/src/main/java/com/casic/app/smartwell/extensions/Int.kt +++ b/app/src/main/java/com/casic/app/smartwell/extensions/Int.kt @@ -1,9 +1,24 @@ package com.casic.app.smartwell.extensions +import android.graphics.Bitmap +import android.graphics.Canvas +import android.graphics.Paint +import android.graphics.RectF + fun Int.toLevel(): String { return if (this == 0) { "" } else { this.toString() } +} + +fun Int.drawCircle(color: Int): Bitmap? { + val bitmap = Bitmap.createBitmap(this * 2, this * 2, Bitmap.Config.ARGB_8888) + val canvas = Canvas(bitmap) + val paint = Paint() + val rectF = RectF(0f, 0f, (this * 2).toFloat(), (this * 2).toFloat()) + paint.color = color + canvas.drawArc(rectF, 0f, 360f, true, paint) + return bitmap } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt index 6b6ca3e..5e45534 100644 --- a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt +++ b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt @@ -2,17 +2,13 @@ import android.content.Context import com.casic.app.smartwell.callback.OnImageCompressListener -import com.casic.app.smartwell.model.ErrorMessageModel import com.casic.app.smartwell.utils.LocaleConstant -import com.google.gson.Gson -import com.google.gson.reflect.TypeToken +import com.google.gson.JsonParser import com.pengxh.kt.lite.extensions.createCompressImageDir import com.pengxh.kt.lite.utils.SaveKeyValues -import org.json.JSONObject import top.zibin.luban.Luban import top.zibin.luban.OnCompressListener import java.io.File -import java.util.Locale /** * String扩展方法 @@ -74,18 +70,22 @@ } } -fun String.separateResponseCode(): Int { +fun String.getResponseCode(): Int { if (this.isBlank()) { return 404 } - return JSONObject(this).getInt("code") + val element = JsonParser.parseString(this) + val jsonObject = element.asJsonObject + return jsonObject.get("code").asInt } -fun String.toErrorMessage(): String { - val errorModel = Gson().fromJson( - this, object : TypeToken() {}.type - ) - return errorModel.message.toString() +fun String.getResponseMessage(): String { + if (this.isBlank()) { + return "" + } + val element = JsonParser.parseString(this) + val jsonObject = element.asJsonObject + return jsonObject.get("message").asString } fun String.compressImage(context: Context, listener: OnImageCompressListener) { @@ -93,9 +93,6 @@ .load(this) .ignoreBy(100) .setTargetDir(context.createCompressImageDir().toString()) - .filter { - !(it.isBlank() || it.lowercase(Locale.getDefault()).endsWith(".gif")) - } .setCompressListener(object : OnCompressListener { override fun onStart() { 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 96df110..cd25fca 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 @@ -1,26 +1,25 @@ package com.casic.app.smartwell.fragment -import android.graphics.Point +import android.graphics.Color +import android.graphics.drawable.BitmapDrawable +import android.graphics.drawable.Drawable 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 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.LatLngBounds import com.amap.api.maps.model.Marker -import com.amap.api.maps.model.MarkerOptions import com.casic.app.smartwell.R import com.casic.app.smartwell.databinding.FragmentHomeBinding +import com.casic.app.smartwell.extensions.drawCircle import com.casic.app.smartwell.extensions.initImmersionBar -import com.casic.app.smartwell.extensions.valueToType import com.casic.app.smartwell.model.MapWellListModel import com.casic.app.smartwell.utils.LocaleConstant import com.casic.app.smartwell.utils.RouteOnMap @@ -31,9 +30,16 @@ import com.casic.app.smartwell.view.WellOperationActivity import com.casic.app.smartwell.vm.OrderViewModel import com.casic.app.smartwell.vm.WellViewModel +import com.casic.app.smartwell.widgets.MapWellPopup +import com.casic.app.smartwell.widgets.cluster.ClusterItem +import com.casic.app.smartwell.widgets.cluster.ClusterOnClickListener +import com.casic.app.smartwell.widgets.cluster.ClusterOverlay +import com.casic.app.smartwell.widgets.cluster.RegionItem 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.convertDrawable +import com.pengxh.kt.lite.extensions.dp2px import com.pengxh.kt.lite.extensions.navigatePageTo import com.pengxh.kt.lite.extensions.show import com.pengxh.kt.lite.utils.LoadingDialogHub @@ -43,35 +49,23 @@ /** * 地图点位带聚合效果 * */ -class HomePageHaveClusterFragment : KotlinBaseFragment(), AMap.OnMapLoadedListener, - AMap.OnCameraChangeListener, AMap.OnMarkerClickListener, AMap.InfoWindowAdapter, - AMap.OnInfoWindowClickListener { +class HomePageHaveClusterFragment : KotlinBaseFragment(), + AMap.OnCameraChangeListener { private val kTag = "HaveClusterFragment" private val easyPopupWindow by lazy { EasyPopupWindow(requireContext()) } - private lateinit var wellViewModel: WellViewModel - private lateinit var orderViewModel: OrderViewModel - private lateinit var aMap: AMap - - /** - * 所有的marker - */ - private var allMarkerOptions: MutableList = ArrayList() - - /** - * 视野内的marker - */ - private var markerOptionsInView: MutableList = ArrayList() - - /** - * 自定义Marker弹出框 - * */ - private lateinit var v: View + private val regionRadius by lazy { LocaleConstant.RADIUS_SIZE.dp2px(requireContext()) } + private val infoPopup by lazy { MapWellPopup(requireContext()) } /** * 所有窨井列表信息集合 * */ - private var wellModels: MutableList = ArrayList() + private val wellModels = ArrayList() + private val backDrawables = HashMap() + private lateinit var wellViewModel: WellViewModel + private lateinit var orderViewModel: OrderViewModel + private lateinit var aMap: AMap + private var clusterOverlay: ClusterOverlay? = null override fun initViewBinding( inflater: LayoutInflater, @@ -106,6 +100,9 @@ } }) + //地图初始化 + initMap(savedInstanceState) + //初始化vm wellViewModel = ViewModelProvider(this)[WellViewModel::class.java] orderViewModel = ViewModelProvider(this)[OrderViewModel::class.java] @@ -120,25 +117,19 @@ val latitudeList: MutableList = ArrayList() val longitudeList: MutableList = ArrayList() it.data?.forEach { well -> - val lat = well.latGaode.toString() - val lng = well.lngGaode.toString() + val lat = well.latGaode + val lng = well.lngGaode if (lat.isNotBlank() && lng.isNotBlank()) { //返回true代表当前位置在大陆、港澳地区,反之不在 val latitude = lat.toDouble() val longitude = lng.toDouble() if (CoordinateConverter.isAMapDataAvailable(latitude, longitude)) { - //缓存所有设备详情,点击Marker时候需要 + //缓存所有井 wellModels.add(well) + //分别缓存经、纬度 latitudeList.add(latitude) longitudeList.add(longitude) - //将所有设备信息转化缓存为Marker点 - allMarkerOptions.add( - MarkerOptions() - .position(LatLng(latitude, longitude)) - .title(well.wellTypeName) - .snippet(well.wellName) - ) } } } @@ -160,12 +151,12 @@ val cameraPosition = CameraPosition(centerLatLng, 16f, 0f, 0f) val cameraUpdate = CameraUpdateFactory.newCameraPosition(cameraPosition) aMap.animateCamera(cameraUpdate, 1500, null) + + //显示点数据 + displayWellOnMap() } } - //地图初始化 - initMap(savedInstanceState) - //获取窨井监控数据 wellViewModel.countResultModel.observe(this) { binding.deployedWellView.text = it["bfWell"] @@ -220,17 +211,10 @@ uiSettings.isCompassEnabled = true uiSettings.zoomPosition = AMapOptions.ZOOM_POSITION_RIGHT_CENTER uiSettings.isTiltGesturesEnabled = false//不许地图随手势倾斜角度 + uiSettings.isRotateGesturesEnabled = false//不允许地图随手势改变方位 - // 地图加载成功监听 - aMap.addOnMapLoadedListener(this) // 地图缩放监听 aMap.addOnCameraChangeListener(this) - // marker 点击事件监听 - aMap.addOnMarkerClickListener(this) - // 点击marker弹出自定义popup - aMap.setInfoWindowAdapter(this) - //信息窗点击事件 - aMap.addOnInfoWindowClickListener(this) } override fun initEvent() { @@ -259,9 +243,111 @@ } - override fun onMapLoaded() { - //地图加载成功之后显示聚合点数据 - initClustersMarkers() + private fun displayWellOnMap() { + clusterOverlay?.onDestroy() + val clusterItems = ArrayList() + + wellModels.forEach { + val latitude = it.latGaode.toDouble() + val longitude = it.lngGaode.toDouble() + + val latLng = LatLng(latitude, longitude, false) + val regionItem = RegionItem(latLng, it) + clusterItems.add(regionItem) + } + + clusterOverlay = ClusterOverlay(requireContext(), aMap, clusterItems, regionRadius) + clusterOverlay?.setClusterRender { clusterNum -> + //聚合圆半径 + val radius = 100.dp2px(requireContext()) + if (clusterNum == 0) { + var bitmapDrawable = backDrawables[0] + if (bitmapDrawable == null) { + bitmapDrawable = BitmapDrawable( + null, radius.drawCircle(Color.argb(159, 100, 149, 237)) + ) + backDrawables[0] = bitmapDrawable + } + bitmapDrawable + } + if (clusterNum == 1) { + var bitmapDrawable = backDrawables[1] + if (bitmapDrawable == null) { + bitmapDrawable = R.mipmap.well_location.convertDrawable(requireContext())!! + backDrawables[1] = bitmapDrawable + } + bitmapDrawable + } else if (clusterNum < 5) { + var bitmapDrawable = backDrawables[2] + if (bitmapDrawable == null) { + bitmapDrawable = BitmapDrawable( + null, radius.drawCircle(Color.argb(159, 100, 149, 237)) + ) + backDrawables[2] = bitmapDrawable + } + bitmapDrawable + } else if (clusterNum < 10) { + var bitmapDrawable = backDrawables[3] + if (bitmapDrawable == null) { + bitmapDrawable = BitmapDrawable( + null, radius.drawCircle(Color.argb(199, 30, 144, 255)) + ) + backDrawables[3] = bitmapDrawable + } + bitmapDrawable + } else { + var bitmapDrawable = backDrawables[4] + if (bitmapDrawable == null) { + bitmapDrawable = BitmapDrawable( + null, radius.drawCircle(Color.argb(235, 65, 105, 225)) + ) + backDrawables[4] = bitmapDrawable + } + bitmapDrawable + } + } + + clusterOverlay?.setOnClusterClickListener(object : ClusterOnClickListener { + override fun onMarkerClicked(marker: Marker?, items: List) { + if (items.size > 1) { + "请缩放地图比例在查看数据".show(requireContext()) + return + } + + var item: RegionItem? = null + val builder = LatLngBounds.Builder() + for (clusterItem in items) { + builder.include(clusterItem.position) + item = clusterItem as RegionItem + } + + item?.apply { + showWellPopup(well) + } + } + }) + } + + private fun showWellPopup(well: MapWellListModel.DataModel) { + infoPopup.set(well, object : MapWellPopup.OnPopupWindowClickListener { + override fun onPopupClicked(lat: Double, lng: Double) { + AlertControlDialog.Builder().setContext(requireContext()).setTitle("操作提示") + .setMessage("确定要前往吗").setNegativeButton("取消").setPositiveButton("确定") + .setOnDialogButtonClickListener(object : + AlertControlDialog.OnDialogButtonClickListener { + override fun onConfirmClick() { + RouteOnMap.startNavigation( + requireContext(), "", LatLng(lat, lng) + ) + } + + override fun onCancelClick() { + + } + }).build().show() + } + }) + infoPopup.showAsDropDown(binding.rightOptionView) } override fun onCameraChange(p0: CameraPosition?) { @@ -282,103 +368,10 @@ } } - //获取视野内的marker 根据聚合算法合成自定义的marker 显示视野内的marker override fun onCameraChangeFinish(p0: CameraPosition?) { //地图缩放之后显示聚合点数据 LoadingDialogHub.dismiss() httpCountDownTimer.cancel() - initClustersMarkers() - } - - private fun initClustersMarkers() { - 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 { - v = LayoutInflater.from(requireContext()).inflate(R.layout.popup_map_info, null) - - //显示闸井信息 - marker?.showInfoWindow() - return true - } - - override fun getInfoWindow(marker: Marker?): View { - //反射得到popup里面的控件对象 - val wellNameView = v.findViewById(R.id.wellNameView) - val wellCodeView = v.findViewById(R.id.wellCodeView) - val wellTypeView = v.findViewById(R.id.wellTypeView) - val wellStateView = v.findViewById(R.id.wellStateView) - val deepView = v.findViewById(R.id.deepView) - val locationView = v.findViewById(R.id.locationView) - - //绑定数据 - val clickedLatLng = marker?.position!! - wellModels.forEach { well -> - if (clickedLatLng.latitude == well.latGaode!!.toDouble() - && clickedLatLng.longitude == well.lngGaode!!.toDouble() - ) { - wellNameView.text = String.format("点位名称: ${well.wellName}") - wellCodeView.text = String.format("点位编号: ${well.wellCode}") - wellTypeView.text = String.format("点位类型: ${well.wellType.valueToType()}") - val bfztName = if (well.bfzt == "1") { - "已布防" - } else { - "已撤防" - } - wellStateView.text = String.format("布/撤防状态: $bfztName") - deepView.text = String.format("点位深度: ${well.deep}m") - locationView.text = String.format("详细位置: ${well.position}") - } - } - return v - } - - /** - * 此方法不能修改整个 InfoWindow 的背景和边框,无论自定义的样式是什么样,SDK 都会在最外层添加一个默认的边框 - * */ - override fun getInfoContents(p0: Marker?): View? = null - - override fun onInfoWindowClick(p0: Marker?) { - p0?.apply { - AlertControlDialog.Builder() - .setContext(requireContext()) - .setTitle("操作提示") - .setMessage("确定要前往吗") - .setNegativeButton("取消") - .setPositiveButton("确定") - .setOnDialogButtonClickListener(object : - AlertControlDialog.OnDialogButtonClickListener { - override fun onConfirmClick() { - val lat = position.latitude.toString() - val lng = position.longitude.toString() - if (lat.isBlank() || lng.isBlank()) { - "点位经纬度异常,无法开启导航".show(requireContext()) - return - } - RouteOnMap.startNavigation( - requireContext(), snippet, LatLng(lat.toDouble(), lng.toDouble()) - ) - } - - override fun onCancelClick() { - - } - }).build().show() - } } /***以下是地图生命周期管理************************************************************************/ 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 a54d213..bfa7a57 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 @@ -44,8 +44,8 @@ * 地图点位不带聚合效果 * */ class HomePageNoClusterFragment : KotlinBaseFragment(), - AMap.OnMapLoadedListener, AMap.OnCameraChangeListener, AMap.OnMarkerClickListener, - AMap.InfoWindowAdapter, AMap.OnInfoWindowClickListener { + AMap.OnCameraChangeListener, AMap.OnMarkerClickListener, AMap.InfoWindowAdapter, + AMap.OnInfoWindowClickListener { private val kTag = "NoClusterFragment" private val easyPopupWindow by lazy { EasyPopupWindow(requireContext()) } @@ -109,6 +109,9 @@ wellViewModel = ViewModelProvider(this)[WellViewModel::class.java] orderViewModel = ViewModelProvider(this)[OrderViewModel::class.java] + //地图初始化 + initMap(savedInstanceState) + //获取所有窨井数据 httpCountDownTimer.start() LoadingDialogHub.show(requireActivity(), "数据加载中,请稍后...") @@ -157,12 +160,12 @@ val cameraPosition = CameraPosition(centerLatLng, 16f, 0f, 0f) val cameraUpdate = CameraUpdateFactory.newCameraPosition(cameraPosition) aMap.animateCamera(cameraUpdate, 1500, null) + + //显示点数据 + displayWellOnMap() } } - //地图初始化 - initMap(savedInstanceState) - //获取窨井监控数据 wellViewModel.countResultModel.observe(this) { binding.deployedWellView.text = it["bfWell"] @@ -214,9 +217,8 @@ uiSettings.isCompassEnabled = true uiSettings.zoomPosition = AMapOptions.ZOOM_POSITION_RIGHT_CENTER uiSettings.isTiltGesturesEnabled = false//不许地图随手势倾斜角度 + uiSettings.isRotateGesturesEnabled = false//不允许地图随手势改变方位 - // 地图加载成功监听 - aMap.addOnMapLoadedListener(this) // 地图缩放监听 aMap.addOnCameraChangeListener(this) // marker 点击事件监听 @@ -253,11 +255,6 @@ } - override fun onMapLoaded() { - //地图加载成功之后显示聚合点数据 - initClustersMarkers() - } - override fun onCameraChange(p0: CameraPosition?) { } @@ -281,10 +278,9 @@ //地图缩放之后显示聚合点数据 LoadingDialogHub.dismiss() httpCountDownTimer.cancel() - initClustersMarkers() } - private fun initClustersMarkers() { + private fun displayWellOnMap() { val proj = aMap.projection val dm = resources.displayMetrics var screenLocation: Point diff --git a/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.java b/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.java deleted file mode 100644 index d8b18ef..0000000 --- a/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.java +++ /dev/null @@ -1,50 +0,0 @@ -package com.casic.app.smartwell.model; - -public class ErrorMessageModel { - - private int code; - private String data; - private String exceptionClazz; - private String message; - private boolean success; - - public int getCode() { - return code; - } - - public void setCode(int code) { - this.code = code; - } - - public String getData() { - return data; - } - - public void setData(String data) { - this.data = data; - } - - public String getExceptionClazz() { - return exceptionClazz; - } - - public void setExceptionClazz(String exceptionClazz) { - this.exceptionClazz = exceptionClazz; - } - - public String getMessage() { - return message; - } - - public void setMessage(String message) { - this.message = message; - } - - public boolean isSuccess() { - return success; - } - - public void setSuccess(boolean success) { - this.success = success; - } -} \ No newline at end of file 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 new file mode 100644 index 0000000..215ac0c --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/PipelineModel.java @@ -0,0 +1,328 @@ +package com.casic.app.smartwell.model; + +import java.util.List; + +public class PipelineModel { + + private Integer code; + private DataModel data; + private String message; + private Boolean success; + + public Integer getCode() { + return code; + } + + public void setCode(Integer code) { + this.code = code; + } + + public DataModel getData() { + return data; + } + + public void setData(DataModel data) { + this.data = data; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + public Boolean getSuccess() { + return success; + } + + public void setSuccess(Boolean success) { + this.success = success; + } + + public static class DataModel { + private List rows; + private Integer total; + + public List getRows() { + return rows; + } + + public void setRows(List rows) { + this.rows = rows; + } + + public Integer getTotal() { + return total; + } + + public void setTotal(Integer total) { + this.total = total; + } + + 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 getBuryMode() { + return buryMode; + } + + public void setBuryMode(String buryMode) { + this.buryMode = buryMode; + } + + public String getConstructEra() { + return constructEra; + } + + public void setConstructEra(String constructEra) { + this.constructEra = constructEra; + } + + 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; + } + } + } +} 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 06d3d2b..4f38a2c 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 = 100 //相距多少米才聚合,单位:米 + const val RADIUS_SIZE = 80 //相距多少米才聚合,单位:米 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:11308" + // 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 0d5f3fa..991e1db 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 @@ -312,4 +312,14 @@ @Header("token") token: String, @Field("clientid") deviceCode: String ): String + + /** + * 管线位置数据 + */ + @GET("/pipeline/listPage") + suspend fun getPipeline( + @Header("token") token: String, + @Query("limit") limit: Int, + @Query("offset") offset: Int + ): String } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt index 1a0ce22..4050067 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt @@ -294,4 +294,11 @@ suspend fun registerPush(clientId: String): String { return api.registerPush(AuthenticationHelper.token!!, clientId) } + + /** + * 管线位置数据 + */ + suspend fun getPipeline(): String { + return api.getPipeline(AuthenticationHelper.token!!, 2000, 1) + } } \ No newline at end of file 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 9270fa1..4ca5a5e 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.HomePageNoClusterFragment +import com.casic.app.smartwell.fragment.HomePageHaveClusterFragment 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/vm/AlarmViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/AlarmViewModel.kt index 9cff08c..e7acc17 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/AlarmViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/AlarmViewModel.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.AlarmContentModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager import com.google.gson.Gson @@ -16,7 +16,7 @@ fun getAlarmContentType(alarmType: String) = launch({ val response = RetrofitServiceManager.getAlarmContentType(alarmType) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { listModel.value = gson.fromJson( response, object : TypeToken() {}.type diff --git a/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt index 5e5b163..895dedd 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.PublicKeyModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager import com.google.gson.Gson @@ -18,7 +18,7 @@ fun getPublicKey() = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.authenticate() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { keyModel.value = gson.fromJson( response, object : TypeToken() {}.type diff --git a/app/src/main/java/com/casic/app/smartwell/vm/DeviceViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/DeviceViewModel.kt index db5ccf6..899a962 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/DeviceViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/DeviceViewModel.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.DeviceDetailModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager import com.google.gson.Gson @@ -16,7 +16,7 @@ fun getDeviceDetail(deviceCode: String) = launch({ val response = RetrofitServiceManager.getDeviceDetail(deviceCode) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { detailModel.value = gson.fromJson( response, object : TypeToken() {}.type diff --git a/app/src/main/java/com/casic/app/smartwell/vm/LoginViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/LoginViewModel.kt index cd8b8a9..a417398 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/LoginViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/LoginViewModel.kt @@ -2,7 +2,7 @@ import androidx.lifecycle.MutableLiveData import com.casic.app.smartwell.base.BaseApplication -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.CommonResultModel import com.casic.app.smartwell.model.LoginResultModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -21,7 +21,7 @@ fun enter(account: String, secretKey: String) = launch({ val response = RetrofitServiceManager.login(account, secretKey) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success enterResultModel.value = gson.fromJson( @@ -38,7 +38,7 @@ fun out() = launch({ val response = RetrofitServiceManager.loginOut() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { outResultModel.value = gson.fromJson( response, object : TypeToken() {}.type diff --git a/app/src/main/java/com/casic/app/smartwell/vm/OperationViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/OperationViewModel.kt index 8943ed3..37e115f 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/OperationViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/OperationViewModel.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.vm import com.casic.app.smartwell.base.BaseApplication -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager import com.pengxh.kt.lite.base.BaseViewModel import com.pengxh.kt.lite.extensions.launch @@ -16,7 +16,7 @@ fun acceptWorkOrder(id: String) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.acceptWorkOrder(id) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success "接单成功".show(BaseApplication.get()) @@ -35,7 +35,7 @@ loadState.value = LoadState.Loading val response = RetrofitServiceManager.confirmWorkOrder(id, firstState, firstStatePhotos, needHandle) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success "工单确认成功".show(BaseApplication.get()) @@ -50,7 +50,7 @@ fun transferWorkOrder(id: String, userId: String) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.transferWorkOrder(id, userId) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success "转单成功".show(BaseApplication.get()) @@ -65,7 +65,7 @@ fun completeWorkOrder(id: String, handleMessage: String, handlePhotos: String) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.completeWorkOrder(id, handleMessage, handlePhotos) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success "工单处理成功".show(BaseApplication.get()) diff --git a/app/src/main/java/com/casic/app/smartwell/vm/OrderViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/OrderViewModel.kt index 4cb26b7..d2fad86 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/OrderViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/OrderViewModel.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.OrderDetailModel import com.casic.app.smartwell.model.OrderListModel import com.casic.app.smartwell.model.OrderStatusModel @@ -37,7 +37,7 @@ val response = RetrofitServiceManager.getSearchResult( keywords, alarmContent, alarmLevel, jobStatus, deptId, beginTime, endTime, offset ) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success searchResult.value = gson.fromJson( @@ -53,7 +53,7 @@ fun getWorkOrderListByState(jobStatus: String, page: Int) = launch({ val response = RetrofitServiceManager.getWorkOrderList(jobStatus, page) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { orderList.value = gson.fromJson( response, object : TypeToken() {}.type @@ -65,7 +65,7 @@ fun getNotAcceptOderList(page: Int) = launch({ val response = RetrofitServiceManager.getNotAcceptOderList(page) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { orderList.value = gson.fromJson( response, object : TypeToken() {}.type @@ -77,7 +77,7 @@ fun getNotHandleOderList(page: Int) = launch({ val response = RetrofitServiceManager.getNotHandleOderList(page) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { orderList.value = gson.fromJson( response, object : TypeToken() {}.type @@ -89,7 +89,7 @@ fun countWorkOrderByState() = launch({ val response = RetrofitServiceManager.countWorkOrderByState() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { val map = HashMap(4) @@ -107,7 +107,7 @@ fun getOrderStatus() = launch({ val response = RetrofitServiceManager.getOrderStatus() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { orderStatusModel.value = gson.fromJson( response, object : TypeToken() {}.type @@ -120,7 +120,7 @@ fun getWorkOrderDetail(id: String) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.getWorkOrderDetail(id) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success detailModel.value = gson.fromJson( diff --git a/app/src/main/java/com/casic/app/smartwell/vm/PipelineViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/PipelineViewModel.kt new file mode 100644 index 0000000..60c1e2f --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/vm/PipelineViewModel.kt @@ -0,0 +1,28 @@ +package com.casic.app.smartwell.vm + +import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.extensions.getResponseCode +import com.casic.app.smartwell.model.PipelineModel +import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken +import com.pengxh.kt.lite.base.BaseViewModel +import com.pengxh.kt.lite.extensions.launch + +class PipelineViewModel : BaseViewModel() { + + private val gson by lazy { Gson() } + val lineResult = MutableLiveData() + + fun getPipeline() = launch({ + val response = RetrofitServiceManager.getPipeline() + val responseCode = response.getResponseCode() + if (responseCode == 200) { + lineResult.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } + }, { + it.printStackTrace() + }) +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/PushViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/PushViewModel.kt index 9279815..12fd610 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/PushViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/PushViewModel.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.CommonResultModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager import com.google.gson.Gson @@ -16,7 +16,7 @@ fun registerPush(clientId: String) = launch({ val response = RetrofitServiceManager.registerPush(clientId) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { registerResultModel.value = gson.fromJson( response, object : TypeToken() {}.type diff --git a/app/src/main/java/com/casic/app/smartwell/vm/UploadImageViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/UploadImageViewModel.kt index 8d6744e..9707eeb 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/UploadImageViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/UploadImageViewModel.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.CommonResultModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager import com.google.gson.Gson @@ -19,7 +19,7 @@ fun uploadImage(image: File) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.uploadImage(image) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success resultModel.value = gson.fromJson( diff --git a/app/src/main/java/com/casic/app/smartwell/vm/UserViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/UserViewModel.kt index 31a4d4c..070c35a 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/UserViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/UserViewModel.kt @@ -2,7 +2,7 @@ import androidx.lifecycle.MutableLiveData import com.casic.app.smartwell.base.BaseApplication -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.SubordinateModel import com.casic.app.smartwell.model.UserDetailModel import com.casic.app.smartwell.model.VersionResultModel @@ -25,7 +25,7 @@ fun getUserDetail() = launch({ val response = RetrofitServiceManager.getUserDetail() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { val userDetail = gson.fromJson( response, object : TypeToken() {}.type @@ -48,7 +48,7 @@ * */ fun getSubordinate(hasMine: String?, deptId: String?, roleTips: String?) = launch({ val response = RetrofitServiceManager.getSubordinate(hasMine, deptId, roleTips) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { subordinateModel.value = gson.fromJson( response, object : TypeToken() {}.type @@ -61,7 +61,7 @@ fun changePassword(oldPwd: String, newPwd: String) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.changePassword(oldPwd, newPwd) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success "修改成功,请重新登录".show(BaseApplication.get()) @@ -76,7 +76,7 @@ fun updateVersion() = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.updateVersion() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success versionResultModel.value = gson.fromJson( diff --git a/app/src/main/java/com/casic/app/smartwell/vm/WellViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/WellViewModel.kt index 3d41e9b..9e42e36 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/WellViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/WellViewModel.kt @@ -2,8 +2,7 @@ import androidx.lifecycle.MutableLiveData import com.casic.app.smartwell.base.BaseApplication -import com.casic.app.smartwell.extensions.separateResponseCode -import com.casic.app.smartwell.extensions.toErrorMessage +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.AuthorDeptModel import com.casic.app.smartwell.model.CommonResultModel import com.casic.app.smartwell.model.MapWellListModel @@ -32,7 +31,7 @@ fun countWellByState() = launch({ val response = RetrofitServiceManager.countWellByState() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { val map = HashMap(3) @@ -57,7 +56,7 @@ fun getWellType() = launch({ val response = RetrofitServiceManager.getWellType() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { wellTypeModel.value = gson.fromJson( response, object : TypeToken() {}.type @@ -70,7 +69,7 @@ fun getWellDetail(id: String) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.getWellDetail(id) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success wellDetailModel.value = gson.fromJson( @@ -87,7 +86,7 @@ fun getOperationResult(id: String, state: String) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.getOperationResult(id, state) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success "操作成功".show(BaseApplication.get()) @@ -105,7 +104,7 @@ fun getMonitorResult(id: String) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.getMonitorResult(id) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success monitorModel.value = gson.fromJson( @@ -125,7 +124,7 @@ val response = RetrofitServiceManager.getWellListByPage( keywords, wellType, deptid, bfzt, page ) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { listModel.value = gson.fromJson( response, object : TypeToken() {}.type @@ -137,13 +136,11 @@ fun getWellList() = launch({ val response = RetrofitServiceManager.getWellList() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { totalWellModel.value = gson.fromJson( response, object : TypeToken() {}.type ) - } else { - response.toErrorMessage().show(BaseApplication.get()) } }, { it.printStackTrace() diff --git a/app/src/main/java/com/casic/app/smartwell/widgets/GaoDeClusterMarkerView.kt b/app/src/main/java/com/casic/app/smartwell/widgets/GaoDeClusterMarkerView.kt deleted file mode 100644 index 1f375df..0000000 --- a/app/src/main/java/com/casic/app/smartwell/widgets/GaoDeClusterMarkerView.kt +++ /dev/null @@ -1,100 +0,0 @@ -package com.casic.app.smartwell.widgets - -import android.content.Context -import android.graphics.Bitmap -import android.graphics.Point -import android.view.Gravity -import android.view.LayoutInflater -import android.view.View -import android.widget.TextView -import com.amap.api.maps.Projection -import com.amap.api.maps.model.BitmapDescriptorFactory -import com.amap.api.maps.model.LatLng -import com.amap.api.maps.model.LatLngBounds -import com.amap.api.maps.model.MarkerOptions -import com.casic.app.smartwell.R -import com.pengxh.kt.lite.extensions.toBitmap -import java.util.* - -class GaoDeClusterMarkerView( - private val context: Context, firstMarkers: MarkerOptions, projection: Projection, gridSize: Int -) { - //当前可观区域里的 聚合过之后的集合 - private val includeMarkers: ArrayList - - // 创建区域 - val bounds: LatLngBounds - var options: MarkerOptions = MarkerOptions() - - init { - val screenLocation = projection.toScreenLocation(firstMarkers.position) - //范围类 - val southwestPoint = Point(screenLocation.x - gridSize, screenLocation.y + gridSize) - //范围类 - val northeastPoint = Point(screenLocation.x + gridSize, screenLocation.y - gridSize) - bounds = LatLngBounds( - projection.fromScreenLocation(southwestPoint), - projection.fromScreenLocation(northeastPoint) - ) - //设置初始化marker属性 - options.anchor(0.5f, 1.3f) - .title(firstMarkers.title) - .position(firstMarkers.position) - .icon(firstMarkers.icon) - .snippet(firstMarkers.snippet) - .draggable(false) - includeMarkers = ArrayList() - includeMarkers.add(firstMarkers) - } - - /** - * 添加marker - */ - fun addMarker(markerOptions: MarkerOptions) { - includeMarkers.add(markerOptions) // 添加到列表中 - } - - /** - * 设置聚合点的中心位置以及图标 - */ - fun setPositionAndIcon() { - val size = includeMarkers.size - var lat = 0.0 - var lng = 0.0 - // 一个的时候 - if (size == 1) { //设置marker单个属性 - // 设置marker位置 - options.position( - LatLng( - includeMarkers[0].position.latitude, includeMarkers[0].position.longitude - ) - ) - } else { // 聚合的时候 - //设置marker聚合属性 - for (op in includeMarkers) { - lat += op.position.latitude - lng += op.position.longitude - } - // 设置marker的位置为中心位置为聚集点的平均位置 - options.position(LatLng(lat / size, lng / size)) - } - options.icon(BitmapDescriptorFactory.fromBitmap(getBitmap(size))) - } - - /** - * marker视图 - */ - private fun getBitmap(num: Int): Bitmap? { - val view = LayoutInflater.from(context).inflate(R.layout.marker_gaode, null) - val wellCountView = view.findViewById(R.id.wellCountView) - return if (num > 1) { - wellCountView.visibility = View.VISIBLE - wellCountView.text = String.format("${num}个") - wellCountView.gravity = Gravity.CENTER - view.toBitmap() - } else { - wellCountView.visibility = View.GONE - BitmapDescriptorFactory.fromResource(R.mipmap.well_location).bitmap - } - } -} \ No newline at end of file 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 new file mode 100644 index 0000000..ec455dd --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/widgets/MapWellPopup.kt @@ -0,0 +1,58 @@ +package com.casic.app.smartwell.widgets + +import android.content.Context +import android.view.LayoutInflater +import android.view.ViewGroup +import android.widget.LinearLayout +import android.widget.PopupWindow +import android.widget.TextView +import com.casic.app.smartwell.R +import com.casic.app.smartwell.extensions.valueToType +import com.casic.app.smartwell.model.MapWellListModel + +class MapWellPopup constructor(context: Context) : PopupWindow() { + + init { + width = ViewGroup.LayoutParams.MATCH_PARENT + height = ViewGroup.LayoutParams.WRAP_CONTENT + isOutsideTouchable = true + isFocusable = true + animationStyle = R.style.MapPopupAnimation + setBackgroundDrawable(null) + contentView = LayoutInflater.from(context).inflate( + R.layout.popup_map_info, null, false + ) + } + + fun set(well: MapWellListModel.DataModel, windowClickListener: OnPopupWindowClickListener) { + //反射得到popup里面的控件对象 + val rootView = contentView.findViewById(R.id.rootView) + val wellNameView = contentView.findViewById(R.id.wellNameView) + val wellCodeView = contentView.findViewById(R.id.wellCodeView) + val wellTypeView = contentView.findViewById(R.id.wellTypeView) + val wellStateView = contentView.findViewById(R.id.wellStateView) + val deepView = contentView.findViewById(R.id.deepView) + val locationView = contentView.findViewById(R.id.locationView) + + //绑定数据 + wellNameView.text = String.format("点位名称: ${well.wellName}") + wellCodeView.text = String.format("点位编号: ${well.wellCode}") + wellTypeView.text = String.format("点位类型: ${well.wellType.valueToType()}") + val bfztName = if (well.bfzt == "1") { + "已布防" + } else { + "已撤防" + } + wellStateView.text = String.format("布/撤防状态: $bfztName") + deepView.text = String.format("点位深度: ${well.deep}m") + locationView.text = String.format("详细位置: ${well.position}") + + rootView.setOnClickListener { + windowClickListener.onPopupClicked(well.latGaode.toDouble(), well.lngGaode.toDouble()) + } + } + + interface OnPopupWindowClickListener { + fun onPopupClicked(lat: Double, lng: Double) + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/widgets/cluster/Cluster.java b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/Cluster.java new file mode 100644 index 0000000..9455ccd --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/Cluster.java @@ -0,0 +1,43 @@ +package com.casic.app.smartwell.widgets.cluster; + +import com.amap.api.maps.model.LatLng; +import com.amap.api.maps.model.Marker; + +import java.util.ArrayList; +import java.util.List; + +public class Cluster { + private final LatLng latLng; + private final List clusterItems; + private Marker marker; + + + public Cluster(LatLng latLng) { + this.latLng = latLng; + clusterItems = new ArrayList<>(); + } + + public void addClusterItem(ClusterItem clusterItem) { + clusterItems.add(clusterItem); + } + + public int getClusterCount() { + return clusterItems.size(); + } + + public LatLng getCenterLatLng() { + return latLng; + } + + public void setMarker(Marker marker) { + this.marker = marker; + } + + public Marker getMarker() { + return marker; + } + + public List getClusterItems() { + return clusterItems; + } +} diff --git a/app/src/main/java/com/casic/app/smartwell/widgets/cluster/ClusterItem.java b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/ClusterItem.java new file mode 100644 index 0000000..f5d9a9d --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/ClusterItem.java @@ -0,0 +1,10 @@ +package com.casic.app.smartwell.widgets.cluster; + +import com.amap.api.maps.model.LatLng; + +public interface ClusterItem { + /** + * 返回聚合元素的地理位置 + */ + LatLng getPosition(); +} diff --git a/app/src/main/java/com/casic/app/smartwell/widgets/cluster/ClusterOnClickListener.java b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/ClusterOnClickListener.java new file mode 100644 index 0000000..0efa1f1 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/ClusterOnClickListener.java @@ -0,0 +1,15 @@ +package com.casic.app.smartwell.widgets.cluster; + +import com.amap.api.maps.model.Marker; + +import java.util.List; + +public interface ClusterOnClickListener { + /** + * 点击聚合点的回调处理函数 + * + * @param marker 点击的聚合点 + * @param items 聚合点所包含的元素 + */ + void onMarkerClicked(Marker marker, List items); +} 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 new file mode 100644 index 0000000..40df562 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/ClusterOverlay.java @@ -0,0 +1,349 @@ +package com.casic.app.smartwell.widgets.cluster; + +import android.content.Context; +import android.graphics.Color; +import android.os.Handler; +import android.os.HandlerThread; +import android.os.Looper; +import android.os.Message; +import android.util.TypedValue; +import android.view.Gravity; +import android.widget.TextView; + +import com.amap.api.maps.AMap; +import com.amap.api.maps.AMapUtils; +import com.amap.api.maps.model.BitmapDescriptor; +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.LatLngBounds; +import com.amap.api.maps.model.Marker; +import com.amap.api.maps.model.MarkerOptions; +import com.amap.api.maps.model.animation.AlphaAnimation; +import com.casic.app.smartwell.R; + +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.CopyOnWriteArrayList; + +/** + * 整体设计采用了两个线程,一个线程用于计算组织聚合数据,一个线程负责处理Marker相关操作 + */ +public class ClusterOverlay implements AMap.OnCameraChangeListener, AMap.OnMarkerClickListener { + private final AMap amap; + private final Context context; + private final List clusterItems; + private final List clusters; + private final int clusterSize; + private ClusterOnClickListener clusterClickListener; + private ClusterRender clusterRender; + private final CopyOnWriteArrayList addMarkers = new CopyOnWriteArrayList<>(); + private double clusterDistance; + private final HandlerThread markerHandlerThread = new HandlerThread("addMarker"); + private final HandlerThread signClusterThread = new HandlerThread("calculateCluster"); + private Handler markerHandler; + private Handler signClusterHandler; + private float pxInMeters; + private boolean isCanceled = false; + private final AlphaAnimation addAnimation = new AlphaAnimation(0, 1); + + /** + * 构造函数,批量添加聚合元素时,调用此构造函数 + */ + public ClusterOverlay(Context context, AMap amap, int clusterSize) { + this(context, amap, null, clusterSize); + } + + /** + * 构造函数,批量添加聚合元素时,调用此构造函数 + */ + public ClusterOverlay(Context context, AMap amap, List clusterItems, int clusterSize) { + if (clusterItems != null) { + this.clusterItems = clusterItems; + } else { + this.clusterItems = new ArrayList<>(); + } + this.context = context; + this.clusters = new ArrayList<>(); + this.amap = amap; + this.clusterSize = clusterSize; + this.pxInMeters = amap.getScalePerPixel(); + this.clusterDistance = pxInMeters * clusterSize; + amap.setOnCameraChangeListener(this); + amap.setOnMarkerClickListener(this); + initThreadHandler(); + assignClusters(); + } + + /** + * 设置聚合点的点击事件 + */ + public void setOnClusterClickListener(ClusterOnClickListener clusterClickListener) { + this.clusterClickListener = clusterClickListener; + } + + /** + * 添加一个聚合点 + */ + public void addClusterItem(ClusterItem item) { + Message message = Message.obtain(); + message.what = SignClusterHandler.CALCULATE_SINGLE_CLUSTER; + message.obj = item; + signClusterHandler.sendMessage(message); + } + + /** + * 设置聚合元素的渲染样式,不设置则默认为气泡加数字形式进行渲染 + */ + public void setClusterRender(ClusterRender render) { + this.clusterRender = render; + } + + public void onDestroy() { + isCanceled = true; + signClusterHandler.removeCallbacksAndMessages(null); + markerHandler.removeCallbacksAndMessages(null); + signClusterThread.quit(); + markerHandlerThread.quit(); + for (Marker marker : addMarkers) { + marker.remove(); + } + addMarkers.clear(); + } + + //初始化Handler + private void initThreadHandler() { + markerHandlerThread.start(); + signClusterThread.start(); + markerHandler = new MarkerHandler(markerHandlerThread.getLooper()); + signClusterHandler = new SignClusterHandler(signClusterThread.getLooper()); + } + + @Override + public void onCameraChange(CameraPosition arg0) { + + } + + @Override + public void onCameraChangeFinish(CameraPosition arg0) { + pxInMeters = amap.getScalePerPixel(); + clusterDistance = pxInMeters * clusterSize; + assignClusters(); + } + + @Override + public boolean onMarkerClick(Marker marker) { + if (clusterClickListener == null) { + return true; + } + Cluster cluster = (Cluster) marker.getObject(); + if (cluster != null) { + clusterClickListener.onMarkerClicked(marker, cluster.getClusterItems()); + return true; + } + return false; + } + + /** + * 将聚合元素添加至地图上 + */ + private void addClusterToMap(List clusters) { + ArrayList removeMarkers = new ArrayList<>(addMarkers); + AlphaAnimation alphaAnimation = new AlphaAnimation(1, 0); + RemoveAnimationListener removeAnimationListener = new RemoveAnimationListener(removeMarkers); + for (Marker marker : removeMarkers) { + marker.setAnimation(alphaAnimation); + marker.setAnimationListener(removeAnimationListener); + marker.startAnimation(); + } + + for (Cluster cluster : clusters) { + addSingleClusterToMap(cluster); + } + } + + /** + * 将单个聚合元素添加至地图显示 + */ + private void addSingleClusterToMap(Cluster cluster) { + LatLng latlng = cluster.getCenterLatLng(); + MarkerOptions markerOptions = new MarkerOptions(); + markerOptions.icon(getBitmapDes(cluster.getClusterCount())).position(latlng); + Marker marker = amap.addMarker(markerOptions); + marker.setAnimation(addAnimation); + marker.setObject(cluster); + + marker.startAnimation(); + cluster.setMarker(marker); + addMarkers.add(marker); + } + + private void calculateClusters() { + isCanceled = false; + clusters.clear(); + LatLngBounds visibleBounds = amap.getProjection().getVisibleRegion().latLngBounds; + for (ClusterItem clusterItem : clusterItems) { + if (isCanceled) { + return; + } + LatLng latlng = clusterItem.getPosition(); + if (visibleBounds.contains(latlng)) { + Cluster cluster = getCluster(latlng, clusters); + if (cluster == null) { + cluster = new Cluster(latlng); + clusters.add(cluster); + } + cluster.addClusterItem(clusterItem); + } + } + + //复制一份数据,规避同步 + List tempClusters = new ArrayList<>(clusters); + Message message = Message.obtain(); + message.what = MarkerHandler.ADD_CLUSTER_LIST; + message.obj = tempClusters; + if (isCanceled) { + return; + } + markerHandler.sendMessage(message); + } + + /** + * 对点进行聚合 + */ + private void assignClusters() { + isCanceled = true; + signClusterHandler.removeMessages(SignClusterHandler.CALCULATE_CLUSTER); + signClusterHandler.sendEmptyMessage(SignClusterHandler.CALCULATE_CLUSTER); + } + + /** + * 在已有的聚合基础上,对添加的单个元素进行聚合 + */ + private void calculateSingleCluster(ClusterItem clusterItem) { + LatLngBounds visibleBounds = amap.getProjection().getVisibleRegion().latLngBounds; + LatLng latlng = clusterItem.getPosition(); + if (!visibleBounds.contains(latlng)) { + return; + } + Cluster cluster = getCluster(latlng, clusters); + if (cluster != null) { + cluster.addClusterItem(clusterItem); + Message message = Message.obtain(); + message.what = MarkerHandler.UPDATE_SINGLE_CLUSTER; + + message.obj = cluster; + markerHandler.removeMessages(MarkerHandler.UPDATE_SINGLE_CLUSTER); + markerHandler.sendMessageDelayed(message, 5); + } else { + cluster = new Cluster(latlng); + clusters.add(cluster); + cluster.addClusterItem(clusterItem); + Message message = Message.obtain(); + message.what = MarkerHandler.ADD_SINGLE_CLUSTER; + message.obj = cluster; + markerHandler.sendMessage(message); + } + } + + /** + * 根据一个点获取是否可以依附的聚合点,没有则返回null + */ + private Cluster getCluster(LatLng latLng, List clusters) { + for (Cluster cluster : clusters) { + LatLng clusterCenterPoint = cluster.getCenterLatLng(); + double distance = AMapUtils.calculateLineDistance(latLng, clusterCenterPoint); + if (distance < clusterDistance && amap.getCameraPosition().zoom < 19) { + return cluster; + } + } + return null; + } + + + /** + * 获取每个聚合点的绘制样式 + */ + private BitmapDescriptor getBitmapDes(int num) { + TextView textView = new TextView(context); + if (num > 1) { + String tile = String.valueOf(num); + textView.setText(tile); + } + textView.setGravity(Gravity.CENTER); + textView.setTextColor(Color.BLACK); + textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 15); + if (clusterRender != null && clusterRender.getDrawableByCount(num) != null) { + textView.setBackgroundDrawable(clusterRender.getDrawableByCount(num)); + } else { + textView.setBackgroundResource(R.mipmap.well_location); + } + return BitmapDescriptorFactory.fromView(textView); + } + + /** + * 更新已加入地图聚合点的样式 + */ + private void updateCluster(Cluster cluster) { + Marker marker = cluster.getMarker(); + marker.setIcon(getBitmapDes(cluster.getClusterCount())); + } + + /** + * 处理market添加,更新等操作 + */ + class MarkerHandler extends Handler { + + static final int ADD_CLUSTER_LIST = 0; + + static final int ADD_SINGLE_CLUSTER = 1; + + static final int UPDATE_SINGLE_CLUSTER = 2; + + public MarkerHandler(Looper looper) { + super(looper); + } + + public void handleMessage(Message message) { + switch (message.what) { + case ADD_CLUSTER_LIST: + List clusters = (List) message.obj; + addClusterToMap(clusters); + break; + case ADD_SINGLE_CLUSTER: + Cluster cluster = (Cluster) message.obj; + addSingleClusterToMap(cluster); + break; + case UPDATE_SINGLE_CLUSTER: + Cluster updateCluster = (Cluster) message.obj; + updateCluster(updateCluster); + break; + } + } + } + + /** + * 处理聚合点算法线程 + */ + class SignClusterHandler extends Handler { + static final int CALCULATE_CLUSTER = 0; + static final int CALCULATE_SINGLE_CLUSTER = 1; + + public SignClusterHandler(Looper looper) { + super(looper); + } + + public void handleMessage(Message message) { + switch (message.what) { + case CALCULATE_CLUSTER: + calculateClusters(); + break; + case CALCULATE_SINGLE_CLUSTER: + ClusterItem item = (ClusterItem) message.obj; + clusterItems.add(item); + calculateSingleCluster(item); + break; + } + } + } +} diff --git a/app/src/main/java/com/casic/app/smartwell/widgets/cluster/ClusterRender.java b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/ClusterRender.java new file mode 100644 index 0000000..427ff14 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/ClusterRender.java @@ -0,0 +1,10 @@ +package com.casic.app.smartwell.widgets.cluster; + +import android.graphics.drawable.Drawable; + +public interface ClusterRender { + /** + * 根据聚合点的元素数目返回渲染背景样式 + */ + Drawable getDrawableByCount(int clusterNum); +} diff --git a/app/src/main/java/com/casic/app/smartwell/widgets/cluster/RegionItem.java b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/RegionItem.java new file mode 100644 index 0000000..7b2b6c4 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/RegionItem.java @@ -0,0 +1,23 @@ +package com.casic.app.smartwell.widgets.cluster; + +import com.amap.api.maps.model.LatLng; +import com.casic.app.smartwell.model.MapWellListModel; + +public class RegionItem implements ClusterItem { + private final LatLng latLng; + private final MapWellListModel.DataModel well; + + public RegionItem(LatLng latLng, MapWellListModel.DataModel well) { + this.latLng = latLng; + this.well = well; + } + + @Override + public LatLng getPosition() { + return latLng; + } + + public MapWellListModel.DataModel getWell() { + return well; + } +} diff --git a/app/src/main/java/com/casic/app/smartwell/extensions/Int.kt b/app/src/main/java/com/casic/app/smartwell/extensions/Int.kt index de0617b..a0a5e33 100644 --- a/app/src/main/java/com/casic/app/smartwell/extensions/Int.kt +++ b/app/src/main/java/com/casic/app/smartwell/extensions/Int.kt @@ -1,9 +1,24 @@ package com.casic.app.smartwell.extensions +import android.graphics.Bitmap +import android.graphics.Canvas +import android.graphics.Paint +import android.graphics.RectF + fun Int.toLevel(): String { return if (this == 0) { "" } else { this.toString() } +} + +fun Int.drawCircle(color: Int): Bitmap? { + val bitmap = Bitmap.createBitmap(this * 2, this * 2, Bitmap.Config.ARGB_8888) + val canvas = Canvas(bitmap) + val paint = Paint() + val rectF = RectF(0f, 0f, (this * 2).toFloat(), (this * 2).toFloat()) + paint.color = color + canvas.drawArc(rectF, 0f, 360f, true, paint) + return bitmap } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt index 6b6ca3e..5e45534 100644 --- a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt +++ b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt @@ -2,17 +2,13 @@ import android.content.Context import com.casic.app.smartwell.callback.OnImageCompressListener -import com.casic.app.smartwell.model.ErrorMessageModel import com.casic.app.smartwell.utils.LocaleConstant -import com.google.gson.Gson -import com.google.gson.reflect.TypeToken +import com.google.gson.JsonParser import com.pengxh.kt.lite.extensions.createCompressImageDir import com.pengxh.kt.lite.utils.SaveKeyValues -import org.json.JSONObject import top.zibin.luban.Luban import top.zibin.luban.OnCompressListener import java.io.File -import java.util.Locale /** * String扩展方法 @@ -74,18 +70,22 @@ } } -fun String.separateResponseCode(): Int { +fun String.getResponseCode(): Int { if (this.isBlank()) { return 404 } - return JSONObject(this).getInt("code") + val element = JsonParser.parseString(this) + val jsonObject = element.asJsonObject + return jsonObject.get("code").asInt } -fun String.toErrorMessage(): String { - val errorModel = Gson().fromJson( - this, object : TypeToken() {}.type - ) - return errorModel.message.toString() +fun String.getResponseMessage(): String { + if (this.isBlank()) { + return "" + } + val element = JsonParser.parseString(this) + val jsonObject = element.asJsonObject + return jsonObject.get("message").asString } fun String.compressImage(context: Context, listener: OnImageCompressListener) { @@ -93,9 +93,6 @@ .load(this) .ignoreBy(100) .setTargetDir(context.createCompressImageDir().toString()) - .filter { - !(it.isBlank() || it.lowercase(Locale.getDefault()).endsWith(".gif")) - } .setCompressListener(object : OnCompressListener { override fun onStart() { 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 96df110..cd25fca 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 @@ -1,26 +1,25 @@ package com.casic.app.smartwell.fragment -import android.graphics.Point +import android.graphics.Color +import android.graphics.drawable.BitmapDrawable +import android.graphics.drawable.Drawable 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 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.LatLngBounds import com.amap.api.maps.model.Marker -import com.amap.api.maps.model.MarkerOptions import com.casic.app.smartwell.R import com.casic.app.smartwell.databinding.FragmentHomeBinding +import com.casic.app.smartwell.extensions.drawCircle import com.casic.app.smartwell.extensions.initImmersionBar -import com.casic.app.smartwell.extensions.valueToType import com.casic.app.smartwell.model.MapWellListModel import com.casic.app.smartwell.utils.LocaleConstant import com.casic.app.smartwell.utils.RouteOnMap @@ -31,9 +30,16 @@ import com.casic.app.smartwell.view.WellOperationActivity import com.casic.app.smartwell.vm.OrderViewModel import com.casic.app.smartwell.vm.WellViewModel +import com.casic.app.smartwell.widgets.MapWellPopup +import com.casic.app.smartwell.widgets.cluster.ClusterItem +import com.casic.app.smartwell.widgets.cluster.ClusterOnClickListener +import com.casic.app.smartwell.widgets.cluster.ClusterOverlay +import com.casic.app.smartwell.widgets.cluster.RegionItem 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.convertDrawable +import com.pengxh.kt.lite.extensions.dp2px import com.pengxh.kt.lite.extensions.navigatePageTo import com.pengxh.kt.lite.extensions.show import com.pengxh.kt.lite.utils.LoadingDialogHub @@ -43,35 +49,23 @@ /** * 地图点位带聚合效果 * */ -class HomePageHaveClusterFragment : KotlinBaseFragment(), AMap.OnMapLoadedListener, - AMap.OnCameraChangeListener, AMap.OnMarkerClickListener, AMap.InfoWindowAdapter, - AMap.OnInfoWindowClickListener { +class HomePageHaveClusterFragment : KotlinBaseFragment(), + AMap.OnCameraChangeListener { private val kTag = "HaveClusterFragment" private val easyPopupWindow by lazy { EasyPopupWindow(requireContext()) } - private lateinit var wellViewModel: WellViewModel - private lateinit var orderViewModel: OrderViewModel - private lateinit var aMap: AMap - - /** - * 所有的marker - */ - private var allMarkerOptions: MutableList = ArrayList() - - /** - * 视野内的marker - */ - private var markerOptionsInView: MutableList = ArrayList() - - /** - * 自定义Marker弹出框 - * */ - private lateinit var v: View + private val regionRadius by lazy { LocaleConstant.RADIUS_SIZE.dp2px(requireContext()) } + private val infoPopup by lazy { MapWellPopup(requireContext()) } /** * 所有窨井列表信息集合 * */ - private var wellModels: MutableList = ArrayList() + private val wellModels = ArrayList() + private val backDrawables = HashMap() + private lateinit var wellViewModel: WellViewModel + private lateinit var orderViewModel: OrderViewModel + private lateinit var aMap: AMap + private var clusterOverlay: ClusterOverlay? = null override fun initViewBinding( inflater: LayoutInflater, @@ -106,6 +100,9 @@ } }) + //地图初始化 + initMap(savedInstanceState) + //初始化vm wellViewModel = ViewModelProvider(this)[WellViewModel::class.java] orderViewModel = ViewModelProvider(this)[OrderViewModel::class.java] @@ -120,25 +117,19 @@ val latitudeList: MutableList = ArrayList() val longitudeList: MutableList = ArrayList() it.data?.forEach { well -> - val lat = well.latGaode.toString() - val lng = well.lngGaode.toString() + val lat = well.latGaode + val lng = well.lngGaode if (lat.isNotBlank() && lng.isNotBlank()) { //返回true代表当前位置在大陆、港澳地区,反之不在 val latitude = lat.toDouble() val longitude = lng.toDouble() if (CoordinateConverter.isAMapDataAvailable(latitude, longitude)) { - //缓存所有设备详情,点击Marker时候需要 + //缓存所有井 wellModels.add(well) + //分别缓存经、纬度 latitudeList.add(latitude) longitudeList.add(longitude) - //将所有设备信息转化缓存为Marker点 - allMarkerOptions.add( - MarkerOptions() - .position(LatLng(latitude, longitude)) - .title(well.wellTypeName) - .snippet(well.wellName) - ) } } } @@ -160,12 +151,12 @@ val cameraPosition = CameraPosition(centerLatLng, 16f, 0f, 0f) val cameraUpdate = CameraUpdateFactory.newCameraPosition(cameraPosition) aMap.animateCamera(cameraUpdate, 1500, null) + + //显示点数据 + displayWellOnMap() } } - //地图初始化 - initMap(savedInstanceState) - //获取窨井监控数据 wellViewModel.countResultModel.observe(this) { binding.deployedWellView.text = it["bfWell"] @@ -220,17 +211,10 @@ uiSettings.isCompassEnabled = true uiSettings.zoomPosition = AMapOptions.ZOOM_POSITION_RIGHT_CENTER uiSettings.isTiltGesturesEnabled = false//不许地图随手势倾斜角度 + uiSettings.isRotateGesturesEnabled = false//不允许地图随手势改变方位 - // 地图加载成功监听 - aMap.addOnMapLoadedListener(this) // 地图缩放监听 aMap.addOnCameraChangeListener(this) - // marker 点击事件监听 - aMap.addOnMarkerClickListener(this) - // 点击marker弹出自定义popup - aMap.setInfoWindowAdapter(this) - //信息窗点击事件 - aMap.addOnInfoWindowClickListener(this) } override fun initEvent() { @@ -259,9 +243,111 @@ } - override fun onMapLoaded() { - //地图加载成功之后显示聚合点数据 - initClustersMarkers() + private fun displayWellOnMap() { + clusterOverlay?.onDestroy() + val clusterItems = ArrayList() + + wellModels.forEach { + val latitude = it.latGaode.toDouble() + val longitude = it.lngGaode.toDouble() + + val latLng = LatLng(latitude, longitude, false) + val regionItem = RegionItem(latLng, it) + clusterItems.add(regionItem) + } + + clusterOverlay = ClusterOverlay(requireContext(), aMap, clusterItems, regionRadius) + clusterOverlay?.setClusterRender { clusterNum -> + //聚合圆半径 + val radius = 100.dp2px(requireContext()) + if (clusterNum == 0) { + var bitmapDrawable = backDrawables[0] + if (bitmapDrawable == null) { + bitmapDrawable = BitmapDrawable( + null, radius.drawCircle(Color.argb(159, 100, 149, 237)) + ) + backDrawables[0] = bitmapDrawable + } + bitmapDrawable + } + if (clusterNum == 1) { + var bitmapDrawable = backDrawables[1] + if (bitmapDrawable == null) { + bitmapDrawable = R.mipmap.well_location.convertDrawable(requireContext())!! + backDrawables[1] = bitmapDrawable + } + bitmapDrawable + } else if (clusterNum < 5) { + var bitmapDrawable = backDrawables[2] + if (bitmapDrawable == null) { + bitmapDrawable = BitmapDrawable( + null, radius.drawCircle(Color.argb(159, 100, 149, 237)) + ) + backDrawables[2] = bitmapDrawable + } + bitmapDrawable + } else if (clusterNum < 10) { + var bitmapDrawable = backDrawables[3] + if (bitmapDrawable == null) { + bitmapDrawable = BitmapDrawable( + null, radius.drawCircle(Color.argb(199, 30, 144, 255)) + ) + backDrawables[3] = bitmapDrawable + } + bitmapDrawable + } else { + var bitmapDrawable = backDrawables[4] + if (bitmapDrawable == null) { + bitmapDrawable = BitmapDrawable( + null, radius.drawCircle(Color.argb(235, 65, 105, 225)) + ) + backDrawables[4] = bitmapDrawable + } + bitmapDrawable + } + } + + clusterOverlay?.setOnClusterClickListener(object : ClusterOnClickListener { + override fun onMarkerClicked(marker: Marker?, items: List) { + if (items.size > 1) { + "请缩放地图比例在查看数据".show(requireContext()) + return + } + + var item: RegionItem? = null + val builder = LatLngBounds.Builder() + for (clusterItem in items) { + builder.include(clusterItem.position) + item = clusterItem as RegionItem + } + + item?.apply { + showWellPopup(well) + } + } + }) + } + + private fun showWellPopup(well: MapWellListModel.DataModel) { + infoPopup.set(well, object : MapWellPopup.OnPopupWindowClickListener { + override fun onPopupClicked(lat: Double, lng: Double) { + AlertControlDialog.Builder().setContext(requireContext()).setTitle("操作提示") + .setMessage("确定要前往吗").setNegativeButton("取消").setPositiveButton("确定") + .setOnDialogButtonClickListener(object : + AlertControlDialog.OnDialogButtonClickListener { + override fun onConfirmClick() { + RouteOnMap.startNavigation( + requireContext(), "", LatLng(lat, lng) + ) + } + + override fun onCancelClick() { + + } + }).build().show() + } + }) + infoPopup.showAsDropDown(binding.rightOptionView) } override fun onCameraChange(p0: CameraPosition?) { @@ -282,103 +368,10 @@ } } - //获取视野内的marker 根据聚合算法合成自定义的marker 显示视野内的marker override fun onCameraChangeFinish(p0: CameraPosition?) { //地图缩放之后显示聚合点数据 LoadingDialogHub.dismiss() httpCountDownTimer.cancel() - initClustersMarkers() - } - - private fun initClustersMarkers() { - 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 { - v = LayoutInflater.from(requireContext()).inflate(R.layout.popup_map_info, null) - - //显示闸井信息 - marker?.showInfoWindow() - return true - } - - override fun getInfoWindow(marker: Marker?): View { - //反射得到popup里面的控件对象 - val wellNameView = v.findViewById(R.id.wellNameView) - val wellCodeView = v.findViewById(R.id.wellCodeView) - val wellTypeView = v.findViewById(R.id.wellTypeView) - val wellStateView = v.findViewById(R.id.wellStateView) - val deepView = v.findViewById(R.id.deepView) - val locationView = v.findViewById(R.id.locationView) - - //绑定数据 - val clickedLatLng = marker?.position!! - wellModels.forEach { well -> - if (clickedLatLng.latitude == well.latGaode!!.toDouble() - && clickedLatLng.longitude == well.lngGaode!!.toDouble() - ) { - wellNameView.text = String.format("点位名称: ${well.wellName}") - wellCodeView.text = String.format("点位编号: ${well.wellCode}") - wellTypeView.text = String.format("点位类型: ${well.wellType.valueToType()}") - val bfztName = if (well.bfzt == "1") { - "已布防" - } else { - "已撤防" - } - wellStateView.text = String.format("布/撤防状态: $bfztName") - deepView.text = String.format("点位深度: ${well.deep}m") - locationView.text = String.format("详细位置: ${well.position}") - } - } - return v - } - - /** - * 此方法不能修改整个 InfoWindow 的背景和边框,无论自定义的样式是什么样,SDK 都会在最外层添加一个默认的边框 - * */ - override fun getInfoContents(p0: Marker?): View? = null - - override fun onInfoWindowClick(p0: Marker?) { - p0?.apply { - AlertControlDialog.Builder() - .setContext(requireContext()) - .setTitle("操作提示") - .setMessage("确定要前往吗") - .setNegativeButton("取消") - .setPositiveButton("确定") - .setOnDialogButtonClickListener(object : - AlertControlDialog.OnDialogButtonClickListener { - override fun onConfirmClick() { - val lat = position.latitude.toString() - val lng = position.longitude.toString() - if (lat.isBlank() || lng.isBlank()) { - "点位经纬度异常,无法开启导航".show(requireContext()) - return - } - RouteOnMap.startNavigation( - requireContext(), snippet, LatLng(lat.toDouble(), lng.toDouble()) - ) - } - - override fun onCancelClick() { - - } - }).build().show() - } } /***以下是地图生命周期管理************************************************************************/ 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 a54d213..bfa7a57 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 @@ -44,8 +44,8 @@ * 地图点位不带聚合效果 * */ class HomePageNoClusterFragment : KotlinBaseFragment(), - AMap.OnMapLoadedListener, AMap.OnCameraChangeListener, AMap.OnMarkerClickListener, - AMap.InfoWindowAdapter, AMap.OnInfoWindowClickListener { + AMap.OnCameraChangeListener, AMap.OnMarkerClickListener, AMap.InfoWindowAdapter, + AMap.OnInfoWindowClickListener { private val kTag = "NoClusterFragment" private val easyPopupWindow by lazy { EasyPopupWindow(requireContext()) } @@ -109,6 +109,9 @@ wellViewModel = ViewModelProvider(this)[WellViewModel::class.java] orderViewModel = ViewModelProvider(this)[OrderViewModel::class.java] + //地图初始化 + initMap(savedInstanceState) + //获取所有窨井数据 httpCountDownTimer.start() LoadingDialogHub.show(requireActivity(), "数据加载中,请稍后...") @@ -157,12 +160,12 @@ val cameraPosition = CameraPosition(centerLatLng, 16f, 0f, 0f) val cameraUpdate = CameraUpdateFactory.newCameraPosition(cameraPosition) aMap.animateCamera(cameraUpdate, 1500, null) + + //显示点数据 + displayWellOnMap() } } - //地图初始化 - initMap(savedInstanceState) - //获取窨井监控数据 wellViewModel.countResultModel.observe(this) { binding.deployedWellView.text = it["bfWell"] @@ -214,9 +217,8 @@ uiSettings.isCompassEnabled = true uiSettings.zoomPosition = AMapOptions.ZOOM_POSITION_RIGHT_CENTER uiSettings.isTiltGesturesEnabled = false//不许地图随手势倾斜角度 + uiSettings.isRotateGesturesEnabled = false//不允许地图随手势改变方位 - // 地图加载成功监听 - aMap.addOnMapLoadedListener(this) // 地图缩放监听 aMap.addOnCameraChangeListener(this) // marker 点击事件监听 @@ -253,11 +255,6 @@ } - override fun onMapLoaded() { - //地图加载成功之后显示聚合点数据 - initClustersMarkers() - } - override fun onCameraChange(p0: CameraPosition?) { } @@ -281,10 +278,9 @@ //地图缩放之后显示聚合点数据 LoadingDialogHub.dismiss() httpCountDownTimer.cancel() - initClustersMarkers() } - private fun initClustersMarkers() { + private fun displayWellOnMap() { val proj = aMap.projection val dm = resources.displayMetrics var screenLocation: Point diff --git a/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.java b/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.java deleted file mode 100644 index d8b18ef..0000000 --- a/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.java +++ /dev/null @@ -1,50 +0,0 @@ -package com.casic.app.smartwell.model; - -public class ErrorMessageModel { - - private int code; - private String data; - private String exceptionClazz; - private String message; - private boolean success; - - public int getCode() { - return code; - } - - public void setCode(int code) { - this.code = code; - } - - public String getData() { - return data; - } - - public void setData(String data) { - this.data = data; - } - - public String getExceptionClazz() { - return exceptionClazz; - } - - public void setExceptionClazz(String exceptionClazz) { - this.exceptionClazz = exceptionClazz; - } - - public String getMessage() { - return message; - } - - public void setMessage(String message) { - this.message = message; - } - - public boolean isSuccess() { - return success; - } - - public void setSuccess(boolean success) { - this.success = success; - } -} \ No newline at end of file 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 new file mode 100644 index 0000000..215ac0c --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/PipelineModel.java @@ -0,0 +1,328 @@ +package com.casic.app.smartwell.model; + +import java.util.List; + +public class PipelineModel { + + private Integer code; + private DataModel data; + private String message; + private Boolean success; + + public Integer getCode() { + return code; + } + + public void setCode(Integer code) { + this.code = code; + } + + public DataModel getData() { + return data; + } + + public void setData(DataModel data) { + this.data = data; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + public Boolean getSuccess() { + return success; + } + + public void setSuccess(Boolean success) { + this.success = success; + } + + public static class DataModel { + private List rows; + private Integer total; + + public List getRows() { + return rows; + } + + public void setRows(List rows) { + this.rows = rows; + } + + public Integer getTotal() { + return total; + } + + public void setTotal(Integer total) { + this.total = total; + } + + 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 getBuryMode() { + return buryMode; + } + + public void setBuryMode(String buryMode) { + this.buryMode = buryMode; + } + + public String getConstructEra() { + return constructEra; + } + + public void setConstructEra(String constructEra) { + this.constructEra = constructEra; + } + + 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; + } + } + } +} 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 06d3d2b..4f38a2c 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 = 100 //相距多少米才聚合,单位:米 + const val RADIUS_SIZE = 80 //相距多少米才聚合,单位:米 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:11308" + // 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 0d5f3fa..991e1db 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 @@ -312,4 +312,14 @@ @Header("token") token: String, @Field("clientid") deviceCode: String ): String + + /** + * 管线位置数据 + */ + @GET("/pipeline/listPage") + suspend fun getPipeline( + @Header("token") token: String, + @Query("limit") limit: Int, + @Query("offset") offset: Int + ): String } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt index 1a0ce22..4050067 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt @@ -294,4 +294,11 @@ suspend fun registerPush(clientId: String): String { return api.registerPush(AuthenticationHelper.token!!, clientId) } + + /** + * 管线位置数据 + */ + suspend fun getPipeline(): String { + return api.getPipeline(AuthenticationHelper.token!!, 2000, 1) + } } \ No newline at end of file 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 9270fa1..4ca5a5e 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.HomePageNoClusterFragment +import com.casic.app.smartwell.fragment.HomePageHaveClusterFragment 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/vm/AlarmViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/AlarmViewModel.kt index 9cff08c..e7acc17 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/AlarmViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/AlarmViewModel.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.AlarmContentModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager import com.google.gson.Gson @@ -16,7 +16,7 @@ fun getAlarmContentType(alarmType: String) = launch({ val response = RetrofitServiceManager.getAlarmContentType(alarmType) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { listModel.value = gson.fromJson( response, object : TypeToken() {}.type diff --git a/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt index 5e5b163..895dedd 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.PublicKeyModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager import com.google.gson.Gson @@ -18,7 +18,7 @@ fun getPublicKey() = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.authenticate() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { keyModel.value = gson.fromJson( response, object : TypeToken() {}.type diff --git a/app/src/main/java/com/casic/app/smartwell/vm/DeviceViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/DeviceViewModel.kt index db5ccf6..899a962 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/DeviceViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/DeviceViewModel.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.DeviceDetailModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager import com.google.gson.Gson @@ -16,7 +16,7 @@ fun getDeviceDetail(deviceCode: String) = launch({ val response = RetrofitServiceManager.getDeviceDetail(deviceCode) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { detailModel.value = gson.fromJson( response, object : TypeToken() {}.type diff --git a/app/src/main/java/com/casic/app/smartwell/vm/LoginViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/LoginViewModel.kt index cd8b8a9..a417398 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/LoginViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/LoginViewModel.kt @@ -2,7 +2,7 @@ import androidx.lifecycle.MutableLiveData import com.casic.app.smartwell.base.BaseApplication -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.CommonResultModel import com.casic.app.smartwell.model.LoginResultModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -21,7 +21,7 @@ fun enter(account: String, secretKey: String) = launch({ val response = RetrofitServiceManager.login(account, secretKey) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success enterResultModel.value = gson.fromJson( @@ -38,7 +38,7 @@ fun out() = launch({ val response = RetrofitServiceManager.loginOut() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { outResultModel.value = gson.fromJson( response, object : TypeToken() {}.type diff --git a/app/src/main/java/com/casic/app/smartwell/vm/OperationViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/OperationViewModel.kt index 8943ed3..37e115f 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/OperationViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/OperationViewModel.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.vm import com.casic.app.smartwell.base.BaseApplication -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager import com.pengxh.kt.lite.base.BaseViewModel import com.pengxh.kt.lite.extensions.launch @@ -16,7 +16,7 @@ fun acceptWorkOrder(id: String) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.acceptWorkOrder(id) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success "接单成功".show(BaseApplication.get()) @@ -35,7 +35,7 @@ loadState.value = LoadState.Loading val response = RetrofitServiceManager.confirmWorkOrder(id, firstState, firstStatePhotos, needHandle) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success "工单确认成功".show(BaseApplication.get()) @@ -50,7 +50,7 @@ fun transferWorkOrder(id: String, userId: String) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.transferWorkOrder(id, userId) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success "转单成功".show(BaseApplication.get()) @@ -65,7 +65,7 @@ fun completeWorkOrder(id: String, handleMessage: String, handlePhotos: String) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.completeWorkOrder(id, handleMessage, handlePhotos) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success "工单处理成功".show(BaseApplication.get()) diff --git a/app/src/main/java/com/casic/app/smartwell/vm/OrderViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/OrderViewModel.kt index 4cb26b7..d2fad86 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/OrderViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/OrderViewModel.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.OrderDetailModel import com.casic.app.smartwell.model.OrderListModel import com.casic.app.smartwell.model.OrderStatusModel @@ -37,7 +37,7 @@ val response = RetrofitServiceManager.getSearchResult( keywords, alarmContent, alarmLevel, jobStatus, deptId, beginTime, endTime, offset ) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success searchResult.value = gson.fromJson( @@ -53,7 +53,7 @@ fun getWorkOrderListByState(jobStatus: String, page: Int) = launch({ val response = RetrofitServiceManager.getWorkOrderList(jobStatus, page) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { orderList.value = gson.fromJson( response, object : TypeToken() {}.type @@ -65,7 +65,7 @@ fun getNotAcceptOderList(page: Int) = launch({ val response = RetrofitServiceManager.getNotAcceptOderList(page) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { orderList.value = gson.fromJson( response, object : TypeToken() {}.type @@ -77,7 +77,7 @@ fun getNotHandleOderList(page: Int) = launch({ val response = RetrofitServiceManager.getNotHandleOderList(page) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { orderList.value = gson.fromJson( response, object : TypeToken() {}.type @@ -89,7 +89,7 @@ fun countWorkOrderByState() = launch({ val response = RetrofitServiceManager.countWorkOrderByState() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { val map = HashMap(4) @@ -107,7 +107,7 @@ fun getOrderStatus() = launch({ val response = RetrofitServiceManager.getOrderStatus() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { orderStatusModel.value = gson.fromJson( response, object : TypeToken() {}.type @@ -120,7 +120,7 @@ fun getWorkOrderDetail(id: String) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.getWorkOrderDetail(id) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success detailModel.value = gson.fromJson( diff --git a/app/src/main/java/com/casic/app/smartwell/vm/PipelineViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/PipelineViewModel.kt new file mode 100644 index 0000000..60c1e2f --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/vm/PipelineViewModel.kt @@ -0,0 +1,28 @@ +package com.casic.app.smartwell.vm + +import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.extensions.getResponseCode +import com.casic.app.smartwell.model.PipelineModel +import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken +import com.pengxh.kt.lite.base.BaseViewModel +import com.pengxh.kt.lite.extensions.launch + +class PipelineViewModel : BaseViewModel() { + + private val gson by lazy { Gson() } + val lineResult = MutableLiveData() + + fun getPipeline() = launch({ + val response = RetrofitServiceManager.getPipeline() + val responseCode = response.getResponseCode() + if (responseCode == 200) { + lineResult.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } + }, { + it.printStackTrace() + }) +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/PushViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/PushViewModel.kt index 9279815..12fd610 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/PushViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/PushViewModel.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.CommonResultModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager import com.google.gson.Gson @@ -16,7 +16,7 @@ fun registerPush(clientId: String) = launch({ val response = RetrofitServiceManager.registerPush(clientId) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { registerResultModel.value = gson.fromJson( response, object : TypeToken() {}.type diff --git a/app/src/main/java/com/casic/app/smartwell/vm/UploadImageViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/UploadImageViewModel.kt index 8d6744e..9707eeb 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/UploadImageViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/UploadImageViewModel.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.CommonResultModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager import com.google.gson.Gson @@ -19,7 +19,7 @@ fun uploadImage(image: File) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.uploadImage(image) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success resultModel.value = gson.fromJson( diff --git a/app/src/main/java/com/casic/app/smartwell/vm/UserViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/UserViewModel.kt index 31a4d4c..070c35a 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/UserViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/UserViewModel.kt @@ -2,7 +2,7 @@ import androidx.lifecycle.MutableLiveData import com.casic.app.smartwell.base.BaseApplication -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.SubordinateModel import com.casic.app.smartwell.model.UserDetailModel import com.casic.app.smartwell.model.VersionResultModel @@ -25,7 +25,7 @@ fun getUserDetail() = launch({ val response = RetrofitServiceManager.getUserDetail() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { val userDetail = gson.fromJson( response, object : TypeToken() {}.type @@ -48,7 +48,7 @@ * */ fun getSubordinate(hasMine: String?, deptId: String?, roleTips: String?) = launch({ val response = RetrofitServiceManager.getSubordinate(hasMine, deptId, roleTips) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { subordinateModel.value = gson.fromJson( response, object : TypeToken() {}.type @@ -61,7 +61,7 @@ fun changePassword(oldPwd: String, newPwd: String) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.changePassword(oldPwd, newPwd) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success "修改成功,请重新登录".show(BaseApplication.get()) @@ -76,7 +76,7 @@ fun updateVersion() = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.updateVersion() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success versionResultModel.value = gson.fromJson( diff --git a/app/src/main/java/com/casic/app/smartwell/vm/WellViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/WellViewModel.kt index 3d41e9b..9e42e36 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/WellViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/WellViewModel.kt @@ -2,8 +2,7 @@ import androidx.lifecycle.MutableLiveData import com.casic.app.smartwell.base.BaseApplication -import com.casic.app.smartwell.extensions.separateResponseCode -import com.casic.app.smartwell.extensions.toErrorMessage +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.AuthorDeptModel import com.casic.app.smartwell.model.CommonResultModel import com.casic.app.smartwell.model.MapWellListModel @@ -32,7 +31,7 @@ fun countWellByState() = launch({ val response = RetrofitServiceManager.countWellByState() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { val map = HashMap(3) @@ -57,7 +56,7 @@ fun getWellType() = launch({ val response = RetrofitServiceManager.getWellType() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { wellTypeModel.value = gson.fromJson( response, object : TypeToken() {}.type @@ -70,7 +69,7 @@ fun getWellDetail(id: String) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.getWellDetail(id) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success wellDetailModel.value = gson.fromJson( @@ -87,7 +86,7 @@ fun getOperationResult(id: String, state: String) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.getOperationResult(id, state) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success "操作成功".show(BaseApplication.get()) @@ -105,7 +104,7 @@ fun getMonitorResult(id: String) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.getMonitorResult(id) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success monitorModel.value = gson.fromJson( @@ -125,7 +124,7 @@ val response = RetrofitServiceManager.getWellListByPage( keywords, wellType, deptid, bfzt, page ) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { listModel.value = gson.fromJson( response, object : TypeToken() {}.type @@ -137,13 +136,11 @@ fun getWellList() = launch({ val response = RetrofitServiceManager.getWellList() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { totalWellModel.value = gson.fromJson( response, object : TypeToken() {}.type ) - } else { - response.toErrorMessage().show(BaseApplication.get()) } }, { it.printStackTrace() diff --git a/app/src/main/java/com/casic/app/smartwell/widgets/GaoDeClusterMarkerView.kt b/app/src/main/java/com/casic/app/smartwell/widgets/GaoDeClusterMarkerView.kt deleted file mode 100644 index 1f375df..0000000 --- a/app/src/main/java/com/casic/app/smartwell/widgets/GaoDeClusterMarkerView.kt +++ /dev/null @@ -1,100 +0,0 @@ -package com.casic.app.smartwell.widgets - -import android.content.Context -import android.graphics.Bitmap -import android.graphics.Point -import android.view.Gravity -import android.view.LayoutInflater -import android.view.View -import android.widget.TextView -import com.amap.api.maps.Projection -import com.amap.api.maps.model.BitmapDescriptorFactory -import com.amap.api.maps.model.LatLng -import com.amap.api.maps.model.LatLngBounds -import com.amap.api.maps.model.MarkerOptions -import com.casic.app.smartwell.R -import com.pengxh.kt.lite.extensions.toBitmap -import java.util.* - -class GaoDeClusterMarkerView( - private val context: Context, firstMarkers: MarkerOptions, projection: Projection, gridSize: Int -) { - //当前可观区域里的 聚合过之后的集合 - private val includeMarkers: ArrayList - - // 创建区域 - val bounds: LatLngBounds - var options: MarkerOptions = MarkerOptions() - - init { - val screenLocation = projection.toScreenLocation(firstMarkers.position) - //范围类 - val southwestPoint = Point(screenLocation.x - gridSize, screenLocation.y + gridSize) - //范围类 - val northeastPoint = Point(screenLocation.x + gridSize, screenLocation.y - gridSize) - bounds = LatLngBounds( - projection.fromScreenLocation(southwestPoint), - projection.fromScreenLocation(northeastPoint) - ) - //设置初始化marker属性 - options.anchor(0.5f, 1.3f) - .title(firstMarkers.title) - .position(firstMarkers.position) - .icon(firstMarkers.icon) - .snippet(firstMarkers.snippet) - .draggable(false) - includeMarkers = ArrayList() - includeMarkers.add(firstMarkers) - } - - /** - * 添加marker - */ - fun addMarker(markerOptions: MarkerOptions) { - includeMarkers.add(markerOptions) // 添加到列表中 - } - - /** - * 设置聚合点的中心位置以及图标 - */ - fun setPositionAndIcon() { - val size = includeMarkers.size - var lat = 0.0 - var lng = 0.0 - // 一个的时候 - if (size == 1) { //设置marker单个属性 - // 设置marker位置 - options.position( - LatLng( - includeMarkers[0].position.latitude, includeMarkers[0].position.longitude - ) - ) - } else { // 聚合的时候 - //设置marker聚合属性 - for (op in includeMarkers) { - lat += op.position.latitude - lng += op.position.longitude - } - // 设置marker的位置为中心位置为聚集点的平均位置 - options.position(LatLng(lat / size, lng / size)) - } - options.icon(BitmapDescriptorFactory.fromBitmap(getBitmap(size))) - } - - /** - * marker视图 - */ - private fun getBitmap(num: Int): Bitmap? { - val view = LayoutInflater.from(context).inflate(R.layout.marker_gaode, null) - val wellCountView = view.findViewById(R.id.wellCountView) - return if (num > 1) { - wellCountView.visibility = View.VISIBLE - wellCountView.text = String.format("${num}个") - wellCountView.gravity = Gravity.CENTER - view.toBitmap() - } else { - wellCountView.visibility = View.GONE - BitmapDescriptorFactory.fromResource(R.mipmap.well_location).bitmap - } - } -} \ No newline at end of file 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 new file mode 100644 index 0000000..ec455dd --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/widgets/MapWellPopup.kt @@ -0,0 +1,58 @@ +package com.casic.app.smartwell.widgets + +import android.content.Context +import android.view.LayoutInflater +import android.view.ViewGroup +import android.widget.LinearLayout +import android.widget.PopupWindow +import android.widget.TextView +import com.casic.app.smartwell.R +import com.casic.app.smartwell.extensions.valueToType +import com.casic.app.smartwell.model.MapWellListModel + +class MapWellPopup constructor(context: Context) : PopupWindow() { + + init { + width = ViewGroup.LayoutParams.MATCH_PARENT + height = ViewGroup.LayoutParams.WRAP_CONTENT + isOutsideTouchable = true + isFocusable = true + animationStyle = R.style.MapPopupAnimation + setBackgroundDrawable(null) + contentView = LayoutInflater.from(context).inflate( + R.layout.popup_map_info, null, false + ) + } + + fun set(well: MapWellListModel.DataModel, windowClickListener: OnPopupWindowClickListener) { + //反射得到popup里面的控件对象 + val rootView = contentView.findViewById(R.id.rootView) + val wellNameView = contentView.findViewById(R.id.wellNameView) + val wellCodeView = contentView.findViewById(R.id.wellCodeView) + val wellTypeView = contentView.findViewById(R.id.wellTypeView) + val wellStateView = contentView.findViewById(R.id.wellStateView) + val deepView = contentView.findViewById(R.id.deepView) + val locationView = contentView.findViewById(R.id.locationView) + + //绑定数据 + wellNameView.text = String.format("点位名称: ${well.wellName}") + wellCodeView.text = String.format("点位编号: ${well.wellCode}") + wellTypeView.text = String.format("点位类型: ${well.wellType.valueToType()}") + val bfztName = if (well.bfzt == "1") { + "已布防" + } else { + "已撤防" + } + wellStateView.text = String.format("布/撤防状态: $bfztName") + deepView.text = String.format("点位深度: ${well.deep}m") + locationView.text = String.format("详细位置: ${well.position}") + + rootView.setOnClickListener { + windowClickListener.onPopupClicked(well.latGaode.toDouble(), well.lngGaode.toDouble()) + } + } + + interface OnPopupWindowClickListener { + fun onPopupClicked(lat: Double, lng: Double) + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/widgets/cluster/Cluster.java b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/Cluster.java new file mode 100644 index 0000000..9455ccd --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/Cluster.java @@ -0,0 +1,43 @@ +package com.casic.app.smartwell.widgets.cluster; + +import com.amap.api.maps.model.LatLng; +import com.amap.api.maps.model.Marker; + +import java.util.ArrayList; +import java.util.List; + +public class Cluster { + private final LatLng latLng; + private final List clusterItems; + private Marker marker; + + + public Cluster(LatLng latLng) { + this.latLng = latLng; + clusterItems = new ArrayList<>(); + } + + public void addClusterItem(ClusterItem clusterItem) { + clusterItems.add(clusterItem); + } + + public int getClusterCount() { + return clusterItems.size(); + } + + public LatLng getCenterLatLng() { + return latLng; + } + + public void setMarker(Marker marker) { + this.marker = marker; + } + + public Marker getMarker() { + return marker; + } + + public List getClusterItems() { + return clusterItems; + } +} diff --git a/app/src/main/java/com/casic/app/smartwell/widgets/cluster/ClusterItem.java b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/ClusterItem.java new file mode 100644 index 0000000..f5d9a9d --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/ClusterItem.java @@ -0,0 +1,10 @@ +package com.casic.app.smartwell.widgets.cluster; + +import com.amap.api.maps.model.LatLng; + +public interface ClusterItem { + /** + * 返回聚合元素的地理位置 + */ + LatLng getPosition(); +} diff --git a/app/src/main/java/com/casic/app/smartwell/widgets/cluster/ClusterOnClickListener.java b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/ClusterOnClickListener.java new file mode 100644 index 0000000..0efa1f1 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/ClusterOnClickListener.java @@ -0,0 +1,15 @@ +package com.casic.app.smartwell.widgets.cluster; + +import com.amap.api.maps.model.Marker; + +import java.util.List; + +public interface ClusterOnClickListener { + /** + * 点击聚合点的回调处理函数 + * + * @param marker 点击的聚合点 + * @param items 聚合点所包含的元素 + */ + void onMarkerClicked(Marker marker, List items); +} 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 new file mode 100644 index 0000000..40df562 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/ClusterOverlay.java @@ -0,0 +1,349 @@ +package com.casic.app.smartwell.widgets.cluster; + +import android.content.Context; +import android.graphics.Color; +import android.os.Handler; +import android.os.HandlerThread; +import android.os.Looper; +import android.os.Message; +import android.util.TypedValue; +import android.view.Gravity; +import android.widget.TextView; + +import com.amap.api.maps.AMap; +import com.amap.api.maps.AMapUtils; +import com.amap.api.maps.model.BitmapDescriptor; +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.LatLngBounds; +import com.amap.api.maps.model.Marker; +import com.amap.api.maps.model.MarkerOptions; +import com.amap.api.maps.model.animation.AlphaAnimation; +import com.casic.app.smartwell.R; + +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.CopyOnWriteArrayList; + +/** + * 整体设计采用了两个线程,一个线程用于计算组织聚合数据,一个线程负责处理Marker相关操作 + */ +public class ClusterOverlay implements AMap.OnCameraChangeListener, AMap.OnMarkerClickListener { + private final AMap amap; + private final Context context; + private final List clusterItems; + private final List clusters; + private final int clusterSize; + private ClusterOnClickListener clusterClickListener; + private ClusterRender clusterRender; + private final CopyOnWriteArrayList addMarkers = new CopyOnWriteArrayList<>(); + private double clusterDistance; + private final HandlerThread markerHandlerThread = new HandlerThread("addMarker"); + private final HandlerThread signClusterThread = new HandlerThread("calculateCluster"); + private Handler markerHandler; + private Handler signClusterHandler; + private float pxInMeters; + private boolean isCanceled = false; + private final AlphaAnimation addAnimation = new AlphaAnimation(0, 1); + + /** + * 构造函数,批量添加聚合元素时,调用此构造函数 + */ + public ClusterOverlay(Context context, AMap amap, int clusterSize) { + this(context, amap, null, clusterSize); + } + + /** + * 构造函数,批量添加聚合元素时,调用此构造函数 + */ + public ClusterOverlay(Context context, AMap amap, List clusterItems, int clusterSize) { + if (clusterItems != null) { + this.clusterItems = clusterItems; + } else { + this.clusterItems = new ArrayList<>(); + } + this.context = context; + this.clusters = new ArrayList<>(); + this.amap = amap; + this.clusterSize = clusterSize; + this.pxInMeters = amap.getScalePerPixel(); + this.clusterDistance = pxInMeters * clusterSize; + amap.setOnCameraChangeListener(this); + amap.setOnMarkerClickListener(this); + initThreadHandler(); + assignClusters(); + } + + /** + * 设置聚合点的点击事件 + */ + public void setOnClusterClickListener(ClusterOnClickListener clusterClickListener) { + this.clusterClickListener = clusterClickListener; + } + + /** + * 添加一个聚合点 + */ + public void addClusterItem(ClusterItem item) { + Message message = Message.obtain(); + message.what = SignClusterHandler.CALCULATE_SINGLE_CLUSTER; + message.obj = item; + signClusterHandler.sendMessage(message); + } + + /** + * 设置聚合元素的渲染样式,不设置则默认为气泡加数字形式进行渲染 + */ + public void setClusterRender(ClusterRender render) { + this.clusterRender = render; + } + + public void onDestroy() { + isCanceled = true; + signClusterHandler.removeCallbacksAndMessages(null); + markerHandler.removeCallbacksAndMessages(null); + signClusterThread.quit(); + markerHandlerThread.quit(); + for (Marker marker : addMarkers) { + marker.remove(); + } + addMarkers.clear(); + } + + //初始化Handler + private void initThreadHandler() { + markerHandlerThread.start(); + signClusterThread.start(); + markerHandler = new MarkerHandler(markerHandlerThread.getLooper()); + signClusterHandler = new SignClusterHandler(signClusterThread.getLooper()); + } + + @Override + public void onCameraChange(CameraPosition arg0) { + + } + + @Override + public void onCameraChangeFinish(CameraPosition arg0) { + pxInMeters = amap.getScalePerPixel(); + clusterDistance = pxInMeters * clusterSize; + assignClusters(); + } + + @Override + public boolean onMarkerClick(Marker marker) { + if (clusterClickListener == null) { + return true; + } + Cluster cluster = (Cluster) marker.getObject(); + if (cluster != null) { + clusterClickListener.onMarkerClicked(marker, cluster.getClusterItems()); + return true; + } + return false; + } + + /** + * 将聚合元素添加至地图上 + */ + private void addClusterToMap(List clusters) { + ArrayList removeMarkers = new ArrayList<>(addMarkers); + AlphaAnimation alphaAnimation = new AlphaAnimation(1, 0); + RemoveAnimationListener removeAnimationListener = new RemoveAnimationListener(removeMarkers); + for (Marker marker : removeMarkers) { + marker.setAnimation(alphaAnimation); + marker.setAnimationListener(removeAnimationListener); + marker.startAnimation(); + } + + for (Cluster cluster : clusters) { + addSingleClusterToMap(cluster); + } + } + + /** + * 将单个聚合元素添加至地图显示 + */ + private void addSingleClusterToMap(Cluster cluster) { + LatLng latlng = cluster.getCenterLatLng(); + MarkerOptions markerOptions = new MarkerOptions(); + markerOptions.icon(getBitmapDes(cluster.getClusterCount())).position(latlng); + Marker marker = amap.addMarker(markerOptions); + marker.setAnimation(addAnimation); + marker.setObject(cluster); + + marker.startAnimation(); + cluster.setMarker(marker); + addMarkers.add(marker); + } + + private void calculateClusters() { + isCanceled = false; + clusters.clear(); + LatLngBounds visibleBounds = amap.getProjection().getVisibleRegion().latLngBounds; + for (ClusterItem clusterItem : clusterItems) { + if (isCanceled) { + return; + } + LatLng latlng = clusterItem.getPosition(); + if (visibleBounds.contains(latlng)) { + Cluster cluster = getCluster(latlng, clusters); + if (cluster == null) { + cluster = new Cluster(latlng); + clusters.add(cluster); + } + cluster.addClusterItem(clusterItem); + } + } + + //复制一份数据,规避同步 + List tempClusters = new ArrayList<>(clusters); + Message message = Message.obtain(); + message.what = MarkerHandler.ADD_CLUSTER_LIST; + message.obj = tempClusters; + if (isCanceled) { + return; + } + markerHandler.sendMessage(message); + } + + /** + * 对点进行聚合 + */ + private void assignClusters() { + isCanceled = true; + signClusterHandler.removeMessages(SignClusterHandler.CALCULATE_CLUSTER); + signClusterHandler.sendEmptyMessage(SignClusterHandler.CALCULATE_CLUSTER); + } + + /** + * 在已有的聚合基础上,对添加的单个元素进行聚合 + */ + private void calculateSingleCluster(ClusterItem clusterItem) { + LatLngBounds visibleBounds = amap.getProjection().getVisibleRegion().latLngBounds; + LatLng latlng = clusterItem.getPosition(); + if (!visibleBounds.contains(latlng)) { + return; + } + Cluster cluster = getCluster(latlng, clusters); + if (cluster != null) { + cluster.addClusterItem(clusterItem); + Message message = Message.obtain(); + message.what = MarkerHandler.UPDATE_SINGLE_CLUSTER; + + message.obj = cluster; + markerHandler.removeMessages(MarkerHandler.UPDATE_SINGLE_CLUSTER); + markerHandler.sendMessageDelayed(message, 5); + } else { + cluster = new Cluster(latlng); + clusters.add(cluster); + cluster.addClusterItem(clusterItem); + Message message = Message.obtain(); + message.what = MarkerHandler.ADD_SINGLE_CLUSTER; + message.obj = cluster; + markerHandler.sendMessage(message); + } + } + + /** + * 根据一个点获取是否可以依附的聚合点,没有则返回null + */ + private Cluster getCluster(LatLng latLng, List clusters) { + for (Cluster cluster : clusters) { + LatLng clusterCenterPoint = cluster.getCenterLatLng(); + double distance = AMapUtils.calculateLineDistance(latLng, clusterCenterPoint); + if (distance < clusterDistance && amap.getCameraPosition().zoom < 19) { + return cluster; + } + } + return null; + } + + + /** + * 获取每个聚合点的绘制样式 + */ + private BitmapDescriptor getBitmapDes(int num) { + TextView textView = new TextView(context); + if (num > 1) { + String tile = String.valueOf(num); + textView.setText(tile); + } + textView.setGravity(Gravity.CENTER); + textView.setTextColor(Color.BLACK); + textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 15); + if (clusterRender != null && clusterRender.getDrawableByCount(num) != null) { + textView.setBackgroundDrawable(clusterRender.getDrawableByCount(num)); + } else { + textView.setBackgroundResource(R.mipmap.well_location); + } + return BitmapDescriptorFactory.fromView(textView); + } + + /** + * 更新已加入地图聚合点的样式 + */ + private void updateCluster(Cluster cluster) { + Marker marker = cluster.getMarker(); + marker.setIcon(getBitmapDes(cluster.getClusterCount())); + } + + /** + * 处理market添加,更新等操作 + */ + class MarkerHandler extends Handler { + + static final int ADD_CLUSTER_LIST = 0; + + static final int ADD_SINGLE_CLUSTER = 1; + + static final int UPDATE_SINGLE_CLUSTER = 2; + + public MarkerHandler(Looper looper) { + super(looper); + } + + public void handleMessage(Message message) { + switch (message.what) { + case ADD_CLUSTER_LIST: + List clusters = (List) message.obj; + addClusterToMap(clusters); + break; + case ADD_SINGLE_CLUSTER: + Cluster cluster = (Cluster) message.obj; + addSingleClusterToMap(cluster); + break; + case UPDATE_SINGLE_CLUSTER: + Cluster updateCluster = (Cluster) message.obj; + updateCluster(updateCluster); + break; + } + } + } + + /** + * 处理聚合点算法线程 + */ + class SignClusterHandler extends Handler { + static final int CALCULATE_CLUSTER = 0; + static final int CALCULATE_SINGLE_CLUSTER = 1; + + public SignClusterHandler(Looper looper) { + super(looper); + } + + public void handleMessage(Message message) { + switch (message.what) { + case CALCULATE_CLUSTER: + calculateClusters(); + break; + case CALCULATE_SINGLE_CLUSTER: + ClusterItem item = (ClusterItem) message.obj; + clusterItems.add(item); + calculateSingleCluster(item); + break; + } + } + } +} diff --git a/app/src/main/java/com/casic/app/smartwell/widgets/cluster/ClusterRender.java b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/ClusterRender.java new file mode 100644 index 0000000..427ff14 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/ClusterRender.java @@ -0,0 +1,10 @@ +package com.casic.app.smartwell.widgets.cluster; + +import android.graphics.drawable.Drawable; + +public interface ClusterRender { + /** + * 根据聚合点的元素数目返回渲染背景样式 + */ + Drawable getDrawableByCount(int clusterNum); +} diff --git a/app/src/main/java/com/casic/app/smartwell/widgets/cluster/RegionItem.java b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/RegionItem.java new file mode 100644 index 0000000..7b2b6c4 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/RegionItem.java @@ -0,0 +1,23 @@ +package com.casic.app.smartwell.widgets.cluster; + +import com.amap.api.maps.model.LatLng; +import com.casic.app.smartwell.model.MapWellListModel; + +public class RegionItem implements ClusterItem { + private final LatLng latLng; + private final MapWellListModel.DataModel well; + + public RegionItem(LatLng latLng, MapWellListModel.DataModel well) { + this.latLng = latLng; + this.well = well; + } + + @Override + public LatLng getPosition() { + return latLng; + } + + public MapWellListModel.DataModel getWell() { + return well; + } +} diff --git a/app/src/main/java/com/casic/app/smartwell/widgets/cluster/RemoveAnimationListener.java b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/RemoveAnimationListener.java new file mode 100644 index 0000000..c9c5e84 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/RemoveAnimationListener.java @@ -0,0 +1,30 @@ +package com.casic.app.smartwell.widgets.cluster; + +import com.amap.api.maps.model.Marker; +import com.amap.api.maps.model.animation.Animation; + +import java.util.List; + +/** + * marker渐变动画,动画结束后将Marker删除 + */ +public class RemoveAnimationListener implements Animation.AnimationListener { + private final List removeMarkers; + + public RemoveAnimationListener(List removeMarkers) { + this.removeMarkers = removeMarkers; + } + + @Override + public void onAnimationStart() { + + } + + @Override + public void onAnimationEnd() { + for (Marker marker : removeMarkers) { + marker.remove(); + } + removeMarkers.clear(); + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/extensions/Int.kt b/app/src/main/java/com/casic/app/smartwell/extensions/Int.kt index de0617b..a0a5e33 100644 --- a/app/src/main/java/com/casic/app/smartwell/extensions/Int.kt +++ b/app/src/main/java/com/casic/app/smartwell/extensions/Int.kt @@ -1,9 +1,24 @@ package com.casic.app.smartwell.extensions +import android.graphics.Bitmap +import android.graphics.Canvas +import android.graphics.Paint +import android.graphics.RectF + fun Int.toLevel(): String { return if (this == 0) { "" } else { this.toString() } +} + +fun Int.drawCircle(color: Int): Bitmap? { + val bitmap = Bitmap.createBitmap(this * 2, this * 2, Bitmap.Config.ARGB_8888) + val canvas = Canvas(bitmap) + val paint = Paint() + val rectF = RectF(0f, 0f, (this * 2).toFloat(), (this * 2).toFloat()) + paint.color = color + canvas.drawArc(rectF, 0f, 360f, true, paint) + return bitmap } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt index 6b6ca3e..5e45534 100644 --- a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt +++ b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt @@ -2,17 +2,13 @@ import android.content.Context import com.casic.app.smartwell.callback.OnImageCompressListener -import com.casic.app.smartwell.model.ErrorMessageModel import com.casic.app.smartwell.utils.LocaleConstant -import com.google.gson.Gson -import com.google.gson.reflect.TypeToken +import com.google.gson.JsonParser import com.pengxh.kt.lite.extensions.createCompressImageDir import com.pengxh.kt.lite.utils.SaveKeyValues -import org.json.JSONObject import top.zibin.luban.Luban import top.zibin.luban.OnCompressListener import java.io.File -import java.util.Locale /** * String扩展方法 @@ -74,18 +70,22 @@ } } -fun String.separateResponseCode(): Int { +fun String.getResponseCode(): Int { if (this.isBlank()) { return 404 } - return JSONObject(this).getInt("code") + val element = JsonParser.parseString(this) + val jsonObject = element.asJsonObject + return jsonObject.get("code").asInt } -fun String.toErrorMessage(): String { - val errorModel = Gson().fromJson( - this, object : TypeToken() {}.type - ) - return errorModel.message.toString() +fun String.getResponseMessage(): String { + if (this.isBlank()) { + return "" + } + val element = JsonParser.parseString(this) + val jsonObject = element.asJsonObject + return jsonObject.get("message").asString } fun String.compressImage(context: Context, listener: OnImageCompressListener) { @@ -93,9 +93,6 @@ .load(this) .ignoreBy(100) .setTargetDir(context.createCompressImageDir().toString()) - .filter { - !(it.isBlank() || it.lowercase(Locale.getDefault()).endsWith(".gif")) - } .setCompressListener(object : OnCompressListener { override fun onStart() { 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 96df110..cd25fca 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 @@ -1,26 +1,25 @@ package com.casic.app.smartwell.fragment -import android.graphics.Point +import android.graphics.Color +import android.graphics.drawable.BitmapDrawable +import android.graphics.drawable.Drawable 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 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.LatLngBounds import com.amap.api.maps.model.Marker -import com.amap.api.maps.model.MarkerOptions import com.casic.app.smartwell.R import com.casic.app.smartwell.databinding.FragmentHomeBinding +import com.casic.app.smartwell.extensions.drawCircle import com.casic.app.smartwell.extensions.initImmersionBar -import com.casic.app.smartwell.extensions.valueToType import com.casic.app.smartwell.model.MapWellListModel import com.casic.app.smartwell.utils.LocaleConstant import com.casic.app.smartwell.utils.RouteOnMap @@ -31,9 +30,16 @@ import com.casic.app.smartwell.view.WellOperationActivity import com.casic.app.smartwell.vm.OrderViewModel import com.casic.app.smartwell.vm.WellViewModel +import com.casic.app.smartwell.widgets.MapWellPopup +import com.casic.app.smartwell.widgets.cluster.ClusterItem +import com.casic.app.smartwell.widgets.cluster.ClusterOnClickListener +import com.casic.app.smartwell.widgets.cluster.ClusterOverlay +import com.casic.app.smartwell.widgets.cluster.RegionItem 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.convertDrawable +import com.pengxh.kt.lite.extensions.dp2px import com.pengxh.kt.lite.extensions.navigatePageTo import com.pengxh.kt.lite.extensions.show import com.pengxh.kt.lite.utils.LoadingDialogHub @@ -43,35 +49,23 @@ /** * 地图点位带聚合效果 * */ -class HomePageHaveClusterFragment : KotlinBaseFragment(), AMap.OnMapLoadedListener, - AMap.OnCameraChangeListener, AMap.OnMarkerClickListener, AMap.InfoWindowAdapter, - AMap.OnInfoWindowClickListener { +class HomePageHaveClusterFragment : KotlinBaseFragment(), + AMap.OnCameraChangeListener { private val kTag = "HaveClusterFragment" private val easyPopupWindow by lazy { EasyPopupWindow(requireContext()) } - private lateinit var wellViewModel: WellViewModel - private lateinit var orderViewModel: OrderViewModel - private lateinit var aMap: AMap - - /** - * 所有的marker - */ - private var allMarkerOptions: MutableList = ArrayList() - - /** - * 视野内的marker - */ - private var markerOptionsInView: MutableList = ArrayList() - - /** - * 自定义Marker弹出框 - * */ - private lateinit var v: View + private val regionRadius by lazy { LocaleConstant.RADIUS_SIZE.dp2px(requireContext()) } + private val infoPopup by lazy { MapWellPopup(requireContext()) } /** * 所有窨井列表信息集合 * */ - private var wellModels: MutableList = ArrayList() + private val wellModels = ArrayList() + private val backDrawables = HashMap() + private lateinit var wellViewModel: WellViewModel + private lateinit var orderViewModel: OrderViewModel + private lateinit var aMap: AMap + private var clusterOverlay: ClusterOverlay? = null override fun initViewBinding( inflater: LayoutInflater, @@ -106,6 +100,9 @@ } }) + //地图初始化 + initMap(savedInstanceState) + //初始化vm wellViewModel = ViewModelProvider(this)[WellViewModel::class.java] orderViewModel = ViewModelProvider(this)[OrderViewModel::class.java] @@ -120,25 +117,19 @@ val latitudeList: MutableList = ArrayList() val longitudeList: MutableList = ArrayList() it.data?.forEach { well -> - val lat = well.latGaode.toString() - val lng = well.lngGaode.toString() + val lat = well.latGaode + val lng = well.lngGaode if (lat.isNotBlank() && lng.isNotBlank()) { //返回true代表当前位置在大陆、港澳地区,反之不在 val latitude = lat.toDouble() val longitude = lng.toDouble() if (CoordinateConverter.isAMapDataAvailable(latitude, longitude)) { - //缓存所有设备详情,点击Marker时候需要 + //缓存所有井 wellModels.add(well) + //分别缓存经、纬度 latitudeList.add(latitude) longitudeList.add(longitude) - //将所有设备信息转化缓存为Marker点 - allMarkerOptions.add( - MarkerOptions() - .position(LatLng(latitude, longitude)) - .title(well.wellTypeName) - .snippet(well.wellName) - ) } } } @@ -160,12 +151,12 @@ val cameraPosition = CameraPosition(centerLatLng, 16f, 0f, 0f) val cameraUpdate = CameraUpdateFactory.newCameraPosition(cameraPosition) aMap.animateCamera(cameraUpdate, 1500, null) + + //显示点数据 + displayWellOnMap() } } - //地图初始化 - initMap(savedInstanceState) - //获取窨井监控数据 wellViewModel.countResultModel.observe(this) { binding.deployedWellView.text = it["bfWell"] @@ -220,17 +211,10 @@ uiSettings.isCompassEnabled = true uiSettings.zoomPosition = AMapOptions.ZOOM_POSITION_RIGHT_CENTER uiSettings.isTiltGesturesEnabled = false//不许地图随手势倾斜角度 + uiSettings.isRotateGesturesEnabled = false//不允许地图随手势改变方位 - // 地图加载成功监听 - aMap.addOnMapLoadedListener(this) // 地图缩放监听 aMap.addOnCameraChangeListener(this) - // marker 点击事件监听 - aMap.addOnMarkerClickListener(this) - // 点击marker弹出自定义popup - aMap.setInfoWindowAdapter(this) - //信息窗点击事件 - aMap.addOnInfoWindowClickListener(this) } override fun initEvent() { @@ -259,9 +243,111 @@ } - override fun onMapLoaded() { - //地图加载成功之后显示聚合点数据 - initClustersMarkers() + private fun displayWellOnMap() { + clusterOverlay?.onDestroy() + val clusterItems = ArrayList() + + wellModels.forEach { + val latitude = it.latGaode.toDouble() + val longitude = it.lngGaode.toDouble() + + val latLng = LatLng(latitude, longitude, false) + val regionItem = RegionItem(latLng, it) + clusterItems.add(regionItem) + } + + clusterOverlay = ClusterOverlay(requireContext(), aMap, clusterItems, regionRadius) + clusterOverlay?.setClusterRender { clusterNum -> + //聚合圆半径 + val radius = 100.dp2px(requireContext()) + if (clusterNum == 0) { + var bitmapDrawable = backDrawables[0] + if (bitmapDrawable == null) { + bitmapDrawable = BitmapDrawable( + null, radius.drawCircle(Color.argb(159, 100, 149, 237)) + ) + backDrawables[0] = bitmapDrawable + } + bitmapDrawable + } + if (clusterNum == 1) { + var bitmapDrawable = backDrawables[1] + if (bitmapDrawable == null) { + bitmapDrawable = R.mipmap.well_location.convertDrawable(requireContext())!! + backDrawables[1] = bitmapDrawable + } + bitmapDrawable + } else if (clusterNum < 5) { + var bitmapDrawable = backDrawables[2] + if (bitmapDrawable == null) { + bitmapDrawable = BitmapDrawable( + null, radius.drawCircle(Color.argb(159, 100, 149, 237)) + ) + backDrawables[2] = bitmapDrawable + } + bitmapDrawable + } else if (clusterNum < 10) { + var bitmapDrawable = backDrawables[3] + if (bitmapDrawable == null) { + bitmapDrawable = BitmapDrawable( + null, radius.drawCircle(Color.argb(199, 30, 144, 255)) + ) + backDrawables[3] = bitmapDrawable + } + bitmapDrawable + } else { + var bitmapDrawable = backDrawables[4] + if (bitmapDrawable == null) { + bitmapDrawable = BitmapDrawable( + null, radius.drawCircle(Color.argb(235, 65, 105, 225)) + ) + backDrawables[4] = bitmapDrawable + } + bitmapDrawable + } + } + + clusterOverlay?.setOnClusterClickListener(object : ClusterOnClickListener { + override fun onMarkerClicked(marker: Marker?, items: List) { + if (items.size > 1) { + "请缩放地图比例在查看数据".show(requireContext()) + return + } + + var item: RegionItem? = null + val builder = LatLngBounds.Builder() + for (clusterItem in items) { + builder.include(clusterItem.position) + item = clusterItem as RegionItem + } + + item?.apply { + showWellPopup(well) + } + } + }) + } + + private fun showWellPopup(well: MapWellListModel.DataModel) { + infoPopup.set(well, object : MapWellPopup.OnPopupWindowClickListener { + override fun onPopupClicked(lat: Double, lng: Double) { + AlertControlDialog.Builder().setContext(requireContext()).setTitle("操作提示") + .setMessage("确定要前往吗").setNegativeButton("取消").setPositiveButton("确定") + .setOnDialogButtonClickListener(object : + AlertControlDialog.OnDialogButtonClickListener { + override fun onConfirmClick() { + RouteOnMap.startNavigation( + requireContext(), "", LatLng(lat, lng) + ) + } + + override fun onCancelClick() { + + } + }).build().show() + } + }) + infoPopup.showAsDropDown(binding.rightOptionView) } override fun onCameraChange(p0: CameraPosition?) { @@ -282,103 +368,10 @@ } } - //获取视野内的marker 根据聚合算法合成自定义的marker 显示视野内的marker override fun onCameraChangeFinish(p0: CameraPosition?) { //地图缩放之后显示聚合点数据 LoadingDialogHub.dismiss() httpCountDownTimer.cancel() - initClustersMarkers() - } - - private fun initClustersMarkers() { - 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 { - v = LayoutInflater.from(requireContext()).inflate(R.layout.popup_map_info, null) - - //显示闸井信息 - marker?.showInfoWindow() - return true - } - - override fun getInfoWindow(marker: Marker?): View { - //反射得到popup里面的控件对象 - val wellNameView = v.findViewById(R.id.wellNameView) - val wellCodeView = v.findViewById(R.id.wellCodeView) - val wellTypeView = v.findViewById(R.id.wellTypeView) - val wellStateView = v.findViewById(R.id.wellStateView) - val deepView = v.findViewById(R.id.deepView) - val locationView = v.findViewById(R.id.locationView) - - //绑定数据 - val clickedLatLng = marker?.position!! - wellModels.forEach { well -> - if (clickedLatLng.latitude == well.latGaode!!.toDouble() - && clickedLatLng.longitude == well.lngGaode!!.toDouble() - ) { - wellNameView.text = String.format("点位名称: ${well.wellName}") - wellCodeView.text = String.format("点位编号: ${well.wellCode}") - wellTypeView.text = String.format("点位类型: ${well.wellType.valueToType()}") - val bfztName = if (well.bfzt == "1") { - "已布防" - } else { - "已撤防" - } - wellStateView.text = String.format("布/撤防状态: $bfztName") - deepView.text = String.format("点位深度: ${well.deep}m") - locationView.text = String.format("详细位置: ${well.position}") - } - } - return v - } - - /** - * 此方法不能修改整个 InfoWindow 的背景和边框,无论自定义的样式是什么样,SDK 都会在最外层添加一个默认的边框 - * */ - override fun getInfoContents(p0: Marker?): View? = null - - override fun onInfoWindowClick(p0: Marker?) { - p0?.apply { - AlertControlDialog.Builder() - .setContext(requireContext()) - .setTitle("操作提示") - .setMessage("确定要前往吗") - .setNegativeButton("取消") - .setPositiveButton("确定") - .setOnDialogButtonClickListener(object : - AlertControlDialog.OnDialogButtonClickListener { - override fun onConfirmClick() { - val lat = position.latitude.toString() - val lng = position.longitude.toString() - if (lat.isBlank() || lng.isBlank()) { - "点位经纬度异常,无法开启导航".show(requireContext()) - return - } - RouteOnMap.startNavigation( - requireContext(), snippet, LatLng(lat.toDouble(), lng.toDouble()) - ) - } - - override fun onCancelClick() { - - } - }).build().show() - } } /***以下是地图生命周期管理************************************************************************/ 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 a54d213..bfa7a57 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 @@ -44,8 +44,8 @@ * 地图点位不带聚合效果 * */ class HomePageNoClusterFragment : KotlinBaseFragment(), - AMap.OnMapLoadedListener, AMap.OnCameraChangeListener, AMap.OnMarkerClickListener, - AMap.InfoWindowAdapter, AMap.OnInfoWindowClickListener { + AMap.OnCameraChangeListener, AMap.OnMarkerClickListener, AMap.InfoWindowAdapter, + AMap.OnInfoWindowClickListener { private val kTag = "NoClusterFragment" private val easyPopupWindow by lazy { EasyPopupWindow(requireContext()) } @@ -109,6 +109,9 @@ wellViewModel = ViewModelProvider(this)[WellViewModel::class.java] orderViewModel = ViewModelProvider(this)[OrderViewModel::class.java] + //地图初始化 + initMap(savedInstanceState) + //获取所有窨井数据 httpCountDownTimer.start() LoadingDialogHub.show(requireActivity(), "数据加载中,请稍后...") @@ -157,12 +160,12 @@ val cameraPosition = CameraPosition(centerLatLng, 16f, 0f, 0f) val cameraUpdate = CameraUpdateFactory.newCameraPosition(cameraPosition) aMap.animateCamera(cameraUpdate, 1500, null) + + //显示点数据 + displayWellOnMap() } } - //地图初始化 - initMap(savedInstanceState) - //获取窨井监控数据 wellViewModel.countResultModel.observe(this) { binding.deployedWellView.text = it["bfWell"] @@ -214,9 +217,8 @@ uiSettings.isCompassEnabled = true uiSettings.zoomPosition = AMapOptions.ZOOM_POSITION_RIGHT_CENTER uiSettings.isTiltGesturesEnabled = false//不许地图随手势倾斜角度 + uiSettings.isRotateGesturesEnabled = false//不允许地图随手势改变方位 - // 地图加载成功监听 - aMap.addOnMapLoadedListener(this) // 地图缩放监听 aMap.addOnCameraChangeListener(this) // marker 点击事件监听 @@ -253,11 +255,6 @@ } - override fun onMapLoaded() { - //地图加载成功之后显示聚合点数据 - initClustersMarkers() - } - override fun onCameraChange(p0: CameraPosition?) { } @@ -281,10 +278,9 @@ //地图缩放之后显示聚合点数据 LoadingDialogHub.dismiss() httpCountDownTimer.cancel() - initClustersMarkers() } - private fun initClustersMarkers() { + private fun displayWellOnMap() { val proj = aMap.projection val dm = resources.displayMetrics var screenLocation: Point diff --git a/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.java b/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.java deleted file mode 100644 index d8b18ef..0000000 --- a/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.java +++ /dev/null @@ -1,50 +0,0 @@ -package com.casic.app.smartwell.model; - -public class ErrorMessageModel { - - private int code; - private String data; - private String exceptionClazz; - private String message; - private boolean success; - - public int getCode() { - return code; - } - - public void setCode(int code) { - this.code = code; - } - - public String getData() { - return data; - } - - public void setData(String data) { - this.data = data; - } - - public String getExceptionClazz() { - return exceptionClazz; - } - - public void setExceptionClazz(String exceptionClazz) { - this.exceptionClazz = exceptionClazz; - } - - public String getMessage() { - return message; - } - - public void setMessage(String message) { - this.message = message; - } - - public boolean isSuccess() { - return success; - } - - public void setSuccess(boolean success) { - this.success = success; - } -} \ No newline at end of file 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 new file mode 100644 index 0000000..215ac0c --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/PipelineModel.java @@ -0,0 +1,328 @@ +package com.casic.app.smartwell.model; + +import java.util.List; + +public class PipelineModel { + + private Integer code; + private DataModel data; + private String message; + private Boolean success; + + public Integer getCode() { + return code; + } + + public void setCode(Integer code) { + this.code = code; + } + + public DataModel getData() { + return data; + } + + public void setData(DataModel data) { + this.data = data; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + public Boolean getSuccess() { + return success; + } + + public void setSuccess(Boolean success) { + this.success = success; + } + + public static class DataModel { + private List rows; + private Integer total; + + public List getRows() { + return rows; + } + + public void setRows(List rows) { + this.rows = rows; + } + + public Integer getTotal() { + return total; + } + + public void setTotal(Integer total) { + this.total = total; + } + + 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 getBuryMode() { + return buryMode; + } + + public void setBuryMode(String buryMode) { + this.buryMode = buryMode; + } + + public String getConstructEra() { + return constructEra; + } + + public void setConstructEra(String constructEra) { + this.constructEra = constructEra; + } + + 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; + } + } + } +} 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 06d3d2b..4f38a2c 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 = 100 //相距多少米才聚合,单位:米 + const val RADIUS_SIZE = 80 //相距多少米才聚合,单位:米 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:11308" + // 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 0d5f3fa..991e1db 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 @@ -312,4 +312,14 @@ @Header("token") token: String, @Field("clientid") deviceCode: String ): String + + /** + * 管线位置数据 + */ + @GET("/pipeline/listPage") + suspend fun getPipeline( + @Header("token") token: String, + @Query("limit") limit: Int, + @Query("offset") offset: Int + ): String } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt index 1a0ce22..4050067 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt @@ -294,4 +294,11 @@ suspend fun registerPush(clientId: String): String { return api.registerPush(AuthenticationHelper.token!!, clientId) } + + /** + * 管线位置数据 + */ + suspend fun getPipeline(): String { + return api.getPipeline(AuthenticationHelper.token!!, 2000, 1) + } } \ No newline at end of file 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 9270fa1..4ca5a5e 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.HomePageNoClusterFragment +import com.casic.app.smartwell.fragment.HomePageHaveClusterFragment 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/vm/AlarmViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/AlarmViewModel.kt index 9cff08c..e7acc17 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/AlarmViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/AlarmViewModel.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.AlarmContentModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager import com.google.gson.Gson @@ -16,7 +16,7 @@ fun getAlarmContentType(alarmType: String) = launch({ val response = RetrofitServiceManager.getAlarmContentType(alarmType) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { listModel.value = gson.fromJson( response, object : TypeToken() {}.type diff --git a/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt index 5e5b163..895dedd 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.PublicKeyModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager import com.google.gson.Gson @@ -18,7 +18,7 @@ fun getPublicKey() = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.authenticate() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { keyModel.value = gson.fromJson( response, object : TypeToken() {}.type diff --git a/app/src/main/java/com/casic/app/smartwell/vm/DeviceViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/DeviceViewModel.kt index db5ccf6..899a962 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/DeviceViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/DeviceViewModel.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.DeviceDetailModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager import com.google.gson.Gson @@ -16,7 +16,7 @@ fun getDeviceDetail(deviceCode: String) = launch({ val response = RetrofitServiceManager.getDeviceDetail(deviceCode) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { detailModel.value = gson.fromJson( response, object : TypeToken() {}.type diff --git a/app/src/main/java/com/casic/app/smartwell/vm/LoginViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/LoginViewModel.kt index cd8b8a9..a417398 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/LoginViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/LoginViewModel.kt @@ -2,7 +2,7 @@ import androidx.lifecycle.MutableLiveData import com.casic.app.smartwell.base.BaseApplication -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.CommonResultModel import com.casic.app.smartwell.model.LoginResultModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -21,7 +21,7 @@ fun enter(account: String, secretKey: String) = launch({ val response = RetrofitServiceManager.login(account, secretKey) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success enterResultModel.value = gson.fromJson( @@ -38,7 +38,7 @@ fun out() = launch({ val response = RetrofitServiceManager.loginOut() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { outResultModel.value = gson.fromJson( response, object : TypeToken() {}.type diff --git a/app/src/main/java/com/casic/app/smartwell/vm/OperationViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/OperationViewModel.kt index 8943ed3..37e115f 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/OperationViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/OperationViewModel.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.vm import com.casic.app.smartwell.base.BaseApplication -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager import com.pengxh.kt.lite.base.BaseViewModel import com.pengxh.kt.lite.extensions.launch @@ -16,7 +16,7 @@ fun acceptWorkOrder(id: String) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.acceptWorkOrder(id) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success "接单成功".show(BaseApplication.get()) @@ -35,7 +35,7 @@ loadState.value = LoadState.Loading val response = RetrofitServiceManager.confirmWorkOrder(id, firstState, firstStatePhotos, needHandle) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success "工单确认成功".show(BaseApplication.get()) @@ -50,7 +50,7 @@ fun transferWorkOrder(id: String, userId: String) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.transferWorkOrder(id, userId) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success "转单成功".show(BaseApplication.get()) @@ -65,7 +65,7 @@ fun completeWorkOrder(id: String, handleMessage: String, handlePhotos: String) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.completeWorkOrder(id, handleMessage, handlePhotos) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success "工单处理成功".show(BaseApplication.get()) diff --git a/app/src/main/java/com/casic/app/smartwell/vm/OrderViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/OrderViewModel.kt index 4cb26b7..d2fad86 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/OrderViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/OrderViewModel.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.OrderDetailModel import com.casic.app.smartwell.model.OrderListModel import com.casic.app.smartwell.model.OrderStatusModel @@ -37,7 +37,7 @@ val response = RetrofitServiceManager.getSearchResult( keywords, alarmContent, alarmLevel, jobStatus, deptId, beginTime, endTime, offset ) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success searchResult.value = gson.fromJson( @@ -53,7 +53,7 @@ fun getWorkOrderListByState(jobStatus: String, page: Int) = launch({ val response = RetrofitServiceManager.getWorkOrderList(jobStatus, page) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { orderList.value = gson.fromJson( response, object : TypeToken() {}.type @@ -65,7 +65,7 @@ fun getNotAcceptOderList(page: Int) = launch({ val response = RetrofitServiceManager.getNotAcceptOderList(page) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { orderList.value = gson.fromJson( response, object : TypeToken() {}.type @@ -77,7 +77,7 @@ fun getNotHandleOderList(page: Int) = launch({ val response = RetrofitServiceManager.getNotHandleOderList(page) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { orderList.value = gson.fromJson( response, object : TypeToken() {}.type @@ -89,7 +89,7 @@ fun countWorkOrderByState() = launch({ val response = RetrofitServiceManager.countWorkOrderByState() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { val map = HashMap(4) @@ -107,7 +107,7 @@ fun getOrderStatus() = launch({ val response = RetrofitServiceManager.getOrderStatus() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { orderStatusModel.value = gson.fromJson( response, object : TypeToken() {}.type @@ -120,7 +120,7 @@ fun getWorkOrderDetail(id: String) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.getWorkOrderDetail(id) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success detailModel.value = gson.fromJson( diff --git a/app/src/main/java/com/casic/app/smartwell/vm/PipelineViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/PipelineViewModel.kt new file mode 100644 index 0000000..60c1e2f --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/vm/PipelineViewModel.kt @@ -0,0 +1,28 @@ +package com.casic.app.smartwell.vm + +import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.extensions.getResponseCode +import com.casic.app.smartwell.model.PipelineModel +import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken +import com.pengxh.kt.lite.base.BaseViewModel +import com.pengxh.kt.lite.extensions.launch + +class PipelineViewModel : BaseViewModel() { + + private val gson by lazy { Gson() } + val lineResult = MutableLiveData() + + fun getPipeline() = launch({ + val response = RetrofitServiceManager.getPipeline() + val responseCode = response.getResponseCode() + if (responseCode == 200) { + lineResult.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } + }, { + it.printStackTrace() + }) +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/PushViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/PushViewModel.kt index 9279815..12fd610 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/PushViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/PushViewModel.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.CommonResultModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager import com.google.gson.Gson @@ -16,7 +16,7 @@ fun registerPush(clientId: String) = launch({ val response = RetrofitServiceManager.registerPush(clientId) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { registerResultModel.value = gson.fromJson( response, object : TypeToken() {}.type diff --git a/app/src/main/java/com/casic/app/smartwell/vm/UploadImageViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/UploadImageViewModel.kt index 8d6744e..9707eeb 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/UploadImageViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/UploadImageViewModel.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.CommonResultModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager import com.google.gson.Gson @@ -19,7 +19,7 @@ fun uploadImage(image: File) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.uploadImage(image) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success resultModel.value = gson.fromJson( diff --git a/app/src/main/java/com/casic/app/smartwell/vm/UserViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/UserViewModel.kt index 31a4d4c..070c35a 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/UserViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/UserViewModel.kt @@ -2,7 +2,7 @@ import androidx.lifecycle.MutableLiveData import com.casic.app.smartwell.base.BaseApplication -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.SubordinateModel import com.casic.app.smartwell.model.UserDetailModel import com.casic.app.smartwell.model.VersionResultModel @@ -25,7 +25,7 @@ fun getUserDetail() = launch({ val response = RetrofitServiceManager.getUserDetail() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { val userDetail = gson.fromJson( response, object : TypeToken() {}.type @@ -48,7 +48,7 @@ * */ fun getSubordinate(hasMine: String?, deptId: String?, roleTips: String?) = launch({ val response = RetrofitServiceManager.getSubordinate(hasMine, deptId, roleTips) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { subordinateModel.value = gson.fromJson( response, object : TypeToken() {}.type @@ -61,7 +61,7 @@ fun changePassword(oldPwd: String, newPwd: String) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.changePassword(oldPwd, newPwd) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success "修改成功,请重新登录".show(BaseApplication.get()) @@ -76,7 +76,7 @@ fun updateVersion() = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.updateVersion() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success versionResultModel.value = gson.fromJson( diff --git a/app/src/main/java/com/casic/app/smartwell/vm/WellViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/WellViewModel.kt index 3d41e9b..9e42e36 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/WellViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/WellViewModel.kt @@ -2,8 +2,7 @@ import androidx.lifecycle.MutableLiveData import com.casic.app.smartwell.base.BaseApplication -import com.casic.app.smartwell.extensions.separateResponseCode -import com.casic.app.smartwell.extensions.toErrorMessage +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.AuthorDeptModel import com.casic.app.smartwell.model.CommonResultModel import com.casic.app.smartwell.model.MapWellListModel @@ -32,7 +31,7 @@ fun countWellByState() = launch({ val response = RetrofitServiceManager.countWellByState() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { val map = HashMap(3) @@ -57,7 +56,7 @@ fun getWellType() = launch({ val response = RetrofitServiceManager.getWellType() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { wellTypeModel.value = gson.fromJson( response, object : TypeToken() {}.type @@ -70,7 +69,7 @@ fun getWellDetail(id: String) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.getWellDetail(id) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success wellDetailModel.value = gson.fromJson( @@ -87,7 +86,7 @@ fun getOperationResult(id: String, state: String) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.getOperationResult(id, state) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success "操作成功".show(BaseApplication.get()) @@ -105,7 +104,7 @@ fun getMonitorResult(id: String) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.getMonitorResult(id) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success monitorModel.value = gson.fromJson( @@ -125,7 +124,7 @@ val response = RetrofitServiceManager.getWellListByPage( keywords, wellType, deptid, bfzt, page ) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { listModel.value = gson.fromJson( response, object : TypeToken() {}.type @@ -137,13 +136,11 @@ fun getWellList() = launch({ val response = RetrofitServiceManager.getWellList() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { totalWellModel.value = gson.fromJson( response, object : TypeToken() {}.type ) - } else { - response.toErrorMessage().show(BaseApplication.get()) } }, { it.printStackTrace() diff --git a/app/src/main/java/com/casic/app/smartwell/widgets/GaoDeClusterMarkerView.kt b/app/src/main/java/com/casic/app/smartwell/widgets/GaoDeClusterMarkerView.kt deleted file mode 100644 index 1f375df..0000000 --- a/app/src/main/java/com/casic/app/smartwell/widgets/GaoDeClusterMarkerView.kt +++ /dev/null @@ -1,100 +0,0 @@ -package com.casic.app.smartwell.widgets - -import android.content.Context -import android.graphics.Bitmap -import android.graphics.Point -import android.view.Gravity -import android.view.LayoutInflater -import android.view.View -import android.widget.TextView -import com.amap.api.maps.Projection -import com.amap.api.maps.model.BitmapDescriptorFactory -import com.amap.api.maps.model.LatLng -import com.amap.api.maps.model.LatLngBounds -import com.amap.api.maps.model.MarkerOptions -import com.casic.app.smartwell.R -import com.pengxh.kt.lite.extensions.toBitmap -import java.util.* - -class GaoDeClusterMarkerView( - private val context: Context, firstMarkers: MarkerOptions, projection: Projection, gridSize: Int -) { - //当前可观区域里的 聚合过之后的集合 - private val includeMarkers: ArrayList - - // 创建区域 - val bounds: LatLngBounds - var options: MarkerOptions = MarkerOptions() - - init { - val screenLocation = projection.toScreenLocation(firstMarkers.position) - //范围类 - val southwestPoint = Point(screenLocation.x - gridSize, screenLocation.y + gridSize) - //范围类 - val northeastPoint = Point(screenLocation.x + gridSize, screenLocation.y - gridSize) - bounds = LatLngBounds( - projection.fromScreenLocation(southwestPoint), - projection.fromScreenLocation(northeastPoint) - ) - //设置初始化marker属性 - options.anchor(0.5f, 1.3f) - .title(firstMarkers.title) - .position(firstMarkers.position) - .icon(firstMarkers.icon) - .snippet(firstMarkers.snippet) - .draggable(false) - includeMarkers = ArrayList() - includeMarkers.add(firstMarkers) - } - - /** - * 添加marker - */ - fun addMarker(markerOptions: MarkerOptions) { - includeMarkers.add(markerOptions) // 添加到列表中 - } - - /** - * 设置聚合点的中心位置以及图标 - */ - fun setPositionAndIcon() { - val size = includeMarkers.size - var lat = 0.0 - var lng = 0.0 - // 一个的时候 - if (size == 1) { //设置marker单个属性 - // 设置marker位置 - options.position( - LatLng( - includeMarkers[0].position.latitude, includeMarkers[0].position.longitude - ) - ) - } else { // 聚合的时候 - //设置marker聚合属性 - for (op in includeMarkers) { - lat += op.position.latitude - lng += op.position.longitude - } - // 设置marker的位置为中心位置为聚集点的平均位置 - options.position(LatLng(lat / size, lng / size)) - } - options.icon(BitmapDescriptorFactory.fromBitmap(getBitmap(size))) - } - - /** - * marker视图 - */ - private fun getBitmap(num: Int): Bitmap? { - val view = LayoutInflater.from(context).inflate(R.layout.marker_gaode, null) - val wellCountView = view.findViewById(R.id.wellCountView) - return if (num > 1) { - wellCountView.visibility = View.VISIBLE - wellCountView.text = String.format("${num}个") - wellCountView.gravity = Gravity.CENTER - view.toBitmap() - } else { - wellCountView.visibility = View.GONE - BitmapDescriptorFactory.fromResource(R.mipmap.well_location).bitmap - } - } -} \ No newline at end of file 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 new file mode 100644 index 0000000..ec455dd --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/widgets/MapWellPopup.kt @@ -0,0 +1,58 @@ +package com.casic.app.smartwell.widgets + +import android.content.Context +import android.view.LayoutInflater +import android.view.ViewGroup +import android.widget.LinearLayout +import android.widget.PopupWindow +import android.widget.TextView +import com.casic.app.smartwell.R +import com.casic.app.smartwell.extensions.valueToType +import com.casic.app.smartwell.model.MapWellListModel + +class MapWellPopup constructor(context: Context) : PopupWindow() { + + init { + width = ViewGroup.LayoutParams.MATCH_PARENT + height = ViewGroup.LayoutParams.WRAP_CONTENT + isOutsideTouchable = true + isFocusable = true + animationStyle = R.style.MapPopupAnimation + setBackgroundDrawable(null) + contentView = LayoutInflater.from(context).inflate( + R.layout.popup_map_info, null, false + ) + } + + fun set(well: MapWellListModel.DataModel, windowClickListener: OnPopupWindowClickListener) { + //反射得到popup里面的控件对象 + val rootView = contentView.findViewById(R.id.rootView) + val wellNameView = contentView.findViewById(R.id.wellNameView) + val wellCodeView = contentView.findViewById(R.id.wellCodeView) + val wellTypeView = contentView.findViewById(R.id.wellTypeView) + val wellStateView = contentView.findViewById(R.id.wellStateView) + val deepView = contentView.findViewById(R.id.deepView) + val locationView = contentView.findViewById(R.id.locationView) + + //绑定数据 + wellNameView.text = String.format("点位名称: ${well.wellName}") + wellCodeView.text = String.format("点位编号: ${well.wellCode}") + wellTypeView.text = String.format("点位类型: ${well.wellType.valueToType()}") + val bfztName = if (well.bfzt == "1") { + "已布防" + } else { + "已撤防" + } + wellStateView.text = String.format("布/撤防状态: $bfztName") + deepView.text = String.format("点位深度: ${well.deep}m") + locationView.text = String.format("详细位置: ${well.position}") + + rootView.setOnClickListener { + windowClickListener.onPopupClicked(well.latGaode.toDouble(), well.lngGaode.toDouble()) + } + } + + interface OnPopupWindowClickListener { + fun onPopupClicked(lat: Double, lng: Double) + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/widgets/cluster/Cluster.java b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/Cluster.java new file mode 100644 index 0000000..9455ccd --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/Cluster.java @@ -0,0 +1,43 @@ +package com.casic.app.smartwell.widgets.cluster; + +import com.amap.api.maps.model.LatLng; +import com.amap.api.maps.model.Marker; + +import java.util.ArrayList; +import java.util.List; + +public class Cluster { + private final LatLng latLng; + private final List clusterItems; + private Marker marker; + + + public Cluster(LatLng latLng) { + this.latLng = latLng; + clusterItems = new ArrayList<>(); + } + + public void addClusterItem(ClusterItem clusterItem) { + clusterItems.add(clusterItem); + } + + public int getClusterCount() { + return clusterItems.size(); + } + + public LatLng getCenterLatLng() { + return latLng; + } + + public void setMarker(Marker marker) { + this.marker = marker; + } + + public Marker getMarker() { + return marker; + } + + public List getClusterItems() { + return clusterItems; + } +} diff --git a/app/src/main/java/com/casic/app/smartwell/widgets/cluster/ClusterItem.java b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/ClusterItem.java new file mode 100644 index 0000000..f5d9a9d --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/ClusterItem.java @@ -0,0 +1,10 @@ +package com.casic.app.smartwell.widgets.cluster; + +import com.amap.api.maps.model.LatLng; + +public interface ClusterItem { + /** + * 返回聚合元素的地理位置 + */ + LatLng getPosition(); +} diff --git a/app/src/main/java/com/casic/app/smartwell/widgets/cluster/ClusterOnClickListener.java b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/ClusterOnClickListener.java new file mode 100644 index 0000000..0efa1f1 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/ClusterOnClickListener.java @@ -0,0 +1,15 @@ +package com.casic.app.smartwell.widgets.cluster; + +import com.amap.api.maps.model.Marker; + +import java.util.List; + +public interface ClusterOnClickListener { + /** + * 点击聚合点的回调处理函数 + * + * @param marker 点击的聚合点 + * @param items 聚合点所包含的元素 + */ + void onMarkerClicked(Marker marker, List items); +} 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 new file mode 100644 index 0000000..40df562 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/ClusterOverlay.java @@ -0,0 +1,349 @@ +package com.casic.app.smartwell.widgets.cluster; + +import android.content.Context; +import android.graphics.Color; +import android.os.Handler; +import android.os.HandlerThread; +import android.os.Looper; +import android.os.Message; +import android.util.TypedValue; +import android.view.Gravity; +import android.widget.TextView; + +import com.amap.api.maps.AMap; +import com.amap.api.maps.AMapUtils; +import com.amap.api.maps.model.BitmapDescriptor; +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.LatLngBounds; +import com.amap.api.maps.model.Marker; +import com.amap.api.maps.model.MarkerOptions; +import com.amap.api.maps.model.animation.AlphaAnimation; +import com.casic.app.smartwell.R; + +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.CopyOnWriteArrayList; + +/** + * 整体设计采用了两个线程,一个线程用于计算组织聚合数据,一个线程负责处理Marker相关操作 + */ +public class ClusterOverlay implements AMap.OnCameraChangeListener, AMap.OnMarkerClickListener { + private final AMap amap; + private final Context context; + private final List clusterItems; + private final List clusters; + private final int clusterSize; + private ClusterOnClickListener clusterClickListener; + private ClusterRender clusterRender; + private final CopyOnWriteArrayList addMarkers = new CopyOnWriteArrayList<>(); + private double clusterDistance; + private final HandlerThread markerHandlerThread = new HandlerThread("addMarker"); + private final HandlerThread signClusterThread = new HandlerThread("calculateCluster"); + private Handler markerHandler; + private Handler signClusterHandler; + private float pxInMeters; + private boolean isCanceled = false; + private final AlphaAnimation addAnimation = new AlphaAnimation(0, 1); + + /** + * 构造函数,批量添加聚合元素时,调用此构造函数 + */ + public ClusterOverlay(Context context, AMap amap, int clusterSize) { + this(context, amap, null, clusterSize); + } + + /** + * 构造函数,批量添加聚合元素时,调用此构造函数 + */ + public ClusterOverlay(Context context, AMap amap, List clusterItems, int clusterSize) { + if (clusterItems != null) { + this.clusterItems = clusterItems; + } else { + this.clusterItems = new ArrayList<>(); + } + this.context = context; + this.clusters = new ArrayList<>(); + this.amap = amap; + this.clusterSize = clusterSize; + this.pxInMeters = amap.getScalePerPixel(); + this.clusterDistance = pxInMeters * clusterSize; + amap.setOnCameraChangeListener(this); + amap.setOnMarkerClickListener(this); + initThreadHandler(); + assignClusters(); + } + + /** + * 设置聚合点的点击事件 + */ + public void setOnClusterClickListener(ClusterOnClickListener clusterClickListener) { + this.clusterClickListener = clusterClickListener; + } + + /** + * 添加一个聚合点 + */ + public void addClusterItem(ClusterItem item) { + Message message = Message.obtain(); + message.what = SignClusterHandler.CALCULATE_SINGLE_CLUSTER; + message.obj = item; + signClusterHandler.sendMessage(message); + } + + /** + * 设置聚合元素的渲染样式,不设置则默认为气泡加数字形式进行渲染 + */ + public void setClusterRender(ClusterRender render) { + this.clusterRender = render; + } + + public void onDestroy() { + isCanceled = true; + signClusterHandler.removeCallbacksAndMessages(null); + markerHandler.removeCallbacksAndMessages(null); + signClusterThread.quit(); + markerHandlerThread.quit(); + for (Marker marker : addMarkers) { + marker.remove(); + } + addMarkers.clear(); + } + + //初始化Handler + private void initThreadHandler() { + markerHandlerThread.start(); + signClusterThread.start(); + markerHandler = new MarkerHandler(markerHandlerThread.getLooper()); + signClusterHandler = new SignClusterHandler(signClusterThread.getLooper()); + } + + @Override + public void onCameraChange(CameraPosition arg0) { + + } + + @Override + public void onCameraChangeFinish(CameraPosition arg0) { + pxInMeters = amap.getScalePerPixel(); + clusterDistance = pxInMeters * clusterSize; + assignClusters(); + } + + @Override + public boolean onMarkerClick(Marker marker) { + if (clusterClickListener == null) { + return true; + } + Cluster cluster = (Cluster) marker.getObject(); + if (cluster != null) { + clusterClickListener.onMarkerClicked(marker, cluster.getClusterItems()); + return true; + } + return false; + } + + /** + * 将聚合元素添加至地图上 + */ + private void addClusterToMap(List clusters) { + ArrayList removeMarkers = new ArrayList<>(addMarkers); + AlphaAnimation alphaAnimation = new AlphaAnimation(1, 0); + RemoveAnimationListener removeAnimationListener = new RemoveAnimationListener(removeMarkers); + for (Marker marker : removeMarkers) { + marker.setAnimation(alphaAnimation); + marker.setAnimationListener(removeAnimationListener); + marker.startAnimation(); + } + + for (Cluster cluster : clusters) { + addSingleClusterToMap(cluster); + } + } + + /** + * 将单个聚合元素添加至地图显示 + */ + private void addSingleClusterToMap(Cluster cluster) { + LatLng latlng = cluster.getCenterLatLng(); + MarkerOptions markerOptions = new MarkerOptions(); + markerOptions.icon(getBitmapDes(cluster.getClusterCount())).position(latlng); + Marker marker = amap.addMarker(markerOptions); + marker.setAnimation(addAnimation); + marker.setObject(cluster); + + marker.startAnimation(); + cluster.setMarker(marker); + addMarkers.add(marker); + } + + private void calculateClusters() { + isCanceled = false; + clusters.clear(); + LatLngBounds visibleBounds = amap.getProjection().getVisibleRegion().latLngBounds; + for (ClusterItem clusterItem : clusterItems) { + if (isCanceled) { + return; + } + LatLng latlng = clusterItem.getPosition(); + if (visibleBounds.contains(latlng)) { + Cluster cluster = getCluster(latlng, clusters); + if (cluster == null) { + cluster = new Cluster(latlng); + clusters.add(cluster); + } + cluster.addClusterItem(clusterItem); + } + } + + //复制一份数据,规避同步 + List tempClusters = new ArrayList<>(clusters); + Message message = Message.obtain(); + message.what = MarkerHandler.ADD_CLUSTER_LIST; + message.obj = tempClusters; + if (isCanceled) { + return; + } + markerHandler.sendMessage(message); + } + + /** + * 对点进行聚合 + */ + private void assignClusters() { + isCanceled = true; + signClusterHandler.removeMessages(SignClusterHandler.CALCULATE_CLUSTER); + signClusterHandler.sendEmptyMessage(SignClusterHandler.CALCULATE_CLUSTER); + } + + /** + * 在已有的聚合基础上,对添加的单个元素进行聚合 + */ + private void calculateSingleCluster(ClusterItem clusterItem) { + LatLngBounds visibleBounds = amap.getProjection().getVisibleRegion().latLngBounds; + LatLng latlng = clusterItem.getPosition(); + if (!visibleBounds.contains(latlng)) { + return; + } + Cluster cluster = getCluster(latlng, clusters); + if (cluster != null) { + cluster.addClusterItem(clusterItem); + Message message = Message.obtain(); + message.what = MarkerHandler.UPDATE_SINGLE_CLUSTER; + + message.obj = cluster; + markerHandler.removeMessages(MarkerHandler.UPDATE_SINGLE_CLUSTER); + markerHandler.sendMessageDelayed(message, 5); + } else { + cluster = new Cluster(latlng); + clusters.add(cluster); + cluster.addClusterItem(clusterItem); + Message message = Message.obtain(); + message.what = MarkerHandler.ADD_SINGLE_CLUSTER; + message.obj = cluster; + markerHandler.sendMessage(message); + } + } + + /** + * 根据一个点获取是否可以依附的聚合点,没有则返回null + */ + private Cluster getCluster(LatLng latLng, List clusters) { + for (Cluster cluster : clusters) { + LatLng clusterCenterPoint = cluster.getCenterLatLng(); + double distance = AMapUtils.calculateLineDistance(latLng, clusterCenterPoint); + if (distance < clusterDistance && amap.getCameraPosition().zoom < 19) { + return cluster; + } + } + return null; + } + + + /** + * 获取每个聚合点的绘制样式 + */ + private BitmapDescriptor getBitmapDes(int num) { + TextView textView = new TextView(context); + if (num > 1) { + String tile = String.valueOf(num); + textView.setText(tile); + } + textView.setGravity(Gravity.CENTER); + textView.setTextColor(Color.BLACK); + textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 15); + if (clusterRender != null && clusterRender.getDrawableByCount(num) != null) { + textView.setBackgroundDrawable(clusterRender.getDrawableByCount(num)); + } else { + textView.setBackgroundResource(R.mipmap.well_location); + } + return BitmapDescriptorFactory.fromView(textView); + } + + /** + * 更新已加入地图聚合点的样式 + */ + private void updateCluster(Cluster cluster) { + Marker marker = cluster.getMarker(); + marker.setIcon(getBitmapDes(cluster.getClusterCount())); + } + + /** + * 处理market添加,更新等操作 + */ + class MarkerHandler extends Handler { + + static final int ADD_CLUSTER_LIST = 0; + + static final int ADD_SINGLE_CLUSTER = 1; + + static final int UPDATE_SINGLE_CLUSTER = 2; + + public MarkerHandler(Looper looper) { + super(looper); + } + + public void handleMessage(Message message) { + switch (message.what) { + case ADD_CLUSTER_LIST: + List clusters = (List) message.obj; + addClusterToMap(clusters); + break; + case ADD_SINGLE_CLUSTER: + Cluster cluster = (Cluster) message.obj; + addSingleClusterToMap(cluster); + break; + case UPDATE_SINGLE_CLUSTER: + Cluster updateCluster = (Cluster) message.obj; + updateCluster(updateCluster); + break; + } + } + } + + /** + * 处理聚合点算法线程 + */ + class SignClusterHandler extends Handler { + static final int CALCULATE_CLUSTER = 0; + static final int CALCULATE_SINGLE_CLUSTER = 1; + + public SignClusterHandler(Looper looper) { + super(looper); + } + + public void handleMessage(Message message) { + switch (message.what) { + case CALCULATE_CLUSTER: + calculateClusters(); + break; + case CALCULATE_SINGLE_CLUSTER: + ClusterItem item = (ClusterItem) message.obj; + clusterItems.add(item); + calculateSingleCluster(item); + break; + } + } + } +} diff --git a/app/src/main/java/com/casic/app/smartwell/widgets/cluster/ClusterRender.java b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/ClusterRender.java new file mode 100644 index 0000000..427ff14 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/ClusterRender.java @@ -0,0 +1,10 @@ +package com.casic.app.smartwell.widgets.cluster; + +import android.graphics.drawable.Drawable; + +public interface ClusterRender { + /** + * 根据聚合点的元素数目返回渲染背景样式 + */ + Drawable getDrawableByCount(int clusterNum); +} diff --git a/app/src/main/java/com/casic/app/smartwell/widgets/cluster/RegionItem.java b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/RegionItem.java new file mode 100644 index 0000000..7b2b6c4 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/RegionItem.java @@ -0,0 +1,23 @@ +package com.casic.app.smartwell.widgets.cluster; + +import com.amap.api.maps.model.LatLng; +import com.casic.app.smartwell.model.MapWellListModel; + +public class RegionItem implements ClusterItem { + private final LatLng latLng; + private final MapWellListModel.DataModel well; + + public RegionItem(LatLng latLng, MapWellListModel.DataModel well) { + this.latLng = latLng; + this.well = well; + } + + @Override + public LatLng getPosition() { + return latLng; + } + + public MapWellListModel.DataModel getWell() { + return well; + } +} diff --git a/app/src/main/java/com/casic/app/smartwell/widgets/cluster/RemoveAnimationListener.java b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/RemoveAnimationListener.java new file mode 100644 index 0000000..c9c5e84 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/RemoveAnimationListener.java @@ -0,0 +1,30 @@ +package com.casic.app.smartwell.widgets.cluster; + +import com.amap.api.maps.model.Marker; +import com.amap.api.maps.model.animation.Animation; + +import java.util.List; + +/** + * marker渐变动画,动画结束后将Marker删除 + */ +public class RemoveAnimationListener implements Animation.AnimationListener { + private final List removeMarkers; + + public RemoveAnimationListener(List removeMarkers) { + this.removeMarkers = removeMarkers; + } + + @Override + public void onAnimationStart() { + + } + + @Override + public void onAnimationEnd() { + for (Marker marker : removeMarkers) { + marker.remove(); + } + removeMarkers.clear(); + } +} \ No newline at end of file diff --git a/app/src/main/res/anim/map_popup_hide.xml b/app/src/main/res/anim/map_popup_hide.xml new file mode 100644 index 0000000..119726b --- /dev/null +++ b/app/src/main/res/anim/map_popup_hide.xml @@ -0,0 +1,12 @@ + + + + \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/extensions/Int.kt b/app/src/main/java/com/casic/app/smartwell/extensions/Int.kt index de0617b..a0a5e33 100644 --- a/app/src/main/java/com/casic/app/smartwell/extensions/Int.kt +++ b/app/src/main/java/com/casic/app/smartwell/extensions/Int.kt @@ -1,9 +1,24 @@ package com.casic.app.smartwell.extensions +import android.graphics.Bitmap +import android.graphics.Canvas +import android.graphics.Paint +import android.graphics.RectF + fun Int.toLevel(): String { return if (this == 0) { "" } else { this.toString() } +} + +fun Int.drawCircle(color: Int): Bitmap? { + val bitmap = Bitmap.createBitmap(this * 2, this * 2, Bitmap.Config.ARGB_8888) + val canvas = Canvas(bitmap) + val paint = Paint() + val rectF = RectF(0f, 0f, (this * 2).toFloat(), (this * 2).toFloat()) + paint.color = color + canvas.drawArc(rectF, 0f, 360f, true, paint) + return bitmap } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt index 6b6ca3e..5e45534 100644 --- a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt +++ b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt @@ -2,17 +2,13 @@ import android.content.Context import com.casic.app.smartwell.callback.OnImageCompressListener -import com.casic.app.smartwell.model.ErrorMessageModel import com.casic.app.smartwell.utils.LocaleConstant -import com.google.gson.Gson -import com.google.gson.reflect.TypeToken +import com.google.gson.JsonParser import com.pengxh.kt.lite.extensions.createCompressImageDir import com.pengxh.kt.lite.utils.SaveKeyValues -import org.json.JSONObject import top.zibin.luban.Luban import top.zibin.luban.OnCompressListener import java.io.File -import java.util.Locale /** * String扩展方法 @@ -74,18 +70,22 @@ } } -fun String.separateResponseCode(): Int { +fun String.getResponseCode(): Int { if (this.isBlank()) { return 404 } - return JSONObject(this).getInt("code") + val element = JsonParser.parseString(this) + val jsonObject = element.asJsonObject + return jsonObject.get("code").asInt } -fun String.toErrorMessage(): String { - val errorModel = Gson().fromJson( - this, object : TypeToken() {}.type - ) - return errorModel.message.toString() +fun String.getResponseMessage(): String { + if (this.isBlank()) { + return "" + } + val element = JsonParser.parseString(this) + val jsonObject = element.asJsonObject + return jsonObject.get("message").asString } fun String.compressImage(context: Context, listener: OnImageCompressListener) { @@ -93,9 +93,6 @@ .load(this) .ignoreBy(100) .setTargetDir(context.createCompressImageDir().toString()) - .filter { - !(it.isBlank() || it.lowercase(Locale.getDefault()).endsWith(".gif")) - } .setCompressListener(object : OnCompressListener { override fun onStart() { 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 96df110..cd25fca 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 @@ -1,26 +1,25 @@ package com.casic.app.smartwell.fragment -import android.graphics.Point +import android.graphics.Color +import android.graphics.drawable.BitmapDrawable +import android.graphics.drawable.Drawable 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 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.LatLngBounds import com.amap.api.maps.model.Marker -import com.amap.api.maps.model.MarkerOptions import com.casic.app.smartwell.R import com.casic.app.smartwell.databinding.FragmentHomeBinding +import com.casic.app.smartwell.extensions.drawCircle import com.casic.app.smartwell.extensions.initImmersionBar -import com.casic.app.smartwell.extensions.valueToType import com.casic.app.smartwell.model.MapWellListModel import com.casic.app.smartwell.utils.LocaleConstant import com.casic.app.smartwell.utils.RouteOnMap @@ -31,9 +30,16 @@ import com.casic.app.smartwell.view.WellOperationActivity import com.casic.app.smartwell.vm.OrderViewModel import com.casic.app.smartwell.vm.WellViewModel +import com.casic.app.smartwell.widgets.MapWellPopup +import com.casic.app.smartwell.widgets.cluster.ClusterItem +import com.casic.app.smartwell.widgets.cluster.ClusterOnClickListener +import com.casic.app.smartwell.widgets.cluster.ClusterOverlay +import com.casic.app.smartwell.widgets.cluster.RegionItem 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.convertDrawable +import com.pengxh.kt.lite.extensions.dp2px import com.pengxh.kt.lite.extensions.navigatePageTo import com.pengxh.kt.lite.extensions.show import com.pengxh.kt.lite.utils.LoadingDialogHub @@ -43,35 +49,23 @@ /** * 地图点位带聚合效果 * */ -class HomePageHaveClusterFragment : KotlinBaseFragment(), AMap.OnMapLoadedListener, - AMap.OnCameraChangeListener, AMap.OnMarkerClickListener, AMap.InfoWindowAdapter, - AMap.OnInfoWindowClickListener { +class HomePageHaveClusterFragment : KotlinBaseFragment(), + AMap.OnCameraChangeListener { private val kTag = "HaveClusterFragment" private val easyPopupWindow by lazy { EasyPopupWindow(requireContext()) } - private lateinit var wellViewModel: WellViewModel - private lateinit var orderViewModel: OrderViewModel - private lateinit var aMap: AMap - - /** - * 所有的marker - */ - private var allMarkerOptions: MutableList = ArrayList() - - /** - * 视野内的marker - */ - private var markerOptionsInView: MutableList = ArrayList() - - /** - * 自定义Marker弹出框 - * */ - private lateinit var v: View + private val regionRadius by lazy { LocaleConstant.RADIUS_SIZE.dp2px(requireContext()) } + private val infoPopup by lazy { MapWellPopup(requireContext()) } /** * 所有窨井列表信息集合 * */ - private var wellModels: MutableList = ArrayList() + private val wellModels = ArrayList() + private val backDrawables = HashMap() + private lateinit var wellViewModel: WellViewModel + private lateinit var orderViewModel: OrderViewModel + private lateinit var aMap: AMap + private var clusterOverlay: ClusterOverlay? = null override fun initViewBinding( inflater: LayoutInflater, @@ -106,6 +100,9 @@ } }) + //地图初始化 + initMap(savedInstanceState) + //初始化vm wellViewModel = ViewModelProvider(this)[WellViewModel::class.java] orderViewModel = ViewModelProvider(this)[OrderViewModel::class.java] @@ -120,25 +117,19 @@ val latitudeList: MutableList = ArrayList() val longitudeList: MutableList = ArrayList() it.data?.forEach { well -> - val lat = well.latGaode.toString() - val lng = well.lngGaode.toString() + val lat = well.latGaode + val lng = well.lngGaode if (lat.isNotBlank() && lng.isNotBlank()) { //返回true代表当前位置在大陆、港澳地区,反之不在 val latitude = lat.toDouble() val longitude = lng.toDouble() if (CoordinateConverter.isAMapDataAvailable(latitude, longitude)) { - //缓存所有设备详情,点击Marker时候需要 + //缓存所有井 wellModels.add(well) + //分别缓存经、纬度 latitudeList.add(latitude) longitudeList.add(longitude) - //将所有设备信息转化缓存为Marker点 - allMarkerOptions.add( - MarkerOptions() - .position(LatLng(latitude, longitude)) - .title(well.wellTypeName) - .snippet(well.wellName) - ) } } } @@ -160,12 +151,12 @@ val cameraPosition = CameraPosition(centerLatLng, 16f, 0f, 0f) val cameraUpdate = CameraUpdateFactory.newCameraPosition(cameraPosition) aMap.animateCamera(cameraUpdate, 1500, null) + + //显示点数据 + displayWellOnMap() } } - //地图初始化 - initMap(savedInstanceState) - //获取窨井监控数据 wellViewModel.countResultModel.observe(this) { binding.deployedWellView.text = it["bfWell"] @@ -220,17 +211,10 @@ uiSettings.isCompassEnabled = true uiSettings.zoomPosition = AMapOptions.ZOOM_POSITION_RIGHT_CENTER uiSettings.isTiltGesturesEnabled = false//不许地图随手势倾斜角度 + uiSettings.isRotateGesturesEnabled = false//不允许地图随手势改变方位 - // 地图加载成功监听 - aMap.addOnMapLoadedListener(this) // 地图缩放监听 aMap.addOnCameraChangeListener(this) - // marker 点击事件监听 - aMap.addOnMarkerClickListener(this) - // 点击marker弹出自定义popup - aMap.setInfoWindowAdapter(this) - //信息窗点击事件 - aMap.addOnInfoWindowClickListener(this) } override fun initEvent() { @@ -259,9 +243,111 @@ } - override fun onMapLoaded() { - //地图加载成功之后显示聚合点数据 - initClustersMarkers() + private fun displayWellOnMap() { + clusterOverlay?.onDestroy() + val clusterItems = ArrayList() + + wellModels.forEach { + val latitude = it.latGaode.toDouble() + val longitude = it.lngGaode.toDouble() + + val latLng = LatLng(latitude, longitude, false) + val regionItem = RegionItem(latLng, it) + clusterItems.add(regionItem) + } + + clusterOverlay = ClusterOverlay(requireContext(), aMap, clusterItems, regionRadius) + clusterOverlay?.setClusterRender { clusterNum -> + //聚合圆半径 + val radius = 100.dp2px(requireContext()) + if (clusterNum == 0) { + var bitmapDrawable = backDrawables[0] + if (bitmapDrawable == null) { + bitmapDrawable = BitmapDrawable( + null, radius.drawCircle(Color.argb(159, 100, 149, 237)) + ) + backDrawables[0] = bitmapDrawable + } + bitmapDrawable + } + if (clusterNum == 1) { + var bitmapDrawable = backDrawables[1] + if (bitmapDrawable == null) { + bitmapDrawable = R.mipmap.well_location.convertDrawable(requireContext())!! + backDrawables[1] = bitmapDrawable + } + bitmapDrawable + } else if (clusterNum < 5) { + var bitmapDrawable = backDrawables[2] + if (bitmapDrawable == null) { + bitmapDrawable = BitmapDrawable( + null, radius.drawCircle(Color.argb(159, 100, 149, 237)) + ) + backDrawables[2] = bitmapDrawable + } + bitmapDrawable + } else if (clusterNum < 10) { + var bitmapDrawable = backDrawables[3] + if (bitmapDrawable == null) { + bitmapDrawable = BitmapDrawable( + null, radius.drawCircle(Color.argb(199, 30, 144, 255)) + ) + backDrawables[3] = bitmapDrawable + } + bitmapDrawable + } else { + var bitmapDrawable = backDrawables[4] + if (bitmapDrawable == null) { + bitmapDrawable = BitmapDrawable( + null, radius.drawCircle(Color.argb(235, 65, 105, 225)) + ) + backDrawables[4] = bitmapDrawable + } + bitmapDrawable + } + } + + clusterOverlay?.setOnClusterClickListener(object : ClusterOnClickListener { + override fun onMarkerClicked(marker: Marker?, items: List) { + if (items.size > 1) { + "请缩放地图比例在查看数据".show(requireContext()) + return + } + + var item: RegionItem? = null + val builder = LatLngBounds.Builder() + for (clusterItem in items) { + builder.include(clusterItem.position) + item = clusterItem as RegionItem + } + + item?.apply { + showWellPopup(well) + } + } + }) + } + + private fun showWellPopup(well: MapWellListModel.DataModel) { + infoPopup.set(well, object : MapWellPopup.OnPopupWindowClickListener { + override fun onPopupClicked(lat: Double, lng: Double) { + AlertControlDialog.Builder().setContext(requireContext()).setTitle("操作提示") + .setMessage("确定要前往吗").setNegativeButton("取消").setPositiveButton("确定") + .setOnDialogButtonClickListener(object : + AlertControlDialog.OnDialogButtonClickListener { + override fun onConfirmClick() { + RouteOnMap.startNavigation( + requireContext(), "", LatLng(lat, lng) + ) + } + + override fun onCancelClick() { + + } + }).build().show() + } + }) + infoPopup.showAsDropDown(binding.rightOptionView) } override fun onCameraChange(p0: CameraPosition?) { @@ -282,103 +368,10 @@ } } - //获取视野内的marker 根据聚合算法合成自定义的marker 显示视野内的marker override fun onCameraChangeFinish(p0: CameraPosition?) { //地图缩放之后显示聚合点数据 LoadingDialogHub.dismiss() httpCountDownTimer.cancel() - initClustersMarkers() - } - - private fun initClustersMarkers() { - 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 { - v = LayoutInflater.from(requireContext()).inflate(R.layout.popup_map_info, null) - - //显示闸井信息 - marker?.showInfoWindow() - return true - } - - override fun getInfoWindow(marker: Marker?): View { - //反射得到popup里面的控件对象 - val wellNameView = v.findViewById(R.id.wellNameView) - val wellCodeView = v.findViewById(R.id.wellCodeView) - val wellTypeView = v.findViewById(R.id.wellTypeView) - val wellStateView = v.findViewById(R.id.wellStateView) - val deepView = v.findViewById(R.id.deepView) - val locationView = v.findViewById(R.id.locationView) - - //绑定数据 - val clickedLatLng = marker?.position!! - wellModels.forEach { well -> - if (clickedLatLng.latitude == well.latGaode!!.toDouble() - && clickedLatLng.longitude == well.lngGaode!!.toDouble() - ) { - wellNameView.text = String.format("点位名称: ${well.wellName}") - wellCodeView.text = String.format("点位编号: ${well.wellCode}") - wellTypeView.text = String.format("点位类型: ${well.wellType.valueToType()}") - val bfztName = if (well.bfzt == "1") { - "已布防" - } else { - "已撤防" - } - wellStateView.text = String.format("布/撤防状态: $bfztName") - deepView.text = String.format("点位深度: ${well.deep}m") - locationView.text = String.format("详细位置: ${well.position}") - } - } - return v - } - - /** - * 此方法不能修改整个 InfoWindow 的背景和边框,无论自定义的样式是什么样,SDK 都会在最外层添加一个默认的边框 - * */ - override fun getInfoContents(p0: Marker?): View? = null - - override fun onInfoWindowClick(p0: Marker?) { - p0?.apply { - AlertControlDialog.Builder() - .setContext(requireContext()) - .setTitle("操作提示") - .setMessage("确定要前往吗") - .setNegativeButton("取消") - .setPositiveButton("确定") - .setOnDialogButtonClickListener(object : - AlertControlDialog.OnDialogButtonClickListener { - override fun onConfirmClick() { - val lat = position.latitude.toString() - val lng = position.longitude.toString() - if (lat.isBlank() || lng.isBlank()) { - "点位经纬度异常,无法开启导航".show(requireContext()) - return - } - RouteOnMap.startNavigation( - requireContext(), snippet, LatLng(lat.toDouble(), lng.toDouble()) - ) - } - - override fun onCancelClick() { - - } - }).build().show() - } } /***以下是地图生命周期管理************************************************************************/ 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 a54d213..bfa7a57 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 @@ -44,8 +44,8 @@ * 地图点位不带聚合效果 * */ class HomePageNoClusterFragment : KotlinBaseFragment(), - AMap.OnMapLoadedListener, AMap.OnCameraChangeListener, AMap.OnMarkerClickListener, - AMap.InfoWindowAdapter, AMap.OnInfoWindowClickListener { + AMap.OnCameraChangeListener, AMap.OnMarkerClickListener, AMap.InfoWindowAdapter, + AMap.OnInfoWindowClickListener { private val kTag = "NoClusterFragment" private val easyPopupWindow by lazy { EasyPopupWindow(requireContext()) } @@ -109,6 +109,9 @@ wellViewModel = ViewModelProvider(this)[WellViewModel::class.java] orderViewModel = ViewModelProvider(this)[OrderViewModel::class.java] + //地图初始化 + initMap(savedInstanceState) + //获取所有窨井数据 httpCountDownTimer.start() LoadingDialogHub.show(requireActivity(), "数据加载中,请稍后...") @@ -157,12 +160,12 @@ val cameraPosition = CameraPosition(centerLatLng, 16f, 0f, 0f) val cameraUpdate = CameraUpdateFactory.newCameraPosition(cameraPosition) aMap.animateCamera(cameraUpdate, 1500, null) + + //显示点数据 + displayWellOnMap() } } - //地图初始化 - initMap(savedInstanceState) - //获取窨井监控数据 wellViewModel.countResultModel.observe(this) { binding.deployedWellView.text = it["bfWell"] @@ -214,9 +217,8 @@ uiSettings.isCompassEnabled = true uiSettings.zoomPosition = AMapOptions.ZOOM_POSITION_RIGHT_CENTER uiSettings.isTiltGesturesEnabled = false//不许地图随手势倾斜角度 + uiSettings.isRotateGesturesEnabled = false//不允许地图随手势改变方位 - // 地图加载成功监听 - aMap.addOnMapLoadedListener(this) // 地图缩放监听 aMap.addOnCameraChangeListener(this) // marker 点击事件监听 @@ -253,11 +255,6 @@ } - override fun onMapLoaded() { - //地图加载成功之后显示聚合点数据 - initClustersMarkers() - } - override fun onCameraChange(p0: CameraPosition?) { } @@ -281,10 +278,9 @@ //地图缩放之后显示聚合点数据 LoadingDialogHub.dismiss() httpCountDownTimer.cancel() - initClustersMarkers() } - private fun initClustersMarkers() { + private fun displayWellOnMap() { val proj = aMap.projection val dm = resources.displayMetrics var screenLocation: Point diff --git a/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.java b/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.java deleted file mode 100644 index d8b18ef..0000000 --- a/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.java +++ /dev/null @@ -1,50 +0,0 @@ -package com.casic.app.smartwell.model; - -public class ErrorMessageModel { - - private int code; - private String data; - private String exceptionClazz; - private String message; - private boolean success; - - public int getCode() { - return code; - } - - public void setCode(int code) { - this.code = code; - } - - public String getData() { - return data; - } - - public void setData(String data) { - this.data = data; - } - - public String getExceptionClazz() { - return exceptionClazz; - } - - public void setExceptionClazz(String exceptionClazz) { - this.exceptionClazz = exceptionClazz; - } - - public String getMessage() { - return message; - } - - public void setMessage(String message) { - this.message = message; - } - - public boolean isSuccess() { - return success; - } - - public void setSuccess(boolean success) { - this.success = success; - } -} \ No newline at end of file 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 new file mode 100644 index 0000000..215ac0c --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/PipelineModel.java @@ -0,0 +1,328 @@ +package com.casic.app.smartwell.model; + +import java.util.List; + +public class PipelineModel { + + private Integer code; + private DataModel data; + private String message; + private Boolean success; + + public Integer getCode() { + return code; + } + + public void setCode(Integer code) { + this.code = code; + } + + public DataModel getData() { + return data; + } + + public void setData(DataModel data) { + this.data = data; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + public Boolean getSuccess() { + return success; + } + + public void setSuccess(Boolean success) { + this.success = success; + } + + public static class DataModel { + private List rows; + private Integer total; + + public List getRows() { + return rows; + } + + public void setRows(List rows) { + this.rows = rows; + } + + public Integer getTotal() { + return total; + } + + public void setTotal(Integer total) { + this.total = total; + } + + 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 getBuryMode() { + return buryMode; + } + + public void setBuryMode(String buryMode) { + this.buryMode = buryMode; + } + + public String getConstructEra() { + return constructEra; + } + + public void setConstructEra(String constructEra) { + this.constructEra = constructEra; + } + + 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; + } + } + } +} 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 06d3d2b..4f38a2c 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 = 100 //相距多少米才聚合,单位:米 + const val RADIUS_SIZE = 80 //相距多少米才聚合,单位:米 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:11308" + // 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 0d5f3fa..991e1db 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 @@ -312,4 +312,14 @@ @Header("token") token: String, @Field("clientid") deviceCode: String ): String + + /** + * 管线位置数据 + */ + @GET("/pipeline/listPage") + suspend fun getPipeline( + @Header("token") token: String, + @Query("limit") limit: Int, + @Query("offset") offset: Int + ): String } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt index 1a0ce22..4050067 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt @@ -294,4 +294,11 @@ suspend fun registerPush(clientId: String): String { return api.registerPush(AuthenticationHelper.token!!, clientId) } + + /** + * 管线位置数据 + */ + suspend fun getPipeline(): String { + return api.getPipeline(AuthenticationHelper.token!!, 2000, 1) + } } \ No newline at end of file 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 9270fa1..4ca5a5e 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.HomePageNoClusterFragment +import com.casic.app.smartwell.fragment.HomePageHaveClusterFragment 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/vm/AlarmViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/AlarmViewModel.kt index 9cff08c..e7acc17 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/AlarmViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/AlarmViewModel.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.AlarmContentModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager import com.google.gson.Gson @@ -16,7 +16,7 @@ fun getAlarmContentType(alarmType: String) = launch({ val response = RetrofitServiceManager.getAlarmContentType(alarmType) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { listModel.value = gson.fromJson( response, object : TypeToken() {}.type diff --git a/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt index 5e5b163..895dedd 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.PublicKeyModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager import com.google.gson.Gson @@ -18,7 +18,7 @@ fun getPublicKey() = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.authenticate() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { keyModel.value = gson.fromJson( response, object : TypeToken() {}.type diff --git a/app/src/main/java/com/casic/app/smartwell/vm/DeviceViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/DeviceViewModel.kt index db5ccf6..899a962 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/DeviceViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/DeviceViewModel.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.DeviceDetailModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager import com.google.gson.Gson @@ -16,7 +16,7 @@ fun getDeviceDetail(deviceCode: String) = launch({ val response = RetrofitServiceManager.getDeviceDetail(deviceCode) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { detailModel.value = gson.fromJson( response, object : TypeToken() {}.type diff --git a/app/src/main/java/com/casic/app/smartwell/vm/LoginViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/LoginViewModel.kt index cd8b8a9..a417398 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/LoginViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/LoginViewModel.kt @@ -2,7 +2,7 @@ import androidx.lifecycle.MutableLiveData import com.casic.app.smartwell.base.BaseApplication -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.CommonResultModel import com.casic.app.smartwell.model.LoginResultModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -21,7 +21,7 @@ fun enter(account: String, secretKey: String) = launch({ val response = RetrofitServiceManager.login(account, secretKey) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success enterResultModel.value = gson.fromJson( @@ -38,7 +38,7 @@ fun out() = launch({ val response = RetrofitServiceManager.loginOut() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { outResultModel.value = gson.fromJson( response, object : TypeToken() {}.type diff --git a/app/src/main/java/com/casic/app/smartwell/vm/OperationViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/OperationViewModel.kt index 8943ed3..37e115f 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/OperationViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/OperationViewModel.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.vm import com.casic.app.smartwell.base.BaseApplication -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager import com.pengxh.kt.lite.base.BaseViewModel import com.pengxh.kt.lite.extensions.launch @@ -16,7 +16,7 @@ fun acceptWorkOrder(id: String) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.acceptWorkOrder(id) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success "接单成功".show(BaseApplication.get()) @@ -35,7 +35,7 @@ loadState.value = LoadState.Loading val response = RetrofitServiceManager.confirmWorkOrder(id, firstState, firstStatePhotos, needHandle) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success "工单确认成功".show(BaseApplication.get()) @@ -50,7 +50,7 @@ fun transferWorkOrder(id: String, userId: String) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.transferWorkOrder(id, userId) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success "转单成功".show(BaseApplication.get()) @@ -65,7 +65,7 @@ fun completeWorkOrder(id: String, handleMessage: String, handlePhotos: String) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.completeWorkOrder(id, handleMessage, handlePhotos) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success "工单处理成功".show(BaseApplication.get()) diff --git a/app/src/main/java/com/casic/app/smartwell/vm/OrderViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/OrderViewModel.kt index 4cb26b7..d2fad86 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/OrderViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/OrderViewModel.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.OrderDetailModel import com.casic.app.smartwell.model.OrderListModel import com.casic.app.smartwell.model.OrderStatusModel @@ -37,7 +37,7 @@ val response = RetrofitServiceManager.getSearchResult( keywords, alarmContent, alarmLevel, jobStatus, deptId, beginTime, endTime, offset ) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success searchResult.value = gson.fromJson( @@ -53,7 +53,7 @@ fun getWorkOrderListByState(jobStatus: String, page: Int) = launch({ val response = RetrofitServiceManager.getWorkOrderList(jobStatus, page) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { orderList.value = gson.fromJson( response, object : TypeToken() {}.type @@ -65,7 +65,7 @@ fun getNotAcceptOderList(page: Int) = launch({ val response = RetrofitServiceManager.getNotAcceptOderList(page) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { orderList.value = gson.fromJson( response, object : TypeToken() {}.type @@ -77,7 +77,7 @@ fun getNotHandleOderList(page: Int) = launch({ val response = RetrofitServiceManager.getNotHandleOderList(page) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { orderList.value = gson.fromJson( response, object : TypeToken() {}.type @@ -89,7 +89,7 @@ fun countWorkOrderByState() = launch({ val response = RetrofitServiceManager.countWorkOrderByState() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { val map = HashMap(4) @@ -107,7 +107,7 @@ fun getOrderStatus() = launch({ val response = RetrofitServiceManager.getOrderStatus() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { orderStatusModel.value = gson.fromJson( response, object : TypeToken() {}.type @@ -120,7 +120,7 @@ fun getWorkOrderDetail(id: String) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.getWorkOrderDetail(id) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success detailModel.value = gson.fromJson( diff --git a/app/src/main/java/com/casic/app/smartwell/vm/PipelineViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/PipelineViewModel.kt new file mode 100644 index 0000000..60c1e2f --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/vm/PipelineViewModel.kt @@ -0,0 +1,28 @@ +package com.casic.app.smartwell.vm + +import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.extensions.getResponseCode +import com.casic.app.smartwell.model.PipelineModel +import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken +import com.pengxh.kt.lite.base.BaseViewModel +import com.pengxh.kt.lite.extensions.launch + +class PipelineViewModel : BaseViewModel() { + + private val gson by lazy { Gson() } + val lineResult = MutableLiveData() + + fun getPipeline() = launch({ + val response = RetrofitServiceManager.getPipeline() + val responseCode = response.getResponseCode() + if (responseCode == 200) { + lineResult.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } + }, { + it.printStackTrace() + }) +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/PushViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/PushViewModel.kt index 9279815..12fd610 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/PushViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/PushViewModel.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.CommonResultModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager import com.google.gson.Gson @@ -16,7 +16,7 @@ fun registerPush(clientId: String) = launch({ val response = RetrofitServiceManager.registerPush(clientId) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { registerResultModel.value = gson.fromJson( response, object : TypeToken() {}.type diff --git a/app/src/main/java/com/casic/app/smartwell/vm/UploadImageViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/UploadImageViewModel.kt index 8d6744e..9707eeb 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/UploadImageViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/UploadImageViewModel.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.CommonResultModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager import com.google.gson.Gson @@ -19,7 +19,7 @@ fun uploadImage(image: File) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.uploadImage(image) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success resultModel.value = gson.fromJson( diff --git a/app/src/main/java/com/casic/app/smartwell/vm/UserViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/UserViewModel.kt index 31a4d4c..070c35a 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/UserViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/UserViewModel.kt @@ -2,7 +2,7 @@ import androidx.lifecycle.MutableLiveData import com.casic.app.smartwell.base.BaseApplication -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.SubordinateModel import com.casic.app.smartwell.model.UserDetailModel import com.casic.app.smartwell.model.VersionResultModel @@ -25,7 +25,7 @@ fun getUserDetail() = launch({ val response = RetrofitServiceManager.getUserDetail() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { val userDetail = gson.fromJson( response, object : TypeToken() {}.type @@ -48,7 +48,7 @@ * */ fun getSubordinate(hasMine: String?, deptId: String?, roleTips: String?) = launch({ val response = RetrofitServiceManager.getSubordinate(hasMine, deptId, roleTips) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { subordinateModel.value = gson.fromJson( response, object : TypeToken() {}.type @@ -61,7 +61,7 @@ fun changePassword(oldPwd: String, newPwd: String) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.changePassword(oldPwd, newPwd) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success "修改成功,请重新登录".show(BaseApplication.get()) @@ -76,7 +76,7 @@ fun updateVersion() = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.updateVersion() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success versionResultModel.value = gson.fromJson( diff --git a/app/src/main/java/com/casic/app/smartwell/vm/WellViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/WellViewModel.kt index 3d41e9b..9e42e36 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/WellViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/WellViewModel.kt @@ -2,8 +2,7 @@ import androidx.lifecycle.MutableLiveData import com.casic.app.smartwell.base.BaseApplication -import com.casic.app.smartwell.extensions.separateResponseCode -import com.casic.app.smartwell.extensions.toErrorMessage +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.AuthorDeptModel import com.casic.app.smartwell.model.CommonResultModel import com.casic.app.smartwell.model.MapWellListModel @@ -32,7 +31,7 @@ fun countWellByState() = launch({ val response = RetrofitServiceManager.countWellByState() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { val map = HashMap(3) @@ -57,7 +56,7 @@ fun getWellType() = launch({ val response = RetrofitServiceManager.getWellType() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { wellTypeModel.value = gson.fromJson( response, object : TypeToken() {}.type @@ -70,7 +69,7 @@ fun getWellDetail(id: String) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.getWellDetail(id) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success wellDetailModel.value = gson.fromJson( @@ -87,7 +86,7 @@ fun getOperationResult(id: String, state: String) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.getOperationResult(id, state) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success "操作成功".show(BaseApplication.get()) @@ -105,7 +104,7 @@ fun getMonitorResult(id: String) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.getMonitorResult(id) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success monitorModel.value = gson.fromJson( @@ -125,7 +124,7 @@ val response = RetrofitServiceManager.getWellListByPage( keywords, wellType, deptid, bfzt, page ) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { listModel.value = gson.fromJson( response, object : TypeToken() {}.type @@ -137,13 +136,11 @@ fun getWellList() = launch({ val response = RetrofitServiceManager.getWellList() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { totalWellModel.value = gson.fromJson( response, object : TypeToken() {}.type ) - } else { - response.toErrorMessage().show(BaseApplication.get()) } }, { it.printStackTrace() diff --git a/app/src/main/java/com/casic/app/smartwell/widgets/GaoDeClusterMarkerView.kt b/app/src/main/java/com/casic/app/smartwell/widgets/GaoDeClusterMarkerView.kt deleted file mode 100644 index 1f375df..0000000 --- a/app/src/main/java/com/casic/app/smartwell/widgets/GaoDeClusterMarkerView.kt +++ /dev/null @@ -1,100 +0,0 @@ -package com.casic.app.smartwell.widgets - -import android.content.Context -import android.graphics.Bitmap -import android.graphics.Point -import android.view.Gravity -import android.view.LayoutInflater -import android.view.View -import android.widget.TextView -import com.amap.api.maps.Projection -import com.amap.api.maps.model.BitmapDescriptorFactory -import com.amap.api.maps.model.LatLng -import com.amap.api.maps.model.LatLngBounds -import com.amap.api.maps.model.MarkerOptions -import com.casic.app.smartwell.R -import com.pengxh.kt.lite.extensions.toBitmap -import java.util.* - -class GaoDeClusterMarkerView( - private val context: Context, firstMarkers: MarkerOptions, projection: Projection, gridSize: Int -) { - //当前可观区域里的 聚合过之后的集合 - private val includeMarkers: ArrayList - - // 创建区域 - val bounds: LatLngBounds - var options: MarkerOptions = MarkerOptions() - - init { - val screenLocation = projection.toScreenLocation(firstMarkers.position) - //范围类 - val southwestPoint = Point(screenLocation.x - gridSize, screenLocation.y + gridSize) - //范围类 - val northeastPoint = Point(screenLocation.x + gridSize, screenLocation.y - gridSize) - bounds = LatLngBounds( - projection.fromScreenLocation(southwestPoint), - projection.fromScreenLocation(northeastPoint) - ) - //设置初始化marker属性 - options.anchor(0.5f, 1.3f) - .title(firstMarkers.title) - .position(firstMarkers.position) - .icon(firstMarkers.icon) - .snippet(firstMarkers.snippet) - .draggable(false) - includeMarkers = ArrayList() - includeMarkers.add(firstMarkers) - } - - /** - * 添加marker - */ - fun addMarker(markerOptions: MarkerOptions) { - includeMarkers.add(markerOptions) // 添加到列表中 - } - - /** - * 设置聚合点的中心位置以及图标 - */ - fun setPositionAndIcon() { - val size = includeMarkers.size - var lat = 0.0 - var lng = 0.0 - // 一个的时候 - if (size == 1) { //设置marker单个属性 - // 设置marker位置 - options.position( - LatLng( - includeMarkers[0].position.latitude, includeMarkers[0].position.longitude - ) - ) - } else { // 聚合的时候 - //设置marker聚合属性 - for (op in includeMarkers) { - lat += op.position.latitude - lng += op.position.longitude - } - // 设置marker的位置为中心位置为聚集点的平均位置 - options.position(LatLng(lat / size, lng / size)) - } - options.icon(BitmapDescriptorFactory.fromBitmap(getBitmap(size))) - } - - /** - * marker视图 - */ - private fun getBitmap(num: Int): Bitmap? { - val view = LayoutInflater.from(context).inflate(R.layout.marker_gaode, null) - val wellCountView = view.findViewById(R.id.wellCountView) - return if (num > 1) { - wellCountView.visibility = View.VISIBLE - wellCountView.text = String.format("${num}个") - wellCountView.gravity = Gravity.CENTER - view.toBitmap() - } else { - wellCountView.visibility = View.GONE - BitmapDescriptorFactory.fromResource(R.mipmap.well_location).bitmap - } - } -} \ No newline at end of file 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 new file mode 100644 index 0000000..ec455dd --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/widgets/MapWellPopup.kt @@ -0,0 +1,58 @@ +package com.casic.app.smartwell.widgets + +import android.content.Context +import android.view.LayoutInflater +import android.view.ViewGroup +import android.widget.LinearLayout +import android.widget.PopupWindow +import android.widget.TextView +import com.casic.app.smartwell.R +import com.casic.app.smartwell.extensions.valueToType +import com.casic.app.smartwell.model.MapWellListModel + +class MapWellPopup constructor(context: Context) : PopupWindow() { + + init { + width = ViewGroup.LayoutParams.MATCH_PARENT + height = ViewGroup.LayoutParams.WRAP_CONTENT + isOutsideTouchable = true + isFocusable = true + animationStyle = R.style.MapPopupAnimation + setBackgroundDrawable(null) + contentView = LayoutInflater.from(context).inflate( + R.layout.popup_map_info, null, false + ) + } + + fun set(well: MapWellListModel.DataModel, windowClickListener: OnPopupWindowClickListener) { + //反射得到popup里面的控件对象 + val rootView = contentView.findViewById(R.id.rootView) + val wellNameView = contentView.findViewById(R.id.wellNameView) + val wellCodeView = contentView.findViewById(R.id.wellCodeView) + val wellTypeView = contentView.findViewById(R.id.wellTypeView) + val wellStateView = contentView.findViewById(R.id.wellStateView) + val deepView = contentView.findViewById(R.id.deepView) + val locationView = contentView.findViewById(R.id.locationView) + + //绑定数据 + wellNameView.text = String.format("点位名称: ${well.wellName}") + wellCodeView.text = String.format("点位编号: ${well.wellCode}") + wellTypeView.text = String.format("点位类型: ${well.wellType.valueToType()}") + val bfztName = if (well.bfzt == "1") { + "已布防" + } else { + "已撤防" + } + wellStateView.text = String.format("布/撤防状态: $bfztName") + deepView.text = String.format("点位深度: ${well.deep}m") + locationView.text = String.format("详细位置: ${well.position}") + + rootView.setOnClickListener { + windowClickListener.onPopupClicked(well.latGaode.toDouble(), well.lngGaode.toDouble()) + } + } + + interface OnPopupWindowClickListener { + fun onPopupClicked(lat: Double, lng: Double) + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/widgets/cluster/Cluster.java b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/Cluster.java new file mode 100644 index 0000000..9455ccd --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/Cluster.java @@ -0,0 +1,43 @@ +package com.casic.app.smartwell.widgets.cluster; + +import com.amap.api.maps.model.LatLng; +import com.amap.api.maps.model.Marker; + +import java.util.ArrayList; +import java.util.List; + +public class Cluster { + private final LatLng latLng; + private final List clusterItems; + private Marker marker; + + + public Cluster(LatLng latLng) { + this.latLng = latLng; + clusterItems = new ArrayList<>(); + } + + public void addClusterItem(ClusterItem clusterItem) { + clusterItems.add(clusterItem); + } + + public int getClusterCount() { + return clusterItems.size(); + } + + public LatLng getCenterLatLng() { + return latLng; + } + + public void setMarker(Marker marker) { + this.marker = marker; + } + + public Marker getMarker() { + return marker; + } + + public List getClusterItems() { + return clusterItems; + } +} diff --git a/app/src/main/java/com/casic/app/smartwell/widgets/cluster/ClusterItem.java b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/ClusterItem.java new file mode 100644 index 0000000..f5d9a9d --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/ClusterItem.java @@ -0,0 +1,10 @@ +package com.casic.app.smartwell.widgets.cluster; + +import com.amap.api.maps.model.LatLng; + +public interface ClusterItem { + /** + * 返回聚合元素的地理位置 + */ + LatLng getPosition(); +} diff --git a/app/src/main/java/com/casic/app/smartwell/widgets/cluster/ClusterOnClickListener.java b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/ClusterOnClickListener.java new file mode 100644 index 0000000..0efa1f1 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/ClusterOnClickListener.java @@ -0,0 +1,15 @@ +package com.casic.app.smartwell.widgets.cluster; + +import com.amap.api.maps.model.Marker; + +import java.util.List; + +public interface ClusterOnClickListener { + /** + * 点击聚合点的回调处理函数 + * + * @param marker 点击的聚合点 + * @param items 聚合点所包含的元素 + */ + void onMarkerClicked(Marker marker, List items); +} 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 new file mode 100644 index 0000000..40df562 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/ClusterOverlay.java @@ -0,0 +1,349 @@ +package com.casic.app.smartwell.widgets.cluster; + +import android.content.Context; +import android.graphics.Color; +import android.os.Handler; +import android.os.HandlerThread; +import android.os.Looper; +import android.os.Message; +import android.util.TypedValue; +import android.view.Gravity; +import android.widget.TextView; + +import com.amap.api.maps.AMap; +import com.amap.api.maps.AMapUtils; +import com.amap.api.maps.model.BitmapDescriptor; +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.LatLngBounds; +import com.amap.api.maps.model.Marker; +import com.amap.api.maps.model.MarkerOptions; +import com.amap.api.maps.model.animation.AlphaAnimation; +import com.casic.app.smartwell.R; + +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.CopyOnWriteArrayList; + +/** + * 整体设计采用了两个线程,一个线程用于计算组织聚合数据,一个线程负责处理Marker相关操作 + */ +public class ClusterOverlay implements AMap.OnCameraChangeListener, AMap.OnMarkerClickListener { + private final AMap amap; + private final Context context; + private final List clusterItems; + private final List clusters; + private final int clusterSize; + private ClusterOnClickListener clusterClickListener; + private ClusterRender clusterRender; + private final CopyOnWriteArrayList addMarkers = new CopyOnWriteArrayList<>(); + private double clusterDistance; + private final HandlerThread markerHandlerThread = new HandlerThread("addMarker"); + private final HandlerThread signClusterThread = new HandlerThread("calculateCluster"); + private Handler markerHandler; + private Handler signClusterHandler; + private float pxInMeters; + private boolean isCanceled = false; + private final AlphaAnimation addAnimation = new AlphaAnimation(0, 1); + + /** + * 构造函数,批量添加聚合元素时,调用此构造函数 + */ + public ClusterOverlay(Context context, AMap amap, int clusterSize) { + this(context, amap, null, clusterSize); + } + + /** + * 构造函数,批量添加聚合元素时,调用此构造函数 + */ + public ClusterOverlay(Context context, AMap amap, List clusterItems, int clusterSize) { + if (clusterItems != null) { + this.clusterItems = clusterItems; + } else { + this.clusterItems = new ArrayList<>(); + } + this.context = context; + this.clusters = new ArrayList<>(); + this.amap = amap; + this.clusterSize = clusterSize; + this.pxInMeters = amap.getScalePerPixel(); + this.clusterDistance = pxInMeters * clusterSize; + amap.setOnCameraChangeListener(this); + amap.setOnMarkerClickListener(this); + initThreadHandler(); + assignClusters(); + } + + /** + * 设置聚合点的点击事件 + */ + public void setOnClusterClickListener(ClusterOnClickListener clusterClickListener) { + this.clusterClickListener = clusterClickListener; + } + + /** + * 添加一个聚合点 + */ + public void addClusterItem(ClusterItem item) { + Message message = Message.obtain(); + message.what = SignClusterHandler.CALCULATE_SINGLE_CLUSTER; + message.obj = item; + signClusterHandler.sendMessage(message); + } + + /** + * 设置聚合元素的渲染样式,不设置则默认为气泡加数字形式进行渲染 + */ + public void setClusterRender(ClusterRender render) { + this.clusterRender = render; + } + + public void onDestroy() { + isCanceled = true; + signClusterHandler.removeCallbacksAndMessages(null); + markerHandler.removeCallbacksAndMessages(null); + signClusterThread.quit(); + markerHandlerThread.quit(); + for (Marker marker : addMarkers) { + marker.remove(); + } + addMarkers.clear(); + } + + //初始化Handler + private void initThreadHandler() { + markerHandlerThread.start(); + signClusterThread.start(); + markerHandler = new MarkerHandler(markerHandlerThread.getLooper()); + signClusterHandler = new SignClusterHandler(signClusterThread.getLooper()); + } + + @Override + public void onCameraChange(CameraPosition arg0) { + + } + + @Override + public void onCameraChangeFinish(CameraPosition arg0) { + pxInMeters = amap.getScalePerPixel(); + clusterDistance = pxInMeters * clusterSize; + assignClusters(); + } + + @Override + public boolean onMarkerClick(Marker marker) { + if (clusterClickListener == null) { + return true; + } + Cluster cluster = (Cluster) marker.getObject(); + if (cluster != null) { + clusterClickListener.onMarkerClicked(marker, cluster.getClusterItems()); + return true; + } + return false; + } + + /** + * 将聚合元素添加至地图上 + */ + private void addClusterToMap(List clusters) { + ArrayList removeMarkers = new ArrayList<>(addMarkers); + AlphaAnimation alphaAnimation = new AlphaAnimation(1, 0); + RemoveAnimationListener removeAnimationListener = new RemoveAnimationListener(removeMarkers); + for (Marker marker : removeMarkers) { + marker.setAnimation(alphaAnimation); + marker.setAnimationListener(removeAnimationListener); + marker.startAnimation(); + } + + for (Cluster cluster : clusters) { + addSingleClusterToMap(cluster); + } + } + + /** + * 将单个聚合元素添加至地图显示 + */ + private void addSingleClusterToMap(Cluster cluster) { + LatLng latlng = cluster.getCenterLatLng(); + MarkerOptions markerOptions = new MarkerOptions(); + markerOptions.icon(getBitmapDes(cluster.getClusterCount())).position(latlng); + Marker marker = amap.addMarker(markerOptions); + marker.setAnimation(addAnimation); + marker.setObject(cluster); + + marker.startAnimation(); + cluster.setMarker(marker); + addMarkers.add(marker); + } + + private void calculateClusters() { + isCanceled = false; + clusters.clear(); + LatLngBounds visibleBounds = amap.getProjection().getVisibleRegion().latLngBounds; + for (ClusterItem clusterItem : clusterItems) { + if (isCanceled) { + return; + } + LatLng latlng = clusterItem.getPosition(); + if (visibleBounds.contains(latlng)) { + Cluster cluster = getCluster(latlng, clusters); + if (cluster == null) { + cluster = new Cluster(latlng); + clusters.add(cluster); + } + cluster.addClusterItem(clusterItem); + } + } + + //复制一份数据,规避同步 + List tempClusters = new ArrayList<>(clusters); + Message message = Message.obtain(); + message.what = MarkerHandler.ADD_CLUSTER_LIST; + message.obj = tempClusters; + if (isCanceled) { + return; + } + markerHandler.sendMessage(message); + } + + /** + * 对点进行聚合 + */ + private void assignClusters() { + isCanceled = true; + signClusterHandler.removeMessages(SignClusterHandler.CALCULATE_CLUSTER); + signClusterHandler.sendEmptyMessage(SignClusterHandler.CALCULATE_CLUSTER); + } + + /** + * 在已有的聚合基础上,对添加的单个元素进行聚合 + */ + private void calculateSingleCluster(ClusterItem clusterItem) { + LatLngBounds visibleBounds = amap.getProjection().getVisibleRegion().latLngBounds; + LatLng latlng = clusterItem.getPosition(); + if (!visibleBounds.contains(latlng)) { + return; + } + Cluster cluster = getCluster(latlng, clusters); + if (cluster != null) { + cluster.addClusterItem(clusterItem); + Message message = Message.obtain(); + message.what = MarkerHandler.UPDATE_SINGLE_CLUSTER; + + message.obj = cluster; + markerHandler.removeMessages(MarkerHandler.UPDATE_SINGLE_CLUSTER); + markerHandler.sendMessageDelayed(message, 5); + } else { + cluster = new Cluster(latlng); + clusters.add(cluster); + cluster.addClusterItem(clusterItem); + Message message = Message.obtain(); + message.what = MarkerHandler.ADD_SINGLE_CLUSTER; + message.obj = cluster; + markerHandler.sendMessage(message); + } + } + + /** + * 根据一个点获取是否可以依附的聚合点,没有则返回null + */ + private Cluster getCluster(LatLng latLng, List clusters) { + for (Cluster cluster : clusters) { + LatLng clusterCenterPoint = cluster.getCenterLatLng(); + double distance = AMapUtils.calculateLineDistance(latLng, clusterCenterPoint); + if (distance < clusterDistance && amap.getCameraPosition().zoom < 19) { + return cluster; + } + } + return null; + } + + + /** + * 获取每个聚合点的绘制样式 + */ + private BitmapDescriptor getBitmapDes(int num) { + TextView textView = new TextView(context); + if (num > 1) { + String tile = String.valueOf(num); + textView.setText(tile); + } + textView.setGravity(Gravity.CENTER); + textView.setTextColor(Color.BLACK); + textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 15); + if (clusterRender != null && clusterRender.getDrawableByCount(num) != null) { + textView.setBackgroundDrawable(clusterRender.getDrawableByCount(num)); + } else { + textView.setBackgroundResource(R.mipmap.well_location); + } + return BitmapDescriptorFactory.fromView(textView); + } + + /** + * 更新已加入地图聚合点的样式 + */ + private void updateCluster(Cluster cluster) { + Marker marker = cluster.getMarker(); + marker.setIcon(getBitmapDes(cluster.getClusterCount())); + } + + /** + * 处理market添加,更新等操作 + */ + class MarkerHandler extends Handler { + + static final int ADD_CLUSTER_LIST = 0; + + static final int ADD_SINGLE_CLUSTER = 1; + + static final int UPDATE_SINGLE_CLUSTER = 2; + + public MarkerHandler(Looper looper) { + super(looper); + } + + public void handleMessage(Message message) { + switch (message.what) { + case ADD_CLUSTER_LIST: + List clusters = (List) message.obj; + addClusterToMap(clusters); + break; + case ADD_SINGLE_CLUSTER: + Cluster cluster = (Cluster) message.obj; + addSingleClusterToMap(cluster); + break; + case UPDATE_SINGLE_CLUSTER: + Cluster updateCluster = (Cluster) message.obj; + updateCluster(updateCluster); + break; + } + } + } + + /** + * 处理聚合点算法线程 + */ + class SignClusterHandler extends Handler { + static final int CALCULATE_CLUSTER = 0; + static final int CALCULATE_SINGLE_CLUSTER = 1; + + public SignClusterHandler(Looper looper) { + super(looper); + } + + public void handleMessage(Message message) { + switch (message.what) { + case CALCULATE_CLUSTER: + calculateClusters(); + break; + case CALCULATE_SINGLE_CLUSTER: + ClusterItem item = (ClusterItem) message.obj; + clusterItems.add(item); + calculateSingleCluster(item); + break; + } + } + } +} diff --git a/app/src/main/java/com/casic/app/smartwell/widgets/cluster/ClusterRender.java b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/ClusterRender.java new file mode 100644 index 0000000..427ff14 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/ClusterRender.java @@ -0,0 +1,10 @@ +package com.casic.app.smartwell.widgets.cluster; + +import android.graphics.drawable.Drawable; + +public interface ClusterRender { + /** + * 根据聚合点的元素数目返回渲染背景样式 + */ + Drawable getDrawableByCount(int clusterNum); +} diff --git a/app/src/main/java/com/casic/app/smartwell/widgets/cluster/RegionItem.java b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/RegionItem.java new file mode 100644 index 0000000..7b2b6c4 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/RegionItem.java @@ -0,0 +1,23 @@ +package com.casic.app.smartwell.widgets.cluster; + +import com.amap.api.maps.model.LatLng; +import com.casic.app.smartwell.model.MapWellListModel; + +public class RegionItem implements ClusterItem { + private final LatLng latLng; + private final MapWellListModel.DataModel well; + + public RegionItem(LatLng latLng, MapWellListModel.DataModel well) { + this.latLng = latLng; + this.well = well; + } + + @Override + public LatLng getPosition() { + return latLng; + } + + public MapWellListModel.DataModel getWell() { + return well; + } +} diff --git a/app/src/main/java/com/casic/app/smartwell/widgets/cluster/RemoveAnimationListener.java b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/RemoveAnimationListener.java new file mode 100644 index 0000000..c9c5e84 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/RemoveAnimationListener.java @@ -0,0 +1,30 @@ +package com.casic.app.smartwell.widgets.cluster; + +import com.amap.api.maps.model.Marker; +import com.amap.api.maps.model.animation.Animation; + +import java.util.List; + +/** + * marker渐变动画,动画结束后将Marker删除 + */ +public class RemoveAnimationListener implements Animation.AnimationListener { + private final List removeMarkers; + + public RemoveAnimationListener(List removeMarkers) { + this.removeMarkers = removeMarkers; + } + + @Override + public void onAnimationStart() { + + } + + @Override + public void onAnimationEnd() { + for (Marker marker : removeMarkers) { + marker.remove(); + } + removeMarkers.clear(); + } +} \ No newline at end of file diff --git a/app/src/main/res/anim/map_popup_hide.xml b/app/src/main/res/anim/map_popup_hide.xml new file mode 100644 index 0000000..119726b --- /dev/null +++ b/app/src/main/res/anim/map_popup_hide.xml @@ -0,0 +1,12 @@ + + + + \ No newline at end of file diff --git a/app/src/main/res/anim/map_popup_show.xml b/app/src/main/res/anim/map_popup_show.xml new file mode 100644 index 0000000..1d281ef --- /dev/null +++ b/app/src/main/res/anim/map_popup_show.xml @@ -0,0 +1,12 @@ + + + + \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/extensions/Int.kt b/app/src/main/java/com/casic/app/smartwell/extensions/Int.kt index de0617b..a0a5e33 100644 --- a/app/src/main/java/com/casic/app/smartwell/extensions/Int.kt +++ b/app/src/main/java/com/casic/app/smartwell/extensions/Int.kt @@ -1,9 +1,24 @@ package com.casic.app.smartwell.extensions +import android.graphics.Bitmap +import android.graphics.Canvas +import android.graphics.Paint +import android.graphics.RectF + fun Int.toLevel(): String { return if (this == 0) { "" } else { this.toString() } +} + +fun Int.drawCircle(color: Int): Bitmap? { + val bitmap = Bitmap.createBitmap(this * 2, this * 2, Bitmap.Config.ARGB_8888) + val canvas = Canvas(bitmap) + val paint = Paint() + val rectF = RectF(0f, 0f, (this * 2).toFloat(), (this * 2).toFloat()) + paint.color = color + canvas.drawArc(rectF, 0f, 360f, true, paint) + return bitmap } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt index 6b6ca3e..5e45534 100644 --- a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt +++ b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt @@ -2,17 +2,13 @@ import android.content.Context import com.casic.app.smartwell.callback.OnImageCompressListener -import com.casic.app.smartwell.model.ErrorMessageModel import com.casic.app.smartwell.utils.LocaleConstant -import com.google.gson.Gson -import com.google.gson.reflect.TypeToken +import com.google.gson.JsonParser import com.pengxh.kt.lite.extensions.createCompressImageDir import com.pengxh.kt.lite.utils.SaveKeyValues -import org.json.JSONObject import top.zibin.luban.Luban import top.zibin.luban.OnCompressListener import java.io.File -import java.util.Locale /** * String扩展方法 @@ -74,18 +70,22 @@ } } -fun String.separateResponseCode(): Int { +fun String.getResponseCode(): Int { if (this.isBlank()) { return 404 } - return JSONObject(this).getInt("code") + val element = JsonParser.parseString(this) + val jsonObject = element.asJsonObject + return jsonObject.get("code").asInt } -fun String.toErrorMessage(): String { - val errorModel = Gson().fromJson( - this, object : TypeToken() {}.type - ) - return errorModel.message.toString() +fun String.getResponseMessage(): String { + if (this.isBlank()) { + return "" + } + val element = JsonParser.parseString(this) + val jsonObject = element.asJsonObject + return jsonObject.get("message").asString } fun String.compressImage(context: Context, listener: OnImageCompressListener) { @@ -93,9 +93,6 @@ .load(this) .ignoreBy(100) .setTargetDir(context.createCompressImageDir().toString()) - .filter { - !(it.isBlank() || it.lowercase(Locale.getDefault()).endsWith(".gif")) - } .setCompressListener(object : OnCompressListener { override fun onStart() { 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 96df110..cd25fca 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 @@ -1,26 +1,25 @@ package com.casic.app.smartwell.fragment -import android.graphics.Point +import android.graphics.Color +import android.graphics.drawable.BitmapDrawable +import android.graphics.drawable.Drawable 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 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.LatLngBounds import com.amap.api.maps.model.Marker -import com.amap.api.maps.model.MarkerOptions import com.casic.app.smartwell.R import com.casic.app.smartwell.databinding.FragmentHomeBinding +import com.casic.app.smartwell.extensions.drawCircle import com.casic.app.smartwell.extensions.initImmersionBar -import com.casic.app.smartwell.extensions.valueToType import com.casic.app.smartwell.model.MapWellListModel import com.casic.app.smartwell.utils.LocaleConstant import com.casic.app.smartwell.utils.RouteOnMap @@ -31,9 +30,16 @@ import com.casic.app.smartwell.view.WellOperationActivity import com.casic.app.smartwell.vm.OrderViewModel import com.casic.app.smartwell.vm.WellViewModel +import com.casic.app.smartwell.widgets.MapWellPopup +import com.casic.app.smartwell.widgets.cluster.ClusterItem +import com.casic.app.smartwell.widgets.cluster.ClusterOnClickListener +import com.casic.app.smartwell.widgets.cluster.ClusterOverlay +import com.casic.app.smartwell.widgets.cluster.RegionItem 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.convertDrawable +import com.pengxh.kt.lite.extensions.dp2px import com.pengxh.kt.lite.extensions.navigatePageTo import com.pengxh.kt.lite.extensions.show import com.pengxh.kt.lite.utils.LoadingDialogHub @@ -43,35 +49,23 @@ /** * 地图点位带聚合效果 * */ -class HomePageHaveClusterFragment : KotlinBaseFragment(), AMap.OnMapLoadedListener, - AMap.OnCameraChangeListener, AMap.OnMarkerClickListener, AMap.InfoWindowAdapter, - AMap.OnInfoWindowClickListener { +class HomePageHaveClusterFragment : KotlinBaseFragment(), + AMap.OnCameraChangeListener { private val kTag = "HaveClusterFragment" private val easyPopupWindow by lazy { EasyPopupWindow(requireContext()) } - private lateinit var wellViewModel: WellViewModel - private lateinit var orderViewModel: OrderViewModel - private lateinit var aMap: AMap - - /** - * 所有的marker - */ - private var allMarkerOptions: MutableList = ArrayList() - - /** - * 视野内的marker - */ - private var markerOptionsInView: MutableList = ArrayList() - - /** - * 自定义Marker弹出框 - * */ - private lateinit var v: View + private val regionRadius by lazy { LocaleConstant.RADIUS_SIZE.dp2px(requireContext()) } + private val infoPopup by lazy { MapWellPopup(requireContext()) } /** * 所有窨井列表信息集合 * */ - private var wellModels: MutableList = ArrayList() + private val wellModels = ArrayList() + private val backDrawables = HashMap() + private lateinit var wellViewModel: WellViewModel + private lateinit var orderViewModel: OrderViewModel + private lateinit var aMap: AMap + private var clusterOverlay: ClusterOverlay? = null override fun initViewBinding( inflater: LayoutInflater, @@ -106,6 +100,9 @@ } }) + //地图初始化 + initMap(savedInstanceState) + //初始化vm wellViewModel = ViewModelProvider(this)[WellViewModel::class.java] orderViewModel = ViewModelProvider(this)[OrderViewModel::class.java] @@ -120,25 +117,19 @@ val latitudeList: MutableList = ArrayList() val longitudeList: MutableList = ArrayList() it.data?.forEach { well -> - val lat = well.latGaode.toString() - val lng = well.lngGaode.toString() + val lat = well.latGaode + val lng = well.lngGaode if (lat.isNotBlank() && lng.isNotBlank()) { //返回true代表当前位置在大陆、港澳地区,反之不在 val latitude = lat.toDouble() val longitude = lng.toDouble() if (CoordinateConverter.isAMapDataAvailable(latitude, longitude)) { - //缓存所有设备详情,点击Marker时候需要 + //缓存所有井 wellModels.add(well) + //分别缓存经、纬度 latitudeList.add(latitude) longitudeList.add(longitude) - //将所有设备信息转化缓存为Marker点 - allMarkerOptions.add( - MarkerOptions() - .position(LatLng(latitude, longitude)) - .title(well.wellTypeName) - .snippet(well.wellName) - ) } } } @@ -160,12 +151,12 @@ val cameraPosition = CameraPosition(centerLatLng, 16f, 0f, 0f) val cameraUpdate = CameraUpdateFactory.newCameraPosition(cameraPosition) aMap.animateCamera(cameraUpdate, 1500, null) + + //显示点数据 + displayWellOnMap() } } - //地图初始化 - initMap(savedInstanceState) - //获取窨井监控数据 wellViewModel.countResultModel.observe(this) { binding.deployedWellView.text = it["bfWell"] @@ -220,17 +211,10 @@ uiSettings.isCompassEnabled = true uiSettings.zoomPosition = AMapOptions.ZOOM_POSITION_RIGHT_CENTER uiSettings.isTiltGesturesEnabled = false//不许地图随手势倾斜角度 + uiSettings.isRotateGesturesEnabled = false//不允许地图随手势改变方位 - // 地图加载成功监听 - aMap.addOnMapLoadedListener(this) // 地图缩放监听 aMap.addOnCameraChangeListener(this) - // marker 点击事件监听 - aMap.addOnMarkerClickListener(this) - // 点击marker弹出自定义popup - aMap.setInfoWindowAdapter(this) - //信息窗点击事件 - aMap.addOnInfoWindowClickListener(this) } override fun initEvent() { @@ -259,9 +243,111 @@ } - override fun onMapLoaded() { - //地图加载成功之后显示聚合点数据 - initClustersMarkers() + private fun displayWellOnMap() { + clusterOverlay?.onDestroy() + val clusterItems = ArrayList() + + wellModels.forEach { + val latitude = it.latGaode.toDouble() + val longitude = it.lngGaode.toDouble() + + val latLng = LatLng(latitude, longitude, false) + val regionItem = RegionItem(latLng, it) + clusterItems.add(regionItem) + } + + clusterOverlay = ClusterOverlay(requireContext(), aMap, clusterItems, regionRadius) + clusterOverlay?.setClusterRender { clusterNum -> + //聚合圆半径 + val radius = 100.dp2px(requireContext()) + if (clusterNum == 0) { + var bitmapDrawable = backDrawables[0] + if (bitmapDrawable == null) { + bitmapDrawable = BitmapDrawable( + null, radius.drawCircle(Color.argb(159, 100, 149, 237)) + ) + backDrawables[0] = bitmapDrawable + } + bitmapDrawable + } + if (clusterNum == 1) { + var bitmapDrawable = backDrawables[1] + if (bitmapDrawable == null) { + bitmapDrawable = R.mipmap.well_location.convertDrawable(requireContext())!! + backDrawables[1] = bitmapDrawable + } + bitmapDrawable + } else if (clusterNum < 5) { + var bitmapDrawable = backDrawables[2] + if (bitmapDrawable == null) { + bitmapDrawable = BitmapDrawable( + null, radius.drawCircle(Color.argb(159, 100, 149, 237)) + ) + backDrawables[2] = bitmapDrawable + } + bitmapDrawable + } else if (clusterNum < 10) { + var bitmapDrawable = backDrawables[3] + if (bitmapDrawable == null) { + bitmapDrawable = BitmapDrawable( + null, radius.drawCircle(Color.argb(199, 30, 144, 255)) + ) + backDrawables[3] = bitmapDrawable + } + bitmapDrawable + } else { + var bitmapDrawable = backDrawables[4] + if (bitmapDrawable == null) { + bitmapDrawable = BitmapDrawable( + null, radius.drawCircle(Color.argb(235, 65, 105, 225)) + ) + backDrawables[4] = bitmapDrawable + } + bitmapDrawable + } + } + + clusterOverlay?.setOnClusterClickListener(object : ClusterOnClickListener { + override fun onMarkerClicked(marker: Marker?, items: List) { + if (items.size > 1) { + "请缩放地图比例在查看数据".show(requireContext()) + return + } + + var item: RegionItem? = null + val builder = LatLngBounds.Builder() + for (clusterItem in items) { + builder.include(clusterItem.position) + item = clusterItem as RegionItem + } + + item?.apply { + showWellPopup(well) + } + } + }) + } + + private fun showWellPopup(well: MapWellListModel.DataModel) { + infoPopup.set(well, object : MapWellPopup.OnPopupWindowClickListener { + override fun onPopupClicked(lat: Double, lng: Double) { + AlertControlDialog.Builder().setContext(requireContext()).setTitle("操作提示") + .setMessage("确定要前往吗").setNegativeButton("取消").setPositiveButton("确定") + .setOnDialogButtonClickListener(object : + AlertControlDialog.OnDialogButtonClickListener { + override fun onConfirmClick() { + RouteOnMap.startNavigation( + requireContext(), "", LatLng(lat, lng) + ) + } + + override fun onCancelClick() { + + } + }).build().show() + } + }) + infoPopup.showAsDropDown(binding.rightOptionView) } override fun onCameraChange(p0: CameraPosition?) { @@ -282,103 +368,10 @@ } } - //获取视野内的marker 根据聚合算法合成自定义的marker 显示视野内的marker override fun onCameraChangeFinish(p0: CameraPosition?) { //地图缩放之后显示聚合点数据 LoadingDialogHub.dismiss() httpCountDownTimer.cancel() - initClustersMarkers() - } - - private fun initClustersMarkers() { - 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 { - v = LayoutInflater.from(requireContext()).inflate(R.layout.popup_map_info, null) - - //显示闸井信息 - marker?.showInfoWindow() - return true - } - - override fun getInfoWindow(marker: Marker?): View { - //反射得到popup里面的控件对象 - val wellNameView = v.findViewById(R.id.wellNameView) - val wellCodeView = v.findViewById(R.id.wellCodeView) - val wellTypeView = v.findViewById(R.id.wellTypeView) - val wellStateView = v.findViewById(R.id.wellStateView) - val deepView = v.findViewById(R.id.deepView) - val locationView = v.findViewById(R.id.locationView) - - //绑定数据 - val clickedLatLng = marker?.position!! - wellModels.forEach { well -> - if (clickedLatLng.latitude == well.latGaode!!.toDouble() - && clickedLatLng.longitude == well.lngGaode!!.toDouble() - ) { - wellNameView.text = String.format("点位名称: ${well.wellName}") - wellCodeView.text = String.format("点位编号: ${well.wellCode}") - wellTypeView.text = String.format("点位类型: ${well.wellType.valueToType()}") - val bfztName = if (well.bfzt == "1") { - "已布防" - } else { - "已撤防" - } - wellStateView.text = String.format("布/撤防状态: $bfztName") - deepView.text = String.format("点位深度: ${well.deep}m") - locationView.text = String.format("详细位置: ${well.position}") - } - } - return v - } - - /** - * 此方法不能修改整个 InfoWindow 的背景和边框,无论自定义的样式是什么样,SDK 都会在最外层添加一个默认的边框 - * */ - override fun getInfoContents(p0: Marker?): View? = null - - override fun onInfoWindowClick(p0: Marker?) { - p0?.apply { - AlertControlDialog.Builder() - .setContext(requireContext()) - .setTitle("操作提示") - .setMessage("确定要前往吗") - .setNegativeButton("取消") - .setPositiveButton("确定") - .setOnDialogButtonClickListener(object : - AlertControlDialog.OnDialogButtonClickListener { - override fun onConfirmClick() { - val lat = position.latitude.toString() - val lng = position.longitude.toString() - if (lat.isBlank() || lng.isBlank()) { - "点位经纬度异常,无法开启导航".show(requireContext()) - return - } - RouteOnMap.startNavigation( - requireContext(), snippet, LatLng(lat.toDouble(), lng.toDouble()) - ) - } - - override fun onCancelClick() { - - } - }).build().show() - } } /***以下是地图生命周期管理************************************************************************/ 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 a54d213..bfa7a57 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 @@ -44,8 +44,8 @@ * 地图点位不带聚合效果 * */ class HomePageNoClusterFragment : KotlinBaseFragment(), - AMap.OnMapLoadedListener, AMap.OnCameraChangeListener, AMap.OnMarkerClickListener, - AMap.InfoWindowAdapter, AMap.OnInfoWindowClickListener { + AMap.OnCameraChangeListener, AMap.OnMarkerClickListener, AMap.InfoWindowAdapter, + AMap.OnInfoWindowClickListener { private val kTag = "NoClusterFragment" private val easyPopupWindow by lazy { EasyPopupWindow(requireContext()) } @@ -109,6 +109,9 @@ wellViewModel = ViewModelProvider(this)[WellViewModel::class.java] orderViewModel = ViewModelProvider(this)[OrderViewModel::class.java] + //地图初始化 + initMap(savedInstanceState) + //获取所有窨井数据 httpCountDownTimer.start() LoadingDialogHub.show(requireActivity(), "数据加载中,请稍后...") @@ -157,12 +160,12 @@ val cameraPosition = CameraPosition(centerLatLng, 16f, 0f, 0f) val cameraUpdate = CameraUpdateFactory.newCameraPosition(cameraPosition) aMap.animateCamera(cameraUpdate, 1500, null) + + //显示点数据 + displayWellOnMap() } } - //地图初始化 - initMap(savedInstanceState) - //获取窨井监控数据 wellViewModel.countResultModel.observe(this) { binding.deployedWellView.text = it["bfWell"] @@ -214,9 +217,8 @@ uiSettings.isCompassEnabled = true uiSettings.zoomPosition = AMapOptions.ZOOM_POSITION_RIGHT_CENTER uiSettings.isTiltGesturesEnabled = false//不许地图随手势倾斜角度 + uiSettings.isRotateGesturesEnabled = false//不允许地图随手势改变方位 - // 地图加载成功监听 - aMap.addOnMapLoadedListener(this) // 地图缩放监听 aMap.addOnCameraChangeListener(this) // marker 点击事件监听 @@ -253,11 +255,6 @@ } - override fun onMapLoaded() { - //地图加载成功之后显示聚合点数据 - initClustersMarkers() - } - override fun onCameraChange(p0: CameraPosition?) { } @@ -281,10 +278,9 @@ //地图缩放之后显示聚合点数据 LoadingDialogHub.dismiss() httpCountDownTimer.cancel() - initClustersMarkers() } - private fun initClustersMarkers() { + private fun displayWellOnMap() { val proj = aMap.projection val dm = resources.displayMetrics var screenLocation: Point diff --git a/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.java b/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.java deleted file mode 100644 index d8b18ef..0000000 --- a/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.java +++ /dev/null @@ -1,50 +0,0 @@ -package com.casic.app.smartwell.model; - -public class ErrorMessageModel { - - private int code; - private String data; - private String exceptionClazz; - private String message; - private boolean success; - - public int getCode() { - return code; - } - - public void setCode(int code) { - this.code = code; - } - - public String getData() { - return data; - } - - public void setData(String data) { - this.data = data; - } - - public String getExceptionClazz() { - return exceptionClazz; - } - - public void setExceptionClazz(String exceptionClazz) { - this.exceptionClazz = exceptionClazz; - } - - public String getMessage() { - return message; - } - - public void setMessage(String message) { - this.message = message; - } - - public boolean isSuccess() { - return success; - } - - public void setSuccess(boolean success) { - this.success = success; - } -} \ No newline at end of file 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 new file mode 100644 index 0000000..215ac0c --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/PipelineModel.java @@ -0,0 +1,328 @@ +package com.casic.app.smartwell.model; + +import java.util.List; + +public class PipelineModel { + + private Integer code; + private DataModel data; + private String message; + private Boolean success; + + public Integer getCode() { + return code; + } + + public void setCode(Integer code) { + this.code = code; + } + + public DataModel getData() { + return data; + } + + public void setData(DataModel data) { + this.data = data; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + public Boolean getSuccess() { + return success; + } + + public void setSuccess(Boolean success) { + this.success = success; + } + + public static class DataModel { + private List rows; + private Integer total; + + public List getRows() { + return rows; + } + + public void setRows(List rows) { + this.rows = rows; + } + + public Integer getTotal() { + return total; + } + + public void setTotal(Integer total) { + this.total = total; + } + + 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 getBuryMode() { + return buryMode; + } + + public void setBuryMode(String buryMode) { + this.buryMode = buryMode; + } + + public String getConstructEra() { + return constructEra; + } + + public void setConstructEra(String constructEra) { + this.constructEra = constructEra; + } + + 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; + } + } + } +} 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 06d3d2b..4f38a2c 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 = 100 //相距多少米才聚合,单位:米 + const val RADIUS_SIZE = 80 //相距多少米才聚合,单位:米 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:11308" + // 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 0d5f3fa..991e1db 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 @@ -312,4 +312,14 @@ @Header("token") token: String, @Field("clientid") deviceCode: String ): String + + /** + * 管线位置数据 + */ + @GET("/pipeline/listPage") + suspend fun getPipeline( + @Header("token") token: String, + @Query("limit") limit: Int, + @Query("offset") offset: Int + ): String } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt index 1a0ce22..4050067 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt @@ -294,4 +294,11 @@ suspend fun registerPush(clientId: String): String { return api.registerPush(AuthenticationHelper.token!!, clientId) } + + /** + * 管线位置数据 + */ + suspend fun getPipeline(): String { + return api.getPipeline(AuthenticationHelper.token!!, 2000, 1) + } } \ No newline at end of file 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 9270fa1..4ca5a5e 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.HomePageNoClusterFragment +import com.casic.app.smartwell.fragment.HomePageHaveClusterFragment 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/vm/AlarmViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/AlarmViewModel.kt index 9cff08c..e7acc17 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/AlarmViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/AlarmViewModel.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.AlarmContentModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager import com.google.gson.Gson @@ -16,7 +16,7 @@ fun getAlarmContentType(alarmType: String) = launch({ val response = RetrofitServiceManager.getAlarmContentType(alarmType) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { listModel.value = gson.fromJson( response, object : TypeToken() {}.type diff --git a/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt index 5e5b163..895dedd 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.PublicKeyModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager import com.google.gson.Gson @@ -18,7 +18,7 @@ fun getPublicKey() = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.authenticate() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { keyModel.value = gson.fromJson( response, object : TypeToken() {}.type diff --git a/app/src/main/java/com/casic/app/smartwell/vm/DeviceViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/DeviceViewModel.kt index db5ccf6..899a962 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/DeviceViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/DeviceViewModel.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.DeviceDetailModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager import com.google.gson.Gson @@ -16,7 +16,7 @@ fun getDeviceDetail(deviceCode: String) = launch({ val response = RetrofitServiceManager.getDeviceDetail(deviceCode) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { detailModel.value = gson.fromJson( response, object : TypeToken() {}.type diff --git a/app/src/main/java/com/casic/app/smartwell/vm/LoginViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/LoginViewModel.kt index cd8b8a9..a417398 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/LoginViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/LoginViewModel.kt @@ -2,7 +2,7 @@ import androidx.lifecycle.MutableLiveData import com.casic.app.smartwell.base.BaseApplication -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.CommonResultModel import com.casic.app.smartwell.model.LoginResultModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -21,7 +21,7 @@ fun enter(account: String, secretKey: String) = launch({ val response = RetrofitServiceManager.login(account, secretKey) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success enterResultModel.value = gson.fromJson( @@ -38,7 +38,7 @@ fun out() = launch({ val response = RetrofitServiceManager.loginOut() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { outResultModel.value = gson.fromJson( response, object : TypeToken() {}.type diff --git a/app/src/main/java/com/casic/app/smartwell/vm/OperationViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/OperationViewModel.kt index 8943ed3..37e115f 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/OperationViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/OperationViewModel.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.vm import com.casic.app.smartwell.base.BaseApplication -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager import com.pengxh.kt.lite.base.BaseViewModel import com.pengxh.kt.lite.extensions.launch @@ -16,7 +16,7 @@ fun acceptWorkOrder(id: String) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.acceptWorkOrder(id) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success "接单成功".show(BaseApplication.get()) @@ -35,7 +35,7 @@ loadState.value = LoadState.Loading val response = RetrofitServiceManager.confirmWorkOrder(id, firstState, firstStatePhotos, needHandle) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success "工单确认成功".show(BaseApplication.get()) @@ -50,7 +50,7 @@ fun transferWorkOrder(id: String, userId: String) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.transferWorkOrder(id, userId) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success "转单成功".show(BaseApplication.get()) @@ -65,7 +65,7 @@ fun completeWorkOrder(id: String, handleMessage: String, handlePhotos: String) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.completeWorkOrder(id, handleMessage, handlePhotos) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success "工单处理成功".show(BaseApplication.get()) diff --git a/app/src/main/java/com/casic/app/smartwell/vm/OrderViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/OrderViewModel.kt index 4cb26b7..d2fad86 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/OrderViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/OrderViewModel.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.OrderDetailModel import com.casic.app.smartwell.model.OrderListModel import com.casic.app.smartwell.model.OrderStatusModel @@ -37,7 +37,7 @@ val response = RetrofitServiceManager.getSearchResult( keywords, alarmContent, alarmLevel, jobStatus, deptId, beginTime, endTime, offset ) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success searchResult.value = gson.fromJson( @@ -53,7 +53,7 @@ fun getWorkOrderListByState(jobStatus: String, page: Int) = launch({ val response = RetrofitServiceManager.getWorkOrderList(jobStatus, page) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { orderList.value = gson.fromJson( response, object : TypeToken() {}.type @@ -65,7 +65,7 @@ fun getNotAcceptOderList(page: Int) = launch({ val response = RetrofitServiceManager.getNotAcceptOderList(page) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { orderList.value = gson.fromJson( response, object : TypeToken() {}.type @@ -77,7 +77,7 @@ fun getNotHandleOderList(page: Int) = launch({ val response = RetrofitServiceManager.getNotHandleOderList(page) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { orderList.value = gson.fromJson( response, object : TypeToken() {}.type @@ -89,7 +89,7 @@ fun countWorkOrderByState() = launch({ val response = RetrofitServiceManager.countWorkOrderByState() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { val map = HashMap(4) @@ -107,7 +107,7 @@ fun getOrderStatus() = launch({ val response = RetrofitServiceManager.getOrderStatus() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { orderStatusModel.value = gson.fromJson( response, object : TypeToken() {}.type @@ -120,7 +120,7 @@ fun getWorkOrderDetail(id: String) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.getWorkOrderDetail(id) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success detailModel.value = gson.fromJson( diff --git a/app/src/main/java/com/casic/app/smartwell/vm/PipelineViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/PipelineViewModel.kt new file mode 100644 index 0000000..60c1e2f --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/vm/PipelineViewModel.kt @@ -0,0 +1,28 @@ +package com.casic.app.smartwell.vm + +import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.extensions.getResponseCode +import com.casic.app.smartwell.model.PipelineModel +import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken +import com.pengxh.kt.lite.base.BaseViewModel +import com.pengxh.kt.lite.extensions.launch + +class PipelineViewModel : BaseViewModel() { + + private val gson by lazy { Gson() } + val lineResult = MutableLiveData() + + fun getPipeline() = launch({ + val response = RetrofitServiceManager.getPipeline() + val responseCode = response.getResponseCode() + if (responseCode == 200) { + lineResult.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } + }, { + it.printStackTrace() + }) +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/PushViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/PushViewModel.kt index 9279815..12fd610 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/PushViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/PushViewModel.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.CommonResultModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager import com.google.gson.Gson @@ -16,7 +16,7 @@ fun registerPush(clientId: String) = launch({ val response = RetrofitServiceManager.registerPush(clientId) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { registerResultModel.value = gson.fromJson( response, object : TypeToken() {}.type diff --git a/app/src/main/java/com/casic/app/smartwell/vm/UploadImageViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/UploadImageViewModel.kt index 8d6744e..9707eeb 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/UploadImageViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/UploadImageViewModel.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.CommonResultModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager import com.google.gson.Gson @@ -19,7 +19,7 @@ fun uploadImage(image: File) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.uploadImage(image) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success resultModel.value = gson.fromJson( diff --git a/app/src/main/java/com/casic/app/smartwell/vm/UserViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/UserViewModel.kt index 31a4d4c..070c35a 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/UserViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/UserViewModel.kt @@ -2,7 +2,7 @@ import androidx.lifecycle.MutableLiveData import com.casic.app.smartwell.base.BaseApplication -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.SubordinateModel import com.casic.app.smartwell.model.UserDetailModel import com.casic.app.smartwell.model.VersionResultModel @@ -25,7 +25,7 @@ fun getUserDetail() = launch({ val response = RetrofitServiceManager.getUserDetail() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { val userDetail = gson.fromJson( response, object : TypeToken() {}.type @@ -48,7 +48,7 @@ * */ fun getSubordinate(hasMine: String?, deptId: String?, roleTips: String?) = launch({ val response = RetrofitServiceManager.getSubordinate(hasMine, deptId, roleTips) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { subordinateModel.value = gson.fromJson( response, object : TypeToken() {}.type @@ -61,7 +61,7 @@ fun changePassword(oldPwd: String, newPwd: String) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.changePassword(oldPwd, newPwd) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success "修改成功,请重新登录".show(BaseApplication.get()) @@ -76,7 +76,7 @@ fun updateVersion() = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.updateVersion() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success versionResultModel.value = gson.fromJson( diff --git a/app/src/main/java/com/casic/app/smartwell/vm/WellViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/WellViewModel.kt index 3d41e9b..9e42e36 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/WellViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/WellViewModel.kt @@ -2,8 +2,7 @@ import androidx.lifecycle.MutableLiveData import com.casic.app.smartwell.base.BaseApplication -import com.casic.app.smartwell.extensions.separateResponseCode -import com.casic.app.smartwell.extensions.toErrorMessage +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.AuthorDeptModel import com.casic.app.smartwell.model.CommonResultModel import com.casic.app.smartwell.model.MapWellListModel @@ -32,7 +31,7 @@ fun countWellByState() = launch({ val response = RetrofitServiceManager.countWellByState() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { val map = HashMap(3) @@ -57,7 +56,7 @@ fun getWellType() = launch({ val response = RetrofitServiceManager.getWellType() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { wellTypeModel.value = gson.fromJson( response, object : TypeToken() {}.type @@ -70,7 +69,7 @@ fun getWellDetail(id: String) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.getWellDetail(id) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success wellDetailModel.value = gson.fromJson( @@ -87,7 +86,7 @@ fun getOperationResult(id: String, state: String) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.getOperationResult(id, state) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success "操作成功".show(BaseApplication.get()) @@ -105,7 +104,7 @@ fun getMonitorResult(id: String) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.getMonitorResult(id) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success monitorModel.value = gson.fromJson( @@ -125,7 +124,7 @@ val response = RetrofitServiceManager.getWellListByPage( keywords, wellType, deptid, bfzt, page ) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { listModel.value = gson.fromJson( response, object : TypeToken() {}.type @@ -137,13 +136,11 @@ fun getWellList() = launch({ val response = RetrofitServiceManager.getWellList() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { totalWellModel.value = gson.fromJson( response, object : TypeToken() {}.type ) - } else { - response.toErrorMessage().show(BaseApplication.get()) } }, { it.printStackTrace() diff --git a/app/src/main/java/com/casic/app/smartwell/widgets/GaoDeClusterMarkerView.kt b/app/src/main/java/com/casic/app/smartwell/widgets/GaoDeClusterMarkerView.kt deleted file mode 100644 index 1f375df..0000000 --- a/app/src/main/java/com/casic/app/smartwell/widgets/GaoDeClusterMarkerView.kt +++ /dev/null @@ -1,100 +0,0 @@ -package com.casic.app.smartwell.widgets - -import android.content.Context -import android.graphics.Bitmap -import android.graphics.Point -import android.view.Gravity -import android.view.LayoutInflater -import android.view.View -import android.widget.TextView -import com.amap.api.maps.Projection -import com.amap.api.maps.model.BitmapDescriptorFactory -import com.amap.api.maps.model.LatLng -import com.amap.api.maps.model.LatLngBounds -import com.amap.api.maps.model.MarkerOptions -import com.casic.app.smartwell.R -import com.pengxh.kt.lite.extensions.toBitmap -import java.util.* - -class GaoDeClusterMarkerView( - private val context: Context, firstMarkers: MarkerOptions, projection: Projection, gridSize: Int -) { - //当前可观区域里的 聚合过之后的集合 - private val includeMarkers: ArrayList - - // 创建区域 - val bounds: LatLngBounds - var options: MarkerOptions = MarkerOptions() - - init { - val screenLocation = projection.toScreenLocation(firstMarkers.position) - //范围类 - val southwestPoint = Point(screenLocation.x - gridSize, screenLocation.y + gridSize) - //范围类 - val northeastPoint = Point(screenLocation.x + gridSize, screenLocation.y - gridSize) - bounds = LatLngBounds( - projection.fromScreenLocation(southwestPoint), - projection.fromScreenLocation(northeastPoint) - ) - //设置初始化marker属性 - options.anchor(0.5f, 1.3f) - .title(firstMarkers.title) - .position(firstMarkers.position) - .icon(firstMarkers.icon) - .snippet(firstMarkers.snippet) - .draggable(false) - includeMarkers = ArrayList() - includeMarkers.add(firstMarkers) - } - - /** - * 添加marker - */ - fun addMarker(markerOptions: MarkerOptions) { - includeMarkers.add(markerOptions) // 添加到列表中 - } - - /** - * 设置聚合点的中心位置以及图标 - */ - fun setPositionAndIcon() { - val size = includeMarkers.size - var lat = 0.0 - var lng = 0.0 - // 一个的时候 - if (size == 1) { //设置marker单个属性 - // 设置marker位置 - options.position( - LatLng( - includeMarkers[0].position.latitude, includeMarkers[0].position.longitude - ) - ) - } else { // 聚合的时候 - //设置marker聚合属性 - for (op in includeMarkers) { - lat += op.position.latitude - lng += op.position.longitude - } - // 设置marker的位置为中心位置为聚集点的平均位置 - options.position(LatLng(lat / size, lng / size)) - } - options.icon(BitmapDescriptorFactory.fromBitmap(getBitmap(size))) - } - - /** - * marker视图 - */ - private fun getBitmap(num: Int): Bitmap? { - val view = LayoutInflater.from(context).inflate(R.layout.marker_gaode, null) - val wellCountView = view.findViewById(R.id.wellCountView) - return if (num > 1) { - wellCountView.visibility = View.VISIBLE - wellCountView.text = String.format("${num}个") - wellCountView.gravity = Gravity.CENTER - view.toBitmap() - } else { - wellCountView.visibility = View.GONE - BitmapDescriptorFactory.fromResource(R.mipmap.well_location).bitmap - } - } -} \ No newline at end of file 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 new file mode 100644 index 0000000..ec455dd --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/widgets/MapWellPopup.kt @@ -0,0 +1,58 @@ +package com.casic.app.smartwell.widgets + +import android.content.Context +import android.view.LayoutInflater +import android.view.ViewGroup +import android.widget.LinearLayout +import android.widget.PopupWindow +import android.widget.TextView +import com.casic.app.smartwell.R +import com.casic.app.smartwell.extensions.valueToType +import com.casic.app.smartwell.model.MapWellListModel + +class MapWellPopup constructor(context: Context) : PopupWindow() { + + init { + width = ViewGroup.LayoutParams.MATCH_PARENT + height = ViewGroup.LayoutParams.WRAP_CONTENT + isOutsideTouchable = true + isFocusable = true + animationStyle = R.style.MapPopupAnimation + setBackgroundDrawable(null) + contentView = LayoutInflater.from(context).inflate( + R.layout.popup_map_info, null, false + ) + } + + fun set(well: MapWellListModel.DataModel, windowClickListener: OnPopupWindowClickListener) { + //反射得到popup里面的控件对象 + val rootView = contentView.findViewById(R.id.rootView) + val wellNameView = contentView.findViewById(R.id.wellNameView) + val wellCodeView = contentView.findViewById(R.id.wellCodeView) + val wellTypeView = contentView.findViewById(R.id.wellTypeView) + val wellStateView = contentView.findViewById(R.id.wellStateView) + val deepView = contentView.findViewById(R.id.deepView) + val locationView = contentView.findViewById(R.id.locationView) + + //绑定数据 + wellNameView.text = String.format("点位名称: ${well.wellName}") + wellCodeView.text = String.format("点位编号: ${well.wellCode}") + wellTypeView.text = String.format("点位类型: ${well.wellType.valueToType()}") + val bfztName = if (well.bfzt == "1") { + "已布防" + } else { + "已撤防" + } + wellStateView.text = String.format("布/撤防状态: $bfztName") + deepView.text = String.format("点位深度: ${well.deep}m") + locationView.text = String.format("详细位置: ${well.position}") + + rootView.setOnClickListener { + windowClickListener.onPopupClicked(well.latGaode.toDouble(), well.lngGaode.toDouble()) + } + } + + interface OnPopupWindowClickListener { + fun onPopupClicked(lat: Double, lng: Double) + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/widgets/cluster/Cluster.java b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/Cluster.java new file mode 100644 index 0000000..9455ccd --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/Cluster.java @@ -0,0 +1,43 @@ +package com.casic.app.smartwell.widgets.cluster; + +import com.amap.api.maps.model.LatLng; +import com.amap.api.maps.model.Marker; + +import java.util.ArrayList; +import java.util.List; + +public class Cluster { + private final LatLng latLng; + private final List clusterItems; + private Marker marker; + + + public Cluster(LatLng latLng) { + this.latLng = latLng; + clusterItems = new ArrayList<>(); + } + + public void addClusterItem(ClusterItem clusterItem) { + clusterItems.add(clusterItem); + } + + public int getClusterCount() { + return clusterItems.size(); + } + + public LatLng getCenterLatLng() { + return latLng; + } + + public void setMarker(Marker marker) { + this.marker = marker; + } + + public Marker getMarker() { + return marker; + } + + public List getClusterItems() { + return clusterItems; + } +} diff --git a/app/src/main/java/com/casic/app/smartwell/widgets/cluster/ClusterItem.java b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/ClusterItem.java new file mode 100644 index 0000000..f5d9a9d --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/ClusterItem.java @@ -0,0 +1,10 @@ +package com.casic.app.smartwell.widgets.cluster; + +import com.amap.api.maps.model.LatLng; + +public interface ClusterItem { + /** + * 返回聚合元素的地理位置 + */ + LatLng getPosition(); +} diff --git a/app/src/main/java/com/casic/app/smartwell/widgets/cluster/ClusterOnClickListener.java b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/ClusterOnClickListener.java new file mode 100644 index 0000000..0efa1f1 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/ClusterOnClickListener.java @@ -0,0 +1,15 @@ +package com.casic.app.smartwell.widgets.cluster; + +import com.amap.api.maps.model.Marker; + +import java.util.List; + +public interface ClusterOnClickListener { + /** + * 点击聚合点的回调处理函数 + * + * @param marker 点击的聚合点 + * @param items 聚合点所包含的元素 + */ + void onMarkerClicked(Marker marker, List items); +} 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 new file mode 100644 index 0000000..40df562 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/ClusterOverlay.java @@ -0,0 +1,349 @@ +package com.casic.app.smartwell.widgets.cluster; + +import android.content.Context; +import android.graphics.Color; +import android.os.Handler; +import android.os.HandlerThread; +import android.os.Looper; +import android.os.Message; +import android.util.TypedValue; +import android.view.Gravity; +import android.widget.TextView; + +import com.amap.api.maps.AMap; +import com.amap.api.maps.AMapUtils; +import com.amap.api.maps.model.BitmapDescriptor; +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.LatLngBounds; +import com.amap.api.maps.model.Marker; +import com.amap.api.maps.model.MarkerOptions; +import com.amap.api.maps.model.animation.AlphaAnimation; +import com.casic.app.smartwell.R; + +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.CopyOnWriteArrayList; + +/** + * 整体设计采用了两个线程,一个线程用于计算组织聚合数据,一个线程负责处理Marker相关操作 + */ +public class ClusterOverlay implements AMap.OnCameraChangeListener, AMap.OnMarkerClickListener { + private final AMap amap; + private final Context context; + private final List clusterItems; + private final List clusters; + private final int clusterSize; + private ClusterOnClickListener clusterClickListener; + private ClusterRender clusterRender; + private final CopyOnWriteArrayList addMarkers = new CopyOnWriteArrayList<>(); + private double clusterDistance; + private final HandlerThread markerHandlerThread = new HandlerThread("addMarker"); + private final HandlerThread signClusterThread = new HandlerThread("calculateCluster"); + private Handler markerHandler; + private Handler signClusterHandler; + private float pxInMeters; + private boolean isCanceled = false; + private final AlphaAnimation addAnimation = new AlphaAnimation(0, 1); + + /** + * 构造函数,批量添加聚合元素时,调用此构造函数 + */ + public ClusterOverlay(Context context, AMap amap, int clusterSize) { + this(context, amap, null, clusterSize); + } + + /** + * 构造函数,批量添加聚合元素时,调用此构造函数 + */ + public ClusterOverlay(Context context, AMap amap, List clusterItems, int clusterSize) { + if (clusterItems != null) { + this.clusterItems = clusterItems; + } else { + this.clusterItems = new ArrayList<>(); + } + this.context = context; + this.clusters = new ArrayList<>(); + this.amap = amap; + this.clusterSize = clusterSize; + this.pxInMeters = amap.getScalePerPixel(); + this.clusterDistance = pxInMeters * clusterSize; + amap.setOnCameraChangeListener(this); + amap.setOnMarkerClickListener(this); + initThreadHandler(); + assignClusters(); + } + + /** + * 设置聚合点的点击事件 + */ + public void setOnClusterClickListener(ClusterOnClickListener clusterClickListener) { + this.clusterClickListener = clusterClickListener; + } + + /** + * 添加一个聚合点 + */ + public void addClusterItem(ClusterItem item) { + Message message = Message.obtain(); + message.what = SignClusterHandler.CALCULATE_SINGLE_CLUSTER; + message.obj = item; + signClusterHandler.sendMessage(message); + } + + /** + * 设置聚合元素的渲染样式,不设置则默认为气泡加数字形式进行渲染 + */ + public void setClusterRender(ClusterRender render) { + this.clusterRender = render; + } + + public void onDestroy() { + isCanceled = true; + signClusterHandler.removeCallbacksAndMessages(null); + markerHandler.removeCallbacksAndMessages(null); + signClusterThread.quit(); + markerHandlerThread.quit(); + for (Marker marker : addMarkers) { + marker.remove(); + } + addMarkers.clear(); + } + + //初始化Handler + private void initThreadHandler() { + markerHandlerThread.start(); + signClusterThread.start(); + markerHandler = new MarkerHandler(markerHandlerThread.getLooper()); + signClusterHandler = new SignClusterHandler(signClusterThread.getLooper()); + } + + @Override + public void onCameraChange(CameraPosition arg0) { + + } + + @Override + public void onCameraChangeFinish(CameraPosition arg0) { + pxInMeters = amap.getScalePerPixel(); + clusterDistance = pxInMeters * clusterSize; + assignClusters(); + } + + @Override + public boolean onMarkerClick(Marker marker) { + if (clusterClickListener == null) { + return true; + } + Cluster cluster = (Cluster) marker.getObject(); + if (cluster != null) { + clusterClickListener.onMarkerClicked(marker, cluster.getClusterItems()); + return true; + } + return false; + } + + /** + * 将聚合元素添加至地图上 + */ + private void addClusterToMap(List clusters) { + ArrayList removeMarkers = new ArrayList<>(addMarkers); + AlphaAnimation alphaAnimation = new AlphaAnimation(1, 0); + RemoveAnimationListener removeAnimationListener = new RemoveAnimationListener(removeMarkers); + for (Marker marker : removeMarkers) { + marker.setAnimation(alphaAnimation); + marker.setAnimationListener(removeAnimationListener); + marker.startAnimation(); + } + + for (Cluster cluster : clusters) { + addSingleClusterToMap(cluster); + } + } + + /** + * 将单个聚合元素添加至地图显示 + */ + private void addSingleClusterToMap(Cluster cluster) { + LatLng latlng = cluster.getCenterLatLng(); + MarkerOptions markerOptions = new MarkerOptions(); + markerOptions.icon(getBitmapDes(cluster.getClusterCount())).position(latlng); + Marker marker = amap.addMarker(markerOptions); + marker.setAnimation(addAnimation); + marker.setObject(cluster); + + marker.startAnimation(); + cluster.setMarker(marker); + addMarkers.add(marker); + } + + private void calculateClusters() { + isCanceled = false; + clusters.clear(); + LatLngBounds visibleBounds = amap.getProjection().getVisibleRegion().latLngBounds; + for (ClusterItem clusterItem : clusterItems) { + if (isCanceled) { + return; + } + LatLng latlng = clusterItem.getPosition(); + if (visibleBounds.contains(latlng)) { + Cluster cluster = getCluster(latlng, clusters); + if (cluster == null) { + cluster = new Cluster(latlng); + clusters.add(cluster); + } + cluster.addClusterItem(clusterItem); + } + } + + //复制一份数据,规避同步 + List tempClusters = new ArrayList<>(clusters); + Message message = Message.obtain(); + message.what = MarkerHandler.ADD_CLUSTER_LIST; + message.obj = tempClusters; + if (isCanceled) { + return; + } + markerHandler.sendMessage(message); + } + + /** + * 对点进行聚合 + */ + private void assignClusters() { + isCanceled = true; + signClusterHandler.removeMessages(SignClusterHandler.CALCULATE_CLUSTER); + signClusterHandler.sendEmptyMessage(SignClusterHandler.CALCULATE_CLUSTER); + } + + /** + * 在已有的聚合基础上,对添加的单个元素进行聚合 + */ + private void calculateSingleCluster(ClusterItem clusterItem) { + LatLngBounds visibleBounds = amap.getProjection().getVisibleRegion().latLngBounds; + LatLng latlng = clusterItem.getPosition(); + if (!visibleBounds.contains(latlng)) { + return; + } + Cluster cluster = getCluster(latlng, clusters); + if (cluster != null) { + cluster.addClusterItem(clusterItem); + Message message = Message.obtain(); + message.what = MarkerHandler.UPDATE_SINGLE_CLUSTER; + + message.obj = cluster; + markerHandler.removeMessages(MarkerHandler.UPDATE_SINGLE_CLUSTER); + markerHandler.sendMessageDelayed(message, 5); + } else { + cluster = new Cluster(latlng); + clusters.add(cluster); + cluster.addClusterItem(clusterItem); + Message message = Message.obtain(); + message.what = MarkerHandler.ADD_SINGLE_CLUSTER; + message.obj = cluster; + markerHandler.sendMessage(message); + } + } + + /** + * 根据一个点获取是否可以依附的聚合点,没有则返回null + */ + private Cluster getCluster(LatLng latLng, List clusters) { + for (Cluster cluster : clusters) { + LatLng clusterCenterPoint = cluster.getCenterLatLng(); + double distance = AMapUtils.calculateLineDistance(latLng, clusterCenterPoint); + if (distance < clusterDistance && amap.getCameraPosition().zoom < 19) { + return cluster; + } + } + return null; + } + + + /** + * 获取每个聚合点的绘制样式 + */ + private BitmapDescriptor getBitmapDes(int num) { + TextView textView = new TextView(context); + if (num > 1) { + String tile = String.valueOf(num); + textView.setText(tile); + } + textView.setGravity(Gravity.CENTER); + textView.setTextColor(Color.BLACK); + textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 15); + if (clusterRender != null && clusterRender.getDrawableByCount(num) != null) { + textView.setBackgroundDrawable(clusterRender.getDrawableByCount(num)); + } else { + textView.setBackgroundResource(R.mipmap.well_location); + } + return BitmapDescriptorFactory.fromView(textView); + } + + /** + * 更新已加入地图聚合点的样式 + */ + private void updateCluster(Cluster cluster) { + Marker marker = cluster.getMarker(); + marker.setIcon(getBitmapDes(cluster.getClusterCount())); + } + + /** + * 处理market添加,更新等操作 + */ + class MarkerHandler extends Handler { + + static final int ADD_CLUSTER_LIST = 0; + + static final int ADD_SINGLE_CLUSTER = 1; + + static final int UPDATE_SINGLE_CLUSTER = 2; + + public MarkerHandler(Looper looper) { + super(looper); + } + + public void handleMessage(Message message) { + switch (message.what) { + case ADD_CLUSTER_LIST: + List clusters = (List) message.obj; + addClusterToMap(clusters); + break; + case ADD_SINGLE_CLUSTER: + Cluster cluster = (Cluster) message.obj; + addSingleClusterToMap(cluster); + break; + case UPDATE_SINGLE_CLUSTER: + Cluster updateCluster = (Cluster) message.obj; + updateCluster(updateCluster); + break; + } + } + } + + /** + * 处理聚合点算法线程 + */ + class SignClusterHandler extends Handler { + static final int CALCULATE_CLUSTER = 0; + static final int CALCULATE_SINGLE_CLUSTER = 1; + + public SignClusterHandler(Looper looper) { + super(looper); + } + + public void handleMessage(Message message) { + switch (message.what) { + case CALCULATE_CLUSTER: + calculateClusters(); + break; + case CALCULATE_SINGLE_CLUSTER: + ClusterItem item = (ClusterItem) message.obj; + clusterItems.add(item); + calculateSingleCluster(item); + break; + } + } + } +} diff --git a/app/src/main/java/com/casic/app/smartwell/widgets/cluster/ClusterRender.java b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/ClusterRender.java new file mode 100644 index 0000000..427ff14 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/ClusterRender.java @@ -0,0 +1,10 @@ +package com.casic.app.smartwell.widgets.cluster; + +import android.graphics.drawable.Drawable; + +public interface ClusterRender { + /** + * 根据聚合点的元素数目返回渲染背景样式 + */ + Drawable getDrawableByCount(int clusterNum); +} diff --git a/app/src/main/java/com/casic/app/smartwell/widgets/cluster/RegionItem.java b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/RegionItem.java new file mode 100644 index 0000000..7b2b6c4 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/RegionItem.java @@ -0,0 +1,23 @@ +package com.casic.app.smartwell.widgets.cluster; + +import com.amap.api.maps.model.LatLng; +import com.casic.app.smartwell.model.MapWellListModel; + +public class RegionItem implements ClusterItem { + private final LatLng latLng; + private final MapWellListModel.DataModel well; + + public RegionItem(LatLng latLng, MapWellListModel.DataModel well) { + this.latLng = latLng; + this.well = well; + } + + @Override + public LatLng getPosition() { + return latLng; + } + + public MapWellListModel.DataModel getWell() { + return well; + } +} diff --git a/app/src/main/java/com/casic/app/smartwell/widgets/cluster/RemoveAnimationListener.java b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/RemoveAnimationListener.java new file mode 100644 index 0000000..c9c5e84 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/RemoveAnimationListener.java @@ -0,0 +1,30 @@ +package com.casic.app.smartwell.widgets.cluster; + +import com.amap.api.maps.model.Marker; +import com.amap.api.maps.model.animation.Animation; + +import java.util.List; + +/** + * marker渐变动画,动画结束后将Marker删除 + */ +public class RemoveAnimationListener implements Animation.AnimationListener { + private final List removeMarkers; + + public RemoveAnimationListener(List removeMarkers) { + this.removeMarkers = removeMarkers; + } + + @Override + public void onAnimationStart() { + + } + + @Override + public void onAnimationEnd() { + for (Marker marker : removeMarkers) { + marker.remove(); + } + removeMarkers.clear(); + } +} \ No newline at end of file diff --git a/app/src/main/res/anim/map_popup_hide.xml b/app/src/main/res/anim/map_popup_hide.xml new file mode 100644 index 0000000..119726b --- /dev/null +++ b/app/src/main/res/anim/map_popup_hide.xml @@ -0,0 +1,12 @@ + + + + \ No newline at end of file diff --git a/app/src/main/res/anim/map_popup_show.xml b/app/src/main/res/anim/map_popup_show.xml new file mode 100644 index 0000000..1d281ef --- /dev/null +++ b/app/src/main/res/anim/map_popup_show.xml @@ -0,0 +1,12 @@ + + + + \ No newline at end of file diff --git a/app/src/main/res/anim/popup_hide.xml b/app/src/main/res/anim/popup_hide.xml index 55c7aca..7480485 100644 --- a/app/src/main/res/anim/popup_hide.xml +++ b/app/src/main/res/anim/popup_hide.xml @@ -1,7 +1,8 @@ - + \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/extensions/Int.kt b/app/src/main/java/com/casic/app/smartwell/extensions/Int.kt index de0617b..a0a5e33 100644 --- a/app/src/main/java/com/casic/app/smartwell/extensions/Int.kt +++ b/app/src/main/java/com/casic/app/smartwell/extensions/Int.kt @@ -1,9 +1,24 @@ package com.casic.app.smartwell.extensions +import android.graphics.Bitmap +import android.graphics.Canvas +import android.graphics.Paint +import android.graphics.RectF + fun Int.toLevel(): String { return if (this == 0) { "" } else { this.toString() } +} + +fun Int.drawCircle(color: Int): Bitmap? { + val bitmap = Bitmap.createBitmap(this * 2, this * 2, Bitmap.Config.ARGB_8888) + val canvas = Canvas(bitmap) + val paint = Paint() + val rectF = RectF(0f, 0f, (this * 2).toFloat(), (this * 2).toFloat()) + paint.color = color + canvas.drawArc(rectF, 0f, 360f, true, paint) + return bitmap } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt index 6b6ca3e..5e45534 100644 --- a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt +++ b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt @@ -2,17 +2,13 @@ import android.content.Context import com.casic.app.smartwell.callback.OnImageCompressListener -import com.casic.app.smartwell.model.ErrorMessageModel import com.casic.app.smartwell.utils.LocaleConstant -import com.google.gson.Gson -import com.google.gson.reflect.TypeToken +import com.google.gson.JsonParser import com.pengxh.kt.lite.extensions.createCompressImageDir import com.pengxh.kt.lite.utils.SaveKeyValues -import org.json.JSONObject import top.zibin.luban.Luban import top.zibin.luban.OnCompressListener import java.io.File -import java.util.Locale /** * String扩展方法 @@ -74,18 +70,22 @@ } } -fun String.separateResponseCode(): Int { +fun String.getResponseCode(): Int { if (this.isBlank()) { return 404 } - return JSONObject(this).getInt("code") + val element = JsonParser.parseString(this) + val jsonObject = element.asJsonObject + return jsonObject.get("code").asInt } -fun String.toErrorMessage(): String { - val errorModel = Gson().fromJson( - this, object : TypeToken() {}.type - ) - return errorModel.message.toString() +fun String.getResponseMessage(): String { + if (this.isBlank()) { + return "" + } + val element = JsonParser.parseString(this) + val jsonObject = element.asJsonObject + return jsonObject.get("message").asString } fun String.compressImage(context: Context, listener: OnImageCompressListener) { @@ -93,9 +93,6 @@ .load(this) .ignoreBy(100) .setTargetDir(context.createCompressImageDir().toString()) - .filter { - !(it.isBlank() || it.lowercase(Locale.getDefault()).endsWith(".gif")) - } .setCompressListener(object : OnCompressListener { override fun onStart() { 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 96df110..cd25fca 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 @@ -1,26 +1,25 @@ package com.casic.app.smartwell.fragment -import android.graphics.Point +import android.graphics.Color +import android.graphics.drawable.BitmapDrawable +import android.graphics.drawable.Drawable 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 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.LatLngBounds import com.amap.api.maps.model.Marker -import com.amap.api.maps.model.MarkerOptions import com.casic.app.smartwell.R import com.casic.app.smartwell.databinding.FragmentHomeBinding +import com.casic.app.smartwell.extensions.drawCircle import com.casic.app.smartwell.extensions.initImmersionBar -import com.casic.app.smartwell.extensions.valueToType import com.casic.app.smartwell.model.MapWellListModel import com.casic.app.smartwell.utils.LocaleConstant import com.casic.app.smartwell.utils.RouteOnMap @@ -31,9 +30,16 @@ import com.casic.app.smartwell.view.WellOperationActivity import com.casic.app.smartwell.vm.OrderViewModel import com.casic.app.smartwell.vm.WellViewModel +import com.casic.app.smartwell.widgets.MapWellPopup +import com.casic.app.smartwell.widgets.cluster.ClusterItem +import com.casic.app.smartwell.widgets.cluster.ClusterOnClickListener +import com.casic.app.smartwell.widgets.cluster.ClusterOverlay +import com.casic.app.smartwell.widgets.cluster.RegionItem 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.convertDrawable +import com.pengxh.kt.lite.extensions.dp2px import com.pengxh.kt.lite.extensions.navigatePageTo import com.pengxh.kt.lite.extensions.show import com.pengxh.kt.lite.utils.LoadingDialogHub @@ -43,35 +49,23 @@ /** * 地图点位带聚合效果 * */ -class HomePageHaveClusterFragment : KotlinBaseFragment(), AMap.OnMapLoadedListener, - AMap.OnCameraChangeListener, AMap.OnMarkerClickListener, AMap.InfoWindowAdapter, - AMap.OnInfoWindowClickListener { +class HomePageHaveClusterFragment : KotlinBaseFragment(), + AMap.OnCameraChangeListener { private val kTag = "HaveClusterFragment" private val easyPopupWindow by lazy { EasyPopupWindow(requireContext()) } - private lateinit var wellViewModel: WellViewModel - private lateinit var orderViewModel: OrderViewModel - private lateinit var aMap: AMap - - /** - * 所有的marker - */ - private var allMarkerOptions: MutableList = ArrayList() - - /** - * 视野内的marker - */ - private var markerOptionsInView: MutableList = ArrayList() - - /** - * 自定义Marker弹出框 - * */ - private lateinit var v: View + private val regionRadius by lazy { LocaleConstant.RADIUS_SIZE.dp2px(requireContext()) } + private val infoPopup by lazy { MapWellPopup(requireContext()) } /** * 所有窨井列表信息集合 * */ - private var wellModels: MutableList = ArrayList() + private val wellModels = ArrayList() + private val backDrawables = HashMap() + private lateinit var wellViewModel: WellViewModel + private lateinit var orderViewModel: OrderViewModel + private lateinit var aMap: AMap + private var clusterOverlay: ClusterOverlay? = null override fun initViewBinding( inflater: LayoutInflater, @@ -106,6 +100,9 @@ } }) + //地图初始化 + initMap(savedInstanceState) + //初始化vm wellViewModel = ViewModelProvider(this)[WellViewModel::class.java] orderViewModel = ViewModelProvider(this)[OrderViewModel::class.java] @@ -120,25 +117,19 @@ val latitudeList: MutableList = ArrayList() val longitudeList: MutableList = ArrayList() it.data?.forEach { well -> - val lat = well.latGaode.toString() - val lng = well.lngGaode.toString() + val lat = well.latGaode + val lng = well.lngGaode if (lat.isNotBlank() && lng.isNotBlank()) { //返回true代表当前位置在大陆、港澳地区,反之不在 val latitude = lat.toDouble() val longitude = lng.toDouble() if (CoordinateConverter.isAMapDataAvailable(latitude, longitude)) { - //缓存所有设备详情,点击Marker时候需要 + //缓存所有井 wellModels.add(well) + //分别缓存经、纬度 latitudeList.add(latitude) longitudeList.add(longitude) - //将所有设备信息转化缓存为Marker点 - allMarkerOptions.add( - MarkerOptions() - .position(LatLng(latitude, longitude)) - .title(well.wellTypeName) - .snippet(well.wellName) - ) } } } @@ -160,12 +151,12 @@ val cameraPosition = CameraPosition(centerLatLng, 16f, 0f, 0f) val cameraUpdate = CameraUpdateFactory.newCameraPosition(cameraPosition) aMap.animateCamera(cameraUpdate, 1500, null) + + //显示点数据 + displayWellOnMap() } } - //地图初始化 - initMap(savedInstanceState) - //获取窨井监控数据 wellViewModel.countResultModel.observe(this) { binding.deployedWellView.text = it["bfWell"] @@ -220,17 +211,10 @@ uiSettings.isCompassEnabled = true uiSettings.zoomPosition = AMapOptions.ZOOM_POSITION_RIGHT_CENTER uiSettings.isTiltGesturesEnabled = false//不许地图随手势倾斜角度 + uiSettings.isRotateGesturesEnabled = false//不允许地图随手势改变方位 - // 地图加载成功监听 - aMap.addOnMapLoadedListener(this) // 地图缩放监听 aMap.addOnCameraChangeListener(this) - // marker 点击事件监听 - aMap.addOnMarkerClickListener(this) - // 点击marker弹出自定义popup - aMap.setInfoWindowAdapter(this) - //信息窗点击事件 - aMap.addOnInfoWindowClickListener(this) } override fun initEvent() { @@ -259,9 +243,111 @@ } - override fun onMapLoaded() { - //地图加载成功之后显示聚合点数据 - initClustersMarkers() + private fun displayWellOnMap() { + clusterOverlay?.onDestroy() + val clusterItems = ArrayList() + + wellModels.forEach { + val latitude = it.latGaode.toDouble() + val longitude = it.lngGaode.toDouble() + + val latLng = LatLng(latitude, longitude, false) + val regionItem = RegionItem(latLng, it) + clusterItems.add(regionItem) + } + + clusterOverlay = ClusterOverlay(requireContext(), aMap, clusterItems, regionRadius) + clusterOverlay?.setClusterRender { clusterNum -> + //聚合圆半径 + val radius = 100.dp2px(requireContext()) + if (clusterNum == 0) { + var bitmapDrawable = backDrawables[0] + if (bitmapDrawable == null) { + bitmapDrawable = BitmapDrawable( + null, radius.drawCircle(Color.argb(159, 100, 149, 237)) + ) + backDrawables[0] = bitmapDrawable + } + bitmapDrawable + } + if (clusterNum == 1) { + var bitmapDrawable = backDrawables[1] + if (bitmapDrawable == null) { + bitmapDrawable = R.mipmap.well_location.convertDrawable(requireContext())!! + backDrawables[1] = bitmapDrawable + } + bitmapDrawable + } else if (clusterNum < 5) { + var bitmapDrawable = backDrawables[2] + if (bitmapDrawable == null) { + bitmapDrawable = BitmapDrawable( + null, radius.drawCircle(Color.argb(159, 100, 149, 237)) + ) + backDrawables[2] = bitmapDrawable + } + bitmapDrawable + } else if (clusterNum < 10) { + var bitmapDrawable = backDrawables[3] + if (bitmapDrawable == null) { + bitmapDrawable = BitmapDrawable( + null, radius.drawCircle(Color.argb(199, 30, 144, 255)) + ) + backDrawables[3] = bitmapDrawable + } + bitmapDrawable + } else { + var bitmapDrawable = backDrawables[4] + if (bitmapDrawable == null) { + bitmapDrawable = BitmapDrawable( + null, radius.drawCircle(Color.argb(235, 65, 105, 225)) + ) + backDrawables[4] = bitmapDrawable + } + bitmapDrawable + } + } + + clusterOverlay?.setOnClusterClickListener(object : ClusterOnClickListener { + override fun onMarkerClicked(marker: Marker?, items: List) { + if (items.size > 1) { + "请缩放地图比例在查看数据".show(requireContext()) + return + } + + var item: RegionItem? = null + val builder = LatLngBounds.Builder() + for (clusterItem in items) { + builder.include(clusterItem.position) + item = clusterItem as RegionItem + } + + item?.apply { + showWellPopup(well) + } + } + }) + } + + private fun showWellPopup(well: MapWellListModel.DataModel) { + infoPopup.set(well, object : MapWellPopup.OnPopupWindowClickListener { + override fun onPopupClicked(lat: Double, lng: Double) { + AlertControlDialog.Builder().setContext(requireContext()).setTitle("操作提示") + .setMessage("确定要前往吗").setNegativeButton("取消").setPositiveButton("确定") + .setOnDialogButtonClickListener(object : + AlertControlDialog.OnDialogButtonClickListener { + override fun onConfirmClick() { + RouteOnMap.startNavigation( + requireContext(), "", LatLng(lat, lng) + ) + } + + override fun onCancelClick() { + + } + }).build().show() + } + }) + infoPopup.showAsDropDown(binding.rightOptionView) } override fun onCameraChange(p0: CameraPosition?) { @@ -282,103 +368,10 @@ } } - //获取视野内的marker 根据聚合算法合成自定义的marker 显示视野内的marker override fun onCameraChangeFinish(p0: CameraPosition?) { //地图缩放之后显示聚合点数据 LoadingDialogHub.dismiss() httpCountDownTimer.cancel() - initClustersMarkers() - } - - private fun initClustersMarkers() { - 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 { - v = LayoutInflater.from(requireContext()).inflate(R.layout.popup_map_info, null) - - //显示闸井信息 - marker?.showInfoWindow() - return true - } - - override fun getInfoWindow(marker: Marker?): View { - //反射得到popup里面的控件对象 - val wellNameView = v.findViewById(R.id.wellNameView) - val wellCodeView = v.findViewById(R.id.wellCodeView) - val wellTypeView = v.findViewById(R.id.wellTypeView) - val wellStateView = v.findViewById(R.id.wellStateView) - val deepView = v.findViewById(R.id.deepView) - val locationView = v.findViewById(R.id.locationView) - - //绑定数据 - val clickedLatLng = marker?.position!! - wellModels.forEach { well -> - if (clickedLatLng.latitude == well.latGaode!!.toDouble() - && clickedLatLng.longitude == well.lngGaode!!.toDouble() - ) { - wellNameView.text = String.format("点位名称: ${well.wellName}") - wellCodeView.text = String.format("点位编号: ${well.wellCode}") - wellTypeView.text = String.format("点位类型: ${well.wellType.valueToType()}") - val bfztName = if (well.bfzt == "1") { - "已布防" - } else { - "已撤防" - } - wellStateView.text = String.format("布/撤防状态: $bfztName") - deepView.text = String.format("点位深度: ${well.deep}m") - locationView.text = String.format("详细位置: ${well.position}") - } - } - return v - } - - /** - * 此方法不能修改整个 InfoWindow 的背景和边框,无论自定义的样式是什么样,SDK 都会在最外层添加一个默认的边框 - * */ - override fun getInfoContents(p0: Marker?): View? = null - - override fun onInfoWindowClick(p0: Marker?) { - p0?.apply { - AlertControlDialog.Builder() - .setContext(requireContext()) - .setTitle("操作提示") - .setMessage("确定要前往吗") - .setNegativeButton("取消") - .setPositiveButton("确定") - .setOnDialogButtonClickListener(object : - AlertControlDialog.OnDialogButtonClickListener { - override fun onConfirmClick() { - val lat = position.latitude.toString() - val lng = position.longitude.toString() - if (lat.isBlank() || lng.isBlank()) { - "点位经纬度异常,无法开启导航".show(requireContext()) - return - } - RouteOnMap.startNavigation( - requireContext(), snippet, LatLng(lat.toDouble(), lng.toDouble()) - ) - } - - override fun onCancelClick() { - - } - }).build().show() - } } /***以下是地图生命周期管理************************************************************************/ 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 a54d213..bfa7a57 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 @@ -44,8 +44,8 @@ * 地图点位不带聚合效果 * */ class HomePageNoClusterFragment : KotlinBaseFragment(), - AMap.OnMapLoadedListener, AMap.OnCameraChangeListener, AMap.OnMarkerClickListener, - AMap.InfoWindowAdapter, AMap.OnInfoWindowClickListener { + AMap.OnCameraChangeListener, AMap.OnMarkerClickListener, AMap.InfoWindowAdapter, + AMap.OnInfoWindowClickListener { private val kTag = "NoClusterFragment" private val easyPopupWindow by lazy { EasyPopupWindow(requireContext()) } @@ -109,6 +109,9 @@ wellViewModel = ViewModelProvider(this)[WellViewModel::class.java] orderViewModel = ViewModelProvider(this)[OrderViewModel::class.java] + //地图初始化 + initMap(savedInstanceState) + //获取所有窨井数据 httpCountDownTimer.start() LoadingDialogHub.show(requireActivity(), "数据加载中,请稍后...") @@ -157,12 +160,12 @@ val cameraPosition = CameraPosition(centerLatLng, 16f, 0f, 0f) val cameraUpdate = CameraUpdateFactory.newCameraPosition(cameraPosition) aMap.animateCamera(cameraUpdate, 1500, null) + + //显示点数据 + displayWellOnMap() } } - //地图初始化 - initMap(savedInstanceState) - //获取窨井监控数据 wellViewModel.countResultModel.observe(this) { binding.deployedWellView.text = it["bfWell"] @@ -214,9 +217,8 @@ uiSettings.isCompassEnabled = true uiSettings.zoomPosition = AMapOptions.ZOOM_POSITION_RIGHT_CENTER uiSettings.isTiltGesturesEnabled = false//不许地图随手势倾斜角度 + uiSettings.isRotateGesturesEnabled = false//不允许地图随手势改变方位 - // 地图加载成功监听 - aMap.addOnMapLoadedListener(this) // 地图缩放监听 aMap.addOnCameraChangeListener(this) // marker 点击事件监听 @@ -253,11 +255,6 @@ } - override fun onMapLoaded() { - //地图加载成功之后显示聚合点数据 - initClustersMarkers() - } - override fun onCameraChange(p0: CameraPosition?) { } @@ -281,10 +278,9 @@ //地图缩放之后显示聚合点数据 LoadingDialogHub.dismiss() httpCountDownTimer.cancel() - initClustersMarkers() } - private fun initClustersMarkers() { + private fun displayWellOnMap() { val proj = aMap.projection val dm = resources.displayMetrics var screenLocation: Point diff --git a/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.java b/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.java deleted file mode 100644 index d8b18ef..0000000 --- a/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.java +++ /dev/null @@ -1,50 +0,0 @@ -package com.casic.app.smartwell.model; - -public class ErrorMessageModel { - - private int code; - private String data; - private String exceptionClazz; - private String message; - private boolean success; - - public int getCode() { - return code; - } - - public void setCode(int code) { - this.code = code; - } - - public String getData() { - return data; - } - - public void setData(String data) { - this.data = data; - } - - public String getExceptionClazz() { - return exceptionClazz; - } - - public void setExceptionClazz(String exceptionClazz) { - this.exceptionClazz = exceptionClazz; - } - - public String getMessage() { - return message; - } - - public void setMessage(String message) { - this.message = message; - } - - public boolean isSuccess() { - return success; - } - - public void setSuccess(boolean success) { - this.success = success; - } -} \ No newline at end of file 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 new file mode 100644 index 0000000..215ac0c --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/PipelineModel.java @@ -0,0 +1,328 @@ +package com.casic.app.smartwell.model; + +import java.util.List; + +public class PipelineModel { + + private Integer code; + private DataModel data; + private String message; + private Boolean success; + + public Integer getCode() { + return code; + } + + public void setCode(Integer code) { + this.code = code; + } + + public DataModel getData() { + return data; + } + + public void setData(DataModel data) { + this.data = data; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + public Boolean getSuccess() { + return success; + } + + public void setSuccess(Boolean success) { + this.success = success; + } + + public static class DataModel { + private List rows; + private Integer total; + + public List getRows() { + return rows; + } + + public void setRows(List rows) { + this.rows = rows; + } + + public Integer getTotal() { + return total; + } + + public void setTotal(Integer total) { + this.total = total; + } + + 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 getBuryMode() { + return buryMode; + } + + public void setBuryMode(String buryMode) { + this.buryMode = buryMode; + } + + public String getConstructEra() { + return constructEra; + } + + public void setConstructEra(String constructEra) { + this.constructEra = constructEra; + } + + 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; + } + } + } +} 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 06d3d2b..4f38a2c 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 = 100 //相距多少米才聚合,单位:米 + const val RADIUS_SIZE = 80 //相距多少米才聚合,单位:米 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:11308" + // 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 0d5f3fa..991e1db 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 @@ -312,4 +312,14 @@ @Header("token") token: String, @Field("clientid") deviceCode: String ): String + + /** + * 管线位置数据 + */ + @GET("/pipeline/listPage") + suspend fun getPipeline( + @Header("token") token: String, + @Query("limit") limit: Int, + @Query("offset") offset: Int + ): String } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt index 1a0ce22..4050067 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt @@ -294,4 +294,11 @@ suspend fun registerPush(clientId: String): String { return api.registerPush(AuthenticationHelper.token!!, clientId) } + + /** + * 管线位置数据 + */ + suspend fun getPipeline(): String { + return api.getPipeline(AuthenticationHelper.token!!, 2000, 1) + } } \ No newline at end of file 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 9270fa1..4ca5a5e 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.HomePageNoClusterFragment +import com.casic.app.smartwell.fragment.HomePageHaveClusterFragment 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/vm/AlarmViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/AlarmViewModel.kt index 9cff08c..e7acc17 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/AlarmViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/AlarmViewModel.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.AlarmContentModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager import com.google.gson.Gson @@ -16,7 +16,7 @@ fun getAlarmContentType(alarmType: String) = launch({ val response = RetrofitServiceManager.getAlarmContentType(alarmType) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { listModel.value = gson.fromJson( response, object : TypeToken() {}.type diff --git a/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt index 5e5b163..895dedd 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.PublicKeyModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager import com.google.gson.Gson @@ -18,7 +18,7 @@ fun getPublicKey() = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.authenticate() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { keyModel.value = gson.fromJson( response, object : TypeToken() {}.type diff --git a/app/src/main/java/com/casic/app/smartwell/vm/DeviceViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/DeviceViewModel.kt index db5ccf6..899a962 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/DeviceViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/DeviceViewModel.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.DeviceDetailModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager import com.google.gson.Gson @@ -16,7 +16,7 @@ fun getDeviceDetail(deviceCode: String) = launch({ val response = RetrofitServiceManager.getDeviceDetail(deviceCode) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { detailModel.value = gson.fromJson( response, object : TypeToken() {}.type diff --git a/app/src/main/java/com/casic/app/smartwell/vm/LoginViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/LoginViewModel.kt index cd8b8a9..a417398 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/LoginViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/LoginViewModel.kt @@ -2,7 +2,7 @@ import androidx.lifecycle.MutableLiveData import com.casic.app.smartwell.base.BaseApplication -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.CommonResultModel import com.casic.app.smartwell.model.LoginResultModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -21,7 +21,7 @@ fun enter(account: String, secretKey: String) = launch({ val response = RetrofitServiceManager.login(account, secretKey) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success enterResultModel.value = gson.fromJson( @@ -38,7 +38,7 @@ fun out() = launch({ val response = RetrofitServiceManager.loginOut() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { outResultModel.value = gson.fromJson( response, object : TypeToken() {}.type diff --git a/app/src/main/java/com/casic/app/smartwell/vm/OperationViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/OperationViewModel.kt index 8943ed3..37e115f 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/OperationViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/OperationViewModel.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.vm import com.casic.app.smartwell.base.BaseApplication -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager import com.pengxh.kt.lite.base.BaseViewModel import com.pengxh.kt.lite.extensions.launch @@ -16,7 +16,7 @@ fun acceptWorkOrder(id: String) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.acceptWorkOrder(id) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success "接单成功".show(BaseApplication.get()) @@ -35,7 +35,7 @@ loadState.value = LoadState.Loading val response = RetrofitServiceManager.confirmWorkOrder(id, firstState, firstStatePhotos, needHandle) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success "工单确认成功".show(BaseApplication.get()) @@ -50,7 +50,7 @@ fun transferWorkOrder(id: String, userId: String) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.transferWorkOrder(id, userId) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success "转单成功".show(BaseApplication.get()) @@ -65,7 +65,7 @@ fun completeWorkOrder(id: String, handleMessage: String, handlePhotos: String) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.completeWorkOrder(id, handleMessage, handlePhotos) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success "工单处理成功".show(BaseApplication.get()) diff --git a/app/src/main/java/com/casic/app/smartwell/vm/OrderViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/OrderViewModel.kt index 4cb26b7..d2fad86 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/OrderViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/OrderViewModel.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.OrderDetailModel import com.casic.app.smartwell.model.OrderListModel import com.casic.app.smartwell.model.OrderStatusModel @@ -37,7 +37,7 @@ val response = RetrofitServiceManager.getSearchResult( keywords, alarmContent, alarmLevel, jobStatus, deptId, beginTime, endTime, offset ) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success searchResult.value = gson.fromJson( @@ -53,7 +53,7 @@ fun getWorkOrderListByState(jobStatus: String, page: Int) = launch({ val response = RetrofitServiceManager.getWorkOrderList(jobStatus, page) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { orderList.value = gson.fromJson( response, object : TypeToken() {}.type @@ -65,7 +65,7 @@ fun getNotAcceptOderList(page: Int) = launch({ val response = RetrofitServiceManager.getNotAcceptOderList(page) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { orderList.value = gson.fromJson( response, object : TypeToken() {}.type @@ -77,7 +77,7 @@ fun getNotHandleOderList(page: Int) = launch({ val response = RetrofitServiceManager.getNotHandleOderList(page) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { orderList.value = gson.fromJson( response, object : TypeToken() {}.type @@ -89,7 +89,7 @@ fun countWorkOrderByState() = launch({ val response = RetrofitServiceManager.countWorkOrderByState() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { val map = HashMap(4) @@ -107,7 +107,7 @@ fun getOrderStatus() = launch({ val response = RetrofitServiceManager.getOrderStatus() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { orderStatusModel.value = gson.fromJson( response, object : TypeToken() {}.type @@ -120,7 +120,7 @@ fun getWorkOrderDetail(id: String) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.getWorkOrderDetail(id) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success detailModel.value = gson.fromJson( diff --git a/app/src/main/java/com/casic/app/smartwell/vm/PipelineViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/PipelineViewModel.kt new file mode 100644 index 0000000..60c1e2f --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/vm/PipelineViewModel.kt @@ -0,0 +1,28 @@ +package com.casic.app.smartwell.vm + +import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.extensions.getResponseCode +import com.casic.app.smartwell.model.PipelineModel +import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken +import com.pengxh.kt.lite.base.BaseViewModel +import com.pengxh.kt.lite.extensions.launch + +class PipelineViewModel : BaseViewModel() { + + private val gson by lazy { Gson() } + val lineResult = MutableLiveData() + + fun getPipeline() = launch({ + val response = RetrofitServiceManager.getPipeline() + val responseCode = response.getResponseCode() + if (responseCode == 200) { + lineResult.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } + }, { + it.printStackTrace() + }) +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/PushViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/PushViewModel.kt index 9279815..12fd610 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/PushViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/PushViewModel.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.CommonResultModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager import com.google.gson.Gson @@ -16,7 +16,7 @@ fun registerPush(clientId: String) = launch({ val response = RetrofitServiceManager.registerPush(clientId) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { registerResultModel.value = gson.fromJson( response, object : TypeToken() {}.type diff --git a/app/src/main/java/com/casic/app/smartwell/vm/UploadImageViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/UploadImageViewModel.kt index 8d6744e..9707eeb 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/UploadImageViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/UploadImageViewModel.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.CommonResultModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager import com.google.gson.Gson @@ -19,7 +19,7 @@ fun uploadImage(image: File) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.uploadImage(image) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success resultModel.value = gson.fromJson( diff --git a/app/src/main/java/com/casic/app/smartwell/vm/UserViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/UserViewModel.kt index 31a4d4c..070c35a 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/UserViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/UserViewModel.kt @@ -2,7 +2,7 @@ import androidx.lifecycle.MutableLiveData import com.casic.app.smartwell.base.BaseApplication -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.SubordinateModel import com.casic.app.smartwell.model.UserDetailModel import com.casic.app.smartwell.model.VersionResultModel @@ -25,7 +25,7 @@ fun getUserDetail() = launch({ val response = RetrofitServiceManager.getUserDetail() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { val userDetail = gson.fromJson( response, object : TypeToken() {}.type @@ -48,7 +48,7 @@ * */ fun getSubordinate(hasMine: String?, deptId: String?, roleTips: String?) = launch({ val response = RetrofitServiceManager.getSubordinate(hasMine, deptId, roleTips) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { subordinateModel.value = gson.fromJson( response, object : TypeToken() {}.type @@ -61,7 +61,7 @@ fun changePassword(oldPwd: String, newPwd: String) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.changePassword(oldPwd, newPwd) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success "修改成功,请重新登录".show(BaseApplication.get()) @@ -76,7 +76,7 @@ fun updateVersion() = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.updateVersion() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success versionResultModel.value = gson.fromJson( diff --git a/app/src/main/java/com/casic/app/smartwell/vm/WellViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/WellViewModel.kt index 3d41e9b..9e42e36 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/WellViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/WellViewModel.kt @@ -2,8 +2,7 @@ import androidx.lifecycle.MutableLiveData import com.casic.app.smartwell.base.BaseApplication -import com.casic.app.smartwell.extensions.separateResponseCode -import com.casic.app.smartwell.extensions.toErrorMessage +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.AuthorDeptModel import com.casic.app.smartwell.model.CommonResultModel import com.casic.app.smartwell.model.MapWellListModel @@ -32,7 +31,7 @@ fun countWellByState() = launch({ val response = RetrofitServiceManager.countWellByState() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { val map = HashMap(3) @@ -57,7 +56,7 @@ fun getWellType() = launch({ val response = RetrofitServiceManager.getWellType() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { wellTypeModel.value = gson.fromJson( response, object : TypeToken() {}.type @@ -70,7 +69,7 @@ fun getWellDetail(id: String) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.getWellDetail(id) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success wellDetailModel.value = gson.fromJson( @@ -87,7 +86,7 @@ fun getOperationResult(id: String, state: String) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.getOperationResult(id, state) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success "操作成功".show(BaseApplication.get()) @@ -105,7 +104,7 @@ fun getMonitorResult(id: String) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.getMonitorResult(id) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success monitorModel.value = gson.fromJson( @@ -125,7 +124,7 @@ val response = RetrofitServiceManager.getWellListByPage( keywords, wellType, deptid, bfzt, page ) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { listModel.value = gson.fromJson( response, object : TypeToken() {}.type @@ -137,13 +136,11 @@ fun getWellList() = launch({ val response = RetrofitServiceManager.getWellList() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { totalWellModel.value = gson.fromJson( response, object : TypeToken() {}.type ) - } else { - response.toErrorMessage().show(BaseApplication.get()) } }, { it.printStackTrace() diff --git a/app/src/main/java/com/casic/app/smartwell/widgets/GaoDeClusterMarkerView.kt b/app/src/main/java/com/casic/app/smartwell/widgets/GaoDeClusterMarkerView.kt deleted file mode 100644 index 1f375df..0000000 --- a/app/src/main/java/com/casic/app/smartwell/widgets/GaoDeClusterMarkerView.kt +++ /dev/null @@ -1,100 +0,0 @@ -package com.casic.app.smartwell.widgets - -import android.content.Context -import android.graphics.Bitmap -import android.graphics.Point -import android.view.Gravity -import android.view.LayoutInflater -import android.view.View -import android.widget.TextView -import com.amap.api.maps.Projection -import com.amap.api.maps.model.BitmapDescriptorFactory -import com.amap.api.maps.model.LatLng -import com.amap.api.maps.model.LatLngBounds -import com.amap.api.maps.model.MarkerOptions -import com.casic.app.smartwell.R -import com.pengxh.kt.lite.extensions.toBitmap -import java.util.* - -class GaoDeClusterMarkerView( - private val context: Context, firstMarkers: MarkerOptions, projection: Projection, gridSize: Int -) { - //当前可观区域里的 聚合过之后的集合 - private val includeMarkers: ArrayList - - // 创建区域 - val bounds: LatLngBounds - var options: MarkerOptions = MarkerOptions() - - init { - val screenLocation = projection.toScreenLocation(firstMarkers.position) - //范围类 - val southwestPoint = Point(screenLocation.x - gridSize, screenLocation.y + gridSize) - //范围类 - val northeastPoint = Point(screenLocation.x + gridSize, screenLocation.y - gridSize) - bounds = LatLngBounds( - projection.fromScreenLocation(southwestPoint), - projection.fromScreenLocation(northeastPoint) - ) - //设置初始化marker属性 - options.anchor(0.5f, 1.3f) - .title(firstMarkers.title) - .position(firstMarkers.position) - .icon(firstMarkers.icon) - .snippet(firstMarkers.snippet) - .draggable(false) - includeMarkers = ArrayList() - includeMarkers.add(firstMarkers) - } - - /** - * 添加marker - */ - fun addMarker(markerOptions: MarkerOptions) { - includeMarkers.add(markerOptions) // 添加到列表中 - } - - /** - * 设置聚合点的中心位置以及图标 - */ - fun setPositionAndIcon() { - val size = includeMarkers.size - var lat = 0.0 - var lng = 0.0 - // 一个的时候 - if (size == 1) { //设置marker单个属性 - // 设置marker位置 - options.position( - LatLng( - includeMarkers[0].position.latitude, includeMarkers[0].position.longitude - ) - ) - } else { // 聚合的时候 - //设置marker聚合属性 - for (op in includeMarkers) { - lat += op.position.latitude - lng += op.position.longitude - } - // 设置marker的位置为中心位置为聚集点的平均位置 - options.position(LatLng(lat / size, lng / size)) - } - options.icon(BitmapDescriptorFactory.fromBitmap(getBitmap(size))) - } - - /** - * marker视图 - */ - private fun getBitmap(num: Int): Bitmap? { - val view = LayoutInflater.from(context).inflate(R.layout.marker_gaode, null) - val wellCountView = view.findViewById(R.id.wellCountView) - return if (num > 1) { - wellCountView.visibility = View.VISIBLE - wellCountView.text = String.format("${num}个") - wellCountView.gravity = Gravity.CENTER - view.toBitmap() - } else { - wellCountView.visibility = View.GONE - BitmapDescriptorFactory.fromResource(R.mipmap.well_location).bitmap - } - } -} \ No newline at end of file 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 new file mode 100644 index 0000000..ec455dd --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/widgets/MapWellPopup.kt @@ -0,0 +1,58 @@ +package com.casic.app.smartwell.widgets + +import android.content.Context +import android.view.LayoutInflater +import android.view.ViewGroup +import android.widget.LinearLayout +import android.widget.PopupWindow +import android.widget.TextView +import com.casic.app.smartwell.R +import com.casic.app.smartwell.extensions.valueToType +import com.casic.app.smartwell.model.MapWellListModel + +class MapWellPopup constructor(context: Context) : PopupWindow() { + + init { + width = ViewGroup.LayoutParams.MATCH_PARENT + height = ViewGroup.LayoutParams.WRAP_CONTENT + isOutsideTouchable = true + isFocusable = true + animationStyle = R.style.MapPopupAnimation + setBackgroundDrawable(null) + contentView = LayoutInflater.from(context).inflate( + R.layout.popup_map_info, null, false + ) + } + + fun set(well: MapWellListModel.DataModel, windowClickListener: OnPopupWindowClickListener) { + //反射得到popup里面的控件对象 + val rootView = contentView.findViewById(R.id.rootView) + val wellNameView = contentView.findViewById(R.id.wellNameView) + val wellCodeView = contentView.findViewById(R.id.wellCodeView) + val wellTypeView = contentView.findViewById(R.id.wellTypeView) + val wellStateView = contentView.findViewById(R.id.wellStateView) + val deepView = contentView.findViewById(R.id.deepView) + val locationView = contentView.findViewById(R.id.locationView) + + //绑定数据 + wellNameView.text = String.format("点位名称: ${well.wellName}") + wellCodeView.text = String.format("点位编号: ${well.wellCode}") + wellTypeView.text = String.format("点位类型: ${well.wellType.valueToType()}") + val bfztName = if (well.bfzt == "1") { + "已布防" + } else { + "已撤防" + } + wellStateView.text = String.format("布/撤防状态: $bfztName") + deepView.text = String.format("点位深度: ${well.deep}m") + locationView.text = String.format("详细位置: ${well.position}") + + rootView.setOnClickListener { + windowClickListener.onPopupClicked(well.latGaode.toDouble(), well.lngGaode.toDouble()) + } + } + + interface OnPopupWindowClickListener { + fun onPopupClicked(lat: Double, lng: Double) + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/widgets/cluster/Cluster.java b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/Cluster.java new file mode 100644 index 0000000..9455ccd --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/Cluster.java @@ -0,0 +1,43 @@ +package com.casic.app.smartwell.widgets.cluster; + +import com.amap.api.maps.model.LatLng; +import com.amap.api.maps.model.Marker; + +import java.util.ArrayList; +import java.util.List; + +public class Cluster { + private final LatLng latLng; + private final List clusterItems; + private Marker marker; + + + public Cluster(LatLng latLng) { + this.latLng = latLng; + clusterItems = new ArrayList<>(); + } + + public void addClusterItem(ClusterItem clusterItem) { + clusterItems.add(clusterItem); + } + + public int getClusterCount() { + return clusterItems.size(); + } + + public LatLng getCenterLatLng() { + return latLng; + } + + public void setMarker(Marker marker) { + this.marker = marker; + } + + public Marker getMarker() { + return marker; + } + + public List getClusterItems() { + return clusterItems; + } +} diff --git a/app/src/main/java/com/casic/app/smartwell/widgets/cluster/ClusterItem.java b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/ClusterItem.java new file mode 100644 index 0000000..f5d9a9d --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/ClusterItem.java @@ -0,0 +1,10 @@ +package com.casic.app.smartwell.widgets.cluster; + +import com.amap.api.maps.model.LatLng; + +public interface ClusterItem { + /** + * 返回聚合元素的地理位置 + */ + LatLng getPosition(); +} diff --git a/app/src/main/java/com/casic/app/smartwell/widgets/cluster/ClusterOnClickListener.java b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/ClusterOnClickListener.java new file mode 100644 index 0000000..0efa1f1 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/ClusterOnClickListener.java @@ -0,0 +1,15 @@ +package com.casic.app.smartwell.widgets.cluster; + +import com.amap.api.maps.model.Marker; + +import java.util.List; + +public interface ClusterOnClickListener { + /** + * 点击聚合点的回调处理函数 + * + * @param marker 点击的聚合点 + * @param items 聚合点所包含的元素 + */ + void onMarkerClicked(Marker marker, List items); +} 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 new file mode 100644 index 0000000..40df562 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/ClusterOverlay.java @@ -0,0 +1,349 @@ +package com.casic.app.smartwell.widgets.cluster; + +import android.content.Context; +import android.graphics.Color; +import android.os.Handler; +import android.os.HandlerThread; +import android.os.Looper; +import android.os.Message; +import android.util.TypedValue; +import android.view.Gravity; +import android.widget.TextView; + +import com.amap.api.maps.AMap; +import com.amap.api.maps.AMapUtils; +import com.amap.api.maps.model.BitmapDescriptor; +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.LatLngBounds; +import com.amap.api.maps.model.Marker; +import com.amap.api.maps.model.MarkerOptions; +import com.amap.api.maps.model.animation.AlphaAnimation; +import com.casic.app.smartwell.R; + +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.CopyOnWriteArrayList; + +/** + * 整体设计采用了两个线程,一个线程用于计算组织聚合数据,一个线程负责处理Marker相关操作 + */ +public class ClusterOverlay implements AMap.OnCameraChangeListener, AMap.OnMarkerClickListener { + private final AMap amap; + private final Context context; + private final List clusterItems; + private final List clusters; + private final int clusterSize; + private ClusterOnClickListener clusterClickListener; + private ClusterRender clusterRender; + private final CopyOnWriteArrayList addMarkers = new CopyOnWriteArrayList<>(); + private double clusterDistance; + private final HandlerThread markerHandlerThread = new HandlerThread("addMarker"); + private final HandlerThread signClusterThread = new HandlerThread("calculateCluster"); + private Handler markerHandler; + private Handler signClusterHandler; + private float pxInMeters; + private boolean isCanceled = false; + private final AlphaAnimation addAnimation = new AlphaAnimation(0, 1); + + /** + * 构造函数,批量添加聚合元素时,调用此构造函数 + */ + public ClusterOverlay(Context context, AMap amap, int clusterSize) { + this(context, amap, null, clusterSize); + } + + /** + * 构造函数,批量添加聚合元素时,调用此构造函数 + */ + public ClusterOverlay(Context context, AMap amap, List clusterItems, int clusterSize) { + if (clusterItems != null) { + this.clusterItems = clusterItems; + } else { + this.clusterItems = new ArrayList<>(); + } + this.context = context; + this.clusters = new ArrayList<>(); + this.amap = amap; + this.clusterSize = clusterSize; + this.pxInMeters = amap.getScalePerPixel(); + this.clusterDistance = pxInMeters * clusterSize; + amap.setOnCameraChangeListener(this); + amap.setOnMarkerClickListener(this); + initThreadHandler(); + assignClusters(); + } + + /** + * 设置聚合点的点击事件 + */ + public void setOnClusterClickListener(ClusterOnClickListener clusterClickListener) { + this.clusterClickListener = clusterClickListener; + } + + /** + * 添加一个聚合点 + */ + public void addClusterItem(ClusterItem item) { + Message message = Message.obtain(); + message.what = SignClusterHandler.CALCULATE_SINGLE_CLUSTER; + message.obj = item; + signClusterHandler.sendMessage(message); + } + + /** + * 设置聚合元素的渲染样式,不设置则默认为气泡加数字形式进行渲染 + */ + public void setClusterRender(ClusterRender render) { + this.clusterRender = render; + } + + public void onDestroy() { + isCanceled = true; + signClusterHandler.removeCallbacksAndMessages(null); + markerHandler.removeCallbacksAndMessages(null); + signClusterThread.quit(); + markerHandlerThread.quit(); + for (Marker marker : addMarkers) { + marker.remove(); + } + addMarkers.clear(); + } + + //初始化Handler + private void initThreadHandler() { + markerHandlerThread.start(); + signClusterThread.start(); + markerHandler = new MarkerHandler(markerHandlerThread.getLooper()); + signClusterHandler = new SignClusterHandler(signClusterThread.getLooper()); + } + + @Override + public void onCameraChange(CameraPosition arg0) { + + } + + @Override + public void onCameraChangeFinish(CameraPosition arg0) { + pxInMeters = amap.getScalePerPixel(); + clusterDistance = pxInMeters * clusterSize; + assignClusters(); + } + + @Override + public boolean onMarkerClick(Marker marker) { + if (clusterClickListener == null) { + return true; + } + Cluster cluster = (Cluster) marker.getObject(); + if (cluster != null) { + clusterClickListener.onMarkerClicked(marker, cluster.getClusterItems()); + return true; + } + return false; + } + + /** + * 将聚合元素添加至地图上 + */ + private void addClusterToMap(List clusters) { + ArrayList removeMarkers = new ArrayList<>(addMarkers); + AlphaAnimation alphaAnimation = new AlphaAnimation(1, 0); + RemoveAnimationListener removeAnimationListener = new RemoveAnimationListener(removeMarkers); + for (Marker marker : removeMarkers) { + marker.setAnimation(alphaAnimation); + marker.setAnimationListener(removeAnimationListener); + marker.startAnimation(); + } + + for (Cluster cluster : clusters) { + addSingleClusterToMap(cluster); + } + } + + /** + * 将单个聚合元素添加至地图显示 + */ + private void addSingleClusterToMap(Cluster cluster) { + LatLng latlng = cluster.getCenterLatLng(); + MarkerOptions markerOptions = new MarkerOptions(); + markerOptions.icon(getBitmapDes(cluster.getClusterCount())).position(latlng); + Marker marker = amap.addMarker(markerOptions); + marker.setAnimation(addAnimation); + marker.setObject(cluster); + + marker.startAnimation(); + cluster.setMarker(marker); + addMarkers.add(marker); + } + + private void calculateClusters() { + isCanceled = false; + clusters.clear(); + LatLngBounds visibleBounds = amap.getProjection().getVisibleRegion().latLngBounds; + for (ClusterItem clusterItem : clusterItems) { + if (isCanceled) { + return; + } + LatLng latlng = clusterItem.getPosition(); + if (visibleBounds.contains(latlng)) { + Cluster cluster = getCluster(latlng, clusters); + if (cluster == null) { + cluster = new Cluster(latlng); + clusters.add(cluster); + } + cluster.addClusterItem(clusterItem); + } + } + + //复制一份数据,规避同步 + List tempClusters = new ArrayList<>(clusters); + Message message = Message.obtain(); + message.what = MarkerHandler.ADD_CLUSTER_LIST; + message.obj = tempClusters; + if (isCanceled) { + return; + } + markerHandler.sendMessage(message); + } + + /** + * 对点进行聚合 + */ + private void assignClusters() { + isCanceled = true; + signClusterHandler.removeMessages(SignClusterHandler.CALCULATE_CLUSTER); + signClusterHandler.sendEmptyMessage(SignClusterHandler.CALCULATE_CLUSTER); + } + + /** + * 在已有的聚合基础上,对添加的单个元素进行聚合 + */ + private void calculateSingleCluster(ClusterItem clusterItem) { + LatLngBounds visibleBounds = amap.getProjection().getVisibleRegion().latLngBounds; + LatLng latlng = clusterItem.getPosition(); + if (!visibleBounds.contains(latlng)) { + return; + } + Cluster cluster = getCluster(latlng, clusters); + if (cluster != null) { + cluster.addClusterItem(clusterItem); + Message message = Message.obtain(); + message.what = MarkerHandler.UPDATE_SINGLE_CLUSTER; + + message.obj = cluster; + markerHandler.removeMessages(MarkerHandler.UPDATE_SINGLE_CLUSTER); + markerHandler.sendMessageDelayed(message, 5); + } else { + cluster = new Cluster(latlng); + clusters.add(cluster); + cluster.addClusterItem(clusterItem); + Message message = Message.obtain(); + message.what = MarkerHandler.ADD_SINGLE_CLUSTER; + message.obj = cluster; + markerHandler.sendMessage(message); + } + } + + /** + * 根据一个点获取是否可以依附的聚合点,没有则返回null + */ + private Cluster getCluster(LatLng latLng, List clusters) { + for (Cluster cluster : clusters) { + LatLng clusterCenterPoint = cluster.getCenterLatLng(); + double distance = AMapUtils.calculateLineDistance(latLng, clusterCenterPoint); + if (distance < clusterDistance && amap.getCameraPosition().zoom < 19) { + return cluster; + } + } + return null; + } + + + /** + * 获取每个聚合点的绘制样式 + */ + private BitmapDescriptor getBitmapDes(int num) { + TextView textView = new TextView(context); + if (num > 1) { + String tile = String.valueOf(num); + textView.setText(tile); + } + textView.setGravity(Gravity.CENTER); + textView.setTextColor(Color.BLACK); + textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 15); + if (clusterRender != null && clusterRender.getDrawableByCount(num) != null) { + textView.setBackgroundDrawable(clusterRender.getDrawableByCount(num)); + } else { + textView.setBackgroundResource(R.mipmap.well_location); + } + return BitmapDescriptorFactory.fromView(textView); + } + + /** + * 更新已加入地图聚合点的样式 + */ + private void updateCluster(Cluster cluster) { + Marker marker = cluster.getMarker(); + marker.setIcon(getBitmapDes(cluster.getClusterCount())); + } + + /** + * 处理market添加,更新等操作 + */ + class MarkerHandler extends Handler { + + static final int ADD_CLUSTER_LIST = 0; + + static final int ADD_SINGLE_CLUSTER = 1; + + static final int UPDATE_SINGLE_CLUSTER = 2; + + public MarkerHandler(Looper looper) { + super(looper); + } + + public void handleMessage(Message message) { + switch (message.what) { + case ADD_CLUSTER_LIST: + List clusters = (List) message.obj; + addClusterToMap(clusters); + break; + case ADD_SINGLE_CLUSTER: + Cluster cluster = (Cluster) message.obj; + addSingleClusterToMap(cluster); + break; + case UPDATE_SINGLE_CLUSTER: + Cluster updateCluster = (Cluster) message.obj; + updateCluster(updateCluster); + break; + } + } + } + + /** + * 处理聚合点算法线程 + */ + class SignClusterHandler extends Handler { + static final int CALCULATE_CLUSTER = 0; + static final int CALCULATE_SINGLE_CLUSTER = 1; + + public SignClusterHandler(Looper looper) { + super(looper); + } + + public void handleMessage(Message message) { + switch (message.what) { + case CALCULATE_CLUSTER: + calculateClusters(); + break; + case CALCULATE_SINGLE_CLUSTER: + ClusterItem item = (ClusterItem) message.obj; + clusterItems.add(item); + calculateSingleCluster(item); + break; + } + } + } +} diff --git a/app/src/main/java/com/casic/app/smartwell/widgets/cluster/ClusterRender.java b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/ClusterRender.java new file mode 100644 index 0000000..427ff14 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/ClusterRender.java @@ -0,0 +1,10 @@ +package com.casic.app.smartwell.widgets.cluster; + +import android.graphics.drawable.Drawable; + +public interface ClusterRender { + /** + * 根据聚合点的元素数目返回渲染背景样式 + */ + Drawable getDrawableByCount(int clusterNum); +} diff --git a/app/src/main/java/com/casic/app/smartwell/widgets/cluster/RegionItem.java b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/RegionItem.java new file mode 100644 index 0000000..7b2b6c4 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/RegionItem.java @@ -0,0 +1,23 @@ +package com.casic.app.smartwell.widgets.cluster; + +import com.amap.api.maps.model.LatLng; +import com.casic.app.smartwell.model.MapWellListModel; + +public class RegionItem implements ClusterItem { + private final LatLng latLng; + private final MapWellListModel.DataModel well; + + public RegionItem(LatLng latLng, MapWellListModel.DataModel well) { + this.latLng = latLng; + this.well = well; + } + + @Override + public LatLng getPosition() { + return latLng; + } + + public MapWellListModel.DataModel getWell() { + return well; + } +} diff --git a/app/src/main/java/com/casic/app/smartwell/widgets/cluster/RemoveAnimationListener.java b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/RemoveAnimationListener.java new file mode 100644 index 0000000..c9c5e84 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/RemoveAnimationListener.java @@ -0,0 +1,30 @@ +package com.casic.app.smartwell.widgets.cluster; + +import com.amap.api.maps.model.Marker; +import com.amap.api.maps.model.animation.Animation; + +import java.util.List; + +/** + * marker渐变动画,动画结束后将Marker删除 + */ +public class RemoveAnimationListener implements Animation.AnimationListener { + private final List removeMarkers; + + public RemoveAnimationListener(List removeMarkers) { + this.removeMarkers = removeMarkers; + } + + @Override + public void onAnimationStart() { + + } + + @Override + public void onAnimationEnd() { + for (Marker marker : removeMarkers) { + marker.remove(); + } + removeMarkers.clear(); + } +} \ No newline at end of file diff --git a/app/src/main/res/anim/map_popup_hide.xml b/app/src/main/res/anim/map_popup_hide.xml new file mode 100644 index 0000000..119726b --- /dev/null +++ b/app/src/main/res/anim/map_popup_hide.xml @@ -0,0 +1,12 @@ + + + + \ No newline at end of file diff --git a/app/src/main/res/anim/map_popup_show.xml b/app/src/main/res/anim/map_popup_show.xml new file mode 100644 index 0000000..1d281ef --- /dev/null +++ b/app/src/main/res/anim/map_popup_show.xml @@ -0,0 +1,12 @@ + + + + \ No newline at end of file diff --git a/app/src/main/res/anim/popup_hide.xml b/app/src/main/res/anim/popup_hide.xml index 55c7aca..7480485 100644 --- a/app/src/main/res/anim/popup_hide.xml +++ b/app/src/main/res/anim/popup_hide.xml @@ -1,7 +1,8 @@ - + \ No newline at end of file diff --git a/app/src/main/res/anim/popup_show.xml b/app/src/main/res/anim/popup_show.xml index 1d281ef..dbe2833 100644 --- a/app/src/main/res/anim/popup_show.xml +++ b/app/src/main/res/anim/popup_show.xml @@ -1,12 +1,8 @@ \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/extensions/Int.kt b/app/src/main/java/com/casic/app/smartwell/extensions/Int.kt index de0617b..a0a5e33 100644 --- a/app/src/main/java/com/casic/app/smartwell/extensions/Int.kt +++ b/app/src/main/java/com/casic/app/smartwell/extensions/Int.kt @@ -1,9 +1,24 @@ package com.casic.app.smartwell.extensions +import android.graphics.Bitmap +import android.graphics.Canvas +import android.graphics.Paint +import android.graphics.RectF + fun Int.toLevel(): String { return if (this == 0) { "" } else { this.toString() } +} + +fun Int.drawCircle(color: Int): Bitmap? { + val bitmap = Bitmap.createBitmap(this * 2, this * 2, Bitmap.Config.ARGB_8888) + val canvas = Canvas(bitmap) + val paint = Paint() + val rectF = RectF(0f, 0f, (this * 2).toFloat(), (this * 2).toFloat()) + paint.color = color + canvas.drawArc(rectF, 0f, 360f, true, paint) + return bitmap } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt index 6b6ca3e..5e45534 100644 --- a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt +++ b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt @@ -2,17 +2,13 @@ import android.content.Context import com.casic.app.smartwell.callback.OnImageCompressListener -import com.casic.app.smartwell.model.ErrorMessageModel import com.casic.app.smartwell.utils.LocaleConstant -import com.google.gson.Gson -import com.google.gson.reflect.TypeToken +import com.google.gson.JsonParser import com.pengxh.kt.lite.extensions.createCompressImageDir import com.pengxh.kt.lite.utils.SaveKeyValues -import org.json.JSONObject import top.zibin.luban.Luban import top.zibin.luban.OnCompressListener import java.io.File -import java.util.Locale /** * String扩展方法 @@ -74,18 +70,22 @@ } } -fun String.separateResponseCode(): Int { +fun String.getResponseCode(): Int { if (this.isBlank()) { return 404 } - return JSONObject(this).getInt("code") + val element = JsonParser.parseString(this) + val jsonObject = element.asJsonObject + return jsonObject.get("code").asInt } -fun String.toErrorMessage(): String { - val errorModel = Gson().fromJson( - this, object : TypeToken() {}.type - ) - return errorModel.message.toString() +fun String.getResponseMessage(): String { + if (this.isBlank()) { + return "" + } + val element = JsonParser.parseString(this) + val jsonObject = element.asJsonObject + return jsonObject.get("message").asString } fun String.compressImage(context: Context, listener: OnImageCompressListener) { @@ -93,9 +93,6 @@ .load(this) .ignoreBy(100) .setTargetDir(context.createCompressImageDir().toString()) - .filter { - !(it.isBlank() || it.lowercase(Locale.getDefault()).endsWith(".gif")) - } .setCompressListener(object : OnCompressListener { override fun onStart() { 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 96df110..cd25fca 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 @@ -1,26 +1,25 @@ package com.casic.app.smartwell.fragment -import android.graphics.Point +import android.graphics.Color +import android.graphics.drawable.BitmapDrawable +import android.graphics.drawable.Drawable 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 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.LatLngBounds import com.amap.api.maps.model.Marker -import com.amap.api.maps.model.MarkerOptions import com.casic.app.smartwell.R import com.casic.app.smartwell.databinding.FragmentHomeBinding +import com.casic.app.smartwell.extensions.drawCircle import com.casic.app.smartwell.extensions.initImmersionBar -import com.casic.app.smartwell.extensions.valueToType import com.casic.app.smartwell.model.MapWellListModel import com.casic.app.smartwell.utils.LocaleConstant import com.casic.app.smartwell.utils.RouteOnMap @@ -31,9 +30,16 @@ import com.casic.app.smartwell.view.WellOperationActivity import com.casic.app.smartwell.vm.OrderViewModel import com.casic.app.smartwell.vm.WellViewModel +import com.casic.app.smartwell.widgets.MapWellPopup +import com.casic.app.smartwell.widgets.cluster.ClusterItem +import com.casic.app.smartwell.widgets.cluster.ClusterOnClickListener +import com.casic.app.smartwell.widgets.cluster.ClusterOverlay +import com.casic.app.smartwell.widgets.cluster.RegionItem 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.convertDrawable +import com.pengxh.kt.lite.extensions.dp2px import com.pengxh.kt.lite.extensions.navigatePageTo import com.pengxh.kt.lite.extensions.show import com.pengxh.kt.lite.utils.LoadingDialogHub @@ -43,35 +49,23 @@ /** * 地图点位带聚合效果 * */ -class HomePageHaveClusterFragment : KotlinBaseFragment(), AMap.OnMapLoadedListener, - AMap.OnCameraChangeListener, AMap.OnMarkerClickListener, AMap.InfoWindowAdapter, - AMap.OnInfoWindowClickListener { +class HomePageHaveClusterFragment : KotlinBaseFragment(), + AMap.OnCameraChangeListener { private val kTag = "HaveClusterFragment" private val easyPopupWindow by lazy { EasyPopupWindow(requireContext()) } - private lateinit var wellViewModel: WellViewModel - private lateinit var orderViewModel: OrderViewModel - private lateinit var aMap: AMap - - /** - * 所有的marker - */ - private var allMarkerOptions: MutableList = ArrayList() - - /** - * 视野内的marker - */ - private var markerOptionsInView: MutableList = ArrayList() - - /** - * 自定义Marker弹出框 - * */ - private lateinit var v: View + private val regionRadius by lazy { LocaleConstant.RADIUS_SIZE.dp2px(requireContext()) } + private val infoPopup by lazy { MapWellPopup(requireContext()) } /** * 所有窨井列表信息集合 * */ - private var wellModels: MutableList = ArrayList() + private val wellModels = ArrayList() + private val backDrawables = HashMap() + private lateinit var wellViewModel: WellViewModel + private lateinit var orderViewModel: OrderViewModel + private lateinit var aMap: AMap + private var clusterOverlay: ClusterOverlay? = null override fun initViewBinding( inflater: LayoutInflater, @@ -106,6 +100,9 @@ } }) + //地图初始化 + initMap(savedInstanceState) + //初始化vm wellViewModel = ViewModelProvider(this)[WellViewModel::class.java] orderViewModel = ViewModelProvider(this)[OrderViewModel::class.java] @@ -120,25 +117,19 @@ val latitudeList: MutableList = ArrayList() val longitudeList: MutableList = ArrayList() it.data?.forEach { well -> - val lat = well.latGaode.toString() - val lng = well.lngGaode.toString() + val lat = well.latGaode + val lng = well.lngGaode if (lat.isNotBlank() && lng.isNotBlank()) { //返回true代表当前位置在大陆、港澳地区,反之不在 val latitude = lat.toDouble() val longitude = lng.toDouble() if (CoordinateConverter.isAMapDataAvailable(latitude, longitude)) { - //缓存所有设备详情,点击Marker时候需要 + //缓存所有井 wellModels.add(well) + //分别缓存经、纬度 latitudeList.add(latitude) longitudeList.add(longitude) - //将所有设备信息转化缓存为Marker点 - allMarkerOptions.add( - MarkerOptions() - .position(LatLng(latitude, longitude)) - .title(well.wellTypeName) - .snippet(well.wellName) - ) } } } @@ -160,12 +151,12 @@ val cameraPosition = CameraPosition(centerLatLng, 16f, 0f, 0f) val cameraUpdate = CameraUpdateFactory.newCameraPosition(cameraPosition) aMap.animateCamera(cameraUpdate, 1500, null) + + //显示点数据 + displayWellOnMap() } } - //地图初始化 - initMap(savedInstanceState) - //获取窨井监控数据 wellViewModel.countResultModel.observe(this) { binding.deployedWellView.text = it["bfWell"] @@ -220,17 +211,10 @@ uiSettings.isCompassEnabled = true uiSettings.zoomPosition = AMapOptions.ZOOM_POSITION_RIGHT_CENTER uiSettings.isTiltGesturesEnabled = false//不许地图随手势倾斜角度 + uiSettings.isRotateGesturesEnabled = false//不允许地图随手势改变方位 - // 地图加载成功监听 - aMap.addOnMapLoadedListener(this) // 地图缩放监听 aMap.addOnCameraChangeListener(this) - // marker 点击事件监听 - aMap.addOnMarkerClickListener(this) - // 点击marker弹出自定义popup - aMap.setInfoWindowAdapter(this) - //信息窗点击事件 - aMap.addOnInfoWindowClickListener(this) } override fun initEvent() { @@ -259,9 +243,111 @@ } - override fun onMapLoaded() { - //地图加载成功之后显示聚合点数据 - initClustersMarkers() + private fun displayWellOnMap() { + clusterOverlay?.onDestroy() + val clusterItems = ArrayList() + + wellModels.forEach { + val latitude = it.latGaode.toDouble() + val longitude = it.lngGaode.toDouble() + + val latLng = LatLng(latitude, longitude, false) + val regionItem = RegionItem(latLng, it) + clusterItems.add(regionItem) + } + + clusterOverlay = ClusterOverlay(requireContext(), aMap, clusterItems, regionRadius) + clusterOverlay?.setClusterRender { clusterNum -> + //聚合圆半径 + val radius = 100.dp2px(requireContext()) + if (clusterNum == 0) { + var bitmapDrawable = backDrawables[0] + if (bitmapDrawable == null) { + bitmapDrawable = BitmapDrawable( + null, radius.drawCircle(Color.argb(159, 100, 149, 237)) + ) + backDrawables[0] = bitmapDrawable + } + bitmapDrawable + } + if (clusterNum == 1) { + var bitmapDrawable = backDrawables[1] + if (bitmapDrawable == null) { + bitmapDrawable = R.mipmap.well_location.convertDrawable(requireContext())!! + backDrawables[1] = bitmapDrawable + } + bitmapDrawable + } else if (clusterNum < 5) { + var bitmapDrawable = backDrawables[2] + if (bitmapDrawable == null) { + bitmapDrawable = BitmapDrawable( + null, radius.drawCircle(Color.argb(159, 100, 149, 237)) + ) + backDrawables[2] = bitmapDrawable + } + bitmapDrawable + } else if (clusterNum < 10) { + var bitmapDrawable = backDrawables[3] + if (bitmapDrawable == null) { + bitmapDrawable = BitmapDrawable( + null, radius.drawCircle(Color.argb(199, 30, 144, 255)) + ) + backDrawables[3] = bitmapDrawable + } + bitmapDrawable + } else { + var bitmapDrawable = backDrawables[4] + if (bitmapDrawable == null) { + bitmapDrawable = BitmapDrawable( + null, radius.drawCircle(Color.argb(235, 65, 105, 225)) + ) + backDrawables[4] = bitmapDrawable + } + bitmapDrawable + } + } + + clusterOverlay?.setOnClusterClickListener(object : ClusterOnClickListener { + override fun onMarkerClicked(marker: Marker?, items: List) { + if (items.size > 1) { + "请缩放地图比例在查看数据".show(requireContext()) + return + } + + var item: RegionItem? = null + val builder = LatLngBounds.Builder() + for (clusterItem in items) { + builder.include(clusterItem.position) + item = clusterItem as RegionItem + } + + item?.apply { + showWellPopup(well) + } + } + }) + } + + private fun showWellPopup(well: MapWellListModel.DataModel) { + infoPopup.set(well, object : MapWellPopup.OnPopupWindowClickListener { + override fun onPopupClicked(lat: Double, lng: Double) { + AlertControlDialog.Builder().setContext(requireContext()).setTitle("操作提示") + .setMessage("确定要前往吗").setNegativeButton("取消").setPositiveButton("确定") + .setOnDialogButtonClickListener(object : + AlertControlDialog.OnDialogButtonClickListener { + override fun onConfirmClick() { + RouteOnMap.startNavigation( + requireContext(), "", LatLng(lat, lng) + ) + } + + override fun onCancelClick() { + + } + }).build().show() + } + }) + infoPopup.showAsDropDown(binding.rightOptionView) } override fun onCameraChange(p0: CameraPosition?) { @@ -282,103 +368,10 @@ } } - //获取视野内的marker 根据聚合算法合成自定义的marker 显示视野内的marker override fun onCameraChangeFinish(p0: CameraPosition?) { //地图缩放之后显示聚合点数据 LoadingDialogHub.dismiss() httpCountDownTimer.cancel() - initClustersMarkers() - } - - private fun initClustersMarkers() { - 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 { - v = LayoutInflater.from(requireContext()).inflate(R.layout.popup_map_info, null) - - //显示闸井信息 - marker?.showInfoWindow() - return true - } - - override fun getInfoWindow(marker: Marker?): View { - //反射得到popup里面的控件对象 - val wellNameView = v.findViewById(R.id.wellNameView) - val wellCodeView = v.findViewById(R.id.wellCodeView) - val wellTypeView = v.findViewById(R.id.wellTypeView) - val wellStateView = v.findViewById(R.id.wellStateView) - val deepView = v.findViewById(R.id.deepView) - val locationView = v.findViewById(R.id.locationView) - - //绑定数据 - val clickedLatLng = marker?.position!! - wellModels.forEach { well -> - if (clickedLatLng.latitude == well.latGaode!!.toDouble() - && clickedLatLng.longitude == well.lngGaode!!.toDouble() - ) { - wellNameView.text = String.format("点位名称: ${well.wellName}") - wellCodeView.text = String.format("点位编号: ${well.wellCode}") - wellTypeView.text = String.format("点位类型: ${well.wellType.valueToType()}") - val bfztName = if (well.bfzt == "1") { - "已布防" - } else { - "已撤防" - } - wellStateView.text = String.format("布/撤防状态: $bfztName") - deepView.text = String.format("点位深度: ${well.deep}m") - locationView.text = String.format("详细位置: ${well.position}") - } - } - return v - } - - /** - * 此方法不能修改整个 InfoWindow 的背景和边框,无论自定义的样式是什么样,SDK 都会在最外层添加一个默认的边框 - * */ - override fun getInfoContents(p0: Marker?): View? = null - - override fun onInfoWindowClick(p0: Marker?) { - p0?.apply { - AlertControlDialog.Builder() - .setContext(requireContext()) - .setTitle("操作提示") - .setMessage("确定要前往吗") - .setNegativeButton("取消") - .setPositiveButton("确定") - .setOnDialogButtonClickListener(object : - AlertControlDialog.OnDialogButtonClickListener { - override fun onConfirmClick() { - val lat = position.latitude.toString() - val lng = position.longitude.toString() - if (lat.isBlank() || lng.isBlank()) { - "点位经纬度异常,无法开启导航".show(requireContext()) - return - } - RouteOnMap.startNavigation( - requireContext(), snippet, LatLng(lat.toDouble(), lng.toDouble()) - ) - } - - override fun onCancelClick() { - - } - }).build().show() - } } /***以下是地图生命周期管理************************************************************************/ 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 a54d213..bfa7a57 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 @@ -44,8 +44,8 @@ * 地图点位不带聚合效果 * */ class HomePageNoClusterFragment : KotlinBaseFragment(), - AMap.OnMapLoadedListener, AMap.OnCameraChangeListener, AMap.OnMarkerClickListener, - AMap.InfoWindowAdapter, AMap.OnInfoWindowClickListener { + AMap.OnCameraChangeListener, AMap.OnMarkerClickListener, AMap.InfoWindowAdapter, + AMap.OnInfoWindowClickListener { private val kTag = "NoClusterFragment" private val easyPopupWindow by lazy { EasyPopupWindow(requireContext()) } @@ -109,6 +109,9 @@ wellViewModel = ViewModelProvider(this)[WellViewModel::class.java] orderViewModel = ViewModelProvider(this)[OrderViewModel::class.java] + //地图初始化 + initMap(savedInstanceState) + //获取所有窨井数据 httpCountDownTimer.start() LoadingDialogHub.show(requireActivity(), "数据加载中,请稍后...") @@ -157,12 +160,12 @@ val cameraPosition = CameraPosition(centerLatLng, 16f, 0f, 0f) val cameraUpdate = CameraUpdateFactory.newCameraPosition(cameraPosition) aMap.animateCamera(cameraUpdate, 1500, null) + + //显示点数据 + displayWellOnMap() } } - //地图初始化 - initMap(savedInstanceState) - //获取窨井监控数据 wellViewModel.countResultModel.observe(this) { binding.deployedWellView.text = it["bfWell"] @@ -214,9 +217,8 @@ uiSettings.isCompassEnabled = true uiSettings.zoomPosition = AMapOptions.ZOOM_POSITION_RIGHT_CENTER uiSettings.isTiltGesturesEnabled = false//不许地图随手势倾斜角度 + uiSettings.isRotateGesturesEnabled = false//不允许地图随手势改变方位 - // 地图加载成功监听 - aMap.addOnMapLoadedListener(this) // 地图缩放监听 aMap.addOnCameraChangeListener(this) // marker 点击事件监听 @@ -253,11 +255,6 @@ } - override fun onMapLoaded() { - //地图加载成功之后显示聚合点数据 - initClustersMarkers() - } - override fun onCameraChange(p0: CameraPosition?) { } @@ -281,10 +278,9 @@ //地图缩放之后显示聚合点数据 LoadingDialogHub.dismiss() httpCountDownTimer.cancel() - initClustersMarkers() } - private fun initClustersMarkers() { + private fun displayWellOnMap() { val proj = aMap.projection val dm = resources.displayMetrics var screenLocation: Point diff --git a/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.java b/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.java deleted file mode 100644 index d8b18ef..0000000 --- a/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.java +++ /dev/null @@ -1,50 +0,0 @@ -package com.casic.app.smartwell.model; - -public class ErrorMessageModel { - - private int code; - private String data; - private String exceptionClazz; - private String message; - private boolean success; - - public int getCode() { - return code; - } - - public void setCode(int code) { - this.code = code; - } - - public String getData() { - return data; - } - - public void setData(String data) { - this.data = data; - } - - public String getExceptionClazz() { - return exceptionClazz; - } - - public void setExceptionClazz(String exceptionClazz) { - this.exceptionClazz = exceptionClazz; - } - - public String getMessage() { - return message; - } - - public void setMessage(String message) { - this.message = message; - } - - public boolean isSuccess() { - return success; - } - - public void setSuccess(boolean success) { - this.success = success; - } -} \ No newline at end of file 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 new file mode 100644 index 0000000..215ac0c --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/PipelineModel.java @@ -0,0 +1,328 @@ +package com.casic.app.smartwell.model; + +import java.util.List; + +public class PipelineModel { + + private Integer code; + private DataModel data; + private String message; + private Boolean success; + + public Integer getCode() { + return code; + } + + public void setCode(Integer code) { + this.code = code; + } + + public DataModel getData() { + return data; + } + + public void setData(DataModel data) { + this.data = data; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + public Boolean getSuccess() { + return success; + } + + public void setSuccess(Boolean success) { + this.success = success; + } + + public static class DataModel { + private List rows; + private Integer total; + + public List getRows() { + return rows; + } + + public void setRows(List rows) { + this.rows = rows; + } + + public Integer getTotal() { + return total; + } + + public void setTotal(Integer total) { + this.total = total; + } + + 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 getBuryMode() { + return buryMode; + } + + public void setBuryMode(String buryMode) { + this.buryMode = buryMode; + } + + public String getConstructEra() { + return constructEra; + } + + public void setConstructEra(String constructEra) { + this.constructEra = constructEra; + } + + 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; + } + } + } +} 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 06d3d2b..4f38a2c 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 = 100 //相距多少米才聚合,单位:米 + const val RADIUS_SIZE = 80 //相距多少米才聚合,单位:米 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:11308" + // 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 0d5f3fa..991e1db 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 @@ -312,4 +312,14 @@ @Header("token") token: String, @Field("clientid") deviceCode: String ): String + + /** + * 管线位置数据 + */ + @GET("/pipeline/listPage") + suspend fun getPipeline( + @Header("token") token: String, + @Query("limit") limit: Int, + @Query("offset") offset: Int + ): String } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt index 1a0ce22..4050067 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt @@ -294,4 +294,11 @@ suspend fun registerPush(clientId: String): String { return api.registerPush(AuthenticationHelper.token!!, clientId) } + + /** + * 管线位置数据 + */ + suspend fun getPipeline(): String { + return api.getPipeline(AuthenticationHelper.token!!, 2000, 1) + } } \ No newline at end of file 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 9270fa1..4ca5a5e 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.HomePageNoClusterFragment +import com.casic.app.smartwell.fragment.HomePageHaveClusterFragment 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/vm/AlarmViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/AlarmViewModel.kt index 9cff08c..e7acc17 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/AlarmViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/AlarmViewModel.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.AlarmContentModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager import com.google.gson.Gson @@ -16,7 +16,7 @@ fun getAlarmContentType(alarmType: String) = launch({ val response = RetrofitServiceManager.getAlarmContentType(alarmType) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { listModel.value = gson.fromJson( response, object : TypeToken() {}.type diff --git a/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt index 5e5b163..895dedd 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.PublicKeyModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager import com.google.gson.Gson @@ -18,7 +18,7 @@ fun getPublicKey() = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.authenticate() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { keyModel.value = gson.fromJson( response, object : TypeToken() {}.type diff --git a/app/src/main/java/com/casic/app/smartwell/vm/DeviceViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/DeviceViewModel.kt index db5ccf6..899a962 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/DeviceViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/DeviceViewModel.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.DeviceDetailModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager import com.google.gson.Gson @@ -16,7 +16,7 @@ fun getDeviceDetail(deviceCode: String) = launch({ val response = RetrofitServiceManager.getDeviceDetail(deviceCode) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { detailModel.value = gson.fromJson( response, object : TypeToken() {}.type diff --git a/app/src/main/java/com/casic/app/smartwell/vm/LoginViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/LoginViewModel.kt index cd8b8a9..a417398 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/LoginViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/LoginViewModel.kt @@ -2,7 +2,7 @@ import androidx.lifecycle.MutableLiveData import com.casic.app.smartwell.base.BaseApplication -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.CommonResultModel import com.casic.app.smartwell.model.LoginResultModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -21,7 +21,7 @@ fun enter(account: String, secretKey: String) = launch({ val response = RetrofitServiceManager.login(account, secretKey) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success enterResultModel.value = gson.fromJson( @@ -38,7 +38,7 @@ fun out() = launch({ val response = RetrofitServiceManager.loginOut() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { outResultModel.value = gson.fromJson( response, object : TypeToken() {}.type diff --git a/app/src/main/java/com/casic/app/smartwell/vm/OperationViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/OperationViewModel.kt index 8943ed3..37e115f 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/OperationViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/OperationViewModel.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.vm import com.casic.app.smartwell.base.BaseApplication -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager import com.pengxh.kt.lite.base.BaseViewModel import com.pengxh.kt.lite.extensions.launch @@ -16,7 +16,7 @@ fun acceptWorkOrder(id: String) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.acceptWorkOrder(id) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success "接单成功".show(BaseApplication.get()) @@ -35,7 +35,7 @@ loadState.value = LoadState.Loading val response = RetrofitServiceManager.confirmWorkOrder(id, firstState, firstStatePhotos, needHandle) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success "工单确认成功".show(BaseApplication.get()) @@ -50,7 +50,7 @@ fun transferWorkOrder(id: String, userId: String) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.transferWorkOrder(id, userId) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success "转单成功".show(BaseApplication.get()) @@ -65,7 +65,7 @@ fun completeWorkOrder(id: String, handleMessage: String, handlePhotos: String) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.completeWorkOrder(id, handleMessage, handlePhotos) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success "工单处理成功".show(BaseApplication.get()) diff --git a/app/src/main/java/com/casic/app/smartwell/vm/OrderViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/OrderViewModel.kt index 4cb26b7..d2fad86 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/OrderViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/OrderViewModel.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.OrderDetailModel import com.casic.app.smartwell.model.OrderListModel import com.casic.app.smartwell.model.OrderStatusModel @@ -37,7 +37,7 @@ val response = RetrofitServiceManager.getSearchResult( keywords, alarmContent, alarmLevel, jobStatus, deptId, beginTime, endTime, offset ) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success searchResult.value = gson.fromJson( @@ -53,7 +53,7 @@ fun getWorkOrderListByState(jobStatus: String, page: Int) = launch({ val response = RetrofitServiceManager.getWorkOrderList(jobStatus, page) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { orderList.value = gson.fromJson( response, object : TypeToken() {}.type @@ -65,7 +65,7 @@ fun getNotAcceptOderList(page: Int) = launch({ val response = RetrofitServiceManager.getNotAcceptOderList(page) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { orderList.value = gson.fromJson( response, object : TypeToken() {}.type @@ -77,7 +77,7 @@ fun getNotHandleOderList(page: Int) = launch({ val response = RetrofitServiceManager.getNotHandleOderList(page) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { orderList.value = gson.fromJson( response, object : TypeToken() {}.type @@ -89,7 +89,7 @@ fun countWorkOrderByState() = launch({ val response = RetrofitServiceManager.countWorkOrderByState() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { val map = HashMap(4) @@ -107,7 +107,7 @@ fun getOrderStatus() = launch({ val response = RetrofitServiceManager.getOrderStatus() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { orderStatusModel.value = gson.fromJson( response, object : TypeToken() {}.type @@ -120,7 +120,7 @@ fun getWorkOrderDetail(id: String) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.getWorkOrderDetail(id) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success detailModel.value = gson.fromJson( diff --git a/app/src/main/java/com/casic/app/smartwell/vm/PipelineViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/PipelineViewModel.kt new file mode 100644 index 0000000..60c1e2f --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/vm/PipelineViewModel.kt @@ -0,0 +1,28 @@ +package com.casic.app.smartwell.vm + +import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.extensions.getResponseCode +import com.casic.app.smartwell.model.PipelineModel +import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken +import com.pengxh.kt.lite.base.BaseViewModel +import com.pengxh.kt.lite.extensions.launch + +class PipelineViewModel : BaseViewModel() { + + private val gson by lazy { Gson() } + val lineResult = MutableLiveData() + + fun getPipeline() = launch({ + val response = RetrofitServiceManager.getPipeline() + val responseCode = response.getResponseCode() + if (responseCode == 200) { + lineResult.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } + }, { + it.printStackTrace() + }) +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/PushViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/PushViewModel.kt index 9279815..12fd610 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/PushViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/PushViewModel.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.CommonResultModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager import com.google.gson.Gson @@ -16,7 +16,7 @@ fun registerPush(clientId: String) = launch({ val response = RetrofitServiceManager.registerPush(clientId) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { registerResultModel.value = gson.fromJson( response, object : TypeToken() {}.type diff --git a/app/src/main/java/com/casic/app/smartwell/vm/UploadImageViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/UploadImageViewModel.kt index 8d6744e..9707eeb 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/UploadImageViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/UploadImageViewModel.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.CommonResultModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager import com.google.gson.Gson @@ -19,7 +19,7 @@ fun uploadImage(image: File) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.uploadImage(image) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success resultModel.value = gson.fromJson( diff --git a/app/src/main/java/com/casic/app/smartwell/vm/UserViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/UserViewModel.kt index 31a4d4c..070c35a 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/UserViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/UserViewModel.kt @@ -2,7 +2,7 @@ import androidx.lifecycle.MutableLiveData import com.casic.app.smartwell.base.BaseApplication -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.SubordinateModel import com.casic.app.smartwell.model.UserDetailModel import com.casic.app.smartwell.model.VersionResultModel @@ -25,7 +25,7 @@ fun getUserDetail() = launch({ val response = RetrofitServiceManager.getUserDetail() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { val userDetail = gson.fromJson( response, object : TypeToken() {}.type @@ -48,7 +48,7 @@ * */ fun getSubordinate(hasMine: String?, deptId: String?, roleTips: String?) = launch({ val response = RetrofitServiceManager.getSubordinate(hasMine, deptId, roleTips) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { subordinateModel.value = gson.fromJson( response, object : TypeToken() {}.type @@ -61,7 +61,7 @@ fun changePassword(oldPwd: String, newPwd: String) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.changePassword(oldPwd, newPwd) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success "修改成功,请重新登录".show(BaseApplication.get()) @@ -76,7 +76,7 @@ fun updateVersion() = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.updateVersion() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success versionResultModel.value = gson.fromJson( diff --git a/app/src/main/java/com/casic/app/smartwell/vm/WellViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/WellViewModel.kt index 3d41e9b..9e42e36 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/WellViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/WellViewModel.kt @@ -2,8 +2,7 @@ import androidx.lifecycle.MutableLiveData import com.casic.app.smartwell.base.BaseApplication -import com.casic.app.smartwell.extensions.separateResponseCode -import com.casic.app.smartwell.extensions.toErrorMessage +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.AuthorDeptModel import com.casic.app.smartwell.model.CommonResultModel import com.casic.app.smartwell.model.MapWellListModel @@ -32,7 +31,7 @@ fun countWellByState() = launch({ val response = RetrofitServiceManager.countWellByState() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { val map = HashMap(3) @@ -57,7 +56,7 @@ fun getWellType() = launch({ val response = RetrofitServiceManager.getWellType() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { wellTypeModel.value = gson.fromJson( response, object : TypeToken() {}.type @@ -70,7 +69,7 @@ fun getWellDetail(id: String) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.getWellDetail(id) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success wellDetailModel.value = gson.fromJson( @@ -87,7 +86,7 @@ fun getOperationResult(id: String, state: String) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.getOperationResult(id, state) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success "操作成功".show(BaseApplication.get()) @@ -105,7 +104,7 @@ fun getMonitorResult(id: String) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.getMonitorResult(id) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success monitorModel.value = gson.fromJson( @@ -125,7 +124,7 @@ val response = RetrofitServiceManager.getWellListByPage( keywords, wellType, deptid, bfzt, page ) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { listModel.value = gson.fromJson( response, object : TypeToken() {}.type @@ -137,13 +136,11 @@ fun getWellList() = launch({ val response = RetrofitServiceManager.getWellList() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { totalWellModel.value = gson.fromJson( response, object : TypeToken() {}.type ) - } else { - response.toErrorMessage().show(BaseApplication.get()) } }, { it.printStackTrace() diff --git a/app/src/main/java/com/casic/app/smartwell/widgets/GaoDeClusterMarkerView.kt b/app/src/main/java/com/casic/app/smartwell/widgets/GaoDeClusterMarkerView.kt deleted file mode 100644 index 1f375df..0000000 --- a/app/src/main/java/com/casic/app/smartwell/widgets/GaoDeClusterMarkerView.kt +++ /dev/null @@ -1,100 +0,0 @@ -package com.casic.app.smartwell.widgets - -import android.content.Context -import android.graphics.Bitmap -import android.graphics.Point -import android.view.Gravity -import android.view.LayoutInflater -import android.view.View -import android.widget.TextView -import com.amap.api.maps.Projection -import com.amap.api.maps.model.BitmapDescriptorFactory -import com.amap.api.maps.model.LatLng -import com.amap.api.maps.model.LatLngBounds -import com.amap.api.maps.model.MarkerOptions -import com.casic.app.smartwell.R -import com.pengxh.kt.lite.extensions.toBitmap -import java.util.* - -class GaoDeClusterMarkerView( - private val context: Context, firstMarkers: MarkerOptions, projection: Projection, gridSize: Int -) { - //当前可观区域里的 聚合过之后的集合 - private val includeMarkers: ArrayList - - // 创建区域 - val bounds: LatLngBounds - var options: MarkerOptions = MarkerOptions() - - init { - val screenLocation = projection.toScreenLocation(firstMarkers.position) - //范围类 - val southwestPoint = Point(screenLocation.x - gridSize, screenLocation.y + gridSize) - //范围类 - val northeastPoint = Point(screenLocation.x + gridSize, screenLocation.y - gridSize) - bounds = LatLngBounds( - projection.fromScreenLocation(southwestPoint), - projection.fromScreenLocation(northeastPoint) - ) - //设置初始化marker属性 - options.anchor(0.5f, 1.3f) - .title(firstMarkers.title) - .position(firstMarkers.position) - .icon(firstMarkers.icon) - .snippet(firstMarkers.snippet) - .draggable(false) - includeMarkers = ArrayList() - includeMarkers.add(firstMarkers) - } - - /** - * 添加marker - */ - fun addMarker(markerOptions: MarkerOptions) { - includeMarkers.add(markerOptions) // 添加到列表中 - } - - /** - * 设置聚合点的中心位置以及图标 - */ - fun setPositionAndIcon() { - val size = includeMarkers.size - var lat = 0.0 - var lng = 0.0 - // 一个的时候 - if (size == 1) { //设置marker单个属性 - // 设置marker位置 - options.position( - LatLng( - includeMarkers[0].position.latitude, includeMarkers[0].position.longitude - ) - ) - } else { // 聚合的时候 - //设置marker聚合属性 - for (op in includeMarkers) { - lat += op.position.latitude - lng += op.position.longitude - } - // 设置marker的位置为中心位置为聚集点的平均位置 - options.position(LatLng(lat / size, lng / size)) - } - options.icon(BitmapDescriptorFactory.fromBitmap(getBitmap(size))) - } - - /** - * marker视图 - */ - private fun getBitmap(num: Int): Bitmap? { - val view = LayoutInflater.from(context).inflate(R.layout.marker_gaode, null) - val wellCountView = view.findViewById(R.id.wellCountView) - return if (num > 1) { - wellCountView.visibility = View.VISIBLE - wellCountView.text = String.format("${num}个") - wellCountView.gravity = Gravity.CENTER - view.toBitmap() - } else { - wellCountView.visibility = View.GONE - BitmapDescriptorFactory.fromResource(R.mipmap.well_location).bitmap - } - } -} \ No newline at end of file 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 new file mode 100644 index 0000000..ec455dd --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/widgets/MapWellPopup.kt @@ -0,0 +1,58 @@ +package com.casic.app.smartwell.widgets + +import android.content.Context +import android.view.LayoutInflater +import android.view.ViewGroup +import android.widget.LinearLayout +import android.widget.PopupWindow +import android.widget.TextView +import com.casic.app.smartwell.R +import com.casic.app.smartwell.extensions.valueToType +import com.casic.app.smartwell.model.MapWellListModel + +class MapWellPopup constructor(context: Context) : PopupWindow() { + + init { + width = ViewGroup.LayoutParams.MATCH_PARENT + height = ViewGroup.LayoutParams.WRAP_CONTENT + isOutsideTouchable = true + isFocusable = true + animationStyle = R.style.MapPopupAnimation + setBackgroundDrawable(null) + contentView = LayoutInflater.from(context).inflate( + R.layout.popup_map_info, null, false + ) + } + + fun set(well: MapWellListModel.DataModel, windowClickListener: OnPopupWindowClickListener) { + //反射得到popup里面的控件对象 + val rootView = contentView.findViewById(R.id.rootView) + val wellNameView = contentView.findViewById(R.id.wellNameView) + val wellCodeView = contentView.findViewById(R.id.wellCodeView) + val wellTypeView = contentView.findViewById(R.id.wellTypeView) + val wellStateView = contentView.findViewById(R.id.wellStateView) + val deepView = contentView.findViewById(R.id.deepView) + val locationView = contentView.findViewById(R.id.locationView) + + //绑定数据 + wellNameView.text = String.format("点位名称: ${well.wellName}") + wellCodeView.text = String.format("点位编号: ${well.wellCode}") + wellTypeView.text = String.format("点位类型: ${well.wellType.valueToType()}") + val bfztName = if (well.bfzt == "1") { + "已布防" + } else { + "已撤防" + } + wellStateView.text = String.format("布/撤防状态: $bfztName") + deepView.text = String.format("点位深度: ${well.deep}m") + locationView.text = String.format("详细位置: ${well.position}") + + rootView.setOnClickListener { + windowClickListener.onPopupClicked(well.latGaode.toDouble(), well.lngGaode.toDouble()) + } + } + + interface OnPopupWindowClickListener { + fun onPopupClicked(lat: Double, lng: Double) + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/widgets/cluster/Cluster.java b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/Cluster.java new file mode 100644 index 0000000..9455ccd --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/Cluster.java @@ -0,0 +1,43 @@ +package com.casic.app.smartwell.widgets.cluster; + +import com.amap.api.maps.model.LatLng; +import com.amap.api.maps.model.Marker; + +import java.util.ArrayList; +import java.util.List; + +public class Cluster { + private final LatLng latLng; + private final List clusterItems; + private Marker marker; + + + public Cluster(LatLng latLng) { + this.latLng = latLng; + clusterItems = new ArrayList<>(); + } + + public void addClusterItem(ClusterItem clusterItem) { + clusterItems.add(clusterItem); + } + + public int getClusterCount() { + return clusterItems.size(); + } + + public LatLng getCenterLatLng() { + return latLng; + } + + public void setMarker(Marker marker) { + this.marker = marker; + } + + public Marker getMarker() { + return marker; + } + + public List getClusterItems() { + return clusterItems; + } +} diff --git a/app/src/main/java/com/casic/app/smartwell/widgets/cluster/ClusterItem.java b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/ClusterItem.java new file mode 100644 index 0000000..f5d9a9d --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/ClusterItem.java @@ -0,0 +1,10 @@ +package com.casic.app.smartwell.widgets.cluster; + +import com.amap.api.maps.model.LatLng; + +public interface ClusterItem { + /** + * 返回聚合元素的地理位置 + */ + LatLng getPosition(); +} diff --git a/app/src/main/java/com/casic/app/smartwell/widgets/cluster/ClusterOnClickListener.java b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/ClusterOnClickListener.java new file mode 100644 index 0000000..0efa1f1 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/ClusterOnClickListener.java @@ -0,0 +1,15 @@ +package com.casic.app.smartwell.widgets.cluster; + +import com.amap.api.maps.model.Marker; + +import java.util.List; + +public interface ClusterOnClickListener { + /** + * 点击聚合点的回调处理函数 + * + * @param marker 点击的聚合点 + * @param items 聚合点所包含的元素 + */ + void onMarkerClicked(Marker marker, List items); +} 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 new file mode 100644 index 0000000..40df562 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/ClusterOverlay.java @@ -0,0 +1,349 @@ +package com.casic.app.smartwell.widgets.cluster; + +import android.content.Context; +import android.graphics.Color; +import android.os.Handler; +import android.os.HandlerThread; +import android.os.Looper; +import android.os.Message; +import android.util.TypedValue; +import android.view.Gravity; +import android.widget.TextView; + +import com.amap.api.maps.AMap; +import com.amap.api.maps.AMapUtils; +import com.amap.api.maps.model.BitmapDescriptor; +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.LatLngBounds; +import com.amap.api.maps.model.Marker; +import com.amap.api.maps.model.MarkerOptions; +import com.amap.api.maps.model.animation.AlphaAnimation; +import com.casic.app.smartwell.R; + +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.CopyOnWriteArrayList; + +/** + * 整体设计采用了两个线程,一个线程用于计算组织聚合数据,一个线程负责处理Marker相关操作 + */ +public class ClusterOverlay implements AMap.OnCameraChangeListener, AMap.OnMarkerClickListener { + private final AMap amap; + private final Context context; + private final List clusterItems; + private final List clusters; + private final int clusterSize; + private ClusterOnClickListener clusterClickListener; + private ClusterRender clusterRender; + private final CopyOnWriteArrayList addMarkers = new CopyOnWriteArrayList<>(); + private double clusterDistance; + private final HandlerThread markerHandlerThread = new HandlerThread("addMarker"); + private final HandlerThread signClusterThread = new HandlerThread("calculateCluster"); + private Handler markerHandler; + private Handler signClusterHandler; + private float pxInMeters; + private boolean isCanceled = false; + private final AlphaAnimation addAnimation = new AlphaAnimation(0, 1); + + /** + * 构造函数,批量添加聚合元素时,调用此构造函数 + */ + public ClusterOverlay(Context context, AMap amap, int clusterSize) { + this(context, amap, null, clusterSize); + } + + /** + * 构造函数,批量添加聚合元素时,调用此构造函数 + */ + public ClusterOverlay(Context context, AMap amap, List clusterItems, int clusterSize) { + if (clusterItems != null) { + this.clusterItems = clusterItems; + } else { + this.clusterItems = new ArrayList<>(); + } + this.context = context; + this.clusters = new ArrayList<>(); + this.amap = amap; + this.clusterSize = clusterSize; + this.pxInMeters = amap.getScalePerPixel(); + this.clusterDistance = pxInMeters * clusterSize; + amap.setOnCameraChangeListener(this); + amap.setOnMarkerClickListener(this); + initThreadHandler(); + assignClusters(); + } + + /** + * 设置聚合点的点击事件 + */ + public void setOnClusterClickListener(ClusterOnClickListener clusterClickListener) { + this.clusterClickListener = clusterClickListener; + } + + /** + * 添加一个聚合点 + */ + public void addClusterItem(ClusterItem item) { + Message message = Message.obtain(); + message.what = SignClusterHandler.CALCULATE_SINGLE_CLUSTER; + message.obj = item; + signClusterHandler.sendMessage(message); + } + + /** + * 设置聚合元素的渲染样式,不设置则默认为气泡加数字形式进行渲染 + */ + public void setClusterRender(ClusterRender render) { + this.clusterRender = render; + } + + public void onDestroy() { + isCanceled = true; + signClusterHandler.removeCallbacksAndMessages(null); + markerHandler.removeCallbacksAndMessages(null); + signClusterThread.quit(); + markerHandlerThread.quit(); + for (Marker marker : addMarkers) { + marker.remove(); + } + addMarkers.clear(); + } + + //初始化Handler + private void initThreadHandler() { + markerHandlerThread.start(); + signClusterThread.start(); + markerHandler = new MarkerHandler(markerHandlerThread.getLooper()); + signClusterHandler = new SignClusterHandler(signClusterThread.getLooper()); + } + + @Override + public void onCameraChange(CameraPosition arg0) { + + } + + @Override + public void onCameraChangeFinish(CameraPosition arg0) { + pxInMeters = amap.getScalePerPixel(); + clusterDistance = pxInMeters * clusterSize; + assignClusters(); + } + + @Override + public boolean onMarkerClick(Marker marker) { + if (clusterClickListener == null) { + return true; + } + Cluster cluster = (Cluster) marker.getObject(); + if (cluster != null) { + clusterClickListener.onMarkerClicked(marker, cluster.getClusterItems()); + return true; + } + return false; + } + + /** + * 将聚合元素添加至地图上 + */ + private void addClusterToMap(List clusters) { + ArrayList removeMarkers = new ArrayList<>(addMarkers); + AlphaAnimation alphaAnimation = new AlphaAnimation(1, 0); + RemoveAnimationListener removeAnimationListener = new RemoveAnimationListener(removeMarkers); + for (Marker marker : removeMarkers) { + marker.setAnimation(alphaAnimation); + marker.setAnimationListener(removeAnimationListener); + marker.startAnimation(); + } + + for (Cluster cluster : clusters) { + addSingleClusterToMap(cluster); + } + } + + /** + * 将单个聚合元素添加至地图显示 + */ + private void addSingleClusterToMap(Cluster cluster) { + LatLng latlng = cluster.getCenterLatLng(); + MarkerOptions markerOptions = new MarkerOptions(); + markerOptions.icon(getBitmapDes(cluster.getClusterCount())).position(latlng); + Marker marker = amap.addMarker(markerOptions); + marker.setAnimation(addAnimation); + marker.setObject(cluster); + + marker.startAnimation(); + cluster.setMarker(marker); + addMarkers.add(marker); + } + + private void calculateClusters() { + isCanceled = false; + clusters.clear(); + LatLngBounds visibleBounds = amap.getProjection().getVisibleRegion().latLngBounds; + for (ClusterItem clusterItem : clusterItems) { + if (isCanceled) { + return; + } + LatLng latlng = clusterItem.getPosition(); + if (visibleBounds.contains(latlng)) { + Cluster cluster = getCluster(latlng, clusters); + if (cluster == null) { + cluster = new Cluster(latlng); + clusters.add(cluster); + } + cluster.addClusterItem(clusterItem); + } + } + + //复制一份数据,规避同步 + List tempClusters = new ArrayList<>(clusters); + Message message = Message.obtain(); + message.what = MarkerHandler.ADD_CLUSTER_LIST; + message.obj = tempClusters; + if (isCanceled) { + return; + } + markerHandler.sendMessage(message); + } + + /** + * 对点进行聚合 + */ + private void assignClusters() { + isCanceled = true; + signClusterHandler.removeMessages(SignClusterHandler.CALCULATE_CLUSTER); + signClusterHandler.sendEmptyMessage(SignClusterHandler.CALCULATE_CLUSTER); + } + + /** + * 在已有的聚合基础上,对添加的单个元素进行聚合 + */ + private void calculateSingleCluster(ClusterItem clusterItem) { + LatLngBounds visibleBounds = amap.getProjection().getVisibleRegion().latLngBounds; + LatLng latlng = clusterItem.getPosition(); + if (!visibleBounds.contains(latlng)) { + return; + } + Cluster cluster = getCluster(latlng, clusters); + if (cluster != null) { + cluster.addClusterItem(clusterItem); + Message message = Message.obtain(); + message.what = MarkerHandler.UPDATE_SINGLE_CLUSTER; + + message.obj = cluster; + markerHandler.removeMessages(MarkerHandler.UPDATE_SINGLE_CLUSTER); + markerHandler.sendMessageDelayed(message, 5); + } else { + cluster = new Cluster(latlng); + clusters.add(cluster); + cluster.addClusterItem(clusterItem); + Message message = Message.obtain(); + message.what = MarkerHandler.ADD_SINGLE_CLUSTER; + message.obj = cluster; + markerHandler.sendMessage(message); + } + } + + /** + * 根据一个点获取是否可以依附的聚合点,没有则返回null + */ + private Cluster getCluster(LatLng latLng, List clusters) { + for (Cluster cluster : clusters) { + LatLng clusterCenterPoint = cluster.getCenterLatLng(); + double distance = AMapUtils.calculateLineDistance(latLng, clusterCenterPoint); + if (distance < clusterDistance && amap.getCameraPosition().zoom < 19) { + return cluster; + } + } + return null; + } + + + /** + * 获取每个聚合点的绘制样式 + */ + private BitmapDescriptor getBitmapDes(int num) { + TextView textView = new TextView(context); + if (num > 1) { + String tile = String.valueOf(num); + textView.setText(tile); + } + textView.setGravity(Gravity.CENTER); + textView.setTextColor(Color.BLACK); + textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 15); + if (clusterRender != null && clusterRender.getDrawableByCount(num) != null) { + textView.setBackgroundDrawable(clusterRender.getDrawableByCount(num)); + } else { + textView.setBackgroundResource(R.mipmap.well_location); + } + return BitmapDescriptorFactory.fromView(textView); + } + + /** + * 更新已加入地图聚合点的样式 + */ + private void updateCluster(Cluster cluster) { + Marker marker = cluster.getMarker(); + marker.setIcon(getBitmapDes(cluster.getClusterCount())); + } + + /** + * 处理market添加,更新等操作 + */ + class MarkerHandler extends Handler { + + static final int ADD_CLUSTER_LIST = 0; + + static final int ADD_SINGLE_CLUSTER = 1; + + static final int UPDATE_SINGLE_CLUSTER = 2; + + public MarkerHandler(Looper looper) { + super(looper); + } + + public void handleMessage(Message message) { + switch (message.what) { + case ADD_CLUSTER_LIST: + List clusters = (List) message.obj; + addClusterToMap(clusters); + break; + case ADD_SINGLE_CLUSTER: + Cluster cluster = (Cluster) message.obj; + addSingleClusterToMap(cluster); + break; + case UPDATE_SINGLE_CLUSTER: + Cluster updateCluster = (Cluster) message.obj; + updateCluster(updateCluster); + break; + } + } + } + + /** + * 处理聚合点算法线程 + */ + class SignClusterHandler extends Handler { + static final int CALCULATE_CLUSTER = 0; + static final int CALCULATE_SINGLE_CLUSTER = 1; + + public SignClusterHandler(Looper looper) { + super(looper); + } + + public void handleMessage(Message message) { + switch (message.what) { + case CALCULATE_CLUSTER: + calculateClusters(); + break; + case CALCULATE_SINGLE_CLUSTER: + ClusterItem item = (ClusterItem) message.obj; + clusterItems.add(item); + calculateSingleCluster(item); + break; + } + } + } +} diff --git a/app/src/main/java/com/casic/app/smartwell/widgets/cluster/ClusterRender.java b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/ClusterRender.java new file mode 100644 index 0000000..427ff14 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/ClusterRender.java @@ -0,0 +1,10 @@ +package com.casic.app.smartwell.widgets.cluster; + +import android.graphics.drawable.Drawable; + +public interface ClusterRender { + /** + * 根据聚合点的元素数目返回渲染背景样式 + */ + Drawable getDrawableByCount(int clusterNum); +} diff --git a/app/src/main/java/com/casic/app/smartwell/widgets/cluster/RegionItem.java b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/RegionItem.java new file mode 100644 index 0000000..7b2b6c4 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/RegionItem.java @@ -0,0 +1,23 @@ +package com.casic.app.smartwell.widgets.cluster; + +import com.amap.api.maps.model.LatLng; +import com.casic.app.smartwell.model.MapWellListModel; + +public class RegionItem implements ClusterItem { + private final LatLng latLng; + private final MapWellListModel.DataModel well; + + public RegionItem(LatLng latLng, MapWellListModel.DataModel well) { + this.latLng = latLng; + this.well = well; + } + + @Override + public LatLng getPosition() { + return latLng; + } + + public MapWellListModel.DataModel getWell() { + return well; + } +} diff --git a/app/src/main/java/com/casic/app/smartwell/widgets/cluster/RemoveAnimationListener.java b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/RemoveAnimationListener.java new file mode 100644 index 0000000..c9c5e84 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/RemoveAnimationListener.java @@ -0,0 +1,30 @@ +package com.casic.app.smartwell.widgets.cluster; + +import com.amap.api.maps.model.Marker; +import com.amap.api.maps.model.animation.Animation; + +import java.util.List; + +/** + * marker渐变动画,动画结束后将Marker删除 + */ +public class RemoveAnimationListener implements Animation.AnimationListener { + private final List removeMarkers; + + public RemoveAnimationListener(List removeMarkers) { + this.removeMarkers = removeMarkers; + } + + @Override + public void onAnimationStart() { + + } + + @Override + public void onAnimationEnd() { + for (Marker marker : removeMarkers) { + marker.remove(); + } + removeMarkers.clear(); + } +} \ No newline at end of file diff --git a/app/src/main/res/anim/map_popup_hide.xml b/app/src/main/res/anim/map_popup_hide.xml new file mode 100644 index 0000000..119726b --- /dev/null +++ b/app/src/main/res/anim/map_popup_hide.xml @@ -0,0 +1,12 @@ + + + + \ No newline at end of file diff --git a/app/src/main/res/anim/map_popup_show.xml b/app/src/main/res/anim/map_popup_show.xml new file mode 100644 index 0000000..1d281ef --- /dev/null +++ b/app/src/main/res/anim/map_popup_show.xml @@ -0,0 +1,12 @@ + + + + \ No newline at end of file diff --git a/app/src/main/res/anim/popup_hide.xml b/app/src/main/res/anim/popup_hide.xml index 55c7aca..7480485 100644 --- a/app/src/main/res/anim/popup_hide.xml +++ b/app/src/main/res/anim/popup_hide.xml @@ -1,7 +1,8 @@ - + \ No newline at end of file diff --git a/app/src/main/res/anim/popup_show.xml b/app/src/main/res/anim/popup_show.xml index 1d281ef..dbe2833 100644 --- a/app/src/main/res/anim/popup_show.xml +++ b/app/src/main/res/anim/popup_show.xml @@ -1,12 +1,8 @@ \ No newline at end of file diff --git a/app/src/main/res/drawable/bg_solid_layout_transparent_radius_10.xml b/app/src/main/res/drawable/bg_solid_layout_transparent_radius_10.xml deleted file mode 100644 index 15e6a4b..0000000 --- a/app/src/main/res/drawable/bg_solid_layout_transparent_radius_10.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/extensions/Int.kt b/app/src/main/java/com/casic/app/smartwell/extensions/Int.kt index de0617b..a0a5e33 100644 --- a/app/src/main/java/com/casic/app/smartwell/extensions/Int.kt +++ b/app/src/main/java/com/casic/app/smartwell/extensions/Int.kt @@ -1,9 +1,24 @@ package com.casic.app.smartwell.extensions +import android.graphics.Bitmap +import android.graphics.Canvas +import android.graphics.Paint +import android.graphics.RectF + fun Int.toLevel(): String { return if (this == 0) { "" } else { this.toString() } +} + +fun Int.drawCircle(color: Int): Bitmap? { + val bitmap = Bitmap.createBitmap(this * 2, this * 2, Bitmap.Config.ARGB_8888) + val canvas = Canvas(bitmap) + val paint = Paint() + val rectF = RectF(0f, 0f, (this * 2).toFloat(), (this * 2).toFloat()) + paint.color = color + canvas.drawArc(rectF, 0f, 360f, true, paint) + return bitmap } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt index 6b6ca3e..5e45534 100644 --- a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt +++ b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt @@ -2,17 +2,13 @@ import android.content.Context import com.casic.app.smartwell.callback.OnImageCompressListener -import com.casic.app.smartwell.model.ErrorMessageModel import com.casic.app.smartwell.utils.LocaleConstant -import com.google.gson.Gson -import com.google.gson.reflect.TypeToken +import com.google.gson.JsonParser import com.pengxh.kt.lite.extensions.createCompressImageDir import com.pengxh.kt.lite.utils.SaveKeyValues -import org.json.JSONObject import top.zibin.luban.Luban import top.zibin.luban.OnCompressListener import java.io.File -import java.util.Locale /** * String扩展方法 @@ -74,18 +70,22 @@ } } -fun String.separateResponseCode(): Int { +fun String.getResponseCode(): Int { if (this.isBlank()) { return 404 } - return JSONObject(this).getInt("code") + val element = JsonParser.parseString(this) + val jsonObject = element.asJsonObject + return jsonObject.get("code").asInt } -fun String.toErrorMessage(): String { - val errorModel = Gson().fromJson( - this, object : TypeToken() {}.type - ) - return errorModel.message.toString() +fun String.getResponseMessage(): String { + if (this.isBlank()) { + return "" + } + val element = JsonParser.parseString(this) + val jsonObject = element.asJsonObject + return jsonObject.get("message").asString } fun String.compressImage(context: Context, listener: OnImageCompressListener) { @@ -93,9 +93,6 @@ .load(this) .ignoreBy(100) .setTargetDir(context.createCompressImageDir().toString()) - .filter { - !(it.isBlank() || it.lowercase(Locale.getDefault()).endsWith(".gif")) - } .setCompressListener(object : OnCompressListener { override fun onStart() { 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 96df110..cd25fca 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 @@ -1,26 +1,25 @@ package com.casic.app.smartwell.fragment -import android.graphics.Point +import android.graphics.Color +import android.graphics.drawable.BitmapDrawable +import android.graphics.drawable.Drawable 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 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.LatLngBounds import com.amap.api.maps.model.Marker -import com.amap.api.maps.model.MarkerOptions import com.casic.app.smartwell.R import com.casic.app.smartwell.databinding.FragmentHomeBinding +import com.casic.app.smartwell.extensions.drawCircle import com.casic.app.smartwell.extensions.initImmersionBar -import com.casic.app.smartwell.extensions.valueToType import com.casic.app.smartwell.model.MapWellListModel import com.casic.app.smartwell.utils.LocaleConstant import com.casic.app.smartwell.utils.RouteOnMap @@ -31,9 +30,16 @@ import com.casic.app.smartwell.view.WellOperationActivity import com.casic.app.smartwell.vm.OrderViewModel import com.casic.app.smartwell.vm.WellViewModel +import com.casic.app.smartwell.widgets.MapWellPopup +import com.casic.app.smartwell.widgets.cluster.ClusterItem +import com.casic.app.smartwell.widgets.cluster.ClusterOnClickListener +import com.casic.app.smartwell.widgets.cluster.ClusterOverlay +import com.casic.app.smartwell.widgets.cluster.RegionItem 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.convertDrawable +import com.pengxh.kt.lite.extensions.dp2px import com.pengxh.kt.lite.extensions.navigatePageTo import com.pengxh.kt.lite.extensions.show import com.pengxh.kt.lite.utils.LoadingDialogHub @@ -43,35 +49,23 @@ /** * 地图点位带聚合效果 * */ -class HomePageHaveClusterFragment : KotlinBaseFragment(), AMap.OnMapLoadedListener, - AMap.OnCameraChangeListener, AMap.OnMarkerClickListener, AMap.InfoWindowAdapter, - AMap.OnInfoWindowClickListener { +class HomePageHaveClusterFragment : KotlinBaseFragment(), + AMap.OnCameraChangeListener { private val kTag = "HaveClusterFragment" private val easyPopupWindow by lazy { EasyPopupWindow(requireContext()) } - private lateinit var wellViewModel: WellViewModel - private lateinit var orderViewModel: OrderViewModel - private lateinit var aMap: AMap - - /** - * 所有的marker - */ - private var allMarkerOptions: MutableList = ArrayList() - - /** - * 视野内的marker - */ - private var markerOptionsInView: MutableList = ArrayList() - - /** - * 自定义Marker弹出框 - * */ - private lateinit var v: View + private val regionRadius by lazy { LocaleConstant.RADIUS_SIZE.dp2px(requireContext()) } + private val infoPopup by lazy { MapWellPopup(requireContext()) } /** * 所有窨井列表信息集合 * */ - private var wellModels: MutableList = ArrayList() + private val wellModels = ArrayList() + private val backDrawables = HashMap() + private lateinit var wellViewModel: WellViewModel + private lateinit var orderViewModel: OrderViewModel + private lateinit var aMap: AMap + private var clusterOverlay: ClusterOverlay? = null override fun initViewBinding( inflater: LayoutInflater, @@ -106,6 +100,9 @@ } }) + //地图初始化 + initMap(savedInstanceState) + //初始化vm wellViewModel = ViewModelProvider(this)[WellViewModel::class.java] orderViewModel = ViewModelProvider(this)[OrderViewModel::class.java] @@ -120,25 +117,19 @@ val latitudeList: MutableList = ArrayList() val longitudeList: MutableList = ArrayList() it.data?.forEach { well -> - val lat = well.latGaode.toString() - val lng = well.lngGaode.toString() + val lat = well.latGaode + val lng = well.lngGaode if (lat.isNotBlank() && lng.isNotBlank()) { //返回true代表当前位置在大陆、港澳地区,反之不在 val latitude = lat.toDouble() val longitude = lng.toDouble() if (CoordinateConverter.isAMapDataAvailable(latitude, longitude)) { - //缓存所有设备详情,点击Marker时候需要 + //缓存所有井 wellModels.add(well) + //分别缓存经、纬度 latitudeList.add(latitude) longitudeList.add(longitude) - //将所有设备信息转化缓存为Marker点 - allMarkerOptions.add( - MarkerOptions() - .position(LatLng(latitude, longitude)) - .title(well.wellTypeName) - .snippet(well.wellName) - ) } } } @@ -160,12 +151,12 @@ val cameraPosition = CameraPosition(centerLatLng, 16f, 0f, 0f) val cameraUpdate = CameraUpdateFactory.newCameraPosition(cameraPosition) aMap.animateCamera(cameraUpdate, 1500, null) + + //显示点数据 + displayWellOnMap() } } - //地图初始化 - initMap(savedInstanceState) - //获取窨井监控数据 wellViewModel.countResultModel.observe(this) { binding.deployedWellView.text = it["bfWell"] @@ -220,17 +211,10 @@ uiSettings.isCompassEnabled = true uiSettings.zoomPosition = AMapOptions.ZOOM_POSITION_RIGHT_CENTER uiSettings.isTiltGesturesEnabled = false//不许地图随手势倾斜角度 + uiSettings.isRotateGesturesEnabled = false//不允许地图随手势改变方位 - // 地图加载成功监听 - aMap.addOnMapLoadedListener(this) // 地图缩放监听 aMap.addOnCameraChangeListener(this) - // marker 点击事件监听 - aMap.addOnMarkerClickListener(this) - // 点击marker弹出自定义popup - aMap.setInfoWindowAdapter(this) - //信息窗点击事件 - aMap.addOnInfoWindowClickListener(this) } override fun initEvent() { @@ -259,9 +243,111 @@ } - override fun onMapLoaded() { - //地图加载成功之后显示聚合点数据 - initClustersMarkers() + private fun displayWellOnMap() { + clusterOverlay?.onDestroy() + val clusterItems = ArrayList() + + wellModels.forEach { + val latitude = it.latGaode.toDouble() + val longitude = it.lngGaode.toDouble() + + val latLng = LatLng(latitude, longitude, false) + val regionItem = RegionItem(latLng, it) + clusterItems.add(regionItem) + } + + clusterOverlay = ClusterOverlay(requireContext(), aMap, clusterItems, regionRadius) + clusterOverlay?.setClusterRender { clusterNum -> + //聚合圆半径 + val radius = 100.dp2px(requireContext()) + if (clusterNum == 0) { + var bitmapDrawable = backDrawables[0] + if (bitmapDrawable == null) { + bitmapDrawable = BitmapDrawable( + null, radius.drawCircle(Color.argb(159, 100, 149, 237)) + ) + backDrawables[0] = bitmapDrawable + } + bitmapDrawable + } + if (clusterNum == 1) { + var bitmapDrawable = backDrawables[1] + if (bitmapDrawable == null) { + bitmapDrawable = R.mipmap.well_location.convertDrawable(requireContext())!! + backDrawables[1] = bitmapDrawable + } + bitmapDrawable + } else if (clusterNum < 5) { + var bitmapDrawable = backDrawables[2] + if (bitmapDrawable == null) { + bitmapDrawable = BitmapDrawable( + null, radius.drawCircle(Color.argb(159, 100, 149, 237)) + ) + backDrawables[2] = bitmapDrawable + } + bitmapDrawable + } else if (clusterNum < 10) { + var bitmapDrawable = backDrawables[3] + if (bitmapDrawable == null) { + bitmapDrawable = BitmapDrawable( + null, radius.drawCircle(Color.argb(199, 30, 144, 255)) + ) + backDrawables[3] = bitmapDrawable + } + bitmapDrawable + } else { + var bitmapDrawable = backDrawables[4] + if (bitmapDrawable == null) { + bitmapDrawable = BitmapDrawable( + null, radius.drawCircle(Color.argb(235, 65, 105, 225)) + ) + backDrawables[4] = bitmapDrawable + } + bitmapDrawable + } + } + + clusterOverlay?.setOnClusterClickListener(object : ClusterOnClickListener { + override fun onMarkerClicked(marker: Marker?, items: List) { + if (items.size > 1) { + "请缩放地图比例在查看数据".show(requireContext()) + return + } + + var item: RegionItem? = null + val builder = LatLngBounds.Builder() + for (clusterItem in items) { + builder.include(clusterItem.position) + item = clusterItem as RegionItem + } + + item?.apply { + showWellPopup(well) + } + } + }) + } + + private fun showWellPopup(well: MapWellListModel.DataModel) { + infoPopup.set(well, object : MapWellPopup.OnPopupWindowClickListener { + override fun onPopupClicked(lat: Double, lng: Double) { + AlertControlDialog.Builder().setContext(requireContext()).setTitle("操作提示") + .setMessage("确定要前往吗").setNegativeButton("取消").setPositiveButton("确定") + .setOnDialogButtonClickListener(object : + AlertControlDialog.OnDialogButtonClickListener { + override fun onConfirmClick() { + RouteOnMap.startNavigation( + requireContext(), "", LatLng(lat, lng) + ) + } + + override fun onCancelClick() { + + } + }).build().show() + } + }) + infoPopup.showAsDropDown(binding.rightOptionView) } override fun onCameraChange(p0: CameraPosition?) { @@ -282,103 +368,10 @@ } } - //获取视野内的marker 根据聚合算法合成自定义的marker 显示视野内的marker override fun onCameraChangeFinish(p0: CameraPosition?) { //地图缩放之后显示聚合点数据 LoadingDialogHub.dismiss() httpCountDownTimer.cancel() - initClustersMarkers() - } - - private fun initClustersMarkers() { - 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 { - v = LayoutInflater.from(requireContext()).inflate(R.layout.popup_map_info, null) - - //显示闸井信息 - marker?.showInfoWindow() - return true - } - - override fun getInfoWindow(marker: Marker?): View { - //反射得到popup里面的控件对象 - val wellNameView = v.findViewById(R.id.wellNameView) - val wellCodeView = v.findViewById(R.id.wellCodeView) - val wellTypeView = v.findViewById(R.id.wellTypeView) - val wellStateView = v.findViewById(R.id.wellStateView) - val deepView = v.findViewById(R.id.deepView) - val locationView = v.findViewById(R.id.locationView) - - //绑定数据 - val clickedLatLng = marker?.position!! - wellModels.forEach { well -> - if (clickedLatLng.latitude == well.latGaode!!.toDouble() - && clickedLatLng.longitude == well.lngGaode!!.toDouble() - ) { - wellNameView.text = String.format("点位名称: ${well.wellName}") - wellCodeView.text = String.format("点位编号: ${well.wellCode}") - wellTypeView.text = String.format("点位类型: ${well.wellType.valueToType()}") - val bfztName = if (well.bfzt == "1") { - "已布防" - } else { - "已撤防" - } - wellStateView.text = String.format("布/撤防状态: $bfztName") - deepView.text = String.format("点位深度: ${well.deep}m") - locationView.text = String.format("详细位置: ${well.position}") - } - } - return v - } - - /** - * 此方法不能修改整个 InfoWindow 的背景和边框,无论自定义的样式是什么样,SDK 都会在最外层添加一个默认的边框 - * */ - override fun getInfoContents(p0: Marker?): View? = null - - override fun onInfoWindowClick(p0: Marker?) { - p0?.apply { - AlertControlDialog.Builder() - .setContext(requireContext()) - .setTitle("操作提示") - .setMessage("确定要前往吗") - .setNegativeButton("取消") - .setPositiveButton("确定") - .setOnDialogButtonClickListener(object : - AlertControlDialog.OnDialogButtonClickListener { - override fun onConfirmClick() { - val lat = position.latitude.toString() - val lng = position.longitude.toString() - if (lat.isBlank() || lng.isBlank()) { - "点位经纬度异常,无法开启导航".show(requireContext()) - return - } - RouteOnMap.startNavigation( - requireContext(), snippet, LatLng(lat.toDouble(), lng.toDouble()) - ) - } - - override fun onCancelClick() { - - } - }).build().show() - } } /***以下是地图生命周期管理************************************************************************/ 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 a54d213..bfa7a57 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 @@ -44,8 +44,8 @@ * 地图点位不带聚合效果 * */ class HomePageNoClusterFragment : KotlinBaseFragment(), - AMap.OnMapLoadedListener, AMap.OnCameraChangeListener, AMap.OnMarkerClickListener, - AMap.InfoWindowAdapter, AMap.OnInfoWindowClickListener { + AMap.OnCameraChangeListener, AMap.OnMarkerClickListener, AMap.InfoWindowAdapter, + AMap.OnInfoWindowClickListener { private val kTag = "NoClusterFragment" private val easyPopupWindow by lazy { EasyPopupWindow(requireContext()) } @@ -109,6 +109,9 @@ wellViewModel = ViewModelProvider(this)[WellViewModel::class.java] orderViewModel = ViewModelProvider(this)[OrderViewModel::class.java] + //地图初始化 + initMap(savedInstanceState) + //获取所有窨井数据 httpCountDownTimer.start() LoadingDialogHub.show(requireActivity(), "数据加载中,请稍后...") @@ -157,12 +160,12 @@ val cameraPosition = CameraPosition(centerLatLng, 16f, 0f, 0f) val cameraUpdate = CameraUpdateFactory.newCameraPosition(cameraPosition) aMap.animateCamera(cameraUpdate, 1500, null) + + //显示点数据 + displayWellOnMap() } } - //地图初始化 - initMap(savedInstanceState) - //获取窨井监控数据 wellViewModel.countResultModel.observe(this) { binding.deployedWellView.text = it["bfWell"] @@ -214,9 +217,8 @@ uiSettings.isCompassEnabled = true uiSettings.zoomPosition = AMapOptions.ZOOM_POSITION_RIGHT_CENTER uiSettings.isTiltGesturesEnabled = false//不许地图随手势倾斜角度 + uiSettings.isRotateGesturesEnabled = false//不允许地图随手势改变方位 - // 地图加载成功监听 - aMap.addOnMapLoadedListener(this) // 地图缩放监听 aMap.addOnCameraChangeListener(this) // marker 点击事件监听 @@ -253,11 +255,6 @@ } - override fun onMapLoaded() { - //地图加载成功之后显示聚合点数据 - initClustersMarkers() - } - override fun onCameraChange(p0: CameraPosition?) { } @@ -281,10 +278,9 @@ //地图缩放之后显示聚合点数据 LoadingDialogHub.dismiss() httpCountDownTimer.cancel() - initClustersMarkers() } - private fun initClustersMarkers() { + private fun displayWellOnMap() { val proj = aMap.projection val dm = resources.displayMetrics var screenLocation: Point diff --git a/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.java b/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.java deleted file mode 100644 index d8b18ef..0000000 --- a/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.java +++ /dev/null @@ -1,50 +0,0 @@ -package com.casic.app.smartwell.model; - -public class ErrorMessageModel { - - private int code; - private String data; - private String exceptionClazz; - private String message; - private boolean success; - - public int getCode() { - return code; - } - - public void setCode(int code) { - this.code = code; - } - - public String getData() { - return data; - } - - public void setData(String data) { - this.data = data; - } - - public String getExceptionClazz() { - return exceptionClazz; - } - - public void setExceptionClazz(String exceptionClazz) { - this.exceptionClazz = exceptionClazz; - } - - public String getMessage() { - return message; - } - - public void setMessage(String message) { - this.message = message; - } - - public boolean isSuccess() { - return success; - } - - public void setSuccess(boolean success) { - this.success = success; - } -} \ No newline at end of file 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 new file mode 100644 index 0000000..215ac0c --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/PipelineModel.java @@ -0,0 +1,328 @@ +package com.casic.app.smartwell.model; + +import java.util.List; + +public class PipelineModel { + + private Integer code; + private DataModel data; + private String message; + private Boolean success; + + public Integer getCode() { + return code; + } + + public void setCode(Integer code) { + this.code = code; + } + + public DataModel getData() { + return data; + } + + public void setData(DataModel data) { + this.data = data; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + public Boolean getSuccess() { + return success; + } + + public void setSuccess(Boolean success) { + this.success = success; + } + + public static class DataModel { + private List rows; + private Integer total; + + public List getRows() { + return rows; + } + + public void setRows(List rows) { + this.rows = rows; + } + + public Integer getTotal() { + return total; + } + + public void setTotal(Integer total) { + this.total = total; + } + + 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 getBuryMode() { + return buryMode; + } + + public void setBuryMode(String buryMode) { + this.buryMode = buryMode; + } + + public String getConstructEra() { + return constructEra; + } + + public void setConstructEra(String constructEra) { + this.constructEra = constructEra; + } + + 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; + } + } + } +} 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 06d3d2b..4f38a2c 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 = 100 //相距多少米才聚合,单位:米 + const val RADIUS_SIZE = 80 //相距多少米才聚合,单位:米 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:11308" + // 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 0d5f3fa..991e1db 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 @@ -312,4 +312,14 @@ @Header("token") token: String, @Field("clientid") deviceCode: String ): String + + /** + * 管线位置数据 + */ + @GET("/pipeline/listPage") + suspend fun getPipeline( + @Header("token") token: String, + @Query("limit") limit: Int, + @Query("offset") offset: Int + ): String } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt index 1a0ce22..4050067 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt @@ -294,4 +294,11 @@ suspend fun registerPush(clientId: String): String { return api.registerPush(AuthenticationHelper.token!!, clientId) } + + /** + * 管线位置数据 + */ + suspend fun getPipeline(): String { + return api.getPipeline(AuthenticationHelper.token!!, 2000, 1) + } } \ No newline at end of file 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 9270fa1..4ca5a5e 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.HomePageNoClusterFragment +import com.casic.app.smartwell.fragment.HomePageHaveClusterFragment 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/vm/AlarmViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/AlarmViewModel.kt index 9cff08c..e7acc17 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/AlarmViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/AlarmViewModel.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.AlarmContentModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager import com.google.gson.Gson @@ -16,7 +16,7 @@ fun getAlarmContentType(alarmType: String) = launch({ val response = RetrofitServiceManager.getAlarmContentType(alarmType) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { listModel.value = gson.fromJson( response, object : TypeToken() {}.type diff --git a/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt index 5e5b163..895dedd 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.PublicKeyModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager import com.google.gson.Gson @@ -18,7 +18,7 @@ fun getPublicKey() = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.authenticate() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { keyModel.value = gson.fromJson( response, object : TypeToken() {}.type diff --git a/app/src/main/java/com/casic/app/smartwell/vm/DeviceViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/DeviceViewModel.kt index db5ccf6..899a962 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/DeviceViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/DeviceViewModel.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.DeviceDetailModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager import com.google.gson.Gson @@ -16,7 +16,7 @@ fun getDeviceDetail(deviceCode: String) = launch({ val response = RetrofitServiceManager.getDeviceDetail(deviceCode) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { detailModel.value = gson.fromJson( response, object : TypeToken() {}.type diff --git a/app/src/main/java/com/casic/app/smartwell/vm/LoginViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/LoginViewModel.kt index cd8b8a9..a417398 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/LoginViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/LoginViewModel.kt @@ -2,7 +2,7 @@ import androidx.lifecycle.MutableLiveData import com.casic.app.smartwell.base.BaseApplication -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.CommonResultModel import com.casic.app.smartwell.model.LoginResultModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -21,7 +21,7 @@ fun enter(account: String, secretKey: String) = launch({ val response = RetrofitServiceManager.login(account, secretKey) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success enterResultModel.value = gson.fromJson( @@ -38,7 +38,7 @@ fun out() = launch({ val response = RetrofitServiceManager.loginOut() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { outResultModel.value = gson.fromJson( response, object : TypeToken() {}.type diff --git a/app/src/main/java/com/casic/app/smartwell/vm/OperationViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/OperationViewModel.kt index 8943ed3..37e115f 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/OperationViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/OperationViewModel.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.vm import com.casic.app.smartwell.base.BaseApplication -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager import com.pengxh.kt.lite.base.BaseViewModel import com.pengxh.kt.lite.extensions.launch @@ -16,7 +16,7 @@ fun acceptWorkOrder(id: String) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.acceptWorkOrder(id) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success "接单成功".show(BaseApplication.get()) @@ -35,7 +35,7 @@ loadState.value = LoadState.Loading val response = RetrofitServiceManager.confirmWorkOrder(id, firstState, firstStatePhotos, needHandle) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success "工单确认成功".show(BaseApplication.get()) @@ -50,7 +50,7 @@ fun transferWorkOrder(id: String, userId: String) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.transferWorkOrder(id, userId) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success "转单成功".show(BaseApplication.get()) @@ -65,7 +65,7 @@ fun completeWorkOrder(id: String, handleMessage: String, handlePhotos: String) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.completeWorkOrder(id, handleMessage, handlePhotos) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success "工单处理成功".show(BaseApplication.get()) diff --git a/app/src/main/java/com/casic/app/smartwell/vm/OrderViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/OrderViewModel.kt index 4cb26b7..d2fad86 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/OrderViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/OrderViewModel.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.OrderDetailModel import com.casic.app.smartwell.model.OrderListModel import com.casic.app.smartwell.model.OrderStatusModel @@ -37,7 +37,7 @@ val response = RetrofitServiceManager.getSearchResult( keywords, alarmContent, alarmLevel, jobStatus, deptId, beginTime, endTime, offset ) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success searchResult.value = gson.fromJson( @@ -53,7 +53,7 @@ fun getWorkOrderListByState(jobStatus: String, page: Int) = launch({ val response = RetrofitServiceManager.getWorkOrderList(jobStatus, page) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { orderList.value = gson.fromJson( response, object : TypeToken() {}.type @@ -65,7 +65,7 @@ fun getNotAcceptOderList(page: Int) = launch({ val response = RetrofitServiceManager.getNotAcceptOderList(page) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { orderList.value = gson.fromJson( response, object : TypeToken() {}.type @@ -77,7 +77,7 @@ fun getNotHandleOderList(page: Int) = launch({ val response = RetrofitServiceManager.getNotHandleOderList(page) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { orderList.value = gson.fromJson( response, object : TypeToken() {}.type @@ -89,7 +89,7 @@ fun countWorkOrderByState() = launch({ val response = RetrofitServiceManager.countWorkOrderByState() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { val map = HashMap(4) @@ -107,7 +107,7 @@ fun getOrderStatus() = launch({ val response = RetrofitServiceManager.getOrderStatus() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { orderStatusModel.value = gson.fromJson( response, object : TypeToken() {}.type @@ -120,7 +120,7 @@ fun getWorkOrderDetail(id: String) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.getWorkOrderDetail(id) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success detailModel.value = gson.fromJson( diff --git a/app/src/main/java/com/casic/app/smartwell/vm/PipelineViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/PipelineViewModel.kt new file mode 100644 index 0000000..60c1e2f --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/vm/PipelineViewModel.kt @@ -0,0 +1,28 @@ +package com.casic.app.smartwell.vm + +import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.extensions.getResponseCode +import com.casic.app.smartwell.model.PipelineModel +import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken +import com.pengxh.kt.lite.base.BaseViewModel +import com.pengxh.kt.lite.extensions.launch + +class PipelineViewModel : BaseViewModel() { + + private val gson by lazy { Gson() } + val lineResult = MutableLiveData() + + fun getPipeline() = launch({ + val response = RetrofitServiceManager.getPipeline() + val responseCode = response.getResponseCode() + if (responseCode == 200) { + lineResult.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } + }, { + it.printStackTrace() + }) +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/PushViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/PushViewModel.kt index 9279815..12fd610 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/PushViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/PushViewModel.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.CommonResultModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager import com.google.gson.Gson @@ -16,7 +16,7 @@ fun registerPush(clientId: String) = launch({ val response = RetrofitServiceManager.registerPush(clientId) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { registerResultModel.value = gson.fromJson( response, object : TypeToken() {}.type diff --git a/app/src/main/java/com/casic/app/smartwell/vm/UploadImageViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/UploadImageViewModel.kt index 8d6744e..9707eeb 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/UploadImageViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/UploadImageViewModel.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.CommonResultModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager import com.google.gson.Gson @@ -19,7 +19,7 @@ fun uploadImage(image: File) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.uploadImage(image) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success resultModel.value = gson.fromJson( diff --git a/app/src/main/java/com/casic/app/smartwell/vm/UserViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/UserViewModel.kt index 31a4d4c..070c35a 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/UserViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/UserViewModel.kt @@ -2,7 +2,7 @@ import androidx.lifecycle.MutableLiveData import com.casic.app.smartwell.base.BaseApplication -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.SubordinateModel import com.casic.app.smartwell.model.UserDetailModel import com.casic.app.smartwell.model.VersionResultModel @@ -25,7 +25,7 @@ fun getUserDetail() = launch({ val response = RetrofitServiceManager.getUserDetail() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { val userDetail = gson.fromJson( response, object : TypeToken() {}.type @@ -48,7 +48,7 @@ * */ fun getSubordinate(hasMine: String?, deptId: String?, roleTips: String?) = launch({ val response = RetrofitServiceManager.getSubordinate(hasMine, deptId, roleTips) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { subordinateModel.value = gson.fromJson( response, object : TypeToken() {}.type @@ -61,7 +61,7 @@ fun changePassword(oldPwd: String, newPwd: String) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.changePassword(oldPwd, newPwd) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success "修改成功,请重新登录".show(BaseApplication.get()) @@ -76,7 +76,7 @@ fun updateVersion() = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.updateVersion() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success versionResultModel.value = gson.fromJson( diff --git a/app/src/main/java/com/casic/app/smartwell/vm/WellViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/WellViewModel.kt index 3d41e9b..9e42e36 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/WellViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/WellViewModel.kt @@ -2,8 +2,7 @@ import androidx.lifecycle.MutableLiveData import com.casic.app.smartwell.base.BaseApplication -import com.casic.app.smartwell.extensions.separateResponseCode -import com.casic.app.smartwell.extensions.toErrorMessage +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.AuthorDeptModel import com.casic.app.smartwell.model.CommonResultModel import com.casic.app.smartwell.model.MapWellListModel @@ -32,7 +31,7 @@ fun countWellByState() = launch({ val response = RetrofitServiceManager.countWellByState() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { val map = HashMap(3) @@ -57,7 +56,7 @@ fun getWellType() = launch({ val response = RetrofitServiceManager.getWellType() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { wellTypeModel.value = gson.fromJson( response, object : TypeToken() {}.type @@ -70,7 +69,7 @@ fun getWellDetail(id: String) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.getWellDetail(id) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success wellDetailModel.value = gson.fromJson( @@ -87,7 +86,7 @@ fun getOperationResult(id: String, state: String) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.getOperationResult(id, state) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success "操作成功".show(BaseApplication.get()) @@ -105,7 +104,7 @@ fun getMonitorResult(id: String) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.getMonitorResult(id) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success monitorModel.value = gson.fromJson( @@ -125,7 +124,7 @@ val response = RetrofitServiceManager.getWellListByPage( keywords, wellType, deptid, bfzt, page ) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { listModel.value = gson.fromJson( response, object : TypeToken() {}.type @@ -137,13 +136,11 @@ fun getWellList() = launch({ val response = RetrofitServiceManager.getWellList() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { totalWellModel.value = gson.fromJson( response, object : TypeToken() {}.type ) - } else { - response.toErrorMessage().show(BaseApplication.get()) } }, { it.printStackTrace() diff --git a/app/src/main/java/com/casic/app/smartwell/widgets/GaoDeClusterMarkerView.kt b/app/src/main/java/com/casic/app/smartwell/widgets/GaoDeClusterMarkerView.kt deleted file mode 100644 index 1f375df..0000000 --- a/app/src/main/java/com/casic/app/smartwell/widgets/GaoDeClusterMarkerView.kt +++ /dev/null @@ -1,100 +0,0 @@ -package com.casic.app.smartwell.widgets - -import android.content.Context -import android.graphics.Bitmap -import android.graphics.Point -import android.view.Gravity -import android.view.LayoutInflater -import android.view.View -import android.widget.TextView -import com.amap.api.maps.Projection -import com.amap.api.maps.model.BitmapDescriptorFactory -import com.amap.api.maps.model.LatLng -import com.amap.api.maps.model.LatLngBounds -import com.amap.api.maps.model.MarkerOptions -import com.casic.app.smartwell.R -import com.pengxh.kt.lite.extensions.toBitmap -import java.util.* - -class GaoDeClusterMarkerView( - private val context: Context, firstMarkers: MarkerOptions, projection: Projection, gridSize: Int -) { - //当前可观区域里的 聚合过之后的集合 - private val includeMarkers: ArrayList - - // 创建区域 - val bounds: LatLngBounds - var options: MarkerOptions = MarkerOptions() - - init { - val screenLocation = projection.toScreenLocation(firstMarkers.position) - //范围类 - val southwestPoint = Point(screenLocation.x - gridSize, screenLocation.y + gridSize) - //范围类 - val northeastPoint = Point(screenLocation.x + gridSize, screenLocation.y - gridSize) - bounds = LatLngBounds( - projection.fromScreenLocation(southwestPoint), - projection.fromScreenLocation(northeastPoint) - ) - //设置初始化marker属性 - options.anchor(0.5f, 1.3f) - .title(firstMarkers.title) - .position(firstMarkers.position) - .icon(firstMarkers.icon) - .snippet(firstMarkers.snippet) - .draggable(false) - includeMarkers = ArrayList() - includeMarkers.add(firstMarkers) - } - - /** - * 添加marker - */ - fun addMarker(markerOptions: MarkerOptions) { - includeMarkers.add(markerOptions) // 添加到列表中 - } - - /** - * 设置聚合点的中心位置以及图标 - */ - fun setPositionAndIcon() { - val size = includeMarkers.size - var lat = 0.0 - var lng = 0.0 - // 一个的时候 - if (size == 1) { //设置marker单个属性 - // 设置marker位置 - options.position( - LatLng( - includeMarkers[0].position.latitude, includeMarkers[0].position.longitude - ) - ) - } else { // 聚合的时候 - //设置marker聚合属性 - for (op in includeMarkers) { - lat += op.position.latitude - lng += op.position.longitude - } - // 设置marker的位置为中心位置为聚集点的平均位置 - options.position(LatLng(lat / size, lng / size)) - } - options.icon(BitmapDescriptorFactory.fromBitmap(getBitmap(size))) - } - - /** - * marker视图 - */ - private fun getBitmap(num: Int): Bitmap? { - val view = LayoutInflater.from(context).inflate(R.layout.marker_gaode, null) - val wellCountView = view.findViewById(R.id.wellCountView) - return if (num > 1) { - wellCountView.visibility = View.VISIBLE - wellCountView.text = String.format("${num}个") - wellCountView.gravity = Gravity.CENTER - view.toBitmap() - } else { - wellCountView.visibility = View.GONE - BitmapDescriptorFactory.fromResource(R.mipmap.well_location).bitmap - } - } -} \ No newline at end of file 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 new file mode 100644 index 0000000..ec455dd --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/widgets/MapWellPopup.kt @@ -0,0 +1,58 @@ +package com.casic.app.smartwell.widgets + +import android.content.Context +import android.view.LayoutInflater +import android.view.ViewGroup +import android.widget.LinearLayout +import android.widget.PopupWindow +import android.widget.TextView +import com.casic.app.smartwell.R +import com.casic.app.smartwell.extensions.valueToType +import com.casic.app.smartwell.model.MapWellListModel + +class MapWellPopup constructor(context: Context) : PopupWindow() { + + init { + width = ViewGroup.LayoutParams.MATCH_PARENT + height = ViewGroup.LayoutParams.WRAP_CONTENT + isOutsideTouchable = true + isFocusable = true + animationStyle = R.style.MapPopupAnimation + setBackgroundDrawable(null) + contentView = LayoutInflater.from(context).inflate( + R.layout.popup_map_info, null, false + ) + } + + fun set(well: MapWellListModel.DataModel, windowClickListener: OnPopupWindowClickListener) { + //反射得到popup里面的控件对象 + val rootView = contentView.findViewById(R.id.rootView) + val wellNameView = contentView.findViewById(R.id.wellNameView) + val wellCodeView = contentView.findViewById(R.id.wellCodeView) + val wellTypeView = contentView.findViewById(R.id.wellTypeView) + val wellStateView = contentView.findViewById(R.id.wellStateView) + val deepView = contentView.findViewById(R.id.deepView) + val locationView = contentView.findViewById(R.id.locationView) + + //绑定数据 + wellNameView.text = String.format("点位名称: ${well.wellName}") + wellCodeView.text = String.format("点位编号: ${well.wellCode}") + wellTypeView.text = String.format("点位类型: ${well.wellType.valueToType()}") + val bfztName = if (well.bfzt == "1") { + "已布防" + } else { + "已撤防" + } + wellStateView.text = String.format("布/撤防状态: $bfztName") + deepView.text = String.format("点位深度: ${well.deep}m") + locationView.text = String.format("详细位置: ${well.position}") + + rootView.setOnClickListener { + windowClickListener.onPopupClicked(well.latGaode.toDouble(), well.lngGaode.toDouble()) + } + } + + interface OnPopupWindowClickListener { + fun onPopupClicked(lat: Double, lng: Double) + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/widgets/cluster/Cluster.java b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/Cluster.java new file mode 100644 index 0000000..9455ccd --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/Cluster.java @@ -0,0 +1,43 @@ +package com.casic.app.smartwell.widgets.cluster; + +import com.amap.api.maps.model.LatLng; +import com.amap.api.maps.model.Marker; + +import java.util.ArrayList; +import java.util.List; + +public class Cluster { + private final LatLng latLng; + private final List clusterItems; + private Marker marker; + + + public Cluster(LatLng latLng) { + this.latLng = latLng; + clusterItems = new ArrayList<>(); + } + + public void addClusterItem(ClusterItem clusterItem) { + clusterItems.add(clusterItem); + } + + public int getClusterCount() { + return clusterItems.size(); + } + + public LatLng getCenterLatLng() { + return latLng; + } + + public void setMarker(Marker marker) { + this.marker = marker; + } + + public Marker getMarker() { + return marker; + } + + public List getClusterItems() { + return clusterItems; + } +} diff --git a/app/src/main/java/com/casic/app/smartwell/widgets/cluster/ClusterItem.java b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/ClusterItem.java new file mode 100644 index 0000000..f5d9a9d --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/ClusterItem.java @@ -0,0 +1,10 @@ +package com.casic.app.smartwell.widgets.cluster; + +import com.amap.api.maps.model.LatLng; + +public interface ClusterItem { + /** + * 返回聚合元素的地理位置 + */ + LatLng getPosition(); +} diff --git a/app/src/main/java/com/casic/app/smartwell/widgets/cluster/ClusterOnClickListener.java b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/ClusterOnClickListener.java new file mode 100644 index 0000000..0efa1f1 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/ClusterOnClickListener.java @@ -0,0 +1,15 @@ +package com.casic.app.smartwell.widgets.cluster; + +import com.amap.api.maps.model.Marker; + +import java.util.List; + +public interface ClusterOnClickListener { + /** + * 点击聚合点的回调处理函数 + * + * @param marker 点击的聚合点 + * @param items 聚合点所包含的元素 + */ + void onMarkerClicked(Marker marker, List items); +} 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 new file mode 100644 index 0000000..40df562 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/ClusterOverlay.java @@ -0,0 +1,349 @@ +package com.casic.app.smartwell.widgets.cluster; + +import android.content.Context; +import android.graphics.Color; +import android.os.Handler; +import android.os.HandlerThread; +import android.os.Looper; +import android.os.Message; +import android.util.TypedValue; +import android.view.Gravity; +import android.widget.TextView; + +import com.amap.api.maps.AMap; +import com.amap.api.maps.AMapUtils; +import com.amap.api.maps.model.BitmapDescriptor; +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.LatLngBounds; +import com.amap.api.maps.model.Marker; +import com.amap.api.maps.model.MarkerOptions; +import com.amap.api.maps.model.animation.AlphaAnimation; +import com.casic.app.smartwell.R; + +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.CopyOnWriteArrayList; + +/** + * 整体设计采用了两个线程,一个线程用于计算组织聚合数据,一个线程负责处理Marker相关操作 + */ +public class ClusterOverlay implements AMap.OnCameraChangeListener, AMap.OnMarkerClickListener { + private final AMap amap; + private final Context context; + private final List clusterItems; + private final List clusters; + private final int clusterSize; + private ClusterOnClickListener clusterClickListener; + private ClusterRender clusterRender; + private final CopyOnWriteArrayList addMarkers = new CopyOnWriteArrayList<>(); + private double clusterDistance; + private final HandlerThread markerHandlerThread = new HandlerThread("addMarker"); + private final HandlerThread signClusterThread = new HandlerThread("calculateCluster"); + private Handler markerHandler; + private Handler signClusterHandler; + private float pxInMeters; + private boolean isCanceled = false; + private final AlphaAnimation addAnimation = new AlphaAnimation(0, 1); + + /** + * 构造函数,批量添加聚合元素时,调用此构造函数 + */ + public ClusterOverlay(Context context, AMap amap, int clusterSize) { + this(context, amap, null, clusterSize); + } + + /** + * 构造函数,批量添加聚合元素时,调用此构造函数 + */ + public ClusterOverlay(Context context, AMap amap, List clusterItems, int clusterSize) { + if (clusterItems != null) { + this.clusterItems = clusterItems; + } else { + this.clusterItems = new ArrayList<>(); + } + this.context = context; + this.clusters = new ArrayList<>(); + this.amap = amap; + this.clusterSize = clusterSize; + this.pxInMeters = amap.getScalePerPixel(); + this.clusterDistance = pxInMeters * clusterSize; + amap.setOnCameraChangeListener(this); + amap.setOnMarkerClickListener(this); + initThreadHandler(); + assignClusters(); + } + + /** + * 设置聚合点的点击事件 + */ + public void setOnClusterClickListener(ClusterOnClickListener clusterClickListener) { + this.clusterClickListener = clusterClickListener; + } + + /** + * 添加一个聚合点 + */ + public void addClusterItem(ClusterItem item) { + Message message = Message.obtain(); + message.what = SignClusterHandler.CALCULATE_SINGLE_CLUSTER; + message.obj = item; + signClusterHandler.sendMessage(message); + } + + /** + * 设置聚合元素的渲染样式,不设置则默认为气泡加数字形式进行渲染 + */ + public void setClusterRender(ClusterRender render) { + this.clusterRender = render; + } + + public void onDestroy() { + isCanceled = true; + signClusterHandler.removeCallbacksAndMessages(null); + markerHandler.removeCallbacksAndMessages(null); + signClusterThread.quit(); + markerHandlerThread.quit(); + for (Marker marker : addMarkers) { + marker.remove(); + } + addMarkers.clear(); + } + + //初始化Handler + private void initThreadHandler() { + markerHandlerThread.start(); + signClusterThread.start(); + markerHandler = new MarkerHandler(markerHandlerThread.getLooper()); + signClusterHandler = new SignClusterHandler(signClusterThread.getLooper()); + } + + @Override + public void onCameraChange(CameraPosition arg0) { + + } + + @Override + public void onCameraChangeFinish(CameraPosition arg0) { + pxInMeters = amap.getScalePerPixel(); + clusterDistance = pxInMeters * clusterSize; + assignClusters(); + } + + @Override + public boolean onMarkerClick(Marker marker) { + if (clusterClickListener == null) { + return true; + } + Cluster cluster = (Cluster) marker.getObject(); + if (cluster != null) { + clusterClickListener.onMarkerClicked(marker, cluster.getClusterItems()); + return true; + } + return false; + } + + /** + * 将聚合元素添加至地图上 + */ + private void addClusterToMap(List clusters) { + ArrayList removeMarkers = new ArrayList<>(addMarkers); + AlphaAnimation alphaAnimation = new AlphaAnimation(1, 0); + RemoveAnimationListener removeAnimationListener = new RemoveAnimationListener(removeMarkers); + for (Marker marker : removeMarkers) { + marker.setAnimation(alphaAnimation); + marker.setAnimationListener(removeAnimationListener); + marker.startAnimation(); + } + + for (Cluster cluster : clusters) { + addSingleClusterToMap(cluster); + } + } + + /** + * 将单个聚合元素添加至地图显示 + */ + private void addSingleClusterToMap(Cluster cluster) { + LatLng latlng = cluster.getCenterLatLng(); + MarkerOptions markerOptions = new MarkerOptions(); + markerOptions.icon(getBitmapDes(cluster.getClusterCount())).position(latlng); + Marker marker = amap.addMarker(markerOptions); + marker.setAnimation(addAnimation); + marker.setObject(cluster); + + marker.startAnimation(); + cluster.setMarker(marker); + addMarkers.add(marker); + } + + private void calculateClusters() { + isCanceled = false; + clusters.clear(); + LatLngBounds visibleBounds = amap.getProjection().getVisibleRegion().latLngBounds; + for (ClusterItem clusterItem : clusterItems) { + if (isCanceled) { + return; + } + LatLng latlng = clusterItem.getPosition(); + if (visibleBounds.contains(latlng)) { + Cluster cluster = getCluster(latlng, clusters); + if (cluster == null) { + cluster = new Cluster(latlng); + clusters.add(cluster); + } + cluster.addClusterItem(clusterItem); + } + } + + //复制一份数据,规避同步 + List tempClusters = new ArrayList<>(clusters); + Message message = Message.obtain(); + message.what = MarkerHandler.ADD_CLUSTER_LIST; + message.obj = tempClusters; + if (isCanceled) { + return; + } + markerHandler.sendMessage(message); + } + + /** + * 对点进行聚合 + */ + private void assignClusters() { + isCanceled = true; + signClusterHandler.removeMessages(SignClusterHandler.CALCULATE_CLUSTER); + signClusterHandler.sendEmptyMessage(SignClusterHandler.CALCULATE_CLUSTER); + } + + /** + * 在已有的聚合基础上,对添加的单个元素进行聚合 + */ + private void calculateSingleCluster(ClusterItem clusterItem) { + LatLngBounds visibleBounds = amap.getProjection().getVisibleRegion().latLngBounds; + LatLng latlng = clusterItem.getPosition(); + if (!visibleBounds.contains(latlng)) { + return; + } + Cluster cluster = getCluster(latlng, clusters); + if (cluster != null) { + cluster.addClusterItem(clusterItem); + Message message = Message.obtain(); + message.what = MarkerHandler.UPDATE_SINGLE_CLUSTER; + + message.obj = cluster; + markerHandler.removeMessages(MarkerHandler.UPDATE_SINGLE_CLUSTER); + markerHandler.sendMessageDelayed(message, 5); + } else { + cluster = new Cluster(latlng); + clusters.add(cluster); + cluster.addClusterItem(clusterItem); + Message message = Message.obtain(); + message.what = MarkerHandler.ADD_SINGLE_CLUSTER; + message.obj = cluster; + markerHandler.sendMessage(message); + } + } + + /** + * 根据一个点获取是否可以依附的聚合点,没有则返回null + */ + private Cluster getCluster(LatLng latLng, List clusters) { + for (Cluster cluster : clusters) { + LatLng clusterCenterPoint = cluster.getCenterLatLng(); + double distance = AMapUtils.calculateLineDistance(latLng, clusterCenterPoint); + if (distance < clusterDistance && amap.getCameraPosition().zoom < 19) { + return cluster; + } + } + return null; + } + + + /** + * 获取每个聚合点的绘制样式 + */ + private BitmapDescriptor getBitmapDes(int num) { + TextView textView = new TextView(context); + if (num > 1) { + String tile = String.valueOf(num); + textView.setText(tile); + } + textView.setGravity(Gravity.CENTER); + textView.setTextColor(Color.BLACK); + textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 15); + if (clusterRender != null && clusterRender.getDrawableByCount(num) != null) { + textView.setBackgroundDrawable(clusterRender.getDrawableByCount(num)); + } else { + textView.setBackgroundResource(R.mipmap.well_location); + } + return BitmapDescriptorFactory.fromView(textView); + } + + /** + * 更新已加入地图聚合点的样式 + */ + private void updateCluster(Cluster cluster) { + Marker marker = cluster.getMarker(); + marker.setIcon(getBitmapDes(cluster.getClusterCount())); + } + + /** + * 处理market添加,更新等操作 + */ + class MarkerHandler extends Handler { + + static final int ADD_CLUSTER_LIST = 0; + + static final int ADD_SINGLE_CLUSTER = 1; + + static final int UPDATE_SINGLE_CLUSTER = 2; + + public MarkerHandler(Looper looper) { + super(looper); + } + + public void handleMessage(Message message) { + switch (message.what) { + case ADD_CLUSTER_LIST: + List clusters = (List) message.obj; + addClusterToMap(clusters); + break; + case ADD_SINGLE_CLUSTER: + Cluster cluster = (Cluster) message.obj; + addSingleClusterToMap(cluster); + break; + case UPDATE_SINGLE_CLUSTER: + Cluster updateCluster = (Cluster) message.obj; + updateCluster(updateCluster); + break; + } + } + } + + /** + * 处理聚合点算法线程 + */ + class SignClusterHandler extends Handler { + static final int CALCULATE_CLUSTER = 0; + static final int CALCULATE_SINGLE_CLUSTER = 1; + + public SignClusterHandler(Looper looper) { + super(looper); + } + + public void handleMessage(Message message) { + switch (message.what) { + case CALCULATE_CLUSTER: + calculateClusters(); + break; + case CALCULATE_SINGLE_CLUSTER: + ClusterItem item = (ClusterItem) message.obj; + clusterItems.add(item); + calculateSingleCluster(item); + break; + } + } + } +} diff --git a/app/src/main/java/com/casic/app/smartwell/widgets/cluster/ClusterRender.java b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/ClusterRender.java new file mode 100644 index 0000000..427ff14 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/ClusterRender.java @@ -0,0 +1,10 @@ +package com.casic.app.smartwell.widgets.cluster; + +import android.graphics.drawable.Drawable; + +public interface ClusterRender { + /** + * 根据聚合点的元素数目返回渲染背景样式 + */ + Drawable getDrawableByCount(int clusterNum); +} diff --git a/app/src/main/java/com/casic/app/smartwell/widgets/cluster/RegionItem.java b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/RegionItem.java new file mode 100644 index 0000000..7b2b6c4 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/RegionItem.java @@ -0,0 +1,23 @@ +package com.casic.app.smartwell.widgets.cluster; + +import com.amap.api.maps.model.LatLng; +import com.casic.app.smartwell.model.MapWellListModel; + +public class RegionItem implements ClusterItem { + private final LatLng latLng; + private final MapWellListModel.DataModel well; + + public RegionItem(LatLng latLng, MapWellListModel.DataModel well) { + this.latLng = latLng; + this.well = well; + } + + @Override + public LatLng getPosition() { + return latLng; + } + + public MapWellListModel.DataModel getWell() { + return well; + } +} diff --git a/app/src/main/java/com/casic/app/smartwell/widgets/cluster/RemoveAnimationListener.java b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/RemoveAnimationListener.java new file mode 100644 index 0000000..c9c5e84 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/RemoveAnimationListener.java @@ -0,0 +1,30 @@ +package com.casic.app.smartwell.widgets.cluster; + +import com.amap.api.maps.model.Marker; +import com.amap.api.maps.model.animation.Animation; + +import java.util.List; + +/** + * marker渐变动画,动画结束后将Marker删除 + */ +public class RemoveAnimationListener implements Animation.AnimationListener { + private final List removeMarkers; + + public RemoveAnimationListener(List removeMarkers) { + this.removeMarkers = removeMarkers; + } + + @Override + public void onAnimationStart() { + + } + + @Override + public void onAnimationEnd() { + for (Marker marker : removeMarkers) { + marker.remove(); + } + removeMarkers.clear(); + } +} \ No newline at end of file diff --git a/app/src/main/res/anim/map_popup_hide.xml b/app/src/main/res/anim/map_popup_hide.xml new file mode 100644 index 0000000..119726b --- /dev/null +++ b/app/src/main/res/anim/map_popup_hide.xml @@ -0,0 +1,12 @@ + + + + \ No newline at end of file diff --git a/app/src/main/res/anim/map_popup_show.xml b/app/src/main/res/anim/map_popup_show.xml new file mode 100644 index 0000000..1d281ef --- /dev/null +++ b/app/src/main/res/anim/map_popup_show.xml @@ -0,0 +1,12 @@ + + + + \ No newline at end of file diff --git a/app/src/main/res/anim/popup_hide.xml b/app/src/main/res/anim/popup_hide.xml index 55c7aca..7480485 100644 --- a/app/src/main/res/anim/popup_hide.xml +++ b/app/src/main/res/anim/popup_hide.xml @@ -1,7 +1,8 @@ - + \ No newline at end of file diff --git a/app/src/main/res/anim/popup_show.xml b/app/src/main/res/anim/popup_show.xml index 1d281ef..dbe2833 100644 --- a/app/src/main/res/anim/popup_show.xml +++ b/app/src/main/res/anim/popup_show.xml @@ -1,12 +1,8 @@ \ No newline at end of file diff --git a/app/src/main/res/drawable/bg_solid_layout_transparent_radius_10.xml b/app/src/main/res/drawable/bg_solid_layout_transparent_radius_10.xml deleted file mode 100644 index 15e6a4b..0000000 --- a/app/src/main/res/drawable/bg_solid_layout_transparent_radius_10.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - \ 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 new file mode 100644 index 0000000..18c1e99 --- /dev/null +++ b/app/src/main/res/drawable/bg_solid_layout_transparent_radius_5.xml @@ -0,0 +1,10 @@ + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/extensions/Int.kt b/app/src/main/java/com/casic/app/smartwell/extensions/Int.kt index de0617b..a0a5e33 100644 --- a/app/src/main/java/com/casic/app/smartwell/extensions/Int.kt +++ b/app/src/main/java/com/casic/app/smartwell/extensions/Int.kt @@ -1,9 +1,24 @@ package com.casic.app.smartwell.extensions +import android.graphics.Bitmap +import android.graphics.Canvas +import android.graphics.Paint +import android.graphics.RectF + fun Int.toLevel(): String { return if (this == 0) { "" } else { this.toString() } +} + +fun Int.drawCircle(color: Int): Bitmap? { + val bitmap = Bitmap.createBitmap(this * 2, this * 2, Bitmap.Config.ARGB_8888) + val canvas = Canvas(bitmap) + val paint = Paint() + val rectF = RectF(0f, 0f, (this * 2).toFloat(), (this * 2).toFloat()) + paint.color = color + canvas.drawArc(rectF, 0f, 360f, true, paint) + return bitmap } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt index 6b6ca3e..5e45534 100644 --- a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt +++ b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt @@ -2,17 +2,13 @@ import android.content.Context import com.casic.app.smartwell.callback.OnImageCompressListener -import com.casic.app.smartwell.model.ErrorMessageModel import com.casic.app.smartwell.utils.LocaleConstant -import com.google.gson.Gson -import com.google.gson.reflect.TypeToken +import com.google.gson.JsonParser import com.pengxh.kt.lite.extensions.createCompressImageDir import com.pengxh.kt.lite.utils.SaveKeyValues -import org.json.JSONObject import top.zibin.luban.Luban import top.zibin.luban.OnCompressListener import java.io.File -import java.util.Locale /** * String扩展方法 @@ -74,18 +70,22 @@ } } -fun String.separateResponseCode(): Int { +fun String.getResponseCode(): Int { if (this.isBlank()) { return 404 } - return JSONObject(this).getInt("code") + val element = JsonParser.parseString(this) + val jsonObject = element.asJsonObject + return jsonObject.get("code").asInt } -fun String.toErrorMessage(): String { - val errorModel = Gson().fromJson( - this, object : TypeToken() {}.type - ) - return errorModel.message.toString() +fun String.getResponseMessage(): String { + if (this.isBlank()) { + return "" + } + val element = JsonParser.parseString(this) + val jsonObject = element.asJsonObject + return jsonObject.get("message").asString } fun String.compressImage(context: Context, listener: OnImageCompressListener) { @@ -93,9 +93,6 @@ .load(this) .ignoreBy(100) .setTargetDir(context.createCompressImageDir().toString()) - .filter { - !(it.isBlank() || it.lowercase(Locale.getDefault()).endsWith(".gif")) - } .setCompressListener(object : OnCompressListener { override fun onStart() { 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 96df110..cd25fca 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 @@ -1,26 +1,25 @@ package com.casic.app.smartwell.fragment -import android.graphics.Point +import android.graphics.Color +import android.graphics.drawable.BitmapDrawable +import android.graphics.drawable.Drawable 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 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.LatLngBounds import com.amap.api.maps.model.Marker -import com.amap.api.maps.model.MarkerOptions import com.casic.app.smartwell.R import com.casic.app.smartwell.databinding.FragmentHomeBinding +import com.casic.app.smartwell.extensions.drawCircle import com.casic.app.smartwell.extensions.initImmersionBar -import com.casic.app.smartwell.extensions.valueToType import com.casic.app.smartwell.model.MapWellListModel import com.casic.app.smartwell.utils.LocaleConstant import com.casic.app.smartwell.utils.RouteOnMap @@ -31,9 +30,16 @@ import com.casic.app.smartwell.view.WellOperationActivity import com.casic.app.smartwell.vm.OrderViewModel import com.casic.app.smartwell.vm.WellViewModel +import com.casic.app.smartwell.widgets.MapWellPopup +import com.casic.app.smartwell.widgets.cluster.ClusterItem +import com.casic.app.smartwell.widgets.cluster.ClusterOnClickListener +import com.casic.app.smartwell.widgets.cluster.ClusterOverlay +import com.casic.app.smartwell.widgets.cluster.RegionItem 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.convertDrawable +import com.pengxh.kt.lite.extensions.dp2px import com.pengxh.kt.lite.extensions.navigatePageTo import com.pengxh.kt.lite.extensions.show import com.pengxh.kt.lite.utils.LoadingDialogHub @@ -43,35 +49,23 @@ /** * 地图点位带聚合效果 * */ -class HomePageHaveClusterFragment : KotlinBaseFragment(), AMap.OnMapLoadedListener, - AMap.OnCameraChangeListener, AMap.OnMarkerClickListener, AMap.InfoWindowAdapter, - AMap.OnInfoWindowClickListener { +class HomePageHaveClusterFragment : KotlinBaseFragment(), + AMap.OnCameraChangeListener { private val kTag = "HaveClusterFragment" private val easyPopupWindow by lazy { EasyPopupWindow(requireContext()) } - private lateinit var wellViewModel: WellViewModel - private lateinit var orderViewModel: OrderViewModel - private lateinit var aMap: AMap - - /** - * 所有的marker - */ - private var allMarkerOptions: MutableList = ArrayList() - - /** - * 视野内的marker - */ - private var markerOptionsInView: MutableList = ArrayList() - - /** - * 自定义Marker弹出框 - * */ - private lateinit var v: View + private val regionRadius by lazy { LocaleConstant.RADIUS_SIZE.dp2px(requireContext()) } + private val infoPopup by lazy { MapWellPopup(requireContext()) } /** * 所有窨井列表信息集合 * */ - private var wellModels: MutableList = ArrayList() + private val wellModels = ArrayList() + private val backDrawables = HashMap() + private lateinit var wellViewModel: WellViewModel + private lateinit var orderViewModel: OrderViewModel + private lateinit var aMap: AMap + private var clusterOverlay: ClusterOverlay? = null override fun initViewBinding( inflater: LayoutInflater, @@ -106,6 +100,9 @@ } }) + //地图初始化 + initMap(savedInstanceState) + //初始化vm wellViewModel = ViewModelProvider(this)[WellViewModel::class.java] orderViewModel = ViewModelProvider(this)[OrderViewModel::class.java] @@ -120,25 +117,19 @@ val latitudeList: MutableList = ArrayList() val longitudeList: MutableList = ArrayList() it.data?.forEach { well -> - val lat = well.latGaode.toString() - val lng = well.lngGaode.toString() + val lat = well.latGaode + val lng = well.lngGaode if (lat.isNotBlank() && lng.isNotBlank()) { //返回true代表当前位置在大陆、港澳地区,反之不在 val latitude = lat.toDouble() val longitude = lng.toDouble() if (CoordinateConverter.isAMapDataAvailable(latitude, longitude)) { - //缓存所有设备详情,点击Marker时候需要 + //缓存所有井 wellModels.add(well) + //分别缓存经、纬度 latitudeList.add(latitude) longitudeList.add(longitude) - //将所有设备信息转化缓存为Marker点 - allMarkerOptions.add( - MarkerOptions() - .position(LatLng(latitude, longitude)) - .title(well.wellTypeName) - .snippet(well.wellName) - ) } } } @@ -160,12 +151,12 @@ val cameraPosition = CameraPosition(centerLatLng, 16f, 0f, 0f) val cameraUpdate = CameraUpdateFactory.newCameraPosition(cameraPosition) aMap.animateCamera(cameraUpdate, 1500, null) + + //显示点数据 + displayWellOnMap() } } - //地图初始化 - initMap(savedInstanceState) - //获取窨井监控数据 wellViewModel.countResultModel.observe(this) { binding.deployedWellView.text = it["bfWell"] @@ -220,17 +211,10 @@ uiSettings.isCompassEnabled = true uiSettings.zoomPosition = AMapOptions.ZOOM_POSITION_RIGHT_CENTER uiSettings.isTiltGesturesEnabled = false//不许地图随手势倾斜角度 + uiSettings.isRotateGesturesEnabled = false//不允许地图随手势改变方位 - // 地图加载成功监听 - aMap.addOnMapLoadedListener(this) // 地图缩放监听 aMap.addOnCameraChangeListener(this) - // marker 点击事件监听 - aMap.addOnMarkerClickListener(this) - // 点击marker弹出自定义popup - aMap.setInfoWindowAdapter(this) - //信息窗点击事件 - aMap.addOnInfoWindowClickListener(this) } override fun initEvent() { @@ -259,9 +243,111 @@ } - override fun onMapLoaded() { - //地图加载成功之后显示聚合点数据 - initClustersMarkers() + private fun displayWellOnMap() { + clusterOverlay?.onDestroy() + val clusterItems = ArrayList() + + wellModels.forEach { + val latitude = it.latGaode.toDouble() + val longitude = it.lngGaode.toDouble() + + val latLng = LatLng(latitude, longitude, false) + val regionItem = RegionItem(latLng, it) + clusterItems.add(regionItem) + } + + clusterOverlay = ClusterOverlay(requireContext(), aMap, clusterItems, regionRadius) + clusterOverlay?.setClusterRender { clusterNum -> + //聚合圆半径 + val radius = 100.dp2px(requireContext()) + if (clusterNum == 0) { + var bitmapDrawable = backDrawables[0] + if (bitmapDrawable == null) { + bitmapDrawable = BitmapDrawable( + null, radius.drawCircle(Color.argb(159, 100, 149, 237)) + ) + backDrawables[0] = bitmapDrawable + } + bitmapDrawable + } + if (clusterNum == 1) { + var bitmapDrawable = backDrawables[1] + if (bitmapDrawable == null) { + bitmapDrawable = R.mipmap.well_location.convertDrawable(requireContext())!! + backDrawables[1] = bitmapDrawable + } + bitmapDrawable + } else if (clusterNum < 5) { + var bitmapDrawable = backDrawables[2] + if (bitmapDrawable == null) { + bitmapDrawable = BitmapDrawable( + null, radius.drawCircle(Color.argb(159, 100, 149, 237)) + ) + backDrawables[2] = bitmapDrawable + } + bitmapDrawable + } else if (clusterNum < 10) { + var bitmapDrawable = backDrawables[3] + if (bitmapDrawable == null) { + bitmapDrawable = BitmapDrawable( + null, radius.drawCircle(Color.argb(199, 30, 144, 255)) + ) + backDrawables[3] = bitmapDrawable + } + bitmapDrawable + } else { + var bitmapDrawable = backDrawables[4] + if (bitmapDrawable == null) { + bitmapDrawable = BitmapDrawable( + null, radius.drawCircle(Color.argb(235, 65, 105, 225)) + ) + backDrawables[4] = bitmapDrawable + } + bitmapDrawable + } + } + + clusterOverlay?.setOnClusterClickListener(object : ClusterOnClickListener { + override fun onMarkerClicked(marker: Marker?, items: List) { + if (items.size > 1) { + "请缩放地图比例在查看数据".show(requireContext()) + return + } + + var item: RegionItem? = null + val builder = LatLngBounds.Builder() + for (clusterItem in items) { + builder.include(clusterItem.position) + item = clusterItem as RegionItem + } + + item?.apply { + showWellPopup(well) + } + } + }) + } + + private fun showWellPopup(well: MapWellListModel.DataModel) { + infoPopup.set(well, object : MapWellPopup.OnPopupWindowClickListener { + override fun onPopupClicked(lat: Double, lng: Double) { + AlertControlDialog.Builder().setContext(requireContext()).setTitle("操作提示") + .setMessage("确定要前往吗").setNegativeButton("取消").setPositiveButton("确定") + .setOnDialogButtonClickListener(object : + AlertControlDialog.OnDialogButtonClickListener { + override fun onConfirmClick() { + RouteOnMap.startNavigation( + requireContext(), "", LatLng(lat, lng) + ) + } + + override fun onCancelClick() { + + } + }).build().show() + } + }) + infoPopup.showAsDropDown(binding.rightOptionView) } override fun onCameraChange(p0: CameraPosition?) { @@ -282,103 +368,10 @@ } } - //获取视野内的marker 根据聚合算法合成自定义的marker 显示视野内的marker override fun onCameraChangeFinish(p0: CameraPosition?) { //地图缩放之后显示聚合点数据 LoadingDialogHub.dismiss() httpCountDownTimer.cancel() - initClustersMarkers() - } - - private fun initClustersMarkers() { - 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 { - v = LayoutInflater.from(requireContext()).inflate(R.layout.popup_map_info, null) - - //显示闸井信息 - marker?.showInfoWindow() - return true - } - - override fun getInfoWindow(marker: Marker?): View { - //反射得到popup里面的控件对象 - val wellNameView = v.findViewById(R.id.wellNameView) - val wellCodeView = v.findViewById(R.id.wellCodeView) - val wellTypeView = v.findViewById(R.id.wellTypeView) - val wellStateView = v.findViewById(R.id.wellStateView) - val deepView = v.findViewById(R.id.deepView) - val locationView = v.findViewById(R.id.locationView) - - //绑定数据 - val clickedLatLng = marker?.position!! - wellModels.forEach { well -> - if (clickedLatLng.latitude == well.latGaode!!.toDouble() - && clickedLatLng.longitude == well.lngGaode!!.toDouble() - ) { - wellNameView.text = String.format("点位名称: ${well.wellName}") - wellCodeView.text = String.format("点位编号: ${well.wellCode}") - wellTypeView.text = String.format("点位类型: ${well.wellType.valueToType()}") - val bfztName = if (well.bfzt == "1") { - "已布防" - } else { - "已撤防" - } - wellStateView.text = String.format("布/撤防状态: $bfztName") - deepView.text = String.format("点位深度: ${well.deep}m") - locationView.text = String.format("详细位置: ${well.position}") - } - } - return v - } - - /** - * 此方法不能修改整个 InfoWindow 的背景和边框,无论自定义的样式是什么样,SDK 都会在最外层添加一个默认的边框 - * */ - override fun getInfoContents(p0: Marker?): View? = null - - override fun onInfoWindowClick(p0: Marker?) { - p0?.apply { - AlertControlDialog.Builder() - .setContext(requireContext()) - .setTitle("操作提示") - .setMessage("确定要前往吗") - .setNegativeButton("取消") - .setPositiveButton("确定") - .setOnDialogButtonClickListener(object : - AlertControlDialog.OnDialogButtonClickListener { - override fun onConfirmClick() { - val lat = position.latitude.toString() - val lng = position.longitude.toString() - if (lat.isBlank() || lng.isBlank()) { - "点位经纬度异常,无法开启导航".show(requireContext()) - return - } - RouteOnMap.startNavigation( - requireContext(), snippet, LatLng(lat.toDouble(), lng.toDouble()) - ) - } - - override fun onCancelClick() { - - } - }).build().show() - } } /***以下是地图生命周期管理************************************************************************/ 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 a54d213..bfa7a57 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 @@ -44,8 +44,8 @@ * 地图点位不带聚合效果 * */ class HomePageNoClusterFragment : KotlinBaseFragment(), - AMap.OnMapLoadedListener, AMap.OnCameraChangeListener, AMap.OnMarkerClickListener, - AMap.InfoWindowAdapter, AMap.OnInfoWindowClickListener { + AMap.OnCameraChangeListener, AMap.OnMarkerClickListener, AMap.InfoWindowAdapter, + AMap.OnInfoWindowClickListener { private val kTag = "NoClusterFragment" private val easyPopupWindow by lazy { EasyPopupWindow(requireContext()) } @@ -109,6 +109,9 @@ wellViewModel = ViewModelProvider(this)[WellViewModel::class.java] orderViewModel = ViewModelProvider(this)[OrderViewModel::class.java] + //地图初始化 + initMap(savedInstanceState) + //获取所有窨井数据 httpCountDownTimer.start() LoadingDialogHub.show(requireActivity(), "数据加载中,请稍后...") @@ -157,12 +160,12 @@ val cameraPosition = CameraPosition(centerLatLng, 16f, 0f, 0f) val cameraUpdate = CameraUpdateFactory.newCameraPosition(cameraPosition) aMap.animateCamera(cameraUpdate, 1500, null) + + //显示点数据 + displayWellOnMap() } } - //地图初始化 - initMap(savedInstanceState) - //获取窨井监控数据 wellViewModel.countResultModel.observe(this) { binding.deployedWellView.text = it["bfWell"] @@ -214,9 +217,8 @@ uiSettings.isCompassEnabled = true uiSettings.zoomPosition = AMapOptions.ZOOM_POSITION_RIGHT_CENTER uiSettings.isTiltGesturesEnabled = false//不许地图随手势倾斜角度 + uiSettings.isRotateGesturesEnabled = false//不允许地图随手势改变方位 - // 地图加载成功监听 - aMap.addOnMapLoadedListener(this) // 地图缩放监听 aMap.addOnCameraChangeListener(this) // marker 点击事件监听 @@ -253,11 +255,6 @@ } - override fun onMapLoaded() { - //地图加载成功之后显示聚合点数据 - initClustersMarkers() - } - override fun onCameraChange(p0: CameraPosition?) { } @@ -281,10 +278,9 @@ //地图缩放之后显示聚合点数据 LoadingDialogHub.dismiss() httpCountDownTimer.cancel() - initClustersMarkers() } - private fun initClustersMarkers() { + private fun displayWellOnMap() { val proj = aMap.projection val dm = resources.displayMetrics var screenLocation: Point diff --git a/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.java b/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.java deleted file mode 100644 index d8b18ef..0000000 --- a/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.java +++ /dev/null @@ -1,50 +0,0 @@ -package com.casic.app.smartwell.model; - -public class ErrorMessageModel { - - private int code; - private String data; - private String exceptionClazz; - private String message; - private boolean success; - - public int getCode() { - return code; - } - - public void setCode(int code) { - this.code = code; - } - - public String getData() { - return data; - } - - public void setData(String data) { - this.data = data; - } - - public String getExceptionClazz() { - return exceptionClazz; - } - - public void setExceptionClazz(String exceptionClazz) { - this.exceptionClazz = exceptionClazz; - } - - public String getMessage() { - return message; - } - - public void setMessage(String message) { - this.message = message; - } - - public boolean isSuccess() { - return success; - } - - public void setSuccess(boolean success) { - this.success = success; - } -} \ No newline at end of file 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 new file mode 100644 index 0000000..215ac0c --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/PipelineModel.java @@ -0,0 +1,328 @@ +package com.casic.app.smartwell.model; + +import java.util.List; + +public class PipelineModel { + + private Integer code; + private DataModel data; + private String message; + private Boolean success; + + public Integer getCode() { + return code; + } + + public void setCode(Integer code) { + this.code = code; + } + + public DataModel getData() { + return data; + } + + public void setData(DataModel data) { + this.data = data; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + public Boolean getSuccess() { + return success; + } + + public void setSuccess(Boolean success) { + this.success = success; + } + + public static class DataModel { + private List rows; + private Integer total; + + public List getRows() { + return rows; + } + + public void setRows(List rows) { + this.rows = rows; + } + + public Integer getTotal() { + return total; + } + + public void setTotal(Integer total) { + this.total = total; + } + + 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 getBuryMode() { + return buryMode; + } + + public void setBuryMode(String buryMode) { + this.buryMode = buryMode; + } + + public String getConstructEra() { + return constructEra; + } + + public void setConstructEra(String constructEra) { + this.constructEra = constructEra; + } + + 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; + } + } + } +} 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 06d3d2b..4f38a2c 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 = 100 //相距多少米才聚合,单位:米 + const val RADIUS_SIZE = 80 //相距多少米才聚合,单位:米 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:11308" + // 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 0d5f3fa..991e1db 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 @@ -312,4 +312,14 @@ @Header("token") token: String, @Field("clientid") deviceCode: String ): String + + /** + * 管线位置数据 + */ + @GET("/pipeline/listPage") + suspend fun getPipeline( + @Header("token") token: String, + @Query("limit") limit: Int, + @Query("offset") offset: Int + ): String } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt index 1a0ce22..4050067 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt @@ -294,4 +294,11 @@ suspend fun registerPush(clientId: String): String { return api.registerPush(AuthenticationHelper.token!!, clientId) } + + /** + * 管线位置数据 + */ + suspend fun getPipeline(): String { + return api.getPipeline(AuthenticationHelper.token!!, 2000, 1) + } } \ No newline at end of file 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 9270fa1..4ca5a5e 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.HomePageNoClusterFragment +import com.casic.app.smartwell.fragment.HomePageHaveClusterFragment 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/vm/AlarmViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/AlarmViewModel.kt index 9cff08c..e7acc17 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/AlarmViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/AlarmViewModel.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.AlarmContentModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager import com.google.gson.Gson @@ -16,7 +16,7 @@ fun getAlarmContentType(alarmType: String) = launch({ val response = RetrofitServiceManager.getAlarmContentType(alarmType) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { listModel.value = gson.fromJson( response, object : TypeToken() {}.type diff --git a/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt index 5e5b163..895dedd 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.PublicKeyModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager import com.google.gson.Gson @@ -18,7 +18,7 @@ fun getPublicKey() = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.authenticate() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { keyModel.value = gson.fromJson( response, object : TypeToken() {}.type diff --git a/app/src/main/java/com/casic/app/smartwell/vm/DeviceViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/DeviceViewModel.kt index db5ccf6..899a962 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/DeviceViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/DeviceViewModel.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.DeviceDetailModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager import com.google.gson.Gson @@ -16,7 +16,7 @@ fun getDeviceDetail(deviceCode: String) = launch({ val response = RetrofitServiceManager.getDeviceDetail(deviceCode) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { detailModel.value = gson.fromJson( response, object : TypeToken() {}.type diff --git a/app/src/main/java/com/casic/app/smartwell/vm/LoginViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/LoginViewModel.kt index cd8b8a9..a417398 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/LoginViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/LoginViewModel.kt @@ -2,7 +2,7 @@ import androidx.lifecycle.MutableLiveData import com.casic.app.smartwell.base.BaseApplication -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.CommonResultModel import com.casic.app.smartwell.model.LoginResultModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -21,7 +21,7 @@ fun enter(account: String, secretKey: String) = launch({ val response = RetrofitServiceManager.login(account, secretKey) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success enterResultModel.value = gson.fromJson( @@ -38,7 +38,7 @@ fun out() = launch({ val response = RetrofitServiceManager.loginOut() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { outResultModel.value = gson.fromJson( response, object : TypeToken() {}.type diff --git a/app/src/main/java/com/casic/app/smartwell/vm/OperationViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/OperationViewModel.kt index 8943ed3..37e115f 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/OperationViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/OperationViewModel.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.vm import com.casic.app.smartwell.base.BaseApplication -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager import com.pengxh.kt.lite.base.BaseViewModel import com.pengxh.kt.lite.extensions.launch @@ -16,7 +16,7 @@ fun acceptWorkOrder(id: String) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.acceptWorkOrder(id) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success "接单成功".show(BaseApplication.get()) @@ -35,7 +35,7 @@ loadState.value = LoadState.Loading val response = RetrofitServiceManager.confirmWorkOrder(id, firstState, firstStatePhotos, needHandle) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success "工单确认成功".show(BaseApplication.get()) @@ -50,7 +50,7 @@ fun transferWorkOrder(id: String, userId: String) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.transferWorkOrder(id, userId) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success "转单成功".show(BaseApplication.get()) @@ -65,7 +65,7 @@ fun completeWorkOrder(id: String, handleMessage: String, handlePhotos: String) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.completeWorkOrder(id, handleMessage, handlePhotos) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success "工单处理成功".show(BaseApplication.get()) diff --git a/app/src/main/java/com/casic/app/smartwell/vm/OrderViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/OrderViewModel.kt index 4cb26b7..d2fad86 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/OrderViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/OrderViewModel.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.OrderDetailModel import com.casic.app.smartwell.model.OrderListModel import com.casic.app.smartwell.model.OrderStatusModel @@ -37,7 +37,7 @@ val response = RetrofitServiceManager.getSearchResult( keywords, alarmContent, alarmLevel, jobStatus, deptId, beginTime, endTime, offset ) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success searchResult.value = gson.fromJson( @@ -53,7 +53,7 @@ fun getWorkOrderListByState(jobStatus: String, page: Int) = launch({ val response = RetrofitServiceManager.getWorkOrderList(jobStatus, page) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { orderList.value = gson.fromJson( response, object : TypeToken() {}.type @@ -65,7 +65,7 @@ fun getNotAcceptOderList(page: Int) = launch({ val response = RetrofitServiceManager.getNotAcceptOderList(page) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { orderList.value = gson.fromJson( response, object : TypeToken() {}.type @@ -77,7 +77,7 @@ fun getNotHandleOderList(page: Int) = launch({ val response = RetrofitServiceManager.getNotHandleOderList(page) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { orderList.value = gson.fromJson( response, object : TypeToken() {}.type @@ -89,7 +89,7 @@ fun countWorkOrderByState() = launch({ val response = RetrofitServiceManager.countWorkOrderByState() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { val map = HashMap(4) @@ -107,7 +107,7 @@ fun getOrderStatus() = launch({ val response = RetrofitServiceManager.getOrderStatus() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { orderStatusModel.value = gson.fromJson( response, object : TypeToken() {}.type @@ -120,7 +120,7 @@ fun getWorkOrderDetail(id: String) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.getWorkOrderDetail(id) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success detailModel.value = gson.fromJson( diff --git a/app/src/main/java/com/casic/app/smartwell/vm/PipelineViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/PipelineViewModel.kt new file mode 100644 index 0000000..60c1e2f --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/vm/PipelineViewModel.kt @@ -0,0 +1,28 @@ +package com.casic.app.smartwell.vm + +import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.extensions.getResponseCode +import com.casic.app.smartwell.model.PipelineModel +import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken +import com.pengxh.kt.lite.base.BaseViewModel +import com.pengxh.kt.lite.extensions.launch + +class PipelineViewModel : BaseViewModel() { + + private val gson by lazy { Gson() } + val lineResult = MutableLiveData() + + fun getPipeline() = launch({ + val response = RetrofitServiceManager.getPipeline() + val responseCode = response.getResponseCode() + if (responseCode == 200) { + lineResult.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } + }, { + it.printStackTrace() + }) +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/PushViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/PushViewModel.kt index 9279815..12fd610 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/PushViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/PushViewModel.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.CommonResultModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager import com.google.gson.Gson @@ -16,7 +16,7 @@ fun registerPush(clientId: String) = launch({ val response = RetrofitServiceManager.registerPush(clientId) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { registerResultModel.value = gson.fromJson( response, object : TypeToken() {}.type diff --git a/app/src/main/java/com/casic/app/smartwell/vm/UploadImageViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/UploadImageViewModel.kt index 8d6744e..9707eeb 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/UploadImageViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/UploadImageViewModel.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.CommonResultModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager import com.google.gson.Gson @@ -19,7 +19,7 @@ fun uploadImage(image: File) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.uploadImage(image) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success resultModel.value = gson.fromJson( diff --git a/app/src/main/java/com/casic/app/smartwell/vm/UserViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/UserViewModel.kt index 31a4d4c..070c35a 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/UserViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/UserViewModel.kt @@ -2,7 +2,7 @@ import androidx.lifecycle.MutableLiveData import com.casic.app.smartwell.base.BaseApplication -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.SubordinateModel import com.casic.app.smartwell.model.UserDetailModel import com.casic.app.smartwell.model.VersionResultModel @@ -25,7 +25,7 @@ fun getUserDetail() = launch({ val response = RetrofitServiceManager.getUserDetail() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { val userDetail = gson.fromJson( response, object : TypeToken() {}.type @@ -48,7 +48,7 @@ * */ fun getSubordinate(hasMine: String?, deptId: String?, roleTips: String?) = launch({ val response = RetrofitServiceManager.getSubordinate(hasMine, deptId, roleTips) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { subordinateModel.value = gson.fromJson( response, object : TypeToken() {}.type @@ -61,7 +61,7 @@ fun changePassword(oldPwd: String, newPwd: String) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.changePassword(oldPwd, newPwd) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success "修改成功,请重新登录".show(BaseApplication.get()) @@ -76,7 +76,7 @@ fun updateVersion() = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.updateVersion() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success versionResultModel.value = gson.fromJson( diff --git a/app/src/main/java/com/casic/app/smartwell/vm/WellViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/WellViewModel.kt index 3d41e9b..9e42e36 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/WellViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/WellViewModel.kt @@ -2,8 +2,7 @@ import androidx.lifecycle.MutableLiveData import com.casic.app.smartwell.base.BaseApplication -import com.casic.app.smartwell.extensions.separateResponseCode -import com.casic.app.smartwell.extensions.toErrorMessage +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.AuthorDeptModel import com.casic.app.smartwell.model.CommonResultModel import com.casic.app.smartwell.model.MapWellListModel @@ -32,7 +31,7 @@ fun countWellByState() = launch({ val response = RetrofitServiceManager.countWellByState() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { val map = HashMap(3) @@ -57,7 +56,7 @@ fun getWellType() = launch({ val response = RetrofitServiceManager.getWellType() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { wellTypeModel.value = gson.fromJson( response, object : TypeToken() {}.type @@ -70,7 +69,7 @@ fun getWellDetail(id: String) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.getWellDetail(id) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success wellDetailModel.value = gson.fromJson( @@ -87,7 +86,7 @@ fun getOperationResult(id: String, state: String) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.getOperationResult(id, state) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success "操作成功".show(BaseApplication.get()) @@ -105,7 +104,7 @@ fun getMonitorResult(id: String) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.getMonitorResult(id) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success monitorModel.value = gson.fromJson( @@ -125,7 +124,7 @@ val response = RetrofitServiceManager.getWellListByPage( keywords, wellType, deptid, bfzt, page ) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { listModel.value = gson.fromJson( response, object : TypeToken() {}.type @@ -137,13 +136,11 @@ fun getWellList() = launch({ val response = RetrofitServiceManager.getWellList() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { totalWellModel.value = gson.fromJson( response, object : TypeToken() {}.type ) - } else { - response.toErrorMessage().show(BaseApplication.get()) } }, { it.printStackTrace() diff --git a/app/src/main/java/com/casic/app/smartwell/widgets/GaoDeClusterMarkerView.kt b/app/src/main/java/com/casic/app/smartwell/widgets/GaoDeClusterMarkerView.kt deleted file mode 100644 index 1f375df..0000000 --- a/app/src/main/java/com/casic/app/smartwell/widgets/GaoDeClusterMarkerView.kt +++ /dev/null @@ -1,100 +0,0 @@ -package com.casic.app.smartwell.widgets - -import android.content.Context -import android.graphics.Bitmap -import android.graphics.Point -import android.view.Gravity -import android.view.LayoutInflater -import android.view.View -import android.widget.TextView -import com.amap.api.maps.Projection -import com.amap.api.maps.model.BitmapDescriptorFactory -import com.amap.api.maps.model.LatLng -import com.amap.api.maps.model.LatLngBounds -import com.amap.api.maps.model.MarkerOptions -import com.casic.app.smartwell.R -import com.pengxh.kt.lite.extensions.toBitmap -import java.util.* - -class GaoDeClusterMarkerView( - private val context: Context, firstMarkers: MarkerOptions, projection: Projection, gridSize: Int -) { - //当前可观区域里的 聚合过之后的集合 - private val includeMarkers: ArrayList - - // 创建区域 - val bounds: LatLngBounds - var options: MarkerOptions = MarkerOptions() - - init { - val screenLocation = projection.toScreenLocation(firstMarkers.position) - //范围类 - val southwestPoint = Point(screenLocation.x - gridSize, screenLocation.y + gridSize) - //范围类 - val northeastPoint = Point(screenLocation.x + gridSize, screenLocation.y - gridSize) - bounds = LatLngBounds( - projection.fromScreenLocation(southwestPoint), - projection.fromScreenLocation(northeastPoint) - ) - //设置初始化marker属性 - options.anchor(0.5f, 1.3f) - .title(firstMarkers.title) - .position(firstMarkers.position) - .icon(firstMarkers.icon) - .snippet(firstMarkers.snippet) - .draggable(false) - includeMarkers = ArrayList() - includeMarkers.add(firstMarkers) - } - - /** - * 添加marker - */ - fun addMarker(markerOptions: MarkerOptions) { - includeMarkers.add(markerOptions) // 添加到列表中 - } - - /** - * 设置聚合点的中心位置以及图标 - */ - fun setPositionAndIcon() { - val size = includeMarkers.size - var lat = 0.0 - var lng = 0.0 - // 一个的时候 - if (size == 1) { //设置marker单个属性 - // 设置marker位置 - options.position( - LatLng( - includeMarkers[0].position.latitude, includeMarkers[0].position.longitude - ) - ) - } else { // 聚合的时候 - //设置marker聚合属性 - for (op in includeMarkers) { - lat += op.position.latitude - lng += op.position.longitude - } - // 设置marker的位置为中心位置为聚集点的平均位置 - options.position(LatLng(lat / size, lng / size)) - } - options.icon(BitmapDescriptorFactory.fromBitmap(getBitmap(size))) - } - - /** - * marker视图 - */ - private fun getBitmap(num: Int): Bitmap? { - val view = LayoutInflater.from(context).inflate(R.layout.marker_gaode, null) - val wellCountView = view.findViewById(R.id.wellCountView) - return if (num > 1) { - wellCountView.visibility = View.VISIBLE - wellCountView.text = String.format("${num}个") - wellCountView.gravity = Gravity.CENTER - view.toBitmap() - } else { - wellCountView.visibility = View.GONE - BitmapDescriptorFactory.fromResource(R.mipmap.well_location).bitmap - } - } -} \ No newline at end of file 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 new file mode 100644 index 0000000..ec455dd --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/widgets/MapWellPopup.kt @@ -0,0 +1,58 @@ +package com.casic.app.smartwell.widgets + +import android.content.Context +import android.view.LayoutInflater +import android.view.ViewGroup +import android.widget.LinearLayout +import android.widget.PopupWindow +import android.widget.TextView +import com.casic.app.smartwell.R +import com.casic.app.smartwell.extensions.valueToType +import com.casic.app.smartwell.model.MapWellListModel + +class MapWellPopup constructor(context: Context) : PopupWindow() { + + init { + width = ViewGroup.LayoutParams.MATCH_PARENT + height = ViewGroup.LayoutParams.WRAP_CONTENT + isOutsideTouchable = true + isFocusable = true + animationStyle = R.style.MapPopupAnimation + setBackgroundDrawable(null) + contentView = LayoutInflater.from(context).inflate( + R.layout.popup_map_info, null, false + ) + } + + fun set(well: MapWellListModel.DataModel, windowClickListener: OnPopupWindowClickListener) { + //反射得到popup里面的控件对象 + val rootView = contentView.findViewById(R.id.rootView) + val wellNameView = contentView.findViewById(R.id.wellNameView) + val wellCodeView = contentView.findViewById(R.id.wellCodeView) + val wellTypeView = contentView.findViewById(R.id.wellTypeView) + val wellStateView = contentView.findViewById(R.id.wellStateView) + val deepView = contentView.findViewById(R.id.deepView) + val locationView = contentView.findViewById(R.id.locationView) + + //绑定数据 + wellNameView.text = String.format("点位名称: ${well.wellName}") + wellCodeView.text = String.format("点位编号: ${well.wellCode}") + wellTypeView.text = String.format("点位类型: ${well.wellType.valueToType()}") + val bfztName = if (well.bfzt == "1") { + "已布防" + } else { + "已撤防" + } + wellStateView.text = String.format("布/撤防状态: $bfztName") + deepView.text = String.format("点位深度: ${well.deep}m") + locationView.text = String.format("详细位置: ${well.position}") + + rootView.setOnClickListener { + windowClickListener.onPopupClicked(well.latGaode.toDouble(), well.lngGaode.toDouble()) + } + } + + interface OnPopupWindowClickListener { + fun onPopupClicked(lat: Double, lng: Double) + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/widgets/cluster/Cluster.java b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/Cluster.java new file mode 100644 index 0000000..9455ccd --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/Cluster.java @@ -0,0 +1,43 @@ +package com.casic.app.smartwell.widgets.cluster; + +import com.amap.api.maps.model.LatLng; +import com.amap.api.maps.model.Marker; + +import java.util.ArrayList; +import java.util.List; + +public class Cluster { + private final LatLng latLng; + private final List clusterItems; + private Marker marker; + + + public Cluster(LatLng latLng) { + this.latLng = latLng; + clusterItems = new ArrayList<>(); + } + + public void addClusterItem(ClusterItem clusterItem) { + clusterItems.add(clusterItem); + } + + public int getClusterCount() { + return clusterItems.size(); + } + + public LatLng getCenterLatLng() { + return latLng; + } + + public void setMarker(Marker marker) { + this.marker = marker; + } + + public Marker getMarker() { + return marker; + } + + public List getClusterItems() { + return clusterItems; + } +} diff --git a/app/src/main/java/com/casic/app/smartwell/widgets/cluster/ClusterItem.java b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/ClusterItem.java new file mode 100644 index 0000000..f5d9a9d --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/ClusterItem.java @@ -0,0 +1,10 @@ +package com.casic.app.smartwell.widgets.cluster; + +import com.amap.api.maps.model.LatLng; + +public interface ClusterItem { + /** + * 返回聚合元素的地理位置 + */ + LatLng getPosition(); +} diff --git a/app/src/main/java/com/casic/app/smartwell/widgets/cluster/ClusterOnClickListener.java b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/ClusterOnClickListener.java new file mode 100644 index 0000000..0efa1f1 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/ClusterOnClickListener.java @@ -0,0 +1,15 @@ +package com.casic.app.smartwell.widgets.cluster; + +import com.amap.api.maps.model.Marker; + +import java.util.List; + +public interface ClusterOnClickListener { + /** + * 点击聚合点的回调处理函数 + * + * @param marker 点击的聚合点 + * @param items 聚合点所包含的元素 + */ + void onMarkerClicked(Marker marker, List items); +} 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 new file mode 100644 index 0000000..40df562 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/ClusterOverlay.java @@ -0,0 +1,349 @@ +package com.casic.app.smartwell.widgets.cluster; + +import android.content.Context; +import android.graphics.Color; +import android.os.Handler; +import android.os.HandlerThread; +import android.os.Looper; +import android.os.Message; +import android.util.TypedValue; +import android.view.Gravity; +import android.widget.TextView; + +import com.amap.api.maps.AMap; +import com.amap.api.maps.AMapUtils; +import com.amap.api.maps.model.BitmapDescriptor; +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.LatLngBounds; +import com.amap.api.maps.model.Marker; +import com.amap.api.maps.model.MarkerOptions; +import com.amap.api.maps.model.animation.AlphaAnimation; +import com.casic.app.smartwell.R; + +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.CopyOnWriteArrayList; + +/** + * 整体设计采用了两个线程,一个线程用于计算组织聚合数据,一个线程负责处理Marker相关操作 + */ +public class ClusterOverlay implements AMap.OnCameraChangeListener, AMap.OnMarkerClickListener { + private final AMap amap; + private final Context context; + private final List clusterItems; + private final List clusters; + private final int clusterSize; + private ClusterOnClickListener clusterClickListener; + private ClusterRender clusterRender; + private final CopyOnWriteArrayList addMarkers = new CopyOnWriteArrayList<>(); + private double clusterDistance; + private final HandlerThread markerHandlerThread = new HandlerThread("addMarker"); + private final HandlerThread signClusterThread = new HandlerThread("calculateCluster"); + private Handler markerHandler; + private Handler signClusterHandler; + private float pxInMeters; + private boolean isCanceled = false; + private final AlphaAnimation addAnimation = new AlphaAnimation(0, 1); + + /** + * 构造函数,批量添加聚合元素时,调用此构造函数 + */ + public ClusterOverlay(Context context, AMap amap, int clusterSize) { + this(context, amap, null, clusterSize); + } + + /** + * 构造函数,批量添加聚合元素时,调用此构造函数 + */ + public ClusterOverlay(Context context, AMap amap, List clusterItems, int clusterSize) { + if (clusterItems != null) { + this.clusterItems = clusterItems; + } else { + this.clusterItems = new ArrayList<>(); + } + this.context = context; + this.clusters = new ArrayList<>(); + this.amap = amap; + this.clusterSize = clusterSize; + this.pxInMeters = amap.getScalePerPixel(); + this.clusterDistance = pxInMeters * clusterSize; + amap.setOnCameraChangeListener(this); + amap.setOnMarkerClickListener(this); + initThreadHandler(); + assignClusters(); + } + + /** + * 设置聚合点的点击事件 + */ + public void setOnClusterClickListener(ClusterOnClickListener clusterClickListener) { + this.clusterClickListener = clusterClickListener; + } + + /** + * 添加一个聚合点 + */ + public void addClusterItem(ClusterItem item) { + Message message = Message.obtain(); + message.what = SignClusterHandler.CALCULATE_SINGLE_CLUSTER; + message.obj = item; + signClusterHandler.sendMessage(message); + } + + /** + * 设置聚合元素的渲染样式,不设置则默认为气泡加数字形式进行渲染 + */ + public void setClusterRender(ClusterRender render) { + this.clusterRender = render; + } + + public void onDestroy() { + isCanceled = true; + signClusterHandler.removeCallbacksAndMessages(null); + markerHandler.removeCallbacksAndMessages(null); + signClusterThread.quit(); + markerHandlerThread.quit(); + for (Marker marker : addMarkers) { + marker.remove(); + } + addMarkers.clear(); + } + + //初始化Handler + private void initThreadHandler() { + markerHandlerThread.start(); + signClusterThread.start(); + markerHandler = new MarkerHandler(markerHandlerThread.getLooper()); + signClusterHandler = new SignClusterHandler(signClusterThread.getLooper()); + } + + @Override + public void onCameraChange(CameraPosition arg0) { + + } + + @Override + public void onCameraChangeFinish(CameraPosition arg0) { + pxInMeters = amap.getScalePerPixel(); + clusterDistance = pxInMeters * clusterSize; + assignClusters(); + } + + @Override + public boolean onMarkerClick(Marker marker) { + if (clusterClickListener == null) { + return true; + } + Cluster cluster = (Cluster) marker.getObject(); + if (cluster != null) { + clusterClickListener.onMarkerClicked(marker, cluster.getClusterItems()); + return true; + } + return false; + } + + /** + * 将聚合元素添加至地图上 + */ + private void addClusterToMap(List clusters) { + ArrayList removeMarkers = new ArrayList<>(addMarkers); + AlphaAnimation alphaAnimation = new AlphaAnimation(1, 0); + RemoveAnimationListener removeAnimationListener = new RemoveAnimationListener(removeMarkers); + for (Marker marker : removeMarkers) { + marker.setAnimation(alphaAnimation); + marker.setAnimationListener(removeAnimationListener); + marker.startAnimation(); + } + + for (Cluster cluster : clusters) { + addSingleClusterToMap(cluster); + } + } + + /** + * 将单个聚合元素添加至地图显示 + */ + private void addSingleClusterToMap(Cluster cluster) { + LatLng latlng = cluster.getCenterLatLng(); + MarkerOptions markerOptions = new MarkerOptions(); + markerOptions.icon(getBitmapDes(cluster.getClusterCount())).position(latlng); + Marker marker = amap.addMarker(markerOptions); + marker.setAnimation(addAnimation); + marker.setObject(cluster); + + marker.startAnimation(); + cluster.setMarker(marker); + addMarkers.add(marker); + } + + private void calculateClusters() { + isCanceled = false; + clusters.clear(); + LatLngBounds visibleBounds = amap.getProjection().getVisibleRegion().latLngBounds; + for (ClusterItem clusterItem : clusterItems) { + if (isCanceled) { + return; + } + LatLng latlng = clusterItem.getPosition(); + if (visibleBounds.contains(latlng)) { + Cluster cluster = getCluster(latlng, clusters); + if (cluster == null) { + cluster = new Cluster(latlng); + clusters.add(cluster); + } + cluster.addClusterItem(clusterItem); + } + } + + //复制一份数据,规避同步 + List tempClusters = new ArrayList<>(clusters); + Message message = Message.obtain(); + message.what = MarkerHandler.ADD_CLUSTER_LIST; + message.obj = tempClusters; + if (isCanceled) { + return; + } + markerHandler.sendMessage(message); + } + + /** + * 对点进行聚合 + */ + private void assignClusters() { + isCanceled = true; + signClusterHandler.removeMessages(SignClusterHandler.CALCULATE_CLUSTER); + signClusterHandler.sendEmptyMessage(SignClusterHandler.CALCULATE_CLUSTER); + } + + /** + * 在已有的聚合基础上,对添加的单个元素进行聚合 + */ + private void calculateSingleCluster(ClusterItem clusterItem) { + LatLngBounds visibleBounds = amap.getProjection().getVisibleRegion().latLngBounds; + LatLng latlng = clusterItem.getPosition(); + if (!visibleBounds.contains(latlng)) { + return; + } + Cluster cluster = getCluster(latlng, clusters); + if (cluster != null) { + cluster.addClusterItem(clusterItem); + Message message = Message.obtain(); + message.what = MarkerHandler.UPDATE_SINGLE_CLUSTER; + + message.obj = cluster; + markerHandler.removeMessages(MarkerHandler.UPDATE_SINGLE_CLUSTER); + markerHandler.sendMessageDelayed(message, 5); + } else { + cluster = new Cluster(latlng); + clusters.add(cluster); + cluster.addClusterItem(clusterItem); + Message message = Message.obtain(); + message.what = MarkerHandler.ADD_SINGLE_CLUSTER; + message.obj = cluster; + markerHandler.sendMessage(message); + } + } + + /** + * 根据一个点获取是否可以依附的聚合点,没有则返回null + */ + private Cluster getCluster(LatLng latLng, List clusters) { + for (Cluster cluster : clusters) { + LatLng clusterCenterPoint = cluster.getCenterLatLng(); + double distance = AMapUtils.calculateLineDistance(latLng, clusterCenterPoint); + if (distance < clusterDistance && amap.getCameraPosition().zoom < 19) { + return cluster; + } + } + return null; + } + + + /** + * 获取每个聚合点的绘制样式 + */ + private BitmapDescriptor getBitmapDes(int num) { + TextView textView = new TextView(context); + if (num > 1) { + String tile = String.valueOf(num); + textView.setText(tile); + } + textView.setGravity(Gravity.CENTER); + textView.setTextColor(Color.BLACK); + textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 15); + if (clusterRender != null && clusterRender.getDrawableByCount(num) != null) { + textView.setBackgroundDrawable(clusterRender.getDrawableByCount(num)); + } else { + textView.setBackgroundResource(R.mipmap.well_location); + } + return BitmapDescriptorFactory.fromView(textView); + } + + /** + * 更新已加入地图聚合点的样式 + */ + private void updateCluster(Cluster cluster) { + Marker marker = cluster.getMarker(); + marker.setIcon(getBitmapDes(cluster.getClusterCount())); + } + + /** + * 处理market添加,更新等操作 + */ + class MarkerHandler extends Handler { + + static final int ADD_CLUSTER_LIST = 0; + + static final int ADD_SINGLE_CLUSTER = 1; + + static final int UPDATE_SINGLE_CLUSTER = 2; + + public MarkerHandler(Looper looper) { + super(looper); + } + + public void handleMessage(Message message) { + switch (message.what) { + case ADD_CLUSTER_LIST: + List clusters = (List) message.obj; + addClusterToMap(clusters); + break; + case ADD_SINGLE_CLUSTER: + Cluster cluster = (Cluster) message.obj; + addSingleClusterToMap(cluster); + break; + case UPDATE_SINGLE_CLUSTER: + Cluster updateCluster = (Cluster) message.obj; + updateCluster(updateCluster); + break; + } + } + } + + /** + * 处理聚合点算法线程 + */ + class SignClusterHandler extends Handler { + static final int CALCULATE_CLUSTER = 0; + static final int CALCULATE_SINGLE_CLUSTER = 1; + + public SignClusterHandler(Looper looper) { + super(looper); + } + + public void handleMessage(Message message) { + switch (message.what) { + case CALCULATE_CLUSTER: + calculateClusters(); + break; + case CALCULATE_SINGLE_CLUSTER: + ClusterItem item = (ClusterItem) message.obj; + clusterItems.add(item); + calculateSingleCluster(item); + break; + } + } + } +} diff --git a/app/src/main/java/com/casic/app/smartwell/widgets/cluster/ClusterRender.java b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/ClusterRender.java new file mode 100644 index 0000000..427ff14 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/ClusterRender.java @@ -0,0 +1,10 @@ +package com.casic.app.smartwell.widgets.cluster; + +import android.graphics.drawable.Drawable; + +public interface ClusterRender { + /** + * 根据聚合点的元素数目返回渲染背景样式 + */ + Drawable getDrawableByCount(int clusterNum); +} diff --git a/app/src/main/java/com/casic/app/smartwell/widgets/cluster/RegionItem.java b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/RegionItem.java new file mode 100644 index 0000000..7b2b6c4 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/RegionItem.java @@ -0,0 +1,23 @@ +package com.casic.app.smartwell.widgets.cluster; + +import com.amap.api.maps.model.LatLng; +import com.casic.app.smartwell.model.MapWellListModel; + +public class RegionItem implements ClusterItem { + private final LatLng latLng; + private final MapWellListModel.DataModel well; + + public RegionItem(LatLng latLng, MapWellListModel.DataModel well) { + this.latLng = latLng; + this.well = well; + } + + @Override + public LatLng getPosition() { + return latLng; + } + + public MapWellListModel.DataModel getWell() { + return well; + } +} diff --git a/app/src/main/java/com/casic/app/smartwell/widgets/cluster/RemoveAnimationListener.java b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/RemoveAnimationListener.java new file mode 100644 index 0000000..c9c5e84 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/RemoveAnimationListener.java @@ -0,0 +1,30 @@ +package com.casic.app.smartwell.widgets.cluster; + +import com.amap.api.maps.model.Marker; +import com.amap.api.maps.model.animation.Animation; + +import java.util.List; + +/** + * marker渐变动画,动画结束后将Marker删除 + */ +public class RemoveAnimationListener implements Animation.AnimationListener { + private final List removeMarkers; + + public RemoveAnimationListener(List removeMarkers) { + this.removeMarkers = removeMarkers; + } + + @Override + public void onAnimationStart() { + + } + + @Override + public void onAnimationEnd() { + for (Marker marker : removeMarkers) { + marker.remove(); + } + removeMarkers.clear(); + } +} \ No newline at end of file diff --git a/app/src/main/res/anim/map_popup_hide.xml b/app/src/main/res/anim/map_popup_hide.xml new file mode 100644 index 0000000..119726b --- /dev/null +++ b/app/src/main/res/anim/map_popup_hide.xml @@ -0,0 +1,12 @@ + + + + \ No newline at end of file diff --git a/app/src/main/res/anim/map_popup_show.xml b/app/src/main/res/anim/map_popup_show.xml new file mode 100644 index 0000000..1d281ef --- /dev/null +++ b/app/src/main/res/anim/map_popup_show.xml @@ -0,0 +1,12 @@ + + + + \ No newline at end of file diff --git a/app/src/main/res/anim/popup_hide.xml b/app/src/main/res/anim/popup_hide.xml index 55c7aca..7480485 100644 --- a/app/src/main/res/anim/popup_hide.xml +++ b/app/src/main/res/anim/popup_hide.xml @@ -1,7 +1,8 @@ - + \ No newline at end of file diff --git a/app/src/main/res/anim/popup_show.xml b/app/src/main/res/anim/popup_show.xml index 1d281ef..dbe2833 100644 --- a/app/src/main/res/anim/popup_show.xml +++ b/app/src/main/res/anim/popup_show.xml @@ -1,12 +1,8 @@ \ No newline at end of file diff --git a/app/src/main/res/drawable/bg_solid_layout_transparent_radius_10.xml b/app/src/main/res/drawable/bg_solid_layout_transparent_radius_10.xml deleted file mode 100644 index 15e6a4b..0000000 --- a/app/src/main/res/drawable/bg_solid_layout_transparent_radius_10.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - \ 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 new file mode 100644 index 0000000..18c1e99 --- /dev/null +++ b/app/src/main/res/drawable/bg_solid_layout_transparent_radius_5.xml @@ -0,0 +1,10 @@ + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_home.xml b/app/src/main/res/layout/fragment_home.xml index 9796164..b763355 100644 --- a/app/src/main/res/layout/fragment_home.xml +++ b/app/src/main/res/layout/fragment_home.xml @@ -48,7 +48,7 @@ android:orientation="vertical" app:behavior_fitToContents="false" app:behavior_halfExpandedRatio="0.425" - app:behavior_hideable="true" + app:behavior_hideable="false" app:behavior_peekHeight="30dp" app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior"> diff --git a/app/src/main/java/com/casic/app/smartwell/extensions/Int.kt b/app/src/main/java/com/casic/app/smartwell/extensions/Int.kt index de0617b..a0a5e33 100644 --- a/app/src/main/java/com/casic/app/smartwell/extensions/Int.kt +++ b/app/src/main/java/com/casic/app/smartwell/extensions/Int.kt @@ -1,9 +1,24 @@ package com.casic.app.smartwell.extensions +import android.graphics.Bitmap +import android.graphics.Canvas +import android.graphics.Paint +import android.graphics.RectF + fun Int.toLevel(): String { return if (this == 0) { "" } else { this.toString() } +} + +fun Int.drawCircle(color: Int): Bitmap? { + val bitmap = Bitmap.createBitmap(this * 2, this * 2, Bitmap.Config.ARGB_8888) + val canvas = Canvas(bitmap) + val paint = Paint() + val rectF = RectF(0f, 0f, (this * 2).toFloat(), (this * 2).toFloat()) + paint.color = color + canvas.drawArc(rectF, 0f, 360f, true, paint) + return bitmap } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt index 6b6ca3e..5e45534 100644 --- a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt +++ b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt @@ -2,17 +2,13 @@ import android.content.Context import com.casic.app.smartwell.callback.OnImageCompressListener -import com.casic.app.smartwell.model.ErrorMessageModel import com.casic.app.smartwell.utils.LocaleConstant -import com.google.gson.Gson -import com.google.gson.reflect.TypeToken +import com.google.gson.JsonParser import com.pengxh.kt.lite.extensions.createCompressImageDir import com.pengxh.kt.lite.utils.SaveKeyValues -import org.json.JSONObject import top.zibin.luban.Luban import top.zibin.luban.OnCompressListener import java.io.File -import java.util.Locale /** * String扩展方法 @@ -74,18 +70,22 @@ } } -fun String.separateResponseCode(): Int { +fun String.getResponseCode(): Int { if (this.isBlank()) { return 404 } - return JSONObject(this).getInt("code") + val element = JsonParser.parseString(this) + val jsonObject = element.asJsonObject + return jsonObject.get("code").asInt } -fun String.toErrorMessage(): String { - val errorModel = Gson().fromJson( - this, object : TypeToken() {}.type - ) - return errorModel.message.toString() +fun String.getResponseMessage(): String { + if (this.isBlank()) { + return "" + } + val element = JsonParser.parseString(this) + val jsonObject = element.asJsonObject + return jsonObject.get("message").asString } fun String.compressImage(context: Context, listener: OnImageCompressListener) { @@ -93,9 +93,6 @@ .load(this) .ignoreBy(100) .setTargetDir(context.createCompressImageDir().toString()) - .filter { - !(it.isBlank() || it.lowercase(Locale.getDefault()).endsWith(".gif")) - } .setCompressListener(object : OnCompressListener { override fun onStart() { 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 96df110..cd25fca 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 @@ -1,26 +1,25 @@ package com.casic.app.smartwell.fragment -import android.graphics.Point +import android.graphics.Color +import android.graphics.drawable.BitmapDrawable +import android.graphics.drawable.Drawable 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 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.LatLngBounds import com.amap.api.maps.model.Marker -import com.amap.api.maps.model.MarkerOptions import com.casic.app.smartwell.R import com.casic.app.smartwell.databinding.FragmentHomeBinding +import com.casic.app.smartwell.extensions.drawCircle import com.casic.app.smartwell.extensions.initImmersionBar -import com.casic.app.smartwell.extensions.valueToType import com.casic.app.smartwell.model.MapWellListModel import com.casic.app.smartwell.utils.LocaleConstant import com.casic.app.smartwell.utils.RouteOnMap @@ -31,9 +30,16 @@ import com.casic.app.smartwell.view.WellOperationActivity import com.casic.app.smartwell.vm.OrderViewModel import com.casic.app.smartwell.vm.WellViewModel +import com.casic.app.smartwell.widgets.MapWellPopup +import com.casic.app.smartwell.widgets.cluster.ClusterItem +import com.casic.app.smartwell.widgets.cluster.ClusterOnClickListener +import com.casic.app.smartwell.widgets.cluster.ClusterOverlay +import com.casic.app.smartwell.widgets.cluster.RegionItem 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.convertDrawable +import com.pengxh.kt.lite.extensions.dp2px import com.pengxh.kt.lite.extensions.navigatePageTo import com.pengxh.kt.lite.extensions.show import com.pengxh.kt.lite.utils.LoadingDialogHub @@ -43,35 +49,23 @@ /** * 地图点位带聚合效果 * */ -class HomePageHaveClusterFragment : KotlinBaseFragment(), AMap.OnMapLoadedListener, - AMap.OnCameraChangeListener, AMap.OnMarkerClickListener, AMap.InfoWindowAdapter, - AMap.OnInfoWindowClickListener { +class HomePageHaveClusterFragment : KotlinBaseFragment(), + AMap.OnCameraChangeListener { private val kTag = "HaveClusterFragment" private val easyPopupWindow by lazy { EasyPopupWindow(requireContext()) } - private lateinit var wellViewModel: WellViewModel - private lateinit var orderViewModel: OrderViewModel - private lateinit var aMap: AMap - - /** - * 所有的marker - */ - private var allMarkerOptions: MutableList = ArrayList() - - /** - * 视野内的marker - */ - private var markerOptionsInView: MutableList = ArrayList() - - /** - * 自定义Marker弹出框 - * */ - private lateinit var v: View + private val regionRadius by lazy { LocaleConstant.RADIUS_SIZE.dp2px(requireContext()) } + private val infoPopup by lazy { MapWellPopup(requireContext()) } /** * 所有窨井列表信息集合 * */ - private var wellModels: MutableList = ArrayList() + private val wellModels = ArrayList() + private val backDrawables = HashMap() + private lateinit var wellViewModel: WellViewModel + private lateinit var orderViewModel: OrderViewModel + private lateinit var aMap: AMap + private var clusterOverlay: ClusterOverlay? = null override fun initViewBinding( inflater: LayoutInflater, @@ -106,6 +100,9 @@ } }) + //地图初始化 + initMap(savedInstanceState) + //初始化vm wellViewModel = ViewModelProvider(this)[WellViewModel::class.java] orderViewModel = ViewModelProvider(this)[OrderViewModel::class.java] @@ -120,25 +117,19 @@ val latitudeList: MutableList = ArrayList() val longitudeList: MutableList = ArrayList() it.data?.forEach { well -> - val lat = well.latGaode.toString() - val lng = well.lngGaode.toString() + val lat = well.latGaode + val lng = well.lngGaode if (lat.isNotBlank() && lng.isNotBlank()) { //返回true代表当前位置在大陆、港澳地区,反之不在 val latitude = lat.toDouble() val longitude = lng.toDouble() if (CoordinateConverter.isAMapDataAvailable(latitude, longitude)) { - //缓存所有设备详情,点击Marker时候需要 + //缓存所有井 wellModels.add(well) + //分别缓存经、纬度 latitudeList.add(latitude) longitudeList.add(longitude) - //将所有设备信息转化缓存为Marker点 - allMarkerOptions.add( - MarkerOptions() - .position(LatLng(latitude, longitude)) - .title(well.wellTypeName) - .snippet(well.wellName) - ) } } } @@ -160,12 +151,12 @@ val cameraPosition = CameraPosition(centerLatLng, 16f, 0f, 0f) val cameraUpdate = CameraUpdateFactory.newCameraPosition(cameraPosition) aMap.animateCamera(cameraUpdate, 1500, null) + + //显示点数据 + displayWellOnMap() } } - //地图初始化 - initMap(savedInstanceState) - //获取窨井监控数据 wellViewModel.countResultModel.observe(this) { binding.deployedWellView.text = it["bfWell"] @@ -220,17 +211,10 @@ uiSettings.isCompassEnabled = true uiSettings.zoomPosition = AMapOptions.ZOOM_POSITION_RIGHT_CENTER uiSettings.isTiltGesturesEnabled = false//不许地图随手势倾斜角度 + uiSettings.isRotateGesturesEnabled = false//不允许地图随手势改变方位 - // 地图加载成功监听 - aMap.addOnMapLoadedListener(this) // 地图缩放监听 aMap.addOnCameraChangeListener(this) - // marker 点击事件监听 - aMap.addOnMarkerClickListener(this) - // 点击marker弹出自定义popup - aMap.setInfoWindowAdapter(this) - //信息窗点击事件 - aMap.addOnInfoWindowClickListener(this) } override fun initEvent() { @@ -259,9 +243,111 @@ } - override fun onMapLoaded() { - //地图加载成功之后显示聚合点数据 - initClustersMarkers() + private fun displayWellOnMap() { + clusterOverlay?.onDestroy() + val clusterItems = ArrayList() + + wellModels.forEach { + val latitude = it.latGaode.toDouble() + val longitude = it.lngGaode.toDouble() + + val latLng = LatLng(latitude, longitude, false) + val regionItem = RegionItem(latLng, it) + clusterItems.add(regionItem) + } + + clusterOverlay = ClusterOverlay(requireContext(), aMap, clusterItems, regionRadius) + clusterOverlay?.setClusterRender { clusterNum -> + //聚合圆半径 + val radius = 100.dp2px(requireContext()) + if (clusterNum == 0) { + var bitmapDrawable = backDrawables[0] + if (bitmapDrawable == null) { + bitmapDrawable = BitmapDrawable( + null, radius.drawCircle(Color.argb(159, 100, 149, 237)) + ) + backDrawables[0] = bitmapDrawable + } + bitmapDrawable + } + if (clusterNum == 1) { + var bitmapDrawable = backDrawables[1] + if (bitmapDrawable == null) { + bitmapDrawable = R.mipmap.well_location.convertDrawable(requireContext())!! + backDrawables[1] = bitmapDrawable + } + bitmapDrawable + } else if (clusterNum < 5) { + var bitmapDrawable = backDrawables[2] + if (bitmapDrawable == null) { + bitmapDrawable = BitmapDrawable( + null, radius.drawCircle(Color.argb(159, 100, 149, 237)) + ) + backDrawables[2] = bitmapDrawable + } + bitmapDrawable + } else if (clusterNum < 10) { + var bitmapDrawable = backDrawables[3] + if (bitmapDrawable == null) { + bitmapDrawable = BitmapDrawable( + null, radius.drawCircle(Color.argb(199, 30, 144, 255)) + ) + backDrawables[3] = bitmapDrawable + } + bitmapDrawable + } else { + var bitmapDrawable = backDrawables[4] + if (bitmapDrawable == null) { + bitmapDrawable = BitmapDrawable( + null, radius.drawCircle(Color.argb(235, 65, 105, 225)) + ) + backDrawables[4] = bitmapDrawable + } + bitmapDrawable + } + } + + clusterOverlay?.setOnClusterClickListener(object : ClusterOnClickListener { + override fun onMarkerClicked(marker: Marker?, items: List) { + if (items.size > 1) { + "请缩放地图比例在查看数据".show(requireContext()) + return + } + + var item: RegionItem? = null + val builder = LatLngBounds.Builder() + for (clusterItem in items) { + builder.include(clusterItem.position) + item = clusterItem as RegionItem + } + + item?.apply { + showWellPopup(well) + } + } + }) + } + + private fun showWellPopup(well: MapWellListModel.DataModel) { + infoPopup.set(well, object : MapWellPopup.OnPopupWindowClickListener { + override fun onPopupClicked(lat: Double, lng: Double) { + AlertControlDialog.Builder().setContext(requireContext()).setTitle("操作提示") + .setMessage("确定要前往吗").setNegativeButton("取消").setPositiveButton("确定") + .setOnDialogButtonClickListener(object : + AlertControlDialog.OnDialogButtonClickListener { + override fun onConfirmClick() { + RouteOnMap.startNavigation( + requireContext(), "", LatLng(lat, lng) + ) + } + + override fun onCancelClick() { + + } + }).build().show() + } + }) + infoPopup.showAsDropDown(binding.rightOptionView) } override fun onCameraChange(p0: CameraPosition?) { @@ -282,103 +368,10 @@ } } - //获取视野内的marker 根据聚合算法合成自定义的marker 显示视野内的marker override fun onCameraChangeFinish(p0: CameraPosition?) { //地图缩放之后显示聚合点数据 LoadingDialogHub.dismiss() httpCountDownTimer.cancel() - initClustersMarkers() - } - - private fun initClustersMarkers() { - 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 { - v = LayoutInflater.from(requireContext()).inflate(R.layout.popup_map_info, null) - - //显示闸井信息 - marker?.showInfoWindow() - return true - } - - override fun getInfoWindow(marker: Marker?): View { - //反射得到popup里面的控件对象 - val wellNameView = v.findViewById(R.id.wellNameView) - val wellCodeView = v.findViewById(R.id.wellCodeView) - val wellTypeView = v.findViewById(R.id.wellTypeView) - val wellStateView = v.findViewById(R.id.wellStateView) - val deepView = v.findViewById(R.id.deepView) - val locationView = v.findViewById(R.id.locationView) - - //绑定数据 - val clickedLatLng = marker?.position!! - wellModels.forEach { well -> - if (clickedLatLng.latitude == well.latGaode!!.toDouble() - && clickedLatLng.longitude == well.lngGaode!!.toDouble() - ) { - wellNameView.text = String.format("点位名称: ${well.wellName}") - wellCodeView.text = String.format("点位编号: ${well.wellCode}") - wellTypeView.text = String.format("点位类型: ${well.wellType.valueToType()}") - val bfztName = if (well.bfzt == "1") { - "已布防" - } else { - "已撤防" - } - wellStateView.text = String.format("布/撤防状态: $bfztName") - deepView.text = String.format("点位深度: ${well.deep}m") - locationView.text = String.format("详细位置: ${well.position}") - } - } - return v - } - - /** - * 此方法不能修改整个 InfoWindow 的背景和边框,无论自定义的样式是什么样,SDK 都会在最外层添加一个默认的边框 - * */ - override fun getInfoContents(p0: Marker?): View? = null - - override fun onInfoWindowClick(p0: Marker?) { - p0?.apply { - AlertControlDialog.Builder() - .setContext(requireContext()) - .setTitle("操作提示") - .setMessage("确定要前往吗") - .setNegativeButton("取消") - .setPositiveButton("确定") - .setOnDialogButtonClickListener(object : - AlertControlDialog.OnDialogButtonClickListener { - override fun onConfirmClick() { - val lat = position.latitude.toString() - val lng = position.longitude.toString() - if (lat.isBlank() || lng.isBlank()) { - "点位经纬度异常,无法开启导航".show(requireContext()) - return - } - RouteOnMap.startNavigation( - requireContext(), snippet, LatLng(lat.toDouble(), lng.toDouble()) - ) - } - - override fun onCancelClick() { - - } - }).build().show() - } } /***以下是地图生命周期管理************************************************************************/ 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 a54d213..bfa7a57 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 @@ -44,8 +44,8 @@ * 地图点位不带聚合效果 * */ class HomePageNoClusterFragment : KotlinBaseFragment(), - AMap.OnMapLoadedListener, AMap.OnCameraChangeListener, AMap.OnMarkerClickListener, - AMap.InfoWindowAdapter, AMap.OnInfoWindowClickListener { + AMap.OnCameraChangeListener, AMap.OnMarkerClickListener, AMap.InfoWindowAdapter, + AMap.OnInfoWindowClickListener { private val kTag = "NoClusterFragment" private val easyPopupWindow by lazy { EasyPopupWindow(requireContext()) } @@ -109,6 +109,9 @@ wellViewModel = ViewModelProvider(this)[WellViewModel::class.java] orderViewModel = ViewModelProvider(this)[OrderViewModel::class.java] + //地图初始化 + initMap(savedInstanceState) + //获取所有窨井数据 httpCountDownTimer.start() LoadingDialogHub.show(requireActivity(), "数据加载中,请稍后...") @@ -157,12 +160,12 @@ val cameraPosition = CameraPosition(centerLatLng, 16f, 0f, 0f) val cameraUpdate = CameraUpdateFactory.newCameraPosition(cameraPosition) aMap.animateCamera(cameraUpdate, 1500, null) + + //显示点数据 + displayWellOnMap() } } - //地图初始化 - initMap(savedInstanceState) - //获取窨井监控数据 wellViewModel.countResultModel.observe(this) { binding.deployedWellView.text = it["bfWell"] @@ -214,9 +217,8 @@ uiSettings.isCompassEnabled = true uiSettings.zoomPosition = AMapOptions.ZOOM_POSITION_RIGHT_CENTER uiSettings.isTiltGesturesEnabled = false//不许地图随手势倾斜角度 + uiSettings.isRotateGesturesEnabled = false//不允许地图随手势改变方位 - // 地图加载成功监听 - aMap.addOnMapLoadedListener(this) // 地图缩放监听 aMap.addOnCameraChangeListener(this) // marker 点击事件监听 @@ -253,11 +255,6 @@ } - override fun onMapLoaded() { - //地图加载成功之后显示聚合点数据 - initClustersMarkers() - } - override fun onCameraChange(p0: CameraPosition?) { } @@ -281,10 +278,9 @@ //地图缩放之后显示聚合点数据 LoadingDialogHub.dismiss() httpCountDownTimer.cancel() - initClustersMarkers() } - private fun initClustersMarkers() { + private fun displayWellOnMap() { val proj = aMap.projection val dm = resources.displayMetrics var screenLocation: Point diff --git a/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.java b/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.java deleted file mode 100644 index d8b18ef..0000000 --- a/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.java +++ /dev/null @@ -1,50 +0,0 @@ -package com.casic.app.smartwell.model; - -public class ErrorMessageModel { - - private int code; - private String data; - private String exceptionClazz; - private String message; - private boolean success; - - public int getCode() { - return code; - } - - public void setCode(int code) { - this.code = code; - } - - public String getData() { - return data; - } - - public void setData(String data) { - this.data = data; - } - - public String getExceptionClazz() { - return exceptionClazz; - } - - public void setExceptionClazz(String exceptionClazz) { - this.exceptionClazz = exceptionClazz; - } - - public String getMessage() { - return message; - } - - public void setMessage(String message) { - this.message = message; - } - - public boolean isSuccess() { - return success; - } - - public void setSuccess(boolean success) { - this.success = success; - } -} \ No newline at end of file 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 new file mode 100644 index 0000000..215ac0c --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/PipelineModel.java @@ -0,0 +1,328 @@ +package com.casic.app.smartwell.model; + +import java.util.List; + +public class PipelineModel { + + private Integer code; + private DataModel data; + private String message; + private Boolean success; + + public Integer getCode() { + return code; + } + + public void setCode(Integer code) { + this.code = code; + } + + public DataModel getData() { + return data; + } + + public void setData(DataModel data) { + this.data = data; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + public Boolean getSuccess() { + return success; + } + + public void setSuccess(Boolean success) { + this.success = success; + } + + public static class DataModel { + private List rows; + private Integer total; + + public List getRows() { + return rows; + } + + public void setRows(List rows) { + this.rows = rows; + } + + public Integer getTotal() { + return total; + } + + public void setTotal(Integer total) { + this.total = total; + } + + 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 getBuryMode() { + return buryMode; + } + + public void setBuryMode(String buryMode) { + this.buryMode = buryMode; + } + + public String getConstructEra() { + return constructEra; + } + + public void setConstructEra(String constructEra) { + this.constructEra = constructEra; + } + + 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; + } + } + } +} 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 06d3d2b..4f38a2c 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 = 100 //相距多少米才聚合,单位:米 + const val RADIUS_SIZE = 80 //相距多少米才聚合,单位:米 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:11308" + // 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 0d5f3fa..991e1db 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 @@ -312,4 +312,14 @@ @Header("token") token: String, @Field("clientid") deviceCode: String ): String + + /** + * 管线位置数据 + */ + @GET("/pipeline/listPage") + suspend fun getPipeline( + @Header("token") token: String, + @Query("limit") limit: Int, + @Query("offset") offset: Int + ): String } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt index 1a0ce22..4050067 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt @@ -294,4 +294,11 @@ suspend fun registerPush(clientId: String): String { return api.registerPush(AuthenticationHelper.token!!, clientId) } + + /** + * 管线位置数据 + */ + suspend fun getPipeline(): String { + return api.getPipeline(AuthenticationHelper.token!!, 2000, 1) + } } \ No newline at end of file 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 9270fa1..4ca5a5e 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.HomePageNoClusterFragment +import com.casic.app.smartwell.fragment.HomePageHaveClusterFragment 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/vm/AlarmViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/AlarmViewModel.kt index 9cff08c..e7acc17 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/AlarmViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/AlarmViewModel.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.AlarmContentModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager import com.google.gson.Gson @@ -16,7 +16,7 @@ fun getAlarmContentType(alarmType: String) = launch({ val response = RetrofitServiceManager.getAlarmContentType(alarmType) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { listModel.value = gson.fromJson( response, object : TypeToken() {}.type diff --git a/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt index 5e5b163..895dedd 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.PublicKeyModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager import com.google.gson.Gson @@ -18,7 +18,7 @@ fun getPublicKey() = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.authenticate() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { keyModel.value = gson.fromJson( response, object : TypeToken() {}.type diff --git a/app/src/main/java/com/casic/app/smartwell/vm/DeviceViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/DeviceViewModel.kt index db5ccf6..899a962 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/DeviceViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/DeviceViewModel.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.DeviceDetailModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager import com.google.gson.Gson @@ -16,7 +16,7 @@ fun getDeviceDetail(deviceCode: String) = launch({ val response = RetrofitServiceManager.getDeviceDetail(deviceCode) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { detailModel.value = gson.fromJson( response, object : TypeToken() {}.type diff --git a/app/src/main/java/com/casic/app/smartwell/vm/LoginViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/LoginViewModel.kt index cd8b8a9..a417398 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/LoginViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/LoginViewModel.kt @@ -2,7 +2,7 @@ import androidx.lifecycle.MutableLiveData import com.casic.app.smartwell.base.BaseApplication -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.CommonResultModel import com.casic.app.smartwell.model.LoginResultModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -21,7 +21,7 @@ fun enter(account: String, secretKey: String) = launch({ val response = RetrofitServiceManager.login(account, secretKey) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success enterResultModel.value = gson.fromJson( @@ -38,7 +38,7 @@ fun out() = launch({ val response = RetrofitServiceManager.loginOut() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { outResultModel.value = gson.fromJson( response, object : TypeToken() {}.type diff --git a/app/src/main/java/com/casic/app/smartwell/vm/OperationViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/OperationViewModel.kt index 8943ed3..37e115f 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/OperationViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/OperationViewModel.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.vm import com.casic.app.smartwell.base.BaseApplication -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager import com.pengxh.kt.lite.base.BaseViewModel import com.pengxh.kt.lite.extensions.launch @@ -16,7 +16,7 @@ fun acceptWorkOrder(id: String) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.acceptWorkOrder(id) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success "接单成功".show(BaseApplication.get()) @@ -35,7 +35,7 @@ loadState.value = LoadState.Loading val response = RetrofitServiceManager.confirmWorkOrder(id, firstState, firstStatePhotos, needHandle) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success "工单确认成功".show(BaseApplication.get()) @@ -50,7 +50,7 @@ fun transferWorkOrder(id: String, userId: String) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.transferWorkOrder(id, userId) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success "转单成功".show(BaseApplication.get()) @@ -65,7 +65,7 @@ fun completeWorkOrder(id: String, handleMessage: String, handlePhotos: String) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.completeWorkOrder(id, handleMessage, handlePhotos) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success "工单处理成功".show(BaseApplication.get()) diff --git a/app/src/main/java/com/casic/app/smartwell/vm/OrderViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/OrderViewModel.kt index 4cb26b7..d2fad86 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/OrderViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/OrderViewModel.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.OrderDetailModel import com.casic.app.smartwell.model.OrderListModel import com.casic.app.smartwell.model.OrderStatusModel @@ -37,7 +37,7 @@ val response = RetrofitServiceManager.getSearchResult( keywords, alarmContent, alarmLevel, jobStatus, deptId, beginTime, endTime, offset ) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success searchResult.value = gson.fromJson( @@ -53,7 +53,7 @@ fun getWorkOrderListByState(jobStatus: String, page: Int) = launch({ val response = RetrofitServiceManager.getWorkOrderList(jobStatus, page) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { orderList.value = gson.fromJson( response, object : TypeToken() {}.type @@ -65,7 +65,7 @@ fun getNotAcceptOderList(page: Int) = launch({ val response = RetrofitServiceManager.getNotAcceptOderList(page) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { orderList.value = gson.fromJson( response, object : TypeToken() {}.type @@ -77,7 +77,7 @@ fun getNotHandleOderList(page: Int) = launch({ val response = RetrofitServiceManager.getNotHandleOderList(page) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { orderList.value = gson.fromJson( response, object : TypeToken() {}.type @@ -89,7 +89,7 @@ fun countWorkOrderByState() = launch({ val response = RetrofitServiceManager.countWorkOrderByState() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { val map = HashMap(4) @@ -107,7 +107,7 @@ fun getOrderStatus() = launch({ val response = RetrofitServiceManager.getOrderStatus() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { orderStatusModel.value = gson.fromJson( response, object : TypeToken() {}.type @@ -120,7 +120,7 @@ fun getWorkOrderDetail(id: String) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.getWorkOrderDetail(id) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success detailModel.value = gson.fromJson( diff --git a/app/src/main/java/com/casic/app/smartwell/vm/PipelineViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/PipelineViewModel.kt new file mode 100644 index 0000000..60c1e2f --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/vm/PipelineViewModel.kt @@ -0,0 +1,28 @@ +package com.casic.app.smartwell.vm + +import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.extensions.getResponseCode +import com.casic.app.smartwell.model.PipelineModel +import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken +import com.pengxh.kt.lite.base.BaseViewModel +import com.pengxh.kt.lite.extensions.launch + +class PipelineViewModel : BaseViewModel() { + + private val gson by lazy { Gson() } + val lineResult = MutableLiveData() + + fun getPipeline() = launch({ + val response = RetrofitServiceManager.getPipeline() + val responseCode = response.getResponseCode() + if (responseCode == 200) { + lineResult.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } + }, { + it.printStackTrace() + }) +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/PushViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/PushViewModel.kt index 9279815..12fd610 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/PushViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/PushViewModel.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.CommonResultModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager import com.google.gson.Gson @@ -16,7 +16,7 @@ fun registerPush(clientId: String) = launch({ val response = RetrofitServiceManager.registerPush(clientId) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { registerResultModel.value = gson.fromJson( response, object : TypeToken() {}.type diff --git a/app/src/main/java/com/casic/app/smartwell/vm/UploadImageViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/UploadImageViewModel.kt index 8d6744e..9707eeb 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/UploadImageViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/UploadImageViewModel.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.CommonResultModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager import com.google.gson.Gson @@ -19,7 +19,7 @@ fun uploadImage(image: File) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.uploadImage(image) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success resultModel.value = gson.fromJson( diff --git a/app/src/main/java/com/casic/app/smartwell/vm/UserViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/UserViewModel.kt index 31a4d4c..070c35a 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/UserViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/UserViewModel.kt @@ -2,7 +2,7 @@ import androidx.lifecycle.MutableLiveData import com.casic.app.smartwell.base.BaseApplication -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.SubordinateModel import com.casic.app.smartwell.model.UserDetailModel import com.casic.app.smartwell.model.VersionResultModel @@ -25,7 +25,7 @@ fun getUserDetail() = launch({ val response = RetrofitServiceManager.getUserDetail() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { val userDetail = gson.fromJson( response, object : TypeToken() {}.type @@ -48,7 +48,7 @@ * */ fun getSubordinate(hasMine: String?, deptId: String?, roleTips: String?) = launch({ val response = RetrofitServiceManager.getSubordinate(hasMine, deptId, roleTips) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { subordinateModel.value = gson.fromJson( response, object : TypeToken() {}.type @@ -61,7 +61,7 @@ fun changePassword(oldPwd: String, newPwd: String) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.changePassword(oldPwd, newPwd) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success "修改成功,请重新登录".show(BaseApplication.get()) @@ -76,7 +76,7 @@ fun updateVersion() = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.updateVersion() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success versionResultModel.value = gson.fromJson( diff --git a/app/src/main/java/com/casic/app/smartwell/vm/WellViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/WellViewModel.kt index 3d41e9b..9e42e36 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/WellViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/WellViewModel.kt @@ -2,8 +2,7 @@ import androidx.lifecycle.MutableLiveData import com.casic.app.smartwell.base.BaseApplication -import com.casic.app.smartwell.extensions.separateResponseCode -import com.casic.app.smartwell.extensions.toErrorMessage +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.AuthorDeptModel import com.casic.app.smartwell.model.CommonResultModel import com.casic.app.smartwell.model.MapWellListModel @@ -32,7 +31,7 @@ fun countWellByState() = launch({ val response = RetrofitServiceManager.countWellByState() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { val map = HashMap(3) @@ -57,7 +56,7 @@ fun getWellType() = launch({ val response = RetrofitServiceManager.getWellType() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { wellTypeModel.value = gson.fromJson( response, object : TypeToken() {}.type @@ -70,7 +69,7 @@ fun getWellDetail(id: String) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.getWellDetail(id) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success wellDetailModel.value = gson.fromJson( @@ -87,7 +86,7 @@ fun getOperationResult(id: String, state: String) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.getOperationResult(id, state) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success "操作成功".show(BaseApplication.get()) @@ -105,7 +104,7 @@ fun getMonitorResult(id: String) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.getMonitorResult(id) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success monitorModel.value = gson.fromJson( @@ -125,7 +124,7 @@ val response = RetrofitServiceManager.getWellListByPage( keywords, wellType, deptid, bfzt, page ) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { listModel.value = gson.fromJson( response, object : TypeToken() {}.type @@ -137,13 +136,11 @@ fun getWellList() = launch({ val response = RetrofitServiceManager.getWellList() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { totalWellModel.value = gson.fromJson( response, object : TypeToken() {}.type ) - } else { - response.toErrorMessage().show(BaseApplication.get()) } }, { it.printStackTrace() diff --git a/app/src/main/java/com/casic/app/smartwell/widgets/GaoDeClusterMarkerView.kt b/app/src/main/java/com/casic/app/smartwell/widgets/GaoDeClusterMarkerView.kt deleted file mode 100644 index 1f375df..0000000 --- a/app/src/main/java/com/casic/app/smartwell/widgets/GaoDeClusterMarkerView.kt +++ /dev/null @@ -1,100 +0,0 @@ -package com.casic.app.smartwell.widgets - -import android.content.Context -import android.graphics.Bitmap -import android.graphics.Point -import android.view.Gravity -import android.view.LayoutInflater -import android.view.View -import android.widget.TextView -import com.amap.api.maps.Projection -import com.amap.api.maps.model.BitmapDescriptorFactory -import com.amap.api.maps.model.LatLng -import com.amap.api.maps.model.LatLngBounds -import com.amap.api.maps.model.MarkerOptions -import com.casic.app.smartwell.R -import com.pengxh.kt.lite.extensions.toBitmap -import java.util.* - -class GaoDeClusterMarkerView( - private val context: Context, firstMarkers: MarkerOptions, projection: Projection, gridSize: Int -) { - //当前可观区域里的 聚合过之后的集合 - private val includeMarkers: ArrayList - - // 创建区域 - val bounds: LatLngBounds - var options: MarkerOptions = MarkerOptions() - - init { - val screenLocation = projection.toScreenLocation(firstMarkers.position) - //范围类 - val southwestPoint = Point(screenLocation.x - gridSize, screenLocation.y + gridSize) - //范围类 - val northeastPoint = Point(screenLocation.x + gridSize, screenLocation.y - gridSize) - bounds = LatLngBounds( - projection.fromScreenLocation(southwestPoint), - projection.fromScreenLocation(northeastPoint) - ) - //设置初始化marker属性 - options.anchor(0.5f, 1.3f) - .title(firstMarkers.title) - .position(firstMarkers.position) - .icon(firstMarkers.icon) - .snippet(firstMarkers.snippet) - .draggable(false) - includeMarkers = ArrayList() - includeMarkers.add(firstMarkers) - } - - /** - * 添加marker - */ - fun addMarker(markerOptions: MarkerOptions) { - includeMarkers.add(markerOptions) // 添加到列表中 - } - - /** - * 设置聚合点的中心位置以及图标 - */ - fun setPositionAndIcon() { - val size = includeMarkers.size - var lat = 0.0 - var lng = 0.0 - // 一个的时候 - if (size == 1) { //设置marker单个属性 - // 设置marker位置 - options.position( - LatLng( - includeMarkers[0].position.latitude, includeMarkers[0].position.longitude - ) - ) - } else { // 聚合的时候 - //设置marker聚合属性 - for (op in includeMarkers) { - lat += op.position.latitude - lng += op.position.longitude - } - // 设置marker的位置为中心位置为聚集点的平均位置 - options.position(LatLng(lat / size, lng / size)) - } - options.icon(BitmapDescriptorFactory.fromBitmap(getBitmap(size))) - } - - /** - * marker视图 - */ - private fun getBitmap(num: Int): Bitmap? { - val view = LayoutInflater.from(context).inflate(R.layout.marker_gaode, null) - val wellCountView = view.findViewById(R.id.wellCountView) - return if (num > 1) { - wellCountView.visibility = View.VISIBLE - wellCountView.text = String.format("${num}个") - wellCountView.gravity = Gravity.CENTER - view.toBitmap() - } else { - wellCountView.visibility = View.GONE - BitmapDescriptorFactory.fromResource(R.mipmap.well_location).bitmap - } - } -} \ No newline at end of file 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 new file mode 100644 index 0000000..ec455dd --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/widgets/MapWellPopup.kt @@ -0,0 +1,58 @@ +package com.casic.app.smartwell.widgets + +import android.content.Context +import android.view.LayoutInflater +import android.view.ViewGroup +import android.widget.LinearLayout +import android.widget.PopupWindow +import android.widget.TextView +import com.casic.app.smartwell.R +import com.casic.app.smartwell.extensions.valueToType +import com.casic.app.smartwell.model.MapWellListModel + +class MapWellPopup constructor(context: Context) : PopupWindow() { + + init { + width = ViewGroup.LayoutParams.MATCH_PARENT + height = ViewGroup.LayoutParams.WRAP_CONTENT + isOutsideTouchable = true + isFocusable = true + animationStyle = R.style.MapPopupAnimation + setBackgroundDrawable(null) + contentView = LayoutInflater.from(context).inflate( + R.layout.popup_map_info, null, false + ) + } + + fun set(well: MapWellListModel.DataModel, windowClickListener: OnPopupWindowClickListener) { + //反射得到popup里面的控件对象 + val rootView = contentView.findViewById(R.id.rootView) + val wellNameView = contentView.findViewById(R.id.wellNameView) + val wellCodeView = contentView.findViewById(R.id.wellCodeView) + val wellTypeView = contentView.findViewById(R.id.wellTypeView) + val wellStateView = contentView.findViewById(R.id.wellStateView) + val deepView = contentView.findViewById(R.id.deepView) + val locationView = contentView.findViewById(R.id.locationView) + + //绑定数据 + wellNameView.text = String.format("点位名称: ${well.wellName}") + wellCodeView.text = String.format("点位编号: ${well.wellCode}") + wellTypeView.text = String.format("点位类型: ${well.wellType.valueToType()}") + val bfztName = if (well.bfzt == "1") { + "已布防" + } else { + "已撤防" + } + wellStateView.text = String.format("布/撤防状态: $bfztName") + deepView.text = String.format("点位深度: ${well.deep}m") + locationView.text = String.format("详细位置: ${well.position}") + + rootView.setOnClickListener { + windowClickListener.onPopupClicked(well.latGaode.toDouble(), well.lngGaode.toDouble()) + } + } + + interface OnPopupWindowClickListener { + fun onPopupClicked(lat: Double, lng: Double) + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/widgets/cluster/Cluster.java b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/Cluster.java new file mode 100644 index 0000000..9455ccd --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/Cluster.java @@ -0,0 +1,43 @@ +package com.casic.app.smartwell.widgets.cluster; + +import com.amap.api.maps.model.LatLng; +import com.amap.api.maps.model.Marker; + +import java.util.ArrayList; +import java.util.List; + +public class Cluster { + private final LatLng latLng; + private final List clusterItems; + private Marker marker; + + + public Cluster(LatLng latLng) { + this.latLng = latLng; + clusterItems = new ArrayList<>(); + } + + public void addClusterItem(ClusterItem clusterItem) { + clusterItems.add(clusterItem); + } + + public int getClusterCount() { + return clusterItems.size(); + } + + public LatLng getCenterLatLng() { + return latLng; + } + + public void setMarker(Marker marker) { + this.marker = marker; + } + + public Marker getMarker() { + return marker; + } + + public List getClusterItems() { + return clusterItems; + } +} diff --git a/app/src/main/java/com/casic/app/smartwell/widgets/cluster/ClusterItem.java b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/ClusterItem.java new file mode 100644 index 0000000..f5d9a9d --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/ClusterItem.java @@ -0,0 +1,10 @@ +package com.casic.app.smartwell.widgets.cluster; + +import com.amap.api.maps.model.LatLng; + +public interface ClusterItem { + /** + * 返回聚合元素的地理位置 + */ + LatLng getPosition(); +} diff --git a/app/src/main/java/com/casic/app/smartwell/widgets/cluster/ClusterOnClickListener.java b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/ClusterOnClickListener.java new file mode 100644 index 0000000..0efa1f1 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/ClusterOnClickListener.java @@ -0,0 +1,15 @@ +package com.casic.app.smartwell.widgets.cluster; + +import com.amap.api.maps.model.Marker; + +import java.util.List; + +public interface ClusterOnClickListener { + /** + * 点击聚合点的回调处理函数 + * + * @param marker 点击的聚合点 + * @param items 聚合点所包含的元素 + */ + void onMarkerClicked(Marker marker, List items); +} 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 new file mode 100644 index 0000000..40df562 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/ClusterOverlay.java @@ -0,0 +1,349 @@ +package com.casic.app.smartwell.widgets.cluster; + +import android.content.Context; +import android.graphics.Color; +import android.os.Handler; +import android.os.HandlerThread; +import android.os.Looper; +import android.os.Message; +import android.util.TypedValue; +import android.view.Gravity; +import android.widget.TextView; + +import com.amap.api.maps.AMap; +import com.amap.api.maps.AMapUtils; +import com.amap.api.maps.model.BitmapDescriptor; +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.LatLngBounds; +import com.amap.api.maps.model.Marker; +import com.amap.api.maps.model.MarkerOptions; +import com.amap.api.maps.model.animation.AlphaAnimation; +import com.casic.app.smartwell.R; + +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.CopyOnWriteArrayList; + +/** + * 整体设计采用了两个线程,一个线程用于计算组织聚合数据,一个线程负责处理Marker相关操作 + */ +public class ClusterOverlay implements AMap.OnCameraChangeListener, AMap.OnMarkerClickListener { + private final AMap amap; + private final Context context; + private final List clusterItems; + private final List clusters; + private final int clusterSize; + private ClusterOnClickListener clusterClickListener; + private ClusterRender clusterRender; + private final CopyOnWriteArrayList addMarkers = new CopyOnWriteArrayList<>(); + private double clusterDistance; + private final HandlerThread markerHandlerThread = new HandlerThread("addMarker"); + private final HandlerThread signClusterThread = new HandlerThread("calculateCluster"); + private Handler markerHandler; + private Handler signClusterHandler; + private float pxInMeters; + private boolean isCanceled = false; + private final AlphaAnimation addAnimation = new AlphaAnimation(0, 1); + + /** + * 构造函数,批量添加聚合元素时,调用此构造函数 + */ + public ClusterOverlay(Context context, AMap amap, int clusterSize) { + this(context, amap, null, clusterSize); + } + + /** + * 构造函数,批量添加聚合元素时,调用此构造函数 + */ + public ClusterOverlay(Context context, AMap amap, List clusterItems, int clusterSize) { + if (clusterItems != null) { + this.clusterItems = clusterItems; + } else { + this.clusterItems = new ArrayList<>(); + } + this.context = context; + this.clusters = new ArrayList<>(); + this.amap = amap; + this.clusterSize = clusterSize; + this.pxInMeters = amap.getScalePerPixel(); + this.clusterDistance = pxInMeters * clusterSize; + amap.setOnCameraChangeListener(this); + amap.setOnMarkerClickListener(this); + initThreadHandler(); + assignClusters(); + } + + /** + * 设置聚合点的点击事件 + */ + public void setOnClusterClickListener(ClusterOnClickListener clusterClickListener) { + this.clusterClickListener = clusterClickListener; + } + + /** + * 添加一个聚合点 + */ + public void addClusterItem(ClusterItem item) { + Message message = Message.obtain(); + message.what = SignClusterHandler.CALCULATE_SINGLE_CLUSTER; + message.obj = item; + signClusterHandler.sendMessage(message); + } + + /** + * 设置聚合元素的渲染样式,不设置则默认为气泡加数字形式进行渲染 + */ + public void setClusterRender(ClusterRender render) { + this.clusterRender = render; + } + + public void onDestroy() { + isCanceled = true; + signClusterHandler.removeCallbacksAndMessages(null); + markerHandler.removeCallbacksAndMessages(null); + signClusterThread.quit(); + markerHandlerThread.quit(); + for (Marker marker : addMarkers) { + marker.remove(); + } + addMarkers.clear(); + } + + //初始化Handler + private void initThreadHandler() { + markerHandlerThread.start(); + signClusterThread.start(); + markerHandler = new MarkerHandler(markerHandlerThread.getLooper()); + signClusterHandler = new SignClusterHandler(signClusterThread.getLooper()); + } + + @Override + public void onCameraChange(CameraPosition arg0) { + + } + + @Override + public void onCameraChangeFinish(CameraPosition arg0) { + pxInMeters = amap.getScalePerPixel(); + clusterDistance = pxInMeters * clusterSize; + assignClusters(); + } + + @Override + public boolean onMarkerClick(Marker marker) { + if (clusterClickListener == null) { + return true; + } + Cluster cluster = (Cluster) marker.getObject(); + if (cluster != null) { + clusterClickListener.onMarkerClicked(marker, cluster.getClusterItems()); + return true; + } + return false; + } + + /** + * 将聚合元素添加至地图上 + */ + private void addClusterToMap(List clusters) { + ArrayList removeMarkers = new ArrayList<>(addMarkers); + AlphaAnimation alphaAnimation = new AlphaAnimation(1, 0); + RemoveAnimationListener removeAnimationListener = new RemoveAnimationListener(removeMarkers); + for (Marker marker : removeMarkers) { + marker.setAnimation(alphaAnimation); + marker.setAnimationListener(removeAnimationListener); + marker.startAnimation(); + } + + for (Cluster cluster : clusters) { + addSingleClusterToMap(cluster); + } + } + + /** + * 将单个聚合元素添加至地图显示 + */ + private void addSingleClusterToMap(Cluster cluster) { + LatLng latlng = cluster.getCenterLatLng(); + MarkerOptions markerOptions = new MarkerOptions(); + markerOptions.icon(getBitmapDes(cluster.getClusterCount())).position(latlng); + Marker marker = amap.addMarker(markerOptions); + marker.setAnimation(addAnimation); + marker.setObject(cluster); + + marker.startAnimation(); + cluster.setMarker(marker); + addMarkers.add(marker); + } + + private void calculateClusters() { + isCanceled = false; + clusters.clear(); + LatLngBounds visibleBounds = amap.getProjection().getVisibleRegion().latLngBounds; + for (ClusterItem clusterItem : clusterItems) { + if (isCanceled) { + return; + } + LatLng latlng = clusterItem.getPosition(); + if (visibleBounds.contains(latlng)) { + Cluster cluster = getCluster(latlng, clusters); + if (cluster == null) { + cluster = new Cluster(latlng); + clusters.add(cluster); + } + cluster.addClusterItem(clusterItem); + } + } + + //复制一份数据,规避同步 + List tempClusters = new ArrayList<>(clusters); + Message message = Message.obtain(); + message.what = MarkerHandler.ADD_CLUSTER_LIST; + message.obj = tempClusters; + if (isCanceled) { + return; + } + markerHandler.sendMessage(message); + } + + /** + * 对点进行聚合 + */ + private void assignClusters() { + isCanceled = true; + signClusterHandler.removeMessages(SignClusterHandler.CALCULATE_CLUSTER); + signClusterHandler.sendEmptyMessage(SignClusterHandler.CALCULATE_CLUSTER); + } + + /** + * 在已有的聚合基础上,对添加的单个元素进行聚合 + */ + private void calculateSingleCluster(ClusterItem clusterItem) { + LatLngBounds visibleBounds = amap.getProjection().getVisibleRegion().latLngBounds; + LatLng latlng = clusterItem.getPosition(); + if (!visibleBounds.contains(latlng)) { + return; + } + Cluster cluster = getCluster(latlng, clusters); + if (cluster != null) { + cluster.addClusterItem(clusterItem); + Message message = Message.obtain(); + message.what = MarkerHandler.UPDATE_SINGLE_CLUSTER; + + message.obj = cluster; + markerHandler.removeMessages(MarkerHandler.UPDATE_SINGLE_CLUSTER); + markerHandler.sendMessageDelayed(message, 5); + } else { + cluster = new Cluster(latlng); + clusters.add(cluster); + cluster.addClusterItem(clusterItem); + Message message = Message.obtain(); + message.what = MarkerHandler.ADD_SINGLE_CLUSTER; + message.obj = cluster; + markerHandler.sendMessage(message); + } + } + + /** + * 根据一个点获取是否可以依附的聚合点,没有则返回null + */ + private Cluster getCluster(LatLng latLng, List clusters) { + for (Cluster cluster : clusters) { + LatLng clusterCenterPoint = cluster.getCenterLatLng(); + double distance = AMapUtils.calculateLineDistance(latLng, clusterCenterPoint); + if (distance < clusterDistance && amap.getCameraPosition().zoom < 19) { + return cluster; + } + } + return null; + } + + + /** + * 获取每个聚合点的绘制样式 + */ + private BitmapDescriptor getBitmapDes(int num) { + TextView textView = new TextView(context); + if (num > 1) { + String tile = String.valueOf(num); + textView.setText(tile); + } + textView.setGravity(Gravity.CENTER); + textView.setTextColor(Color.BLACK); + textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 15); + if (clusterRender != null && clusterRender.getDrawableByCount(num) != null) { + textView.setBackgroundDrawable(clusterRender.getDrawableByCount(num)); + } else { + textView.setBackgroundResource(R.mipmap.well_location); + } + return BitmapDescriptorFactory.fromView(textView); + } + + /** + * 更新已加入地图聚合点的样式 + */ + private void updateCluster(Cluster cluster) { + Marker marker = cluster.getMarker(); + marker.setIcon(getBitmapDes(cluster.getClusterCount())); + } + + /** + * 处理market添加,更新等操作 + */ + class MarkerHandler extends Handler { + + static final int ADD_CLUSTER_LIST = 0; + + static final int ADD_SINGLE_CLUSTER = 1; + + static final int UPDATE_SINGLE_CLUSTER = 2; + + public MarkerHandler(Looper looper) { + super(looper); + } + + public void handleMessage(Message message) { + switch (message.what) { + case ADD_CLUSTER_LIST: + List clusters = (List) message.obj; + addClusterToMap(clusters); + break; + case ADD_SINGLE_CLUSTER: + Cluster cluster = (Cluster) message.obj; + addSingleClusterToMap(cluster); + break; + case UPDATE_SINGLE_CLUSTER: + Cluster updateCluster = (Cluster) message.obj; + updateCluster(updateCluster); + break; + } + } + } + + /** + * 处理聚合点算法线程 + */ + class SignClusterHandler extends Handler { + static final int CALCULATE_CLUSTER = 0; + static final int CALCULATE_SINGLE_CLUSTER = 1; + + public SignClusterHandler(Looper looper) { + super(looper); + } + + public void handleMessage(Message message) { + switch (message.what) { + case CALCULATE_CLUSTER: + calculateClusters(); + break; + case CALCULATE_SINGLE_CLUSTER: + ClusterItem item = (ClusterItem) message.obj; + clusterItems.add(item); + calculateSingleCluster(item); + break; + } + } + } +} diff --git a/app/src/main/java/com/casic/app/smartwell/widgets/cluster/ClusterRender.java b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/ClusterRender.java new file mode 100644 index 0000000..427ff14 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/ClusterRender.java @@ -0,0 +1,10 @@ +package com.casic.app.smartwell.widgets.cluster; + +import android.graphics.drawable.Drawable; + +public interface ClusterRender { + /** + * 根据聚合点的元素数目返回渲染背景样式 + */ + Drawable getDrawableByCount(int clusterNum); +} diff --git a/app/src/main/java/com/casic/app/smartwell/widgets/cluster/RegionItem.java b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/RegionItem.java new file mode 100644 index 0000000..7b2b6c4 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/RegionItem.java @@ -0,0 +1,23 @@ +package com.casic.app.smartwell.widgets.cluster; + +import com.amap.api.maps.model.LatLng; +import com.casic.app.smartwell.model.MapWellListModel; + +public class RegionItem implements ClusterItem { + private final LatLng latLng; + private final MapWellListModel.DataModel well; + + public RegionItem(LatLng latLng, MapWellListModel.DataModel well) { + this.latLng = latLng; + this.well = well; + } + + @Override + public LatLng getPosition() { + return latLng; + } + + public MapWellListModel.DataModel getWell() { + return well; + } +} diff --git a/app/src/main/java/com/casic/app/smartwell/widgets/cluster/RemoveAnimationListener.java b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/RemoveAnimationListener.java new file mode 100644 index 0000000..c9c5e84 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/RemoveAnimationListener.java @@ -0,0 +1,30 @@ +package com.casic.app.smartwell.widgets.cluster; + +import com.amap.api.maps.model.Marker; +import com.amap.api.maps.model.animation.Animation; + +import java.util.List; + +/** + * marker渐变动画,动画结束后将Marker删除 + */ +public class RemoveAnimationListener implements Animation.AnimationListener { + private final List removeMarkers; + + public RemoveAnimationListener(List removeMarkers) { + this.removeMarkers = removeMarkers; + } + + @Override + public void onAnimationStart() { + + } + + @Override + public void onAnimationEnd() { + for (Marker marker : removeMarkers) { + marker.remove(); + } + removeMarkers.clear(); + } +} \ No newline at end of file diff --git a/app/src/main/res/anim/map_popup_hide.xml b/app/src/main/res/anim/map_popup_hide.xml new file mode 100644 index 0000000..119726b --- /dev/null +++ b/app/src/main/res/anim/map_popup_hide.xml @@ -0,0 +1,12 @@ + + + + \ No newline at end of file diff --git a/app/src/main/res/anim/map_popup_show.xml b/app/src/main/res/anim/map_popup_show.xml new file mode 100644 index 0000000..1d281ef --- /dev/null +++ b/app/src/main/res/anim/map_popup_show.xml @@ -0,0 +1,12 @@ + + + + \ No newline at end of file diff --git a/app/src/main/res/anim/popup_hide.xml b/app/src/main/res/anim/popup_hide.xml index 55c7aca..7480485 100644 --- a/app/src/main/res/anim/popup_hide.xml +++ b/app/src/main/res/anim/popup_hide.xml @@ -1,7 +1,8 @@ - + \ No newline at end of file diff --git a/app/src/main/res/anim/popup_show.xml b/app/src/main/res/anim/popup_show.xml index 1d281ef..dbe2833 100644 --- a/app/src/main/res/anim/popup_show.xml +++ b/app/src/main/res/anim/popup_show.xml @@ -1,12 +1,8 @@ \ No newline at end of file diff --git a/app/src/main/res/drawable/bg_solid_layout_transparent_radius_10.xml b/app/src/main/res/drawable/bg_solid_layout_transparent_radius_10.xml deleted file mode 100644 index 15e6a4b..0000000 --- a/app/src/main/res/drawable/bg_solid_layout_transparent_radius_10.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - \ 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 new file mode 100644 index 0000000..18c1e99 --- /dev/null +++ b/app/src/main/res/drawable/bg_solid_layout_transparent_radius_5.xml @@ -0,0 +1,10 @@ + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_home.xml b/app/src/main/res/layout/fragment_home.xml index 9796164..b763355 100644 --- a/app/src/main/res/layout/fragment_home.xml +++ b/app/src/main/res/layout/fragment_home.xml @@ -48,7 +48,7 @@ android:orientation="vertical" app:behavior_fitToContents="false" app:behavior_halfExpandedRatio="0.425" - app:behavior_hideable="true" + app:behavior_hideable="false" app:behavior_peekHeight="30dp" app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior"> diff --git a/app/src/main/res/layout/marker_gaode.xml b/app/src/main/res/layout/marker_gaode.xml deleted file mode 100644 index 15e9368..0000000 --- a/app/src/main/res/layout/marker_gaode.xml +++ /dev/null @@ -1,27 +0,0 @@ - - - - - - - \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/extensions/Int.kt b/app/src/main/java/com/casic/app/smartwell/extensions/Int.kt index de0617b..a0a5e33 100644 --- a/app/src/main/java/com/casic/app/smartwell/extensions/Int.kt +++ b/app/src/main/java/com/casic/app/smartwell/extensions/Int.kt @@ -1,9 +1,24 @@ package com.casic.app.smartwell.extensions +import android.graphics.Bitmap +import android.graphics.Canvas +import android.graphics.Paint +import android.graphics.RectF + fun Int.toLevel(): String { return if (this == 0) { "" } else { this.toString() } +} + +fun Int.drawCircle(color: Int): Bitmap? { + val bitmap = Bitmap.createBitmap(this * 2, this * 2, Bitmap.Config.ARGB_8888) + val canvas = Canvas(bitmap) + val paint = Paint() + val rectF = RectF(0f, 0f, (this * 2).toFloat(), (this * 2).toFloat()) + paint.color = color + canvas.drawArc(rectF, 0f, 360f, true, paint) + return bitmap } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt index 6b6ca3e..5e45534 100644 --- a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt +++ b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt @@ -2,17 +2,13 @@ import android.content.Context import com.casic.app.smartwell.callback.OnImageCompressListener -import com.casic.app.smartwell.model.ErrorMessageModel import com.casic.app.smartwell.utils.LocaleConstant -import com.google.gson.Gson -import com.google.gson.reflect.TypeToken +import com.google.gson.JsonParser import com.pengxh.kt.lite.extensions.createCompressImageDir import com.pengxh.kt.lite.utils.SaveKeyValues -import org.json.JSONObject import top.zibin.luban.Luban import top.zibin.luban.OnCompressListener import java.io.File -import java.util.Locale /** * String扩展方法 @@ -74,18 +70,22 @@ } } -fun String.separateResponseCode(): Int { +fun String.getResponseCode(): Int { if (this.isBlank()) { return 404 } - return JSONObject(this).getInt("code") + val element = JsonParser.parseString(this) + val jsonObject = element.asJsonObject + return jsonObject.get("code").asInt } -fun String.toErrorMessage(): String { - val errorModel = Gson().fromJson( - this, object : TypeToken() {}.type - ) - return errorModel.message.toString() +fun String.getResponseMessage(): String { + if (this.isBlank()) { + return "" + } + val element = JsonParser.parseString(this) + val jsonObject = element.asJsonObject + return jsonObject.get("message").asString } fun String.compressImage(context: Context, listener: OnImageCompressListener) { @@ -93,9 +93,6 @@ .load(this) .ignoreBy(100) .setTargetDir(context.createCompressImageDir().toString()) - .filter { - !(it.isBlank() || it.lowercase(Locale.getDefault()).endsWith(".gif")) - } .setCompressListener(object : OnCompressListener { override fun onStart() { 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 96df110..cd25fca 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 @@ -1,26 +1,25 @@ package com.casic.app.smartwell.fragment -import android.graphics.Point +import android.graphics.Color +import android.graphics.drawable.BitmapDrawable +import android.graphics.drawable.Drawable 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 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.LatLngBounds import com.amap.api.maps.model.Marker -import com.amap.api.maps.model.MarkerOptions import com.casic.app.smartwell.R import com.casic.app.smartwell.databinding.FragmentHomeBinding +import com.casic.app.smartwell.extensions.drawCircle import com.casic.app.smartwell.extensions.initImmersionBar -import com.casic.app.smartwell.extensions.valueToType import com.casic.app.smartwell.model.MapWellListModel import com.casic.app.smartwell.utils.LocaleConstant import com.casic.app.smartwell.utils.RouteOnMap @@ -31,9 +30,16 @@ import com.casic.app.smartwell.view.WellOperationActivity import com.casic.app.smartwell.vm.OrderViewModel import com.casic.app.smartwell.vm.WellViewModel +import com.casic.app.smartwell.widgets.MapWellPopup +import com.casic.app.smartwell.widgets.cluster.ClusterItem +import com.casic.app.smartwell.widgets.cluster.ClusterOnClickListener +import com.casic.app.smartwell.widgets.cluster.ClusterOverlay +import com.casic.app.smartwell.widgets.cluster.RegionItem 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.convertDrawable +import com.pengxh.kt.lite.extensions.dp2px import com.pengxh.kt.lite.extensions.navigatePageTo import com.pengxh.kt.lite.extensions.show import com.pengxh.kt.lite.utils.LoadingDialogHub @@ -43,35 +49,23 @@ /** * 地图点位带聚合效果 * */ -class HomePageHaveClusterFragment : KotlinBaseFragment(), AMap.OnMapLoadedListener, - AMap.OnCameraChangeListener, AMap.OnMarkerClickListener, AMap.InfoWindowAdapter, - AMap.OnInfoWindowClickListener { +class HomePageHaveClusterFragment : KotlinBaseFragment(), + AMap.OnCameraChangeListener { private val kTag = "HaveClusterFragment" private val easyPopupWindow by lazy { EasyPopupWindow(requireContext()) } - private lateinit var wellViewModel: WellViewModel - private lateinit var orderViewModel: OrderViewModel - private lateinit var aMap: AMap - - /** - * 所有的marker - */ - private var allMarkerOptions: MutableList = ArrayList() - - /** - * 视野内的marker - */ - private var markerOptionsInView: MutableList = ArrayList() - - /** - * 自定义Marker弹出框 - * */ - private lateinit var v: View + private val regionRadius by lazy { LocaleConstant.RADIUS_SIZE.dp2px(requireContext()) } + private val infoPopup by lazy { MapWellPopup(requireContext()) } /** * 所有窨井列表信息集合 * */ - private var wellModels: MutableList = ArrayList() + private val wellModels = ArrayList() + private val backDrawables = HashMap() + private lateinit var wellViewModel: WellViewModel + private lateinit var orderViewModel: OrderViewModel + private lateinit var aMap: AMap + private var clusterOverlay: ClusterOverlay? = null override fun initViewBinding( inflater: LayoutInflater, @@ -106,6 +100,9 @@ } }) + //地图初始化 + initMap(savedInstanceState) + //初始化vm wellViewModel = ViewModelProvider(this)[WellViewModel::class.java] orderViewModel = ViewModelProvider(this)[OrderViewModel::class.java] @@ -120,25 +117,19 @@ val latitudeList: MutableList = ArrayList() val longitudeList: MutableList = ArrayList() it.data?.forEach { well -> - val lat = well.latGaode.toString() - val lng = well.lngGaode.toString() + val lat = well.latGaode + val lng = well.lngGaode if (lat.isNotBlank() && lng.isNotBlank()) { //返回true代表当前位置在大陆、港澳地区,反之不在 val latitude = lat.toDouble() val longitude = lng.toDouble() if (CoordinateConverter.isAMapDataAvailable(latitude, longitude)) { - //缓存所有设备详情,点击Marker时候需要 + //缓存所有井 wellModels.add(well) + //分别缓存经、纬度 latitudeList.add(latitude) longitudeList.add(longitude) - //将所有设备信息转化缓存为Marker点 - allMarkerOptions.add( - MarkerOptions() - .position(LatLng(latitude, longitude)) - .title(well.wellTypeName) - .snippet(well.wellName) - ) } } } @@ -160,12 +151,12 @@ val cameraPosition = CameraPosition(centerLatLng, 16f, 0f, 0f) val cameraUpdate = CameraUpdateFactory.newCameraPosition(cameraPosition) aMap.animateCamera(cameraUpdate, 1500, null) + + //显示点数据 + displayWellOnMap() } } - //地图初始化 - initMap(savedInstanceState) - //获取窨井监控数据 wellViewModel.countResultModel.observe(this) { binding.deployedWellView.text = it["bfWell"] @@ -220,17 +211,10 @@ uiSettings.isCompassEnabled = true uiSettings.zoomPosition = AMapOptions.ZOOM_POSITION_RIGHT_CENTER uiSettings.isTiltGesturesEnabled = false//不许地图随手势倾斜角度 + uiSettings.isRotateGesturesEnabled = false//不允许地图随手势改变方位 - // 地图加载成功监听 - aMap.addOnMapLoadedListener(this) // 地图缩放监听 aMap.addOnCameraChangeListener(this) - // marker 点击事件监听 - aMap.addOnMarkerClickListener(this) - // 点击marker弹出自定义popup - aMap.setInfoWindowAdapter(this) - //信息窗点击事件 - aMap.addOnInfoWindowClickListener(this) } override fun initEvent() { @@ -259,9 +243,111 @@ } - override fun onMapLoaded() { - //地图加载成功之后显示聚合点数据 - initClustersMarkers() + private fun displayWellOnMap() { + clusterOverlay?.onDestroy() + val clusterItems = ArrayList() + + wellModels.forEach { + val latitude = it.latGaode.toDouble() + val longitude = it.lngGaode.toDouble() + + val latLng = LatLng(latitude, longitude, false) + val regionItem = RegionItem(latLng, it) + clusterItems.add(regionItem) + } + + clusterOverlay = ClusterOverlay(requireContext(), aMap, clusterItems, regionRadius) + clusterOverlay?.setClusterRender { clusterNum -> + //聚合圆半径 + val radius = 100.dp2px(requireContext()) + if (clusterNum == 0) { + var bitmapDrawable = backDrawables[0] + if (bitmapDrawable == null) { + bitmapDrawable = BitmapDrawable( + null, radius.drawCircle(Color.argb(159, 100, 149, 237)) + ) + backDrawables[0] = bitmapDrawable + } + bitmapDrawable + } + if (clusterNum == 1) { + var bitmapDrawable = backDrawables[1] + if (bitmapDrawable == null) { + bitmapDrawable = R.mipmap.well_location.convertDrawable(requireContext())!! + backDrawables[1] = bitmapDrawable + } + bitmapDrawable + } else if (clusterNum < 5) { + var bitmapDrawable = backDrawables[2] + if (bitmapDrawable == null) { + bitmapDrawable = BitmapDrawable( + null, radius.drawCircle(Color.argb(159, 100, 149, 237)) + ) + backDrawables[2] = bitmapDrawable + } + bitmapDrawable + } else if (clusterNum < 10) { + var bitmapDrawable = backDrawables[3] + if (bitmapDrawable == null) { + bitmapDrawable = BitmapDrawable( + null, radius.drawCircle(Color.argb(199, 30, 144, 255)) + ) + backDrawables[3] = bitmapDrawable + } + bitmapDrawable + } else { + var bitmapDrawable = backDrawables[4] + if (bitmapDrawable == null) { + bitmapDrawable = BitmapDrawable( + null, radius.drawCircle(Color.argb(235, 65, 105, 225)) + ) + backDrawables[4] = bitmapDrawable + } + bitmapDrawable + } + } + + clusterOverlay?.setOnClusterClickListener(object : ClusterOnClickListener { + override fun onMarkerClicked(marker: Marker?, items: List) { + if (items.size > 1) { + "请缩放地图比例在查看数据".show(requireContext()) + return + } + + var item: RegionItem? = null + val builder = LatLngBounds.Builder() + for (clusterItem in items) { + builder.include(clusterItem.position) + item = clusterItem as RegionItem + } + + item?.apply { + showWellPopup(well) + } + } + }) + } + + private fun showWellPopup(well: MapWellListModel.DataModel) { + infoPopup.set(well, object : MapWellPopup.OnPopupWindowClickListener { + override fun onPopupClicked(lat: Double, lng: Double) { + AlertControlDialog.Builder().setContext(requireContext()).setTitle("操作提示") + .setMessage("确定要前往吗").setNegativeButton("取消").setPositiveButton("确定") + .setOnDialogButtonClickListener(object : + AlertControlDialog.OnDialogButtonClickListener { + override fun onConfirmClick() { + RouteOnMap.startNavigation( + requireContext(), "", LatLng(lat, lng) + ) + } + + override fun onCancelClick() { + + } + }).build().show() + } + }) + infoPopup.showAsDropDown(binding.rightOptionView) } override fun onCameraChange(p0: CameraPosition?) { @@ -282,103 +368,10 @@ } } - //获取视野内的marker 根据聚合算法合成自定义的marker 显示视野内的marker override fun onCameraChangeFinish(p0: CameraPosition?) { //地图缩放之后显示聚合点数据 LoadingDialogHub.dismiss() httpCountDownTimer.cancel() - initClustersMarkers() - } - - private fun initClustersMarkers() { - 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 { - v = LayoutInflater.from(requireContext()).inflate(R.layout.popup_map_info, null) - - //显示闸井信息 - marker?.showInfoWindow() - return true - } - - override fun getInfoWindow(marker: Marker?): View { - //反射得到popup里面的控件对象 - val wellNameView = v.findViewById(R.id.wellNameView) - val wellCodeView = v.findViewById(R.id.wellCodeView) - val wellTypeView = v.findViewById(R.id.wellTypeView) - val wellStateView = v.findViewById(R.id.wellStateView) - val deepView = v.findViewById(R.id.deepView) - val locationView = v.findViewById(R.id.locationView) - - //绑定数据 - val clickedLatLng = marker?.position!! - wellModels.forEach { well -> - if (clickedLatLng.latitude == well.latGaode!!.toDouble() - && clickedLatLng.longitude == well.lngGaode!!.toDouble() - ) { - wellNameView.text = String.format("点位名称: ${well.wellName}") - wellCodeView.text = String.format("点位编号: ${well.wellCode}") - wellTypeView.text = String.format("点位类型: ${well.wellType.valueToType()}") - val bfztName = if (well.bfzt == "1") { - "已布防" - } else { - "已撤防" - } - wellStateView.text = String.format("布/撤防状态: $bfztName") - deepView.text = String.format("点位深度: ${well.deep}m") - locationView.text = String.format("详细位置: ${well.position}") - } - } - return v - } - - /** - * 此方法不能修改整个 InfoWindow 的背景和边框,无论自定义的样式是什么样,SDK 都会在最外层添加一个默认的边框 - * */ - override fun getInfoContents(p0: Marker?): View? = null - - override fun onInfoWindowClick(p0: Marker?) { - p0?.apply { - AlertControlDialog.Builder() - .setContext(requireContext()) - .setTitle("操作提示") - .setMessage("确定要前往吗") - .setNegativeButton("取消") - .setPositiveButton("确定") - .setOnDialogButtonClickListener(object : - AlertControlDialog.OnDialogButtonClickListener { - override fun onConfirmClick() { - val lat = position.latitude.toString() - val lng = position.longitude.toString() - if (lat.isBlank() || lng.isBlank()) { - "点位经纬度异常,无法开启导航".show(requireContext()) - return - } - RouteOnMap.startNavigation( - requireContext(), snippet, LatLng(lat.toDouble(), lng.toDouble()) - ) - } - - override fun onCancelClick() { - - } - }).build().show() - } } /***以下是地图生命周期管理************************************************************************/ 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 a54d213..bfa7a57 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 @@ -44,8 +44,8 @@ * 地图点位不带聚合效果 * */ class HomePageNoClusterFragment : KotlinBaseFragment(), - AMap.OnMapLoadedListener, AMap.OnCameraChangeListener, AMap.OnMarkerClickListener, - AMap.InfoWindowAdapter, AMap.OnInfoWindowClickListener { + AMap.OnCameraChangeListener, AMap.OnMarkerClickListener, AMap.InfoWindowAdapter, + AMap.OnInfoWindowClickListener { private val kTag = "NoClusterFragment" private val easyPopupWindow by lazy { EasyPopupWindow(requireContext()) } @@ -109,6 +109,9 @@ wellViewModel = ViewModelProvider(this)[WellViewModel::class.java] orderViewModel = ViewModelProvider(this)[OrderViewModel::class.java] + //地图初始化 + initMap(savedInstanceState) + //获取所有窨井数据 httpCountDownTimer.start() LoadingDialogHub.show(requireActivity(), "数据加载中,请稍后...") @@ -157,12 +160,12 @@ val cameraPosition = CameraPosition(centerLatLng, 16f, 0f, 0f) val cameraUpdate = CameraUpdateFactory.newCameraPosition(cameraPosition) aMap.animateCamera(cameraUpdate, 1500, null) + + //显示点数据 + displayWellOnMap() } } - //地图初始化 - initMap(savedInstanceState) - //获取窨井监控数据 wellViewModel.countResultModel.observe(this) { binding.deployedWellView.text = it["bfWell"] @@ -214,9 +217,8 @@ uiSettings.isCompassEnabled = true uiSettings.zoomPosition = AMapOptions.ZOOM_POSITION_RIGHT_CENTER uiSettings.isTiltGesturesEnabled = false//不许地图随手势倾斜角度 + uiSettings.isRotateGesturesEnabled = false//不允许地图随手势改变方位 - // 地图加载成功监听 - aMap.addOnMapLoadedListener(this) // 地图缩放监听 aMap.addOnCameraChangeListener(this) // marker 点击事件监听 @@ -253,11 +255,6 @@ } - override fun onMapLoaded() { - //地图加载成功之后显示聚合点数据 - initClustersMarkers() - } - override fun onCameraChange(p0: CameraPosition?) { } @@ -281,10 +278,9 @@ //地图缩放之后显示聚合点数据 LoadingDialogHub.dismiss() httpCountDownTimer.cancel() - initClustersMarkers() } - private fun initClustersMarkers() { + private fun displayWellOnMap() { val proj = aMap.projection val dm = resources.displayMetrics var screenLocation: Point diff --git a/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.java b/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.java deleted file mode 100644 index d8b18ef..0000000 --- a/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.java +++ /dev/null @@ -1,50 +0,0 @@ -package com.casic.app.smartwell.model; - -public class ErrorMessageModel { - - private int code; - private String data; - private String exceptionClazz; - private String message; - private boolean success; - - public int getCode() { - return code; - } - - public void setCode(int code) { - this.code = code; - } - - public String getData() { - return data; - } - - public void setData(String data) { - this.data = data; - } - - public String getExceptionClazz() { - return exceptionClazz; - } - - public void setExceptionClazz(String exceptionClazz) { - this.exceptionClazz = exceptionClazz; - } - - public String getMessage() { - return message; - } - - public void setMessage(String message) { - this.message = message; - } - - public boolean isSuccess() { - return success; - } - - public void setSuccess(boolean success) { - this.success = success; - } -} \ No newline at end of file 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 new file mode 100644 index 0000000..215ac0c --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/PipelineModel.java @@ -0,0 +1,328 @@ +package com.casic.app.smartwell.model; + +import java.util.List; + +public class PipelineModel { + + private Integer code; + private DataModel data; + private String message; + private Boolean success; + + public Integer getCode() { + return code; + } + + public void setCode(Integer code) { + this.code = code; + } + + public DataModel getData() { + return data; + } + + public void setData(DataModel data) { + this.data = data; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + public Boolean getSuccess() { + return success; + } + + public void setSuccess(Boolean success) { + this.success = success; + } + + public static class DataModel { + private List rows; + private Integer total; + + public List getRows() { + return rows; + } + + public void setRows(List rows) { + this.rows = rows; + } + + public Integer getTotal() { + return total; + } + + public void setTotal(Integer total) { + this.total = total; + } + + 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 getBuryMode() { + return buryMode; + } + + public void setBuryMode(String buryMode) { + this.buryMode = buryMode; + } + + public String getConstructEra() { + return constructEra; + } + + public void setConstructEra(String constructEra) { + this.constructEra = constructEra; + } + + 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; + } + } + } +} 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 06d3d2b..4f38a2c 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 = 100 //相距多少米才聚合,单位:米 + const val RADIUS_SIZE = 80 //相距多少米才聚合,单位:米 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:11308" + // 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 0d5f3fa..991e1db 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 @@ -312,4 +312,14 @@ @Header("token") token: String, @Field("clientid") deviceCode: String ): String + + /** + * 管线位置数据 + */ + @GET("/pipeline/listPage") + suspend fun getPipeline( + @Header("token") token: String, + @Query("limit") limit: Int, + @Query("offset") offset: Int + ): String } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt index 1a0ce22..4050067 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt @@ -294,4 +294,11 @@ suspend fun registerPush(clientId: String): String { return api.registerPush(AuthenticationHelper.token!!, clientId) } + + /** + * 管线位置数据 + */ + suspend fun getPipeline(): String { + return api.getPipeline(AuthenticationHelper.token!!, 2000, 1) + } } \ No newline at end of file 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 9270fa1..4ca5a5e 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.HomePageNoClusterFragment +import com.casic.app.smartwell.fragment.HomePageHaveClusterFragment 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/vm/AlarmViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/AlarmViewModel.kt index 9cff08c..e7acc17 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/AlarmViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/AlarmViewModel.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.AlarmContentModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager import com.google.gson.Gson @@ -16,7 +16,7 @@ fun getAlarmContentType(alarmType: String) = launch({ val response = RetrofitServiceManager.getAlarmContentType(alarmType) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { listModel.value = gson.fromJson( response, object : TypeToken() {}.type diff --git a/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt index 5e5b163..895dedd 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.PublicKeyModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager import com.google.gson.Gson @@ -18,7 +18,7 @@ fun getPublicKey() = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.authenticate() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { keyModel.value = gson.fromJson( response, object : TypeToken() {}.type diff --git a/app/src/main/java/com/casic/app/smartwell/vm/DeviceViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/DeviceViewModel.kt index db5ccf6..899a962 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/DeviceViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/DeviceViewModel.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.DeviceDetailModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager import com.google.gson.Gson @@ -16,7 +16,7 @@ fun getDeviceDetail(deviceCode: String) = launch({ val response = RetrofitServiceManager.getDeviceDetail(deviceCode) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { detailModel.value = gson.fromJson( response, object : TypeToken() {}.type diff --git a/app/src/main/java/com/casic/app/smartwell/vm/LoginViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/LoginViewModel.kt index cd8b8a9..a417398 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/LoginViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/LoginViewModel.kt @@ -2,7 +2,7 @@ import androidx.lifecycle.MutableLiveData import com.casic.app.smartwell.base.BaseApplication -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.CommonResultModel import com.casic.app.smartwell.model.LoginResultModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -21,7 +21,7 @@ fun enter(account: String, secretKey: String) = launch({ val response = RetrofitServiceManager.login(account, secretKey) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success enterResultModel.value = gson.fromJson( @@ -38,7 +38,7 @@ fun out() = launch({ val response = RetrofitServiceManager.loginOut() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { outResultModel.value = gson.fromJson( response, object : TypeToken() {}.type diff --git a/app/src/main/java/com/casic/app/smartwell/vm/OperationViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/OperationViewModel.kt index 8943ed3..37e115f 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/OperationViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/OperationViewModel.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.vm import com.casic.app.smartwell.base.BaseApplication -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager import com.pengxh.kt.lite.base.BaseViewModel import com.pengxh.kt.lite.extensions.launch @@ -16,7 +16,7 @@ fun acceptWorkOrder(id: String) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.acceptWorkOrder(id) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success "接单成功".show(BaseApplication.get()) @@ -35,7 +35,7 @@ loadState.value = LoadState.Loading val response = RetrofitServiceManager.confirmWorkOrder(id, firstState, firstStatePhotos, needHandle) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success "工单确认成功".show(BaseApplication.get()) @@ -50,7 +50,7 @@ fun transferWorkOrder(id: String, userId: String) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.transferWorkOrder(id, userId) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success "转单成功".show(BaseApplication.get()) @@ -65,7 +65,7 @@ fun completeWorkOrder(id: String, handleMessage: String, handlePhotos: String) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.completeWorkOrder(id, handleMessage, handlePhotos) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success "工单处理成功".show(BaseApplication.get()) diff --git a/app/src/main/java/com/casic/app/smartwell/vm/OrderViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/OrderViewModel.kt index 4cb26b7..d2fad86 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/OrderViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/OrderViewModel.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.OrderDetailModel import com.casic.app.smartwell.model.OrderListModel import com.casic.app.smartwell.model.OrderStatusModel @@ -37,7 +37,7 @@ val response = RetrofitServiceManager.getSearchResult( keywords, alarmContent, alarmLevel, jobStatus, deptId, beginTime, endTime, offset ) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success searchResult.value = gson.fromJson( @@ -53,7 +53,7 @@ fun getWorkOrderListByState(jobStatus: String, page: Int) = launch({ val response = RetrofitServiceManager.getWorkOrderList(jobStatus, page) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { orderList.value = gson.fromJson( response, object : TypeToken() {}.type @@ -65,7 +65,7 @@ fun getNotAcceptOderList(page: Int) = launch({ val response = RetrofitServiceManager.getNotAcceptOderList(page) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { orderList.value = gson.fromJson( response, object : TypeToken() {}.type @@ -77,7 +77,7 @@ fun getNotHandleOderList(page: Int) = launch({ val response = RetrofitServiceManager.getNotHandleOderList(page) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { orderList.value = gson.fromJson( response, object : TypeToken() {}.type @@ -89,7 +89,7 @@ fun countWorkOrderByState() = launch({ val response = RetrofitServiceManager.countWorkOrderByState() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { val map = HashMap(4) @@ -107,7 +107,7 @@ fun getOrderStatus() = launch({ val response = RetrofitServiceManager.getOrderStatus() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { orderStatusModel.value = gson.fromJson( response, object : TypeToken() {}.type @@ -120,7 +120,7 @@ fun getWorkOrderDetail(id: String) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.getWorkOrderDetail(id) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success detailModel.value = gson.fromJson( diff --git a/app/src/main/java/com/casic/app/smartwell/vm/PipelineViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/PipelineViewModel.kt new file mode 100644 index 0000000..60c1e2f --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/vm/PipelineViewModel.kt @@ -0,0 +1,28 @@ +package com.casic.app.smartwell.vm + +import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.extensions.getResponseCode +import com.casic.app.smartwell.model.PipelineModel +import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken +import com.pengxh.kt.lite.base.BaseViewModel +import com.pengxh.kt.lite.extensions.launch + +class PipelineViewModel : BaseViewModel() { + + private val gson by lazy { Gson() } + val lineResult = MutableLiveData() + + fun getPipeline() = launch({ + val response = RetrofitServiceManager.getPipeline() + val responseCode = response.getResponseCode() + if (responseCode == 200) { + lineResult.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } + }, { + it.printStackTrace() + }) +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/PushViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/PushViewModel.kt index 9279815..12fd610 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/PushViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/PushViewModel.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.CommonResultModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager import com.google.gson.Gson @@ -16,7 +16,7 @@ fun registerPush(clientId: String) = launch({ val response = RetrofitServiceManager.registerPush(clientId) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { registerResultModel.value = gson.fromJson( response, object : TypeToken() {}.type diff --git a/app/src/main/java/com/casic/app/smartwell/vm/UploadImageViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/UploadImageViewModel.kt index 8d6744e..9707eeb 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/UploadImageViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/UploadImageViewModel.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.CommonResultModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager import com.google.gson.Gson @@ -19,7 +19,7 @@ fun uploadImage(image: File) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.uploadImage(image) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success resultModel.value = gson.fromJson( diff --git a/app/src/main/java/com/casic/app/smartwell/vm/UserViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/UserViewModel.kt index 31a4d4c..070c35a 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/UserViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/UserViewModel.kt @@ -2,7 +2,7 @@ import androidx.lifecycle.MutableLiveData import com.casic.app.smartwell.base.BaseApplication -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.SubordinateModel import com.casic.app.smartwell.model.UserDetailModel import com.casic.app.smartwell.model.VersionResultModel @@ -25,7 +25,7 @@ fun getUserDetail() = launch({ val response = RetrofitServiceManager.getUserDetail() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { val userDetail = gson.fromJson( response, object : TypeToken() {}.type @@ -48,7 +48,7 @@ * */ fun getSubordinate(hasMine: String?, deptId: String?, roleTips: String?) = launch({ val response = RetrofitServiceManager.getSubordinate(hasMine, deptId, roleTips) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { subordinateModel.value = gson.fromJson( response, object : TypeToken() {}.type @@ -61,7 +61,7 @@ fun changePassword(oldPwd: String, newPwd: String) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.changePassword(oldPwd, newPwd) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success "修改成功,请重新登录".show(BaseApplication.get()) @@ -76,7 +76,7 @@ fun updateVersion() = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.updateVersion() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success versionResultModel.value = gson.fromJson( diff --git a/app/src/main/java/com/casic/app/smartwell/vm/WellViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/WellViewModel.kt index 3d41e9b..9e42e36 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/WellViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/WellViewModel.kt @@ -2,8 +2,7 @@ import androidx.lifecycle.MutableLiveData import com.casic.app.smartwell.base.BaseApplication -import com.casic.app.smartwell.extensions.separateResponseCode -import com.casic.app.smartwell.extensions.toErrorMessage +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.AuthorDeptModel import com.casic.app.smartwell.model.CommonResultModel import com.casic.app.smartwell.model.MapWellListModel @@ -32,7 +31,7 @@ fun countWellByState() = launch({ val response = RetrofitServiceManager.countWellByState() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { val map = HashMap(3) @@ -57,7 +56,7 @@ fun getWellType() = launch({ val response = RetrofitServiceManager.getWellType() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { wellTypeModel.value = gson.fromJson( response, object : TypeToken() {}.type @@ -70,7 +69,7 @@ fun getWellDetail(id: String) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.getWellDetail(id) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success wellDetailModel.value = gson.fromJson( @@ -87,7 +86,7 @@ fun getOperationResult(id: String, state: String) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.getOperationResult(id, state) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success "操作成功".show(BaseApplication.get()) @@ -105,7 +104,7 @@ fun getMonitorResult(id: String) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.getMonitorResult(id) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success monitorModel.value = gson.fromJson( @@ -125,7 +124,7 @@ val response = RetrofitServiceManager.getWellListByPage( keywords, wellType, deptid, bfzt, page ) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { listModel.value = gson.fromJson( response, object : TypeToken() {}.type @@ -137,13 +136,11 @@ fun getWellList() = launch({ val response = RetrofitServiceManager.getWellList() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { totalWellModel.value = gson.fromJson( response, object : TypeToken() {}.type ) - } else { - response.toErrorMessage().show(BaseApplication.get()) } }, { it.printStackTrace() diff --git a/app/src/main/java/com/casic/app/smartwell/widgets/GaoDeClusterMarkerView.kt b/app/src/main/java/com/casic/app/smartwell/widgets/GaoDeClusterMarkerView.kt deleted file mode 100644 index 1f375df..0000000 --- a/app/src/main/java/com/casic/app/smartwell/widgets/GaoDeClusterMarkerView.kt +++ /dev/null @@ -1,100 +0,0 @@ -package com.casic.app.smartwell.widgets - -import android.content.Context -import android.graphics.Bitmap -import android.graphics.Point -import android.view.Gravity -import android.view.LayoutInflater -import android.view.View -import android.widget.TextView -import com.amap.api.maps.Projection -import com.amap.api.maps.model.BitmapDescriptorFactory -import com.amap.api.maps.model.LatLng -import com.amap.api.maps.model.LatLngBounds -import com.amap.api.maps.model.MarkerOptions -import com.casic.app.smartwell.R -import com.pengxh.kt.lite.extensions.toBitmap -import java.util.* - -class GaoDeClusterMarkerView( - private val context: Context, firstMarkers: MarkerOptions, projection: Projection, gridSize: Int -) { - //当前可观区域里的 聚合过之后的集合 - private val includeMarkers: ArrayList - - // 创建区域 - val bounds: LatLngBounds - var options: MarkerOptions = MarkerOptions() - - init { - val screenLocation = projection.toScreenLocation(firstMarkers.position) - //范围类 - val southwestPoint = Point(screenLocation.x - gridSize, screenLocation.y + gridSize) - //范围类 - val northeastPoint = Point(screenLocation.x + gridSize, screenLocation.y - gridSize) - bounds = LatLngBounds( - projection.fromScreenLocation(southwestPoint), - projection.fromScreenLocation(northeastPoint) - ) - //设置初始化marker属性 - options.anchor(0.5f, 1.3f) - .title(firstMarkers.title) - .position(firstMarkers.position) - .icon(firstMarkers.icon) - .snippet(firstMarkers.snippet) - .draggable(false) - includeMarkers = ArrayList() - includeMarkers.add(firstMarkers) - } - - /** - * 添加marker - */ - fun addMarker(markerOptions: MarkerOptions) { - includeMarkers.add(markerOptions) // 添加到列表中 - } - - /** - * 设置聚合点的中心位置以及图标 - */ - fun setPositionAndIcon() { - val size = includeMarkers.size - var lat = 0.0 - var lng = 0.0 - // 一个的时候 - if (size == 1) { //设置marker单个属性 - // 设置marker位置 - options.position( - LatLng( - includeMarkers[0].position.latitude, includeMarkers[0].position.longitude - ) - ) - } else { // 聚合的时候 - //设置marker聚合属性 - for (op in includeMarkers) { - lat += op.position.latitude - lng += op.position.longitude - } - // 设置marker的位置为中心位置为聚集点的平均位置 - options.position(LatLng(lat / size, lng / size)) - } - options.icon(BitmapDescriptorFactory.fromBitmap(getBitmap(size))) - } - - /** - * marker视图 - */ - private fun getBitmap(num: Int): Bitmap? { - val view = LayoutInflater.from(context).inflate(R.layout.marker_gaode, null) - val wellCountView = view.findViewById(R.id.wellCountView) - return if (num > 1) { - wellCountView.visibility = View.VISIBLE - wellCountView.text = String.format("${num}个") - wellCountView.gravity = Gravity.CENTER - view.toBitmap() - } else { - wellCountView.visibility = View.GONE - BitmapDescriptorFactory.fromResource(R.mipmap.well_location).bitmap - } - } -} \ No newline at end of file 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 new file mode 100644 index 0000000..ec455dd --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/widgets/MapWellPopup.kt @@ -0,0 +1,58 @@ +package com.casic.app.smartwell.widgets + +import android.content.Context +import android.view.LayoutInflater +import android.view.ViewGroup +import android.widget.LinearLayout +import android.widget.PopupWindow +import android.widget.TextView +import com.casic.app.smartwell.R +import com.casic.app.smartwell.extensions.valueToType +import com.casic.app.smartwell.model.MapWellListModel + +class MapWellPopup constructor(context: Context) : PopupWindow() { + + init { + width = ViewGroup.LayoutParams.MATCH_PARENT + height = ViewGroup.LayoutParams.WRAP_CONTENT + isOutsideTouchable = true + isFocusable = true + animationStyle = R.style.MapPopupAnimation + setBackgroundDrawable(null) + contentView = LayoutInflater.from(context).inflate( + R.layout.popup_map_info, null, false + ) + } + + fun set(well: MapWellListModel.DataModel, windowClickListener: OnPopupWindowClickListener) { + //反射得到popup里面的控件对象 + val rootView = contentView.findViewById(R.id.rootView) + val wellNameView = contentView.findViewById(R.id.wellNameView) + val wellCodeView = contentView.findViewById(R.id.wellCodeView) + val wellTypeView = contentView.findViewById(R.id.wellTypeView) + val wellStateView = contentView.findViewById(R.id.wellStateView) + val deepView = contentView.findViewById(R.id.deepView) + val locationView = contentView.findViewById(R.id.locationView) + + //绑定数据 + wellNameView.text = String.format("点位名称: ${well.wellName}") + wellCodeView.text = String.format("点位编号: ${well.wellCode}") + wellTypeView.text = String.format("点位类型: ${well.wellType.valueToType()}") + val bfztName = if (well.bfzt == "1") { + "已布防" + } else { + "已撤防" + } + wellStateView.text = String.format("布/撤防状态: $bfztName") + deepView.text = String.format("点位深度: ${well.deep}m") + locationView.text = String.format("详细位置: ${well.position}") + + rootView.setOnClickListener { + windowClickListener.onPopupClicked(well.latGaode.toDouble(), well.lngGaode.toDouble()) + } + } + + interface OnPopupWindowClickListener { + fun onPopupClicked(lat: Double, lng: Double) + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/widgets/cluster/Cluster.java b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/Cluster.java new file mode 100644 index 0000000..9455ccd --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/Cluster.java @@ -0,0 +1,43 @@ +package com.casic.app.smartwell.widgets.cluster; + +import com.amap.api.maps.model.LatLng; +import com.amap.api.maps.model.Marker; + +import java.util.ArrayList; +import java.util.List; + +public class Cluster { + private final LatLng latLng; + private final List clusterItems; + private Marker marker; + + + public Cluster(LatLng latLng) { + this.latLng = latLng; + clusterItems = new ArrayList<>(); + } + + public void addClusterItem(ClusterItem clusterItem) { + clusterItems.add(clusterItem); + } + + public int getClusterCount() { + return clusterItems.size(); + } + + public LatLng getCenterLatLng() { + return latLng; + } + + public void setMarker(Marker marker) { + this.marker = marker; + } + + public Marker getMarker() { + return marker; + } + + public List getClusterItems() { + return clusterItems; + } +} diff --git a/app/src/main/java/com/casic/app/smartwell/widgets/cluster/ClusterItem.java b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/ClusterItem.java new file mode 100644 index 0000000..f5d9a9d --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/ClusterItem.java @@ -0,0 +1,10 @@ +package com.casic.app.smartwell.widgets.cluster; + +import com.amap.api.maps.model.LatLng; + +public interface ClusterItem { + /** + * 返回聚合元素的地理位置 + */ + LatLng getPosition(); +} diff --git a/app/src/main/java/com/casic/app/smartwell/widgets/cluster/ClusterOnClickListener.java b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/ClusterOnClickListener.java new file mode 100644 index 0000000..0efa1f1 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/ClusterOnClickListener.java @@ -0,0 +1,15 @@ +package com.casic.app.smartwell.widgets.cluster; + +import com.amap.api.maps.model.Marker; + +import java.util.List; + +public interface ClusterOnClickListener { + /** + * 点击聚合点的回调处理函数 + * + * @param marker 点击的聚合点 + * @param items 聚合点所包含的元素 + */ + void onMarkerClicked(Marker marker, List items); +} 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 new file mode 100644 index 0000000..40df562 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/ClusterOverlay.java @@ -0,0 +1,349 @@ +package com.casic.app.smartwell.widgets.cluster; + +import android.content.Context; +import android.graphics.Color; +import android.os.Handler; +import android.os.HandlerThread; +import android.os.Looper; +import android.os.Message; +import android.util.TypedValue; +import android.view.Gravity; +import android.widget.TextView; + +import com.amap.api.maps.AMap; +import com.amap.api.maps.AMapUtils; +import com.amap.api.maps.model.BitmapDescriptor; +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.LatLngBounds; +import com.amap.api.maps.model.Marker; +import com.amap.api.maps.model.MarkerOptions; +import com.amap.api.maps.model.animation.AlphaAnimation; +import com.casic.app.smartwell.R; + +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.CopyOnWriteArrayList; + +/** + * 整体设计采用了两个线程,一个线程用于计算组织聚合数据,一个线程负责处理Marker相关操作 + */ +public class ClusterOverlay implements AMap.OnCameraChangeListener, AMap.OnMarkerClickListener { + private final AMap amap; + private final Context context; + private final List clusterItems; + private final List clusters; + private final int clusterSize; + private ClusterOnClickListener clusterClickListener; + private ClusterRender clusterRender; + private final CopyOnWriteArrayList addMarkers = new CopyOnWriteArrayList<>(); + private double clusterDistance; + private final HandlerThread markerHandlerThread = new HandlerThread("addMarker"); + private final HandlerThread signClusterThread = new HandlerThread("calculateCluster"); + private Handler markerHandler; + private Handler signClusterHandler; + private float pxInMeters; + private boolean isCanceled = false; + private final AlphaAnimation addAnimation = new AlphaAnimation(0, 1); + + /** + * 构造函数,批量添加聚合元素时,调用此构造函数 + */ + public ClusterOverlay(Context context, AMap amap, int clusterSize) { + this(context, amap, null, clusterSize); + } + + /** + * 构造函数,批量添加聚合元素时,调用此构造函数 + */ + public ClusterOverlay(Context context, AMap amap, List clusterItems, int clusterSize) { + if (clusterItems != null) { + this.clusterItems = clusterItems; + } else { + this.clusterItems = new ArrayList<>(); + } + this.context = context; + this.clusters = new ArrayList<>(); + this.amap = amap; + this.clusterSize = clusterSize; + this.pxInMeters = amap.getScalePerPixel(); + this.clusterDistance = pxInMeters * clusterSize; + amap.setOnCameraChangeListener(this); + amap.setOnMarkerClickListener(this); + initThreadHandler(); + assignClusters(); + } + + /** + * 设置聚合点的点击事件 + */ + public void setOnClusterClickListener(ClusterOnClickListener clusterClickListener) { + this.clusterClickListener = clusterClickListener; + } + + /** + * 添加一个聚合点 + */ + public void addClusterItem(ClusterItem item) { + Message message = Message.obtain(); + message.what = SignClusterHandler.CALCULATE_SINGLE_CLUSTER; + message.obj = item; + signClusterHandler.sendMessage(message); + } + + /** + * 设置聚合元素的渲染样式,不设置则默认为气泡加数字形式进行渲染 + */ + public void setClusterRender(ClusterRender render) { + this.clusterRender = render; + } + + public void onDestroy() { + isCanceled = true; + signClusterHandler.removeCallbacksAndMessages(null); + markerHandler.removeCallbacksAndMessages(null); + signClusterThread.quit(); + markerHandlerThread.quit(); + for (Marker marker : addMarkers) { + marker.remove(); + } + addMarkers.clear(); + } + + //初始化Handler + private void initThreadHandler() { + markerHandlerThread.start(); + signClusterThread.start(); + markerHandler = new MarkerHandler(markerHandlerThread.getLooper()); + signClusterHandler = new SignClusterHandler(signClusterThread.getLooper()); + } + + @Override + public void onCameraChange(CameraPosition arg0) { + + } + + @Override + public void onCameraChangeFinish(CameraPosition arg0) { + pxInMeters = amap.getScalePerPixel(); + clusterDistance = pxInMeters * clusterSize; + assignClusters(); + } + + @Override + public boolean onMarkerClick(Marker marker) { + if (clusterClickListener == null) { + return true; + } + Cluster cluster = (Cluster) marker.getObject(); + if (cluster != null) { + clusterClickListener.onMarkerClicked(marker, cluster.getClusterItems()); + return true; + } + return false; + } + + /** + * 将聚合元素添加至地图上 + */ + private void addClusterToMap(List clusters) { + ArrayList removeMarkers = new ArrayList<>(addMarkers); + AlphaAnimation alphaAnimation = new AlphaAnimation(1, 0); + RemoveAnimationListener removeAnimationListener = new RemoveAnimationListener(removeMarkers); + for (Marker marker : removeMarkers) { + marker.setAnimation(alphaAnimation); + marker.setAnimationListener(removeAnimationListener); + marker.startAnimation(); + } + + for (Cluster cluster : clusters) { + addSingleClusterToMap(cluster); + } + } + + /** + * 将单个聚合元素添加至地图显示 + */ + private void addSingleClusterToMap(Cluster cluster) { + LatLng latlng = cluster.getCenterLatLng(); + MarkerOptions markerOptions = new MarkerOptions(); + markerOptions.icon(getBitmapDes(cluster.getClusterCount())).position(latlng); + Marker marker = amap.addMarker(markerOptions); + marker.setAnimation(addAnimation); + marker.setObject(cluster); + + marker.startAnimation(); + cluster.setMarker(marker); + addMarkers.add(marker); + } + + private void calculateClusters() { + isCanceled = false; + clusters.clear(); + LatLngBounds visibleBounds = amap.getProjection().getVisibleRegion().latLngBounds; + for (ClusterItem clusterItem : clusterItems) { + if (isCanceled) { + return; + } + LatLng latlng = clusterItem.getPosition(); + if (visibleBounds.contains(latlng)) { + Cluster cluster = getCluster(latlng, clusters); + if (cluster == null) { + cluster = new Cluster(latlng); + clusters.add(cluster); + } + cluster.addClusterItem(clusterItem); + } + } + + //复制一份数据,规避同步 + List tempClusters = new ArrayList<>(clusters); + Message message = Message.obtain(); + message.what = MarkerHandler.ADD_CLUSTER_LIST; + message.obj = tempClusters; + if (isCanceled) { + return; + } + markerHandler.sendMessage(message); + } + + /** + * 对点进行聚合 + */ + private void assignClusters() { + isCanceled = true; + signClusterHandler.removeMessages(SignClusterHandler.CALCULATE_CLUSTER); + signClusterHandler.sendEmptyMessage(SignClusterHandler.CALCULATE_CLUSTER); + } + + /** + * 在已有的聚合基础上,对添加的单个元素进行聚合 + */ + private void calculateSingleCluster(ClusterItem clusterItem) { + LatLngBounds visibleBounds = amap.getProjection().getVisibleRegion().latLngBounds; + LatLng latlng = clusterItem.getPosition(); + if (!visibleBounds.contains(latlng)) { + return; + } + Cluster cluster = getCluster(latlng, clusters); + if (cluster != null) { + cluster.addClusterItem(clusterItem); + Message message = Message.obtain(); + message.what = MarkerHandler.UPDATE_SINGLE_CLUSTER; + + message.obj = cluster; + markerHandler.removeMessages(MarkerHandler.UPDATE_SINGLE_CLUSTER); + markerHandler.sendMessageDelayed(message, 5); + } else { + cluster = new Cluster(latlng); + clusters.add(cluster); + cluster.addClusterItem(clusterItem); + Message message = Message.obtain(); + message.what = MarkerHandler.ADD_SINGLE_CLUSTER; + message.obj = cluster; + markerHandler.sendMessage(message); + } + } + + /** + * 根据一个点获取是否可以依附的聚合点,没有则返回null + */ + private Cluster getCluster(LatLng latLng, List clusters) { + for (Cluster cluster : clusters) { + LatLng clusterCenterPoint = cluster.getCenterLatLng(); + double distance = AMapUtils.calculateLineDistance(latLng, clusterCenterPoint); + if (distance < clusterDistance && amap.getCameraPosition().zoom < 19) { + return cluster; + } + } + return null; + } + + + /** + * 获取每个聚合点的绘制样式 + */ + private BitmapDescriptor getBitmapDes(int num) { + TextView textView = new TextView(context); + if (num > 1) { + String tile = String.valueOf(num); + textView.setText(tile); + } + textView.setGravity(Gravity.CENTER); + textView.setTextColor(Color.BLACK); + textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 15); + if (clusterRender != null && clusterRender.getDrawableByCount(num) != null) { + textView.setBackgroundDrawable(clusterRender.getDrawableByCount(num)); + } else { + textView.setBackgroundResource(R.mipmap.well_location); + } + return BitmapDescriptorFactory.fromView(textView); + } + + /** + * 更新已加入地图聚合点的样式 + */ + private void updateCluster(Cluster cluster) { + Marker marker = cluster.getMarker(); + marker.setIcon(getBitmapDes(cluster.getClusterCount())); + } + + /** + * 处理market添加,更新等操作 + */ + class MarkerHandler extends Handler { + + static final int ADD_CLUSTER_LIST = 0; + + static final int ADD_SINGLE_CLUSTER = 1; + + static final int UPDATE_SINGLE_CLUSTER = 2; + + public MarkerHandler(Looper looper) { + super(looper); + } + + public void handleMessage(Message message) { + switch (message.what) { + case ADD_CLUSTER_LIST: + List clusters = (List) message.obj; + addClusterToMap(clusters); + break; + case ADD_SINGLE_CLUSTER: + Cluster cluster = (Cluster) message.obj; + addSingleClusterToMap(cluster); + break; + case UPDATE_SINGLE_CLUSTER: + Cluster updateCluster = (Cluster) message.obj; + updateCluster(updateCluster); + break; + } + } + } + + /** + * 处理聚合点算法线程 + */ + class SignClusterHandler extends Handler { + static final int CALCULATE_CLUSTER = 0; + static final int CALCULATE_SINGLE_CLUSTER = 1; + + public SignClusterHandler(Looper looper) { + super(looper); + } + + public void handleMessage(Message message) { + switch (message.what) { + case CALCULATE_CLUSTER: + calculateClusters(); + break; + case CALCULATE_SINGLE_CLUSTER: + ClusterItem item = (ClusterItem) message.obj; + clusterItems.add(item); + calculateSingleCluster(item); + break; + } + } + } +} diff --git a/app/src/main/java/com/casic/app/smartwell/widgets/cluster/ClusterRender.java b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/ClusterRender.java new file mode 100644 index 0000000..427ff14 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/ClusterRender.java @@ -0,0 +1,10 @@ +package com.casic.app.smartwell.widgets.cluster; + +import android.graphics.drawable.Drawable; + +public interface ClusterRender { + /** + * 根据聚合点的元素数目返回渲染背景样式 + */ + Drawable getDrawableByCount(int clusterNum); +} diff --git a/app/src/main/java/com/casic/app/smartwell/widgets/cluster/RegionItem.java b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/RegionItem.java new file mode 100644 index 0000000..7b2b6c4 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/RegionItem.java @@ -0,0 +1,23 @@ +package com.casic.app.smartwell.widgets.cluster; + +import com.amap.api.maps.model.LatLng; +import com.casic.app.smartwell.model.MapWellListModel; + +public class RegionItem implements ClusterItem { + private final LatLng latLng; + private final MapWellListModel.DataModel well; + + public RegionItem(LatLng latLng, MapWellListModel.DataModel well) { + this.latLng = latLng; + this.well = well; + } + + @Override + public LatLng getPosition() { + return latLng; + } + + public MapWellListModel.DataModel getWell() { + return well; + } +} diff --git a/app/src/main/java/com/casic/app/smartwell/widgets/cluster/RemoveAnimationListener.java b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/RemoveAnimationListener.java new file mode 100644 index 0000000..c9c5e84 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/RemoveAnimationListener.java @@ -0,0 +1,30 @@ +package com.casic.app.smartwell.widgets.cluster; + +import com.amap.api.maps.model.Marker; +import com.amap.api.maps.model.animation.Animation; + +import java.util.List; + +/** + * marker渐变动画,动画结束后将Marker删除 + */ +public class RemoveAnimationListener implements Animation.AnimationListener { + private final List removeMarkers; + + public RemoveAnimationListener(List removeMarkers) { + this.removeMarkers = removeMarkers; + } + + @Override + public void onAnimationStart() { + + } + + @Override + public void onAnimationEnd() { + for (Marker marker : removeMarkers) { + marker.remove(); + } + removeMarkers.clear(); + } +} \ No newline at end of file diff --git a/app/src/main/res/anim/map_popup_hide.xml b/app/src/main/res/anim/map_popup_hide.xml new file mode 100644 index 0000000..119726b --- /dev/null +++ b/app/src/main/res/anim/map_popup_hide.xml @@ -0,0 +1,12 @@ + + + + \ No newline at end of file diff --git a/app/src/main/res/anim/map_popup_show.xml b/app/src/main/res/anim/map_popup_show.xml new file mode 100644 index 0000000..1d281ef --- /dev/null +++ b/app/src/main/res/anim/map_popup_show.xml @@ -0,0 +1,12 @@ + + + + \ No newline at end of file diff --git a/app/src/main/res/anim/popup_hide.xml b/app/src/main/res/anim/popup_hide.xml index 55c7aca..7480485 100644 --- a/app/src/main/res/anim/popup_hide.xml +++ b/app/src/main/res/anim/popup_hide.xml @@ -1,7 +1,8 @@ - + \ No newline at end of file diff --git a/app/src/main/res/anim/popup_show.xml b/app/src/main/res/anim/popup_show.xml index 1d281ef..dbe2833 100644 --- a/app/src/main/res/anim/popup_show.xml +++ b/app/src/main/res/anim/popup_show.xml @@ -1,12 +1,8 @@ \ No newline at end of file diff --git a/app/src/main/res/drawable/bg_solid_layout_transparent_radius_10.xml b/app/src/main/res/drawable/bg_solid_layout_transparent_radius_10.xml deleted file mode 100644 index 15e6a4b..0000000 --- a/app/src/main/res/drawable/bg_solid_layout_transparent_radius_10.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - \ 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 new file mode 100644 index 0000000..18c1e99 --- /dev/null +++ b/app/src/main/res/drawable/bg_solid_layout_transparent_radius_5.xml @@ -0,0 +1,10 @@ + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_home.xml b/app/src/main/res/layout/fragment_home.xml index 9796164..b763355 100644 --- a/app/src/main/res/layout/fragment_home.xml +++ b/app/src/main/res/layout/fragment_home.xml @@ -48,7 +48,7 @@ android:orientation="vertical" app:behavior_fitToContents="false" app:behavior_halfExpandedRatio="0.425" - app:behavior_hideable="true" + app:behavior_hideable="false" app:behavior_peekHeight="30dp" app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior"> diff --git a/app/src/main/res/layout/marker_gaode.xml b/app/src/main/res/layout/marker_gaode.xml deleted file mode 100644 index 15e9368..0000000 --- a/app/src/main/res/layout/marker_gaode.xml +++ /dev/null @@ -1,27 +0,0 @@ - - - - - - - \ No newline at end of file diff --git a/app/src/main/res/layout/popup_map_info.xml b/app/src/main/res/layout/popup_map_info.xml index bd6b147..b7db29e 100644 --- a/app/src/main/res/layout/popup_map_info.xml +++ b/app/src/main/res/layout/popup_map_info.xml @@ -1,8 +1,9 @@ diff --git a/app/src/main/java/com/casic/app/smartwell/extensions/Int.kt b/app/src/main/java/com/casic/app/smartwell/extensions/Int.kt index de0617b..a0a5e33 100644 --- a/app/src/main/java/com/casic/app/smartwell/extensions/Int.kt +++ b/app/src/main/java/com/casic/app/smartwell/extensions/Int.kt @@ -1,9 +1,24 @@ package com.casic.app.smartwell.extensions +import android.graphics.Bitmap +import android.graphics.Canvas +import android.graphics.Paint +import android.graphics.RectF + fun Int.toLevel(): String { return if (this == 0) { "" } else { this.toString() } +} + +fun Int.drawCircle(color: Int): Bitmap? { + val bitmap = Bitmap.createBitmap(this * 2, this * 2, Bitmap.Config.ARGB_8888) + val canvas = Canvas(bitmap) + val paint = Paint() + val rectF = RectF(0f, 0f, (this * 2).toFloat(), (this * 2).toFloat()) + paint.color = color + canvas.drawArc(rectF, 0f, 360f, true, paint) + return bitmap } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt index 6b6ca3e..5e45534 100644 --- a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt +++ b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt @@ -2,17 +2,13 @@ import android.content.Context import com.casic.app.smartwell.callback.OnImageCompressListener -import com.casic.app.smartwell.model.ErrorMessageModel import com.casic.app.smartwell.utils.LocaleConstant -import com.google.gson.Gson -import com.google.gson.reflect.TypeToken +import com.google.gson.JsonParser import com.pengxh.kt.lite.extensions.createCompressImageDir import com.pengxh.kt.lite.utils.SaveKeyValues -import org.json.JSONObject import top.zibin.luban.Luban import top.zibin.luban.OnCompressListener import java.io.File -import java.util.Locale /** * String扩展方法 @@ -74,18 +70,22 @@ } } -fun String.separateResponseCode(): Int { +fun String.getResponseCode(): Int { if (this.isBlank()) { return 404 } - return JSONObject(this).getInt("code") + val element = JsonParser.parseString(this) + val jsonObject = element.asJsonObject + return jsonObject.get("code").asInt } -fun String.toErrorMessage(): String { - val errorModel = Gson().fromJson( - this, object : TypeToken() {}.type - ) - return errorModel.message.toString() +fun String.getResponseMessage(): String { + if (this.isBlank()) { + return "" + } + val element = JsonParser.parseString(this) + val jsonObject = element.asJsonObject + return jsonObject.get("message").asString } fun String.compressImage(context: Context, listener: OnImageCompressListener) { @@ -93,9 +93,6 @@ .load(this) .ignoreBy(100) .setTargetDir(context.createCompressImageDir().toString()) - .filter { - !(it.isBlank() || it.lowercase(Locale.getDefault()).endsWith(".gif")) - } .setCompressListener(object : OnCompressListener { override fun onStart() { 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 96df110..cd25fca 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 @@ -1,26 +1,25 @@ package com.casic.app.smartwell.fragment -import android.graphics.Point +import android.graphics.Color +import android.graphics.drawable.BitmapDrawable +import android.graphics.drawable.Drawable 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 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.LatLngBounds import com.amap.api.maps.model.Marker -import com.amap.api.maps.model.MarkerOptions import com.casic.app.smartwell.R import com.casic.app.smartwell.databinding.FragmentHomeBinding +import com.casic.app.smartwell.extensions.drawCircle import com.casic.app.smartwell.extensions.initImmersionBar -import com.casic.app.smartwell.extensions.valueToType import com.casic.app.smartwell.model.MapWellListModel import com.casic.app.smartwell.utils.LocaleConstant import com.casic.app.smartwell.utils.RouteOnMap @@ -31,9 +30,16 @@ import com.casic.app.smartwell.view.WellOperationActivity import com.casic.app.smartwell.vm.OrderViewModel import com.casic.app.smartwell.vm.WellViewModel +import com.casic.app.smartwell.widgets.MapWellPopup +import com.casic.app.smartwell.widgets.cluster.ClusterItem +import com.casic.app.smartwell.widgets.cluster.ClusterOnClickListener +import com.casic.app.smartwell.widgets.cluster.ClusterOverlay +import com.casic.app.smartwell.widgets.cluster.RegionItem 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.convertDrawable +import com.pengxh.kt.lite.extensions.dp2px import com.pengxh.kt.lite.extensions.navigatePageTo import com.pengxh.kt.lite.extensions.show import com.pengxh.kt.lite.utils.LoadingDialogHub @@ -43,35 +49,23 @@ /** * 地图点位带聚合效果 * */ -class HomePageHaveClusterFragment : KotlinBaseFragment(), AMap.OnMapLoadedListener, - AMap.OnCameraChangeListener, AMap.OnMarkerClickListener, AMap.InfoWindowAdapter, - AMap.OnInfoWindowClickListener { +class HomePageHaveClusterFragment : KotlinBaseFragment(), + AMap.OnCameraChangeListener { private val kTag = "HaveClusterFragment" private val easyPopupWindow by lazy { EasyPopupWindow(requireContext()) } - private lateinit var wellViewModel: WellViewModel - private lateinit var orderViewModel: OrderViewModel - private lateinit var aMap: AMap - - /** - * 所有的marker - */ - private var allMarkerOptions: MutableList = ArrayList() - - /** - * 视野内的marker - */ - private var markerOptionsInView: MutableList = ArrayList() - - /** - * 自定义Marker弹出框 - * */ - private lateinit var v: View + private val regionRadius by lazy { LocaleConstant.RADIUS_SIZE.dp2px(requireContext()) } + private val infoPopup by lazy { MapWellPopup(requireContext()) } /** * 所有窨井列表信息集合 * */ - private var wellModels: MutableList = ArrayList() + private val wellModels = ArrayList() + private val backDrawables = HashMap() + private lateinit var wellViewModel: WellViewModel + private lateinit var orderViewModel: OrderViewModel + private lateinit var aMap: AMap + private var clusterOverlay: ClusterOverlay? = null override fun initViewBinding( inflater: LayoutInflater, @@ -106,6 +100,9 @@ } }) + //地图初始化 + initMap(savedInstanceState) + //初始化vm wellViewModel = ViewModelProvider(this)[WellViewModel::class.java] orderViewModel = ViewModelProvider(this)[OrderViewModel::class.java] @@ -120,25 +117,19 @@ val latitudeList: MutableList = ArrayList() val longitudeList: MutableList = ArrayList() it.data?.forEach { well -> - val lat = well.latGaode.toString() - val lng = well.lngGaode.toString() + val lat = well.latGaode + val lng = well.lngGaode if (lat.isNotBlank() && lng.isNotBlank()) { //返回true代表当前位置在大陆、港澳地区,反之不在 val latitude = lat.toDouble() val longitude = lng.toDouble() if (CoordinateConverter.isAMapDataAvailable(latitude, longitude)) { - //缓存所有设备详情,点击Marker时候需要 + //缓存所有井 wellModels.add(well) + //分别缓存经、纬度 latitudeList.add(latitude) longitudeList.add(longitude) - //将所有设备信息转化缓存为Marker点 - allMarkerOptions.add( - MarkerOptions() - .position(LatLng(latitude, longitude)) - .title(well.wellTypeName) - .snippet(well.wellName) - ) } } } @@ -160,12 +151,12 @@ val cameraPosition = CameraPosition(centerLatLng, 16f, 0f, 0f) val cameraUpdate = CameraUpdateFactory.newCameraPosition(cameraPosition) aMap.animateCamera(cameraUpdate, 1500, null) + + //显示点数据 + displayWellOnMap() } } - //地图初始化 - initMap(savedInstanceState) - //获取窨井监控数据 wellViewModel.countResultModel.observe(this) { binding.deployedWellView.text = it["bfWell"] @@ -220,17 +211,10 @@ uiSettings.isCompassEnabled = true uiSettings.zoomPosition = AMapOptions.ZOOM_POSITION_RIGHT_CENTER uiSettings.isTiltGesturesEnabled = false//不许地图随手势倾斜角度 + uiSettings.isRotateGesturesEnabled = false//不允许地图随手势改变方位 - // 地图加载成功监听 - aMap.addOnMapLoadedListener(this) // 地图缩放监听 aMap.addOnCameraChangeListener(this) - // marker 点击事件监听 - aMap.addOnMarkerClickListener(this) - // 点击marker弹出自定义popup - aMap.setInfoWindowAdapter(this) - //信息窗点击事件 - aMap.addOnInfoWindowClickListener(this) } override fun initEvent() { @@ -259,9 +243,111 @@ } - override fun onMapLoaded() { - //地图加载成功之后显示聚合点数据 - initClustersMarkers() + private fun displayWellOnMap() { + clusterOverlay?.onDestroy() + val clusterItems = ArrayList() + + wellModels.forEach { + val latitude = it.latGaode.toDouble() + val longitude = it.lngGaode.toDouble() + + val latLng = LatLng(latitude, longitude, false) + val regionItem = RegionItem(latLng, it) + clusterItems.add(regionItem) + } + + clusterOverlay = ClusterOverlay(requireContext(), aMap, clusterItems, regionRadius) + clusterOverlay?.setClusterRender { clusterNum -> + //聚合圆半径 + val radius = 100.dp2px(requireContext()) + if (clusterNum == 0) { + var bitmapDrawable = backDrawables[0] + if (bitmapDrawable == null) { + bitmapDrawable = BitmapDrawable( + null, radius.drawCircle(Color.argb(159, 100, 149, 237)) + ) + backDrawables[0] = bitmapDrawable + } + bitmapDrawable + } + if (clusterNum == 1) { + var bitmapDrawable = backDrawables[1] + if (bitmapDrawable == null) { + bitmapDrawable = R.mipmap.well_location.convertDrawable(requireContext())!! + backDrawables[1] = bitmapDrawable + } + bitmapDrawable + } else if (clusterNum < 5) { + var bitmapDrawable = backDrawables[2] + if (bitmapDrawable == null) { + bitmapDrawable = BitmapDrawable( + null, radius.drawCircle(Color.argb(159, 100, 149, 237)) + ) + backDrawables[2] = bitmapDrawable + } + bitmapDrawable + } else if (clusterNum < 10) { + var bitmapDrawable = backDrawables[3] + if (bitmapDrawable == null) { + bitmapDrawable = BitmapDrawable( + null, radius.drawCircle(Color.argb(199, 30, 144, 255)) + ) + backDrawables[3] = bitmapDrawable + } + bitmapDrawable + } else { + var bitmapDrawable = backDrawables[4] + if (bitmapDrawable == null) { + bitmapDrawable = BitmapDrawable( + null, radius.drawCircle(Color.argb(235, 65, 105, 225)) + ) + backDrawables[4] = bitmapDrawable + } + bitmapDrawable + } + } + + clusterOverlay?.setOnClusterClickListener(object : ClusterOnClickListener { + override fun onMarkerClicked(marker: Marker?, items: List) { + if (items.size > 1) { + "请缩放地图比例在查看数据".show(requireContext()) + return + } + + var item: RegionItem? = null + val builder = LatLngBounds.Builder() + for (clusterItem in items) { + builder.include(clusterItem.position) + item = clusterItem as RegionItem + } + + item?.apply { + showWellPopup(well) + } + } + }) + } + + private fun showWellPopup(well: MapWellListModel.DataModel) { + infoPopup.set(well, object : MapWellPopup.OnPopupWindowClickListener { + override fun onPopupClicked(lat: Double, lng: Double) { + AlertControlDialog.Builder().setContext(requireContext()).setTitle("操作提示") + .setMessage("确定要前往吗").setNegativeButton("取消").setPositiveButton("确定") + .setOnDialogButtonClickListener(object : + AlertControlDialog.OnDialogButtonClickListener { + override fun onConfirmClick() { + RouteOnMap.startNavigation( + requireContext(), "", LatLng(lat, lng) + ) + } + + override fun onCancelClick() { + + } + }).build().show() + } + }) + infoPopup.showAsDropDown(binding.rightOptionView) } override fun onCameraChange(p0: CameraPosition?) { @@ -282,103 +368,10 @@ } } - //获取视野内的marker 根据聚合算法合成自定义的marker 显示视野内的marker override fun onCameraChangeFinish(p0: CameraPosition?) { //地图缩放之后显示聚合点数据 LoadingDialogHub.dismiss() httpCountDownTimer.cancel() - initClustersMarkers() - } - - private fun initClustersMarkers() { - 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 { - v = LayoutInflater.from(requireContext()).inflate(R.layout.popup_map_info, null) - - //显示闸井信息 - marker?.showInfoWindow() - return true - } - - override fun getInfoWindow(marker: Marker?): View { - //反射得到popup里面的控件对象 - val wellNameView = v.findViewById(R.id.wellNameView) - val wellCodeView = v.findViewById(R.id.wellCodeView) - val wellTypeView = v.findViewById(R.id.wellTypeView) - val wellStateView = v.findViewById(R.id.wellStateView) - val deepView = v.findViewById(R.id.deepView) - val locationView = v.findViewById(R.id.locationView) - - //绑定数据 - val clickedLatLng = marker?.position!! - wellModels.forEach { well -> - if (clickedLatLng.latitude == well.latGaode!!.toDouble() - && clickedLatLng.longitude == well.lngGaode!!.toDouble() - ) { - wellNameView.text = String.format("点位名称: ${well.wellName}") - wellCodeView.text = String.format("点位编号: ${well.wellCode}") - wellTypeView.text = String.format("点位类型: ${well.wellType.valueToType()}") - val bfztName = if (well.bfzt == "1") { - "已布防" - } else { - "已撤防" - } - wellStateView.text = String.format("布/撤防状态: $bfztName") - deepView.text = String.format("点位深度: ${well.deep}m") - locationView.text = String.format("详细位置: ${well.position}") - } - } - return v - } - - /** - * 此方法不能修改整个 InfoWindow 的背景和边框,无论自定义的样式是什么样,SDK 都会在最外层添加一个默认的边框 - * */ - override fun getInfoContents(p0: Marker?): View? = null - - override fun onInfoWindowClick(p0: Marker?) { - p0?.apply { - AlertControlDialog.Builder() - .setContext(requireContext()) - .setTitle("操作提示") - .setMessage("确定要前往吗") - .setNegativeButton("取消") - .setPositiveButton("确定") - .setOnDialogButtonClickListener(object : - AlertControlDialog.OnDialogButtonClickListener { - override fun onConfirmClick() { - val lat = position.latitude.toString() - val lng = position.longitude.toString() - if (lat.isBlank() || lng.isBlank()) { - "点位经纬度异常,无法开启导航".show(requireContext()) - return - } - RouteOnMap.startNavigation( - requireContext(), snippet, LatLng(lat.toDouble(), lng.toDouble()) - ) - } - - override fun onCancelClick() { - - } - }).build().show() - } } /***以下是地图生命周期管理************************************************************************/ 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 a54d213..bfa7a57 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 @@ -44,8 +44,8 @@ * 地图点位不带聚合效果 * */ class HomePageNoClusterFragment : KotlinBaseFragment(), - AMap.OnMapLoadedListener, AMap.OnCameraChangeListener, AMap.OnMarkerClickListener, - AMap.InfoWindowAdapter, AMap.OnInfoWindowClickListener { + AMap.OnCameraChangeListener, AMap.OnMarkerClickListener, AMap.InfoWindowAdapter, + AMap.OnInfoWindowClickListener { private val kTag = "NoClusterFragment" private val easyPopupWindow by lazy { EasyPopupWindow(requireContext()) } @@ -109,6 +109,9 @@ wellViewModel = ViewModelProvider(this)[WellViewModel::class.java] orderViewModel = ViewModelProvider(this)[OrderViewModel::class.java] + //地图初始化 + initMap(savedInstanceState) + //获取所有窨井数据 httpCountDownTimer.start() LoadingDialogHub.show(requireActivity(), "数据加载中,请稍后...") @@ -157,12 +160,12 @@ val cameraPosition = CameraPosition(centerLatLng, 16f, 0f, 0f) val cameraUpdate = CameraUpdateFactory.newCameraPosition(cameraPosition) aMap.animateCamera(cameraUpdate, 1500, null) + + //显示点数据 + displayWellOnMap() } } - //地图初始化 - initMap(savedInstanceState) - //获取窨井监控数据 wellViewModel.countResultModel.observe(this) { binding.deployedWellView.text = it["bfWell"] @@ -214,9 +217,8 @@ uiSettings.isCompassEnabled = true uiSettings.zoomPosition = AMapOptions.ZOOM_POSITION_RIGHT_CENTER uiSettings.isTiltGesturesEnabled = false//不许地图随手势倾斜角度 + uiSettings.isRotateGesturesEnabled = false//不允许地图随手势改变方位 - // 地图加载成功监听 - aMap.addOnMapLoadedListener(this) // 地图缩放监听 aMap.addOnCameraChangeListener(this) // marker 点击事件监听 @@ -253,11 +255,6 @@ } - override fun onMapLoaded() { - //地图加载成功之后显示聚合点数据 - initClustersMarkers() - } - override fun onCameraChange(p0: CameraPosition?) { } @@ -281,10 +278,9 @@ //地图缩放之后显示聚合点数据 LoadingDialogHub.dismiss() httpCountDownTimer.cancel() - initClustersMarkers() } - private fun initClustersMarkers() { + private fun displayWellOnMap() { val proj = aMap.projection val dm = resources.displayMetrics var screenLocation: Point diff --git a/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.java b/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.java deleted file mode 100644 index d8b18ef..0000000 --- a/app/src/main/java/com/casic/app/smartwell/model/ErrorMessageModel.java +++ /dev/null @@ -1,50 +0,0 @@ -package com.casic.app.smartwell.model; - -public class ErrorMessageModel { - - private int code; - private String data; - private String exceptionClazz; - private String message; - private boolean success; - - public int getCode() { - return code; - } - - public void setCode(int code) { - this.code = code; - } - - public String getData() { - return data; - } - - public void setData(String data) { - this.data = data; - } - - public String getExceptionClazz() { - return exceptionClazz; - } - - public void setExceptionClazz(String exceptionClazz) { - this.exceptionClazz = exceptionClazz; - } - - public String getMessage() { - return message; - } - - public void setMessage(String message) { - this.message = message; - } - - public boolean isSuccess() { - return success; - } - - public void setSuccess(boolean success) { - this.success = success; - } -} \ No newline at end of file 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 new file mode 100644 index 0000000..215ac0c --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/PipelineModel.java @@ -0,0 +1,328 @@ +package com.casic.app.smartwell.model; + +import java.util.List; + +public class PipelineModel { + + private Integer code; + private DataModel data; + private String message; + private Boolean success; + + public Integer getCode() { + return code; + } + + public void setCode(Integer code) { + this.code = code; + } + + public DataModel getData() { + return data; + } + + public void setData(DataModel data) { + this.data = data; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + public Boolean getSuccess() { + return success; + } + + public void setSuccess(Boolean success) { + this.success = success; + } + + public static class DataModel { + private List rows; + private Integer total; + + public List getRows() { + return rows; + } + + public void setRows(List rows) { + this.rows = rows; + } + + public Integer getTotal() { + return total; + } + + public void setTotal(Integer total) { + this.total = total; + } + + 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 getBuryMode() { + return buryMode; + } + + public void setBuryMode(String buryMode) { + this.buryMode = buryMode; + } + + public String getConstructEra() { + return constructEra; + } + + public void setConstructEra(String constructEra) { + this.constructEra = constructEra; + } + + 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; + } + } + } +} 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 06d3d2b..4f38a2c 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 = 100 //相距多少米才聚合,单位:米 + const val RADIUS_SIZE = 80 //相距多少米才聚合,单位:米 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:11308" + // 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 0d5f3fa..991e1db 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 @@ -312,4 +312,14 @@ @Header("token") token: String, @Field("clientid") deviceCode: String ): String + + /** + * 管线位置数据 + */ + @GET("/pipeline/listPage") + suspend fun getPipeline( + @Header("token") token: String, + @Query("limit") limit: Int, + @Query("offset") offset: Int + ): String } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt index 1a0ce22..4050067 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt @@ -294,4 +294,11 @@ suspend fun registerPush(clientId: String): String { return api.registerPush(AuthenticationHelper.token!!, clientId) } + + /** + * 管线位置数据 + */ + suspend fun getPipeline(): String { + return api.getPipeline(AuthenticationHelper.token!!, 2000, 1) + } } \ No newline at end of file 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 9270fa1..4ca5a5e 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.HomePageNoClusterFragment +import com.casic.app.smartwell.fragment.HomePageHaveClusterFragment 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/vm/AlarmViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/AlarmViewModel.kt index 9cff08c..e7acc17 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/AlarmViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/AlarmViewModel.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.AlarmContentModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager import com.google.gson.Gson @@ -16,7 +16,7 @@ fun getAlarmContentType(alarmType: String) = launch({ val response = RetrofitServiceManager.getAlarmContentType(alarmType) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { listModel.value = gson.fromJson( response, object : TypeToken() {}.type diff --git a/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt index 5e5b163..895dedd 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/AuthenticateViewModel.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.PublicKeyModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager import com.google.gson.Gson @@ -18,7 +18,7 @@ fun getPublicKey() = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.authenticate() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { keyModel.value = gson.fromJson( response, object : TypeToken() {}.type diff --git a/app/src/main/java/com/casic/app/smartwell/vm/DeviceViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/DeviceViewModel.kt index db5ccf6..899a962 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/DeviceViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/DeviceViewModel.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.DeviceDetailModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager import com.google.gson.Gson @@ -16,7 +16,7 @@ fun getDeviceDetail(deviceCode: String) = launch({ val response = RetrofitServiceManager.getDeviceDetail(deviceCode) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { detailModel.value = gson.fromJson( response, object : TypeToken() {}.type diff --git a/app/src/main/java/com/casic/app/smartwell/vm/LoginViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/LoginViewModel.kt index cd8b8a9..a417398 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/LoginViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/LoginViewModel.kt @@ -2,7 +2,7 @@ import androidx.lifecycle.MutableLiveData import com.casic.app.smartwell.base.BaseApplication -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.CommonResultModel import com.casic.app.smartwell.model.LoginResultModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager @@ -21,7 +21,7 @@ fun enter(account: String, secretKey: String) = launch({ val response = RetrofitServiceManager.login(account, secretKey) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success enterResultModel.value = gson.fromJson( @@ -38,7 +38,7 @@ fun out() = launch({ val response = RetrofitServiceManager.loginOut() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { outResultModel.value = gson.fromJson( response, object : TypeToken() {}.type diff --git a/app/src/main/java/com/casic/app/smartwell/vm/OperationViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/OperationViewModel.kt index 8943ed3..37e115f 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/OperationViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/OperationViewModel.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.vm import com.casic.app.smartwell.base.BaseApplication -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager import com.pengxh.kt.lite.base.BaseViewModel import com.pengxh.kt.lite.extensions.launch @@ -16,7 +16,7 @@ fun acceptWorkOrder(id: String) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.acceptWorkOrder(id) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success "接单成功".show(BaseApplication.get()) @@ -35,7 +35,7 @@ loadState.value = LoadState.Loading val response = RetrofitServiceManager.confirmWorkOrder(id, firstState, firstStatePhotos, needHandle) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success "工单确认成功".show(BaseApplication.get()) @@ -50,7 +50,7 @@ fun transferWorkOrder(id: String, userId: String) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.transferWorkOrder(id, userId) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success "转单成功".show(BaseApplication.get()) @@ -65,7 +65,7 @@ fun completeWorkOrder(id: String, handleMessage: String, handlePhotos: String) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.completeWorkOrder(id, handleMessage, handlePhotos) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success "工单处理成功".show(BaseApplication.get()) diff --git a/app/src/main/java/com/casic/app/smartwell/vm/OrderViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/OrderViewModel.kt index 4cb26b7..d2fad86 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/OrderViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/OrderViewModel.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.OrderDetailModel import com.casic.app.smartwell.model.OrderListModel import com.casic.app.smartwell.model.OrderStatusModel @@ -37,7 +37,7 @@ val response = RetrofitServiceManager.getSearchResult( keywords, alarmContent, alarmLevel, jobStatus, deptId, beginTime, endTime, offset ) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success searchResult.value = gson.fromJson( @@ -53,7 +53,7 @@ fun getWorkOrderListByState(jobStatus: String, page: Int) = launch({ val response = RetrofitServiceManager.getWorkOrderList(jobStatus, page) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { orderList.value = gson.fromJson( response, object : TypeToken() {}.type @@ -65,7 +65,7 @@ fun getNotAcceptOderList(page: Int) = launch({ val response = RetrofitServiceManager.getNotAcceptOderList(page) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { orderList.value = gson.fromJson( response, object : TypeToken() {}.type @@ -77,7 +77,7 @@ fun getNotHandleOderList(page: Int) = launch({ val response = RetrofitServiceManager.getNotHandleOderList(page) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { orderList.value = gson.fromJson( response, object : TypeToken() {}.type @@ -89,7 +89,7 @@ fun countWorkOrderByState() = launch({ val response = RetrofitServiceManager.countWorkOrderByState() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { val map = HashMap(4) @@ -107,7 +107,7 @@ fun getOrderStatus() = launch({ val response = RetrofitServiceManager.getOrderStatus() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { orderStatusModel.value = gson.fromJson( response, object : TypeToken() {}.type @@ -120,7 +120,7 @@ fun getWorkOrderDetail(id: String) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.getWorkOrderDetail(id) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success detailModel.value = gson.fromJson( diff --git a/app/src/main/java/com/casic/app/smartwell/vm/PipelineViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/PipelineViewModel.kt new file mode 100644 index 0000000..60c1e2f --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/vm/PipelineViewModel.kt @@ -0,0 +1,28 @@ +package com.casic.app.smartwell.vm + +import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.extensions.getResponseCode +import com.casic.app.smartwell.model.PipelineModel +import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken +import com.pengxh.kt.lite.base.BaseViewModel +import com.pengxh.kt.lite.extensions.launch + +class PipelineViewModel : BaseViewModel() { + + private val gson by lazy { Gson() } + val lineResult = MutableLiveData() + + fun getPipeline() = launch({ + val response = RetrofitServiceManager.getPipeline() + val responseCode = response.getResponseCode() + if (responseCode == 200) { + lineResult.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } + }, { + it.printStackTrace() + }) +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/PushViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/PushViewModel.kt index 9279815..12fd610 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/PushViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/PushViewModel.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.CommonResultModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager import com.google.gson.Gson @@ -16,7 +16,7 @@ fun registerPush(clientId: String) = launch({ val response = RetrofitServiceManager.registerPush(clientId) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { registerResultModel.value = gson.fromJson( response, object : TypeToken() {}.type diff --git a/app/src/main/java/com/casic/app/smartwell/vm/UploadImageViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/UploadImageViewModel.kt index 8d6744e..9707eeb 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/UploadImageViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/UploadImageViewModel.kt @@ -1,7 +1,7 @@ package com.casic.app.smartwell.vm import androidx.lifecycle.MutableLiveData -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.CommonResultModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager import com.google.gson.Gson @@ -19,7 +19,7 @@ fun uploadImage(image: File) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.uploadImage(image) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success resultModel.value = gson.fromJson( diff --git a/app/src/main/java/com/casic/app/smartwell/vm/UserViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/UserViewModel.kt index 31a4d4c..070c35a 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/UserViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/UserViewModel.kt @@ -2,7 +2,7 @@ import androidx.lifecycle.MutableLiveData import com.casic.app.smartwell.base.BaseApplication -import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.SubordinateModel import com.casic.app.smartwell.model.UserDetailModel import com.casic.app.smartwell.model.VersionResultModel @@ -25,7 +25,7 @@ fun getUserDetail() = launch({ val response = RetrofitServiceManager.getUserDetail() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { val userDetail = gson.fromJson( response, object : TypeToken() {}.type @@ -48,7 +48,7 @@ * */ fun getSubordinate(hasMine: String?, deptId: String?, roleTips: String?) = launch({ val response = RetrofitServiceManager.getSubordinate(hasMine, deptId, roleTips) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { subordinateModel.value = gson.fromJson( response, object : TypeToken() {}.type @@ -61,7 +61,7 @@ fun changePassword(oldPwd: String, newPwd: String) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.changePassword(oldPwd, newPwd) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success "修改成功,请重新登录".show(BaseApplication.get()) @@ -76,7 +76,7 @@ fun updateVersion() = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.updateVersion() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success versionResultModel.value = gson.fromJson( diff --git a/app/src/main/java/com/casic/app/smartwell/vm/WellViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/WellViewModel.kt index 3d41e9b..9e42e36 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/WellViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/WellViewModel.kt @@ -2,8 +2,7 @@ import androidx.lifecycle.MutableLiveData import com.casic.app.smartwell.base.BaseApplication -import com.casic.app.smartwell.extensions.separateResponseCode -import com.casic.app.smartwell.extensions.toErrorMessage +import com.casic.app.smartwell.extensions.getResponseCode import com.casic.app.smartwell.model.AuthorDeptModel import com.casic.app.smartwell.model.CommonResultModel import com.casic.app.smartwell.model.MapWellListModel @@ -32,7 +31,7 @@ fun countWellByState() = launch({ val response = RetrofitServiceManager.countWellByState() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { val map = HashMap(3) @@ -57,7 +56,7 @@ fun getWellType() = launch({ val response = RetrofitServiceManager.getWellType() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { wellTypeModel.value = gson.fromJson( response, object : TypeToken() {}.type @@ -70,7 +69,7 @@ fun getWellDetail(id: String) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.getWellDetail(id) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success wellDetailModel.value = gson.fromJson( @@ -87,7 +86,7 @@ fun getOperationResult(id: String, state: String) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.getOperationResult(id, state) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success "操作成功".show(BaseApplication.get()) @@ -105,7 +104,7 @@ fun getMonitorResult(id: String) = launch({ loadState.value = LoadState.Loading val response = RetrofitServiceManager.getMonitorResult(id) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { loadState.value = LoadState.Success monitorModel.value = gson.fromJson( @@ -125,7 +124,7 @@ val response = RetrofitServiceManager.getWellListByPage( keywords, wellType, deptid, bfzt, page ) - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { listModel.value = gson.fromJson( response, object : TypeToken() {}.type @@ -137,13 +136,11 @@ fun getWellList() = launch({ val response = RetrofitServiceManager.getWellList() - val responseCode = response.separateResponseCode() + val responseCode = response.getResponseCode() if (responseCode == 200) { totalWellModel.value = gson.fromJson( response, object : TypeToken() {}.type ) - } else { - response.toErrorMessage().show(BaseApplication.get()) } }, { it.printStackTrace() diff --git a/app/src/main/java/com/casic/app/smartwell/widgets/GaoDeClusterMarkerView.kt b/app/src/main/java/com/casic/app/smartwell/widgets/GaoDeClusterMarkerView.kt deleted file mode 100644 index 1f375df..0000000 --- a/app/src/main/java/com/casic/app/smartwell/widgets/GaoDeClusterMarkerView.kt +++ /dev/null @@ -1,100 +0,0 @@ -package com.casic.app.smartwell.widgets - -import android.content.Context -import android.graphics.Bitmap -import android.graphics.Point -import android.view.Gravity -import android.view.LayoutInflater -import android.view.View -import android.widget.TextView -import com.amap.api.maps.Projection -import com.amap.api.maps.model.BitmapDescriptorFactory -import com.amap.api.maps.model.LatLng -import com.amap.api.maps.model.LatLngBounds -import com.amap.api.maps.model.MarkerOptions -import com.casic.app.smartwell.R -import com.pengxh.kt.lite.extensions.toBitmap -import java.util.* - -class GaoDeClusterMarkerView( - private val context: Context, firstMarkers: MarkerOptions, projection: Projection, gridSize: Int -) { - //当前可观区域里的 聚合过之后的集合 - private val includeMarkers: ArrayList - - // 创建区域 - val bounds: LatLngBounds - var options: MarkerOptions = MarkerOptions() - - init { - val screenLocation = projection.toScreenLocation(firstMarkers.position) - //范围类 - val southwestPoint = Point(screenLocation.x - gridSize, screenLocation.y + gridSize) - //范围类 - val northeastPoint = Point(screenLocation.x + gridSize, screenLocation.y - gridSize) - bounds = LatLngBounds( - projection.fromScreenLocation(southwestPoint), - projection.fromScreenLocation(northeastPoint) - ) - //设置初始化marker属性 - options.anchor(0.5f, 1.3f) - .title(firstMarkers.title) - .position(firstMarkers.position) - .icon(firstMarkers.icon) - .snippet(firstMarkers.snippet) - .draggable(false) - includeMarkers = ArrayList() - includeMarkers.add(firstMarkers) - } - - /** - * 添加marker - */ - fun addMarker(markerOptions: MarkerOptions) { - includeMarkers.add(markerOptions) // 添加到列表中 - } - - /** - * 设置聚合点的中心位置以及图标 - */ - fun setPositionAndIcon() { - val size = includeMarkers.size - var lat = 0.0 - var lng = 0.0 - // 一个的时候 - if (size == 1) { //设置marker单个属性 - // 设置marker位置 - options.position( - LatLng( - includeMarkers[0].position.latitude, includeMarkers[0].position.longitude - ) - ) - } else { // 聚合的时候 - //设置marker聚合属性 - for (op in includeMarkers) { - lat += op.position.latitude - lng += op.position.longitude - } - // 设置marker的位置为中心位置为聚集点的平均位置 - options.position(LatLng(lat / size, lng / size)) - } - options.icon(BitmapDescriptorFactory.fromBitmap(getBitmap(size))) - } - - /** - * marker视图 - */ - private fun getBitmap(num: Int): Bitmap? { - val view = LayoutInflater.from(context).inflate(R.layout.marker_gaode, null) - val wellCountView = view.findViewById(R.id.wellCountView) - return if (num > 1) { - wellCountView.visibility = View.VISIBLE - wellCountView.text = String.format("${num}个") - wellCountView.gravity = Gravity.CENTER - view.toBitmap() - } else { - wellCountView.visibility = View.GONE - BitmapDescriptorFactory.fromResource(R.mipmap.well_location).bitmap - } - } -} \ No newline at end of file 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 new file mode 100644 index 0000000..ec455dd --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/widgets/MapWellPopup.kt @@ -0,0 +1,58 @@ +package com.casic.app.smartwell.widgets + +import android.content.Context +import android.view.LayoutInflater +import android.view.ViewGroup +import android.widget.LinearLayout +import android.widget.PopupWindow +import android.widget.TextView +import com.casic.app.smartwell.R +import com.casic.app.smartwell.extensions.valueToType +import com.casic.app.smartwell.model.MapWellListModel + +class MapWellPopup constructor(context: Context) : PopupWindow() { + + init { + width = ViewGroup.LayoutParams.MATCH_PARENT + height = ViewGroup.LayoutParams.WRAP_CONTENT + isOutsideTouchable = true + isFocusable = true + animationStyle = R.style.MapPopupAnimation + setBackgroundDrawable(null) + contentView = LayoutInflater.from(context).inflate( + R.layout.popup_map_info, null, false + ) + } + + fun set(well: MapWellListModel.DataModel, windowClickListener: OnPopupWindowClickListener) { + //反射得到popup里面的控件对象 + val rootView = contentView.findViewById(R.id.rootView) + val wellNameView = contentView.findViewById(R.id.wellNameView) + val wellCodeView = contentView.findViewById(R.id.wellCodeView) + val wellTypeView = contentView.findViewById(R.id.wellTypeView) + val wellStateView = contentView.findViewById(R.id.wellStateView) + val deepView = contentView.findViewById(R.id.deepView) + val locationView = contentView.findViewById(R.id.locationView) + + //绑定数据 + wellNameView.text = String.format("点位名称: ${well.wellName}") + wellCodeView.text = String.format("点位编号: ${well.wellCode}") + wellTypeView.text = String.format("点位类型: ${well.wellType.valueToType()}") + val bfztName = if (well.bfzt == "1") { + "已布防" + } else { + "已撤防" + } + wellStateView.text = String.format("布/撤防状态: $bfztName") + deepView.text = String.format("点位深度: ${well.deep}m") + locationView.text = String.format("详细位置: ${well.position}") + + rootView.setOnClickListener { + windowClickListener.onPopupClicked(well.latGaode.toDouble(), well.lngGaode.toDouble()) + } + } + + interface OnPopupWindowClickListener { + fun onPopupClicked(lat: Double, lng: Double) + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/widgets/cluster/Cluster.java b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/Cluster.java new file mode 100644 index 0000000..9455ccd --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/Cluster.java @@ -0,0 +1,43 @@ +package com.casic.app.smartwell.widgets.cluster; + +import com.amap.api.maps.model.LatLng; +import com.amap.api.maps.model.Marker; + +import java.util.ArrayList; +import java.util.List; + +public class Cluster { + private final LatLng latLng; + private final List clusterItems; + private Marker marker; + + + public Cluster(LatLng latLng) { + this.latLng = latLng; + clusterItems = new ArrayList<>(); + } + + public void addClusterItem(ClusterItem clusterItem) { + clusterItems.add(clusterItem); + } + + public int getClusterCount() { + return clusterItems.size(); + } + + public LatLng getCenterLatLng() { + return latLng; + } + + public void setMarker(Marker marker) { + this.marker = marker; + } + + public Marker getMarker() { + return marker; + } + + public List getClusterItems() { + return clusterItems; + } +} diff --git a/app/src/main/java/com/casic/app/smartwell/widgets/cluster/ClusterItem.java b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/ClusterItem.java new file mode 100644 index 0000000..f5d9a9d --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/ClusterItem.java @@ -0,0 +1,10 @@ +package com.casic.app.smartwell.widgets.cluster; + +import com.amap.api.maps.model.LatLng; + +public interface ClusterItem { + /** + * 返回聚合元素的地理位置 + */ + LatLng getPosition(); +} diff --git a/app/src/main/java/com/casic/app/smartwell/widgets/cluster/ClusterOnClickListener.java b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/ClusterOnClickListener.java new file mode 100644 index 0000000..0efa1f1 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/ClusterOnClickListener.java @@ -0,0 +1,15 @@ +package com.casic.app.smartwell.widgets.cluster; + +import com.amap.api.maps.model.Marker; + +import java.util.List; + +public interface ClusterOnClickListener { + /** + * 点击聚合点的回调处理函数 + * + * @param marker 点击的聚合点 + * @param items 聚合点所包含的元素 + */ + void onMarkerClicked(Marker marker, List items); +} 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 new file mode 100644 index 0000000..40df562 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/ClusterOverlay.java @@ -0,0 +1,349 @@ +package com.casic.app.smartwell.widgets.cluster; + +import android.content.Context; +import android.graphics.Color; +import android.os.Handler; +import android.os.HandlerThread; +import android.os.Looper; +import android.os.Message; +import android.util.TypedValue; +import android.view.Gravity; +import android.widget.TextView; + +import com.amap.api.maps.AMap; +import com.amap.api.maps.AMapUtils; +import com.amap.api.maps.model.BitmapDescriptor; +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.LatLngBounds; +import com.amap.api.maps.model.Marker; +import com.amap.api.maps.model.MarkerOptions; +import com.amap.api.maps.model.animation.AlphaAnimation; +import com.casic.app.smartwell.R; + +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.CopyOnWriteArrayList; + +/** + * 整体设计采用了两个线程,一个线程用于计算组织聚合数据,一个线程负责处理Marker相关操作 + */ +public class ClusterOverlay implements AMap.OnCameraChangeListener, AMap.OnMarkerClickListener { + private final AMap amap; + private final Context context; + private final List clusterItems; + private final List clusters; + private final int clusterSize; + private ClusterOnClickListener clusterClickListener; + private ClusterRender clusterRender; + private final CopyOnWriteArrayList addMarkers = new CopyOnWriteArrayList<>(); + private double clusterDistance; + private final HandlerThread markerHandlerThread = new HandlerThread("addMarker"); + private final HandlerThread signClusterThread = new HandlerThread("calculateCluster"); + private Handler markerHandler; + private Handler signClusterHandler; + private float pxInMeters; + private boolean isCanceled = false; + private final AlphaAnimation addAnimation = new AlphaAnimation(0, 1); + + /** + * 构造函数,批量添加聚合元素时,调用此构造函数 + */ + public ClusterOverlay(Context context, AMap amap, int clusterSize) { + this(context, amap, null, clusterSize); + } + + /** + * 构造函数,批量添加聚合元素时,调用此构造函数 + */ + public ClusterOverlay(Context context, AMap amap, List clusterItems, int clusterSize) { + if (clusterItems != null) { + this.clusterItems = clusterItems; + } else { + this.clusterItems = new ArrayList<>(); + } + this.context = context; + this.clusters = new ArrayList<>(); + this.amap = amap; + this.clusterSize = clusterSize; + this.pxInMeters = amap.getScalePerPixel(); + this.clusterDistance = pxInMeters * clusterSize; + amap.setOnCameraChangeListener(this); + amap.setOnMarkerClickListener(this); + initThreadHandler(); + assignClusters(); + } + + /** + * 设置聚合点的点击事件 + */ + public void setOnClusterClickListener(ClusterOnClickListener clusterClickListener) { + this.clusterClickListener = clusterClickListener; + } + + /** + * 添加一个聚合点 + */ + public void addClusterItem(ClusterItem item) { + Message message = Message.obtain(); + message.what = SignClusterHandler.CALCULATE_SINGLE_CLUSTER; + message.obj = item; + signClusterHandler.sendMessage(message); + } + + /** + * 设置聚合元素的渲染样式,不设置则默认为气泡加数字形式进行渲染 + */ + public void setClusterRender(ClusterRender render) { + this.clusterRender = render; + } + + public void onDestroy() { + isCanceled = true; + signClusterHandler.removeCallbacksAndMessages(null); + markerHandler.removeCallbacksAndMessages(null); + signClusterThread.quit(); + markerHandlerThread.quit(); + for (Marker marker : addMarkers) { + marker.remove(); + } + addMarkers.clear(); + } + + //初始化Handler + private void initThreadHandler() { + markerHandlerThread.start(); + signClusterThread.start(); + markerHandler = new MarkerHandler(markerHandlerThread.getLooper()); + signClusterHandler = new SignClusterHandler(signClusterThread.getLooper()); + } + + @Override + public void onCameraChange(CameraPosition arg0) { + + } + + @Override + public void onCameraChangeFinish(CameraPosition arg0) { + pxInMeters = amap.getScalePerPixel(); + clusterDistance = pxInMeters * clusterSize; + assignClusters(); + } + + @Override + public boolean onMarkerClick(Marker marker) { + if (clusterClickListener == null) { + return true; + } + Cluster cluster = (Cluster) marker.getObject(); + if (cluster != null) { + clusterClickListener.onMarkerClicked(marker, cluster.getClusterItems()); + return true; + } + return false; + } + + /** + * 将聚合元素添加至地图上 + */ + private void addClusterToMap(List clusters) { + ArrayList removeMarkers = new ArrayList<>(addMarkers); + AlphaAnimation alphaAnimation = new AlphaAnimation(1, 0); + RemoveAnimationListener removeAnimationListener = new RemoveAnimationListener(removeMarkers); + for (Marker marker : removeMarkers) { + marker.setAnimation(alphaAnimation); + marker.setAnimationListener(removeAnimationListener); + marker.startAnimation(); + } + + for (Cluster cluster : clusters) { + addSingleClusterToMap(cluster); + } + } + + /** + * 将单个聚合元素添加至地图显示 + */ + private void addSingleClusterToMap(Cluster cluster) { + LatLng latlng = cluster.getCenterLatLng(); + MarkerOptions markerOptions = new MarkerOptions(); + markerOptions.icon(getBitmapDes(cluster.getClusterCount())).position(latlng); + Marker marker = amap.addMarker(markerOptions); + marker.setAnimation(addAnimation); + marker.setObject(cluster); + + marker.startAnimation(); + cluster.setMarker(marker); + addMarkers.add(marker); + } + + private void calculateClusters() { + isCanceled = false; + clusters.clear(); + LatLngBounds visibleBounds = amap.getProjection().getVisibleRegion().latLngBounds; + for (ClusterItem clusterItem : clusterItems) { + if (isCanceled) { + return; + } + LatLng latlng = clusterItem.getPosition(); + if (visibleBounds.contains(latlng)) { + Cluster cluster = getCluster(latlng, clusters); + if (cluster == null) { + cluster = new Cluster(latlng); + clusters.add(cluster); + } + cluster.addClusterItem(clusterItem); + } + } + + //复制一份数据,规避同步 + List tempClusters = new ArrayList<>(clusters); + Message message = Message.obtain(); + message.what = MarkerHandler.ADD_CLUSTER_LIST; + message.obj = tempClusters; + if (isCanceled) { + return; + } + markerHandler.sendMessage(message); + } + + /** + * 对点进行聚合 + */ + private void assignClusters() { + isCanceled = true; + signClusterHandler.removeMessages(SignClusterHandler.CALCULATE_CLUSTER); + signClusterHandler.sendEmptyMessage(SignClusterHandler.CALCULATE_CLUSTER); + } + + /** + * 在已有的聚合基础上,对添加的单个元素进行聚合 + */ + private void calculateSingleCluster(ClusterItem clusterItem) { + LatLngBounds visibleBounds = amap.getProjection().getVisibleRegion().latLngBounds; + LatLng latlng = clusterItem.getPosition(); + if (!visibleBounds.contains(latlng)) { + return; + } + Cluster cluster = getCluster(latlng, clusters); + if (cluster != null) { + cluster.addClusterItem(clusterItem); + Message message = Message.obtain(); + message.what = MarkerHandler.UPDATE_SINGLE_CLUSTER; + + message.obj = cluster; + markerHandler.removeMessages(MarkerHandler.UPDATE_SINGLE_CLUSTER); + markerHandler.sendMessageDelayed(message, 5); + } else { + cluster = new Cluster(latlng); + clusters.add(cluster); + cluster.addClusterItem(clusterItem); + Message message = Message.obtain(); + message.what = MarkerHandler.ADD_SINGLE_CLUSTER; + message.obj = cluster; + markerHandler.sendMessage(message); + } + } + + /** + * 根据一个点获取是否可以依附的聚合点,没有则返回null + */ + private Cluster getCluster(LatLng latLng, List clusters) { + for (Cluster cluster : clusters) { + LatLng clusterCenterPoint = cluster.getCenterLatLng(); + double distance = AMapUtils.calculateLineDistance(latLng, clusterCenterPoint); + if (distance < clusterDistance && amap.getCameraPosition().zoom < 19) { + return cluster; + } + } + return null; + } + + + /** + * 获取每个聚合点的绘制样式 + */ + private BitmapDescriptor getBitmapDes(int num) { + TextView textView = new TextView(context); + if (num > 1) { + String tile = String.valueOf(num); + textView.setText(tile); + } + textView.setGravity(Gravity.CENTER); + textView.setTextColor(Color.BLACK); + textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 15); + if (clusterRender != null && clusterRender.getDrawableByCount(num) != null) { + textView.setBackgroundDrawable(clusterRender.getDrawableByCount(num)); + } else { + textView.setBackgroundResource(R.mipmap.well_location); + } + return BitmapDescriptorFactory.fromView(textView); + } + + /** + * 更新已加入地图聚合点的样式 + */ + private void updateCluster(Cluster cluster) { + Marker marker = cluster.getMarker(); + marker.setIcon(getBitmapDes(cluster.getClusterCount())); + } + + /** + * 处理market添加,更新等操作 + */ + class MarkerHandler extends Handler { + + static final int ADD_CLUSTER_LIST = 0; + + static final int ADD_SINGLE_CLUSTER = 1; + + static final int UPDATE_SINGLE_CLUSTER = 2; + + public MarkerHandler(Looper looper) { + super(looper); + } + + public void handleMessage(Message message) { + switch (message.what) { + case ADD_CLUSTER_LIST: + List clusters = (List) message.obj; + addClusterToMap(clusters); + break; + case ADD_SINGLE_CLUSTER: + Cluster cluster = (Cluster) message.obj; + addSingleClusterToMap(cluster); + break; + case UPDATE_SINGLE_CLUSTER: + Cluster updateCluster = (Cluster) message.obj; + updateCluster(updateCluster); + break; + } + } + } + + /** + * 处理聚合点算法线程 + */ + class SignClusterHandler extends Handler { + static final int CALCULATE_CLUSTER = 0; + static final int CALCULATE_SINGLE_CLUSTER = 1; + + public SignClusterHandler(Looper looper) { + super(looper); + } + + public void handleMessage(Message message) { + switch (message.what) { + case CALCULATE_CLUSTER: + calculateClusters(); + break; + case CALCULATE_SINGLE_CLUSTER: + ClusterItem item = (ClusterItem) message.obj; + clusterItems.add(item); + calculateSingleCluster(item); + break; + } + } + } +} diff --git a/app/src/main/java/com/casic/app/smartwell/widgets/cluster/ClusterRender.java b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/ClusterRender.java new file mode 100644 index 0000000..427ff14 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/ClusterRender.java @@ -0,0 +1,10 @@ +package com.casic.app.smartwell.widgets.cluster; + +import android.graphics.drawable.Drawable; + +public interface ClusterRender { + /** + * 根据聚合点的元素数目返回渲染背景样式 + */ + Drawable getDrawableByCount(int clusterNum); +} diff --git a/app/src/main/java/com/casic/app/smartwell/widgets/cluster/RegionItem.java b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/RegionItem.java new file mode 100644 index 0000000..7b2b6c4 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/RegionItem.java @@ -0,0 +1,23 @@ +package com.casic.app.smartwell.widgets.cluster; + +import com.amap.api.maps.model.LatLng; +import com.casic.app.smartwell.model.MapWellListModel; + +public class RegionItem implements ClusterItem { + private final LatLng latLng; + private final MapWellListModel.DataModel well; + + public RegionItem(LatLng latLng, MapWellListModel.DataModel well) { + this.latLng = latLng; + this.well = well; + } + + @Override + public LatLng getPosition() { + return latLng; + } + + public MapWellListModel.DataModel getWell() { + return well; + } +} diff --git a/app/src/main/java/com/casic/app/smartwell/widgets/cluster/RemoveAnimationListener.java b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/RemoveAnimationListener.java new file mode 100644 index 0000000..c9c5e84 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/widgets/cluster/RemoveAnimationListener.java @@ -0,0 +1,30 @@ +package com.casic.app.smartwell.widgets.cluster; + +import com.amap.api.maps.model.Marker; +import com.amap.api.maps.model.animation.Animation; + +import java.util.List; + +/** + * marker渐变动画,动画结束后将Marker删除 + */ +public class RemoveAnimationListener implements Animation.AnimationListener { + private final List removeMarkers; + + public RemoveAnimationListener(List removeMarkers) { + this.removeMarkers = removeMarkers; + } + + @Override + public void onAnimationStart() { + + } + + @Override + public void onAnimationEnd() { + for (Marker marker : removeMarkers) { + marker.remove(); + } + removeMarkers.clear(); + } +} \ No newline at end of file diff --git a/app/src/main/res/anim/map_popup_hide.xml b/app/src/main/res/anim/map_popup_hide.xml new file mode 100644 index 0000000..119726b --- /dev/null +++ b/app/src/main/res/anim/map_popup_hide.xml @@ -0,0 +1,12 @@ + + + + \ No newline at end of file diff --git a/app/src/main/res/anim/map_popup_show.xml b/app/src/main/res/anim/map_popup_show.xml new file mode 100644 index 0000000..1d281ef --- /dev/null +++ b/app/src/main/res/anim/map_popup_show.xml @@ -0,0 +1,12 @@ + + + + \ No newline at end of file diff --git a/app/src/main/res/anim/popup_hide.xml b/app/src/main/res/anim/popup_hide.xml index 55c7aca..7480485 100644 --- a/app/src/main/res/anim/popup_hide.xml +++ b/app/src/main/res/anim/popup_hide.xml @@ -1,7 +1,8 @@ - + \ No newline at end of file diff --git a/app/src/main/res/anim/popup_show.xml b/app/src/main/res/anim/popup_show.xml index 1d281ef..dbe2833 100644 --- a/app/src/main/res/anim/popup_show.xml +++ b/app/src/main/res/anim/popup_show.xml @@ -1,12 +1,8 @@ \ No newline at end of file diff --git a/app/src/main/res/drawable/bg_solid_layout_transparent_radius_10.xml b/app/src/main/res/drawable/bg_solid_layout_transparent_radius_10.xml deleted file mode 100644 index 15e6a4b..0000000 --- a/app/src/main/res/drawable/bg_solid_layout_transparent_radius_10.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - \ 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 new file mode 100644 index 0000000..18c1e99 --- /dev/null +++ b/app/src/main/res/drawable/bg_solid_layout_transparent_radius_5.xml @@ -0,0 +1,10 @@ + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_home.xml b/app/src/main/res/layout/fragment_home.xml index 9796164..b763355 100644 --- a/app/src/main/res/layout/fragment_home.xml +++ b/app/src/main/res/layout/fragment_home.xml @@ -48,7 +48,7 @@ android:orientation="vertical" app:behavior_fitToContents="false" app:behavior_halfExpandedRatio="0.425" - app:behavior_hideable="true" + app:behavior_hideable="false" app:behavior_peekHeight="30dp" app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior"> diff --git a/app/src/main/res/layout/marker_gaode.xml b/app/src/main/res/layout/marker_gaode.xml deleted file mode 100644 index 15e9368..0000000 --- a/app/src/main/res/layout/marker_gaode.xml +++ /dev/null @@ -1,27 +0,0 @@ - - - - - - - \ No newline at end of file diff --git a/app/src/main/res/layout/popup_map_info.xml b/app/src/main/res/layout/popup_map_info.xml index bd6b147..b7db29e 100644 --- a/app/src/main/res/layout/popup_map_info.xml +++ b/app/src/main/res/layout/popup_map_info.xml @@ -1,8 +1,9 @@ diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index 14c1838..69e56a6 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -80,6 +80,13 @@ + +