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

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

Closed
comatory opened this issue Jun 25, 2021 · 11 comments · Fixed by #1532
Closed

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

comatory opened this issue Jun 25, 2021 · 11 comments · Fixed by #1532
Labels
feature This issue requests a new feature

Comments

@comatory
Copy link
Contributor

I want to actually reopen this issue #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
Copy link
Contributor Author

comatory commented Jul 2, 2021

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
Copy link

github-actions bot commented Aug 2, 2021

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 github-actions bot added the Stale label Aug 2, 2021
@1075dn
Copy link

1075dn commented Aug 3, 2021

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!

@github-actions github-actions bot removed the Stale label Aug 4, 2021
@heebj
Copy link

heebj commented Aug 23, 2021

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
Copy link

pawelsa commented Aug 31, 2021

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

@comatory
Copy link
Contributor Author

comatory commented Aug 31, 2021

@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
Copy link

github-actions bot commented Oct 1, 2021

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 github-actions bot added the Stale label Oct 1, 2021
@comatory
Copy link
Contributor Author

comatory commented Oct 5, 2021

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

@github-actions github-actions bot removed the Stale label Oct 6, 2021
@github-actions
Copy link

github-actions bot commented Nov 6, 2021

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 github-actions bot added the Stale label Nov 6, 2021
@github-actions
Copy link

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

JaffaKetchup added a commit that referenced this issue May 29, 2023
…esolves #1460, #777, #952)

Major refactoring and re-organization to improve understandibility
@JaffaKetchup JaffaKetchup reopened this May 29, 2023
@JaffaKetchup JaffaKetchup linked a pull request May 29, 2023 that will close this issue
@JaffaKetchup
Copy link
Member

JaffaKetchup commented May 29, 2023

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

@JaffaKetchup JaffaKetchup added duplicate This issue already exists feature This issue requests a new feature labels May 29, 2023
@JaffaKetchup JaffaKetchup closed this as not planned Won't fix, can't repro, duplicate, stale May 29, 2023
@JaffaKetchup JaffaKetchup reopened this May 30, 2023
@JaffaKetchup JaffaKetchup removed the duplicate This issue already exists label May 30, 2023
@JaffaKetchup JaffaKetchup changed the title [Feature request]: Allow to add offset when moving map via MapController [FEATURE] Add screen-based offset capability to MapController.move May 30, 2023
JaffaKetchup added a commit that referenced this issue Jun 4, 2023
* Multiple changes, see PR body

* Updated CHANGELOG

* Added `offset` option to `FlutterMapState.move` and related methods (resolves #1460, #777, #952)
Major refactoring and re-organization to improve understandibility

* Updated CHANGELOG

* Ensure `id` of `MapController.move` is passed through to the emitted `MapEventMove`

Originally from #1534 (3eca34e) - thanks @rorystephenson!

Co-Authored-By: Rory Stephenson <[email protected]>

* Fixed regression in commit 2764747 where internal `MapController` state was not continuous

* Added `rotateAroundPoint` - resolves #1460

Co-Authored-By: 6y <[email protected]>

* Updated CHANGELOG

* Added `TileLayer.fallbackUrl` support to `FileTileProvider`
Improved performance of `AssetTileProvider` when `TileLayer.fallbackUrl` not specified (resolves #1436)
Improved documentation about performance pitfalls of `TileLayer.fallbackUrl`

* Updated CHANGELOG

* Updated pubspec.yaml
Updated CHANGELOG

* Removed `saveLayers` property from `PolylineLayer`

* Updated CHANGELOG

* Updated MacOS configuration
Removed unnecessary Java installation from Windows GitHub Actions builder

* Added more position options to `AnchorAlign`
Deprecated `AnchorAlign.none` in favour of `AnchorAlign.center` or `null`
Improved response/emission time of `onTap`/`MapEventTap` when `InteractiveFlag.doubleTapZoom` is disabled
Improved `MarkerLayer`/`Layer` interoperability
Improved/reorganized example application
Updated CHANGELOG

* Simplified `Anchor`
Improved documentation of marker anchor methods
Improved CHANGELOG

* Updated version numbers

* Fixed bug in example application

* Added automated publishing action for tags in format 'v_._._'

* Updated CHANGELOG

* Added credit to CHANGELOG

---------

Co-authored-by: Rory Stephenson <[email protected]>
Co-authored-by: 6y <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature This issue requests a new feature
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants