1

I have my own custom subclass of MGLPointFeature. I create a source for my instances like so:

let myAnnotations: [MySubclassType] = /* code that generates those annotations */
let source = MGLShapeSource(identifier: "some_identifier",
                            features: myAnnotations,
                            options: [.clustered: true, .clusterRadius: 40])

I also add a MGLSymbolStyleLayer that now displays those annotations.

Everything works as expected. My MGLMapView properly shows my annotations. Nice! Check!

So now I'd love to know when a user taps on them. (Note that I cluster my annotations, so adding them separately to the mapView does not work.)

Ok... So now I detect the tap like so:

let rect = CGRect(x: tapPoint.x, y: tapPoint.x, width: 0, height: 0).insetBy(dx: -10, dy: -10)
// I inset it so that the user does not have to be thaaaat super accurate
let features = mapView.visibleFeatures(in: rect)

So now I get those features below my finger. Also still fine! BUT.... I'd expect that feature to be of type MySubclassType as I added that one to the map. But instead it is of type MGLPointFeature. So I guess Mapbox somehow copies my custom PointFeature to a regular one?

So... my question is... how to I get to the instance of the point-feature that I created (where I attached additional information that I'd like to know). I know that I can simply add them to the attributes field, but then I'd need to query my data again... Is there no easier way?

Also... If I style my points a bit more, having 2-3 layers for it (background and icon f.e.) I get multiple instances of my MGLPointFeature... is this intended to be that way?

riastrad
  • 1,624
  • 10
  • 22
Georg
  • 3,664
  • 3
  • 34
  • 75

1 Answers1

0

Maybe it is like a uitableviewcell where you cast it to your own custom cell to access your attributes?

malaki1974
  • 1,605
  • 3
  • 16
  • 32