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] bounds set in MapOptions are sometimes ignored #1412

Closed
5 tasks done
felix-ht opened this issue Dec 5, 2022 · 5 comments
Closed
5 tasks done

[BUG] bounds set in MapOptions are sometimes ignored #1412

felix-ht opened this issue Dec 5, 2022 · 5 comments
Labels
bug This issue reports broken functionality or another error

Comments

@felix-ht
Copy link

felix-ht commented Dec 5, 2022

What is the bug?

If i define bounds in MapOptions these are sometimes ignored - and the map shows the full world map. If i have any interaction with the map (even with disabled interactions) the zoom seems to fix itself.

options: MapOptions(
        bounds: bounds,
),
Bildschirmaufnahme.2022-12-05.um.13.40.36.mov

What is the expected behaviour?

The map is zoomed to the bounds.

How can we reproduce this issue?

import 'package:flutter/material.dart';
import 'package:flutter/src/widgets/container.dart';
import 'package:flutter/src/widgets/framework.dart';
import 'package:flutter_map/plugin_api.dart';
import 'package:latlong2/latlong.dart';

class ExampleMap extends StatelessWidget {
  const ExampleMap({super.key});

  @override
  Widget build(BuildContext context) {
    final bounds = LatLngBounds(LatLng(51.6, 12.6), LatLng(53.4, 14.4));
    return FlutterMap(
      options: MapOptions(
        interactiveFlags: InteractiveFlag.none,
        bounds: bounds,
      ),
      nonRotatedChildren: [
        AttributionWidget.defaultWidget(
          source: 'OpenStreetMap contributors',
          onSourceTapped: null,
        ),
      ],
      children: [
        TileLayer(
          urlTemplate: 'https://tile.openstreetmap.org/{z}/{x}/{y}.png',
          userAgentPackageName: 'com.example.app',
        ),
      ],
    );
  }
}

Do you have a potential solution?

No response

Can you provide any other information?

Workaround is to set

   onMapReady: () {
          controller.fitBounds(bounds);
        },

Platforms Affected

MacOS

Severity

Erroneous: Prevents normal functioning and causes errors in the console

Frequency

Once: Occurred on a single occasion

Requirements

  • I agree to follow this project's Code of Conduct
  • My Flutter/Dart installation is unaltered, and flutter doctor finds no relevant issues
  • I am using the latest stable version of this package
  • I have checked the FAQs section on the documentation website
  • I have checked for similar issues which may be duplicates
@felix-ht felix-ht added bug This issue reports broken functionality or another error needs triage This new bug report needs reproducing and prioritizing labels Dec 5, 2022
@felix-ht felix-ht changed the title [BUG] bounds set in MapOptions is sometimes ignored [BUG] bounds set in MapOptions are sometimes ignored Dec 5, 2022
@ibrierley ibrierley added high priority and removed needs triage This new bug report needs reproducing and prioritizing labels Dec 5, 2022
@ibrierley
Copy link
Collaborator

ibrierley commented Dec 5, 2022

I can confirm this...I noticed this the other day with a report of bounds not working (preventing dragging), but sometimes would display zoom 0.

Quite from my Discord:

I thought there was a fix for this, just checking https://github.com/fleaflet/flutter_map/pull/1369/files#
But there's something still buggy going on somewhere, I can't quickly see but firstly make sure you are using the latest version from Git, that may help fix it...but then I think there's still something odd going on with fitbounds, but haven't got time to debug atm
it feels like now sometimes it doesnt fit to bounds at all, so I would raise an issue on Git, and also reference that change (out of interest, you could switch that PR exactly and test to see if your code works with it just to isolate)
(my suspicion would be the main problem was fixed, but maybe the fitbounds gets called too early, although I think that was taken into account)

So, originally there was a addPostFrameCallback in there, to call fitBound() after it has a correct size calculated...maybe some other code introduced as meant that this is no longer good enough, and needs further to wait. I note in Web, this works fine, and I suspect that's because typically there are more tiles to display and its a bit slower.

@ibrierley
Copy link
Collaborator

It looks like it was the code from this 4276a91 which is weird, as I'm sure we tested this (but maybe we only tested it on web which does works?). So it looks like the original problem is still there or back. Cue trying to fix that, for flickering to return!

@ibrierley
Copy link
Collaborator

Possible fix at #1413 please test thoroughly everyone who uses bounds, as it can be hard to replicate this problem and the initial flashing problem, as it can depend on device :)

@felix-ht
Copy link
Author

felix-ht commented Dec 6, 2022

@ibrierley the PR seems to have fixed the issues 👍

@ibrierley
Copy link
Collaborator

Closing as merged, thanks!

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
Projects
None yet
Development

No branches or pull requests

2 participants