diff options
author | Iván Ávalos <avalos@disroot.org> | 2022-01-13 02:54:42 -0600 |
---|---|---|
committer | Iván Ávalos <avalos@disroot.org> | 2022-01-13 02:54:42 -0600 |
commit | 72d4b1005a885fee7b44bdfcdffa830b27c7d12b (patch) | |
tree | 3fdeec879b0d144a05c0bffef8c0b475c934fd14 /androidApp/src/main/java/mx/trackermap | |
parent | c031a94852402f3b4cc8a8cdbe349af6660d74ce (diff) | |
download | etbsa-trackermap-mobile-72d4b1005a885fee7b44bdfcdffa830b27c7d12b.tar.gz etbsa-trackermap-mobile-72d4b1005a885fee7b44bdfcdffa830b27c7d12b.tar.bz2 etbsa-trackermap-mobile-72d4b1005a885fee7b44bdfcdffa830b27c7d12b.zip |
Added labels for markers and disabled clustering until we figure out how to combine it with marker labels
Diffstat (limited to 'androidApp/src/main/java/mx/trackermap')
-rw-r--r-- | androidApp/src/main/java/mx/trackermap/TrackerMap/android/map/MapFragment.kt | 70 | ||||
-rw-r--r-- | androidApp/src/main/java/mx/trackermap/TrackerMap/android/map/MarkerTransformations.kt | 3 |
2 files changed, 46 insertions, 27 deletions
diff --git a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/map/MapFragment.kt b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/map/MapFragment.kt index 9b4d24a..b8fbc57 100644 --- a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/map/MapFragment.kt +++ b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/map/MapFragment.kt @@ -27,6 +27,7 @@ class MapFragment : GlobeMapFragment() { data class Marker( val id: Int, + val name: String, val latitude: Double, val longitude: Double, val type: MarkerType = MarkerType.DEFAULT @@ -74,20 +75,6 @@ class MapFragment : GlobeMapFragment() { loader = QuadImageLoader(params, tileInfo, baseControl) loader?.setImageFormat(RenderController.ImageFormat.MaplyImageUShort565) - val clusterGenerator = BasicClusterGenerator( - intArrayOf( - Color.argb(255, 255, 255, 255) - ), 0, Point2d(64.0, 64.0), baseControl, activity - ) - clusterGenerator.cacheBitmaps(true) - clusterGenerator.setExponentBase(2.5) - clusterGenerator.setTextColor(Color.BLACK) - clusterGenerator.setLayoutSize(Point2d(80.0, 80.0)) - clusterGenerator.setSelectable(false) - - baseControl.clearClusterGenerators() - baseControl.addClusterGenerator(clusterGenerator) - val latitude = 23.191 val longitude = -100.36 focusOn(latitude, longitude, zoom = 0.4, animated = false) @@ -143,10 +130,22 @@ class MapFragment : GlobeMapFragment() { Point2d.FromDegrees(marker.longitude, marker.latitude) }.toTypedArray() + val fontSize = context?.resources?.getDimensionPixelSize(R.dimen.marker_label_text_size) + val reportColor = ContextCompat.getColor(context!!, R.color.colorReport) + val labelColor = ContextCompat.getColor(context!!, R.color.colorMarkerLabel) + val labelBgColor = ContextCompat.getColor(context!!, R.color.bgColorMarkerLabel) + val vectorInfo = VectorInfo() - vectorInfo.setColor(ContextCompat.getColor(context!!, R.color.colorReport)) + vectorInfo.setColor(reportColor) vectorInfo.setLineWidth(20.0f) + val labelInfo = LabelInfo() + labelInfo.textColor = labelColor + labelInfo.backgroundColor = labelBgColor + fontSize?.let { + labelInfo.fontSize = it.toFloat() + } + /* Draw markers for positions */ val screenMarkers = markers.mapIndexed { i, marker -> val screenMarker = ScreenMarker() @@ -169,24 +168,36 @@ class MapFragment : GlobeMapFragment() { } else Point2d(144.0, 144.0) screenMarker.userObject = marker.id screenMarker.selectable = true - if (!isReport) { - screenMarker.layoutImportance = 1.0f - } screenMarker } - val markerInfo = MarkerInfo() - if (!isReport) { - markerInfo.setClusterGroup(0) - } - objects.add(mapControl.addScreenMarkers( screenMarkers, - markerInfo, + MarkerInfo(), ThreadMode.ThreadAny )) + /* Add labels for markers */ + if (!isReport && markers.isNotEmpty()) { + val screenLabels = markers.map { marker -> + val label = ScreenLabel() + label.layoutImportance = Float.MAX_VALUE + label.text = if (marker.name.length >= 20) { + marker.name.substring(0 until 20) + "..." + } else marker.name + label.loc = Point2d.FromDegrees(marker.longitude, marker.latitude) + label.offset = Point2d(0.0, 92.0) + label + } + + objects.add(mapControl.addScreenLabels( + screenLabels, + labelInfo, + ThreadMode.ThreadAny + )) + } + /* Draw polyline for report */ if (isReport && markers.isNotEmpty()) { val vector = VectorObject() @@ -219,14 +230,19 @@ class MapFragment : GlobeMapFragment() { clear(true) - val color = ContextCompat.getColor(context!!, R.color.colorGeofence) + val fontSize = context?.resources?.getDimensionPixelSize(R.dimen.marker_label_text_size) + val colorFill = ContextCompat.getColor(context!!, R.color.colorGeofence) + val colorLabel = ContextCompat.getColor(context!!, R.color.colorGeofenceLabel) val vectorInfo = VectorInfo() - vectorInfo.setColor(color) + vectorInfo.setColor(colorFill) vectorInfo.setLineWidth(10.0f) val labelInfo = LabelInfo() - labelInfo.textColor = color + labelInfo.textColor = colorLabel + fontSize?.let { + labelInfo.fontSize = it.toFloat() + } val shapes = mutableListOf<Shape>() val vectors = mutableListOf<VectorObject>() diff --git a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/map/MarkerTransformations.kt b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/map/MarkerTransformations.kt index fcde58d..b1d52fb 100644 --- a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/map/MarkerTransformations.kt +++ b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/map/MarkerTransformations.kt @@ -13,6 +13,7 @@ object MarkerTransformations { return MapFragment.Marker( unit.position!!.id!!, + unit.device.name, unit.position!!.latitude!!, unit.position!!.longitude!!, categoryToMarkerType(unit.device.category ?: "") @@ -26,6 +27,7 @@ object MarkerTransformations { return MapFragment.Marker( position.id!!, + "", position.latitude!!, position.longitude!! ) @@ -38,6 +40,7 @@ object MarkerTransformations { return MapFragment.Marker( stop.deviceId!!, + stop.deviceName!!, stop.lat!!, stop.lon!! ) |