This repository was archived by the owner on Aug 8, 2023. It is now read-only.
Repository navigation
This repository was archived by the owner on Aug 8, 2023. It is now read-only.
PointAnnotations not showing #1883
Copy link
Copy link
Closed
Labels
Description
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
}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
}Why is this happening?


Activity
nulvinge commentedon Jul 22, 2015
Looks like this:

The solution is only exposed in the android code as of now.
nulvinge commentedon Jul 22, 2015
This problem is the related to #141, sprite atlas overflow. By using the glyph atlas the problem is eliminated for this problem set.
ljbade commentedon Aug 10, 2015
@1ec5 Do you understand what is happening here and in #2019?
ohlsont commentedon Aug 19, 2015
Could it be that only some set amount of sprites are possible?
could the problem be in one of the sprites functions here somewhere?
jfirebaugh commentedon Feb 8, 2017
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.