Skip to content

Commit

Permalink
feat : add interestPoint for drawRoadManually in android side (liodal…
Browse files Browse the repository at this point in the history
…i#231)

* add new data to receive from dart side concern interestPoints and custom icon
  • Loading branch information
liodali committed Mar 1, 2022
1 parent 955e826 commit 5797f69
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -612,7 +612,6 @@ class FlutterOsmView(
}
val polyLine = Polyline(map!!)
polyLine.setPoints(lastRoad.roadPoints)
//customRoadMarkerIcon.p
flutterRoad = createRoad(
polyLine = polyLine,
colorRoad = lastRoad.roadColor,
Expand Down Expand Up @@ -1043,17 +1042,38 @@ class FlutterOsmView(
val color = Color.rgb(colorRoad.first(), colorRoad.last(), colorRoad[1])
val widthRoad = (args["roadWidth"] as Double)
val zoomToRegion = args["zoomInto"] as Boolean
val clearPreviousRoad = args["clearPreviousRoad"] as Boolean
val interestPointsEncoded = args["interestPoints"] as String?
val iconInterestPoints = args["iconInterestPoints"] as ByteArray?
checkRoadFolderAboveUserOverlay()
if (clearPreviousRoad) {
folderRoad.items.clear()
}
var bitmapIconInterestPoints :Bitmap? = null
if (iconInterestPoints != null){
bitmapIconInterestPoints = getBitmap(bytes = iconInterestPoints!!)
}

folderRoad.items.clear()


val route = PolylineEncoder.decode(encodedWayPoints, 10, false)
val listInterestPoints = when (interestPointsEncoded != null) {
true -> PolylineEncoder.decode(interestPointsEncoded, 10, false)
false -> emptyList<GeoPoint>()
}

val polyLine = Polyline(map!!)
polyLine.setPoints(route)
polyLine.outlinePaint.color = color
polyLine.outlinePaint.strokeWidth = widthRoad.toFloat()

createRoad(
polyLine = polyLine,
colorRoad = color,
roadWidth = widthRoad.toFloat(),
showPoiMarker = listInterestPoints.isNotEmpty(),
listInterestPoints = listInterestPoints,
bitmapIcon = bitmapIconInterestPoints
)
folderRoad.items.add(polyLine)

mapSnapShot().cacheRoad(
Expand Down Expand Up @@ -1574,6 +1594,7 @@ class FlutterOsmView(
showPoiMarker: Boolean,
listInterestPoints: List<GeoPoint>,
roadWidth: Float,
bitmapIcon: Bitmap? = null,
): FlutterRoad {
polyLine.setOnClickListener { _, _, eventPos ->
methodChannel.invokeMethod("receiveSinglePress", eventPos?.toHashMap())
Expand All @@ -1582,19 +1603,29 @@ class FlutterOsmView(
/// set polyline color
polyLine.outlinePaint.color = colorRoad ?: Color.GREEN

val iconsRoads = customRoadMarkerIcon
if (iconsRoads.isEmpty() && bitmapIcon != null) {
iconsRoads[Constants.STARTPOSITIONROAD] = bitmapIcon
iconsRoads[Constants.MIDDLEPOSITIONROAD] = bitmapIcon
iconsRoads[Constants.ENDPOSITIONROAD] = bitmapIcon

}
val flutterRoad = FlutterRoad(
context,
map!!,
interestPoint = if (showPoiMarker) listInterestPoints else emptyList()
interestPoint = if (showPoiMarker) listInterestPoints else emptyList(),
showInterestPoints = showPoiMarker
)

flutterRoad.let { roadF ->
roadF.markersIcons = customRoadMarkerIcon
if (showPoiMarker) {
roadF.markersIcons = iconsRoads
}
polyLine.outlinePaint.strokeWidth = roadWidth

roadF.road = polyLine
if (showPoiMarker) {
roadF.items.add(polyLine)
/*if (showPoiMarker) {
// if (it.start != null)
folderRoad.items.add(roadF.start.apply {
this.visibilityInfoWindow(visibilityInfoWindow)
Expand All @@ -1604,9 +1635,9 @@ class FlutterOsmView(
this.visibilityInfoWindow(visibilityInfoWindow)
})
folderRoad.items.addAll(roadF.middlePoints)
}
}*/

folderRoad.items.add(roadF.road!!)
folderRoad.items.add(roadF)
}

return flutterRoad
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,32 @@ import android.graphics.Bitmap
import hamza.dali.flutter_osm_plugin.utilities.Constants
import org.osmdroid.util.GeoPoint
import org.osmdroid.views.MapView
import org.osmdroid.views.overlay.Overlay
import org.osmdroid.views.overlay.FolderOverlay
import org.osmdroid.views.overlay.Polyline

open class FlutterRoad(
val context: Context,
private val context: Context,
private val mapView: MapView,
private val interestPoint: List<GeoPoint> = emptyList(),
) : Overlay() {
private val showInterestPoints: Boolean = false,
) : FolderOverlay() {

lateinit var start: FlutterRoadMarker//? = null
lateinit var end: FlutterRoadMarker//? = null
var middlePoints: MutableList<FlutterRoadMarker> = emptyList<FlutterRoadMarker>().toMutableList()
var middlePoints: MutableList<FlutterRoadMarker> =
emptyList<FlutterRoadMarker>().toMutableList()
var road: Polyline? = null
set(value) {
if (value != null) {
initStartEndPoints(value.actualPoints.first(), value.actualPoints.last(), interestPoint)
field = value
if (showInterestPoints) {
initStartEndPoints(
value.actualPoints.first(),
value.actualPoints.last(),
interestPoint
)
}

}
}
var markersIcons: HashMap<String, Bitmap> = HashMap()
Expand All @@ -30,10 +39,11 @@ open class FlutterRoad(
}

private fun initStartEndPoints(
startRoad: GeoPoint,
destinationRoad: GeoPoint,
interestPoint: List<GeoPoint> = emptyList()
startRoad: GeoPoint,
destinationRoad: GeoPoint,
interestPoint: List<GeoPoint> = emptyList()
) {
val listInterest = interestPoint.toMutableList()
start = FlutterRoadMarker(context, mapView, startRoad).apply {
this.mapIconsBitmaps = markersIcons
this.iconPosition(Constants.PositionMarker.START)
Expand All @@ -43,16 +53,29 @@ open class FlutterRoad(
this.mapIconsBitmaps = markersIcons
this.iconPosition(Constants.PositionMarker.END)
}
interestPoint.forEach { geoPoint ->
middlePoints.add(

items.add(start)
items.add(end)
if(interestPoint.isNotEmpty()){
if (interestPoint.first() == startRoad) {
listInterest.removeFirst()
}

if (interestPoint.last() == destinationRoad) {
listInterest.removeLast()
}
listInterest.forEach { geoPoint ->
middlePoints.add(
FlutterRoadMarker(context, mapView, geoPoint).apply {
this.mapIconsBitmaps = markersIcons
this.iconPosition(Constants.PositionMarker.MIDDLE)
this.visibilityInfoWindow(false)
}
)
}
)
}
items.addAll(middlePoints.toList())

}

}

Expand Down

0 comments on commit 5797f69

Please sign in to comment.