maplibre / flutter-maplibre-gl

Customizable, performant and vendor-free vector and raster maps, flutter wrapper for maplibre-native and maplibre-gl-js (fork of flutter-mapbox-gl/maps)
https://pub.dev/packages/maplibre_gl
Other
225 stars 125 forks source link

Adding a Map Scale #143

Open noorbakerally opened 2 years ago

noorbakerally commented 2 years ago

I'm sorry to ask this here but cannot find this in the documentation, How to add a Map scale to a map that automatically updates based on the zoom level?

m0nac0 commented 2 years ago

This is not yet implemented in this plugin, but the functionality exists in the underlying MapLibre SDKs. (Also see https://github.com/flutter-mapbox-gl/maps/issues/908)

It should be relatively straightforward to implement this, a PR for this would be very welcome.

rohanshankar commented 2 years ago

Hi, I can try to work on this. Which file should I try adding the scale to https://docs.maptiler.com/maplibre-gl-js/markers-and-controls/ - may help

m0nac0 commented 2 years ago

@rohanshankar Sorry, I mislabeled this issue, since this is a bit more involved and probably not really suitable for a first contribution.

noorbakerally commented 1 year ago

@m0nac0 in our project, we reached a point where we are required to implement this before delivering, can you provide some general/brief instructions for implementing this, before us diving into the plugin.

mariusvn commented 1 year ago

after looking at maplibre-gl-native, looks like the ScaleBar is implemented on ios only, I may be wrong but it looks like a hard task, I hope @m0nac0 can help. Since he is not active since december, i suggest you to ask the maplibre-gl-native team if it is possible at the current state of the library

noorbakerally commented 1 year ago

@mariusvn Thanks for your advice, just a question, is there a different simpler way, like for example, without diving into the plugin, having a widget, the map scale, that is an overlay on the map. The widget will say have a width of Apx, we only need a way to tell us how much Apx represents on the map in terms of say meters, having this solve our problem, then we just have a listener that reacts to map zoom to update the map scale label.

mariusvn commented 1 year ago

Well i think you can do that with the controller's getMetersPerPixelAtLatitude method

mariusvn commented 1 year ago

If you really want the widget to update only when the camera moves, you'll need to update this function in controller.dart:90 in the library to add a public callback:

    _mapboxGlPlatform.onCameraMovePlatform.add((cameraPosition) {
      _cameraPosition = cameraPosition;
      notifyListeners();
    });

We should actually add an event in the controller that says when the camera start moving

You can also use the isCameraMoving boolean to check that but it will need a continuous check but it would not need a library edit.

GaelleJoubert commented 1 year ago

Hello, I am also interested by a scale :) I don't know if this is still on the plan ? For now I'll try to do something with getMetersPerPixelAtLatitude.