mirror of
https://github.com/meshtastic/Meshtastic-Android.git
synced 2026-04-20 22:23:37 +00:00
adding map markers kinda works
This commit is contained in:
parent
ecef170004
commit
915bd837ed
2 changed files with 66 additions and 13 deletions
|
|
@ -7,14 +7,22 @@ import androidx.compose.Composable
|
|||
import androidx.compose.onCommit
|
||||
import androidx.ui.core.ContextAmbient
|
||||
import androidx.ui.fakeandroidview.AndroidView
|
||||
import androidx.ui.layout.Column
|
||||
import androidx.ui.material.MaterialTheme
|
||||
import androidx.ui.tooling.preview.Preview
|
||||
import com.geeksville.android.Logging
|
||||
import com.geeksville.mesh.R
|
||||
import com.geeksville.mesh.model.NodeDB
|
||||
import com.geeksville.mesh.model.UIState
|
||||
import com.mapbox.geojson.Feature
|
||||
import com.mapbox.geojson.FeatureCollection
|
||||
import com.mapbox.geojson.Point
|
||||
import com.mapbox.mapboxsdk.maps.MapView
|
||||
import com.mapbox.mapboxsdk.maps.Style
|
||||
import com.mapbox.mapboxsdk.style.layers.Property
|
||||
import com.mapbox.mapboxsdk.style.layers.PropertyFactory
|
||||
import com.mapbox.mapboxsdk.style.layers.SymbolLayer
|
||||
import com.mapbox.mapboxsdk.style.sources.GeoJsonSource
|
||||
|
||||
|
||||
object mapLog : Logging
|
||||
|
||||
|
|
@ -74,23 +82,53 @@ fun MapContent() {
|
|||
}
|
||||
}
|
||||
|
||||
Column {
|
||||
AndroidView(R.layout.map_view) { view ->
|
||||
view as MapView
|
||||
view.onCreate(UIState.savedInstanceState)
|
||||
|
||||
mapLifecycleCallbacks.view = view
|
||||
(context.applicationContext as Application).registerActivityLifecycleCallbacks(
|
||||
mapLifecycleCallbacks
|
||||
// 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(
|
||||
Point.fromLngLat(
|
||||
p.latitude,
|
||||
p.longitude
|
||||
)
|
||||
)
|
||||
else
|
||||
null
|
||||
}
|
||||
val nodeSourceId = "node-positions"
|
||||
val nodeLayerId = "node-layer"
|
||||
val markerImageId = "my-marker-image"
|
||||
val nodePositions =
|
||||
GeoJsonSource(nodeSourceId, FeatureCollection.fromFeatures(locations))
|
||||
|
||||
view.getMapAsync { map ->
|
||||
map.setStyle(Style.OUTDOORS) {
|
||||
// Map is set up and the style has loaded. Now you can add data or make other map adjustments
|
||||
}
|
||||
// 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(
|
||||
PropertyFactory.iconImage(markerImageId),
|
||||
PropertyFactory.iconAnchor(Property.ICON_ANCHOR_BOTTOM)
|
||||
)
|
||||
|
||||
//Column {
|
||||
AndroidView(R.layout.map_view) { view ->
|
||||
view as MapView
|
||||
view.onCreate(UIState.savedInstanceState)
|
||||
|
||||
mapLifecycleCallbacks.view = view
|
||||
(context.applicationContext as Application).registerActivityLifecycleCallbacks(
|
||||
mapLifecycleCallbacks
|
||||
)
|
||||
|
||||
view.getMapAsync { map ->
|
||||
map.setStyle(Style.OUTDOORS) { style ->
|
||||
style.addImage(markerImageId, markerIcon)
|
||||
style.addSource(nodePositions)
|
||||
style.addLayer(nodeLayer)
|
||||
}
|
||||
}
|
||||
}
|
||||
//}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
15
app/src/main/res/drawable/ic_twotone_person_pin_24.xml
Normal file
15
app/src/main/res/drawable/ic_twotone_person_pin_24.xml
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24"
|
||||
android:tint="?attr/colorControlNormal">
|
||||
<path
|
||||
android:fillColor="@android:color/white"
|
||||
android:pathData="M9.83,18l0.59,0.59L12,20.17l1.59,-1.59 0.58,-0.58H19V4H5v14h4.83zM12,5c1.65,0 3,1.35 3,3s-1.35,3 -3,3 -3,-1.35 -3,-3 1.35,-3 3,-3zM6,15.58C6,13.08 9.97,12 12,12s6,1.08 6,3.58V17H6v-1.42z"
|
||||
android:strokeAlpha="0.3"
|
||||
android:fillAlpha="0.3"/>
|
||||
<path
|
||||
android:fillColor="@android:color/white"
|
||||
android:pathData="M9,20l3,3 3,-3h4c1.1,0 2,-0.9 2,-2L21,4c0,-1.1 -0.9,-2 -2,-2L5,2c-1.11,0 -2,0.9 -2,2v14c0,1.1 0.89,2 2,2h4zM5,4h14v14h-4.83l-0.59,0.59L12,20.17l-1.59,-1.59 -0.58,-0.58L5,18L5,4zM12,11c1.65,0 3,-1.35 3,-3s-1.35,-3 -3,-3 -3,1.35 -3,3 1.35,3 3,3zM12,7c0.55,0 1,0.45 1,1s-0.45,1 -1,1 -1,-0.45 -1,-1 0.45,-1 1,-1zM18,15.58c0,-2.5 -3.97,-3.58 -6,-3.58s-6,1.08 -6,3.58L6,17h12v-1.42zM8.48,15c0.74,-0.51 2.23,-1 3.52,-1s2.78,0.49 3.52,1L8.48,15z"/>
|
||||
</vector>
|
||||
Loading…
Add table
Add a link
Reference in a new issue