From afc0f21691f691281c96cdb65f83c119298f6b29 Mon Sep 17 00:00:00 2001 From: Nenad Vujicic Date: Mon, 8 Jul 2024 22:23:58 +0200 Subject: [PATCH] Improved focusing map view to include markers --- app/assets/javascripts/index/directions.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/app/assets/javascripts/index/directions.js b/app/assets/javascripts/index/directions.js index 38703578d1..1069c70857 100644 --- a/app/assets/javascripts/index/directions.js +++ b/app/assets/javascripts/index/directions.js @@ -263,6 +263,14 @@ OSM.Directions = function (map) { $("#sidebar_content").html("
" + I18n.t("javascripts.directions.errors.no_route") + "
"); } + if (fitRoute) { + var partiallyCombinedBounds = L.latLngBounds(); + partiallyCombinedBounds.extend(L.latLngBounds(o, o)); + partiallyCombinedBounds.extend(L.latLngBounds(d, d)); + + map.fitBounds(partiallyCombinedBounds.pad(0.05)); + } + return; } @@ -271,7 +279,12 @@ OSM.Directions = function (map) { .addTo(map); if (fitRoute) { - map.fitBounds(polyline.getBounds().pad(0.05)); + var fullyCombinedBounds = L.latLngBounds(); + fullyCombinedBounds.extend(polyline.getBounds()); + fullyCombinedBounds.extend(L.latLngBounds(o, o)); + fullyCombinedBounds.extend(L.latLngBounds(d, d)); + + map.fitBounds(fullyCombinedBounds.pad(0.05)); } var distanceText = $("

").append(