Closed gdesmott closed 8 years ago
Pseudo code:
closest_resto = _.min(restos, function(resto) { return resto.latlng.distanceTo(user_position) }
map.fitBounds([user_position, closest_resto], padding=XX)
(je recommande un peu de padding)
I got this working in this branch : https://github.com/gdesmott/manger-veggie/tree/zoom
The only problem is that now the user position is very far from the center making it harder to find. I'm not sure of the best way to fix that, help welcome. Also, the padding properties doesn't seem to work.
<Bram> ici https://github.com/gdesmott/manger-veggie/compare/zoom?expand=1#diff-17e6d4d8ce23c23e218e1465bb87c337R22
<Bram> il faudrait rajouter un point
<Bram> qui serait le point correspondant au restaurant par symétrie de point par rapport à la position courante
<Bram> y a une formule qui traine/qui est retrouvable
<Bram> genre
<Bram> au pif de tête
<Bram> l = là où on est
<Bram> r = resto
<Bram> t = target
<Bram> t = (l.x + (l.x - r.x)), (ly + (l.y - r.y))
<Bram> ou un truc du genre
<Bram> maths ™
<Bram> et je pense que ça devrait le faire
For the record I opened https://github.com/Leaflet/Leaflet/issues/4056 suggesting Leaflet to add API for this use case.
So far the default zoom is not very useful if there is no restaurant in the close area next to you. Maybe we could zoom out until at least or restaurant is displayed on the map or something?