Map Widget - dji-sdk/Mobile-UXSDK-Beta-iOS GitHub Wiki

Map Widget

The Map widget displays the current aircraft's data, as well as other relevant location data on top of a map view. This includes aircraft location, home location, aircraft trail path, aircraft heading, aircraft path to home and No Fly Zones. Here is an example of what the map widget looks like.

Architecture

The map widget has a modularized architecture to better manage complexity, testability, and extensibility. In general, functionality is kept inside the component that it belongs in.

A brief overview of the components is below.

DUXBetaDataProvider is the class that is responsible for interfacing with DJIFlyZoneManager. For better separation of concepts, expose any additional DJIFlyZoneManager functionality to the rest of the map widget only via DUXBetaDataProvider.

DUXBetaAnnotationProvider and DUXBetaOverlayProvider handle the conversion of fly zone data into drawable map objects.

DUXBetaMapRenderer is responsible for handling MKMapView callbacks, and generating views from the drawable map objects.

The map widget includes custom classes for fly zone overlays and annotations. In general overlays need to conform to MapKit MKOverlay protocol, and annotations to MKAnnotation protocol. We do not currently support custom annotations or overlays, but instead will expose methods to customize specific visual properties of those items.

Usage

If creating the map widget through code it can be added using the convenience method:

- (void)installInViewController:(nullable UIViewController *)viewController

which adds the widget the method is called on as a subview of the ViewController that is passed in as an argument. Following this add constraints to the widget using it's widgetSizeHint property to determine width, height and aspect ratio constraints.

If creating the widget through storyboard use the object library to drag a container view controller into the desired view controller like so:

Following this make sure to change the class of the child view controller to be DUXBetaMapWidget. From here you can create the constraints on the container view using the Map Widget's widgetSizeHint property.

Customizations

Customizing iOS-specific map settings

The map widget is highly customizable, starting with the underlying map view. We use MKMapView from MapKit to present standard map data. Every aspect of the map view may be customized. For example, to change the type of map displayed to satellite:

Objective C

mapWidget.mapView.mapType = MKMapTypeSatellite;

Swift

mapWidget.mapView.mapType = .satellite;

Besides standard MKMapView properties, almost every aspect of added-on DJI functionality may be customized as well.

Direction to Home

Show a straight path line to the aircraft home point.

Objective C

mapWidget.showDirectionToHome = YES;

Swift

mapWidget.showDirectionToHome = true;

Flight Path

This line shows the path the aircraft has taken during its flight.

Objective C

mapWidget.showFlightPath = YES;

Swift

mapWidget.showFlightPath = true;

For both flight path and direction to home, customize the stroke thickness and color

Objective C

mapWidget.directionToHomeStrokeColor = [UIColor colorWithRed:0.83 green:0.33 blue:0.00 alpha:1.0];
mapWidget.directionToHomeStrokeWidth = 0.5f;

Swift

mapWidget.directionToHomeStrokeColor = UIColor(red: 0.83, green: 0.33, blue: 0.0, alpha: 1.0)
mapWidget.directionToHomeStrokeWidth = 0.5;

Camera Lock on Aircraft

When turned on, it will keep the map camera focused on the aircraft even as it moves or if the user adjusts the map.

Objective C

mapWidget. isMapCameraLockedOnAircraft = YES;

Swift

mapWidget. isMapCameraLockedOnAircraft = true;

Visible Fly Zones

Map widget users have access to the same fly zone database as exposed by DJIFlightZoneManager. To enable flight zones, set the visibleFlyZones property with a bitmask of the types of zones desired.

Objective C

mapWidget.visibleFlyZones = DUXBetaVisibleFlyZonesWarning;

Swift

mapWidget.visibleFlyZones = .warning;

You can also enable tap to unlock to enable unlocking functionality.

Objective C

mapWidget.tapToUnlockEnabled = YES;

Swift

mapWidget.tapToUnlockEnabled = true;

Tapping on the annotation will allow the user to unlock it if it's unlockable. Already unlocked annotations will display a callout listing the details of the unlocking.

Customizing fly zone color, alpha, and border width are all exposed by the map widget.

Objective C

[mapWidget.setFlyZoneOverlayColor:[UIColor myCustomColor] forFlyZoneCategory:DJIFlyZoneCategoryAuthorization];
[mapWidget.setFlyZoneOverlayAlpha:0.5f forFlyZoneCategory:DJIFlyZoneCategoryAuthorization];

Swift

mapWidget.setFlyZoneOverlayColor(UIColor.myCustomColor, for: .authorization)
mapWidget.setFlyZoneOverlayAlpha(0.5, for: .authorization)

