This commit is contained in:
qiji4215
2023-07-07 18:06:38 +08:00
36 changed files with 3637 additions and 135 deletions

View File

@@ -0,0 +1,13 @@
package com.navinfo.collect.library.data.entity
import io.realm.RealmList
import io.realm.RealmObject
import io.realm.annotations.PrimaryKey
open class NoteBean @JvmOverloads constructor(
@PrimaryKey
var id: String = "",
var guideGeometry: String = "",
var description: String = "",
var list: RealmList<SketchAttachContent> = RealmList<SketchAttachContent>(),
) : RealmObject()

View File

@@ -0,0 +1,40 @@
package com.navinfo.collect.library.data.entity
import io.realm.RealmObject
import io.realm.annotations.PrimaryKey
/**
* @author zhjch
* @version V1.0
* @ClassName: SketchAttachContent
* @Date 2016/5/19
* @Description: ${TODO}(草图内容 )
*/
open class SketchAttachContent @JvmOverloads constructor(
@PrimaryKey
var id: String = "",
/**
* 获取geo
*
* @return geo
*/
/**
* 设置geo
*
* @param geo geo
*/
//几何
var geometry: String = "",
/**
* 获取style
*
* @return style
*/
/**
* 设置style
*
* @param style style
*/
//样式
var style: String = ""
) : RealmObject()

View File

@@ -20,6 +20,8 @@ abstract class BaseHandler(context: AppCompatActivity, mapView: NIMapView) {
mMapView.vtmMap.layers().remove(layer)
}
// fun setOnMapClickListener(listener: NIMapView.OnMapClickListener) {
// mMapView.setOnMapClickListener(listener)
// }

View File

