Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] 6.0.0-dev.2: Assertion false positive: "MapCamera is no longer within the cameraConstraint after an option change" #1613

Closed
jjoelson opened this issue Aug 14, 2023 · 4 comments · Fixed by #1614
Labels
bug This issue reports broken functionality or another error P: 1 (important)

Comments

@jjoelson
Copy link
Contributor

What is the bug?

Hi all! I'm testing out some code on the pre-release 6.0.0-dev.2 version. Whenever I include a camera constraint in my map options, I get an assertion failure from lib/src/map/internal_controller.dart:

    assert(
      newOptions.cameraConstraint.constrain(newCamera) == newCamera,
      'MapCamera is no longer within the cameraConstraint after an option change.',
    );

My constraint is a CameraConstraint.containCenter constraint, and I've confirmed that the map center is indeed within the given constraint.

How can we reproduce it?

Create a map with map options that include a camera constraint, but ensure the map options change after the initial build such that FlutterMaps didUpdateWidget is called with the new set of map options.

Do you have a potential solution?

I may have missed it, but it doesn't seem as though MapCamera implements operator ==, which may explain the issue (i.e. the assertion is essentially doing reference equality, which I think would always fail). If someone else is not already working on this then I could work on a PR to add it.

cc @rorystephenson @JaffaKetchup

Platforms

Android, iOS

Severity

Erroneous: Prevents normal functioning and causes errors in the console

@jjoelson jjoelson added bug This issue reports broken functionality or another error needs triage This new bug report needs reproducing and prioritizing labels Aug 14, 2023
jjoelson added a commit to jjoelson/flutter_map that referenced this issue Aug 14, 2023
This will ensure assertions like the one described in [this issue](fleaflet#1613)
work as intended.
@jjoelson
Copy link
Contributor Author

Turns out to be a relatively simple fix; I just had to implement operator ==/hashCode: #1614

@JaffaKetchup JaffaKetchup changed the title [BUG] Assertion failure false positive in flutter_map 6.0.0-dev.2: "MapCamera is no longer within the cameraConstraint after an option change" [BUG] 6.0.0-dev.2: Assertion false negative: "MapCamera is no longer within the cameraConstraint after an option change" Aug 14, 2023
@jjoelson jjoelson changed the title [BUG] 6.0.0-dev.2: Assertion false negative: "MapCamera is no longer within the cameraConstraint after an option change" [BUG] 6.0.0-dev.2: Assertion false positive: "MapCamera is no longer within the cameraConstraint after an option change" Aug 14, 2023
jjoelson added a commit to jjoelson/flutter_map that referenced this issue Aug 14, 2023
This will ensure assertions like the one described in [this issue](fleaflet#1613)
work as intended.
JaffaKetchup pushed a commit that referenced this issue Aug 15, 2023
This will ensure assertions like the one described in #1613 work as intended
@JaffaKetchup JaffaKetchup linked a pull request Aug 15, 2023 that will close this issue
@JaffaKetchup JaffaKetchup added P: 1 (important) and removed needs triage This new bug report needs reproducing and prioritizing labels Aug 15, 2023
@DevTello
Copy link

DevTello commented Dec 5, 2023

@JaffaKetchup The same issue if I'm using CameraConstraint.contain(). No problems, if it's CameraConstraint.containCenter()

@JaffaKetchup
Copy link
Member

@DevTello If you're still getting this issue in v6.1.0, please open a new issue!

@priyanshi-pandya
Copy link

I was getting the same exception, i had to adjust the initialCenter with respect to the cameraConstraints

Like,
initialZoom: 2.3, cameraConstraint: CameraConstraint.contain( bounds: LatLngBounds( const LatLng(-90, -180), const LatLng(90, 180), ), ),

For this above bounds it works perfectly with initialZoom of 2.3, if I go any less than this, its throws me again MapCamera, is not within cameraConstraint error.

Here is my full code

     FlutterMap(
            options: MapOptions(
              minZoom: 1,
              maxZoom: 19,
              initialCenter: const LatLng(0, 0),
              initialZoom: 2.3,
              cameraConstraint: CameraConstraint.contain(
                bounds: LatLngBounds(
                  const LatLng(-90, -180),
                  const LatLng(90, 180),
                ),
              ),
              onTap: (tapPosition, point)  {
                //Tap logic
              },
              onPointerHover: (event, point) {
                //Hover logic                  },
            ),
            mapController: mapProvider.mapController,
            children: [
              TileLayer(
                urlTemplate:
                    'https://tile.openstreetmap.org/{z}/{x}/{y}.png',
                userAgentPackageName: 'com.example.app',
                tileProvider: CancellableNetworkTileProvider(),
              ),
              //other layers
              
            ]
         ), 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue reports broken functionality or another error P: 1 (important)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants