Select to view content in your preferred language

ADDING ESRI'S WORLD TRAFFIC SERVICE TO A WEB APPLICATION - Updated 7/22/2020

6017
10
04-08-2016 10:20 AM
EricRodenberg
Esri Contributor
6 10 6,017

First, thanks to Peter Gamberg on the State and Local Government Team for helping me by updating the steps in the workflow.  It has been several years since I wrote this and I knew the workflow had changed based on updates made to the Esri Developers site but my priorities have been elsewhere.  

 As you build more and more ArcGIS Online web applications for your organization, you'll likely need to include one of Esri's Premium Services, such as Live Traffic, especially if your organization is a State Department of Transportation. While Live Traffic does not cost credits, it does require a named user to access the premium content. You, of course, know this because when you launched the application, which you tirelessly spent all that time configuring, you hit the snag where the app requires the user to sign in. So how are you supposed to deploy a public app with traffic cameras, weather, and live traffic if your app requires a login?

 

You could provide an access token and embed it in your application, but this requires custom development, and you must host the application yourself. Also, this method creates a security risk because your token could be hijacked and used without you ever knowing. 

 

A more straightforward solution is to create a proxy service configuration for the premium service of your choice. A proxy service allows you to encode and manage your credentials inside a service URL. Additionally, proxy services support rate-limiting. Proxy services allow you to make the Esri World Geocoding Service available to an end-user for batch Geocoding or other operations which do consume credits. However, it protects you because you can specify the rate at which addresses can be batch geocoded, preventing runaway usage while allowing the public the access they need.

Here is how it works.

  1. Log in to developers.arcgis.com with your ArcGIS Online credentials
  2. Register your application by choosing New Application
  3. Provide the Application Details
  4. Click on the Services Tab
  5. Scroll down to the Service Proxies area.
  6. Select the service you wish to proxy and enter a rate limit for the number of requests you want to allow over a given period.
  7. Copy the newly created proxy URL and add it to the webmap that your application is consuming. Remove the original service if it exists and save the webmap.
  8. Log out of all web sessions using your ArcGIS Online credentials or use Incognito Mode on your browser to test that your app opens without challenging you for credentials. (This is a quick trick to allow you to open the browser with a cleared browser cache.)  
  9. Open your web application and bask in the glory of your app opening with Premium Services that don't prompt your public users for an ArcGIS Online Username and Password. 

Try it live

Besides Traffic and Batch Geocoding you can also proxy the following services:

 
 

Service

Proxy Value

Geocoding

geocode

Geoenrichment

geoenrichment

Routing

route

Rout@@ing (Async)

asyncRoute

Closest Facility

closestFacility

Closest Facility (Async)

asyncClosestFacility

Service Area

serviceArea

Service Area (Async)

asyncServiceArea

Location Allocation

asyncLocationAllocation

Vehicle Routing Problem

syncVRP

Vehicle Routing Problem (Async)

asyncVRP

World Traffic

traffic

Elevation

elevation

Elevation

elevationSync

Hydrology

hydrology

10 Comments
EmilyLee
Deactivated User

Thank you for the step-by-step clips, Eric.  But with the new ArcGIS Online interface, in step #7, where do I add the proxy URL to the webmap item page please?

Thank you,

Emily

EricRodenberg
Esri Contributor

Emily,  Copy the proxy URL that you configured in the Developers.arcgis.com website.  The URL that was generated is an encoded rest endpoint with the necessary permissions to your ArcGIS Online account.  Open the web map that you want to add the traffic service to in the web map viewer.  Click the "Add" button on the map viewer and choose "Add Layer from Web" then paste the URL that you copied earlier.  Now that the layer is added you can set transparency, scale threshold, refresh interval, symbology and popups.

EmilyLee
Deactivated User

Thank you for your reply, Eric.  Sorry, I should have mentioned earlier that I was trying to use the Routing Service, not the Traffic Service.  Would the workflow be different?  When I tried to add the copied proxy Url as a web layer, it gave me the following error.  Is it because unlike Traffic Service, Routing Service is not really a layer?

