Configure Routing Task

In one of my recent teaching trips to St. Louis, MO the discussion came up as to how to use the network analyst extension capabilities in the web mapping application. While looking through the Web ADF Java Doc surprisingly I did find the Routing task and an associated taskinfo class. Java Web ADF has a ready to use Routing Task but is not configurable through the manager.

Out of curiosity and with help of fellow employee (Thanks Lloyd) we figured out that if you have ArcGIS Server Service with Network Analysis capability enabled and a Geocode service then you can use these services with the Routing task in your web mapping application. The only thing missing is documentation on how to configure and use the task. Here are the steps to add this task to your application :

1. Add the Task as a managed bean in the faces-config.xml

<managed-bean>

<managed-bean-name>routingTask</managed-bean-name>
<managed-bean-class>com.esri.adf.web.ags.tasks.RoutingTask</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
<managed-property>

<property-name>webContext</property-name>
<value>#{mapContext}</value>

</managed-property>

</managed-bean>

2. Add the TaskInfo class as a managed bean in the faces-config.xml

<managed-bean>

<managed-bean-name>routingTaskInfo</managed-bean-name>
<managed-bean-class>com.esri.adf.web.ags.tasks.RoutingTaskInfo</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>

</managed-bean>

3. In order to get the Routing task to work you need to have a extension resource which has network analyst functionality and a geocoding resource. You can use the SanFrancisco-SimpleRoute.MXD provided with the samples to start a map service with network analysis capability enabled and associated locator file to start geocoding service. Then you can add these resources to the mapping application as managed bean entries into the faces-config.xml

<managed-bean>

<managed-bean-name>routingresource</managed-bean-name>
<managed-bean-class>com.esri.adf.web.ags.data.AGSExtensionsResource</managed-bean-class>
<managed-bean-scope>none</managed-bean-scope>
<managed-property>

<property-name>endPointURL</property-name>
<property-class>java.lang.String</property-class>
<value>http://localhost:8399/arcgis/services/SanFrancisco/MapServer</value&gt;

</managed-property>

<managed-property>

<property-name>alias</property-name>
<value>SanFrancisco-SimpleRoute</value>

</managed-property>

<managed-property>

<property-name>functionalities</property-name>
<map-entries>
<map-entry>
<key>map</key>
<value>#{agsMap}</value>
</map-entry>
<map-entry>
<key>toc</key>
<value>#{agsToc}</value>
</map-entry>
<map-entry>
<key>overview</key>
<value>#{agsOverview}</value>
</map-entry>
<map-entry>
<key>query</key>
<value>#{agsQuery}</value>
</map-entry>
<map-entry>
<key>tile</key>
<value>#{agsTile}</value>
</map-entry>
<map-entry>
<key>scalebar</key>
<value>#{agsScaleBar}</value>
</map-entry><map-entry>
<key>networkAnalyst</key>
<value>#{agsNetworkAnalyst}</value>
</map-entry>
</map-entries>

</managed-property>

</managed-bean>

<managed-bean>

<managed-bean-name>geocoderesource</managed-bean-name>
<managed-bean-class>com.esri.adf.web.ags.data.AGSGeocodeResource</managed-bean-class>
<managed-bean-scope>none</managed-bean-scope>
<managed-property>

<property-name>endPointURL</property-name>
<property-class>java.lang.String</property-class>
<value>http://localhost:8399/arcgis/services/SanFranciscoGeocode/GeocodeServer</value&gt;</managed-property>

<managed-property>

<property-name>alias</property-name>
<value>SanFran_street_zip</value>

</managed-property>
<managed-property>

<property-name>functionalities</property-name>
<map-entries>

<map-entry>
<key>geocode</key>
<value>#{agsGeocode}</value>
</map-entry>

</map-entries>

</managed-property>

</managed-bean>

4. Once you have the resources make sure its added to WebContext (managed bean is called mapContext in the faces-config.xml) as a managed property for resources

<managed-property>

<property-name>resources</property-name>
<map-entries>

<map-entry>
<key>ags1</key>
<value>#{routingresource}</value>
</map-entry>
<map-entry>
<key>ags2</key>
<value>#{geocoderesource}</value>
</map-entry>

</map-entries>

</managed-property>

5. Finally add the task tag to the JSP page and some javascript code to invoke the task.

<a:task id=”routingTask” value=”#{routingTask}” taskInfo=”#{routingTaskInfo}” mapId=”map1″ windowingSupport=”true” />

<a href=”javascript:void(0);” onclick=”toggleWindow(‘win_EsriTaskCell_routingTask’);”>Routing Task</a>

Screen shot showing the task and the result :

Advertisements

2 Responses to “Configure Routing Task”

  1. vajco Says:

    thanks a lot for this man !

  2. Carlos Says:

    Any links or information on how to do this in .NET?

    Thanks!


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: