Skip to content

Commit

Permalink
Directions tool zooms to route extent
Browse files Browse the repository at this point in the history
When a route is first displayed, or its waypoints change, the map extent doesn't change, and users often need to zoom in to the route to see it clearly. This change gets a bounding box for all route segments and zooms to the corners of the bounding box (plus some padding).
  • Loading branch information
michaelpnelson committed Jun 13, 2023
1 parent b75faf1 commit b017e8b
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/smk/tool/directions/tool-directions-waypoints.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ include.module( 'tool-directions.tool-directions-waypoints-js', [
this.routePlanner = new SMK.TYPE.RoutePlanner( this.routePlannerService )
this.geocoder = new SMK.TYPE.Geocoder( this.geocoderService )

this.map = smk.$viewer.map;

this.changedActive( function () {
if ( self.active ) {
// if ( self.waypoints.length == 0 ) {
Expand Down Expand Up @@ -371,6 +373,10 @@ include.module( 'tool-directions.tool-directions-waypoints-js', [
sg.style = self.layer[ ly ].config.style
} )
} )

const bbox = turf.bbox(segments);
const latLngBounds = L.latLngBounds({lng: bbox[0], lat: bbox[1]}, {lng: bbox[2], lat: bbox[3]});
self.map.flyToBounds(latLngBounds, {padding: [100,100]});
},

displayWaypoints: function () {
Expand Down

0 comments on commit b017e8b

Please sign in to comment.