-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Jump to style’s default viewport on initialization #6129
Comments
Linking the related properties van style spec here
For Android this would work as well, this requirement fits well in the Android concept of API wise, how do you see this happening? add parameters to update: dependency on the following PR #6046 |
Ideally there would be no API change, even at the core level. Core would jump to the default viewport internally upon loading the first style. Only the first style ever loaded would ever cause a jump, and setters on mbgl::Map like setLatLng() would automatically turn off that functionality. So if the developer calls MapView.setLatLng() before the style finishes loading, the end result would be just as it is today. |
One idea: this could be as simple as a |
Looked into where the values are being set:
This function is responsible for parsing a style and setting up Style values: eg. defaultLatLng = parser.latLng;
defaultZoom = parser.zoom;
defaultBearing = parser.bearing;
defaultPitch = parser.pitch; This function than notifies an observer letting map.ccp know that the style has been loaded. |
I have something working: Not manipulating the camera results in showing the default from the style: Manipulating the camera in java: mapView.getMapAsync(new OnMapReadyCallback() {
@Override
public void onMapReady(@NonNull MapboxMap mapboxMap) {
DynamicMarkerChangeActivity.this.mapboxMap = mapboxMap;
mapboxMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(51.506675, -0.128699), 10));
}
}); Results in: or manipulating in xml: <com.mapbox.mapboxsdk.maps.MapView
app:center_latitude="51.506675"
app:center_longitude="-0.128699"
app:zoom="10" /> Results in: or manipulating via MapboxMapOptions: MapboxMapOptions options = new MapboxMapOptions()
.camera(new CameraPosition.Builder()
.target(new LatLng(51.506675, -0.128699))
.zoom(10)
.build()); Results in: |
The map should jump to the default center coordinates, zoom level, bearing, and pitch as soon as the first style loads after initialization. Switching from one style to another probably shouldn’t change the viewport.
Complicating matters, the initial viewport may be overridden for various reasons. For example, state restoration would take place upon initialization. Or the developer may programmatically set the viewport immediately after initializing the map view but before the style loads. The style shouldn’t be able to clobber a viewport set this way.
In the iOS and macOS SDKs, MGLMapView’s initial center coordinates, zoom level, and direction can be specified in a storyboard. Unfortunately, storyboard-defined properties are set asynchronously, in piecemeal fashion, after the MGLMapView object is initialized and thus sometime after
mbgl::Map
is initialized. The style’s default viewport shouldn’t clobber this asynchronously set viewport, either.In #6127 (comment), @jfirebaugh suggests implementing the initial viewport behavior in core. That could work for the iOS and macOS SDKs, as long as we account for the cases above. Perhaps methods like
mbgl::Map::setLatLng()
andeaseTo()
could shut off any style-default-viewport functionality for the lifetime of the map./cc @friedbunny @tobrun
The text was updated successfully, but these errors were encountered: