增加高亮图层

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

@@ -16,7 +16,7 @@ import java.util.*
/**
* 渲染要素对应的实体
* */
open class RenderEntity(): RealmObject() {
open class RenderEntity() : RealmObject() {
@PrimaryKey
var id: String = UUID.randomUUID().toString() // id
lateinit var name: String //要素名
@@ -39,14 +39,38 @@ open class RenderEntity(): RealmObject() {
}
}
@Ignore
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 tileX: RealmSet<Int> = RealmSet() // x方向的tile编码
var tileY: RealmSet<Int> = RealmSet() // y方向的tile编码
constructor(name: String, properties: RealmDictionary<String?>): this() {
constructor(name: String, properties: RealmDictionary<String?>) : this() {
this.name = name
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
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.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.source.MapLifeNiLocationTileSource
import com.navinfo.collect.library.map.source.NavinfoMultiMapFileTileSource
import com.navinfo.collect.library.map.source.OMDBTileSource
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.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.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.vector.VectorTileLayer
import org.oscim.layers.tile.vector.labeling.LabelLayer
import org.oscim.layers.tile.vector.labeling.LabelTileLoaderHook
import org.oscim.map.Map
import org.oscim.map.Map.UpdateListener
import org.oscim.tiling.source.OkHttpEngine.OkHttpFactory
import org.oscim.tiling.source.mapfile.MapFileTileSource
import java.io.File
import java.util.*
/**
* 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 // 用于盛放所有基础底图的图层组,便于统一管理
: GroupLayer? = null
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 omdbLabelLayer: LabelLayer
/**
* 文字大小
*/
private val NUM_13 = 13
init {
initMap()

View File

@@ -1,13 +1,15 @@
package com.navinfo.collect.library.map.handler
import android.content.Context
import android.graphics.BitmapFactory
import android.os.Build
import android.widget.Toast
import androidx.annotation.RequiresApi
import androidx.appcompat.app.AppCompatActivity
import com.navinfo.collect.library.R
import com.navinfo.collect.library.map.NIMapView
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
@@ -22,8 +24,9 @@ import org.oscim.layers.vector.PathLayer
import org.oscim.layers.vector.geometries.Style
import org.oscim.map.Map
open class LineHandler(context: AppCompatActivity, mapView: NIMapView) :
BaseHandler(context, mapView), Map.UpdateListener {
@RequiresApi(Build.VERSION_CODES.M)
class LineHandler(context: AppCompatActivity, mapView: NIMapView) : BaseHandler(context, mapView),
Map.UpdateListener {
private var editIndex: Int = -1;
private val mPathMakers: MutableList<MarkerItem> = mutableListOf()
@@ -51,6 +54,9 @@ open class LineHandler(context: AppCompatActivity, mapView: NIMapView) :
private var bDrawLine = false
private val mDefaultPathLayer: PathLayer
init {
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))
.fillAlpha(0.5f)
.strokeColor(context.resources.getColor(R.color.draw_line_blue2_color, null))
.fixed(true)
.build()
.fixed(true).build()
newTempStyle = Style.builder()
.stippleColor(context.resources.getColor(R.color.transparent, null))
.stipple(30)
.stippleWidth(30f)
.strokeWidth(4f)
.strokeColor(context.resources.getColor(R.color.draw_line_blue2_color, null))
.fixed(true)
.randomOffset(false)
.build()
editTempStyle = Style.builder()
.stippleColor(context.resources.getColor(R.color.transparent, null))
.stipple(30)
.stippleWidth(30f)
.strokeWidth(8f)
.strokeColor(context.resources.getColor(R.color.draw_line_red_color, null))
.fixed(true)
.randomOffset(false)
.build()
newTempStyle =
Style.builder().stippleColor(context.resources.getColor(R.color.transparent, null))
.stipple(30).stippleWidth(30f).strokeWidth(4f)
.strokeColor(context.resources.getColor(R.color.draw_line_blue2_color, null))
.fixed(true).randomOffset(false).build()
editTempStyle =
Style.builder().stippleColor(context.resources.getColor(R.color.transparent, null))
.stipple(30).stippleWidth(30f).strokeWidth(8f)
.strokeColor(context.resources.getColor(R.color.draw_line_red_color, null))
.fixed(true).randomOffset(false).build()
mDefaultPathLayer = PathLayer(mMapView.vtmMap, lineStyle)
addLayer(mDefaultPathLayer, NIMapView.LAYER_GROUPS.VECTOR)
mPathLayer = PathLayer(mMapView.vtmMap, lineStyle)
// addLayer(mPathLayer, NIMapView.LAYER_GROUPS.OPERATE)
@@ -92,8 +90,7 @@ open class LineHandler(context: AppCompatActivity, mapView: NIMapView) :
mPathMarkerBitmap = AndroidBitmap(
BitmapFactory.decodeResource(
mContext.resources,
R.mipmap.icon_path_maker
mContext.resources, R.mipmap.icon_path_maker
)
)
val markerSymbol = MarkerSymbol(mPathMarkerBitmap, MarkerSymbol.HotspotPlace.CENTER)
@@ -110,8 +107,7 @@ open class LineHandler(context: AppCompatActivity, mapView: NIMapView) :
if (item === item1) {
mMapView.vtmMap.animator().animateTo(
GeoPoint(
item.getPoint().latitude,
item.getPoint().longitude
item.getPoint().latitude, item.getPoint().longitude
)
)
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> {
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)
val list2: MutableList<GeoPoint> = mutableListOf<GeoPoint>()
list2.addAll(mPathLayer.points)
@@ -268,8 +280,7 @@ open class LineHandler(context: AppCompatActivity, mapView: NIMapView) :
override fun onMapEvent(e: Event, mapPosition: MapPosition) {
if (!bDrawLine)
return
if (!bDrawLine) return
// if (mMapView.centerPixel[1] > mMapView.vtmMap.height / 2) {
// val geoPoint =
// mMapView.vtmMap.viewport()
@@ -287,16 +298,14 @@ open class LineHandler(context: AppCompatActivity, mapView: NIMapView) :
list.add(mPathMakers[editIndex].geoPoint)
list.add(
GeoPoint(
mapPosition.latitude,
mapPosition.longitude
mapPosition.latitude, mapPosition.longitude
)
)
} else {
list.add(mPathMakers[editIndex - 1].geoPoint)
list.add(
GeoPoint(
mapPosition.latitude,
mapPosition.longitude
mapPosition.latitude, mapPosition.longitude
)
)
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(
GeoPoint(
mapPosition.latitude,
mapPosition.longitude
mapPosition.latitude, mapPosition.longitude
)
)
mPathLayerTemp.setPoints(list)
@@ -317,8 +325,7 @@ open class LineHandler(context: AppCompatActivity, mapView: NIMapView) :
val listDis: MutableList<GeoPoint> = mutableListOf()
listDis.add(
GeoPoint(
mapPosition.latitude,
mapPosition.longitude
mapPosition.latitude, mapPosition.longitude
)
)
// val distance: Double =

View File

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