@@ -8,10 +8,10 @@ import androidx.appcompat.app.AppCompatActivity
import com.navinfo.collect.library.R
import com.navinfo.collect.library.map.NIMapView
import com.navinfo.collect.library.map.layers.MultiLinesLayer
import com.navinfo.collect.library.map.layers.NoteLineLayer
import com.navinfo.collect.library.map.layers.OmdbTaskLinkLayer
import com.navinfo.collect.library.utils.GeometryTools
import com.navinfo.collect.library.utils.StringUtil
import org.locationtech.jts.geom.LineString
import org.oscim.android.canvas.AndroidBitmap
import org.oscim.backend.canvas.Bitmap
import org.oscim.core.GeoPoint
@@ -23,7 +23,6 @@ import org.oscim.layers.marker.MarkerInterface
import org.oscim.layers.marker.MarkerItem
import org.oscim.layers.marker.MarkerSymbol
import org.oscim.layers.vector.PathLayer
import org.oscim.layers.vector.VectorLayer
import org.oscim.layers.vector.geometries.Style
import org.oscim.map.Map
@@ -69,6 +68,9 @@ class LineHandler(context: AppCompatActivity, mapView: NIMapView) : BaseHandler(
layer
}
/**
* 任务线图层
*/
val omdbTaskLinkLayer by lazy {
val omdbTaskLinkLayer = OmdbTaskLinkLayer(
mMapView.vtmMap,
@@ -84,6 +86,7 @@ class LineHandler(context: AppCompatActivity, mapView: NIMapView) : BaseHandler(
omdbTaskLinkLayer
}
init {
mMapView.vtmMap.events.bind(this)

View File

@@ -4,16 +4,17 @@ 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 androidx.lifecycle.lifecycleScope
import com.navinfo.collect.library.R
import com.navinfo.collect.library.data.entity.NoteBean
import com.navinfo.collect.library.data.entity.QsRecordBean
import com.navinfo.collect.library.map.NIMapView
import com.navinfo.collect.library.map.cluster.ClusterMarkerItem
import com.navinfo.collect.library.map.cluster.ClusterMarkerRenderer
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
@@ -22,6 +23,8 @@ 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
import org.oscim.android.canvas.AndroidBitmap
import org.oscim.backend.CanvasAdapter
import org.oscim.backend.canvas.Bitmap
@@ -29,9 +32,9 @@ import org.oscim.backend.canvas.Paint
import org.oscim.core.GeoPoint
import org.oscim.layers.marker.*
import org.oscim.layers.marker.ItemizedLayer.OnItemGestureListener
import org.oscim.layers.vector.geometries.*
import org.oscim.map.Map
import java.util.*
import kotlin.collections.ArrayList
/**
* marker 操作
@@ -56,8 +59,10 @@ class MarkHandler(context: AppCompatActivity, mapView: NIMapView) :
//画布
private lateinit var canvas: org.oscim.backend.canvas.Canvas
private lateinit var itemizedLayer: MyItemizedLayer
private lateinit var markerRendererFactory: MarkerRendererFactory
private var resId = R.mipmap.map_icon_report
private val resId = R.mipmap.map_icon_report
private val noteResId = R.drawable.icon_note_marker
private var itemListener: OnQsRecordItemClickListener? = null
/**
@@ -65,6 +70,56 @@ class MarkHandler(context: AppCompatActivity, mapView: NIMapView) :
*/
private val NUM_13 = 13
/**
* 便签线图层
*/
private val noteLineLayer: NoteLineLayer by lazy {
val layer = NoteLineLayer(mMapView.vtmMap)
addLayer(layer, NIMapView.LAYER_GROUPS.VECTOR)
layer
}
private val noteLayer: MyItemizedLayer by lazy {
val layer = MyItemizedLayer(
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
}
override fun onItemLongPress(
list: MutableList<Int>?,
nearest: Int
): Boolean {
return true
}
})
addLayer(layer, NIMapView.LAYER_GROUPS.OPERATE_MARKER)
layer
}
init {
//新增marker图标样式
val mDefaultBitmap =
@@ -100,6 +155,7 @@ class MarkHandler(context: AppCompatActivity, mapView: NIMapView) :
itemizedLayer.isEnabled = mapPosition.getZoomLevel() >= 12
}
})
initNoteData()
mMapView.updateMap()
}
@@ -141,6 +197,9 @@ class MarkHandler(context: AppCompatActivity, mapView: NIMapView) :
}
}
/**
* 移除marker
*/
fun removeMarker(title: String) {
var marker: MarkerItem? = null
for (e in mDefaultMarkerLayer.itemList) {
@@ -172,12 +231,53 @@ class MarkHandler(context: AppCompatActivity, mapView: NIMapView) :
withContext(Dispatchers.Main) {
mMapView.updateMap(true)
}
}
/**
* 删除marker
* 增加或更新便签
*/
suspend fun addOrUpdateNoteMark(data: NoteBean) {
for (item in noteLayer.itemList) {
if (item is MarkerItem) {
if (item.title == data.id) {
noteLayer.itemList.remove(item)
break
}
}
}
noteLineLayer.removeNoteBeanLines(data)
createNoteMarkerItem(data)
withContext(Dispatchers.Main) {
mMapView.updateMap(true)
}
}
private fun convertGeometry2Drawable(geometry: Geometry, vectorLayerStyle: Style): Drawable? {
var resultDrawable: Drawable? = null
if ("POINT" == geometry.geometryType.uppercase(Locale.getDefault())) {
val geoPoint = GeoPoint(geometry.coordinate.y, geometry.coordinate.x)
if (geoPoint != null) {
resultDrawable = PointDrawable(geoPoint, vectorLayerStyle)
}
} else if ("LINESTRING" == geometry.geometryType.uppercase(Locale.getDefault())) {
val lineString = geometry as LineString
if (lineString != null) {
resultDrawable = LineDrawable(lineString, vectorLayerStyle)
}
} else if ("POLYGON" == geometry.geometryType.uppercase(Locale.getDefault())) {
val polygon = geometry as Polygon
if (polygon != null) {
resultDrawable = PolygonDrawable(polygon, vectorLayerStyle)
}
}
return resultDrawable
}
/**
* 删除质检数据
*/
suspend fun removeQsRecordMark(data: QsRecordBean) {
for (item in itemizedLayer.itemList) {
@@ -191,6 +291,43 @@ class MarkHandler(context: AppCompatActivity, mapView: NIMapView) :
}
}
/**
* 删除标签
*/
suspend fun removeNoteMark(data: NoteBean) {
for (item in noteLayer.itemList) {
if (item is MarkerItem) {
if (item.title == data.id) {
noteLayer.itemList.remove(item)
noteLineLayer.removeNoteBeanLines(data)
noteLayer.populate()
withContext(Dispatchers.Main) {
mMapView.updateMap(true)
}
return
}
}
}
}
/**
* 初始化便签
*/
private fun initNoteData() {
mContext.lifecycleScope.launch(Dispatchers.IO) {
var list = mutableListOf<NoteBean>()
val realm = Realm.getDefaultInstance()
realm.executeTransaction {
val objects = realm.where<NoteBean>().findAll()
list = realm.copyFromRealm(objects)
}
for (item in list) {
createNoteMarkerItem(item)
}
}
}
/**
* 初始话质检数据图层
*/
@@ -276,6 +413,39 @@ class MarkHandler(context: AppCompatActivity, mapView: NIMapView) :
}
/**
* 添加质检数据marker
*/
private suspend fun createNoteMarkerItem(item: NoteBean) {
val bitmap: Bitmap = createTextMarkerBitmap(mContext, item.description, noteResId)
val geometry: Geometry? = GeometryTools.createGeometry(item.guideGeometry)
if (geometry != null) {
var geoPoint: org.oscim.core.GeoPoint? = null
if (geometry.geometryType != null) {
when (geometry.geometryType.uppercase(Locale.getDefault())) {
"POINT" -> geoPoint =
org.oscim.core.GeoPoint(geometry.coordinate.y, geometry.coordinate.x)
}
}
if (geoPoint != null) {
var geoMarkerItem: MarkerItem
geoMarkerItem = ClusterMarkerItem(
1, item.id, item.description, geoPoint
)
val markerSymbol =
MarkerSymbol(bitmap, MarkerSymbol.HotspotPlace.CENTER)
geoMarkerItem.marker = markerSymbol
noteLayer.itemList.add(geoMarkerItem)
}
}
noteLineLayer.showNoteBeanLines(item)
noteLayer.populate()
}
/**
* 添加质检数据marker
*/
private suspend fun createMarkerItem(item: QsRecordBean) {
val bitmap: Bitmap = createTextMarkerBitmap(mContext, item.description, resId)
if (item.t_lifecycle != 2) {
@@ -554,4 +724,5 @@ class MarkHandler(context: AppCompatActivity, mapView: NIMapView) :
interface OnQsRecordItemClickListener {
fun onQsRecordList(list: MutableList<String>)
fun onNoteList(list: MutableList<String>)
}

View File

@@ -1,13 +1,13 @@
package com.navinfo.collect.library.map.handler
import android.content.Context
import android.graphics.Point
import androidx.appcompat.app.AppCompatActivity
import com.navinfo.collect.library.map.NIMapView
import com.navinfo.collect.library.utils.GeometryTools
import org.oscim.core.GeoPoint
import org.oscim.core.Point
open class ViewportHandler(context: AppCompatActivity, mapView: NIMapView) : BaseHandler(context, mapView) {
open class ViewportHandler(context: AppCompatActivity, mapView: NIMapView) :
BaseHandler(context, mapView) {
/**
* Set pivot horizontal / vertical relative to view center in [-1, 1].
* e.g. pivotY 0.5 is usually preferred for navigation, moving center to 25% of view height.
@@ -54,32 +54,47 @@ open class ViewportHandler(context: AppCompatActivity, mapView: NIMapView) : Bas
* @param snapType 扩展外接矩形的方式,用屏幕像素还是距离
* @param distance 距离大小 像素 或 米
*/
// fun toScreenPoint(
// geoPoint: GeoPoint
// ): String {
// val point = Point()
//
// mMapView.vtmMap.viewport().toScreenPoint(geoPoint, false, point)
//
// return "${point.x},${point.y}"
// }
fun toScreenPoint(
geoPoint: GeoPoint
): String {
val point = Point()
): Point {
val point = org.oscim.core.Point()
mMapView.vtmMap.viewport().toScreenPoint(geoPoint, false, point)
return "${point.x},${point.y}"
return Point(point.x.toInt(), point.y.toInt())
}
/**
* 获取几何的外接矩形,返回矩形的左上,右下两个坐标
* @param snapType 扩展外接矩形的方式,用屏幕像素还是距离
* @param distance 距离大小 像素 或 米
*/
fun fromScreenPoint(
px: Float, py: Float
): Map<String, Any> {
val geo = mMapView.vtmMap.viewport().fromScreenPoint(px, py)
// /**
// * 获取几何的外接矩形,返回矩形的左上,右下两个坐标
// * @param snapType 扩展外接矩形的方式,用屏幕像素还是距离
// * @param distance 距离大小 像素 或 米
// */
// fun fromScreenPointMap(
// px: Float, py: Float
// ): Map<String, Any> {
//
// val geo = mMapView.vtmMap.viewport().fromScreenPoint(px, py)
//
// return mapOf(
// "latitude" to geo.latitude,
// "longitude" to geo.longitude,
// "longitudeE6" to geo.longitudeE6,
// "latitudeE6" to geo.latitudeE6,
// )
// }
return mapOf(
"latitude" to geo.latitude,
"longitude" to geo.longitude,
"longitudeE6" to geo.longitudeE6,
"latitudeE6" to geo.latitudeE6,
)
fun fromScreenPoint(point: android.graphics.Point): GeoPoint {
return mMapView.vtmMap.viewport().fromScreenPoint(point.x.toFloat(), point.y.toFloat())
}
}

View File

@@ -0,0 +1,98 @@
package com.navinfo.collect.library.map.layers
import android.graphics.Color
import com.navinfo.collect.library.data.entity.NoteBean
import com.navinfo.collect.library.utils.GeometryTools
import org.oscim.layers.vector.VectorLayer
import org.oscim.layers.vector.geometries.Drawable
import org.oscim.layers.vector.geometries.LineDrawable
import org.oscim.layers.vector.geometries.Style
import org.oscim.map.Map
class NoteLineLayer(map: Map) : VectorLayer(map) {
private val lineMap = HashMap<String, MutableList<Drawable>>()
private var selectDrawable: Drawable? = null
private val selectStyle =
Style.builder().fillColor(Color.GREEN).strokeColor(Color.GREEN)
.strokeWidth(10f).fixed(false).build()
@Synchronized
fun showNoteBeanLines(noteBean: NoteBean) {
removeNoteBeanLines(noteBean)
val list = mutableListOf<Drawable>()
for (item in noteBean.list) {
val lineDrawable =
LineDrawable(GeometryTools.createGeometry(item.geometry), getStyle(item.style))
add(lineDrawable)
list.add(lineDrawable)
}
lineMap[noteBean.id] = list
update()
}
@Synchronized
fun removeNoteBeanLines(noteBean: NoteBean) {
if (lineMap.containsKey(noteBean.id)) {
for (drawable in lineMap[noteBean.id]!!) {
remove(drawable)
}
lineMap.remove(noteBean.id)
}
update()
}
private fun getStyle(style: String): Style {
// if (style.startsWith("4")) {
// canvasStyle = CanvasView.CanvasStyle.RAILWAY_LINE
// } else if (style.startsWith("5")) {
// if (style.contains("cde3ac")) {
// canvasStyle = CanvasView.CanvasStyle.GREENLAND_LINE
// } else if (style.contains("abcaff")) {
// canvasStyle = CanvasView.CanvasStyle.WATER_LINE
// } else if (style.contains("fffe98")) {
// canvasStyle = CanvasView.CanvasStyle.PARKING_LINE
// }
// } else {
// val s: String = style.substring(0, 1)
// if (TextUtils.equals(s, "2")) {
// canvasStyle = CanvasView.CanvasStyle.STRAIGHT_LINE
// } else if (TextUtils.equals(s, "3")) {
// canvasStyle = CanvasView.CanvasStyle.RECT_LINE
// } else if (TextUtils.equals(s, "6")) {
// canvasStyle = CanvasView.CanvasStyle.POLY_LINE
// } else if (TextUtils.equals(s, "7")) {
// canvasStyle = CanvasView.CanvasStyle.ELLIPSE_LINE
// } else if (TextUtils.equals(s, "9")) {
// canvasStyle = CanvasView.CanvasStyle.CIRCULAR_POINT
// } else if (TextUtils.equals(s, "1")) {
// canvasStyle = CanvasView.CanvasStyle.FREE_LINE
// }
val width = style.substring(1, 3).toFloat()
var colorStr: String = style.substring(3, style.length)
colorStr = if (colorStr.length == 6) {
"#ff$colorStr"
} else {
"#ff000000"
}
// val color = colorStr.toLong(16).toInt()
return Style.builder().fillColor(colorStr).fillAlpha(0.5f).strokeColor(colorStr)
.strokeWidth(width).fixed(true).build()
}
fun removeAll() {
for ((_, value) in lineMap) {
for (item in value) {
remove(item)
}
}
lineMap.clear()
update()
}
}

View File

@@ -0,0 +1,12 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="54.723"
android:viewportHeight="40">
<path
android:pathData="M7.442,28.743S26.236,7.002 42.58,4.502C23.513,11.5 1.721,39.987 1.721,39.987L22.968,39.987a1.589,1.589 0,0 0,-1.631 -1L4.445,38.987A78.915,78.915 0,0 1,10.438 33.243c10.9,-0.5 20.43,-1.5 26.968,-10 1.089,-2 -0.815,-1.749 -1.362,-1.749 5.176,-2 16.344,-9.495 14.709,-13.245 -0.815,-0.748 -1.362,-0.251 -1.362,-0.251s8.444,-5 4.077,-7.247S38.214,2.003 38.214,2.003s0.815,-1.5 -1.631,-1.5A31.679,31.679 0,0 0,20.521 7.002s0,-2 -1.362,-1.249C0.359,16.497 7.442,28.743 7.442,28.743Z"
android:fillColor="#EA6B00"/>
<path
android:pathData="M4.6,35.624a2.016,2.016 0,0 0,-1.157 -0.481,2.3 2.3,0 0,0 -1.19,0.164 4.085,4.085 0,0 0,-1.3 1.189,4.031 4.031,0 0,0 -0.8,1.174s-0.478,1.749 0.229,2.1a3.616,3.616 0,0 0,2.484 0.067,4.594 4.594,0 0,0 1.373,-0.5 2.832,2.832 0,0 0,0.973 -0.978A2.291,2.291 0,0 0,4.6 35.624Z"
android:fillColor="#EA6B00"/>
</vector>