Map - Pan / Zoom to marker cluster

I have managed to plot several markers on the map, lets imagine delivery locations, say 8 of them so 8 markers but the delivery locations will change daily, some days they could all be within the same city 10 mile radius, some days they could be spread over 150 miles between the furthest locations.
Is there a way for me to pan / zoom when the map opens to display the whole cluster so that the cluster of markers fits the extent of the may window and able to adjust itself automatically to a different cluster each day rather than starting with a canvas of hundreds of square miles and a 5 mile radius cluster off screen ?
Im aware it can be done for one marker but I havent found a way to do it for a cluster yet.

When you have set all your map markers, draw (it can be invisible) a polygon using all the map marker coordinates. You should then be able to get the centroid of the polygon, and use this to centre your map...(not tested)

Example can be found here for creating a polygon

Probably can use

Sets or gets the current boundary for the map’s drawn view. The value is a list of lists containing the northwest and southeast coordinates of the current view in the form ((North West) (South East)).

and a list of the coordinates of each of the markers.

Figure out the Westernmost longitude, Easternmost longitude, Northernmost latitude, Southernmost latitude in each cluster and set the BoundingBox coordinates using the resulting northwest and southeast coordinates. :wink:

1 Like


I've been trying your suggestion of using BoundingBox.
I made a list of 2 coordinates to try and set the BoundingBox but it fails with runtime error - "java.lang.String cannot be cast to"

Using the blocks below to compare the figures.

textbox1 shows [[57.5976, -2.70631],[57.09971, -2.177155]]
textbox2 shows ["57.6858814 -2.0134259",57.2964716 -2.1426393"]
are the coordinates needing to be just to 4 decimal places and why does my list appear as a list of strings ?

Like so:

Actually to make the boundingBox for a cluster of Markers you should use


BoundingBox looked the easiest of the two options and it was .. sorting out the Tinydb sotorint a dictionary and trying to re-order the lists was a nightmare but I got there eventually.
Sorting the values was easy enough and I added a bit of padding to prevent the markers being too close to the edge of the map plot area.

It looks fine but ill need to try on the go to see how it performs in use.

I have some questions about markers but Ill ask those in a separate question so its searchable on the subject matter.