0

Is it possible to make an MGLPolyLine touchable/selectable/have user interaction? In my project, the user needs to touch the polyline. There was this question asked before but it is outdated by about 2 years. Have they (MapBox) updated this?

  • As far as I know Polyline's don't have this feature. However if you need that solution maybe you can use custom annotation, and as annotationView you can put a image which is scale as zoomIn and zoomOut. – Said Alır Feb 08 '19 at 07:15

1 Answers1

1

I've just checked back and it looks like this has been implemented though I'm not sure which Mapbox release rolled this out.

If you take a look at the simple Mapbox example, Annotation Models, that demos an MGLPolyline and interspaced circular annotations, you can make a simple mod to the supplied code and see for yourself. The demo looks like this:

enter image description here

If you look into the viewController code, add a couple of lines below the polyline creation:

let polyline = CustomPolyline(coordinates: &coordinates, count: UInt(coordinates.count))

polyline.title = "Polyline"               // New line
polyline.subtitle = "Pretty Poly".        // New line

// Set the custom `color` property, later used in the `mapView:strokeColorForShapeAnnotation:` delegate method.
polyline.color = .darkGray

Now you can tap and see a basic callout:

enter image description here

This example subclasses MGLPolyline (CustomPolyline) so that its appearance can be altered slightly but that doesn't change anything with regards to the tappability.

Magnas
  • 3,832
  • 5
  • 33
  • 48
  • is there a way to make it tappable without an annotation? –  Feb 09 '19 at 23:47
  • @user123 Please see here: https://stackoverflow.com/questions/54612568/is-it-possible-to-create-a-custom-popup-for-a-mglpolyline – Magnas Feb 10 '19 at 09:44