From ffe66ec81c4aa40d66db1f8ef187abea1b728f86 Mon Sep 17 00:00:00 2001 From: PWRxPSYCHO Date: Wed, 16 Feb 2022 13:56:17 -0500 Subject: [PATCH] Fixed issue with adding multiple layers instead of moving touch position --- .../com/geeksville/mesh/ui/MapFragment.kt | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/com/geeksville/mesh/ui/MapFragment.kt b/app/src/main/java/com/geeksville/mesh/ui/MapFragment.kt index 62d535747..6c4bc4496 100644 --- a/app/src/main/java/com/geeksville/mesh/ui/MapFragment.kt +++ b/app/src/main/java/com/geeksville/mesh/ui/MapFragment.kt @@ -53,6 +53,9 @@ class MapFragment : ScreenFragment("Map"), Logging { private val userTouchLayerId = "user-touch-layer" private var nodePositions = GeoJsonSource(GeoJsonSource.Builder(nodeSourceId)) + private val userTouchPosition = GeoJsonSource(GeoJsonSource.Builder(userTouchPositionId)) + + private val nodeLayer = SymbolLayer(nodeLayerId, nodeSourceId) .iconImage(markerImageId) .iconAnchor(IconAnchor.BOTTOM) @@ -208,19 +211,23 @@ class MapFragment : ScreenFragment("Map"), Logging { } } - //TODO Create list of touch positions that can be updated on new press + /** + * OnLongClick of the map set a position marker. + */ private val longClick = OnMapLongClickListener { val userDefinedPointImg = ContextCompat.getDrawable(requireActivity(), R.drawable.ic_twotone_person_24)!! .toBitmap() val point = Point.fromLngLat(it.longitude(), it.latitude()) - val userTouchPosition = GeoJsonSource(GeoJsonSource.Builder(userTouchPositionId)) - userTouchPosition.geometry(point) mapView?.getMapboxMap()?.getStyle()?.let { style -> - style.addImage("userImage", userDefinedPointImg) - style.addSource(userTouchPosition) - style.addLayer(userTouchLayer) + userTouchPosition.geometry(point) + + if (!style.styleLayerExists(userTouchLayerId)) { + style.addImage("userImage", userDefinedPointImg) + style.addSource(userTouchPosition) + style.addLayer(userTouchLayer) + } } return@OnMapLongClickListener true