add stops programmatically Directions Widget 4.8

1236
10
08-16-2018 09:54 AM
juanDavid
New Contributor II

Is there a way to actually to that in its current state?

Add some stops and then query the route.

10 Replies
RobertScheitlin__GISP
MVP Esteemed Contributor

Juan,

   The widgets stops collection property is part of the viewModel:

https://developers.arcgis.com/javascript/latest/api-reference/esri-widgets-Directions-DirectionsView... 

0 Kudos
juanDavid
New Contributor II

I know, but when deleted and added again the widget won't make a new query with the same results.

0 Kudos
ChrisGuirguis
New Contributor II

Robert,

Have you actually validated that setting the stops dynamically will solve the route and display directions? I have tried this and it does not seem to be the case. Unless there is something else I need to do besides specifying viewModel stops. 

Would love your input!

Chris

0 Kudos
RobertScheitlin__GISP
MVP Esteemed Contributor

Chris,  No I did not test this myself. It use to work in 3.x but 4.x Directions widget is still in Beta.

0 Kudos
KellyHutchins
Esri Frequent Contributor

We are working to add support for this in a future release. I don't currently have an ETA on when this functionality will be available. 

ChrisGuirguis
New Contributor II

Has there been any update on this? I'd like to use all of the nifty UI/UX interactions that come with the built-in widget, but without requiring manual input of start/end stops. 

Would very much appreciate an update.

Thanks,

Chris

StratosKourtzanidis
New Contributor

Any news on this? Is it going to be included soon?

0 Kudos
ToryWeber
New Contributor III

I am also looking for a 'proper' way to programmatically add stops to the directions widget.

I am successful at adding the geometries to the ViewModel, and can route successfully, however this leaves the widget in a semi-broken state, as the search inputs and the related Directions._stops && Directions._stopsToSearches properties do not get populated, so if I change one of the stops manually in the widget (like changing the start location), ALL the programmatically entered stops get removed and only the manually entered stop is present.

for now, I am hooking into the 'after render' event with dojo's aspect.after method, and manually setting the input text value and disabling the input so the user is unable to change stops, BUT this is not going to work for my customer in the long run.

I have no problem manually performing all the steps to add the 'stop' objects to keep the ViewModel and Widget in sync, but trying to look through the minified code to determine what steps I actually need to take hasn't gotten me anywhere, as it is near impossible to tell what the parameter types are, or even the correct order to do things. Is there an engineer that can help with the required steps? Thanks!

Not all who wander are lost ~ J.R.R. Tolkien
TonyGeorges1
New Contributor III

Hi all,

I was exactly doing that today. The only way I found to do it is to hack a little bit the widget.

When you change the stops collection in view model it has absolutely no effect on SearchWidget view model that is embedded inside Directions widget... So, basically, you have to find SearchWidget, and run a search.


Here is a simple example using a feature geometry : 

function addFromToDirection2(directionsfeature) {
          
          // eslint-disable-next-line no-underscore-dangle
          const searchWidget = directions._stopsToSearches.values().next().value;
          searchWidget.viewModel.search(feature.geometry);
}

You can extend it by configuring SearchWidget view model to search inside Feature layers if needed

This little hack works on 4.10->4.12

Good luck with that until that will become a feature