Select to view content in your preferred language

directions widget sample enhanced to support 'click on the map to add a stop'

7058
16
04-17-2014 02:37 PM
JohnGravois
Frequent Contributor
hi all, ive had a few people curious about getting the directions widget to support adding stops by clicking on the map itself so i put together a basic sample in case anyone wants to check it out

http://johngravois.com/maps/directions-click.html

(just an fyi, you'll have to sign in to ArcGIS Online to do the actual routing)
16 Replies
ICZEMICZEM
New Contributor

Thank you very much for this wonderful sample!

There's one question: if I click on the map it returns stop name like "204 E 90th St". Is it possible to make it also return city name, something like "204 E 90th St New York"?

0 Kudos
JohnGravois
Frequent Contributor

you're very welcome.

as you can see from the code in that page, we aren't doing anything in the application itself to handle the reverse geocoding.  based on your other post it sounds like you want to skip this part entirely, but if you really wanted to get that level of control i guess you could update the string manually using a method like updateStop()

0 Kudos
ICZEMICZEM
New Contributor

Thanks, John!

We're using our own locator so we have solved this problem by editing 'reverse geocoding' section in the locator style file.

As for my other question - no, we don't want to skip geocoding... In fact we would be happy to use only geocoding but unfortunately we have many important roads with no names and no addresses nearby   So now I see maybe 2 solutions: using Route Task or creating geolocator for every road segment. But we just hoped for the most convenient way out - to translate coordinates of the clicked point to Directions dijit stops even if  'location could not be found' by geocoder. This point could have a name 'unknown stop' of something like that.

0 Kudos
JeffPace
MVP Alum

Hey john,

I am going to try to integrate this with my code, hope it makes it into core eventually.

Two quick questions.

1. When i move a stop, the stop display turns to coordinates (I am using my own geocoding, geometry and routing services).  A successful reverse geocode call is made with a single address, but the display never updates.. any ideas?

2. My print page is not printing an overview map.  Not sure how to even troubleshoot.

Thanks!

Jeff

John Gravois

  var geometryService = window.location.protocol+'//'+window.location.hostname+"/arcgis01/rest/services/Utilities/Geometry/GeometryServer";
                             var locatorUrl = window.location.protocol+'//'+window.location.hostname+"/arcgis01/rest/services/tools/AGSStreetOnly/GeocodeServer";
                           var locatorUrl2 = window.location.protocol+'//'+window.location.hostname+"/arcgis01/rest/services/tools/AGSParcel/GeocodeServer";
                           var routingUrl = window.location.protocol+'//'+window.location.hostname+"/arcgis02/rest/services/routing/routing/NAServer/Route";
                           var printUrl = window.location.protocol+'//'+window.location.hostname+"/arcgis01/rest/services/Utilities/PrintingTools/GPServer/Export%20Web%20Map%20Task";
                          



function createDirections() {
                                    var options = { 
                                    autoComplete:true, 
                                    arcgisGeocoder: false, 
                                    geocoders:[{ 
                                      url: locatorUrl ,
                                      name:"centerlineLocator"
                                    } ]
                                  }; 
                                      var directions = new Directions({
                                        map: map,
                                        routeTaskUrl:routingUrl,
                                        printTaskUrl:printUrl,
                                        showSegmentPopup:false,
                                        directionsLengthUnits:"MILES",
                                        geometryTaskUrl:geometryService,
                                        geocoderOptions: options 

                                    }, "directionsDiv");


                                    directions.startup();
                                }
0 Kudos
KellyHutchins
Esri Frequent Contributor

Jeff and John the ability to click on the map to add stops will be in the next release (due very soon) of the ArcGIS API for JavaScript (version 3.12) .

0 Kudos
JeffPace
MVP Alum

Thats awesome Kelly Hutchins!! Thank you.

Still not sure why my Stop is not updating the location with the reverse geocode address though, or why my overview map is not showing.

Help.

0 Kudos
KellyHutchins
Esri Frequent Contributor

Jeff

Do you have a test app that shows the issue you are having with the overview map and reverse geocode?

0 Kudos
JeffPace
MVP Alum

Manatee County GIS Mobile Server

Directions are on the tools tab on the left.  Add two addresses, for example

1112 Manatee Ave W, Bradenton

2027 Manatee Ave W, Bradenton

And then move one of the points.  It will show coordinates.  Fiddler and Firebug show the reverse geocode is called and that an address is returned, it just doesnt update the box.

0 Kudos
KellyHutchins
Esri Frequent Contributor

Jeff,

I can reproduce the issue with your app but not with the Directions sample in the help.   Are you able to reproduce with the sample? If not then maybe try adding some of your custom logic to the sample until it breaks. This will give us a small bit of code that easily allows us to reproduce the issue and troubleshoot the problem.

ArcGIS API for JavaScript Sandbox

0 Kudos