Unlocked fly zones can be customized too

Custom Annotation Images

You can set custom annotation images for zones that can be unlocked, unlocked zones, and aircraft / home point locations.

Objective C

[mapWidget changeAnnotationType:DUXBetaMapAnnotationTypeEligibleFlyZones withImage:[UIImage myImage] withCenterOffset:CGPointZero];

Swift

mapWidget.changeAnnotation(of: .eligibleFlyZones, toCustomImage: UIImage.customImage, withCenterOffset: CGPointZero)

Full list of properties

List of the customizable properties
  • showFlyZoneLegend - Shows the fly zone legend. The fly zone legend indicates the color for all zone categories and self-unlock zones.
  • showDirectionToHome - A Boolean value indicating whether the map displays a line showing the direction to home.
  • isMapCameraLockedOnAircraft - A Boolean value that determines whether the map locks the camera view on the aircraft.
  • isMapCameraLockedOnHomePoint - A Boolean property that if enabled will lock map center onto aircraft home location.
  • visibleFlyZones - Sets the types of fly zones to be displayed on the map. Set to DUXBetaMapVisibleFlyZonesNone to hide all fly zone types.
  • showCustomUnlockZones - Shows custom unlock zones if any are available for the currently connected aircraft.
  • tapToUnlockEnabled - Gets whether tap to unlock is enabled.
  • showDJIAccountLoginIndicator - Show a small indicator displaying the latest DJI account login state. Useful if using FlySafe features.
  • showFlightPath - A boolean value indicating if the flight path is visible.
  • showHomeAnnotation - A boolean indicating that the home point marker is visible.
  • unlockedFlyZoneOverlayColor - Current color of a self-unlock fly zone overlay.
  • unlockedFlyZoneOverlayAlpha - Current alpha of a self-unlock fly zone overlay.
  • customUnlockFlyZoneOverlayColor - Current color of a custom unlock fly zone overlay.
  • customUnlockFlyZoneOverlayAlpha - Current alpha of a custom unlock fly zone overlay.
  • customUnlockFlyZoneSentToAircraftOverlayColor - Current color of a custom unlock fly zone overlay that has been sent to the aircraft.
  • customUnlockFlyZoneSentToAircraftOverlayAlpha - Current alpha of a custom unlock fly zone overlay that has been sent to the aircraft.
  • customUnlockFlyZoneEnabledOverlayColor - Current color of a custom unlock fly zone overlay that has been sent to aircraft and enabled.
  • customUnlockFlyZoneEnabledOverlayAlpha - Current alpha of a custom unlock fly zone overlay that has been sent to aircraft and enabled.
  • maximumHeightFlyZoneOverlayColor - Current color of a fly zone with maximum height.
  • maximumHeightFlyZoneOverlayAlpha - Current alpha of a fly zone with maximum height.
  • flyZoneOverlayBorderWidth - Width of the solid colored border of all fly zone overlays.
  • flightPathStrokeColor - Current color of the rendered flight path.
  • flightPathStrokeWidth - Current stroke width of the rendered flight path.
  • directionToHomeStrokeColor - Current color of the rendered direction to home line.
  • directionToHomeStrokeWidth - Current stroke width of the rendered direction to home line.

APIs

List of the customization APIs
  • - (void)changeAnnotationOfType:(DUXBetaMapAnnotationType)annotationType toCustomImage:(nonnull UIImage *)image withCenterOffset:(CGPoint)centerOffset - Change the annotation type of the map widget.
  • - (void)clearCurrentFlightPath - Clears the flight path up to the current location. The flight path is removed even if it is hidden.
  • - (void)syncCustomUnlockZones - Call this to sync currently shown custom unlock zones to aircraft. They will still need to be manually enabled.
  • - (void)setFlyZoneOverlayColor:(nullable UIColor *)color forFlyZoneCategory:(DJIFlyZoneCategory)category - Change the rendered color for a given fly zone category.
  • - (nonnull UIColor *)flyZoneOverlayColorForFlyZoneCategory:(DJIFlyZoneCategory)category - Returns the currently used color for a given fly zone category. This does not include unlocked zones.
  • - (void)setFlyZoneOverlayAlpha:(CGFloat)alpha forFlyZoneCategory:(DJIFlyZoneCategory)category - Change the rendered alpha for a given fly zone category.
  • - (CGFloat)flyZoneOverlayAlphaForFlyZoneCategory:(DJIFlyZoneCategory)category - Returns the currently used alpha for a given fly zone category. This does not include unlocked zones.
⚠️ **GitHub.com Fallback** ⚠️