Commit caa4d969 authored by 马乐's avatar 马乐

1.增加地图annotation

parent 552c8ce0
......@@ -35,18 +35,20 @@ android {
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
}
kotlinOptions {
jvmTarget = '1.8'
jvmTarget = '17'
}
buildFeatures {
viewBinding true
dataBinding true
}
packagingOptions {
exclude'META-INF/io.netty.versions.properties'
resources {
excludes += ['META-INF/io.netty.versions.properties']
}
}
}
......
{
"draft": false,
"glyphs": "http://192.168.9.152:8089/map/glyphs/{fontstack}/{range}.pbf",
"id": "pk.eyJ1IjoibWFybGxlciIsImEiOiJjbGVhMXlmeXIwdmRzM29vNmM4aDA1M202In0.tfLD_AOs1OPmg5rLERcbfw",
"layers": [
{
"id": "background",
"interactive": true,
"paint": {
"background-color": "black"
},
"type": "background"
}
],
"metadata": {
"mapbox:autocomposite": true,
"mapbox:sdk-support": {
"android": "10.11.0",
"ios": "4.0.0",
"js": "0.46.0"
},
"mapbox:type": "default"
},
"name": "Dark",
"owner": "HT",
"sprite": "http://192.168.9.152:8089/map/sprite/street/sprite",
"version": 8,
"visibility": "private"
}
{
"version": 8,
"name": "Satellite",
"metadata": {
"mapbox:autocomposite": true,
"mapbox:type": "default"
},
"sources": {
"composite": {
"tiles": [
"https://services.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}"
],
"type": "raster",
"tileSize": 256
}
},
"sprite": "http://192.168.9.152:8089/map/sprite/street/sprite",
"glyphs": "http://192.168.9.152:8089/map/glyphs/{fontstack}/{range}.pbf",
"layers": [{
"id": "background",
"type": "background",
"paint": {
"background-color": "#3c3d3f"
},
"interactive": true
}, {
"id": "satellite",
"type": "raster",
"source": "composite",
"interactive": true
}],
"created": "2019-02-22T17:58:57.291Z",
"id": "sk.eyJ1IjoibWFybGxlciIsImEiOiJjbGVjNHZhdWgwd3U4M29uMjJrY3BqYXpkIn0.cqcw1CHYVGwESBqsfWcm7w",
"modified": "2019-02-22T17:58:57.291Z",
"owner": "scfjp",
"visibility": "private",
"draft": false
}
\ No newline at end of file
{
"version": 8,
"name": "Dark",
"metadata": {
"mapbox:autocomposite": true,
"mapbox:type": "default",
"mapbox:sdk-support": {
"js": "0.46.0",
"android": "6.0.0",
"ios": "4.0.0"
}
},
"sources": {
},
"sprite": "http://192.168.9.198:8089/map/sprite/street/sprite",
"glyphs": "http://192.168.9.198:8089/map/glyphs/{fontstack}/{range}.pbf",
"layers": [{
"id": "background",
"type": "background",
"layout": {},
"paint": {
"background-color": {
"base": 1,
"stops": [
[
6,
"hsl(215, 17%, 35%)"
],
[
8,
"#030b22"
]
]
}
},
"interactive": true
}],
"created": "2018-07-25T01:43:01.085Z",
"id": "cjk0gss0a1n872rlia7papueg",
"modified": "2018-07-25T01:43:01.085Z",
"owner": "scfjp",
"visibility": "private",
"draft": false
}
\ No newline at end of file
{
"version": 8,
"name": "Satellite",
"metadata": {
"mapbox:autocomposite": true,
"mapbox:type": "default"
},
"sources": {
"composite": {
"tiles": [
"https://services.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}"
],
"type": "raster",
"tileSize": 256
}
},
"sprite": "http://192.168.9.198:8089/map/sprite/street/sprite",
"glyphs": "http://192.168.9.198:8089/map/glyphs/{fontstack}/{range}.pbf",
"layers": [{
"id": "background",
"type": "background",
"paint": {
"background-color": "#3c3d3f"
},
"interactive": true
}, {
"id": "satellite",
"type": "raster",
"source": "composite",
"interactive": true
}],
"created": "2019-02-22T17:58:57.291Z",
"id": "cjsgd0f6w0ndu1fo4trxeh4na",
"modified": "2019-02-22T17:58:57.291Z",
"owner": "scfjp",
"visibility": "private",
"draft": false
}
\ No newline at end of file
{
"version": 8,
"name": "Street",
"metadata": {
"mapbox:origin": "basic-template-v1",
"mapbox:autocomposite": true,
"mapbox:type": "template",
"mapbox:sdk-support": {
"js": "0.50.0",
"android": "6.7.0",
"ios": "4.6.0"
}
},
"sources": {},
"sprite": "http://192.168.9.198:8089/map/sprite/street/sprite",
"glyphs": "http://192.168.9.198:8089/map/glyphs/{fontstack}/{range}.pbf",
"layers": [{
"id": "background",
"type": "background",
"layout": {},
"paint": {
"background-color": [
"interpolate", ["linear"],
["zoom"],
5,
"hsl(38, 43%, 89%)",
7,
"hsl(38, 48%, 86%)"
]
}
}],
"created": "2019-01-02T03:16:28.622Z",
"id": "cjqem145mg5gh2sqi37v0gmhm",
"modified": "2019-01-02T03:16:28.622Z",
"owner": "scfjp",
"visibility": "private",
"draft": false
}
\ No newline at end of file
package com.waytous.anticollision.bean
data class MapDataSourceWrapper(val mapDataSource: MapDataSource, val abort:Boolean)
\ No newline at end of file
data class MapDataSourceWrapper(val mapDataSource: MapDataSource?, val abort:Boolean)
\ No newline at end of file
......@@ -7,7 +7,7 @@ import com.waytous.anticollision.bean.MapDataSource
interface MapDataDao {
@Query("SELECT * FROM map_source WHERE sourceId = :sourceId")
suspend fun findById(sourceId:String):MapDataSource
suspend fun findById(sourceId:String):MapDataSource?
@Insert(onConflict = OnConflictStrategy.REPLACE)
suspend fun insertAll(vararg sources: MapDataSource)
......
......@@ -27,11 +27,16 @@ class MainRepository@Inject constructor(context:Context) {
fun remoteObstaclesVersion(version:String = "-1") = suspend { mapApi.obstaclesVersion(version) }
.asFlow()
.map {
if (it != null) {
val tempSource = mapDao.findById(OBSTACLES_SOURCE)
if (tempSource.version != it.version) {
mapDao.deleteSource(tempSource)
.map {source->
LogUtils.d("remoteObstaclesVersion")
source?.let {
val dbSource = mapDao.findById(OBSTACLES_SOURCE)
if (dbSource == null) {
mapDao.insertAll(it.apply { sourceId = OBSTACLES_SOURCE })
MapDataSourceWrapper(it, true)
} else {
if (dbSource.version != it.version) {
mapDao.deleteSource(dbSource)
mapDao.insertAll(it.apply { sourceId = OBSTACLES_SOURCE })
LogUtils.d("remoteObstaclesVersion")
MapDataSourceWrapper(it, true)
......@@ -39,9 +44,8 @@ class MainRepository@Inject constructor(context:Context) {
LogUtils.d("remoteObstaclesVersion")
MapDataSourceWrapper(it, false)
}
} else {
throw Exception("获取到的障碍物图层数据为空!")
}
}?:throw Exception("获取到的障碍物图层数据为空!")
}
fun localObstaclesVersion() = flow {
......@@ -49,21 +53,27 @@ class MainRepository@Inject constructor(context:Context) {
emit( MapDataSourceWrapper(source, false))
}
fun remoteElectronicFenceVersion(version:String = "-")= suspend { mapApi.electronicFenceVersion(version) }
fun remoteElectronicFenceVersion(version:String = "-1")= suspend { mapApi.electronicFenceVersion(version) }
.asFlow()
.map {
if (it != null) {
val tempSource = mapDao.findById(ELECTRONIC_FENCE_SOURCE)
if (tempSource.version != it.version) {
mapDao.deleteSource(tempSource)
.map {source->
source?.let {
val dbSource = mapDao.findById(ELECTRONIC_FENCE_SOURCE)
if (dbSource == null) {
mapDao.insertAll(it.apply { sourceId = ELECTRONIC_FENCE_SOURCE })
MapDataSourceWrapper(it, true)
} else {
if (dbSource.version != it.version) {
mapDao.deleteSource(dbSource)
mapDao.insertAll(it.apply { sourceId = ELECTRONIC_FENCE_SOURCE })
LogUtils.d("remoteElectronicFenceVersion")
MapDataSourceWrapper(it, true)
} else {
LogUtils.d("remoteElectronicFenceVersion")
MapDataSourceWrapper(it, false)
}
} else {
throw Exception("获取到的电子围栏地图数据为空!")
}
}?:throw Exception("获取到的电子围栏地图数据为空!")
}
fun localElectronicFenceVersion() = flow {
......@@ -73,19 +83,24 @@ class MainRepository@Inject constructor(context:Context) {
fun remoteWetAreaVersion(version:String = "-1")= suspend { mapApi.wetAreaVersion(version) }
.asFlow()
.map {
if (it != null) {
val tempSource = mapDao.findById(WET_AREA_SOURCE)
if (tempSource.version != it.version) {
mapDao.deleteSource(tempSource)
.map {source->
source?.let {
val dbSource = mapDao.findById(WET_AREA_SOURCE)
if (dbSource == null) {
mapDao.insertAll(it.apply { sourceId = WET_AREA_SOURCE })
MapDataSourceWrapper(it, true)
} else {
if (dbSource.version != it.version) {
mapDao.deleteSource(dbSource)
mapDao.insertAll(it.apply { sourceId = WET_AREA_SOURCE })
LogUtils.d("remoteWetAreaVersion")
MapDataSourceWrapper(it, true)
} else {
LogUtils.d("remoteWetAreaVersion")
MapDataSourceWrapper(it, false)
}
} else {
throw Exception("获取到的湿滑区域地图数据为空!")
}
}?:throw Exception("获取到的湿滑区域地图数据为空!")
}
fun localWetAreaVersion() = flow {
......@@ -95,19 +110,24 @@ class MainRepository@Inject constructor(context:Context) {
fun remoteLaneNodeVersion(version:String = "-1")= suspend { mapApi.laneNodeVersion(version) }
.asFlow()
.map {
if (it != null) {
val tempSource = mapDao.findById(LANE_NODE_SOURCE)
if (tempSource.version != it.version) {
mapDao.deleteSource(tempSource)
.map {source->
source?.let {
val dbSource = mapDao.findById(LANE_NODE_SOURCE)
if (dbSource == null) {
mapDao.insertAll(it.apply { sourceId = LANE_NODE_SOURCE })
MapDataSourceWrapper(it, true)
} else {
if (dbSource.version != it.version) {
mapDao.deleteSource(dbSource)
mapDao.insertAll(it.apply { sourceId = LANE_NODE_SOURCE })
LogUtils.d("remoteLaneNodeVersion")
MapDataSourceWrapper(it, true)
} else {
LogUtils.d("remoteLaneNodeVersion")
MapDataSourceWrapper(it, false)
}
} else {
throw Exception("获取到的车道节点地图数据为空!")
}
}?:throw Exception("获取到的湿滑区域地图数据为空!")
}
fun localLaneNodeVersion() = flow {
......@@ -117,19 +137,24 @@ class MainRepository@Inject constructor(context:Context) {
fun remoteLaneVersion(version:String = "-1")= suspend { mapApi.laneVersion(version) }
.asFlow()
.map {
if (it != null) {
val tempSource = mapDao.findById(LANE_SOURCE)
if (tempSource.version != it.version) {
mapDao.deleteSource(tempSource)
.map {source->
source?.let {
val dbSource = mapDao.findById(LANE_SOURCE)
if (dbSource == null) {
mapDao.insertAll(it.apply { sourceId = LANE_SOURCE })
MapDataSourceWrapper(it, true)
} else {
if (dbSource.version != it.version) {
mapDao.deleteSource(dbSource)
mapDao.insertAll(it.apply { sourceId = LANE_SOURCE })
LogUtils.d("remoteLaneVersion")
MapDataSourceWrapper(it, true)
} else {
LogUtils.d("remoteLaneVersion")
MapDataSourceWrapper(it, false)
}
} else {
throw Exception("获取到的车道图层地图数据为空!")
}
}?:throw Exception("获取到的车道图层地图数据为空!")
}
fun localLaneVersion() = flow {
......@@ -139,19 +164,24 @@ class MainRepository@Inject constructor(context:Context) {
fun remoteRunnableAreaVersion(version:String = "-1")= suspend { mapApi.runnableAreaVersion(version) }
.asFlow()
.map {
if (it != null) {
val tempSource = mapDao.findById(RUNNABLE_AREA_SOURCE)
if (tempSource.version != it.version) {
mapDao.deleteSource(tempSource)
.map {source->
source?.let {
val dbSource = mapDao.findById(RUNNABLE_AREA_SOURCE)
if (dbSource == null) {
mapDao.insertAll(it.apply { sourceId = RUNNABLE_AREA_SOURCE })
MapDataSourceWrapper(it, true)
} else {
if (dbSource.version != it.version) {
mapDao.deleteSource(dbSource)
mapDao.insertAll(it.apply { sourceId = RUNNABLE_AREA_SOURCE })
LogUtils.d("remoteRunnableAreaVersion")
MapDataSourceWrapper(it, true)
} else {
LogUtils.d("remoteRunnableAreaVersion")
MapDataSourceWrapper(it, false)
}
} else {
throw Exception("获取到的可行使区域地图数据为空!")
}
}?:throw Exception("获取到的可行使区域地图数据为空!")
}
fun localRunnableAreaVersion() = flow {
......@@ -161,19 +191,24 @@ class MainRepository@Inject constructor(context:Context) {
fun remoteDumpAreaVersion(version:String = "-1")= suspend { mapApi.dumpAreaVersion(version) }
.asFlow()
.map {
if (it != null) {
val tempSource = mapDao.findById(DUMP_AREA_SOURCE)
if (tempSource.version != it.version) {
mapDao.deleteSource(tempSource)
.map {source->
source?.let {
val dbSource = mapDao.findById(DUMP_AREA_SOURCE)
if (dbSource == null) {
mapDao.insertAll(it.apply { sourceId = DUMP_AREA_SOURCE })
MapDataSourceWrapper(it, true)
} else {
if (dbSource.version != it.version) {
mapDao.deleteSource(dbSource)
mapDao.insertAll(it.apply { sourceId = DUMP_AREA_SOURCE })
LogUtils.d("remoteDumpAreaVersion")
MapDataSourceWrapper(it, true)
} else {
LogUtils.d("remoteDumpAreaVersion")
MapDataSourceWrapper(it, false)
}
} else {
throw Exception("获取到的卸载区地图数据为空!")
}
}?:throw Exception("获取到的卸载区地图数据为空!")
}
fun localDumpAreaVersion() = flow {
......@@ -183,19 +218,24 @@ class MainRepository@Inject constructor(context:Context) {
fun remoteDiggingWorkAreaVersion(version:String = "-1")= suspend { mapApi.diggingWorkAreaVersion(version) }
.asFlow()
.map {
if (it != null) {
val tempSource = mapDao.findById(DIGGING_WORK_AREA_SOURCE)
if (tempSource.version != it.version) {
mapDao.deleteSource(tempSource)
.map {source->
source?.let {
val dbSource = mapDao.findById(DIGGING_WORK_AREA_SOURCE)
if (dbSource == null) {
mapDao.insertAll(it.apply { sourceId = DIGGING_WORK_AREA_SOURCE })
MapDataSourceWrapper(it, true)
} else {
if (dbSource.version != it.version) {
mapDao.deleteSource(dbSource)
mapDao.insertAll(it.apply { sourceId = DIGGING_WORK_AREA_SOURCE })
LogUtils.d("remoteDiggingWorkAreaVersion")
MapDataSourceWrapper(it, true)
} else {
LogUtils.d("remoteDiggingWorkAreaVersion")
MapDataSourceWrapper(it, false)
}
} else {
throw Exception("获取到的装载区地图数据为空!")
}
}?:throw Exception("获取到的装载区地图数据为空!")
}
fun localDiggingAreaVersion() = flow {
......@@ -205,19 +245,24 @@ class MainRepository@Inject constructor(context:Context) {
fun remoteBarricadeVersion(version:String = "-1")= suspend { mapApi.barricadeVersion(version) }
.asFlow()
.map {
if (it != null) {
val tempSource = mapDao.findById(BARRICADE_SOURCE)
if (tempSource.version != it.version) {
mapDao.deleteSource(tempSource)
.map {source->
source?.let {
val dbSource = mapDao.findById(BARRICADE_SOURCE)
if (dbSource == null) {
mapDao.insertAll(it.apply { sourceId = BARRICADE_SOURCE })
MapDataSourceWrapper(it, true)
} else {
if (dbSource.version != it.version) {
mapDao.deleteSource(dbSource)
mapDao.insertAll(it.apply { sourceId = BARRICADE_SOURCE })
LogUtils.d("remoteBarricadeVersion")
MapDataSourceWrapper(it, true)
} else {
LogUtils.d("remoteBarricadeVersion")
MapDataSourceWrapper(it, false)
}
} else {
throw Exception("获取到的挡墙区域地图数据为空!")
}
}?:throw Exception("获取到的挡墙区域地图数据为空!")
}
fun localBarricadeVersion() = flow {
......@@ -227,19 +272,24 @@ class MainRepository@Inject constructor(context:Context) {
fun remoteStationAreaVersion(version:String = "-1")= suspend { mapApi.stationAreaVersion(version) }
.asFlow()
.map {
if (it != null) {
val tempSource = mapDao.findById(STATION_AREA_SOURCE)
if (tempSource.version != it.version) {
mapDao.deleteSource(tempSource)
.map {source->
source?.let {
val dbSource = mapDao.findById(STATION_AREA_SOURCE)
if (dbSource == null) {
mapDao.insertAll(it.apply { sourceId = STATION_AREA_SOURCE })
MapDataSourceWrapper(it, true)
} else {
if (dbSource.version != it.version) {
mapDao.deleteSource(dbSource)
mapDao.insertAll(it.apply { sourceId = STATION_AREA_SOURCE })
LogUtils.d("remoteStationAreaVersion")
MapDataSourceWrapper(it, true)
} else {
LogUtils.d("remoteStationAreaVersion")
MapDataSourceWrapper(it, false)
}
} else {
throw Exception("获取到的静态区域地图数据为空!")
}
}?:throw Exception("获取到的静态区域地图数据为空!")
}
fun localStationAreaVersion() = flow {
......@@ -249,19 +299,24 @@ class MainRepository@Inject constructor(context:Context) {
fun remoteParkSpotVersion(version:String = "-1")= suspend { mapApi.parkSpotVersion(version) }
.asFlow()
.map {
if (it != null) {
val tempSource = mapDao.findById(PARK_SPOT_SOURCE)
if (tempSource.version != it.version) {
mapDao.deleteSource(tempSource)
.map {source->
source?.let {
val dbSource = mapDao.findById(PARK_SPOT_SOURCE)
if (dbSource == null) {
mapDao.insertAll(it.apply { sourceId = PARK_SPOT_SOURCE })
MapDataSourceWrapper(it, true)
} else {
if (dbSource.version != it.version) {
mapDao.deleteSource(dbSource)
mapDao.insertAll(it.apply { sourceId = PARK_SPOT_SOURCE })
LogUtils.d("remoteParkSpotVersion")
MapDataSourceWrapper(it, true)
} else {
LogUtils.d("remoteParkSpotVersion")
MapDataSourceWrapper(it, false)
}
} else {
throw Exception("获取到的停车位图层地图数据为空!")
}
}?:throw Exception("获取到的停车位图层地图数据为空!")
}
fun localParkSpotVersion() = flow {
......@@ -271,19 +326,24 @@ class MainRepository@Inject constructor(context:Context) {
fun remoteStaticObjectsVersion(version:String = "-1")= suspend { mapApi.staticObjectsVersion(version) }
.asFlow()
.map {
if (it != null) {
val tempSource = mapDao.findById(STATIC_OBJECTS_SOURCE)
if (tempSource.version != it.version) {
mapDao.deleteSource(tempSource)
.map {source->
source?.let {
val dbSource = mapDao.findById(STATIC_OBJECTS_SOURCE)
if (dbSource == null) {
mapDao.insertAll(it.apply { sourceId = STATIC_OBJECTS_SOURCE })
MapDataSourceWrapper(it, true)
} else {
if (dbSource.version != it.version) {
mapDao.deleteSource(dbSource)
mapDao.insertAll(it.apply { sourceId = STATIC_OBJECTS_SOURCE })
LogUtils.d("remoteStaticObjectsVersion")
MapDataSourceWrapper(it, true)
} else {
LogUtils.d("remoteStaticObjectsVersion")
MapDataSourceWrapper(it, false)
}
} else {
throw Exception("获取到的静态区域地图数据为空!")
}
}?:throw Exception("获取到的静态区域地图数据为空!")
}
fun localStaticObjectsVersion() = flow {
......
package com.waytous.anticollision.ui
import android.annotation.SuppressLint
import android.graphics.Bitmap
import android.graphics.Color
import android.os.Bundle
import androidx.core.graphics.scale
import android.view.View
import androidx.appcompat.widget.AppCompatTextView
import androidx.fragment.app.Fragment
import androidx.fragment.app.viewModels
import androidx.lifecycle.lifecycleScope
......@@ -11,6 +13,7 @@ import androidx.lifecycle.withStarted
import com.mapbox.geojson.Point
import com.mapbox.maps.CameraOptions
import com.mapbox.maps.MapView
import com.mapbox.maps.ViewAnnotationAnchor
import com.mapbox.maps.extension.style.expressions.dsl.generated.get
import com.mapbox.maps.extension.style.layers.generated.circleLayer
import com.mapbox.maps.extension.style.layers.generated.fillLayer
......@@ -24,11 +27,16 @@ import com.mapbox.maps.plugin.annotation.generated.PointAnnotation
import com.mapbox.maps.plugin.annotation.generated.PointAnnotationManager
import com.mapbox.maps.plugin.annotation.generated.PointAnnotationOptions
import com.mapbox.maps.plugin.annotation.generated.createPointAnnotationManager
import com.mapbox.maps.plugin.scalebar.scalebar
import com.mapbox.maps.viewannotation.ViewAnnotationManager
import com.mapbox.maps.viewannotation.viewAnnotationOptions
import com.waytous.anticollision.R
import com.waytous.anticollision.api.ApiService
import com.waytous.anticollision.databinding.CurrentVehicleViewAnnotationLayoutBinding
import com.waytous.anticollision.databinding.OtherVehicleViewAnnotationLayoutBinding
import com.waytous.anticollision.repository.MainRepository
import com.waytous.anticollision.utils.getBitmapFromVectorDrawable
import com.waytous.anticollision.utils.BitmapUtils
import com.waytous.anticollision.vo.VehicleAnnotation
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
......@@ -39,16 +47,37 @@ open class BaseFragment : Fragment() {
MainViewModel.MainViewModelFactory(MainRepository(requireContext()))
}
val iconCurrentNormalVehicleBitmap by lazy {
BitmapUtils.bitmapFromDrawableRes(requireContext(),R.drawable.my_vehicle_normal)
}
private val iconOtherAlarmVehicleBitmap by lazy {
BitmapUtils.bitmapFromDrawableRes(requireContext(),R.drawable.other_vehicle_normal)
}
private lateinit var viewAnnotation: View
private lateinit var viewAnnotationManager: ViewAnnotationManager
private lateinit var pointAnnotationManager: PointAnnotationManager
private lateinit var pointAnnotation: PointAnnotation
companion object{
private val scaleLengths = listOf(5, 10, 20, 50, 100, 200, 500, 1000, 2000, 5000, 10000, 20000, 50000, 100000, 200000, 500000, 1000000, 2000000)
private const val MINIMUM_ZOOM_LEVEL = 11.0
private const val MAXIMUM_ZOOM_LEVEL = 26.0
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
}
fun initAnnotationManager(mapView:MapView){
viewAnnotationManager = mapView.viewAnnotationManager
pointAnnotationManager = mapView.annotations.createPointAnnotationManager()
}
fun updateMapBox(mapView:MapView){
mapView.getMapboxMap().setCamera(
CameraOptions.Builder().center(
......@@ -350,22 +379,93 @@ open class BaseFragment : Fragment() {
}
}
){
val bitmap: Bitmap? =
activity?.getBitmapFromVectorDrawable(R.drawable.my_vehicle_normal, 4)
// prepareAnnotationMarker(mapView,iconCurrentNormalVehicleBitmap!!)
// prepareViewAnnotation()
val otherAnnotation = VehicleAnnotation("KK-01",36,25,
Point.fromLngLat(MainViewModel.LONGITUDE,MainViewModel.LATITUDE),true)
addCurrentVehicleAnnotation(otherAnnotation)
val otherAnnotation1 = VehicleAnnotation("KK-02",24,25,Point.fromLngLat(119.76019,49.37932),true)
addOtherVehicleAnnotation(otherAnnotation1)
val otherAnnotation2 = VehicleAnnotation("KK-03",36,20,Point.fromLngLat(119.75694,49.38632),true)
addOtherVehicleAnnotation(otherAnnotation2)
}
}
}
}
}
@SuppressLint("SetTextI18n")
fun prepareViewAnnotation() {
viewAnnotation = viewAnnotationManager.addViewAnnotation(
resId = R.layout.current_vehicle_view_annotation_layout,
options = viewAnnotationOptions {
geometry(Point.fromLngLat(MainViewModel.LONGITUDE,MainViewModel.LATITUDE))
associatedFeatureId(pointAnnotation.featureIdentifier)
anchor(ViewAnnotationAnchor.BOTTOM)
offsetY((pointAnnotation.iconImageBitmap?.height!!*0.25).toInt())
}
)
val binding = CurrentVehicleViewAnnotationLayoutBinding.bind(viewAnnotation)
binding.annotationCurrentVehicleNo.text = context?.getString(R.string.annotation_vehicle_no,"KK-001")
binding.annotationCurrentVehicleSpeed.text = context?.getString(R.string.annotation_vehicle_speed,36)
}
fun prepareAnnotationMarker(mapView: MapView, iconBitmap: Bitmap) {
val annotationPlugin = mapView.annotations
val pointAnnotationOptions: PointAnnotationOptions = PointAnnotationOptions()
.withPoint(mapModel.center.value!!)
.withIconImage(bitmap!!.apply {
scale(bitmap.width / 4, bitmap.height / 4)
})
.withPoint(Point.fromLngLat(MainViewModel.LONGITUDE,MainViewModel.LATITUDE))
.withIconImage(iconBitmap)
.withIconSize(0.25)
.withIconAnchor(IconAnchor.BOTTOM)
.withDraggable(false)
pointAnnotationManager = annotationPlugin.createPointAnnotationManager()
pointAnnotation = pointAnnotationManager.create(pointAnnotationOptions)
}
fun addCurrentVehicleAnnotation(otherAnnotation: VehicleAnnotation){
val pointAnnotationOptions: PointAnnotationOptions = PointAnnotationOptions()
.withPoint(Point.fromLngLat(MainViewModel.LONGITUDE,MainViewModel.LATITUDE))
.withIconImage(iconCurrentNormalVehicleBitmap!!)
.withIconSize(0.25)
.withIconAnchor(IconAnchor.BOTTOM)
.withDraggable(false)
val pointAnnotation = pointAnnotationManager.create(pointAnnotationOptions)
val viewAnnotation = viewAnnotationManager.addViewAnnotation(
resId = R.layout.current_vehicle_view_annotation_layout,
options = viewAnnotationOptions {
geometry(Point.fromLngLat(MainViewModel.LONGITUDE,MainViewModel.LATITUDE))
associatedFeatureId(pointAnnotation.featureIdentifier)
anchor(ViewAnnotationAnchor.BOTTOM)
offsetY((pointAnnotation.iconImageBitmap?.height!!*0.25).toInt())
}
)
val binding = CurrentVehicleViewAnnotationLayoutBinding.bind(viewAnnotation)
binding.annotationCurrentVehicleNo.text = context?.getString(R.string.annotation_vehicle_no,"KK-001")
binding.annotationCurrentVehicleSpeed.text = context?.getString(R.string.annotation_vehicle_speed,36)
}
fun addOtherVehicleAnnotation(otherAnnotation: VehicleAnnotation){
val pointAnnotationOptions: PointAnnotationOptions = PointAnnotationOptions()
.withPoint(otherAnnotation.point)
.withIconImage(iconOtherAlarmVehicleBitmap!!)
.withIconSize(0.25)
.withIconAnchor(IconAnchor.BOTTOM)
.withDraggable(false)
val pointAnnotation = pointAnnotationManager.create(pointAnnotationOptions)
val viewAnnotation = viewAnnotationManager.addViewAnnotation(
resId = R.layout.other_vehicle_view_annotation_layout,
options = viewAnnotationOptions {
geometry(otherAnnotation.point)
associatedFeatureId(otherAnnotation.vehicleNo)
anchor(ViewAnnotationAnchor.BOTTOM)
offsetY((pointAnnotation.iconImageBitmap?.height!!*0.25).toInt())
}
)
val binding = OtherVehicleViewAnnotationLayoutBinding.bind(viewAnnotation)
binding.annotationOtherVehicleNo.text = context?.getString(R.string.annotation_vehicle_no,otherAnnotation.vehicleNo)
binding.annotationOtherVehicleSpeed.text = 24.toString()
binding.annotationOtherVehicleDistance.text = 25.toString()
}
}
\ No newline at end of file
......@@ -4,6 +4,7 @@ import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.viewmodel.CreationExtras
import com.blankj.utilcode.util.LogUtils
import com.mapbox.geojson.Point
import com.waytous.anticollision.repository.MainRepository
import kotlinx.coroutines.Dispatchers
......@@ -28,24 +29,25 @@ class MainViewModel @Inject constructor(private val mainRepository: MainReposito
emit(it.mapDataSource)
!it.abort
}.map {
it.geojson
it?.geojson
}.flowOn(Dispatchers.IO)
.catch {
LogUtils.e(it.message)
emit("")
}
fun electronicFenceSource() = flowOf(
mainRepository.localElectronicFenceVersion(),
mainRepository.remoteElectronicFenceVersion()
)
.flattenMerge()
).flattenMerge()
.transformWhile {
emit(it.mapDataSource)
!it.abort
}.map {
it.geojson
it?.geojson
}.flowOn(Dispatchers.IO)
.catch {
LogUtils.e(it.message)
emit("")
}
......@@ -56,9 +58,10 @@ class MainViewModel @Inject constructor(private val mainRepository: MainReposito
emit(it.mapDataSource)
!it.abort
}.map {
it.geojson
it?.geojson
}.flowOn(Dispatchers.IO)
.catch {
LogUtils.e(it.message)
emit("")
}
......@@ -69,9 +72,10 @@ class MainViewModel @Inject constructor(private val mainRepository: MainReposito
emit(it.mapDataSource)
!it.abort
}.map {
it.geojson
it?.geojson
}.flowOn(Dispatchers.IO)
.catch {
LogUtils.e(it.message)
emit("")
}
......@@ -81,9 +85,10 @@ class MainViewModel @Inject constructor(private val mainRepository: MainReposito
emit(it.mapDataSource)
!it.abort
}.map {
it.geojson
it?.geojson
}.flowOn(Dispatchers.IO)
.catch {
LogUtils.e(it.message)
emit("")
}
......@@ -95,9 +100,10 @@ class MainViewModel @Inject constructor(private val mainRepository: MainReposito
emit(it.mapDataSource)
!it.abort
}.map {
it.geojson
it?.geojson
}.flowOn(Dispatchers.IO)
.catch {
LogUtils.e(it.message)
emit("")
}
......@@ -108,9 +114,10 @@ class MainViewModel @Inject constructor(private val mainRepository: MainReposito
emit(it.mapDataSource)
!it.abort
}.map {
it.geojson
it?.geojson
}.flowOn(Dispatchers.IO)
.catch {
LogUtils.e(it.message)
emit("")
}
......@@ -122,9 +129,10 @@ class MainViewModel @Inject constructor(private val mainRepository: MainReposito
emit(it.mapDataSource)
!it.abort
}.map {
it.geojson
it?.geojson
}.flowOn(Dispatchers.IO)
.catch {
LogUtils.e(it.message)
emit("")
}
......@@ -135,9 +143,10 @@ class MainViewModel @Inject constructor(private val mainRepository: MainReposito
emit(it.mapDataSource)
!it.abort
}.map {
it.geojson
it?.geojson
}.flowOn(Dispatchers.IO)
.catch {
LogUtils.e(it.message)
emit("")
}
......@@ -148,9 +157,10 @@ class MainViewModel @Inject constructor(private val mainRepository: MainReposito
emit(it.mapDataSource)
!it.abort
}.map {
it.geojson
it?.geojson
}.flowOn(Dispatchers.IO)
.catch {
LogUtils.e(it.message)
emit("")
}
......@@ -161,9 +171,10 @@ class MainViewModel @Inject constructor(private val mainRepository: MainReposito
emit(it.mapDataSource)
!it.abort
}.map {
it.geojson
it?.geojson
}.flowOn(Dispatchers.IO)
.catch {
LogUtils.e(it.message)
emit("")
}
......@@ -175,9 +186,10 @@ class MainViewModel @Inject constructor(private val mainRepository: MainReposito
emit(it.mapDataSource)
!it.abort
}.map {
it.geojson
it?.geojson
}.flowOn(Dispatchers.IO)
.catch {
LogUtils.e(it.message)
emit("")
}
......
package com.waytous.anticollision.ui
import android.annotation.SuppressLint
import android.content.Context
import android.graphics.Color
import android.text.Spannable
import android.text.SpannableString
import android.text.style.ForegroundColorSpan
import android.util.AttributeSet
import android.view.LayoutInflater
import android.graphics.Bitmap
import android.view.View
import android.widget.FrameLayout
import androidx.appcompat.widget.AppCompatImageView
import androidx.appcompat.widget.AppCompatTextView
import com.blankj.utilcode.util.LogUtils
import androidx.appcompat.content.res.AppCompatResources
import com.mapbox.geojson.Point
import com.mapbox.maps.CameraOptions
import com.mapbox.maps.MapView
import com.mapbox.maps.MapboxMap
import com.mapbox.maps.Style
import com.mapbox.maps.extension.style.expressions.dsl.generated.get
import com.mapbox.maps.extension.style.layers.generated.circleLayer
import com.mapbox.maps.extension.style.layers.generated.fillLayer
import com.mapbox.maps.extension.style.layers.generated.lineLayer
import com.mapbox.maps.extension.style.layers.generated.symbolLayer
import com.mapbox.maps.ViewAnnotationAnchor
import com.mapbox.maps.extension.style.expressions.dsl.generated.interpolate
import com.mapbox.maps.extension.style.layers.properties.generated.*
import com.mapbox.maps.extension.style.projection.generated.projection
import com.mapbox.maps.extension.style.sources.addSource
import com.mapbox.maps.extension.style.sources.generated.geoJsonSource
import com.mapbox.maps.extension.style.style
import com.mapbox.maps.plugin.animation.flyTo
import com.mapbox.maps.plugin.attribution.attribution
import com.mapbox.maps.plugin.compass.compass
import com.mapbox.maps.plugin.logo.logo
import com.waytous.anticollision.BuildConfig
import com.mapbox.maps.plugin.LocationPuck2D
import com.mapbox.maps.plugin.annotation.annotations
import com.mapbox.maps.plugin.annotation.generated.PointAnnotation
import com.mapbox.maps.plugin.annotation.generated.PointAnnotationManager
import com.mapbox.maps.plugin.annotation.generated.PointAnnotationOptions
import com.mapbox.maps.plugin.annotation.generated.createPointAnnotationManager
import com.mapbox.maps.plugin.locationcomponent.location
import com.mapbox.maps.viewannotation.ViewAnnotationManager
import com.mapbox.maps.viewannotation.viewAnnotationOptions
import com.waytous.anticollision.R
import com.waytous.anticollision.databinding.CurrentVehicleViewAnnotationLayoutBinding
import com.waytous.anticollision.utils.BitmapUtils
/**
* mapbox及控制组件封装
* @author male
* @param context
* @param attributeSet
* */
class MapBoxLayout(context: Context, private val attributeSet: AttributeSet):FrameLayout(context,attributeSet) {
class MapBoxLayout(private val context: Context,private val mapView:MapView){
/**
* mapbox地图
* */
private var mapView:MapView
/**
* mapbox
* */
private var mapBox:MapboxMap
/**
* sos按钮
* */
private var sosButton: AppCompatImageView
/**
* 急停按钮
* */
private var emergency: AppCompatImageView
/**
* 放大按钮
* */
private var zoomOut: AppCompatImageView
/**
* 缩小按钮
* */
private var zoomIn: AppCompatImageView
/**
* 定位车辆位置
* */
private var locationTruck: AppCompatImageView
/**
* 关闭&显示安全距离
* */
private var toggleSafetyRange: AppCompatImageView
/**
* 地图采集信息文本
* */
private var collectDataText:AppCompatTextView
private var cameraOptions:CameraOptions
private var zoomLevel:Double = 14.0
private lateinit var style: Style
companion object{
private val scaleLengths = listOf(5, 10, 20, 50, 100, 200, 500, 1000, 2000, 5000, 10000, 20000, 50000, 100000, 200000, 500000, 1000000, 2000000)
private const val MINIMUM_ZOOM_LEVEL = 11.0
private const val MAXIMUM_ZOOM_LEVEL = 26.0
}
init {
val root:View = LayoutInflater.from(context).inflate(R.layout.layout_map_box,this,true)
mapView = root.findViewById<MapView>(R.id.mapView).also {
it.logo.enabled = false
it.compass.enabled = false
it.attribution.enabled = false
}
mapBox = mapView.getMapboxMap().also {mapbox ->
mapbox.loadStyle(style(MainViewModel.MY_MAP_BOX_STYLE){
+projection(ProjectionName.GLOBE)
}){
style = it
addTruckPathSource()
}
}
cameraOptions = CameraOptions.Builder().center(Point.fromLngLat(BuildConfig.DEFAULT_LONGITUDE,BuildConfig.DEFAULT_LATITUDE)).zoom(zoomLevel).build()
sosButton = root.findViewById<AppCompatImageView?>(R.id.sos).also {
it.setOnClickListener {
}
}
emergency = root.findViewById(R.id.emergency)
zoomOut = root.findViewById<AppCompatImageView?>(R.id.zoomOut).also {
it.setOnClickListener {
}
}
zoomIn = root.findViewById<AppCompatImageView?>(R.id.zoomIn).also {
}
locationTruck = root.findViewById<AppCompatImageView?>(R.id.locationTruck).also {
}
toggleSafetyRange = root.findViewById<AppCompatImageView?>(R.id.toggleSafetyRange).also {
}
collectDataText = root.findViewById(R.id.collectDataText)
}
fun updateCenter(center:Point){
mapBox.flyTo(cameraOptions.toBuilder().center(center).build())
}
private lateinit var viewAnnotationManager: ViewAnnotationManager
private fun calculateScale(){
private lateinit var pointAnnotationManager: PointAnnotationManager
}
fun addRunnableAreaSource(source: String){
style.addSource{
geoJsonSource(MainViewModel.RUNNABLE_AREA_SOURCE) {
data(source)
}
fillLayer(
MainViewModel.RUNNABLE_AREA_LAYER,
MainViewModel.RUNNABLE_AREA_SOURCE
){
fillColor("#98a0a0")
fillOpacity(0.85)
fillOutlineColor("#FFFF00")
visibility(Visibility.VISIBLE)
}
}
}
private lateinit var pointAnnotation: PointAnnotation
fun addLaneSource(source: String){
style.addSource{
geoJsonSource(MainViewModel.LANE_SOURCE) {
data(source)
}
lineLayer(
MainViewModel.LANE_LAYER,
MainViewModel.LANE_SOURCE
){
lineColor("white")
lineWidth(3.0)
lineJoin(LineJoin.ROUND)
lineCap(LineCap.ROUND)
visibility(Visibility.VISIBLE)
}
}
}
fun addStaticObjectsSource(source: String){
style.addSource{
geoJsonSource(MainViewModel.STATIC_OBJECTS_SOURCE) {
data(source)
}
fillLayer(
MainViewModel.STATIC_OBJECTS_LAYER,
MainViewModel.STATIC_OBJECTS_SOURCE
){
fillColor("#98a0a0")
fillOpacity(0.85)
fillAntialias(false)
visibility(Visibility.VISIBLE)
}
symbolLayer(MainViewModel.STATIC_OBJECTS_TEXT_LAYER, MainViewModel.STATIC_OBJECTS_SOURCE){
textColor(Color.BLACK)
textField(get("name"))
textFont(listOf("DIN Offc Pro Italic", "Arial Unicode MS Regular"))
textLineHeight(1.0)
textPadding(1.0)
textOffset(listOf(0.5,-0.5))
textRotationAlignment(TextRotationAlignment.MAP)
textAnchor(TextAnchor.TOP)
textSize(16.0)
textMaxAngle(10.0)
visibility(Visibility.VISIBLE)
}
}
}
private lateinit var viewAnnotation: View
fun addDiggingWorkAreaSource(source: String){
style.addSource{
geoJsonSource(MainViewModel.DIGGING_WORK_AREA_SOURCE) {
data(source)
}
fillLayer(
MainViewModel.DIGGING_WORK_AREA_LAYER,
MainViewModel.DIGGING_WORK_AREA_SOURCE
){
fillColor("#886e26")
fillOpacity(0.85)
fillAntialias(false)
visibility(Visibility.VISIBLE)
}
symbolLayer(MainViewModel.DIGGING_WORK_AREA_TEXT_LAYER, MainViewModel.DIGGING_WORK_AREA_SOURCE){
textColor(Color.BLACK)
textField(get("name"))
textFont(listOf("DIN Offc Pro Italic", "Arial Unicode MS Regular"))
textLineHeight(1.0)
textPadding(1.0)
textOffset(listOf(0.5,-0.5))
textRotationAlignment(TextRotationAlignment.MAP)
textAnchor(TextAnchor.TOP)
textSize(16.0)
textMaxAngle(10.0)
visibility(Visibility.VISIBLE)
}
}
}
fun addBarricadeSource(source: String){
style.addSource{
geoJsonSource(MainViewModel.BARRICADE_SOURCE) {
data(source)
}
lineLayer(
MainViewModel.BARRICADE_LAYER,
MainViewModel.BARRICADE_SOURCE
){
lineColor("blue")
lineWidth(4.0)
lineJoin(LineJoin.ROUND)
lineCap(LineCap.ROUND)
visibility(Visibility.VISIBLE)
}
}
companion object{
private val scaleLengths = listOf(5, 10, 20, 50, 100, 200, 500, 1000, 2000, 5000, 10000, 20000, 50000, 100000, 200000, 500000, 1000000, 2000000)
private const val MINIMUM_ZOOM_LEVEL = 11.0
private const val MAXIMUM_ZOOM_LEVEL = 26.0
}
fun addObstaclesSource(source: String){
style.addSource{
geoJsonSource(MainViewModel.OBSTACLES_SOURCE) {
data(source)
}
fillLayer(
MainViewModel.OBSTACLES_LAYER,
MainViewModel.OBSTACLES_SOURCE
){
fillColor("#6f9bdd")
fillOpacity(0.8)
visibility(Visibility.VISIBLE)
}
symbolLayer(MainViewModel.OBSTACLES_TEXT_LAYER, MainViewModel.OBSTACLES_SOURCE){
textColor(Color.BLACK)
textField(get("name"))
textFont(listOf("DIN Offc Pro Italic", "Arial Unicode MS Regular"))
textLineHeight(1.0)
textPadding(1.0)
textOffset(listOf(0.5,-0.5))
textRotationAlignment(TextRotationAlignment.MAP)
textAnchor(TextAnchor.TOP)
textSize(16.0)
textMaxAngle(10.0)
visibility(Visibility.VISIBLE)
}
}
}
fun addStationAreaSource(source: String){
style.addSource{
geoJsonSource(MainViewModel.STATION_AREA_SOURCE) {
data(source)
}
fillLayer(
MainViewModel.STATION_AREA_LAYER,
MainViewModel.STATION_AREA_SOURCE
){
fillColor("lightgreen")
fillOpacity(0.8)
visibility(Visibility.VISIBLE)
}
symbolLayer(MainViewModel.STATION_AREA_TEXT_LAYER, MainViewModel.STATION_AREA_SOURCE){
textColor(Color.BLACK)
textField(get("name"))
textFont(listOf("DIN Offc Pro Italic", "Arial Unicode MS Regular"))
textLineHeight(1.0)
textPadding(1.0)
textOffset(listOf(0.5,-0.5))
textRotationAlignment(TextRotationAlignment.MAP)
textAnchor(TextAnchor.TOP)
textSize(16.0)
textMaxWidth(10.0)
}
}
}
fun addLaneNodeSource(source: String){
style.addSource{
geoJsonSource(MainViewModel.LANE_NODE_SOURCE) {
data(source)
}
circleLayer(
MainViewModel.LANE_NODE_LAYER,
MainViewModel.LANE_NODE_SOURCE
){
circleColor("red")
circleRadius(6.0)
visibility(Visibility.VISIBLE)
}
symbolLayer(MainViewModel.LANE_TEXT_LAYER, MainViewModel.LANE_NODE_SOURCE){
textColor(Color.BLACK)
textField(get("name"))
textFont(listOf("DIN Offc Pro Italic", "Arial Unicode MS Regular"))
textLineHeight(1.0)
textPadding(1.0)
textOffset(listOf(0.5,-0.5))
textRotationAlignment(TextRotationAlignment.MAP)
textAnchor(TextAnchor.TOP)
textSize(9.0)
textMaxAngle(10.0)
visibility(Visibility.VISIBLE)
}
}
private val iconCurrentNormalVehicleBitmap by lazy {
BitmapUtils.bitmapFromDrawableRes(context,R.drawable.my_vehicle_normal)
}
fun addParkSpotSource(source: String){
style.addSource{
geoJsonSource(MainViewModel.PARK_SPOT_SOURCE) {
data(source)
}
fillLayer(
MainViewModel.PARK_SPOT_LAYER,
MainViewModel.PARK_SPOT_SOURCE
){
fillColor(get("#7e8185"))
fillOpacity(0.8)
fillAntialias(false)
visibility(Visibility.VISIBLE)
}
symbolLayer(MainViewModel.PARK_SPOT_TEXT_LAYER, MainViewModel.PARK_SPOT_SOURCE){
textColor(Color.BLACK)
textField(get("name"))
textFont(listOf("DIN Offc Pro Italic", "Arial Unicode MS Regular"))
textLineHeight(1.0)
textPadding(1.0)
textOffset(listOf(0.5,-0.5))
textRotationAlignment(TextRotationAlignment.MAP)
textAnchor(TextAnchor.TOP)
textSize(9.0)
textMaxAngle(10.0)
visibility(Visibility.VISIBLE)
}
}
private val iconOtherAlarmVehicleBitmap by lazy {
BitmapUtils.bitmapFromDrawableRes(context,R.drawable.other_vehicle_normal)
}
fun addElectronicFenceSource(source: String){
style.addSource{
geoJsonSource(MainViewModel.ELECTRONIC_FENCE_SOURCE) {
data(source)
}
fillLayer(
MainViewModel.ELECTRONIC_FENCE_LAYER,
MainViewModel.ELECTRONIC_FENCE_SOURCE
){
fillColor(get("color"))
fillOpacity(0.85)
fillAntialias(false)
visibility(Visibility.VISIBLE)
}
symbolLayer(MainViewModel.ELECTRONIC_FENCE_TEXT_LAYER, MainViewModel.ELECTRONIC_FENCE_SOURCE){
textColor(Color.BLACK)
textField(get("name"))
textFont(listOf("DIN Offc Pro Italic", "Arial Unicode MS Regular"))
textLineHeight(1.0)
textPadding(1.0)
textOffset(listOf(0.5,-0.5))
textRotationAlignment(TextRotationAlignment.MAP)
textAnchor(TextAnchor.TOP)
textSize(16.0)
textMaxAngle(10.0)
visibility(Visibility.VISIBLE)
fun updateTruckLocation(drawable:Int){
mapView.location.locationPuck = LocationPuck2D(AppCompatResources.getDrawable(context,drawable),scaleExpression = interpolate {
linear()
zoom()
stop {
literal(MINIMUM_ZOOM_LEVEL)
literal(0.6)
}
stop {
literal(MAXIMUM_ZOOM_LEVEL)
literal(1.2)
}
}.toJson())
}
fun addWetAreaSource(source: String){
style.addSource{
geoJsonSource(MainViewModel.WET_AREA_SOURCE) {
data(source)
}
fillLayer(
MainViewModel.WET_AREA_LAYER,
MainViewModel.WET_AREA_SOURCE
){
fillColor(get("color"))
fillOpacity(0.8)
fillAntialias(false)
visibility(Visibility.VISIBLE)
}
symbolLayer(MainViewModel.WET_AREA_TEXT_LAYER, MainViewModel.WET_AREA_SOURCE){
textColor(Color.BLACK)
textField(get("name"))
textFont(listOf("DIN Offc Pro Italic", "Arial Unicode MS Regular"))
textLineHeight(1.0)
textPadding(1.0)
textOffset(listOf(0.5,-0.5))
textRotationAlignment(TextRotationAlignment.MAP)
textAnchor(TextAnchor.TOP)
textSize(16.0)
textMaxAngle(10.0)
visibility(Visibility.VISIBLE)
}
}
}
fun updateRoundTrucks(vararg points:Point){
points.forEach {
fun addDumpAreaSource(source: String){
style.addSource{
geoJsonSource(MainViewModel.DUMP_AREA_SOURCE) {
data(source)
}
fillLayer(
MainViewModel.DUMP_AREA_LAYER,
MainViewModel.DUMP_AREA_SOURCE
){
fillColor("#886e26")
fillOpacity(0.85)
fillAntialias(false)
visibility(Visibility.VISIBLE)
}
symbolLayer(MainViewModel.DUMP_AREA_TEXT_LAYER, MainViewModel.DUMP_AREA_SOURCE){
textColor(Color.BLACK)
textField(get("name"))
textFont(listOf("DIN Offc Pro Italic", "Arial Unicode MS Regular"))
textLineHeight(1.0)
textPadding(1.0)
textOffset(listOf(0.5,-0.5))
textRotationAlignment(TextRotationAlignment.MAP)
textAnchor(TextAnchor.TOP)
textSize(16.0)
textMaxAngle(10.0)
visibility(Visibility.VISIBLE)
}
}
}
private fun addTruckPathSource(){
style.addSource{
geoJsonSource("truckPathSource") {
data("{ \"type\": \"FeatureCollection\", \"features\":[]}")
}
lineLayer(
"truckPathLayer",
"truckPathSource"
){
lineColor("green")
lineWidth(8.0)
lineOpacity(0.8)
lineJoin(LineJoin.ROUND)
lineCap(LineCap.ROUND)
visibility(Visibility.VISIBLE)
@SuppressLint("SetTextI18n")
private fun prepareViewAnnotation() {
viewAnnotation = viewAnnotationManager.addViewAnnotation(
resId = R.layout.current_vehicle_view_annotation_layout,
options = viewAnnotationOptions {
geometry(Point.fromLngLat(MainViewModel.LONGITUDE,MainViewModel.LATITUDE))
associatedFeatureId(pointAnnotation.featureIdentifier)
anchor(ViewAnnotationAnchor.BOTTOM)
offsetY((pointAnnotation.iconImageBitmap?.height!!).toInt())
}
}
}
fun formatCollectionData(text:String){
val tagSpan = ForegroundColorSpan(Color.parseColor("#666666"))
val contentSpan = ForegroundColorSpan(Color.parseColor("#000000"))
val spannableString = SpannableString(text)
spannableString.setSpan(tagSpan, 0, 4, Spannable.SPAN_INCLUSIVE_INCLUSIVE)
val textPointIndex = text.indexOf("采集点数")
spannableString.setSpan(contentSpan, 5, textPointIndex, Spannable.SPAN_INCLUSIVE_EXCLUSIVE)
spannableString.setSpan(tagSpan, textPointIndex, textPointIndex+4, Spannable.SPAN_INCLUSIVE_INCLUSIVE)
val textPositionIndex = text.indexOf("当前位置")
spannableString.setSpan(contentSpan, textPointIndex+1, textPositionIndex, Spannable.SPAN_INCLUSIVE_EXCLUSIVE)
spannableString.setSpan(tagSpan, textPositionIndex, textPositionIndex+4, Spannable.SPAN_INCLUSIVE_INCLUSIVE)
val textAltitudeIndex = text.indexOf("高程")
spannableString.setSpan(contentSpan, textPositionIndex+1, textAltitudeIndex, Spannable.SPAN_INCLUSIVE_EXCLUSIVE)
spannableString.setSpan(tagSpan, textAltitudeIndex, textAltitudeIndex+2, Spannable.SPAN_INCLUSIVE_INCLUSIVE)
collectDataText.text = spannableString
)
CurrentVehicleViewAnnotationLayoutBinding.bind(viewAnnotation)
}
override fun onAttachedToWindow() {
super.onAttachedToWindow()
private fun prepareAnnotationMarker(mapView: MapView, iconBitmap: Bitmap) {
val annotationPlugin = mapView.annotations
val pointAnnotationOptions: PointAnnotationOptions = PointAnnotationOptions()
.withPoint(Point.fromLngLat(MainViewModel.LONGITUDE,MainViewModel.LATITUDE))
.withIconImage(iconBitmap)
.withIconAnchor(IconAnchor.BOTTOM)
pointAnnotationManager = annotationPlugin.createPointAnnotationManager()
pointAnnotation = pointAnnotationManager.create(pointAnnotationOptions)
}
}
\ No newline at end of file
package com.waytous.anticollision.ui.home
import android.graphics.Color
import android.os.Bundle
import android.text.SpannableString
import android.util.Log
import android.view.Gravity
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.FrameLayout
import android.widget.ImageView
import android.widget.TextView
import androidx.fragment.app.viewModels
import androidx.lifecycle.*
import com.blankj.utilcode.util.LogUtils
import com.mapbox.geojson.Point
import com.mapbox.maps.CameraOptions
import com.mapbox.maps.MapView
import com.mapbox.maps.MapboxMap
import com.mapbox.maps.extension.style.expressions.dsl.generated.get
import com.mapbox.maps.extension.style.layers.generated.circleLayer
import com.mapbox.maps.extension.style.layers.generated.fillLayer
import com.mapbox.maps.extension.style.layers.generated.lineLayer
import com.mapbox.maps.extension.style.layers.generated.symbolLayer
import com.mapbox.maps.extension.style.layers.properties.generated.LineCap
import com.mapbox.maps.extension.style.layers.properties.generated.LineJoin
import com.mapbox.maps.extension.style.layers.properties.generated.TextAnchor
import com.mapbox.maps.extension.style.layers.properties.generated.TextRotationAlignment
import com.mapbox.maps.extension.style.layers.properties.generated.Visibility
import com.mapbox.maps.extension.style.sources.generated.geoJsonSource
import com.mapbox.maps.extension.style.style
import com.mapbox.maps.plugin.annotation.generated.PointAnnotation
import com.mapbox.maps.plugin.annotation.generated.PointAnnotationManager
import com.mapbox.maps.plugin.attribution.attribution
import com.mapbox.maps.plugin.compass.compass
import com.mapbox.maps.plugin.logo.logo
import com.mapbox.maps.plugin.scalebar.scalebar
import com.mapbox.maps.viewannotation.ViewAnnotationManager
import com.waytous.anticollision.R
import com.waytous.anticollision.databinding.FragmentHomeBinding
......@@ -24,7 +44,21 @@ import com.waytous.anticollision.ui.BaseFragment
import com.waytous.anticollision.ui.MainViewModel
import com.waytous.anticollision.ui.view.MoreFeaturesPopup
import com.waytous.anticollision.ui.view.WorkStatusEditPopup
import com.waytous.anticollision.utils.addBarricadeSource
import com.waytous.anticollision.utils.addDiggingWorkAreaSource
import com.waytous.anticollision.utils.addDumpAreaSource
import com.waytous.anticollision.utils.addElectronicFenceSource
import com.waytous.anticollision.utils.addLaneNodeSource
import com.waytous.anticollision.utils.addLaneSource
import com.waytous.anticollision.utils.addObstaclesSource
import com.waytous.anticollision.utils.addParkSpotSource
import com.waytous.anticollision.utils.addRunnableAreaSource
import com.waytous.anticollision.utils.addStaticObjectsSource
import com.waytous.anticollision.utils.addStationAreaSource
import com.waytous.anticollision.utils.addTruckPathSource
import com.waytous.anticollision.utils.addWetAreaSource
import com.waytous.anticollision.utils.setTextSize
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.launch
class HomeFragment : BaseFragment() {
......@@ -35,27 +69,16 @@ class HomeFragment : BaseFragment() {
private lateinit var mapView: MapView
private lateinit var mapBox:MapboxMap
private lateinit var viewAnnotationManager: ViewAnnotationManager
private lateinit var pointAnnotationManager: PointAnnotationManager
private lateinit var pointAnnotation: PointAnnotation
private var count = 0
private lateinit var moreFeaturesPopup: MoreFeaturesPopup
private lateinit var workStatusEditPopup: WorkStatusEditPopup
private val mapModel: MainViewModel by viewModels{
private val mapModel: MainViewModel by viewModels {
MainViewModel.MainViewModelFactory(MainRepository(requireContext()))
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
}
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
......@@ -64,7 +87,7 @@ class HomeFragment : BaseFragment() {
val homeViewModel =
ViewModelProvider(this)[HomeViewModel::class.java]
_binding = FragmentHomeBinding.inflate(inflater, container, false)
context?:return binding.root
context ?: return binding.root
workStatusEditPopup = WorkStatusEditPopup(context).also {
it.setOutSideDismiss(true)
it.popupGravity = Gravity.TOP or Gravity.CENTER
......@@ -76,15 +99,16 @@ class HomeFragment : BaseFragment() {
it.maskOffsetY = 20
it.setBackgroundColor(R.color.color_99000000)
}
mapView = binding.root.findViewById<MapView?>(R.id.mapView).also {
mapView = binding.root.findViewById<MapView?>(R.id.mapView).also { it ->
it.logo.enabled = false
it.compass.enabled = false
it.attribution.enabled = false
it.scalebar.enabled = false
}
viewAnnotationManager = mapView.viewAnnotationManager
initAnnotationManager(mapView)
updateMapBox(mapView)
mapView.addRendererSetupErrorListener {
error -> LogUtils.e("RendererSetupErrorListener:${error}")
mapView.addRendererSetupErrorListener { error ->
LogUtils.e("RendererSetupErrorListener:${error}")
}
setTodayCarriedNum(18)
setTodayIllegallyNum(1)
......@@ -94,37 +118,19 @@ class HomeFragment : BaseFragment() {
binding.defaultToggleMore.setOnClickListener {
moreFeaturesPopup.showPopupWindow(binding.defaultToggleMore)
}
viewLifecycleOwner.lifecycleScope.launch {
repeatOnLifecycle(Lifecycle.State.STARTED){
mapModel.obstaclesSource().collect{binding.defaultMapLayout.addObstaclesSource(it)}
mapModel.runnableAreaSource().collect{binding.defaultMapLayout.addRunnableAreaSource(it)}
mapModel.laneSource().collect{binding.defaultMapLayout.addLaneSource(it)}
mapModel.laneNodeSource().collect{binding.defaultMapLayout.addLaneNodeSource(it)}
mapModel.staticObjectsSource().collect{binding.defaultMapLayout.addStaticObjectsSource(it)}
mapModel.diggingWorkAreaSource().collect{binding.defaultMapLayout.addDiggingWorkAreaSource(it)}
mapModel.barricadeSource().collect{binding.defaultMapLayout.addBarricadeSource(it)}
mapModel.stationAreaSource().collect{binding.defaultMapLayout.addStationAreaSource(it)}
mapModel.parkSpotSource().collect{binding.defaultMapLayout.addParkSpotSource(it)}
mapModel.electronicFenceSource().collect{binding.defaultMapLayout.addElectronicFenceSource(it)}
mapModel.wetAreaSource().collect{binding.defaultMapLayout.addWetAreaSource(it)}
mapModel.dumpAreaSource().collect{binding.defaultMapLayout.addDumpAreaSource(it)}
}
}
return binding.root
}
private fun setTodayCarriedNum(num:Int){
private fun setTodayCarriedNum(num: Int) {
val templateString = getString(R.string.today_carried_text, num)
val spannableString = SpannableString(templateString)
binding.todayCarried.setTextSize(spannableString, templateString,"今日运载(车)")
binding.todayCarried.setTextSize(spannableString, templateString, "今日运载(车)")
}
private fun setTodayIllegallyNum(num:Int){
private fun setTodayIllegallyNum(num: Int) {
val templateString = getString(R.string.today_illegally_text, num)
val spannableString = SpannableString(templateString)
binding.illegallyNum.setTextSize(spannableString, templateString,"违章/警告(次)")
binding.illegallyNum.setTextSize(spannableString, templateString, "违章/警告(次)")
}
override fun onDestroyView() {
......
package com.waytous.anticollision.utils
import android.content.Context
import android.graphics.Bitmap
import android.graphics.Canvas
import android.graphics.drawable.BitmapDrawable
import android.graphics.drawable.Drawable
import androidx.annotation.DrawableRes
import androidx.appcompat.content.res.AppCompatResources
/**
* Utility class to work with bitmaps and drawables.
*/
object BitmapUtils {
/**
* Convert given drawable id to bitmap.
*/
fun bitmapFromDrawableRes(context: Context, @DrawableRes resourceId: Int) =
convertDrawableToBitmap(AppCompatResources.getDrawable(context, resourceId))
private fun convertDrawableToBitmap(sourceDrawable: Drawable?): Bitmap? {
if (sourceDrawable == null) {
return null
}
return if (sourceDrawable is BitmapDrawable) {
sourceDrawable.bitmap
} else {
// copying drawable object to not manipulate on the same reference
val constantState = sourceDrawable.constantState ?: return null
val drawable = constantState.newDrawable().mutate()
val bitmap: Bitmap = Bitmap.createBitmap(
drawable.intrinsicWidth, drawable.intrinsicHeight,
Bitmap.Config.ARGB_8888
)
val canvas = Canvas(bitmap)
drawable.setBounds(0, 0, canvas.width, canvas.height)
drawable.draw(canvas)
bitmap
}
}
}
\ No newline at end of file
......@@ -3,6 +3,7 @@ package com.waytous.anticollision.utils
import android.content.Context
import android.graphics.Bitmap
import android.graphics.Canvas
import android.graphics.Color
import android.graphics.drawable.Drawable
import android.os.Build
import android.text.Spannable
......@@ -13,6 +14,21 @@ import androidx.appcompat.app.AppCompatActivity
import androidx.core.app.ActivityCompat
import androidx.core.content.ContextCompat
import androidx.core.graphics.drawable.DrawableCompat
import com.blankj.utilcode.util.LogUtils
import com.mapbox.maps.Style
import com.mapbox.maps.extension.style.expressions.dsl.generated.get
import com.mapbox.maps.extension.style.layers.generated.circleLayer
import com.mapbox.maps.extension.style.layers.generated.fillLayer
import com.mapbox.maps.extension.style.layers.generated.lineLayer
import com.mapbox.maps.extension.style.layers.generated.symbolLayer
import com.mapbox.maps.extension.style.layers.properties.generated.LineCap
import com.mapbox.maps.extension.style.layers.properties.generated.LineJoin
import com.mapbox.maps.extension.style.layers.properties.generated.TextAnchor
import com.mapbox.maps.extension.style.layers.properties.generated.TextRotationAlignment
import com.mapbox.maps.extension.style.layers.properties.generated.Visibility
import com.mapbox.maps.extension.style.sources.addSource
import com.mapbox.maps.extension.style.sources.generated.geoJsonSource
import com.waytous.anticollision.ui.MainViewModel
const val databaseName = "anti_collision.db"
......@@ -69,6 +85,357 @@ fun Context.getBitmapFromVectorDrawable(drawableId:Int,scale:Int = 2): Bitmap? {
return bitmap
}
fun Style.addRunnableAreaSource(source: String){
LogUtils.dTag("MapBoxLayout","addRunnableAreaSource")
addSource{
geoJsonSource(MainViewModel.RUNNABLE_AREA_SOURCE) {
data(source)
}
fillLayer(
MainViewModel.RUNNABLE_AREA_LAYER,
MainViewModel.RUNNABLE_AREA_SOURCE
){
fillColor("#98a0a0")
fillOpacity(0.85)
fillOutlineColor("#FFFF00")
visibility(Visibility.VISIBLE)
}
}
}
fun Style.addLaneSource(source: String){
LogUtils.dTag("MapBoxLayout","addLaneSource")
addSource{
geoJsonSource(MainViewModel.LANE_SOURCE) {
data(source)
}
lineLayer(
MainViewModel.LANE_LAYER,
MainViewModel.LANE_SOURCE
){
lineColor("white")
lineWidth(3.0)
lineJoin(LineJoin.ROUND)
lineCap(LineCap.ROUND)
visibility(Visibility.VISIBLE)
}
}
}
fun Style.addStaticObjectsSource(source: String){
LogUtils.dTag("MapBoxLayout","addStaticObjectsSource")
addSource{
geoJsonSource(MainViewModel.STATIC_OBJECTS_SOURCE) {
data(source)
}
fillLayer(
MainViewModel.STATIC_OBJECTS_LAYER,
MainViewModel.STATIC_OBJECTS_SOURCE
){
fillColor("#98a0a0")
fillOpacity(0.85)
fillAntialias(false)
visibility(Visibility.VISIBLE)
}
symbolLayer(MainViewModel.STATIC_OBJECTS_TEXT_LAYER, MainViewModel.STATIC_OBJECTS_SOURCE){
textColor(Color.BLACK)
textField(get("name"))
textFont(listOf("DIN Offc Pro Italic", "Arial Unicode MS Regular"))
textLineHeight(1.0)
textPadding(1.0)
textOffset(listOf(0.5,-0.5))
textRotationAlignment(TextRotationAlignment.MAP)
textAnchor(TextAnchor.TOP)
textSize(16.0)
textMaxAngle(10.0)
visibility(Visibility.VISIBLE)
}
}
}
fun Style.addDiggingWorkAreaSource(source: String){
LogUtils.dTag("MapBoxLayout","addDiggingWorkAreaSource")
addSource{
geoJsonSource(MainViewModel.DIGGING_WORK_AREA_SOURCE) {
data(source)
}
fillLayer(
MainViewModel.DIGGING_WORK_AREA_LAYER,
MainViewModel.DIGGING_WORK_AREA_SOURCE
){
fillColor("#886e26")
fillOpacity(0.85)
fillAntialias(false)
visibility(Visibility.VISIBLE)
}
symbolLayer(MainViewModel.DIGGING_WORK_AREA_TEXT_LAYER, MainViewModel.DIGGING_WORK_AREA_SOURCE){
textColor(Color.BLACK)
textField(get("name"))
textFont(listOf("DIN Offc Pro Italic", "Arial Unicode MS Regular"))
textLineHeight(1.0)
textPadding(1.0)
textOffset(listOf(0.5,-0.5))
textRotationAlignment(TextRotationAlignment.MAP)
textAnchor(TextAnchor.TOP)
textSize(16.0)
textMaxAngle(10.0)
visibility(Visibility.VISIBLE)
}
}
}
fun Style.addBarricadeSource(source: String){
LogUtils.dTag("MapBoxLayout","addBarricadeSource")
addSource{
geoJsonSource(MainViewModel.BARRICADE_SOURCE) {
data(source)
}
lineLayer(
MainViewModel.BARRICADE_LAYER,
MainViewModel.BARRICADE_SOURCE
){
lineColor("blue")
lineWidth(4.0)
lineJoin(LineJoin.ROUND)
lineCap(LineCap.ROUND)
visibility(Visibility.VISIBLE)
}
}
}
fun Style.addObstaclesSource(source: String){
LogUtils.dTag("MapBoxLayout","addObstaclesSource")
addSource{
geoJsonSource(MainViewModel.OBSTACLES_SOURCE) {
url(source)
}
fillLayer(
MainViewModel.OBSTACLES_LAYER,
MainViewModel.OBSTACLES_SOURCE
){
fillColor("#6f9bdd")
fillOpacity(0.8)
visibility(Visibility.VISIBLE)
}
symbolLayer(MainViewModel.OBSTACLES_TEXT_LAYER, MainViewModel.OBSTACLES_SOURCE){
textColor(Color.BLACK)
textField(get("name"))
textFont(listOf("DIN Offc Pro Italic", "Arial Unicode MS Regular"))
textLineHeight(1.0)
textPadding(1.0)
textOffset(listOf(0.5,-0.5))
textRotationAlignment(TextRotationAlignment.MAP)
textAnchor(TextAnchor.TOP)
textSize(16.0)
textMaxAngle(10.0)
visibility(Visibility.VISIBLE)
}
}
}
fun Style.addStationAreaSource(source: String){
LogUtils.dTag("MapBoxLayout","addStationAreaSource")
addSource{
geoJsonSource(MainViewModel.STATION_AREA_SOURCE) {
data(source)
}
fillLayer(
MainViewModel.STATION_AREA_LAYER,
MainViewModel.STATION_AREA_SOURCE
){
fillColor("lightgreen")
fillOpacity(0.8)
visibility(Visibility.VISIBLE)
}
symbolLayer(MainViewModel.STATION_AREA_TEXT_LAYER, MainViewModel.STATION_AREA_SOURCE){
textColor(Color.BLACK)
textField(get("name"))
textFont(listOf("DIN Offc Pro Italic", "Arial Unicode MS Regular"))
textLineHeight(1.0)
textPadding(1.0)
textOffset(listOf(0.5,-0.5))
textRotationAlignment(TextRotationAlignment.MAP)
textAnchor(TextAnchor.TOP)
textSize(16.0)
textMaxWidth(10.0)
}
}
}
fun Style.addLaneNodeSource(source: String){
LogUtils.dTag("MapBoxLayout","addLaneNodeSource")
addSource{
geoJsonSource(MainViewModel.LANE_NODE_SOURCE) {
data(source)
}
circleLayer(
MainViewModel.LANE_NODE_LAYER,
MainViewModel.LANE_NODE_SOURCE
){
circleColor("red")
circleRadius(6.0)
visibility(Visibility.VISIBLE)
}
symbolLayer(MainViewModel.LANE_TEXT_LAYER, MainViewModel.LANE_NODE_SOURCE){
textColor(Color.BLACK)
textField(get("name"))
textFont(listOf("DIN Offc Pro Italic", "Arial Unicode MS Regular"))
textLineHeight(1.0)
textPadding(1.0)
textOffset(listOf(0.5,-0.5))
textRotationAlignment(TextRotationAlignment.MAP)
textAnchor(TextAnchor.TOP)
textSize(9.0)
textMaxAngle(10.0)
visibility(Visibility.VISIBLE)
}
}
}
fun Style.addParkSpotSource(source: String){
LogUtils.dTag("MapBoxLayout","addParkSpotSource")
addSource{
geoJsonSource(MainViewModel.PARK_SPOT_SOURCE) {
data(source)
}
fillLayer(
MainViewModel.PARK_SPOT_LAYER,
MainViewModel.PARK_SPOT_SOURCE
){
fillColor(get("#7e8185"))
fillOpacity(0.8)
fillAntialias(false)
visibility(Visibility.VISIBLE)
}
symbolLayer(MainViewModel.PARK_SPOT_TEXT_LAYER, MainViewModel.PARK_SPOT_SOURCE){
textColor(Color.BLACK)
textField(get("name"))
textFont(listOf("DIN Offc Pro Italic", "Arial Unicode MS Regular"))
textLineHeight(1.0)
textPadding(1.0)
textOffset(listOf(0.5,-0.5))
textRotationAlignment(TextRotationAlignment.MAP)
textAnchor(TextAnchor.TOP)
textSize(9.0)
textMaxAngle(10.0)
visibility(Visibility.VISIBLE)
}
}
}
fun Style.addElectronicFenceSource(source: String){
LogUtils.dTag("MapBoxLayout","addElectronicFenceSource")
addSource{
geoJsonSource(MainViewModel.ELECTRONIC_FENCE_SOURCE) {
data(source)
}
fillLayer(
MainViewModel.ELECTRONIC_FENCE_LAYER,
MainViewModel.ELECTRONIC_FENCE_SOURCE
){
fillColor(get("color"))
fillOpacity(0.85)
fillAntialias(false)
visibility(Visibility.VISIBLE)
}
symbolLayer(MainViewModel.ELECTRONIC_FENCE_TEXT_LAYER, MainViewModel.ELECTRONIC_FENCE_SOURCE){
textColor(Color.BLACK)
textField(get("name"))
textFont(listOf("DIN Offc Pro Italic", "Arial Unicode MS Regular"))
textLineHeight(1.0)
textPadding(1.0)
textOffset(listOf(0.5,-0.5))
textRotationAlignment(TextRotationAlignment.MAP)
textAnchor(TextAnchor.TOP)
textSize(16.0)
textMaxAngle(10.0)
visibility(Visibility.VISIBLE)
}
}
}
fun Style.addWetAreaSource(source: String){
LogUtils.dTag("MapBoxLayout","addWetAreaSource")
addSource{
geoJsonSource(MainViewModel.WET_AREA_SOURCE) {
data(source)
}
fillLayer(
MainViewModel.WET_AREA_LAYER,
MainViewModel.WET_AREA_SOURCE
){
fillColor(get("color"))
fillOpacity(0.8)
fillAntialias(false)
visibility(Visibility.VISIBLE)
}
symbolLayer(MainViewModel.WET_AREA_TEXT_LAYER, MainViewModel.WET_AREA_SOURCE){
textColor(Color.BLACK)
textField(get("name"))
textFont(listOf("DIN Offc Pro Italic", "Arial Unicode MS Regular"))
textLineHeight(1.0)
textPadding(1.0)
textOffset(listOf(0.5,-0.5))
textRotationAlignment(TextRotationAlignment.MAP)
textAnchor(TextAnchor.TOP)
textSize(16.0)
textMaxAngle(10.0)
visibility(Visibility.VISIBLE)
}
}
}
fun Style.addDumpAreaSource(source: String){
LogUtils.dTag("MapBoxLayout","addDumpAreaSource")
addSource{
geoJsonSource(MainViewModel.DUMP_AREA_SOURCE) {
data(source)
}
fillLayer(
MainViewModel.DUMP_AREA_LAYER,
MainViewModel.DUMP_AREA_SOURCE
){
fillColor("#886e26")
fillOpacity(0.85)
fillAntialias(false)
visibility(Visibility.VISIBLE)
}
symbolLayer(MainViewModel.DUMP_AREA_TEXT_LAYER, MainViewModel.DUMP_AREA_SOURCE){
textColor(Color.BLACK)
textField(get("name"))
textFont(listOf("DIN Offc Pro Italic", "Arial Unicode MS Regular"))
textLineHeight(1.0)
textPadding(1.0)
textOffset(listOf(0.5,-0.5))
textRotationAlignment(TextRotationAlignment.MAP)
textAnchor(TextAnchor.TOP)
textSize(16.0)
textMaxAngle(10.0)
visibility(Visibility.VISIBLE)
}
}
}
fun Style.addTruckPathSource(){
LogUtils.dTag("MapBoxLayout","addTruckPathSource")
addSource{
geoJsonSource("truckPathSource") {
data("{ \"type\": \"FeatureCollection\", \"features\":[]}")
}
lineLayer(
"truckPathLayer",
"truckPathSource"
){
lineColor("green")
lineWidth(8.0)
lineOpacity(0.8)
lineJoin(LineJoin.ROUND)
lineCap(LineCap.ROUND)
visibility(Visibility.VISIBLE)
}
}
}
fun AppCompatActivity.checkSelfPermissionCompat(permission: String) =
ActivityCompat.checkSelfPermission(this, permission)
......
package com.waytous.anticollision.vo
import com.mapbox.geojson.Point
data class VehicleAnnotation(val vehicleNo:String, val speed:Int, val distance:Int, val point: Point, val isShow:Boolean)
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<size android:width="@dimen/dp_140" android:height="@dimen/dp_54"/>
<solid android:color="@color/color_e6114da5" />
<corners android:radius="@dimen/dp_6" />
</shape>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<size android:width="@dimen/dp_140" android:height="@dimen/dp_64"/>
<solid android:color="@color/color_cc1c1c1c" />
<corners android:radius="@dimen/dp_6" />
</shape>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<size android:width="@dimen/dp_52" android:height="@dimen/dp_26"/>
<solid android:color="@color/color_80f97c36" />
<corners android:radius="@dimen/dp_6" />
</shape>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<size android:width="@dimen/dp_66" android:height="@dimen/dp_26"/>
<solid android:color="@color/color_803684f9" />
<corners android:radius="@dimen/dp_6" />
</shape>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<size android:width="@dimen/dp_140" android:height="@dimen/dp_54"/>
<solid android:color="@color/color_ff005aff" />
<corners android:radius="@dimen/dp_6" />
</shape>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<size android:width="@dimen/dp_140" android:height="@dimen/dp_64"/>
<solid android:color="@color/color_ccffffff" />
<corners android:radius="@dimen/dp_6" />
</shape>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<size android:width="@dimen/dp_52" android:height="@dimen/dp_26"/>
<solid android:color="@color/color_33f97c36" />
<corners android:radius="@dimen/dp_6" />
</shape>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<size android:width="@dimen/dp_66" android:height="@dimen/dp_26"/>
<solid android:color="@color/color_333684f9" />
<corners android:radius="@dimen/dp_6" />
</shape>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<androidx.appcompat.widget.LinearLayoutCompat xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="@drawable/background_view_annotation_current_vehicle">
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/annotationCurrentVehicleNo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/dp_13"
android:layout_marginTop="@dimen/dp_4"
android:textColor="@color/white"
android:textSize="@dimen/sp_16"
android:text="@string/annotation_vehicle_no"/>
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/annotationCurrentVehicleSpeed"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/dp_13"
android:textColor="@color/white"
android:textSize="@dimen/sp_16"
android:text="@string/annotation_vehicle_speed"/>
</androidx.appcompat.widget.LinearLayoutCompat>
\ No newline at end of file
......@@ -282,8 +282,9 @@
app:layout_constraintTop_toTopOf="@id/defaultToggleMore"
app:layout_constraintEnd_toEndOf="@id/defaultMapLayout" />
<com.waytous.anticollision.ui.MapBoxLayout
<include
android:id="@+id/defaultMapLayout"
layout="@layout/layout_map_box"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginEnd="16dp"
......
<?xml version="1.0" encoding="utf-8"?>
<androidx.appcompat.widget.LinearLayoutCompat xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="@drawable/background_view_annotation_other_vehicle">
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/annotationOtherVehicleNo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/dp_10"
android:layout_marginTop="@dimen/dp_7"
android:textColor="@color/color_ff333333"
android:textSize="@dimen/sp_16"
android:text="@string/annotation_vehicle_no"/>
<androidx.appcompat.widget.LinearLayoutCompat
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/dp_2">
<androidx.appcompat.widget.LinearLayoutCompat
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/dp_10"
android:background="@drawable/background_view_annotation_other_vehicle_speed">
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/annotationOtherVehicleSpeed"
style="@style/OtherVehicleSpeed"
android:layout_width="@dimen/dp_30"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:layout_marginStart="@dimen/dp_8"
android:textSize="@dimen/sp_16"
android:text="24"
/>
<androidx.appcompat.widget.AppCompatTextView
style="@style/OtherVehicleSpeed"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:textSize="@dimen/sp_10"
android:text="@string/current_speed_unit"
/>
</androidx.appcompat.widget.LinearLayoutCompat>
<androidx.appcompat.widget.LinearLayoutCompat
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/dp_5"
android:background="@drawable/background_view_annotation_other_vehicle_distance">
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/annotationOtherVehicleDistance"
style="@style/OtherVehicleDistance"
android:layout_width="@dimen/dp_30"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:layout_marginStart="@dimen/dp_8"
android:textSize="@dimen/sp_16"
android:text="25"
/>
<androidx.appcompat.widget.AppCompatTextView
style="@style/OtherVehicleDistance"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:textSize="@dimen/sp_10"
android:text="@string/other_distance_unit" />
</androidx.appcompat.widget.LinearLayoutCompat>
</androidx.appcompat.widget.LinearLayoutCompat>
</androidx.appcompat.widget.LinearLayoutCompat>
\ No newline at end of file
......@@ -47,4 +47,10 @@
<item name="android:maxLength">8</item>
<item name="android:textSize">10sp</item>
</style>
<style name="OtherVehicleSpeed" parent="Theme.HTAnticollision">
<item name="android:textColor">@color/color_ffebf0ff</item>
</style>
<style name="OtherVehicleDistance" parent="Theme.HTAnticollision">
<item name="android:textColor">@color/color_ffffdbc7</item>
</style>
</resources>
\ No newline at end of file
......@@ -33,4 +33,16 @@
<color name="color_1a000000">#1a000000</color>
<color name="color_ff3684F9">#ff3684F9</color>
<color name="color_green">#00ff00</color>
<color name="color_ff005aff">#ff005aff</color>
<color name="color_e6114da5">#e6114da5</color>
<color name="color_cc1c1c1c">#cc1c1c1c</color>
<color name="color_333684f9">#333684f9</color>
<color name="color_33f97c36">#33f97c36</color>
<color name="color_803684f9">#803684f9</color>
<color name="color_80f97c36">#80f97c36</color>
<color name="color_1352C5">#1352C5</color>
<color name="color_ffebf0ff">#ffebf0ff</color>
<color name="color_fff06313">#fff06313</color>
<color name="color_ffffdbc7">#ffffdbc7</color>
</resources>
\ No newline at end of file
......@@ -19,6 +19,7 @@
<string name="today_illegally_text">%1d\n违章/警告(次)</string>
<string name="current_speed2">32</string>
<string name="current_speed_unit">km/h</string>
<string name="other_distance_unit">m</string>
<string name="toggle_more">toggle more</string>
<string name="work_status_edit">修改</string>
<string name="work_status_mark">当前</string>
......@@ -71,6 +72,8 @@
<string name="collect_data_text">采集状态:%1s 采集点数:%2d 速度:%3dKM/h 当前位置:%4f,%5f 高程:%6fm</string>
<string name="confirm">确定</string>
<string name="cancel">取消</string>
<string name="annotation_vehicle_no">编号:%1s</string>
<string name="annotation_vehicle_speed">时速:%1d km/h</string>
<string-array name="collectRange">
......
......@@ -63,4 +63,10 @@
<item name="android:clickable">true</item>
<item name="android:focusable">true</item>
</style>
<style name="OtherVehicleSpeed" parent="Theme.HTAnticollision">
<item name="android:textColor">@color/color_1352C5</item>
</style>
<style name="OtherVehicleDistance" parent="Theme.HTAnticollision">
<item name="android:textColor">@color/color_fff06313</item>
</style>
</resources>
\ No newline at end of file
// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
id 'com.android.application' version '7.4.2' apply false
id 'com.android.library' version '7.4.2' apply false
id 'com.android.application' version '8.0.1' apply false
id 'com.android.library' version '8.0.1' apply false
id 'org.jetbrains.kotlin.android' version '1.8.0' apply false
id 'com.google.dagger.hilt.android' version '2.44' apply false
}
\ No newline at end of file
......@@ -23,3 +23,5 @@ kotlin.code.style=official
# thereby reducing the size of the R class for that library
android.nonTransitiveRClass=true
MAPBOX_DOWNLOADS_TOKEN=sk.eyJ1IjoibWFybGxlciIsImEiOiJjbGVjNHZhdWgwd3U4M29uMjJrY3BqYXpkIn0.cqcw1CHYVGwESBqsfWcm7w
android.defaults.buildfeatures.buildconfig=true
android.nonFinalResIds=false
\ No newline at end of file
#Thu May 04 15:47:53 CST 2023
distributionBase=GRADLE_USER_HOME
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0-bin.zip
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment