67 lines
2.0 KiB
Kotlin
67 lines
2.0 KiB
Kotlin
package com.danilafe.fencelessgrazing
|
|
|
|
import android.graphics.Color
|
|
import androidx.appcompat.app.AppCompatActivity
|
|
import android.os.Bundle
|
|
import com.danilafe.fencelessgrazing.model.CollarPos
|
|
import com.danilafe.fencelessgrazing.model.Polygon
|
|
import org.osmdroid.util.GeoPoint
|
|
import org.osmdroid.views.MapView
|
|
|
|
class CollarDetailActivity : AppCompatActivity() {
|
|
|
|
private lateinit var token: String
|
|
private var collarId: Int = -1
|
|
|
|
private lateinit var map: MapView
|
|
|
|
private lateinit var mapPolygon: org.osmdroid.views.overlay.Polygon
|
|
private var boundingBox: Polygon? = null
|
|
set(newValue) {
|
|
if(newValue != null) updateBoundingBox(field, newValue)
|
|
else clearBoundingBox()
|
|
field = newValue
|
|
}
|
|
|
|
override fun onCreate(savedInstanceState: Bundle?) {
|
|
super.onCreate(savedInstanceState)
|
|
setContentView(R.layout.activity_collar_detail)
|
|
|
|
token = intent.getStringExtra("token")!!
|
|
collarId = intent.getIntExtra("identifier", -1)
|
|
|
|
map = findViewById(R.id.detailMap)
|
|
mapPolygon = org.osmdroid.views.overlay.Polygon(map)
|
|
configureMapPolygon()
|
|
}
|
|
|
|
private fun configureMapPolygon() {
|
|
mapPolygon.fillPaint.color = Color.CYAN
|
|
mapPolygon.fillPaint.alpha = 127
|
|
mapPolygon.outlinePaint.strokeWidth = 0.0f
|
|
mapPolygon.title = "Valid Grazing Area"
|
|
}
|
|
|
|
private fun updateBoundingBox(oldValue: Polygon?, polygon: Polygon) {
|
|
if(oldValue == null) map.overlays.add(mapPolygon)
|
|
val points = polygon.dataPoints.map { GeoPoint(it.longitude.toDouble(), it.latitude.toDouble()) }
|
|
val polygonPoints = points.toMutableList()
|
|
polygonPoints.add(polygonPoints[0])
|
|
mapPolygon.points = polygonPoints
|
|
}
|
|
|
|
private fun clearBoundingBox() {
|
|
map.overlays.remove(mapPolygon)
|
|
}
|
|
|
|
override fun onPause() {
|
|
super.onPause()
|
|
map.onPause()
|
|
}
|
|
|
|
override fun onResume() {
|
|
super.onResume()
|
|
map.onResume()
|
|
}
|
|
}
|