Commit 7552d1f8 authored by 马乐's avatar 马乐

1.地图异步加载

parent baa0be8d
package com.waytous.anticollision.repository
import android.content.Context
import androidx.annotation.RequiresPermission
import androidx.room.Room
import com.blankj.utilcode.util.LogUtils
import com.waytous.anticollision.api.MapSourceService
......
package com.waytous.anticollision.ui
import android.graphics.Color
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
......@@ -8,24 +7,16 @@ import android.view.ViewGroup
import androidx.asynclayoutinflater.view.AsyncLayoutInflater
import androidx.fragment.app.Fragment
import androidx.fragment.app.viewModels
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.lifecycleScope
import androidx.lifecycle.withStarted
import androidx.lifecycle.repeatOnLifecycle
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.Style
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
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.IconAnchor
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.AnnotationPlugin
import com.mapbox.maps.plugin.annotation.annotations
......@@ -39,36 +30,74 @@ import com.mapbox.maps.plugin.logo.logo
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.LayoutMapBoxBinding
import com.waytous.anticollision.databinding.OtherVehicleViewAnnotationLayoutBinding
import com.waytous.anticollision.repository.MainRepository
import com.waytous.anticollision.utils.BitmapUtils
import com.waytous.anticollision.utils.addBarricadeLineLayer
import com.waytous.anticollision.utils.addBarricadeSource
import com.waytous.anticollision.utils.addDiggingWorkAreaFillLayer
import com.waytous.anticollision.utils.addDiggingWorkAreaSource
import com.waytous.anticollision.utils.addDiggingWorkAreaSymbolLayer
import com.waytous.anticollision.utils.addDumpAreaFillLayer
import com.waytous.anticollision.utils.addDumpAreaSource
import com.waytous.anticollision.utils.addDumpAreaSymbolLayer
import com.waytous.anticollision.utils.addElectronicFenceFillLayer
import com.waytous.anticollision.utils.addElectronicFenceSource
import com.waytous.anticollision.utils.addElectronicFenceSymbolLayer
import com.waytous.anticollision.utils.addLaneLayer
import com.waytous.anticollision.utils.addLaneNodeCircleLayer
import com.waytous.anticollision.utils.addLaneNodeSource
import com.waytous.anticollision.utils.addLaneNodeSymbolLayer
import com.waytous.anticollision.utils.addLaneSource
import com.waytous.anticollision.utils.addObstaclesFillLayer
import com.waytous.anticollision.utils.addObstaclesSource
import com.waytous.anticollision.utils.addObstaclesSymbolLayer
import com.waytous.anticollision.utils.addParkSpotFillLayer
import com.waytous.anticollision.utils.addParkSpotSource
import com.waytous.anticollision.utils.addParkSpotSymbolLayer
import com.waytous.anticollision.utils.addRunnableAreaLayer
import com.waytous.anticollision.utils.addRunnableAreaSource
import com.waytous.anticollision.utils.addStaticObjectsFillLayer
import com.waytous.anticollision.utils.addStaticObjectsSource
import com.waytous.anticollision.utils.addStaticObjectsSymbolLayer
import com.waytous.anticollision.utils.addStationAreaFillLayer
import com.waytous.anticollision.utils.addStationAreaSource
import com.waytous.anticollision.utils.addStationAreaSymbolLayer
import com.waytous.anticollision.utils.addTruckPathLineLayer
import com.waytous.anticollision.utils.addTruckPathSource
import com.waytous.anticollision.utils.addWetAreaFillLayer
import com.waytous.anticollision.utils.addWetAreaSource
import com.waytous.anticollision.utils.addWetAreaSymbolLayer
import com.waytous.anticollision.vo.VehicleAnnotation
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.MainScope
import kotlinx.coroutines.flow.last
import kotlinx.coroutines.flow.single
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import java.math.BigDecimal
open class BaseFragment : Fragment() {
private val mapModel: MainViewModel by viewModels{
private val mapModel: MainViewModel by viewModels {
MainViewModel.MainViewModelFactory(MainRepository(requireContext()))
}
val iconCurrentNormalVehicleBitmap by lazy {
BitmapUtils.bitmapFromDrawableRes(requireContext(),R.drawable.my_vehicle_normal)
BitmapUtils.bitmapFromDrawableRes(requireContext(), R.drawable.my_vehicle_normal)
}
private val iconOtherAlarmVehicleBitmap by lazy {
BitmapUtils.bitmapFromDrawableRes(requireContext(),R.drawable.other_vehicle_normal)
BitmapUtils.bitmapFromDrawableRes(requireContext(), R.drawable.other_vehicle_normal)
}
private val asyncInflater by lazy {
AsyncLayoutInflater(requireContext())
}
private lateinit var layoutMapBoxBinding: LayoutMapBoxBinding
lateinit var layoutMapBoxBinding: LayoutMapBoxBinding
lateinit var mapboxMap: MapboxMap
private lateinit var viewAnnotation: View
......@@ -80,352 +109,175 @@ open class BaseFragment : Fragment() {
private lateinit var pointAnnotation: PointAnnotation
private val cameraOptions:CameraOptions by lazy {
private val cameraOptions: CameraOptions by lazy {
CameraOptions.Builder().center(
Point.fromLngLat(
MainViewModel.LONGITUDE,
MainViewModel.LATITUDE
)).zoom(14.0).build()
)
).zoom(14.0).build()
}
companion object{
private val scaleLengths = listOf(5, 10, 20, 50, 100, 200, 500, 1000, 2000, 5000, 10000, 20000, 50000, 100000, 200000, 500000, 1000000, 2000000)
companion object {
private val scaleLengths = listOf(
5,
10,
20,
50,
100,
200,
500,
1000,
2000,
5000,
10000,
20000,
50000,
100000,
200000,
500000,
1000000,
2000000
)
const val MINIMUM_ZOOM_LEVEL = 11.0
const val MAXIMUM_ZOOM_LEVEL = 26.0
const val DEFAULT_ZOOM_LEVEL = 14.0
}
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
layoutMapBoxBinding = LayoutMapBoxBinding.inflate(LayoutInflater.from(requireContext()))
}
fun setupMapBox() {
layoutMapBoxBinding.mapView.run {
logo.enabled = false
compass.enabled = false
attribution.enabled = false
}
return super.onCreateView(inflater, container, savedInstanceState)
}
mapboxMap = layoutMapBoxBinding.mapView.getMapboxMap().also {
it.setCamera(cameraOptions)
}
layoutMapBoxBinding.zoomIn.setOnClickListener {
val zoomLevel = BigDecimal(mapboxMap.cameraState.zoom).minus(BigDecimal(0.1.toString()))
when (BigDecimal(MINIMUM_ZOOM_LEVEL.toString()).compareTo(zoomLevel)) {
-1 -> {
mapboxMap.setCamera(CameraOptions.Builder().zoom(zoomLevel.toDouble()).build())
}
private fun initAnnotationManager(mapView:MapView){
annotationPlugin = mapView.annotations
viewAnnotationManager = mapView.viewAnnotationManager
pointAnnotationManager = annotationPlugin.createPointAnnotationManager()
else -> {
mapboxMap.setCamera(CameraOptions.Builder().zoom(DEFAULT_ZOOM_LEVEL).build())
}
}
}
layoutMapBoxBinding.zoomOut.setOnClickListener {
val zoomLevel = BigDecimal(mapboxMap.cameraState.zoom).add(BigDecimal(0.1.toString()))
when (BigDecimal(MAXIMUM_ZOOM_LEVEL.toString()).compareTo(zoomLevel)) {
-1 -> {
mapboxMap.setCamera(CameraOptions.Builder().zoom(DEFAULT_ZOOM_LEVEL).build())
}
else -> {
mapboxMap.setCamera(CameraOptions.Builder().zoom(zoomLevel.toDouble()).build())
}
}
}
mapboxMap.loadStyle(style(MainViewModel.MY_MAP_BOX_STYLE) {
}) {
initAnnotationManager()
setupStyle(it)
addTempAnnotations()
}
}
fun updateMapBox(mapView:MapView){
mapView.getMapboxMap().setCamera(
cameraOptions
)
lifecycleScope.launch{
withContext(Dispatchers.IO){
val apiService = ApiService.create()
val runnableAreaSource = apiService.runnableAreaVersion("-1")
val laneSource = apiService.laneVersion("-1")
val laneNodeSource = apiService.laneNodeVersion("-1")
val diggingWorkAreaSource = apiService.diggingWorkAreaVersion("-1")
val obstaclesSource = apiService.obstaclesVersion("-1")
val electronicFenceSource = apiService.electronicFenceVersion("-1")
val dumpAreaSource = apiService.dumpAreaVersion("-1")
val staticObjectsSource = apiService.staticObjectsVersion("-1")
val stationAreaSource = apiService.stationAreaVersion("-1")
val barricadeSource = apiService.barricadeVersion("-1")
val parkSpotSource = apiService.parkSpotVersion("-1")
val wetAreaSource = apiService.wetAreaVersion("-1")
withStarted {
mapView.getMapboxMap().loadStyle(
style(styleUri = MainViewModel.MY_MAP_BOX_STYLE) {
+geoJsonSource(MainViewModel.RUNNABLE_AREA_SOURCE) {
data(runnableAreaSource!!.geojson)
+fillLayer(
MainViewModel.RUNNABLE_AREA_LAYER,
MainViewModel.RUNNABLE_AREA_SOURCE
){
fillColor("#98a0a0")
fillOpacity(0.85)
fillOutlineColor("#FFFF00")
visibility(Visibility.VISIBLE)
}
}
+geoJsonSource(MainViewModel.LANE_SOURCE) {
data(laneSource!!.geojson)
+lineLayer(
MainViewModel.LANE_LAYER,
MainViewModel.LANE_SOURCE
){
lineColor("white")
lineWidth(3.0)
lineJoin(LineJoin.ROUND)
lineCap(LineCap.ROUND)
visibility(Visibility.VISIBLE)
}
}
+geoJsonSource(MainViewModel.STATIC_OBJECTS_SOURCE) {
data(staticObjectsSource!!.geojson)
+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)
}
}
+geoJsonSource(MainViewModel.DIGGING_WORK_AREA_SOURCE) {
data(diggingWorkAreaSource!!.geojson)
+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)
}
}
+geoJsonSource(MainViewModel.BARRICADE_SOURCE) {
data(barricadeSource!!.geojson)
+lineLayer(
MainViewModel.BARRICADE_LAYER,
MainViewModel.BARRICADE_SOURCE
){
lineColor("blue")
lineWidth(4.0)
lineJoin(LineJoin.ROUND)
lineCap(LineCap.ROUND)
visibility(Visibility.VISIBLE)
}
}
+geoJsonSource(MainViewModel.OBSTACLES_SOURCE) {
data(obstaclesSource!!.geojson)
+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)
}
}
+geoJsonSource(MainViewModel.STATION_AREA_SOURCE) {
data(stationAreaSource!!.geojson)
+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)
}
}
+geoJsonSource(MainViewModel.LANE_NODE_SOURCE) {
data(laneNodeSource!!.geojson)
+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)
}
}
+geoJsonSource(MainViewModel.PARK_SPOT_SOURCE) {
data(parkSpotSource!!.geojson)
+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)
}
}
+geoJsonSource(MainViewModel.ELECTRONIC_FENCE_SOURCE) {
data(electronicFenceSource!!.geojson)
+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)
}
}
+geoJsonSource(MainViewModel.WET_AREA_SOURCE) {
data(wetAreaSource!!.geojson)
+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)
}
}
+geoJsonSource(MainViewModel.DUMP_AREA_SOURCE) {
data(dumpAreaSource!!.geojson)
+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)
}
}
+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)
}
}
}
){
initAnnotationManager(mapView)
val otherAnnotation = VehicleAnnotation("KK-01",36,25,
Point.fromLngLat(MainViewModel.LONGITUDE,MainViewModel.LATITUDE),true)
updateCurrentVehicleAnnotation(otherAnnotation)
val otherAnnotation1 = VehicleAnnotation("KK-02",24,25,Point.fromLngLat(119.76739,49.37722),true)
val otherAnnotation2 = VehicleAnnotation("KK-03",36,20,Point.fromLngLat(119.75694,49.38632),true)
val others = listOf(otherAnnotation1,otherAnnotation2)
addOtherVehicleAnnotations(others)
}
private fun setupStyle(style: Style) {
lifecycleScope.launch {
viewLifecycleOwner.repeatOnLifecycle(Lifecycle.State.STARTED) {
mapModel.runnableAreaSource().last()?.let { source ->
style.addRunnableAreaSource(source)
style.addRunnableAreaLayer()
}
mapModel.laneSource().last()?.let { source ->
style.addLaneSource(source)
style.addLaneLayer()
}
mapModel.laneNodeSource().last()?.let { source ->
style.addLaneNodeSource(source)
style.addLaneNodeCircleLayer()
style.addLaneNodeSymbolLayer()
}
mapModel.diggingWorkAreaSource().last()?.let { source ->
style.addDiggingWorkAreaSource(source)
style.addDiggingWorkAreaFillLayer()
style.addDiggingWorkAreaSymbolLayer()
}
mapModel.obstaclesSource().last()?.let { source ->
style.addObstaclesSource(source)
style.addObstaclesFillLayer()
style.addObstaclesSymbolLayer()
}
mapModel.electronicFenceSource().last()?.let { source ->
style.addElectronicFenceSource(source)
style.addElectronicFenceFillLayer()
style.addElectronicFenceSymbolLayer()
}
mapModel.wetAreaSource().last()?.let { source ->
style.addWetAreaSource(source)
style.addWetAreaFillLayer()
style.addWetAreaSymbolLayer()
}
mapModel.dumpAreaSource().last()?.let { source ->
style.addDumpAreaSource(source)
style.addDumpAreaFillLayer()
style.addDumpAreaSymbolLayer()
}
mapModel.barricadeSource().last()?.let { source ->
style.addBarricadeSource(source)
style.addBarricadeLineLayer()
}
mapModel.stationAreaSource().last()?.let { source ->
style.addStationAreaSource(source)
style.addStationAreaFillLayer()
style.addStationAreaSymbolLayer()
}
mapModel.staticObjectsSource().last()?.let { source ->
style.addStaticObjectsSource(source)
style.addStaticObjectsFillLayer()
style.addStaticObjectsSymbolLayer()
}
mapModel.parkSpotSource().last()?.let { source ->
style.addParkSpotSource(source)
style.addParkSpotFillLayer()
style.addParkSpotSymbolLayer()
}
style.addTruckPathSource()
style.addTruckPathLineLayer()
}
}
}
fun updateCurrentVehicleAnnotation(otherAnnotation: VehicleAnnotation){
fun addTempAnnotations() {
val otherAnnotation = VehicleAnnotation(
"KK-01", 36, 25,
Point.fromLngLat(MainViewModel.LONGITUDE, MainViewModel.LATITUDE), true
)
updateCurrentVehicleAnnotation(otherAnnotation)
val otherAnnotation1 =
VehicleAnnotation("KK-02", 24, 25, Point.fromLngLat(119.76739, 49.37722), true)
val otherAnnotation2 =
VehicleAnnotation("KK-03", 36, 20, Point.fromLngLat(119.75694, 49.38632), true)
val others = listOf(otherAnnotation1, otherAnnotation2)
addOtherVehicleAnnotations(others)
}
private fun initAnnotationManager() {
annotationPlugin = layoutMapBoxBinding.mapView.annotations
viewAnnotationManager = layoutMapBoxBinding.mapView.viewAnnotationManager
pointAnnotationManager = annotationPlugin.createPointAnnotationManager()
}
fun updateCurrentVehicleAnnotation(otherAnnotation: VehicleAnnotation) {
val pointAnnotationOptions: PointAnnotationOptions = PointAnnotationOptions()
.withPoint(otherAnnotation.point)
.withIconImage(iconCurrentNormalVehicleBitmap!!)
......@@ -433,43 +285,49 @@ open class BaseFragment : Fragment() {
.withIconAnchor(IconAnchor.BOTTOM)
.withDraggable(false)
val pointAnnotation = pointAnnotationManager.create(pointAnnotationOptions)
pointAnnotation.symbolSortKey = Double.MAX_VALUE
val viewAnnotation = viewAnnotationManager.addViewAnnotation(
resId = R.layout.current_vehicle_view_annotation_layout,
options = viewAnnotationOptions {
geometry(otherAnnotation.point)
associatedFeatureId(pointAnnotation.featureIdentifier)
anchor(ViewAnnotationAnchor.BOTTOM)
offsetY((pointAnnotation.iconImageBitmap?.height!!*0.25).toInt())
offsetY((pointAnnotation.iconImageBitmap?.height!! * 0.25).toInt())
allowOverlap(true)
}
)
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)
binding.annotationCurrentVehicleNo.text =
context?.getString(R.string.annotation_vehicle_no, "KK-001")
binding.annotationCurrentVehicleSpeed.text =
context?.getString(R.string.annotation_vehicle_speed, 36)
}
fun addOtherVehicleAnnotations(others: List<VehicleAnnotation>){
others.forEach {vehicle->
val pointAnnotationOptions: PointAnnotationOptions = PointAnnotationOptions()
.withPoint(vehicle.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(vehicle.point)
fun addOtherVehicleAnnotations(others: List<VehicleAnnotation>) {
others.forEach { vehicle ->
val pointAnnotationOptions: PointAnnotationOptions = PointAnnotationOptions()
.withPoint(vehicle.point)
.withIconImage(iconOtherAlarmVehicleBitmap!!)
.withIconSize(0.25)
.withIconAnchor(IconAnchor.BOTTOM)
.withDraggable(false)
val pointAnnotation = pointAnnotationManager.create(pointAnnotationOptions)
pointAnnotation.symbolSortKey = Double.MAX_VALUE
val viewAnnotation = viewAnnotationManager.addViewAnnotation(
resId = R.layout.other_vehicle_view_annotation_layout,
options = viewAnnotationOptions {
geometry(vehicle.point)
// associatedFeatureId(pointAnnotation.featureIdentifier)
anchor(ViewAnnotationAnchor.BOTTOM)
offsetY((pointAnnotation.iconImageBitmap?.height!!*0.25).toInt())
allowOverlap(true)
}
)
val binding = OtherVehicleViewAnnotationLayoutBinding.bind(viewAnnotation)
binding.annotationOtherVehicleNo.text = context?.getString(R.string.annotation_vehicle_no,vehicle.vehicleNo)
binding.annotationOtherVehicleSpeed.text = vehicle.speed.toString()
binding.annotationOtherVehicleDistance.text = vehicle.distance.toString()
anchor(ViewAnnotationAnchor.BOTTOM)
offsetY((pointAnnotation.iconImageBitmap?.height!! * 0.25).toInt())
allowOverlap(true)
}
)
val binding = OtherVehicleViewAnnotationLayoutBinding.bind(viewAnnotation)
binding.annotationOtherVehicleNo.text =
context?.getString(R.string.annotation_vehicle_no, vehicle.vehicleNo)
binding.annotationOtherVehicleSpeed.text = vehicle.speed.toString()
binding.annotationOtherVehicleDistance.text = vehicle.distance.toString()
}
}
}
\ No newline at end of file
......@@ -95,7 +95,10 @@ class MainViewModel @Inject constructor(private val mainRepository: MainReposito
fun runnableAreaSource() = flowOf(
mainRepository.localRunnableAreaVersion(),
mainRepository.remoteRunnableAreaVersion()
).flattenMerge()
).onStart {
LogUtils.dTag("MainViewModel","runnableAreaSource start")
}
.flattenMerge()
.transformWhile {
emit(it.mapDataSource)
!it.abort
......
......@@ -6,19 +6,10 @@ import android.view.Gravity
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.databinding.adapters.ZoomControlsBindingAdapter
import androidx.fragment.app.viewModels
import androidx.lifecycle.ViewModelProvider
import com.blankj.utilcode.util.LogUtils
import com.mapbox.maps.CameraOptions
import com.mapbox.maps.MapView
import com.mapbox.maps.extension.style.expressions.dsl.generated.image
import com.mapbox.maps.extension.style.layers.generated.backgroundLayer
import com.mapbox.maps.plugin.animation.camera
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.waytous.anticollision.R
import com.waytous.anticollision.databinding.FragmentHomeBinding
import com.waytous.anticollision.repository.MainRepository
......@@ -27,7 +18,6 @@ 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.setTextSize
import java.math.BigDecimal
class HomeFragment : BaseFragment() {
......@@ -69,39 +59,9 @@ class HomeFragment : BaseFragment() {
it.maskOffsetY = 20
it.setBackgroundColor(R.color.color_99000000)
}
mapView = binding.root.findViewById<MapView?>(R.id.mapView).also { it ->
it.logo.enabled = false
it.compass.enabled = false
it.attribution.enabled = false
}
binding.defaultMapLayout.zoomIn.setOnClickListener {
LogUtils.d("zoomIn level = ${mapView.getMapboxMap().cameraState.zoom}")
val zoomLevel = BigDecimal(mapView.getMapboxMap().cameraState.zoom).minus(BigDecimal(0.1.toString()))
when(BigDecimal(MINIMUM_ZOOM_LEVEL.toString()).compareTo(zoomLevel)){
-1->{
mapView.getMapboxMap().setCamera(CameraOptions.Builder().zoom(zoomLevel.toDouble()).build())
}
else ->{
mapView.getMapboxMap().setCamera(CameraOptions.Builder().zoom(DEFAULT_ZOOM_LEVEL).build())
}
}
}
binding.defaultMapLayout.zoomOut.setOnClickListener {
LogUtils.d("zoomOut level = ${mapView.getMapboxMap().cameraState.zoom}")
val zoomLevel = BigDecimal(mapView.getMapboxMap().cameraState.zoom).add(BigDecimal(0.1.toString()))
when(BigDecimal(MAXIMUM_ZOOM_LEVEL.toString()).compareTo(zoomLevel)){
-1->{
mapView.getMapboxMap().setCamera(CameraOptions.Builder().zoom(DEFAULT_ZOOM_LEVEL).build())
}
else ->{
mapView.getMapboxMap().setCamera(CameraOptions.Builder().zoom(zoomLevel.toDouble()).build())
}
}
}
updateMapBox(mapView)
mapView.addRendererSetupErrorListener { error ->
LogUtils.e("RendererSetupErrorListener:${error}")
}
LogUtils.d("HomeFragment.onCreateView")
setupMapBox()
binding.defaultMapLayout.addView(layoutMapBoxBinding.root)
setTodayCarriedNum(18)
setTodayIllegallyNum(1)
binding.workStatusEdit.setOnClickListener {
......@@ -127,6 +87,7 @@ class HomeFragment : BaseFragment() {
override fun onDestroyView() {
super.onDestroyView()
binding.defaultMapLayout.removeView(layoutMapBoxBinding.root)
_binding = null
}
......
......@@ -5,7 +5,6 @@ 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
import android.text.SpannableString
import android.text.style.AbsoluteSizeSpan
......@@ -13,10 +12,10 @@ import android.widget.TextView
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.addLayer
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
......@@ -90,16 +89,21 @@ fun Context.getBitmapFromVectorDrawable(drawableId:Int,scale:Int = 2): Bitmap? {
return bitmap
}
fun Style.addRunnableAreaSource(source: String):GeoJsonSource{
LogUtils.dTag("MapBoxLayout","addRunnableAreaSource")
return geoJsonSource(MainViewModel.RUNNABLE_AREA_SOURCE){
/**
* runablearea:可行驶区域
* */
fun Style.addRunnableAreaSource(source: String){
LogUtils.dTag("MapBoxExtensions","addRunnableAreaSource")
LogUtils.dTag("MapBoxExtensions","addRunnableAreaSource,source = ${source.substring(0..15)}")
val source = geoJsonSource(MainViewModel.RUNNABLE_AREA_SOURCE){
data(source)
}
addSource(source)
}
fun Style.addRunnableAreaLayer():FillLayer{
LogUtils.dTag("MapBoxLayout","addRunnableAreaLayer")
return fillLayer(
fun Style.addRunnableAreaLayer(){
LogUtils.dTag("MapBoxExtensions","addRunnableAreaLayer")
val fillLayer = fillLayer(
MainViewModel.RUNNABLE_AREA_LAYER,
MainViewModel.RUNNABLE_AREA_SOURCE
){
......@@ -108,18 +112,21 @@ fun Style.addRunnableAreaLayer():FillLayer{
fillOutlineColor("#FFFF00")
visibility(Visibility.VISIBLE)
}
addLayer(fillLayer)
}
fun Style.addLaneSource(source: String):GeoJsonSource{
LogUtils.dTag("MapBoxLayout","addLaneSource")
return geoJsonSource(MainViewModel.RUNNABLE_AREA_SOURCE){
/**
* lanelayer:整个矿山边界路线
* */
fun Style.addLaneSource(source: String){
LogUtils.dTag("MapBoxExtensions","addLaneSource")
val source = geoJsonSource(MainViewModel.LANE_SOURCE){
data(source)
}
addSource(source)
}
fun Style.addLaneLayer():LineLayer{
LogUtils.dTag("MapBoxLayout","addLaneLayer")
return lineLayer(
fun Style.addLaneLayer(){
LogUtils.dTag("MapBoxExtensions","addLaneLayer")
val lineLayer = lineLayer(
MainViewModel.LANE_LAYER,
MainViewModel.LANE_SOURCE
){
......@@ -129,18 +136,21 @@ fun Style.addLaneLayer():LineLayer{
lineCap(LineCap.ROUND)
visibility(Visibility.VISIBLE)
}
addLayer(lineLayer)
}
fun Style.addStaticObjectsSource(source: String):GeoJsonSource{
LogUtils.dTag("MapBoxLayout","addStaticObjectsSource")
return geoJsonSource(MainViewModel.STATIC_OBJECTS_SOURCE) {
/**
* staticobjs:静态对象区域
* */
fun Style.addStaticObjectsSource(source: String){
LogUtils.dTag("MapBoxExtensions","addStaticObjectsSource")
val source = geoJsonSource(MainViewModel.STATIC_OBJECTS_SOURCE) {
data(source)
}
addSource(source)
}
fun Style.addStaticObjectsFillLayer():FillLayer{
LogUtils.dTag("MapBoxLayout","addStaticObjectsFillLayer")
return fillLayer(
fun Style.addStaticObjectsFillLayer(){
LogUtils.dTag("MapBoxExtensions","addStaticObjectsFillLayer")
val fillLayer = fillLayer(
MainViewModel.STATIC_OBJECTS_LAYER,
MainViewModel.STATIC_OBJECTS_SOURCE
){
......@@ -149,11 +159,11 @@ fun Style.addStaticObjectsFillLayer():FillLayer{
fillAntialias(false)
visibility(Visibility.VISIBLE)
}
addLayer(fillLayer)
}
fun Style.addStaticObjectsSymbolLayer():SymbolLayer{
LogUtils.dTag("MapBoxLayout","addStaticObjectsSymbolLayer")
return symbolLayer(MainViewModel.STATIC_OBJECTS_TEXT_LAYER, MainViewModel.STATIC_OBJECTS_SOURCE){
fun Style.addStaticObjectsSymbolLayer(){
LogUtils.dTag("MapBoxExtensions","addStaticObjectsSymbolLayer")
val symbolLayer = 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"))
......@@ -163,21 +173,24 @@ fun Style.addStaticObjectsSymbolLayer():SymbolLayer{
textRotationAlignment(TextRotationAlignment.MAP)
textAnchor(TextAnchor.TOP)
textSize(16.0)
textMaxAngle(10.0)
textMaxWidth(10.0)
visibility(Visibility.VISIBLE)
}
addLayer(symbolLayer)
}
fun Style.addDiggingWorkAreaSource(source: String):GeoJsonSource{
LogUtils.dTag("MapBoxLayout","addDiggingWorkAreaSource")
return geoJsonSource(MainViewModel.DIGGING_WORK_AREA_SOURCE) {
/**
* diggingarea:挖掘区域
* */
fun Style.addDiggingWorkAreaSource(source: String){
LogUtils.dTag("MapBoxExtensions","addDiggingWorkAreaSource")
val source = geoJsonSource(MainViewModel.DIGGING_WORK_AREA_SOURCE) {
data(source)
}
addSource(source)
}
fun Style.addDiggingWorkAreaFillLayer():FillLayer{
LogUtils.dTag("MapBoxLayout","addStaticObjectsFillLayer")
return fillLayer(
fun Style.addDiggingWorkAreaFillLayer(){
LogUtils.dTag("MapBoxExtensions","addStaticObjectsFillLayer")
val fillLayer = fillLayer(
MainViewModel.DIGGING_WORK_AREA_LAYER,
MainViewModel.DIGGING_WORK_AREA_SOURCE
){
......@@ -186,11 +199,11 @@ fun Style.addDiggingWorkAreaFillLayer():FillLayer{
fillAntialias(false)
visibility(Visibility.VISIBLE)
}
addLayer(fillLayer)
}
fun Style.addDiggingWorkAreaSymbolLayer():SymbolLayer{
LogUtils.dTag("MapBoxLayout","addDiggingWorkAreaSymbolLayer")
return symbolLayer(MainViewModel.DIGGING_WORK_AREA_TEXT_LAYER, MainViewModel.DIGGING_WORK_AREA_SOURCE){
fun Style.addDiggingWorkAreaSymbolLayer(){
LogUtils.dTag("MapBoxExtensions","addDiggingWorkAreaSymbolLayer")
val symbolLayer = 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"))
......@@ -200,21 +213,65 @@ fun Style.addDiggingWorkAreaSymbolLayer():SymbolLayer{
textRotationAlignment(TextRotationAlignment.MAP)
textAnchor(TextAnchor.TOP)
textSize(16.0)
textMaxAngle(10.0)
textMaxWidth(10.0)
visibility(Visibility.VISIBLE)
}
addLayer(symbolLayer)
}
fun Style.addBarricadeSource(source: String):GeoJsonSource{
LogUtils.dTag("MapBoxLayout","addBarricadeSource")
return geoJsonSource(MainViewModel.BARRICADE_SOURCE) {
/**
* dumparea:排土区域
* */
fun Style.addDumpAreaSource(source: String){
LogUtils.dTag("MapBoxExtensions","addDumpAreaSource")
val source = geoJsonSource(MainViewModel.DUMP_AREA_SOURCE) {
data(source)
}
addSource(source)
}
fun Style.addDumpAreaFillLayer(){
LogUtils.dTag("MapBoxExtensions","addDumpAreaFillLayer")
val fillLayer = fillLayer(
MainViewModel.DUMP_AREA_LAYER,
MainViewModel.DUMP_AREA_SOURCE
){
fillColor("#886e26")
fillOpacity(0.85)
fillAntialias(false)
visibility(Visibility.VISIBLE)
}
addLayer(fillLayer)
}
fun Style.addDumpAreaSymbolLayer(){
LogUtils.dTag("MapBoxExtensions","addDumpAreaSymbolLayer")
val symbolLayer = 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)
textMaxWidth(10.0)
visibility(Visibility.VISIBLE)
}
addLayer(symbolLayer)
}
/**
* barricade:挡墙
* */
fun Style.addBarricadeSource(source: String){
LogUtils.dTag("MapBoxExtensions","addBarricadeSource")
val source = geoJsonSource(MainViewModel.BARRICADE_SOURCE) {
data(source)
}
addSource(source)
}
fun Style.addBarricadeLineLayer():LineLayer{
LogUtils.dTag("MapBoxLayout","addLaneLayer")
return lineLayer(
fun Style.addBarricadeLineLayer(){
LogUtils.dTag("MapBoxExtensions","addLaneLayer")
val lineLayer = lineLayer(
MainViewModel.BARRICADE_LAYER,
MainViewModel.BARRICADE_SOURCE
){
......@@ -224,18 +281,21 @@ fun Style.addBarricadeLineLayer():LineLayer{
lineCap(LineCap.ROUND)
visibility(Visibility.VISIBLE)
}
addLayer(lineLayer)
}
fun Style.addObstaclesSource(source: String):GeoJsonSource{
LogUtils.dTag("MapBoxLayout","addObstaclesSource")
return geoJsonSource(MainViewModel.OBSTACLES_SOURCE) {
/**
* obstacles:障碍物
* */
fun Style.addObstaclesSource(source: String){
LogUtils.dTag("MapBoxExtensions","addObstaclesSource")
val source = geoJsonSource(MainViewModel.OBSTACLES_SOURCE) {
url(source)
}
addSource(source)
}
fun Style.addObstaclesFillLayer():FillLayer{
LogUtils.dTag("MapBoxLayout","addObstaclesFillLayer")
return fillLayer(
fun Style.addObstaclesFillLayer(){
LogUtils.dTag("MapBoxExtensions","addObstaclesFillLayer")
val fillLayer = fillLayer(
MainViewModel.OBSTACLES_LAYER,
MainViewModel.OBSTACLES_SOURCE
){
......@@ -243,10 +303,11 @@ fun Style.addObstaclesFillLayer():FillLayer{
fillOpacity(0.8)
visibility(Visibility.VISIBLE)
}
addLayer(fillLayer)
}
fun Style.addObstaclesSymbolLayer():SymbolLayer{
LogUtils.dTag("MapBoxLayout","addObstaclesSymbolLayer")
return symbolLayer(MainViewModel.DIGGING_WORK_AREA_TEXT_LAYER, MainViewModel.DIGGING_WORK_AREA_SOURCE){
fun Style.addObstaclesSymbolLayer(){
LogUtils.dTag("MapBoxExtensions","addObstaclesSymbolLayer")
val symbolLayer = symbolLayer(MainViewModel.OBSTACLES_TEXT_LAYER, MainViewModel.OBSTACLES_SOURCE){
textColor(Color.BLACK)
textField(get("name"))
textFont(listOf("DIN Offc Pro Italic", "Arial Unicode MS Regular"))
......@@ -256,19 +317,24 @@ fun Style.addObstaclesSymbolLayer():SymbolLayer{
textRotationAlignment(TextRotationAlignment.MAP)
textAnchor(TextAnchor.TOP)
textSize(16.0)
textMaxAngle(10.0)
textMaxWidth(10.0)
visibility(Visibility.VISIBLE)
}
addLayer(symbolLayer)
}
fun Style.addStationAreaSource(source: String):GeoJsonSource{
LogUtils.dTag("MapBoxLayout","addStationAreaSource")
return geoJsonSource(MainViewModel.STATION_AREA_SOURCE) {
/**
* stationarea:静态物体
* */
fun Style.addStationAreaSource(source: String){
LogUtils.dTag("MapBoxExtensions","addStationAreaSource")
val source = geoJsonSource(MainViewModel.STATION_AREA_SOURCE) {
data(source)
}
addSource(source)
}
fun Style.addStationAreaFillLayer():FillLayer{
LogUtils.dTag("MapBoxLayout","addStationAreaFillLayer")
return fillLayer(
fun Style.addStationAreaFillLayer(){
LogUtils.dTag("MapBoxExtensions","addStationAreaFillLayer")
val fillLayer = fillLayer(
MainViewModel.STATION_AREA_LAYER,
MainViewModel.STATION_AREA_SOURCE
){
......@@ -276,11 +342,11 @@ fun Style.addStationAreaFillLayer():FillLayer{
fillOpacity(0.8)
visibility(Visibility.VISIBLE)
}
addLayer(fillLayer)
}
fun Style.addStationAreaSymbolLayer():SymbolLayer{
LogUtils.dTag("MapBoxLayout","addStationAreaSymbolLayer")
return symbolLayer(MainViewModel.STATION_AREA_TEXT_LAYER, MainViewModel.STATION_AREA_SOURCE){
fun Style.addStationAreaSymbolLayer(){
LogUtils.dTag("MapBoxExtensions","addStationAreaSymbolLayer")
val symbolLayer = 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"))
......@@ -292,18 +358,21 @@ fun Style.addStationAreaSymbolLayer():SymbolLayer{
textSize(16.0)
textMaxWidth(10.0)
}
addLayer(symbolLayer)
}
fun Style.addLaneNodeSource(source: String):GeoJsonSource{
LogUtils.dTag("MapBoxLayout","addLaneNodeSource")
return geoJsonSource(MainViewModel.LANE_NODE_SOURCE) {
/**
* lanenode:道路节点
* */
fun Style.addLaneNodeSource(source: String){
LogUtils.dTag("MapBoxExtensions","addLaneNodeSource")
val source = geoJsonSource(MainViewModel.LANE_NODE_SOURCE) {
data(source)
}
addSource(source)
}
fun Style.addLaneNodeCircleLayer():CircleLayer{
LogUtils.dTag("MapBoxLayout","addLaneNodeCircleLayer")
return circleLayer(
fun Style.addLaneNodeCircleLayer(){
LogUtils.dTag("MapBoxExtensions","addLaneNodeCircleLayer")
val circleLayer = circleLayer(
MainViewModel.LANE_NODE_LAYER,
MainViewModel.LANE_NODE_SOURCE
){
......@@ -311,11 +380,11 @@ fun Style.addLaneNodeCircleLayer():CircleLayer{
circleRadius(6.0)
visibility(Visibility.VISIBLE)
}
addLayer(circleLayer)
}
fun Style.addLaneNodeSymbolLayer():SymbolLayer{
LogUtils.dTag("MapBoxLayout","addLaneNodeSymbolLayer")
return symbolLayer(MainViewModel.STATION_AREA_TEXT_LAYER, MainViewModel.STATION_AREA_SOURCE){
fun Style.addLaneNodeSymbolLayer(){
LogUtils.dTag("MapBoxExtensions","addLaneNodeSymbolLayer")
val symbolLayer = symbolLayer(MainViewModel.LANE_NODE_TEXT_LAYER, MainViewModel.LANE_NODE_SOURCE){
textColor(Color.BLACK)
textField(get("name"))
textFont(listOf("DIN Offc Pro Italic", "Arial Unicode MS Regular"))
......@@ -324,32 +393,37 @@ fun Style.addLaneNodeSymbolLayer():SymbolLayer{
textOffset(listOf(0.5,-0.5))
textRotationAlignment(TextRotationAlignment.MAP)
textAnchor(TextAnchor.TOP)
textSize(16.0)
textSize(9.0)
textMaxWidth(10.0)
}
addLayer(symbolLayer)
}
fun Style.addParkSpotSource(source: String):GeoJsonSource{
LogUtils.dTag("MapBoxLayout","addParkSpotSource")
return geoJsonSource(MainViewModel.PARK_SPOT_SOURCE) {
/**
* parkspot:停车区
* */
fun Style.addParkSpotSource(source: String){
LogUtils.dTag("MapBoxExtensions","addParkSpotSource")
val source = geoJsonSource(MainViewModel.PARK_SPOT_SOURCE) {
data(source)
}
addSource(source)
}
fun Style.addParkSpotFillLayer():FillLayer{
LogUtils.dTag("MapBoxLayout","addParkSpotFillLayer")
return fillLayer(
fun Style.addParkSpotFillLayer(){
LogUtils.dTag("MapBoxExtensions","addParkSpotFillLayer")
val fillLayer = fillLayer(
MainViewModel.PARK_SPOT_LAYER,
MainViewModel.PARK_SPOT_SOURCE
){
fillColor(get("#7e8185"))
fillOpacity(0.8)
fillAntialias(false)
visibility(Visibility.VISIBLE)
}
addLayer(fillLayer)
}
fun Style.addParkSpotSymbolLayer():SymbolLayer{
LogUtils.dTag("MapBoxLayout","addParkSpotSymbolLayer")
return symbolLayer(MainViewModel.PARK_SPOT_TEXT_LAYER, MainViewModel.PARK_SPOT_SOURCE){
fun Style.addParkSpotSymbolLayer(){
LogUtils.dTag("MapBoxExtensions","addParkSpotSymbolLayer")
val symbolLayer = 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"))
......@@ -358,21 +432,25 @@ fun Style.addParkSpotSymbolLayer():SymbolLayer{
textOffset(listOf(0.5,-0.5))
textRotationAlignment(TextRotationAlignment.MAP)
textAnchor(TextAnchor.TOP)
textSize(9.0)
textMaxAngle(10.0)
textSize(16.0)
textMaxWidth(10.0)
visibility(Visibility.VISIBLE)
}
addLayer(symbolLayer)
}
fun Style.addElectronicFenceSource(source: String):GeoJsonSource{
LogUtils.dTag("MapBoxLayout","addElectronicFenceSource")
return geoJsonSource(MainViewModel.ELECTRONIC_FENCE_SOURCE) {
/**
* 电子围栏
* */
fun Style.addElectronicFenceSource(source: String){
LogUtils.dTag("MapBoxExtensions","addElectronicFenceSource")
val source = geoJsonSource(MainViewModel.ELECTRONIC_FENCE_SOURCE) {
data(source)
}
addSource(source)
}
fun Style.addElectronicFenceFillLayer():FillLayer{
LogUtils.dTag("MapBoxLayout","addElectronicFenceFillLayer")
return fillLayer(
fun Style.addElectronicFenceFillLayer(){
LogUtils.dTag("MapBoxExtensions","addElectronicFenceFillLayer")
val fillLayer = fillLayer(
MainViewModel.ELECTRONIC_FENCE_LAYER,
MainViewModel.ELECTRONIC_FENCE_SOURCE
){
......@@ -381,11 +459,12 @@ fun Style.addElectronicFenceFillLayer():FillLayer{
fillAntialias(false)
visibility(Visibility.VISIBLE)
}
addLayer(fillLayer)
}
fun Style.addElectronicFenceSymbolLayer():SymbolLayer{
LogUtils.dTag("MapBoxLayout","addElectronicFenceSymbolLayer")
return symbolLayer(MainViewModel.ELECTRONIC_FENCE_TEXT_LAYER, MainViewModel.ELECTRONIC_FENCE_SOURCE){
fun Style.addElectronicFenceSymbolLayer(){
LogUtils.dTag("MapBoxExtensions","addElectronicFenceSymbolLayer")
val symbolLayer = 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"))
......@@ -395,20 +474,22 @@ fun Style.addElectronicFenceSymbolLayer():SymbolLayer{
textRotationAlignment(TextRotationAlignment.MAP)
textAnchor(TextAnchor.TOP)
textSize(16.0)
textMaxAngle(10.0)
textMaxWidth(10.0)
visibility(Visibility.VISIBLE)
}
addLayer(symbolLayer)
}
fun Style.addWetAreaSource(source: String):GeoJsonSource{
LogUtils.dTag("MapBoxLayout","addWetAreaSource")
return geoJsonSource(MainViewModel.WET_AREA_SOURCE) {
fun Style.addWetAreaSource(source: String){
LogUtils.dTag("MapBoxExtensions","addWetAreaSource")
val source = geoJsonSource(MainViewModel.WET_AREA_SOURCE) {
data(source)
}
addSource(source)
}
fun Style.addWetAreaFillLayer():FillLayer{
LogUtils.dTag("MapBoxLayout","addWetAreaFillLayer")
return fillLayer(
fun Style.addWetAreaFillLayer(){
LogUtils.dTag("MapBoxExtensions","addWetAreaFillLayer")
val fillLayer = fillLayer(
MainViewModel.WET_AREA_LAYER,
MainViewModel.WET_AREA_SOURCE
){
......@@ -417,47 +498,12 @@ fun Style.addWetAreaFillLayer():FillLayer{
fillAntialias(false)
visibility(Visibility.VISIBLE)
}
addLayer(fillLayer)
}
fun Style.addWetAreaSymbolLayer():SymbolLayer{
LogUtils.dTag("MapBoxLayout","addWetAreaSymbolLayer")
return 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):GeoJsonSource{
LogUtils.dTag("MapBoxLayout","addDumpAreaSource")
return geoJsonSource(MainViewModel.DUMP_AREA_SOURCE) {
data(source)
}
}
fun Style.addDumpAreaFillLayer():FillLayer{
LogUtils.dTag("MapBoxLayout","addDumpAreaFillLayer")
return fillLayer(
MainViewModel.DUMP_AREA_LAYER,
MainViewModel.DUMP_AREA_SOURCE
){
fillColor("#886e26")
fillOpacity(0.85)
fillAntialias(false)
visibility(Visibility.VISIBLE)
}
}
fun Style.addDumpAreaSymbolLayer():SymbolLayer{
LogUtils.dTag("MapBoxLayout","addDumpAreaSymbolLayer")
return symbolLayer(MainViewModel.DUMP_AREA_TEXT_LAYER, MainViewModel.DUMP_AREA_SOURCE){
fun Style.addWetAreaSymbolLayer(){
LogUtils.dTag("MapBoxExtensions","addWetAreaSymbolLayer")
val symbolLayer = 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"))
......@@ -467,20 +513,21 @@ fun Style.addDumpAreaSymbolLayer():SymbolLayer{
textRotationAlignment(TextRotationAlignment.MAP)
textAnchor(TextAnchor.TOP)
textSize(16.0)
textMaxAngle(10.0)
textMaxWidth(10.0)
visibility(Visibility.VISIBLE)
}
addLayer(symbolLayer)
}
fun Style.addTruckPathSource():GeoJsonSource{
LogUtils.dTag("MapBoxLayout","addTruckPathSource")
return geoJsonSource("truckPathSource") {
fun Style.addTruckPathSource(){
LogUtils.dTag("MapBoxExtensions","addTruckPathSource")
val source = geoJsonSource("truckPathSource") {
data("{ \"type\": \"FeatureCollection\", \"features\":[]}")
}
addSource(source)
}
fun Style.addTruckPathLineLayer():LineLayer{
LogUtils.dTag("MapBoxLayout","addTruckPathSource")
return lineLayer(
fun Style.addTruckPathLineLayer(){
LogUtils.dTag("MapBoxExtensions","addTruckPathLineLayer")
val lineLayer = lineLayer(
"truckPathLayer",
"truckPathSource"
){
......@@ -491,6 +538,7 @@ fun Style.addTruckPathLineLayer():LineLayer{
lineCap(LineCap.ROUND)
visibility(Visibility.VISIBLE)
}
addLayer(lineLayer)
}
fun AppCompatActivity.checkSelfPermissionCompat(permission: String) =
......
......@@ -282,9 +282,8 @@
app:layout_constraintTop_toTopOf="@id/defaultToggleMore"
app:layout_constraintEnd_toEndOf="@id/defaultMapLayout" />
<include
<FrameLayout
android:id="@+id/defaultMapLayout"
layout="@layout/layout_map_box"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginEnd="16dp"
......
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