You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
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.
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.
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.
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.
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.
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.
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.
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.
#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.
@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.
@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?
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?
Activity
picciano commentedon Oct 13, 2015
+1
Zakay commentedon Oct 13, 2015
+1 Both Apple and Google uses this offset thing on their map apps. Would be very useful to have!
ljbade commentedon Oct 13, 2015
/cc @1ec5
incanus commentedon Oct 15, 2015
Just to clarify, this is in their own user-facing apps, not their developer-facing frameworks.
But agree.
1ec5 commentedon Nov 9, 2015
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.ljbade commentedon Nov 9, 2015
@1ec5 Glueing the dot to the screen centre then moving the map was the approach @tobrun took in the Android code.
RomainQuidet commentedon Dec 9, 2015
Apple MapKit uses 2 APIs for this using insets:
edgePadding:(UIEdgeInsets)insets
animated:(BOOL)animate
and
edgePadding:(UIEdgeInsets)insets
1ec5 commentedon Dec 9, 2015
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.
RomainQuidet commentedon Dec 9, 2015
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.
1ec5 commentedon Dec 9, 2015
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.RomainQuidet commentedon Dec 9, 2015
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.
1ec5 commentedon Dec 14, 2015
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.
11 remaining items
[ios] Affix user dot on screen in user tracking mode
1ec5 commentedon Jan 17, 2016
#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.
[core] Added padding option to CameraOptions
[ios] Affix user dot on screen in user tracking mode
[ios] Affix user dot on screen in user tracking mode
[ios] Affix user dot on screen in user tracking mode
[ios] Affix user dot on screen in user tracking mode
1ec5 commentedon Apr 22, 2016
Implemented in #4790.
leonardodev commentedon Jan 16, 2018
{
[self moveCenterByOffset:CGPointMake(0, -100) from:pAnnotation.coordinate];
}
where
{
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];
}
1ec5 commentedon Jan 16, 2018
@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.
Michael11358 commentedon Mar 4, 2018
@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?
surfnrad commentedon Oct 15, 2020
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?