Find a Route and how to clear route

905
4
02-04-2014 05:34 AM
GloriaForthun
New Contributor
I have used the Find a Route program and it works great.  But I want to have a clear button so that when you click on it the old stops and path are deleted.  I have used onclick = "map.graphics.clear();" and that does appear to remove the stops and path, however, after I clear the graphics, I click on a new stop and a path is drawn from the last stop from the "cleared" route to the new stop.  Apparently I am not clearing out (deleting) the last stop.  Can anyone tell me how to do this?  Thanks.
0 Kudos
4 Replies
JohnGravois
Frequent Contributor
hi Gloria.  welcome to our forum!

im assuming you're talking about this sample, correct?

in addition to clearing the map.graphics, you also need to make sure the stops which were previously added to your RouteParameters objects are removed as well.

routeParams.stops.features = [];


i first tried setting routeParams.stops and routeParams.stops.features to 'null', but afterward, no additional route requests went out. this seemed a little counterintuitive at first, but the problem with that is that you've unset the object associated with that property completely.
0 Kudos
JohnGravois
Frequent Contributor
just a reminder, the routing and geocoding services on tasks.arcgisonline.com will be retired any day now.  you can use sampleserver3 (for prototyping only), but i would highly recommend migrating all code to utilize our new subscription route services if you aren't interested in maintaining your own service.

here is a link to a fiddle of the same sample converted to AMD and using route.arcgis.com.  it could be run with a proxy like our Directions widget sample if you don't want end users to provide the authentication, but from jsfiddle, its necessary to sign in with ArcGIS Organizational credentials to solve the route.
0 Kudos
GloriaForthun
New Contributor
Worked perfect.  I had almost gotten it a few times !  Thanks !
0 Kudos
JohnGravois
Frequent Contributor
glad to hear you're sorted out.  please consider marking this thread as 'answered'.
0 Kudos