Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
H
HTAnticollision
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
马乐
HTAnticollision
Commits
7552d1f8
Commit
7552d1f8
authored
May 25, 2023
by
马乐
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1.地图异步加载
parent
baa0be8d
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
445 additions
and
574 deletions
+445
-574
MainRepository.kt
...va/com/waytous/anticollision/repository/MainRepository.kt
+1
-0
BaseFragment.kt
...rc/main/java/com/waytous/anticollision/ui/BaseFragment.kt
+227
-368
MainViewModel.kt
...c/main/java/com/waytous/anticollision/ui/MainViewModel.kt
+4
-1
HomeFragment.kt
...in/java/com/waytous/anticollision/ui/home/HomeFragment.kt
+4
-43
Extensions.kt
...c/main/java/com/waytous/anticollision/utils/Extensions.kt
+208
-160
fragment_home.xml
app/src/main/res/layout/fragment_home.xml
+1
-2
No files found.
app/src/main/java/com/waytous/anticollision/repository/MainRepository.kt
View file @
7552d1f8
package
com.waytous.anticollision.repository
package
com.waytous.anticollision.repository
import
android.content.Context
import
android.content.Context
import
androidx.annotation.RequiresPermission
import
androidx.room.Room
import
androidx.room.Room
import
com.blankj.utilcode.util.LogUtils
import
com.blankj.utilcode.util.LogUtils
import
com.waytous.anticollision.api.MapSourceService
import
com.waytous.anticollision.api.MapSourceService
...
...
app/src/main/java/com/waytous/anticollision/ui/BaseFragment.kt
View file @
7552d1f8
package
com.waytous.anticollision.ui
package
com.waytous.anticollision.ui
import
android.graphics.Color
import
android.os.Bundle
import
android.os.Bundle
import
android.view.LayoutInflater
import
android.view.LayoutInflater
import
android.view.View
import
android.view.View
...
@@ -8,24 +7,16 @@ import android.view.ViewGroup
...
@@ -8,24 +7,16 @@ import android.view.ViewGroup
import
androidx.asynclayoutinflater.view.AsyncLayoutInflater
import
androidx.asynclayoutinflater.view.AsyncLayoutInflater
import
androidx.fragment.app.Fragment
import
androidx.fragment.app.Fragment
import
androidx.fragment.app.viewModels
import
androidx.fragment.app.viewModels
import
androidx.lifecycle.Lifecycle
import
androidx.lifecycle.lifecycleScope
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.geojson.Point
import
com.mapbox.maps.CameraOptions
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.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.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.extension.style.style
import
com.mapbox.maps.plugin.annotation.AnnotationPlugin
import
com.mapbox.maps.plugin.annotation.AnnotationPlugin
import
com.mapbox.maps.plugin.annotation.annotations
import
com.mapbox.maps.plugin.annotation.annotations
...
@@ -39,36 +30,74 @@ import com.mapbox.maps.plugin.logo.logo
...
@@ -39,36 +30,74 @@ import com.mapbox.maps.plugin.logo.logo
import
com.mapbox.maps.viewannotation.ViewAnnotationManager
import
com.mapbox.maps.viewannotation.ViewAnnotationManager
import
com.mapbox.maps.viewannotation.viewAnnotationOptions
import
com.mapbox.maps.viewannotation.viewAnnotationOptions
import
com.waytous.anticollision.R
import
com.waytous.anticollision.R
import
com.waytous.anticollision.api.ApiService
import
com.waytous.anticollision.databinding.CurrentVehicleViewAnnotationLayoutBinding
import
com.waytous.anticollision.databinding.CurrentVehicleViewAnnotationLayoutBinding
import
com.waytous.anticollision.databinding.LayoutMapBoxBinding
import
com.waytous.anticollision.databinding.LayoutMapBoxBinding
import
com.waytous.anticollision.databinding.OtherVehicleViewAnnotationLayoutBinding
import
com.waytous.anticollision.databinding.OtherVehicleViewAnnotationLayoutBinding
import
com.waytous.anticollision.repository.MainRepository
import
com.waytous.anticollision.repository.MainRepository
import
com.waytous.anticollision.utils.BitmapUtils
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
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.launch
import
kotlinx.coroutines.withContext
import
java.math.BigDecimal
open
class
BaseFragment
:
Fragment
()
{
open
class
BaseFragment
:
Fragment
()
{
private
val
mapModel
:
MainViewModel
by
viewModels
{
private
val
mapModel
:
MainViewModel
by
viewModels
{
MainViewModel
.
MainViewModelFactory
(
MainRepository
(
requireContext
()))
MainViewModel
.
MainViewModelFactory
(
MainRepository
(
requireContext
()))
}
}
val
iconCurrentNormalVehicleBitmap
by
lazy
{
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
{
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
{
private
val
asyncInflater
by
lazy
{
AsyncLayoutInflater
(
requireContext
())
AsyncLayoutInflater
(
requireContext
())
}
}
private
lateinit
var
layoutMapBoxBinding
:
LayoutMapBoxBinding
lateinit
var
layoutMapBoxBinding
:
LayoutMapBoxBinding
lateinit
var
mapboxMap
:
MapboxMap
private
lateinit
var
viewAnnotation
:
View
private
lateinit
var
viewAnnotation
:
View
...
@@ -80,352 +109,175 @@ open class BaseFragment : Fragment() {
...
@@ -80,352 +109,175 @@ open class BaseFragment : Fragment() {
private
lateinit
var
pointAnnotation
:
PointAnnotation
private
lateinit
var
pointAnnotation
:
PointAnnotation
private
val
cameraOptions
:
CameraOptions
by
lazy
{
private
val
cameraOptions
:
CameraOptions
by
lazy
{
CameraOptions
.
Builder
().
center
(
CameraOptions
.
Builder
().
center
(
Point
.
fromLngLat
(
Point
.
fromLngLat
(
MainViewModel
.
LONGITUDE
,
MainViewModel
.
LONGITUDE
,
MainViewModel
.
LATITUDE
MainViewModel
.
LATITUDE
)).
zoom
(
14.0
).
build
()
)
).
zoom
(
14.0
).
build
()
}
}
companion
object
{
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
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
MINIMUM_ZOOM_LEVEL
=
11.0
const
val
MAXIMUM_ZOOM_LEVEL
=
26.0
const
val
MAXIMUM_ZOOM_LEVEL
=
26.0
const
val
DEFAULT_ZOOM_LEVEL
=
14.0
const
val
DEFAULT_ZOOM_LEVEL
=
14.0
}
}
override
fun
onCreateView
(
override
fun
onCreate
(
savedInstanceState
:
Bundle
?)
{
inflater
:
LayoutInflater
,
super
.
onCreate
(
savedInstanceState
)
container
:
ViewGroup
?,
savedInstanceState
:
Bundle
?
):
View
?
{
layoutMapBoxBinding
=
LayoutMapBoxBinding
.
inflate
(
LayoutInflater
.
from
(
requireContext
()))
layoutMapBoxBinding
=
LayoutMapBoxBinding
.
inflate
(
LayoutInflater
.
from
(
requireContext
()))
}
fun
setupMapBox
()
{
layoutMapBoxBinding
.
mapView
.
run
{
layoutMapBoxBinding
.
mapView
.
run
{
logo
.
enabled
=
false
logo
.
enabled
=
false
compass
.
enabled
=
false
compass
.
enabled
=
false
attribution
.
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
){
else
->
{
annotationPlugin
=
mapView
.
annotations
mapboxMap
.
setCamera
(
CameraOptions
.
Builder
().
zoom
(
DEFAULT_ZOOM_LEVEL
).
build
())
viewAnnotationManager
=
mapView
.
viewAnnotationManager
}
pointAnnotationManager
=
annotationPlugin
.
createPointAnnotationManager
()
}
}
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
){
private
fun
setupStyle
(
style
:
Style
)
{
mapView
.
getMapboxMap
().
setCamera
(
lifecycleScope
.
launch
{
cameraOptions
viewLifecycleOwner
.
repeatOnLifecycle
(
Lifecycle
.
State
.
STARTED
)
{
)
mapModel
.
runnableAreaSource
().
last
()
?.
let
{
source
->
lifecycleScope
.
launch
{
style
.
addRunnableAreaSource
(
source
)
withContext
(
Dispatchers
.
IO
){
style
.
addRunnableAreaLayer
()
val
apiService
=
ApiService
.
create
()
}
val
runnableAreaSource
=
apiService
.
runnableAreaVersion
(
"-1"
)
mapModel
.
laneSource
().
last
()
?.
let
{
source
->
val
laneSource
=
apiService
.
laneVersion
(
"-1"
)
style
.
addLaneSource
(
source
)
val
laneNodeSource
=
apiService
.
laneNodeVersion
(
"-1"
)
style
.
addLaneLayer
()
val
diggingWorkAreaSource
=
apiService
.
diggingWorkAreaVersion
(
"-1"
)
}
val
obstaclesSource
=
apiService
.
obstaclesVersion
(
"-1"
)
mapModel
.
laneNodeSource
().
last
()
?.
let
{
source
->
val
electronicFenceSource
=
apiService
.
electronicFenceVersion
(
"-1"
)
style
.
addLaneNodeSource
(
source
)
val
dumpAreaSource
=
apiService
.
dumpAreaVersion
(
"-1"
)
style
.
addLaneNodeCircleLayer
()
val
staticObjectsSource
=
apiService
.
staticObjectsVersion
(
"-1"
)
style
.
addLaneNodeSymbolLayer
()
val
stationAreaSource
=
apiService
.
stationAreaVersion
(
"-1"
)
}
val
barricadeSource
=
apiService
.
barricadeVersion
(
"-1"
)
mapModel
.
diggingWorkAreaSource
().
last
()
?.
let
{
source
->
val
parkSpotSource
=
apiService
.
parkSpotVersion
(
"-1"
)
style
.
addDiggingWorkAreaSource
(
source
)
val
wetAreaSource
=
apiService
.
wetAreaVersion
(
"-1"
)
style
.
addDiggingWorkAreaFillLayer
()
withStarted
{
style
.
addDiggingWorkAreaSymbolLayer
()
mapView
.
getMapboxMap
().
loadStyle
(
}
style
(
styleUri
=
MainViewModel
.
MY_MAP_BOX_STYLE
)
{
mapModel
.
obstaclesSource
().
last
()
?.
let
{
source
->
+
geoJsonSource
(
MainViewModel
.
RUNNABLE_AREA_SOURCE
)
{
style
.
addObstaclesSource
(
source
)
data
(
runnableAreaSource
!!
.
geojson
)
style
.
addObstaclesFillLayer
()
+
fillLayer
(
style
.
addObstaclesSymbolLayer
()
MainViewModel
.
RUNNABLE_AREA_LAYER
,
}
MainViewModel
.
RUNNABLE_AREA_SOURCE
mapModel
.
electronicFenceSource
().
last
()
?.
let
{
source
->
){
style
.
addElectronicFenceSource
(
source
)
fillColor
(
"#98a0a0"
)
style
.
addElectronicFenceFillLayer
()
fillOpacity
(
0.85
)
style
.
addElectronicFenceSymbolLayer
()
fillOutlineColor
(
"#FFFF00"
)
}
visibility
(
Visibility
.
VISIBLE
)
mapModel
.
wetAreaSource
().
last
()
?.
let
{
source
->
}
style
.
addWetAreaSource
(
source
)
}
style
.
addWetAreaFillLayer
()
+
geoJsonSource
(
MainViewModel
.
LANE_SOURCE
)
{
style
.
addWetAreaSymbolLayer
()
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
)
}
}
}
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
()
val
pointAnnotationOptions
:
PointAnnotationOptions
=
PointAnnotationOptions
()
.
withPoint
(
otherAnnotation
.
point
)
.
withPoint
(
otherAnnotation
.
point
)
.
withIconImage
(
iconCurrentNormalVehicleBitmap
!!
)
.
withIconImage
(
iconCurrentNormalVehicleBitmap
!!
)
...
@@ -433,43 +285,49 @@ open class BaseFragment : Fragment() {
...
@@ -433,43 +285,49 @@ open class BaseFragment : Fragment() {
.
withIconAnchor
(
IconAnchor
.
BOTTOM
)
.
withIconAnchor
(
IconAnchor
.
BOTTOM
)
.
withDraggable
(
false
)
.
withDraggable
(
false
)
val
pointAnnotation
=
pointAnnotationManager
.
create
(
pointAnnotationOptions
)
val
pointAnnotation
=
pointAnnotationManager
.
create
(
pointAnnotationOptions
)
pointAnnotation
.
symbolSortKey
=
Double
.
MAX_VALUE
val
viewAnnotation
=
viewAnnotationManager
.
addViewAnnotation
(
val
viewAnnotation
=
viewAnnotationManager
.
addViewAnnotation
(
resId
=
R
.
layout
.
current_vehicle_view_annotation_layout
,
resId
=
R
.
layout
.
current_vehicle_view_annotation_layout
,
options
=
viewAnnotationOptions
{
options
=
viewAnnotationOptions
{
geometry
(
otherAnnotation
.
point
)
geometry
(
otherAnnotation
.
point
)
associatedFeatureId
(
pointAnnotation
.
featureIdentifier
)
associatedFeatureId
(
pointAnnotation
.
featureIdentifier
)
anchor
(
ViewAnnotationAnchor
.
BOTTOM
)
anchor
(
ViewAnnotationAnchor
.
BOTTOM
)
offsetY
((
pointAnnotation
.
iconImageBitmap
?.
height
!!
*
0.25
).
toInt
())
offsetY
((
pointAnnotation
.
iconImageBitmap
?.
height
!!
*
0.25
).
toInt
())
allowOverlap
(
true
)
allowOverlap
(
true
)
}
}
)
)
val
binding
=
CurrentVehicleViewAnnotationLayoutBinding
.
bind
(
viewAnnotation
)
val
binding
=
CurrentVehicleViewAnnotationLayoutBinding
.
bind
(
viewAnnotation
)
binding
.
annotationCurrentVehicleNo
.
text
=
context
?.
getString
(
R
.
string
.
annotation_vehicle_no
,
"KK-001"
)
binding
.
annotationCurrentVehicleNo
.
text
=
binding
.
annotationCurrentVehicleSpeed
.
text
=
context
?.
getString
(
R
.
string
.
annotation_vehicle_speed
,
36
)
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
->
fun
addOtherVehicleAnnotations
(
others
:
List
<
VehicleAnnotation
>)
{
val
pointAnnotationOptions
:
PointAnnotationOptions
=
PointAnnotationOptions
()
others
.
forEach
{
vehicle
->
.
withPoint
(
vehicle
.
point
)
val
pointAnnotationOptions
:
PointAnnotationOptions
=
PointAnnotationOptions
()
.
withIconImage
(
iconOtherAlarmVehicleBitmap
!!
)
.
withPoint
(
vehicle
.
point
)
.
withIconSize
(
0.25
)
.
withIconImage
(
iconOtherAlarmVehicleBitmap
!!
)
.
withIconAnchor
(
IconAnchor
.
BOTTOM
)
.
withIconSize
(
0.25
)
.
withDraggable
(
false
)
.
withIconAnchor
(
IconAnchor
.
BOTTOM
)
val
pointAnnotation
=
pointAnnotationManager
.
create
(
pointAnnotationOptions
)
.
withDraggable
(
false
)
val
viewAnnotation
=
viewAnnotationManager
.
addViewAnnotation
(
val
pointAnnotation
=
pointAnnotationManager
.
create
(
pointAnnotationOptions
)
resId
=
R
.
layout
.
other_vehicle_view_annotation_layout
,
pointAnnotation
.
symbolSortKey
=
Double
.
MAX_VALUE
options
=
viewAnnotationOptions
{
val
viewAnnotation
=
viewAnnotationManager
.
addViewAnnotation
(
geometry
(
vehicle
.
point
)
resId
=
R
.
layout
.
other_vehicle_view_annotation_layout
,
options
=
viewAnnotationOptions
{
geometry
(
vehicle
.
point
)
// associatedFeatureId(pointAnnotation.featureIdentifier)
// associatedFeatureId(pointAnnotation.featureIdentifier)
anchor
(
ViewAnnotationAnchor
.
BOTTOM
)
anchor
(
ViewAnnotationAnchor
.
BOTTOM
)
offsetY
((
pointAnnotation
.
iconImageBitmap
?.
height
!!
*
0.25
).
toInt
())
offsetY
((
pointAnnotation
.
iconImageBitmap
?.
height
!!
*
0.25
).
toInt
())
allowOverlap
(
true
)
allowOverlap
(
true
)
}
}
)
)
val
binding
=
OtherVehicleViewAnnotationLayoutBinding
.
bind
(
viewAnnotation
)
val
binding
=
OtherVehicleViewAnnotationLayoutBinding
.
bind
(
viewAnnotation
)
binding
.
annotationOtherVehicleNo
.
text
=
context
?.
getString
(
R
.
string
.
annotation_vehicle_no
,
vehicle
.
vehicleNo
)
binding
.
annotationOtherVehicleNo
.
text
=
binding
.
annotationOtherVehicleSpeed
.
text
=
vehicle
.
speed
.
toString
()
context
?.
getString
(
R
.
string
.
annotation_vehicle_no
,
vehicle
.
vehicleNo
)
binding
.
annotationOtherVehicleDistance
.
text
=
vehicle
.
distance
.
toString
()
binding
.
annotationOtherVehicleSpeed
.
text
=
vehicle
.
speed
.
toString
()
binding
.
annotationOtherVehicleDistance
.
text
=
vehicle
.
distance
.
toString
()
}
}
}
}
}
}
\ No newline at end of file
app/src/main/java/com/waytous/anticollision/ui/MainViewModel.kt
View file @
7552d1f8
...
@@ -95,7 +95,10 @@ class MainViewModel @Inject constructor(private val mainRepository: MainReposito
...
@@ -95,7 +95,10 @@ class MainViewModel @Inject constructor(private val mainRepository: MainReposito
fun
runnableAreaSource
()
=
flowOf
(
fun
runnableAreaSource
()
=
flowOf
(
mainRepository
.
localRunnableAreaVersion
(),
mainRepository
.
localRunnableAreaVersion
(),
mainRepository
.
remoteRunnableAreaVersion
()
mainRepository
.
remoteRunnableAreaVersion
()
).
flattenMerge
()
).
onStart
{
LogUtils
.
dTag
(
"MainViewModel"
,
"runnableAreaSource start"
)
}
.
flattenMerge
()
.
transformWhile
{
.
transformWhile
{
emit
(
it
.
mapDataSource
)
emit
(
it
.
mapDataSource
)
!
it
.
abort
!
it
.
abort
...
...
app/src/main/java/com/waytous/anticollision/ui/home/HomeFragment.kt
View file @
7552d1f8
...
@@ -6,19 +6,10 @@ import android.view.Gravity
...
@@ -6,19 +6,10 @@ import android.view.Gravity
import
android.view.LayoutInflater
import
android.view.LayoutInflater
import
android.view.View
import
android.view.View
import
android.view.ViewGroup
import
android.view.ViewGroup
import
androidx.databinding.adapters.ZoomControlsBindingAdapter
import
androidx.fragment.app.viewModels
import
androidx.fragment.app.viewModels
import
androidx.lifecycle.ViewModelProvider
import
androidx.lifecycle.ViewModelProvider
import
com.blankj.utilcode.util.LogUtils
import
com.blankj.utilcode.util.LogUtils
import
com.mapbox.maps.CameraOptions
import
com.mapbox.maps.MapView
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.R
import
com.waytous.anticollision.databinding.FragmentHomeBinding
import
com.waytous.anticollision.databinding.FragmentHomeBinding
import
com.waytous.anticollision.repository.MainRepository
import
com.waytous.anticollision.repository.MainRepository
...
@@ -27,7 +18,6 @@ import com.waytous.anticollision.ui.MainViewModel
...
@@ -27,7 +18,6 @@ import com.waytous.anticollision.ui.MainViewModel
import
com.waytous.anticollision.ui.view.MoreFeaturesPopup
import
com.waytous.anticollision.ui.view.MoreFeaturesPopup
import
com.waytous.anticollision.ui.view.WorkStatusEditPopup
import
com.waytous.anticollision.ui.view.WorkStatusEditPopup
import
com.waytous.anticollision.utils.setTextSize
import
com.waytous.anticollision.utils.setTextSize
import
java.math.BigDecimal
class
HomeFragment
:
BaseFragment
()
{
class
HomeFragment
:
BaseFragment
()
{
...
@@ -69,39 +59,9 @@ class HomeFragment : BaseFragment() {
...
@@ -69,39 +59,9 @@ class HomeFragment : BaseFragment() {
it
.
maskOffsetY
=
20
it
.
maskOffsetY
=
20
it
.
setBackgroundColor
(
R
.
color
.
color_99000000
)
it
.
setBackgroundColor
(
R
.
color
.
color_99000000
)
}
}
mapView
=
binding
.
root
.
findViewById
<
MapView
?>(
R
.
id
.
mapView
).
also
{
it
->
LogUtils
.
d
(
"HomeFragment.onCreateView"
)
it
.
logo
.
enabled
=
false
setupMapBox
()
it
.
compass
.
enabled
=
false
binding
.
defaultMapLayout
.
addView
(
layoutMapBoxBinding
.
root
)
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}"
)
}
setTodayCarriedNum
(
18
)
setTodayCarriedNum
(
18
)
setTodayIllegallyNum
(
1
)
setTodayIllegallyNum
(
1
)
binding
.
workStatusEdit
.
setOnClickListener
{
binding
.
workStatusEdit
.
setOnClickListener
{
...
@@ -127,6 +87,7 @@ class HomeFragment : BaseFragment() {
...
@@ -127,6 +87,7 @@ class HomeFragment : BaseFragment() {
override
fun
onDestroyView
()
{
override
fun
onDestroyView
()
{
super
.
onDestroyView
()
super
.
onDestroyView
()
binding
.
defaultMapLayout
.
removeView
(
layoutMapBoxBinding
.
root
)
_binding
=
null
_binding
=
null
}
}
...
...
app/src/main/java/com/waytous/anticollision/utils/Extensions.kt
View file @
7552d1f8
...
@@ -5,7 +5,6 @@ import android.graphics.Bitmap
...
@@ -5,7 +5,6 @@ import android.graphics.Bitmap
import
android.graphics.Canvas
import
android.graphics.Canvas
import
android.graphics.Color
import
android.graphics.Color
import
android.graphics.drawable.Drawable
import
android.graphics.drawable.Drawable
import
android.os.Build
import
android.text.Spannable
import
android.text.Spannable
import
android.text.SpannableString
import
android.text.SpannableString
import
android.text.style.AbsoluteSizeSpan
import
android.text.style.AbsoluteSizeSpan
...
@@ -13,10 +12,10 @@ import android.widget.TextView
...
@@ -13,10 +12,10 @@ import android.widget.TextView
import
androidx.appcompat.app.AppCompatActivity
import
androidx.appcompat.app.AppCompatActivity
import
androidx.core.app.ActivityCompat
import
androidx.core.app.ActivityCompat
import
androidx.core.content.ContextCompat
import
androidx.core.content.ContextCompat
import
androidx.core.graphics.drawable.DrawableCompat
import
com.blankj.utilcode.util.LogUtils
import
com.blankj.utilcode.util.LogUtils
import
com.mapbox.maps.Style
import
com.mapbox.maps.Style
import
com.mapbox.maps.extension.style.expressions.dsl.generated.get
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.CircleLayer
import
com.mapbox.maps.extension.style.layers.generated.FillLayer
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.LineLayer
...
@@ -90,16 +89,21 @@ fun Context.getBitmapFromVectorDrawable(drawableId:Int,scale:Int = 2): Bitmap? {
...
@@ -90,16 +89,21 @@ fun Context.getBitmapFromVectorDrawable(drawableId:Int,scale:Int = 2): Bitmap? {
return
bitmap
return
bitmap
}
}
fun
Style
.
addRunnableAreaSource
(
source
:
String
):
GeoJsonSource
{
/**
LogUtils
.
dTag
(
"MapBoxLayout"
,
"addRunnableAreaSource"
)
* runablearea:可行驶区域
return
geoJsonSource
(
MainViewModel
.
RUNNABLE_AREA_SOURCE
){
* */
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
)
data
(
source
)
}
}
addSource
(
source
)
}
}
fun
Style
.
addRunnableAreaLayer
()
:
FillLayer
{
fun
Style
.
addRunnableAreaLayer
(){
LogUtils
.
dTag
(
"MapBox
Layout
"
,
"addRunnableAreaLayer"
)
LogUtils
.
dTag
(
"MapBox
Extensions
"
,
"addRunnableAreaLayer"
)
return
fillLayer
(
val
fillLayer
=
fillLayer
(
MainViewModel
.
RUNNABLE_AREA_LAYER
,
MainViewModel
.
RUNNABLE_AREA_LAYER
,
MainViewModel
.
RUNNABLE_AREA_SOURCE
MainViewModel
.
RUNNABLE_AREA_SOURCE
){
){
...
@@ -108,18 +112,21 @@ fun Style.addRunnableAreaLayer():FillLayer{
...
@@ -108,18 +112,21 @@ fun Style.addRunnableAreaLayer():FillLayer{
fillOutlineColor
(
"#FFFF00"
)
fillOutlineColor
(
"#FFFF00"
)
visibility
(
Visibility
.
VISIBLE
)
visibility
(
Visibility
.
VISIBLE
)
}
}
addLayer
(
fillLayer
)
}
}
/**
fun
Style
.
addLaneSource
(
source
:
String
):
GeoJsonSource
{
* lanelayer:整个矿山边界路线
LogUtils
.
dTag
(
"MapBoxLayout"
,
"addLaneSource"
)
* */
return
geoJsonSource
(
MainViewModel
.
RUNNABLE_AREA_SOURCE
){
fun
Style
.
addLaneSource
(
source
:
String
){
LogUtils
.
dTag
(
"MapBoxExtensions"
,
"addLaneSource"
)
val
source
=
geoJsonSource
(
MainViewModel
.
LANE_SOURCE
){
data
(
source
)
data
(
source
)
}
}
addSource
(
source
)
}
}
fun
Style
.
addLaneLayer
(){
fun
Style
.
addLaneLayer
():
LineLayer
{
LogUtils
.
dTag
(
"MapBoxExtensions"
,
"addLaneLayer"
)
LogUtils
.
dTag
(
"MapBoxLayout"
,
"addLaneLayer"
)
val
lineLayer
=
lineLayer
(
return
lineLayer
(
MainViewModel
.
LANE_LAYER
,
MainViewModel
.
LANE_LAYER
,
MainViewModel
.
LANE_SOURCE
MainViewModel
.
LANE_SOURCE
){
){
...
@@ -129,18 +136,21 @@ fun Style.addLaneLayer():LineLayer{
...
@@ -129,18 +136,21 @@ fun Style.addLaneLayer():LineLayer{
lineCap
(
LineCap
.
ROUND
)
lineCap
(
LineCap
.
ROUND
)
visibility
(
Visibility
.
VISIBLE
)
visibility
(
Visibility
.
VISIBLE
)
}
}
addLayer
(
lineLayer
)
}
}
/**
fun
Style
.
addStaticObjectsSource
(
source
:
String
):
GeoJsonSource
{
* staticobjs:静态对象区域
LogUtils
.
dTag
(
"MapBoxLayout"
,
"addStaticObjectsSource"
)
* */
return
geoJsonSource
(
MainViewModel
.
STATIC_OBJECTS_SOURCE
)
{
fun
Style
.
addStaticObjectsSource
(
source
:
String
){
LogUtils
.
dTag
(
"MapBoxExtensions"
,
"addStaticObjectsSource"
)
val
source
=
geoJsonSource
(
MainViewModel
.
STATIC_OBJECTS_SOURCE
)
{
data
(
source
)
data
(
source
)
}
}
addSource
(
source
)
}
}
fun
Style
.
addStaticObjectsFillLayer
(){
fun
Style
.
addStaticObjectsFillLayer
():
FillLayer
{
LogUtils
.
dTag
(
"MapBoxExtensions"
,
"addStaticObjectsFillLayer"
)
LogUtils
.
dTag
(
"MapBoxLayout"
,
"addStaticObjectsFillLayer"
)
val
fillLayer
=
fillLayer
(
return
fillLayer
(
MainViewModel
.
STATIC_OBJECTS_LAYER
,
MainViewModel
.
STATIC_OBJECTS_LAYER
,
MainViewModel
.
STATIC_OBJECTS_SOURCE
MainViewModel
.
STATIC_OBJECTS_SOURCE
){
){
...
@@ -149,11 +159,11 @@ fun Style.addStaticObjectsFillLayer():FillLayer{
...
@@ -149,11 +159,11 @@ fun Style.addStaticObjectsFillLayer():FillLayer{
fillAntialias
(
false
)
fillAntialias
(
false
)
visibility
(
Visibility
.
VISIBLE
)
visibility
(
Visibility
.
VISIBLE
)
}
}
addLayer
(
fillLayer
)
}
}
fun
Style
.
addStaticObjectsSymbolLayer
(){
fun
Style
.
addStaticObjectsSymbolLayer
():
SymbolLayer
{
LogUtils
.
dTag
(
"MapBoxExtensions"
,
"addStaticObjectsSymbolLayer"
)
LogUtils
.
dTag
(
"MapBoxLayout"
,
"addStaticObjectsSymbolLayer"
)
val
symbolLayer
=
symbolLayer
(
MainViewModel
.
STATIC_OBJECTS_TEXT_LAYER
,
MainViewModel
.
STATIC_OBJECTS_SOURCE
){
return
symbolLayer
(
MainViewModel
.
STATIC_OBJECTS_TEXT_LAYER
,
MainViewModel
.
STATIC_OBJECTS_SOURCE
){
textColor
(
Color
.
BLACK
)
textColor
(
Color
.
BLACK
)
textField
(
get
(
"name"
))
textField
(
get
(
"name"
))
textFont
(
listOf
(
"DIN Offc Pro Italic"
,
"Arial Unicode MS Regular"
))
textFont
(
listOf
(
"DIN Offc Pro Italic"
,
"Arial Unicode MS Regular"
))
...
@@ -163,21 +173,24 @@ fun Style.addStaticObjectsSymbolLayer():SymbolLayer{
...
@@ -163,21 +173,24 @@ fun Style.addStaticObjectsSymbolLayer():SymbolLayer{
textRotationAlignment
(
TextRotationAlignment
.
MAP
)
textRotationAlignment
(
TextRotationAlignment
.
MAP
)
textAnchor
(
TextAnchor
.
TOP
)
textAnchor
(
TextAnchor
.
TOP
)
textSize
(
16.0
)
textSize
(
16.0
)
textMax
Angle
(
10.0
)
textMax
Width
(
10.0
)
visibility
(
Visibility
.
VISIBLE
)
visibility
(
Visibility
.
VISIBLE
)
}
}
addLayer
(
symbolLayer
)
}
}
/**
fun
Style
.
addDiggingWorkAreaSource
(
source
:
String
):
GeoJsonSource
{
* diggingarea:挖掘区域
LogUtils
.
dTag
(
"MapBoxLayout"
,
"addDiggingWorkAreaSource"
)
* */
return
geoJsonSource
(
MainViewModel
.
DIGGING_WORK_AREA_SOURCE
)
{
fun
Style
.
addDiggingWorkAreaSource
(
source
:
String
){
LogUtils
.
dTag
(
"MapBoxExtensions"
,
"addDiggingWorkAreaSource"
)
val
source
=
geoJsonSource
(
MainViewModel
.
DIGGING_WORK_AREA_SOURCE
)
{
data
(
source
)
data
(
source
)
}
}
addSource
(
source
)
}
}
fun
Style
.
addDiggingWorkAreaFillLayer
(){
fun
Style
.
addDiggingWorkAreaFillLayer
():
FillLayer
{
LogUtils
.
dTag
(
"MapBoxExtensions"
,
"addStaticObjectsFillLayer"
)
LogUtils
.
dTag
(
"MapBoxLayout"
,
"addStaticObjectsFillLayer"
)
val
fillLayer
=
fillLayer
(
return
fillLayer
(
MainViewModel
.
DIGGING_WORK_AREA_LAYER
,
MainViewModel
.
DIGGING_WORK_AREA_LAYER
,
MainViewModel
.
DIGGING_WORK_AREA_SOURCE
MainViewModel
.
DIGGING_WORK_AREA_SOURCE
){
){
...
@@ -186,11 +199,11 @@ fun Style.addDiggingWorkAreaFillLayer():FillLayer{
...
@@ -186,11 +199,11 @@ fun Style.addDiggingWorkAreaFillLayer():FillLayer{
fillAntialias
(
false
)
fillAntialias
(
false
)
visibility
(
Visibility
.
VISIBLE
)
visibility
(
Visibility
.
VISIBLE
)
}
}
addLayer
(
fillLayer
)
}
}
fun
Style
.
addDiggingWorkAreaSymbolLayer
(){
fun
Style
.
addDiggingWorkAreaSymbolLayer
():
SymbolLayer
{
LogUtils
.
dTag
(
"MapBoxExtensions"
,
"addDiggingWorkAreaSymbolLayer"
)
LogUtils
.
dTag
(
"MapBoxLayout"
,
"addDiggingWorkAreaSymbolLayer"
)
val
symbolLayer
=
symbolLayer
(
MainViewModel
.
DIGGING_WORK_AREA_TEXT_LAYER
,
MainViewModel
.
DIGGING_WORK_AREA_SOURCE
){
return
symbolLayer
(
MainViewModel
.
DIGGING_WORK_AREA_TEXT_LAYER
,
MainViewModel
.
DIGGING_WORK_AREA_SOURCE
){
textColor
(
Color
.
BLACK
)
textColor
(
Color
.
BLACK
)
textField
(
get
(
"name"
))
textField
(
get
(
"name"
))
textFont
(
listOf
(
"DIN Offc Pro Italic"
,
"Arial Unicode MS Regular"
))
textFont
(
listOf
(
"DIN Offc Pro Italic"
,
"Arial Unicode MS Regular"
))
...
@@ -200,21 +213,65 @@ fun Style.addDiggingWorkAreaSymbolLayer():SymbolLayer{
...
@@ -200,21 +213,65 @@ fun Style.addDiggingWorkAreaSymbolLayer():SymbolLayer{
textRotationAlignment
(
TextRotationAlignment
.
MAP
)
textRotationAlignment
(
TextRotationAlignment
.
MAP
)
textAnchor
(
TextAnchor
.
TOP
)
textAnchor
(
TextAnchor
.
TOP
)
textSize
(
16.0
)
textSize
(
16.0
)
textMax
Angle
(
10.0
)
textMax
Width
(
10.0
)
visibility
(
Visibility
.
VISIBLE
)
visibility
(
Visibility
.
VISIBLE
)
}
}
addLayer
(
symbolLayer
)
}
}
/**
fun
Style
.
addBarricadeSource
(
source
:
String
):
GeoJsonSource
{
* dumparea:排土区域
LogUtils
.
dTag
(
"MapBoxLayout"
,
"addBarricadeSource"
)
* */
return
geoJsonSource
(
MainViewModel
.
BARRICADE_SOURCE
)
{
fun
Style
.
addDumpAreaSource
(
source
:
String
){
LogUtils
.
dTag
(
"MapBoxExtensions"
,
"addDumpAreaSource"
)
val
source
=
geoJsonSource
(
MainViewModel
.
DUMP_AREA_SOURCE
)
{
data
(
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
{
fun
Style
.
addBarricadeLineLayer
(){
LogUtils
.
dTag
(
"MapBox
Layout
"
,
"addLaneLayer"
)
LogUtils
.
dTag
(
"MapBox
Extensions
"
,
"addLaneLayer"
)
return
lineLayer
(
val
lineLayer
=
lineLayer
(
MainViewModel
.
BARRICADE_LAYER
,
MainViewModel
.
BARRICADE_LAYER
,
MainViewModel
.
BARRICADE_SOURCE
MainViewModel
.
BARRICADE_SOURCE
){
){
...
@@ -224,18 +281,21 @@ fun Style.addBarricadeLineLayer():LineLayer{
...
@@ -224,18 +281,21 @@ fun Style.addBarricadeLineLayer():LineLayer{
lineCap
(
LineCap
.
ROUND
)
lineCap
(
LineCap
.
ROUND
)
visibility
(
Visibility
.
VISIBLE
)
visibility
(
Visibility
.
VISIBLE
)
}
}
addLayer
(
lineLayer
)
}
}
/**
fun
Style
.
addObstaclesSource
(
source
:
String
):
GeoJsonSource
{
* obstacles:障碍物
LogUtils
.
dTag
(
"MapBoxLayout"
,
"addObstaclesSource"
)
* */
return
geoJsonSource
(
MainViewModel
.
OBSTACLES_SOURCE
)
{
fun
Style
.
addObstaclesSource
(
source
:
String
){
LogUtils
.
dTag
(
"MapBoxExtensions"
,
"addObstaclesSource"
)
val
source
=
geoJsonSource
(
MainViewModel
.
OBSTACLES_SOURCE
)
{
url
(
source
)
url
(
source
)
}
}
addSource
(
source
)
}
}
fun
Style
.
addObstaclesFillLayer
(){
fun
Style
.
addObstaclesFillLayer
():
FillLayer
{
LogUtils
.
dTag
(
"MapBoxExtensions"
,
"addObstaclesFillLayer"
)
LogUtils
.
dTag
(
"MapBoxLayout"
,
"addObstaclesFillLayer"
)
val
fillLayer
=
fillLayer
(
return
fillLayer
(
MainViewModel
.
OBSTACLES_LAYER
,
MainViewModel
.
OBSTACLES_LAYER
,
MainViewModel
.
OBSTACLES_SOURCE
MainViewModel
.
OBSTACLES_SOURCE
){
){
...
@@ -243,10 +303,11 @@ fun Style.addObstaclesFillLayer():FillLayer{
...
@@ -243,10 +303,11 @@ fun Style.addObstaclesFillLayer():FillLayer{
fillOpacity
(
0.8
)
fillOpacity
(
0.8
)
visibility
(
Visibility
.
VISIBLE
)
visibility
(
Visibility
.
VISIBLE
)
}
}
addLayer
(
fillLayer
)
}
}
fun
Style
.
addObstaclesSymbolLayer
()
:
SymbolLayer
{
fun
Style
.
addObstaclesSymbolLayer
(){
LogUtils
.
dTag
(
"MapBox
Layout
"
,
"addObstaclesSymbolLayer"
)
LogUtils
.
dTag
(
"MapBox
Extensions
"
,
"addObstaclesSymbolLayer"
)
return
symbolLayer
(
MainViewModel
.
DIGGING_WORK_AREA_TEXT_LAYER
,
MainViewModel
.
DIGGING_WORK_AREA
_SOURCE
){
val
symbolLayer
=
symbolLayer
(
MainViewModel
.
OBSTACLES_TEXT_LAYER
,
MainViewModel
.
OBSTACLES
_SOURCE
){
textColor
(
Color
.
BLACK
)
textColor
(
Color
.
BLACK
)
textField
(
get
(
"name"
))
textField
(
get
(
"name"
))
textFont
(
listOf
(
"DIN Offc Pro Italic"
,
"Arial Unicode MS Regular"
))
textFont
(
listOf
(
"DIN Offc Pro Italic"
,
"Arial Unicode MS Regular"
))
...
@@ -256,19 +317,24 @@ fun Style.addObstaclesSymbolLayer():SymbolLayer{
...
@@ -256,19 +317,24 @@ fun Style.addObstaclesSymbolLayer():SymbolLayer{
textRotationAlignment
(
TextRotationAlignment
.
MAP
)
textRotationAlignment
(
TextRotationAlignment
.
MAP
)
textAnchor
(
TextAnchor
.
TOP
)
textAnchor
(
TextAnchor
.
TOP
)
textSize
(
16.0
)
textSize
(
16.0
)
textMax
Angle
(
10.0
)
textMax
Width
(
10.0
)
visibility
(
Visibility
.
VISIBLE
)
visibility
(
Visibility
.
VISIBLE
)
}
}
addLayer
(
symbolLayer
)
}
}
fun
Style
.
addStationAreaSource
(
source
:
String
):
GeoJsonSource
{
/**
LogUtils
.
dTag
(
"MapBoxLayout"
,
"addStationAreaSource"
)
* stationarea:静态物体
return
geoJsonSource
(
MainViewModel
.
STATION_AREA_SOURCE
)
{
* */
fun
Style
.
addStationAreaSource
(
source
:
String
){
LogUtils
.
dTag
(
"MapBoxExtensions"
,
"addStationAreaSource"
)
val
source
=
geoJsonSource
(
MainViewModel
.
STATION_AREA_SOURCE
)
{
data
(
source
)
data
(
source
)
}
}
addSource
(
source
)
}
}
fun
Style
.
addStationAreaFillLayer
()
:
FillLayer
{
fun
Style
.
addStationAreaFillLayer
(){
LogUtils
.
dTag
(
"MapBox
Layout
"
,
"addStationAreaFillLayer"
)
LogUtils
.
dTag
(
"MapBox
Extensions
"
,
"addStationAreaFillLayer"
)
return
fillLayer
(
val
fillLayer
=
fillLayer
(
MainViewModel
.
STATION_AREA_LAYER
,
MainViewModel
.
STATION_AREA_LAYER
,
MainViewModel
.
STATION_AREA_SOURCE
MainViewModel
.
STATION_AREA_SOURCE
){
){
...
@@ -276,11 +342,11 @@ fun Style.addStationAreaFillLayer():FillLayer{
...
@@ -276,11 +342,11 @@ fun Style.addStationAreaFillLayer():FillLayer{
fillOpacity
(
0.8
)
fillOpacity
(
0.8
)
visibility
(
Visibility
.
VISIBLE
)
visibility
(
Visibility
.
VISIBLE
)
}
}
addLayer
(
fillLayer
)
}
}
fun
Style
.
addStationAreaSymbolLayer
(){
fun
Style
.
addStationAreaSymbolLayer
():
SymbolLayer
{
LogUtils
.
dTag
(
"MapBoxExtensions"
,
"addStationAreaSymbolLayer"
)
LogUtils
.
dTag
(
"MapBoxLayout"
,
"addStationAreaSymbolLayer"
)
val
symbolLayer
=
symbolLayer
(
MainViewModel
.
STATION_AREA_TEXT_LAYER
,
MainViewModel
.
STATION_AREA_SOURCE
){
return
symbolLayer
(
MainViewModel
.
STATION_AREA_TEXT_LAYER
,
MainViewModel
.
STATION_AREA_SOURCE
){
textColor
(
Color
.
BLACK
)
textColor
(
Color
.
BLACK
)
textField
(
get
(
"name"
))
textField
(
get
(
"name"
))
textFont
(
listOf
(
"DIN Offc Pro Italic"
,
"Arial Unicode MS Regular"
))
textFont
(
listOf
(
"DIN Offc Pro Italic"
,
"Arial Unicode MS Regular"
))
...
@@ -292,18 +358,21 @@ fun Style.addStationAreaSymbolLayer():SymbolLayer{
...
@@ -292,18 +358,21 @@ fun Style.addStationAreaSymbolLayer():SymbolLayer{
textSize
(
16.0
)
textSize
(
16.0
)
textMaxWidth
(
10.0
)
textMaxWidth
(
10.0
)
}
}
addLayer
(
symbolLayer
)
}
}
/**
fun
Style
.
addLaneNodeSource
(
source
:
String
):
GeoJsonSource
{
* lanenode:道路节点
LogUtils
.
dTag
(
"MapBoxLayout"
,
"addLaneNodeSource"
)
* */
return
geoJsonSource
(
MainViewModel
.
LANE_NODE_SOURCE
)
{
fun
Style
.
addLaneNodeSource
(
source
:
String
){
LogUtils
.
dTag
(
"MapBoxExtensions"
,
"addLaneNodeSource"
)
val
source
=
geoJsonSource
(
MainViewModel
.
LANE_NODE_SOURCE
)
{
data
(
source
)
data
(
source
)
}
}
addSource
(
source
)
}
}
fun
Style
.
addLaneNodeCircleLayer
(){
fun
Style
.
addLaneNodeCircleLayer
():
CircleLayer
{
LogUtils
.
dTag
(
"MapBoxExtensions"
,
"addLaneNodeCircleLayer"
)
LogUtils
.
dTag
(
"MapBoxLayout"
,
"addLaneNodeCircleLayer"
)
val
circleLayer
=
circleLayer
(
return
circleLayer
(
MainViewModel
.
LANE_NODE_LAYER
,
MainViewModel
.
LANE_NODE_LAYER
,
MainViewModel
.
LANE_NODE_SOURCE
MainViewModel
.
LANE_NODE_SOURCE
){
){
...
@@ -311,11 +380,11 @@ fun Style.addLaneNodeCircleLayer():CircleLayer{
...
@@ -311,11 +380,11 @@ fun Style.addLaneNodeCircleLayer():CircleLayer{
circleRadius
(
6.0
)
circleRadius
(
6.0
)
visibility
(
Visibility
.
VISIBLE
)
visibility
(
Visibility
.
VISIBLE
)
}
}
addLayer
(
circleLayer
)
}
}
fun
Style
.
addLaneNodeSymbolLayer
(){
fun
Style
.
addLaneNodeSymbolLayer
():
SymbolLayer
{
LogUtils
.
dTag
(
"MapBoxExtensions"
,
"addLaneNodeSymbolLayer"
)
LogUtils
.
dTag
(
"MapBoxLayout"
,
"addLaneNodeSymbolLayer"
)
val
symbolLayer
=
symbolLayer
(
MainViewModel
.
LANE_NODE_TEXT_LAYER
,
MainViewModel
.
LANE_NODE_SOURCE
){
return
symbolLayer
(
MainViewModel
.
STATION_AREA_TEXT_LAYER
,
MainViewModel
.
STATION_AREA_SOURCE
){
textColor
(
Color
.
BLACK
)
textColor
(
Color
.
BLACK
)
textField
(
get
(
"name"
))
textField
(
get
(
"name"
))
textFont
(
listOf
(
"DIN Offc Pro Italic"
,
"Arial Unicode MS Regular"
))
textFont
(
listOf
(
"DIN Offc Pro Italic"
,
"Arial Unicode MS Regular"
))
...
@@ -324,32 +393,37 @@ fun Style.addLaneNodeSymbolLayer():SymbolLayer{
...
@@ -324,32 +393,37 @@ fun Style.addLaneNodeSymbolLayer():SymbolLayer{
textOffset
(
listOf
(
0.5
,-
0.5
))
textOffset
(
listOf
(
0.5
,-
0.5
))
textRotationAlignment
(
TextRotationAlignment
.
MAP
)
textRotationAlignment
(
TextRotationAlignment
.
MAP
)
textAnchor
(
TextAnchor
.
TOP
)
textAnchor
(
TextAnchor
.
TOP
)
textSize
(
16
.0
)
textSize
(
9
.0
)
textMaxWidth
(
10.0
)
textMaxWidth
(
10.0
)
}
}
addLayer
(
symbolLayer
)
}
}
fun
Style
.
addParkSpotSource
(
source
:
String
):
GeoJsonSource
{
/**
LogUtils
.
dTag
(
"MapBoxLayout"
,
"addParkSpotSource"
)
* parkspot:停车区
return
geoJsonSource
(
MainViewModel
.
PARK_SPOT_SOURCE
)
{
* */
fun
Style
.
addParkSpotSource
(
source
:
String
){
LogUtils
.
dTag
(
"MapBoxExtensions"
,
"addParkSpotSource"
)
val
source
=
geoJsonSource
(
MainViewModel
.
PARK_SPOT_SOURCE
)
{
data
(
source
)
data
(
source
)
}
}
addSource
(
source
)
}
}
fun
Style
.
addParkSpotFillLayer
()
:
FillLayer
{
fun
Style
.
addParkSpotFillLayer
(){
LogUtils
.
dTag
(
"MapBox
Layout
"
,
"addParkSpotFillLayer"
)
LogUtils
.
dTag
(
"MapBox
Extensions
"
,
"addParkSpotFillLayer"
)
return
fillLayer
(
val
fillLayer
=
fillLayer
(
MainViewModel
.
PARK_SPOT_LAYER
,
MainViewModel
.
PARK_SPOT_LAYER
,
MainViewModel
.
PARK_SPOT_SOURCE
MainViewModel
.
PARK_SPOT_SOURCE
){
){
fillColor
(
get
(
"#7e8185"
))
fillColor
(
get
(
"#7e8185"
))
fillOpacity
(
0.8
)
fillOpacity
(
0.8
)
fillAntialias
(
false
)
visibility
(
Visibility
.
VISIBLE
)
visibility
(
Visibility
.
VISIBLE
)
}
}
addLayer
(
fillLayer
)
}
}
fun
Style
.
addParkSpotSymbolLayer
()
:
SymbolLayer
{
fun
Style
.
addParkSpotSymbolLayer
(){
LogUtils
.
dTag
(
"MapBox
Layout
"
,
"addParkSpotSymbolLayer"
)
LogUtils
.
dTag
(
"MapBox
Extensions
"
,
"addParkSpotSymbolLayer"
)
return
symbolLayer
(
MainViewModel
.
PARK_SPOT_TEXT_LAYER
,
MainViewModel
.
PARK_SPOT_SOURCE
){
val
symbolLayer
=
symbolLayer
(
MainViewModel
.
PARK_SPOT_TEXT_LAYER
,
MainViewModel
.
PARK_SPOT_SOURCE
){
textColor
(
Color
.
BLACK
)
textColor
(
Color
.
BLACK
)
textField
(
get
(
"name"
))
textField
(
get
(
"name"
))
textFont
(
listOf
(
"DIN Offc Pro Italic"
,
"Arial Unicode MS Regular"
))
textFont
(
listOf
(
"DIN Offc Pro Italic"
,
"Arial Unicode MS Regular"
))
...
@@ -358,21 +432,25 @@ fun Style.addParkSpotSymbolLayer():SymbolLayer{
...
@@ -358,21 +432,25 @@ fun Style.addParkSpotSymbolLayer():SymbolLayer{
textOffset
(
listOf
(
0.5
,-
0.5
))
textOffset
(
listOf
(
0.5
,-
0.5
))
textRotationAlignment
(
TextRotationAlignment
.
MAP
)
textRotationAlignment
(
TextRotationAlignment
.
MAP
)
textAnchor
(
TextAnchor
.
TOP
)
textAnchor
(
TextAnchor
.
TOP
)
textSize
(
9
.0
)
textSize
(
16
.0
)
textMax
Angle
(
10.0
)
textMax
Width
(
10.0
)
visibility
(
Visibility
.
VISIBLE
)
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
)
data
(
source
)
}
}
addSource
(
source
)
}
}
fun
Style
.
addElectronicFenceFillLayer
()
:
FillLayer
{
fun
Style
.
addElectronicFenceFillLayer
(){
LogUtils
.
dTag
(
"MapBox
Layout
"
,
"addElectronicFenceFillLayer"
)
LogUtils
.
dTag
(
"MapBox
Extensions
"
,
"addElectronicFenceFillLayer"
)
return
fillLayer
(
val
fillLayer
=
fillLayer
(
MainViewModel
.
ELECTRONIC_FENCE_LAYER
,
MainViewModel
.
ELECTRONIC_FENCE_LAYER
,
MainViewModel
.
ELECTRONIC_FENCE_SOURCE
MainViewModel
.
ELECTRONIC_FENCE_SOURCE
){
){
...
@@ -381,11 +459,12 @@ fun Style.addElectronicFenceFillLayer():FillLayer{
...
@@ -381,11 +459,12 @@ fun Style.addElectronicFenceFillLayer():FillLayer{
fillAntialias
(
false
)
fillAntialias
(
false
)
visibility
(
Visibility
.
VISIBLE
)
visibility
(
Visibility
.
VISIBLE
)
}
}
addLayer
(
fillLayer
)
}
}
fun
Style
.
addElectronicFenceSymbolLayer
()
:
SymbolLayer
{
fun
Style
.
addElectronicFenceSymbolLayer
(){
LogUtils
.
dTag
(
"MapBox
Layout
"
,
"addElectronicFenceSymbolLayer"
)
LogUtils
.
dTag
(
"MapBox
Extensions
"
,
"addElectronicFenceSymbolLayer"
)
return
symbolLayer
(
MainViewModel
.
ELECTRONIC_FENCE_TEXT_LAYER
,
MainViewModel
.
ELECTRONIC_FENCE_SOURCE
){
val
symbolLayer
=
symbolLayer
(
MainViewModel
.
ELECTRONIC_FENCE_TEXT_LAYER
,
MainViewModel
.
ELECTRONIC_FENCE_SOURCE
){
textColor
(
Color
.
BLACK
)
textColor
(
Color
.
BLACK
)
textField
(
get
(
"name"
))
textField
(
get
(
"name"
))
textFont
(
listOf
(
"DIN Offc Pro Italic"
,
"Arial Unicode MS Regular"
))
textFont
(
listOf
(
"DIN Offc Pro Italic"
,
"Arial Unicode MS Regular"
))
...
@@ -395,20 +474,22 @@ fun Style.addElectronicFenceSymbolLayer():SymbolLayer{
...
@@ -395,20 +474,22 @@ fun Style.addElectronicFenceSymbolLayer():SymbolLayer{
textRotationAlignment
(
TextRotationAlignment
.
MAP
)
textRotationAlignment
(
TextRotationAlignment
.
MAP
)
textAnchor
(
TextAnchor
.
TOP
)
textAnchor
(
TextAnchor
.
TOP
)
textSize
(
16.0
)
textSize
(
16.0
)
textMax
Angle
(
10.0
)
textMax
Width
(
10.0
)
visibility
(
Visibility
.
VISIBLE
)
visibility
(
Visibility
.
VISIBLE
)
}
}
addLayer
(
symbolLayer
)
}
}
fun
Style
.
addWetAreaSource
(
source
:
String
)
:
GeoJsonSource
{
fun
Style
.
addWetAreaSource
(
source
:
String
){
LogUtils
.
dTag
(
"MapBox
Layout
"
,
"addWetAreaSource"
)
LogUtils
.
dTag
(
"MapBox
Extensions
"
,
"addWetAreaSource"
)
return
geoJsonSource
(
MainViewModel
.
WET_AREA_SOURCE
)
{
val
source
=
geoJsonSource
(
MainViewModel
.
WET_AREA_SOURCE
)
{
data
(
source
)
data
(
source
)
}
}
addSource
(
source
)
}
}
fun
Style
.
addWetAreaFillLayer
()
:
FillLayer
{
fun
Style
.
addWetAreaFillLayer
(){
LogUtils
.
dTag
(
"MapBox
Layout
"
,
"addWetAreaFillLayer"
)
LogUtils
.
dTag
(
"MapBox
Extensions
"
,
"addWetAreaFillLayer"
)
return
fillLayer
(
val
fillLayer
=
fillLayer
(
MainViewModel
.
WET_AREA_LAYER
,
MainViewModel
.
WET_AREA_LAYER
,
MainViewModel
.
WET_AREA_SOURCE
MainViewModel
.
WET_AREA_SOURCE
){
){
...
@@ -417,47 +498,12 @@ fun Style.addWetAreaFillLayer():FillLayer{
...
@@ -417,47 +498,12 @@ fun Style.addWetAreaFillLayer():FillLayer{
fillAntialias
(
false
)
fillAntialias
(
false
)
visibility
(
Visibility
.
VISIBLE
)
visibility
(
Visibility
.
VISIBLE
)
}
}
addLayer
(
fillLayer
)
}
}
fun
Style
.
addWetAreaSymbolLayer
():
SymbolLayer
{
fun
Style
.
addWetAreaSymbolLayer
(){
LogUtils
.
dTag
(
"MapBoxLayout"
,
"addWetAreaSymbolLayer"
)
LogUtils
.
dTag
(
"MapBoxExtensions"
,
"addWetAreaSymbolLayer"
)
return
symbolLayer
(
MainViewModel
.
WET_AREA_TEXT_LAYER
,
MainViewModel
.
WET_AREA_SOURCE
){
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"
))
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
){
textColor
(
Color
.
BLACK
)
textColor
(
Color
.
BLACK
)
textField
(
get
(
"name"
))
textField
(
get
(
"name"
))
textFont
(
listOf
(
"DIN Offc Pro Italic"
,
"Arial Unicode MS Regular"
))
textFont
(
listOf
(
"DIN Offc Pro Italic"
,
"Arial Unicode MS Regular"
))
...
@@ -467,20 +513,21 @@ fun Style.addDumpAreaSymbolLayer():SymbolLayer{
...
@@ -467,20 +513,21 @@ fun Style.addDumpAreaSymbolLayer():SymbolLayer{
textRotationAlignment
(
TextRotationAlignment
.
MAP
)
textRotationAlignment
(
TextRotationAlignment
.
MAP
)
textAnchor
(
TextAnchor
.
TOP
)
textAnchor
(
TextAnchor
.
TOP
)
textSize
(
16.0
)
textSize
(
16.0
)
textMax
Angle
(
10.0
)
textMax
Width
(
10.0
)
visibility
(
Visibility
.
VISIBLE
)
visibility
(
Visibility
.
VISIBLE
)
}
}
addLayer
(
symbolLayer
)
}
}
fun
Style
.
addTruckPathSource
(){
fun
Style
.
addTruckPathSource
():
GeoJsonSource
{
LogUtils
.
dTag
(
"MapBoxExtensions"
,
"addTruckPathSource"
)
LogUtils
.
dTag
(
"MapBoxLayout"
,
"addTruckPathSource"
)
val
source
=
geoJsonSource
(
"truckPathSource"
)
{
return
geoJsonSource
(
"truckPathSource"
)
{
data
(
"{ \"type\": \"FeatureCollection\", \"features\":[]}"
)
data
(
"{ \"type\": \"FeatureCollection\", \"features\":[]}"
)
}
}
addSource
(
source
)
}
}
fun
Style
.
addTruckPathLineLayer
()
:
LineLayer
{
fun
Style
.
addTruckPathLineLayer
(){
LogUtils
.
dTag
(
"MapBox
Layout"
,
"addTruckPathSource
"
)
LogUtils
.
dTag
(
"MapBox
Extensions"
,
"addTruckPathLineLayer
"
)
return
lineLayer
(
val
lineLayer
=
lineLayer
(
"truckPathLayer"
,
"truckPathLayer"
,
"truckPathSource"
"truckPathSource"
){
){
...
@@ -491,6 +538,7 @@ fun Style.addTruckPathLineLayer():LineLayer{
...
@@ -491,6 +538,7 @@ fun Style.addTruckPathLineLayer():LineLayer{
lineCap
(
LineCap
.
ROUND
)
lineCap
(
LineCap
.
ROUND
)
visibility
(
Visibility
.
VISIBLE
)
visibility
(
Visibility
.
VISIBLE
)
}
}
addLayer
(
lineLayer
)
}
}
fun
AppCompatActivity
.
checkSelfPermissionCompat
(
permission
:
String
)
=
fun
AppCompatActivity
.
checkSelfPermissionCompat
(
permission
:
String
)
=
...
...
app/src/main/res/layout/fragment_home.xml
View file @
7552d1f8
...
@@ -282,9 +282,8 @@
...
@@ -282,9 +282,8 @@
app:layout_constraintTop_toTopOf=
"@id/defaultToggleMore"
app:layout_constraintTop_toTopOf=
"@id/defaultToggleMore"
app:layout_constraintEnd_toEndOf=
"@id/defaultMapLayout"
/>
app:layout_constraintEnd_toEndOf=
"@id/defaultMapLayout"
/>
<
include
<
FrameLayout
android:id=
"@+id/defaultMapLayout"
android:id=
"@+id/defaultMapLayout"
layout=
"@layout/layout_map_box"
android:layout_width=
"0dp"
android:layout_width=
"0dp"
android:layout_height=
"0dp"
android:layout_height=
"0dp"
android:layout_marginEnd=
"16dp"
android:layout_marginEnd=
"16dp"
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment