dji-sdk / Mobile-UXSDK-Beta-Android

Mobile Android UXSDK Beta
MIT License
96 stars 55 forks source link

Centering on aircraft without setMapCenterLock? #56

Open bbenson09 opened 2 years ago

bbenson09 commented 2 years ago

Hi, I'm trying to center the MapWidget on the aircraft WITHOUT locking it. After centering, I want to be able to drag the map without it popping back to the aircraft.

This does not work reliably:

public void centerMap() {
   mapWidget.setMapCenterLock(MapWidget.MapCenterLock.AIRCRAFT);
   mapWidget.setMapCenterLock(MapWidget.MapCenterLock.NONE);
}

Is there a way to do this? It seems like this should be a simple thing to implement if it's not already.

kenargo commented 2 years ago

This is easily done by creating a key listener for aircraft location:

private val aircraftLocationKey = FlightControllerKey.create(FlightControllerKey.AIRCRAFT_LOCATION)

creating a listener to this event and using the map's moveCamera or animateCamera like this:

val djiCameraPosition = DJICameraPosition.Builder().bearing(currentBearing).target(djiLatLng).zoom(20f) .build()

    val cameraUpdate = DJICameraUpdateFactory.newCameraPosition(djiCameraPosition)

    if (!snapToPosition) {
        binding.mapViewFragmentCommonMapWidget.map!!.animateCamera(cameraUpdate)
    } else {
        binding.mapViewFragmentCommonMapWidget.map!!.moveCamera(cameraUpdate)
    }