@@ -1335,14 +1335,30 @@ open class NavigationMapView: UIView {
1335
1335
1336
1336
if let lastLeg = route. legs. last,
1337
1337
let destinationCoordinate = lastLeg. destination? . coordinate {
1338
- addDestinationAnnotation ( destinationCoordinate)
1338
+ addDestinationAnnotation ( destinationCoordinate) { [ weak self] in
1339
+ guard self != nil else { return }
1340
+ }
1339
1341
}
1340
1342
}
1341
1343
1342
- func addDestinationAnnotation( _ coordinate: CLLocationCoordinate2D ,
1343
- identifier: String = NavigationMapView . AnnotationIdentifier. finalDestinationAnnotation) {
1344
+ /**
1345
+ Adds a final destination annotation to the map.
1346
+
1347
+ - parameter coordinate: Coordinate which represents the annotation location.
1348
+ - parameter identifier: String to uniquely identify the destination annotation. Defaults to `nil` and a default identifier will be provided.
1349
+ - parameter styleLoaded: An escaping closure to be executed when the `MapView` style has finished loading.
1350
+ */
1351
+ public func addDestinationAnnotation( _ coordinate: CLLocationCoordinate2D ,
1352
+ identifier: String ? = nil ,
1353
+ styleLoaded: @escaping ( ) -> Void ) {
1354
+ let identifier = identifier ?? String ( " finalDestinationAnnotation_ \( finalDestinationAnnotations. count) " )
1344
1355
var destinationAnnotation = PointAnnotation ( id: identifier, coordinate: coordinate)
1345
1356
destinationAnnotation. image = . init( image: . defaultMarkerImage, name: ImageIdentifier . markerImage)
1357
+
1358
+ mapView. mapboxMap. onNext ( event: . styleLoaded) { [ weak self] _ in
1359
+ guard self != nil else { return }
1360
+ styleLoaded ( )
1361
+ }
1346
1362
1347
1363
// If `PointAnnotationManager` is available - add `PointAnnotation`, if not - remember it
1348
1364
// and add it only after fully loading `MapView` style.
@@ -1356,12 +1372,19 @@ open class NavigationMapView: UIView {
1356
1372
}
1357
1373
}
1358
1374
1359
- func removeDestinationAnnotation( _ identifier: String = NavigationMapView . AnnotationIdentifier. finalDestinationAnnotation) {
1360
- let remainingAnnotations = pointAnnotationManager? . annotations. filter {
1361
- $0. id != identifier
1375
+ /**
1376
+ Removes a final destination annotation to the map.
1377
+
1378
+ - parameter identifier: String to uniquely identify the destination annotation to be removed. Defaults to `nil` and removes all destination annotations.
1379
+ */
1380
+ public func removeDestinationAnnotation( _ identifier: String ? = nil ) {
1381
+ if let identifier {
1382
+ finalDestinationAnnotations. removeAll ( where: { $0. id == identifier } )
1383
+ pointAnnotationManager? . annotations. removeAll ( where: { $0. id == identifier } )
1384
+ } else {
1385
+ finalDestinationAnnotations. removeAll ( where: { $0. id. contains ( " finalDestinationAnnotation " ) } )
1386
+ pointAnnotationManager? . annotations. removeAll ( where: { $0. id. contains ( " finalDestinationAnnotation " ) } )
1362
1387
}
1363
-
1364
- pointAnnotationManager? . annotations = remainingAnnotations ?? [ ]
1365
1388
}
1366
1389
1367
1390
/**
0 commit comments