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.

Add Marker anchor points #2916

Closed
Closed

Description

@ljbade

Currently due to lack of support in core GL layer, we don't support anchor() with Marker. An anchor is a custom point in the Marker image (using a GL texture like coordinate system of 0 to 1) where we assign the Markers 'position()` to.

Currently we just use the centre of the image. You can see this is the default red marker image which is twice as high as needed (and padded with transparent pixels) to push the tip of the marker to the image centre. A anchor function would remove the need for this padding.

However this is not currently on our core GL roadmap.

A similar infoWindowAnchor() function would be easy to implement currently as it would only require changes to Java.

Activity

  1. added
    Android
    on Nov 3, 2015
  2. ljbade commented on Nov 3, 2015

    @ljbade
    ContributorAuthor
  3. thatsvishalhere commented on Dec 29, 2015

    @thatsvishalhere

    Hi, I was working on an Android app and experimenting with somewhat bigger markers on Mapbox maps with images. Since the marker is fairly big (having a big marker is kind of necessary for the app. I just need 1 marker for the map and no marking of routes involved), I would definitely need the anchor for the marker. The big marker currently gets a very inaccurate position on the map and gets worse while zooming in/out of the map in different views. Is there any workaround regarding the same? Any help would be appreciated. Thanks! :)

  4. added this to the android-v3.1.0 milestone on Jan 4, 2016
  5. tobrun commented on Jan 4, 2016

    @tobrun
    Member

    @thatsvishalhere
    Thank you for reaching out and highlighting this issue.

    • Are you able to share that image you are referring to?
    • or share the details (height/width)?

    It will help a lot when trying to implement the feature / resolve the incorrect positioning,

  6. thatsvishalhere commented on Jan 4, 2016

    @thatsvishalhere

    Hi, thanks for your reply. I'm using markers of height more than 48 dp. For example you may consider this marker, https://github.com/google/material-design-icons/blob/master/navigation/drawable-mdpi/ic_arrow_downward_black_48dp.png. I can't anchor the lowermost tip of the marker to a particular point in the map. Since I want to show the correct point on the map with the lowermost tip and the anchor is of the image is set to the middle of the icon, I can't really show the right location on the map. The lower most point on the icon is pointing to different locations on the map on zoom in/out and rotation of the map.

  7. friedbunny commented on Jan 4, 2016

    @friedbunny
    Contributor

    The (already mentioned) workaround here is to double the height of your marker asset, such that the desired anchor is also the true center. This is how our marker images currently work.

  8. thatsvishalhere commented on Jan 4, 2016

    @thatsvishalhere

    Thanks for your response. I'm doing exactly that for the workaround. I was just worried if clicking on the empty space would also trigger the onMarkerClick actions. But, so far there haven't been any issues. :)

    Just for reference, if somebody else is looking for a hack and lands on this thread, this is the code I'm using:

    public static Bitmap mapboxHackIcon(Bitmap icon){
            Bitmap loc_img = Bitmap.createBitmap(icon.getWidth(), 2*icon.getHeight(), Bitmap.Config.ARGB_8888);
            Canvas bitmapCanvas = new Canvas(loc_img);
            Bitmap tempBitmap = icon.copy(Bitmap.Config.ARGB_8888, false);
            bitmapCanvas.drawBitmap(tempBitmap, 0, 0, null);
            return loc_img;
        }
    

    Thanks again for your response!

  9. removed this from the android-v4.0.0 milestone on Mar 5, 2016
  10. added this to the android-v4.1.0 milestone on Mar 6, 2016
  11. 1 remaining item

  12. modified the milestone: android-v4.1.0 on Mar 18, 2016
  13. added this to the android-v4.1.0 milestone on Apr 4, 2016
  14. tobrun commented on Apr 4, 2016

    @tobrun
    Member

    I'm picking this up, since this is a blocker for #3643 and a highly requested feature.

  15. tobrun commented on Apr 4, 2016

    @tobrun
    Member

    Looking into this, I feel the only real good solution would be a feature in core.
    We could go with a hack as suggested above but this will be not very efficient.
    I need to check what status is for core GL roadmap on this feature.

  16. bleege commented on Apr 4, 2016

    @bleege
    Contributor

    Looking into this, I feel the only real good solution would be a feature in core.

    👍

  17. added
    iOS
    Core
    on Apr 4, 2016
  18. brunoabinader commented on Apr 5, 2016

    @brunoabinader
    Contributor

    Looking into this, I feel the only real good solution would be a feature in core.

    After discussing this with @tobrun, I propose the following:

    • Replace Map::getTopOffsetPixelsForAnnotationIcon withMap::getAnnotationIconOrigin, with origin being a ScreenCoordinate to comply with both axis customization.
    • Add an optional anchor parameter to addAnnotationIcon, which will be the return value for the function suggested above, being the top left position the fallback value.
  19. jfirebaugh commented on Apr 5, 2016

    @jfirebaugh
    Contributor

    This comment from the related iOS issue is relevant.

    The "right way" to implement this is via the icon-offset or icon-translate style properties. But in order to control those per-annotation, we need either data-driven styles or control over annotation grouping into layers.

  20. tobrun commented on Apr 6, 2016

    @tobrun
    Member

    @jfirebaugh thank you for the 👀, will not work or ping people for this or similar issues until the dust from implementing the style api has settled.

  21. removed this from the android-v4.1.0 milestone on May 4, 2016
  22. tobrun commented on Jun 21, 2016

    @tobrun
    Member

    Closing as it will be automatically be picked up again with style api and we have a workaround with view annotations in place.

  23. andre99 commented on Jul 17, 2016

    @andre99

    Just in case someone comes across this and needs it working on v4.1.0, I have found a solution.

    If you call MarkerViewManager.ensureInfoWindowOffset() with the marker that you've just added it will add the marker correctly.

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

    AndroidCorefeatureiOS

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions