I'm using Leaflet with Mapbox and I'd like to set the view of the map so :
- all markers are visible
- the center is set to a specific point
setView と fitbounds を使用して各ポイントを個別に行うのは簡単ですが、setView が境界を変更し、fitBounds が中心を変更するため、両方を同時に行う方法がわかりません。解決策は、中心とズームを定義することですが、どのズームがすべてのマーカーを表示できるようにするかをどのように知ることができますか?
編集
IvanSanchez が提案したソリューションを実装しましたが、期待どおりに動作します。
let ne=leafletBounds.getNorthEast();
let sw=leafletBounds.getSouthWest();
let neSymetric=[ne.lat + (center.lat - ne.lat)*2, ne.lng + (center.lng - ne.lng)*2];
let swSymetric=[sw.lat +(center.lat - sw.lat)*2, sw.lng + (center.lng - sw.lng)*2];
leafletBounds.extend(L.latLngBounds(swSymetric, neSymetric));