fleaflet / flutter_map

A versatile mapping package for Flutter. Simple and easy to learn, yet completely customizable and configurable, it's the best choice for mapping in your Flutter app.
https://pub.dev/packages/flutter_map
BSD 3-Clause "New" or "Revised" License
2.74k stars 861 forks source link

[FEATURE] Add screen-based offset capability to `MapController.move` #952

Closed comatory closed 1 year ago

comatory commented 3 years ago

I want to actually reopen this issue https://github.com/fleaflet/flutter_map/issues/777

I think it would be super useful to have. I have used Mapbox Javascript SDK in the past and would take advantage of their ability to calculate offset via pixels.

My use case is that I have map that takes up the whole screen. Then I have bottom sheet that covers the bottom of the map. Now I want to center / move map to programmatically via MapController, the problem is the bottom sheet could cover the point where I want to move. The bottom sheet is also expandable, you can pull it up and down so you never know it's size.

I could get the height of the sheet in pixels before I center or move the map but at the moment, I can't easily do this since the move and moveAndRotate method does take any parameter. It seems like fitBounds uses padding which I'm not sure if it's the same.

I might resort to zooming out a bit to make sure it's not completely covered but it'd be really nice to have this feature.

comatory commented 3 years ago

Could someone point me how to implement this? I believe the plugin has to do this internally anyway since fitBounds takes padding. Could you point me to relevant code?

Would be great to expose some utilities that do this calculation as well.

github-actions[bot] commented 3 years ago

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

1075dn commented 3 years ago

I had to do this too, and ended up having to copy most of the relevant code in src/map/map.dart 😞. Hope this helps!

heebj commented 3 years ago

I had the same problem and was able to do it with the following lines:

LatLng _moveByBottomPadding(LatLng coordinates, double zoomLevel, double bottomOffset) {
    // the following code is copied from unreachable flutter map internas
    final crs = const Epsg3857();
    final oldCenterPt = crs.latLngToPoint(coordinates, zoomLevel);
    final offset = CustomPoint(0, bottomOffset);

    final newCenterPt = oldCenterPt + offset;
    final newCenter = crs.pointToLatLng(newCenterPt, zoomLevel);

    return newCenter;
  }

Would be nice if this is directly provided by the API :-)

pawelsa commented 3 years ago

@comatory how do you obtain the size/offset of bottom sheet ?

comatory commented 3 years ago

@comatory how do you obtain the size/offset of bottom sheet ?

There is a way to obtain widget sizes in Flutter, can't tell you from head right now but you use widget's key currentContext property: https://stackoverflow.com/questions/49307677/how-to-get-height-of-a-widget

So I have a handler set up that after user changes size of the bottom sheet by dragging, I look up the size and store the value so I can then use it as an offset later. I also have to do it initially when the widget is mounted.

github-actions[bot] commented 3 years ago

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

comatory commented 3 years ago

Bump. I tried using @heebj but that did not work for me. Could we get this functionality built-in?

github-actions[bot] commented 2 years ago

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

github-actions[bot] commented 2 years ago

This issue was closed because it has been stalled for 5 days with no activity.

JaffaKetchup commented 1 year ago

This will be added for v5 by #1532 (2764747)!