mapbox / mapbox/mapbox-maps-flutter

`cameraForCoordinatesPadding` does not zoom map to exactly wrap coordinates provided

Open
#618 2 comments 0 reactions 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

## Reproduction Code

```dart
import 'package:flutter/material.dart';
import 'package:mapbox_maps_flutter/mapbox_maps_flutter.dart';

class Test extends StatefulWidget {
const Test({Key? key}) : super(key: key);

@override
_TestState createState() => _TestState();
}

class _TestState extends State {
_onMapCreated(MapboxMap mapboxMap) async {
final latlngList = [
[31.23208, 121.38376],
[31.23207, 121.38375],
[31.23205, 121.38375],
[31.23204, 121.38374],
[31.23203, 121.38373],
[31.23202, 121.38372],
[31.232, 121.38372],
[31.23199, 121.38371],
[31.23198, 121.3837],
[31.23197, 121.3837]
];
final coordinates = latlngList
.map((e) =>
Point(coordinates: Position(e[1].toDouble(), e[0].toDouble())))
.toList();

final options = await mapboxMap.cameraForCoordinatesPadding(
coordinates,
CameraOptions(),
MbxEdgeInsets(top: 0, right: 0, bottom: 0, left: 0),
1000,
null,
);
await mapboxMap.setCamera(options);
final polylineAnnotationManager =
await mapboxMap.annotations.createPolylineAnnotationManager();
final positions = latlngList
.map((e) => Position(e[1].toDouble(), e[0].toDouble()))
.toList();
polylineAnnotationManager.create(PolylineAnnotationOptions(
geometry: LineString(coordinates: positions)));
}

@override
Widget build(BuildContext context) {
return Container(
child: MapWidget(
key: const ValueKey("mapbox"),
onMapCreated: _onMapCreated,
styleUri: MapboxStyles.LIGHT,
),
);
}
}

```

## Environment

```
mapbox_maps_flutter: ^2.1.0
```

flutter doctor output:

```
Flutter (Channel stable, 3.22.2, on macOS 14.0 23A344 darwin-arm64, locale zh-Hans-CN)
```

## What is actually happening?

image

## What is expected?

I thought the map would zoom to the rectangle like below:

截屏2024-07-14 14 38 00

Is this expected? Or is there any way to achieve what I want?

Thank you

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 with the provided Dart reproduction, focusing on the mapboxMap.cameraForCoordinatesPadding call and the subsequent setCamera call. Confirm whether the returned camera is expected to fit these tightly spaced coordinates with zero padding; done means a documented answer or a reproducible fix or workaround.

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
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.