Use of Arcade Expression in ArcGIS MapViewer

Introduction

In the previously demonstrated section was the use of Arcade Expression within ArcGIS Pro, an installed application. In this and the remaining lessons described, web applications will be explored. In no way are these lessons designed to completely demonstrate all possible usages within any single application or program. 

Calculate Field

Many times a table might contain values, but none of the values meet the needs of the researcher. For Example, the research might need to columns to be added together and that column will be visualized on the map. If working with U.S. Census data, the table might have a column for male population and another column for female population. But for the map the research wants to plot a tool population column. Thus a new field needs to be created and then the created column have the summation results.

The first step will be to create a new field.

The second step will be to populate the attribute with summation results.

Pop-Ups

Example 

The use of Arcade in the construction of Pop-up within ArcGIS Pro is an example of how to improve the information displayed for the user. In this example, pop-ups will again be explored using a set of feature class files contained within ArcGIS Online, (AGO, AGOL).

For this example, the following file will be used to demonstrate the process.  https://kctcs.maps.arcgis.com/apps/mapviewer/index.html?layers=42890691bd8a4dc9b9a7a5c43b8bf727 

The file is named Indiana Select Files and make sure it opens in the new ArcViewer and not the classic (see image to the right). The file contains three feature class files. The location of the cemeteries in Indiana is from USGS data, [1] a line file of water bodies in Indiana and portions of adjoining states is from the state of Indiana GIS data repository, and a polygon file of county boundaries is also from USGS.  A background map is also loaded.

[1] United States Geologic Survey 

Figure -1- Pop-up Expression

On the left side of the screen, under layers button, select the point file of cemeteries, and the display will open the property window on the right side of the screen (if already opened it will disappear and if this occurs, select again). In the buttons on the right side is a button for pop-ups (list of properties), once selected this button will open the properties. The pop-up window will appear, and a new menu will be on the right side of the screen. Select under options Attribute expressions. Once the Expression is selected, the window will allow for adding expressions, opening a large full screen window to input the Expression using Arcade. The window will open initially with three lines of comments that can be modified or deleted. On the far right side of the window are two different types of expressions that can be used and a help button. At the bottom right corner is the done and cancel buttons. See the image below.

Figure -2- Creating the Script

Explore the fields in the cemetery file to understand the structure.

The red box (upper right corner) shows the button used to display the fields. The purple box displays the fields (must select $feature), thus eliminating the need to type the features in the Expression. The green box shows the two lines of scripts created along with the comments. The script will add the word county followed by the name and the word Quad followed by the Quad. When the script was completed, it was ran by selecting the button in the blue box. The result of running the script is shown in the golden box. Finally, when completed, select the done button.  

Figure -3- Selected fields in a pop-up

The next step is selecting the field list and turning off those fields that are no longer needed in the pop-up window; a much better-appearing pop-up window has been created. Select done when all the selections have been created. Finally, the web map is saved and opened in the map viewer. The pop-ups are tested to ensure they are working properly.  

Advanced Pop-Ups

This part of the workshop will deal with more advanced uses of pop-ups which includes Arcade Scripts.

The process and the purpose:

  1. Collect data from historical markers and display the information. A Survey123 instrument was developed, which includes the text from historical markers, keyword search terms, location of the marker, and photographs of the marker. The survey information can be collected using a smart device with a GPS. The collected information is a feature class file.
  2. The collected information is opened in MapViewer and the pop-ups are modified through the use of Arcade Expression script. The default pop-up is modified so that fields are combined, the latitude and the longitude is displayed, along with marker photographs and the text of the marker front and backsides are displayed in a continuous appearance.
  3. Within MapViewer all the fields in the normal pop-up are turned off and a textbox is created to make a more attractive display.
  4. Once the pop-ups are configured, a Dashboard was created that displays keywords and states, which are interactive and dynamic information.

The Arcade Script used to create the pop-up is shown below, along with the test run. To the right is displayed MapViewer results, select different datapoints and observe the pop-up.

Pop-up Arcade Script and Results.

The script is composed of six lines of codes, which are reflected below.

  1. On the first line a new variable is constructed which combines city and state together, and adds blank lines.
  2. On the next line a new variable is defined, which combines the front and back text as well as line returns.
  3. On line 3, code is composed that converts latitude from meters to decimal degrees.
  4. On line 4, code is composed that converts longitude from meters to decimal degrees as well as rounding the results to three decimal places. This line also combines the latitude and longitude to a single line for display purposes.
  5. This line of script is used to create a new variable which combines different fields of the keywords into a single variable.
  6. The final line of the code outputs the display of the information.

The results are displayed in the lower portion of the scripting window.

In MapViewer the pop-up is configured as a textbox with the information script and other fields. In this effort a much better display of information can be accomplished.

Once the script is completed, the webmap is loaded into a Dashboard. Many of the dashboard features are used as well as making the pop-ups more attractive by change font and background color. Note, that content displayed in the web map and the dashboard are the same, but have a different appearance.

Assignment 

Use the css skills learned in the ArcGIS Pro lesson on pop-ups and those skills learned in this example (ArcGIS Online pop-up) to create a pop-up with at least two colors and different font sizes within ArcGIS Online. Use the same maps used in this example, one of the other layers from this example, or one of the learner's choice. 

In addition to being able to combine two fields together and adding text to the pop-up there are many other things and more complex scripts that can be written which includes the use of logic and decision making functions. For example if the field uses either a 'y' or an 'n' for yes and no respectively. The actual shown output can be yes and no instead. In addition multiple fields can be combined together and formatted to make a more appealing information set.

For example, a project was being constructed and there were several yes/no answers each as a unique field thus in the default pop-up there were multiple rows to show the information, the example below shows how that can be done in a single row.

Labels in ArcGIS Online 

Example 

The learner will explore labeling features using Arcade in ArcGIS Online in this example. The concepts will be similar to what was done with the pop-ups in the previous section. Select the cemetery feature class file on the left side of the screen, and use the cemetery layer; the water layer or boundary layer could have been selected. Once the layer is selected, select Labels on the right side and select add label class. It may take a moment until the window opens. The first thing to do is to ensure the labels do not appear until the zoom level is at the county level. Therefore, adjust the visible range. Select the </> symbol next to the name field, which will open an expression window. Expressions can also be written to filter content.  

Figure -4- Starting Labeling with Arcade

A new window similar to the pop-up expression window will open, and the script will initially display the name field. Select the (x) and the > symbol on the right side to display all the fields in the cemetery file. Create an expression that displays the Quad and the name to assist genealogist. Provide a name for the Expression. Do a test run, and when functioning properly, select Done. Add comments to the Arcade expressions to understand their function and purpose. Once the Expression is completed, save the web map and test it. 

Figure -5- Label of Cemetery

Assignment 

Use the other two feature class files to create appropriate labels that utilize css scripts. In addition, do calculations with the county boundary files similar to what was done using the desktop software, ArcGIS Pro, for the percentage of water. 

Figure -1- Pop-up Expression

Figure -2- Creating the Script

Figure -3- Selected fields in a pop-up

Pop-up Arcade Script and Results.

Figure -4- Starting Labeling with Arcade

Figure -5- Label of Cemetery