Conflicts:
	app/src/main/java/com/navinfo/omqs/ui/activity/map/MainActivity.kt
	app/src/main/java/com/navinfo/omqs/ui/activity/map/MainViewModel.kt
	collect-library/src/main/java/com/navinfo/collect/library/map/handler/MarkHandler.kt
This commit is contained in:
qiji4215
2023-07-18 15:54:06 +08:00
15 changed files with 337 additions and 191 deletions

View File

@@ -1690,7 +1690,7 @@
<m k="speedFlag" v="1">
<caption fill="#000000" k="maxSpeed" priority="0" size="12" stroke="#ffffff"
stroke-width="1.0"></caption>
<symbol src="assets:omdb/icon_4004_1.png" symbol-height="46"
<symbol src="assets:omdb/icon_4004_0.svg" symbol-height="46"
symbol-width="46"></symbol>
<!-- <caption k="minSpeed" dy="-28" fill="#000000" priority="0" size="14" stroke="#ffffff"-->
<!-- stroke-width="1.0"></caption>-->

View File

@@ -1,12 +1,13 @@
package com.navinfo.collect.library.data.entity
import io.realm.RealmObject
import io.realm.annotations.PrimaryKey
open class HadLinkDvoBean @JvmOverloads constructor(
// /**
// * 任务id方便捕捉查询
// */
// var taskId: Int = 0,
/**
* 任务id方便捕捉查询
*/
var taskId: Int = 0,
/**
* 图幅号
*/
@@ -14,6 +15,7 @@ open class HadLinkDvoBean @JvmOverloads constructor(
/**
* linkPid
*/
@PrimaryKey
var linkPid: String = "",
/**
* (几何)加偏后

View File

@@ -1,6 +1,5 @@
package com.navinfo.collect.library.map
import android.os.Build
import androidx.appcompat.app.AppCompatActivity
import androidx.lifecycle.lifecycleScope
import com.navinfo.collect.library.map.handler.*

View File

@@ -1,6 +1,6 @@
package com.navinfo.collect.library.map.handler
import android.content.Context
import android.util.Log
import androidx.appcompat.app.AppCompatActivity
import com.navinfo.collect.library.map.NIMapView
import org.oscim.layers.Layer
@@ -10,6 +10,7 @@ abstract class BaseHandler(context: AppCompatActivity, mapView: NIMapView) {
protected val mMapView: NIMapView = mapView
fun addLayer(layer: Layer, groupType: NIMapView.LAYER_GROUPS) {
Log.e("jingo", "增加了图层 ${layer.toString()}")
mMapView.vtmMap.layers().add(
layer,
groupType.groupIndex
@@ -17,11 +18,11 @@ abstract class BaseHandler(context: AppCompatActivity, mapView: NIMapView) {
}
fun removeLayer(layer: Layer) {
Log.e("jingo", "移除了图层 ${layer.toString()}")
mMapView.vtmMap.layers().remove(layer)
}
// fun setOnMapClickListener(listener: NIMapView.OnMapClickListener) {
// mMapView.setOnMapClickListener(listener)
// }

View File

@@ -36,6 +36,7 @@ class LineHandler(context: AppCompatActivity, mapView: NIMapView) : BaseHandler(
onTaskLinkItemClickListener = listener
}
/**
* 路口高亮
*/
@@ -183,6 +184,12 @@ class LineHandler(context: AppCompatActivity, mapView: NIMapView) : BaseHandler(
* 增加一条任务高亮线
*/
fun addTaskLink(linkBean: HadLinkDvoBean) {
for (marker in omdbTaskMarkerLayer.itemList) {
if ((marker as MarkerItem).title == linkBean.linkPid) {
omdbTaskMarkerLayer.removeItem(marker)
break
}
}
if (linkBean.linkStatus == 3) {
val pointList = GeometryTools.getGeoPoints(linkBean.geometry)
val geoPoint = if (pointList.size < 3) {
@@ -197,7 +204,10 @@ class LineHandler(context: AppCompatActivity, mapView: NIMapView) : BaseHandler(
)
omdbTaskMarkerLayer.addItem(marker)
}
omdbTaskLinkLayer.removeLine(linkBean.linkPid)
omdbTaskLinkLayer.addLine(linkBean)
omdbTaskLinkLayer.update()
mMapView.vtmMap.updateMap(true)
}
/**
@@ -211,6 +221,8 @@ class LineHandler(context: AppCompatActivity, mapView: NIMapView) : BaseHandler(
}
}
omdbTaskLinkLayer.removeLine(linkBeanId)
omdbTaskLinkLayer.update()
mMapView.vtmMap.updateMap(true)
}
}

View File

@@ -12,6 +12,7 @@ import com.baidu.location.LocationClientOption.LocationMode
import com.navinfo.collect.library.data.entity.NiLocation
import com.navinfo.collect.library.map.NIMapView
import com.navinfo.collect.library.utils.DateUtils
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.launch
import org.oscim.core.GeoPoint
@@ -29,7 +30,7 @@ class LocationLayerHandler(context: AppCompatActivity, mapView: NIMapView) :
//
// }
val niLocationFlow = MutableSharedFlow<NiLocation>(5)
val niLocationFlow = MutableSharedFlow<NiLocation>(3)
init {
///添加定位图层到地图,[NIMapView.LAYER_GROUPS.NAVIGATION] 是最上层layer组
@@ -72,10 +73,10 @@ class LocationLayerHandler(context: AppCompatActivity, mapView: NIMapView) :
// )
// if (niLocationListener != null) {
getCurrentNiLocation()?.let { it1 ->
mContext.lifecycleScope.launch {
niLocationFlow.emit(it1)
}
getCurrentNiLocation()?.let { it1 ->
mContext.lifecycleScope.launch(Dispatchers.Default) {
niLocationFlow.emit(it1)
}
// }// niLocationListener.call(it1) }
}

View File

@@ -4,6 +4,7 @@ import android.content.Context
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 com.navinfo.collect.library.R
@@ -25,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 操作
@@ -65,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图层
@@ -79,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(),
@@ -151,30 +178,18 @@ 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(index,(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
@@ -198,69 +213,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
@@ -437,26 +416,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
*/
@@ -523,9 +482,11 @@ class MarkHandler(context: AppCompatActivity, mapView: NIMapView) :
* 添加质检数据marker
*/
fun addNiLocationMarkerItem(niLocation: NiLocation) {
var geoMarkerItem = createNILocationBitmap(niLocation)
niLocationItemizedLayer.addItem(geoMarkerItem)
niLocationItemizedLayer.update()
synchronized(this) {
var geoMarkerItem = createNILocationBitmap(niLocation)
niLocationItemizedLayer.addItem(geoMarkerItem)
niLocationItemizedLayer.update()
}
}
private fun createNILocationBitmap(niLocation: NiLocation): MarkerItem{
@@ -810,6 +771,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(index:Int,it: NiLocation)
}

View File

@@ -3,11 +3,9 @@ package com.navinfo.collect.library.map.handler
import android.graphics.BitmapFactory
import android.graphics.Canvas
import android.graphics.Color
import android.os.Build
import android.text.TextPaint
import android.util.Log
import android.widget.Toast
import androidx.annotation.RequiresApi
import androidx.appcompat.app.AppCompatActivity
import androidx.lifecycle.MutableLiveData
import com.navinfo.collect.library.R
@@ -453,6 +451,32 @@ open class MeasureLayerHandler(context: AppCompatActivity, mapView: NIMapView) :
}
}
/**
* 初始化线数据, 用来二次编辑
*/
fun initPathLine(geometry: String) {
bDrawLine = true
mPathLayer.isEnabled = true
mPathLayerTemp.isEnabled = true
val pointList = GeometryTools.getGeoPoints(geometry)
mPathLayer.setPoints(pointList)
for (point in pointList) {
val markerItem = MarkerItem(createUUID(), "", "", point)
markerLayer.addItem(markerItem)
mPathMakers.add(markerItem)
}
if (mPathLayer.points.size > 1) {
val distance: Double = GeometryTools.getDistance(mPathLayer.points)
val bg = BigDecimal(distance)
val f1 = bg.setScale(3, BigDecimal.ROUND_HALF_UP).toDouble()
lineLengthLiveData.value = f1
tempLineDistanceLiveData.value = "${f1}"
} else {
lineLengthLiveData.value = 0.000
}
mMapView.updateMap(true)
}
private val itemGestureListener: OnItemGestureListener<MarkerInterface> =
object : OnItemGestureListener<MarkerInterface> {
override fun onItemSingleTapUp(index: Int, item: MarkerInterface): Boolean {

View File

@@ -59,12 +59,11 @@ class OmdbTaskLinkLayer(map: Map, private var style: Style) : VectorLayer(map) {
update()
}
fun removeLine(linkPid: String): Boolean {
fun removeLine(linkPid: String) {
if (lineMap.containsKey(linkPid)) {
super.remove(lineMap[linkPid])
lineMap.remove(linkPid)
}
return false
}
fun removeLine(geometry: Geometry) {