diff --git a/public/js/route.js b/public/js/route.js index e881f11..13a6a4e 100644 --- a/public/js/route.js +++ b/public/js/route.js @@ -14,6 +14,19 @@ function buildRoute() $('#wayPoints div').each(function(i, el) { + lat = points[$(el).attr('pointId')]._latlng.lat; + lng = points[$(el).attr('pointId')]._latlng.lng; + + if (i == 0) + { + bounds = [[lat, lng],[lat, lng]]; + } else { + if (lat < bounds[0][0]) bounds[0][0] = lat; + if (lng < bounds[0][1]) bounds[0][1] = lng; + if (lat > bounds[1][0]) bounds[1][0] = lat; + if (lng > bounds[1][1]) bounds[1][1] = lng; + } + wayPoints.push({latLng: points[$(el).attr('pointId')]._latlng}); }); @@ -27,10 +40,19 @@ function buildRoute() route = L.Routing.line(routes[0]); distance = Math.round(routes[0].summary.totalDistance / 1000); $('#routeDistance').html('Протяженность ' + distance + ' км.'); + + route.options.styles = [ + {color: 'black', opacity: 0.5, weight: 9}, + {color: 'green', opacity: 0.7, weight: 7}, + {color: 'orange', opacity: 1, weight: 3} + ]; + route.addTo(myMap); } }); + myMap.fitBounds(bounds).zoomOut(); + routeToURL(); } }