修改点击聚合marker崩溃问题

This commit is contained in:
squallzhjch 2023-07-18 15:13:01 +08:00
parent 71948187c3
commit 4ef07f470d
4 changed files with 130 additions and 178 deletions

View File

@ -176,7 +176,7 @@ class MainActivity : BaseActivity() {
//给xml传递viewModel对象
binding.viewModel = viewModel
binding.mainActivityVoice.setOnTouchListener { v, event ->
binding.mainActivityVoice.setOnTouchListener { v, event ->
when (event?.action) {
MotionEvent.ACTION_DOWN -> {
voiceOnTouchStart()//Do Something
@ -206,7 +206,7 @@ class MainActivity : BaseActivity() {
}
}
//捕捉列表变化回调
viewModel.liveDataNoteIdList.observe(this) {
viewModel.liveDataNoteId.observe(this) {
//跳转到质检数据页面
//获取右侧fragment容器
val naviController = findNavController(R.id.main_activity_right_fragment)
@ -214,11 +214,9 @@ class MainActivity : BaseActivity() {
naviController.currentDestination?.let { navDestination ->
when (navDestination.id) {
R.id.RightEmptyFragment -> {
if (it.size == 1) {
val bundle = Bundle()
bundle.putString("NoteId", it[0])
naviController.navigate(R.id.NoteFragment, bundle)
}
val bundle = Bundle()
bundle.putString("NoteId", it)
naviController.navigate(R.id.NoteFragment, bundle)
}
}
}
@ -235,8 +233,8 @@ class MainActivity : BaseActivity() {
//捕捉列表变化回调
viewModel.liveDataNILocationList.observe(this) {
if(viewModel.isSelectTrace()){
Toast.makeText(this,"轨迹被点击了",Toast.LENGTH_LONG).show()
if (viewModel.isSelectTrace()) {
Toast.makeText(this, "轨迹被点击了", Toast.LENGTH_LONG).show()
}
}
@ -544,8 +542,8 @@ class MainActivity : BaseActivity() {
@RequiresApi(Build.VERSION_CODES.N)
fun tracePointsOnclick() {
viewModel.setSelectTrace(!viewModel.isSelectTrace())
if(viewModel.isSelectTrace()){
Toast.makeText(this,"请选择轨迹点!",Toast.LENGTH_LONG).show()
if (viewModel.isSelectTrace()) {
Toast.makeText(this, "请选择轨迹点!", Toast.LENGTH_LONG).show()
}
binding.mainActivityTraceSnapshotPoints.isSelected = viewModel.isSelectTrace()
}
@ -628,7 +626,12 @@ class MainActivity : BaseActivity() {
mapController.mMapView.setScaleBarLayer(GLViewport.Position.BOTTOM_CENTER, 128, 65)
}
mapController.mMapView.vtmMap.animator()
.animateTo(GeoPoint( mapController.mMapView.vtmMap.mapPosition.geoPoint.latitude,mapController.mMapView.vtmMap.mapPosition.geoPoint.longitude))
.animateTo(
GeoPoint(
mapController.mMapView.vtmMap.mapPosition.geoPoint.latitude,
mapController.mMapView.vtmMap.mapPosition.geoPoint.longitude
)
)
}
@RequiresApi(Build.VERSION_CODES.N)
@ -689,14 +692,14 @@ class MainActivity : BaseActivity() {
*/
fun showIndoorDataLayout() {
binding.mainActivityMenuIndoorGroup.visibility = View.VISIBLE
if(Constant.INDOOR_IP.isNotEmpty()){
if (Constant.INDOOR_IP.isNotEmpty()) {
setIndoorGroupEnable(true)
}else{
} else {
setIndoorGroupEnable(false)
}
}
private fun setIndoorGroupEnable(enable: Boolean){
private fun setIndoorGroupEnable(enable: Boolean) {
binding.mainActivitySnapshotFinish.isEnabled = enable
binding.mainActivityTraceSnapshotPoints.isEnabled = enable
binding.mainActivitySnapshotMediaFlag.isEnabled = enable

View File

@ -75,7 +75,7 @@ class MainViewModel @Inject constructor(
val liveDataQsRecordIdList = MutableLiveData<List<String>>()
//地图点击捕捉到的标签ID列表
val liveDataNoteIdList = MutableLiveData<List<String>>()
val liveDataNoteId = MutableLiveData<String>()
//地图点击捕捉到的轨迹列表
val liveDataNILocationList = MutableLiveData<NiLocation>()
@ -159,8 +159,8 @@ class MainViewModel @Inject constructor(
liveDataQsRecordIdList.value = list
}
override fun onNoteList(list: MutableList<String>) {
liveDataNoteIdList.value = list
override fun onNote(id: String) {
liveDataNoteId.value = id
}
override fun onNiLocation(item: NiLocation) {
@ -182,9 +182,7 @@ class MainViewModel @Inject constructor(
// testPoint = it
//线选择状态
if (bSelectRoad) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
captureLink(it)
}
captureLink(it)
} else {
captureItem(it)
}
@ -249,8 +247,7 @@ class MainViewModel @Inject constructor(
//加载轨迹数据
val id = sharedPreferences.getInt(Constant.SELECT_TASK_ID, -1)
val list: List<NiLocation>? = TraceDataBase.getDatabase(
mapController.mMapView.context,
Constant.USER_DATA_PATH
mapController.mMapView.context, Constant.USER_DATA_PATH
).niLocationDao.findToTaskIdAll(id.toString())
if (list != null) {
for (location in list) {
@ -268,11 +265,13 @@ class MainViewModel @Inject constructor(
viewModelScope.launch(Dispatchers.Default) {
//用于定位点捕捉道路
mapController.locationLayerHandler.niLocationFlow.collectLatest { location ->
if (!isSelectRoad()&&!GeometryTools.isCheckError(location.longitude,location.latitude)) if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
if (!isSelectRoad() && !GeometryTools.isCheckError(
location.longitude, location.latitude
)
) {
captureLink(
GeoPoint(
location.latitude,
location.longitude
location.latitude, location.longitude
)
)
}
@ -280,7 +279,7 @@ class MainViewModel @Inject constructor(
mapController.locationLayerHandler.niLocationFlow.collect { location ->
//过滤掉无效点
if(!GeometryTools.isCheckError(location.longitude,location.latitude)){
if (!GeometryTools.isCheckError(location.longitude, location.latitude)) {
val geometry = GeometryTools.createGeometry(
GeoPoint(
location.latitude, location.longitude
@ -309,8 +308,11 @@ class MainViewModel @Inject constructor(
//增加间距判断
if (lastNiLocaion != null) {
val disance = GeometryTools.getDistance(
location.latitude, location.longitude,
lastNiLocaion!!.latitude, lastNiLocaion!!.longitude)
location.latitude,
location.longitude,
lastNiLocaion!!.latitude,
lastNiLocaion!!.longitude
)
//相距差距大于2.5米以上进行存储
if (disance > 2.5) {
traceDataBase.niLocationDao.insert(location)
@ -345,11 +347,11 @@ class MainViewModel @Inject constructor(
*/
@RequiresApi(Build.VERSION_CODES.N)
private suspend fun captureLink(point: GeoPoint) {
if(captureLinkState){
if (captureLinkState) {
return
}
try{
try {
captureLinkState = true
val linkList = realmOperateHelper.queryLink(
@ -447,9 +449,9 @@ class MainViewModel @Inject constructor(
liveDataRoadName.postValue(null)
}
}catch (e:Exception){
} catch (e: Exception) {
}finally {
} finally {
captureLinkState = false
}
@ -501,12 +503,10 @@ class MainViewModel @Inject constructor(
try {
if (!mCameraDialog!!.getmShareUtil().connectstate) {
mCameraDialog!!.updateCameraResources(
1,
mCameraDialog!!.getmDeviceNum()
1, mCameraDialog!!.getmDeviceNum()
)
}
TakePhotoManager.getInstance()
.getCameraVedioClent(mCameraDialog!!.getmDeviceNum())
TakePhotoManager.getInstance().getCameraVedioClent(mCameraDialog!!.getmDeviceNum())
.StopSearch()
} catch (e: Exception) {
}

View File

@ -1,16 +1,13 @@
package com.navinfo.collect.library.map.handler
import android.content.Context
import android.content.SharedPreferences
import android.graphics.BitmapFactory
import android.graphics.Canvas
import android.graphics.Color
import android.util.Log
import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.res.ResourcesCompat
import androidx.lifecycle.lifecycleScope
import com.navinfo.collect.library.R
import com.navinfo.collect.library.data.dao.impl.TraceDataBase
import com.navinfo.collect.library.data.entity.NiLocation
import com.navinfo.collect.library.data.entity.NoteBean
import com.navinfo.collect.library.data.entity.QsRecordBean
@ -21,11 +18,6 @@ import com.navinfo.collect.library.map.layers.MyItemizedLayer
import com.navinfo.collect.library.map.layers.NoteLineLayer
import com.navinfo.collect.library.utils.GeometryTools
import com.navinfo.collect.library.utils.StringUtil
import io.realm.Realm
import io.realm.kotlin.where
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import org.locationtech.jts.geom.Geometry
import org.locationtech.jts.geom.LineString
import org.locationtech.jts.geom.Polygon
@ -34,19 +26,11 @@ import org.oscim.backend.CanvasAdapter
import org.oscim.backend.canvas.Bitmap
import org.oscim.backend.canvas.Paint
import org.oscim.core.GeoPoint
import org.oscim.layers.marker.ItemizedLayer
import org.oscim.layers.marker.*
import org.oscim.layers.marker.ItemizedLayer.OnItemGestureListener
import org.oscim.layers.marker.MarkerInterface
import org.oscim.layers.marker.MarkerItem
import org.oscim.layers.marker.MarkerRendererFactory
import org.oscim.layers.marker.MarkerSymbol
import org.oscim.layers.vector.geometries.Drawable
import org.oscim.layers.vector.geometries.LineDrawable
import org.oscim.layers.vector.geometries.PointDrawable
import org.oscim.layers.vector.geometries.PolygonDrawable
import org.oscim.layers.vector.geometries.Style
import org.oscim.layers.vector.geometries.*
import org.oscim.map.Map
import java.util.Locale
import java.util.*
/**
* marker 操作
@ -74,9 +58,7 @@ class MarkHandler(context: AppCompatActivity, mapView: NIMapView) :
/**
* 画布
*/
private val canvas: org.oscim.backend.canvas.Canvas by lazy {
CanvasAdapter.newCanvas()
}
private val canvas: org.oscim.backend.canvas.Canvas = CanvasAdapter.newCanvas()
/**
* 默认marker图层
@ -88,36 +70,72 @@ class MarkHandler(context: AppCompatActivity, mapView: NIMapView) :
val markerSymbol = MarkerSymbol(
mDefaultBitmap,
MarkerSymbol.HotspotPlace.BOTTOM_CENTER
MarkerSymbol.HotspotPlace.CENTER
)
val layer = ItemizedLayer(
mapView.vtmMap,
ArrayList(),
markerSymbol,
object : OnItemGestureListener<MarkerInterface> {
override fun onItemSingleTapUp(index: Int, item: MarkerInterface?): Boolean {
return false
}
override fun onItemLongPress(index: Int, item: MarkerInterface?): Boolean {
return false
}
}
)
addLayer(layer, NIMapView.LAYER_GROUPS.OPERATE_MARKER)
layer
}
private var niLocationBitmap: Bitmap? = null
private var niLocationBitmap1: Bitmap? = null
private var niLocationBitmap2: Bitmap? = null
private var niLocationBitmap3: Bitmap? = null
private val niLocationBitmap: Bitmap by lazy {
AndroidBitmap(
BitmapFactory.decodeResource(
context.resources,
R.mipmap.icon_gps
)
)
}
private val niLocationBitmap1: Bitmap by lazy {
AndroidBitmap(
BitmapFactory.decodeResource(
context.resources,
R.mipmap.icon_gps_1
)
)
}
private val niLocationBitmap2: Bitmap by lazy {
AndroidBitmap(
BitmapFactory.decodeResource(
context.resources,
R.mipmap.icon_nilocation
)
)
}
private val niLocationBitmap3: Bitmap by lazy {
AndroidBitmap(
BitmapFactory.decodeResource(
context.resources,
R.mipmap.icon_nilocation_1
)
)
}
/**
* 评测数据marker 图层
*/
private val qsRecordItemizedLayer: MyItemizedLayer by lazy {
val bitmapPoi: Bitmap = AndroidBitmap(
BitmapFactory.decodeResource(
mContext.resources,
R.mipmap.map_icon_blue2
)
)
val symbol = MarkerSymbol(bitmapPoi, MarkerSymbol.HotspotPlace.BOTTOM_CENTER)
val markerRendererFactory = MarkerRendererFactory { markerLayer ->
object : ClusterMarkerRenderer(
mContext,
markerLayer,
symbol,
ClusterStyle(
org.oscim.backend.canvas.Color.WHITE,
org.oscim.backend.canvas.Color.BLUE
)
) {
}
}
val layer = MyItemizedLayer(
mMapView.vtmMap,
mutableListOf(),
@ -160,37 +178,24 @@ class MarkHandler(context: AppCompatActivity, mapView: NIMapView) :
*/
private val niLocationItemizedLayer: ItemizedLayer by lazy {
niLocationBitmap =
AndroidBitmap(BitmapFactory.decodeResource(context.resources, R.mipmap.icon_gps))
niLocationBitmap1 =
AndroidBitmap(BitmapFactory.decodeResource(context.resources, R.mipmap.icon_gps_1))
niLocationBitmap2 =
AndroidBitmap(BitmapFactory.decodeResource(context.resources, R.mipmap.icon_nilocation))
niLocationBitmap3 = AndroidBitmap(
BitmapFactory.decodeResource(
context.resources,
R.mipmap.icon_nilocation_1
)
)
val symbol = MarkerSymbol(niLocationBitmap, MarkerSymbol.HotspotPlace.CENTER)
val layer = ItemizedLayer(
mapView.vtmMap,
mutableListOf(),
markerRendererFactory,
object : OnItemGestureListener<MarkerInterface> {
override fun onItemSingleTapUp(index: Int, item: MarkerInterface?): Boolean {
itemListener?.let {
it.onNiLocation((niLocationItemizedLayer.itemList[index] as MarkerItem).uid as NiLocation)
}
return true
symbol,
)
layer.setOnItemGestureListener(object : OnItemGestureListener<MarkerInterface> {
override fun onItemSingleTapUp(index: Int, item: MarkerInterface?): Boolean {
itemListener?.let {
it.onNiLocation((niLocationItemizedLayer.itemList[index] as MarkerItem).uid as NiLocation)
}
return true
}
override fun onItemLongPress(index: Int, item: MarkerInterface?): Boolean {
return true
}
})
override fun onItemLongPress(index: Int, item: MarkerInterface?): Boolean {
return true
}
})
addLayer(layer, NIMapView.LAYER_GROUPS.OPERATE_MARKER)
layer
}
@ -207,69 +212,33 @@ class MarkHandler(context: AppCompatActivity, mapView: NIMapView) :
/**
* 便签图标图层
*/
private val noteLayer: MyItemizedLayer by lazy {
val layer = MyItemizedLayer(
private val noteLayer: ItemizedLayer by lazy {
val bitmap =
AndroidBitmap(BitmapFactory.decodeResource(context.resources, noteResId))
val symbol = MarkerSymbol(bitmap, MarkerSymbol.HotspotPlace.CENTER)
val layer = ItemizedLayer(
mMapView.vtmMap,
mutableListOf(),
markerRendererFactory,
object : MyItemizedLayer.OnItemGestureListener {
override fun onItemSingleTapUp(
list: MutableList<Int>,
nearest: Int
): Boolean {
itemListener?.let {
val idList = mutableListOf<String>()
if (list.size == 0) {
} else {
for (i in list) {
val markerInterface: MarkerInterface =
noteLayer.itemList[i]
if (markerInterface is MarkerItem) {
idList.add(markerInterface.title)
}
}
it.onNoteList(idList.distinct().toMutableList())
}
}
return true
symbol,
)
layer.setOnItemGestureListener(object : OnItemGestureListener<MarkerInterface> {
override fun onItemSingleTapUp(index: Int, item: MarkerInterface?): Boolean {
itemListener?.let {
val marker = layer.itemList[index]
if (marker is MarkerItem)
it.onNote(marker.title)
}
return true
}
override fun onItemLongPress(
list: MutableList<Int>?,
nearest: Int
): Boolean {
return true
}
})
override fun onItemLongPress(index: Int, item: MarkerInterface?): Boolean {
return true
}
})
addLayer(layer, NIMapView.LAYER_GROUPS.OPERATE_MARKER)
layer
}
private val markerRendererFactory: MarkerRendererFactory by lazy {
val bitmapPoi: Bitmap = AndroidBitmap(
BitmapFactory.decodeResource(
mContext.resources,
R.mipmap.map_icon_blue2
)
)
val symbol = MarkerSymbol(bitmapPoi, MarkerSymbol.HotspotPlace.BOTTOM_CENTER)
MarkerRendererFactory { markerLayer ->
object : ClusterMarkerRenderer(
mContext,
markerLayer,
symbol,
ClusterStyle(
org.oscim.backend.canvas.Color.WHITE,
org.oscim.backend.canvas.Color.BLUE
)
) {
}
}
}
private val resId = R.mipmap.map_icon_report
private val noteResId = R.drawable.icon_note_marker
private var itemListener: OnQsRecordItemClickListener? = null
@ -436,26 +405,6 @@ class MarkHandler(context: AppCompatActivity, mapView: NIMapView) :
}
// /**
// * 初始话质检数据图层
// */
// private fun initQsRecordDataLayer() {
//
// mContext.lifecycleScope.launch(Dispatchers.IO) {
// var list = mutableListOf<QsRecordBean>()
// val realm = Realm.getDefaultInstance()
// realm.executeTransaction {
// val objects = realm.where<QsRecordBean>().findAll()
// list = realm.copyFromRealm(objects)
// }
// for (item in list) {
// createMarkerItem(item)
// }
// }
//
// }
/**
* 添加质检数据marker
*/
@ -808,6 +757,6 @@ class MarkHandler(context: AppCompatActivity, mapView: NIMapView) :
interface OnQsRecordItemClickListener {
fun onQsRecordList(list: MutableList<String>)
fun onNoteList(list: MutableList<String>)
fun onNote(noteId: String)
fun onNiLocation(it: NiLocation)
}

2
vtm

@ -1 +1 @@
Subproject commit dd13e533c38b5738ab404c2737d7ccadeff01323
Subproject commit 1ee201a41f78f169873848209a3f3bdac36f185a