Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Query MGLPolyline added by MGLMapView.addAnnotation() #7843

Closed
nitrag opened this issue Jan 25, 2017 · 2 comments
Closed

Query MGLPolyline added by MGLMapView.addAnnotation() #7843

nitrag opened this issue Jan 25, 2017 · 2 comments
Labels
annotations Annotations on iOS and macOS or markers on Android iOS Mapbox Maps SDK for iOS runtime styling

Comments

@nitrag
Copy link
Contributor

nitrag commented Jan 25, 2017

Because DDS is not yet implemented, I can't import GeoJSON and have the SDK automatically style the polylines.

Instead, I parse the GeoJSON manually and create individual MGLPolyLine shapes and add it to the map:

self.mapView.addAnnotation(newPolyline)

Documentation does not say what layer this shape gets added to, if any.

I would like to be able to query the newly added polyline features during a tap gesture, like my other layers:

func mapTap(recognizer: UITapGestureRecognizer) {
    func squareFrom(location: CGPoint) -> CGRect {
        let length = 10.0
        return CGRect(x: Double(location.x - CGFloat(length / 2)), y: Double(location.y - CGFloat(length / 2)), width: length, height: length)
    }
    let location = recognizer.location(in: mapView)
    let touchableSquare = squareFrom(location: location)
    let features = mapView.visibleFeatures(in: touchableSquare, styleLayerIdentifiers: ["what-is-the-default-style?"])
    ....

iOS
3.4.0-beta7

@nitrag
Copy link
Contributor Author

nitrag commented Jan 25, 2017

I should note that the generic/basic popup with the title (CalloutView?) is shown when MGLPointAnnotation is tapped, and so does this fire correctly:

func mapView(_ mapView: MGLMapView, didSelect annotationView: MGLAnnotationView) {
    print("Annotation selected")
}

but not for MGLPolyline, hence why I thought to use mapView.visibleFeatures()

@1ec5
Copy link
Contributor

1ec5 commented Jan 25, 2017

Documentation does not say what layer this shape gets added to, if any.

This is intentional; the layer identifier is an implementation detail that depends on the order in which the annotations are added.

what-is-the-default-style?

You can omit the styleLayerIdentifiers argument; by default, that method returns features in any layer that fall within the rect.

but not for MGLPolyline

This is covered by #2082. See that issue and #6505 for workarounds.

#6515 would help by providing a specialized gesture recognizer class to work with style layers.

@1ec5 1ec5 added annotations Annotations on iOS and macOS or markers on Android iOS Mapbox Maps SDK for iOS runtime styling labels Jan 25, 2017
@1ec5 1ec5 closed this as completed Jan 25, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
annotations Annotations on iOS and macOS or markers on Android iOS Mapbox Maps SDK for iOS runtime styling
Projects
None yet
Development

No branches or pull requests

2 participants