增加高亮图层

This commit is contained in:
squallzhjch 2023-04-27 15:01:57 +08:00
parent 977b4b54da
commit b028975221
8 changed files with 201 additions and 119 deletions

View File

@ -68,6 +68,6 @@ open class TaskBean @JvmOverloads constructor(
var message: String = "" var message: String = ""
) : RealmObject() { ) : RealmObject() {
fun getDownLoadUrl(): String { fun getDownLoadUrl(): String {
return "${Constant.SERVER_ADDRESS}devcp/download?fileStr=26" return "${Constant.SERVER_ADDRESS}devcp/download?fileStr=$id"
} }
} }

View File

@ -1,7 +1,10 @@
package com.navinfo.omqs.db package com.navinfo.omqs.db
import android.os.Build
import android.util.Log import android.util.Log
import androidx.annotation.RequiresApi
import com.navinfo.collect.library.data.entity.RenderEntity import com.navinfo.collect.library.data.entity.RenderEntity
import com.navinfo.collect.library.data.entity.RenderEntity.Companion.LinkTable
import com.navinfo.collect.library.map.NIMapController import com.navinfo.collect.library.map.NIMapController
import com.navinfo.collect.library.utils.GeometryTools import com.navinfo.collect.library.utils.GeometryTools
import com.navinfo.collect.library.utils.GeometryToolsKt import com.navinfo.collect.library.utils.GeometryToolsKt
@ -17,10 +20,11 @@ import org.oscim.core.MercatorProjection
import javax.inject.Inject import javax.inject.Inject
import kotlin.streams.toList import kotlin.streams.toList
@RequiresApi(Build.VERSION_CODES.N)
class RealmOperateHelper() { class RealmOperateHelper() {
@Inject @Inject
lateinit var niMapController: NIMapController lateinit var niMapController: NIMapController
/** /**
* 根据当前点位查询匹配的Link数据 * 根据当前点位查询匹配的Link数据
* @param point 点位经纬度信息 * @param point 点位经纬度信息
@ -28,7 +32,12 @@ class RealmOperateHelper() {
* @param bufferType 点位外扩距离的单位 -Meter像素-PIXEL * @param bufferType 点位外扩距离的单位 -Meter像素-PIXEL
* @param sort 是否需要排序 * @param sort 是否需要排序
* */ * */
suspend fun queryLink(point: Point, buffer: Double = DEFAULT_BUFFER, bufferType: BUFFER_TYPE = DEFAULT_BUFFER_TYPE, sort: Boolean = false): MutableList<RenderEntity> { suspend fun queryLink(
point: Point,
buffer: Double = DEFAULT_BUFFER,
bufferType: BUFFER_TYPE = DEFAULT_BUFFER_TYPE,
sort: Boolean = true
): MutableList<RenderEntity> {
val result = mutableListOf<RenderEntity>() val result = mutableListOf<RenderEntity>()
withContext(Dispatchers.IO) { withContext(Dispatchers.IO) {
val polygon = getPolygonFromPoint(point, buffer, bufferType) val polygon = getPolygonFromPoint(point, buffer, bufferType)
@ -45,25 +54,49 @@ class RealmOperateHelper() {
val yStart = tileYSet.stream().min(Comparator.naturalOrder()).orElse(null) val yStart = tileYSet.stream().min(Comparator.naturalOrder()).orElse(null)
val yEnd = tileYSet.stream().max(Comparator.naturalOrder()).orElse(null) val yEnd = tileYSet.stream().max(Comparator.naturalOrder()).orElse(null)
// 查询realm中对应tile号的数据 // 查询realm中对应tile号的数据
val realmList = Realm.getDefaultInstance().where(RenderEntity::class.java) val realm = Realm.getDefaultInstance()
val realmList = realm.where(RenderEntity::class.java)
.equalTo("table", "OMDB_RD_LINK") .equalTo("table", "OMDB_RD_LINK")
.and() .and()
.rawPredicate("tileX>=$xStart and tileX<=$xEnd and tileY>=$yStart and tileY<=$yEnd") .rawPredicate("tileX>=$xStart and tileX<=$xEnd and tileY>=$yStart and tileY<=$yEnd")
.findAll() .findAll()
// 将获取到的数据和查询的polygon做相交只返回相交的数据 // 将获取到的数据和查询的polygon做相交只返回相交的数据
val queryResult = realmList?.stream()?.filter { val dataList = realm.copyFromRealm(realmList)
val queryResult = dataList?.stream()?.filter {
polygon.intersects(it.wkt) polygon.intersects(it.wkt)
}?.toList() }?.toList()
queryResult?.let { queryResult?.let {
result.addAll(queryResult)
}
if (sort) { if (sort) {
result.clear() result.addAll(sortRenderEntity(point, it))
result.addAll(sortRenderEntity(point, result)) } else {
result.addAll(it)
} }
} }
}
return result return result
} }
suspend fun queryLink(
linkPid: String,
): RenderEntity? {
var link: RenderEntity? = null
withContext(Dispatchers.IO) {
val realm = Realm.getDefaultInstance()
val realmR = realm.where(RenderEntity::class.java)
.equalTo("table", "OMDB_RD_LINK")
.and()
.rawPredicate("properties['${LinkTable.linkPid}']=$linkPid")
.findFirst()
if (realmR != null) {
link = realm.copyFromRealm(realmR)
}
}
return link
}
/** /**
* 根据当前点位查询匹配的除Link外的其他要素数据 * 根据当前点位查询匹配的除Link外的其他要素数据
* @param point 点位经纬度信息 * @param point 点位经纬度信息
@ -71,7 +104,12 @@ class RealmOperateHelper() {
* @param bufferType 点位外扩距离的单位 -Meter像素-PIXEL * @param bufferType 点位外扩距离的单位 -Meter像素-PIXEL
* @param sort 是否需要排序 * @param sort 是否需要排序
* */ * */
suspend fun queryElement(point: Point, buffer: Double = DEFAULT_BUFFER, bufferType: BUFFER_TYPE = DEFAULT_BUFFER_TYPE, sort: Boolean = false): MutableList<RenderEntity> { suspend fun queryElement(
point: Point,
buffer: Double = DEFAULT_BUFFER,
bufferType: BUFFER_TYPE = DEFAULT_BUFFER_TYPE,
sort: Boolean = true
): MutableList<RenderEntity> {
val result = mutableListOf<RenderEntity>() val result = mutableListOf<RenderEntity>()
withContext(Dispatchers.IO) { withContext(Dispatchers.IO) {
val polygon = getPolygonFromPoint(point, buffer, bufferType) val polygon = getPolygonFromPoint(point, buffer, bufferType)
@ -121,7 +159,7 @@ class RealmOperateHelper() {
val realmList = Realm.getDefaultInstance().where(RenderEntity::class.java) val realmList = Realm.getDefaultInstance().where(RenderEntity::class.java)
.notEqualTo("table", "OMDB_RD_LINK") .notEqualTo("table", "OMDB_RD_LINK")
.and() .and()
.equalTo("properties['LINK_PID']", linkPid) .equalTo("properties['${LinkTable.linkPid}']", linkPid)
.findAll() .findAll()
result.addAll(realmList) result.addAll(realmList)
} }
@ -134,7 +172,7 @@ class RealmOperateHelper() {
* @param unSortList 未排序的数据 * @param unSortList 未排序的数据
* @return 排序后的数据 * @return 排序后的数据
* */ * */
fun sortRenderEntity(point: Point, unSortList: MutableList<RenderEntity>): List<RenderEntity> { fun sortRenderEntity(point: Point, unSortList: List<RenderEntity>): List<RenderEntity> {
val sortList = unSortList.stream().sorted { renderEntity, renderEntity2 -> val sortList = unSortList.stream().sorted { renderEntity, renderEntity2 ->
val near = point.distance(renderEntity.wkt) - point.distance(renderEntity2.wkt) val near = point.distance(renderEntity.wkt) - point.distance(renderEntity2.wkt)
if (near < 0) -1 else 1 if (near < 0) -1 else 1
@ -142,7 +180,11 @@ class RealmOperateHelper() {
return sortList return sortList
} }
private fun getPolygonFromPoint(point: Point, buffer: Double = DEFAULT_BUFFER, bufferType: BUFFER_TYPE = DEFAULT_BUFFER_TYPE): Polygon { private fun getPolygonFromPoint(
point: Point,
buffer: Double = DEFAULT_BUFFER,
bufferType: BUFFER_TYPE = DEFAULT_BUFFER_TYPE
): Polygon {
// 首先计算当前点位的buffer组成的geometry // 首先计算当前点位的buffer组成的geometry
val wkt: Polygon = if (bufferType == BUFFER_TYPE.METER) { // 如果单位是米 val wkt: Polygon = if (bufferType == BUFFER_TYPE.METER) { // 如果单位是米
val distanceDegrees = GeometryTools.convertDistanceToDegree(buffer, point.y) val distanceDegrees = GeometryTools.convertDistanceToDegree(buffer, point.y)
@ -151,14 +193,30 @@ class RealmOperateHelper() {
} else { // 如果单位是像素,需要根据当前屏幕像素计算出经纬度变化 } else { // 如果单位是像素,需要根据当前屏幕像素计算出经纬度变化
val currentMapScale = niMapController.mMapView.vtmMap.mapPosition.scale val currentMapScale = niMapController.mMapView.vtmMap.mapPosition.scale
// 转换为屏幕坐标 // 转换为屏幕坐标
val pixelPoint = MercatorProjection.getPixelWithScale(GeoPoint(point.y, point.x), currentMapScale) val pixelPoint =
MercatorProjection.getPixelWithScale(
GeoPoint(point.y, point.x),
currentMapScale
)
// 将屏幕坐标外扩指定距离 // 将屏幕坐标外扩指定距离
// 计算外扩矩形 // 计算外扩矩形
val envelope = Envelope( val envelope = Envelope(
MercatorProjection.pixelXToLongitudeWithScale(pixelPoint.x - buffer, currentMapScale), MercatorProjection.pixelXToLongitudeWithScale(
MercatorProjection.pixelXToLongitudeWithScale(pixelPoint.x + buffer, currentMapScale), pixelPoint.x - buffer,
MercatorProjection.pixelYToLatitudeWithScale(pixelPoint.y - buffer, currentMapScale), currentMapScale
MercatorProjection.pixelYToLatitudeWithScale(pixelPoint.y + buffer, currentMapScale), ),
MercatorProjection.pixelXToLongitudeWithScale(
pixelPoint.x + buffer,
currentMapScale
),
MercatorProjection.pixelYToLatitudeWithScale(
pixelPoint.y - buffer,
currentMapScale
),
MercatorProjection.pixelYToLatitudeWithScale(
pixelPoint.y + buffer,
currentMapScale
),
) )
// 将Envelope对象转换为Polygon对象 // 将Envelope对象转换为Polygon对象
val geometryFactory = GeometryFactory() val geometryFactory = GeometryFactory()
@ -178,6 +236,7 @@ class RealmOperateHelper() {
enum class BUFFER_TYPE(val index: Int) { enum class BUFFER_TYPE(val index: Int) {
METER(0)/*米*/, PIXEL(1)/*像素*/; METER(0)/*米*/, PIXEL(1)/*像素*/;
fun getBufferTypeByIndex(index: Int): BUFFER_TYPE { fun getBufferTypeByIndex(index: Int): BUFFER_TYPE {
for (item in BUFFER_TYPE.values()) { for (item in BUFFER_TYPE.values()) {
if (item.index == index) { if (item.index == index) {

View File

@ -59,7 +59,7 @@ class EvaluationResultFragment : BaseFragment(), View.OnClickListener {
if (arguments != null) { if (arguments != null) {
val id = requireArguments().getString("QsId") val id = requireArguments().getString("QsId")
if (id != null) { if (id != null) {
viewModel.loadData(id) viewModel.initData(id)
} else { } else {
viewModel.initNewData() viewModel.initNewData()
} }

View File

@ -1,10 +1,14 @@
package com.navinfo.omqs.ui.fragment.evaluationresult package com.navinfo.omqs.ui.fragment.evaluationresult
import android.os.Build
import android.util.Log import android.util.Log
import androidx.annotation.RequiresApi
import androidx.lifecycle.MutableLiveData import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope import androidx.lifecycle.viewModelScope
import com.navinfo.collect.library.data.entity.QsRecordBean import com.navinfo.collect.library.data.entity.QsRecordBean
import com.navinfo.collect.library.data.entity.RenderEntity.Companion.LinkTable
import com.navinfo.collect.library.map.GeoPoint
import com.navinfo.collect.library.map.NIMapController import com.navinfo.collect.library.map.NIMapController
import com.navinfo.collect.library.utils.GeometryTools import com.navinfo.collect.library.utils.GeometryTools
import com.navinfo.omqs.db.RealmOperateHelper import com.navinfo.omqs.db.RealmOperateHelper
@ -14,10 +18,10 @@ import io.realm.Realm
import io.realm.kotlin.where import io.realm.kotlin.where
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import org.locationtech.jts.geom.Point
import java.util.* import java.util.*
import javax.inject.Inject import javax.inject.Inject
@RequiresApi(Build.VERSION_CODES.N)
@HiltViewModel @HiltViewModel
class EvaluationResultViewModel @Inject constructor( class EvaluationResultViewModel @Inject constructor(
private val roomAppDatabase: RoomAppDatabase, private val roomAppDatabase: RoomAppDatabase,
@ -60,15 +64,7 @@ class EvaluationResultViewModel @Inject constructor(
liveDataQsRecordBean.value!!.geometry = it.toGeometry() liveDataQsRecordBean.value!!.geometry = it.toGeometry()
addMarker(it, markerTitle) addMarker(it, markerTitle)
viewModelScope.launch { viewModelScope.launch {
val linkList = realmOperateHelper.queryLink( captureLink(it.longitude, it.latitude)
point = GeometryTools.createPoint(
it.longitude,
it.latitude
), sort = true
)
if (linkList.isNotEmpty()) {
liveDataQsRecordBean.value!!.linkId = linkList[0].id
}
} }
} }
} }
@ -80,6 +76,7 @@ class EvaluationResultViewModel @Inject constructor(
Log.e("jingo", "EvaluationResultViewModel 销毁了 ${hashCode()}") Log.e("jingo", "EvaluationResultViewModel 销毁了 ${hashCode()}")
mapController.markerHandle.removeMarker(markerTitle) mapController.markerHandle.removeMarker(markerTitle)
mapController.markerHandle.removeOnMapClickListener() mapController.markerHandle.removeOnMapClickListener()
mapController.lineHandler.removeLine()
} }
@ -96,17 +93,31 @@ class EvaluationResultViewModel @Inject constructor(
liveDataQsRecordBean.value!!.geometry = it.toGeometry() liveDataQsRecordBean.value!!.geometry = it.toGeometry()
mapController.markerHandle.addMarker(geoPoint, markerTitle) mapController.markerHandle.addMarker(geoPoint, markerTitle)
viewModelScope.launch { viewModelScope.launch {
val linkList = realmOperateHelper.queryLink( captureLink(geoPoint.longitude, geoPoint.latitude)
GeometryTools.createPoint(
geoPoint.longitude,
geoPoint.latitude
)
)
if (linkList.isNotEmpty()) {
liveDataQsRecordBean.value!!.linkId = linkList[0].id
} }
} }
} }
/**
* 捕捉到路
*/
private suspend fun captureLink(longitude: Double, latitude: Double) {
val linkList = realmOperateHelper.queryLink(
point = GeometryTools.createPoint(
longitude,
latitude
),
)
liveDataQsRecordBean.value?.let {
if (linkList.isNotEmpty()) {
it.linkId =
linkList[0].properties[LinkTable.linkPid] ?: ""
mapController.lineHandler.showLine(linkList[0].geometry)
} else {
it.linkId = ""
mapController.lineHandler.removeLine()
}
}
} }
/** /**
@ -263,14 +274,28 @@ class EvaluationResultViewModel @Inject constructor(
/** /**
* 根据数据id查询数据 * 根据数据id查询数据
*/ */
fun loadData(id: String) {
fun initData(id: String) {
viewModelScope.launch(Dispatchers.IO) { viewModelScope.launch(Dispatchers.IO) {
val realm = Realm.getDefaultInstance() val realm = Realm.getDefaultInstance()
val objects = realm.where<QsRecordBean>().equalTo("id", id).findFirst() val objects = realm.where<QsRecordBean>().equalTo("id", id).findFirst()
if (objects != null) { if (objects != null) {
oldBean = realm.copyFromRealm(objects) oldBean = realm.copyFromRealm(objects)
liveDataQsRecordBean.postValue(oldBean!!.copy()) oldBean?.let {
liveDataQsRecordBean.postValue(it.copy())
val p = GeometryTools.createGeoPoint(it.geometry)
mapController.markerHandle.addMarker(
GeoPoint(p.longitude, p.latitude),
markerTitle
)
if (it.linkId.isNotEmpty()) {
val link = realmOperateHelper.queryLink(it.linkId)
link?.let { l ->
mapController.lineHandler.showLine(l.geometry)
}
}
}
} }
} }
} }

View File

@ -39,8 +39,19 @@ open class RenderEntity(): RealmObject() {
} }
} }
@Ignore @Ignore
var wkt: Geometry? = null var wkt: Geometry? = null
get() {
if (field == null || field!!.isEmpty) {
try {
field = GeometryTools.createGeometry(geometry)
} catch (e: Exception) {
}
}
return field
}
var properties: RealmDictionary<String?> = RealmDictionary() var properties: RealmDictionary<String?> = RealmDictionary()
var tileX: RealmSet<Int> = RealmSet() // x方向的tile编码 var tileX: RealmSet<Int> = RealmSet() // x方向的tile编码
var tileY: RealmSet<Int> = RealmSet() // y方向的tile编码 var tileY: RealmSet<Int> = RealmSet() // y方向的tile编码
@ -49,4 +60,17 @@ open class RenderEntity(): RealmObject() {
this.name = name this.name = name
this.properties = properties this.properties = properties
} }
companion object {
object LinkTable {
//道路linkId
const val linkPid = "linkPid"
}
object LimitTable {
const val linkPid = "linkPid"
}
object KindCodeTable {
const val linkPid = "linkPid"
}
}
} }

View File

@ -1,57 +1,27 @@
package com.navinfo.collect.library.map.handler package com.navinfo.collect.library.map.handler
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.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.QsRecordBean
import com.navinfo.collect.library.map.NIMapView 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.source.MapLifeNiLocationTileSource import com.navinfo.collect.library.map.source.MapLifeNiLocationTileSource
import com.navinfo.collect.library.map.source.NavinfoMultiMapFileTileSource import com.navinfo.collect.library.map.source.NavinfoMultiMapFileTileSource
import com.navinfo.collect.library.map.source.OMDBTileSource import com.navinfo.collect.library.map.source.OMDBTileSource
import com.navinfo.collect.library.system.Constant import com.navinfo.collect.library.system.Constant
import com.navinfo.collect.library.utils.GeometryTools
import io.realm.Realm
import io.realm.kotlin.where
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import okhttp3.Cache import okhttp3.Cache
import okhttp3.OkHttpClient import okhttp3.OkHttpClient
import org.locationtech.jts.geom.Geometry
import org.oscim.android.canvas.AndroidBitmap
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.GroupLayer import org.oscim.layers.GroupLayer
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.tile.buildings.BuildingLayer import org.oscim.layers.tile.buildings.BuildingLayer
import org.oscim.layers.tile.vector.VectorTileLayer import org.oscim.layers.tile.vector.VectorTileLayer
import org.oscim.layers.tile.vector.labeling.LabelLayer import org.oscim.layers.tile.vector.labeling.LabelLayer
import org.oscim.layers.tile.vector.labeling.LabelTileLoaderHook import org.oscim.layers.tile.vector.labeling.LabelTileLoaderHook
import org.oscim.map.Map
import org.oscim.map.Map.UpdateListener import org.oscim.map.Map.UpdateListener
import org.oscim.tiling.source.OkHttpEngine.OkHttpFactory import org.oscim.tiling.source.OkHttpEngine.OkHttpFactory
import org.oscim.tiling.source.mapfile.MapFileTileSource import org.oscim.tiling.source.mapfile.MapFileTileSource
import java.io.File import java.io.File
import java.util.*
/** /**
* Layer 操作 * Layer 操作
*/ */
open class LayerManagerHandler(context: AppCompatActivity, mapView: NIMapView,tracePath: String) : BaseHandler(context, mapView) { class LayerManagerHandler(context: AppCompatActivity, mapView: NIMapView,tracePath: String) : BaseHandler(context, mapView) {
private var baseGroupLayer // 用于盛放所有基础底图的图层组,便于统一管理 private var baseGroupLayer // 用于盛放所有基础底图的图层组,便于统一管理
: GroupLayer? = null : GroupLayer? = null
protected val mTracePath:String = tracePath protected val mTracePath:String = tracePath
@ -76,10 +46,6 @@ open class LayerManagerHandler(context: AppCompatActivity, mapView: NIMapView,tr
* */ * */
private lateinit var omdbVectorTileLayer: VectorTileLayer private lateinit var omdbVectorTileLayer: VectorTileLayer
private lateinit var omdbLabelLayer: LabelLayer private lateinit var omdbLabelLayer: LabelLayer
/**
* 文字大小
*/
private val NUM_13 = 13
init { init {
initMap() initMap()

View File

@ -1,13 +1,15 @@
package com.navinfo.collect.library.map.handler package com.navinfo.collect.library.map.handler
import android.content.Context
import android.graphics.BitmapFactory import android.graphics.BitmapFactory
import android.os.Build
import android.widget.Toast import android.widget.Toast
import androidx.annotation.RequiresApi
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import com.navinfo.collect.library.R import com.navinfo.collect.library.R
import com.navinfo.collect.library.map.NIMapView import com.navinfo.collect.library.map.NIMapView
import com.navinfo.collect.library.utils.GeometryTools import com.navinfo.collect.library.utils.GeometryTools
import com.navinfo.collect.library.utils.StringUtil import com.navinfo.collect.library.utils.StringUtil
import org.locationtech.jts.geom.LineString
import org.oscim.android.canvas.AndroidBitmap import org.oscim.android.canvas.AndroidBitmap
import org.oscim.backend.canvas.Bitmap import org.oscim.backend.canvas.Bitmap
import org.oscim.core.GeoPoint import org.oscim.core.GeoPoint
@ -22,8 +24,9 @@ import org.oscim.layers.vector.PathLayer
import org.oscim.layers.vector.geometries.Style import org.oscim.layers.vector.geometries.Style
import org.oscim.map.Map import org.oscim.map.Map
open class LineHandler(context: AppCompatActivity, mapView: NIMapView) : @RequiresApi(Build.VERSION_CODES.M)
BaseHandler(context, mapView), Map.UpdateListener { class LineHandler(context: AppCompatActivity, mapView: NIMapView) : BaseHandler(context, mapView),
Map.UpdateListener {
private var editIndex: Int = -1; private var editIndex: Int = -1;
private val mPathMakers: MutableList<MarkerItem> = mutableListOf() private val mPathMakers: MutableList<MarkerItem> = mutableListOf()
@ -51,6 +54,9 @@ open class LineHandler(context: AppCompatActivity, mapView: NIMapView) :
private var bDrawLine = false private var bDrawLine = false
private val mDefaultPathLayer: PathLayer
init { init {
mMapView.vtmMap.events.bind(this) mMapView.vtmMap.events.bind(this)
@ -61,29 +67,21 @@ open class LineHandler(context: AppCompatActivity, mapView: NIMapView) :
.fillColor(context.resources.getColor(R.color.draw_line_blue2_color, null)) .fillColor(context.resources.getColor(R.color.draw_line_blue2_color, null))
.fillAlpha(0.5f) .fillAlpha(0.5f)
.strokeColor(context.resources.getColor(R.color.draw_line_blue2_color, null)) .strokeColor(context.resources.getColor(R.color.draw_line_blue2_color, null))
.fixed(true) .fixed(true).build()
.build()
newTempStyle = Style.builder() newTempStyle =
.stippleColor(context.resources.getColor(R.color.transparent, null)) Style.builder().stippleColor(context.resources.getColor(R.color.transparent, null))
.stipple(30) .stipple(30).stippleWidth(30f).strokeWidth(4f)
.stippleWidth(30f)
.strokeWidth(4f)
.strokeColor(context.resources.getColor(R.color.draw_line_blue2_color, null)) .strokeColor(context.resources.getColor(R.color.draw_line_blue2_color, null))
.fixed(true) .fixed(true).randomOffset(false).build()
.randomOffset(false)
.build()
editTempStyle = Style.builder() editTempStyle =
.stippleColor(context.resources.getColor(R.color.transparent, null)) Style.builder().stippleColor(context.resources.getColor(R.color.transparent, null))
.stipple(30) .stipple(30).stippleWidth(30f).strokeWidth(8f)
.stippleWidth(30f)
.strokeWidth(8f)
.strokeColor(context.resources.getColor(R.color.draw_line_red_color, null)) .strokeColor(context.resources.getColor(R.color.draw_line_red_color, null))
.fixed(true) .fixed(true).randomOffset(false).build()
.randomOffset(false) mDefaultPathLayer = PathLayer(mMapView.vtmMap, lineStyle)
.build() addLayer(mDefaultPathLayer, NIMapView.LAYER_GROUPS.VECTOR)
mPathLayer = PathLayer(mMapView.vtmMap, lineStyle) mPathLayer = PathLayer(mMapView.vtmMap, lineStyle)
// addLayer(mPathLayer, NIMapView.LAYER_GROUPS.OPERATE) // addLayer(mPathLayer, NIMapView.LAYER_GROUPS.OPERATE)
@ -92,8 +90,7 @@ open class LineHandler(context: AppCompatActivity, mapView: NIMapView) :
mPathMarkerBitmap = AndroidBitmap( mPathMarkerBitmap = AndroidBitmap(
BitmapFactory.decodeResource( BitmapFactory.decodeResource(
mContext.resources, mContext.resources, R.mipmap.icon_path_maker
R.mipmap.icon_path_maker
) )
) )
val markerSymbol = MarkerSymbol(mPathMarkerBitmap, MarkerSymbol.HotspotPlace.CENTER) val markerSymbol = MarkerSymbol(mPathMarkerBitmap, MarkerSymbol.HotspotPlace.CENTER)
@ -110,8 +107,7 @@ open class LineHandler(context: AppCompatActivity, mapView: NIMapView) :
if (item === item1) { if (item === item1) {
mMapView.vtmMap.animator().animateTo( mMapView.vtmMap.animator().animateTo(
GeoPoint( GeoPoint(
item.getPoint().latitude, item.getPoint().latitude, item.getPoint().longitude
item.getPoint().longitude
) )
) )
editIndex = i editIndex = i
@ -139,6 +135,22 @@ open class LineHandler(context: AppCompatActivity, mapView: NIMapView) :
}) })
} }
fun showLine(geometry: String) {
try {
} catch (e: Exception) {
Toast.makeText(mContext, "高亮路线失败 ${e.message}", Toast.LENGTH_SHORT).show()
}
val g = GeometryTools.getGeoPoints(geometry)
mDefaultPathLayer.setPoints(g)
mDefaultPathLayer.isEnabled = true
}
fun removeLine() {
mDefaultPathLayer.clearPath()
mDefaultPathLayer.isEnabled = false
}
fun addDrawLinePoint(geoPoint: GeoPoint): List<GeoPoint> { fun addDrawLinePoint(geoPoint: GeoPoint): List<GeoPoint> {
if (!bDrawLine) { if (!bDrawLine) {
@ -210,7 +222,7 @@ open class LineHandler(context: AppCompatActivity, mapView: NIMapView) :
} }
} }
} }
if (editIndex < mPathLayer.getPoints().size) { if (editIndex < mPathLayer.points.size) {
mPathLayer.points.removeAt(editIndex) mPathLayer.points.removeAt(editIndex)
val list2: MutableList<GeoPoint> = mutableListOf<GeoPoint>() val list2: MutableList<GeoPoint> = mutableListOf<GeoPoint>()
list2.addAll(mPathLayer.points) list2.addAll(mPathLayer.points)
@ -268,8 +280,7 @@ open class LineHandler(context: AppCompatActivity, mapView: NIMapView) :
override fun onMapEvent(e: Event, mapPosition: MapPosition) { override fun onMapEvent(e: Event, mapPosition: MapPosition) {
if (!bDrawLine) if (!bDrawLine) return
return
// if (mMapView.centerPixel[1] > mMapView.vtmMap.height / 2) { // if (mMapView.centerPixel[1] > mMapView.vtmMap.height / 2) {
// val geoPoint = // val geoPoint =
// mMapView.vtmMap.viewport() // mMapView.vtmMap.viewport()
@ -287,16 +298,14 @@ open class LineHandler(context: AppCompatActivity, mapView: NIMapView) :
list.add(mPathMakers[editIndex].geoPoint) list.add(mPathMakers[editIndex].geoPoint)
list.add( list.add(
GeoPoint( GeoPoint(
mapPosition.latitude, mapPosition.latitude, mapPosition.longitude
mapPosition.longitude
) )
) )
} else { } else {
list.add(mPathMakers[editIndex - 1].geoPoint) list.add(mPathMakers[editIndex - 1].geoPoint)
list.add( list.add(
GeoPoint( GeoPoint(
mapPosition.latitude, mapPosition.latitude, mapPosition.longitude
mapPosition.longitude
) )
) )
list.add(mPathMakers[editIndex + 1].geoPoint) list.add(mPathMakers[editIndex + 1].geoPoint)
@ -308,8 +317,7 @@ open class LineHandler(context: AppCompatActivity, mapView: NIMapView) :
list.add(mPathLayer.points[mPathLayer.points.size - 1]) list.add(mPathLayer.points[mPathLayer.points.size - 1])
list.add( list.add(
GeoPoint( GeoPoint(
mapPosition.latitude, mapPosition.latitude, mapPosition.longitude
mapPosition.longitude
) )
) )
mPathLayerTemp.setPoints(list) mPathLayerTemp.setPoints(list)
@ -317,8 +325,7 @@ open class LineHandler(context: AppCompatActivity, mapView: NIMapView) :
val listDis: MutableList<GeoPoint> = mutableListOf() val listDis: MutableList<GeoPoint> = mutableListOf()
listDis.add( listDis.add(
GeoPoint( GeoPoint(
mapPosition.latitude, mapPosition.latitude, mapPosition.longitude
mapPosition.longitude
) )
) )
// val distance: Double = // val distance: Double =

View File

@ -65,6 +65,7 @@ class LocationLayerHandler(context: AppCompatActivity, mapView: NIMapView) : Bas
//第一次定位成功显示当前位置 //第一次定位成功显示当前位置
if (this.bFirst) { if (this.bFirst) {
animateToCurrentPosition(16.0) animateToCurrentPosition(16.0)
this.bFirst = false
} }
} }