简体   繁体   中英

How to delete a polyline in Mapbox iOS SDK?

I can do it in Google Maps by using

polyline.map = nil 

and

mapView.clear() 

but I cannot find any relevant methods.

You can call mapView.removeAnnotation(polyline)

Where mapView is your MGLMapView and polyline is a MGLPolyline .

You will probably need to keep track of your polylines, how you do that is up to you (array, dictionary, etc)

Here is the documentation for MGLMapView if you need it

Here is a category extension method for MGLMapView that I am using. Its just like Google Maps SDK , so its easier to use anywhere in your project.

- (void)clear {
    if (self.annotations.count > 0) {
        NSArray *annotations = self.annotations;
        [self removeAnnotations:annotations];
    }
}

You can use it like

[self.mapView clear];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM