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.

Offset map center #2600

Closed
Closed

Description

@maciekish

Hi,
Is it possible to easily offset what the map treats as it centre? We want the map to follow the users position more like a navigation app where the "car" is much lower on the screen so that you can see further ahead.

I've looked for a value that defines the center but wasn't able to find anything. We have our own fork so it doesn't matter what the change is as long as it's possible.

Thanks
Maciej

Activity

  1. picciano commented on Oct 13, 2015

    @picciano

    +1

  2. Zakay commented on Oct 13, 2015

    @Zakay

    +1 Both Apple and Google uses this offset thing on their map apps. Would be very useful to have!

  3. added
    iOS
    on Oct 13, 2015
  4. ljbade commented on Oct 13, 2015

    @ljbade
    Contributor

    /cc @1ec5

  5. incanus commented on Oct 15, 2015

    @incanus
    Contributor

    Both Apple and Google uses this offset thing on their map apps.

    Just to clarify, this is in their own user-facing apps, not their developer-facing frameworks.

    But agree.

  6. 1ec5 commented on Nov 9, 2015

    @1ec5
    Contributor

    This is in some ways blocked by #1041: currently “user tracking” consists of moving the user dot in response to user location changes, then synchronizing the map’s center point in response. A better approach would be to affix the user dot to a set location on-screen (usually the center point but in this case somewhere near the bottom) and pan the map directly in response to user location changes. The logic in -[MGLMapView locationManager:didUpdateLocations:] may need to be rewritten, especially due to tilting, which is typically used with course tracking mode.

  7. ljbade commented on Nov 9, 2015

    @ljbade
    Contributor

    @1ec5 Glueing the dot to the screen centre then moving the map was the approach @tobrun took in the Android code.

  8. RomainQuidet commented on Dec 9, 2015

    @RomainQuidet
    Contributor

    Apple MapKit uses 2 APIs for this using insets:

    • (void)setVisibleMapRect:(MKMapRect)mapRect
      edgePadding:(UIEdgeInsets)insets
      animated:(BOOL)animate

    and

    • (MKMapRect)mapRectThatFits:(MKMapRect)mapRect
      edgePadding:(UIEdgeInsets)insets
  9. 1ec5 commented on Dec 9, 2015

    @1ec5
    Contributor

    We have -setVisibleCoordinateBounds:edgePadding:animated: already; a -coordinateBoundsThatFits:edgePadding: would certainly complement it. But I think this request is more about having MGLMapView offset the center when automatically panning due to user location tracking.

    One thing I’m stuck on is how best to present this option to developers: should it be a percentage or an absolute pixel? Should we measure from the view’s edge to the annotation view’s edge, or to its center? The thought crossed my mind of allowing the annotation view to be constrained using Auto Layout – the map view would effectively pin the map view to the annotation – but maybe that’d be too difficult to work with.

  10. RomainQuidet commented on Dec 9, 2015

    @RomainQuidet
    Contributor

    Ok, it's something not available on Apple MapKit. We have this feature on our map at Mappy, we just expose a property to users in the framework:
    @Property (nonatomic, assign) UIEdgeInsets insets;

    This inset is used when centering the map at coordinates or at the user position or when setting the region.
    This allow users to offset the center easily, add other views above the map and keep the map's center where it should be.
    Internal code is quite clean by using the insets property to compute the map center.

  11. 1ec5 commented on Dec 9, 2015

    @1ec5
    Contributor

    So if you have course tracking on and want to push the puck down to the bottom, as depicted in #2600 (comment), you’d set a very large top inset, correct? That sounds reasonable. In fact, under the hood, we’ll want methods like -setCenterCoordinate: to respect an implicit top or bottom inset whenever there’s a top or bottom layout guide.

  12. RomainQuidet commented on Dec 9, 2015

    @RomainQuidet
    Contributor

    Yes, it's working like that.
    User defines a mapView frame, and then sets an inset. The frame displays a full map, centered on the inset rectangle center.

  13. added
    macOS
    on Dec 14, 2015
  14. 1ec5 commented on Dec 14, 2015

    @1ec5
    Contributor

    Both the iOS and OS X versions of MGLMapView need this functionality regardless of the user tracking mode, because it’s common for there to be a translucent top bar overlay. On iOS, MGLMapView’s center should account for the top and bottom layout guides; on OS X, if the MGLMapView occupies the entire content view and the content view is full size, the center should account for the toolbar.

  15. 11 remaining items

  16. added a commit that references this issue on Jan 17, 2016
    176a333
  17. 1ec5 commented on Jan 17, 2016

    @1ec5
    Contributor

    #3583 adds content insets and shifts the map’s visual center point to account for any translucent top and bottom bars.

    #3589 pushes the visual center even further downward in course tracking mode. Note that in both Apple’s Maps application and Google Maps, the user puck is only offset in turn-by-turn mode, but not before you complete the first step (e.g., leaving the parking lot). So the puck’s position will be configurable.

  18. 1ec5 commented on Apr 22, 2016

    @1ec5
    Contributor

    We have -setVisibleCoordinateBounds:edgePadding:animated: already; a -coordinateBoundsThatFits:edgePadding: would certainly complement it.

    Implemented in #4790.

  19. leonardodev commented on Jan 16, 2018

    @leonardodev
    • (void)mapView:(MKMapView*)mapView didSelectAnnotationView:(YLAnnotationView*)pinView
      {
      [self moveCenterByOffset:CGPointMake(0, -100) from:pAnnotation.coordinate];
      }

    where

    • (void)moveCenterByOffset:(CGPoint)offset from:(CLLocationCoordinate2D)coordinate
      {
      CGPoint point = [self.oMapView convertCoordinate:coordinate toPointToView:self.oMapView];
      point.x += offset.x;
      point.y += offset.y;
      CLLocationCoordinate2D center = [self.oMapView convertPoint:point toCoordinateFromView:self.oMapView];
      [self.oMapView setCenterCoordinate:center animated:YES];
      }
  20. 1ec5 commented on Jan 16, 2018

    @1ec5
    Contributor

    @leonardodev, panning to fit a selected annotation is unrelated to this issue, but it would be great for the SDK to have that functionality built in: #3249.

  21. Michael11358 commented on Mar 4, 2018

    @Michael11358

    @leonardodev Great solution, but it doesn't take into account different zoom levels. If I'm on a different zoom level, the coordinate point messes up. Any suggestions to fix that?

  22. surfnrad commented on Oct 15, 2020

    @surfnrad

    I'm confused about whether this was answered for Android. It seems that it was achieved as a feature for iOS. Any insights to Android, particularly Kotlin? Is this possible with Mapbox Maps SDK or is it necessary to switch to Navigation UI?

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

Metadata

Metadata

Assignees

Labels

AndroidfeatureiOSmacOS

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions