The maps created earlier in the lesson offer interactivity in the form of zooming in/out, toggling layers on/off, accessing info about map features by clicking on them, changing the base map, etc. This part of the lesson will begin by showing how to embed your Google and Esri maps within a separate web page. After that, we'll look at tools developed by Esri that make it possible to incorporate even more interactivity -- to turn your map into an app.
Embedding a map
While it's sometimes preferable to share the link to your map -- allowing it to fill the viewer's browser window -- it can also be useful to embed the map within a page of content.
- Save this example page to your computer. (Right-click on the link and choose Save.)
- Open the page in a plain text editor of your choosing (e.g., Notepad).
- Go back to Google My Maps and open the map you created earlier in the lesson.
- Click the vertically oriented dots next to your map's title, then select Embed on my site from the list of options.
- Following the instructions in the dialog that appears, paste the code for your map into the html document you opened for editing above. Paste the code below the line that produces the My Google Map heading.
We'll get into HTML coding in the next lesson (probably more than you'd like), so don't worry if you don't fully understand everything that's going on in your HTML document. One piece of the code you just pasted that's easy to follow is the fact that the map will be drawn with a width of 640 pixels and a height of 480 pixels. You're welcome to change those values if you like.
Now let's embed the ArcGIS Online map. - If your ArcGIS Online map is no longer open, go to our Penn State organization page, click My Content, click on the map you created earlier, then select Open > Open in map viewer.
- Click Share, then EMBED IN WEBSITE.
Note that ArcGIS Online provides a number of options for customizing the embedded map. For example, it's possible to specify the dimensions of the map, and to include widgets such as a base map selector or legend. - After making settings to your liking, find the wide text box just above the Map Options. This box contains the HTML code required to embed your map within a web page. Click the COPY button to the right of that text box to copy the HTML code to your machine's clipboard.
- Paste that code into your HTML document just beneath the My ArcGIS Online Map heading.
- Save your HTML document with a name like lesson1.html.
- Using the File Explorer in Windows, browse to the document you just saved and double-click on it to open it in a web browser. (If .html files aren't set to open in a web browser on your machine, you may need to right-click and select Open With.)
Configuring an app based on a template
The interactivity offered by these maps is nice, but you may find yourself in situations where you need to go further. For example, maybe you want end users to be able to query the map's underlying data for features meeting certain criteria or to be able to edit the underlying data. Esri offers a couple of different non-programming options for those looking to build apps with greater functionality. The first of these is a set of templates that each meet a narrowly focused need (e.g., Edit, Query, Directions). As the app developer, you select the desired template and make a relatively small number of configurations to tailor the app to your needs. The second option is to use Web AppBuilder. This option is more open-ended, allowing you to build a less narrowly focused app by picking and choosing from a set of widgets.
We'll start with configurable app templates and to demonstrate their use we'll create an app for locating buildings on the Penn State Main Campus.
- In your Penn State ArcGIS Online organizational account, create a new map.
- Add the campus building data as a layer by going to Add > Add Layer from Web and pasting this ArcGIS Server map service:
http://maps.pasda.psu.edu/arcgis/rest/services/pasda/PSU_Campus/MapServer/1 - Zoom to the central part of campus and style the layer as desired.
- Save the map with the name PSU Buildings. Be sure to add some tags that would aid in discovering the map (e.g., Penn State, buildings) and optionally enter a summary.
- Click Share, then check the Everyone box to ensure your map is viewable to the public.
- Click Create a Web App. You'll be presented with a gallery of app templates on which you can base your own app. Browse the templates to get a sense of the variety of apps available. Note that how your map will look within a given template can be previewed by clicking on the desired template and selecting Preview.
We're going to create a Finder application so that users can search for buildings by name. - Click on the Finder template and select CREATE WEB APP.
- Assign a title to the app (e.g., Penn State Main Campus Building Finder), add some tags that would aid in discovering the app (e.g., Penn State, buildings), optionally enter a summary, then click DONE. After a few moments, you'll be presented with a Configure page. The full set of configuration options for this template are organized into App Settings and Search Settings (links on the upper left of the page). Let's start with App Settings, already shown by default.
- The app initializes with a generic default logo and heading. Set the Application title to Penn State Main Campus Building Finder.
- Set the URL of application logo to http://www.e-education.psu.edu/geog863_gmaps/sites/www.e-education.psu.edu.geog863_gmaps/files/psu-facebook-avatar-180x180.jpg
Note that while the image is actually 180 pixels x 180 pixels, it will be dynamically resized to 48 pixels x 48 pixels. - The Sea Blues option is the best match to the University's colors, so leave that as the Color Scheme.
The Finder app includes a widget that allows the user to change the basemap. The next two GUI options are used to specify a custom basemap collection, if your organization has one. Our Penn State organization does not, so we will stick with Esri's default basemaps and skip to the Help Widget Text. - Under the Help Widget Text heading, enter:
Penn State Main Campus Building Finder<hr><br>Click on the magnifying glass icon to find all buildings on the PSU University Park campus whose name contains your search text.
The Finder app provides a box for the user to enter search text, displays a list of matching features and re-centers and zooms in to the selected feature. As the developer, you get to specify what columns to search, how to display the matching features, the zoom level to zoom to and whether a popup window should open over the selected feature. - Click the Search Settings link (upper left) to access these options.
- Set the Hint to Enter part of a building name.
- Leave the Zoom Level set to 16 and confirm that a popup window will be displayed.
- Under the Find layers and fields heading, check the box next to PSU_Campus - PSU OPP Buildings 2016 to expand the list of columns in that layer.
- Check the BLDG_NAME_ column. (That's the column you want to search.)
- Select the same layer and column under the Result display layers and fields heading. (You want the building name to be shown in the list of matching features.)
With that, you've made all the necessary settings to tailor this template to your specific purpose. - Click Save and View. You'll see a preview of your app embedded within the same Configure page, making it easy to go back to the app's settings should you see something you want to change.
- Click Close once you're satisfied with the app's settings. You'll be taken to your app's "item details" page (also accessible from your "My Content" page).
- To see the app as an end user would see it, click the View Application button to open it in a new browser tab and test your new app by clicking on the Find (magnifying glass) icon in the upper right of the window.
- Try entering the name 'walker' and you'll see that the app finds two buildings that make up the Walker Clubhouse (associated with the PSU golf courses) and Walker Building (home of the Geography and Meteorology departments). Note how the settings you made when configuring are reflected in the app.
- Returning to the Details page, note the various pieces of metadata that can be edited (thumbnail, description, access use and constraints, etc.).
- Note also that you would come here and click the Configure App button if you wanted to make changes to the app.
- Finally, and importantly, if you want others to be able to use your app, you'll need to click the Share button. In the Share dialog, you can select whether you want the app to be visible to Everyone, your Penn State group, or some other group to which you belong. Select Everyone in this case.
- And just to test your app's visibility, scroll to the bottom of the app's Details page and find the URL in the bottom right. Click the Copy button to copy the URL to your clipboard, then paste that URL into a different browser where you are not signed in to ArcGIS Online. If the app works properly, then you can safely share that URL with your end users.
Creating an app with the Web AppBuilder
Now let's try Esri's more open-ended option for creating apps.
- Re-open your Buildings map and click again on the Share button.
- Click Create a Web App and this time click on the Web AppBuilder tab rather than the Configurable Apps tab.
- Assign a Title of PSU Main Campus Buildings, add some tags that would aid in discovering the app (e.g., Penn State, buildings), optionally enter a summary, then click Get Started.
The Web AppBuilder will open with configuration options organized within tabs on the left side of the window and a preview of your new app on the right side. The app is dynamically linked to the configuration options so that changes made on the left will be reflected on the right immediately. The first of the configuration tabs is Theme, which provides access to settings that deal mainly with the app's appearance. - Try out some or all of the available themes (Billboard, Box, Dart, etc.). The controls on the app preview are functional, so you can click on the Legend and Layer List controls to see how they would behave. Depending on the theme chosen, you will see different options under the Style and Layout headings.
- Click on the Map tab and note that it is possible to change the app's underlying Web Map and to override the map's initial extent and visible scale levels.
- Next, click on the Widget tab. This is where the real power of the Web AppBuilder becomes apparent.
The widgets available in Web AppBuilder can be categorized as off-panel or in-panel. Off-panel widgets are built into the app and can only be toggled on/off. Examples include the Scalebar and Coordinate widgets. In-panel widgets, on the other hand, can be added to or removed from the app. When adding an in-panel widget, the developer can position the widget within a container. If you experimented with the various themes, you saw that the shape and positioning of the widget container is something that differs across the themes. And for some themes, in-panel widgets can also be placed in numbered positions outside of the theme's container. - Hover your mouse over some of the off-panel widgets and note the following:
- An eye icon appears in the widget's upper-right corner. The widget can be toggled on/off by clicking on this icon. Widgets that have been turned on are shaded dark blue, while those that are turned off are light blue.
- Widgets that are toggled on will have their position within the app highlighted in red.
- A pencil icon appears in the widget's lower-right corner. The widget can be configured by clicking on this icon. (For example, the Scalebar widget can be configured to show distance measured in English units, metric units, or both.) - Turn on the following widgets: Attribute Table, Coordinate, My Location, Scalebar, Overview Map.
- Configure the widgets as follows:
- Attach the Overview Map to the top-right corner and initialize it in its expanded state.
- Modify the Attribute Table so that only the building name and abbreviation columns are visible. (Note that this can also be done for the web map itself, which is an important consideration if you're using the map as the basis for multiple apps serving multiple purposes/audiences.)
Now let's modify the widgets that are held within your theme's widget container (or controller). - Regardless of the theme you selected, you should see a Set the widgets in this controller link near the top of the tab. Click on this link. You should see the Legend and Layers List widgets by default.
For this simple map in which the title makes it clear what's being shown, a legend is unnecessary. - Hover your mouse over the Legend widget and click on the X in the upper right to remove it from the app.
For the same reason, you could probably also remove the Layer List widget. However, this widget provides a context menu of options that could be of interest to users. - Hover your mouse over the Layer List widget and click on the pencil icon to change its configuration.
Note that the widget makes it possible to view a legend for each layer (by clicking on a small arrow to the left of the layer name) and to access a set of layer-specific actions through the context menu. All of these items are turned on by default. - Uncheck the Show Legend box (again, not much point in a legend), the Enable/Disable Pop-up box and the Move up/Move down box (with only one layer on the map, these options will be disabled anyway).
- Click OK to dismiss the Layer List dialog, then Save your app.
- Click the Launch button to open your app in a new tab and confirm that the various settings you've made have taken effect.
Now let's check out some of the other in-panel widgets that are available. - Close the tab containing your running app and return to the Web AppBuilder tab.
- Under the Widgets heading, click on the + sign to add a new widget. In addition to the Layer List and Legend widgets that we've already seen, you should see many others including Basemap Gallery, Edit and Geoprocessing, among others. Being able to switch basemaps is a nice feature to have, even in a very simple demo like this, so let's provide that capability.
- Click on the Basemap Gallery widget and click OK. You'll be taken immediately to a configuration panel, which for this widget provides the ability to remove basemap options.
- Remove the Imagery with Labels (it differs little from Imagery in this area), Oceans (not applicable to this area) and Terrain with Labels (not intended for use at this scale) basemaps as options and click OK.
- Click again on the + sign, add the Draw widget, check the box to Add the drawing as an operational layer of the map and click OK. This will enable the user to add custom features and annotation as a separate layer.
Now let's say you want the widgets to appear in a different order. - Click on one of the widgets and drag it to a new position. You should see a red vertical line indicating where the widget will end up when you release the mouse button.
Before leaving the Widgets tab, there are a few more points worth mentioning:
- The Analysis widget provides access to several analytical tools that may be useful depending on the app's purpose (e.g., Create Buffers, Create Viewshed, etc.). Keep in mind though that usage of these tools may consume service credits allocated to your ArcGIS Online organization.
- The Edit widget can be used to develop online editing apps.
- The Geoprocessing widget can be used to "wire up" your app to a geoprocessing task
- Full documentation for all of Esri's widgets can be found at http://doc.arcgis.com/en/web-appbuilder/create-apps/widget-overview.htm - Click on the Attribute tab to move on to a set of options that help with branding your app.
- Enter a sensible Title, such as Penn State University Park Buildings.
- If you're not interested in advertising for Esri, clear the text in the Subtitle box or assign your own.
- Download the Nittany Lion shield and assign it as the app's logo by hovering over the Logo icon, clicking the button that appears in the lower right and browsing to the image on your computer. (It's not possible to link to an image hosted elsewhere as we did earlier with the configurable app.) Note that the logo is not displayed for all themes.
- Click on Add New Link, enter www.psu.edu in the first box (the text that you want to display) and the URL http://www.psu.edu in the second box. Again, note that links are not displayed for all themes.
- Finally, Save your app, then click Launch to see the app as an end user would.