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

PointAnnotations not showing #1883

Closed
Closed

Description

@ohlsont

I'm having problems with PointAnnotations not showing up

This code ends up not showing some of the markers

func mapView(mapView: MGLMapView, imageForAnnotation annotation: MGLAnnotation) -> MGLAnnotationImage? {
        if let an = annotation as? TFPointAnnotation {
            if var image = mapView.dequeueReusableAnnotationImageWithIdentifier(an.id) {
                return image
            } else {
                if let title = an.title {
                    return makeImage(title, reuseIdentifier: an.id)
                } else {
                    lg.debug("no title \(an.id)")
                }
            }
        } else {
            lg.debug("not a TFPoint")
        }
        return nil
    }

    func makeImage(title: String, reuseIdentifier: String) -> MGLAnnotationImage {
        let rect = CGRectMake(0, 0, 50, 15);
        UIGraphicsBeginImageContextWithOptions(rect.size, false, UIScreen.mainScreen().scale);
        let ctx = UIGraphicsGetCurrentContext();
        CGContextSetFillColorWithColor(ctx, UIColor.clearColor().CGColor);
        CGContextFillRect(ctx, rect);
        var attrs = [String : AnyObject]()
        attrs[NSFontAttributeName] = UIFont(name: "Arial-BoldMT", size: 12)
        attrs[NSForegroundColorAttributeName] = UIColor.blackColor()

        let drawString = NSAttributedString(string: title, attributes: attrs)
        let stringSize = drawString.size();
        let stringRect = CGRectMake((rect.size.width - stringSize.width) / 2,
            (rect.size.height - stringSize.height) / 2,
            stringSize.width,
            stringSize.height);
        drawString.drawInRect(stringRect)


        let image = MGLAnnotationImage(image: UIGraphicsGetImageFromCurrentImageContext(), reuseIdentifier: reuseIdentifier)
        UIGraphicsEndImageContext()
        return image
    }

ios simulator screen shot 13 jul 2015 09 56 03

This code shows markers on all positions but only using the same reuseidentifier

func mapView(mapView: MGLMapView, imageForAnnotation annotation: MGLAnnotation) -> MGLAnnotationImage? {
        if let an = annotation as? TFPointAnnotation {
            if var image = mapView.dequeueReusableAnnotationImageWithIdentifier(an.id) {
                return image
            } else {
                if let title = an.title {
                    return makeImage("bajs", reuseIdentifier: "bajs")
                } else {
                    lg.debug("no title \(an.id)")
                }
            }
        } else {
            lg.debug("not a TFPoint")
        }
        return nil
    }

    func makeImage(title: String, reuseIdentifier: String) -> MGLAnnotationImage {
        let rect = CGRectMake(0, 0, 50, 15);
        UIGraphicsBeginImageContextWithOptions(rect.size, false, UIScreen.mainScreen().scale);
        let ctx = UIGraphicsGetCurrentContext();
        CGContextSetFillColorWithColor(ctx, UIColor.clearColor().CGColor);
        CGContextFillRect(ctx, rect);
        var attrs = [String : AnyObject]()
        attrs[NSFontAttributeName] = UIFont(name: "Arial-BoldMT", size: 12)
        attrs[NSForegroundColorAttributeName] = UIColor.blackColor()

        let drawString = NSAttributedString(string: title, attributes: attrs)
        let stringSize = drawString.size();
        let stringRect = CGRectMake((rect.size.width - stringSize.width) / 2,
            (rect.size.height - stringSize.height) / 2,
            stringSize.width,
            stringSize.height);
        drawString.drawInRect(stringRect)


        let image = MGLAnnotationImage(image: UIGraphicsGetImageFromCurrentImageContext(), reuseIdentifier: reuseIdentifier)
        UIGraphicsEndImageContext()
        return image
    }

ios simulator screen shot 13 jul 2015 09 57 54

Why is this happening?

Activity

  1. nulvinge commented on Jul 22, 2015

    @nulvinge
    Contributor

    Looks like this:
    output

    The solution is only exposed in the android code as of now.

  2. nulvinge commented on Jul 22, 2015

    @nulvinge
    Contributor

    This problem is the related to #141, sprite atlas overflow. By using the glyph atlas the problem is eliminated for this problem set.

  3. ljbade commented on Aug 10, 2015

    @ljbade
    Contributor

    @1ec5 Do you understand what is happening here and in #2019?

  4. ohlsont commented on Aug 19, 2015

    @ohlsont
    Author

    Could it be that only some set amount of sprites are possible?
    could the problem be in one of the sprites functions here somewhere?

  5. jfirebaugh commented on Feb 8, 2017

    @jfirebaugh
    Contributor

    For display of many point features with distinct text, we recommend using MGLSymbolStyleLayer, which allows precise control over text content, font face, size, and other properties via the runtime styling APIs.

    We'll continue to track the issue of many distinct annotation images in #3185.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions