fix: 增加任务数据高亮功能

This commit is contained in:
xiaoyan 2023-04-27 17:16:53 +08:00
parent d129f26d82
commit 3eed9bad33
7 changed files with 81 additions and 29 deletions

View File

@ -1,6 +1,7 @@
package com.navinfo.omqs.bean
import com.google.gson.annotations.SerializedName
import com.navinfo.collect.library.data.entity.HadLinkDvoBean
import com.navinfo.omqs.Constant
import com.navinfo.omqs.tools.FileManager
import com.navinfo.omqs.tools.FileManager.Companion.FileDownloadStatus
@ -8,7 +9,6 @@ import io.realm.RealmList
import io.realm.RealmObject
import io.realm.annotations.Ignore
import io.realm.annotations.PrimaryKey
import io.realm.annotations.RealmClass
open class TaskBean @JvmOverloads constructor(
/**

View File

@ -1,9 +1,9 @@
package com.navinfo.omqs.db
import com.navinfo.omqs.bean.HadLinkDvoBean
import com.navinfo.collect.library.data.entity.HadLinkDvoBean
import com.navinfo.omqs.bean.TaskBean
import io.realm.annotations.RealmModule
@RealmModule(classes = [TaskBean::class, HadLinkDvoBean::class])
@RealmModule(classes = [TaskBean::class])
class MyRealmModule {
}

View File

@ -1,11 +1,16 @@
package com.navinfo.omqs.ui.fragment.tasklist
import android.content.Context
import android.graphics.Color
import android.os.Build
import android.util.Log
import android.widget.Toast
import androidx.annotation.RequiresApi
import androidx.core.graphics.toColor
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.navinfo.collect.library.map.NIMapController
import com.navinfo.omqs.bean.TaskBean
import com.navinfo.omqs.http.NetResult
import com.navinfo.omqs.http.NetworkService
@ -19,7 +24,8 @@ import javax.inject.Inject
@HiltViewModel
class TaskListViewModel @Inject constructor(
private val networkService: NetworkService
private val networkService: NetworkService,
private val niMapController: NIMapController
) : ViewModel() {
val liveDataTaskList = MutableLiveData<List<TaskBean>>()
@ -70,6 +76,11 @@ class TaskListViewModel @Inject constructor(
for (item in taskList) {
FileManager.checkOMDBFileInfo(item)
}
// niMapController.lineHandler.omdbTaskLinkLayer.setLineColor(Color.rgb(0, 255, 0).toColor())
// taskList.forEach {
// niMapController.lineHandler.omdbTaskLinkLayer.addLineList(it.hadLinkDvoList)
// }
// niMapController.lineHandler.omdbTaskLinkLayer.update()
liveDataTaskList.postValue(taskList)
}

View File

@ -1,7 +1,6 @@
package com.navinfo.omqs.bean
package com.navinfo.collect.library.data.entity
import io.realm.RealmObject
import io.realm.annotations.RealmClass
open class HadLinkDvoBean @JvmOverloads constructor(
/**

View File

@ -26,7 +26,7 @@ import org.oscim.layers.vector.VectorLayer
import org.oscim.layers.vector.geometries.Style
import org.oscim.map.Map
@RequiresApi(Build.VERSION_CODES.M)
@RequiresApi(Build.VERSION_CODES.N)
class LineHandler(context: AppCompatActivity, mapView: NIMapView) : BaseHandler(context, mapView),
Map.UpdateListener {
@ -60,6 +60,16 @@ class LineHandler(context: AppCompatActivity, mapView: NIMapView) : BaseHandler(
private val mDefaultPathLayer: PathLayer
val omdbTaskLinkLayer by lazy {
val omdbTaskLinkLayer = OmdbTaskLinkLayer(mMapView.vtmMap,
Style.builder()
// .stippleColor(context.resources.getColor(R.color.draw_line_red_color, null))
.fillColor(context.resources.getColor(R.color.draw_line_red_color, null))
.fillAlpha(0.5f)
.strokeColor(context.resources.getColor(R.color.draw_line_red_color, null))
.strokeWidth(4f)
.fixed(true).build())
addLayer(omdbTaskLinkLayer, NIMapView.LAYER_GROUPS.VECTOR)
omdbTaskLinkLayer
}
init {

View File

@ -1,22 +0,0 @@
package com.navinfo.collect.library.map.layers;
import org.locationtech.jts.geom.Geometry;
import org.locationtech.jts.geom.LineString;
import org.oscim.layers.vector.VectorLayer;
import org.oscim.layers.vector.geometries.Drawable;
import org.oscim.layers.vector.geometries.Style;
import org.oscim.map.Map;
import org.oscim.utils.SpatialIndex;
import java.util.HashMap;
import java.util.List;
public class OmdbTaskLinkLayer extends VectorLayer {
private java.util.Map<String, LineString> lineList = new HashMap<>();
private Style style;
public OmdbTaskLinkLayer(Map map) {
super(map);
}
}

View File

@ -0,0 +1,54 @@
package com.navinfo.collect.library.map.layers
import android.graphics.Color
import com.navinfo.collect.library.R
import com.navinfo.collect.library.data.entity.HadLinkDvoBean
import com.navinfo.collect.library.utils.GeometryTools
import org.locationtech.jts.geom.Geometry
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 OmdbTaskLinkLayer(map: Map, private var style: Style) : VectorLayer(map) {
private val lineMap = HashMap<String, Drawable>()
fun addLine(hadLinkDvoBean: HadLinkDvoBean, style: Style = this.style) {
hadLinkDvoBean.let {
if (!lineMap.containsKey(it.linkPid)) {
// 添加geometry到图层上
val lineDrawable = LineDrawable(GeometryTools.createGeometry(it.geometry), style)
super.add(lineDrawable)
lineMap[it.linkPid] = lineDrawable
}
}
}
fun addLineList(hadLinkDvoBeanList: List<HadLinkDvoBean>, style: Style = this.style) {
hadLinkDvoBeanList.forEach {
addLine(it, style)
}
}
fun removeLine(linkPid: String):Boolean {
if (lineMap.containsKey(linkPid)) {
super.remove(lineMap[linkPid])
lineMap.remove(linkPid)
}
return false
}
fun removeLine(geometry: Geometry) {
super.remove(geometry)
}
fun setLineColor(color: Color) {
this.style = Style.builder()
.fillColor(color.toArgb())
.fillAlpha(0.5f)
.strokeColor(color.toArgb())
.strokeWidth(4f)
.fixed(true).build()
}
}