Any guidance would be appreciated please.  I've been trying to configure the the routing service (even calling the tech support) for anonymous access in my apps since the last conference and hoping after this conference we'd have something easier to grant anonymous access for routing (directions).  Sorry, I know that we're asking for a magic button for everything! 

Thanks again,

Emily

EricRodenberg
Esri Contributor

Emily,  In this case since you want to ues the routing service to generate driving directions, you would add the URL to a routing widget.  So for example if I were configuring Web App Builder application with the Directions widget.  In the configuration there is a route URL.  I would replace it with the URL I generated when I created the proxy service.  So in this case the URL isn't added to the web map but rather to a widget.  How you add the URL depends on how the URL is accessed Route Services are accessed via Geoprocessing or Widgets. Live Traffic is accessed as a layer. The out of the box directions web app provided with ArcGIS Online already takes care of securing the directions service on your behalf but I don't think it gives you any control of how many routes can be generated.  The workflow I provide lets you choose that threshold.  Let me know if you need more help and as always you can also call Tech Support and they actually walk you through the steps.

Routing Service.png

EmilyLee
Deactivated User

It works perfectly!! Thank you, Eric!!

ManuelaEhrhardt
Deactivated User

Hello Eric,

thanks for your description, but it doesn't work in my web application. When I add the generated URL to my directions widget it shows me a red sign like in my screenshot.

So I can not save the widget. I am trying now for more than two days to get my application running for public users without AGOL Account. It's freaking me out that no way does work. 

Any solution?

Edit:

I tried it again an registered a new application, generated a new proxy service url in it and put it into the direction widget in my application. It worked this time. But it anyway has ABSOLUTELY NO effect for using it in public application. I am still being redirected to the login page when clicking on the widget. 😞

EricRodenberg
Esri Contributor

Manuela Ehrhardt, Based on what I see from the screen shot, it looks like it the world routing service can't reconcile identity.  I remember the ability to apply your ArcGIS Online user name and password to a service so when the service is used, the requests are impersonated by your identity...  I did a search and found this article from 2014... Give this a try and let me know how it goes... otherwise log a support incident because there may be something else missing. 

If you follow the directions in the aritcle make sure you remember to share the service publicly once you create it with your identity embedded otherwise your users will be prompted for a username and password.

ManuelaEhrhardt
Deactivated User

Hello Eric, thanks for your answer. I couldn't fix it on my own and so I asked my local esri support for help. The problem wasn't the Routing Service. I had an self made geocoder added to the app and this geocoder was simply not shared with public. So I added the esri geocoder again and it worked then.

Now I am happy 🙂

EricRodenberg
Esri Contributor

Excellent. I'm glad my doc wasn't incorrect and I sorry to hear that is was a permissions issue with another service. Glad you got it worked out. I'm sure it was a good learning experience. Thanks for letting me know.

Get Outlook for iOS<https://aka.ms/o0ukef>

e_cat
by
Occasional Contributor

Hi Eric, I've tried to add the World Traffic Service to my webmap. I am based in the UK and it seems the traffic data is displaying on the wrong side of the road. It seems the traffic is on the opposite side to the route we actually drive on and displaying as traffic on Google maps. Do you know how to fix this please?

About the Author
Eric Rodenberg is a Solution Engineer and has been with Esri for 19 years. Eric works with Esri's Port and Maritime customers to use best practices when deploying the ArcGIS platform and implementing efficient GIS workflows. Eric has earned multiple Esri certifications and is versed in the entire Esri software suite of products. Eric has presented technical workshops at the Esri International User Conference. Additionally, Eric had the opportunity to teach hundreds of users during his time as an instructor with Esri. Eric is a graduate of Wittenberg University. In his spare time, Eric enjoys, traveling with his family, playing, and watching sports.