mirror of
https://github.com/meshtastic/Meshtastic-Android.git
synced 2026-03-24 00:33:14 -04:00
done with map view for now
This commit is contained in:
@@ -2,6 +2,7 @@ package com.geeksville.mesh.ui
|
||||
|
||||
import android.app.Activity
|
||||
import android.app.Application
|
||||
import android.graphics.Color
|
||||
import android.os.Bundle
|
||||
import androidx.compose.Composable
|
||||
import androidx.compose.onCommit
|
||||
@@ -21,8 +22,12 @@ import com.mapbox.mapboxsdk.camera.CameraUpdateFactory
|
||||
import com.mapbox.mapboxsdk.geometry.LatLng
|
||||
import com.mapbox.mapboxsdk.maps.MapView
|
||||
import com.mapbox.mapboxsdk.maps.Style
|
||||
import com.mapbox.mapboxsdk.style.expressions.Expression
|
||||
import com.mapbox.mapboxsdk.style.layers.Property
|
||||
import com.mapbox.mapboxsdk.style.layers.Property.TEXT_ANCHOR_TOP
|
||||
import com.mapbox.mapboxsdk.style.layers.Property.TEXT_JUSTIFY_AUTO
|
||||
import com.mapbox.mapboxsdk.style.layers.PropertyFactory
|
||||
import com.mapbox.mapboxsdk.style.layers.PropertyFactory.*
|
||||
import com.mapbox.mapboxsdk.style.layers.SymbolLayer
|
||||
import com.mapbox.mapboxsdk.style.sources.GeoJsonSource
|
||||
|
||||
@@ -88,18 +93,21 @@ fun MapContent() {
|
||||
// Find all nodes with valid locations
|
||||
val locations = NodeDB.nodes.values.mapNotNull { node ->
|
||||
val p = node.position
|
||||
if (p != null && (p.latitude != 0.0 || p.longitude != 0.0))
|
||||
Feature.fromGeometry(
|
||||
if (p != null && (p.latitude != 0.0 || p.longitude != 0.0)) {
|
||||
val f = Feature.fromGeometry(
|
||||
Point.fromLngLat(
|
||||
p.latitude,
|
||||
p.longitude
|
||||
p.longitude,
|
||||
p.latitude
|
||||
)
|
||||
)
|
||||
else
|
||||
node.user?.let { f.addStringProperty("name", it.longName) }
|
||||
f
|
||||
} else
|
||||
null
|
||||
}
|
||||
val nodeSourceId = "node-positions"
|
||||
val nodeLayerId = "node-layer"
|
||||
val labelLayerId = "label-layer"
|
||||
val markerImageId = "my-marker-image"
|
||||
val nodePositions =
|
||||
GeoJsonSource(nodeSourceId, FeatureCollection.fromFeatures(locations))
|
||||
@@ -107,13 +115,19 @@ fun MapContent() {
|
||||
// val markerIcon = BitmapFactory.decodeResource(context.resources, R.drawable.ic_twotone_person_pin_24)
|
||||
val markerIcon = context.getDrawable(R.drawable.ic_twotone_person_pin_24)!!
|
||||
|
||||
val nodeLayer = SymbolLayer(nodeLayerId, nodeSourceId)
|
||||
nodeLayer.setProperties(
|
||||
val nodeLayer = SymbolLayer(nodeLayerId, nodeSourceId).withProperties(
|
||||
PropertyFactory.iconImage(markerImageId),
|
||||
PropertyFactory.iconAnchor(Property.ICON_ANCHOR_BOTTOM)
|
||||
)
|
||||
|
||||
//Column {
|
||||
val labelLayer = SymbolLayer(labelLayerId, nodeSourceId).withProperties(
|
||||
textField(Expression.get("name")),
|
||||
textSize(12f),
|
||||
textColor(Color.RED),
|
||||
textVariableAnchor(arrayOf(TEXT_ANCHOR_TOP)),
|
||||
textJustify(TEXT_JUSTIFY_AUTO)
|
||||
)
|
||||
|
||||
AndroidView(R.layout.map_view) { view ->
|
||||
view as MapView
|
||||
view.onCreate(UIState.savedInstanceState)
|
||||
@@ -125,21 +139,24 @@ fun MapContent() {
|
||||
|
||||
view.getMapAsync { map ->
|
||||
map.setStyle(Style.OUTDOORS) { style ->
|
||||
style.addImage(markerImageId, markerIcon)
|
||||
style.addSource(nodePositions)
|
||||
style.addImage(markerImageId, markerIcon)
|
||||
style.addLayer(nodeLayer)
|
||||
style.addLayer(labelLayer)
|
||||
}
|
||||
|
||||
//map.uiSettings.isScrollGesturesEnabled = true
|
||||
//map.uiSettings.isZoomGesturesEnabled = true
|
||||
|
||||
// Center on the user's position (if we have it)
|
||||
NodeDB.ourNodeInfo?.position?.let {
|
||||
val cameraPos = CameraPosition.Builder().target(
|
||||
LatLng(it.latitude, it.longitude)
|
||||
).zoom(8.0).build()
|
||||
).zoom(9.0).build()
|
||||
map.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPos), 1000)
|
||||
}
|
||||
}
|
||||
}
|
||||
//}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user