I am trying to calculate a default zoom level for when a Tiled Web Map (using OpenStreetMap) is first loaded that will contain all of the set POI (points of interest).
From there, the user can zoom in/out and move the map around.
To that end, I am calculating the center of all of the POIs.
That is working.
For zoom level, it is generally working except that it is not taking into account the current size of the map itself.
Here is the code I have used (in Java):
Code: Select all
int zoomLevel = 1;
double maxDiff = Math.max(maxLatitude - minLatitude, maxLongitude - minLongitude);
if (maxDiff > 0)
{
zoomLevel = (int) Math.floor(Math.log(360 / maxDiff) / Math.log(2));
}
Take, for example, the Highcharts demo for this here:
https://www.highcharts.com/docs/maps/tiledwebmap
As of now, it is hardcoded to a zoom level of 13.
firToGeometry will not work because it will not allow for zooming or scrolling beyond those bounds.