Directions Widget: Prevent zoom to full route after the route is calculated

1108
4
Jump to solution
05-08-2017 08:48 AM
MaxMcCosham
New Contributor III

Hello,

I'm using the Directions widget in version 3.20 of the API:

Directions | API Reference | ArcGIS API for JavaScript 3.20 

Is it possible to prevent the zoomToFullRoute() method from being called after the route is calculated? I would like to keep the map at its current extent instead of automatically zooming in/out to the calculated route.

Thanks,

0 Kudos
1 Solution

Accepted Solutions
NiklasKöhn
Esri Contributor

Max,

try overriding the Directions class like this:

var NoZoomDirections = declare(Directions, {
    zoomToFullRoute: function () {
        console.log("overriding zoomToFullRoute");
    }
});

var directionsWidget = new NoZoomDirections(/*... the usual instantiation */);

Works for me. I only get the console message, not the zoom.

If you want to have the zoomToFullRoute() functionality in some cases, you'd need to add 

this.inherited(arguments);

into the new function body along with a conditional statement.

About what you and Robert Scheitlin, GISP‌ said about when the map is automatically zoomed in or not: I've had exactly that issue and described it here: Zoom button and auto zoom in Directions widget. Maybe you could take a look at it and verify the problem.

Cheers,

Nik

View solution in original post

0 Kudos
4 Replies
RobertScheitlin__GISP
MVP Emeritus

Max,

   I am not seeing the map zoom to the calculated route unless I click on the route directions results.

0 Kudos
MaxMcCosham
New Contributor III

Hi Robert,

This sample shows an example:

ArcGIS API for JavaScript Sandbox 

After two cities are entered, the list of steps is populated and the map zooms in to the full extent of the route. I was wondering if it is possible to show the steps and highlight the route on the map, but leave the map extent as is.

Cheers,

0 Kudos
NiklasKöhn
Esri Contributor

Max,

try overriding the Directions class like this:

var NoZoomDirections = declare(Directions, {
    zoomToFullRoute: function () {
        console.log("overriding zoomToFullRoute");
    }
});

var directionsWidget = new NoZoomDirections(/*... the usual instantiation */);

Works for me. I only get the console message, not the zoom.

If you want to have the zoomToFullRoute() functionality in some cases, you'd need to add 

this.inherited(arguments);

into the new function body along with a conditional statement.

About what you and Robert Scheitlin, GISP‌ said about when the map is automatically zoomed in or not: I've had exactly that issue and described it here: Zoom button and auto zoom in Directions widget. Maybe you could take a look at it and verify the problem.

Cheers,

Nik

0 Kudos
MaxMcCosham
New Contributor III

Thanks Niklas, this works for me. Hopefully the manual zoom button is added again as an option.