user_location_plugin icon indicating copy to clipboard operation
user_location_plugin copied to clipboard

Markers being rebuild without moving map

Open Swepilot opened this issue 5 years ago • 2 comments

When adding UserLocationOptions to the map layers it causes my map markers to rebuild every second which has a performance issue since I'm adding hundreds of Markers to the map. The same thing happens when zooming/panning the map but that's more understandable as this requires the markers to be redrawn.

Steps to reproduce the behaviour:

  1. Add Markers to a flutter_map
  2. Add UserLocationOptions to the layers
  3. Add debug code to print out the Marker build function

I have tried setting a higher value in locationUpdateIntervalMs to reduce the frequency of the rebuild but that does not seem to reduce the frequency or the rebuild. This is on a physical Android device.

Interested to know if this is by design, any easy way around it or I need to look on how my Markers are build?

TIA!

Swepilot avatar Jan 08 '21 07:01 Swepilot

Hi, thank you for pointing out the issue.

No, that is not a choice by design.

The reason you are facing performance issues might be because we rebuild all the markers every locationUpdateIntervalMs, not when the map moves or you zoom in/out.

This is a problem in the plugin itself I guess, and we would need to make changes to how markers are rendered, one quick try could be to delete and add only those markers whose position is changed and see if that changes anything

widget.options.markers.remove(_locationMarker); widget.options.markers.add(_locationMarker);

I am quite busy with my exams, as of now, I am really sorry I am not able to work on this issue as of now. Please, write back if you found a solution to the issue, and once again thank you for this issue.

igaurab avatar Jan 09 '21 12:01 igaurab

No worries, I will try to find a way in the meantime. I'm beginner/intermediate with Flutter so just wanted to see if I was doing something terrible wrong or not. I'll keep you updated. Good luck with the exams!

Swepilot avatar Jan 09 '21 14:01 Swepilot