maplibre-native icon indicating copy to clipboard operation
maplibre-native copied to clipboard

Metal branch (5.12.0-pre.1) doesn't show custom annotation view

Open mehlkelm opened this issue 3 years ago • 12 comments

Hi – First: Wow the performance of the metal branch is amazing! Looking forward to it.

I can't get it to show custom annotation views, though. The sample UIViewController below shows the annotation under MapLibre 5.11 (iOS) and doesn't show it on 5.12.0-pre.1 (tried with different style URLs, use one where you have access to the sources).

import UIKit
import Mapbox

class ViewController: UIViewController, MGLMapViewDelegate {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        let mapView = MGLMapView(frame: view.bounds, styleURL: Bundle.main.url(forResource: "maptiler-demo-style", withExtension: "json")!)
        mapView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
        mapView.delegate = self
        view.addSubview(mapView)
    }
    
    func mapViewDidFinishLoadingMap(_ mapView: MGLMapView) {
        let test = MyAnnotation(coordinate: CLLocationCoordinate2D(latitude: 47.356, longitude: 8.530))
        mapView.addAnnotations([test])
        mapView.setCenter(test.coordinate, zoomLevel: 13, animated: true)
    }
    
    func mapView(_ mapView: MGLMapView, viewFor annotation: MGLAnnotation) -> MGLAnnotationView? {
        if annotation is MyAnnotation {
            let view = MyAnnotationView(annotation: annotation, reuseIdentifier: "AnnotationView")
            return view
        }
        return nil
    }
}

class MyAnnotation: NSObject, MGLAnnotation {
    var ID = UUID()
    var coordinate: CLLocationCoordinate2D

    init(coordinate: CLLocationCoordinate2D) {
        self.coordinate = coordinate
        super.init()
    }
}

class MyAnnotationView: MGLAnnotationView {
    override init(annotation: MGLAnnotation?, reuseIdentifier: String?) {
        super.init(annotation: annotation, reuseIdentifier: reuseIdentifier)
        let size = CGSize(width: 40, height: 40)
        let origin = CGPoint(x: 0, y: 0)
        frame = CGRect(origin: origin, size: size)

        let image = UIImageView(image: UIImage(systemName: "doc.fill"))
        image.tintColor = .blue
        image.frame = CGRect(origin: .zero, size: size)
        addSubview(image)
    }
        
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}

mehlkelm avatar Jun 14 '21 10:06 mehlkelm

Same issue here. The annotations are rendered under the map. When running the app the map seems to be empty, but by debugging the view hierarchy you can see that the annotations are rendered underneath.

ChristianVinterly avatar Jun 16 '21 08:06 ChristianVinterly

Thanks for reporting the issue. AFAIK @roblabs and @sulewicz are going to work on these but pull requests are welcome if you would like to contribute. There are failed tests related to annotations listed as known issues in the pre-release which needs to be fixed too. https://github.com/maplibre/maplibre-gl-native/releases/tag/ios-v5.12.0-pre.1

petr-pokorny-1 avatar Jun 16 '21 08:06 petr-pokorny-1

@mehlkelm, @ChristianVinterly - there is new beta release where this issue should be fixed. Cloud you please test it?

https://github.com/maplibre/maplibre-gl-native/releases/tag/ios-v5.13.0-pre.1 and https://github.com/maplibre/maplibre-gl-native-distribution/releases/tag/5.13.0-pre.1

petr-pokorny-1 avatar Jul 06 '21 09:07 petr-pokorny-1

I just tested it. Custom annotation views are now visible, but: In contrast to the increased map display performance, the performance of the annotation views is much worse than before the Metal version.

https://user-images.githubusercontent.com/4712931/124601397-124e0480-de68-11eb-9186-201818cc653d.mov

https://user-images.githubusercontent.com/4712931/124601417-1712b880-de68-11eb-96df-ee51a8445b6a.mov

(Edit: That's on an iPhone X running the test 'app' from above)

mehlkelm avatar Jul 06 '21 12:07 mehlkelm

Thanks @mehlkelm! @roblabs @sulewicz could you please take a look?

petr-pokorny-1 avatar Jul 06 '21 12:07 petr-pokorny-1

Thanks for the video! Yes, we will have a look.

sulewicz avatar Jul 06 '21 19:07 sulewicz

@sulewicz @petr-pokorny-1 @roblabs Could the metal annotation performance issue be the same as #46? The fix for it has been merged to master but not to metal branch as there was this issue. I haven't unfortunately yet had chance to check the issue of merging to metal.

juhieta avatar Aug 13 '21 05:08 juhieta

Hi @juhieta! Yes that may be the case. I had a look recently but could not reproduce the problem. I will have a look on different devices and once I repro I will check if https://github.com/mapbox/mapbox-gl-native-ios/pull/411/files fixes it.

sulewicz avatar Aug 17 '21 16:08 sulewicz

I tried to backport https://github.com/mapbox/mapbox-gl-native-ios/pull/411/commits/02ad17432857e55fee19e849c7ca46dcfa63d61b to Metal branch and I experienced the same assertion error that Petr ran into. Disabling the assertion causes crashes. Most likely caused by different initialization order in Metal-based views, I will investigate further.

sulewicz avatar Aug 17 '21 20:08 sulewicz

Ok, thanks a lot @sulewicz!

juhieta avatar Aug 19 '21 04:08 juhieta

Small update on this. The key is to enable presentsWithTransactions in the Metal layer, which isn't currently supported out of the box in MetalANGLE. I did a quick proof of concept implementation with this patch and it looks as shown in this video. However, the map sometimes stutters when panned, which is less than ideal.

sulewicz avatar Sep 15 '21 04:09 sulewicz

Ok, good progress @sulewicz and I'm not sure if this is even a blocker for Metal release as the MGLSymbolStyleLayer and MGLShapeSource should work better for most use cases and are also better performing option in general.

juhieta avatar Sep 16 '21 12:09 juhieta

Metal is now being implemented using an alternate approach, namely using a rendering backend that uses Metal-cpp directly.

Progress can be tracked here: https://github.com/orgs/maplibre/projects/8

louwers avatar Aug 07 '23 10:08 louwers