Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How do I delete markers? #1308

Open
CaioZen opened this issue Jun 3, 2024 · 1 comment
Open

How do I delete markers? #1308

CaioZen opened this issue Jun 3, 2024 · 1 comment

Comments

@CaioZen
Copy link

CaioZen commented Jun 3, 2024

Hello, I am creating a waypointv3 application and I wonder how can I delete the waypoint markers the application draws me. The code I got mostly from the sample app.

`
fun markWaypoints() {
// version参数实际未用到
//Lista de waypoints
val parseInfo = JNIWPMZManager.getWaylines("1.0.0", curMissionPath)
//Lista de waylines
var waylines = parseInfo.waylines
waylines.forEach() {
waypoints.addAll(it.waypoints)
markLine(it.waypoints)
}
waypoints.forEach() {
markWaypoint(DJILatLng(it.location.latitude, it.location.longitude), it.waypointIndex)
}

    val firstWaypoint = waypoints.first()
    val djilatlng1 = DJILatLng(firstWaypoint.location.latitude, firstWaypoint.location.longitude)
    val djilatlng2 = DJILatLng(firstWaypoint.location.latitude, firstWaypoint.location.longitude)
    val localWaypoint = DJILatLngBounds(djilatlng1, djilatlng2)
    map_widget.map?.animateCamera(DJICameraUpdateFactory.newLatLngBounds(localWaypoint, 0))
}

fun clearWaypoints() {
    // Limpa a lista de waypoints
    waypoints.clear()
    
    // Remove todos os marcadores e linhas do mapa
    //removeAllLines()
}


fun removeAllLines() {
    //deletes all markers, even the ones I dont want to
    map_widget.map?.clear()

}


fun markWaypoint(latlong: DJILatLng, waypointIndex: Int) : DJIMarker?{
    var markOptions = DJIMarkerOptions()
    markOptions.position(latlong)
    markOptions.icon(getMarkerRes(waypointIndex, 0f))
    markOptions.title(waypointIndex.toString())
    markOptions.isInfoWindowEnable = true
    //map_widget.map?.animateCamera(CameraUpdateFactory.newLatLngZoom(markOptions, 15),2000, null);
    return map_widget.map?.addMarker(markOptions)
}

fun markLine(waypoints: List<WaylineExecuteWaypoint>) {

    var djiwaypoints = waypoints.filter {
        true
    }.map {
        DJILatLng(it.location.latitude, it.location.longitude)
    }
    var lineOptions = DJIPolylineOptions()
    lineOptions.width(5f)
    lineOptions.color(Color.GREEN)
    lineOptions.addAll(djiwaypoints)
    map_widget.map?.addPolyline(lineOptions)
}


/**
 * Convert view to bitmap
 * Notice: recycle the bitmap after use
 */
fun getMarkerBitmap(
    index: Int,
    rotation: Float,
): Bitmap? {
    // create View for marker
    @SuppressLint("InflateParams") val markerView: View =
        LayoutInflater.from(activity)
            .inflate(R.layout.activity_waypoint_marker_style_layout, null)
    val markerBg = markerView.findViewById<ImageView>(R.id.image_content)
    val markerTv = markerView.findViewById<TextView>(R.id.image_text)
    markerTv.text = index.toString()
    markerTv.setTextColor(AndUtil.getResColor(R.color.uxsdk_blue))
    markerTv.textSize =
        AndUtil.getDimension(R.dimen.mission_waypoint_index_text_large_size)

    markerBg.setImageResource(R.mipmap.mission_edit_waypoint_normal)

    markerBg.rotation = rotation
    // convert view to bitmap
    markerView.destroyDrawingCache()
    markerView.measure(
        View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED),
        View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED)
    )
    markerView.layout(0, 0, markerView.measuredWidth, markerView.measuredHeight)
    markerView.isDrawingCacheEnabled = true
    return markerView.getDrawingCache(true)
}

private fun getMarkerRes(
    index: Int,
    rotation: Float,
): DJIBitmapDescriptor? {
    return DJIBitmapDescriptorFactory.fromBitmap(
        getMarkerBitmap(index , rotation)
    )
}

fun showWaypoints(){
    var loction2D = showWaypoints.last().waylineWaypoint.location
    val waypoint =  DJILatLng(loction2D.latitude , loction2D.longitude)
    var pointMarker =  markWaypoint(waypoint , getCurWaypointIndex())
    pointMarkers.add(pointMarker)
}

fun getCurWaypointIndex():Int{
    if (showWaypoints.size <= 0) {
        return 0
    }
    return showWaypoints.size
}`
@dji-dev
Copy link
Contributor

dji-dev commented Jun 4, 2024

Agent comment from yating.liao in Zendesk ticket #108922:

If you have the marker you want to delete, you can use marker.remove to clear it.
Please note that this removal interface is from the map library.

°°°

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants