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.

iOS Annotation view sticked at the left of the screen when dragging map #8603

Closed

Description

@evgzor

Hello,

I have a strange behavior on 3.5.0 release for the map with annotations like:
screen shot 2017-03-31 at 18 40 21
Please also look attached video.
I just drag the map to the left and it appears new annotation from the left side. Before 3.3.4 I did not have such issues. Probably u had similar problem before?

Platform:
iOS 10.2
Mapbox SDK version:
3.5.0

Steps to trigger behavior

  1. Load map with annotations with custom pictures
  2. Drug map to left corner so like annotation will be out of map edge.
  3. Observe the result

Expected behavior

No side effect from dragging and all annotations on the same place.

Actual behavior

Appears annotation which was out of map edge.
MapBox issue.zip

Activity

  1. added
    iOS
    on Mar 31, 2017
  2. added
    annotations
    on Mar 31, 2017
  3. fabian-guerra commented on Mar 31, 2017

    @fabian-guerra
    Contributor

    Hi @evgzor sorry to hear you are having issues with the latest iOS SDK release, if you can provide a code example that help us reproduce the problem, would likely help us solve this issue faster.

    Thank you.

  4. evgzor commented on Apr 1, 2017

    @evgzor
    Author

    Hi @fabian-guerra I attached code source
    AnnotationViewMultipleExample.m.zip from Mapbox example project with simulated problem. Please have a look. If u need full project u may check out from https://github.com/rmnblm/Mapbox-iOS-Examples.git and replace modified file. For reproducing just drag map to the left edge from the scope of annotation region. and u will see the problem.

  5. changed the title [-]iOS Annotation view sticked at the left of the screen when drugging map[/-] [+]iOS Annotation view sticked at the left of the screen when dragging map[/+] on Apr 2, 2017
  6. added this to the ios-v3.5.1 milestone on Apr 3, 2017
  7. fabian-guerra commented on Apr 3, 2017

    @fabian-guerra
    Contributor

    Hi @evgzor thank you for sending an example, I'm able to see the problem. One more question did you updated the SDK from 3.3.4 to 3.5.0?

    Thanks again!

  8. evgzor commented on Apr 3, 2017

    @evgzor
    Author

    Hi @fabian-guerra right, I updated from 3.3.4 to 3.5.0 for getting MGLStyle API. However, I observed the same problem on 3.4.2 SDK. Do u still need more info from my side?

  9. fabian-guerra commented on Apr 3, 2017

    @fabian-guerra
    Contributor

    Hi @evgzor we have found the issue. When you create a custom MGLAnnotationView you need to set the frame, you can see something because the UIImageView automatically sizes itself to fit the UIImage.

    You can fix this by setting the frame e.g annotationView.frame = imageView.frame;

    /cc @boundsj

  10. boundsj commented on Apr 3, 2017

    @boundsj
    Contributor

    #5469 would simplify this use case by providing an image property that could be set to a UIImage. MGLAnnotationView would add the image and size itself appropriately (the work that is currently being almost done in the example noted here)

  11. evgzor commented on Apr 3, 2017

    @evgzor
    Author

    @fabian-guerra if I set frame like (0,0,1,1) the issue does not fix and if i set annotationView.frame = imageView.frame; -- I get
    screenshot 2017-04-03 22 04 37 and it make problem bigger.
    @boundsj I have implemented own image property for 3.3.4 - and it worked ok till but it works in a little bit different way. I cannot easily use to new approach. It very difficult adopt application when u start to change behavior. From my point of view it's a bug if I cannot use annotation with zero frames (as it was before). You closed it without getting any feedback.
    If it's easier for you, ok ...

  12. boundsj commented on Apr 3, 2017

    @boundsj
    Contributor

    I'm sorry the workaround in #8603 (comment) did not work for you @evgzor.

    In 3.4.0, we made some performance improvements to the way annotation views get updated when the map moves. A side effect of the improvements is that we no longer handle this case where the MGLAnnotationView is not large enough to contain its subviews.

    We could add logic to the SDK to re-enable support for this by special casing invisible MGLAnnotationViews and always moving them but that would not solve for MGLAnnotationViews that are still visible but smaller than their content. Another option might be to add logic to dig through all of the subviews that an MGLAnnotationView has and determine a sort of sizeThatFits and use that for the view update calculation. However, I'm concerned about introducing another performance degradation by doing that.

    I can say that simply using (0,0,1,1) as the frame won't work (although it might if your UIImageView were much smaller).

    I'm not sure why setting MGLAnnotationView's width and height to be big enough to contain the UIImageView does not work for you. When I try that with your example it appears to work fine.

    That is:

    UIImage *image = [UIImage imageNamed:@"lighthouse"];
    UIImageView* imageView = [[UIImageView alloc] initWithImage:image];
    CGRect annotationViewFrame = CGRectMake(0, 0, CGRectGetWidth(imageView.frame), CGRectGetHeight(imageView.frame));
    annotationView.frame = annotationViewFrame;
    [annotationView addSubview:imageView];

    Looks like:

    annotation

    Can you please show a code sample where you set the annotation view's width and height to be the same as the image view and say more about why this make the problem worse for you?

  13. fabian-guerra commented on Apr 3, 2017

    @fabian-guerra
    Contributor

    Hi @evgzor sorry that #8603 (comment) didn't work for you. Complementing what I said you can use a parent view that fits the UIView subview combined withMGLAnnotationView.centerOffset e.g.

    annotationView.centerOffset = CGVectorMake(0, -CGRectGetHeight(imageView.frame)/2.0);

    This will help you fix the offset you see in #8603 (comment).

  14. evgzor commented on Apr 4, 2017

    @evgzor
    Author

    @boundsj and @fabian-guerra for the moment I fixed like that: frame = CGRect(x: 0, y: 0, width: 4, height: 0). and overide centerOffset self.centerOffset = CGVector(dx: self.centerOffset.dx + self.bounds.width / 2 - .... Its workaround, but for complex annotation view which contains several views (not only image view) I have to use that approach. In general it implemented for SDK which can swith between MKMapView and MapBox map, by toggle and I have to always alighn high level api.

  15. removed this from the ios-v3.5.1 milestone on Apr 4, 2017
  16. cansurmeli commented on Apr 8, 2017

    @cansurmeli

    I'm trying to implement a custom MGLAnnotationView on iOS with Swift as well. And this issue seems to be continuing even on SDK 3.5.2.

    Besides the annotation locations not updating continuously along with the map view, when the map view is initially launched, the annotations appear after a delay of couple of seconds but not immediately.

  17. reopened this on May 8, 2017
  18. boundsj commented on May 10, 2017

    @boundsj
    Contributor

    This should be fixed in the Mapbox iOS v3.5.4 release

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

Metadata

Metadata

Assignees

Labels

annotationsbugiOS

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions