parent
080f5a176b
commit
8163c75932
@ -1,31 +1,56 @@
|
|||||||
package uca.baptistearthur.geocaching.ui.overlay
|
package uca.baptistearthur.geocaching.ui.overlay
|
||||||
|
|
||||||
import android.graphics.Rect
|
import android.os.AsyncTask
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import android.view.MotionEvent
|
import android.view.MotionEvent
|
||||||
|
import kotlinx.coroutines.CoroutineScope
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
|
import kotlinx.coroutines.withContext
|
||||||
|
import org.osmdroid.bonuspack.routing.Road
|
||||||
|
import org.osmdroid.bonuspack.routing.RoadManager
|
||||||
import org.osmdroid.util.GeoPoint
|
import org.osmdroid.util.GeoPoint
|
||||||
import org.osmdroid.views.MapView
|
import org.osmdroid.views.MapView
|
||||||
import org.osmdroid.views.overlay.Overlay
|
import org.osmdroid.views.overlay.Overlay
|
||||||
|
import org.osmdroid.views.overlay.Polyline
|
||||||
|
|
||||||
class AddMarkerOverlay : Overlay() {
|
|
||||||
|
|
||||||
private var locations: MutableSet<GeoPoint> = mutableSetOf()
|
class AddMarkerOverlay(val roadManager: RoadManager) : Overlay() {
|
||||||
|
|
||||||
|
private var locations: MutableSet<GeoPoint> = mutableSetOf()
|
||||||
|
private lateinit var roadOverlay: Polyline
|
||||||
override fun onDoubleTap(e: MotionEvent?, mapView: MapView?): Boolean {
|
override fun onDoubleTap(e: MotionEvent?, mapView: MapView?): Boolean {
|
||||||
Log.d("GeoMap", "Longpress")
|
Log.d("GeoMap", "Longpress")
|
||||||
val proj = mapView?.projection;
|
val proj = mapView?.projection;
|
||||||
if(proj!=null){
|
if(proj!=null){
|
||||||
val loc = proj.fromPixels(e?.x?.toInt()!!, e?.y?.toInt() !! ) as GeoPoint
|
val loc = proj.fromPixels(e?.x?.toInt()!!, e.y.toInt() ) as GeoPoint
|
||||||
locations.add(loc)
|
locations.add(loc)
|
||||||
val marker = PlaceMarker(mapView, locations)
|
val marker = PlaceMarker(mapView, locations, this)
|
||||||
marker.position = loc
|
marker.position = loc
|
||||||
marker.title = "Step " + locations.size
|
marker.title = "Step " + locations.size
|
||||||
mapView.overlays.add(marker)
|
mapView.overlays.add(marker)
|
||||||
mapView.invalidate()
|
computeRoad(mapView)
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun computeRoad(mapView: MapView) {
|
||||||
|
mapView.overlays.remove(mapView.overlays.find { it is Polyline})
|
||||||
|
if (locations.size > 1) {
|
||||||
|
CoroutineScope(Dispatchers.IO).launch {
|
||||||
|
val road = roadManager.getRoad(ArrayList(locations))
|
||||||
|
withContext(Dispatchers.Main) {
|
||||||
|
roadOverlay = RoadManager.buildRoadOverlay(road)
|
||||||
|
roadOverlay.width=10.0f;
|
||||||
|
mapView.overlays.add(roadOverlay)
|
||||||
|
mapView.invalidate()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in new issue