How do I compute map bounds/zoom of markers (each with lat/lng) while excluding outliers (e.g. from 10th to 90th quantile only by Y: most of my markers are in Europe and US, some are in Australia but for usability purpose I'm okay to keep them off the default zoom)?
Should I manually project first lat/lng to X/Y, then compute quantiles, then project back to lat/lng? Is there an idiomatic way to do this?
(If no need to exclude outliers, map.fitBounds(L.latLngBounds(latlons))
works okay, but I'd like to exclude outliers)
If you want to zoom and show a group of markers that can be done easily by using the map.fitBounds()
method.
If you want to show only some of the markers you can put all the wanted markers in a L.FeatureGroup
:
import * as L from 'Leaflet';
let pointsToGoToGroup = new L.FeatureGroup()
//Add all the wanted markers
let bounds = pointsToGoToGroup.getBounds() //get the bounds
map.fitBounds(bounds) //zoom and show all the points in the group
You can also add options to fitBounds()
to control the animation, duration, padding exc...
L.FeatureGroup
docs: https://leafletjs.com/reference.html#featuregroup
L.FitBoundsOptions
docs: https://leafletjs.com/reference.html#fitbounds-options