AGRC Web Mapping Services Demo

This article will take 4 minutes to read

AGRC offers a variety of mapping-related web services that make it easy to add authoritative Utah web maps to your applications. The two most popular are our base maps and geocoding service. These web services, together with a custom map service that shows your own agency/business-specific data, can add great geographic context to your web applications.

This post will show you how simple it is to leverage AGRC's services with JavaScript. We will develop a simple web app that contains a dynamic map and simple address finding controls. Please note that we've added a simple glossary of terms at the bottom of this page.

This will load all necessary dependencies including Dojo into your application. Dojo is a widely used javascript library containing commonly used functionality for cross-browser compatible user interface presentation and management. Because it's built on top of Dojo, ESRI's API also employs the new Asynchronous Module Definition (AMD) standard for loading external JavaScript libraries. With both Dojo and ESRI development teams using AMD, it is highly recommended that you also use the AMD loading syntax, as this should maximize the life-expectancy for the map-service consuming code that you write. All code examples in this post will be using the new AMD syntax. If you are unfamiliar with AMD you may want to check out Dojo's excellent tutorial on the subject.

Adding one of these services to a map is relatively easy. First, we need to import a few ESRI modules. Then create a new map and tiled layer. Finally, we add the newly created layer to the map. Here's what the code looks like:

Geocoding (Address Matching)

To geocode an address means to find it's corresponding geographic coordinates (think latitude and longitude). AGRC provides a highly authoritative service for geocoding addresses which is regularly updated from road centerline and address point data available to AGRC through its local government partners across the state. In addition, the service has been optimized for the State of Utah's somewhat unique placename and addressing system conventions.

Before you can use any of AGRC's web API services you will need to create an account and an API key for your domain. Check out the Getting Started Guide for more information. Once you have a key you can start using services such as geocoding. Here's an example of a typical geocoding request that finds coordinates for 123 S Main St, SLC:

Perhaps the easiest way for you to use this service is to use the FindAddress widget in our AGRC Dojo Widget Library. You can do this by adding a config object to your require call that defines an agrc package and its location. Here we have it pointing at the 'agrc' package on our CDN resource:

Once we have defined our agrc package, we can import modules just like any other package. This example shows how to import the FindAddress widget and initializing it with our map object and our AGRC Web API key:

Custom Data Overlays

The next step in our demo will be to add a data overlay on top of the base map. To do this you need to have access to a map web service, that points at your own data on a server and makes it accessible to web-based map requests. This is most commonly done using ESRI's ArcGIS Server or similar software or via cloud-hosted data and services platform such as ArcGIS Online. If you do not have access to this software, you may want to contact us about getting a service set up on our servers for you. For this demo we will use a service that we host that shows the Utah Division of Fleet Operations' vehicle refueling sites around the state. The endpoint for this service is here:

To add this map service to our map we need to import the esri/layers/ArcGISDynamicMapServiceLayer module and create a new layer using the url to the service. Then we can add it to the map. Here's what it looks like:

Spatial Queries

Another useful AGRC web API service is the ability to search for geographic features in any of the datasets in the SGID. This functionality is found in the Search service. You can check out the api docs for an example request and response. We will use this service to display a message that tells us what city we are in when we click on the map. Within the map's click event we pass the coordinates from the map click event to the search service along with the feature class name (SGID10.BOUNDARIES.Municipalities) and the field name (NAME). Then when the service returns, we populate the page with the data. Here's what it looks like:

Wrap-up

This is just a small sampling of what AGRC has to offer in terms of web mapping services. If you are interested in an advanced example of one of our web applications you can check out our AGRCJavaScriptBoilerPlate. A presentation detailing how this sample was engineered was given at the ESRI Dev Summit in March 2013.