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

Getting screen point by latlng of the map. #402

Closed
softmarshmallow opened this issue Sep 4, 2020 · 14 comments
Closed

Getting screen point by latlng of the map. #402

softmarshmallow opened this issue Sep 4, 2020 · 14 comments
Labels

Comments

@softmarshmallow
Copy link

I'm trying to implement super animated marker, which cannot done with mapbox marker (symbol).
I have to display flutter widget on different layer than inside the map, but it should look sticked to the specific latlng (obviously,).
on fullscreen map, how can i get the screen position of specific latlng, and get it by event or etc in order to update the marker widget's position on the screen?

it can done on mapbox web, i'm not sure such callback / feature is implemented on this project.

thanks!!

@softmarshmallow
Copy link
Author

https://github.com/softmarshmallow/flutter-mapbox-gl
working on here, one more question is, how to get map location changed event?

@m0nac0
Copy link
Collaborator

m0nac0 commented Sep 6, 2020

@softmarshmallow #380 adds methods to convert between screen coordinates and geographic coordinates.
MapboxMapController is a ChangeNotifier, so you can subscribe to it and get notified when the cameraPosition property changes. Also see https://pub.dev/documentation/mapbox_gl/latest/mapbox_gl/MapboxMapController-class.html.
I personally think a separate callback would be nice, as MapboxMapController also notifies its listeners on changes to some other properties.

@m0nac0
Copy link
Collaborator

m0nac0 commented Sep 6, 2020

@softmarshmallow Also, I'd be very interested to hear if you manage to achieve a good performance with your approach, as I haven't tried this myself.

@softmarshmallow
Copy link
Author

@m0nac0 Oh.. LOL i was working on the samethig.

@softmarshmallow
Copy link
Author

#407 (comment)

i don't see any updates related to map movement callback @m0nac0

@m0nac0
Copy link
Collaborator

m0nac0 commented Sep 6, 2020

This is what I meant:

MapboxMapController is a ChangeNotifier, so you can subscribe to it and get notified when the cameraPosition property changes. Also see https://pub.dev/documentation/mapbox_gl/latest/mapbox_gl/MapboxMapController-class.html.

The cameraPosition describes what is visible on the map.

@softmarshmallow
Copy link
Author

@m0nac0
as descirbed here, #407

I was saying adding listener on controller won't work as expected. it only gets called on start/end of the camera movement

@m0nac0
Copy link
Collaborator

m0nac0 commented Sep 7, 2020

@softmarshmallow Ah sorry, I misunderstood that. Have you tried listening to isCameraMoving and as long as that's true checking for a newcameraPosition?

@softmarshmallow
Copy link
Author

How exactly can i "listen" to isCameraMoving ? it's just a property, not observable. use a loop? (seems alot dangerous)

@softmarshmallow
Copy link
Author

softmarshmallow commented Sep 7, 2020


  @override
  void initState() {
    super.initState();
    widget.controller.addListener(() {
      print("updated");

      if (controller.isCameraMoving) {
        startUpdate();
      } else {
        stopUpdate();
      }

      //          controller.
//          cameraPosition = controller.cameraPosition;
//          print("cameraPosition.bearing : ${cameraPosition.bearing}");
//          print("cameraPosition.tilt : ${cameraPosition.tilt}");
//          print("cameraPosition.target : ${cameraPosition.target}");
//          print("cameraPosition.zoom : ${cameraPosition.zoom}");
      controller.toScreenLocation(LatLng(0, 0)).then((value) {
        print("screen point: $value");
        setState(() {
          point = value;
        });
      });
      controller.getVisibleRegion().then((value) {
//            setState(() {
        visibleRegion = value;
//            });
      });
    });
  }

  bool isUpdating;

  startUpdate() async {
    isUpdating = true;
    while (isUpdating) {
      print("point!!");
      final newp = await controller.toScreenLocation(LatLng(0, 0));
      setState(() {
        point = newp;
      });
    }
  }

  stopUpdate() {
    isUpdating = false;
  }

not getting the performance i want TT..

marker follows late by apx. 15 fps

i think toScreenPoint should be implmeneted with dart nativly, the latency is crazy. not usable for live updates.

@m0nac0
Copy link
Collaborator

m0nac0 commented Sep 7, 2020

How exactly can i "listen" to isCameraMoving ? it's just a property, not observable. use a loop? (seems alot dangerous)

Just like with the cameraPosition property; MapboxMapController will notify its listeners also on changes to the isCameraMoving property.

@softmarshmallow
Copy link
Author

How exactly can i "listen" to isCameraMoving ? it's just a property, not observable. use a loop? (seems alot dangerous)

Just like with the cameraPosition property; MapboxMapController will notify its listeners also on changes to the isCameraMoving property.

tried it, cannot get the desired performance.

related: #408

@stale
Copy link

stale bot commented Jan 14, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Jan 14, 2022
@stale stale bot closed this as completed Jan 21, 2022
@teganscott
Copy link

@softmarshmallow did you ever have any success with a super animated marker? Currently I am working on implementing a similar solution as you described above but am concerned about the performance hits. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants