mapbox / mapbox/mapbox-maps-flutter

CameraViewportState initial position is jumping

Open
#820 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Dart
Stars
380
Forks
204
PR merge metrics
No merged PRs in 30d

Description

When initially loading a map that uses `CameraViewportState`, the map is briefly centering to a different center than configured.
This behavior is different to when using `CameraOptions`, where the `onCameraChangeListener` is also fired twice, but both with the same center.

```
MapWidget(
key: ValueKey("mapWidget"),
viewport: CameraViewportState(
center: Point(coordinates: Position(-117.918976, 33.812092)),
bearing: currentCity.bearing,
pitch: 0,
zoom: 18),
onCameraChangeListener: (cameraChangedEventData) =>
print(cameraChangedEventData.cameraState.center.toJson()),
),
```

Output for `onCameraChangeListener`:
```
{type: Point, bbox: null, coordinates: [-9.999999999999972, 29.999999999999964]}
{type: Point, bbox: null, coordinates: [-117.918976, 33.812092000000014]}
```

When configuring both, `viewport ` and `cameraOptions`, it first centers to the position from `cameraOptions` and then to the position of `viewport`. Maybe there is some unwanted default/calculation when using `viewport` alone?

```
MapWidget(
key: ValueKey("mapWidget"),
viewport: CameraViewportState(
center: Point(coordinates: Position(-117.918976, 33.812092)),
bearing: currentCity.bearing,
pitch: 0,
zoom: 18),
cameraOptions: CameraOptions(
center: Point(coordinates: Position(-100.918976, 33.812092)),
zoom: 18,
),
onCameraChangeListener: (cameraChangedEventData) =>
print(cameraChangedEventData.cameraState.center.toJson()),
),
```
Output for `onCameraChangeListener`:
```
{type: Point, bbox: null, coordinates: [-100.918976, 33.812092000000035]}
{type: Point, bbox: null, coordinates: [-117.918976, 33.812092000000014]}
```

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the initial load with MapWidget using CameraViewportState and onCameraChangeListener, then compare it with CameraOptions and the combined configuration shown in the report. Done means the initial camera does not briefly jump to an unintended center and the reported camera-change events have consistent centers.

Written by the indexing model from the issue text.

Assessment

Tech stack
dart, flutter
Domain
mobile-dev
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.